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