]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - net/rarp.c
* Patch by Rune Torgersen, 27 Feb 2004:
[karo-tx-uboot.git] / net / rarp.c
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>
27 #include "nfs.h"
28 #include "bootp.h"
29 #include "rarp.h"
30 #include "tftp.h"
31
32 #if (CONFIG_COMMANDS & CFG_CMD_NET)
33
34 #define TIMEOUT         5               /* Seconds before trying BOOTP again */
35 #ifndef CONFIG_NET_RETRY_COUNT
36 # define TIMEOUT_COUNT  5               /* # of timeouts before giving up  */
37 #else
38 # define TIMEOUT_COUNT  (CONFIG_NET_RETRY_COUNT)
39 #endif
40
41
42 int             RarpTry;
43
44 /*
45  *      Handle a RARP received packet.
46  */
47 static void
48 RarpHandler(uchar * dummi0, unsigned dummi1, unsigned dummi2, unsigned dummi3)
49 {
50         char *s;
51 #ifdef  DEBUG
52         printf("Got good RARP\n");
53 #endif
54         if (((s = getenv("autoload")) != NULL) && (*s == 'n')) {
55                 NetState = NETLOOP_SUCCESS;
56                 return;
57         }
58         else if ((s != NULL) && !strcmp(s, "NFS")) {
59                 NfsStart();
60                 return;
61         }
62         TftpStart ();
63 }
64
65
66 /*
67  *      Timeout on BOOTP request.
68  */
69 static void
70 RarpTimeout(void)
71 {
72         if (RarpTry >= TIMEOUT_COUNT) {
73                 puts ("\nRetry count exceeded; starting again\n");
74                 NetStartAgain ();
75         } else {
76                 NetSetTimeout (TIMEOUT * CFG_HZ, RarpTimeout);
77                 RarpRequest ();
78         }
79 }
80
81
82 void
83 RarpRequest (void)
84 {
85         int i;
86         volatile uchar *pkt;
87         ARP_t * rarp;
88
89         printf("RARP broadcast %d\n", ++RarpTry);
90         pkt = NetTxPacket;
91
92         NetSetEther(pkt, NetBcastAddr, PROT_RARP);
93         pkt += ETHER_HDR_SIZE;
94
95         rarp = (ARP_t *)pkt;
96
97         rarp->ar_hrd = htons (ARP_ETHER);
98         rarp->ar_pro = htons (PROT_IP);
99         rarp->ar_hln = 6;
100         rarp->ar_pln = 4;
101         rarp->ar_op  = htons (RARPOP_REQUEST);
102         memcpy (&rarp->ar_data[0],  NetOurEther, 6);    /* source ET addr */
103         memcpy (&rarp->ar_data[6],  &NetOurIP,   4);    /* source IP addr */
104         memcpy (&rarp->ar_data[10], NetOurEther, 6);    /* dest ET addr = source ET addr ??*/
105         /* dest. IP addr set to broadcast */
106         for (i = 0; i <= 3; i++) {
107                 rarp->ar_data[16 + i] = 0xff;
108         }
109
110         NetSendPacket(NetTxPacket, ETHER_HDR_SIZE + ARP_HDR_SIZE);
111
112         NetSetTimeout(TIMEOUT * CFG_HZ, RarpTimeout);
113         NetSetHandler(RarpHandler);
114 }
115
116 #endif /* CFG_CMD_NET */