Blame view
net/bootp.c
22.7 KB
3861aa5ce Initial revision |
1 2 3 4 5 6 7 |
/* * Based on LiMon - BOOTP. * * Copyright 1994, 1995, 2000 Neil Russell. * (See License) * Copyright 2000 Roland Borde * Copyright 2000 Paolo Scaffardi |
232c150a2 Add support for S... |
8 |
* Copyright 2000-2004 Wolfgang Denk, wd@denx.de |
3861aa5ce Initial revision |
9 |
*/ |
3861aa5ce Initial revision |
10 11 12 13 14 |
#include <common.h> #include <command.h> #include <net.h> #include "bootp.h" #include "tftp.h" |
232c150a2 Add support for S... |
15 |
#include "nfs.h" |
3861aa5ce Initial revision |
16 17 18 |
#ifdef CONFIG_STATUS_LED #include <status_led.h> #endif |
db7720bad net: make net_ran... |
19 20 21 |
#ifdef CONFIG_BOOTP_RANDOM_DELAY #include "net_rand.h" #endif |
3861aa5ce Initial revision |
22 |
|
3090b7e36 net: cosmetic: bo... |
23 |
#define BOOTP_VENDOR_MAGIC 0x63825363 /* RFC1048 Magic Cookie */ |
3861aa5ce Initial revision |
24 |
|
49f3bdbba net: express the ... |
25 |
#define TIMEOUT 5000UL /* Milliseconds before trying BOOTP again */ |
232c150a2 Add support for S... |
26 |
#ifndef CONFIG_NET_RETRY_COUNT |
3090b7e36 net: cosmetic: bo... |
27 |
# define TIMEOUT_COUNT 5 /* # of timeouts before giving up */ |
3861aa5ce Initial revision |
28 |
#else |
232c150a2 Add support for S... |
29 |
# define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT) |
3861aa5ce Initial revision |
30 |
#endif |
3090b7e36 net: cosmetic: bo... |
31 32 |
#define PORT_BOOTPS 67 /* BOOTP server UDP port */ #define PORT_BOOTPC 68 /* BOOTP client UDP port */ |
3861aa5ce Initial revision |
33 |
|
3090b7e36 net: cosmetic: bo... |
34 |
#ifndef CONFIG_DHCP_MIN_EXT_LEN /* minimal length of extension list */ |
232c150a2 Add support for S... |
35 |
#define CONFIG_DHCP_MIN_EXT_LEN 64 |
3861aa5ce Initial revision |
36 37 38 39 |
#endif ulong BootpID; int BootpTry; |
3861aa5ce Initial revision |
40 |
|
643d1ab23 net/: Remove obso... |
41 |
#if defined(CONFIG_CMD_DHCP) |
063705908 net/: sparse fixes |
42 43 44 |
static dhcp_state_t dhcp_state = INIT; static unsigned long dhcp_leasetime; static IPaddr_t NetDHCPServerIP; |
03eb129f8 NET: pass source ... |
45 46 |
static void DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len); |
3861aa5ce Initial revision |
47 48 |
/* For Debug */ |
3e38691e8 * Patch by Arun D... |
49 50 |
#if 0 static char *dhcpmsg2str(int type) |
3861aa5ce Initial revision |
51 52 |
{ switch (type) { |
232c150a2 Add support for S... |
53 54 55 56 57 58 59 |
case 1: return "DHCPDISCOVER"; break; case 2: return "DHCPOFFER"; break; case 3: return "DHCPREQUEST"; break; case 4: return "DHCPDECLINE"; break; case 5: return "DHCPACK"; break; case 6: return "DHCPNACK"; break; case 7: return "DHCPRELEASE"; break; |
3861aa5ce Initial revision |
60 61 62 |
default: return "UNKNOWN/INVALID MSG TYPE"; break; } } |
3e38691e8 * Patch by Arun D... |
63 |
#endif |
610f2e9c2 net/: Remove ling... |
64 |
#endif |
3861aa5ce Initial revision |
65 66 67 |
static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len) { |
3090b7e36 net: cosmetic: bo... |
68 |
struct Bootp_t *bp = (struct Bootp_t *) pkt; |
3861aa5ce Initial revision |
69 70 71 72 |
int retval = 0; if (dest != PORT_BOOTPC || src != PORT_BOOTPS) retval = -1; |
f8315731d net: cosmetic: Re... |
73 |
else if (len < sizeof(struct Bootp_t) - OPT_FIELD_SIZE) |
3861aa5ce Initial revision |
74 75 |
retval = -2; else if (bp->bp_op != OP_BOOTREQUEST && |
3090b7e36 net: cosmetic: bo... |
76 77 78 79 |
bp->bp_op != OP_BOOTREPLY && bp->bp_op != DHCP_OFFER && bp->bp_op != DHCP_ACK && bp->bp_op != DHCP_NAK) |
3861aa5ce Initial revision |
80 |
retval = -3; |
3861aa5ce Initial revision |
81 82 83 84 |
else if (bp->bp_htype != HWT_ETHER) retval = -4; else if (bp->bp_hlen != HWL_ETHER) retval = -5; |
3090b7e36 net: cosmetic: bo... |
85 |
else if (NetReadLong((ulong *)&bp->bp_id) != BootpID) |
3861aa5ce Initial revision |
86 |
retval = -6; |
3861aa5ce Initial revision |
87 |
|
0ebf04c60 minor debug clean... |
88 89 |
debug("Filtering pkt = %d ", retval); |
3861aa5ce Initial revision |
90 91 92 93 94 95 96 |
return retval; } /* * Copy parameters of interest from BOOTP_REPLY/DHCP_OFFER packet */ |
3090b7e36 net: cosmetic: bo... |
97 |
static void BootpCopyNetParams(struct Bootp_t *bp) |
3861aa5ce Initial revision |
98 |
{ |
5d110f0aa New CONFIG_BOOTP_... |
99 |
#if !defined(CONFIG_BOOTP_SERVERIP) |
1752f0fdc net: Fix unused v... |
100 |
IPaddr_t tmp_ip; |
3d3befa75 * Patch by Philip... |
101 102 103 |
NetCopyIP(&tmp_ip, &bp->bp_siaddr); if (tmp_ip != 0) NetCopyIP(&NetServerIP, &bp->bp_siaddr); |
cb487f566 net: cosmetic: Un... |
104 |
memcpy(NetServerEther, ((struct ethernet_hdr *)NetRxPacket)->et_src, 6); |
5d110f0aa New CONFIG_BOOTP_... |
105 |
#endif |
1752f0fdc net: Fix unused v... |
106 |
NetCopyIP(&NetOurIP, &bp->bp_yiaddr); |
3d3befa75 * Patch by Philip... |
107 |
if (strlen(bp->bp_file) > 0) |
3090b7e36 net: cosmetic: bo... |
108 |
copy_filename(BootFile, bp->bp_file, sizeof(BootFile)); |
3861aa5ce Initial revision |
109 |
|
0ebf04c60 minor debug clean... |
110 111 |
debug("Bootfile: %s ", BootFile); |
3861aa5ce Initial revision |
112 113 |
/* Propagate to environment: |
8bde7f776 * Code cleanup: |
114 |
* don't delete exising entry when BOOTP / DHCP reply does |
3861aa5ce Initial revision |
115 116 |
* not contain a new value */ |
3090b7e36 net: cosmetic: bo... |
117 118 |
if (*BootFile) setenv("bootfile", BootFile); |
3861aa5ce Initial revision |
119 |
} |
3090b7e36 net: cosmetic: bo... |
120 |
static int truncate_sz(const char *name, int maxlen, int curlen) |
3861aa5ce Initial revision |
121 122 |
{ if (curlen >= maxlen) { |
3090b7e36 net: cosmetic: bo... |
123 124 125 |
printf("*** WARNING: %s is too long (%d - max: %d)" " - truncated ", name, curlen, maxlen); |
3861aa5ce Initial revision |
126 127 |
curlen = maxlen - 1; } |
3090b7e36 net: cosmetic: bo... |
128 |
return curlen; |
3861aa5ce Initial revision |
129 |
} |
643d1ab23 net/: Remove obso... |
130 |
#if !defined(CONFIG_CMD_DHCP) |
3861aa5ce Initial revision |
131 |
|
3090b7e36 net: cosmetic: bo... |
132 |
static void BootpVendorFieldProcess(u8 *ext) |
3861aa5ce Initial revision |
133 |
{ |
232c150a2 Add support for S... |
134 |
int size = *(ext + 1); |
3861aa5ce Initial revision |
135 |
|
0ebf04c60 minor debug clean... |
136 137 |
debug("[BOOTP] Processing extension %d... (%d bytes) ", *ext, |
3090b7e36 net: cosmetic: bo... |
138 |
*(ext + 1)); |
3861aa5ce Initial revision |
139 |
|
232c150a2 Add support for S... |
140 |
NetBootFileSize = 0; |
3861aa5ce Initial revision |
141 |
|
232c150a2 Add support for S... |
142 143 |
switch (*ext) { /* Fixed length fields */ |
3090b7e36 net: cosmetic: bo... |
144 |
case 1: /* Subnet mask */ |
3861aa5ce Initial revision |
145 |
if (NetOurSubnetMask == 0) |
3090b7e36 net: cosmetic: bo... |
146 |
NetCopyIP(&NetOurSubnetMask, (IPaddr_t *) (ext + 2)); |
3861aa5ce Initial revision |
147 |
break; |
3090b7e36 net: cosmetic: bo... |
148 |
case 2: /* Time offset - Not yet supported */ |
3861aa5ce Initial revision |
149 |
break; |
232c150a2 Add support for S... |
150 |
/* Variable length fields */ |
3090b7e36 net: cosmetic: bo... |
151 152 153 |
case 3: /* Gateways list */ if (NetOurGatewayIP == 0) NetCopyIP(&NetOurGatewayIP, (IPaddr_t *) (ext + 2)); |
3861aa5ce Initial revision |
154 |
break; |
3090b7e36 net: cosmetic: bo... |
155 |
case 4: /* Time server - Not yet supported */ |
3861aa5ce Initial revision |
156 |
break; |
3090b7e36 net: cosmetic: bo... |
157 |
case 5: /* IEN-116 name server - Not yet supported */ |
3861aa5ce Initial revision |
158 159 |
break; case 6: |
3090b7e36 net: cosmetic: bo... |
160 161 |
if (NetOurDNSIP == 0) NetCopyIP(&NetOurDNSIP, (IPaddr_t *) (ext + 2)); |
1fe80d79c Finally retire cm... |
162 |
#if defined(CONFIG_BOOTP_DNS2) |
3090b7e36 net: cosmetic: bo... |
163 164 |
if ((NetOurDNS2IP == 0) && (size > 4)) NetCopyIP(&NetOurDNS2IP, (IPaddr_t *) (ext + 2 + 4)); |
fe389a82c - Added CONFIG_BO... |
165 |
#endif |
3861aa5ce Initial revision |
166 |
break; |
3090b7e36 net: cosmetic: bo... |
167 |
case 7: /* Log server - Not yet supported */ |
3861aa5ce Initial revision |
168 |
break; |
3090b7e36 net: cosmetic: bo... |
169 |
case 8: /* Cookie/Quote server - Not yet supported */ |
3861aa5ce Initial revision |
170 |
break; |
3090b7e36 net: cosmetic: bo... |
171 |
case 9: /* LPR server - Not yet supported */ |
3861aa5ce Initial revision |
172 |
break; |
3090b7e36 net: cosmetic: bo... |
173 |
case 10: /* Impress server - Not yet supported */ |
3861aa5ce Initial revision |
174 |
break; |
3090b7e36 net: cosmetic: bo... |
175 |
case 11: /* RPL server - Not yet supported */ |
3861aa5ce Initial revision |
176 |
break; |
3090b7e36 net: cosmetic: bo... |
177 |
case 12: /* Host name */ |
3861aa5ce Initial revision |
178 |
if (NetOurHostName[0] == 0) { |
3090b7e36 net: cosmetic: bo... |
179 180 181 |
size = truncate_sz("Host Name", sizeof(NetOurHostName), size); memcpy(&NetOurHostName, ext + 2, size); |
232c150a2 Add support for S... |
182 |
NetOurHostName[size] = 0; |
3861aa5ce Initial revision |
183 184 |
} break; |
3090b7e36 net: cosmetic: bo... |
185 |
case 13: /* Boot file size */ |
3861aa5ce Initial revision |
186 |
if (size == 2) |
3090b7e36 net: cosmetic: bo... |
187 |
NetBootFileSize = ntohs(*(ushort *) (ext + 2)); |
3861aa5ce Initial revision |
188 |
else if (size == 4) |
3090b7e36 net: cosmetic: bo... |
189 |
NetBootFileSize = ntohl(*(ulong *) (ext + 2)); |
3861aa5ce Initial revision |
190 |
break; |
3090b7e36 net: cosmetic: bo... |
191 |
case 14: /* Merit dump file - Not yet supported */ |
3861aa5ce Initial revision |
192 |
break; |
3090b7e36 net: cosmetic: bo... |
193 |
case 15: /* Domain name - Not yet supported */ |
3861aa5ce Initial revision |
194 |
break; |
3090b7e36 net: cosmetic: bo... |
195 |
case 16: /* Swap server - Not yet supported */ |
3861aa5ce Initial revision |
196 |
break; |
3090b7e36 net: cosmetic: bo... |
197 |
case 17: /* Root path */ |
3861aa5ce Initial revision |
198 |
if (NetOurRootPath[0] == 0) { |
3090b7e36 net: cosmetic: bo... |
199 200 201 |
size = truncate_sz("Root Path", sizeof(NetOurRootPath), size); memcpy(&NetOurRootPath, ext + 2, size); |
232c150a2 Add support for S... |
202 |
NetOurRootPath[size] = 0; |
3861aa5ce Initial revision |
203 204 |
} break; |
3090b7e36 net: cosmetic: bo... |
205 |
case 18: /* Extension path - Not yet supported */ |
3861aa5ce Initial revision |
206 |
/* |
8bde7f776 * Code cleanup: |
207 208 209 |
* This can be used to send the information of the * vendor area in another file that the client can * access via TFTP. |
3861aa5ce Initial revision |
210 211 |
*/ break; |
232c150a2 Add support for S... |
212 |
/* IP host layer fields */ |
3090b7e36 net: cosmetic: bo... |
213 |
case 40: /* NIS Domain name */ |
3861aa5ce Initial revision |
214 |
if (NetOurNISDomain[0] == 0) { |
3090b7e36 net: cosmetic: bo... |
215 216 217 |
size = truncate_sz("NIS Domain Name", sizeof(NetOurNISDomain), size); memcpy(&NetOurNISDomain, ext + 2, size); |
232c150a2 Add support for S... |
218 |
NetOurNISDomain[size] = 0; |
3861aa5ce Initial revision |
219 220 |
} break; |
09e3a67de bootp: add ntpser... |
221 222 223 224 225 |
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER) case 42: /* NTP server IP */ NetCopyIP(&NetNtpServerIP, (IPaddr_t *) (ext + 2)); break; #endif |
232c150a2 Add support for S... |
226 |
/* Application layer fields */ |
3090b7e36 net: cosmetic: bo... |
227 |
case 43: /* Vendor specific info - Not yet supported */ |
3861aa5ce Initial revision |
228 |
/* |
8bde7f776 * Code cleanup: |
229 230 |
* Binary information to exchange specific * product information. |
3861aa5ce Initial revision |
231 232 |
*/ break; |
232c150a2 Add support for S... |
233 234 |
/* Reserved (custom) fields (128..254) */ } |
3861aa5ce Initial revision |
235 |
} |
3090b7e36 net: cosmetic: bo... |
236 |
static void BootpVendorProcess(u8 *ext, int size) |
3861aa5ce Initial revision |
237 |
{ |
232c150a2 Add support for S... |
238 |
u8 *end = ext + size; |
3861aa5ce Initial revision |
239 |
|
0ebf04c60 minor debug clean... |
240 241 |
debug("[BOOTP] Checking extension (%d bytes)... ", size); |
3861aa5ce Initial revision |
242 |
|
232c150a2 Add support for S... |
243 244 245 246 247 248 249 250 |
while ((ext < end) && (*ext != 0xff)) { if (*ext == 0) { ext++; } else { u8 *opt = ext; ext += ext[1] + 2; if (ext <= end) |
3090b7e36 net: cosmetic: bo... |
251 |
BootpVendorFieldProcess(opt); |
232c150a2 Add support for S... |
252 |
} |
3861aa5ce Initial revision |
253 |
} |
3861aa5ce Initial revision |
254 |
|
3090b7e36 net: cosmetic: bo... |
255 256 |
debug("[BOOTP] Received fields: "); |
b6446b677 convert print_IPa... |
257 |
if (NetOurSubnetMask) |
0ebf04c60 minor debug clean... |
258 259 |
debug("NetOurSubnetMask : %pI4 ", &NetOurSubnetMask); |
232c150a2 Add support for S... |
260 |
|
b6446b677 convert print_IPa... |
261 |
if (NetOurGatewayIP) |
0ebf04c60 minor debug clean... |
262 |
debug("NetOurGatewayIP : %pI4", &NetOurGatewayIP); |
232c150a2 Add support for S... |
263 |
|
0ebf04c60 minor debug clean... |
264 265 266 |
if (NetBootFileSize) debug("NetBootFileSize : %d ", NetBootFileSize); |
3861aa5ce Initial revision |
267 |
|
0ebf04c60 minor debug clean... |
268 269 270 |
if (NetOurHostName[0]) debug("NetOurHostName : %s ", NetOurHostName); |
232c150a2 Add support for S... |
271 |
|
0ebf04c60 minor debug clean... |
272 273 274 |
if (NetOurRootPath[0]) debug("NetOurRootPath : %s ", NetOurRootPath); |
232c150a2 Add support for S... |
275 |
|
0ebf04c60 minor debug clean... |
276 277 278 |
if (NetOurNISDomain[0]) debug("NetOurNISDomain : %s ", NetOurNISDomain); |
232c150a2 Add support for S... |
279 |
|
0ebf04c60 minor debug clean... |
280 281 282 |
if (NetBootFileSize) debug("NetBootFileSize: %d ", NetBootFileSize); |
09e3a67de bootp: add ntpser... |
283 284 285 286 287 288 |
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER) if (NetNtpServerIP) debug("NetNtpServerIP : %pI4 ", &NetNtpServerIP); #endif |
232c150a2 Add support for S... |
289 |
} |
093498669 Put common autolo... |
290 |
|
3861aa5ce Initial revision |
291 292 293 294 |
/* * Handle a BOOTP received packet. */ static void |
03eb129f8 NET: pass source ... |
295 296 |
BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len) |
3861aa5ce Initial revision |
297 |
{ |
3090b7e36 net: cosmetic: bo... |
298 |
struct Bootp_t *bp; |
3861aa5ce Initial revision |
299 |
|
0ebf04c60 minor debug clean... |
300 301 |
debug("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%zu) ", |
3090b7e36 net: cosmetic: bo... |
302 |
src, dest, len, sizeof(struct Bootp_t)); |
3861aa5ce Initial revision |
303 |
|
3090b7e36 net: cosmetic: bo... |
304 |
bp = (struct Bootp_t *)pkt; |
3861aa5ce Initial revision |
305 |
|
3090b7e36 net: cosmetic: bo... |
306 307 |
/* Filter out pkts we don't want */ if (BootpCheckPkt(pkt, dest, src, len)) |
3861aa5ce Initial revision |
308 309 310 |
return; /* |
232c150a2 Add support for S... |
311 |
* Got a good BOOTP reply. Copy the data into our variables. |
3861aa5ce Initial revision |
312 313 |
*/ #ifdef CONFIG_STATUS_LED |
3090b7e36 net: cosmetic: bo... |
314 |
status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF); |
3861aa5ce Initial revision |
315 316 317 318 319 |
#endif BootpCopyNetParams(bp); /* Store net parameters from reply */ /* Retrieve extended information (we must parse the vendor area) */ |
3090b7e36 net: cosmetic: bo... |
320 |
if (NetReadLong((ulong *)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC)) |
77ddac948 Cleanup for GCC-4.x |
321 |
BootpVendorProcess((uchar *)&bp->bp_vend[4], len); |
3861aa5ce Initial revision |
322 323 |
NetSetTimeout(0, (thand_f *)0); |
573f14fe4 bootstage: Plumb ... |
324 |
bootstage_mark_name(BOOTSTAGE_ID_BOOTP_STOP, "bootp_stop"); |
3861aa5ce Initial revision |
325 |
|
0ebf04c60 minor debug clean... |
326 327 |
debug("Got good BOOTP "); |
3861aa5ce Initial revision |
328 |
|
e4a3d57dc net: Export auto_... |
329 |
net_auto_load(); |
3861aa5ce Initial revision |
330 |
} |
610f2e9c2 net/: Remove ling... |
331 |
#endif |
3861aa5ce Initial revision |
332 333 334 335 336 337 338 339 |
/* * Timeout on BOOTP/DHCP request. */ static void BootpTimeout(void) { if (BootpTry >= TIMEOUT_COUNT) { |
2c00e099f net: Add option C... |
340 341 342 343 |
#ifdef CONFIG_BOOTP_MAY_FAIL puts(" Retry count exceeded "); |
b977aa80b net: bootp: fix b... |
344 |
net_set_state(NETLOOP_FAIL); |
2c00e099f net: Add option C... |
345 |
#else |
3090b7e36 net: cosmetic: bo... |
346 347 348 349 |
puts(" Retry count exceeded; starting again "); NetStartAgain(); |
2c00e099f net: Add option C... |
350 |
#endif |
3861aa5ce Initial revision |
351 |
} else { |
3090b7e36 net: cosmetic: bo... |
352 353 |
NetSetTimeout(TIMEOUT, BootpTimeout); BootpRequest(); |
3861aa5ce Initial revision |
354 355 |
} } |
9ace17c88 net/bootp: add VC... |
356 357 358 359 360 361 362 363 |
#define put_vci(e, str) \ do { \ size_t vci_strlen = strlen(str); \ *e++ = 60; /* Vendor Class Identifier */ \ *e++ = vci_strlen; \ memcpy(e, str, vci_strlen); \ e += vci_strlen; \ } while (0) |
3861aa5ce Initial revision |
364 365 366 |
/* * Initialize BOOTP extension fields in the request. */ |
643d1ab23 net/: Remove obso... |
367 |
#if defined(CONFIG_CMD_DHCP) |
3090b7e36 net: cosmetic: bo... |
368 369 |
static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID, IPaddr_t RequestedIP) |
3861aa5ce Initial revision |
370 |
{ |
232c150a2 Add support for S... |
371 372 |
u8 *start = e; u8 *cnt; |
d2b5d5c4c net: bootp: add P... |
373 374 |
#if defined(CONFIG_BOOTP_PXE) char *uuid; |
d2b5d5c4c net: bootp: add P... |
375 376 |
u16 clientarch; #endif |
232c150a2 Add support for S... |
377 |
|
1fe80d79c Finally retire cm... |
378 |
#if defined(CONFIG_BOOTP_VENDOREX) |
232c150a2 Add support for S... |
379 |
u8 *x; |
3861aa5ce Initial revision |
380 |
#endif |
1fe80d79c Finally retire cm... |
381 |
#if defined(CONFIG_BOOTP_SEND_HOSTNAME) |
77ddac948 Cleanup for GCC-4.x |
382 |
char *hostname; |
fe389a82c - Added CONFIG_BO... |
383 |
#endif |
3861aa5ce Initial revision |
384 |
|
232c150a2 Add support for S... |
385 386 387 388 |
*e++ = 99; /* RFC1048 Magic Cookie */ *e++ = 130; *e++ = 83; *e++ = 99; |
3861aa5ce Initial revision |
389 |
|
232c150a2 Add support for S... |
390 391 392 |
*e++ = 53; /* DHCP Message Type */ *e++ = 1; *e++ = message_type; |
3861aa5ce Initial revision |
393 |
|
232c150a2 Add support for S... |
394 395 |
*e++ = 57; /* Maximum DHCP Message Size */ *e++ = 2; |
f8315731d net: cosmetic: Re... |
396 397 |
*e++ = (576 - 312 + OPT_FIELD_SIZE) >> 8; *e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff; |
3861aa5ce Initial revision |
398 |
|
232c150a2 Add support for S... |
399 |
if (ServerID) { |
3090b7e36 net: cosmetic: bo... |
400 |
int tmp = ntohl(ServerID); |
3861aa5ce Initial revision |
401 |
|
232c150a2 Add support for S... |
402 403 404 405 406 407 408 |
*e++ = 54; /* ServerID */ *e++ = 4; *e++ = tmp >> 24; *e++ = tmp >> 16; *e++ = tmp >> 8; *e++ = tmp & 0xff; } |
3861aa5ce Initial revision |
409 |
|
232c150a2 Add support for S... |
410 |
if (RequestedIP) { |
3090b7e36 net: cosmetic: bo... |
411 |
int tmp = ntohl(RequestedIP); |
3861aa5ce Initial revision |
412 |
|
232c150a2 Add support for S... |
413 414 415 416 417 418 419 |
*e++ = 50; /* Requested IP */ *e++ = 4; *e++ = tmp >> 24; *e++ = tmp >> 16; *e++ = tmp >> 8; *e++ = tmp & 0xff; } |
1fe80d79c Finally retire cm... |
420 |
#if defined(CONFIG_BOOTP_SEND_HOSTNAME) |
3090b7e36 net: cosmetic: bo... |
421 422 423 |
hostname = getenv("hostname"); if (hostname) { int hostnamelen = strlen(hostname); |
232c150a2 Add support for S... |
424 425 426 |
*e++ = 12; /* Hostname */ *e++ = hostnamelen; |
3090b7e36 net: cosmetic: bo... |
427 |
memcpy(e, hostname, hostnamelen); |
232c150a2 Add support for S... |
428 429 |
e += hostnamelen; } |
fe389a82c - Added CONFIG_BO... |
430 |
#endif |
d2b5d5c4c net: bootp: add P... |
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
#if defined(CONFIG_BOOTP_PXE) clientarch = CONFIG_BOOTP_PXE_CLIENTARCH; *e++ = 93; /* Client System Architecture */ *e++ = 2; *e++ = (clientarch >> 8) & 0xff; *e++ = clientarch & 0xff; *e++ = 94; /* Client Network Interface Identifier */ *e++ = 3; *e++ = 1; /* type field for UNDI */ *e++ = 0; /* major revision */ *e++ = 0; /* minor revision */ uuid = getenv("pxeuuid"); if (uuid) { if (uuid_str_valid(uuid)) { *e++ = 97; /* Client Machine Identifier */ *e++ = 17; *e++ = 0; /* type 0 - UUID */ |
d718ded05 lib: uuid: code r... |
451 |
uuid_str_to_bin(uuid, e, UUID_STR_FORMAT_STD); |
d2b5d5c4c net: bootp: add P... |
452 453 454 455 456 457 |
e += 16; } else { printf("Invalid pxeuuid: %s ", uuid); } } |
9ace17c88 net/bootp: add VC... |
458 |
#endif |
d2b5d5c4c net: bootp: add P... |
459 |
|
9ace17c88 net/bootp: add VC... |
460 461 |
#ifdef CONFIG_BOOTP_VCI_STRING put_vci(e, CONFIG_BOOTP_VCI_STRING); |
d2b5d5c4c net: bootp: add P... |
462 |
#endif |
1fe80d79c Finally retire cm... |
463 |
#if defined(CONFIG_BOOTP_VENDOREX) |
3090b7e36 net: cosmetic: bo... |
464 465 |
x = dhcp_vendorex_prep(e); if (x) |
232c150a2 Add support for S... |
466 |
return x - start; |
3861aa5ce Initial revision |
467 |
#endif |
232c150a2 Add support for S... |
468 469 470 |
*e++ = 55; /* Parameter Request List */ cnt = e++; /* Pointer to count of requested items */ *cnt = 0; |
1fe80d79c Finally retire cm... |
471 |
#if defined(CONFIG_BOOTP_SUBNETMASK) |
232c150a2 Add support for S... |
472 473 |
*e++ = 1; /* Subnet Mask */ *cnt += 1; |
3861aa5ce Initial revision |
474 |
#endif |
1fe80d79c Finally retire cm... |
475 |
#if defined(CONFIG_BOOTP_TIMEOFFSET) |
ea287debe * Patch by Masami... |
476 477 478 |
*e++ = 2; *cnt += 1; #endif |
1fe80d79c Finally retire cm... |
479 |
#if defined(CONFIG_BOOTP_GATEWAY) |
232c150a2 Add support for S... |
480 481 |
*e++ = 3; /* Router Option */ *cnt += 1; |
3861aa5ce Initial revision |
482 |
#endif |
1fe80d79c Finally retire cm... |
483 |
#if defined(CONFIG_BOOTP_DNS) |
232c150a2 Add support for S... |
484 485 |
*e++ = 6; /* DNS Server(s) */ *cnt += 1; |
3861aa5ce Initial revision |
486 |
#endif |
1fe80d79c Finally retire cm... |
487 |
#if defined(CONFIG_BOOTP_HOSTNAME) |
232c150a2 Add support for S... |
488 489 |
*e++ = 12; /* Hostname */ *cnt += 1; |
3861aa5ce Initial revision |
490 |
#endif |
1fe80d79c Finally retire cm... |
491 |
#if defined(CONFIG_BOOTP_BOOTFILESIZE) |
232c150a2 Add support for S... |
492 493 |
*e++ = 13; /* Boot File Size */ *cnt += 1; |
3861aa5ce Initial revision |
494 |
#endif |
1fe80d79c Finally retire cm... |
495 |
#if defined(CONFIG_BOOTP_BOOTPATH) |
232c150a2 Add support for S... |
496 497 |
*e++ = 17; /* Boot path */ *cnt += 1; |
3861aa5ce Initial revision |
498 |
#endif |
1fe80d79c Finally retire cm... |
499 |
#if defined(CONFIG_BOOTP_NISDOMAIN) |
232c150a2 Add support for S... |
500 501 |
*e++ = 40; /* NIS Domain name request */ *cnt += 1; |
3861aa5ce Initial revision |
502 |
#endif |
1fe80d79c Finally retire cm... |
503 |
#if defined(CONFIG_BOOTP_NTPSERVER) |
ea287debe * Patch by Masami... |
504 505 506 |
*e++ = 42; *cnt += 1; #endif |
258ccd681 net: Fix potentia... |
507 508 509 |
/* no options, so back up to avoid sending an empty request list */ if (*cnt == 0) e -= 2; |
232c150a2 Add support for S... |
510 |
*e++ = 255; /* End of the list */ |
3861aa5ce Initial revision |
511 |
|
232c150a2 Add support for S... |
512 |
/* Pad to minimal length */ |
3861aa5ce Initial revision |
513 |
#ifdef CONFIG_DHCP_MIN_EXT_LEN |
21076f61c Fix bad padding o... |
514 |
while ((e - start) < CONFIG_DHCP_MIN_EXT_LEN) |
232c150a2 Add support for S... |
515 |
*e++ = 0; |
3861aa5ce Initial revision |
516 |
#endif |
232c150a2 Add support for S... |
517 |
return e - start; |
3861aa5ce Initial revision |
518 |
} |
610f2e9c2 net/: Remove ling... |
519 |
#else |
3861aa5ce Initial revision |
520 |
/* |
3090b7e36 net: cosmetic: bo... |
521 |
* Warning: no field size check - change CONFIG_BOOTP_* at your own risk! |
3861aa5ce Initial revision |
522 |
*/ |
3090b7e36 net: cosmetic: bo... |
523 |
static int BootpExtended(u8 *e) |
3861aa5ce Initial revision |
524 |
{ |
232c150a2 Add support for S... |
525 |
u8 *start = e; |
3861aa5ce Initial revision |
526 |
|
232c150a2 Add support for S... |
527 528 529 530 |
*e++ = 99; /* RFC1048 Magic Cookie */ *e++ = 130; *e++ = 83; *e++ = 99; |
3861aa5ce Initial revision |
531 |
|
643d1ab23 net/: Remove obso... |
532 |
#if defined(CONFIG_CMD_DHCP) |
232c150a2 Add support for S... |
533 534 535 536 537 538 |
*e++ = 53; /* DHCP Message Type */ *e++ = 1; *e++ = DHCP_DISCOVER; *e++ = 57; /* Maximum DHCP Message Size */ *e++ = 2; |
f8315731d net: cosmetic: Re... |
539 540 |
*e++ = (576 - 312 + OPT_FIELD_SIZE) >> 16; *e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff; |
610f2e9c2 net/: Remove ling... |
541 |
#endif |
3861aa5ce Initial revision |
542 |
|
7ac2fe2da OMAP: networking ... |
543 544 545 546 547 |
#if defined(CONFIG_BOOTP_VCI_STRING) || \ (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_NET_VCI_STRING)) #ifdef CONFIG_SPL_BUILD put_vci(e, CONFIG_SPL_NET_VCI_STRING); #else |
9ace17c88 net/bootp: add VC... |
548 549 |
put_vci(e, CONFIG_BOOTP_VCI_STRING); #endif |
7ac2fe2da OMAP: networking ... |
550 |
#endif |
9ace17c88 net/bootp: add VC... |
551 |
|
1fe80d79c Finally retire cm... |
552 |
#if defined(CONFIG_BOOTP_SUBNETMASK) |
232c150a2 Add support for S... |
553 554 555 |
*e++ = 1; /* Subnet mask request */ *e++ = 4; e += 4; |
3861aa5ce Initial revision |
556 |
#endif |
1fe80d79c Finally retire cm... |
557 |
#if defined(CONFIG_BOOTP_GATEWAY) |
232c150a2 Add support for S... |
558 559 560 |
*e++ = 3; /* Default gateway request */ *e++ = 4; e += 4; |
3861aa5ce Initial revision |
561 |
#endif |
1fe80d79c Finally retire cm... |
562 |
#if defined(CONFIG_BOOTP_DNS) |
232c150a2 Add support for S... |
563 564 565 |
*e++ = 6; /* Domain Name Server */ *e++ = 4; e += 4; |
3861aa5ce Initial revision |
566 |
#endif |
1fe80d79c Finally retire cm... |
567 |
#if defined(CONFIG_BOOTP_HOSTNAME) |
232c150a2 Add support for S... |
568 569 570 |
*e++ = 12; /* Host name request */ *e++ = 32; e += 32; |
3861aa5ce Initial revision |
571 |
#endif |
1fe80d79c Finally retire cm... |
572 |
#if defined(CONFIG_BOOTP_BOOTFILESIZE) |
232c150a2 Add support for S... |
573 574 575 |
*e++ = 13; /* Boot file size */ *e++ = 2; e += 2; |
3861aa5ce Initial revision |
576 |
#endif |
1fe80d79c Finally retire cm... |
577 |
#if defined(CONFIG_BOOTP_BOOTPATH) |
232c150a2 Add support for S... |
578 579 580 |
*e++ = 17; /* Boot path */ *e++ = 32; e += 32; |
3861aa5ce Initial revision |
581 |
#endif |
1fe80d79c Finally retire cm... |
582 |
#if defined(CONFIG_BOOTP_NISDOMAIN) |
232c150a2 Add support for S... |
583 584 585 |
*e++ = 40; /* NIS Domain name request */ *e++ = 32; e += 32; |
3861aa5ce Initial revision |
586 |
#endif |
09e3a67de bootp: add ntpser... |
587 588 589 590 591 |
#if defined(CONFIG_BOOTP_NTPSERVER) *e++ = 42; *e++ = 4; e += 4; #endif |
3861aa5ce Initial revision |
592 |
|
232c150a2 Add support for S... |
593 |
*e++ = 255; /* End of the list */ |
3861aa5ce Initial revision |
594 |
|
232c150a2 Add support for S... |
595 |
return e - start; |
3861aa5ce Initial revision |
596 |
} |
610f2e9c2 net/: Remove ling... |
597 |
#endif |
3861aa5ce Initial revision |
598 599 |
void |
3090b7e36 net: cosmetic: bo... |
600 |
BootpRequest(void) |
3861aa5ce Initial revision |
601 |
{ |
db288a960 net: Remove volat... |
602 |
uchar *pkt, *iphdr; |
3090b7e36 net: cosmetic: bo... |
603 |
struct Bootp_t *bp; |
ae446f562 net: Refactor boo... |
604 605 |
int extlen, pktlen, iplen; int eth_hdr_size; |
eafc8db0e net: Move MAC-see... |
606 607 608 |
#ifdef CONFIG_BOOTP_RANDOM_DELAY ulong i, rand_ms; #endif |
3861aa5ce Initial revision |
609 |
|
573f14fe4 bootstage: Plumb ... |
610 |
bootstage_mark_name(BOOTSTAGE_ID_BOOTP_START, "bootp_start"); |
643d1ab23 net/: Remove obso... |
611 |
#if defined(CONFIG_CMD_DHCP) |
3861aa5ce Initial revision |
612 613 614 615 |
dhcp_state = INIT; #endif #ifdef CONFIG_BOOTP_RANDOM_DELAY /* Random BOOTP delay */ |
eafc8db0e net: Move MAC-see... |
616 617 |
if (BootpTry == 0) srand_mac(); |
3861aa5ce Initial revision |
618 |
|
eafc8db0e net: Move MAC-see... |
619 620 621 622 |
if (BootpTry <= 2) /* Start with max 1024 * 1ms */ rand_ms = rand() >> (22 - BootpTry); else /* After 3rd BOOTP request max 8192 * 1ms */ rand_ms = rand() >> 19; |
3861aa5ce Initial revision |
623 |
|
eafc8db0e net: Move MAC-see... |
624 625 626 |
printf("Random delay: %ld ms... ", rand_ms); for (i = 0; i < rand_ms; i++) |
3861aa5ce Initial revision |
627 |
udelay(1000); /*Wait 1ms*/ |
3090b7e36 net: cosmetic: bo... |
628 |
|
3861aa5ce Initial revision |
629 630 631 632 633 |
#endif /* CONFIG_BOOTP_RANDOM_DELAY */ printf("BOOTP broadcast %d ", ++BootpTry); pkt = NetTxPacket; |
3090b7e36 net: cosmetic: bo... |
634 |
memset((void *)pkt, 0, PKTSIZE); |
3861aa5ce Initial revision |
635 |
|
ae446f562 net: Refactor boo... |
636 637 |
eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_IP); pkt += eth_hdr_size; |
3861aa5ce Initial revision |
638 639 |
/* |
3090b7e36 net: cosmetic: bo... |
640 641 642 643 |
* Next line results in incorrect packet size being transmitted, * resulting in errors in some DHCP servers, reporting missing bytes. * Size must be set in packet header after extension length has been * determined. |
3861aa5ce Initial revision |
644 645 |
* C. Hallinan, DS4.COM, Inc. */ |
4b11c9166 net: Refactor IP,... |
646 |
/* net_set_udp_header(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, |
3090b7e36 net: cosmetic: bo... |
647 |
sizeof (struct Bootp_t)); */ |
4b11c9166 net: Refactor IP,... |
648 |
iphdr = pkt; /* We need this later for net_set_udp_header() */ |
594c26f8a net: cosmetic: Un... |
649 |
pkt += IP_UDP_HDR_SIZE; |
3861aa5ce Initial revision |
650 |
|
3090b7e36 net: cosmetic: bo... |
651 |
bp = (struct Bootp_t *)pkt; |
3861aa5ce Initial revision |
652 653 654 655 |
bp->bp_op = OP_BOOTREQUEST; bp->bp_htype = HWT_ETHER; bp->bp_hlen = HWL_ETHER; bp->bp_hops = 0; |
49f3bdbba net: express the ... |
656 |
bp->bp_secs = htons(get_timer(0) / 1000); |
3861aa5ce Initial revision |
657 658 659 660 |
NetWriteIP(&bp->bp_ciaddr, 0); NetWriteIP(&bp->bp_yiaddr, 0); NetWriteIP(&bp->bp_siaddr, 0); NetWriteIP(&bp->bp_giaddr, 0); |
3090b7e36 net: cosmetic: bo... |
661 662 |
memcpy(bp->bp_chaddr, NetOurEther, 6); copy_filename(bp->bp_file, BootFile, sizeof(bp->bp_file)); |
3861aa5ce Initial revision |
663 664 |
/* Request additional information from the BOOTP/DHCP server */ |
643d1ab23 net/: Remove obso... |
665 |
#if defined(CONFIG_CMD_DHCP) |
ae446f562 net: Refactor boo... |
666 |
extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0); |
3861aa5ce Initial revision |
667 |
#else |
ae446f562 net: Refactor boo... |
668 |
extlen = BootpExtended((u8 *)bp->bp_vend); |
610f2e9c2 net/: Remove ling... |
669 |
#endif |
3861aa5ce Initial revision |
670 671 672 |
/* * Bootp ID is the lower 4 bytes of our ethernet address |
49f3bdbba net: express the ... |
673 |
* plus the current time in ms. |
3861aa5ce Initial revision |
674 675 676 677 678 679 |
*/ BootpID = ((ulong)NetOurEther[2] << 24) | ((ulong)NetOurEther[3] << 16) | ((ulong)NetOurEther[4] << 8) | (ulong)NetOurEther[5]; BootpID += get_timer(0); |
232c150a2 Add support for S... |
680 |
BootpID = htonl(BootpID); |
3861aa5ce Initial revision |
681 682 683 684 685 686 |
NetCopyLong(&bp->bp_id, &BootpID); /* * Calculate proper packet lengths taking into account the * variable size of the options field */ |
ae446f562 net: Refactor boo... |
687 688 |
iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen; pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen; |
4b11c9166 net: Refactor IP,... |
689 |
net_set_udp_header(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen); |
49f3bdbba net: express the ... |
690 |
NetSetTimeout(SELECT_TIMEOUT, BootpTimeout); |
3861aa5ce Initial revision |
691 |
|
643d1ab23 net/: Remove obso... |
692 |
#if defined(CONFIG_CMD_DHCP) |
3861aa5ce Initial revision |
693 |
dhcp_state = SELECTING; |
ece223b52 net: Refactor to ... |
694 |
net_set_udp_handler(DhcpHandler); |
3861aa5ce Initial revision |
695 |
#else |
ece223b52 net: Refactor to ... |
696 |
net_set_udp_handler(BootpHandler); |
610f2e9c2 net/: Remove ling... |
697 |
#endif |
3861aa5ce Initial revision |
698 699 |
NetSendPacket(NetTxPacket, pktlen); } |
643d1ab23 net/: Remove obso... |
700 |
#if defined(CONFIG_CMD_DHCP) |
3090b7e36 net: cosmetic: bo... |
701 |
static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp) |
3861aa5ce Initial revision |
702 |
{ |
3e38691e8 * Patch by Arun D... |
703 |
uchar *end = popt + BOOTP_HDR_SIZE; |
3861aa5ce Initial revision |
704 |
int oplen, size; |
d8d8724be net/bootp.c: fix ... |
705 706 707 |
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET) int *to_ptr; #endif |
3861aa5ce Initial revision |
708 |
|
232c150a2 Add support for S... |
709 |
while (popt < end && *popt != 0xff) { |
3861aa5ce Initial revision |
710 |
oplen = *(popt + 1); |
232c150a2 Add support for S... |
711 712 |
switch (*popt) { case 1: |
3090b7e36 net: cosmetic: bo... |
713 |
NetCopyIP(&NetOurSubnetMask, (popt + 2)); |
232c150a2 Add support for S... |
714 |
break; |
1fe80d79c Finally retire cm... |
715 |
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET) |
ea287debe * Patch by Masami... |
716 |
case 2: /* Time offset */ |
d8d8724be net/bootp.c: fix ... |
717 |
to_ptr = &NetTimeOffset; |
3090b7e36 net: cosmetic: bo... |
718 719 |
NetCopyLong((ulong *)to_ptr, (ulong *)(popt + 2)); NetTimeOffset = ntohl(NetTimeOffset); |
ea287debe * Patch by Masami... |
720 721 |
break; #endif |
232c150a2 Add support for S... |
722 |
case 3: |
3090b7e36 net: cosmetic: bo... |
723 |
NetCopyIP(&NetOurGatewayIP, (popt + 2)); |
232c150a2 Add support for S... |
724 725 |
break; case 6: |
3090b7e36 net: cosmetic: bo... |
726 |
NetCopyIP(&NetOurDNSIP, (popt + 2)); |
1fe80d79c Finally retire cm... |
727 |
#if defined(CONFIG_BOOTP_DNS2) |
3090b7e36 net: cosmetic: bo... |
728 729 |
if (*(popt + 1) > 4) NetCopyIP(&NetOurDNS2IP, (popt + 2 + 4)); |
fe389a82c - Added CONFIG_BO... |
730 |
#endif |
232c150a2 Add support for S... |
731 732 |
break; case 12: |
3090b7e36 net: cosmetic: bo... |
733 734 735 |
size = truncate_sz("Host Name", sizeof(NetOurHostName), oplen); memcpy(&NetOurHostName, popt + 2, size); |
232c150a2 Add support for S... |
736 737 738 739 740 |
NetOurHostName[size] = 0; break; case 15: /* Ignore Domain Name Option */ break; case 17: |
3090b7e36 net: cosmetic: bo... |
741 742 743 |
size = truncate_sz("Root Path", sizeof(NetOurRootPath), oplen); memcpy(&NetOurRootPath, popt + 2, size); |
232c150a2 Add support for S... |
744 745 |
NetOurRootPath[size] = 0; break; |
ee0f60df0 net: Quietly igno... |
746 747 |
case 28: /* Ignore Broadcast Address Option */ break; |
1fe80d79c Finally retire cm... |
748 |
#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER) |
ea287debe * Patch by Masami... |
749 |
case 42: /* NTP server IP */ |
3090b7e36 net: cosmetic: bo... |
750 |
NetCopyIP(&NetNtpServerIP, (popt + 2)); |
ea287debe * Patch by Masami... |
751 752 |
break; #endif |
232c150a2 Add support for S... |
753 |
case 51: |
3090b7e36 net: cosmetic: bo... |
754 |
NetCopyLong(&dhcp_leasetime, (ulong *) (popt + 2)); |
232c150a2 Add support for S... |
755 756 757 758 |
break; case 53: /* Ignore Message Type Option */ break; case 54: |
3090b7e36 net: cosmetic: bo... |
759 |
NetCopyIP(&NetDHCPServerIP, (popt + 2)); |
232c150a2 Add support for S... |
760 761 762 763 764 |
break; case 58: /* Ignore Renewal Time Option */ break; case 59: /* Ignore Rebinding Time Option */ break; |
3b2e4fd9b Add support for t... |
765 766 767 768 769 770 771 772 773 |
case 66: /* Ignore TFTP server name */ break; case 67: /* vendor opt bootfile */ /* * I can't use dhcp_vendorex_proc here because I need * to write into the bootp packet - even then I had to * pass the bootp packet pointer into here as the * second arg */ |
3090b7e36 net: cosmetic: bo... |
774 |
size = truncate_sz("Opt Boot File", |
3b2e4fd9b Add support for t... |
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 |
sizeof(bp->bp_file), oplen); if (bp->bp_file[0] == '\0' && size > 0) { /* * only use vendor boot file if we didn't * receive a boot file in the main non-vendor * part of the packet - god only knows why * some vendors chose not to use this perfectly * good spot to store the boot file (join on * Tru64 Unix) it seems mind bogglingly crazy * to me */ printf("*** WARNING: using vendor " "optional boot file "); memcpy(bp->bp_file, popt + 2, size); bp->bp_file[size] = '\0'; } break; |
232c150a2 Add support for S... |
794 |
default: |
1fe80d79c Finally retire cm... |
795 |
#if defined(CONFIG_BOOTP_VENDOREX) |
3090b7e36 net: cosmetic: bo... |
796 |
if (dhcp_vendorex_proc(popt)) |
8bde7f776 * Code cleanup: |
797 |
break; |
3861aa5ce Initial revision |
798 |
#endif |
3090b7e36 net: cosmetic: bo... |
799 800 801 |
printf("*** Unhandled DHCP Option in OFFER/ACK:" " %d ", *popt); |
232c150a2 Add support for S... |
802 |
break; |
3861aa5ce Initial revision |
803 804 805 806 807 808 809 |
} popt += oplen + 2; /* Process next option */ } } static int DhcpMessageType(unsigned char *popt) { |
3090b7e36 net: cosmetic: bo... |
810 |
if (NetReadLong((ulong *)popt) != htonl(BOOTP_VENDOR_MAGIC)) |
3861aa5ce Initial revision |
811 812 813 |
return -1; popt += 4; |
3090b7e36 net: cosmetic: bo... |
814 815 |
while (*popt != 0xff) { if (*popt == 53) /* DHCP Message Type */ |
3861aa5ce Initial revision |
816 817 818 819 820 |
return *(popt + 2); popt += *(popt + 1) + 2; /* Scan through all options */ } return -1; } |
3090b7e36 net: cosmetic: bo... |
821 |
static void DhcpSendRequestPkt(struct Bootp_t *bp_offer) |
3861aa5ce Initial revision |
822 |
{ |
db288a960 net: Remove volat... |
823 |
uchar *pkt, *iphdr; |
3090b7e36 net: cosmetic: bo... |
824 |
struct Bootp_t *bp; |
3861aa5ce Initial revision |
825 |
int pktlen, iplen, extlen; |
ae446f562 net: Refactor boo... |
826 |
int eth_hdr_size; |
47cd00fa7 * Patches by Robe... |
827 |
IPaddr_t OfferedIP; |
3861aa5ce Initial revision |
828 |
|
0ebf04c60 minor debug clean... |
829 830 |
debug("DhcpSendRequestPkt: Sending DHCPREQUEST "); |
3861aa5ce Initial revision |
831 |
pkt = NetTxPacket; |
3090b7e36 net: cosmetic: bo... |
832 |
memset((void *)pkt, 0, PKTSIZE); |
3861aa5ce Initial revision |
833 |
|
ae446f562 net: Refactor boo... |
834 835 |
eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_IP); pkt += eth_hdr_size; |
3861aa5ce Initial revision |
836 |
|
3090b7e36 net: cosmetic: bo... |
837 |
iphdr = pkt; /* We'll need this later to set proper pkt size */ |
594c26f8a net: cosmetic: Un... |
838 |
pkt += IP_UDP_HDR_SIZE; |
3861aa5ce Initial revision |
839 |
|
3090b7e36 net: cosmetic: bo... |
840 |
bp = (struct Bootp_t *)pkt; |
3861aa5ce Initial revision |
841 842 843 844 |
bp->bp_op = OP_BOOTREQUEST; bp->bp_htype = HWT_ETHER; bp->bp_hlen = HWL_ETHER; bp->bp_hops = 0; |
49f3bdbba net: express the ... |
845 |
bp->bp_secs = htons(get_timer(0) / 1000); |
3090b7e36 net: cosmetic: bo... |
846 847 |
/* Do not set the client IP, your IP, or server IP yet, since it * hasn't been ACK'ed by the server yet */ |
e5c794e49 DHCP Client Fix |
848 |
|
c66867039 Minor code cleanup. |
849 |
/* |
d82718fed Make bootp implem... |
850 851 852 853 |
* RFC3046 requires Relay Agents to discard packets with * nonzero and offered giaddr */ NetWriteIP(&bp->bp_giaddr, 0); |
3090b7e36 net: cosmetic: bo... |
854 |
memcpy(bp->bp_chaddr, NetOurEther, 6); |
3861aa5ce Initial revision |
855 856 857 858 859 860 861 862 863 864 |
/* * ID is the id of the OFFER packet */ NetCopyLong(&bp->bp_id, &bp_offer->bp_id); /* * Copy options from OFFER packet if present */ |
e5c794e49 DHCP Client Fix |
865 866 867 |
/* Copy offered IP into the parameters request list */ NetCopyIP(&OfferedIP, &bp_offer->bp_yiaddr); |
3090b7e36 net: cosmetic: bo... |
868 869 |
extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST, NetDHCPServerIP, OfferedIP); |
3861aa5ce Initial revision |
870 |
|
ae446f562 net: Refactor boo... |
871 872 |
iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen; pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen; |
4b11c9166 net: Refactor IP,... |
873 |
net_set_udp_header(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen); |
3861aa5ce Initial revision |
874 |
|
d9a2f416d DHCP request fix ... |
875 876 877 |
#ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY); #endif /* CONFIG_BOOTP_DHCP_REQUEST_DELAY */ |
f9623229f net: Move debug t... |
878 879 |
debug("Transmitting DHCPREQUEST packet: len = %d ", pktlen); |
3861aa5ce Initial revision |
880 881 882 883 884 885 886 |
NetSendPacket(NetTxPacket, pktlen); } /* * Handle DHCP received packets. */ static void |
03eb129f8 NET: pass source ... |
887 888 |
DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len) |
3861aa5ce Initial revision |
889 |
{ |
3090b7e36 net: cosmetic: bo... |
890 |
struct Bootp_t *bp = (struct Bootp_t *)pkt; |
3861aa5ce Initial revision |
891 |
|
0ebf04c60 minor debug clean... |
892 893 |
debug("DHCPHandler: got packet: (src=%d, dst=%d, len=%d) state: %d ", |
3861aa5ce Initial revision |
894 |
src, dest, len, dhcp_state); |
3090b7e36 net: cosmetic: bo... |
895 896 |
/* Filter out pkts we don't want */ if (BootpCheckPkt(pkt, dest, src, len)) |
3861aa5ce Initial revision |
897 |
return; |
3090b7e36 net: cosmetic: bo... |
898 899 900 |
debug("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state:" " %d ", src, dest, len, dhcp_state); |
3861aa5ce Initial revision |
901 902 903 904 905 |
switch (dhcp_state) { case SELECTING: /* * Wait an appropriate time for any potential DHCPOFFER packets |
3090b7e36 net: cosmetic: bo... |
906 907 908 |
* to arrive. Then select one, and generate DHCPREQUEST * response. If filename is in format we recognize, assume it * is a valid OFFER from a server we want. |
3861aa5ce Initial revision |
909 |
*/ |
0ebf04c60 minor debug clean... |
910 911 |
debug("DHCP: state=SELECTING bp_file: \"%s\" ", bp->bp_file); |
6d0f6bcf3 rename CFG_ macro... |
912 |
#ifdef CONFIG_SYS_BOOTFILE_PREFIX |
3861aa5ce Initial revision |
913 |
if (strncmp(bp->bp_file, |
6d0f6bcf3 rename CFG_ macro... |
914 |
CONFIG_SYS_BOOTFILE_PREFIX, |
3090b7e36 net: cosmetic: bo... |
915 |
strlen(CONFIG_SYS_BOOTFILE_PREFIX)) == 0) { |
6d0f6bcf3 rename CFG_ macro... |
916 |
#endif /* CONFIG_SYS_BOOTFILE_PREFIX */ |
3861aa5ce Initial revision |
917 |
|
0ebf04c60 minor debug clean... |
918 919 |
debug("TRANSITIONING TO REQUESTING STATE "); |
3861aa5ce Initial revision |
920 |
dhcp_state = REQUESTING; |
759a51b4f Changed DHCP clie... |
921 |
|
3090b7e36 net: cosmetic: bo... |
922 923 |
if (NetReadLong((ulong *)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC)) |
3b2e4fd9b Add support for t... |
924 |
DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp); |
3861aa5ce Initial revision |
925 |
|
49f3bdbba net: express the ... |
926 |
NetSetTimeout(TIMEOUT, BootpTimeout); |
3861aa5ce Initial revision |
927 |
DhcpSendRequestPkt(bp); |
6d0f6bcf3 rename CFG_ macro... |
928 |
#ifdef CONFIG_SYS_BOOTFILE_PREFIX |
3861aa5ce Initial revision |
929 |
} |
6d0f6bcf3 rename CFG_ macro... |
930 |
#endif /* CONFIG_SYS_BOOTFILE_PREFIX */ |
3861aa5ce Initial revision |
931 932 933 934 |
return; break; case REQUESTING: |
0ebf04c60 minor debug clean... |
935 936 |
debug("DHCP State: REQUESTING "); |
3861aa5ce Initial revision |
937 |
|
3090b7e36 net: cosmetic: bo... |
938 939 940 |
if (DhcpMessageType((u8 *)bp->bp_vend) == DHCP_ACK) { if (NetReadLong((ulong *)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC)) |
3b2e4fd9b Add support for t... |
941 |
DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp); |
3090b7e36 net: cosmetic: bo... |
942 943 |
/* Store net params from reply */ BootpCopyNetParams(bp); |
3861aa5ce Initial revision |
944 |
dhcp_state = BOUND; |
3090b7e36 net: cosmetic: bo... |
945 946 947 |
printf("DHCP client bound to address %pI4 ", &NetOurIP); |
573f14fe4 bootstage: Plumb ... |
948 |
bootstage_mark_name(BOOTSTAGE_ID_BOOTP_STOP, |
3090b7e36 net: cosmetic: bo... |
949 |
"bootp_stop"); |
3861aa5ce Initial revision |
950 |
|
e4a3d57dc net: Export auto_... |
951 |
net_auto_load(); |
3861aa5ce Initial revision |
952 953 954 |
return; } break; |
51dfe1382 Fix bogus error m... |
955 956 957 |
case BOUND: /* DHCP client bound to address */ break; |
3861aa5ce Initial revision |
958 |
default: |
3090b7e36 net: cosmetic: bo... |
959 960 |
puts("DHCP: INVALID STATE "); |
3861aa5ce Initial revision |
961 962 963 964 965 966 967 968 969 |
break; } } void DhcpRequest(void) { BootpRequest(); } |
992742a5b Cleanup coding st... |
970 |
#endif /* CONFIG_CMD_DHCP */ |