Update QCA956x GPIO OUT functions list
[oweals/u-boot_mod.git] / u-boot / 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 defined(CONFIG_CMD_NET)
33
34 DECLARE_GLOBAL_DATA_PTR;
35
36 #define TIMEOUT 5       /* Seconds before trying BOOTP again */
37
38 #if !defined(CONFIG_NET_RETRY_COUNT)
39         /* # of timeouts before giving up  */
40         #define TIMEOUT_COUNT   5
41 #else
42         #define TIMEOUT_COUNT   (CONFIG_NET_RETRY_COUNT)
43 #endif
44
45 int RarpTry;
46
47 /* Handle a RARP received packet */
48 static void RarpHandler(uchar   *dummi0,
49                         unsigned dummi1,
50                         unsigned dummi2,
51                         unsigned dummi3)
52 {
53         char *s;
54
55 #if defined(DEBUG)
56         puts ("Got good RARP\n");
57 #endif
58
59         if ((s = getenv("autoload")) != NULL) {
60                 if (*s == 'n') {
61                         /*
62                          * Just use RARP to configure system;
63                          * Do not use TFTP/NFS to to load the bootfile.
64                          */
65                         NetState = NETLOOP_SUCCESS;
66                         return;
67 #if defined(CONFIG_CMD_NFS)
68                 } else if ((s != NULL) && !strcmp(s, "NFS")) {
69                         NfsStart();
70                         return;
71 #endif
72                 }
73         }
74
75         TftpStart(TFTPGET);
76 }
77
78 /* Timeout on BOOTP request */
79 static void RarpTimeout(void)
80 {
81         bd_t *bd = gd->bd;
82
83         if (RarpTry >= TIMEOUT_COUNT) {
84                 puts("\nRetry count exceeded; starting again\n");
85                 NetStartAgain();
86         } else {
87                 NetSetTimeout(TIMEOUT * CFG_HZ, RarpTimeout);
88                 RarpRequest();
89         }
90 }
91
92 void RarpRequest(void)
93 {
94         int i;
95         ARP_t *rarp;
96         bd_t *bd = gd->bd;
97         volatile uchar *pkt;
98
99         printf("RARP broadcast %d\n", ++RarpTry);
100         pkt = NetTxPacket;
101
102         pkt += NetSetEther(pkt, NetBcastAddr, PROT_RARP);
103
104         rarp = (ARP_t *)pkt;
105
106         rarp->ar_hrd = htons(ARP_ETHER);
107         rarp->ar_pro = htons(PROT_IP);
108         rarp->ar_hln = 6;
109         rarp->ar_pln = 4;
110         rarp->ar_op  = htons(RARPOP_REQUEST);
111
112         memcpy(&rarp->ar_data[0],  NetOurEther, 6);     /* source ET addr */
113         memcpy(&rarp->ar_data[6],  &NetOurIP,   4);     /* source IP addr */
114         memcpy(&rarp->ar_data[10], NetOurEther, 6);     /* dest ET addr = source ET addr ??*/
115
116         /* Dest. IP addr set to broadcast */
117         for (i = 0; i <= 3; i++)
118                 rarp->ar_data[16 + i] = 0xff;
119
120         NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE);
121
122         NetSetTimeout(TIMEOUT * CFG_HZ, RarpTimeout);
123         NetSetHandler(RarpHandler);
124 }
125 #endif /* CONFIG_CMD_NET */