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, IPaddr_t sip, unsigned src,
52 static char *dhcpmsg2str(int type)
55 case 1: return "DHCPDISCOVER"; break;
56 case 2: return "DHCPOFFER"; break;
57 case 3: return "DHCPREQUEST"; break;
58 case 4: return "DHCPDECLINE"; break;
59 case 5: return "DHCPACK"; break;
60 case 6: return "DHCPNACK"; break;
61 case 7: return "DHCPRELEASE"; break;
62 default: return "UNKNOWN/INVALID MSG TYPE"; break;
67 #if defined(CONFIG_BOOTP_VENDOREX)
68 extern u8 *dhcp_vendorex_prep (u8 *e); /*rtn new e after add own opts. */
69 extern u8 *dhcp_vendorex_proc (u8 *e); /*rtn next e if mine,else NULL */
74 static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
76 Bootp_t *bp = (Bootp_t *) pkt;
79 if (dest != PORT_BOOTPC || src != PORT_BOOTPS)
81 else if (len < sizeof (Bootp_t) - OPT_SIZE)
83 else if (bp->bp_op != OP_BOOTREQUEST &&
84 bp->bp_op != OP_BOOTREPLY &&
85 bp->bp_op != DHCP_OFFER &&
86 bp->bp_op != DHCP_ACK &&
87 bp->bp_op != DHCP_NAK ) {
90 else if (bp->bp_htype != HWT_ETHER)
92 else if (bp->bp_hlen != HWL_ETHER)
94 else if (NetReadLong((ulong*)&bp->bp_id) != BootpID) {
98 debug("Filtering pkt = %d\n", retval);
104 * Copy parameters of interest from BOOTP_REPLY/DHCP_OFFER packet
106 static void BootpCopyNetParams(Bootp_t *bp)
110 NetCopyIP(&NetOurIP, &bp->bp_yiaddr);
111 #if !defined(CONFIG_BOOTP_SERVERIP)
112 NetCopyIP(&tmp_ip, &bp->bp_siaddr);
114 NetCopyIP(&NetServerIP, &bp->bp_siaddr);
115 memcpy (NetServerEther, ((Ethernet_t *)NetRxPacket)->et_src, 6);
117 if (strlen(bp->bp_file) > 0)
118 copy_filename (BootFile, bp->bp_file, sizeof(BootFile));
120 debug("Bootfile: %s\n", BootFile);
122 /* Propagate to environment:
123 * don't delete exising entry when BOOTP / DHCP reply does
124 * not contain a new value
127 setenv ("bootfile", BootFile);
131 static int truncate_sz (const char *name, int maxlen, int curlen)
133 if (curlen >= maxlen) {
134 printf("*** WARNING: %s is too long (%d - max: %d) - truncated\n",
135 name, curlen, maxlen);
141 #if !defined(CONFIG_CMD_DHCP)
143 static void BootpVendorFieldProcess (u8 * ext)
145 int size = *(ext + 1);
147 debug("[BOOTP] Processing extension %d... (%d bytes)\n", *ext,
153 /* Fixed length fields */
154 case 1: /* Subnet mask */
155 if (NetOurSubnetMask == 0)
156 NetCopyIP (&NetOurSubnetMask, (IPaddr_t *) (ext + 2));
158 case 2: /* Time offset - Not yet supported */
160 /* Variable length fields */
161 case 3: /* Gateways list */
162 if (NetOurGatewayIP == 0) {
163 NetCopyIP (&NetOurGatewayIP, (IPaddr_t *) (ext + 2));
166 case 4: /* Time server - Not yet supported */
168 case 5: /* IEN-116 name server - Not yet supported */
171 if (NetOurDNSIP == 0) {
172 NetCopyIP (&NetOurDNSIP, (IPaddr_t *) (ext + 2));
174 #if defined(CONFIG_BOOTP_DNS2)
175 if ((NetOurDNS2IP == 0) && (size > 4)) {
176 NetCopyIP (&NetOurDNS2IP, (IPaddr_t *) (ext + 2 + 4));
180 case 7: /* Log server - Not yet supported */
182 case 8: /* Cookie/Quote server - Not yet supported */
184 case 9: /* LPR server - Not yet supported */
186 case 10: /* Impress server - Not yet supported */
188 case 11: /* RPL server - Not yet supported */
190 case 12: /* Host name */
191 if (NetOurHostName[0] == 0) {
192 size = truncate_sz ("Host Name", sizeof (NetOurHostName), size);
193 memcpy (&NetOurHostName, ext + 2, size);
194 NetOurHostName[size] = 0;
197 case 13: /* Boot file size */
199 NetBootFileSize = ntohs (*(ushort *) (ext + 2));
201 NetBootFileSize = ntohl (*(ulong *) (ext + 2));
203 case 14: /* Merit dump file - Not yet supported */
205 case 15: /* Domain name - Not yet supported */
207 case 16: /* Swap server - Not yet supported */
209 case 17: /* Root path */
210 if (NetOurRootPath[0] == 0) {
211 size = truncate_sz ("Root Path", sizeof (NetOurRootPath), size);
212 memcpy (&NetOurRootPath, ext + 2, size);
213 NetOurRootPath[size] = 0;
216 case 18: /* Extension path - Not yet supported */
218 * This can be used to send the information of the
219 * vendor area in another file that the client can
223 /* IP host layer fields */
224 case 40: /* NIS Domain name */
225 if (NetOurNISDomain[0] == 0) {
226 size = truncate_sz ("NIS Domain Name", sizeof (NetOurNISDomain), size);
227 memcpy (&NetOurNISDomain, ext + 2, size);
228 NetOurNISDomain[size] = 0;
231 /* Application layer fields */
232 case 43: /* Vendor specific info - Not yet supported */
234 * Binary information to exchange specific
235 * product information.
238 /* Reserved (custom) fields (128..254) */
242 static void BootpVendorProcess (u8 * ext, int size)
244 u8 *end = ext + size;
246 debug("[BOOTP] Checking extension (%d bytes)...\n", size);
248 while ((ext < end) && (*ext != 0xff)) {
256 BootpVendorFieldProcess (opt);
260 debug("[BOOTP] Received fields: \n");
261 if (NetOurSubnetMask)
262 debug("NetOurSubnetMask : %pI4\n", &NetOurSubnetMask);
265 debug("NetOurGatewayIP : %pI4", &NetOurGatewayIP);
268 debug("NetBootFileSize : %d\n", NetBootFileSize);
270 if (NetOurHostName[0])
271 debug("NetOurHostName : %s\n", NetOurHostName);
273 if (NetOurRootPath[0])
274 debug("NetOurRootPath : %s\n", NetOurRootPath);
276 if (NetOurNISDomain[0])
277 debug("NetOurNISDomain : %s\n", NetOurNISDomain);
280 debug("NetBootFileSize: %d\n", NetBootFileSize);
283 * Handle a BOOTP received packet.
286 BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
292 debug("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%zu)\n",
293 src, dest, len, sizeof (Bootp_t));
297 if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */
301 * Got a good BOOTP reply. Copy the data into our variables.
303 #ifdef CONFIG_STATUS_LED
304 status_led_set (STATUS_LED_BOOT, STATUS_LED_OFF);
307 BootpCopyNetParams(bp); /* Store net parameters from reply */
309 /* Retrieve extended information (we must parse the vendor area) */
310 if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
311 BootpVendorProcess((uchar *)&bp->bp_vend[4], len);
313 NetSetTimeout(0, (thand_f *)0);
315 debug("Got good BOOTP\n");
317 if ((s = getenv("autoload")) != NULL) {
320 * Just use BOOTP to configure system;
321 * Do not use TFTP to load the bootfile.
323 NetState = NETLOOP_SUCCESS;
325 #if defined(CONFIG_CMD_NFS)
326 } else if (strcmp(s, "NFS") == 0) {
328 * Use NFS to load the bootfile.
341 * Timeout on BOOTP/DHCP request.
346 if (BootpTry >= TIMEOUT_COUNT) {
347 puts ("\nRetry count exceeded; starting again\n");
350 NetSetTimeout (TIMEOUT, BootpTimeout);
356 * Initialize BOOTP extension fields in the request.
358 #if defined(CONFIG_CMD_DHCP)
359 static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t RequestedIP)
364 #if defined(CONFIG_BOOTP_VENDOREX)
367 #if defined(CONFIG_BOOTP_SEND_HOSTNAME)
371 *e++ = 99; /* RFC1048 Magic Cookie */
376 *e++ = 53; /* DHCP Message Type */
380 *e++ = 57; /* Maximum DHCP Message Size */
382 *e++ = (576 - 312 + OPT_SIZE) >> 8;
383 *e++ = (576 - 312 + OPT_SIZE) & 0xff;
386 int tmp = ntohl (ServerID);
388 *e++ = 54; /* ServerID */
397 int tmp = ntohl (RequestedIP);
399 *e++ = 50; /* Requested IP */
406 #if defined(CONFIG_BOOTP_SEND_HOSTNAME)
407 if ((hostname = getenv ("hostname"))) {
408 int hostnamelen = strlen (hostname);
410 *e++ = 12; /* Hostname */
412 memcpy (e, hostname, hostnamelen);
417 #if defined(CONFIG_BOOTP_VENDOREX)
418 if ((x = dhcp_vendorex_prep (e)))
422 *e++ = 55; /* Parameter Request List */
423 cnt = e++; /* Pointer to count of requested items */
425 #if defined(CONFIG_BOOTP_SUBNETMASK)
426 *e++ = 1; /* Subnet Mask */
429 #if defined(CONFIG_BOOTP_TIMEOFFSET)
433 #if defined(CONFIG_BOOTP_GATEWAY)
434 *e++ = 3; /* Router Option */
437 #if defined(CONFIG_BOOTP_DNS)
438 *e++ = 6; /* DNS Server(s) */
441 #if defined(CONFIG_BOOTP_HOSTNAME)
442 *e++ = 12; /* Hostname */
445 #if defined(CONFIG_BOOTP_BOOTFILESIZE)
446 *e++ = 13; /* Boot File Size */
449 #if defined(CONFIG_BOOTP_BOOTPATH)
450 *e++ = 17; /* Boot path */
453 #if defined(CONFIG_BOOTP_NISDOMAIN)
454 *e++ = 40; /* NIS Domain name request */
457 #if defined(CONFIG_BOOTP_NTPSERVER)
461 /* no options, so back up to avoid sending an empty request list */
465 *e++ = 255; /* End of the list */
467 /* Pad to minimal length */
468 #ifdef CONFIG_DHCP_MIN_EXT_LEN
469 while ((e - start) < CONFIG_DHCP_MIN_EXT_LEN)
478 * Warning: no field size check - change CONFIG_BOOTP_* at your own risk!
480 static int BootpExtended (u8 * e)
484 *e++ = 99; /* RFC1048 Magic Cookie */
489 #if defined(CONFIG_CMD_DHCP)
490 *e++ = 53; /* DHCP Message Type */
492 *e++ = DHCP_DISCOVER;
494 *e++ = 57; /* Maximum DHCP Message Size */
496 *e++ = (576 - 312 + OPT_SIZE) >> 16;
497 *e++ = (576 - 312 + OPT_SIZE) & 0xff;
500 #if defined(CONFIG_BOOTP_SUBNETMASK)
501 *e++ = 1; /* Subnet mask request */
506 #if defined(CONFIG_BOOTP_GATEWAY)
507 *e++ = 3; /* Default gateway request */
512 #if defined(CONFIG_BOOTP_DNS)
513 *e++ = 6; /* Domain Name Server */
518 #if defined(CONFIG_BOOTP_HOSTNAME)
519 *e++ = 12; /* Host name request */
524 #if defined(CONFIG_BOOTP_BOOTFILESIZE)
525 *e++ = 13; /* Boot file size */
530 #if defined(CONFIG_BOOTP_BOOTPATH)
531 *e++ = 17; /* Boot path */
536 #if defined(CONFIG_BOOTP_NISDOMAIN)
537 *e++ = 40; /* NIS Domain name request */
542 *e++ = 255; /* End of the list */
551 volatile uchar *pkt, *iphdr;
553 int ext_len, pktlen, iplen;
555 #if defined(CONFIG_CMD_DHCP)
559 #ifdef CONFIG_BOOTP_RANDOM_DELAY /* Random BOOTP delay */
560 unsigned char bi_enetaddr[6];
562 ulong tst1, tst2, sum, m_mask, m_value = 0;
566 eth_getenv_enetaddr("ethaddr", bi_enetaddr);
568 debug("BootpRequest => Our Mac: ");
569 for (reg=0; reg<6; reg++)
570 debug("%x%c", bi_enetaddr[reg], reg==5 ? '\n' : ':');
572 /* Mac-Manipulation 2 get seed1 */
575 for (reg=2; reg<6; reg++) {
577 tst1 = tst1 | bi_enetaddr[reg];
579 for (reg=0; reg<2; reg++) {
580 tst2 = tst2 | bi_enetaddr[reg];
588 for (reg=1;reg<=32;reg++) {
589 m_value |= (m_mask & seed1);
591 m_value = m_value << 1;
597 /* Random Number Generator */
599 for (reg=0;reg<=0;reg++) {
601 if (sum < seed1 || sum < seed2)
606 if (BootpTry<=2) { /* Start with max 1024 * 1ms */
607 sum = sum >> (22-BootpTry);
608 } else { /*After 3rd BOOTP request max 8192 * 1ms */
613 printf ("Random delay: %ld ms...\n", sum);
614 for (reg=0; reg <sum; reg++) {
615 udelay(1000); /*Wait 1ms*/
617 #endif /* CONFIG_BOOTP_RANDOM_DELAY */
619 printf("BOOTP broadcast %d\n", ++BootpTry);
621 memset ((void*)pkt, 0, PKTSIZE);
623 pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
626 * Next line results in incorrect packet size being transmitted, resulting
627 * in errors in some DHCP servers, reporting missing bytes. Size must be
628 * set in packet header after extension length has been determined.
629 * C. Hallinan, DS4.COM, Inc.
631 /* NetSetIP(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, sizeof (Bootp_t)); */
632 iphdr = pkt; /* We need this later for NetSetIP() */
636 bp->bp_op = OP_BOOTREQUEST;
637 bp->bp_htype = HWT_ETHER;
638 bp->bp_hlen = HWL_ETHER;
640 bp->bp_secs = htons(get_timer(0) / 1000);
641 NetWriteIP(&bp->bp_ciaddr, 0);
642 NetWriteIP(&bp->bp_yiaddr, 0);
643 NetWriteIP(&bp->bp_siaddr, 0);
644 NetWriteIP(&bp->bp_giaddr, 0);
645 memcpy (bp->bp_chaddr, NetOurEther, 6);
646 copy_filename (bp->bp_file, BootFile, sizeof(bp->bp_file));
648 /* Request additional information from the BOOTP/DHCP server */
649 #if defined(CONFIG_CMD_DHCP)
650 ext_len = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0);
652 ext_len = BootpExtended((u8 *)bp->bp_vend);
656 * Bootp ID is the lower 4 bytes of our ethernet address
657 * plus the current time in ms.
659 BootpID = ((ulong)NetOurEther[2] << 24)
660 | ((ulong)NetOurEther[3] << 16)
661 | ((ulong)NetOurEther[4] << 8)
662 | (ulong)NetOurEther[5];
663 BootpID += get_timer(0);
664 BootpID = htonl(BootpID);
665 NetCopyLong(&bp->bp_id, &BootpID);
668 * Calculate proper packet lengths taking into account the
669 * variable size of the options field
671 pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
672 iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
673 NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
674 NetSetTimeout(SELECT_TIMEOUT, BootpTimeout);
676 #if defined(CONFIG_CMD_DHCP)
677 dhcp_state = SELECTING;
678 NetSetHandler(DhcpHandler);
680 NetSetHandler(BootpHandler);
682 NetSendPacket(NetTxPacket, pktlen);
685 #if defined(CONFIG_CMD_DHCP)
686 static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp)
688 uchar *end = popt + BOOTP_HDR_SIZE;
690 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
694 while (popt < end && *popt != 0xff) {
698 NetCopyIP (&NetOurSubnetMask, (popt + 2));
700 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
701 case 2: /* Time offset */
702 to_ptr = &NetTimeOffset;
703 NetCopyLong ((ulong *)to_ptr, (ulong *)(popt + 2));
704 NetTimeOffset = ntohl (NetTimeOffset);
708 NetCopyIP (&NetOurGatewayIP, (popt + 2));
711 NetCopyIP (&NetOurDNSIP, (popt + 2));
712 #if defined(CONFIG_BOOTP_DNS2)
713 if (*(popt + 1) > 4) {
714 NetCopyIP (&NetOurDNS2IP, (popt + 2 + 4));
719 size = truncate_sz ("Host Name", sizeof (NetOurHostName), oplen);
720 memcpy (&NetOurHostName, popt + 2, size);
721 NetOurHostName[size] = 0;
723 case 15: /* Ignore Domain Name Option */
726 size = truncate_sz ("Root Path", sizeof (NetOurRootPath), oplen);
727 memcpy (&NetOurRootPath, popt + 2, size);
728 NetOurRootPath[size] = 0;
730 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
731 case 42: /* NTP server IP */
732 NetCopyIP (&NetNtpServerIP, (popt + 2));
736 NetCopyLong (&dhcp_leasetime, (ulong *) (popt + 2));
738 case 53: /* Ignore Message Type Option */
741 NetCopyIP (&NetDHCPServerIP, (popt + 2));
743 case 58: /* Ignore Renewal Time Option */
745 case 59: /* Ignore Rebinding Time Option */
747 case 66: /* Ignore TFTP server name */
749 case 67: /* vendor opt bootfile */
751 * I can't use dhcp_vendorex_proc here because I need
752 * to write into the bootp packet - even then I had to
753 * pass the bootp packet pointer into here as the
756 size = truncate_sz ("Opt Boot File",
759 if (bp->bp_file[0] == '\0' && size > 0) {
761 * only use vendor boot file if we didn't
762 * receive a boot file in the main non-vendor
763 * part of the packet - god only knows why
764 * some vendors chose not to use this perfectly
765 * good spot to store the boot file (join on
766 * Tru64 Unix) it seems mind bogglingly crazy
769 printf("*** WARNING: using vendor "
770 "optional boot file\n");
771 memcpy(bp->bp_file, popt + 2, size);
772 bp->bp_file[size] = '\0';
776 #if defined(CONFIG_BOOTP_VENDOREX)
777 if (dhcp_vendorex_proc (popt))
780 printf ("*** Unhandled DHCP Option in OFFER/ACK: %d\n", *popt);
783 popt += oplen + 2; /* Process next option */
787 static int DhcpMessageType(unsigned char *popt)
789 if (NetReadLong((ulong*)popt) != htonl(BOOTP_VENDOR_MAGIC))
793 while ( *popt != 0xff ) {
794 if ( *popt == 53 ) /* DHCP Message Type */
796 popt += *(popt + 1) + 2; /* Scan through all options */
801 static void DhcpSendRequestPkt(Bootp_t *bp_offer)
803 volatile uchar *pkt, *iphdr;
805 int pktlen, iplen, extlen;
808 debug("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
810 memset ((void*)pkt, 0, PKTSIZE);
812 pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
814 iphdr = pkt; /* We'll need this later to set proper pkt size */
818 bp->bp_op = OP_BOOTREQUEST;
819 bp->bp_htype = HWT_ETHER;
820 bp->bp_hlen = HWL_ETHER;
822 bp->bp_secs = htons(get_timer(0) / 1000);
823 /* Do not set the client IP, your IP, or server IP yet, since it hasn't been ACK'ed by
827 * RFC3046 requires Relay Agents to discard packets with
828 * nonzero and offered giaddr
830 NetWriteIP(&bp->bp_giaddr, 0);
832 memcpy (bp->bp_chaddr, NetOurEther, 6);
835 * ID is the id of the OFFER packet
838 NetCopyLong(&bp->bp_id, &bp_offer->bp_id);
841 * Copy options from OFFER packet if present
844 /* Copy offered IP into the parameters request list */
845 NetCopyIP(&OfferedIP, &bp_offer->bp_yiaddr);
846 extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST, NetDHCPServerIP, OfferedIP);
848 pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
849 iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
850 NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
852 debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);
853 #ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY
854 udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY);
855 #endif /* CONFIG_BOOTP_DHCP_REQUEST_DELAY */
856 NetSendPacket(NetTxPacket, pktlen);
860 * Handle DHCP received packets.
863 DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
866 Bootp_t *bp = (Bootp_t *)pkt;
868 debug("DHCPHandler: got packet: (src=%d, dst=%d, len=%d) state: %d\n",
869 src, dest, len, dhcp_state);
871 if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */
874 debug("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state: %d\n",
875 src, dest, len, dhcp_state);
877 switch (dhcp_state) {
880 * Wait an appropriate time for any potential DHCPOFFER packets
881 * to arrive. Then select one, and generate DHCPREQUEST response.
882 * If filename is in format we recognize, assume it is a valid
883 * OFFER from a server we want.
885 debug("DHCP: state=SELECTING bp_file: \"%s\"\n", bp->bp_file);
886 #ifdef CONFIG_SYS_BOOTFILE_PREFIX
887 if (strncmp(bp->bp_file,
888 CONFIG_SYS_BOOTFILE_PREFIX,
889 strlen(CONFIG_SYS_BOOTFILE_PREFIX)) == 0 ) {
890 #endif /* CONFIG_SYS_BOOTFILE_PREFIX */
892 debug("TRANSITIONING TO REQUESTING STATE\n");
893 dhcp_state = REQUESTING;
895 if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
896 DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
898 NetSetTimeout(TIMEOUT, BootpTimeout);
899 DhcpSendRequestPkt(bp);
900 #ifdef CONFIG_SYS_BOOTFILE_PREFIX
902 #endif /* CONFIG_SYS_BOOTFILE_PREFIX */
907 debug("DHCP State: REQUESTING\n");
909 if ( DhcpMessageType((u8 *)bp->bp_vend) == DHCP_ACK ) {
912 if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
913 DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
914 BootpCopyNetParams(bp); /* Store net params from reply */
916 printf ("DHCP client bound to address %pI4\n", &NetOurIP);
918 /* Obey the 'autoload' setting */
919 if ((s = getenv("autoload")) != NULL) {
922 * Just use BOOTP to configure system;
923 * Do not use TFTP to load the bootfile.
925 NetState = NETLOOP_SUCCESS;
927 #if defined(CONFIG_CMD_NFS)
928 } else if (strcmp(s, "NFS") == 0) {
930 * Use NFS to load the bootfile.
942 /* DHCP client bound to address */
945 puts ("DHCP: INVALID STATE\n");
951 void DhcpRequest(void)
955 #endif /* CONFIG_CMD_DHCP */