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);
142 * Check if autoload is enabled. If so, use either NFS or TFTP to download
145 static void auto_load(void)
147 const char *s = getenv("autoload");
152 * Just use BOOTP to configure system;
153 * Do not use TFTP to load the bootfile.
155 NetState = NETLOOP_SUCCESS;
158 #if defined(CONFIG_CMD_NFS)
159 if (strcmp(s, "NFS") == 0) {
161 * Use NFS to load the bootfile.
171 #if !defined(CONFIG_CMD_DHCP)
173 static void BootpVendorFieldProcess (u8 * ext)
175 int size = *(ext + 1);
177 debug("[BOOTP] Processing extension %d... (%d bytes)\n", *ext,
183 /* Fixed length fields */
184 case 1: /* Subnet mask */
185 if (NetOurSubnetMask == 0)
186 NetCopyIP (&NetOurSubnetMask, (IPaddr_t *) (ext + 2));
188 case 2: /* Time offset - Not yet supported */
190 /* Variable length fields */
191 case 3: /* Gateways list */
192 if (NetOurGatewayIP == 0) {
193 NetCopyIP (&NetOurGatewayIP, (IPaddr_t *) (ext + 2));
196 case 4: /* Time server - Not yet supported */
198 case 5: /* IEN-116 name server - Not yet supported */
201 if (NetOurDNSIP == 0) {
202 NetCopyIP (&NetOurDNSIP, (IPaddr_t *) (ext + 2));
204 #if defined(CONFIG_BOOTP_DNS2)
205 if ((NetOurDNS2IP == 0) && (size > 4)) {
206 NetCopyIP (&NetOurDNS2IP, (IPaddr_t *) (ext + 2 + 4));
210 case 7: /* Log server - Not yet supported */
212 case 8: /* Cookie/Quote server - Not yet supported */
214 case 9: /* LPR server - Not yet supported */
216 case 10: /* Impress server - Not yet supported */
218 case 11: /* RPL server - Not yet supported */
220 case 12: /* Host name */
221 if (NetOurHostName[0] == 0) {
222 size = truncate_sz ("Host Name", sizeof (NetOurHostName), size);
223 memcpy (&NetOurHostName, ext + 2, size);
224 NetOurHostName[size] = 0;
227 case 13: /* Boot file size */
229 NetBootFileSize = ntohs (*(ushort *) (ext + 2));
231 NetBootFileSize = ntohl (*(ulong *) (ext + 2));
233 case 14: /* Merit dump file - Not yet supported */
235 case 15: /* Domain name - Not yet supported */
237 case 16: /* Swap server - Not yet supported */
239 case 17: /* Root path */
240 if (NetOurRootPath[0] == 0) {
241 size = truncate_sz ("Root Path", sizeof (NetOurRootPath), size);
242 memcpy (&NetOurRootPath, ext + 2, size);
243 NetOurRootPath[size] = 0;
246 case 18: /* Extension path - Not yet supported */
248 * This can be used to send the information of the
249 * vendor area in another file that the client can
253 /* IP host layer fields */
254 case 40: /* NIS Domain name */
255 if (NetOurNISDomain[0] == 0) {
256 size = truncate_sz ("NIS Domain Name", sizeof (NetOurNISDomain), size);
257 memcpy (&NetOurNISDomain, ext + 2, size);
258 NetOurNISDomain[size] = 0;
261 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
262 case 42: /* NTP server IP */
263 NetCopyIP(&NetNtpServerIP, (IPaddr_t *) (ext + 2));
266 /* Application layer fields */
267 case 43: /* Vendor specific info - Not yet supported */
269 * Binary information to exchange specific
270 * product information.
273 /* Reserved (custom) fields (128..254) */
277 static void BootpVendorProcess (u8 * ext, int size)
279 u8 *end = ext + size;
281 debug("[BOOTP] Checking extension (%d bytes)...\n", size);
283 while ((ext < end) && (*ext != 0xff)) {
291 BootpVendorFieldProcess (opt);
295 debug("[BOOTP] Received fields: \n");
296 if (NetOurSubnetMask)
297 debug("NetOurSubnetMask : %pI4\n", &NetOurSubnetMask);
300 debug("NetOurGatewayIP : %pI4", &NetOurGatewayIP);
303 debug("NetBootFileSize : %d\n", NetBootFileSize);
305 if (NetOurHostName[0])
306 debug("NetOurHostName : %s\n", NetOurHostName);
308 if (NetOurRootPath[0])
309 debug("NetOurRootPath : %s\n", NetOurRootPath);
311 if (NetOurNISDomain[0])
312 debug("NetOurNISDomain : %s\n", NetOurNISDomain);
315 debug("NetBootFileSize: %d\n", NetBootFileSize);
317 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
319 debug("NetNtpServerIP : %pI4\n", &NetNtpServerIP);
324 * Handle a BOOTP received packet.
327 BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
332 debug("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%zu)\n",
333 src, dest, len, sizeof (Bootp_t));
337 if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */
341 * Got a good BOOTP reply. Copy the data into our variables.
343 #ifdef CONFIG_STATUS_LED
344 status_led_set (STATUS_LED_BOOT, STATUS_LED_OFF);
347 BootpCopyNetParams(bp); /* Store net parameters from reply */
349 /* Retrieve extended information (we must parse the vendor area) */
350 if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
351 BootpVendorProcess((uchar *)&bp->bp_vend[4], len);
353 NetSetTimeout(0, (thand_f *)0);
355 debug("Got good BOOTP\n");
362 * Timeout on BOOTP/DHCP request.
367 if (BootpTry >= TIMEOUT_COUNT) {
368 puts ("\nRetry count exceeded; starting again\n");
371 NetSetTimeout (TIMEOUT, BootpTimeout);
377 * Initialize BOOTP extension fields in the request.
379 #if defined(CONFIG_CMD_DHCP)
380 static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t RequestedIP)
385 #if defined(CONFIG_BOOTP_VENDOREX)
388 #if defined(CONFIG_BOOTP_SEND_HOSTNAME)
392 *e++ = 99; /* RFC1048 Magic Cookie */
397 *e++ = 53; /* DHCP Message Type */
401 *e++ = 57; /* Maximum DHCP Message Size */
403 *e++ = (576 - 312 + OPT_SIZE) >> 8;
404 *e++ = (576 - 312 + OPT_SIZE) & 0xff;
407 int tmp = ntohl (ServerID);
409 *e++ = 54; /* ServerID */
418 int tmp = ntohl (RequestedIP);
420 *e++ = 50; /* Requested IP */
427 #if defined(CONFIG_BOOTP_SEND_HOSTNAME)
428 if ((hostname = getenv ("hostname"))) {
429 int hostnamelen = strlen (hostname);
431 *e++ = 12; /* Hostname */
433 memcpy (e, hostname, hostnamelen);
438 #if defined(CONFIG_BOOTP_VENDOREX)
439 if ((x = dhcp_vendorex_prep (e)))
443 *e++ = 55; /* Parameter Request List */
444 cnt = e++; /* Pointer to count of requested items */
446 #if defined(CONFIG_BOOTP_SUBNETMASK)
447 *e++ = 1; /* Subnet Mask */
450 #if defined(CONFIG_BOOTP_TIMEOFFSET)
454 #if defined(CONFIG_BOOTP_GATEWAY)
455 *e++ = 3; /* Router Option */
458 #if defined(CONFIG_BOOTP_DNS)
459 *e++ = 6; /* DNS Server(s) */
462 #if defined(CONFIG_BOOTP_HOSTNAME)
463 *e++ = 12; /* Hostname */
466 #if defined(CONFIG_BOOTP_BOOTFILESIZE)
467 *e++ = 13; /* Boot File Size */
470 #if defined(CONFIG_BOOTP_BOOTPATH)
471 *e++ = 17; /* Boot path */
474 #if defined(CONFIG_BOOTP_NISDOMAIN)
475 *e++ = 40; /* NIS Domain name request */
478 #if defined(CONFIG_BOOTP_NTPSERVER)
482 /* no options, so back up to avoid sending an empty request list */
486 *e++ = 255; /* End of the list */
488 /* Pad to minimal length */
489 #ifdef CONFIG_DHCP_MIN_EXT_LEN
490 while ((e - start) < CONFIG_DHCP_MIN_EXT_LEN)
499 * Warning: no field size check - change CONFIG_BOOTP_* at your own risk!
501 static int BootpExtended (u8 * e)
505 *e++ = 99; /* RFC1048 Magic Cookie */
510 #if defined(CONFIG_CMD_DHCP)
511 *e++ = 53; /* DHCP Message Type */
513 *e++ = DHCP_DISCOVER;
515 *e++ = 57; /* Maximum DHCP Message Size */
517 *e++ = (576 - 312 + OPT_SIZE) >> 16;
518 *e++ = (576 - 312 + OPT_SIZE) & 0xff;
521 #if defined(CONFIG_BOOTP_SUBNETMASK)
522 *e++ = 1; /* Subnet mask request */
527 #if defined(CONFIG_BOOTP_GATEWAY)
528 *e++ = 3; /* Default gateway request */
533 #if defined(CONFIG_BOOTP_DNS)
534 *e++ = 6; /* Domain Name Server */
539 #if defined(CONFIG_BOOTP_HOSTNAME)
540 *e++ = 12; /* Host name request */
545 #if defined(CONFIG_BOOTP_BOOTFILESIZE)
546 *e++ = 13; /* Boot file size */
551 #if defined(CONFIG_BOOTP_BOOTPATH)
552 *e++ = 17; /* Boot path */
557 #if defined(CONFIG_BOOTP_NISDOMAIN)
558 *e++ = 40; /* NIS Domain name request */
562 #if defined(CONFIG_BOOTP_NTPSERVER)
568 *e++ = 255; /* End of the list */
577 volatile uchar *pkt, *iphdr;
579 int ext_len, pktlen, iplen;
581 #if defined(CONFIG_CMD_DHCP)
585 #ifdef CONFIG_BOOTP_RANDOM_DELAY /* Random BOOTP delay */
586 unsigned char bi_enetaddr[6];
588 ulong tst1, tst2, sum, m_mask, m_value = 0;
592 eth_getenv_enetaddr("ethaddr", bi_enetaddr);
594 debug("BootpRequest => Our Mac: ");
595 for (reg=0; reg<6; reg++)
596 debug("%x%c", bi_enetaddr[reg], reg==5 ? '\n' : ':');
598 /* Mac-Manipulation 2 get seed1 */
601 for (reg=2; reg<6; reg++) {
603 tst1 = tst1 | bi_enetaddr[reg];
605 for (reg=0; reg<2; reg++) {
606 tst2 = tst2 | bi_enetaddr[reg];
614 for (reg=1;reg<=32;reg++) {
615 m_value |= (m_mask & seed1);
617 m_value = m_value << 1;
623 /* Random Number Generator */
625 for (reg=0;reg<=0;reg++) {
627 if (sum < seed1 || sum < seed2)
632 if (BootpTry<=2) { /* Start with max 1024 * 1ms */
633 sum = sum >> (22-BootpTry);
634 } else { /*After 3rd BOOTP request max 8192 * 1ms */
639 printf ("Random delay: %ld ms...\n", sum);
640 for (reg=0; reg <sum; reg++) {
641 udelay(1000); /*Wait 1ms*/
643 #endif /* CONFIG_BOOTP_RANDOM_DELAY */
645 printf("BOOTP broadcast %d\n", ++BootpTry);
647 memset ((void*)pkt, 0, PKTSIZE);
649 pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
652 * Next line results in incorrect packet size being transmitted, resulting
653 * in errors in some DHCP servers, reporting missing bytes. Size must be
654 * set in packet header after extension length has been determined.
655 * C. Hallinan, DS4.COM, Inc.
657 /* NetSetIP(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, sizeof (Bootp_t)); */
658 iphdr = pkt; /* We need this later for NetSetIP() */
662 bp->bp_op = OP_BOOTREQUEST;
663 bp->bp_htype = HWT_ETHER;
664 bp->bp_hlen = HWL_ETHER;
666 bp->bp_secs = htons(get_timer(0) / 1000);
667 NetWriteIP(&bp->bp_ciaddr, 0);
668 NetWriteIP(&bp->bp_yiaddr, 0);
669 NetWriteIP(&bp->bp_siaddr, 0);
670 NetWriteIP(&bp->bp_giaddr, 0);
671 memcpy (bp->bp_chaddr, NetOurEther, 6);
672 copy_filename (bp->bp_file, BootFile, sizeof(bp->bp_file));
674 /* Request additional information from the BOOTP/DHCP server */
675 #if defined(CONFIG_CMD_DHCP)
676 ext_len = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0);
678 ext_len = BootpExtended((u8 *)bp->bp_vend);
682 * Bootp ID is the lower 4 bytes of our ethernet address
683 * plus the current time in ms.
685 BootpID = ((ulong)NetOurEther[2] << 24)
686 | ((ulong)NetOurEther[3] << 16)
687 | ((ulong)NetOurEther[4] << 8)
688 | (ulong)NetOurEther[5];
689 BootpID += get_timer(0);
690 BootpID = htonl(BootpID);
691 NetCopyLong(&bp->bp_id, &BootpID);
694 * Calculate proper packet lengths taking into account the
695 * variable size of the options field
697 pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
698 iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
699 NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
700 NetSetTimeout(SELECT_TIMEOUT, BootpTimeout);
702 #if defined(CONFIG_CMD_DHCP)
703 dhcp_state = SELECTING;
704 NetSetHandler(DhcpHandler);
706 NetSetHandler(BootpHandler);
708 NetSendPacket(NetTxPacket, pktlen);
711 #if defined(CONFIG_CMD_DHCP)
712 static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp)
714 uchar *end = popt + BOOTP_HDR_SIZE;
716 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
720 while (popt < end && *popt != 0xff) {
724 NetCopyIP (&NetOurSubnetMask, (popt + 2));
726 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
727 case 2: /* Time offset */
728 to_ptr = &NetTimeOffset;
729 NetCopyLong ((ulong *)to_ptr, (ulong *)(popt + 2));
730 NetTimeOffset = ntohl (NetTimeOffset);
734 NetCopyIP (&NetOurGatewayIP, (popt + 2));
737 NetCopyIP (&NetOurDNSIP, (popt + 2));
738 #if defined(CONFIG_BOOTP_DNS2)
739 if (*(popt + 1) > 4) {
740 NetCopyIP (&NetOurDNS2IP, (popt + 2 + 4));
745 size = truncate_sz ("Host Name", sizeof (NetOurHostName), oplen);
746 memcpy (&NetOurHostName, popt + 2, size);
747 NetOurHostName[size] = 0;
749 case 15: /* Ignore Domain Name Option */
752 size = truncate_sz ("Root Path", sizeof (NetOurRootPath), oplen);
753 memcpy (&NetOurRootPath, popt + 2, size);
754 NetOurRootPath[size] = 0;
756 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
757 case 42: /* NTP server IP */
758 NetCopyIP (&NetNtpServerIP, (popt + 2));
762 NetCopyLong (&dhcp_leasetime, (ulong *) (popt + 2));
764 case 53: /* Ignore Message Type Option */
767 NetCopyIP (&NetDHCPServerIP, (popt + 2));
769 case 58: /* Ignore Renewal Time Option */
771 case 59: /* Ignore Rebinding Time Option */
773 case 66: /* Ignore TFTP server name */
775 case 67: /* vendor opt bootfile */
777 * I can't use dhcp_vendorex_proc here because I need
778 * to write into the bootp packet - even then I had to
779 * pass the bootp packet pointer into here as the
782 size = truncate_sz ("Opt Boot File",
785 if (bp->bp_file[0] == '\0' && size > 0) {
787 * only use vendor boot file if we didn't
788 * receive a boot file in the main non-vendor
789 * part of the packet - god only knows why
790 * some vendors chose not to use this perfectly
791 * good spot to store the boot file (join on
792 * Tru64 Unix) it seems mind bogglingly crazy
795 printf("*** WARNING: using vendor "
796 "optional boot file\n");
797 memcpy(bp->bp_file, popt + 2, size);
798 bp->bp_file[size] = '\0';
802 #if defined(CONFIG_BOOTP_VENDOREX)
803 if (dhcp_vendorex_proc (popt))
806 printf ("*** Unhandled DHCP Option in OFFER/ACK: %d\n", *popt);
809 popt += oplen + 2; /* Process next option */
813 static int DhcpMessageType(unsigned char *popt)
815 if (NetReadLong((ulong*)popt) != htonl(BOOTP_VENDOR_MAGIC))
819 while ( *popt != 0xff ) {
820 if ( *popt == 53 ) /* DHCP Message Type */
822 popt += *(popt + 1) + 2; /* Scan through all options */
827 static void DhcpSendRequestPkt(Bootp_t *bp_offer)
829 volatile uchar *pkt, *iphdr;
831 int pktlen, iplen, extlen;
834 debug("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
836 memset ((void*)pkt, 0, PKTSIZE);
838 pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
840 iphdr = pkt; /* We'll need this later to set proper pkt size */
844 bp->bp_op = OP_BOOTREQUEST;
845 bp->bp_htype = HWT_ETHER;
846 bp->bp_hlen = HWL_ETHER;
848 bp->bp_secs = htons(get_timer(0) / 1000);
849 /* Do not set the client IP, your IP, or server IP yet, since it hasn't been ACK'ed by
853 * RFC3046 requires Relay Agents to discard packets with
854 * nonzero and offered giaddr
856 NetWriteIP(&bp->bp_giaddr, 0);
858 memcpy (bp->bp_chaddr, NetOurEther, 6);
861 * ID is the id of the OFFER packet
864 NetCopyLong(&bp->bp_id, &bp_offer->bp_id);
867 * Copy options from OFFER packet if present
870 /* Copy offered IP into the parameters request list */
871 NetCopyIP(&OfferedIP, &bp_offer->bp_yiaddr);
872 extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST, NetDHCPServerIP, OfferedIP);
874 pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
875 iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
876 NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
878 debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);
879 #ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY
880 udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY);
881 #endif /* CONFIG_BOOTP_DHCP_REQUEST_DELAY */
882 NetSendPacket(NetTxPacket, pktlen);
886 * Handle DHCP received packets.
889 DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
892 Bootp_t *bp = (Bootp_t *)pkt;
894 debug("DHCPHandler: got packet: (src=%d, dst=%d, len=%d) state: %d\n",
895 src, dest, len, dhcp_state);
897 if (BootpCheckPkt(pkt, dest, src, len)) /* Filter out pkts we don't want */
900 debug("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state: %d\n",
901 src, dest, len, dhcp_state);
903 switch (dhcp_state) {
906 * Wait an appropriate time for any potential DHCPOFFER packets
907 * to arrive. Then select one, and generate DHCPREQUEST response.
908 * If filename is in format we recognize, assume it is a valid
909 * OFFER from a server we want.
911 debug("DHCP: state=SELECTING bp_file: \"%s\"\n", bp->bp_file);
912 #ifdef CONFIG_SYS_BOOTFILE_PREFIX
913 if (strncmp(bp->bp_file,
914 CONFIG_SYS_BOOTFILE_PREFIX,
915 strlen(CONFIG_SYS_BOOTFILE_PREFIX)) == 0 ) {
916 #endif /* CONFIG_SYS_BOOTFILE_PREFIX */
918 debug("TRANSITIONING TO REQUESTING STATE\n");
919 dhcp_state = REQUESTING;
921 if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
922 DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
924 NetSetTimeout(TIMEOUT, BootpTimeout);
925 DhcpSendRequestPkt(bp);
926 #ifdef CONFIG_SYS_BOOTFILE_PREFIX
928 #endif /* CONFIG_SYS_BOOTFILE_PREFIX */
933 debug("DHCP State: REQUESTING\n");
935 if ( DhcpMessageType((u8 *)bp->bp_vend) == DHCP_ACK ) {
936 if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
937 DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
938 BootpCopyNetParams(bp); /* Store net params from reply */
940 printf ("DHCP client bound to address %pI4\n", &NetOurIP);
947 /* DHCP client bound to address */
950 puts ("DHCP: INVALID STATE\n");
956 void DhcpRequest(void)
960 #endif /* CONFIG_CMD_DHCP */