forked from xuos/xiuos
Support double lwip eport, use mongoose.a
This commit is contained in:
@@ -640,7 +640,8 @@ 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) {
|
||||
return -1;
|
||||
KPrintf("sock = get_socket(s);\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* wait for a new connection */
|
||||
@@ -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;
|
||||
|
||||
@@ -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). */
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
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_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);
|
||||
#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,
|
||||
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,
|
||||
u16_t optlen);
|
||||
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,
|
||||
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 */
|
||||
|
||||
@@ -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
|
||||
|
||||
/**
|
||||
@@ -538,7 +538,7 @@
|
||||
* In that case, you need one per thread calling lwip_select.)
|
||||
*/
|
||||
#if !defined MEMP_NUM_SELECT_CB || defined __DOXYGEN__
|
||||
#define MEMP_NUM_SELECT_CB 4
|
||||
#define MEMP_NUM_SELECT_CB 4
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -547,7 +547,7 @@
|
||||
* (only needed if you use tcpip.c)
|
||||
*/
|
||||
#if !defined MEMP_NUM_TCPIP_MSG_API || defined __DOXYGEN__
|
||||
#define MEMP_NUM_TCPIP_MSG_API 8
|
||||
#define MEMP_NUM_TCPIP_MSG_API 8
|
||||
#endif
|
||||
|
||||
/**
|
||||
@@ -556,7 +556,7 @@
|
||||
* (only needed if you use tcpip.c)
|
||||
*/
|
||||
#if !defined MEMP_NUM_TCPIP_MSG_INPKT || defined __DOXYGEN__
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT 8
|
||||
#define MEMP_NUM_TCPIP_MSG_INPKT 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
|
||||
|
||||
/**
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
enum NETWORK_ACTIVE_E {
|
||||
LWIP_ACTIVE = 'e',
|
||||
LWIP_ACTIVE_ALL = 'a',
|
||||
};
|
||||
|
||||
void LwipSetIPTest(int argc, char* argv[])
|
||||
void LwipNetworkActive(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);
|
||||
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",
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
} 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));
|
||||
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;
|
||||
}
|
||||
// sys_thread_new("SET ip address", LwipSetIPTask, &enet_id, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||
LwipSetIPTask(&enet_id);
|
||||
}
|
||||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user