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>
22 #define BOOTP_VENDOR_MAGIC 0x63825363 /* RFC1048 Magic Cookie */
24 #define TIMEOUT 5000UL /* Milliseconds before trying BOOTP again */
25 #ifndef CONFIG_NET_RETRY_COUNT
26 # define TIMEOUT_COUNT 5 /* # of timeouts before giving up */
28 # define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT)
31 #define PORT_BOOTPS 67 /* BOOTP server UDP port */
32 #define PORT_BOOTPC 68 /* BOOTP client UDP port */
34 #ifndef CONFIG_DHCP_MIN_EXT_LEN /* minimal length of extension list */
35 #define CONFIG_DHCP_MIN_EXT_LEN 64
41 #if defined(CONFIG_CMD_DHCP)
42 dhcp_state_t dhcp_state = INIT;
43 unsigned long dhcp_leasetime;
44 IPaddr_t NetDHCPServerIP;
45 static void DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
50 static char *dhcpmsg2str(int type)
53 case 1: return "DHCPDISCOVER"; break;
54 case 2: return "DHCPOFFER"; break;
55 case 3: return "DHCPREQUEST"; break;
56 case 4: return "DHCPDECLINE"; break;
57 case 5: return "DHCPACK"; break;
58 case 6: return "DHCPNACK"; break;
59 case 7: return "DHCPRELEASE"; break;
60 default: return "UNKNOWN/INVALID MSG TYPE"; break;
66 static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
68 struct Bootp_t *bp = (struct Bootp_t *) pkt;
71 if (dest != PORT_BOOTPC || src != PORT_BOOTPS)
73 else if (len < sizeof(struct Bootp_t) - OPT_FIELD_SIZE)
75 else if (bp->bp_op != OP_BOOTREQUEST &&
76 bp->bp_op != OP_BOOTREPLY &&
77 bp->bp_op != DHCP_OFFER &&
78 bp->bp_op != DHCP_ACK &&
79 bp->bp_op != DHCP_NAK)
81 else if (bp->bp_htype != HWT_ETHER)
83 else if (bp->bp_hlen != HWL_ETHER)
85 else if (NetReadLong((ulong *)&bp->bp_id) != BootpID)
88 debug("Filtering pkt = %d\n", retval);
94 * Copy parameters of interest from BOOTP_REPLY/DHCP_OFFER packet
96 static void BootpCopyNetParams(struct Bootp_t *bp)
98 #if !defined(CONFIG_BOOTP_SERVERIP)
101 NetCopyIP(&tmp_ip, &bp->bp_siaddr);
103 NetCopyIP(&NetServerIP, &bp->bp_siaddr);
104 memcpy(NetServerEther, ((struct ethernet_hdr *)NetRxPacket)->et_src, 6);
106 NetCopyIP(&NetOurIP, &bp->bp_yiaddr);
107 if (strlen(bp->bp_file) > 0)
108 copy_filename(BootFile, bp->bp_file, sizeof(BootFile));
110 debug("Bootfile: %s\n", BootFile);
112 /* Propagate to environment:
113 * don't delete exising entry when BOOTP / DHCP reply does
114 * not contain a new value
117 setenv("bootfile", BootFile);
120 static int truncate_sz(const char *name, int maxlen, int curlen)
122 if (curlen >= maxlen) {
123 printf("*** WARNING: %s is too long (%d - max: %d)"
124 " - truncated\n", name, curlen, maxlen);
130 #if !defined(CONFIG_CMD_DHCP)
132 static void BootpVendorFieldProcess(u8 *ext)
134 int size = *(ext + 1);
136 debug("[BOOTP] Processing extension %d... (%d bytes)\n", *ext,
142 /* Fixed length fields */
143 case 1: /* Subnet mask */
144 if (NetOurSubnetMask == 0)
145 NetCopyIP(&NetOurSubnetMask, (IPaddr_t *) (ext + 2));
147 case 2: /* Time offset - Not yet supported */
149 /* Variable length fields */
150 case 3: /* Gateways list */
151 if (NetOurGatewayIP == 0)
152 NetCopyIP(&NetOurGatewayIP, (IPaddr_t *) (ext + 2));
154 case 4: /* Time server - Not yet supported */
156 case 5: /* IEN-116 name server - Not yet supported */
159 if (NetOurDNSIP == 0)
160 NetCopyIP(&NetOurDNSIP, (IPaddr_t *) (ext + 2));
161 #if defined(CONFIG_BOOTP_DNS2)
162 if ((NetOurDNS2IP == 0) && (size > 4))
163 NetCopyIP(&NetOurDNS2IP, (IPaddr_t *) (ext + 2 + 4));
166 case 7: /* Log server - Not yet supported */
168 case 8: /* Cookie/Quote server - Not yet supported */
170 case 9: /* LPR server - Not yet supported */
172 case 10: /* Impress server - Not yet supported */
174 case 11: /* RPL server - Not yet supported */
176 case 12: /* Host name */
177 if (NetOurHostName[0] == 0) {
178 size = truncate_sz("Host Name",
179 sizeof(NetOurHostName), size);
180 memcpy(&NetOurHostName, ext + 2, size);
181 NetOurHostName[size] = 0;
184 case 13: /* Boot file size */
186 NetBootFileSize = ntohs(*(ushort *) (ext + 2));
188 NetBootFileSize = ntohl(*(ulong *) (ext + 2));
190 case 14: /* Merit dump file - Not yet supported */
192 case 15: /* Domain name - Not yet supported */
194 case 16: /* Swap server - Not yet supported */
196 case 17: /* Root path */
197 if (NetOurRootPath[0] == 0) {
198 size = truncate_sz("Root Path",
199 sizeof(NetOurRootPath), size);
200 memcpy(&NetOurRootPath, ext + 2, size);
201 NetOurRootPath[size] = 0;
204 case 18: /* Extension path - Not yet supported */
206 * This can be used to send the information of the
207 * vendor area in another file that the client can
211 /* IP host layer fields */
212 case 40: /* NIS Domain name */
213 if (NetOurNISDomain[0] == 0) {
214 size = truncate_sz("NIS Domain Name",
215 sizeof(NetOurNISDomain), size);
216 memcpy(&NetOurNISDomain, ext + 2, size);
217 NetOurNISDomain[size] = 0;
220 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
221 case 42: /* NTP server IP */
222 NetCopyIP(&NetNtpServerIP, (IPaddr_t *) (ext + 2));
225 /* Application layer fields */
226 case 43: /* Vendor specific info - Not yet supported */
228 * Binary information to exchange specific
229 * product information.
232 /* Reserved (custom) fields (128..254) */
236 static void BootpVendorProcess(u8 *ext, int size)
238 u8 *end = ext + size;
240 debug("[BOOTP] Checking extension (%d bytes)...\n", size);
242 while ((ext < end) && (*ext != 0xff)) {
250 BootpVendorFieldProcess(opt);
254 debug("[BOOTP] Received fields:\n");
255 if (NetOurSubnetMask)
256 debug("NetOurSubnetMask : %pI4\n", &NetOurSubnetMask);
259 debug("NetOurGatewayIP : %pI4", &NetOurGatewayIP);
262 debug("NetBootFileSize : %d\n", NetBootFileSize);
264 if (NetOurHostName[0])
265 debug("NetOurHostName : %s\n", NetOurHostName);
267 if (NetOurRootPath[0])
268 debug("NetOurRootPath : %s\n", NetOurRootPath);
270 if (NetOurNISDomain[0])
271 debug("NetOurNISDomain : %s\n", NetOurNISDomain);
274 debug("NetBootFileSize: %d\n", NetBootFileSize);
276 #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
278 debug("NetNtpServerIP : %pI4\n", &NetNtpServerIP);
283 * Handle a BOOTP received packet.
286 BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
291 debug("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%zu)\n",
292 src, dest, len, sizeof(struct Bootp_t));
294 bp = (struct Bootp_t *)pkt;
296 /* Filter out pkts we don't want */
297 if (BootpCheckPkt(pkt, dest, src, len))
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);
314 bootstage_mark_name(BOOTSTAGE_ID_BOOTP_STOP, "bootp_stop");
316 debug("Got good BOOTP\n");
323 * Timeout on BOOTP/DHCP request.
328 if (BootpTry >= TIMEOUT_COUNT) {
329 puts("\nRetry count exceeded; starting again\n");
332 NetSetTimeout(TIMEOUT, BootpTimeout);
338 * Initialize BOOTP extension fields in the request.
340 #if defined(CONFIG_CMD_DHCP)
341 static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID,
342 IPaddr_t RequestedIP)
346 #if defined(CONFIG_BOOTP_PXE)
352 #if defined(CONFIG_BOOTP_VENDOREX)
355 #if defined(CONFIG_BOOTP_SEND_HOSTNAME)
359 *e++ = 99; /* RFC1048 Magic Cookie */
364 *e++ = 53; /* DHCP Message Type */
368 *e++ = 57; /* Maximum DHCP Message Size */
370 *e++ = (576 - 312 + OPT_FIELD_SIZE) >> 8;
371 *e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff;
374 int tmp = ntohl(ServerID);
376 *e++ = 54; /* ServerID */
385 int tmp = ntohl(RequestedIP);
387 *e++ = 50; /* Requested IP */
394 #if defined(CONFIG_BOOTP_SEND_HOSTNAME)
395 hostname = getenv("hostname");
397 int hostnamelen = strlen(hostname);
399 *e++ = 12; /* Hostname */
401 memcpy(e, hostname, hostnamelen);
406 #if defined(CONFIG_BOOTP_PXE)
407 clientarch = CONFIG_BOOTP_PXE_CLIENTARCH;
408 *e++ = 93; /* Client System Architecture */
410 *e++ = (clientarch >> 8) & 0xff;
411 *e++ = clientarch & 0xff;
413 *e++ = 94; /* Client Network Interface Identifier */
415 *e++ = 1; /* type field for UNDI */
416 *e++ = 0; /* major revision */
417 *e++ = 0; /* minor revision */
419 uuid = getenv("pxeuuid");
422 if (uuid_str_valid(uuid)) {
423 *e++ = 97; /* Client Machine Identifier */
425 *e++ = 0; /* type 0 - UUID */
427 uuid_str_to_bin(uuid, e);
430 printf("Invalid pxeuuid: %s\n", uuid);
434 *e++ = 60; /* Vendor Class Identifier */
435 vci_strlen = strlen(CONFIG_BOOTP_VCI_STRING);
437 memcpy(e, CONFIG_BOOTP_VCI_STRING, vci_strlen);
441 #if defined(CONFIG_BOOTP_VENDOREX)
442 x = dhcp_vendorex_prep(e);
447 *e++ = 55; /* Parameter Request List */
448 cnt = e++; /* Pointer to count of requested items */
450 #if defined(CONFIG_BOOTP_SUBNETMASK)
451 *e++ = 1; /* Subnet Mask */
454 #if defined(CONFIG_BOOTP_TIMEOFFSET)
458 #if defined(CONFIG_BOOTP_GATEWAY)
459 *e++ = 3; /* Router Option */
462 #if defined(CONFIG_BOOTP_DNS)
463 *e++ = 6; /* DNS Server(s) */
466 #if defined(CONFIG_BOOTP_HOSTNAME)
467 *e++ = 12; /* Hostname */
470 #if defined(CONFIG_BOOTP_BOOTFILESIZE)
471 *e++ = 13; /* Boot File Size */
474 #if defined(CONFIG_BOOTP_BOOTPATH)
475 *e++ = 17; /* Boot path */
478 #if defined(CONFIG_BOOTP_NISDOMAIN)
479 *e++ = 40; /* NIS Domain name request */
482 #if defined(CONFIG_BOOTP_NTPSERVER)
486 /* no options, so back up to avoid sending an empty request list */
490 *e++ = 255; /* End of the list */
492 /* Pad to minimal length */
493 #ifdef CONFIG_DHCP_MIN_EXT_LEN
494 while ((e - start) < CONFIG_DHCP_MIN_EXT_LEN)
503 * Warning: no field size check - change CONFIG_BOOTP_* at your own risk!
505 static int BootpExtended(u8 *e)
509 *e++ = 99; /* RFC1048 Magic Cookie */
514 #if defined(CONFIG_CMD_DHCP)
515 *e++ = 53; /* DHCP Message Type */
517 *e++ = DHCP_DISCOVER;
519 *e++ = 57; /* Maximum DHCP Message Size */
521 *e++ = (576 - 312 + OPT_FIELD_SIZE) >> 16;
522 *e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff;
525 #if defined(CONFIG_BOOTP_SUBNETMASK)
526 *e++ = 1; /* Subnet mask request */
531 #if defined(CONFIG_BOOTP_GATEWAY)
532 *e++ = 3; /* Default gateway request */
537 #if defined(CONFIG_BOOTP_DNS)
538 *e++ = 6; /* Domain Name Server */
543 #if defined(CONFIG_BOOTP_HOSTNAME)
544 *e++ = 12; /* Host name request */
549 #if defined(CONFIG_BOOTP_BOOTFILESIZE)
550 *e++ = 13; /* Boot file size */
555 #if defined(CONFIG_BOOTP_BOOTPATH)
556 *e++ = 17; /* Boot path */
561 #if defined(CONFIG_BOOTP_NISDOMAIN)
562 *e++ = 40; /* NIS Domain name request */
566 #if defined(CONFIG_BOOTP_NTPSERVER)
572 *e++ = 255; /* End of the list */
583 int extlen, 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 eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_IP);
617 * Next line results in incorrect packet size being transmitted,
618 * resulting in errors in some DHCP servers, reporting missing bytes.
619 * Size must be set in packet header after extension length has been
621 * C. Hallinan, DS4.COM, Inc.
623 /* net_set_udp_header(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC,
624 sizeof (struct Bootp_t)); */
625 iphdr = pkt; /* We need this later for net_set_udp_header() */
626 pkt += IP_UDP_HDR_SIZE;
628 bp = (struct Bootp_t *)pkt;
629 bp->bp_op = OP_BOOTREQUEST;
630 bp->bp_htype = HWT_ETHER;
631 bp->bp_hlen = HWL_ETHER;
633 bp->bp_secs = htons(get_timer(0) / 1000);
634 NetWriteIP(&bp->bp_ciaddr, 0);
635 NetWriteIP(&bp->bp_yiaddr, 0);
636 NetWriteIP(&bp->bp_siaddr, 0);
637 NetWriteIP(&bp->bp_giaddr, 0);
638 memcpy(bp->bp_chaddr, NetOurEther, 6);
639 copy_filename(bp->bp_file, BootFile, sizeof(bp->bp_file));
641 /* Request additional information from the BOOTP/DHCP server */
642 #if defined(CONFIG_CMD_DHCP)
643 extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0);
645 extlen = BootpExtended((u8 *)bp->bp_vend);
649 * Bootp ID is the lower 4 bytes of our ethernet address
650 * plus the current time in ms.
652 BootpID = ((ulong)NetOurEther[2] << 24)
653 | ((ulong)NetOurEther[3] << 16)
654 | ((ulong)NetOurEther[4] << 8)
655 | (ulong)NetOurEther[5];
656 BootpID += get_timer(0);
657 BootpID = htonl(BootpID);
658 NetCopyLong(&bp->bp_id, &BootpID);
661 * Calculate proper packet lengths taking into account the
662 * variable size of the options field
664 iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen;
665 pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen;
666 net_set_udp_header(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
667 NetSetTimeout(SELECT_TIMEOUT, BootpTimeout);
669 #if defined(CONFIG_CMD_DHCP)
670 dhcp_state = SELECTING;
671 net_set_udp_handler(DhcpHandler);
673 net_set_udp_handler(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;
804 debug("DhcpSendRequestPkt: Sending DHCPREQUEST\n");
806 memset((void *)pkt, 0, PKTSIZE);
808 eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_IP);
811 iphdr = pkt; /* We'll need this later to set proper pkt size */
812 pkt += IP_UDP_HDR_SIZE;
814 bp = (struct Bootp_t *)pkt;
815 bp->bp_op = OP_BOOTREQUEST;
816 bp->bp_htype = HWT_ETHER;
817 bp->bp_hlen = HWL_ETHER;
819 bp->bp_secs = htons(get_timer(0) / 1000);
820 /* Do not set the client IP, your IP, or server IP yet, since it
821 * hasn't been ACK'ed by the server yet */
824 * RFC3046 requires Relay Agents to discard packets with
825 * nonzero and offered giaddr
827 NetWriteIP(&bp->bp_giaddr, 0);
829 memcpy(bp->bp_chaddr, NetOurEther, 6);
832 * ID is the id of the OFFER packet
835 NetCopyLong(&bp->bp_id, &bp_offer->bp_id);
838 * Copy options from OFFER packet if present
841 /* Copy offered IP into the parameters request list */
842 NetCopyIP(&OfferedIP, &bp_offer->bp_yiaddr);
843 extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST,
844 NetDHCPServerIP, OfferedIP);
846 iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen;
847 pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen;
848 net_set_udp_header(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen);
850 #ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY
851 udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY);
852 #endif /* CONFIG_BOOTP_DHCP_REQUEST_DELAY */
853 debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);
854 NetSendPacket(NetTxPacket, pktlen);
858 * Handle DHCP received packets.
861 DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
864 struct Bootp_t *bp = (struct Bootp_t *)pkt;
866 debug("DHCPHandler: got packet: (src=%d, dst=%d, len=%d) state: %d\n",
867 src, dest, len, dhcp_state);
869 /* Filter out pkts we don't want */
870 if (BootpCheckPkt(pkt, dest, src, len))
873 debug("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state:"
874 " %d\n", src, dest, len, dhcp_state);
876 switch (dhcp_state) {
879 * Wait an appropriate time for any potential DHCPOFFER packets
880 * to arrive. Then select one, and generate DHCPREQUEST
881 * response. If filename is in format we recognize, assume it
882 * is a valid OFFER from a server we want.
884 debug("DHCP: state=SELECTING bp_file: \"%s\"\n", bp->bp_file);
885 #ifdef CONFIG_SYS_BOOTFILE_PREFIX
886 if (strncmp(bp->bp_file,
887 CONFIG_SYS_BOOTFILE_PREFIX,
888 strlen(CONFIG_SYS_BOOTFILE_PREFIX)) == 0) {
889 #endif /* CONFIG_SYS_BOOTFILE_PREFIX */
891 debug("TRANSITIONING TO REQUESTING STATE\n");
892 dhcp_state = REQUESTING;
894 if (NetReadLong((ulong *)&bp->bp_vend[0]) ==
895 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) {
910 if (NetReadLong((ulong *)&bp->bp_vend[0]) ==
911 htonl(BOOTP_VENDOR_MAGIC))
912 DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
913 /* Store net params from reply */
914 BootpCopyNetParams(bp);
916 printf("DHCP client bound to address %pI4\n",
918 bootstage_mark_name(BOOTSTAGE_ID_BOOTP_STOP,
926 /* DHCP client bound to address */
929 puts("DHCP: INVALID STATE\n");
935 void DhcpRequest(void)
939 #endif /* CONFIG_CMD_DHCP */