]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - net/net.c
Merge branch 'master' of git://git.denx.de/u-boot-mmc
[karo-tx-uboot.git] / net / net.c
index a22b350efea9b6a19bcd2e7990866e6b72ab5a35..7a6058339cccaf8a21879a685c837a0a10fc5695 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -321,7 +321,8 @@ NetInitLoop(proto_t protocol)
 
        /* update only when the environment has changed */
        if (env_changed_id != env_id) {
-               NetCopyIP(&NetOurIP, &bd->bi_ip_addr);
+               NetOurIP = getenv_IPaddr("ipaddr");
+               NetCopyIP(&bd->bi_ip_addr, &NetOurIP);
                NetOurGatewayIP = getenv_IPaddr("gatewayip");
                NetOurSubnetMask = getenv_IPaddr("netmask");
                NetServerIP = getenv_IPaddr("serverip");
@@ -383,7 +384,7 @@ NetLoop(proto_t protocol)
 #endif
        if (eth_init(bd) < 0) {
                eth_halt();
-               return(-1);
+               return -1;
        }
 
 restart:
@@ -406,7 +407,7 @@ restart:
        case 1:
                /* network not configured */
                eth_halt();
-               return (-1);
+               return -1;
 
 #ifdef CONFIG_NET_MULTI
        case 2:
@@ -423,7 +424,11 @@ restart:
                        /* always use ARP to get server ethernet address */
                        TftpStart();
                        break;
-
+#ifdef CONFIG_CMD_TFTPSRV
+               case TFTPSRV:
+                       TftpStartServer();
+                       break;
+#endif
 #if defined(CONFIG_CMD_DHCP)
                case DHCP:
                        BootpTry = 0;
@@ -521,7 +526,7 @@ restart:
                if (ctrlc()) {
                        eth_halt();
                        puts("\nAbort\n");
-                       return (-1);
+                       return -1;
                }
 
                ArpTimeoutCheck();
@@ -578,7 +583,7 @@ restart:
                        return NetBootFileXferSize;
 
                case NETLOOP_FAIL:
-                       return (-1);
+                       return -1;
                }
        }
 }
@@ -654,14 +659,14 @@ void NetStartAgain(void)
  */
 
 void
-NetSetHandler(rxhand_f * f)
+NetSetHandler(rxhand_f *f)
 {
        packetHandler = f;
 }
 
 
 void
-NetSetTimeout(ulong iv, thand_f * f)
+NetSetTimeout(ulong iv, thand_f *f)
 {
        if (iv == 0) {
                timeHandler = (thand_f *)0;
@@ -674,7 +679,7 @@ NetSetTimeout(ulong iv, thand_f * f)
 
 
 void
-NetSendPacket(volatile uchar * pkt, int len)
+NetSendPacket(volatile uchar *pkt, int len)
 {
        (void) eth_send(pkt, len);
 }
@@ -769,9 +774,9 @@ int PingSend(void)
        ip->ip_p     = 0x01;            /* ICMP */
        ip->ip_sum   = 0;
        /* already in network byte order */
-       NetCopyIP((void*)&ip->ip_src, &NetOurIP);
+       NetCopyIP((void *)&ip->ip_src, &NetOurIP);
        /* - "" - */
-       NetCopyIP((void*)&ip->ip_dst, &NetPingIP);
+       NetCopyIP((void *)&ip->ip_dst, &NetPingIP);
        ip->ip_sum   = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2);
 
        s = &ip->udp_src;               /* XXX ICMP starts here */
@@ -1047,7 +1052,7 @@ CDPDummyHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
 }
 
 static void
-CDPHandler(const uchar * pkt, unsigned len)
+CDPHandler(const uchar *pkt, unsigned len)
 {
        const uchar *t;
        const ushort *ss;
@@ -1103,51 +1108,50 @@ CDPHandler(const uchar * pkt, unsigned len)
                tlen -= 4;
 
                switch (type) {
-                       case CDP_DEVICE_ID_TLV:
-                               break;
-                       case CDP_ADDRESS_TLV:
-                               break;
-                       case CDP_PORT_ID_TLV:
-                               break;
-                       case CDP_CAPABILITIES_TLV:
-                               break;
-                       case CDP_VERSION_TLV:
-                               break;
-                       case CDP_PLATFORM_TLV:
-                               break;
-                       case CDP_NATIVE_VLAN_TLV:
-                               nvlan = *ss;
-                               break;
-                       case CDP_APPLIANCE_VLAN_TLV:
-                               t = (const uchar *)ss;
-                               while (tlen > 0) {
-                                       if (tlen < 3)
-                                               goto pkt_short;
+               case CDP_DEVICE_ID_TLV:
+                       break;
+               case CDP_ADDRESS_TLV:
+                       break;
+               case CDP_PORT_ID_TLV:
+                       break;
+               case CDP_CAPABILITIES_TLV:
+                       break;
+               case CDP_VERSION_TLV:
+                       break;
+               case CDP_PLATFORM_TLV:
+                       break;
+               case CDP_NATIVE_VLAN_TLV:
+                       nvlan = *ss;
+                       break;
+               case CDP_APPLIANCE_VLAN_TLV:
+                       t = (const uchar *)ss;
+                       while (tlen > 0) {
+                               if (tlen < 3)
+                                       goto pkt_short;
 
-                                       applid = t[0];
-                                       ss = (const ushort *)(t + 1);
+                               applid = t[0];
+                               ss = (const ushort *)(t + 1);
 
 #ifdef CONFIG_CDP_APPLIANCE_VLAN_TYPE
-                                       if (applid ==
-                                           CONFIG_CDP_APPLIANCE_VLAN_TYPE)
-                                               vlan = *ss;
+                               if (applid == CONFIG_CDP_APPLIANCE_VLAN_TYPE)
+                                       vlan = *ss;
 #else
-                                       /* XXX will this work; dunno */
-                                       vlan = ntohs(*ss);
+                               /* XXX will this work; dunno */
+                               vlan = ntohs(*ss);
 #endif
-                                       t += 3; tlen -= 3;
-                               }
-                               break;
-                       case CDP_TRIGGER_TLV:
-                               break;
-                       case CDP_POWER_CONSUMPTION_TLV:
-                               break;
-                       case CDP_SYSNAME_TLV:
-                               break;
-                       case CDP_SYSOBJECT_TLV:
-                               break;
-                       case CDP_MANAGEMENT_ADDRESS_TLV:
-                               break;
+                               t += 3; tlen -= 3;
+                       }
+                       break;
+               case CDP_TRIGGER_TLV:
+                       break;
+               case CDP_POWER_CONSUMPTION_TLV:
+                       break;
+               case CDP_SYSNAME_TLV:
+                       break;
+               case CDP_SYSOBJECT_TLV:
+                       break;
+               case CDP_MANAGEMENT_ADDRESS_TLV:
+                       break;
                }
        }
 
@@ -1353,7 +1357,7 @@ static inline IP_t *NetDefragment(IP_t *ip, int *lenp)
 #endif
 
 void
-NetReceive(volatile uchar * inpkt, int len)
+NetReceive(volatile uchar *inpkt, int len)
 {
        Ethernet_t *et;
        IP_t    *ip;
@@ -1608,7 +1612,7 @@ NetReceive(volatile uchar * inpkt, int len)
 #ifdef CONFIG_MCAST_TFTP
                        if (Mcast_addr != tmp)
 #endif
-                       return;
+                               return;
                }
                /* Read source IP address for later use */
                src_ip = NetReadIP(&ip->ip_src);
@@ -1617,7 +1621,8 @@ NetReceive(volatile uchar * inpkt, int len)
                 * a fragment, and either the complete packet or NULL if
                 * it is a fragment (if !CONFIG_IP_DEFRAG, it returns NULL)
                 */
-               if (!(ip = NetDefragment(ip, &len)))
+               ip = NetDefragment(ip, &len);
+               if (!ip)
                        return;
                /*
                 * watch for ICMP host redirects
@@ -1664,8 +1669,8 @@ NetReceive(volatile uchar * inpkt, int len)
 
                                ip->ip_sum = 0;
                                ip->ip_off = 0;
-                               NetCopyIP((void*)&ip->ip_dst, &ip->ip_src);
-                               NetCopyIP((void*)&ip->ip_src, &NetOurIP);
+                               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);
 
@@ -1756,7 +1761,7 @@ static int net_check_prereq(proto_t protocol)
        case PING:
                if (NetPingIP == 0) {
                        puts("*** ERROR: ping address not given\n");
-                       return (1);
+                       return 1;
                }
                goto common;
 #endif
@@ -1764,7 +1769,7 @@ static int net_check_prereq(proto_t protocol)
        case SNTP:
                if (NetNtpServerIP == 0) {
                        puts("*** ERROR: NTP server address not given\n");
-                       return (1);
+                       return 1;
                }
                goto common;
 #endif
@@ -1782,7 +1787,7 @@ static int net_check_prereq(proto_t protocol)
        case TFTP:
                if (NetServerIP == 0) {
                        puts("*** ERROR: `serverip' not set\n");
-                       return (1);
+                       return 1;
                }
 #if    defined(CONFIG_CMD_PING) || defined(CONFIG_CMD_SNTP) || \
        defined(CONFIG_CMD_DNS)
@@ -1791,9 +1796,10 @@ common:
                /* Fall through */
 
        case NETCONS:
+       case TFTPSRV:
                if (NetOurIP == 0) {
                        puts("*** ERROR: `ipaddr' not set\n");
-                       return (1);
+                       return 1;
                }
                /* Fall through */
 
@@ -1811,7 +1817,7 @@ common:
                        switch (num) {
                        case -1:
                                puts("*** ERROR: No ethernet found.\n");
-                               return (1);
+                               return 1;
                        case 0:
                                puts("*** ERROR: `ethaddr' not set\n");
                                break;
@@ -1822,29 +1828,29 @@ common:
                        }
 
                        NetStartAgain();
-                       return (2);
+                       return 2;
 #else
                        puts("*** ERROR: `ethaddr' not set\n");
-                       return (1);
+                       return 1;
 #endif
                }
                /* Fall through */
        default:
-               return (0);
+               return 0;
        }
-       return (0);             /* OK */
+       return 0;               /* OK */
 }
 /**********************************************************************/
 
 int
-NetCksumOk(uchar * ptr, int len)
+NetCksumOk(uchar *ptr, int len)
 {
        return !((NetCksum(ptr, len) + 1) & 0xfffe);
 }
 
 
 unsigned
-NetCksum(uchar * ptr, int len)
+NetCksum(uchar *ptr, int len)
 {
        ulong   xsum;
        ushort *p = (ushort *)ptr;
@@ -1854,7 +1860,7 @@ NetCksum(uchar * ptr, int len)
                xsum += *p++;
        xsum = (xsum & 0xffff) + (xsum >> 16);
        xsum = (xsum & 0xffff) + (xsum >> 16);
-       return (xsum & 0xffff);
+       return xsum & 0xffff;
 }
 
 int
@@ -1871,7 +1877,7 @@ NetEthHdrSize(void)
 }
 
 int
-NetSetEther(volatile uchar * xet, uchar * addr, uint prot)
+NetSetEther(volatile uchar *xet, uchar * addr, uint prot)
 {
        Ethernet_t *et = (Ethernet_t *)xet;
        ushort myvlanid;
@@ -1883,7 +1889,7 @@ NetSetEther(volatile uchar * xet, uchar * addr, uint prot)
        memcpy(et->et_dest, addr, 6);
        memcpy(et->et_src, NetOurEther, 6);
        if ((myvlanid & VLAN_IDMASK) == VLAN_NONE) {
-       et->et_protlen = htons(prot);
+               et->et_protlen = htons(prot);
                return ETHER_HDR_SIZE;
        } else {
                VLAN_Ethernet_t *vet = (VLAN_Ethernet_t *)xet;
@@ -1896,7 +1902,7 @@ NetSetEther(volatile uchar * xet, uchar * addr, uint prot)
 }
 
 void
-NetSetIP(volatile uchar * xip, IPaddr_t dest, int dport, int sport, int len)
+NetSetIP(volatile uchar *xip, IPaddr_t dest, int dport, int sport, int len)
 {
        IP_t *ip = (IP_t *)xip;
 
@@ -1922,9 +1928,9 @@ NetSetIP(volatile uchar * xip, IPaddr_t dest, int dport, int sport, int len)
        ip->ip_p     = 17;              /* UDP */
        ip->ip_sum   = 0;
        /* already in network byte order */
-       NetCopyIP((void*)&ip->ip_src, &NetOurIP);
+       NetCopyIP((void *)&ip->ip_src, &NetOurIP);
        /* - "" - */
-       NetCopyIP((void*)&ip->ip_dst, &dest);
+       NetCopyIP((void *)&ip->ip_dst, &dest);
        ip->udp_src  = htons(sport);
        ip->udp_dst  = htons(dport);
        ip->udp_len  = htons(8 + len);
@@ -1998,5 +2004,5 @@ ushort string_to_VLAN(const char *s)
 
 ushort getenv_VLAN(char *var)
 {
-       return (string_to_VLAN(getenv(var)));
+       return string_to_VLAN(getenv(var));
 }