Support double lwip eport, use mongoose.a

This commit is contained in:
TXuian 2023-12-06 15:59:27 +08:00
parent e0e314e301
commit 616dc4584f
41 changed files with 417 additions and 10941 deletions

View File

@ -76,10 +76,12 @@ struct IperfParam {
static void* TestIperfServer(void* param)
{
struct IperfParam* iperf_param = (struct IperfParam*)param;
int sock = socket(AF_INET, SOCK_STREAM, 0);
int sock = socket(AF_INET, SOCK_STREAM, 6);
if (sock < 0) {
printf("[%s] Err: Can't create socker.\n", __func__);
return NULL;
} else {
printf("[%s] Info Create server socket %d\n", __func__, sock);
}
uint8_t* recv_data = (uint8_t*)malloc(IPERF_BUFSZ);
@ -121,8 +123,9 @@ static void* TestIperfServer(void* param)
socklen_t sin_size = sizeof(struct sockaddr_in);
struct sockaddr_in client_addr;
int connection = accept(sock, (struct sockaddr*)&client_addr, &sin_size);
printf("[%s] Info: New client connected from (%s, %d)\n", __func__,
inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
printf("[%s] Info: New client connected from (%s, %d), connect: %d\n", __func__,
inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port),
connection);
int flag = 1;
setsockopt(connection,
@ -141,8 +144,8 @@ static void* TestIperfServer(void* param)
inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
break;
} else if (bytes_received < 0) {
KPrintf("recv error, client: (%s, %d)\n",
inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
KPrintf("recv error: %d, client: (%s, %d)\n",
bytes_received, inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
break;
}
@ -258,8 +261,6 @@ enum IperfParamEnum {
void TestSocket(int argc, char* argv[])
{
lwip_config_tcp(0, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
static char usage_info[] = "Run either a iperf server or iperf client.";
static char program_info[] = "Lwip socket test task, a simple iperf.";
static const char* const usages[] = {

View File

@ -1,3 +1,3 @@
SRC_FILES += mongoose.c netsetting.c project.c
SRC_FILES += project.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -0,0 +1,3 @@
SRC_FILES += mongoose.c
include $(KERNEL_ROOT)/compiler.mk

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,102 +0,0 @@
// Copyright (c) 2022 Cesanta Software Limited
// All rights reserved
//
// UI example
// It implements the following endpoints:
// /api/config/get - respond with current config
// /api/config/set - POST a config change
// any other URI serves static files from s_root_dir
// Data and results are JSON strings
#include "ip_addr.h"
#include "mongoose.h"
#include "netdev.h"
static const char* s_http_addr = "http://0.0.0.0:8000"; // HTTP port
static const char* s_root_dir = "netsetting";
static struct netdev* p_netdev;
static struct config {
char *ip, *mask, *gw, *dns;
} s_config;
// Try to update a single configuration value
static void update_config(struct mg_str json, const char* path, char** value)
{
char* jval;
if ((jval = mg_json_get_str(json, path)) != NULL) {
free(*value);
*value = strdup(jval);
}
}
static void fn(struct mg_connection* c, int ev, void* ev_data, void* fn_data)
{
if (ev == MG_EV_OPEN && c->is_listening) {
s_config.ip = strdup(inet_ntoa(p_netdev->ip_addr));
s_config.mask = strdup(inet_ntoa(p_netdev->netmask));
s_config.gw = strdup(inet_ntoa(p_netdev->gw));
s_config.dns = strdup(inet_ntoa(p_netdev->dns_servers[0]));
} else if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message* hm = (struct mg_http_message*)ev_data;
if (mg_http_match_uri(hm, "/api/config/get")) {
mg_http_reply(c, 200, "Content-Type: application/json\r\n",
"{%m:%m,%m:%m,%m:%m,%m:%m}\n",
MG_ESC("ip"), MG_ESC(s_config.ip),
MG_ESC("mask"), MG_ESC(s_config.mask),
MG_ESC("gw"), MG_ESC(s_config.gw),
MG_ESC("dns"), MG_ESC(s_config.dns));
} else if (mg_http_match_uri(hm, "/api/config/set")) {
struct mg_str json = hm->body;
printf("json: %s\n", json.ptr);
update_config(json, "$.ip", &s_config.ip);
update_config(json, "$.mask", &s_config.mask);
update_config(json, "$.gw", &s_config.gw);
update_config(json, "$.dns", &s_config.dns);
mg_http_reply(c, 200, "", "ok\n");
ip_addr_t ipaddr, maskaddr, gwaddr;
inet_aton(s_config.ip, &ipaddr);
inet_aton(s_config.mask, &maskaddr);
inet_aton(s_config.gw, &gwaddr);
p_netdev->ops->set_addr_info(p_netdev, &ipaddr, &maskaddr, &gwaddr);
printf("Board Net Configuration changed to [IP: %s, Mask: %s, GW: %s]\n",
s_config.ip,
s_config.mask,
s_config.gw);
} else {
struct mg_http_serve_opts opts = { .root_dir = s_root_dir };
mg_http_serve_dir(c, ev_data, &opts);
}
}
(void)fn_data;
}
static void* do_net_setting_demo(void* none)
{
p_netdev = NETDEV_DEFAULT;
struct mg_mgr mgr; // Event manager
mg_log_set(MG_LL_DEBUG); // Set to 3 to enable debug
mg_mgr_init(&mgr); // Initialise event manager
mg_http_listen(&mgr, s_http_addr, fn, NULL); // Create HTTP listener
for (;;)
mg_mgr_poll(&mgr, 10); // Infinite event loop
mg_mgr_free(&mgr);
return NULL;
}
int net_setting_demo(int argc, char* argv[])
{
pthread_t tid = -1;
pthread_attr_t attr;
attr.schedparam.sched_priority = 30;
attr.stacksize = 16384;
PrivTaskCreate(&tid, &attr, do_net_setting_demo, NULL);
return 0;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(5), NetSettingDemo, net_setting_demo, webserver to set net configurations);

View File

@ -14,7 +14,7 @@
char index_path[] = "login.html";
static const char* s_http_addr = "http://0.0.0.0:8000"; // HTTP port
static const char* s_http_addr = "http://192.168.131.88:8000"; // HTTP port
static const char* s_root_dir = "webserver";
static const char* s_enable_hexdump = "no";
static const char* s_ssi_pattern = "#.html";
@ -104,18 +104,22 @@ static void fn(struct mg_connection* c, int ev, void* ev_data, void* fn_data)
(void)fn_data;
}
extern void LwipSetIPTest(int argc, char* argv[]);
static void* do_webserver_demo(void* none)
{
p_netdev = netdev_get_by_name("wz");
if (p_netdev == NULL) {
MG_INFO(("Did nto find wz netdev, use default.\n"));
p_netdev = NETDEV_DEFAULT;
s_config.ip = strdup(inet_ntoa(p_netdev->ip_addr));
s_config.mask = strdup(inet_ntoa(p_netdev->netmask));
s_config.gw = strdup(inet_ntoa(p_netdev->gw));
}
MG_INFO(("Use Netdev %s", p_netdev->name));
s_config.ip = strdup(inet_ntoa(*p_netdev->ip_addr));
s_config.mask = strdup(inet_ntoa(*p_netdev->netmask));
s_config.gw = strdup(inet_ntoa(*p_netdev->gw));
s_config.dns = strdup(inet_ntoa(p_netdev->dns_servers[0]));
struct mg_mgr mgr; // Event manager
mg_log_set(MG_LL_INFO); // Set to 3 to enable debug
// mg_log_set(MG_LL_DEBUG); // Set to 3 to enable debug
// mg_log_set(MG_LL_INFO); // Set to 3 to enable debug
mg_log_set(MG_LL_DEBUG); // Set to 3 to enable debug
mg_mgr_init(&mgr); // Initialise event manager
mg_http_listen(&mgr, s_http_addr, fn, NULL); // Create HTTP listener
for (;;)
@ -126,12 +130,10 @@ static void* do_webserver_demo(void* none)
int webserver_demo(int argc, char* argv[])
{
LwipSetIPTest(1, NULL);
pthread_t tid = -1;
pthread_attr_t attr;
attr.schedparam.sched_priority = 30;
attr.stacksize = 0x4000;
attr.stacksize = 0x2000;
PrivTaskCreate(&tid, &attr, do_webserver_demo, NULL);

View File

@ -50,6 +50,7 @@ export SRC_DIR:= $(SRC_APP_DIR) $(SRC_KERNEL_DIR)
export LIBCC
export MUSL_DIR := $(KERNEL_ROOT)/lib/musllib
export LWIP_DIR := $(KERNEL_ROOT)/resources/ethernet
export MONGOOSE_DIR := $(KERNEL_ROOT)/../../APP_Framework/Applications/mongoose/lib
PART:=
@ -74,6 +75,10 @@ ifeq ($(CONFIG_RESOURCES_LWIP), y)
PART += COMPILE_LWIP
endif
ifeq ($(CONFIG_USE_MONGOOSE), y)
# PART += COMPILE_MONGOOSE
endif
ifeq ($(CONFIG_MCUBOOT_BOOTLOADER), y)
PART += COMPILE_BOOTLOADER
else ifeq ($(CONFIG_MCUBOOT_APPLICATION), y)
@ -130,6 +135,15 @@ COMPILE_LWIP:
@cp build/liblwip.a $(KERNEL_ROOT)/resources/ethernet/LwIP/liblwip.a
@rm build/Makefile build/make.obj
COMPILE_MONGOOSE:
@for dir in $(MONGOOSE_DIR);do \
$(MAKE) -C $$dir COMPILE_TYPE=$@; \
done
@cp link_mongoose.mk build/Makefile
@$(MAKE) -C build TARGET=mongoose.a LINK_FLAGS=LFLAGS
@cp build/mongoose.a $(KERNEL_ROOT)/../../APP_Framework/Applications/mongoose/mongoose.a
@rm build/Makefile build/make.obj
COMPILE_KERNEL:
@for dir in $(SRC_KERNEL_DIR);do \
$(MAKE) -C $$dir; \

View File

@ -278,10 +278,7 @@ struct pbuf* low_level_input(struct netif* netif)
return p;
}
extern void LwipSetIPTest(int argc, char* argv[]);
int HwEthInit(void)
{
// lwip_config_tcp(0, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
LwipSetIPTest(1, NULL);
return EOK;
}

View File

@ -76,6 +76,7 @@ static int lwip_netdev_set_addr_info(struct netdev* netdev, ip_addr_t* ip_addr,
netif_set_gw((struct netif*)netdev->user_data, ip_2_ip4(gw));
}
}
return 0;
}
#ifdef LWIP_DNS
@ -92,7 +93,7 @@ static int lwip_netdev_set_dns_server(struct netdev* netdev, uint8_t dns_num, ip
}
#endif
#ifdef LWIP_DHCP
#if LWIP_DHCP
static int lwip_netdev_set_dhcp(struct netdev* netdev, bool is_enabled)
{
netdev_low_level_set_dhcp_status(netdev, is_enabled);
@ -120,7 +121,7 @@ static const struct netdev_ops lwip_netdev_ops = {
#ifdef LWIP_DNS
.set_dns_server = lwip_netdev_set_dns_server,
#endif
#ifdef LWIP_DHCP
#if LWIP_DHCP
.set_dhcp = lwip_netdev_set_dhcp,
#endif
.set_default = lwip_netdev_set_default,
@ -179,9 +180,9 @@ int lwip_netdev_add(struct netif* lwip_netif)
netdev->ops = &lwip_netdev_ops;
netdev->hwaddr_len = lwip_netif->hwaddr_len;
memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
netdev->ip_addr = lwip_netif->ip_addr;
netdev->gw = lwip_netif->gw;
netdev->netmask = lwip_netif->netmask;
netdev->ip_addr = &lwip_netif->ip_addr;
netdev->gw = &lwip_netif->gw;
netdev->netmask = &lwip_netif->netmask;
return result;
}

View File

@ -1,4 +1,4 @@
# SRC_FILES := socket.c connect_w5500.c w5500.c wizchip_conf.c spi_interface.c wiz_ping.c connect_w5500_test.c wiz_iperf.c
SRC_FILES := socket.c connect_w5500.c w5500.c wizchip_conf.c spi_interface.c wiz_ping.c connect_w5500_test.c w5x00_lwip.c wiz_iperf.c
SRC_FILES := socket.c connect_w5500.c w5500.c wizchip_conf.c spi_interface.c w5x00_lwip.c
include $(KERNEL_ROOT)/compiler.mk

View File

@ -328,8 +328,12 @@ int HwWiznetInit(void)
setSHAR(wiz_mac);
ctlwizchip(CW_RESET_PHY, 0);
network_init();
wiz_interrupt_init(0, wiz_irq_handler);
network_init();
setSn_RXBUF_SIZE(0, 16);
setSn_TXBUF_SIZE(0, 16);
#define SOCK_ANY_PORT_NUM 0xC000
@ -349,7 +353,5 @@ int HwWiznetInit(void)
}
}
network_init();
return EOK;
}

View File

@ -152,6 +152,9 @@ static uint32 SpiDrvConfigure(void *drv, struct BusConfigureInfo *configure_info
static uint32 SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg)
{
#define WRITE_BUF_SIZE 1600
static uint32_t write_buf[4 * WRITE_BUF_SIZE] = { 0 };
SpiDeviceParam *dev_param = (SpiDeviceParam *)(spi_dev->haldev.private_data);
uint8 device_id = dev_param->spi_slave_param->spi_slave_id;
@ -184,10 +187,15 @@ static uint32 SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDataStan
dmac_set_single_mode(dev_param->spi_dma_param->spi_dmac_txchannel, &dummy, (void *)(&spi_instance[device_master_id]->dr[0]), DMAC_ADDR_NOCHANGE, DMAC_ADDR_NOCHANGE,
DMAC_MSIZE_4, DMAC_TRANS_WIDTH_32, spi_datacfg->length);
} else {
if (spi_datacfg->length > WRITE_BUF_SIZE) {
tx_buff = x_malloc(spi_datacfg->length * 4);
if (!tx_buff) {
goto transfer_done;
}
} else {
tx_buff = write_buf;
}
for (i = 0; i < spi_datacfg->length; i++) {
tx_buff[i] = ((uint8_t *)spi_datacfg->tx_buff)[i];
}
@ -202,7 +210,7 @@ static uint32 SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDataStan
spi_instance[device_master_id]->ssienr = 0x00;
transfer_done:
if (tx_buff != NULL) {
if (tx_buff != NULL && spi_datacfg->length > WRITE_BUF_SIZE) {
x_free(tx_buff);
}
}
@ -219,6 +227,9 @@ static uint32 SpiWriteData(struct SpiHardwareDevice *spi_dev, struct SpiDataStan
static uint32 SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStandard *spi_datacfg)
{
#define READ_BUF_SIZE 1600
static uint32_t read_buf[4 * READ_BUF_SIZE] = { 0 };
SpiDeviceParam *dev_param = (SpiDeviceParam *)(spi_dev->haldev.private_data);
uint32 spi_read_length = 0;;
@ -251,11 +262,14 @@ static uint32 SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStand
dmac_set_single_mode(dev_param->spi_dma_param->spi_dmac_rxchannel, (void *)(&spi_instance[device_master_id]->dr[0]), &dummy, DMAC_ADDR_NOCHANGE, DMAC_ADDR_NOCHANGE,
DMAC_MSIZE_1, DMAC_TRANS_WIDTH_32, spi_datacfg->length);
} else {
if (spi_datacfg->length > READ_BUF_SIZE) {
rx_buff = x_calloc(spi_datacfg->length * 4, 1);
if(!rx_buff)
{
if (!rx_buff) {
goto transfer_done;
}
} else {
rx_buff = read_buf;
}
dmac_set_single_mode(dev_param->spi_dma_param->spi_dmac_rxchannel, (void *)(&spi_instance[device_master_id]->dr[0]), rx_buff, DMAC_ADDR_NOCHANGE, DMAC_ADDR_INCREMENT,
DMAC_MSIZE_1, DMAC_TRANS_WIDTH_32, spi_datacfg->length);
@ -274,7 +288,7 @@ static uint32 SpiReadData(struct SpiHardwareDevice *spi_dev, struct SpiDataStand
}
transfer_done:
if (rx_buff) {
if (rx_buff && spi_datacfg->length > READ_BUF_SIZE) {
x_free(rx_buff);
}
}

View File

@ -76,6 +76,7 @@ static int lwip_netdev_set_addr_info(struct netdev* netdev, ip_addr_t* ip_addr,
netif_set_gw((struct netif*)netdev->user_data, ip_2_ip4(gw));
}
}
return 0;
}
#ifdef LWIP_DNS
@ -92,7 +93,7 @@ static int lwip_netdev_set_dns_server(struct netdev* netdev, uint8_t dns_num, ip
}
#endif
#ifdef LWIP_DHCP
#if LWIP_DHCP
static int lwip_netdev_set_dhcp(struct netdev* netdev, bool is_enabled)
{
netdev_low_level_set_dhcp_status(netdev, is_enabled);
@ -120,7 +121,7 @@ static const struct netdev_ops lwip_netdev_ops = {
#ifdef LWIP_DNS
.set_dns_server = lwip_netdev_set_dns_server,
#endif
#ifdef LWIP_DHCP
#if LWIP_DHCP
.set_dhcp = lwip_netdev_set_dhcp,
#endif
.set_default = lwip_netdev_set_default,
@ -180,9 +181,9 @@ int lwip_netdev_add(struct netif* lwip_netif)
netdev->ops = &lwip_netdev_ops;
netdev->hwaddr_len = lwip_netif->hwaddr_len;
memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
netdev->ip_addr = lwip_netif->ip_addr;
netdev->gw = lwip_netif->gw;
netdev->netmask = lwip_netif->netmask;
netdev->ip_addr = &lwip_netif->ip_addr;
netdev->gw = &lwip_netif->gw;
netdev->netmask = &lwip_netif->netmask;
return result;
}

View File

@ -76,6 +76,7 @@ static int lwip_netdev_set_addr_info(struct netdev* netdev, ip_addr_t* ip_addr,
netif_set_gw((struct netif*)netdev->user_data, ip_2_ip4(gw));
}
}
return 0;
}
#ifdef LWIP_DNS
@ -92,7 +93,7 @@ static int lwip_netdev_set_dns_server(struct netdev* netdev, uint8_t dns_num, ip
}
#endif
#ifdef LWIP_DHCP
#if LWIP_DHCP
static int lwip_netdev_set_dhcp(struct netdev* netdev, bool is_enabled)
{
netdev_low_level_set_dhcp_status(netdev, is_enabled);
@ -120,7 +121,7 @@ static const struct netdev_ops lwip_netdev_ops = {
#ifdef LWIP_DNS
.set_dns_server = lwip_netdev_set_dns_server,
#endif
#ifdef LWIP_DHCP
#if LWIP_DHCP
.set_dhcp = lwip_netdev_set_dhcp,
#endif
.set_default = lwip_netdev_set_default,
@ -180,9 +181,9 @@ int lwip_netdev_add(struct netif* lwip_netif)
netdev->ops = &lwip_netdev_ops;
netdev->hwaddr_len = lwip_netif->hwaddr_len;
memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
netdev->ip_addr = lwip_netif->ip_addr;
netdev->gw = lwip_netif->gw;
netdev->netmask = lwip_netif->netmask;
netdev->ip_addr = &lwip_netif->ip_addr;
netdev->gw = &lwip_netif->gw;
netdev->netmask = &lwip_netif->netmask;
return result;
}

View File

@ -76,6 +76,7 @@ static int lwip_netdev_set_addr_info(struct netdev* netdev, ip_addr_t* ip_addr,
netif_set_gw((struct netif*)netdev->user_data, ip_2_ip4(gw));
}
}
return 0;
}
#ifdef LWIP_DNS
@ -92,7 +93,7 @@ static int lwip_netdev_set_dns_server(struct netdev* netdev, uint8_t dns_num, ip
}
#endif
#ifdef LWIP_DHCP
#if LWIP_DHCP
static int lwip_netdev_set_dhcp(struct netdev* netdev, bool is_enabled)
{
netdev_low_level_set_dhcp_status(netdev, is_enabled);
@ -120,7 +121,7 @@ static const struct netdev_ops lwip_netdev_ops = {
#ifdef LWIP_DNS
.set_dns_server = lwip_netdev_set_dns_server,
#endif
#ifdef LWIP_DHCP
#if LWIP_DHCP
.set_dhcp = lwip_netdev_set_dhcp,
#endif
.set_default = lwip_netdev_set_default,
@ -180,9 +181,9 @@ int lwip_netdev_add(struct netif* lwip_netif)
netdev->ops = &lwip_netdev_ops;
netdev->hwaddr_len = lwip_netif->hwaddr_len;
memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
netdev->ip_addr = lwip_netif->ip_addr;
netdev->gw = lwip_netif->gw;
netdev->netmask = lwip_netif->netmask;
netdev->ip_addr = &lwip_netif->ip_addr;
netdev->gw = &lwip_netif->gw;
netdev->netmask = &lwip_netif->netmask;
return result;
}

View File

@ -15,4 +15,8 @@ ifeq ($(CONFIG_RESOURCES_LWIP), y)
export LINK_LWIP := $(KERNEL_ROOT)/resources/ethernet/LwIP/liblwip.a
endif
ifeq ($(CONFIG_USE_MONGOOSE), y)
export LINK_MONGOOSE := $(KERNEL_ROOT)/../../APP_Framework/Applications/mongoose/mongoose.a
endif
export ARCH = arm

View File

@ -277,10 +277,7 @@ struct pbuf* low_level_input(struct netif* netif)
return p;
}
extern void LwipSetIPTest(int argc, char* argv[]);
int HwEthInit(void)
{
// lwip_config_tcp(0, lwip_ipaddr, lwip_netmask, lwip_gwaddr);
LwipSetIPTest(1, NULL);
return EOK;
}

View File

@ -76,6 +76,7 @@ static int lwip_netdev_set_addr_info(struct netdev* netdev, ip_addr_t* ip_addr,
netif_set_gw((struct netif*)netdev->user_data, ip_2_ip4(gw));
}
}
return 0;
}
#ifdef LWIP_DNS
@ -92,7 +93,7 @@ static int lwip_netdev_set_dns_server(struct netdev* netdev, uint8_t dns_num, ip
}
#endif
#ifdef LWIP_DHCP
#if LWIP_DHCP
static int lwip_netdev_set_dhcp(struct netdev* netdev, bool is_enabled)
{
netdev_low_level_set_dhcp_status(netdev, is_enabled);
@ -120,7 +121,7 @@ static const struct netdev_ops lwip_netdev_ops = {
#ifdef LWIP_DNS
.set_dns_server = lwip_netdev_set_dns_server,
#endif
#ifdef LWIP_DHCP
#if LWIP_DHCP
.set_dhcp = lwip_netdev_set_dhcp,
#endif
.set_default = lwip_netdev_set_default,
@ -183,9 +184,9 @@ int lwip_netdev_add(struct netif* lwip_netif)
netdev->ops = &lwip_netdev_ops;
netdev->hwaddr_len = lwip_netif->hwaddr_len;
memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
netdev->ip_addr = lwip_netif->ip_addr;
netdev->gw = lwip_netif->gw;
netdev->netmask = lwip_netif->netmask;
netdev->ip_addr = &lwip_netif->ip_addr;
netdev->gw = &lwip_netif->gw;
netdev->netmask = &lwip_netif->netmask;
return result;
}

View File

@ -204,7 +204,6 @@ void ethernetif_input(void* netif_arg)
/* Move received packet into a new pbuf */
while (1) {
sys_arch_sem_wait(get_eth_recv_sem(), WAITING_FOREVER);
KPrintf("%s -->\n", netif->name);
while (1) {
p = low_level_input(netif);
#ifndef ETHERNET_LOOPBACK_TEST

View File

@ -113,7 +113,6 @@ void ethernetif_input2(void* netif_arg)
struct pbuf* p = NULL;
for (;;) {
sys_arch_sem_wait(get_eth_recv_sem2(), WAITING_FOREVER);
KPrintf("%s -->\n", netif->name);
sys_mutex_lock(&wiz_trans_mtx);
while (1) {

View File

@ -76,6 +76,7 @@ static int lwip_netdev_set_addr_info(struct netdev* netdev, ip_addr_t* ip_addr,
netif_set_gw((struct netif*)netdev->user_data, ip_2_ip4(gw));
}
}
return 0;
}
#ifdef LWIP_DNS
@ -92,7 +93,7 @@ static int lwip_netdev_set_dns_server(struct netdev* netdev, uint8_t dns_num, ip
}
#endif
#ifdef LWIP_DHCP
#if LWIP_DHCP
static int lwip_netdev_set_dhcp(struct netdev* netdev, bool is_enabled)
{
netdev_low_level_set_dhcp_status(netdev, is_enabled);
@ -120,7 +121,7 @@ static const struct netdev_ops lwip_netdev_ops = {
#ifdef LWIP_DNS
.set_dns_server = lwip_netdev_set_dns_server,
#endif
#ifdef LWIP_DHCP
#if LWIP_DHCP
.set_dhcp = lwip_netdev_set_dhcp,
#endif
.set_default = lwip_netdev_set_default,
@ -180,9 +181,9 @@ int lwip_netdev_add(struct netif* lwip_netif)
netdev->ops = &lwip_netdev_ops;
netdev->hwaddr_len = lwip_netif->hwaddr_len;
memcpy(netdev->hwaddr, lwip_netif->hwaddr, lwip_netif->hwaddr_len);
netdev->ip_addr = lwip_netif->ip_addr;
netdev->gw = lwip_netif->gw;
netdev->netmask = lwip_netif->netmask;
netdev->ip_addr = &lwip_netif->ip_addr;
netdev->gw = &lwip_netif->gw;
netdev->netmask = &lwip_netif->netmask;
return result;
}

View File

@ -2,6 +2,8 @@ ifeq ($(COMPILE_TYPE), COMPILE_MUSL)
SRC_DIR_TEMP := $(MUSL_DIR)
else ifeq ($(COMPILE_TYPE), COMPILE_LWIP)
SRC_DIR_TEMP := $(LWIP_DIR)
else ifeq ($(COMPILE_TYPE), COMPILE_MONGOOSE)
SRC_DIR_TEMP := $(MONGOOSE_DIR)
else
SRC_DIR_TEMP := $(SRC_DIR)
endif
@ -9,6 +11,7 @@ endif
SRC_DIR :=
MUSL_DIR :=
LWIP_DIR :=
MONGOOSE_DIR :=
ifeq ($(USE_APP_INCLUDEPATH), y)
include $(KERNEL_ROOT)/path_app.mk

View File

@ -44,13 +44,14 @@ extern "C" {
#define MSGQUEUE_DEBUG 0
#define FILESYS_DEBUG 0
#define NETDEV_DEBUG 0
#define NETDEV_DEBUG 1
#define WEBNET_DEBUG 0
#define WIZNET_DEBUG 0
#define SYS_KDEBUG_LOG(section, information) \
do { \
if (section) { \
KPrintf("[%s:%d] ", __func__, __LINE__); \
KPrintf information; \
} \
} while (0)

View File

@ -3,7 +3,7 @@ OBJS := $(shell cat make.obj)
$(TARGET): $(OBJS)
@echo ------------------------------------------------
@echo link $(TARGET)
@$(CROSS_COMPILE)g++ -o $@ $($(LINK_FLAGS)) $(OBJS) $(LINK_LWIP) $(LINK_MUSLLIB) $(LIBCC)
@$(CROSS_COMPILE)g++ -o $@ $($(LINK_FLAGS)) $(OBJS) $(LINK_LWIP) $(LINK_MUSLLIB) $(LINK_MONGOOSE) $(LIBCC)
@echo ------------------------------------------------
@$(CROSS_COMPILE)objcopy -O binary $@ XiZi-$(BOARD)$(COMPILE_TYPE).bin
@$(CROSS_COMPILE)objdump -S $@ > XiZi-$(BOARD)$(COMPILE_TYPE).asm

View File

@ -0,0 +1,9 @@
OBJS := $(shell cat make.obj)
$(TARGET): $(OBJS)
@echo ------------------------------------------------
@echo link $(TARGET)
@$(CROSS_COMPILE)ar -r $@ $(OBJS)
@echo ------------------------------------------------
@$(CROSS_COMPILE)objcopy $@ $(TARGET)
@$(CROSS_COMPILE)size $@

View File

@ -640,6 +640,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d)...\n", s));
sock = get_socket(s);
if (!sock) {
KPrintf("sock = get_socket(s);\n");
return -1;
}
@ -655,6 +656,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
sock_set_errno(sock, err_to_errno(err));
}
done_socket(sock);
KPrintf("err = netconn_accept(sock->conn, &newconn);\n");
return -1;
}
LWIP_ASSERT("newconn != NULL", newconn != NULL);
@ -664,6 +666,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
netconn_delete(newconn);
sock_set_errno(sock, ENFILE);
done_socket(sock);
KPrintf("newsock = alloc_socket(newconn, 1);\n");
return -1;
}
LWIP_ASSERT("invalid socket index", (newsock >= LWIP_SOCKET_OFFSET) && (newsock < NUM_SOCKETS + LWIP_SOCKET_OFFSET));
@ -701,6 +704,7 @@ lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen)
free_socket(nsock, 1);
sock_set_errno(sock, err_to_errno(err));
done_socket(sock);
KPrintf("err = netconn_peer(newconn, &naddr, &port);\n");
return -1;
}
@ -1242,6 +1246,8 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags,
if (err != ERR_OK) {
LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom[UDP/RAW](%d): buf == NULL, error is \"%s\"!\n",
s, lwip_strerr(err)));
KPrintf("lwip_recvfrom[UDP/RAW](%d): buf == NULL, error is \"%s\"!\n",
s, lwip_strerr(err));
sock_set_errno(sock, err_to_errno(err));
done_socket(sock);
return -1;

View File

@ -272,13 +272,16 @@ a lot of data that needs to be copied, this should be set high. */
#define MEMP_NUM_PBUF 32
/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One
per active UDP "connection". */
#define MEMP_NUM_UDP_PCB 4
#define MEMP_NUM_UDP_PCB 32
/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP
connections. */
#define MEMP_NUM_TCP_PCB 64
#define MEMP_NUM_TCP_PCB 32
#define MEMP_NUM_RAW_PCB 32
#define MEMP_NUM_REASSDATA 32
#define MEMP_NUM_NETCONN 32
/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP
connections. */
#define MEMP_NUM_TCP_PCB_LISTEN 2
#define MEMP_NUM_TCP_PCB_LISTEN 32
/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP
segments. */
#define MEMP_NUM_TCP_SEG 256
@ -384,12 +387,6 @@ a lot of data that needs to be copied, this should be set high. */
/* ---------- ICMP options ---------- */
#define LWIP_ICMP 1
/* ---------- DHCP options ---------- */
/* Define LWIP_DHCP to 1 if you want DHCP configuration of
interfaces. DHCP is not implemented in lwIP 0.5.1, however, so
turning this on does currently not work. */
#define LWIP_DHCP 1
/* ---------- UDP options ---------- */
#define LWIP_UDP 1
#define UDP_TTL 255
@ -521,7 +518,7 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums
/* ---------- DHCP options ---------- */
/* Define LWIP_DHCP to 1 if you want DHCP configuration of
interfaces. */
#define LWIP_DHCP 1
#define LWIP_DHCP 0
/* 1 if you want to do an ARP check on the offered address
(recommended). */

View File

@ -76,7 +76,7 @@ char lwip_eth0_ipaddr[20] = { 192, 168, 130, 77 };
char lwip_eth0_netmask[20] = { 255, 255, 254, 0 };
char lwip_eth0_gwaddr[20] = { 192, 168, 130, 1 };
char lwip_eth1_ipaddr[20] = { 192, 168, 130, 88 };
char lwip_eth1_ipaddr[20] = { 192, 168, 131, 88 };
char lwip_eth1_netmask[20] = { 255, 255, 254, 0 };
char lwip_eth1_gwaddr[20] = { 192, 168, 130, 1 };
@ -346,7 +346,9 @@ void lwip_config_input(int eport, struct netif* net)
if (eport == 0) {
th_id = sys_thread_new("eth_input", ethernetif_input, net, LWIP_TASK_STACK_SIZE, 30);
} else if (eport == 1) {
#ifdef NETIF_ENET1_INIT_FUNC
th_id = sys_thread_new("eth_input2", ethernetif_input2, net, LWIP_TASK_STACK_SIZE, 30);
#endif
}
}
@ -360,7 +362,6 @@ void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
if (chk_lwip_bit(LWIP_INIT_FLAG)) {
lw_print("lw: [%s] already ...\n", __func__);
return;
}
set_lwip_bit(LWIP_INIT_FLAG);
@ -384,12 +385,13 @@ void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
lw_print("Not Netif driver for Eport 0\n");
return;
#endif
#ifdef NETIF_ENET0_INIT_FUNC
lw_print("Add netif eport 0\n");
netif_add(&gnetif, &net_ipaddr, &net_netmask, &net_gw, eth_cfg, NETIF_ENET0_INIT_FUNC,
tcpip_input);
// netif_set_default(&gnetif);
// netif_set_up(&gnetif);
netif_set_default(&gnetif);
netif_set_up(&gnetif);
lw_print("\r\n************************************************\r\n");
lw_print(" Network Configuration\r\n");
@ -404,6 +406,7 @@ void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
lwip_config_input(enet_port, &gnetif);
is_init_0 = 1;
#endif
} else if (1 == enet_port) {
if (is_init_1 == 1) {
@ -413,11 +416,12 @@ void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
lw_print("Not Netif driver for Eport 1\n");
return;
#endif
#ifdef NETIF_ENET1_INIT_FUNC
lw_print("Add netif eport 1\n");
netif_add(&gnetif2, &net_ipaddr, &net_netmask, &net_gw, eth_cfg, NETIF_ENET1_INIT_FUNC,
tcpip_input);
netif_set_default(&gnetif2);
// netif_set_default(&gnetif2);
netif_set_up(&gnetif2);
lw_print("\r\n************************************************\r\n");
@ -433,5 +437,6 @@ void lwip_config_tcp(uint8_t enet_port, char* ip, char* mask, char* gw)
lwip_config_input(enet_port, &gnetif2);
is_init_1 = 1;
#endif
}
}

View File

@ -228,6 +228,95 @@ ip4_route(const ip4_addr_t *dest)
return netif_default;
}
/**
* Finds the appropriate network interface for a given IP address. It
* searches the list of network interfaces linearly. A match is found
* if the masked IP address of the network interface equals the masked
* IP address given to the function.
*
* @param dest the destination IP address for which to find the route
* @return the netif on which to send to reach dest
*/
struct netif*
ip4_route2(const ip4_addr_t* src, const ip4_addr_t* dest)
{
#if !LWIP_SINGLE_NETIF
struct netif* netif;
LWIP_ASSERT_CORE_LOCKED();
#if LWIP_MULTICAST_TX_OPTIONS
/* Use administratively selected interface for multicast by default */
if (ip4_addr_ismulticast(dest) && ip4_default_multicast_netif) {
return ip4_default_multicast_netif;
}
#endif /* LWIP_MULTICAST_TX_OPTIONS */
/* bug #54569: in case LWIP_SINGLE_NETIF=1 and LWIP_DEBUGF() disabled, the following loop is optimized away */
LWIP_UNUSED_ARG(dest);
/* iterate through netifs */
NETIF_FOREACH(netif)
{
/* is the netif up, does it have a link and a valid address? */
if (netif_is_up(netif) && netif_is_link_up(netif) && !ip4_addr_isany_val(*netif_ip4_addr(netif))) {
/* network mask matches? */
// if (ip4_addr_netcmp(dest, netif_ip4_addr(netif), netif_ip4_netmask(netif))) {
if (ip4_addr_cmp(src, netif_ip4_addr(netif))) {
/* return netif on which to forward IP packet */
return netif;
}
/* gateway matches on a non broadcast interface? (i.e. peer in a point to point interface) */
if (((netif->flags & NETIF_FLAG_BROADCAST) == 0) && ip4_addr_cmp(dest, netif_ip4_gw(netif))) {
/* return netif on which to forward IP packet */
return netif;
}
}
}
#if LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF
/* loopif is disabled, looopback traffic is passed through any netif */
if (ip4_addr_isloopback(dest)) {
/* don't check for link on loopback traffic */
if (netif_default != NULL && netif_is_up(netif_default)) {
return netif_default;
}
/* default netif is not up, just use any netif for loopback traffic */
NETIF_FOREACH(netif)
{
if (netif_is_up(netif)) {
return netif;
}
}
return NULL;
}
#endif /* LWIP_NETIF_LOOPBACK && !LWIP_HAVE_LOOPIF */
#ifdef LWIP_HOOK_IP4_ROUTE_SRC
netif = LWIP_HOOK_IP4_ROUTE_SRC(NULL, dest);
if (netif != NULL) {
return netif;
}
#elif defined(LWIP_HOOK_IP4_ROUTE)
netif = LWIP_HOOK_IP4_ROUTE(dest);
if (netif != NULL) {
return netif;
}
#endif
#endif /* !LWIP_SINGLE_NETIF */
if ((netif_default == NULL) || !netif_is_up(netif_default) || !netif_is_link_up(netif_default) || ip4_addr_isany_val(*netif_ip4_addr(netif_default)) || ip4_addr_isloopback(dest)) {
/* No matching netif found and default netif is not usable.
If this is not good enough for you, use LWIP_HOOK_IP4_ROUTE() */
LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_LEVEL_SERIOUS, ("ip4_route: No route to %" U16_F ".%" U16_F ".%" U16_F ".%" U16_F "\n", ip4_addr1_16(dest), ip4_addr2_16(dest), ip4_addr3_16(dest), ip4_addr4_16(dest)));
IP_STATS_INC(ip.rterr);
MIB2_STATS_INC(mib2.ipoutnoroutes);
return NULL;
}
return netif_default;
}
#if IP_FORWARD
/**
* Determine whether an IP address is in a reserved set of addresses

View File

@ -63,39 +63,41 @@ extern "C" {
#define ip_init() /* Compatibility define, no init needed. */
struct netif *ip4_route(const ip4_addr_t *dest);
struct netif* ip4_route2(const ip4_addr_t* src, const ip4_addr_t* dest);
#if LWIP_IPV4_SRC_ROUTING
struct netif *ip4_route_src(const ip4_addr_t *src, const ip4_addr_t *dest);
struct netif* ip4_route_src(const ip4_addr_t* src, const ip4_addr_t* dest);
#else /* LWIP_IPV4_SRC_ROUTING */
#define ip4_route_src(src, dest) ip4_route(dest)
// #define ip4_route_src(src, dest) ip4_route(dest)
#define ip4_route_src(src, dest) ip4_route2(src, dest)
#endif /* LWIP_IPV4_SRC_ROUTING */
err_t ip4_input(struct pbuf *p, struct netif *inp);
err_t ip4_output(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
err_t ip4_input(struct pbuf* p, struct netif* inp);
err_t ip4_output(struct pbuf* p, const ip4_addr_t* src, const ip4_addr_t* dest,
u8_t ttl, u8_t tos, u8_t proto);
err_t ip4_output_if(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif *netif);
err_t ip4_output_if_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif *netif);
err_t ip4_output_if(struct pbuf* p, const ip4_addr_t* src, const ip4_addr_t* dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif* netif);
err_t ip4_output_if_src(struct pbuf* p, const ip4_addr_t* src, const ip4_addr_t* dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif* netif);
#if LWIP_NETIF_USE_HINTS
err_t ip4_output_hinted(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif_hint *netif_hint);
err_t ip4_output_hinted(struct pbuf* p, const ip4_addr_t* src, const ip4_addr_t* dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif_hint* netif_hint);
#endif /* LWIP_NETIF_USE_HINTS */
#if IP_OPTIONS_SEND
err_t ip4_output_if_opt(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
err_t ip4_output_if_opt(struct pbuf* p, const ip4_addr_t* src, const ip4_addr_t* dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif* netif, void* ip_options,
u16_t optlen);
err_t ip4_output_if_opt_src(struct pbuf *p, const ip4_addr_t *src, const ip4_addr_t *dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif *netif, void *ip_options,
err_t ip4_output_if_opt_src(struct pbuf* p, const ip4_addr_t* src, const ip4_addr_t* dest,
u8_t ttl, u8_t tos, u8_t proto, struct netif* netif, void* ip_options,
u16_t optlen);
#endif /* IP_OPTIONS_SEND */
#if LWIP_MULTICAST_TX_OPTIONS
void ip4_set_default_multicast_netif(struct netif* default_multicast_netif);
void ip4_set_default_multicast_netif(struct netif* default_multicast_netif);
#endif /* LWIP_MULTICAST_TX_OPTIONS */
#define ip4_netif_get_local_ip(netif) (((netif) != NULL) ? netif_ip_addr4(netif) : NULL)
#if IP_DEBUG
void ip4_debug_print(struct pbuf *p);
void ip4_debug_print(struct pbuf* p);
#else
#define ip4_debug_print(p)
#endif /* IP_DEBUG */

View File

@ -521,7 +521,7 @@
* (only needed if you use the sequential API, like api_lib.c)
*/
#if !defined MEMP_NUM_NETBUF || defined __DOXYGEN__
#define MEMP_NUM_NETBUF 2
#define MEMP_NUM_NETBUF 8
#endif
/**
@ -529,7 +529,7 @@
* (only needed if you use the sequential API, like api_lib.c)
*/
#if !defined MEMP_NUM_NETCONN || defined __DOXYGEN__
#define MEMP_NUM_NETCONN 4
#define MEMP_NUM_NETCONN 8
#endif
/**
@ -564,7 +564,7 @@
* (before freeing the corresponding memory using lwip_freeaddrinfo()).
*/
#if !defined MEMP_NUM_NETDB || defined __DOXYGEN__
#define MEMP_NUM_NETDB 1
#define MEMP_NUM_NETDB 2
#endif
/**
@ -572,7 +572,7 @@
* if DNS_LOCAL_HOSTLIST_IS_DYNAMIC==1.
*/
#if !defined MEMP_NUM_LOCALHOSTLIST || defined __DOXYGEN__
#define MEMP_NUM_LOCALHOSTLIST 1
#define MEMP_NUM_LOCALHOSTLIST 2
#endif
/**

View File

@ -25,102 +25,145 @@
#include <sys_arch.h>
#include <xs_kdbg.h>
#include <netdev.h>
#include "argparse.h"
#include "inet.h"
#include "netdev.h"
/******************************************************************************/
uint8_t enet_id = 0;
static void LwipSetIPTask(void* param)
enum NETWORK_ACTIVE_E {
LWIP_ACTIVE = 'e',
LWIP_ACTIVE_ALL = 'a',
};
void LwipNetworkActive(int argc, char* argv[])
{
static char usage_info[] = "select a eport to start.";
static char program_info[] = "Active lwip network function.";
static const char* const net_active_usages[] = {
"LwipNetworkActive -e 0",
"LwipNetworkActive -e 1",
"LwipNetworkActive -a",
};
int eport = -1;
bool all = false;
bool is_help = false;
struct argparse_option options[] = {
OPT_HELP(&is_help),
OPT_INTEGER(LWIP_ACTIVE, "eport", &eport, "eport to start network.", NULL, 0, 0),
OPT_BIT(LWIP_ACTIVE_ALL, "all", &all, "start network at both eport 0 and 1.", NULL, true, 0),
OPT_END(),
};
struct argparse argparse;
argparse_init(&argparse, options, net_active_usages, 0);
argparse_describe(&argparse, usage_info, program_info);
argc = argparse_parse(&argparse, argc, (const char**)argv);
if (is_help) {
return;
}
if (all) {
lwip_config_tcp(0, lwip_eth0_ipaddr, lwip_eth0_netmask, lwip_eth0_gwaddr);
lwip_config_tcp(1, lwip_eth1_ipaddr, lwip_eth1_netmask, lwip_eth1_gwaddr);
}
void LwipSetIPTest(int argc, char* argv[])
{
if (argc >= 4) {
printf("lw: [%s] ip %s mask %s gw %s netport %s\n", __func__, argv[1], argv[2], argv[3], argv[4]);
sscanf(argv[1], "%hhd.%hhd.%hhd.%hhd", &lwip_ipaddr[0], &lwip_ipaddr[1], &lwip_ipaddr[2], &lwip_ipaddr[3]);
sscanf(argv[2], "%hhd.%hhd.%hhd.%hhd", &lwip_netmask[0], &lwip_netmask[1], &lwip_netmask[2], &lwip_netmask[3]);
sscanf(argv[3], "%hhd.%hhd.%hhd.%hhd", &lwip_gwaddr[0], &lwip_gwaddr[1], &lwip_gwaddr[2], &lwip_gwaddr[3]);
sscanf(argv[4], "%hhd", &enet_id);
if (0 == enet_id) {
printf("save eth0 info\n");
memcpy(lwip_eth0_ipaddr, lwip_ipaddr, 20);
memcpy(lwip_eth0_netmask, lwip_netmask, 20);
memcpy(lwip_eth0_gwaddr, lwip_gwaddr, 20);
} else if (1 == enet_id) {
printf("save eth1 info\n");
memcpy(lwip_eth1_ipaddr, lwip_ipaddr, 20);
memcpy(lwip_eth1_netmask, lwip_netmask, 20);
memcpy(lwip_eth1_gwaddr, lwip_gwaddr, 20);
return;
}
} else if (argc == 2) {
printf("lw: [%s] set eth0 ipaddr %s \n", __func__, argv[1]);
sscanf(argv[1], "%hhd.%hhd.%hhd.%hhd", &lwip_ipaddr[0], &lwip_ipaddr[1], &lwip_ipaddr[2], &lwip_ipaddr[3]);
memcpy(lwip_eth0_ipaddr, lwip_ipaddr, strlen(lwip_ipaddr));
}
// sys_thread_new("SET ip address", LwipSetIPTask, &enet_id, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
LwipSetIPTask(&enet_id);
}
if (eport != 0 && eport != 1) {
printf("[%s] Err: Support only eport 0 and eport 1.\n", __func__);
}
if (eport == 0) {
lwip_config_tcp(0, lwip_eth0_ipaddr, lwip_eth0_netmask, lwip_eth0_gwaddr);
} else if (eport == 1) {
lwip_config_tcp(1, lwip_eth1_ipaddr, lwip_eth1_netmask, lwip_eth1_gwaddr);
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(5),
setip, LwipSetIPTest, setip[IP][Netmask][Gateway][port]);
LwipNetworkActive, LwipNetworkActive, start lwip);
void LwipShowIPTask(int argc, char* argv[])
enum NETWORK_CONFIG_E {
NETWORK_DEV = 'd',
NETWORK_IP = 'i',
NETWORK_NM = 'n',
NETWORK_GW = 'g',
};
void LwipSetNetwork(int argc, char* argv[])
{
#ifdef configMAC_ADDR
char mac_addr0[] = configMAC_ADDR;
#endif
static char usage_info[] = "config network information.";
static char program_info[] = "set network ip, netmask, gateway";
static const char* const net_set_usages[] = {
"LwipSetNetwork -d [dev] -i [ip]",
"LwipSetNetwork -d [dev] -n [netmask]",
"LwipSetNetwork -d [dev] -g [gw]",
"LwipSetNetwork -d [dev] -i [ip] -n [netmask] -g [gw]",
};
// find default netdev
struct netdev* netdev = netdev_get_by_name("en\0");
char* dev_ptr = NULL;
char* ip_ptr = NULL;
char* nm_ptr = NULL;
char* gw_ptr = NULL;
bool is_help = false;
struct argparse_option options[] = {
OPT_HELP(&is_help),
OPT_GROUP("Param Options"),
OPT_STRING(NETWORK_DEV, "dev", &dev_ptr, "netdev", NULL, 0, 0),
OPT_STRING(NETWORK_IP, "ip", &ip_ptr, "change ip", NULL, 0, 0),
OPT_STRING(NETWORK_NM, "nm", &nm_ptr, "change netmask", NULL, 0, 0),
OPT_STRING(NETWORK_GW, "gw", &gw_ptr, "change gateway", NULL, 0, 0),
OPT_END(),
};
struct argparse argparse;
argparse_init(&argparse, options, net_set_usages, 0);
argparse_describe(&argparse, usage_info, program_info);
argc = argparse_parse(&argparse, argc, (const char**)argv);
/* help task */
if (is_help) {
return;
}
if (dev_ptr == NULL) {
printf("[%s] Err: must given a netdev name.\n", __func__);
return;
}
struct netdev* netdev = netdev_get_by_name(dev_ptr);
if (netdev == NULL) {
lw_notice("[%s] Netdev not found by name en\n");
struct netdev* default_netdev = NETDEV_DEFAULT;
printf("[%s] Err: Netdev not found by name: %s\n", __func__, dev_ptr);
return;
}
lw_notice("\r\n************************************************\r\n");
lw_notice(" Network Configuration\r\n");
lw_notice("************************************************\r\n");
// lw_notice(" ETH0 IPv4 Address : %u.%u.%u.%u\r\n", ((u8_t*)&lwip_eth0_ipaddr)[0], ((u8_t*)&lwip_eth0_ipaddr)[1],
// ((u8_t*)&lwip_eth0_ipaddr)[2], ((u8_t*)&lwip_eth0_ipaddr)[3]);
// lw_notice(" ETH0 IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t*)&lwip_eth0_netmask)[0], ((u8_t*)&lwip_eth0_netmask)[1],
// ((u8_t*)&lwip_eth0_netmask)[2], ((u8_t*)&lwip_eth0_netmask)[3]);
// lw_notice(" ETH0 IPv4 Gateway : %u.%u.%u.%u\r\n", ((u8_t*)&lwip_gwaddr)[0], ((u8_t*)&lwip_eth0_gwaddr)[1],
// ((u8_t*)&lwip_eth0_gwaddr)[2], ((u8_t*)&lwip_eth0_gwaddr)[3]);
// #ifdef configMAC_ADDR
// lw_notice(" ETH0 MAC Address : %x:%x:%x:%x:%x:%x\r\n", mac_addr0[0], mac_addr0[1], mac_addr0[2],
// mac_addr0[3], mac_addr0[4], mac_addr0[5]);
// #endif
lw_notice(" ETH0 IPv4 Address : %u.%u.%u.%u\r\n", ((u8_t*)&lwip_eth0_ipaddr)[0], ((u8_t*)&lwip_eth0_ipaddr)[1],
((u8_t*)&lwip_eth0_ipaddr)[2], ((u8_t*)&lwip_eth0_ipaddr)[3]);
lw_notice(" ETH0 IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t*)&lwip_eth0_netmask)[0], ((u8_t*)&lwip_eth0_netmask)[1],
((u8_t*)&lwip_eth0_netmask)[2], ((u8_t*)&lwip_eth0_netmask)[3]);
lw_notice(" ETH0 IPv4 Gateway : %u.%u.%u.%u\r\n", ((u8_t*)&lwip_gwaddr)[0], ((u8_t*)&lwip_eth0_gwaddr)[1],
((u8_t*)&lwip_eth0_gwaddr)[2], ((u8_t*)&lwip_eth0_gwaddr)[3]);
#ifdef configMAC_ADDR
lw_notice(" ETH0 MAC Address : %x:%x:%x:%x:%x:%x\r\n", mac_addr0[0], mac_addr0[1], mac_addr0[2],
mac_addr0[3], mac_addr0[4], mac_addr0[5]);
#endif
#ifdef BOARD_NET_COUNT
if (BOARD_NET_COUNT > 1) {
char mac_addr1[] = configMAC_ADDR_ETH1;
lw_notice("\r\n");
lw_notice(" ETH1 IPv4 Address : %u.%u.%u.%u\r\n", ((u8_t*)&lwip_eth1_ipaddr)[0], ((u8_t*)&lwip_eth1_ipaddr)[1],
((u8_t*)&lwip_eth1_ipaddr)[2], ((u8_t*)&lwip_eth1_ipaddr)[3]);
lw_notice(" ETH1 IPv4 Subnet mask : %u.%u.%u.%u\r\n", ((u8_t*)&lwip_eth1_netmask)[0], ((u8_t*)&lwip_eth1_netmask)[1],
((u8_t*)&lwip_eth1_netmask)[2], ((u8_t*)&lwip_eth1_netmask)[3]);
lw_notice(" ETH1 IPv4 Gateway : %u.%u.%u.%u\r\n", ((u8_t*)&lwip_eth1_gwaddr)[0], ((u8_t*)&lwip_eth1_gwaddr)[1],
((u8_t*)&lwip_eth1_gwaddr)[2], ((u8_t*)&lwip_eth1_gwaddr)[3]);
lw_notice(" ETH1 MAC Address : %x:%x:%x:%x:%x:%x\r\n", mac_addr1[0], mac_addr1[1], mac_addr1[2],
mac_addr1[3], mac_addr1[4], mac_addr1[5]);
ip_addr_t ipaddr, maskaddr, gwaddr;
if (ip_ptr != NULL) {
inet_aton(ip_ptr, &ipaddr);
if (0 != netdev_set_ipaddr(netdev, &ipaddr)) {
printf("[%s] Err: set ip: %s failed.\n", __func__, ip_ptr);
}
#endif
lw_notice("************************************************\r\n");
}
if (nm_ptr != NULL) {
inet_aton(nm_ptr, &maskaddr);
if (0 != netdev_set_netmask(netdev, &maskaddr)) {
printf("[%s] Err: set netmask: %s failed.\n", __func__, nm_ptr);
}
}
if (gw_ptr != NULL) {
inet_aton(gw_ptr, &gwaddr);
if (0 != netdev_set_gw(netdev, &gwaddr)) {
printf("[%s] Err: set gateway: %s failed.\n", __func__, gw_ptr);
}
}
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(11),
LwipSetNetwork, LwipSetNetwork, config lwip);
void LwipShowNetwork(int argc, char* argv[])
{
extern void netdev_list_dev();
netdev_list_dev();
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(0),
showip, LwipShowIPTask, GetIp[IP][Netmask][Gateway]);
LwipShowNetwork, LwipShowNetwork, show lwip network configuration);

View File

@ -43,8 +43,8 @@ void netdev_low_level_set_ipaddr(struct netdev* netdev, const ip_addr_t* ip_addr
{
CHECK(ip_addr);
if (netdev && ip_addr_cmp(&(netdev->ip_addr), ip_addr) == 0) {
ip_addr_copy(netdev->ip_addr, *ip_addr);
if (netdev && ip_addr_cmp((netdev->ip_addr), ip_addr) == 0) {
ip_addr_copy(*netdev->ip_addr, *ip_addr);
/* execute IP address change callback function */
if (netdev->addr_callback) {
@ -64,8 +64,8 @@ void netdev_low_level_set_netmask(struct netdev* netdev, const ip_addr_t* netmas
{
CHECK(netmask);
if (netdev && ip_addr_cmp(&(netdev->netmask), netmask) == 0) {
ip_addr_copy(netdev->netmask, *netmask);
if (netdev && ip_addr_cmp((netdev->netmask), netmask) == 0) {
ip_addr_copy(*netdev->netmask, *netmask);
/* execute netmask address change callback function */
if (netdev->addr_callback) {
@ -85,8 +85,8 @@ void netdev_low_level_set_gw(struct netdev* netdev, const ip_addr_t* gw)
{
CHECK(gw);
if (netdev && ip_addr_cmp(&(netdev->gw), gw) == 0) {
ip_addr_copy(netdev->gw, *gw);
if (netdev && ip_addr_cmp((netdev->gw), gw) == 0) {
ip_addr_copy(*netdev->gw, *gw);
/* execute gateway address change callback function */
if (netdev->addr_callback) {

View File

@ -277,7 +277,7 @@ struct netdev* netdev_get_by_ipaddr(ip_addr_t* ip_addr)
struct netdev* current_dev = NETDEV_LISTHEAD;
SINGLE_LINKLIST_FOR_EACH_ENTRY(current_dev, &(NETDEV_LISTHEAD->list), list)
{
if (NULL != current_dev && ip_addr_cmp(&(current_dev->ip_addr), ip_addr)) {
if (NULL != current_dev && ip_addr_cmp((current_dev->ip_addr), ip_addr)) {
ENABLE_INTERRUPT(lock);
return current_dev;
}
@ -325,10 +325,10 @@ struct netdev* netdev_get_by_name(const char* name)
return NULL;
}
struct netdev* netdev_list_dev()
void netdev_list_dev()
{
if (NETDEV_LISTHEAD == NULL) {
return NULL;
return;
}
char ip[IP4ADDR_STRLEN_MAX], netmask[IP4ADDR_STRLEN_MAX], gw[IP4ADDR_STRLEN_MAX], dns[IP4ADDR_STRLEN_MAX];
@ -342,9 +342,9 @@ struct netdev* netdev_list_dev()
continue;
}
strncpy(ip, inet_ntoa(current_dev->ip_addr), IP4ADDR_STRLEN_MAX);
strncpy(netmask, inet_ntoa(current_dev->netmask), IP4ADDR_STRLEN_MAX);
strncpy(gw, inet_ntoa(current_dev->gw), IP4ADDR_STRLEN_MAX);
strncpy(ip, inet_ntoa(*current_dev->ip_addr), IP4ADDR_STRLEN_MAX);
strncpy(netmask, inet_ntoa(*current_dev->netmask), IP4ADDR_STRLEN_MAX);
strncpy(gw, inet_ntoa(*current_dev->gw), IP4ADDR_STRLEN_MAX);
strncpy(dns, inet_ntoa(current_dev->dns_servers[0]), IP4ADDR_STRLEN_MAX);
KPrintf("Netdev %s: ip: %s, mask: %s, gw: %s, dns: %s\n",
current_dev->name,
@ -352,7 +352,7 @@ struct netdev* netdev_list_dev()
}
ENABLE_INTERRUPT(lock);
return NULL;
return;
}
SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(5),
netdev_list, netdev_list_dev, list sys netdev);

View File

@ -65,17 +65,13 @@ int netdev_register(struct netdev* netdev, const char* name, void* user_data)
// set flag mask, assert network is down
uint16_t flag_mask = 0;
flag_mask = NETDEV_FLAG_UP | NETDEV_FLAG_LINK_UP | NETDEV_FLAG_INTERNET_UP | NETDEV_FLAG_DHCP;
flag_mask = NETDEV_FLAG_UP | NETDEV_FLAG_LINK_UP | NETDEV_FLAG_INTERNET_UP;
netdev->flags &= ~flag_mask;
// clear dev setting
ip_addr_set_zero(&(netdev->ip_addr));
ip_addr_set_zero(&(netdev->netmask));
ip_addr_set_zero(&(netdev->gw));
IP_SET_TYPE_VAL(netdev->ip_addr, IPADDR_TYPE_V4);
IP_SET_TYPE_VAL(netdev->netmask, IPADDR_TYPE_V4);
IP_SET_TYPE_VAL(netdev->gw, IPADDR_TYPE_V4);
netdev->ip_addr = NULL;
netdev->netmask = NULL;
netdev->gw = NULL;
#if NETDEV_IPV6
for (index = 0; index < NETDEV_IPV6_NUM_ADDRESSES; index++) {
@ -87,7 +83,6 @@ int netdev_register(struct netdev* netdev, const char* name, void* user_data)
// clear DNS servers
for (uint16_t idx = 0; idx < NETDEV_DNS_SERVERS_NUM; idx++) {
ip_addr_set_zero(&(netdev->dns_servers[idx]));
IP_SET_TYPE_VAL(netdev->ip_addr, IPADDR_TYPE_V4);
}
// clear callback fn
netdev->addr_callback = NULL;

View File

@ -93,9 +93,9 @@ struct netdev {
SysSingleLinklistType list;
char name[NAME_NUM_MAX]; /* network interface device name */
ip_addr_t ip_addr; /* IP address */
ip_addr_t netmask; /* subnet mask */
ip_addr_t gw; /* gateway */
ip_addr_t* ip_addr; /* IP address */
ip_addr_t* netmask; /* subnet mask */
ip_addr_t* gw; /* gateway */
#if NETDEV_IPV6
ip_addr_t ip6_addr[NETDEV_IPV6_NUM_ADDRESSES]; /* array of IPv6 addresses */
#endif /* NETDEV_IPV6 */