]> git.sur5r.net Git - u-boot/blobdiff - net/bootp.c
* Added PCI-X #defines for PCI-X initialization
[u-boot] / net / bootp.c
index 9eae34fd4002e0c97623def7a2afe962a2fdd5ef..669d74a6a50ae0f9f1a8ecba05101bb8ada04624 100644 (file)
@@ -268,7 +268,7 @@ static void BootpVendorProcess (u8 * ext, int size)
        }
 
 #ifdef DEBUG_BOOTP_EXT
-       printf ("[BOOTP] Received fields: \n");
+       puts ("[BOOTP] Received fields: \n");
        if (NetOurSubnetMask) {
                puts ("NetOurSubnetMask : ");
                print_IPaddr (NetOurSubnetMask);
@@ -330,7 +330,7 @@ BootpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
 
        /* Retrieve extended information (we must parse the vendor area) */
        if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
-               BootpVendorProcess(&bp->bp_vend[4], len);
+               BootpVendorProcess((uchar *)&bp->bp_vend[4], len);
 
        NetSetTimeout(0, (thand_f *)0);
 
@@ -387,7 +387,7 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R
        u8 *x;
 #endif
 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_SEND_HOSTNAME)
-       uchar *hostname;
+       char *hostname;
 #endif
 
        *e++ = 99;              /* RFC1048 Magic Cookie */
@@ -448,6 +448,10 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R
        *e++  = 1;              /* Subnet Mask */
        *cnt += 1;
 #endif
+#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_TIMEOFFSET)
+       *e++  = 2;
+       *cnt += 1;
+#endif
 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_GATEWAY)
        *e++  = 3;              /* Router Option */
        *cnt += 1;
@@ -471,6 +475,10 @@ static int DhcpExtended (u8 * e, int message_type, IPaddr_t ServerID, IPaddr_t R
 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_NISDOMAIN)
        *e++  = 40;             /* NIS Domain name request */
        *cnt += 1;
+#endif
+#if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_NTPSERVER)
+       *e++  = 42;
+       *cnt += 1;
 #endif
        *e++  = 255;            /* End of the list */
 
@@ -570,7 +578,7 @@ BootpRequest (void)
        unsigned char bi_enetaddr[6];
        int   reg;
        char  *e,*s;
-       uchar tmp[64];
+       char tmp[64];
        ulong tst1, tst2, sum, m_mask, m_value = 0;
 
        if (BootpTry ==0) {
@@ -585,7 +593,7 @@ BootpRequest (void)
                        }
                }
 #ifdef DEBUG
-               printf("BootpRequest => Our Mac: ");
+               puts ("BootpRequest => Our Mac: ");
                for (reg=0; reg<6; reg++) {
                        printf ("%x%c",
                                bi_enetaddr[reg],
@@ -644,8 +652,7 @@ BootpRequest (void)
        pkt = NetTxPacket;
        memset ((void*)pkt, 0, PKTSIZE);
 
-       NetSetEther(pkt, NetBcastAddr, PROT_IP);
-       pkt += ETHER_HDR_SIZE;
+       pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
 
        /*
         * Next line results in incorrect packet size being transmitted, resulting
@@ -672,9 +679,9 @@ BootpRequest (void)
 
        /* Request additional information from the BOOTP/DHCP server */
 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
-       ext_len = DhcpExtended(bp->bp_vend, DHCP_DISCOVER, 0, 0);
+       ext_len = DhcpExtended((u8 *)bp->bp_vend, DHCP_DISCOVER, 0, 0);
 #else
-       ext_len = BootpExtended(bp->bp_vend);
+       ext_len = BootpExtended((u8 *)bp->bp_vend);
 #endif /* CFG_CMD_DHCP */
 
        /*
@@ -708,7 +715,7 @@ BootpRequest (void)
 }
 
 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
-static void DhcpOptionsProcess (uchar * popt)
+static void DhcpOptionsProcess (uchar * popt, Bootp_t *bp)
 {
        uchar *end = popt + BOOTP_HDR_SIZE;
        int oplen, size;
@@ -719,6 +726,12 @@ static void DhcpOptionsProcess (uchar * popt)
                case 1:
                        NetCopyIP (&NetOurSubnetMask, (popt + 2));
                        break;
+#if (CONFIG_COMMANDS & CFG_CMD_SNTP) && (CONFIG_BOOTP_MASK & CONFIG_BOOTP_TIMEOFFSET)
+               case 2:         /* Time offset  */
+                       NetCopyLong (&NetTimeOffset, (ulong *) (popt + 2));
+                       NetTimeOffset = ntohl (NetTimeOffset);
+                       break;
+#endif
                case 3:
                        NetCopyIP (&NetOurGatewayIP, (popt + 2));
                        break;
@@ -742,6 +755,11 @@ static void DhcpOptionsProcess (uchar * popt)
                        memcpy (&NetOurRootPath, popt + 2, size);
                        NetOurRootPath[size] = 0;
                        break;
+#if (CONFIG_COMMANDS & CFG_CMD_SNTP) && (CONFIG_BOOTP_MASK & CONFIG_BOOTP_NTPSERVER)
+               case 42:        /* NTP server IP */
+                       NetCopyIP (&NetNtpServerIP, (popt + 2));
+                       break;
+#endif
                case 51:
                        NetCopyLong (&dhcp_leasetime, (ulong *) (popt + 2));
                        break;
@@ -754,6 +772,34 @@ static void DhcpOptionsProcess (uchar * popt)
                        break;
                case 59:        /* Ignore Rebinding Time Option */
                        break;
+               case 66:        /* Ignore TFTP server name */
+                       break;
+               case 67:        /* vendor opt bootfile */
+                       /*
+                        * I can't use dhcp_vendorex_proc here because I need
+                        * to write into the bootp packet - even then I had to
+                        * pass the bootp packet pointer into here as the
+                        * second arg
+                        */
+                       size = truncate_sz ("Opt Boot File",
+                                           sizeof(bp->bp_file),
+                                           oplen);
+                       if (bp->bp_file[0] == '\0' && size > 0) {
+                               /*
+                                * only use vendor boot file if we didn't
+                                * receive a boot file in the main non-vendor
+                                * part of the packet - god only knows why
+                                * some vendors chose not to use this perfectly
+                                * good spot to store the boot file (join on
+                                * Tru64 Unix) it seems mind bogglingly crazy
+                                * to me
+                                */
+                               printf("*** WARNING: using vendor "
+                                       "optional boot file\n");
+                               memcpy(bp->bp_file, popt + 2, size);
+                               bp->bp_file[size] = '\0';
+                       }
+                       break;
                default:
 #if (CONFIG_BOOTP_MASK & CONFIG_BOOTP_VENDOREX)
                        if (dhcp_vendorex_proc (popt))
@@ -791,8 +837,7 @@ static void DhcpSendRequestPkt(Bootp_t *bp_offer)
        pkt = NetTxPacket;
        memset ((void*)pkt, 0, PKTSIZE);
 
-       NetSetEther(pkt, NetBcastAddr, PROT_IP);
-       pkt += ETHER_HDR_SIZE;
+       pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
 
        iphdr = pkt;            /* We'll need this later to set proper pkt size */
        pkt += IP_HDR_SIZE;
@@ -819,7 +864,7 @@ static void DhcpSendRequestPkt(Bootp_t *bp_offer)
         * Copy options from OFFER packet if present
         */
        NetCopyIP(&OfferedIP, &bp->bp_yiaddr);
-       extlen = DhcpExtended(bp->bp_vend, DHCP_REQUEST, NetDHCPServerIP, OfferedIP);
+       extlen = DhcpExtended((u8 *)bp->bp_vend, DHCP_REQUEST, NetDHCPServerIP, OfferedIP);
 
        pktlen = BOOTP_SIZE - sizeof(bp->bp_vend) + extlen;
        iplen = BOOTP_HDR_SIZE - sizeof(bp->bp_vend) + extlen;
@@ -865,7 +910,7 @@ DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
                        dhcp_state = REQUESTING;
 
                        if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
-                               DhcpOptionsProcess(&bp->bp_vend[4]);
+                               DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
 
                        BootpCopyNetParams(bp); /* Store net params from reply */
 
@@ -880,16 +925,16 @@ DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
        case REQUESTING:
                debug ("DHCP State: REQUESTING\n");
 
-               if ( DhcpMessageType(bp->bp_vend) == DHCP_ACK ) {
+               if ( DhcpMessageType((u8 *)bp->bp_vend) == DHCP_ACK ) {
                        char *s;
 
                        if (NetReadLong((ulong*)&bp->bp_vend[0]) == htonl(BOOTP_VENDOR_MAGIC))
-                               DhcpOptionsProcess(&bp->bp_vend[4]);
+                               DhcpOptionsProcess((u8 *)&bp->bp_vend[4], bp);
                        BootpCopyNetParams(bp); /* Store net params from reply */
                        dhcp_state = BOUND;
-                       printf("DHCP client bound to address ");
+                       puts ("DHCP client bound to address ");
                        print_IPaddr(NetOurIP);
-                       printf("\n");
+                       putc ('\n');
 
                        /* Obey the 'autoload' setting */
                        if ((s = getenv("autoload")) != NULL) {
@@ -915,7 +960,7 @@ DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
                }
                break;
        default:
-               printf("DHCP: INVALID STATE\n");
+               puts ("DHCP: INVALID STATE\n");
                break;
        }