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