]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - net/bootp.c
net: cosmetic: Rename OPT_SIZE to OPT_FIELD_SIZE
[karo-tx-uboot.git] / net / bootp.c
index d0a7da248e4e9c57251548bbafb82b5568384698..009369b3bd382c236387eb28bba94714b92954e5 100644 (file)
@@ -12,6 +12,7 @@
 #include <command.h>
 #include <net.h>
 #include "bootp.h"
+#include "net_rand.h"
 #include "tftp.h"
 #include "nfs.h"
 #ifdef CONFIG_STATUS_LED
@@ -37,9 +38,6 @@
 
 ulong          BootpID;
 int            BootpTry;
-#ifdef CONFIG_BOOTP_RANDOM_DELAY
-ulong          seed1, seed2;
-#endif
 
 #if defined(CONFIG_CMD_DHCP)
 dhcp_state_t dhcp_state = INIT;
@@ -73,7 +71,7 @@ static int BootpCheckPkt(uchar *pkt, unsigned dest, unsigned src, unsigned len)
 
        if (dest != PORT_BOOTPC || src != PORT_BOOTPS)
                retval = -1;
-       else if (len < sizeof(struct Bootp_t) - OPT_SIZE)
+       else if (len < sizeof(struct Bootp_t) - OPT_FIELD_SIZE)
                retval = -2;
        else if (bp->bp_op != OP_BOOTREQUEST &&
                        bp->bp_op != OP_BOOTREPLY &&
@@ -105,7 +103,7 @@ static void BootpCopyNetParams(struct Bootp_t *bp)
        NetCopyIP(&tmp_ip, &bp->bp_siaddr);
        if (tmp_ip != 0)
                NetCopyIP(&NetServerIP, &bp->bp_siaddr);
-       memcpy(NetServerEther, ((Ethernet_t *)NetRxPacket)->et_src, 6);
+       memcpy(NetServerEther, ((struct ethernet_hdr *)NetRxPacket)->et_src, 6);
 #endif
        if (strlen(bp->bp_file) > 0)
                copy_filename(BootFile, bp->bp_file, sizeof(BootFile));
@@ -370,8 +368,8 @@ static int DhcpExtended(u8 *e, int message_type, IPaddr_t ServerID,
 
        *e++ = 57;              /* Maximum DHCP Message Size */
        *e++ = 2;
-       *e++ = (576 - 312 + OPT_SIZE) >> 8;
-       *e++ = (576 - 312 + OPT_SIZE) & 0xff;
+       *e++ = (576 - 312 + OPT_FIELD_SIZE) >> 8;
+       *e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff;
 
        if (ServerID) {
                int tmp = ntohl(ServerID);
@@ -521,8 +519,8 @@ static int BootpExtended(u8 *e)
 
        *e++ = 57;              /* Maximum DHCP Message Size */
        *e++ = 2;
-       *e++ = (576 - 312 + OPT_SIZE) >> 16;
-       *e++ = (576 - 312 + OPT_SIZE) & 0xff;
+       *e++ = (576 - 312 + OPT_FIELD_SIZE) >> 16;
+       *e++ = (576 - 312 + OPT_FIELD_SIZE) & 0xff;
 #endif
 
 #if defined(CONFIG_BOOTP_SUBNETMASK)
@@ -584,6 +582,9 @@ BootpRequest(void)
        uchar *pkt, *iphdr;
        struct Bootp_t *bp;
        int ext_len, pktlen, iplen;
+#ifdef CONFIG_BOOTP_RANDOM_DELAY
+       ulong i, rand_ms;
+#endif
 
        bootstage_mark_name(BOOTSTAGE_ID_BOOTP_START, "bootp_start");
 #if defined(CONFIG_CMD_DHCP)
@@ -591,60 +592,16 @@ BootpRequest(void)
 #endif
 
 #ifdef CONFIG_BOOTP_RANDOM_DELAY               /* Random BOOTP delay */
-       unsigned char bi_enetaddr[6];
-       int   reg;
-       ulong tst1, tst2, sum, m_mask, m_value = 0;
-
-       if (BootpTry == 0) {
-               /* get our mac */
-               eth_getenv_enetaddr("ethaddr", bi_enetaddr);
-
-               debug("BootpRequest => Our Mac: ");
-               for (reg = 0; reg < 6; reg++)
-                       debug("%x%c", bi_enetaddr[reg], reg == 5 ? '\n' : ':');
-
-               /* Mac-Manipulation 2 get seed1 */
-               tst1 = 0;
-               tst2 = 0;
-               for (reg = 2; reg < 6; reg++) {
-                       tst1 = tst1 << 8;
-                       tst1 = tst1 | bi_enetaddr[reg];
-               }
-               for (reg = 0; reg < 2; reg++) {
-                       tst2 = tst2 | bi_enetaddr[reg];
-                       tst2 = tst2 << 8;
-               }
+       if (BootpTry == 0)
+               srand_mac();
 
-               seed1 = tst1^tst2;
-
-               /* Mirror seed1*/
-               m_mask = 0x1;
-               for (reg = 1; reg <= 32; reg++) {
-                       m_value |= (m_mask & seed1);
-                       seed1 = seed1 >> 1;
-                       m_value = m_value << 1;
-               }
-               seed1 = m_value;
-               seed2 = 0xB78D0945;
-       }
-
-       /* Random Number Generator */
-       for (reg = 0; reg <= 0; reg++) {
-               sum = seed1 + seed2;
-               if (sum < seed1 || sum < seed2)
-                       sum++;
-               seed2 = seed1;
-               seed1 = sum;
-
-               if (BootpTry <= 2) {    /* Start with max 1024 * 1ms */
-                       sum = sum >> (22-BootpTry);
-               } else {        /*After 3rd BOOTP request max 8192 * 1ms */
-                       sum = sum >> 19;
-               }
-       }
+       if (BootpTry <= 2)      /* Start with max 1024 * 1ms */
+               rand_ms = rand() >> (22 - BootpTry);
+       else            /* After 3rd BOOTP request max 8192 * 1ms */
+               rand_ms = rand() >> 19;
 
-       printf("Random delay: %ld ms...\n", sum);
-       for (reg = 0; reg < sum; reg++)
+       printf("Random delay: %ld ms...\n", rand_ms);
+       for (i = 0; i < rand_ms; i++)
                udelay(1000); /*Wait 1ms*/
 
 #endif /* CONFIG_BOOTP_RANDOM_DELAY */
@@ -665,7 +622,7 @@ BootpRequest(void)
        /* NetSetIP(pkt, 0xFFFFFFFFL, PORT_BOOTPS, PORT_BOOTPC,
                sizeof (struct Bootp_t)); */
        iphdr = pkt;    /* We need this later for NetSetIP() */
-       pkt += IP_HDR_SIZE;
+       pkt += IP_UDP_HDR_SIZE;
 
        bp = (struct Bootp_t *)pkt;
        bp->bp_op = OP_BOOTREQUEST;
@@ -850,7 +807,7 @@ static void DhcpSendRequestPkt(struct Bootp_t *bp_offer)
        pkt += NetSetEther(pkt, NetBcastAddr, PROT_IP);
 
        iphdr = pkt;    /* We'll need this later to set proper pkt size */
-       pkt += IP_HDR_SIZE;
+       pkt += IP_UDP_HDR_SIZE;
 
        bp = (struct Bootp_t *)pkt;
        bp->bp_op = OP_BOOTREQUEST;