]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - net/bootp.c
net: tftpput: Factor out start, restart and next block functions
[karo-tx-uboot.git] / net / bootp.c
index e679f8b7f876e236bd7ec84b7218299c3bb82f57..73470f2d46fc66942b65e39a975be89e43329f4a 100644 (file)
@@ -44,7 +44,8 @@ ulong         seed1, seed2;
 dhcp_state_t dhcp_state = INIT;
 unsigned long dhcp_leasetime = 0;
 IPaddr_t NetDHCPServerIP = 0;
-static void DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len);
+static void DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+                       unsigned len);
 
 /* For Debug */
 #if 0
@@ -137,6 +138,36 @@ static int truncate_sz (const char *name, int maxlen, int curlen)
        return (curlen);
 }
 
+/*
+ * Check if autoload is enabled. If so, use either NFS or TFTP to download
+ * the boot file.
+ */
+static void auto_load(void)
+{
+       const char *s = getenv("autoload");
+
+       if (s != NULL) {
+               if (*s == 'n') {
+                       /*
+                        * Just use BOOTP to configure system;
+                        * Do not use TFTP to load the bootfile.
+                        */
+                       NetState = NETLOOP_SUCCESS;
+                       return;
+               }
+#if defined(CONFIG_CMD_NFS)
+               if (strcmp(s, "NFS") == 0) {
+                       /*
+                        * Use NFS to load the bootfile.
+                        */
+                       NfsStart();
+                       return;
+               }
+#endif
+       }
+       TftpStart();
+}
+
 #if !defined(CONFIG_CMD_DHCP)
 
 static void BootpVendorFieldProcess (u8 * ext)
@@ -227,6 +258,11 @@ static void BootpVendorFieldProcess (u8 * ext)
                        NetOurNISDomain[size] = 0;
                }
                break;
+#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
+       case 42:        /* NTP server IP */
+               NetCopyIP(&NetNtpServerIP, (IPaddr_t *) (ext + 2));
+               break;
+#endif
                /* Application layer fields */
        case 43:                /* Vendor specific info - Not yet supported     */
                /*
@@ -277,15 +313,21 @@ static void BootpVendorProcess (u8 * ext, int size)
 
        if (NetBootFileSize)
                debug("NetBootFileSize: %d\n", NetBootFileSize);
+
+#if defined(CONFIG_CMD_SNTP) && defined(CONFIG_BOOTP_NTPSERVER)
+       if (NetNtpServerIP)
+               debug("NetNtpServerIP : %pI4\n", &NetNtpServerIP);
+#endif
 }
+
 /*
  *     Handle a BOOTP received packet.
  */
 static void
-BootpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
+BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+            unsigned len)
 {
        Bootp_t *bp;
-       char    *s;
 
        debug("got BOOTP packet (src=%d, dst=%d, len=%d want_len=%zu)\n",
                src, dest, len, sizeof (Bootp_t));
@@ -312,26 +354,7 @@ BootpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
 
        debug("Got good BOOTP\n");
 
-       if ((s = getenv("autoload")) != NULL) {
-               if (*s == 'n') {
-                       /*
-                        * Just use BOOTP to configure system;
-                        * Do not use TFTP to load the bootfile.
-                        */
-                       NetState = NETLOOP_SUCCESS;
-                       return;
-#if defined(CONFIG_CMD_NFS)
-               } else if (strcmp(s, "NFS") == 0) {
-                       /*
-                        * Use NFS to load the bootfile.
-                        */
-                       NfsStart();
-                       return;
-#endif
-               }
-       }
-
-       TftpStart();
+       auto_load();
 }
 #endif
 
@@ -358,6 +381,11 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R
 {
        u8 *start = e;
        u8 *cnt;
+#if defined(CONFIG_BOOTP_PXE)
+       char *uuid;
+       size_t vci_strlen;
+       u16 clientarch;
+#endif
 
 #if defined(CONFIG_BOOTP_VENDOREX)
        u8 *x;
@@ -412,6 +440,41 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R
        }
 #endif
 
+#if defined(CONFIG_BOOTP_PXE)
+       clientarch = CONFIG_BOOTP_PXE_CLIENTARCH;
+       *e++ = 93;      /* Client System Architecture */
+       *e++ = 2;
+       *e++ = (clientarch >> 8) & 0xff;
+       *e++ = clientarch & 0xff;
+
+       *e++ = 94;      /* Client Network Interface Identifier */
+       *e++ = 3;
+       *e++ = 1;       /* type field for UNDI */
+       *e++ = 0;       /* major revision */
+       *e++ = 0;       /* minor revision */
+
+       uuid = getenv("pxeuuid");
+
+       if (uuid) {
+               if (uuid_str_valid(uuid)) {
+                       *e++ = 97;      /* Client Machine Identifier */
+                       *e++ = 17;
+                       *e++ = 0;       /* type 0 - UUID */
+
+                       uuid_str_to_bin(uuid, e);
+                       e += 16;
+               } else {
+                       printf("Invalid pxeuuid: %s\n", uuid);
+               }
+       }
+
+       *e++ = 60;      /* Vendor Class Identifier */
+       vci_strlen = strlen(CONFIG_BOOTP_VCI_STRING);
+       *e++ = vci_strlen;
+       memcpy(e, CONFIG_BOOTP_VCI_STRING, vci_strlen);
+       e += vci_strlen;
+#endif
+
 #if defined(CONFIG_BOOTP_VENDOREX)
        if ((x = dhcp_vendorex_prep (e)))
                return x - start;
@@ -456,11 +519,15 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R
        *e++  = 42;
        *cnt += 1;
 #endif
+       /* no options, so back up to avoid sending an empty request list */
+       if (*cnt == 0)
+               e -= 2;
+
        *e++  = 255;            /* End of the list */
 
        /* Pad to minimal length */
 #ifdef CONFIG_DHCP_MIN_EXT_LEN
-       while ((e - start) <= CONFIG_DHCP_MIN_EXT_LEN)
+       while ((e - start) < CONFIG_DHCP_MIN_EXT_LEN)
                *e++ = 0;
 #endif
 
@@ -532,6 +599,11 @@ static int BootpExtended (u8 * e)
        *e++ = 32;
        e   += 32;
 #endif
+#if defined(CONFIG_BOOTP_NTPSERVER)
+       *e++ = 42;
+       *e++ = 4;
+       e   += 4;
+#endif
 
        *e++ = 255;             /* End of the list */
 
@@ -854,7 +926,8 @@ static void DhcpSendRequestPkt(Bootp_t *bp_offer)
  *     Handle DHCP received packets.
  */
 static void
-DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
+DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+           unsigned len)
 {
        Bootp_t *bp = (Bootp_t *)pkt;
 
@@ -900,34 +973,13 @@ DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
                debug("DHCP State: REQUESTING\n");
 
                if ( DhcpMessageType((u8 *)bp->bp_vend) == DHCP_ACK ) {
-                       char *s;
-
                        if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
                                DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
                        BootpCopyNetParams(bp); /* Store net params from reply */
                        dhcp_state = BOUND;
                        printf ("DHCP client bound to address %pI4\n", &NetOurIP);
 
-                       /* Obey the 'autoload' setting */
-                       if ((s = getenv("autoload")) != NULL) {
-                               if (*s == 'n') {
-                                       /*
-                                        * Just use BOOTP to configure system;
-                                        * Do not use TFTP to load the bootfile.
-                                        */
-                                       NetState = NETLOOP_SUCCESS;
-                                       return;
-#if defined(CONFIG_CMD_NFS)
-                               } else if (strcmp(s, "NFS") == 0) {
-                                       /*
-                                        * Use NFS to load the bootfile.
-                                        */
-                                       NfsStart();
-                                       return;
-#endif
-                               }
-                       }
-                       TftpStart();
+                       auto_load();
                        return;
                }
                break;