public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot-Users] [PATCH] net - Support ping reply when processing net-loop
@ 2007-03-06  7:20 Ed Swarthout
  0 siblings, 0 replies; 8+ messages in thread
From: Ed Swarthout @ 2007-03-06  7:20 UTC (permalink / raw)
  To: u-boot

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp).  This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>

---

This version does not add unused variable i.

 net/net.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/net/net.c b/net/net.c
index 1d1c98f..2df52dc 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1424,6 +1424,29 @@ NetReceive(volatile uchar * inpkt, int len)
 				/* XXX point to ip packet */
 				(*packetHandler)((uchar *)ip, 0, 0, 0);
 				return;
+
+			case ICMP_ECHO_REQUEST:
+			{
+				int rlen = ETHER_HDR_SIZE + len;
+#ifdef ET_DEBUG
+				printf ("Got ICMP ECHO REQUEST, return %d bytes \n",rlen);
+#endif
+				memcpy (&et->et_dest[0], &et->et_src[0], 6);
+				memcpy (&et->et_src[ 0], NetOurEther, 6);
+
+				ip->ip_sum = 0;
+				ip->ip_off = 0;
+				NetCopyIP((void*)&ip->ip_dst, &ip->ip_src);
+				NetCopyIP((void*)&ip->ip_src, &NetOurIP);
+				ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP >> 1);
+
+				icmph->type = ICMP_ECHO_REPLY;
+				icmph->checksum = 0;
+				icmph->checksum = ~NetCksum((uchar *)icmph,
+							    (len - IP_HDR_SIZE_NO_UDP) >> 1);
+				(void) eth_send((uchar *)et, rlen);
+				return;
+			}
 #endif
 			default:
 				return;
-- 
1.5.0.2.279.g4808

^ permalink raw reply related	[flat|nested] 8+ messages in thread
* [U-Boot-Users] [PATCH] net - Support ping reply when processing net-loop
@ 2007-03-06  5:33 Ed Swarthout
  2007-03-06 15:56 ` Ben Warren
  0 siblings, 1 reply; 8+ messages in thread
From: Ed Swarthout @ 2007-03-06  5:33 UTC (permalink / raw)
  To: u-boot

Add ICMP_ECHO_REQUEST packet support by responding with a ICMP_ECHO_REPLY.

This permits the ping command to test the phy interface when the phy
is put in loopback mode (typically by setting register 0 bit 14).

It also allows the port to respond to an external ping when u-boot is
processing some other net command (such as tftp).  This is useful when
tftp appears to hang.

Signed-off-by: Ed Swarthout <Ed.Swarthout@freescale.com>
---
 net/net.c |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/net/net.c b/net/net.c
index 1d1c98f..3294380 100644
--- a/net/net.c
+++ b/net/net.c
@@ -1424,6 +1424,30 @@ NetReceive(volatile uchar * inpkt, int len)
 				/* XXX point to ip packet */
 				(*packetHandler)((uchar *)ip, 0, 0, 0);
 				return;
+
+			case ICMP_ECHO_REQUEST:
+			{
+				int rlen = ETHER_HDR_SIZE + len;
+				int i;
+#ifdef ET_DEBUG
+				printf ("Got ICMP ECHO REQUEST, return %d bytes \n",rlen);
+#endif
+				memcpy (&et->et_dest[0], &et->et_src[0], 6);
+				memcpy (&et->et_src[ 0], NetOurEther, 6);
+
+				ip->ip_sum = 0;
+				ip->ip_off = 0;
+				NetCopyIP((void*)&ip->ip_dst, &ip->ip_src);
+				NetCopyIP((void*)&ip->ip_src, &NetOurIP);
+				ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP >> 1);
+
+				icmph->type = ICMP_ECHO_REPLY;
+				icmph->checksum = 0;
+				icmph->checksum = ~NetCksum((uchar *)icmph,
+							    (len - IP_HDR_SIZE_NO_UDP) >> 1);
+				(void) eth_send((uchar *)et, rlen);
+				return;
+			}
 #endif
 			default:
 				return;
-- 
1.5.0.2.279.g4808

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2007-03-07 18:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-06  7:20 [U-Boot-Users] [PATCH] net - Support ping reply when processing net-loop Ed Swarthout
  -- strict thread matches above, loose matches on Subject: below --
2007-03-06  5:33 Ed Swarthout
2007-03-06 15:56 ` Ben Warren
2007-03-07  6:12   ` Ed Swarthout
2007-03-07 14:51     ` Ben Warren
2007-03-07 15:09       ` Wolfgang Denk
2007-03-07 18:14       ` Ed Swarthout
2007-03-07 18:31         ` Ben Warren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox