complie and debug test_net

This commit is contained in:
lr 2024-05-23 11:26:36 +08:00
parent dced598cbf
commit 2147d92121
9 changed files with 229 additions and 22 deletions

View File

@ -108,7 +108,7 @@ test_priority: test_priority.o libserial.o printf.o usyscall.o arch_usyscall.o l
@${objdump} -S $@ > $@.asm @${objdump} -S $@ > $@.asm
test_net: test_net.o lwip_service.o libipc.o session.o libserial.o printf.o usyscall.o arch_usyscall.o libmem.o test_net: test_net.o lwip_service.o libipc.o session.o libserial.o printf.o usyscall.o arch_usyscall.o libmem.o
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs} @${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs} -llwip -L$(KERNEL_ROOT)/services/net/net_server
@${objdump} -S $@ > $@.asm @${objdump} -S $@ > $@.asm
%.o: %.c %.o: %.c

View File

@ -33,19 +33,23 @@ int main(int argc, char* argv[])
struct Session sess; struct Session sess;
connect_session(&sess, "LWIPServer", 4096); connect_session(&sess, "LWIPServer", 4096);
printf("%s %d\n", __func__, __LINE__);
fd = ipc_socket(&sess, AF_INET, SOCK_DGRAM, 0); fd = ipc_socket(&sess, AF_INET, SOCK_DGRAM, 0);
if(fd < 0) { if(fd < 0) {
printf("Socket error\n"); printf("Socket error\n");
return 0; return 0;
} }
printf("%s %d\n", __func__, __LINE__);
struct sockaddr_in udp_sock; struct sockaddr_in udp_sock;
udp_sock.sin_family = AF_INET; udp_sock.sin_family = AF_INET;
udp_sock.sin_port = htons(udp_socket_port); udp_sock.sin_port = htons(udp_socket_port);
udp_sock.sin_addr.s_addr = inet_addr(udp_ip_str); udp_sock.sin_addr.s_addr = inet_addr(udp_ip_str);
memset(&(udp_sock.sin_zero), 0, sizeof(udp_sock.sin_zero)); memset(&(udp_sock.sin_zero), 0, sizeof(udp_sock.sin_zero));
printf("%s %d\n", __func__, __LINE__);
if(ipc_connect(&sess, fd, (struct sockaddr *)&udp_sock, sizeof(struct sockaddr)) < 0) { 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); printf("Unable to connect %s:%d\n", udp_ip_str, udp_socket_port);
@ -53,6 +57,8 @@ int main(int argc, char* argv[])
return 0; return 0;
} }
printf("%s %d\n", __func__, __LINE__);
printf("UDP connect %s:%d success, start to send.\n", printf("UDP connect %s:%d success, start to send.\n",
udp_ip_str, udp_ip_str,
udp_socket_port); udp_socket_port);

View File

@ -18,12 +18,12 @@ int ipc_socket(struct Session* session, int domain, int type, int protocol){
} }
IPC_INTERFACE(Ipc_bind, 3, s, name, namelen, sizeof(int), sizeof(struct sockaddr), sizeof(socklen_t)); IPC_INTERFACE(Ipc_bind, 3, s, name, namelen, sizeof(int), sizeof(struct sockaddr), sizeof(socklen_t));
int ipc_bind(struct Session* session, int s, const struct sockaddr *name, socklen_t namelen){ int ipc_bind(struct Session* session, int s, struct sockaddr *name, socklen_t namelen){
return IPC_CALL(Ipc_bind)(session, &s, name, &namelen); return IPC_CALL(Ipc_bind)(session, &s, name, &namelen);
} }
IPC_INTERFACE(Ipc_connect, 3, s, name, namelen, sizeof(int), sizeof(struct sockaddr), sizeof(socklen_t)); IPC_INTERFACE(Ipc_connect, 3, s, name, namelen, sizeof(int), sizeof(struct sockaddr), sizeof(socklen_t));
int ipc_connect(struct Session* session, int s, const struct sockaddr *name, socklen_t namelen){ int ipc_connect(struct Session* session, int s, struct sockaddr *name, socklen_t namelen){
return IPC_CALL(Ipc_connect)(session, &s, name, &namelen); return IPC_CALL(Ipc_connect)(session, &s, name, &namelen);
} }
@ -53,17 +53,17 @@ ssize_t ipc_recvfrom(struct Session* session, int s, void *mem, size_t len, int
} }
IPC_INTERFACE(Ipc_sendto, 6, s, data, size, flags, to, tolen, sizeof(int), *(size_t *)size, sizeof(size_t), sizeof(int), sizeof(struct sockaddr), sizeof(socklen_t)); IPC_INTERFACE(Ipc_sendto, 6, s, data, size, flags, to, tolen, sizeof(int), *(size_t *)size, sizeof(size_t), sizeof(int), sizeof(struct sockaddr), sizeof(socklen_t));
ssize_t ipc_sendto(struct Session* session, int s, const void *data, size_t size, int flags, const struct sockaddr *to, socklen_t tolen){ ssize_t ipc_sendto(struct Session* session, int s, void *data, size_t size, int flags, struct sockaddr *to, socklen_t tolen){
return IPC_CALL(Ipc_sendto)(session, &s, data, &size, &flags, to, &tolen); return IPC_CALL(Ipc_sendto)(session, &s, data, &size, &flags, to, &tolen);
} }
IPC_INTERFACE(Ipc_send, 4, s, data, size, flags, sizeof(int), *(size_t *)size, sizeof(size_t), sizeof(int)); IPC_INTERFACE(Ipc_send, 4, s, data, size, flags, sizeof(int), *(size_t *)size, sizeof(size_t), sizeof(int));
ssize_t ipc_send(struct Session* session, int s, const void *data, size_t size, int flags){ ssize_t ipc_send(struct Session* session, int s, void *data, size_t size, int flags){
return IPC_CALL(Ipc_send)(session, &s, data, &size, &flags); return IPC_CALL(Ipc_send)(session, &s, data, &size, &flags);
} }
IPC_INTERFACE(Ipc_write, 3, s, data, size, sizeof(int), *(size_t *)size, sizeof(size_t)); IPC_INTERFACE(Ipc_write, 3, s, data, size, sizeof(int), *(size_t *)size, sizeof(size_t));
ssize_t ipc_write(struct Session* session, int s, const void *data, size_t size){ ssize_t ipc_write(struct Session* session, int s, void *data, size_t size){
return IPC_CALL(Ipc_write)(session, &s, data, &size); return IPC_CALL(Ipc_write)(session, &s, data, &size);
} }
@ -73,6 +73,6 @@ int ipc_close(struct Session* session, int s){
} }
IPC_INTERFACE(Ipc_setsockopt, 5, s, level, optname, optval, optlen, sizeof(int), sizeof(int), sizeof(int), *(socklen_t*)optlen, sizeof(socklen_t)); IPC_INTERFACE(Ipc_setsockopt, 5, s, level, optname, optval, optlen, sizeof(int), sizeof(int), sizeof(int), *(socklen_t*)optlen, sizeof(socklen_t));
int ipc_setsockopt(struct Session* session, int s, int level, int optname, const void *optval, socklen_t optlen){ int ipc_setsockopt(struct Session* session, int s, int level, int optname, void *optval, socklen_t optlen){
return IPC_CALL(Ipc_setsockopt)(session, &s, &level, &optname, optval, &optlen); return IPC_CALL(Ipc_setsockopt)(session, &s, &level, &optname, optval, &optlen);
} }

View File

@ -19,10 +19,9 @@ IPC_SERVICES(IpcLWIPServer, Ipc_socket, Ipc_bind,Ipc_connect,Ipc_listen,Ipc_acce
int ipc_socket(struct Session* session, int ipc_socket(struct Session* session,
int domain, int type, int protocol); int domain, int type, int protocol);
int ipc_bind(struct Session* session, int s, int ipc_bind(struct Session* session, int s, struct sockaddr *name, socklen_t namelen);
const struct sockaddr *name, socklen_t namelen);
int ipc_connect(struct Session* session, int s, const struct sockaddr *name, socklen_t namelen); int ipc_connect(struct Session* session, int s, struct sockaddr *name, socklen_t namelen);
int ipc_listen(struct Session* session, int s, int backlog); int ipc_listen(struct Session* session, int s, int backlog);
@ -34,12 +33,12 @@ ssize_t ipc_recv(struct Session* session, int s, void *mem, size_t len, int flag
ssize_t ipc_recvfrom(struct Session* session, int s, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen); ssize_t ipc_recvfrom(struct Session* session, int s, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);
ssize_t ipc_sendto(struct Session* session, int s, const void *data, size_t size, int flags, const struct sockaddr *to, socklen_t tolen); ssize_t ipc_sendto(struct Session* session, int s, void *data, size_t size, int flags, struct sockaddr *to, socklen_t tolen);
ssize_t ipc_send(struct Session* session, int s, const void *data, size_t size, int flags); ssize_t ipc_send(struct Session* session, int s, void *data, size_t size, int flags);
ssize_t ipc_write(struct Session* session, int s, const void *data, size_t size); ssize_t ipc_write(struct Session* session, int s, void *data, size_t size);
int ipc_close(struct Session* session, int s); int ipc_close(struct Session* session, int s);
int ipc_setsockopt(struct Session* session, int s, int level, int optname, const void *optval, socklen_t optlen); int ipc_setsockopt(struct Session* session, int s, int level, int optname, void *optval, socklen_t optlen);

View File

@ -56,6 +56,7 @@ libsem = $(KERNEL_ROOT)/services/app/libsemaphore.o
lwip: COMPILER lwip_server.o | bin 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 $@ ${sys} ${api} ${core} ${ipv4} ${netif} lwip_server.o ${libserial} ${printf} ${libmem} ${usyscall} ${arch_usyscall} ${session} ${libipc} ${libsem} ${board_specs}
@${objdump} -S $@ > $@.asm @${objdump} -S $@ > $@.asm
@$(ar) -r liblwip.a ${sys} ${api} ${core} ${ipv4} ${netif}
@mv *.o bin @mv *.o bin
@mv $@ $(KERNEL_ROOT)/services/app @mv $@ $(KERNEL_ROOT)/services/app
@mv $@.asm $(KERNEL_ROOT)/services/app @mv $@.asm $(KERNEL_ROOT)/services/app

View File

@ -51,7 +51,7 @@ static void low_level_init(struct netif *netif)
netif->mtu = 1500; netif->mtu = 1500;
#if LWIP_ARP #if LWIP_ARP
netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP; netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP ;
#else #else
netif->flags |= NETIF_FLAG_BROADCAST; netif->flags |= NETIF_FLAG_BROADCAST;
#endif /* LWIP_ARP */ #endif /* LWIP_ARP */
@ -60,6 +60,26 @@ static void low_level_init(struct netif *netif)
} }
void print_packet_data(const char *packet_data, int length) {
printf("Packet Data:\n");
for (int i = 0; i < length; ++i) {
printf("%02X ", packet_data[i]); // 打印十六进制值,每个字节两位
if ((i + 1) % 16 == 0 || i == length - 1) { // 每16个字节一行
for (int j = 0; j < 15 - (i % 16); ++j) {
printf(" "); // 打印空格对齐
}
printf("| ");
for (int j = i - (i % 16); j <= i; ++j) {
if (packet_data[j] >= 32 && packet_data[j] <= 126) {
printf("%c", packet_data[j]); // 如果是可打印的ASCII字符打印对应字符
} else {
printf("."); // 否则打印点表示不可打印字符
}
}
printf("\n");
}
}
}
/** /**
* This function should do the actual transmission of the packet. The packet is * 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 * contained in the pbuf that is passed to the function. This pbuf
@ -85,7 +105,7 @@ static err_t low_level_output(struct netif *netif, struct pbuf *p)
pbuf_copy_partial(p, buf, p->tot_len, 0); pbuf_copy_partial(p, buf, p->tot_len, 0);
printf("output %s\n", buf); print_packet_data(buf, p->tot_len);
return ERR_OK; return ERR_OK;
} }
@ -114,12 +134,8 @@ static struct pbuf* low_level_input(struct netif *netif)
*/ */
void ethernetif_input(struct netif *netif) void ethernetif_input(struct netif *netif)
{ {
struct ethernetif *ethernetif;
struct eth_hdr *ethhdr;
struct pbuf *p; struct pbuf *p;
ethernetif = netif->state;
/* move received packet into a new pbuf */ /* move received packet into a new pbuf */
p = low_level_input(netif); p = low_level_input(netif);
/* if no packet could be read, silently ignore this */ /* if no packet could be read, silently ignore this */

View File

@ -223,5 +223,188 @@
---------- Lwip Debug options ---------- ---------- Lwip Debug options ----------
---------------------------------------- ----------------------------------------
*/ */
#ifndef LWIP_DEBUG
#define LWIP_DEBUG 1
#define LWIP_SOCKET_DEBUG
#define LWIP_SOCKETS_DEBUG
#define LWIP_TCPIP_DEBUG
#define LWIP_MEMP_DEBUG
#define LWIP_PBUF_DEBUG
#define LWIP_TCP_INPUT_DEBUG
#define LWIP_TCP_OUTPUT_DEBUG
#define LWIP_NETIF_DEBUG
#define LWIP_ETHARP_DEBUG
#define LWIP_API_MSG_DEBUG
#endif
#ifdef LWIP_DEBUG
#ifdef LWIP_SYS_DEBUG
#define SYS_DEBUG LWIP_DBG_ON
#else
#define SYS_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_ETHARP_DEBUG
#define ETHARP_DEBUG LWIP_DBG_ON
#else
#define ETHARP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_PPP_DEBUG
#define PPP_DEBUG LWIP_DBG_ON
#else
#define PPP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_MEM_DEBUG
#define MEM_DEBUG LWIP_DBG_ON
#else
#define MEM_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_MEMP_DEBUG
#define MEMP_DEBUG LWIP_DBG_ON
#else
#define MEMP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_PBUF_DEBUG
#define PBUF_DEBUG LWIP_DBG_ON
#else
#define PBUF_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_API_LIB_DEBUG
#define API_LIB_DEBUG LWIP_DBG_ON
#else
#define API_LIB_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_API_MSG_DEBUG
#define API_MSG_DEBUG LWIP_DBG_ON
#else
#define API_MSG_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCPIP_DEBUG
#define TCPIP_DEBUG LWIP_DBG_ON
#else
#define TCPIP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_NETIF_DEBUG
#define NETIF_DEBUG LWIP_DBG_ON
#else
#define NETIF_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_SOCKETS_DEBUG
#define SOCKETS_DEBUG LWIP_DBG_ON
#else
#define SOCKETS_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_DNS_DEBUG
#define DNS_DEBUG LWIP_DBG_ON
#else
#define DNS_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_AUTOIP_DEBUG
#define AUTOIP_DEBUG LWIP_DBG_ON
#else
#define AUTOIP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_DHCP_DEBUG
#define DHCP_DEBUG LWIP_DBG_ON
#else
#define DHCP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_IP_DEBUG
#define IP_DEBUG LWIP_DBG_ON
#else
#define IP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_IP_REASS_DEBUG
#define IP_REASS_DEBUG LWIP_DBG_ON
#else
#define IP_REASS_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_ICMP_DEBUG
#define ICMP_DEBUG LWIP_DBG_ON
#else
#define ICMP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_IGMP_DEBUG
#define IGMP_DEBUG LWIP_DBG_ON
#else
#define IGMP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_UDP_DEBUG
#define UDP_DEBUG LWIP_DBG_ON
#else
#define UDP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCP_DEBUG
#define TCP_DEBUG LWIP_DBG_ON
#else
#define TCP_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCP_INPUT_DEBUG
#define TCP_INPUT_DEBUG LWIP_DBG_ON
#else
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCP_OUTPUT_DEBUG
#define TCP_OUTPUT_DEBUG LWIP_DBG_ON
#else
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCP_RTO_DEBUG
#define TCP_RTO_DEBUG LWIP_DBG_ON
#else
#define TCP_RTO_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCP_CWND_DEBUG
#define TCP_CWND_DEBUG LWIP_DBG_ON
#else
#define TCP_CWND_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCP_WND_DEBUG
#define TCP_WND_DEBUG LWIP_DBG_ON
#else
#define TCP_WND_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCP_FR_DEBUG
#define TCP_FR_DEBUG LWIP_DBG_ON
#else
#define TCP_FR_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCP_QLEN_DEBUG
#define TCP_QLEN_DEBUG LWIP_DBG_ON
#else
#define TCP_QLEN_DEBUG LWIP_DBG_OFF
#endif
#ifdef LWIP_TCP_RST_DEBUG
#define TCP_RST_DEBUG LWIP_DBG_ON
#else
#define TCP_RST_DEBUG LWIP_DBG_OFF
#endif
#endif /* LWIP_DEBUG */
#endif /* LWIP_LWIPOPTS_H */ #endif /* LWIP_LWIPOPTS_H */

View File

@ -46,6 +46,7 @@
#endif #endif
#include "arch/cc.h" #include "arch/cc.h"
#include "libserial.h"
/** /**
* @defgroup compiler_abstraction Compiler/platform abstraction * @defgroup compiler_abstraction Compiler/platform abstraction
@ -78,7 +79,7 @@
* systems, this should be defined to something less resource-consuming. * systems, this should be defined to something less resource-consuming.
*/ */
#ifndef LWIP_PLATFORM_DIAG #ifndef LWIP_PLATFORM_DIAG
#define LWIP_PLATFORM_DIAG(x) do {printf(x);} while(0) #define LWIP_PLATFORM_DIAG(x) do {printf x;} while(0)
// #include <stdio.h> // #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#endif #endif

View File

@ -13,6 +13,7 @@ endif
cc = ${toolchain}gcc cc = ${toolchain}gcc
ld = ${toolchain}g++ ld = ${toolchain}g++
objdump = ${toolchain}objdump objdump = ${toolchain}objdump
ar = ${toolchain}ar
c_useropts = -O2 c_useropts = -O2