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 /* no options, so back up to avoid sending an empty request list */
463 *e++ = 255; /* End of the list */
465 /* Pad to minimal length */
466 #ifdef CONFIG_DHCP_MIN_EXT_LEN
467 while ((e - start) <= CONFIG_DHCP_MIN_EXT_LEN)
476 * Warning: no field size check - change CONFIG_BOOTP_* at your own risk!
478 static int BootpExtended (u8 * e)
482 *e++ = 99; /* RFC1048 Magic Cookie */
487 #if defined(CONFIG_CMD_DHCP)
488 *e++ = 53; /* DHCP Message Type */
490 *e++ = DHCP_DISCOVER;
492 *e++ = 57; /* Maximum DHCP Message Size */
494 *e++ = (576 - 312 + OPT_SIZE) >> 16;
495 *e++ = (576 - 312 + OPT_SIZE) & 0xff;
498 #if defined(CONFIG_BOOTP_SUBNETMASK)
499 *e++ = 1; /* Subnet mask request */
504 #if defined(CONFIG_BOOTP_GATEWAY)
505 *e++ = 3; /* Default gateway request */
510 #if defined(CONFIG_BOOTP_DNS)
511 *e++ = 6; /* Domain Name Server */
516 #if defined(CONFIG_BOOTP_HOSTNAME)
517 *e++ = 12; /* Host name request */
522 #if defined(CONFIG_BOOTP_BOOTFILESIZE)
523 *e++ = 13; /* Boot file size */
528 #if defined(CONFIG_BOOTP_BOOTPATH)
529 *e++ = 17; /* Boot path */
534 #if defined(CONFIG_BOOTP_NISDOMAIN)
535 *e++ = 40; /* NIS Domain name request */
540 *e++ = 255; /* End of the list */
549 volatile uchar *pkt, *iphdr;
551 int ext_len, pktlen, iplen;
553 #if defined(CONFIG_CMD_DHCP)
557 #ifdef CONFIG_BOOTP_RANDOM_DELAY /* Random BOOTP delay */
558 unsigned char bi_enetaddr[6];
560 ulong tst1, tst2, sum, m_mask, m_value = 0;
564 eth_getenv_enetaddr("ethaddr", bi_enetaddr);
566 debug("BootpRequest => Our Mac: ");
567 for (reg=0; reg<6; reg++)
568 debug("%x%c", bi_enetaddr[reg], reg==5 ? '\n' : ':');
570 /* Mac-Manipulation 2 get seed1 */
573 for (reg=2; reg<6; reg++) {
575 tst1 = tst1 | bi_enetaddr[reg];
577 for (reg=0; reg<2; reg++) {
578 tst2 = tst2 | bi_enetaddr[reg];
586 for (reg=1;reg<=32;reg++) {
587 m_value |= (m_mask & seed1);
589 m_value = m_value << 1;
595 /* Random Number Generator */
597 for (reg=0;reg<=0;reg++) {
599 if (sum < seed1 || sum < seed2)
604 if (BootpTry<=2) { /* Start with max 1024 * 1ms */
605 sum = sum >> (22-BootpTry);
606 } else { /*After 3rd BOOTP request max 8192 * 1ms */
611 printf ("Random delay: %ld ms...\n", sum);
612 for (reg=0; reg <sum; reg++) {
613 udelay(1000); /*Wait 1ms*/
615 #endif /* CONFIG_BOOTP_RANDOM_DELAY */
617 printf("BOOTP broadcast %d\n", ++BootpTry);
619 memset ((void*)pkt, 0, PKTSIZE);
621 pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
624 * Next line results in incorrect packet size being transmitted, resulting
625 * in errors in some DHCP servers, reporting missing bytes. Size must be
626 * set in packet header after extension length has been determined.
627 * C. Hallinan, DS4.COM, Inc.
629 /* NetSetIP(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, sizeof (Bootp_t)); */
630 iphdr = pkt; /* We need this later for NetSetIP() */
634 bp->bp_op = OP_BOOTREQUEST;
635 bp->bp_htype = HWT_ETHER;
636 bp->bp_hlen = HWL_ETHER;
638 bp->bp_secs = htons(get_timer(0) / 1000);
639 NetWriteIP(&bp->bp_ciaddr, 0);
640 NetWriteIP(&bp->bp_yiaddr, 0);
641 NetWriteIP(&bp->bp_siaddr, 0);
642 NetWriteIP(&bp->bp_giaddr, 0);
643 memcpy (bp->bp_chaddr, NetOurEther, 6);
644 copy_filename (bp->bp_file, BootFile, sizeof(bp->bp_file));
646 /* Request additional information from the BOOTP/DHCP server */
647 #if defined(CONFIG_CMD_DHCP)
648 ext_len = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0);
650 ext_len = BootpExtended((u8 *)bp->bp_vend);
654 * Bootp ID is the lower 4 bytes of our ethernet address
655 * plus the current time in ms.
657 BootpID = ((ulong)NetOurEther[2] << 24)
658 | ((ulong)NetOurEther[3] << 16)
659 | ((ulong)NetOurEther[4] << 8)
660 | (ulong)NetOurEther[5];
661 BootpID += get_timer(0);
662 BootpID = htonl(BootpID);
663 NetCopyLong(&bp->bp_id, &BootpID);
666 * Calculate proper packet lengths taking into account the
667 * variable size of the options field
669 pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
670 iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
671 NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
672 NetSetTimeout(SELECT_TIMEOUT, BootpTimeout);
674 #if defined(CONFIG_CMD_DHCP)
675 dhcp_state = SELECTING;
676 NetSetHandler(DhcpHandler);
678 NetSetHandler(BootpHandler);
680 NetSendPacket(NetTxPacket, pktlen);
683 #if defined(CONFIG_CMD_DHCP)
684 static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp)
686 uchar *end = popt + BOOTP_HDR_SIZE;
688 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
692 while (popt < end && *popt != 0xff) {
696 NetCopyIP (&NetOurSubnetMask, (popt + 2));
698 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
699 case 2: /* Time offset */
700 to_ptr = &NetTimeOffset;
701 NetCopyLong ((ulong *)to_ptr, (ulong *)(popt + 2));
702 NetTimeOffset = ntohl (NetTimeOffset);
706 NetCopyIP (&NetOurGatewayIP, (popt + 2));
709 NetCopyIP (&NetOurDNSIP, (popt + 2));
710 #if defined(CONFIG_BOOTP_DNS2)
711 if (*(popt + 1) > 4) {
712 NetCopyIP (&NetOurDNS2IP, (popt + 2 + 4));
717 size = truncate_sz ("Host Name", sizeof (NetOurHostName), oplen);
718 memcpy (&NetOurHostName, popt + 2, size);
719 NetOurHostName[size] = 0;
721 case 15: /* Ignore Domain Name Option */
724 size = truncate_sz ("Root Path", sizeof (NetOurRootPath), oplen);
725 memcpy (&NetOurRootPath, popt + 2, size);
726 NetOurRootPath[size] = 0;
728 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
729 case 42: /* NTP server IP */
730 NetCopyIP (&NetNtpServerIP, (popt + 2));
734 NetCopyLong (&dhcp_leasetime, (ulong *) (popt + 2));
736 case 53: /* Ignore Message Type Option */
739 NetCopyIP (&NetDHCPServerIP, (popt + 2));
741 case 58: /* Ignore Renewal Time Option */
743 case 59: /* Ignore Rebinding Time Option */
745 case 66: /* Ignore TFTP server name */
747 case 67: /* vendor opt bootfile */
749 * I can't use dhcp_vendorex_proc here because I need
750 * to write into the bootp packet - even then I had to
751 * pass the bootp packet pointer into here as the
754 size = truncate_sz ("Opt Boot File",
757 if (bp->bp_file[0] == '\0' && size > 0) {
759 * only use vendor boot file if we didn't
760 * receive a boot file in the main non-vendor
761 * part of the packet - god only knows why
762 * some vendors chose not to use this perfectly
763 * good spot to store the boot file (join on
764 * Tru64 Unix) it seems mind bogglingly crazy
767 printf("*** WARNING: using vendor "
768 "optional boot file\n");
769 memcpy(bp->bp_file, popt + 2, size);
770 bp->bp_file[size] = '\0';
774 #if defined(CONFIG_BOOTP_VENDOREX)
775 if (dhcp_vendorex_proc (popt))
778 printf ("*** Unhandled DHCP Option in OFFER/ACK: %d\n", *popt);
781 popt += oplen + 2; /* Process next option */
785 static int DhcpMessageType(unsigned char *popt)
787 if (NetReadLong((ulong*)popt) != htonl(BOOTP_VENDOR_MAGIC))
791 while ( *popt != 0xff ) {
792 if ( *popt == 53 ) /* DHCP Message Type */
794 popt += *(popt + 1) + 2; /* Scan through all options */
799 static void DhcpSendRequestPkt(Bootp_t *bp_offer)
801 volatile uchar *pkt, *iphdr;
803 int pktlen, iplen, extlen;
806 debug("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
808 memset ((void*)pkt, 0, PKTSIZE);
810 pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
812 iphdr = pkt; /* We'll need this later to set proper pkt size */
816 bp->bp_op = OP_BOOTREQUEST;
817 bp->bp_htype = HWT_ETHER;
818 bp->bp_hlen = HWL_ETHER;
820 bp->bp_secs = htons(get_timer(0) / 1000);
821 /* Do not set the client IP, your IP, or server IP yet, since it hasn't been ACK'ed by
825 * RFC3046 requires Relay Agents to discard packets with
826 * nonzero and offered giaddr
828 NetWriteIP(&bp->bp_giaddr, 0);
830 memcpy (bp->bp_chaddr, NetOurEther, 6);
833 * ID is the id of the OFFER packet
836 NetCopyLong(&bp->bp_id, &bp_offer->bp_id);
839 * Copy options from OFFER packet if present
842 /* Copy offered IP into the parameters request list */
843 NetCopyIP(&OfferedIP, &bp_offer->bp_yiaddr);
844 extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST, NetDHCPServerIP, OfferedIP);
846 pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
847 iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
848 NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
850 debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);
851 #ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY
852 udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY);
853 #endif /* CONFIG_BOOTP_DHCP_REQUEST_DELAY */
854 NetSendPacket(NetTxPacket, pktlen);
858 * Handle DHCP received packets.
861 DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
863 Bootp_t *bp = (Bootp_t *)pkt;
865 debug("DHCPHandler: got packet: (src=%d, dst=%d, len=%d) state: %d\n",
866 src, dest, len, dhcp_state);
868 if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */
871 debug("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state: %d\n",
872 src, dest, len, dhcp_state);
874 switch (dhcp_state) {
877 * Wait an appropriate time for any potential DHCPOFFER packets
878 * to arrive. Then select one, and generate DHCPREQUEST response.
879 * If filename is in format we recognize, assume it is a valid
880 * OFFER from a server we want.
882 debug("DHCP: state=SELECTING bp_file: \"%s\"\n", bp->bp_file);
883 #ifdef CONFIG_SYS_BOOTFILE_PREFIX
884 if (strncmp(bp->bp_file,
885 CONFIG_SYS_BOOTFILE_PREFIX,
886 strlen(CONFIG_SYS_BOOTFILE_PREFIX)) == 0 ) {
887 #endif /* CONFIG_SYS_BOOTFILE_PREFIX */
889 debug("TRANSITIONING TO REQUESTING STATE\n");
890 dhcp_state = REQUESTING;
892 if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
893 DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
895 NetSetTimeout(TIMEOUT, BootpTimeout);
896 DhcpSendRequestPkt(bp);
897 #ifdef CONFIG_SYS_BOOTFILE_PREFIX
899 #endif /* CONFIG_SYS_BOOTFILE_PREFIX */
904 debug("DHCP State: REQUESTING\n");
906 if ( DhcpMessageType((u8 *)bp->bp_vend) == DHCP_ACK ) {
909 if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
910 DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
911 BootpCopyNetParams(bp); /* Store net params from reply */
913 printf ("DHCP client bound to address %pI4\n", &NetOurIP);
915 /* Obey the 'autoload' setting */
916 if ((s = getenv("autoload")) != NULL) {
919 * Just use BOOTP to configure system;
920 * Do not use TFTP to load the bootfile.
922 NetState = NETLOOP_SUCCESS;
924 #if defined(CONFIG_CMD_NFS)
925 } else if (strcmp(s, "NFS") == 0) {
927 * Use NFS to load the bootfile.
939 /* DHCP client bound to address */
942 puts ("DHCP: INVALID STATE\n");
948 void DhcpRequest(void)
952 #endif /* CONFIG_CMD_DHCP */