From patchwork Fri Jan 20 00:53:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Hershberger X-Patchwork-Id: 136985 X-Patchwork-Delegate: joe.hershberger@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 833101007D5 for ; Fri, 20 Jan 2012 20:14:05 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BDF85282F1; Fri, 20 Jan 2012 10:11:18 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UoGHzI9OrCM6; Fri, 20 Jan 2012 10:11:17 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 58C1D2842B; Fri, 20 Jan 2012 10:07:58 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7F93C28235 for ; Fri, 20 Jan 2012 01:47:11 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id me72QlIocOpu for ; Fri, 20 Jan 2012 01:47:11 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from spamkiller05.natinst.com (mailserver5.natinst.com [130.164.80.5]) by theia.denx.de (Postfix) with ESMTP id AF05128149 for ; Fri, 20 Jan 2012 01:47:09 +0100 (CET) Received: from mailserv59-us.natinst.com (nb-hsrp-1338.natinst.com [130.164.19.133]) by spamkiller05.natinst.com (8.14.4/8.14.4) with ESMTP id q0JLxcxK018215; Thu, 19 Jan 2012 15:59:38 -0600 Received: from localhost.localdomain ([130.164.14.197]) by mailserv59-us.natinst.com (Lotus Domino Release 8.5.2FP3) with ESMTP id 2012011915590780-509595 ; Thu, 19 Jan 2012 15:59:07 -0600 From: Joe Hershberger To: u-boot@lists.denx.de Date: Thu, 19 Jan 2012 18:53:11 -0600 Message-Id: <1327020811-1538-9-git-send-email-joe.hershberger@ni.com> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: <1327020811-1538-1-git-send-email-joe.hershberger@ni.com> References: <1327020811-1538-1-git-send-email-joe.hershberger@ni.com> X-MIMETrack: Itemize by SMTP Server on MailServ59-US/AUS/H/NIC(Release 8.5.2FP3|July 10, 2011) at 01/19/2012 03:59:07 PM, Serialize by Router on MailServ59-US/AUS/H/NIC(Release 8.5.2FP3|July 10, 2011) at 01/19/2012 03:59:08 PM, Serialize complete at 01/19/2012 03:59:08 PM X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.6.7361, 1.0.211, 0.0.0000 definitions=2012-01-19_09:2012-01-19, 2012-01-19, 1970-01-01 signatures=0 X-Mailman-Approved-At: Fri, 20 Jan 2012 10:07:24 +0100 Cc: Joe Hershberger Subject: [U-Boot] [PATCH 08/28] net: Move RARP receive logic out of net.c X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Signed-off-by: Joe Hershberger Cc: Joe Hershberger Cc: Wolfgang Denk Acked-by: Simon Glass Acked-by: Mike Frysinger --- net/net.c | 25 +------------------------ net/rarp.c | 38 +++++++++++++++++++++++++++----------- net/rarp.h | 1 + 3 files changed, 29 insertions(+), 35 deletions(-) diff --git a/net/net.c b/net/net.c index c2fbcb5..fdc1ebe 100644 --- a/net/net.c +++ b/net/net.c @@ -857,9 +857,6 @@ NetReceive(volatile uchar *inpkt, int len) { Ethernet_t *et; IP_t *ip; -#ifdef CONFIG_CMD_RARP - ARP_t *arp; -#endif IPaddr_t tmp; IPaddr_t src_ip; int x; @@ -964,27 +961,7 @@ NetReceive(volatile uchar *inpkt, int len) #ifdef CONFIG_CMD_RARP case PROT_RARP: - debug("Got RARP\n"); - arp = (ARP_t *)ip; - if (len < ARP_HDR_SIZE) { - printf("bad length %d < %d\n", len, ARP_HDR_SIZE); - return; - } - - if ((ntohs(arp->ar_op) != RARPOP_REPLY) || - (ntohs(arp->ar_hrd) != ARP_ETHER) || - (ntohs(arp->ar_pro) != PROT_IP) || - (arp->ar_hln != 6) || (arp->ar_pln != 4)) { - - puts("invalid RARP header\n"); - } else { - NetCopyIP(&NetOurIP, &arp->ar_data[16]); - if (NetServerIP == 0) - NetCopyIP(&NetServerIP, &arp->ar_data[6]); - memcpy(NetServerEther, &arp->ar_data[0], 6); - - (*packetHandler)(0, 0, 0, 0, 0); - } + RarpReceive(ip, len); break; #endif case PROT_IP: diff --git a/net/rarp.c b/net/rarp.c index 5a813a2..761560c 100644 --- a/net/rarp.c +++ b/net/rarp.c @@ -36,18 +36,37 @@ # define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT) #endif - int RarpTry; /* * Handle a RARP received packet. */ -static void -RarpHandler(uchar *dummi0, unsigned dummi1, IPaddr_t sip, unsigned dummi2, - unsigned dummi3) +void +RarpReceive(IP_t *ip, unsigned len) { - debug("Got good RARP\n"); - net_auto_load(); + ARP_t *arp; + + debug("Got RARP\n"); + arp = (ARP_t *)ip; + if (len < ARP_HDR_SIZE) { + printf("bad length %d < %d\n", len, ARP_HDR_SIZE); + return; + } + + if ((ntohs(arp->ar_op) != RARPOP_REPLY) || + (ntohs(arp->ar_hrd) != ARP_ETHER) || + (ntohs(arp->ar_pro) != PROT_IP) || + (arp->ar_hln != 6) || (arp->ar_pln != 4)) { + + puts("invalid RARP header\n"); + } else { + NetCopyIP(&NetOurIP, &arp->ar_data[16]); + if (NetServerIP == 0) + NetCopyIP(&NetServerIP, &arp->ar_data[6]); + memcpy(NetServerEther, &arp->ar_data[0], 6); + debug("Got good RARP\n"); + net_auto_load(); + } } @@ -70,7 +89,6 @@ RarpTimeout(void) void RarpRequest(void) { - int i; uchar *pkt; ARP_t *rarp; @@ -90,12 +108,10 @@ RarpRequest(void) memcpy(&rarp->ar_data[6], &NetOurIP, 4); /* source IP addr */ /* dest ET addr = source ET addr ??*/ memcpy(&rarp->ar_data[10], NetOurEther, 6); - /* dest. IP addr set to broadcast */ - for (i = 0; i <= 3; i++) - rarp->ar_data[16 + i] = 0xff; + /* dest IP addr set to broadcast */ + memset(&rarp->ar_data[16], 0xff, 4); NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE); NetSetTimeout(TIMEOUT, RarpTimeout); - NetSetHandler(RarpHandler); } diff --git a/net/rarp.h b/net/rarp.h index 4e92d80..0d728dc 100644 --- a/net/rarp.h +++ b/net/rarp.h @@ -37,6 +37,7 @@ extern int RarpTry; +extern void RarpReceive(IP_t *ip, unsigned len); extern void RarpRequest(void); /* Send a RARP request */ /**********************************************************************/