Blame view
net/rarp.c
2.23 KB
affae2bff Initial revision |
1 2 3 4 |
/* * (C) Copyright 2000-2002 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * |
1a4596601 Add GPL-2.0+ SPDX... |
5 |
* SPDX-License-Identifier: GPL-2.0+ |
affae2bff Initial revision |
6 7 8 9 10 |
*/ #include <common.h> #include <command.h> #include <net.h> |
c40b29568 * Patch by Rune T... |
11 |
#include "nfs.h" |
affae2bff Initial revision |
12 13 14 |
#include "bootp.h" #include "rarp.h" #include "tftp.h" |
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 |
8b9c53221 net: Move RARP re... |
21 |
int RarpTry; |
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 40 41 42 43 44 45 46 47 48 49 50 |
if (len < ARP_HDR_SIZE) { printf("bad length %d < %d ", len, ARP_HDR_SIZE); return; } if ((ntohs(arp->ar_op) != RARPOP_REPLY) || (ntohs(arp->ar_hrd) != ARP_ETHER) || (ntohs(arp->ar_pro) != PROT_IP) || (arp->ar_hln != 6) || (arp->ar_pln != 4)) { puts("invalid RARP header "); } else { NetCopyIP(&NetOurIP, &arp->ar_data[16]); if (NetServerIP == 0) NetCopyIP(&NetServerIP, &arp->ar_data[6]); memcpy(NetServerEther, &arp->ar_data[0], 6); |
4ef8d53ca net: Allow filter... |
51 52 |
debug_cond(DEBUG_DEV_PKT, "Got good RARP "); |
8b9c53221 net: Move RARP re... |
53 54 |
net_auto_load(); } |
affae2bff Initial revision |
55 56 57 58 59 60 |
} /* * Timeout on BOOTP request. */ |
8b9c53221 net: Move RARP re... |
61 |
static void RarpTimeout(void) |
affae2bff Initial revision |
62 63 |
{ if (RarpTry >= TIMEOUT_COUNT) { |
c2faf4f90 net: cosmetic: ra... |
64 65 66 67 |
puts(" Retry count exceeded; starting again "); NetStartAgain(); |
affae2bff Initial revision |
68 |
} else { |
c2faf4f90 net: cosmetic: ra... |
69 70 |
NetSetTimeout(TIMEOUT, RarpTimeout); RarpRequest(); |
affae2bff Initial revision |
71 72 |
} } |
8b9c53221 net: Move RARP re... |
73 |
void RarpRequest(void) |
affae2bff Initial revision |
74 |
{ |
db288a960 net: Remove volat... |
75 |
uchar *pkt; |
738853bb6 net: cosmetic: Un... |
76 |
struct arp_hdr *rarp; |
00f33268a net: Refactor pac... |
77 |
int eth_hdr_size; |
affae2bff Initial revision |
78 79 80 81 |
printf("RARP broadcast %d ", ++RarpTry); pkt = NetTxPacket; |
00f33268a net: Refactor pac... |
82 83 |
eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_RARP); 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 92 93 94 95 |
rarp->ar_op = htons(RARPOP_REQUEST); memcpy(&rarp->ar_data[0], NetOurEther, 6); /* source ET addr */ memcpy(&rarp->ar_data[6], &NetOurIP, 4); /* source IP addr */ /* dest ET addr = source ET addr ??*/ memcpy(&rarp->ar_data[10], NetOurEther, 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 |
|
00f33268a net: Refactor pac... |
99 |
NetSendPacket(NetTxPacket, eth_hdr_size + ARP_HDR_SIZE); |
affae2bff Initial revision |
100 |
|
49f3bdbba net: express the ... |
101 |
NetSetTimeout(TIMEOUT, RarpTimeout); |
affae2bff Initial revision |
102 |
} |