forked from xuos/xiuos
test lwip through udp
This commit is contained in:
parent
43bb298df9
commit
dced598cbf
|
@ -23,6 +23,15 @@ INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell \
|
||||||
-I$(KERNEL_ROOT)/services/lib/usyscall \
|
-I$(KERNEL_ROOT)/services/lib/usyscall \
|
||||||
-I$(KERNEL_ROOT)/services/fs/libfs \
|
-I$(KERNEL_ROOT)/services/fs/libfs \
|
||||||
-I$(KERNEL_ROOT)/services/net/libnet \
|
-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/semaphore \
|
||||||
-I$(KERNEL_ROOT)/services/boards/$(BOARD) \
|
-I$(KERNEL_ROOT)/services/boards/$(BOARD) \
|
||||||
-I$(KERNEL_ROOT)/services/app
|
-I$(KERNEL_ROOT)/services/app
|
||||||
|
|
|
@ -16,13 +16,54 @@
|
||||||
#include "lwip_service.h"
|
#include "lwip_service.h"
|
||||||
#include "usyscall.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[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
printf("lwip network stack test \n");
|
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;
|
struct Session sess;
|
||||||
connect_session(&sess, "LWIPServer", 4096);
|
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);
|
free_session(&sess);
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,15 @@ objdump = ${toolchain}objdump
|
||||||
c_useropts = -O2
|
c_useropts = -O2
|
||||||
|
|
||||||
INC_DIR = -I$(KERNEL_ROOT)/services/net/libnet \
|
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/ipc \
|
||||||
-I$(KERNEL_ROOT)/services/lib/memory \
|
-I$(KERNEL_ROOT)/services/lib/memory \
|
||||||
-I$(KERNEL_ROOT)/services/lib/serial \
|
-I$(KERNEL_ROOT)/services/lib/serial \
|
||||||
|
|
|
@ -43,7 +43,7 @@ ipv4 = autoip.o \
|
||||||
netif = bridgeif.o \
|
netif = bridgeif.o \
|
||||||
ethernet.o \
|
ethernet.o \
|
||||||
zepif.o
|
zepif.o
|
||||||
sys = sys_arch.o
|
sys = sys_arch.o ethernetif.o
|
||||||
|
|
||||||
libserial = $(KERNEL_ROOT)/services/app/libserial.o
|
libserial = $(KERNEL_ROOT)/services/app/libserial.o
|
||||||
printf = $(KERNEL_ROOT)/services/app/printf.o
|
printf = $(KERNEL_ROOT)/services/app/printf.o
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
include $(KERNEL_ROOT)/services/net/net_server/lwip.mk
|
include $(KERNEL_ROOT)/services/net/net_server/lwip.mk
|
||||||
objs += sys_arch.o
|
objs += sys_arch.o ethernetif.o
|
||||||
|
|
||||||
|
|
||||||
arch: ${objs}
|
arch: ${objs}
|
||||||
|
|
|
@ -31,15 +31,14 @@
|
||||||
* @param netif the already initialized lwip network interface structure
|
* @param netif the already initialized lwip network interface structure
|
||||||
* for this ethernetif
|
* for this ethernetif
|
||||||
*/
|
*/
|
||||||
static void
|
static void low_level_init(struct netif *netif)
|
||||||
low_level_init(struct netif *netif)
|
|
||||||
{
|
{
|
||||||
#if LWIP_ARP || LWIP_ETHERNET
|
#if LWIP_ARP || LWIP_ETHERNET
|
||||||
|
|
||||||
/* set MAC hardware address length */
|
/* set MAC hardware address length */
|
||||||
netif->hwaddr_len = ETH_HWADDR_LEN;
|
netif->hwaddr_len = ETH_HWADDR_LEN;
|
||||||
|
|
||||||
/* set MAC hardware address */
|
/* set MAC hardware address */
|
||||||
netif->hwaddr[0] = 0x02;
|
netif->hwaddr[0] = 0x02;
|
||||||
netif->hwaddr[1] = 0x12;
|
netif->hwaddr[1] = 0x12;
|
||||||
netif->hwaddr[2] = 0x34;
|
netif->hwaddr[2] = 0x34;
|
||||||
|
@ -77,8 +76,7 @@ low_level_init(struct netif *netif)
|
||||||
* dropped because of memory failure (except for the TCP timers).
|
* dropped because of memory failure (except for the TCP timers).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static err_t
|
static err_t low_level_output(struct netif *netif, struct pbuf *p)
|
||||||
low_level_output(struct netif *netif, struct pbuf *p)
|
|
||||||
{
|
{
|
||||||
char buf[1518];
|
char buf[1518];
|
||||||
#if ETH_PAD_SIZE
|
#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)
|
static struct pbuf* low_level_input(struct netif *netif)
|
||||||
{
|
{
|
||||||
struct pbuf *p, *q;
|
struct pbuf *p=NULL, *q=NULL;
|
||||||
|
|
||||||
|
|
||||||
return p;
|
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
|
* @param netif the lwip network interface structure for this ethernetif
|
||||||
*/
|
*/
|
||||||
static void
|
void ethernetif_input(struct netif *netif)
|
||||||
ethernetif_input(struct netif *netif)
|
|
||||||
{
|
{
|
||||||
struct ethernetif *ethernetif;
|
struct ethernetif *ethernetif;
|
||||||
struct eth_hdr *ethhdr;
|
struct eth_hdr *ethhdr;
|
||||||
|
@ -150,8 +145,7 @@ ethernetif_input(struct netif *netif)
|
||||||
* ERR_MEM if private data couldn't be allocated
|
* ERR_MEM if private data couldn't be allocated
|
||||||
* any other err_t on error
|
* any other err_t on error
|
||||||
*/
|
*/
|
||||||
err_t
|
err_t ethernetif_init(struct netif *netif)
|
||||||
ethernetif_init(struct netif *netif)
|
|
||||||
{
|
{
|
||||||
LWIP_ASSERT("netif != NULL", (netif != NULL));
|
LWIP_ASSERT("netif != NULL", (netif != NULL));
|
||||||
|
|
|
@ -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
|
|
@ -30,6 +30,8 @@
|
||||||
#include "usyscall.h"
|
#include "usyscall.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "ethernetif.h"
|
||||||
|
|
||||||
#define SYS_THREAD_MAX 4
|
#define SYS_THREAD_MAX 4
|
||||||
|
|
||||||
static char sem_server_name[] = "DefaultSemaphoreServer";
|
static char sem_server_name[] = "DefaultSemaphoreServer";
|
||||||
|
|
|
@ -36,6 +36,9 @@ int IPC_DO_SERVE_FUNC(Ipc_connect)(int* s, const struct sockaddr* name, socklen_
|
||||||
return connect(*s, name, *namelen);
|
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) {
|
// int serve_accept(struct Session* session, int *s, struct sockaddr *addr, socklen_t *addrlen) {
|
||||||
// session_finish_handle(session, accept(*s, addr, addrlen));
|
// session_finish_handle(session, accept(*s, addr, addrlen));
|
||||||
// exit(0);
|
// exit(0);
|
||||||
|
|
Loading…
Reference in New Issue