diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-09-02 23:04:10 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2008-09-02 23:04:10 +0000 |
commit | 9f60d09c6faaac732a62a188228a88321aad7368 (patch) | |
tree | 4404ee0e25d63abaad5e23b9aa8dce9ed6a9c8e9 /nuttx/net | |
parent | 8a2d54981a1c1ee6563f3444cffc1d2d4784156e (diff) | |
download | px4-nuttx-9f60d09c6faaac732a62a188228a88321aad7368.tar.gz px4-nuttx-9f60d09c6faaac732a62a188228a88321aad7368.tar.bz2 px4-nuttx-9f60d09c6faaac732a62a188228a88321aad7368.zip |
Add NSH ping command
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@870 42af7a65-404d-4744-a932-0658087f49c3
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. */ |