This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi, I have a project that uses lwip without RTOS, I based my project on this example: http://dev.ti.com/tirex/explore/node?node=AOoA7W7yQeZdRcpVGT6w3Q__J4.hfJy__LATEST
The project works fine, but I've tried to add ping support without success. Since there's no a ping example on the Resource Explorer, I used this as a guide:
http://download.savannah.nongnu.org/releases/lwip/ (contrib-2.1.0/apps/ping)
Then I modified my lwipopts.h file: I enabled LWIP_ICMP and LWIP_RAW (see attached file) but no luck.
What I've noticed is that when I ping my dev kit, the programa doesn't enter this if:
Any help would be appreciated. I attached my ping.c file
/* * ping.c * * Created on: 13 may. 2019 * Author: RICHARD */ #include "ping.h" #include "lwip/mem.h" #include "lwip/raw.h" #include "lwip/icmp.h" #include "lwip/netif.h" #include "lwip/sys.h" #include "lwip/timeouts.h" #include "lwip/inet_chksum.h" #include "lwip/prot/ip4.h" #include "lwip/sockets.h" #include "lwip/inet.h" #include <string.h> #ifndef PING_DEBUG #define PING_DEBUG LWIP_DBG_ON #endif /** ping receive timeout - in milliseconds */ #ifndef PING_RCV_TIMEO #define PING_RCV_TIMEO 1000 #endif /** ping delay - in milliseconds */ #ifndef PING_DELAY #define PING_DELAY 1000 #endif /** ping identifier - must fit on a u16_t */ #ifndef PING_ID #define PING_ID 0xAFAF #endif /** ping additional data size to include in the packet */ #ifndef PING_DATA_SIZE #define PING_DATA_SIZE 32 #endif /** ping result action - no default action */ #ifndef PING_RESULT #define PING_RESULT(ping_ok) #endif static const ip_addr_t* ping_target; static u16_t ping_seq_num; static struct raw_pcb *ping_pcb; static void ping_prepare_echo( struct icmp_echo_hdr *iecho, u16_t len) { size_t i; size_t data_len = len - sizeof(struct icmp_echo_hdr); ICMPH_TYPE_SET(iecho, ICMP_ECHO); ICMPH_CODE_SET(iecho, 0); iecho->chksum = 0; iecho->id = PING_ID; iecho->seqno = lwip_htons(++ping_seq_num); /* fill the additional data buffer with some data */ for(i = 0; i < data_len; i++) { ((char*)iecho)[sizeof(struct icmp_echo_hdr) + i] = (char)i; } iecho->chksum = inet_chksum(iecho, len); } static void ping_send(struct raw_pcb *raw, const ip_addr_t *addr) { struct pbuf *p; struct icmp_echo_hdr *iecho; size_t ping_size = sizeof(struct icmp_echo_hdr) + PING_DATA_SIZE; LWIP_DEBUGF( PING_DEBUG, ("ping: send ")); ip_addr_debug_print(PING_DEBUG, addr); LWIP_DEBUGF( PING_DEBUG, ("\n")); LWIP_ASSERT("ping_size <= 0xffff", ping_size <= 0xffff); p = pbuf_alloc(PBUF_IP, (u16_t)ping_size, PBUF_RAM); if (!p) { return; } if ((p->len == p->tot_len) && (p->next == NULL)) { iecho = (struct icmp_echo_hdr *)p->payload; ping_prepare_echo(iecho, (u16_t)ping_size); raw_sendto(raw, p, addr); #ifdef LWIP_DEBUG ping_time = sys_now(); #endif /* LWIP_DEBUG */ } pbuf_free(p); } static void ping_timeout(void *arg) { struct raw_pcb *pcb = (struct raw_pcb*)arg; LWIP_ASSERT("ping_timeout: no pcb given!", pcb != NULL); ping_send(pcb, ping_target); sys_timeout(PING_DELAY, ping_timeout, pcb); } static u8_t ping_recv(void *arg, struct raw_pcb *pcb, struct pbuf *p, const ip_addr_t *addr) { struct icmp_echo_hdr *iecho; LWIP_UNUSED_ARG(arg); LWIP_UNUSED_ARG(pcb); LWIP_UNUSED_ARG(addr); LWIP_ASSERT("p != NULL", p != NULL); if ((p->tot_len >= (PBUF_IP_HLEN + sizeof(struct icmp_echo_hdr))) && pbuf_header(p, -PBUF_IP_HLEN) == 0) { iecho = (struct icmp_echo_hdr *)p->payload; if ((iecho->id == PING_ID) && (iecho->seqno == lwip_htons(ping_seq_num))) { LWIP_DEBUGF( PING_DEBUG, ("ping: recv ")); ip_addr_debug_print(PING_DEBUG, addr); LWIP_DEBUGF( PING_DEBUG, (" %"U32_F" ms\n", (sys_now()-ping_time))); /* do some ping result processing */ PING_RESULT(1); pbuf_free(p); return 1; /* eat the packet */ } /* not eaten, restore original packet */ pbuf_header(p, PBUF_IP_HLEN); } return 0; /* don't eat the packet */ } void ping_raw_init(void){ ping_pcb = raw_new(IP_PROTO_ICMP); LWIP_ASSERT("ping_pcb != NULL", ping_pcb != NULL); raw_recv(ping_pcb, ping_recv, NULL); raw_bind(ping_pcb, IP_ADDR_ANY); sys_timeout(PING_DELAY, ping_timeout, ping_pcb); }
**Attention** This is a public forum