diff options
Diffstat (limited to 'nuttx/net')
-rw-r--r-- | nuttx/net/uip/uip-chksum.c | 11 | ||||
-rw-r--r-- | nuttx/net/uip/uip-icmpping.c | 10 | ||||
-rw-r--r-- | nuttx/net/uip/uip-icmpsend.c | 6 |
3 files changed, 24 insertions, 3 deletions
diff --git a/nuttx/net/uip/uip-chksum.c b/nuttx/net/uip/uip-chksum.c index 50602f481..479ebc797 100644 --- a/nuttx/net/uip/uip-chksum.c +++ b/nuttx/net/uip/uip-chksum.c @@ -55,6 +55,7 @@ ****************************************************************************/ #define BUF ((struct uip_ip_hdr *)&dev->d_buf[UIP_LLH_LEN]) +#define ICMPBUF ((struct uip_icmpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) /**************************************************************************** * Private Data @@ -224,6 +225,16 @@ uint16 uip_udpchksum(struct uip_driver_s *dev) return upper_layer_chksum(dev, UIP_PROTO_UDP); } #endif + +/* Calculate the checksum of the ICMP message */ + +#if defined(CONFIG_NET_ICMP) && defined(CONFIG_NET_ICMP_PING) +uint16 uip_icmpchksum(struct uip_driver_s *dev) +{ + return uip_chksum((uint16*)&ICMPBUF->type, dev->d_sndlen); +} +#endif + #endif /* UIP_ARCH_CHKSUM */ #endif /* CONFIG_NET */ diff --git a/nuttx/net/uip/uip-icmpping.c b/nuttx/net/uip/uip-icmpping.c index e62209dcd..5bc9b68b0 100644 --- a/nuttx/net/uip/uip-icmpping.c +++ b/nuttx/net/uip/uip-icmpping.c @@ -58,6 +58,7 @@ ****************************************************************************/ #define ICMPBUF ((struct uip_icmpip_hdr *)&dev->d_buf[UIP_LLH_LEN]) +#define ICMPDAT &dev->d_buf[UIP_LLH_LEN + sizeof(struct uip_icmpip_hdr)] /* Allocate a new ICMP data callback */ @@ -79,6 +80,7 @@ struct icmp_ping_s uip_ipaddr_t png_addr; /* The peer to be ping'ed */ uint16 png_id; /* Used to match requests with replies */ uint16 png_seqno; /* IN: seqno to send; OUT: seqno recieved */ + uint16 png_datlen; /* The length of data to send in the ECHO request */ boolean png_sent; /* TRUE... the PING request has been sent */ }; @@ -211,13 +213,14 @@ static uint16 ping_interrupt(struct uip_driver_s *dev, void *conn, #else # error "IPv6 ECHO Request not implemented" #endif + memset(ICMPDAT, 0, pstate->png_datlen); /* Send the ICMP echo request. Note that d_sndlen is set to * the size of the ICMP payload and does not include the size * of the ICMP header. */ - dev->d_sndlen= 4; + dev->d_sndlen= pstate->png_datlen + 4; uip_icmpsend(dev, &pstate->png_addr); pstate->png_sent = TRUE; return flags; @@ -283,7 +286,7 @@ end_wait: * ****************************************************************************/ -int uip_ping(uip_ipaddr_t addr, uint16 id, uint16 seqno, int dsecs) +int uip_ping(uip_ipaddr_t addr, uint16 id, uint16 seqno, uint16 datalen, int dsecs) { struct icmp_ping_s state; irqstate_t save; @@ -296,6 +299,7 @@ int uip_ping(uip_ipaddr_t addr, uint16 id, uint16 seqno, int dsecs) state.png_addr = addr; /* Address of the peer to be ping'ed */ state.png_id = id; /* The ID to use in the ECHO request */ state.png_seqno = seqno; /* The seqno to use int the ECHO request */ + state.png_datlen = datalen; /* The length of data to send in the ECHO request */ state.png_sent = FALSE; /* ECHO request not yet sent */ save = irqsave(); @@ -303,7 +307,7 @@ int uip_ping(uip_ipaddr_t addr, uint16 id, uint16 seqno, int dsecs) /* Set up the callback */ - state.png_cb = uip_icmpcallbackalloc(); + state.png_cb = uip_icmpcallbackalloc(); if (state.png_cb) { state.png_cb->flags = UIP_POLL|UIP_ECHOREPLY; diff --git a/nuttx/net/uip/uip-icmpsend.c b/nuttx/net/uip/uip-icmpsend.c index 90c2a6c6e..c0076b0e8 100644 --- a/nuttx/net/uip/uip-icmpsend.c +++ b/nuttx/net/uip/uip-icmpsend.c @@ -98,6 +98,12 @@ void uip_icmpsend(struct uip_driver_s *dev, uip_ipaddr_t *destaddr) dev->d_len = dev->d_sndlen + UIP_IPICMPH_LEN; + /* The total size of the data (for ICMP checksum calculation) includes + * the size of the ICMP header + */ + + dev->d_sndlen += UIP_ICMPH_LEN; + /* Initialize the IP header. Note that for IPv6, the IP length field * does not include the IPv6 IP header length. */ |