1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2002
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
15 #define TIMEOUT 5000UL /* Milliseconds before trying BOOTP again */
16 #ifndef CONFIG_NET_RETRY_COUNT
17 #define TIMEOUT_COUNT 5 /* # of timeouts before giving up */
19 #define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT)
25 * Handle a RARP received packet.
27 void rarp_receive(struct ip_udp_hdr *ip, unsigned len)
31 debug_cond(DEBUG_NET_PKT, "Got RARP\n");
32 arp = (struct arp_hdr *)ip;
33 if (len < ARP_HDR_SIZE) {
34 printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
38 if ((ntohs(arp->ar_op) != RARPOP_REPLY) ||
39 (ntohs(arp->ar_hrd) != ARP_ETHER) ||
40 (ntohs(arp->ar_pro) != PROT_IP) ||
41 (arp->ar_hln != 6) || (arp->ar_pln != 4)) {
42 puts("invalid RARP header\n");
44 net_copy_ip(&net_ip, &arp->ar_data[16]);
45 if (net_server_ip.s_addr == 0)
46 net_copy_ip(&net_server_ip, &arp->ar_data[6]);
47 memcpy(net_server_ethaddr, &arp->ar_data[0], 6);
48 debug_cond(DEBUG_DEV_PKT, "Got good RARP\n");
55 * Timeout on BOOTP request.
57 static void rarp_timeout_handler(void)
59 if (rarp_try >= TIMEOUT_COUNT) {
60 puts("\nRetry count exceeded; starting again\n");
63 net_set_timeout_handler(TIMEOUT, rarp_timeout_handler);
69 void rarp_request(void)
75 printf("RARP broadcast %d\n", ++rarp_try);
78 eth_hdr_size = net_set_ether(pkt, net_bcast_ethaddr, PROT_RARP);
81 rarp = (struct arp_hdr *)pkt;
83 rarp->ar_hrd = htons(ARP_ETHER);
84 rarp->ar_pro = htons(PROT_IP);
87 rarp->ar_op = htons(RARPOP_REQUEST);
88 memcpy(&rarp->ar_data[0], net_ethaddr, 6); /* source ET addr */
89 memcpy(&rarp->ar_data[6], &net_ip, 4); /* source IP addr */
90 /* dest ET addr = source ET addr ??*/
91 memcpy(&rarp->ar_data[10], net_ethaddr, 6);
92 /* dest IP addr set to broadcast */
93 memset(&rarp->ar_data[16], 0xff, 4);
95 net_send_packet(net_tx_packet, eth_hdr_size + ARP_HDR_SIZE);
97 net_set_timeout_handler(TIMEOUT, rarp_timeout_handler);