]> git.ipfire.org Git - people/ms/u-boot.git/blame - net/rarp.c
net: Move PING out of net.c
[people/ms/u-boot.git] / net / rarp.c
CommitLineData
affae2bf
WD
1/*
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
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.
12 *
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.
17 *
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,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <command.h>
26#include <net.h>
c40b2956 27#include "nfs.h"
affae2bf
WD
28#include "bootp.h"
29#include "rarp.h"
30#include "tftp.h"
31
49f3bdbb 32#define TIMEOUT 5000UL /* Milliseconds before trying BOOTP again */
affae2bf
WD
33#ifndef CONFIG_NET_RETRY_COUNT
34# define TIMEOUT_COUNT 5 /* # of timeouts before giving up */
35#else
36# define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT)
37#endif
38
39
40int RarpTry;
41
42/*
43 * Handle a RARP received packet.
44 */
45static void
03eb129f
LC
46RarpHandler(uchar *dummi0, unsigned dummi1, IPaddr_t sip, unsigned dummi2,
47 unsigned dummi3)
affae2bf 48{
0ebf04c6 49 debug("Got good RARP\n");
e4a3d57d 50 net_auto_load();
affae2bf
WD
51}
52
53
54/*
55 * Timeout on BOOTP request.
56 */
57static void
58RarpTimeout(void)
59{
60 if (RarpTry >= TIMEOUT_COUNT) {
c2faf4f9
JH
61 puts("\nRetry count exceeded; starting again\n");
62 NetStartAgain();
affae2bf 63 } else {
c2faf4f9
JH
64 NetSetTimeout(TIMEOUT, RarpTimeout);
65 RarpRequest();
affae2bf
WD
66 }
67}
68
69
70void
c2faf4f9 71RarpRequest(void)
affae2bf
WD
72{
73 int i;
db288a96 74 uchar *pkt;
c2faf4f9 75 ARP_t *rarp;
affae2bf
WD
76
77 printf("RARP broadcast %d\n", ++RarpTry);
78 pkt = NetTxPacket;
79
a3d991bd 80 pkt += NetSetEther(pkt, NetBcastAddr, PROT_RARP);
affae2bf
WD
81
82 rarp = (ARP_t *)pkt;
83
c2faf4f9
JH
84 rarp->ar_hrd = htons(ARP_ETHER);
85 rarp->ar_pro = htons(PROT_IP);
affae2bf
WD
86 rarp->ar_hln = 6;
87 rarp->ar_pln = 4;
c2faf4f9
JH
88 rarp->ar_op = htons(RARPOP_REQUEST);
89 memcpy(&rarp->ar_data[0], NetOurEther, 6); /* source ET addr */
90 memcpy(&rarp->ar_data[6], &NetOurIP, 4); /* source IP addr */
91 /* dest ET addr = source ET addr ??*/
92 memcpy(&rarp->ar_data[10], NetOurEther, 6);
affae2bf 93 /* dest. IP addr set to broadcast */
c2faf4f9 94 for (i = 0; i <= 3; i++)
affae2bf 95 rarp->ar_data[16 + i] = 0xff;
affae2bf 96
a3d991bd 97 NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
affae2bf 98
49f3bdbb 99 NetSetTimeout(TIMEOUT, RarpTimeout);
affae2bf
WD
100 NetSetHandler(RarpHandler);
101}