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-2004 Wolfgang Denk, wd@denx.de
17 #ifdef CONFIG_STATUS_LED
18 #include <status_led.h>
21 #define BOOTP_VENDOR_MAGIC 0x63825363 /* RFC1048 Magic Cookie */
23 #define TIMEOUT 5000UL /* Milliseconds before trying BOOTP again */
24 #ifndef CONFIG_NET_RETRY_COUNT
25 # define TIMEOUT_COUNT 5 /* # of timeouts before giving up */
27 # define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT)
30 #define PORT_BOOTPS 67 /* BOOTP server UDP port */
31 #define PORT_BOOTPC 68 /* BOOTP client UDP port */
33 #ifndef CONFIG_DHCP_MIN_EXT_LEN /* minimal length of extension list */
34 #define CONFIG_DHCP_MIN_EXT_LEN 64
39 #ifdef CONFIG_BOOTP_RANDOM_DELAY
43 #if defined(CONFIG_CMD_DHCP)
44 dhcp_state_t dhcp_state = INIT;
45 unsigned long dhcp_leasetime = 0;
46 IPaddr_t NetDHCPServerIP = 0;
47 static void DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len);
51 static char *dhcpmsg2str(int type)
54 case 1: return "DHCPDISCOVER"; break;
55 case 2: return "DHCPOFFER"; break;
56 case 3: return "DHCPREQUEST"; break;
57 case 4: return "DHCPDECLINE"; break;
58 case 5: return "DHCPACK"; break;
59 case 6: return "DHCPNACK"; break;
60 case 7: return "DHCPRELEASE"; break;
61 default: return "UNKNOWN/INVALID MSG TYPE"; break;
66 #if defined(CONFIG_BOOTP_VENDOREX)
67 extern u8 *dhcp_vendorex_prep (u8 *e); /*rtn new e after add own opts. */
68 extern u8 *dhcp_vendorex_proc (u8 *e); /*rtn next e if mine,else NULL */
73 static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
75 Bootp_t *bp = (Bootp_t *) pkt;
78 if (dest != PORT_BOOTPC || src != PORT_BOOTPS)
80 else if (len < sizeof (Bootp_t) - OPT_SIZE)
82 else if (bp->bp_op != OP_BOOTREQUEST &&
83 bp->bp_op != OP_BOOTREPLY &&
84 bp->bp_op != DHCP_OFFER &&
85 bp->bp_op != DHCP_ACK &&
86 bp->bp_op != DHCP_NAK ) {
89 else if (bp->bp_htype != HWT_ETHER)
91 else if (bp->bp_hlen != HWL_ETHER)
93 else if (NetReadLong((ulong*)&bp->bp_id) != BootpID) {
97 debug("Filtering pkt = %d\n", retval);
103 * Copy parameters of interest from BOOTP_REPLY/DHCP_OFFER packet
105 static void BootpCopyNetParams(Bootp_t *bp)
109 NetCopyIP(&NetOurIP, &bp->bp_yiaddr);
110 #if !defined(CONFIG_BOOTP_SERVERIP)
111 NetCopyIP(&tmp_ip, &bp->bp_siaddr);
113 NetCopyIP(&NetServerIP, &bp->bp_siaddr);
114 memcpy (NetServerEther, ((Ethernet_t *)NetRxPacket)->et_src, 6);
116 if (strlen(bp->bp_file) > 0)
117 copy_filename (BootFile, bp->bp_file, sizeof(BootFile));
119 debug("Bootfile: %s\n", BootFile);
121 /* Propagate to environment:
122 * don't delete exising entry when BOOTP / DHCP reply does
123 * not contain a new value
126 setenv ("bootfile", BootFile);
130 static int truncate_sz (const char *name, int maxlen, int curlen)
132 if (curlen >= maxlen) {
133 printf("*** WARNING: %s is too long (%d - max: %d) - truncated\n",
134 name, curlen, maxlen);
140 #if !defined(CONFIG_CMD_DHCP)
142 static void BootpVendorFieldProcess (u8 * ext)
144 int size = *(ext + 1);
146 debug("[BOOTP] Processing extension %d... (%d bytes)\n", *ext,
152 /* Fixed length fields */
153 case 1: /* Subnet mask */
154 if (NetOurSubnetMask == 0)
155 NetCopyIP (&NetOurSubnetMask, (IPaddr_t *) (ext + 2));
157 case 2: /* Time offset - Not yet supported */
159 /* Variable length fields */
160 case 3: /* Gateways list */
161 if (NetOurGatewayIP == 0) {
162 NetCopyIP (&NetOurGatewayIP, (IPaddr_t *) (ext + 2));
165 case 4: /* Time server - Not yet supported */
167 case 5: /* IEN-116 name server - Not yet supported */
170 if (NetOurDNSIP == 0) {
171 NetCopyIP (&NetOurDNSIP, (IPaddr_t *) (ext + 2));
173 #if defined(CONFIG_BOOTP_DNS2)
174 if ((NetOurDNS2IP == 0) && (size > 4)) {
175 NetCopyIP (&NetOurDNS2IP, (IPaddr_t *) (ext + 2 + 4));
179 case 7: /* Log server - Not yet supported */
181 case 8: /* Cookie/Quote server - Not yet supported */
183 case 9: /* LPR server - Not yet supported */
185 case 10: /* Impress server - Not yet supported */
187 case 11: /* RPL server - Not yet supported */
189 case 12: /* Host name */
190 if (NetOurHostName[0] == 0) {
191 size = truncate_sz ("Host Name", sizeof (NetOurHostName), size);
192 memcpy (&NetOurHostName, ext + 2, size);
193 NetOurHostName[size] = 0;
196 case 13: /* Boot file size */
198 NetBootFileSize = ntohs (*(ushort *) (ext + 2));
200 NetBootFileSize = ntohl (*(ulong *) (ext + 2));
202 case 14: /* Merit dump file - Not yet supported */
204 case 15: /* Domain name - Not yet supported */
206 case 16: /* Swap server - Not yet supported */
208 case 17: /* Root path */
209 if (NetOurRootPath[0] == 0) {
210 size = truncate_sz ("Root Path", sizeof (NetOurRootPath), size);
211 memcpy (&NetOurRootPath, ext + 2, size);
212 NetOurRootPath[size] = 0;
215 case 18: /* Extension path - Not yet supported */
217 * This can be used to send the information of the
218 * vendor area in another file that the client can
222 /* IP host layer fields */
223 case 40: /* NIS Domain name */
224 if (NetOurNISDomain[0] == 0) {
225 size = truncate_sz ("NIS Domain Name", sizeof (NetOurNISDomain), size);
226 memcpy (&NetOurNISDomain, ext + 2, size);
227 NetOurNISDomain[size] = 0;
230 /* Application layer fields */
231 case 43: /* Vendor specific info - Not yet supported */
233 * Binary information to exchange specific
234 * product information.
237 /* Reserved (custom) fields (128..254) */
241 static void BootpVendorProcess (u8 * ext, int size)
243 u8 *end = ext + size;
245 debug("[BOOTP] Checking extension (%d bytes)...\n", size);
247 while ((ext < end) && (*ext != 0xff)) {
255 BootpVendorFieldProcess (opt);
259 debug("[BOOTP] Received fields: \n");
260 if (NetOurSubnetMask)
261 debug("NetOurSubnetMask : %pI4\n", &NetOurSubnetMask);
264 debug("NetOurGatewayIP : %pI4", &NetOurGatewayIP);
267 debug("NetBootFileSize : %d\n", NetBootFileSize);
269 if (NetOurHostName[0])
270 debug("NetOurHostName : %s\n", NetOurHostName);
272 if (NetOurRootPath[0])
273 debug("NetOurRootPath : %s\n", NetOurRootPath);
275 if (NetOurNISDomain[0])
276 debug("NetOurNISDomain : %s\n", NetOurNISDomain);
279 debug("NetBootFileSize: %d\n", NetBootFileSize);
282 * Handle a BOOTP received packet.
285 BootpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
290 debug("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%zu)\n",
291 src, dest, len, sizeof (Bootp_t));
295 if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */
299 * Got a good BOOTP reply. Copy the data into our variables.
301 #ifdef CONFIG_STATUS_LED
302 status_led_set (STATUS_LED_BOOT, STATUS_LED_OFF);
305 BootpCopyNetParams(bp); /* Store net parameters from reply */
307 /* Retrieve extended information (we must parse the vendor area) */
308 if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
309 BootpVendorProcess((uchar *)&bp->bp_vend[4], len);
311 NetSetTimeout(0, (thand_f *)0);
313 debug("Got good BOOTP\n");
315 if ((s = getenv("autoload")) != NULL) {
318 * Just use BOOTP to configure system;
319 * Do not use TFTP to load the bootfile.
321 NetState = NETLOOP_SUCCESS;
323 #if defined(CONFIG_CMD_NFS)
324 } else if (strcmp(s, "NFS") == 0) {
326 * Use NFS to load the bootfile.
339 * Timeout on BOOTP/DHCP request.
344 if (BootpTry >= TIMEOUT_COUNT) {
345 puts ("\nRetry count exceeded; starting again\n");
348 NetSetTimeout (TIMEOUT, BootpTimeout);
354 * Initialize BOOTP extension fields in the request.
356 #if defined(CONFIG_CMD_DHCP)
357 static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t RequestedIP)
362 #if defined(CONFIG_BOOTP_VENDOREX)
365 #if defined(CONFIG_BOOTP_SEND_HOSTNAME)
369 *e++ = 99; /* RFC1048 Magic Cookie */
374 *e++ = 53; /* DHCP Message Type */
378 *e++ = 57; /* Maximum DHCP Message Size */
380 *e++ = (576 - 312 + OPT_SIZE) >> 8;
381 *e++ = (576 - 312 + OPT_SIZE) & 0xff;
384 int tmp = ntohl (ServerID);
386 *e++ = 54; /* ServerID */
395 int tmp = ntohl (RequestedIP);
397 *e++ = 50; /* Requested IP */
404 #if defined(CONFIG_BOOTP_SEND_HOSTNAME)
405 if ((hostname = getenv ("hostname"))) {
406 int hostnamelen = strlen (hostname);
408 *e++ = 12; /* Hostname */
410 memcpy (e, hostname, hostnamelen);
415 #if defined(CONFIG_BOOTP_VENDOREX)
416 if ((x = dhcp_vendorex_prep (e)))
420 *e++ = 55; /* Parameter Request List */
421 cnt = e++; /* Pointer to count of requested items */
423 #if defined(CONFIG_BOOTP_SUBNETMASK)
424 *e++ = 1; /* Subnet Mask */
427 #if defined(CONFIG_BOOTP_TIMEOFFSET)
431 #if defined(CONFIG_BOOTP_GATEWAY)
432 *e++ = 3; /* Router Option */
435 #if defined(CONFIG_BOOTP_DNS)
436 *e++ = 6; /* DNS Server(s) */
439 #if defined(CONFIG_BOOTP_HOSTNAME)
440 *e++ = 12; /* Hostname */
443 #if defined(CONFIG_BOOTP_BOOTFILESIZE)
444 *e++ = 13; /* Boot File Size */
447 #if defined(CONFIG_BOOTP_BOOTPATH)
448 *e++ = 17; /* Boot path */
451 #if defined(CONFIG_BOOTP_NISDOMAIN)
452 *e++ = 40; /* NIS Domain name request */
455 #if defined(CONFIG_BOOTP_NTPSERVER)
459 *e++ = 255; /* End of the list */
461 /* Pad to minimal length */
462 #ifdef CONFIG_DHCP_MIN_EXT_LEN
463 while ((e - start) <= CONFIG_DHCP_MIN_EXT_LEN)
472 * Warning: no field size check - change CONFIG_BOOTP_* at your own risk!
474 static int BootpExtended (u8 * e)
478 *e++ = 99; /* RFC1048 Magic Cookie */
483 #if defined(CONFIG_CMD_DHCP)
484 *e++ = 53; /* DHCP Message Type */
486 *e++ = DHCP_DISCOVER;
488 *e++ = 57; /* Maximum DHCP Message Size */
490 *e++ = (576 - 312 + OPT_SIZE) >> 16;
491 *e++ = (576 - 312 + OPT_SIZE) & 0xff;
494 #if defined(CONFIG_BOOTP_SUBNETMASK)
495 *e++ = 1; /* Subnet mask request */
500 #if defined(CONFIG_BOOTP_GATEWAY)
501 *e++ = 3; /* Default gateway request */
506 #if defined(CONFIG_BOOTP_DNS)
507 *e++ = 6; /* Domain Name Server */
512 #if defined(CONFIG_BOOTP_HOSTNAME)
513 *e++ = 12; /* Host name request */
518 #if defined(CONFIG_BOOTP_BOOTFILESIZE)
519 *e++ = 13; /* Boot file size */
524 #if defined(CONFIG_BOOTP_BOOTPATH)
525 *e++ = 17; /* Boot path */
530 #if defined(CONFIG_BOOTP_NISDOMAIN)
531 *e++ = 40; /* NIS Domain name request */
536 *e++ = 255; /* End of the list */
545 volatile uchar *pkt, *iphdr;
547 int ext_len, pktlen, iplen;
549 #if defined(CONFIG_CMD_DHCP)
553 #ifdef CONFIG_BOOTP_RANDOM_DELAY /* Random BOOTP delay */
554 unsigned char bi_enetaddr[6];
556 ulong tst1, tst2, sum, m_mask, m_value = 0;
560 eth_getenv_enetaddr("ethaddr", bi_enetaddr);
562 debug("BootpRequest => Our Mac: ");
563 for (reg=0; reg<6; reg++)
564 debug("%x%c", bi_enetaddr[reg], reg==5 ? '\n' : ':');
566 /* Mac-Manipulation 2 get seed1 */
569 for (reg=2; reg<6; reg++) {
571 tst1 = tst1 | bi_enetaddr[reg];
573 for (reg=0; reg<2; reg++) {
574 tst2 = tst2 | bi_enetaddr[reg];
582 for (reg=1;reg<=32;reg++) {
583 m_value |= (m_mask & seed1);
585 m_value = m_value << 1;
591 /* Random Number Generator */
593 for (reg=0;reg<=0;reg++) {
595 if (sum < seed1 || sum < seed2)
600 if (BootpTry<=2) { /* Start with max 1024 * 1ms */
601 sum = sum >> (22-BootpTry);
602 } else { /*After 3rd BOOTP request max 8192 * 1ms */
607 printf ("Random delay: %ld ms...\n", sum);
608 for (reg=0; reg <sum; reg++) {
609 udelay(1000); /*Wait 1ms*/
611 #endif /* CONFIG_BOOTP_RANDOM_DELAY */
613 printf("BOOTP broadcast %d\n", ++BootpTry);
615 memset ((void*)pkt, 0, PKTSIZE);
617 pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
620 * Next line results in incorrect packet size being transmitted, resulting
621 * in errors in some DHCP servers, reporting missing bytes. Size must be
622 * set in packet header after extension length has been determined.
623 * C. Hallinan, DS4.COM, Inc.
625 /* NetSetIP(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, sizeof (Bootp_t)); */
626 iphdr = pkt; /* We need this later for NetSetIP() */
630 bp->bp_op = OP_BOOTREQUEST;
631 bp->bp_htype = HWT_ETHER;
632 bp->bp_hlen = HWL_ETHER;
634 bp->bp_secs = htons(get_timer(0) / 1000);
635 NetWriteIP(&bp->bp_ciaddr, 0);
636 NetWriteIP(&bp->bp_yiaddr, 0);
637 NetWriteIP(&bp->bp_siaddr, 0);
638 NetWriteIP(&bp->bp_giaddr, 0);
639 memcpy (bp->bp_chaddr, NetOurEther, 6);
640 copy_filename (bp->bp_file, BootFile, sizeof(bp->bp_file));
642 /* Request additional information from the BOOTP/DHCP server */
643 #if defined(CONFIG_CMD_DHCP)
644 ext_len = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0);
646 ext_len = BootpExtended((u8 *)bp->bp_vend);
650 * Bootp ID is the lower 4 bytes of our ethernet address
651 * plus the current time in ms.
653 BootpID = ((ulong)NetOurEther[2] << 24)
654 | ((ulong)NetOurEther[3] << 16)
655 | ((ulong)NetOurEther[4] << 8)
656 | (ulong)NetOurEther[5];
657 BootpID += get_timer(0);
658 BootpID = htonl(BootpID);
659 NetCopyLong(&bp->bp_id, &BootpID);
662 * Calculate proper packet lengths taking into account the
663 * variable size of the options field
665 pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
666 iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
667 NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
668 NetSetTimeout(SELECT_TIMEOUT, BootpTimeout);
670 #if defined(CONFIG_CMD_DHCP)
671 dhcp_state = SELECTING;
672 NetSetHandler(DhcpHandler);
674 NetSetHandler(BootpHandler);
676 NetSendPacket(NetTxPacket, pktlen);
679 #if defined(CONFIG_CMD_DHCP)
680 static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp)
682 uchar *end = popt + BOOTP_HDR_SIZE;
684 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
688 while (popt < end && *popt != 0xff) {
692 NetCopyIP (&NetOurSubnetMask, (popt + 2));
694 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
695 case 2: /* Time offset */
696 to_ptr = &NetTimeOffset;
697 NetCopyLong ((ulong *)to_ptr, (ulong *)(popt + 2));
698 NetTimeOffset = ntohl (NetTimeOffset);
702 NetCopyIP (&NetOurGatewayIP, (popt + 2));
705 NetCopyIP (&NetOurDNSIP, (popt + 2));
706 #if defined(CONFIG_BOOTP_DNS2)
707 if (*(popt + 1) > 4) {
708 NetCopyIP (&NetOurDNS2IP, (popt + 2 + 4));
713 size = truncate_sz ("Host Name", sizeof (NetOurHostName), oplen);
714 memcpy (&NetOurHostName, popt + 2, size);
715 NetOurHostName[size] = 0;
717 case 15: /* Ignore Domain Name Option */
720 size = truncate_sz ("Root Path", sizeof (NetOurRootPath), oplen);
721 memcpy (&NetOurRootPath, popt + 2, size);
722 NetOurRootPath[size] = 0;
724 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
725 case 42: /* NTP server IP */
726 NetCopyIP (&NetNtpServerIP, (popt + 2));
730 NetCopyLong (&dhcp_leasetime, (ulong *) (popt + 2));
732 case 53: /* Ignore Message Type Option */
735 NetCopyIP (&NetDHCPServerIP, (popt + 2));
737 case 58: /* Ignore Renewal Time Option */
739 case 59: /* Ignore Rebinding Time Option */
741 case 66: /* Ignore TFTP server name */
743 case 67: /* vendor opt bootfile */
745 * I can't use dhcp_vendorex_proc here because I need
746 * to write into the bootp packet - even then I had to
747 * pass the bootp packet pointer into here as the
750 size = truncate_sz ("Opt Boot File",
753 if (bp->bp_file[0] == '\0' && size > 0) {
755 * only use vendor boot file if we didn't
756 * receive a boot file in the main non-vendor
757 * part of the packet - god only knows why
758 * some vendors chose not to use this perfectly
759 * good spot to store the boot file (join on
760 * Tru64 Unix) it seems mind bogglingly crazy
763 printf("*** WARNING: using vendor "
764 "optional boot file\n");
765 memcpy(bp->bp_file, popt + 2, size);
766 bp->bp_file[size] = '\0';
770 #if defined(CONFIG_BOOTP_VENDOREX)
771 if (dhcp_vendorex_proc (popt))
774 printf ("*** Unhandled DHCP Option in OFFER/ACK: %d\n", *popt);
777 popt += oplen + 2; /* Process next option */
781 static int DhcpMessageType(unsigned char *popt)
783 if (NetReadLong((ulong*)popt) != htonl(BOOTP_VENDOR_MAGIC))
787 while ( *popt != 0xff ) {
788 if ( *popt == 53 ) /* DHCP Message Type */
790 popt += *(popt + 1) + 2; /* Scan through all options */
795 static void DhcpSendRequestPkt(Bootp_t *bp_offer)
797 volatile uchar *pkt, *iphdr;
799 int pktlen, iplen, extlen;
802 debug("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
804 memset ((void*)pkt, 0, PKTSIZE);
806 pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
808 iphdr = pkt; /* We'll need this later to set proper pkt size */
812 bp->bp_op = OP_BOOTREQUEST;
813 bp->bp_htype = HWT_ETHER;
814 bp->bp_hlen = HWL_ETHER;
816 bp->bp_secs = htons(get_timer(0) / 1000);
817 /* Do not set the client IP, your IP, or server IP yet, since it hasn't been ACK'ed by
821 * RFC3046 requires Relay Agents to discard packets with
822 * nonzero and offered giaddr
824 NetWriteIP(&bp->bp_giaddr, 0);
826 memcpy (bp->bp_chaddr, NetOurEther, 6);
829 * ID is the id of the OFFER packet
832 NetCopyLong(&bp->bp_id, &bp_offer->bp_id);
835 * Copy options from OFFER packet if present
838 /* Copy offered IP into the parameters request list */
839 NetCopyIP(&OfferedIP, &bp_offer->bp_yiaddr);
840 extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST, NetDHCPServerIP, OfferedIP);
842 pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
843 iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
844 NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
846 debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);
847 #ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY
848 udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY);
849 #endif /* CONFIG_BOOTP_DHCP_REQUEST_DELAY */
850 NetSendPacket(NetTxPacket, pktlen);
854 * Handle DHCP received packets.
857 DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
859 Bootp_t *bp = (Bootp_t *)pkt;
861 debug("DHCPHandler: got packet: (src=%d, dst=%d, len=%d) state: %d\n",
862 src, dest, len, dhcp_state);
864 if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */
867 debug("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state: %d\n",
868 src, dest, len, dhcp_state);
870 switch (dhcp_state) {
873 * Wait an appropriate time for any potential DHCPOFFER packets
874 * to arrive. Then select one, and generate DHCPREQUEST response.
875 * If filename is in format we recognize, assume it is a valid
876 * OFFER from a server we want.
878 debug("DHCP: state=SELECTING bp_file: \"%s\"\n", bp->bp_file);
879 #ifdef CONFIG_SYS_BOOTFILE_PREFIX
880 if (strncmp(bp->bp_file,
881 CONFIG_SYS_BOOTFILE_PREFIX,
882 strlen(CONFIG_SYS_BOOTFILE_PREFIX)) == 0 ) {
883 #endif /* CONFIG_SYS_BOOTFILE_PREFIX */
885 debug("TRANSITIONING TO REQUESTING STATE\n");
886 dhcp_state = REQUESTING;
888 if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
889 DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
891 NetSetTimeout(TIMEOUT, BootpTimeout);
892 DhcpSendRequestPkt(bp);
893 #ifdef CONFIG_SYS_BOOTFILE_PREFIX
895 #endif /* CONFIG_SYS_BOOTFILE_PREFIX */
900 debug("DHCP State: REQUESTING\n");
902 if ( DhcpMessageType((u8 *)bp->bp_vend) == DHCP_ACK ) {
905 if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
906 DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
907 BootpCopyNetParams(bp); /* Store net params from reply */
909 printf ("DHCP client bound to address %pI4\n", &NetOurIP);
911 /* Obey the 'autoload' setting */
912 if ((s = getenv("autoload")) != NULL) {
915 * Just use BOOTP to configure system;
916 * Do not use TFTP to load the bootfile.
918 NetState = NETLOOP_SUCCESS;
920 #if defined(CONFIG_CMD_NFS)
921 } else if (strcmp(s, "NFS") == 0) {
923 * Use NFS to load the bootfile.
935 /* DHCP client bound to address */
938 puts ("DHCP: INVALID STATE\n");
944 void DhcpRequest(void)
948 #endif /* CONFIG_CMD_DHCP */