]>
git.ipfire.org Git - people/ms/u-boot.git/blob - net/bootp.c
2 * Based on LiMon - BOOTP.
4 * Copyright 1994, 1995, 2000 Neil Russell.
6 * Copyright 2000 Roland Borde
7 * Copyright 2000 Paolo Scaffardi
8 * Copyright 2000-2002 Wolfgang Denk, wd@denx.de
12 #define DEBUG 1 /* general debug */
13 #define DEBUG_BOOTP_EXT 1 /* Debug received vendor fields */
16 #ifdef DEBUG_BOOTP_EXT
17 #define debug_ext(fmt,args...) printf (fmt ,##args)
19 #define debug_ext(fmt,args...)
28 #ifdef CONFIG_STATUS_LED
29 #include <status_led.h>
32 #define BOOTP_VENDOR_MAGIC 0x63825363 /* RFC1048 Magic Cookie */
34 #if (CONFIG_COMMANDS & CFG_CMD_NET)
36 #define TIMEOUT 5 /* Seconds before trying BOOTP again */
37 #ifndef CONFIG_NET_RETRY_COUNT
38 # define TIMEOUT_COUNT 5 /* # of timeouts before giving up */
40 # define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT)
43 #define PORT_BOOTPS 67 /* BOOTP server UDP port */
44 #define PORT_BOOTPC 68 /* BOOTP client UDP port */
46 #ifndef CONFIG_DHCP_MIN_EXT_LEN /* minimal length of extension list */
47 #define CONFIG_DHCP_MIN_EXT_LEN 64
52 #ifdef CONFIG_BOOTP_RANDOM_DELAY
56 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
57 dhcp_state_t dhcp_state
= INIT
;
58 unsigned int dhcp_leasetime
= 0;
59 static void DhcpHandler(uchar
* pkt
, unsigned dest
, unsigned src
, unsigned len
);
62 char *dhcpmsg2str(int type
)
65 case 1: return "DHCPDISCOVER"; break;
66 case 2: return "DHCPOFFER"; break;
67 case 3: return "DHCPREQUEST"; break;
68 case 4: return "DHCPDECLINE"; break;
69 case 5: return "DHCPACK"; break;
70 case 6: return "DHCPNACK"; break;
71 case 7: return "DHCPRELEASE"; break;
72 default: return "UNKNOWN/INVALID MSG TYPE"; break;
76 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
77 extern u8
*dhcp_vendorex_prep (u8
*e
); /*rtn new e after add own opts. */
78 extern u8
*dhcp_vendorex_proc (u8
*e
); /*rtn next e if mine,else NULL */
81 #endif /* CFG_CMD_DHCP */
83 static int BootpCheckPkt(uchar
*pkt
, unsigned dest
, unsigned src
, unsigned len
)
85 Bootp_t
*bp
= (Bootp_t
*) pkt
;
88 if (dest
!= PORT_BOOTPC
|| src
!= PORT_BOOTPS
)
90 else if (len
< sizeof (Bootp_t
) - OPT_SIZE
)
92 else if (bp
->bp_op
!= OP_BOOTREQUEST
&&
93 bp
->bp_op
!= OP_BOOTREPLY
&&
94 bp
->bp_op
!= DHCP_OFFER
&&
95 bp
->bp_op
!= DHCP_ACK
&&
96 bp
->bp_op
!= DHCP_NAK
) {
99 else if (bp
->bp_htype
!= HWT_ETHER
)
101 else if (bp
->bp_hlen
!= HWL_ETHER
)
103 else if (NetReadLong((ulong
*)&bp
->bp_id
) != BootpID
) {
107 debug ("Filtering pkt = %d\n", retval
);
113 * Copy parameters of interest from BOOTP_REPLY/DHCP_OFFER packet
115 void BootpCopyNetParams(Bootp_t
*bp
)
117 NetCopyIP(&NetOurIP
, &bp
->bp_yiaddr
);
118 NetCopyIP(&NetServerIP
, &bp
->bp_siaddr
);
119 memcpy (NetServerEther
, ((Ethernet_t
*)NetRxPkt
)->et_src
, 6);
120 copy_filename (BootFile
, bp
->bp_file
, sizeof(BootFile
));
122 debug ("Bootfile: %s\n", BootFile
);
124 /* Propagate to environment:
125 * don't delete exising entry when BOOTP / DHCP reply does
126 * not contain a new value
129 setenv ("bootfile", BootFile
);
133 static int truncate_sz (const char *name
, int maxlen
, int curlen
)
135 if (curlen
>= maxlen
) {
136 printf("*** WARNING: %s is too long (%d - max: %d) - truncated\n",
137 name
, curlen
, maxlen
);
143 #if !(CONFIG_COMMANDS & CFG_CMD_DHCP)
145 static void BootpVendorFieldProcess(u8
*ext
)
147 int size
= *(ext
+1) ;
149 debug_ext ("[BOOTP] Processing extension %d... (%d bytes)\n", *ext
, *(ext
+1));
154 /* Fixed length fields */
155 case 1: /* Subnet mask */
156 if (NetOurSubnetMask
== 0)
157 NetCopyIP(&NetOurSubnetMask
, (IPaddr_t
*)(ext
+2));
159 case 2: /* Time offset - Not yet supported */
161 /* Variable length fields */
162 case 3: /* Gateways list */
163 if (NetOurGatewayIP
== 0) {
164 NetCopyIP(&NetOurGatewayIP
, (IPaddr_t
*)(ext
+2));
167 case 4: /* Time server - Not yet supported */
169 case 5: /* IEN-116 name server - Not yet supported */
172 if (NetOurDNSIP
== 0) {
173 NetCopyIP(&NetOurDNSIP
, (IPaddr_t
*)(ext
+2));
176 case 7: /* Log server - Not yet supported */
178 case 8: /* Cookie/Quote server - Not yet supported */
180 case 9: /* LPR server - Not yet supported */
182 case 10: /* Impress server - Not yet supported */
184 case 11: /* RPL server - Not yet supported */
186 case 12: /* Host name */
187 if (NetOurHostName
[0] == 0) {
188 size
= truncate_sz("Host Name", sizeof(NetOurHostName
), size
);
189 memcpy(&NetOurHostName
, ext
+2, size
);
190 NetOurHostName
[size
] = 0 ;
193 case 13: /* Boot file size */
195 NetBootFileSize
= ntohs(*(ushort
*)(ext
+2));
197 NetBootFileSize
= ntohl(*(ulong
*)(ext
+2));
199 case 14: /* Merit dump file - Not yet supported */
201 case 15: /* Domain name - Not yet supported */
203 case 16: /* Swap server - Not yet supported */
205 case 17: /* Root path */
206 if (NetOurRootPath
[0] == 0) {
207 size
= truncate_sz("Root Path", sizeof(NetOurRootPath
), size
);
208 memcpy(&NetOurRootPath
, ext
+2, size
);
209 NetOurRootPath
[size
] = 0 ;
212 case 18: /* Extension path - Not yet supported */
214 * This can be used to send the informations of the
215 * vendor area in another file that the client can
219 /* IP host layer fields */
220 case 40: /* NIS Domain name */
221 if (NetOurNISDomain
[0] == 0) {
222 size
= truncate_sz ("NIS Domain Name",
223 sizeof(NetOurNISDomain
),
225 memcpy(&NetOurNISDomain
, ext
+2, size
);
226 NetOurNISDomain
[size
] = 0 ;
229 /* Application layer fields */
230 case 43: /* Vendor specific info - Not yet supported */
232 * Binary informations to exchange specific
233 * product information.
236 /* Reserved (custom) fields (128..254) */
240 static void BootpVendorProcess(u8
*ext
, int size
)
242 u8
*end
= ext
+ size
;
244 debug_ext ("[BOOTP] Checking extension (%d bytes)...\n", size
);
246 while ((ext
< end
) && (*ext
!= 0xff)) {
253 BootpVendorFieldProcess (opt
) ;
257 #ifdef DEBUG_BOOTP_EXT
258 printf("[BOOTP] Received fields: \n");
259 if (NetOurSubnetMask
) {
260 puts ("NetOurSubnetMask : ");
261 print_IPaddr (NetOurSubnetMask
);
265 if (NetOurGatewayIP
) {
266 puts ("NetOurGatewayIP : ");
267 print_IPaddr (NetOurGatewayIP
);
271 if (NetBootFileSize
) {
272 printf("NetBootFileSize : %d\n", NetBootFileSize
);
275 if (NetOurHostName
[0]) {
276 printf("NetOurHostName : %s\n", NetOurHostName
);
279 if (NetOurRootPath
[0]) {
280 printf("NetOurRootPath : %s\n", NetOurRootPath
);
283 if (NetOurNISDomain
[0]) {
284 printf("NetOurNISDomain : %s\n", NetOurNISDomain
);
287 if (NetBootFileSize
) {
288 printf("NetBootFileSize: %d\n", NetBootFileSize
);
290 #endif /* DEBUG_BOOTP_EXT */
294 * Handle a BOOTP received packet.
297 BootpHandler(uchar
* pkt
, unsigned dest
, unsigned src
, unsigned len
)
302 debug ("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%d)\n",
303 src
, dest
, len
, sizeof (Bootp_t
));
307 if (BootpCheckPkt(pkt
, dest
, src
, len
)) /* Filter out pkts we don't want */
311 * Got a good BOOTP reply. Copy the data into our variables.
313 #ifdef CONFIG_STATUS_LED
314 status_led_set (STATUS_LED_BOOT
, STATUS_LED_OFF
);
317 BootpCopyNetParams(bp
); /* Store net parameters from reply */
319 /* Retrieve extended information (we must parse the vendor area) */
320 if (NetReadLong((ulong
*)&bp
->bp_vend
[0]) == htonl(BOOTP_VENDOR_MAGIC
))
321 BootpVendorProcess(&bp
->bp_vend
[4], len
);
323 NetSetTimeout(0, (thand_f
*)0);
325 debug ("Got good BOOTP\n");
327 if (((s
= getenv("autoload")) != NULL
) && (*s
== 'n')) {
329 * Just use BOOTP to configure system;
330 * Do not use TFTP to load the bootfile.
332 NetState
= NETLOOP_SUCCESS
;
336 /* Send ARP request to get TFTP server ethernet address.
337 * This automagically starts TFTP, too.
341 #endif /* !CFG_CMD_DHCP */
344 * Timeout on BOOTP/DHCP request.
349 if (BootpTry
>= TIMEOUT_COUNT
) {
350 puts ("\nRetry count exceeded; starting again\n");
353 NetSetTimeout (TIMEOUT
* CFG_HZ
, BootpTimeout
);
359 * Initialize BOOTP extension fields in the request.
361 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
362 static int DhcpExtended(u8
*e
, int message_type
, IPaddr_t ServerID
, IPaddr_t RequestedIP
)
366 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
370 *e
++ = 99; /* RFC1048 Magic Cookie */
375 *e
++ = 53; /* DHCP Message Type */
379 *e
++ = 57; /* Maximum DHCP Message Size */
381 *e
++ = (576-312+OPT_SIZE
) >> 8;
382 *e
++ = (576-312+OPT_SIZE
) & 0xff;
385 int tmp
= ntohl(ServerID
);
387 *e
++ = 54; /* ServerID */
396 int tmp
= ntohl(RequestedIP
);
398 *e
++ = 50; /* Requested IP */
406 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
407 if ((x
= dhcp_vendorex_prep (e
)))
411 *e
++ = 55; /* Parameter Request List */
412 cnt
= e
++; /* Pointer to count of requested items */
414 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_SUBNETMASK)
415 *e
++ = 1; /* Subnet Mask */
418 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_GATEWAY)
419 *e
++ = 3; /* Router Option */
422 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS)
423 *e
++ = 6; /* DNS Server(s) */
426 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_HOSTNAME)
427 *e
++ = 12; /* Hostname */
430 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_BOOTFILESIZE)
431 *e
++ = 13; /* Boot File Size */
434 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_BOOTPATH)
435 *e
++ = 17; /* Boot path */
438 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_NISDOMAIN)
439 *e
++ = 40; /* NIS Domain name request */
442 *e
++ = 255; /* End of the list */
444 /* Pad to minimal length */
445 #ifdef CONFIG_DHCP_MIN_EXT_LEN
446 while ((e
- start
) <= CONFIG_DHCP_MIN_EXT_LEN
)
453 #else /* CFG_CMD_DHCP */
455 * Warning: no field size check - change CONFIG_BOOTP_MASK at your own risk!
457 static int BootpExtended (u8
*e
)
461 *e
++ = 99; /* RFC1048 Magic Cookie */
466 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
467 *e
++ = 53; /* DHCP Message Type */
469 *e
++ = DHCP_DISCOVER
;
471 *e
++ = 57; /* Maximum DHCP Message Size */
473 *e
++ = (576-312+OPT_SIZE
) >> 16;
474 *e
++ = (576-312+OPT_SIZE
) & 0xff;
475 #endif /* CFG_CMD_DHCP */
477 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_SUBNETMASK)
478 *e
++ = 1; /* Subnet mask request */
483 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_GATEWAY)
484 *e
++ = 3; /* Default gateway request */
489 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS)
490 *e
++ = 6; /* Domain Name Server */
495 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_HOSTNAME)
496 *e
++ = 12; /* Host name request */
501 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_BOOTFILESIZE)
502 *e
++ = 13; /* Boot file size */
507 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_BOOTPATH)
508 *e
++ = 17; /* Boot path */
513 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_NISDOMAIN)
514 *e
++ = 40; /* NIS Domain name request */
519 *e
++ = 255; /* End of the list */
523 #endif /* CFG_CMD_DHCP */
528 volatile uchar
*pkt
, *iphdr
;
530 int ext_len
, pktlen
, iplen
;
532 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
536 #ifdef CONFIG_BOOTP_RANDOM_DELAY /* Random BOOTP delay */
537 unsigned char bi_enetaddr
[6];
541 ulong tst1
, tst2
, sum
, m_mask
, m_value
= 0;
545 reg
= getenv_r ("ethaddr", tmp
, sizeof(tmp
));
546 s
= (reg
> 0) ? tmp
: NULL
;
548 for (reg
=0; reg
<6; ++reg
) {
549 bi_enetaddr
[reg
] = s
? simple_strtoul(s
, &e
, 16) : 0;
555 printf("BootpRequest => Our Mac: ");
556 for (reg
=0; reg
<6; reg
++) {
559 reg
==5 ? '\n' : ':');
563 /* Mac-Manipulation 2 get seed1 */
566 for (reg
=2; reg
<6; reg
++) {
568 tst1
= tst1
| bi_enetaddr
[reg
];
570 for (reg
=0; reg
<2; reg
++) {
571 tst2
= tst2
| bi_enetaddr
[reg
];
579 for (reg
=1;reg
<=32;reg
++) {
580 m_value
|= (m_mask
& seed1
);
582 m_value
= m_value
<< 1;
588 /* Random Number Generator */
590 for (reg
=0;reg
<=0;reg
++) {
592 if (sum
< seed1
|| sum
< seed2
)
597 if (BootpTry
<=2) { /* Start with max 1024 * 1ms */
598 sum
= sum
>> (22-BootpTry
);
599 } else { /*After 3rd BOOTP request max 8192 * 1ms */
604 printf ("Random delay: %ld ms...\n", sum
);
605 for (reg
=0; reg
<sum
; reg
++) {
606 udelay(1000); /*Wait 1ms*/
608 #endif /* CONFIG_BOOTP_RANDOM_DELAY */
610 printf("BOOTP broadcast %d\n", ++BootpTry
);
612 memset ((void*)pkt
, 0, PKTSIZE
);
614 NetSetEther(pkt
, NetBcastAddr
, PROT_IP
);
615 pkt
+= ETHER_HDR_SIZE
;
618 * Next line results in incorrect packet size being transmitted, resulting
619 * in errors in some DHCP servers, reporting missing bytes. Size must be
620 * set in packet header after extension length has been determined.
621 * C. Hallinan, DS4.COM, Inc.
623 /* NetSetIP(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, sizeof (Bootp_t)); */
624 iphdr
= pkt
; /* We need this later for NetSetIP() */
628 bp
->bp_op
= OP_BOOTREQUEST
;
629 bp
->bp_htype
= HWT_ETHER
;
630 bp
->bp_hlen
= HWL_ETHER
;
632 bp
->bp_secs
= htons(get_timer(0) / CFG_HZ
);
633 NetWriteIP(&bp
->bp_ciaddr
, 0);
634 NetWriteIP(&bp
->bp_yiaddr
, 0);
635 NetWriteIP(&bp
->bp_siaddr
, 0);
636 NetWriteIP(&bp
->bp_giaddr
, 0);
637 memcpy (bp
->bp_chaddr
, NetOurEther
, 6);
638 copy_filename (bp
->bp_file
, BootFile
, sizeof(bp
->bp_file
));
640 /* Request additional information from the BOOTP/DHCP server */
641 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
642 ext_len
= DhcpExtended(bp
->bp_vend
, DHCP_DISCOVER
, 0, 0);
644 ext_len
= BootpExtended(bp
->bp_vend
);
645 #endif /* CFG_CMD_DHCP */
648 * Bootp ID is the lower 4 bytes of our ethernet address
649 * plus the current time in HZ.
651 BootpID
= ((ulong
)NetOurEther
[2] << 24)
652 | ((ulong
)NetOurEther
[3] << 16)
653 | ((ulong
)NetOurEther
[4] << 8)
654 | (ulong
)NetOurEther
[5];
655 BootpID
+= get_timer(0);
656 BootpID
= htonl(BootpID
);
657 NetCopyLong(&bp
->bp_id
, &BootpID
);
660 * Calculate proper packet lengths taking into account the
661 * variable size of the options field
663 pktlen
= BOOTP_SIZE
- sizeof(bp
->bp_vend
) + ext_len
;
664 iplen
= BOOTP_HDR_SIZE
- sizeof(bp
->bp_vend
) + ext_len
;
665 NetSetIP(iphdr
, 0xFFFFFFFFL
, PORT_BOOTPS
, PORT_BOOTPC
, iplen
);
666 NetSetTimeout(SELECT_TIMEOUT
* CFG_HZ
, BootpTimeout
);
668 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
669 dhcp_state
= SELECTING
;
670 NetSetHandler(DhcpHandler
);
672 NetSetHandler(BootpHandler
);
673 #endif /* CFG_CMD_DHCP */
674 NetSendPacket(NetTxPacket
, pktlen
);
677 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
678 void DhcpOptionsProcess(char *popt
)
680 char *end
= popt
+ BOOTP_HDR_SIZE
;
683 while ( popt
< end
&& *popt
!= 0xff ) {
687 NetCopyIP(&NetOurSubnetMask
, (popt
+2));
690 NetCopyIP(&NetOurGatewayIP
, (popt
+2));
693 NetCopyIP(&NetOurDNSIP
, (popt
+2));
696 size
= truncate_sz ("Host Name",
697 sizeof(NetOurHostName
),
699 memcpy(&NetOurHostName
, popt
+2, size
);
700 NetOurHostName
[size
] = 0 ;
702 case 15: /* Ignore Domain Name Option */
705 size
= truncate_sz ("Root Path",
706 sizeof(NetOurRootPath
),
708 memcpy(&NetOurRootPath
, popt
+2, size
);
709 NetOurRootPath
[size
] = 0 ;
712 dhcp_leasetime
= *(unsigned int *)(popt
+ 2);
714 case 53: /* Ignore Message Type Option */
717 NetCopyIP(&NetServerIP
, (popt
+2));
719 case 58: /* Ignore Renewal Time Option */
721 case 59: /* Ignore Rebinding Time Option */
724 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
725 if (dhcp_vendorex_proc(popt
))
728 printf("*** Unhandled DHCP Option in OFFER/ACK: %d\n",
732 popt
+= oplen
+ 2; /* Process next option */
736 static int DhcpMessageType(unsigned char *popt
)
738 if (NetReadLong((ulong
*)popt
) != htonl(BOOTP_VENDOR_MAGIC
))
742 while ( *popt
!= 0xff ) {
743 if ( *popt
== 53 ) /* DHCP Message Type */
745 popt
+= *(popt
+ 1) + 2; /* Scan through all options */
750 void DhcpSendRequestPkt(Bootp_t
*bp_offer
)
752 volatile uchar
*pkt
, *iphdr
;
754 int pktlen
, iplen
, extlen
;
756 debug ("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
758 memset ((void*)pkt
, 0, PKTSIZE
);
760 NetSetEther(pkt
, NetBcastAddr
, PROT_IP
);
761 pkt
+= ETHER_HDR_SIZE
;
763 iphdr
= pkt
; /* We'll need this later to set proper pkt size */
767 bp
->bp_op
= OP_BOOTREQUEST
;
768 bp
->bp_htype
= HWT_ETHER
;
769 bp
->bp_hlen
= HWL_ETHER
;
771 bp
->bp_secs
= htons(get_timer(0) / CFG_HZ
);
772 NetCopyIP(&bp
->bp_ciaddr
, &bp_offer
->bp_ciaddr
); /* both in network byte order */
773 NetCopyIP(&bp
->bp_yiaddr
, &bp_offer
->bp_yiaddr
);
774 NetCopyIP(&bp
->bp_siaddr
, &bp_offer
->bp_siaddr
);
775 NetCopyIP(&bp
->bp_giaddr
, &bp_offer
->bp_giaddr
);
776 memcpy (bp
->bp_chaddr
, NetOurEther
, 6);
779 * ID is the id of the OFFER packet
782 NetCopyLong(&bp
->bp_id
, &bp_offer
->bp_id
);
785 * Copy options from OFFER packet if present
787 extlen
= DhcpExtended(bp
->bp_vend
, DHCP_REQUEST
, NetServerIP
, bp
->bp_yiaddr
);
789 pktlen
= BOOTP_SIZE
- sizeof(bp
->bp_vend
) + extlen
;
790 iplen
= BOOTP_HDR_SIZE
- sizeof(bp
->bp_vend
) + extlen
;
791 NetSetIP(iphdr
, 0xFFFFFFFFL
, PORT_BOOTPS
, PORT_BOOTPC
, iplen
);
793 debug ("Transmitting DHCPREQUEST packet: len = %d\n", pktlen
);
794 NetSendPacket(NetTxPacket
, pktlen
);
798 * Handle DHCP received packets.
801 DhcpHandler(uchar
* pkt
, unsigned dest
, unsigned src
, unsigned len
)
803 Bootp_t
*bp
= (Bootp_t
*)pkt
;
805 debug ("DHCPHandler: got packet: (src=%d, dst=%d, len=%d) state: %d\n",
806 src
, dest
, len
, dhcp_state
);
808 if (BootpCheckPkt(pkt
, dest
, src
, len
)) /* Filter out pkts we don't want */
811 debug ("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state: %d\n",
812 src
, dest
, len
, dhcp_state
);
814 switch (dhcp_state
) {
817 * Wait an appropriate time for any potential DHCPOFFER packets
818 * to arrive. Then select one, and generate DHCPREQUEST response.
819 * If filename is in format we recognize, assume it is a valid
820 * OFFER from a server we want.
822 debug ("DHCP: state=SELECTING bp_file: \"%s\"\n", bp
->bp_file
);
823 #ifdef CFG_BOOTFILE_PREFIX
824 if (strncmp(bp
->bp_file
,
826 strlen(CFG_BOOTFILE_PREFIX
)) == 0 ) {
827 #endif /* CFG_BOOTFILE_PREFIX */
829 debug ("TRANSITIONING TO REQUESTING STATE\n");
830 dhcp_state
= REQUESTING
;
832 if (NetReadLong((ulong
*)&bp
->bp_vend
[0]) == htonl(BOOTP_VENDOR_MAGIC
))
833 DhcpOptionsProcess(&bp
->bp_vend
[4]);
836 BootpCopyNetParams(bp
); /* Store net params from reply */
838 NetSetTimeout(TIMEOUT
* CFG_HZ
, BootpTimeout
);
839 DhcpSendRequestPkt(bp
);
840 #ifdef CFG_BOOTFILE_PREFIX
842 #endif /* CFG_BOOTFILE_PREFIX */
847 debug ("DHCP State: REQUESTING\n");
849 if ( DhcpMessageType(bp
->bp_vend
) == DHCP_ACK
) {
852 if (NetReadLong((ulong
*)&bp
->bp_vend
[0]) == htonl(BOOTP_VENDOR_MAGIC
))
853 DhcpOptionsProcess(&bp
->bp_vend
[4]);
854 BootpCopyNetParams(bp
); /* Store net params from reply */
856 printf("DHCP client bound to address ");
857 print_IPaddr(NetOurIP
);
860 /* Obey the 'autoload' setting */
861 if (((s
= getenv("autoload")) != NULL
) && (*s
== 'n')) {
862 NetState
= NETLOOP_SUCCESS
;
865 /* Send ARP request to get TFTP server ethernet address.
866 * This automagically starts TFTP, too.
873 printf("DHCP: INVALID STATE\n");
879 void DhcpRequest(void)
883 #endif /* CFG_CMD_DHCP */
885 #endif /* CFG_CMD_NET */