1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2002
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
16 #define TIMEOUT 5000UL /* Milliseconds before trying BOOTP again */
21 * Handle a RARP received packet.
23 void rarp_receive(struct ip_udp_hdr *ip, unsigned len)
27 debug_cond(DEBUG_NET_PKT, "Got RARP\n");
28 arp = (struct arp_hdr *)ip;
29 if (len < ARP_HDR_SIZE) {
30 printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
34 if ((ntohs(arp->ar_op) != RARPOP_REPLY) ||
35 (ntohs(arp->ar_hrd) != ARP_ETHER) ||
36 (ntohs(arp->ar_pro) != PROT_IP) ||
37 (arp->ar_hln != 6) || (arp->ar_pln != 4)) {
38 puts("invalid RARP header\n");
40 net_copy_ip(&net_ip, &arp->ar_data[16]);
41 if (net_server_ip.s_addr == 0)
42 net_copy_ip(&net_server_ip, &arp->ar_data[6]);
43 memcpy(net_server_ethaddr, &arp->ar_data[0], 6);
44 debug_cond(DEBUG_DEV_PKT, "Got good RARP\n");
51 * Timeout on BOOTP request.
53 static void rarp_timeout_handler(void)
55 if (rarp_try >= CONFIG_NET_RETRY_COUNT) {
56 puts("\nRetry count exceeded; starting again\n");
59 net_set_timeout_handler(TIMEOUT, rarp_timeout_handler);
65 void rarp_request(void)
71 printf("RARP broadcast %d\n", ++rarp_try);
74 eth_hdr_size = net_set_ether(pkt, net_bcast_ethaddr, PROT_RARP);
77 rarp = (struct arp_hdr *)pkt;
79 rarp->ar_hrd = htons(ARP_ETHER);
80 rarp->ar_pro = htons(PROT_IP);
83 rarp->ar_op = htons(RARPOP_REQUEST);
84 memcpy(&rarp->ar_data[0], net_ethaddr, 6); /* source ET addr */
85 memcpy(&rarp->ar_data[6], &net_ip, 4); /* source IP addr */
86 /* dest ET addr = source ET addr ??*/
87 memcpy(&rarp->ar_data[10], net_ethaddr, 6);
88 /* dest IP addr set to broadcast */
89 memset(&rarp->ar_data[16], 0xff, 4);
91 net_send_packet(net_tx_packet, eth_hdr_size + ARP_HDR_SIZE);
93 net_set_timeout_handler(TIMEOUT, rarp_timeout_handler);