include/configs: Use new CONFIG_CMD_* in various [NO]* named board config files.
[platform/kernel/u-boot.git] / net / net.c
index d1a15e2..250abcd 100644 (file)
--- a/net/net.c
+++ b/net/net.c
 #include <status_led.h>
 #include <miiphy.h>
 #endif
-#if (CONFIG_COMMANDS & CFG_CMD_SNTP)
+#if (CONFIG_COMMANDS & CFG_CMD_SNTP) || defined(CONFIG_CMD_SNTP)
 #include "sntp.h"
 #endif
 
-#if (CONFIG_COMMANDS & CFG_CMD_NET)
+#if (CONFIG_COMMANDS & CFG_CMD_NET) || defined(CONFIG_CMD_NET)
+
+DECLARE_GLOBAL_DATA_PTR;
 
 #define ARP_TIMEOUT            5               /* Seconds before trying ARP again */
 #ifndef        CONFIG_NET_RETRY_COUNT
@@ -131,7 +133,7 @@ uchar               NetBcastAddr[6] =       /* Ethernet bcast address               */
                        { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 uchar          NetEtherNullAddr[6] =
                        { 0, 0, 0, 0, 0, 0 };
-#if (CONFIG_COMMANDS & CFG_CMD_CDP)
+#if (CONFIG_COMMANDS & CFG_CMD_CDP) || defined(CONFIG_CMD_CDP)
 uchar          NetCDPAddr[6] =         /* Ethernet bcast address               */
                        { 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc };
 #endif
@@ -148,17 +150,17 @@ ushort            NetOurNativeVLAN = 0xFFFF;      /* ditto                        */
 
 char           BootFile[128];          /* Boot File name                       */
 
-#if (CONFIG_COMMANDS & CFG_CMD_PING)
+#if (CONFIG_COMMANDS & CFG_CMD_PING) || defined(CONFIG_CMD_PING)
 IPaddr_t       NetPingIP;              /* the ip address to ping               */
 
 static void PingStart(void);
 #endif
 
-#if (CONFIG_COMMANDS & CFG_CMD_CDP)
+#if (CONFIG_COMMANDS & CFG_CMD_CDP) || defined(CONFIG_CMD_CDP)
 static void CDPStart(void);
 #endif
 
-#if (CONFIG_COMMANDS & CFG_CMD_SNTP)
+#if (CONFIG_COMMANDS & CFG_CMD_SNTP) || defined(CONFIG_CMD_SNTP)
 IPaddr_t       NetNtpServerIP;         /* NTP server IP address                */
 int            NetTimeOffset=0;        /* offset time from UTC                 */
 #endif
@@ -222,8 +224,10 @@ void ArpRequest (void)
            (NetOurIP & NetOurSubnetMask)) {
                if (NetOurGatewayIP == 0) {
                        puts ("## Warning: gatewayip needed but not set\n");
+                       NetArpWaitReplyIP = NetArpWaitPacketIP;
+               } else {
+                       NetArpWaitReplyIP = NetOurGatewayIP;
                }
-               NetArpWaitReplyIP = NetOurGatewayIP;
        } else {
                NetArpWaitReplyIP = NetArpWaitPacketIP;
        }
@@ -264,8 +268,6 @@ void ArpTimeoutCheck(void)
 int
 NetLoop(proto_t protocol)
 {
-       DECLARE_GLOBAL_DATA_PTR;
-
        bd_t *bd = gd->bd;
 
 #ifdef CONFIG_NET_MULTI
@@ -324,13 +326,13 @@ restart:
         */
 
        switch (protocol) {
-#if (CONFIG_COMMANDS & CFG_CMD_NFS)
+#if (CONFIG_COMMANDS & CFG_CMD_NFS) || defined(CONFIG_CMD_NFS)
        case NFS:
 #endif
-#if (CONFIG_COMMANDS & CFG_CMD_PING)
+#if (CONFIG_COMMANDS & CFG_CMD_PING) || defined(CONFIG_CMD_PING)
        case PING:
 #endif
-#if (CONFIG_COMMANDS & CFG_CMD_SNTP)
+#if (CONFIG_COMMANDS & CFG_CMD_SNTP) || defined(CONFIG_CMD_SNTP)
        case SNTP:
 #endif
        case NETCONS:
@@ -342,19 +344,19 @@ restart:
                NetOurNativeVLAN = getenv_VLAN("nvlan");
 
                switch (protocol) {
-#if (CONFIG_COMMANDS & CFG_CMD_NFS)
+#if (CONFIG_COMMANDS & CFG_CMD_NFS) || defined(CONFIG_CMD_NFS)
                case NFS:
 #endif
                case NETCONS:
                case TFTP:
                        NetServerIP = getenv_IPaddr ("serverip");
                        break;
-#if (CONFIG_COMMANDS & CFG_CMD_PING)
+#if (CONFIG_COMMANDS & CFG_CMD_PING) || defined(CONFIG_CMD_PING)
                case PING:
                        /* nothing */
                        break;
 #endif
-#if (CONFIG_COMMANDS & CFG_CMD_SNTP)
+#if (CONFIG_COMMANDS & CFG_CMD_SNTP) || defined(CONFIG_CMD_SNTP)
                case SNTP:
                        /* nothing */
                        break;
@@ -404,7 +406,7 @@ restart:
                        TftpStart();
                        break;
 
-#if (CONFIG_COMMANDS & CFG_CMD_DHCP)
+#if (CONFIG_COMMANDS & CFG_CMD_DHCP) || defined(CONFIG_CMD_DHCP)
                case DHCP:
                        /* Start with a clean slate... */
                        BootpTry = 0;
@@ -423,17 +425,17 @@ restart:
                        RarpTry = 0;
                        RarpRequest ();
                        break;
-#if (CONFIG_COMMANDS & CFG_CMD_PING)
+#if (CONFIG_COMMANDS & CFG_CMD_PING) || defined(CONFIG_CMD_PING)
                case PING:
                        PingStart();
                        break;
 #endif
-#if (CONFIG_COMMANDS & CFG_CMD_NFS)
+#if (CONFIG_COMMANDS & CFG_CMD_NFS) || defined(CONFIG_CMD_NFS)
                case NFS:
                        NfsStart();
                        break;
 #endif
-#if (CONFIG_COMMANDS & CFG_CMD_CDP)
+#if (CONFIG_COMMANDS & CFG_CMD_CDP) || defined(CONFIG_CMD_CDP)
                case CDP:
                        CDPStart();
                        break;
@@ -443,7 +445,7 @@ restart:
                        NcStart();
                        break;
 #endif
-#if (CONFIG_COMMANDS & CFG_CMD_SNTP)
+#if (CONFIG_COMMANDS & CFG_CMD_SNTP) || defined(CONFIG_CMD_SNTP)
                case SNTP:
                        SntpStart();
                        break;
@@ -456,12 +458,12 @@ restart:
                break;
        }
 
-#if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
+#if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII) || defined(CONFIG_CMD_MII)
 #if defined(CFG_FAULT_ECHO_LINK_DOWN) && defined(CONFIG_STATUS_LED) && defined(STATUS_LED_RED)
        /*
         * Echo the inverted link state to the fault LED.
         */
-       if(miiphy_link(CFG_FAULT_MII_ADDR)) {
+       if(miiphy_link(eth_get_dev()->name, CFG_FAULT_MII_ADDR)) {
                status_led_set (STATUS_LED_RED, STATUS_LED_OFF);
        } else {
                status_led_set (STATUS_LED_RED, STATUS_LED_ON);
@@ -505,14 +507,14 @@ restart:
                if (timeHandler && ((get_timer(0) - timeStart) > timeDelta)) {
                        thand_f *x;
 
-#if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
+#if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII) || defined(CONFIG_CMD_MII)
 #  if defined(CFG_FAULT_ECHO_LINK_DOWN) && \
       defined(CONFIG_STATUS_LED) &&       \
       defined(STATUS_LED_RED)
                        /*
                         * Echo the inverted link state to the fault LED.
                         */
-                       if(miiphy_link(CFG_FAULT_MII_ADDR)) {
+                       if(miiphy_link(eth_get_dev()->name, CFG_FAULT_MII_ADDR)) {
                                status_led_set (STATUS_LED_RED, STATUS_LED_OFF);
                        } else {
                                status_led_set (STATUS_LED_RED, STATUS_LED_ON);
@@ -570,9 +572,6 @@ startAgainHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
 
 void NetStartAgain (void)
 {
-#ifdef CONFIG_NET_MULTI
-       DECLARE_GLOBAL_DATA_PTR;
-#endif
        char *nretry;
        int noretry = 0, once = 0;
 
@@ -688,7 +687,7 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
        return 0;       /* transmitted */
 }
 
-#if (CONFIG_COMMANDS & CFG_CMD_PING)
+#if (CONFIG_COMMANDS & CFG_CMD_PING) || defined(CONFIG_CMD_PING)
 static ushort PingSeqNo;
 
 int PingSend(void)
@@ -778,7 +777,7 @@ static void PingStart(void)
 }
 #endif /* CFG_CMD_PING */
 
-#if (CONFIG_COMMANDS & CFG_CMD_CDP)
+#if (CONFIG_COMMANDS & CFG_CMD_CDP) || defined(CONFIG_CMD_CDP)
 
 #define CDP_DEVICE_ID_TLV              0x0001
 #define CDP_ADDRESS_TLV                        0x0002
@@ -829,7 +828,10 @@ static ushort CDP_compute_csum(const uchar *buff, ushort len)
                }
                if (len) {
                        leftover = (signed short)(*(const signed char *)buff);
-                       /* * XXX CISCO SUCKS big time! (and blows too) */
+                       /* CISCO SUCKS big time! (and blows too):
+                        * CDP uses the IP checksum algorithm with a twist;
+                        * for the last byte it *sign* extends and sums.
+                        */
                        result = (result & 0xffff0000) | ((result + leftover) & 0x0000ffff);
                }
                while (result >> 16)
@@ -1138,7 +1140,7 @@ NetReceive(volatile uchar * inpkt, int len)
        IPaddr_t tmp;
        int     x;
        uchar *pkt;
-#if (CONFIG_COMMANDS & CFG_CMD_CDP)
+#if (CONFIG_COMMANDS & CFG_CMD_CDP) || defined(CONFIG_CMD_CDP)
        int iscdp;
 #endif
        ushort cti = 0, vlanid = VLAN_NONE, myvlanid, mynvlanid;
@@ -1155,7 +1157,7 @@ NetReceive(volatile uchar * inpkt, int len)
        if (len < ETHER_HDR_SIZE)
                return;
 
-#if (CONFIG_COMMANDS & CFG_CMD_CDP)
+#if (CONFIG_COMMANDS & CFG_CMD_CDP) || defined(CONFIG_CMD_CDP)
        /* keep track if packet is CDP */
        iscdp = memcmp(et->et_dest, NetCDPAddr, 6) == 0;
 #endif
@@ -1198,7 +1200,7 @@ NetReceive(volatile uchar * inpkt, int len)
 
                /* if no VLAN active */
                if ((ntohs(NetOurVLAN) & VLAN_IDMASK) == VLAN_NONE
-#if (CONFIG_COMMANDS & CFG_CMD_CDP)
+#if (CONFIG_COMMANDS & CFG_CMD_CDP) || defined(CONFIG_CMD_CDP)
                                && iscdp == 0
 #endif
                                )
@@ -1216,7 +1218,7 @@ NetReceive(volatile uchar * inpkt, int len)
        printf("Receive from protocol 0x%x\n", x);
 #endif
 
-#if (CONFIG_COMMANDS & CFG_CMD_CDP)
+#if (CONFIG_COMMANDS & CFG_CMD_CDP) || defined(CONFIG_CMD_CDP)
        if (iscdp) {
                CDPHandler((uchar *)ip, len);
                return;
@@ -1414,7 +1416,7 @@ NetReceive(volatile uchar * inpkt, int len)
                                print_IPaddr(icmph->un.gateway);
                                putc(' ');
                                return;
-#if (CONFIG_COMMANDS & CFG_CMD_PING)
+#if (CONFIG_COMMANDS & CFG_CMD_PING) || defined(CONFIG_CMD_PING)
                        case ICMP_ECHO_REPLY:
                                /*
                                 *      IP header OK.  Pass the packet to the current handler.
@@ -1422,6 +1424,26 @@ NetReceive(volatile uchar * inpkt, int len)
                                /* XXX point to ip packet */
                                (*packetHandler)((uchar *)ip, 0, 0, 0);
                                return;
+                       case ICMP_ECHO_REQUEST:
+#ifdef ET_DEBUG
+                               printf ("Got ICMP ECHO REQUEST, return %d bytes \n",
+                                       ETHER_HDR_SIZE + len);
+#endif
+                               memcpy (&et->et_dest[0], &et->et_src[0], 6);
+                               memcpy (&et->et_src[ 0], NetOurEther, 6);
+
+                               ip->ip_sum = 0;
+                               ip->ip_off = 0;
+                               NetCopyIP((void*)&ip->ip_dst, &ip->ip_src);
+                               NetCopyIP((void*)&ip->ip_src, &NetOurIP);
+                               ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP >> 1);
+
+                               icmph->type = ICMP_ECHO_REPLY;
+                               icmph->checksum = 0;
+                               icmph->checksum = ~NetCksum((uchar *)icmph,
+                                               (len - IP_HDR_SIZE_NO_UDP) >> 1);
+                               (void) eth_send((uchar *)et, ETHER_HDR_SIZE + len);
+                               return;
 #endif
                        default:
                                return;
@@ -1494,7 +1516,7 @@ static int net_check_prereq (proto_t protocol)
 {
        switch (protocol) {
                /* Fall through */
-#if (CONFIG_COMMANDS & CFG_CMD_PING)
+#if (CONFIG_COMMANDS & CFG_CMD_PING) || defined(CONFIG_CMD_PING)
        case PING:
                if (NetPingIP == 0) {
                        puts ("*** ERROR: ping address not given\n");
@@ -1502,7 +1524,7 @@ static int net_check_prereq (proto_t protocol)
                }
                goto common;
 #endif
-#if (CONFIG_COMMANDS & CFG_CMD_SNTP)
+#if (CONFIG_COMMANDS & CFG_CMD_SNTP) || defined(CONFIG_CMD_SNTP)
        case SNTP:
                if (NetNtpServerIP == 0) {
                        puts ("*** ERROR: NTP server address not given\n");
@@ -1510,7 +1532,7 @@ static int net_check_prereq (proto_t protocol)
                }
                goto common;
 #endif
-#if (CONFIG_COMMANDS & CFG_CMD_NFS)
+#if (CONFIG_COMMANDS & CFG_CMD_NFS) || defined(CONFIG_CMD_NFS)
        case NFS:
 #endif
        case NETCONS:
@@ -1519,7 +1541,7 @@ static int net_check_prereq (proto_t protocol)
                        puts ("*** ERROR: `serverip' not set\n");
                        return (1);
                }
-#if (CONFIG_COMMANDS & (CFG_CMD_PING | CFG_CMD_SNTP))
+#if (CONFIG_COMMANDS & (CFG_CMD_PING | CFG_CMD_SNTP)) || defined(CONFIG_CMD_PING) || defined(CONFIG_CMD_SNTP)
     common:
 #endif