summaryrefslogtreecommitdiff
path: root/net/net.c
diff options
context:
space:
mode:
authorWolfgang Denk <wd@denx.de>2009-07-23 19:20:26 +0200
committerWolfgang Denk <wd@denx.de>2009-07-23 19:20:26 +0200
commit4fb799aeafa71c4e6caacd3acdc4a4547cfbd5d4 (patch)
tree6c49be563c2bcf3d24af9279493a054b613999ff /net/net.c
parentb201171f2b4d509f3ad510b214bee70ff902e3d6 (diff)
parent97cfe86163505ea18e7ff7b71e78df5bb03dad57 (diff)
downloadu-boot-imx-4fb799aeafa71c4e6caacd3acdc4a4547cfbd5d4.zip
u-boot-imx-4fb799aeafa71c4e6caacd3acdc4a4547cfbd5d4.tar.gz
u-boot-imx-4fb799aeafa71c4e6caacd3acdc4a4547cfbd5d4.tar.bz2
Merge branch 'master' of git://git.denx.de/u-boot-net
Diffstat (limited to 'net/net.c')
-rw-r--r--net/net.c49
1 files changed, 45 insertions, 4 deletions
diff --git a/net/net.c b/net/net.c
index 5637cf5..641c37c 100644
--- a/net/net.c
+++ b/net/net.c
@@ -92,6 +92,9 @@
#if defined(CONFIG_CDP_VERSION)
#include <timestamp.h>
#endif
+#if defined(CONFIG_CMD_DNS)
+#include "dns.h"
+#endif
#if defined(CONFIG_CMD_NET)
@@ -139,8 +142,8 @@ uchar NetServerEther[6] = /* Boot server enet address */
{ 0, 0, 0, 0, 0, 0 };
IPaddr_t NetOurIP; /* Our IP addr (0 = unknown) */
IPaddr_t NetServerIP; /* Server IP addr (0 = unknown) */
-volatile uchar *NetRxPkt; /* Current receive packet */
-int NetRxPktLen; /* Current rx packet length */
+volatile uchar *NetRxPacket; /* Current receive packet */
+int NetRxPacketLen; /* Current rx packet length */
unsigned NetIPID; /* IP packet ID */
uchar NetBcastAddr[6] = /* Ethernet bcast address */
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
@@ -291,6 +294,9 @@ NetInitLoop(proto_t protocol)
NetServerIP = getenv_IPaddr ("serverip");
NetOurNativeVLAN = getenv_VLAN("nvlan");
NetOurVLAN = getenv_VLAN("vlan");
+#if defined(CONFIG_CMD_DNS)
+ NetOurDNSIP = getenv_IPaddr("dnsip");
+#endif
env_changed_id = env_id;
}
@@ -388,17 +394,20 @@ restart:
#if defined(CONFIG_CMD_DHCP)
case DHCP:
BootpTry = 0;
+ NetOurIP = 0;
DhcpRequest(); /* Basically same as BOOTP */
break;
#endif
case BOOTP:
BootpTry = 0;
+ NetOurIP = 0;
BootpRequest ();
break;
case RARP:
RarpTry = 0;
+ NetOurIP = 0;
RarpRequest ();
break;
#if defined(CONFIG_CMD_PING)
@@ -426,6 +435,11 @@ restart:
SntpStart();
break;
#endif
+#if defined(CONFIG_CMD_DNS)
+ case DNS:
+ DnsStart();
+ break;
+#endif
default:
break;
}
@@ -1122,8 +1136,8 @@ NetReceive(volatile uchar * inpkt, int len)
printf("packet received\n");
#endif
- NetRxPkt = inpkt;
- NetRxPktLen = len;
+ NetRxPacket = inpkt;
+ NetRxPacketLen = len;
et = (Ethernet_t *)inpkt;
/* too small packet? */
@@ -1273,6 +1287,15 @@ NetReceive(volatile uchar * inpkt, int len)
/* are we waiting for a reply */
if (!NetArpWaitPacketIP || !NetArpWaitPacketMAC)
break;
+
+#ifdef CONFIG_KEEP_SERVERADDR
+ if (NetServerIP == NetArpWaitPacketIP) {
+ char buf[20];
+ sprintf(buf, "%pM", arp->ar_data);
+ setenv("serveraddr", buf);
+ }
+#endif
+
#ifdef ET_DEBUG
printf("Got ARP REPLY, set server/gtwy eth addr (%pM)\n",
arp->ar_data);
@@ -1518,6 +1541,14 @@ static int net_check_prereq (proto_t protocol)
}
goto common;
#endif
+#if defined(CONFIG_CMD_DNS)
+ case DNS:
+ if (NetOurDNSIP == 0) {
+ puts("*** ERROR: DNS server address not given\n");
+ return 1;
+ }
+ goto common;
+#endif
#if defined(CONFIG_CMD_NFS)
case NFS:
#endif
@@ -1681,6 +1712,16 @@ void copy_filename (char *dst, char *src, int size)
#endif
+#if defined(CONFIG_CMD_NFS) || defined(CONFIG_CMD_SNTP) || defined(CONFIG_CMD_DNS)
+/*
+ * make port a little random, but use something trivial to compute
+ */
+unsigned int random_port(void)
+{
+ return 1024 + (get_timer(0) % 0x8000);;
+}
+#endif
+
void ip_to_string (IPaddr_t x, char *s)
{
x = ntohl (x);