From aaceb82386951e4be3491a8ba6b7b86e13ae1fbc Mon Sep 17 00:00:00 2001 From: songyanguang <345810377@qq.com> Date: Tue, 13 Aug 2024 14:43:22 +0800 Subject: [PATCH] New IPC interface, lwip sends data to rndis --- .../XiZi_AIoT/services/drivers/usb/Makefile | 2 +- .../services/drivers/usb/components/usb.mk | 1 + .../services/drivers/usb/usb_service/Makefile | 10 ++++ .../drivers/usb/usb_service/rndis_service.c | 13 ++++++ .../drivers/usb/usb_service/rndis_service.h | 12 +++++ .../drivers/usb/usb_service/usb_host.c | 43 ++++++++++++++--- .../drivers/usb/usb_service/usb_host.h | 7 ++- .../services/net/net_server/Makefile | 6 ++- .../services/net/net_server/arch/Makefile | 1 + .../services/net/net_server/arch/ethernetif.c | 46 ++++++++++++++++++- .../XiZi_AIoT/services/net/net_server/lwip.mk | 3 +- 11 files changed, 129 insertions(+), 15 deletions(-) create mode 100644 Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/rndis_service.c create mode 100644 Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/rndis_service.h diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/Makefile b/Ubiquitous/XiZi_AIoT/services/drivers/usb/Makefile index 888b55863..99287c6c1 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/usb/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/Makefile @@ -1,3 +1,3 @@ -SRC_DIR := components +SRC_DIR := components usb_service include $(KERNEL_ROOT)/compiler.mk diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/usb.mk b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/usb.mk index ba38d3725..32fa1fc2c 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/usb.mk +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/usb.mk @@ -36,6 +36,7 @@ INC_DIR = -I$(KERNEL_ROOT)/services/drivers/usb/ \ -I$(KERNEL_ROOT)/services/drivers/usb/components/osal \ -I$(KERNEL_ROOT)/services/drivers/usb/components/port \ -I$(KERNEL_ROOT)/services/drivers/usb/components/port/xhci \ + -I$(KERNEL_ROOT)/services/drivers/usb/usb_service \ -I$(KERNEL_ROOT)/services//semaphore \ -I$(KERNEL_ROOT)/services/lib/ipc \ -I$(KERNEL_ROOT)/services/lib/memory \ diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/Makefile b/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/Makefile index e69de29bb..27b53be78 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/Makefile @@ -0,0 +1,10 @@ +include $(KERNEL_ROOT)/services/drivers/usb/components/usb.mk + +objs = usb_host.o + +all: ${objs} + @echo "generate $^" + +%.o: %.c + @echo "cc $^" + @${cc} ${cflags} ${c_useropts} ${INC_DIR} -o $@ -c $^ diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/rndis_service.c b/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/rndis_service.c new file mode 100644 index 000000000..24bd7e7fa --- /dev/null +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/rndis_service.c @@ -0,0 +1,13 @@ +#include "libipc.h" +#include "rndis_service.h" + +IPC_INTERFACE(Ipc_usbh_rndis_eth_tx, 2, dataptr, tot_len, *(size_t *)tot_len, sizeof(size_t)); +int ipc_usbh_rndis_eth_tx(struct Session* session, void *dataptr, size_t tot_len){ + return IPC_CALL(Ipc_usbh_rndis_eth_tx)(session, dataptr, &tot_len); +} + +IPC_INTERFACE(Ipc_usbh_rndis_eth_control, 3, cmd, args, len, sizeof(int), *(size_t *)len, sizeof(size_t)); +int ipc_usbh_rndis_eth_control(struct Session* session, int cmd, void *args, size_t len){ + return IPC_CALL(Ipc_usbh_rndis_eth_control)(session, &cmd, args, &len); +} + diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/rndis_service.h b/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/rndis_service.h new file mode 100644 index 000000000..c9c2dcf34 --- /dev/null +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/rndis_service.h @@ -0,0 +1,12 @@ +#ifndef RNDIS_SERVICE_H_ +#define RNDIS_SERVICE_H_ + +#include "libipc.h" + +IPC_SERVICES(IpcRndisServer, Ipc_usbh_rndis_eth_tx, Ipc_usbh_rndis_eth_control); + +int ipc_usbh_rndis_eth_tx(struct Session* session, void *dataptr, size_t tot_len); +int ipc_usbh_rndis_eth_control(struct Session* session, int cmd, void *args, size_t len); + +#endif + diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/usb_host.c b/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/usb_host.c index b46384fc7..902455a1a 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/usb_host.c +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/usb_host.c @@ -1,6 +1,37 @@ -#include "usb_host.h" - - -int main(){ - return 0; -} +#include "usb_host.h" +#include "usyscall.h" +#include "libipc.h" +#include "rndis_service.h" + +/* IPC rndis server */ +int IPC_DO_SERVE_FUNC(Ipc_usbh_rndis_eth_tx)(void *dataptr, size_t *tot_len){ + return usbh_rndis_eth_tx(dataptr, *tot_len); +} + +int IPC_DO_SERVE_FUNC(Ipc_usbh_rndis_eth_control)(int *cmd, void *args, size_t *len){ + return usbh_rndis_eth_control(*cmd, args, *len); +} + +IPC_SERVER_INTERFACE(Ipc_usbh_rndis_eth_tx, 2); +IPC_SERVER_INTERFACE(Ipc_usbh_rndis_eth_control, 3); + +IPC_SERVER_REGISTER_INTERFACES(IpcRndisServer, 2, Ipc_usbh_rndis_eth_tx, Ipc_usbh_rndis_eth_control); + +int ipc_rndis_server_init(void) +{ + if (register_server("RndisServer") < 0) { + printf("register server name: %s failed.\n", "RndisServer"); + return -1; + } + ipc_server_loop(&IpcRndisServer); + + return 0; +} + + +/* usb main*/ +int main(){ + ipc_rndis_server_init(); + return 0; +} + diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/usb_host.h b/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/usb_host.h index e6e9f9efb..904cb4abe 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/usb_host.h +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/usb_host.h @@ -1,9 +1,8 @@ #ifndef USB_HOST_H_ #define USB_HOST_H_ +#include - - - - +int usbh_rndis_eth_tx(void *dataptr, size_t tot_len); +int usbh_rndis_eth_control(int cmd, void *args, size_t len); #endif diff --git a/Ubiquitous/XiZi_AIoT/services/net/net_server/Makefile b/Ubiquitous/XiZi_AIoT/services/net/net_server/Makefile index aeade75e7..498b63d53 100644 --- a/Ubiquitous/XiZi_AIoT/services/net/net_server/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/net/net_server/Makefile @@ -53,10 +53,12 @@ arch_usyscall = $(KERNEL_ROOT)/services/app/arch_usyscall.o session = $(KERNEL_ROOT)/services/app/session.o libipc = $(KERNEL_ROOT)/services/app/libipc.o libsem = $(KERNEL_ROOT)/services/app/libsemaphore.o +librndis = $(KERNEL_ROOT)/services/net/net_server/rndis_service.o + lwip: COMPILER lwip_server.o | bin - @${ld} ${user_ldflags} -e main -o $@ ${sys} ${api} ${core} ${ipv4} ${netif} lwip_server.o ${libserial} ${printf} ${libmem} ${usyscall} ${arch_usyscall} ${session} ${libipc} ${libsem} ${board_specs} + @${ld} ${user_ldflags} -e main -o $@ ${librndis} ${sys} ${api} ${core} ${ipv4} ${netif} lwip_server.o ${libserial} ${printf} ${libmem} ${usyscall} ${arch_usyscall} ${session} ${libipc} ${libsem} ${board_specs} @${objdump} -S $@ > $@.asm - @$(ar) -r liblwip.a ${sys} ${api} ${core} ${ipv4} ${netif} + @$(ar) -r liblwip.a ${librndis} ${sys} ${api} ${core} ${ipv4} ${netif} @mv *.o bin @mv $@ $(KERNEL_ROOT)/services/app @mv $@.asm $(KERNEL_ROOT)/services/app diff --git a/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/Makefile b/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/Makefile index 1a5320eda..6b1c4e9b6 100644 --- a/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/Makefile @@ -1,5 +1,6 @@ include $(KERNEL_ROOT)/services/net/net_server/lwip.mk objs += sys_arch.o ethernetif.o +objs += $(KERNEL_ROOT)/services/drivers/usb/usb_service/rndis_service.o arch: ${objs} diff --git a/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/ethernetif.c b/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/ethernetif.c index 91d0c91fa..5973e0cd1 100644 --- a/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/ethernetif.c +++ b/Ubiquitous/XiZi_AIoT/services/net/net_server/arch/ethernetif.c @@ -20,10 +20,15 @@ #include "lwip/ethip6.h" #include "lwip/etharp.h" #include "libserial.h" +#include "rndis_service.h" + /* Define those to better describe your network interface. */ #define IFNAME0 'e' #define IFNAME1 'n' +/* IPC rndis client */ +struct Session *g_session_rndis = NULL; + /** * In this function, the hardware should be initialized. * Called from ethernetif_init(). @@ -80,6 +85,21 @@ void print_packet_data(const char *packet_data, int length) { } } } + +/** + * This function should do the actual transmission of the packet. + * + * @param dataptr pointer to the actual data in the buffer + * @param tot_len the length of this buffer + * @return ERR_OK if the send is success + * any other err_t on error + */ +int usbh_rndis_eth_tx(void *dataptr, size_t tot_len) +{ + struct Session* session = g_session_rndis; + return ipc_usbh_rndis_eth_tx(session, dataptr, tot_len);; +} + /** * This function should do the actual transmission of the packet. The packet is * contained in the pbuf that is passed to the function. This pbuf @@ -104,8 +124,11 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p) #endif pbuf_copy_partial(p, buf, p->tot_len, 0); - + print_packet_data(buf, p->tot_len); + + usbh_rndis_eth_tx(buf, p->tot_len); + return ERR_OK; } @@ -149,6 +172,26 @@ void ethernetif_input(struct netif *netif) } } +/** + * In this function, get session info. + * Called from ethernetif_init(). + * + * @return lwIP error code + */ +int ipc_rndis_client_init(void) +{ + struct Session *session; + + session = mem_malloc(sizeof(struct Session)); + if(connect_session(session, "RndisServer", 4096) < 0) { + printf("connect session failed\n"); + return ERR_IF; + } + g_session_rndis = session; + + return ERR_OK; +} + /** * Should be called at the beginning of the program to set up the * network interface. It calls the function low_level_init() to do the @@ -190,6 +233,7 @@ err_t ethernetif_init(struct netif *netif) /* initialize the hardware */ low_level_init(netif); + ipc_rndis_client_init(); return ERR_OK; } diff --git a/Ubiquitous/XiZi_AIoT/services/net/net_server/lwip.mk b/Ubiquitous/XiZi_AIoT/services/net/net_server/lwip.mk index df9b6bd6e..0dc3e5777 100644 --- a/Ubiquitous/XiZi_AIoT/services/net/net_server/lwip.mk +++ b/Ubiquitous/XiZi_AIoT/services/net/net_server/lwip.mk @@ -41,4 +41,5 @@ INC_DIR = -I$(KERNEL_ROOT)/services/net/libnet \ -I$(KERNEL_ROOT)/services/lib/serial \ -I$(KERNEL_ROOT)/services/lib/usyscall \ -I$(KERNEL_ROOT)/services/boards/$(BOARD) \ - -I$(KERNEL_ROOT)/services/app + -I$(KERNEL_ROOT)/services/app \ + -I$(KERNEL_ROOT)/services/drivers/usb/usb_service