1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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#define TIMEOUT 5000UL
33#ifndef CONFIG_NET_RETRY_COUNT
34# define TIMEOUT_COUNT 5
35#else
36# define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT)
37#endif
38
39
40int RarpTry;
41
42
43
44
45static void
46RarpHandler(uchar * dummi0, unsigned dummi1, unsigned dummi2, unsigned dummi3)
47{
48 char *s;
49 debug("Got good RARP\n");
50 if ((s = getenv("autoload")) != NULL) {
51 if (*s == 'n') {
52
53
54
55
56 NetState = NETLOOP_SUCCESS;
57 return;
58#if defined(CONFIG_CMD_NFS)
59 } else if ((s != NULL) && !strcmp(s, "NFS")) {
60 NfsStart();
61 return;
62#endif
63 }
64 }
65 TftpStart ();
66}
67
68
69
70
71
72static void
73RarpTimeout(void)
74{
75 if (RarpTry >= TIMEOUT_COUNT) {
76 puts ("\nRetry count exceeded; starting again\n");
77 NetStartAgain ();
78 } else {
79 NetSetTimeout (TIMEOUT, RarpTimeout);
80 RarpRequest ();
81 }
82}
83
84
85void
86RarpRequest (void)
87{
88 int i;
89 volatile uchar *pkt;
90 ARP_t * rarp;
91
92 printf("RARP broadcast %d\n", ++RarpTry);
93 pkt = NetTxPacket;
94
95 pkt += NetSetEther(pkt, NetBcastAddr, PROT_RARP);
96
97 rarp = (ARP_t *)pkt;
98
99 rarp->ar_hrd = htons (ARP_ETHER);
100 rarp->ar_pro = htons (PROT_IP);
101 rarp->ar_hln = 6;
102 rarp->ar_pln = 4;
103 rarp->ar_op = htons (RARPOP_REQUEST);
104 memcpy (&rarp->ar_data[0], NetOurEther, 6);
105 memcpy (&rarp->ar_data[6], &NetOurIP, 4);
106 memcpy (&rarp->ar_data[10], NetOurEther, 6);
107
108 for (i = 0; i <= 3; i++) {
109 rarp->ar_data[16 + i] = 0xff;
110 }
111
112 NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
113
114 NetSetTimeout(TIMEOUT, RarpTimeout);
115 NetSetHandler(RarpHandler);
116}
117