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> |
| 27 | #include "bootp.h" |
| 28 | #include "rarp.h" |
| 29 | #include "tftp.h" |
| 30 | |
| 31 | #if (CONFIG_COMMANDS & CFG_CMD_NET) |
| 32 | |
| 33 | #define TIMEOUT 5 /* Seconds before trying BOOTP again */ |
| 34 | #ifndef CONFIG_NET_RETRY_COUNT |
| 35 | # define TIMEOUT_COUNT 5 /* # of timeouts before giving up */ |
| 36 | #else |
| 37 | # define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT) |
| 38 | #endif |
| 39 | |
| 40 | |
| 41 | int RarpTry; |
| 42 | |
| 43 | /* |
| 44 | * Handle a RARP received packet. |
| 45 | */ |
| 46 | static void |
| 47 | RarpHandler(uchar * dummi0, unsigned dummi1, unsigned dummi2, unsigned dummi3) |
| 48 | { |
| 49 | #ifdef DEBUG |
| 50 | printf("Got good RARP\n"); |
| 51 | #endif |
| 52 | TftpStart (); |
| 53 | } |
| 54 | |
| 55 | |
| 56 | /* |
| 57 | * Timeout on BOOTP request. |
| 58 | */ |
| 59 | static void |
| 60 | RarpTimeout(void) |
| 61 | { |
| 62 | if (RarpTry >= TIMEOUT_COUNT) { |
| 63 | puts ("\nRetry count exceeded; starting again\n"); |
| 64 | NetStartAgain (); |
| 65 | } else { |
| 66 | NetSetTimeout (TIMEOUT * CFG_HZ, RarpTimeout); |
| 67 | RarpRequest (); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | |
| 72 | void |
| 73 | RarpRequest (void) |
| 74 | { |
| 75 | int i; |
| 76 | volatile uchar *pkt; |
| 77 | ARP_t * rarp; |
| 78 | |
| 79 | printf("RARP broadcast %d\n", ++RarpTry); |
| 80 | pkt = NetTxPacket; |
| 81 | |
| 82 | NetSetEther(pkt, NetBcastAddr, PROT_RARP); |
| 83 | pkt += ETHER_HDR_SIZE; |
| 84 | |
| 85 | rarp = (ARP_t *)pkt; |
| 86 | |
| 87 | rarp->ar_hrd = ARP_ETHER; |
| 88 | rarp->ar_pro = PROT_IP; |
| 89 | rarp->ar_hln = 6; |
| 90 | rarp->ar_pln = 4; |
| 91 | rarp->ar_op = RARPOP_REQUEST; |
| 92 | memcpy (&rarp->ar_data[0], NetOurEther, 6); /* source ET addr */ |
| 93 | memcpy (&rarp->ar_data[6], &NetOurIP, 4); /* source IP addr */ |
| 94 | memcpy (&rarp->ar_data[10], NetOurEther, 6); /* dest ET addr = source ET addr ??*/ |
| 95 | /* dest. IP addr set to broadcast */ |
| 96 | for (i = 0; i <= 3; i++) { |
| 97 | rarp->ar_data[16 + i] = 0xff; |
| 98 | } |
| 99 | |
| 100 | NetSendPacket(NetTxPacket, ETHER_HDR_SIZE + ARP_HDR_SIZE); |
| 101 | |
| 102 | NetSetTimeout(TIMEOUT * CFG_HZ, RarpTimeout); |
| 103 | NetSetHandler(RarpHandler); |
| 104 | } |
| 105 | |
| 106 | #endif /* CFG_CMD_NET */ |