Blame view
net/rarp.c
2.32 KB
83d290c56 SPDX: Convert all... |
1 |
// SPDX-License-Identifier: GPL-2.0+ |
affae2bff Initial revision |
2 3 4 |
/* * (C) Copyright 2000-2002 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
affae2bff Initial revision |
5 6 7 8 9 |
*/ #include <common.h> #include <command.h> #include <net.h> |
346969584 net: tftp: Move t... |
10 |
#include <net/tftp.h> |
c40b29568 * Patch by Rune T... |
11 |
#include "nfs.h" |
affae2bff Initial revision |
12 13 |
#include "bootp.h" #include "rarp.h" |
affae2bff Initial revision |
14 |
|
8b9c53221 net: Move RARP re... |
15 |
#define TIMEOUT 5000UL /* Milliseconds before trying BOOTP again */ |
affae2bff Initial revision |
16 |
#ifndef CONFIG_NET_RETRY_COUNT |
8b9c53221 net: Move RARP re... |
17 |
#define TIMEOUT_COUNT 5 /* # of timeouts before giving up */ |
affae2bff Initial revision |
18 |
#else |
8b9c53221 net: Move RARP re... |
19 |
#define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT) |
affae2bff Initial revision |
20 |
#endif |
698d78e54 net: cosmetic: Cl... |
21 |
int rarp_try; |
affae2bff Initial revision |
22 23 24 25 |
/* * Handle a RARP received packet. */ |
594c26f8a net: cosmetic: Un... |
26 |
void rarp_receive(struct ip_udp_hdr *ip, unsigned len) |
affae2bff Initial revision |
27 |
{ |
738853bb6 net: cosmetic: Un... |
28 |
struct arp_hdr *arp; |
8b9c53221 net: Move RARP re... |
29 |
|
4ef8d53ca net: Allow filter... |
30 31 |
debug_cond(DEBUG_NET_PKT, "Got RARP "); |
738853bb6 net: cosmetic: Un... |
32 |
arp = (struct arp_hdr *)ip; |
8b9c53221 net: Move RARP re... |
33 34 35 36 37 38 39 |
if (len < ARP_HDR_SIZE) { printf("bad length %d < %d ", len, ARP_HDR_SIZE); return; } if ((ntohs(arp->ar_op) != RARPOP_REPLY) || |
698d78e54 net: cosmetic: Cl... |
40 41 42 |
(ntohs(arp->ar_hrd) != ARP_ETHER) || (ntohs(arp->ar_pro) != PROT_IP) || (arp->ar_hln != 6) || (arp->ar_pln != 4)) { |
8b9c53221 net: Move RARP re... |
43 44 45 |
puts("invalid RARP header "); } else { |
049a95a77 net: cosmetic: Ch... |
46 47 48 |
net_copy_ip(&net_ip, &arp->ar_data[16]); if (net_server_ip.s_addr == 0) net_copy_ip(&net_server_ip, &arp->ar_data[6]); |
0adb5b761 net: cosmetic: Na... |
49 |
memcpy(net_server_ethaddr, &arp->ar_data[0], 6); |
4ef8d53ca net: Allow filter... |
50 51 |
debug_cond(DEBUG_DEV_PKT, "Got good RARP "); |
8b9c53221 net: Move RARP re... |
52 53 |
net_auto_load(); } |
affae2bff Initial revision |
54 55 56 57 58 59 |
} /* * Timeout on BOOTP request. */ |
698d78e54 net: cosmetic: Cl... |
60 |
static void rarp_timeout_handler(void) |
affae2bff Initial revision |
61 |
{ |
698d78e54 net: cosmetic: Cl... |
62 |
if (rarp_try >= TIMEOUT_COUNT) { |
c2faf4f90 net: cosmetic: ra... |
63 64 65 |
puts(" Retry count exceeded; starting again "); |
bc0571fc1 net: cosmetic: Fi... |
66 |
net_start_again(); |
affae2bff Initial revision |
67 |
} else { |
bc0571fc1 net: cosmetic: Fi... |
68 |
net_set_timeout_handler(TIMEOUT, rarp_timeout_handler); |
698d78e54 net: cosmetic: Cl... |
69 |
rarp_request(); |
affae2bff Initial revision |
70 71 |
} } |
698d78e54 net: cosmetic: Cl... |
72 |
void rarp_request(void) |
affae2bff Initial revision |
73 |
{ |
db288a960 net: Remove volat... |
74 |
uchar *pkt; |
738853bb6 net: cosmetic: Un... |
75 |
struct arp_hdr *rarp; |
00f33268a net: Refactor pac... |
76 |
int eth_hdr_size; |
affae2bff Initial revision |
77 |
|
698d78e54 net: cosmetic: Cl... |
78 79 |
printf("RARP broadcast %d ", ++rarp_try); |
1203fccee net: cosmetic: Cl... |
80 |
pkt = net_tx_packet; |
affae2bff Initial revision |
81 |
|
1203fccee net: cosmetic: Cl... |
82 |
eth_hdr_size = net_set_ether(pkt, net_bcast_ethaddr, PROT_RARP); |
00f33268a net: Refactor pac... |
83 |
pkt += eth_hdr_size; |
affae2bff Initial revision |
84 |
|
738853bb6 net: cosmetic: Un... |
85 |
rarp = (struct arp_hdr *)pkt; |
affae2bff Initial revision |
86 |
|
c2faf4f90 net: cosmetic: ra... |
87 88 |
rarp->ar_hrd = htons(ARP_ETHER); rarp->ar_pro = htons(PROT_IP); |
affae2bff Initial revision |
89 90 |
rarp->ar_hln = 6; rarp->ar_pln = 4; |
c2faf4f90 net: cosmetic: ra... |
91 |
rarp->ar_op = htons(RARPOP_REQUEST); |
0adb5b761 net: cosmetic: Na... |
92 |
memcpy(&rarp->ar_data[0], net_ethaddr, 6); /* source ET addr */ |
049a95a77 net: cosmetic: Ch... |
93 |
memcpy(&rarp->ar_data[6], &net_ip, 4); /* source IP addr */ |
c2faf4f90 net: cosmetic: ra... |
94 |
/* dest ET addr = source ET addr ??*/ |
0adb5b761 net: cosmetic: Na... |
95 |
memcpy(&rarp->ar_data[10], net_ethaddr, 6); |
8b9c53221 net: Move RARP re... |
96 97 |
/* dest IP addr set to broadcast */ memset(&rarp->ar_data[16], 0xff, 4); |
affae2bff Initial revision |
98 |
|
1203fccee net: cosmetic: Cl... |
99 |
net_send_packet(net_tx_packet, eth_hdr_size + ARP_HDR_SIZE); |
affae2bff Initial revision |
100 |
|
bc0571fc1 net: cosmetic: Fi... |
101 |
net_set_timeout_handler(TIMEOUT, rarp_timeout_handler); |
affae2bff Initial revision |
102 |
} |