]> Git Repo - J-u-boot.git/blobdiff - net/bootp.c
net: Get pxe config file from dhcp option 209
[J-u-boot.git] / net / bootp.c
index 163af41e926fcd2957d2c8e8b83fb1a3dcd193dd..680029096349d1c8b4c6ae5ab0a605337df33e06 100644 (file)
 #ifdef CONFIG_BOOTP_RANDOM_DELAY
 #include "net_rand.h"
 #endif
+#include <malloc.h>
 
 #define BOOTP_VENDOR_MAGIC     0x63825363      /* RFC1048 Magic Cookie */
 
 /*
  * The timeout for the initial BOOTP/DHCP request used to be described by a
- * counter of fixed-length timeout periods. TIMEOUT_COUNT represents
+ * counter of fixed-length timeout periods. CONFIG_NET_RETRY_COUNT represents
  * that counter
  *
  * Now that the timeout periods are variable (exponential backoff and retry)
  * execute that many retries, and keep sending retry packets until that time
  * is reached.
  */
-#ifndef CONFIG_NET_RETRY_COUNT
-# define TIMEOUT_COUNT 5               /* # of timeouts before giving up */
-#else
-# define TIMEOUT_COUNT (CONFIG_NET_RETRY_COUNT)
-#endif
-#define TIMEOUT_MS     ((3 + (TIMEOUT_COUNT * 5)) * 1000)
-
-#define PORT_BOOTPS    67              /* BOOTP server UDP port */
-#define PORT_BOOTPC    68              /* BOOTP client UDP port */
+#define TIMEOUT_MS     ((3 + (CONFIG_NET_RETRY_COUNT * 5)) * 1000)
 
-#ifndef CONFIG_DHCP_MIN_EXT_LEN                /* minimal length of extension list */
-#define CONFIG_DHCP_MIN_EXT_LEN 64
+#ifndef CFG_DHCP_MIN_EXT_LEN           /* minimal length of extension list */
+#define CFG_DHCP_MIN_EXT_LEN 64
 #endif
 
-#ifndef CONFIG_BOOTP_ID_CACHE_SIZE
-#define CONFIG_BOOTP_ID_CACHE_SIZE 4
+#ifndef CFG_BOOTP_ID_CACHE_SIZE
+#define CFG_BOOTP_ID_CACHE_SIZE 4
 #endif
 
-u32            bootp_ids[CONFIG_BOOTP_ID_CACHE_SIZE];
+u32            bootp_ids[CFG_BOOTP_ID_CACHE_SIZE];
 unsigned int   bootp_num_ids;
 int            bootp_try;
 ulong          bootp_start;
 ulong          bootp_timeout;
 char net_nis_domain[32] = {0,}; /* Our NIS domain */
 char net_hostname[32] = {0,}; /* Our hostname */
-char net_root_path[64] = {0,}; /* Our bootpath */
+char net_root_path[CONFIG_BOOTP_MAX_ROOT_PATH_LEN] = {0,}; /* Our bootpath */
 
 static ulong time_taken_max;
 
@@ -148,10 +141,12 @@ static int check_reply_packet(uchar *pkt, unsigned dest, unsigned src,
 
 static void store_bootp_params(struct bootp_hdr *bp)
 {
-#if !defined(CONFIG_BOOTP_SERVERIP)
        struct in_addr tmp_ip;
        bool overwrite_serverip = true;
 
+       if (IS_ENABLED(CONFIG_BOOTP_SERVERIP))
+               return;
+
 #if defined(CONFIG_BOOTP_PREFER_SERVERIP)
        overwrite_serverip = false;
 #endif
@@ -179,7 +174,6 @@ static void store_bootp_params(struct bootp_hdr *bp)
         */
        if (*net_boot_file_name)
                env_set("bootfile", net_boot_file_name);
-#endif
 }
 
 /*
@@ -608,6 +602,10 @@ static int dhcp_extended(u8 *e, int message_type, struct in_addr server_ip,
        *e++  = 42;
        *cnt += 1;
 #endif
+       if (IS_ENABLED(CONFIG_BOOTP_PXE_DHCP_OPTION)) {
+               *e++ = 209;     /* PXELINUX Config File */
+               *cnt += 1;
+       }
        /* no options, so back up to avoid sending an empty request list */
        if (*cnt == 0)
                e -= 2;
@@ -615,8 +613,8 @@ static int dhcp_extended(u8 *e, int message_type, struct in_addr server_ip,
        *e++  = 255;            /* End of the list */
 
        /* Pad to minimal length */
-#ifdef CONFIG_DHCP_MIN_EXT_LEN
-       while ((e - start) < CONFIG_DHCP_MIN_EXT_LEN)
+#ifdef CFG_DHCP_MIN_EXT_LEN
+       while ((e - start) < CFG_DHCP_MIN_EXT_LEN)
                *e++ = 0;
 #endif
 
@@ -647,7 +645,7 @@ static int bootp_extended(u8 *e)
        *e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff;
 #endif
 
-       add_vci(e);
+       e = add_vci(e);
 
 #if defined(CONFIG_BOOTP_SUBNETMASK)
        *e++ = 1;               /* Subnet mask request */
@@ -740,7 +738,7 @@ void bootp_request(void)
 
        ep = env_get("bootpretryperiod");
        if (ep != NULL)
-               time_taken_max = simple_strtoul(ep, NULL, 10);
+               time_taken_max = dectoul(ep, NULL);
        else
                time_taken_max = TIMEOUT_MS;
 
@@ -916,6 +914,22 @@ static void dhcp_process_options(uchar *popt, uchar *end)
                                net_boot_file_name[size] = 0;
                        }
                        break;
+               case 209:       /* PXELINUX Config File */
+                       if (IS_ENABLED(CONFIG_BOOTP_PXE_DHCP_OPTION)) {
+                               /* In case it has already been allocated when get DHCP Offer packet,
+                                * free first to avoid memory leak.
+                                */
+                               if (pxelinux_configfile)
+                                       free(pxelinux_configfile);
+
+                               pxelinux_configfile = (char *)malloc((oplen + 1) * sizeof(char));
+
+                               if (pxelinux_configfile)
+                                       strlcpy(pxelinux_configfile, popt + 2, oplen + 1);
+                               else
+                                       printf("Error: Failed to allocate pxelinux_configfile\n");
+                       }
+                       break;
                default:
 #if defined(CONFIG_BOOTP_VENDOREX)
                        if (dhcp_vendorex_proc(popt))
@@ -1037,9 +1051,6 @@ static void dhcp_send_request_packet(struct bootp_hdr *bp_offer)
        bcast_ip.s_addr = 0xFFFFFFFFL;
        net_set_udp_header(iphdr, bcast_ip, PORT_BOOTPS, PORT_BOOTPC, iplen);
 
-#ifdef CONFIG_BOOTP_DHCP_REQUEST_DELAY
-       udelay(CONFIG_BOOTP_DHCP_REQUEST_DELAY);
-#endif /* CONFIG_BOOTP_DHCP_REQUEST_DELAY */
        debug("Transmitting DHCPREQUEST packet: len = %d\n", pktlen);
        net_send_packet(net_tx_packet, pktlen);
 }
@@ -1083,8 +1094,15 @@ static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
                            CONFIG_SYS_BOOTFILE_PREFIX,
                            strlen(CONFIG_SYS_BOOTFILE_PREFIX)) == 0) {
 #endif /* CONFIG_SYS_BOOTFILE_PREFIX */
+                       if (CONFIG_IS_ENABLED(UNIT_TEST) &&
+                           dhcp_message_type((u8 *)bp->bp_vend) == -1) {
+                               debug("got BOOTP response; transitioning to BOUND\n");
+                               goto dhcp_got_bootp;
+                       }
                        dhcp_packet_process_options(bp);
-                       efi_net_set_dhcp_ack(pkt, len);
+                       if (CONFIG_IS_ENABLED(EFI_LOADER) &&
+                           IS_ENABLED(CONFIG_NETDEVICES))
+                               efi_net_set_dhcp_ack(pkt, len);
 
 #if defined(CONFIG_SERVERIP_FROM_PROXYDHCP)
                        if (!net_server_ip.s_addr)
@@ -1107,6 +1125,7 @@ static void dhcp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
                debug("DHCP State: REQUESTING\n");
 
                if (dhcp_message_type((u8 *)bp->bp_vend) == DHCP_ACK) {
+dhcp_got_bootp:
                        dhcp_packet_process_options(bp);
                        /* Store net params from reply */
                        store_net_params(bp);
This page took 0.031998 seconds and 4 git commands to generate.