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
18 #ifdef CONFIG_STATUS_LED
19 #include <status_led.h>
21 #include <linux/compiler.h>
23 #define BOOTP_VENDOR_MAGIC 0x63825363 /* RFC1048 Magic Cookie */
25 #define TIMEOUT 5000UL /* Milliseconds before trying BOOTP again */
26 #ifndef CONFIG_NET_RETRY_COUNT
27 # define TIMEOUT_COUNT 5 /* # of timeouts before giving up */
29 # define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT)
32 #define PORT_BOOTPS 67 /* BOOTP server UDP port */
33 #define PORT_BOOTPC 68 /* BOOTP client UDP port */
35 #ifndef CONFIG_DHCP_MIN_EXT_LEN /* minimal length of extension list */
36 #define CONFIG_DHCP_MIN_EXT_LEN 64
42 #if defined(CONFIG_CMD_DHCP)
43 dhcp_state_t dhcp_state = INIT;
44 unsigned long dhcp_leasetime;
45 IPaddr_t NetDHCPServerIP;
46 static void DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
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;
67 static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
69 struct Bootp_t *bp = (struct Bootp_t *) pkt;
72 if (dest != PORT_BOOTPC || src != PORT_BOOTPS)
74 else if (len < sizeof(struct Bootp_t) - OPT_SIZE)
76 else if (bp->bp_op != OP_BOOTREQUEST &&
77 bp->bp_op != OP_BOOTREPLY &&
78 bp->bp_op != DHCP_OFFER &&
79 bp->bp_op != DHCP_ACK &&
80 bp->bp_op != DHCP_NAK)
82 else if (bp->bp_htype != HWT_ETHER)
84 else if (bp->bp_hlen != HWL_ETHER)
86 else if (NetReadLong((ulong *)&bp->bp_id) != BootpID)
89 debug("Filtering pkt = %d\n", retval);
95 * Copy parameters of interest from BOOTP_REPLY/DHCP_OFFER packet
97 static void BootpCopyNetParams(struct Bootp_t *bp)
99 __maybe_unused IPaddr_t tmp_ip;
101 NetCopyIP(&NetOurIP, &bp->bp_yiaddr);
102 #if !defined(CONFIG_BOOTP_SERVERIP)
103 NetCopyIP(&tmp_ip, &bp->bp_siaddr);
105 NetCopyIP(&NetServerIP, &bp->bp_siaddr);
106 memcpy(NetServerEther, ((struct ethernet_hdr *)NetRxPacket)->et_src, 6);
108 if (strlen(bp->bp_file) > 0)
109 copy_filename(BootFile, bp->bp_file, sizeof(BootFile));
111 debug("Bootfile: %s\n", BootFile);
113 /* Propagate to environment:
114 * don't delete exising entry when BOOTP / DHCP reply does
115 * not contain a new value
118 setenv("bootfile", BootFile);
121 static int truncate_sz(const char *name, int maxlen, int curlen)
123 if (curlen >= maxlen) {
124 printf("*** WARNING: %s is too long (%d - max: %d)"
125 " - truncated\n", name, curlen, maxlen);
131 #if !defined(CONFIG_CMD_DHCP)
133 static void BootpVendorFieldProcess(u8 *ext)
135 int size = *(ext + 1);
137 debug("[BOOTP] Processing extension %d... (%d bytes)\n", *ext,
143 /* Fixed length fields */
144 case 1: /* Subnet mask */
145 if (NetOurSubnetMask == 0)
146 NetCopyIP(&NetOurSubnetMask, (IPaddr_t *) (ext + 2));
148 case 2: /* Time offset - Not yet supported */
150 /* Variable length fields */
151 case 3: /* Gateways list */
152 if (NetOurGatewayIP == 0)
153 NetCopyIP(&NetOurGatewayIP, (IPaddr_t *) (ext + 2));
155 case 4: /* Time server - Not yet supported */
157 case 5: /* IEN-116 name server - Not yet supported */
160 if (NetOurDNSIP == 0)
161 NetCopyIP(&NetOurDNSIP, (IPaddr_t *) (ext + 2));
162 #if defined(CONFIG_BOOTP_DNS2)
163 if ((NetOurDNS2IP == 0) && (size > 4))
164 NetCopyIP(&NetOurDNS2IP, (IPaddr_t *) (ext + 2 + 4));
167 case 7: /* Log server - Not yet supported */
169 case 8: /* Cookie/Quote server - Not yet supported */
171 case 9: /* LPR server - Not yet supported */
173 case 10: /* Impress server - Not yet supported */
175 case 11: /* RPL server - Not yet supported */
177 case 12: /* Host name */
178 if (NetOurHostName[0] == 0) {
179 size = truncate_sz("Host Name",
180 sizeof(NetOurHostName), size);
181 memcpy(&NetOurHostName, ext + 2, size);
182 NetOurHostName[size] = 0;
185 case 13: /* Boot file size */
187 NetBootFileSize = ntohs(*(ushort *) (ext + 2));
189 NetBootFileSize = ntohl(*(ulong *) (ext + 2));
191 case 14: /* Merit dump file - Not yet supported */
193 case 15: /* Domain name - Not yet supported */
195 case 16: /* Swap server - Not yet supported */
197 case 17: /* Root path */
198 if (NetOurRootPath[0] == 0) {
199 size = truncate_sz("Root Path",
200 sizeof(NetOurRootPath), size);
201 memcpy(&NetOurRootPath, ext + 2, size);
202 NetOurRootPath[size] = 0;
205 case 18: /* Extension path - Not yet supported */
207 * This can be used to send the information of the
208 * vendor area in another file that the client can
212 /* IP host layer fields */
213 case 40: /* NIS Domain name */
214 if (NetOurNISDomain[0] == 0) {
215 size = truncate_sz("NIS Domain Name",
216 sizeof(NetOurNISDomain), size);
217 memcpy(&NetOurNISDomain, ext + 2, size);
218 NetOurNISDomain[size] = 0;
221 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
222 case 42: /* NTP server IP */
223 NetCopyIP(&NetNtpServerIP, (IPaddr_t *) (ext + 2));
226 /* Application layer fields */
227 case 43: /* Vendor specific info - Not yet supported */
229 * Binary information to exchange specific
230 * product information.
233 /* Reserved (custom) fields (128..254) */
237 static void BootpVendorProcess(u8 *ext, int size)
239 u8 *end = ext + size;
241 debug("[BOOTP] Checking extension (%d bytes)...\n", size);
243 while ((ext < end) && (*ext != 0xff)) {
251 BootpVendorFieldProcess(opt);
255 debug("[BOOTP] Received fields:\n");
256 if (NetOurSubnetMask)
257 debug("NetOurSubnetMask : %pI4\n", &NetOurSubnetMask);
260 debug("NetOurGatewayIP : %pI4", &NetOurGatewayIP);
263 debug("NetBootFileSize : %d\n", NetBootFileSize);
265 if (NetOurHostName[0])
266 debug("NetOurHostName : %s\n", NetOurHostName);
268 if (NetOurRootPath[0])
269 debug("NetOurRootPath : %s\n", NetOurRootPath);
271 if (NetOurNISDomain[0])
272 debug("NetOurNISDomain : %s\n", NetOurNISDomain);
275 debug("NetBootFileSize: %d\n", NetBootFileSize);
277 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
279 debug("NetNtpServerIP : %pI4\n", &NetNtpServerIP);
284 * Handle a BOOTP received packet.
287 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(struct Bootp_t));
295 bp = (struct Bootp_t *)pkt;
297 /* Filter out pkts we don't want */
298 if (BootpCheckPkt(pkt, dest, src, len))
302 * Got a good BOOTP reply. Copy the data into our variables.
304 #ifdef CONFIG_STATUS_LED
305 status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF);
308 BootpCopyNetParams(bp); /* Store net parameters from reply */
310 /* Retrieve extended information (we must parse the vendor area) */
311 if (NetReadLong((ulong *)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
312 BootpVendorProcess((uchar *)&bp->bp_vend[4], len);
314 NetSetTimeout(0, (thand_f *)0);
315 bootstage_mark_name(BOOTSTAGE_ID_BOOTP_STOP, "bootp_stop");
317 debug("Got good BOOTP\n");
324 * Timeout on BOOTP/DHCP request.
329 if (BootpTry >= TIMEOUT_COUNT) {
330 puts("\nRetry count exceeded; starting again\n");
333 NetSetTimeout(TIMEOUT, BootpTimeout);
339 * Initialize BOOTP extension fields in the request.
341 #if defined(CONFIG_CMD_DHCP)
342 static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID,
343 IPaddr_t RequestedIP)
347 #if defined(CONFIG_BOOTP_PXE)
353 #if defined(CONFIG_BOOTP_VENDOREX)
356 #if defined(CONFIG_BOOTP_SEND_HOSTNAME)
360 *e++ = 99; /* RFC1048 Magic Cookie */
365 *e++ = 53; /* DHCP Message Type */
369 *e++ = 57; /* Maximum DHCP Message Size */
371 *e++ = (576 - 312 + OPT_SIZE) >> 8;
372 *e++ = (576 - 312 + OPT_SIZE) & 0xff;
375 int tmp = ntohl(ServerID);
377 *e++ = 54; /* ServerID */
386 int tmp = ntohl(RequestedIP);
388 *e++ = 50; /* Requested IP */
395 #if defined(CONFIG_BOOTP_SEND_HOSTNAME)
396 hostname = getenv("hostname");
398 int hostnamelen = strlen(hostname);
400 *e++ = 12; /* Hostname */
402 memcpy(e, hostname, hostnamelen);
407 #if defined(CONFIG_BOOTP_PXE)
408 clientarch = CONFIG_BOOTP_PXE_CLIENTARCH;
409 *e++ = 93; /* Client System Architecture */
411 *e++ = (clientarch >> 8) & 0xff;
412 *e++ = clientarch & 0xff;
414 *e++ = 94; /* Client Network Interface Identifier */
416 *e++ = 1; /* type field for UNDI */
417 *e++ = 0; /* major revision */
418 *e++ = 0; /* minor revision */
420 uuid = getenv("pxeuuid");
423 if (uuid_str_valid(uuid)) {
424 *e++ = 97; /* Client Machine Identifier */
426 *e++ = 0; /* type 0 - UUID */
428 uuid_str_to_bin(uuid, e);
431 printf("Invalid pxeuuid: %s\n", uuid);
435 *e++ = 60; /* Vendor Class Identifier */
436 vci_strlen = strlen(CONFIG_BOOTP_VCI_STRING);
438 memcpy(e, CONFIG_BOOTP_VCI_STRING, vci_strlen);
442 #if defined(CONFIG_BOOTP_VENDOREX)
443 x = dhcp_vendorex_prep(e);
448 *e++ = 55; /* Parameter Request List */
449 cnt = e++; /* Pointer to count of requested items */
451 #if defined(CONFIG_BOOTP_SUBNETMASK)
452 *e++ = 1; /* Subnet Mask */
455 #if defined(CONFIG_BOOTP_TIMEOFFSET)
459 #if defined(CONFIG_BOOTP_GATEWAY)
460 *e++ = 3; /* Router Option */
463 #if defined(CONFIG_BOOTP_DNS)
464 *e++ = 6; /* DNS Server(s) */
467 #if defined(CONFIG_BOOTP_HOSTNAME)
468 *e++ = 12; /* Hostname */
471 #if defined(CONFIG_BOOTP_BOOTFILESIZE)
472 *e++ = 13; /* Boot File Size */
475 #if defined(CONFIG_BOOTP_BOOTPATH)
476 *e++ = 17; /* Boot path */
479 #if defined(CONFIG_BOOTP_NISDOMAIN)
480 *e++ = 40; /* NIS Domain name request */
483 #if defined(CONFIG_BOOTP_NTPSERVER)
487 /* no options, so back up to avoid sending an empty request list */
491 *e++ = 255; /* End of the list */
493 /* Pad to minimal length */
494 #ifdef CONFIG_DHCP_MIN_EXT_LEN
495 while ((e - start) < CONFIG_DHCP_MIN_EXT_LEN)
504 * Warning: no field size check - change CONFIG_BOOTP_* at your own risk!
506 static int BootpExtended(u8 *e)
510 *e++ = 99; /* RFC1048 Magic Cookie */
515 #if defined(CONFIG_CMD_DHCP)
516 *e++ = 53; /* DHCP Message Type */
518 *e++ = DHCP_DISCOVER;
520 *e++ = 57; /* Maximum DHCP Message Size */
522 *e++ = (576 - 312 + OPT_SIZE) >> 16;
523 *e++ = (576 - 312 + OPT_SIZE) & 0xff;
526 #if defined(CONFIG_BOOTP_SUBNETMASK)
527 *e++ = 1; /* Subnet mask request */
532 #if defined(CONFIG_BOOTP_GATEWAY)
533 *e++ = 3; /* Default gateway request */
538 #if defined(CONFIG_BOOTP_DNS)
539 *e++ = 6; /* Domain Name Server */
544 #if defined(CONFIG_BOOTP_HOSTNAME)
545 *e++ = 12; /* Host name request */
550 #if defined(CONFIG_BOOTP_BOOTFILESIZE)
551 *e++ = 13; /* Boot file size */
556 #if defined(CONFIG_BOOTP_BOOTPATH)
557 *e++ = 17; /* Boot path */
562 #if defined(CONFIG_BOOTP_NISDOMAIN)
563 *e++ = 40; /* NIS Domain name request */
567 #if defined(CONFIG_BOOTP_NTPSERVER)
573 *e++ = 255; /* End of the list */
584 int ext_len, pktlen, iplen;
585 #ifdef CONFIG_BOOTP_RANDOM_DELAY
589 bootstage_mark_name(BOOTSTAGE_ID_BOOTP_START, "bootp_start");
590 #if defined(CONFIG_CMD_DHCP)
594 #ifdef CONFIG_BOOTP_RANDOM_DELAY /* Random BOOTP delay */
598 if (BootpTry <= 2) /* Start with max 1024 * 1ms */
599 rand_ms = rand() >> (22 - BootpTry);
600 else /* After 3rd BOOTP request max 8192 * 1ms */
601 rand_ms = rand() >> 19;
603 printf("Random delay: %ld ms...\n", rand_ms);
604 for (i = 0; i < rand_ms; i++)
605 udelay(1000); /*Wait 1ms*/
607 #endif /* CONFIG_BOOTP_RANDOM_DELAY */
609 printf("BOOTP broadcast %d\n", ++BootpTry);
611 memset((void *)pkt, 0, PKTSIZE);
613 pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
616 * Next line results in incorrect packet size being transmitted,
617 * resulting in errors in some DHCP servers, reporting missing bytes.
618 * Size must be set in packet header after extension length has been
620 * C. Hallinan, DS4.COM, Inc.
622 /* NetSetIP(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC,
623 sizeof (struct Bootp_t)); */
624 iphdr = pkt; /* We need this later for NetSetIP() */
625 pkt += IP_UDP_HDR_SIZE;
627 bp = (struct Bootp_t *)pkt;
628 bp->bp_op = OP_BOOTREQUEST;
629 bp->bp_htype = HWT_ETHER;
630 bp->bp_hlen = HWL_ETHER;
632 bp->bp_secs = htons(get_timer(0) / 1000);
633 NetWriteIP(&bp->bp_ciaddr, 0);
634 NetWriteIP(&bp->bp_yiaddr, 0);
635 NetWriteIP(&bp->bp_siaddr, 0);
636 NetWriteIP(&bp->bp_giaddr, 0);
637 memcpy(bp->bp_chaddr, NetOurEther, 6);
638 copy_filename(bp->bp_file, BootFile, sizeof(bp->bp_file));
640 /* Request additional information from the BOOTP/DHCP server */
641 #if defined(CONFIG_CMD_DHCP)
642 ext_len = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0);
644 ext_len = BootpExtended((u8 *)bp->bp_vend);
648 * Bootp ID is the lower 4 bytes of our ethernet address
649 * plus the current time in ms.
651 BootpID = ((ulong)NetOurEther[2] << 24)
652 | ((ulong)NetOurEther[3] << 16)
653 | ((ulong)NetOurEther[4] << 8)
654 | (ulong)NetOurEther[5];
655 BootpID += get_timer(0);
656 BootpID = htonl(BootpID);
657 NetCopyLong(&bp->bp_id, &BootpID);
660 * Calculate proper packet lengths taking into account the
661 * variable size of the options field
663 pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE -
664 sizeof(bp->bp_vend) + ext_len;
665 iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + ext_len;
666 NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
667 NetSetTimeout(SELECT_TIMEOUT, BootpTimeout);
669 #if defined(CONFIG_CMD_DHCP)
670 dhcp_state = SELECTING;
671 NetSetHandler(DhcpHandler);
673 NetSetHandler(BootpHandler);
675 NetSendPacket(NetTxPacket, pktlen);
678 #if defined(CONFIG_CMD_DHCP)
679 static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp)
681 uchar *end = popt + BOOTP_HDR_SIZE;
683 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
687 while (popt < end && *popt != 0xff) {
691 NetCopyIP(&NetOurSubnetMask, (popt + 2));
693 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET)
694 case 2: /* Time offset */
695 to_ptr = &NetTimeOffset;
696 NetCopyLong((ulong *)to_ptr, (ulong *)(popt + 2));
697 NetTimeOffset = ntohl(NetTimeOffset);
701 NetCopyIP(&NetOurGatewayIP, (popt + 2));
704 NetCopyIP(&NetOurDNSIP, (popt + 2));
705 #if defined(CONFIG_BOOTP_DNS2)
707 NetCopyIP(&NetOurDNS2IP, (popt + 2 + 4));
711 size = truncate_sz("Host Name",
712 sizeof(NetOurHostName), oplen);
713 memcpy(&NetOurHostName, popt + 2, size);
714 NetOurHostName[size] = 0;
716 case 15: /* Ignore Domain Name Option */
719 size = truncate_sz("Root Path",
720 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:"
778 popt += oplen + 2; /* Process next option */
782 static int DhcpMessageType(unsigned char *popt)
784 if (NetReadLong((ulong *)popt) != htonl(BOOTP_VENDOR_MAGIC))
788 while (*popt != 0xff) {
789 if (*popt == 53) /* DHCP Message Type */
791 popt += *(popt + 1) + 2; /* Scan through all options */
796 static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
800 int pktlen, iplen, extlen;
803 debug("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
805 memset((void *)pkt, 0, PKTSIZE);
807 pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
809 iphdr = pkt; /* We'll need this later to set proper pkt size */
810 pkt += IP_UDP_HDR_SIZE;
812 bp = (struct Bootp_t *)pkt;
813 bp->bp_op = OP_BOOTREQUEST;
814 bp->bp_htype = HWT_ETHER;
815 bp->bp_hlen = HWL_ETHER;
817 bp->bp_secs = htons(get_timer(0) / 1000);
818 /* Do not set the client IP, your IP, or server IP yet, since it
819 * hasn't been ACK'ed by the server yet */
822 * RFC3046 requires Relay Agents to discard packets with
823 * nonzero and offered giaddr
825 NetWriteIP(&bp->bp_giaddr, 0);
827 memcpy(bp->bp_chaddr, NetOurEther, 6);
830 * ID is the id of the OFFER packet
833 NetCopyLong(&bp->bp_id, &bp_offer->bp_id);
836 * Copy options from OFFER packet if present
839 /* Copy offered IP into the parameters request list */
840 NetCopyIP(&OfferedIP, &bp_offer->bp_yiaddr);
841 extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST,
842 NetDHCPServerIP, OfferedIP);
844 pktlen = ((int)(pkt-NetTxPacket)) + BOOTP_HDR_SIZE -
845 sizeof(bp->bp_vend) + extlen;
846 iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
847 NetSetIP(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
849 debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);
850 #ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY
851 udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY);
852 #endif /* CONFIG_BOOTP_DHCP_REQUEST_DELAY */
853 NetSendPacket(NetTxPacket, pktlen);
857 * Handle DHCP received packets.
860 DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
863 struct Bootp_t *bp = (struct Bootp_t *)pkt;
865 debug("DHCPHandler: got packet: (src=%d, dst=%d, len=%d) state: %d\n",
866 src, dest, len, dhcp_state);
868 /* Filter out pkts we don't want */
869 if (BootpCheckPkt(pkt, dest, src, len))
872 debug("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state:"
873 " %d\n", src, dest, len, dhcp_state);
875 switch (dhcp_state) {
878 * Wait an appropriate time for any potential DHCPOFFER packets
879 * to arrive. Then select one, and generate DHCPREQUEST
880 * response. If filename is in format we recognize, assume it
881 * is a valid OFFER from a server we want.
883 debug("DHCP: state=SELECTING bp_file: \"%s\"\n", bp->bp_file);
884 #ifdef CONFIG_SYS_BOOTFILE_PREFIX
885 if (strncmp(bp->bp_file,
886 CONFIG_SYS_BOOTFILE_PREFIX,
887 strlen(CONFIG_SYS_BOOTFILE_PREFIX)) == 0) {
888 #endif /* CONFIG_SYS_BOOTFILE_PREFIX */
890 debug("TRANSITIONING TO REQUESTING STATE\n");
891 dhcp_state = REQUESTING;
893 if (NetReadLong((ulong *)&bp->bp_vend[0]) ==
894 htonl(BOOTP_VENDOR_MAGIC))
895 DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
897 NetSetTimeout(TIMEOUT, BootpTimeout);
898 DhcpSendRequestPkt(bp);
899 #ifdef CONFIG_SYS_BOOTFILE_PREFIX
901 #endif /* CONFIG_SYS_BOOTFILE_PREFIX */
906 debug("DHCP State: REQUESTING\n");
908 if (DhcpMessageType((u8 *)bp->bp_vend) == DHCP_ACK) {
909 if (NetReadLong((ulong *)&bp->bp_vend[0]) ==
910 htonl(BOOTP_VENDOR_MAGIC))
911 DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
912 /* Store net params from reply */
913 BootpCopyNetParams(bp);
915 printf("DHCP client bound to address %pI4\n",
917 bootstage_mark_name(BOOTSTAGE_ID_BOOTP_STOP,
925 /* DHCP client bound to address */
928 puts("DHCP: INVALID STATE\n");
934 void DhcpRequest(void)
938 #endif /* CONFIG_CMD_DHCP */