]>
git.ipfire.org Git - people/ms/u-boot.git/blob - net/rarp.c
2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
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 */
36 #define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT)
42 * Handle a RARP received packet.
44 void rarp_receive(IP_t
*ip
, unsigned len
)
50 if (len
< ARP_HDR_SIZE
) {
51 printf("bad length %d < %d\n", len
, ARP_HDR_SIZE
);
55 if ((ntohs(arp
->ar_op
) != RARPOP_REPLY
) ||
56 (ntohs(arp
->ar_hrd
) != ARP_ETHER
) ||
57 (ntohs(arp
->ar_pro
) != PROT_IP
) ||
58 (arp
->ar_hln
!= 6) || (arp
->ar_pln
!= 4)) {
60 puts("invalid RARP header\n");
62 NetCopyIP(&NetOurIP
, &arp
->ar_data
[16]);
64 NetCopyIP(&NetServerIP
, &arp
->ar_data
[6]);
65 memcpy(NetServerEther
, &arp
->ar_data
[0], 6);
66 debug("Got good RARP\n");
73 * Timeout on BOOTP request.
75 static void RarpTimeout(void)
77 if (RarpTry
>= TIMEOUT_COUNT
) {
78 puts("\nRetry count exceeded; starting again\n");
81 NetSetTimeout(TIMEOUT
, RarpTimeout
);
87 void RarpRequest(void)
92 printf("RARP broadcast %d\n", ++RarpTry
);
95 pkt
+= NetSetEther(pkt
, NetBcastAddr
, PROT_RARP
);
99 rarp
->ar_hrd
= htons(ARP_ETHER
);
100 rarp
->ar_pro
= htons(PROT_IP
);
103 rarp
->ar_op
= htons(RARPOP_REQUEST
);
104 memcpy(&rarp
->ar_data
[0], NetOurEther
, 6); /* source ET addr */
105 memcpy(&rarp
->ar_data
[6], &NetOurIP
, 4); /* source IP addr */
106 /* dest ET addr = source ET addr ??*/
107 memcpy(&rarp
->ar_data
[10], NetOurEther
, 6);
108 /* dest IP addr set to broadcast */
109 memset(&rarp
->ar_data
[16], 0xff, 4);
111 NetSendPacket(NetTxPacket
, (pkt
- NetTxPacket
) + ARP_HDR_SIZE
);
113 NetSetTimeout(TIMEOUT
, RarpTimeout
);