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
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 long dhcp_leasetime = 0;
59 IPaddr_t NetDHCPServerIP = 0;
60 static void DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len);
64 static char *dhcpmsg2str(int type)
67 case 1: return "DHCPDISCOVER"; break;
68 case 2: return "DHCPOFFER"; break;
69 case 3: return "DHCPREQUEST"; break;
70 case 4: return "DHCPDECLINE"; break;
71 case 5: return "DHCPACK"; break;
72 case 6: return "DHCPNACK"; break;
73 case 7: return "DHCPRELEASE"; break;
74 default: return "UNKNOWN/INVALID MSG TYPE"; break;
79 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
80 extern u8 *dhcp_vendorex_prep (u8 *e); /*rtn new e after add own opts. */
81 extern u8 *dhcp_vendorex_proc (u8 *e); /*rtn next e if mine,else NULL */
84 #endif /* CFG_CMD_DHCP */
86 static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
88 Bootp_t *bp = (Bootp_t *) pkt;
91 if (dest != PORT_BOOTPC || src != PORT_BOOTPS)
93 else if (len < sizeof (Bootp_t) - OPT_SIZE)
95 else if (bp->bp_op != OP_BOOTREQUEST &&
96 bp->bp_op != OP_BOOTREPLY &&
97 bp->bp_op != DHCP_OFFER &&
98 bp->bp_op != DHCP_ACK &&
99 bp->bp_op != DHCP_NAK ) {
102 else if (bp->bp_htype != HWT_ETHER)
104 else if (bp->bp_hlen != HWL_ETHER)
106 else if (NetReadLong((ulong*)&bp->bp_id) != BootpID) {
110 debug ("Filtering pkt = %d\n", retval);
116 * Copy parameters of interest from BOOTP_REPLY/DHCP_OFFER packet
118 static void BootpCopyNetParams(Bootp_t *bp)
120 NetCopyIP(&NetOurIP, &bp->bp_yiaddr);
121 NetCopyIP(&NetServerIP, &bp->bp_siaddr);
122 memcpy (NetServerEther, ((Ethernet_t *)NetRxPkt)->et_src, 6);
123 copy_filename (BootFile, bp->bp_file, sizeof(BootFile));
125 debug ("Bootfile: %s\n", BootFile);
127 /* Propagate to environment:
128 * don't delete exising entry when BOOTP / DHCP reply does
129 * not contain a new value
132 setenv ("bootfile", BootFile);
136 static int truncate_sz (const char *name, int maxlen, int curlen)
138 if (curlen >= maxlen) {
139 printf("*** WARNING: %s is too long (%d - max: %d) - truncated\n",
140 name, curlen, maxlen);
146 #if !(CONFIG_COMMANDS & CFG_CMD_DHCP)
148 static void BootpVendorFieldProcess (u8 * ext)
150 int size = *(ext + 1);
152 debug_ext ("[BOOTP] Processing extension %d... (%d bytes)\n", *ext,
158 /* Fixed length fields */
159 case 1: /* Subnet mask */
160 if (NetOurSubnetMask == 0)
161 NetCopyIP (&NetOurSubnetMask, (IPaddr_t *) (ext + 2));
163 case 2: /* Time offset - Not yet supported */
165 /* Variable length fields */
166 case 3: /* Gateways list */
167 if (NetOurGatewayIP == 0) {
168 NetCopyIP (&NetOurGatewayIP, (IPaddr_t *) (ext + 2));
171 case 4: /* Time server - Not yet supported */
173 case 5: /* IEN-116 name server - Not yet supported */
176 if (NetOurDNSIP == 0) {
177 NetCopyIP (&NetOurDNSIP, (IPaddr_t *) (ext + 2));
179 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS2)
180 if ((NetOurDNS2IP == 0) && (size > 4)) {
181 NetCopyIP (&NetOurDNS2IP, (IPaddr_t *) (ext + 2 + 4));
185 case 7: /* Log server - Not yet supported */
187 case 8: /* Cookie/Quote server - Not yet supported */
189 case 9: /* LPR server - Not yet supported */
191 case 10: /* Impress server - Not yet supported */
193 case 11: /* RPL server - Not yet supported */
195 case 12: /* Host name */
196 if (NetOurHostName[0] == 0) {
197 size = truncate_sz ("Host Name", sizeof (NetOurHostName), size);
198 memcpy (&NetOurHostName, ext + 2, size);
199 NetOurHostName[size] = 0;
202 case 13: /* Boot file size */
204 NetBootFileSize = ntohs (*(ushort *) (ext + 2));
206 NetBootFileSize = ntohl (*(ulong *) (ext + 2));
208 case 14: /* Merit dump file - Not yet supported */
210 case 15: /* Domain name - Not yet supported */
212 case 16: /* Swap server - Not yet supported */
214 case 17: /* Root path */
215 if (NetOurRootPath[0] == 0) {
216 size = truncate_sz ("Root Path", sizeof (NetOurRootPath), size);
217 memcpy (&NetOurRootPath, ext + 2, size);
218 NetOurRootPath[size] = 0;
221 case 18: /* Extension path - Not yet supported */
223 * This can be used to send the information of the
224 * vendor area in another file that the client can
228 /* IP host layer fields */
229 case 40: /* NIS Domain name */
230 if (NetOurNISDomain[0] == 0) {
231 size = truncate_sz ("NIS Domain Name", sizeof (NetOurNISDomain), size);
232 memcpy (&NetOurNISDomain, ext + 2, size);
233 NetOurNISDomain[size] = 0;
236 /* Application layer fields */
237 case 43: /* Vendor specific info - Not yet supported */
239 * Binary information to exchange specific
240 * product information.
243 /* Reserved (custom) fields (128..254) */
247 static void BootpVendorProcess (u8 * ext, int size)
249 u8 *end = ext + size;
251 debug_ext ("[BOOTP] Checking extension (%d bytes)...\n", size);
253 while ((ext < end) && (*ext != 0xff)) {
261 BootpVendorFieldProcess (opt);
265 #ifdef DEBUG_BOOTP_EXT
266 printf ("[BOOTP] Received fields: \n");
267 if (NetOurSubnetMask) {
268 puts ("NetOurSubnetMask : ");
269 print_IPaddr (NetOurSubnetMask);
273 if (NetOurGatewayIP) {
274 puts ("NetOurGatewayIP : ");
275 print_IPaddr (NetOurGatewayIP);
279 if (NetBootFileSize) {
280 printf ("NetBootFileSize : %d\n", NetBootFileSize);
283 if (NetOurHostName[0]) {
284 printf ("NetOurHostName : %s\n", NetOurHostName);
287 if (NetOurRootPath[0]) {
288 printf ("NetOurRootPath : %s\n", NetOurRootPath);
291 if (NetOurNISDomain[0]) {
292 printf ("NetOurNISDomain : %s\n", NetOurNISDomain);
295 if (NetBootFileSize) {
296 printf ("NetBootFileSize: %d\n", NetBootFileSize);
298 #endif /* DEBUG_BOOTP_EXT */
301 * Handle a BOOTP received packet.
304 BootpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
309 debug ("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%d)\n",
310 src, dest, len, sizeof (Bootp_t));
314 if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */
318 * Got a good BOOTP reply. Copy the data into our variables.
320 #ifdef CONFIG_STATUS_LED
321 status_led_set (STATUS_LED_BOOT, STATUS_LED_OFF);
324 BootpCopyNetParams(bp); /* Store net parameters from reply */
326 /* Retrieve extended information (we must parse the vendor area) */
327 if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
328 BootpVendorProcess(&bp->bp_vend[4], len);
330 NetSetTimeout(0, (thand_f *)0);
332 debug ("Got good BOOTP\n");
334 if ((s = getenv("autoload")) != NULL) {
337 * Just use BOOTP to configure system;
338 * Do not use TFTP to load the bootfile.
340 NetState = NETLOOP_SUCCESS;
342 #if (CONFIG_COMMANDS & CFG_CMD_NFS)
343 } else if (strcmp(s, "NFS") == 0) {
345 * Use NFS to load the bootfile.
355 #endif /* !CFG_CMD_DHCP */
358 * Timeout on BOOTP/DHCP request.
363 if (BootpTry >= TIMEOUT_COUNT) {
364 puts ("\nRetry count exceeded; starting again\n");
367 NetSetTimeout (TIMEOUT * CFG_HZ, BootpTimeout);
373 * Initialize BOOTP extension fields in the request.
375 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
376 static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t RequestedIP)
381 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
384 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_SEND_HOSTNAME)
388 *e++ = 99; /* RFC1048 Magic Cookie */
393 *e++ = 53; /* DHCP Message Type */
397 *e++ = 57; /* Maximum DHCP Message Size */
399 *e++ = (576 - 312 + OPT_SIZE) >> 8;
400 *e++ = (576 - 312 + OPT_SIZE) & 0xff;
403 int tmp = ntohl (ServerID);
405 *e++ = 54; /* ServerID */
414 int tmp = ntohl (RequestedIP);
416 *e++ = 50; /* Requested IP */
423 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_SEND_HOSTNAME)
424 if ((hostname = getenv ("hostname"))) {
425 int hostnamelen = strlen (hostname);
427 *e++ = 12; /* Hostname */
429 memcpy (e, hostname, hostnamelen);
434 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
435 if ((x = dhcp_vendorex_prep (e)))
439 *e++ = 55; /* Parameter Request List */
440 cnt = e++; /* Pointer to count of requested items */
442 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_SUBNETMASK)
443 *e++ = 1; /* Subnet Mask */
446 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_GATEWAY)
447 *e++ = 3; /* Router Option */
450 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS)
451 *e++ = 6; /* DNS Server(s) */
454 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_HOSTNAME)
455 *e++ = 12; /* Hostname */
458 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_BOOTFILESIZE)
459 *e++ = 13; /* Boot File Size */
462 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_BOOTPATH)
463 *e++ = 17; /* Boot path */
466 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_NISDOMAIN)
467 *e++ = 40; /* NIS Domain name request */
470 *e++ = 255; /* End of the list */
472 /* Pad to minimal length */
473 #ifdef CONFIG_DHCP_MIN_EXT_LEN
474 while ((e - start) <= CONFIG_DHCP_MIN_EXT_LEN)
481 #else /* CFG_CMD_DHCP */
483 * Warning: no field size check - change CONFIG_BOOTP_MASK at your own risk!
485 static int BootpExtended (u8 * e)
489 *e++ = 99; /* RFC1048 Magic Cookie */
494 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
495 *e++ = 53; /* DHCP Message Type */
497 *e++ = DHCP_DISCOVER;
499 *e++ = 57; /* Maximum DHCP Message Size */
501 *e++ = (576 - 312 + OPT_SIZE) >> 16;
502 *e++ = (576 - 312 + OPT_SIZE) & 0xff;
503 #endif /* CFG_CMD_DHCP */
505 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_SUBNETMASK)
506 *e++ = 1; /* Subnet mask request */
511 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_GATEWAY)
512 *e++ = 3; /* Default gateway request */
517 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS)
518 *e++ = 6; /* Domain Name Server */
523 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_HOSTNAME)
524 *e++ = 12; /* Host name request */
529 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_BOOTFILESIZE)
530 *e++ = 13; /* Boot file size */
535 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_BOOTPATH)
536 *e++ = 17; /* Boot path */
541 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_NISDOMAIN)
542 *e++ = 40; /* NIS Domain name request */
547 *e++ = 255; /* End of the list */
551 #endif /* CFG_CMD_DHCP */
556 volatile uchar *pkt, *iphdr;
558 int ext_len, pktlen, iplen;
560 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
564 #ifdef CONFIG_BOOTP_RANDOM_DELAY /* Random BOOTP delay */
565 unsigned char bi_enetaddr[6];
569 ulong tst1, tst2, sum, m_mask, m_value = 0;
573 reg = getenv_r ("ethaddr", tmp, sizeof(tmp));
574 s = (reg > 0) ? tmp : NULL;
576 for (reg=0; reg<6; ++reg) {
577 bi_enetaddr[reg] = s ? simple_strtoul(s, &e, 16) : 0;
583 printf("BootpRequest => Our Mac: ");
584 for (reg=0; reg<6; reg++) {
587 reg==5 ? '\n' : ':');
591 /* Mac-Manipulation 2 get seed1 */
594 for (reg=2; reg<6; reg++) {
596 tst1 = tst1 | bi_enetaddr[reg];
598 for (reg=0; reg<2; reg++) {
599 tst2 = tst2 | bi_enetaddr[reg];
607 for (reg=1;reg<=32;reg++) {
608 m_value |= (m_mask & seed1);
610 m_value = m_value << 1;
616 /* Random Number Generator */
618 for (reg=0;reg<=0;reg++) {
620 if (sum < seed1 || sum < seed2)
625 if (BootpTry<=2) { /* Start with max 1024 * 1ms */
626 sum = sum >> (22-BootpTry);
627 } else { /*After 3rd BOOTP request max 8192 * 1ms */
632 printf ("Random delay: %ld ms...\n", sum);
633 for (reg=0; reg <sum; reg++) {
634 udelay(1000); /*Wait 1ms*/
636 #endif /* CONFIG_BOOTP_RANDOM_DELAY */
638 printf("BOOTP broadcast %d\n", ++BootpTry);
640 memset ((void*)pkt, 0, PKTSIZE);
642 NetSetEther(pkt, NetBcastAddr, PROT_IP);
643 pkt += ETHER_HDR_SIZE;
646 * Next line results in incorrect packet size being transmitted, resulting
647 * in errors in some DHCP servers, reporting missing bytes. Size must be
648 * set in packet header after extension length has been determined.
649 * C. Hallinan, DS4.COM, Inc.
651 /* NetSetIP(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, sizeof (Bootp_t)); */
652 iphdr = pkt; /* We need this later for NetSetIP() */
656 bp->bp_op = OP_BOOTREQUEST;
657 bp->bp_htype = HWT_ETHER;
658 bp->bp_hlen = HWL_ETHER;
660 bp->bp_secs = htons(get_timer(0) / CFG_HZ);
661 NetWriteIP(&bp->bp_ciaddr, 0);
662 NetWriteIP(&bp->bp_yiaddr, 0);
663 NetWriteIP(&bp->bp_siaddr, 0);
664 NetWriteIP(&bp->bp_giaddr, 0);
665 memcpy (bp->bp_chaddr, NetOurEther, 6);
666 copy_filename (bp->bp_file, BootFile, sizeof(bp->bp_file));
668 /* Request additional information from the BOOTP/DHCP server */
669 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
670 ext_len = DhcpExtended(bp->bp_vend, DHCP_DISCOVER, 0, 0);
672 ext_len = BootpExtended(bp->bp_vend);
673 #endif /* CFG_CMD_DHCP */
676 * Bootp ID is the lower 4 bytes of our ethernet address
677 * plus the current time in HZ.
679 BootpID = ((ulong)NetOurEther[2] << 24)
680 | ((ulong)NetOurEther[3] << 16)
681 | ((ulong)NetOurEther[4] << 8)
682 | (ulong)NetOurEther[5];
683 BootpID += get_timer(0);
684 BootpID = htonl(BootpID);
685 NetCopyLong(&bp->bp_id, &BootpID);
688 * Calculate proper packet lengths taking into account the
689 * variable size of the options field
691 pktlen = BOOTP_SIZE - sizeof(bp->bp_vend) + ext_len;
692 iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
693 NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
694 NetSetTimeout(SELECT_TIMEOUT * CFG_HZ, BootpTimeout);
696 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
697 dhcp_state = SELECTING;
698 NetSetHandler(DhcpHandler);
700 NetSetHandler(BootpHandler);
701 #endif /* CFG_CMD_DHCP */
702 NetSendPacket(NetTxPacket, pktlen);
705 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
706 static void DhcpOptionsProcess (uchar * popt)
708 uchar *end = popt + BOOTP_HDR_SIZE;
711 while (popt < end && *popt != 0xff) {
715 NetCopyIP (&NetOurSubnetMask, (popt + 2));
718 NetCopyIP (&NetOurGatewayIP, (popt + 2));
721 NetCopyIP (&NetOurDNSIP, (popt + 2));
722 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_DNS2)
723 if (*(popt + 1) > 4) {
724 NetCopyIP (&NetOurDNS2IP, (popt + 2 + 4));
729 size = truncate_sz ("Host Name", sizeof (NetOurHostName), oplen);
730 memcpy (&NetOurHostName, popt + 2, size);
731 NetOurHostName[size] = 0;
733 case 15: /* Ignore Domain Name Option */
736 size = truncate_sz ("Root Path", sizeof (NetOurRootPath), oplen);
737 memcpy (&NetOurRootPath, popt + 2, size);
738 NetOurRootPath[size] = 0;
741 NetCopyLong (&dhcp_leasetime, (ulong *) (popt + 2));
743 case 53: /* Ignore Message Type Option */
746 NetCopyIP (&NetDHCPServerIP, (popt + 2));
748 case 58: /* Ignore Renewal Time Option */
750 case 59: /* Ignore Rebinding Time Option */
753 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
754 if (dhcp_vendorex_proc (popt))
757 printf ("*** Unhandled DHCP Option in OFFER/ACK: %d\n", *popt);
760 popt += oplen + 2; /* Process next option */
764 static int DhcpMessageType(unsigned char *popt)
766 if (NetReadLong((ulong*)popt) != htonl(BOOTP_VENDOR_MAGIC))
770 while ( *popt != 0xff ) {
771 if ( *popt == 53 ) /* DHCP Message Type */
773 popt += *(popt + 1) + 2; /* Scan through all options */
778 static void DhcpSendRequestPkt(Bootp_t *bp_offer)
780 volatile uchar *pkt, *iphdr;
782 int pktlen, iplen, extlen;
785 debug ("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
787 memset ((void*)pkt, 0, PKTSIZE);
789 NetSetEther(pkt, NetBcastAddr, PROT_IP);
790 pkt += ETHER_HDR_SIZE;
792 iphdr = pkt; /* We'll need this later to set proper pkt size */
796 bp->bp_op = OP_BOOTREQUEST;
797 bp->bp_htype = HWT_ETHER;
798 bp->bp_hlen = HWL_ETHER;
800 bp->bp_secs = htons(get_timer(0) / CFG_HZ);
801 NetCopyIP(&bp->bp_ciaddr, &bp_offer->bp_ciaddr); /* both in network byte order */
802 NetCopyIP(&bp->bp_yiaddr, &bp_offer->bp_yiaddr);
803 NetCopyIP(&bp->bp_siaddr, &bp_offer->bp_siaddr);
804 NetCopyIP(&bp->bp_giaddr, &bp_offer->bp_giaddr);
805 memcpy (bp->bp_chaddr, NetOurEther, 6);
808 * ID is the id of the OFFER packet
811 NetCopyLong(&bp->bp_id, &bp_offer->bp_id);
814 * Copy options from OFFER packet if present
816 NetCopyIP(&OfferedIP, &bp->bp_yiaddr);
817 extlen = DhcpExtended(bp->bp_vend, DHCP_REQUEST, NetDHCPServerIP, OfferedIP);
819 pktlen = BOOTP_SIZE - sizeof(bp->bp_vend) + extlen;
820 iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
821 NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
823 debug ("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);
824 NetSendPacket(NetTxPacket, pktlen);
828 * Handle DHCP received packets.
831 DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
833 Bootp_t *bp = (Bootp_t *)pkt;
835 debug ("DHCPHandler: got packet: (src=%d, dst=%d, len=%d) state: %d\n",
836 src, dest, len, dhcp_state);
838 if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */
841 debug ("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state: %d\n",
842 src, dest, len, dhcp_state);
844 switch (dhcp_state) {
847 * Wait an appropriate time for any potential DHCPOFFER packets
848 * to arrive. Then select one, and generate DHCPREQUEST response.
849 * If filename is in format we recognize, assume it is a valid
850 * OFFER from a server we want.
852 debug ("DHCP: state=SELECTING bp_file: \"%s\"\n", bp->bp_file);
853 #ifdef CFG_BOOTFILE_PREFIX
854 if (strncmp(bp->bp_file,
856 strlen(CFG_BOOTFILE_PREFIX)) == 0 ) {
857 #endif /* CFG_BOOTFILE_PREFIX */
859 debug ("TRANSITIONING TO REQUESTING STATE\n");
860 dhcp_state = REQUESTING;
862 if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
863 DhcpOptionsProcess(&bp->bp_vend[4]);
865 BootpCopyNetParams(bp); /* Store net params from reply */
867 NetSetTimeout(TIMEOUT * CFG_HZ, BootpTimeout);
868 DhcpSendRequestPkt(bp);
869 #ifdef CFG_BOOTFILE_PREFIX
871 #endif /* CFG_BOOTFILE_PREFIX */
876 debug ("DHCP State: REQUESTING\n");
878 if ( DhcpMessageType(bp->bp_vend) == DHCP_ACK ) {
881 if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
882 DhcpOptionsProcess(&bp->bp_vend[4]);
883 BootpCopyNetParams(bp); /* Store net params from reply */
885 printf("DHCP client bound to address ");
886 print_IPaddr(NetOurIP);
889 /* Obey the 'autoload' setting */
890 if ((s = getenv("autoload")) != NULL) {
893 * Just use BOOTP to configure system;
894 * Do not use TFTP to load the bootfile.
896 NetState = NETLOOP_SUCCESS;
898 #if (CONFIG_COMMANDS & CFG_CMD_NFS)
899 } else if (strcmp(s, "NFS") == 0) {
901 * Use NFS to load the bootfile.
913 printf("DHCP: INVALID STATE\n");
919 void DhcpRequest(void)
923 #endif /* CFG_CMD_DHCP */
925 #endif /* CFG_CMD_NET */