]> git.sur5r.net Git - u-boot/blobdiff - net/net.c
* Patch by Stefan Roese, 5 Jul 2005:
[u-boot] / net / net.c
index 6e0288dc0676cc7f2cd427d26b6add770eb58d0c..5b0649568945d4d09f709435891959a124f45174 100644 (file)
--- a/net/net.c
+++ b/net/net.c
  *                       derived from our own IP address)
  *     We want:        - load the boot file
  *     Next step:      none
+ *
+ * SNTP:
+ *
+ *     Prerequisites:  - own ethernet address
+ *                     - own IP address
+ *     We want:        - network time
+ *     Next step:      none
  */
 
 
@@ -79,6 +86,9 @@
 #include <status_led.h>
 #include <miiphy.h>
 #endif
+#if (CONFIG_COMMANDS & CFG_CMD_SNTP)
+#include "sntp.h"
+#endif
 
 #if (CONFIG_COMMANDS & CFG_CMD_NET)
 
@@ -148,6 +158,16 @@ static void PingStart(void);
 static void CDPStart(void);
 #endif
 
+#if (CONFIG_COMMANDS & CFG_CMD_SNTP)
+IPaddr_t       NetNtpServerIP;         /* NTP server IP address                */
+int            NetTimeOffset=0;        /* offset time from UTC                 */
+#endif
+
+#ifdef CONFIG_NETCONSOLE
+void NcStart(void);
+int nc_input_packet(uchar *pkt, unsigned dest, unsigned src, unsigned len);
+#endif
+
 volatile uchar PktBuf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];
 
 volatile uchar *NetRxPackets[PKTBUFSRX]; /* Receive packets                    */
@@ -283,8 +303,10 @@ NetLoop(proto_t protocol)
 #ifdef CONFIG_NET_MULTI
        eth_set_current();
 #endif
-       if (eth_init(bd) < 0)
+       if (eth_init(bd) < 0) {
+               eth_halt();
                return(-1);
+       }
 
 restart:
 #ifdef CONFIG_NET_MULTI
@@ -308,6 +330,10 @@ restart:
 #if (CONFIG_COMMANDS & CFG_CMD_PING)
        case PING:
 #endif
+#if (CONFIG_COMMANDS & CFG_CMD_SNTP)
+       case SNTP:
+#endif
+       case NETCONS:
        case TFTP:
                NetCopyIP(&NetOurIP, &bd->bi_ip_addr);
                NetOurGatewayIP = getenv_IPaddr ("gatewayip");
@@ -319,6 +345,7 @@ restart:
 #if (CONFIG_COMMANDS & CFG_CMD_NFS)
                case NFS:
 #endif
+               case NETCONS:
                case TFTP:
                        NetServerIP = getenv_IPaddr ("serverip");
                        break;
@@ -326,6 +353,11 @@ restart:
                case PING:
                        /* nothing */
                        break;
+#endif
+#if (CONFIG_COMMANDS & CFG_CMD_SNTP)
+               case SNTP:
+                       /* nothing */
+                       break;
 #endif
                default:
                        break;
@@ -353,6 +385,7 @@ restart:
        switch (net_check_prereq (protocol)) {
        case 1:
                /* network not configured */
+               eth_halt();
                return (-1);
 
 #ifdef CONFIG_NET_MULTI
@@ -374,6 +407,7 @@ restart:
 #if (CONFIG_COMMANDS & CFG_CMD_DHCP)
                case DHCP:
                        /* Start with a clean slate... */
+                       BootpTry = 0;
                        NetOurIP = 0;
                        NetServerIP = getenv_IPaddr ("serverip");
                        DhcpRequest();          /* Basically same as BOOTP */
@@ -403,6 +437,16 @@ restart:
                case CDP:
                        CDPStart();
                        break;
+#endif
+#ifdef CONFIG_NETCONSOLE
+               case NETCONS:
+                       NcStart();
+                       break;
+#endif
+#if (CONFIG_COMMANDS & CFG_CMD_SNTP)
+               case SNTP:
+                       SntpStart();
+                       break;
 #endif
                default:
                        break;
@@ -427,7 +471,7 @@ restart:
 
        /*
         *      Main packet reception loop.  Loop receiving packets until
-        *      someone sets `NetQuit'.
+        *      someone sets `NetState' to a state that terminates.
         */
        for (;;) {
                WATCHDOG_RESET();
@@ -462,7 +506,9 @@ restart:
                        thand_f *x;
 
 #if defined(CONFIG_MII) || (CONFIG_COMMANDS & CFG_CMD_MII)
-#if defined(CFG_FAULT_ECHO_LINK_DOWN) && defined(CONFIG_STATUS_LED) && defined(STATUS_LED_RED)
+#  if defined(CFG_FAULT_ECHO_LINK_DOWN) && \
+      defined(CONFIG_STATUS_LED) &&       \
+      defined(STATUS_LED_RED)
                        /*
                         * Echo the inverted link state to the fault LED.
                         */
@@ -471,7 +517,7 @@ restart:
                        } else {
                                status_led_set (STATUS_LED_RED, STATUS_LED_ON);
                        }
-#endif /* CFG_FAULT_ECHO_LINK_DOWN, ... */
+#  endif /* CFG_FAULT_ECHO_LINK_DOWN, ... */
 #endif /* CONFIG_MII, ... */
                        x = timeHandler;
                        timeHandler = (thand_f *)0;
@@ -573,7 +619,7 @@ NetSetHandler(rxhand_f * f)
 
 
 void
-NetSetTimeout(int iv, thand_f * f)
+NetSetTimeout(ulong iv, thand_f * f)
 {
        if (iv == 0) {
                timeHandler = (thand_f *)0;
@@ -1259,6 +1305,9 @@ NetReceive(volatile uchar * inpkt, int len)
                                /* save address for later use */
                                memcpy(NetArpWaitPacketMAC, &arp->ar_data[0], 6);
 
+#ifdef CONFIG_NETCONSOLE
+                               (*packetHandler)(0,0,0,0);
+#endif
                                /* modify header, and transmit it */
                                memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, NetArpWaitPacketMAC, 6);
                                (void) eth_send(NetArpWaitTxPacket, NetArpWaitTxPacketSize);
@@ -1276,6 +1325,7 @@ NetReceive(volatile uchar * inpkt, int len)
 #endif
                        return;
                }
+               break;
 
        case PROT_RARP:
 #ifdef ET_DEBUG
@@ -1355,11 +1405,11 @@ NetReceive(volatile uchar * inpkt, int len)
 
                        switch (icmph->type) {
                        case ICMP_REDIRECT:
-                       if (icmph->code != ICMP_REDIR_HOST)
-                               return;
-                       puts (" ICMP Host Redirect to ");
-                       print_IPaddr(icmph->un.gateway);
-                       putc(' ');
+                               if (icmph->code != ICMP_REDIR_HOST)
+                                       return;
+                               puts (" ICMP Host Redirect to ");
+                               print_IPaddr(icmph->un.gateway);
+                               putc(' ');
                                break;
 #if (CONFIG_COMMANDS & CFG_CMD_PING)
                        case ICMP_ECHO_REPLY:
@@ -1377,6 +1427,12 @@ NetReceive(volatile uchar * inpkt, int len)
                        return;
                }
 
+#ifdef CONFIG_NETCONSOLE
+               nc_input_packet((uchar *)ip +IP_HDR_SIZE,
+                                               ntohs(ip->udp_dst),
+                                               ntohs(ip->udp_src),
+                                               ntohs(ip->udp_len) - 8);
+#endif
                /*
                 *      IP header OK.  Pass the packet to the current handler.
                 */
@@ -1403,15 +1459,24 @@ static int net_check_prereq (proto_t protocol)
                }
                goto common;
 #endif
+#if (CONFIG_COMMANDS & CFG_CMD_SNTP)
+       case SNTP:
+               if (NetNtpServerIP == 0) {
+                       puts ("*** ERROR: NTP server address not given\n");
+                       return (1);
+               }
+               goto common;
+#endif
 #if (CONFIG_COMMANDS & CFG_CMD_NFS)
        case NFS:
 #endif
+       case NETCONS:
        case TFTP:
                if (NetServerIP == 0) {
                        puts ("*** ERROR: `serverip' not set\n");
                        return (1);
                }
-#if (CONFIG_COMMANDS & CFG_CMD_PING)
+#if (CONFIG_COMMANDS & (CFG_CMD_PING | CFG_CMD_SNTP))
              common:
 #endif