diff --git a/Ubiquitous/XiZi_AIoT/services/app/Makefile b/Ubiquitous/XiZi_AIoT/services/app/Makefile index a93afb4f8..86051c9ff 100644 --- a/Ubiquitous/XiZi_AIoT/services/app/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/app/Makefile @@ -23,6 +23,15 @@ INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell \ -I$(KERNEL_ROOT)/services/lib/usyscall \ -I$(KERNEL_ROOT)/services/fs/libfs \ -I$(KERNEL_ROOT)/services/net/libnet \ + -I$(KERNEL_ROOT)/services/net/net_server \ + -I$(KERNEL_ROOT)/services/net/net_server/arch \ + -I$(KERNEL_ROOT)/services/net/net_server/include \ + -I$(KERNEL_ROOT)/services/net/net_server/include/lwip \ + -I$(KERNEL_ROOT)/services/net/net_server/include/lwip/apps \ + -I$(KERNEL_ROOT)/services/net/net_server/include/lwip/priv \ + -I$(KERNEL_ROOT)/services/net/net_server/include/lwip/prot \ + -I$(KERNEL_ROOT)/services/net/net_server/include/netif \ + -I$(KERNEL_ROOT)/services/net/net_server/include/compat \ -I$(KERNEL_ROOT)/services/semaphore \ -I$(KERNEL_ROOT)/services/boards/$(BOARD) \ -I$(KERNEL_ROOT)/services/app diff --git a/Ubiquitous/XiZi_AIoT/services/app/test_net.c b/Ubiquitous/XiZi_AIoT/services/app/test_net.c index d05b44fc7..1ecca6edb 100644 --- a/Ubiquitous/XiZi_AIoT/services/app/test_net.c +++ b/Ubiquitous/XiZi_AIoT/services/app/test_net.c @@ -16,13 +16,54 @@ #include "lwip_service.h" #include "usyscall.h" +static char udp_ip_str[128] = {0}; +static uint16_t udp_socket_port = 8888; +#define UDP_DEMO_SEND_TIMES 20 + int main(int argc, char* argv[]) { printf("lwip network stack test \n"); + + int cnt = UDP_DEMO_SEND_TIMES; + char send_str[128]; + int fd = -1; + + memset(send_str, 0, sizeof(send_str)); struct Session sess; connect_session(&sess, "LWIPServer", 4096); + fd = ipc_socket(&sess, AF_INET, SOCK_DGRAM, 0); + if(fd < 0) { + printf("Socket error\n"); + return 0; + } + + struct sockaddr_in udp_sock; + udp_sock.sin_family = AF_INET; + udp_sock.sin_port = htons(udp_socket_port); + udp_sock.sin_addr.s_addr = inet_addr(udp_ip_str); + memset(&(udp_sock.sin_zero), 0, sizeof(udp_sock.sin_zero)); + + + + if(ipc_connect(&sess, fd, (struct sockaddr *)&udp_sock, sizeof(struct sockaddr)) < 0) { + printf("Unable to connect %s:%d\n", udp_ip_str, udp_socket_port); + ipc_close(&sess,fd); + return 0; + } + + printf("UDP connect %s:%d success, start to send.\n", + udp_ip_str, + udp_socket_port); + + while(cnt --) { + snprintf(send_str, sizeof(send_str), "UDP test package times %d\r\n", cnt); + ipc_send(&sess, fd, send_str, strlen(send_str), 0); + printf("Send UDP msg: %s ", send_str); + } + + ipc_close(&sess,fd); free_session(&sess); diff --git a/Ubiquitous/XiZi_AIoT/services/net/libnet/Makefile b/Ubiquitous/XiZi_AIoT/services/net/libnet/Makefile index 513229930..31e958b8d 100644 --- a/Ubiquitous/XiZi_AIoT/services/net/libnet/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/net/libnet/Makefile @@ -16,6 +16,15 @@ objdump = ${toolchain}objdump c_useropts = -O2 INC_DIR = -I$(KERNEL_ROOT)/services/net/libnet \ + -I$(KERNEL_ROOT)/services/net/net_server \ + -I$(KERNEL_ROOT)/services/net/net_server/arch \ + -I$(KERNEL_ROOT)/services/net/net_server/include \ + -I$(KERNEL_ROOT)/services/net/net_server/include/lwip \ + -I$(KERNEL_ROOT)/services/net/net_server/include/lwip/apps \ + -I$(KERNEL_ROOT)/services/net/net_server/include/lwip/priv \ + -I$(KERNEL_ROOT)/services/net/net_server/include/lwip/prot \ + -I$(KERNEL_ROOT)/services/net/net_server/include/netif \ + -I$(KERNEL_ROOT)/services/net/net_server/include/compat \ -I$(KERNEL_ROOT)/services/lib/ipc \ -I$(KERNEL_ROOT)/services/lib/memory \ -I$(KERNEL_ROOT)/services/lib/serial \ diff --git a/Ubiquitous/XiZi_AIoT/services/net/net_server/Makefile b/Ubiquitous/XiZi_AIoT/services/net/net_server/Makefile index e429bbfa3..67f7a17e8 100644 --- a/Ubiquitous/XiZi_AIoT/services/net/net_server/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/net/net_server/Makefile @@ -43,7 +43,7 @@ ipv4 = autoip.o \ netif = bridgeif.o \ ethernet.o \ zepif.o -sys = sys_arch.o +sys = sys_arch.o ethernetif.o libserial = $(KERNEL_ROOT)/services/app/libserial.o printf = $(KERNEL_ROOT)/services/app/printf.o diff --git a/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/Makefile b/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/Makefile index 655032886..1a5320eda 100644 --- a/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/Makefile @@ -1,5 +1,5 @@ include $(KERNEL_ROOT)/services/net/net_server/lwip.mk -objs += sys_arch.o +objs += sys_arch.o ethernetif.o arch: ${objs} diff --git a/Ubiquitous/XiZi_AIoT/services/net/console_eth_driver/ethernetif.c b/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/ethernetif.c similarity index 90% rename from Ubiquitous/XiZi_AIoT/services/net/console_eth_driver/ethernetif.c rename to Ubiquitous/XiZi_AIoT/services/net/net_server/arch/ethernetif.c index 93e721963..8a2fb4d6b 100644 --- a/Ubiquitous/XiZi_AIoT/services/net/console_eth_driver/ethernetif.c +++ b/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/ethernetif.c @@ -31,15 +31,14 @@ * @param netif the already initialized lwip network interface structure * for this ethernetif */ -static void -low_level_init(struct netif *netif) +static void low_level_init(struct netif *netif) { #if LWIP_ARP || LWIP_ETHERNET - /* set MAC hardware address length */ - netif->hwaddr_len = ETH_HWADDR_LEN; + /* set MAC hardware address length */ + netif->hwaddr_len = ETH_HWADDR_LEN; - /* set MAC hardware address */ + /* set MAC hardware address */ netif->hwaddr[0] = 0x02; netif->hwaddr[1] = 0x12; netif->hwaddr[2] = 0x34; @@ -77,8 +76,7 @@ low_level_init(struct netif *netif) * dropped because of memory failure (except for the TCP timers). */ -static err_t -low_level_output(struct netif *netif, struct pbuf *p) +static err_t low_level_output(struct netif *netif, struct pbuf *p) { char buf[1518]; #if ETH_PAD_SIZE @@ -101,9 +99,7 @@ low_level_output(struct netif *netif, struct pbuf *p) */ static struct pbuf* low_level_input(struct netif *netif) { - struct pbuf *p, *q; - - + struct pbuf *p=NULL, *q=NULL; return p; } @@ -116,8 +112,7 @@ static struct pbuf* low_level_input(struct netif *netif) * * @param netif the lwip network interface structure for this ethernetif */ -static void -ethernetif_input(struct netif *netif) +void ethernetif_input(struct netif *netif) { struct ethernetif *ethernetif; struct eth_hdr *ethhdr; @@ -150,8 +145,7 @@ ethernetif_input(struct netif *netif) * ERR_MEM if private data couldn't be allocated * any other err_t on error */ -err_t -ethernetif_init(struct netif *netif) +err_t ethernetif_init(struct netif *netif) { LWIP_ASSERT("netif != NULL", (netif != NULL)); diff --git a/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/ethernetif.h b/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/ethernetif.h new file mode 100644 index 000000000..98a576b0a --- /dev/null +++ b/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/ethernetif.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2020 AIIT XUOS Lab + * XiUOS is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +#ifndef ETHERNETIF_H +#define ETHERNETIF_H + +#include "lwip/err.h" + +#define NETIF_ENET_INIT_FUNC ethernetif_init + +err_t ethernetif_init(struct netif *netif); +void ethernetif_input(struct netif *netif); + +#endif diff --git a/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/sys_arch.c b/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/sys_arch.c index 87c1b6591..f77de8396 100644 --- a/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/sys_arch.c +++ b/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/sys_arch.c @@ -30,6 +30,8 @@ #include "usyscall.h" #endif +#include "ethernetif.h" + #define SYS_THREAD_MAX 4 static char sem_server_name[] = "DefaultSemaphoreServer"; diff --git a/Ubiquitous/XiZi_AIoT/services/net/net_server/lwip_server.c b/Ubiquitous/XiZi_AIoT/services/net/net_server/lwip_server.c index 4664d81c5..12757e45d 100644 --- a/Ubiquitous/XiZi_AIoT/services/net/net_server/lwip_server.c +++ b/Ubiquitous/XiZi_AIoT/services/net/net_server/lwip_server.c @@ -36,6 +36,9 @@ int IPC_DO_SERVE_FUNC(Ipc_connect)(int* s, const struct sockaddr* name, socklen_ return connect(*s, name, *namelen); } +int IPC_DO_SERVE_FUNC(Ipc_listen)(int* s, int* backlog){ + return listen(*s, *backlog); +} // int serve_accept(struct Session* session, int *s, struct sockaddr *addr, socklen_t *addrlen) { // session_finish_handle(session, accept(*s, addr, addrlen)); // exit(0);