Rename mcfrtc to rtc
[oweals/u-boot.git] / net / bootp.c
index b907351f25c5434969731cfa2bb587ecd860eba6..1de9a8f2c6aab435182e3e9df23de893978ec9cb 100644 (file)
@@ -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 */
@@ -578,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) {
@@ -679,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 */
 
        /*
@@ -715,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;
@@ -772,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))
@@ -823,7 +851,12 @@ static void DhcpSendRequestPkt(Bootp_t *bp_offer)
        NetCopyIP(&bp->bp_ciaddr, &bp_offer->bp_ciaddr); /* both in network byte order */
        NetCopyIP(&bp->bp_yiaddr, &bp_offer->bp_yiaddr);
        NetCopyIP(&bp->bp_siaddr, &bp_offer->bp_siaddr);
-       NetCopyIP(&bp->bp_giaddr, &bp_offer->bp_giaddr);
+       /*
+        * RFC3046 requires Relay Agents to discard packets with
+        * nonzero and offered giaddr
+        */
+       NetWriteIP(&bp->bp_giaddr, 0);
+
        memcpy (bp->bp_chaddr, NetOurEther, 6);
 
        /*
@@ -836,7 +869,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;
@@ -882,7 +915,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 */
 
@@ -897,11 +930,11 @@ 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;
                        puts ("DHCP client bound to address ");