wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Based on LiMon - BOOTP. |
| 3 | * |
| 4 | * Copyright 1994, 1995, 2000 Neil Russell. |
| 5 | * (See License) |
| 6 | * Copyright 2000 Roland Borde |
| 7 | * Copyright 2000 Paolo Scaffardi |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 8 | * Copyright 2000-2004 Wolfgang Denk, wd@denx.de |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 11 | #include <common.h> |
| 12 | #include <command.h> |
| 13 | #include <net.h> |
| 14 | #include "bootp.h" |
| 15 | #include "tftp.h" |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 16 | #include "nfs.h" |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 17 | #ifdef CONFIG_STATUS_LED |
| 18 | #include <status_led.h> |
| 19 | #endif |
Kim Phillips | 576175b | 2012-07-05 13:19:32 +0000 | [diff] [blame] | 20 | #ifdef CONFIG_BOOTP_RANDOM_DELAY |
| 21 | #include "net_rand.h" |
| 22 | #endif |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 23 | |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 24 | #define BOOTP_VENDOR_MAGIC 0x63825363 /* RFC1048 Magic Cookie */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 25 | |
Bartlomiej Sieka | 5666846 | 2008-10-01 15:26:28 +0200 | [diff] [blame] | 26 | #define TIMEOUT 5000UL /* Milliseconds before trying BOOTP again */ |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 27 | #ifndef CONFIG_NET_RETRY_COUNT |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 28 | # define TIMEOUT_COUNT 5 /* # of timeouts before giving up */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 29 | #else |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 30 | # define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 31 | #endif |
| 32 | |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 33 | #define PORT_BOOTPS 67 /* BOOTP server UDP port */ |
| 34 | #define PORT_BOOTPC 68 /* BOOTP client UDP port */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 35 | |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 36 | #ifndef CONFIG_DHCP_MIN_EXT_LEN /* minimal length of extension list */ |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 37 | #define CONFIG_DHCP_MIN_EXT_LEN 64 |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 38 | #endif |
| 39 | |
| 40 | ulong BootpID; |
| 41 | int BootpTry; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 42 | |
Jon Loeliger | 54f35c2 | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 43 | #if defined(CONFIG_CMD_DHCP) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 44 | dhcp_state_t dhcp_state = INIT; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 45 | unsigned long dhcp_leasetime; |
| 46 | IPaddr_t NetDHCPServerIP; |
Luca Ceresoli | 428ab36 | 2011-04-18 06:19:50 +0000 | [diff] [blame] | 47 | static void DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, |
| 48 | unsigned len); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 49 | |
| 50 | /* For Debug */ |
wdenk | b02744a | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 51 | #if 0 |
| 52 | static char *dhcpmsg2str(int type) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 53 | { |
| 54 | switch (type) { |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 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; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 62 | default: return "UNKNOWN/INVALID MSG TYPE"; break; |
| 63 | } |
| 64 | } |
wdenk | b02744a | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 65 | #endif |
Jon Loeliger | a9807e5 | 2007-07-10 11:05:02 -0500 | [diff] [blame] | 66 | #endif |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 67 | |
| 68 | static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len) |
| 69 | { |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 70 | struct Bootp_t *bp = (struct Bootp_t *) pkt; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 71 | int retval = 0; |
| 72 | |
| 73 | if (dest != PORT_BOOTPC || src != PORT_BOOTPS) |
| 74 | retval = -1; |
Joe Hershberger | ceba447 | 2012-05-23 07:58:14 +0000 | [diff] [blame] | 75 | else if (len < sizeof(struct Bootp_t) - OPT_FIELD_SIZE) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 76 | retval = -2; |
| 77 | else if (bp->bp_op != OP_BOOTREQUEST && |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 78 | bp->bp_op != OP_BOOTREPLY && |
| 79 | bp->bp_op != DHCP_OFFER && |
| 80 | bp->bp_op != DHCP_ACK && |
| 81 | bp->bp_op != DHCP_NAK) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 82 | retval = -3; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 83 | else if (bp->bp_htype != HWT_ETHER) |
| 84 | retval = -4; |
| 85 | else if (bp->bp_hlen != HWL_ETHER) |
| 86 | retval = -5; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 87 | else if (NetReadLong((ulong *)&bp->bp_id) != BootpID) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 88 | retval = -6; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 89 | |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 90 | debug("Filtering pkt = %d\n", retval); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 91 | |
| 92 | return retval; |
| 93 | } |
| 94 | |
| 95 | /* |
| 96 | * Copy parameters of interest from BOOTP_REPLY/DHCP_OFFER packet |
| 97 | */ |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 98 | static void BootpCopyNetParams(struct Bootp_t *bp) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 99 | { |
Wilson Callan | 22bcd6e | 2007-07-28 10:56:13 -0400 | [diff] [blame] | 100 | #if !defined(CONFIG_BOOTP_SERVERIP) |
Joe Hershberger | 9d37a58 | 2012-05-23 07:59:18 +0000 | [diff] [blame] | 101 | IPaddr_t tmp_ip; |
| 102 | |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 103 | NetCopyIP(&tmp_ip, &bp->bp_siaddr); |
| 104 | if (tmp_ip != 0) |
| 105 | NetCopyIP(&NetServerIP, &bp->bp_siaddr); |
Joe Hershberger | 1178f41 | 2012-05-23 07:58:06 +0000 | [diff] [blame] | 106 | memcpy(NetServerEther, ((struct ethernet_hdr *)NetRxPacket)->et_src, 6); |
Wilson Callan | 22bcd6e | 2007-07-28 10:56:13 -0400 | [diff] [blame] | 107 | #endif |
Joe Hershberger | 9d37a58 | 2012-05-23 07:59:18 +0000 | [diff] [blame] | 108 | NetCopyIP(&NetOurIP, &bp->bp_yiaddr); |
wdenk | 4989f87 | 2004-03-14 15:06:13 +0000 | [diff] [blame] | 109 | if (strlen(bp->bp_file) > 0) |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 110 | copy_filename(BootFile, bp->bp_file, sizeof(BootFile)); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 111 | |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 112 | debug("Bootfile: %s\n", BootFile); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 113 | |
| 114 | /* Propagate to environment: |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 115 | * don't delete exising entry when BOOTP / DHCP reply does |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 116 | * not contain a new value |
| 117 | */ |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 118 | if (*BootFile) |
| 119 | setenv("bootfile", BootFile); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 122 | static int truncate_sz(const char *name, int maxlen, int curlen) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 123 | { |
| 124 | if (curlen >= maxlen) { |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 125 | printf("*** WARNING: %s is too long (%d - max: %d)" |
| 126 | " - truncated\n", name, curlen, maxlen); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 127 | curlen = maxlen - 1; |
| 128 | } |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 129 | return curlen; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Jon Loeliger | 54f35c2 | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 132 | #if !defined(CONFIG_CMD_DHCP) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 133 | |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 134 | static void BootpVendorFieldProcess(u8 *ext) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 135 | { |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 136 | int size = *(ext + 1); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 137 | |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 138 | debug("[BOOTP] Processing extension %d... (%d bytes)\n", *ext, |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 139 | *(ext + 1)); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 140 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 141 | NetBootFileSize = 0; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 142 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 143 | switch (*ext) { |
| 144 | /* Fixed length fields */ |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 145 | case 1: /* Subnet mask */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 146 | if (NetOurSubnetMask == 0) |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 147 | NetCopyIP(&NetOurSubnetMask, (IPaddr_t *) (ext + 2)); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 148 | break; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 149 | case 2: /* Time offset - Not yet supported */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 150 | break; |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 151 | /* Variable length fields */ |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 152 | case 3: /* Gateways list */ |
| 153 | if (NetOurGatewayIP == 0) |
| 154 | NetCopyIP(&NetOurGatewayIP, (IPaddr_t *) (ext + 2)); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 155 | break; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 156 | case 4: /* Time server - Not yet supported */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 157 | break; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 158 | case 5: /* IEN-116 name server - Not yet supported */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 159 | break; |
| 160 | case 6: |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 161 | if (NetOurDNSIP == 0) |
| 162 | NetCopyIP(&NetOurDNSIP, (IPaddr_t *) (ext + 2)); |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 163 | #if defined(CONFIG_BOOTP_DNS2) |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 164 | if ((NetOurDNS2IP == 0) && (size > 4)) |
| 165 | NetCopyIP(&NetOurDNS2IP, (IPaddr_t *) (ext + 2 + 4)); |
stroese | e0aadfb | 2003-08-28 14:17:32 +0000 | [diff] [blame] | 166 | #endif |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 167 | break; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 168 | case 7: /* Log server - Not yet supported */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 169 | break; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 170 | case 8: /* Cookie/Quote server - Not yet supported */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 171 | break; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 172 | case 9: /* LPR server - Not yet supported */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 173 | break; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 174 | case 10: /* Impress server - Not yet supported */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 175 | break; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 176 | case 11: /* RPL server - Not yet supported */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 177 | break; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 178 | case 12: /* Host name */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 179 | if (NetOurHostName[0] == 0) { |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 180 | size = truncate_sz("Host Name", |
| 181 | sizeof(NetOurHostName), size); |
| 182 | memcpy(&NetOurHostName, ext + 2, size); |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 183 | NetOurHostName[size] = 0; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 184 | } |
| 185 | break; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 186 | case 13: /* Boot file size */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 187 | if (size == 2) |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 188 | NetBootFileSize = ntohs(*(ushort *) (ext + 2)); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 189 | else if (size == 4) |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 190 | NetBootFileSize = ntohl(*(ulong *) (ext + 2)); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 191 | break; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 192 | case 14: /* Merit dump file - Not yet supported */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 193 | break; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 194 | case 15: /* Domain name - Not yet supported */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 195 | break; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 196 | case 16: /* Swap server - Not yet supported */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 197 | break; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 198 | case 17: /* Root path */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 199 | if (NetOurRootPath[0] == 0) { |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 200 | size = truncate_sz("Root Path", |
| 201 | sizeof(NetOurRootPath), size); |
| 202 | memcpy(&NetOurRootPath, ext + 2, size); |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 203 | NetOurRootPath[size] = 0; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 204 | } |
| 205 | break; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 206 | case 18: /* Extension path - Not yet supported */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 207 | /* |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 208 | * This can be used to send the information of the |
| 209 | * vendor area in another file that the client can |
| 210 | * access via TFTP. |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 211 | */ |
| 212 | break; |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 213 | /* IP host layer fields */ |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 214 | case 40: /* NIS Domain name */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 215 | if (NetOurNISDomain[0] == 0) { |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 216 | size = truncate_sz("NIS Domain Name", |
| 217 | sizeof(NetOurNISDomain), size); |
| 218 | memcpy(&NetOurNISDomain, ext + 2, size); |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 219 | NetOurNISDomain[size] = 0; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 220 | } |
| 221 | break; |
Luuk Paulussen | 6380e01 | 2011-05-16 18:29:19 +0000 | [diff] [blame] | 222 | #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER) |
| 223 | case 42: /* NTP server IP */ |
| 224 | NetCopyIP(&NetNtpServerIP, (IPaddr_t *) (ext + 2)); |
| 225 | break; |
| 226 | #endif |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 227 | /* Application layer fields */ |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 228 | case 43: /* Vendor specific info - Not yet supported */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 229 | /* |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 230 | * Binary information to exchange specific |
| 231 | * product information. |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 232 | */ |
| 233 | break; |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 234 | /* Reserved (custom) fields (128..254) */ |
| 235 | } |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 238 | static void BootpVendorProcess(u8 *ext, int size) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 239 | { |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 240 | u8 *end = ext + size; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 241 | |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 242 | debug("[BOOTP] Checking extension (%d bytes)...\n", size); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 243 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 244 | while ((ext < end) && (*ext != 0xff)) { |
| 245 | if (*ext == 0) { |
| 246 | ext++; |
| 247 | } else { |
| 248 | u8 *opt = ext; |
| 249 | |
| 250 | ext += ext[1] + 2; |
| 251 | if (ext <= end) |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 252 | BootpVendorFieldProcess(opt); |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 253 | } |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 254 | } |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 255 | |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 256 | debug("[BOOTP] Received fields:\n"); |
Mike Frysinger | d5695f4 | 2009-02-17 00:00:53 -0500 | [diff] [blame] | 257 | if (NetOurSubnetMask) |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 258 | debug("NetOurSubnetMask : %pI4\n", &NetOurSubnetMask); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 259 | |
Mike Frysinger | d5695f4 | 2009-02-17 00:00:53 -0500 | [diff] [blame] | 260 | if (NetOurGatewayIP) |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 261 | debug("NetOurGatewayIP : %pI4", &NetOurGatewayIP); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 262 | |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 263 | if (NetBootFileSize) |
| 264 | debug("NetBootFileSize : %d\n", NetBootFileSize); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 265 | |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 266 | if (NetOurHostName[0]) |
| 267 | debug("NetOurHostName : %s\n", NetOurHostName); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 268 | |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 269 | if (NetOurRootPath[0]) |
| 270 | debug("NetOurRootPath : %s\n", NetOurRootPath); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 271 | |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 272 | if (NetOurNISDomain[0]) |
| 273 | debug("NetOurNISDomain : %s\n", NetOurNISDomain); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 274 | |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 275 | if (NetBootFileSize) |
| 276 | debug("NetBootFileSize: %d\n", NetBootFileSize); |
Luuk Paulussen | 6380e01 | 2011-05-16 18:29:19 +0000 | [diff] [blame] | 277 | |
| 278 | #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER) |
| 279 | if (NetNtpServerIP) |
| 280 | debug("NetNtpServerIP : %pI4\n", &NetNtpServerIP); |
| 281 | #endif |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 282 | } |
Simon Glass | ab068eb | 2011-06-13 16:13:12 -0700 | [diff] [blame] | 283 | |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 284 | /* |
| 285 | * Handle a BOOTP received packet. |
| 286 | */ |
| 287 | static void |
Luca Ceresoli | 428ab36 | 2011-04-18 06:19:50 +0000 | [diff] [blame] | 288 | BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, |
| 289 | unsigned len) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 290 | { |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 291 | struct Bootp_t *bp; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 292 | |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 293 | debug("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%zu)\n", |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 294 | src, dest, len, sizeof(struct Bootp_t)); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 295 | |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 296 | bp = (struct Bootp_t *)pkt; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 297 | |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 298 | /* Filter out pkts we don't want */ |
| 299 | if (BootpCheckPkt(pkt, dest, src, len)) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 300 | return; |
| 301 | |
| 302 | /* |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 303 | * Got a good BOOTP reply. Copy the data into our variables. |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 304 | */ |
| 305 | #ifdef CONFIG_STATUS_LED |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 306 | status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 307 | #endif |
| 308 | |
| 309 | BootpCopyNetParams(bp); /* Store net parameters from reply */ |
| 310 | |
| 311 | /* Retrieve extended information (we must parse the vendor area) */ |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 312 | if (NetReadLong((ulong *)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC)) |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 313 | BootpVendorProcess((uchar *)&bp->bp_vend[4], len); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 314 | |
| 315 | NetSetTimeout(0, (thand_f *)0); |
Simon Glass | 768cbf0 | 2011-12-10 11:08:06 +0000 | [diff] [blame] | 316 | bootstage_mark_name(BOOTSTAGE_ID_BOOTP_STOP, "bootp_stop"); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 317 | |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 318 | debug("Got good BOOTP\n"); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 319 | |
Simon Glass | 5234ad1 | 2011-10-27 06:24:32 +0000 | [diff] [blame] | 320 | net_auto_load(); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 321 | } |
Jon Loeliger | a9807e5 | 2007-07-10 11:05:02 -0500 | [diff] [blame] | 322 | #endif |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 323 | |
| 324 | /* |
| 325 | * Timeout on BOOTP/DHCP request. |
| 326 | */ |
| 327 | static void |
| 328 | BootpTimeout(void) |
| 329 | { |
| 330 | if (BootpTry >= TIMEOUT_COUNT) { |
Joe Hershberger | 8ca7fa0 | 2012-05-23 07:59:19 +0000 | [diff] [blame] | 331 | #ifdef CONFIG_BOOTP_MAY_FAIL |
| 332 | puts("\nRetry count exceeded\n"); |
benoit.thebaudeau@advans | 7232ee5 | 2012-07-19 01:23:21 +0000 | [diff] [blame] | 333 | net_set_state(NETLOOP_FAIL); |
Joe Hershberger | 8ca7fa0 | 2012-05-23 07:59:19 +0000 | [diff] [blame] | 334 | #else |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 335 | puts("\nRetry count exceeded; starting again\n"); |
| 336 | NetStartAgain(); |
Joe Hershberger | 8ca7fa0 | 2012-05-23 07:59:19 +0000 | [diff] [blame] | 337 | #endif |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 338 | } else { |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 339 | NetSetTimeout(TIMEOUT, BootpTimeout); |
| 340 | BootpRequest(); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
Ilya Yanok | 3087658 | 2012-09-17 10:26:25 +0000 | [diff] [blame] | 344 | #define put_vci(e, str) \ |
| 345 | do { \ |
| 346 | size_t vci_strlen = strlen(str); \ |
| 347 | *e++ = 60; /* Vendor Class Identifier */ \ |
| 348 | *e++ = vci_strlen; \ |
| 349 | memcpy(e, str, vci_strlen); \ |
| 350 | e += vci_strlen; \ |
| 351 | } while (0) |
| 352 | |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 353 | /* |
| 354 | * Initialize BOOTP extension fields in the request. |
| 355 | */ |
Jon Loeliger | 54f35c2 | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 356 | #if defined(CONFIG_CMD_DHCP) |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 357 | static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID, |
| 358 | IPaddr_t RequestedIP) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 359 | { |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 360 | u8 *start = e; |
| 361 | u8 *cnt; |
Jason Hobbs | ea320281 | 2011-08-31 05:37:31 +0000 | [diff] [blame] | 362 | #if defined(CONFIG_BOOTP_PXE) |
| 363 | char *uuid; |
Jason Hobbs | ea320281 | 2011-08-31 05:37:31 +0000 | [diff] [blame] | 364 | u16 clientarch; |
| 365 | #endif |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 366 | |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 367 | #if defined(CONFIG_BOOTP_VENDOREX) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 368 | u8 *x; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 369 | #endif |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 370 | #if defined(CONFIG_BOOTP_SEND_HOSTNAME) |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 371 | char *hostname; |
stroese | e0aadfb | 2003-08-28 14:17:32 +0000 | [diff] [blame] | 372 | #endif |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 373 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 374 | *e++ = 99; /* RFC1048 Magic Cookie */ |
| 375 | *e++ = 130; |
| 376 | *e++ = 83; |
| 377 | *e++ = 99; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 378 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 379 | *e++ = 53; /* DHCP Message Type */ |
| 380 | *e++ = 1; |
| 381 | *e++ = message_type; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 382 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 383 | *e++ = 57; /* Maximum DHCP Message Size */ |
| 384 | *e++ = 2; |
Joe Hershberger | ceba447 | 2012-05-23 07:58:14 +0000 | [diff] [blame] | 385 | *e++ = (576 - 312 + OPT_FIELD_SIZE) >> 8; |
| 386 | *e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 387 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 388 | if (ServerID) { |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 389 | int tmp = ntohl(ServerID); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 390 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 391 | *e++ = 54; /* ServerID */ |
| 392 | *e++ = 4; |
| 393 | *e++ = tmp >> 24; |
| 394 | *e++ = tmp >> 16; |
| 395 | *e++ = tmp >> 8; |
| 396 | *e++ = tmp & 0xff; |
| 397 | } |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 398 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 399 | if (RequestedIP) { |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 400 | int tmp = ntohl(RequestedIP); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 401 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 402 | *e++ = 50; /* Requested IP */ |
| 403 | *e++ = 4; |
| 404 | *e++ = tmp >> 24; |
| 405 | *e++ = tmp >> 16; |
| 406 | *e++ = tmp >> 8; |
| 407 | *e++ = tmp & 0xff; |
| 408 | } |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 409 | #if defined(CONFIG_BOOTP_SEND_HOSTNAME) |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 410 | hostname = getenv("hostname"); |
| 411 | if (hostname) { |
| 412 | int hostnamelen = strlen(hostname); |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 413 | |
| 414 | *e++ = 12; /* Hostname */ |
| 415 | *e++ = hostnamelen; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 416 | memcpy(e, hostname, hostnamelen); |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 417 | e += hostnamelen; |
| 418 | } |
Jason Hobbs | ea320281 | 2011-08-31 05:37:31 +0000 | [diff] [blame] | 419 | #endif |
| 420 | |
| 421 | #if defined(CONFIG_BOOTP_PXE) |
| 422 | clientarch = CONFIG_BOOTP_PXE_CLIENTARCH; |
| 423 | *e++ = 93; /* Client System Architecture */ |
| 424 | *e++ = 2; |
| 425 | *e++ = (clientarch >> 8) & 0xff; |
| 426 | *e++ = clientarch & 0xff; |
| 427 | |
| 428 | *e++ = 94; /* Client Network Interface Identifier */ |
| 429 | *e++ = 3; |
| 430 | *e++ = 1; /* type field for UNDI */ |
| 431 | *e++ = 0; /* major revision */ |
| 432 | *e++ = 0; /* minor revision */ |
| 433 | |
| 434 | uuid = getenv("pxeuuid"); |
| 435 | |
| 436 | if (uuid) { |
| 437 | if (uuid_str_valid(uuid)) { |
| 438 | *e++ = 97; /* Client Machine Identifier */ |
| 439 | *e++ = 17; |
| 440 | *e++ = 0; /* type 0 - UUID */ |
| 441 | |
| 442 | uuid_str_to_bin(uuid, e); |
| 443 | e += 16; |
| 444 | } else { |
| 445 | printf("Invalid pxeuuid: %s\n", uuid); |
| 446 | } |
| 447 | } |
Ilya Yanok | 3087658 | 2012-09-17 10:26:25 +0000 | [diff] [blame] | 448 | #endif |
Jason Hobbs | ea320281 | 2011-08-31 05:37:31 +0000 | [diff] [blame] | 449 | |
Ilya Yanok | 3087658 | 2012-09-17 10:26:25 +0000 | [diff] [blame] | 450 | #ifdef CONFIG_BOOTP_VCI_STRING |
| 451 | put_vci(e, CONFIG_BOOTP_VCI_STRING); |
stroese | e0aadfb | 2003-08-28 14:17:32 +0000 | [diff] [blame] | 452 | #endif |
| 453 | |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 454 | #if defined(CONFIG_BOOTP_VENDOREX) |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 455 | x = dhcp_vendorex_prep(e); |
| 456 | if (x) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 457 | return x - start; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 458 | #endif |
| 459 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 460 | *e++ = 55; /* Parameter Request List */ |
| 461 | cnt = e++; /* Pointer to count of requested items */ |
| 462 | *cnt = 0; |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 463 | #if defined(CONFIG_BOOTP_SUBNETMASK) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 464 | *e++ = 1; /* Subnet Mask */ |
| 465 | *cnt += 1; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 466 | #endif |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 467 | #if defined(CONFIG_BOOTP_TIMEOFFSET) |
wdenk | b4ad962 | 2005-04-01 00:25:43 +0000 | [diff] [blame] | 468 | *e++ = 2; |
| 469 | *cnt += 1; |
| 470 | #endif |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 471 | #if defined(CONFIG_BOOTP_GATEWAY) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 472 | *e++ = 3; /* Router Option */ |
| 473 | *cnt += 1; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 474 | #endif |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 475 | #if defined(CONFIG_BOOTP_DNS) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 476 | *e++ = 6; /* DNS Server(s) */ |
| 477 | *cnt += 1; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 478 | #endif |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 479 | #if defined(CONFIG_BOOTP_HOSTNAME) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 480 | *e++ = 12; /* Hostname */ |
| 481 | *cnt += 1; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 482 | #endif |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 483 | #if defined(CONFIG_BOOTP_BOOTFILESIZE) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 484 | *e++ = 13; /* Boot File Size */ |
| 485 | *cnt += 1; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 486 | #endif |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 487 | #if defined(CONFIG_BOOTP_BOOTPATH) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 488 | *e++ = 17; /* Boot path */ |
| 489 | *cnt += 1; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 490 | #endif |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 491 | #if defined(CONFIG_BOOTP_NISDOMAIN) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 492 | *e++ = 40; /* NIS Domain name request */ |
| 493 | *cnt += 1; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 494 | #endif |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 495 | #if defined(CONFIG_BOOTP_NTPSERVER) |
wdenk | b4ad962 | 2005-04-01 00:25:43 +0000 | [diff] [blame] | 496 | *e++ = 42; |
| 497 | *cnt += 1; |
| 498 | #endif |
Jason Liu | 1c7dca5 | 2010-11-14 12:23:09 +0800 | [diff] [blame] | 499 | /* no options, so back up to avoid sending an empty request list */ |
| 500 | if (*cnt == 0) |
| 501 | e -= 2; |
| 502 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 503 | *e++ = 255; /* End of the list */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 504 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 505 | /* Pad to minimal length */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 506 | #ifdef CONFIG_DHCP_MIN_EXT_LEN |
Simon Glass | a0978eb | 2011-02-02 15:03:28 -0800 | [diff] [blame] | 507 | while ((e - start) < CONFIG_DHCP_MIN_EXT_LEN) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 508 | *e++ = 0; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 509 | #endif |
| 510 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 511 | return e - start; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Jon Loeliger | a9807e5 | 2007-07-10 11:05:02 -0500 | [diff] [blame] | 514 | #else |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 515 | /* |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 516 | * Warning: no field size check - change CONFIG_BOOTP_* at your own risk! |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 517 | */ |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 518 | static int BootpExtended(u8 *e) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 519 | { |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 520 | u8 *start = e; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 521 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 522 | *e++ = 99; /* RFC1048 Magic Cookie */ |
| 523 | *e++ = 130; |
| 524 | *e++ = 83; |
| 525 | *e++ = 99; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 526 | |
Jon Loeliger | 54f35c2 | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 527 | #if defined(CONFIG_CMD_DHCP) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 528 | *e++ = 53; /* DHCP Message Type */ |
| 529 | *e++ = 1; |
| 530 | *e++ = DHCP_DISCOVER; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 531 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 532 | *e++ = 57; /* Maximum DHCP Message Size */ |
| 533 | *e++ = 2; |
Joe Hershberger | ceba447 | 2012-05-23 07:58:14 +0000 | [diff] [blame] | 534 | *e++ = (576 - 312 + OPT_FIELD_SIZE) >> 16; |
| 535 | *e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff; |
Jon Loeliger | a9807e5 | 2007-07-10 11:05:02 -0500 | [diff] [blame] | 536 | #endif |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 537 | |
Ilya Yanok | f7a2c55 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 538 | #if defined(CONFIG_BOOTP_VCI_STRING) || \ |
| 539 | (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_NET_VCI_STRING)) |
| 540 | #ifdef CONFIG_SPL_BUILD |
| 541 | put_vci(e, CONFIG_SPL_NET_VCI_STRING); |
| 542 | #else |
Ilya Yanok | 3087658 | 2012-09-17 10:26:25 +0000 | [diff] [blame] | 543 | put_vci(e, CONFIG_BOOTP_VCI_STRING); |
| 544 | #endif |
Ilya Yanok | f7a2c55 | 2012-09-18 00:22:50 +0000 | [diff] [blame] | 545 | #endif |
Ilya Yanok | 3087658 | 2012-09-17 10:26:25 +0000 | [diff] [blame] | 546 | |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 547 | #if defined(CONFIG_BOOTP_SUBNETMASK) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 548 | *e++ = 1; /* Subnet mask request */ |
| 549 | *e++ = 4; |
| 550 | e += 4; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 551 | #endif |
| 552 | |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 553 | #if defined(CONFIG_BOOTP_GATEWAY) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 554 | *e++ = 3; /* Default gateway request */ |
| 555 | *e++ = 4; |
| 556 | e += 4; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 557 | #endif |
| 558 | |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 559 | #if defined(CONFIG_BOOTP_DNS) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 560 | *e++ = 6; /* Domain Name Server */ |
| 561 | *e++ = 4; |
| 562 | e += 4; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 563 | #endif |
| 564 | |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 565 | #if defined(CONFIG_BOOTP_HOSTNAME) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 566 | *e++ = 12; /* Host name request */ |
| 567 | *e++ = 32; |
| 568 | e += 32; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 569 | #endif |
| 570 | |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 571 | #if defined(CONFIG_BOOTP_BOOTFILESIZE) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 572 | *e++ = 13; /* Boot file size */ |
| 573 | *e++ = 2; |
| 574 | e += 2; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 575 | #endif |
| 576 | |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 577 | #if defined(CONFIG_BOOTP_BOOTPATH) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 578 | *e++ = 17; /* Boot path */ |
| 579 | *e++ = 32; |
| 580 | e += 32; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 581 | #endif |
| 582 | |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 583 | #if defined(CONFIG_BOOTP_NISDOMAIN) |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 584 | *e++ = 40; /* NIS Domain name request */ |
| 585 | *e++ = 32; |
| 586 | e += 32; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 587 | #endif |
Luuk Paulussen | 6380e01 | 2011-05-16 18:29:19 +0000 | [diff] [blame] | 588 | #if defined(CONFIG_BOOTP_NTPSERVER) |
| 589 | *e++ = 42; |
| 590 | *e++ = 4; |
| 591 | e += 4; |
| 592 | #endif |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 593 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 594 | *e++ = 255; /* End of the list */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 595 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 596 | return e - start; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 597 | } |
Jon Loeliger | a9807e5 | 2007-07-10 11:05:02 -0500 | [diff] [blame] | 598 | #endif |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 599 | |
| 600 | void |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 601 | BootpRequest(void) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 602 | { |
Joe Hershberger | 4b7747e | 2012-05-15 08:59:04 +0000 | [diff] [blame] | 603 | uchar *pkt, *iphdr; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 604 | struct Bootp_t *bp; |
Joe Hershberger | db3e6e4 | 2012-05-23 07:59:10 +0000 | [diff] [blame] | 605 | int extlen, pktlen, iplen; |
| 606 | int eth_hdr_size; |
Joe Hershberger | 797f2c5 | 2012-05-23 07:57:58 +0000 | [diff] [blame] | 607 | #ifdef CONFIG_BOOTP_RANDOM_DELAY |
| 608 | ulong i, rand_ms; |
| 609 | #endif |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 610 | |
Simon Glass | 768cbf0 | 2011-12-10 11:08:06 +0000 | [diff] [blame] | 611 | bootstage_mark_name(BOOTSTAGE_ID_BOOTP_START, "bootp_start"); |
Jon Loeliger | 54f35c2 | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 612 | #if defined(CONFIG_CMD_DHCP) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 613 | dhcp_state = INIT; |
| 614 | #endif |
| 615 | |
| 616 | #ifdef CONFIG_BOOTP_RANDOM_DELAY /* Random BOOTP delay */ |
Joe Hershberger | 797f2c5 | 2012-05-23 07:57:58 +0000 | [diff] [blame] | 617 | if (BootpTry == 0) |
| 618 | srand_mac(); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 619 | |
Joe Hershberger | 797f2c5 | 2012-05-23 07:57:58 +0000 | [diff] [blame] | 620 | if (BootpTry <= 2) /* Start with max 1024 * 1ms */ |
| 621 | rand_ms = rand() >> (22 - BootpTry); |
| 622 | else /* After 3rd BOOTP request max 8192 * 1ms */ |
| 623 | rand_ms = rand() >> 19; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 624 | |
Joe Hershberger | 797f2c5 | 2012-05-23 07:57:58 +0000 | [diff] [blame] | 625 | printf("Random delay: %ld ms...\n", rand_ms); |
| 626 | for (i = 0; i < rand_ms; i++) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 627 | udelay(1000); /*Wait 1ms*/ |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 628 | |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 629 | #endif /* CONFIG_BOOTP_RANDOM_DELAY */ |
| 630 | |
| 631 | printf("BOOTP broadcast %d\n", ++BootpTry); |
| 632 | pkt = NetTxPacket; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 633 | memset((void *)pkt, 0, PKTSIZE); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 634 | |
Joe Hershberger | db3e6e4 | 2012-05-23 07:59:10 +0000 | [diff] [blame] | 635 | eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_IP); |
| 636 | pkt += eth_hdr_size; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 637 | |
| 638 | /* |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 639 | * Next line results in incorrect packet size being transmitted, |
| 640 | * resulting in errors in some DHCP servers, reporting missing bytes. |
| 641 | * Size must be set in packet header after extension length has been |
| 642 | * determined. |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 643 | * C. Hallinan, DS4.COM, Inc. |
| 644 | */ |
Joe Hershberger | 2ed5b49 | 2012-05-23 07:59:07 +0000 | [diff] [blame] | 645 | /* net_set_udp_header(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 646 | sizeof (struct Bootp_t)); */ |
Joe Hershberger | 2ed5b49 | 2012-05-23 07:59:07 +0000 | [diff] [blame] | 647 | iphdr = pkt; /* We need this later for net_set_udp_header() */ |
Joe Hershberger | 6fe8b45 | 2012-05-23 07:58:04 +0000 | [diff] [blame] | 648 | pkt += IP_UDP_HDR_SIZE; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 649 | |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 650 | bp = (struct Bootp_t *)pkt; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 651 | bp->bp_op = OP_BOOTREQUEST; |
| 652 | bp->bp_htype = HWT_ETHER; |
| 653 | bp->bp_hlen = HWL_ETHER; |
| 654 | bp->bp_hops = 0; |
Bartlomiej Sieka | 5666846 | 2008-10-01 15:26:28 +0200 | [diff] [blame] | 655 | bp->bp_secs = htons(get_timer(0) / 1000); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 656 | NetWriteIP(&bp->bp_ciaddr, 0); |
| 657 | NetWriteIP(&bp->bp_yiaddr, 0); |
| 658 | NetWriteIP(&bp->bp_siaddr, 0); |
| 659 | NetWriteIP(&bp->bp_giaddr, 0); |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 660 | memcpy(bp->bp_chaddr, NetOurEther, 6); |
| 661 | copy_filename(bp->bp_file, BootFile, sizeof(bp->bp_file)); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 662 | |
| 663 | /* Request additional information from the BOOTP/DHCP server */ |
Jon Loeliger | 54f35c2 | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 664 | #if defined(CONFIG_CMD_DHCP) |
Joe Hershberger | db3e6e4 | 2012-05-23 07:59:10 +0000 | [diff] [blame] | 665 | extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 666 | #else |
Joe Hershberger | db3e6e4 | 2012-05-23 07:59:10 +0000 | [diff] [blame] | 667 | extlen = BootpExtended((u8 *)bp->bp_vend); |
Jon Loeliger | a9807e5 | 2007-07-10 11:05:02 -0500 | [diff] [blame] | 668 | #endif |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 669 | |
| 670 | /* |
| 671 | * Bootp ID is the lower 4 bytes of our ethernet address |
Bartlomiej Sieka | 5666846 | 2008-10-01 15:26:28 +0200 | [diff] [blame] | 672 | * plus the current time in ms. |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 673 | */ |
| 674 | BootpID = ((ulong)NetOurEther[2] << 24) |
| 675 | | ((ulong)NetOurEther[3] << 16) |
| 676 | | ((ulong)NetOurEther[4] << 8) |
| 677 | | (ulong)NetOurEther[5]; |
| 678 | BootpID += get_timer(0); |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 679 | BootpID = htonl(BootpID); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 680 | NetCopyLong(&bp->bp_id, &BootpID); |
| 681 | |
| 682 | /* |
| 683 | * Calculate proper packet lengths taking into account the |
| 684 | * variable size of the options field |
| 685 | */ |
Joe Hershberger | db3e6e4 | 2012-05-23 07:59:10 +0000 | [diff] [blame] | 686 | iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen; |
| 687 | pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen; |
Joe Hershberger | 2ed5b49 | 2012-05-23 07:59:07 +0000 | [diff] [blame] | 688 | net_set_udp_header(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen); |
Bartlomiej Sieka | 5666846 | 2008-10-01 15:26:28 +0200 | [diff] [blame] | 689 | NetSetTimeout(SELECT_TIMEOUT, BootpTimeout); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 690 | |
Jon Loeliger | 54f35c2 | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 691 | #if defined(CONFIG_CMD_DHCP) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 692 | dhcp_state = SELECTING; |
Joe Hershberger | f50357b | 2012-05-23 07:59:15 +0000 | [diff] [blame] | 693 | net_set_udp_handler(DhcpHandler); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 694 | #else |
Joe Hershberger | f50357b | 2012-05-23 07:59:15 +0000 | [diff] [blame] | 695 | net_set_udp_handler(BootpHandler); |
Jon Loeliger | a9807e5 | 2007-07-10 11:05:02 -0500 | [diff] [blame] | 696 | #endif |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 697 | NetSendPacket(NetTxPacket, pktlen); |
| 698 | } |
| 699 | |
Jon Loeliger | 54f35c2 | 2007-07-09 17:45:14 -0500 | [diff] [blame] | 700 | #if defined(CONFIG_CMD_DHCP) |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 701 | static void DhcpOptionsProcess(uchar *popt, struct Bootp_t *bp) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 702 | { |
wdenk | b02744a | 2003-04-05 00:53:31 +0000 | [diff] [blame] | 703 | uchar *end = popt + BOOTP_HDR_SIZE; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 704 | int oplen, size; |
Wolfgang Denk | 2b18422 | 2009-09-11 09:05:32 +0200 | [diff] [blame] | 705 | #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET) |
| 706 | int *to_ptr; |
| 707 | #endif |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 708 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 709 | while (popt < end && *popt != 0xff) { |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 710 | oplen = *(popt + 1); |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 711 | switch (*popt) { |
| 712 | case 1: |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 713 | NetCopyIP(&NetOurSubnetMask, (popt + 2)); |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 714 | break; |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 715 | #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_TIMEOFFSET) |
wdenk | b4ad962 | 2005-04-01 00:25:43 +0000 | [diff] [blame] | 716 | case 2: /* Time offset */ |
Wolfgang Denk | 2b18422 | 2009-09-11 09:05:32 +0200 | [diff] [blame] | 717 | to_ptr = &NetTimeOffset; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 718 | NetCopyLong((ulong *)to_ptr, (ulong *)(popt + 2)); |
| 719 | NetTimeOffset = ntohl(NetTimeOffset); |
wdenk | b4ad962 | 2005-04-01 00:25:43 +0000 | [diff] [blame] | 720 | break; |
| 721 | #endif |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 722 | case 3: |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 723 | NetCopyIP(&NetOurGatewayIP, (popt + 2)); |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 724 | break; |
| 725 | case 6: |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 726 | NetCopyIP(&NetOurDNSIP, (popt + 2)); |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 727 | #if defined(CONFIG_BOOTP_DNS2) |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 728 | if (*(popt + 1) > 4) |
| 729 | NetCopyIP(&NetOurDNS2IP, (popt + 2 + 4)); |
stroese | e0aadfb | 2003-08-28 14:17:32 +0000 | [diff] [blame] | 730 | #endif |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 731 | break; |
| 732 | case 12: |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 733 | size = truncate_sz("Host Name", |
| 734 | sizeof(NetOurHostName), oplen); |
| 735 | memcpy(&NetOurHostName, popt + 2, size); |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 736 | NetOurHostName[size] = 0; |
| 737 | break; |
| 738 | case 15: /* Ignore Domain Name Option */ |
| 739 | break; |
| 740 | case 17: |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 741 | size = truncate_sz("Root Path", |
| 742 | sizeof(NetOurRootPath), oplen); |
| 743 | memcpy(&NetOurRootPath, popt + 2, size); |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 744 | NetOurRootPath[size] = 0; |
| 745 | break; |
Brian Rzycki | 5a672a2 | 2012-09-11 09:22:53 +0000 | [diff] [blame] | 746 | case 28: /* Ignore Broadcast Address Option */ |
| 747 | break; |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 748 | #if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER) |
wdenk | b4ad962 | 2005-04-01 00:25:43 +0000 | [diff] [blame] | 749 | case 42: /* NTP server IP */ |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 750 | NetCopyIP(&NetNtpServerIP, (popt + 2)); |
wdenk | b4ad962 | 2005-04-01 00:25:43 +0000 | [diff] [blame] | 751 | break; |
| 752 | #endif |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 753 | case 51: |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 754 | NetCopyLong(&dhcp_leasetime, (ulong *) (popt + 2)); |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 755 | break; |
| 756 | case 53: /* Ignore Message Type Option */ |
| 757 | break; |
| 758 | case 54: |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 759 | NetCopyIP(&NetDHCPServerIP, (popt + 2)); |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 760 | break; |
| 761 | case 58: /* Ignore Renewal Time Option */ |
| 762 | break; |
| 763 | case 59: /* Ignore Rebinding Time Option */ |
| 764 | break; |
Wolfgang Denk | 012429c | 2006-03-12 18:26:46 +0100 | [diff] [blame] | 765 | case 66: /* Ignore TFTP server name */ |
| 766 | break; |
| 767 | case 67: /* vendor opt bootfile */ |
| 768 | /* |
| 769 | * I can't use dhcp_vendorex_proc here because I need |
| 770 | * to write into the bootp packet - even then I had to |
| 771 | * pass the bootp packet pointer into here as the |
| 772 | * second arg |
| 773 | */ |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 774 | size = truncate_sz("Opt Boot File", |
Wolfgang Denk | 012429c | 2006-03-12 18:26:46 +0100 | [diff] [blame] | 775 | sizeof(bp->bp_file), |
| 776 | oplen); |
| 777 | if (bp->bp_file[0] == '\0' && size > 0) { |
| 778 | /* |
| 779 | * only use vendor boot file if we didn't |
| 780 | * receive a boot file in the main non-vendor |
| 781 | * part of the packet - god only knows why |
| 782 | * some vendors chose not to use this perfectly |
| 783 | * good spot to store the boot file (join on |
| 784 | * Tru64 Unix) it seems mind bogglingly crazy |
| 785 | * to me |
| 786 | */ |
| 787 | printf("*** WARNING: using vendor " |
| 788 | "optional boot file\n"); |
| 789 | memcpy(bp->bp_file, popt + 2, size); |
| 790 | bp->bp_file[size] = '\0'; |
| 791 | } |
| 792 | break; |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 793 | default: |
Jon Loeliger | 5336a76 | 2007-07-09 22:08:34 -0500 | [diff] [blame] | 794 | #if defined(CONFIG_BOOTP_VENDOREX) |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 795 | if (dhcp_vendorex_proc(popt)) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 796 | break; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 797 | #endif |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 798 | printf("*** Unhandled DHCP Option in OFFER/ACK:" |
| 799 | " %d\n", *popt); |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 800 | break; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 801 | } |
| 802 | popt += oplen + 2; /* Process next option */ |
| 803 | } |
| 804 | } |
| 805 | |
| 806 | static int DhcpMessageType(unsigned char *popt) |
| 807 | { |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 808 | if (NetReadLong((ulong *)popt) != htonl(BOOTP_VENDOR_MAGIC)) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 809 | return -1; |
| 810 | |
| 811 | popt += 4; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 812 | while (*popt != 0xff) { |
| 813 | if (*popt == 53) /* DHCP Message Type */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 814 | return *(popt + 2); |
| 815 | popt += *(popt + 1) + 2; /* Scan through all options */ |
| 816 | } |
| 817 | return -1; |
| 818 | } |
| 819 | |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 820 | static void DhcpSendRequestPkt(struct Bootp_t *bp_offer) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 821 | { |
Joe Hershberger | 4b7747e | 2012-05-15 08:59:04 +0000 | [diff] [blame] | 822 | uchar *pkt, *iphdr; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 823 | struct Bootp_t *bp; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 824 | int pktlen, iplen, extlen; |
Joe Hershberger | db3e6e4 | 2012-05-23 07:59:10 +0000 | [diff] [blame] | 825 | int eth_hdr_size; |
wdenk | cc1e256 | 2003-03-06 13:39:27 +0000 | [diff] [blame] | 826 | IPaddr_t OfferedIP; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 827 | |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 828 | debug("DhcpSendRequestPkt: Sending DHCPREQUEST\n"); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 829 | pkt = NetTxPacket; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 830 | memset((void *)pkt, 0, PKTSIZE); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 831 | |
Joe Hershberger | db3e6e4 | 2012-05-23 07:59:10 +0000 | [diff] [blame] | 832 | eth_hdr_size = NetSetEther(pkt, NetBcastAddr, PROT_IP); |
| 833 | pkt += eth_hdr_size; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 834 | |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 835 | iphdr = pkt; /* We'll need this later to set proper pkt size */ |
Joe Hershberger | 6fe8b45 | 2012-05-23 07:58:04 +0000 | [diff] [blame] | 836 | pkt += IP_UDP_HDR_SIZE; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 837 | |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 838 | bp = (struct Bootp_t *)pkt; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 839 | bp->bp_op = OP_BOOTREQUEST; |
| 840 | bp->bp_htype = HWT_ETHER; |
| 841 | bp->bp_hlen = HWL_ETHER; |
| 842 | bp->bp_hops = 0; |
Bartlomiej Sieka | 5666846 | 2008-10-01 15:26:28 +0200 | [diff] [blame] | 843 | bp->bp_secs = htons(get_timer(0) / 1000); |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 844 | /* Do not set the client IP, your IP, or server IP yet, since it |
| 845 | * hasn't been ACK'ed by the server yet */ |
Justin Flammia | 01f256b | 2007-10-29 17:40:35 -0400 | [diff] [blame] | 846 | |
Wolfgang Denk | 8a933fb | 2006-10-12 00:01:08 +0200 | [diff] [blame] | 847 | /* |
Wolfgang Denk | 68e83a8 | 2006-10-09 01:26:14 +0200 | [diff] [blame] | 848 | * RFC3046 requires Relay Agents to discard packets with |
| 849 | * nonzero and offered giaddr |
| 850 | */ |
| 851 | NetWriteIP(&bp->bp_giaddr, 0); |
| 852 | |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 853 | memcpy(bp->bp_chaddr, NetOurEther, 6); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 854 | |
| 855 | /* |
| 856 | * ID is the id of the OFFER packet |
| 857 | */ |
| 858 | |
| 859 | NetCopyLong(&bp->bp_id, &bp_offer->bp_id); |
| 860 | |
| 861 | /* |
| 862 | * Copy options from OFFER packet if present |
| 863 | */ |
Justin Flammia | 01f256b | 2007-10-29 17:40:35 -0400 | [diff] [blame] | 864 | |
| 865 | /* Copy offered IP into the parameters request list */ |
| 866 | NetCopyIP(&OfferedIP, &bp_offer->bp_yiaddr); |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 867 | extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST, |
| 868 | NetDHCPServerIP, OfferedIP); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 869 | |
Joe Hershberger | db3e6e4 | 2012-05-23 07:59:10 +0000 | [diff] [blame] | 870 | iplen = BOOTP_HDR_SIZE - OPT_FIELD_SIZE + extlen; |
| 871 | pktlen = eth_hdr_size + IP_UDP_HDR_SIZE + iplen; |
Joe Hershberger | 2ed5b49 | 2012-05-23 07:59:07 +0000 | [diff] [blame] | 872 | net_set_udp_header(iphdr, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC, iplen); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 873 | |
Aras Vaichas | 72aa3f3 | 2008-03-26 09:43:57 +1100 | [diff] [blame] | 874 | #ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY |
| 875 | udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY); |
| 876 | #endif /* CONFIG_BOOTP_DHCP_REQUEST_DELAY */ |
Joe Hershberger | b1e9476 | 2012-05-23 07:59:11 +0000 | [diff] [blame] | 877 | debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 878 | NetSendPacket(NetTxPacket, pktlen); |
| 879 | } |
| 880 | |
| 881 | /* |
| 882 | * Handle DHCP received packets. |
| 883 | */ |
| 884 | static void |
Luca Ceresoli | 428ab36 | 2011-04-18 06:19:50 +0000 | [diff] [blame] | 885 | DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, |
| 886 | unsigned len) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 887 | { |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 888 | struct Bootp_t *bp = (struct Bootp_t *)pkt; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 889 | |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 890 | debug("DHCPHandler: got packet: (src=%d, dst=%d, len=%d) state: %d\n", |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 891 | src, dest, len, dhcp_state); |
| 892 | |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 893 | /* Filter out pkts we don't want */ |
| 894 | if (BootpCheckPkt(pkt, dest, src, len)) |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 895 | return; |
| 896 | |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 897 | debug("DHCPHandler: got DHCP packet: (src=%d, dst=%d, len=%d) state:" |
| 898 | " %d\n", src, dest, len, dhcp_state); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 899 | |
| 900 | switch (dhcp_state) { |
| 901 | case SELECTING: |
| 902 | /* |
| 903 | * Wait an appropriate time for any potential DHCPOFFER packets |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 904 | * to arrive. Then select one, and generate DHCPREQUEST |
| 905 | * response. If filename is in format we recognize, assume it |
| 906 | * is a valid OFFER from a server we want. |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 907 | */ |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 908 | debug("DHCP: state=SELECTING bp_file: \"%s\"\n", bp->bp_file); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 909 | #ifdef CONFIG_SYS_BOOTFILE_PREFIX |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 910 | if (strncmp(bp->bp_file, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 911 | CONFIG_SYS_BOOTFILE_PREFIX, |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 912 | strlen(CONFIG_SYS_BOOTFILE_PREFIX)) == 0) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 913 | #endif /* CONFIG_SYS_BOOTFILE_PREFIX */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 914 | |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 915 | debug("TRANSITIONING TO REQUESTING STATE\n"); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 916 | dhcp_state = REQUESTING; |
stroese | 5fa6e90 | 2003-04-10 13:26:44 +0000 | [diff] [blame] | 917 | |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 918 | if (NetReadLong((ulong *)&bp->bp_vend[0]) == |
| 919 | htonl(BOOTP_VENDOR_MAGIC)) |
Wolfgang Denk | 012429c | 2006-03-12 18:26:46 +0100 | [diff] [blame] | 920 | DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 921 | |
Bartlomiej Sieka | 5666846 | 2008-10-01 15:26:28 +0200 | [diff] [blame] | 922 | NetSetTimeout(TIMEOUT, BootpTimeout); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 923 | DhcpSendRequestPkt(bp); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 924 | #ifdef CONFIG_SYS_BOOTFILE_PREFIX |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 925 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 926 | #endif /* CONFIG_SYS_BOOTFILE_PREFIX */ |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 927 | |
| 928 | return; |
| 929 | break; |
| 930 | case REQUESTING: |
Robin Getz | 9e0a4d6 | 2009-07-23 03:01:03 -0400 | [diff] [blame] | 931 | debug("DHCP State: REQUESTING\n"); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 932 | |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 933 | if (DhcpMessageType((u8 *)bp->bp_vend) == DHCP_ACK) { |
| 934 | if (NetReadLong((ulong *)&bp->bp_vend[0]) == |
| 935 | htonl(BOOTP_VENDOR_MAGIC)) |
Wolfgang Denk | 012429c | 2006-03-12 18:26:46 +0100 | [diff] [blame] | 936 | DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp); |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 937 | /* Store net params from reply */ |
| 938 | BootpCopyNetParams(bp); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 939 | dhcp_state = BOUND; |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 940 | printf("DHCP client bound to address %pI4\n", |
| 941 | &NetOurIP); |
Simon Glass | 768cbf0 | 2011-12-10 11:08:06 +0000 | [diff] [blame] | 942 | bootstage_mark_name(BOOTSTAGE_ID_BOOTP_STOP, |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 943 | "bootp_stop"); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 944 | |
Simon Glass | 5234ad1 | 2011-10-27 06:24:32 +0000 | [diff] [blame] | 945 | net_auto_load(); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 946 | return; |
| 947 | } |
| 948 | break; |
Remy Bohmer | 03a4449 | 2008-08-20 11:30:28 +0200 | [diff] [blame] | 949 | case BOUND: |
| 950 | /* DHCP client bound to address */ |
| 951 | break; |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 952 | default: |
Joe Hershberger | 8f4b135 | 2012-05-15 08:59:06 +0000 | [diff] [blame] | 953 | puts("DHCP: INVALID STATE\n"); |
wdenk | 3861aa5 | 2002-09-27 23:19:37 +0000 | [diff] [blame] | 954 | break; |
| 955 | } |
| 956 | |
| 957 | } |
| 958 | |
| 959 | void DhcpRequest(void) |
| 960 | { |
| 961 | BootpRequest(); |
| 962 | } |
Wolfgang Denk | f7a7f08 | 2007-11-03 23:09:27 +0100 | [diff] [blame] | 963 | #endif /* CONFIG_CMD_DHCP */ |