3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 #if (CONFIG_COMMANDS & CFG_CMD_NET)
33 #define TIMEOUT 5 /* Seconds before trying ARP again */
34 #ifndef CONFIG_NET_RETRY_COUNT
35 # define TIMEOUT_COUNT 5 /* # of timeouts before giving up */
37 # define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT)
40 static void ArpHandler(uchar *pkt, unsigned dest, unsigned src, unsigned len);
41 static void ArpTimeout(void);
46 * Handle a ARP received packet.
49 ArpHandler(uchar *pkt, unsigned dest, unsigned src, unsigned len)
51 /* Check if the frame is really an ARP reply */
52 if (memcmp (NetServerEther, NetBcastAddr, 6) != 0) {
54 printf("Got good ARP - start TFTP\n");
62 * Timeout on ARP request.
67 if (ArpTry >= TIMEOUT_COUNT) {
68 puts ("\nRetry count exceeded; starting again\n");
71 NetSetTimeout (TIMEOUT * CFG_HZ, ArpTimeout);
84 printf("ARP broadcast %d\n", ++ArpTry);
87 NetSetEther(pkt, NetBcastAddr, PROT_ARP);
88 pkt += ETHER_HDR_SIZE;
92 arp->ar_hrd = htons(ARP_ETHER);
93 arp->ar_pro = htons(PROT_IP);
96 arp->ar_op = htons(ARPOP_REQUEST);
98 memcpy (&arp->ar_data[0], NetOurEther, 6); /* source ET addr */
99 NetWriteIP((uchar*)&arp->ar_data[6], NetOurIP); /* source IP addr */
100 for (i=10; i<16; ++i) {
101 arp->ar_data[i] = 0; /* dest ET addr = 0 */
104 if((NetServerIP & NetOurSubnetMask) != (NetOurIP & NetOurSubnetMask)) {
105 if (NetOurGatewayIP == 0) {
106 puts ("## Warning: gatewayip needed but not set\n");
108 NetWriteIP((uchar*)&arp->ar_data[16], NetOurGatewayIP);
110 NetWriteIP((uchar*)&arp->ar_data[16], NetServerIP);
114 NetSendPacket(NetTxPacket, ETHER_HDR_SIZE + ARP_HDR_SIZE);
116 NetSetTimeout(TIMEOUT * CFG_HZ, ArpTimeout);
117 NetSetHandler(ArpHandler);
120 #endif /* CFG_CMD_NET */