wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 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> |
wdenk | f602aa0 | 2004-03-13 23:29:43 +0000 | [diff] [blame] | 27 | #include "nfs.h" |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 28 | #include "bootp.h" |
| 29 | #include "rarp.h" |
| 30 | #include "tftp.h" |
| 31 | |
Bartlomiej Sieka | 5666846 | 2008-10-01 15:26:28 +0200 | [diff] [blame] | 32 | #define TIMEOUT 5000UL /* Milliseconds before trying BOOTP again */ |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 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 |
Luca Ceresoli | 428ab36 | 2011-04-18 06:19:50 +0000 | [diff] [blame] | 46 | RarpHandler(uchar *dummi0, unsigned dummi1, IPaddr_t sip, unsigned dummi2, |
| 47 | unsigned dummi3) |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 48 | { |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 49 | debug("Got good RARP\n"); |
Simon Glass | 5234ad1 | 2011-10-27 06:24:32 +0000 | [diff] [blame] | 50 | net_auto_load(); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | |
| 54 | /* |
| 55 | * Timeout on BOOTP request. |
| 56 | */ |
| 57 | static void |
| 58 | RarpTimeout(void) |
| 59 | { |
| 60 | if (RarpTry >= TIMEOUT_COUNT) { |
| 61 | puts ("\nRetry count exceeded; starting again\n"); |
| 62 | NetStartAgain (); |
| 63 | } else { |
Bartlomiej Sieka | 5666846 | 2008-10-01 15:26:28 +0200 | [diff] [blame] | 64 | NetSetTimeout (TIMEOUT, RarpTimeout); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 65 | RarpRequest (); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | |
| 70 | void |
| 71 | RarpRequest (void) |
| 72 | { |
| 73 | int i; |
Joe Hershberger | 4b7747e | 2012-05-15 08:59:04 +0000 | [diff] [blame^] | 74 | uchar *pkt; |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 75 | ARP_t * rarp; |
| 76 | |
| 77 | printf("RARP broadcast %d\n", ++RarpTry); |
| 78 | pkt = NetTxPacket; |
| 79 | |
wdenk | 145d2c1 | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 80 | pkt += NetSetEther(pkt, NetBcastAddr, PROT_RARP); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 81 | |
| 82 | rarp = (ARP_t *)pkt; |
| 83 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 84 | rarp->ar_hrd = htons (ARP_ETHER); |
| 85 | rarp->ar_pro = htons (PROT_IP); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 86 | rarp->ar_hln = 6; |
| 87 | rarp->ar_pln = 4; |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 88 | rarp->ar_op = htons (RARPOP_REQUEST); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 89 | memcpy (&rarp->ar_data[0], NetOurEther, 6); /* source ET addr */ |
| 90 | memcpy (&rarp->ar_data[6], &NetOurIP, 4); /* source IP addr */ |
| 91 | memcpy (&rarp->ar_data[10], NetOurEther, 6); /* dest ET addr = source ET addr ??*/ |
| 92 | /* dest. IP addr set to broadcast */ |
| 93 | for (i = 0; i <= 3; i++) { |
| 94 | rarp->ar_data[16 + i] = 0xff; |
| 95 | } |
| 96 | |
wdenk | 145d2c1 | 2004-04-15 21:48:45 +0000 | [diff] [blame] | 97 | NetSendPacket(NetTxPacket, (pkt - NetTxPacket) + ARP_HDR_SIZE); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 98 | |
Bartlomiej Sieka | 5666846 | 2008-10-01 15:26:28 +0200 | [diff] [blame] | 99 | NetSetTimeout(TIMEOUT, RarpTimeout); |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 100 | NetSetHandler(RarpHandler); |
| 101 | } |