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