summaryrefslogtreecommitdiffstats
path: root/net/sntp.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2007-07-05 18:01:23 +0200
committerSascha Hauer <sha@octopus.labnet.pengutronix.de>2007-07-05 18:01:23 +0200
commit11a0b5a0dd5f092777de41db00f3ffa8a95d698c (patch)
tree519db270d85dbbab4dab0928ed43a0c156436093 /net/sntp.c
parent3533c30ef469bd5e6ff1f715fcaae4a64066e612 (diff)
downloadbarebox-11a0b5a0dd5f092777de41db00f3ffa8a95d698c.tar.gz
barebox-11a0b5a0dd5f092777de41db00f3ffa8a95d698c.tar.xz
svn_rev_108
removed ifdefs, moved ping to own file, fix timeout handler
Diffstat (limited to 'net/sntp.c')
-rw-r--r--net/sntp.c44
1 files changed, 39 insertions, 5 deletions
diff --git a/net/sntp.c b/net/sntp.c
index db8c2c2799..df22caef24 100644
--- a/net/sntp.c
+++ b/net/sntp.c
@@ -7,13 +7,12 @@
#include <common.h>
#include <command.h>
+#include <clock.h>
#include <net.h>
#include <rtc.h>
#include "sntp.h"
-#if ((CONFIG_COMMANDS & CFG_CMD_NET) && (CONFIG_COMMANDS & CFG_CMD_SNTP))
-
#define SNTP_TIMEOUT 10
static int SntpOurPort;
@@ -35,7 +34,7 @@ SntpSend (void)
memcpy ((char *)NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE, (char *)&pkt, pktlen);
- SntpOurPort = 10000 + (get_timer(0) % 4096);
+ SntpOurPort = 10000 + ((uint32_t)get_time_ns() % 4096);
sport = NTP_SERVICE_PORT;
NetSendUDPPacket (NetServerEther, NetNtpServerIP, sport, SntpOurPort, pktlen);
@@ -82,11 +81,46 @@ SntpStart (void)
{
debug ("%s\n", __FUNCTION__);
- NetSetTimeout (SNTP_TIMEOUT * CFG_HZ, SntpTimeout);
+ NetSetTimeout (SNTP_TIMEOUT * SECOND, SntpTimeout);
NetSetHandler(SntpHandler);
memset (NetServerEther, 0, 6);
SntpSend ();
}
-#endif /* CONFIG_COMMANDS & CFG_CMD_SNTP */
+int do_sntp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+{
+ char *toff;
+
+ if (argc < 2) {
+ NetNtpServerIP = getenv_IPaddr ("ntpserverip");
+ if (NetNtpServerIP == 0) {
+ printf ("ntpserverip not set\n");
+ return (1);
+ }
+ } else {
+ NetNtpServerIP = string_to_ip(argv[1]);
+ if (NetNtpServerIP == 0) {
+ printf ("Bad NTP server IP address\n");
+ return (1);
+ }
+ }
+
+ toff = getenv ("timeoffset");
+ if (toff == NULL) NetTimeOffset = 0;
+ else NetTimeOffset = simple_strtol (toff, NULL, 10);
+
+ if (NetLoop(SNTP) < 0) {
+ printf("SNTP failed: host %s not responding\n", argv[1]);
+ return 1;
+ }
+
+ return 0;
+}
+
+U_BOOT_CMD(
+ sntp, 2, 1, do_sntp,
+ "sntp\t- synchronize RTC via network\n",
+ "[NTP server IP]\n"
+);
+