4 * Masami Komiya <mkomiya@sonare.it> 2005
15 #if (defined(CONFIG_CMD_NET) \
16 && defined(CONFIG_CMD_SNTP)
18 #define SNTP_TIMEOUT 10
20 static int SntpOurPort;
25 struct sntp_pkt_t pkt;
26 int pktlen = SNTP_PACKET_LEN;
29 debug ("%s\n", __FUNCTION__);
31 memset (&pkt, 0, sizeof(pkt));
33 pkt.li = NTP_LI_NOLEAP;
35 pkt.mode = NTP_MODE_CLIENT;
37 memcpy ((char *)NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE, (char *)&pkt, pktlen);
39 SntpOurPort = 10000 + (get_timer(0) % 4096);
40 sport = NTP_SERVICE_PORT;
42 NetSendUDPPacket (NetServerEther, NetNtpServerIP, sport, SntpOurPort, pktlen);
49 NetState = NETLOOP_FAIL;
54 SntpHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len)
56 struct sntp_pkt_t *rpktp = (struct sntp_pkt_t *)pkt;
60 debug ("%s\n", __FUNCTION__);
62 if (dest != SntpOurPort) return;
65 * As the RTC's used in U-Boot sepport second resolution only
66 * we simply ignore the sub-second field.
68 memcpy (&seconds, &rpktp->transmit_timestamp, sizeof(ulong));
70 to_tm(ntohl(seconds) - 2208988800UL + NetTimeOffset, &tm);
71 #if defined(CONFIG_CMD_DATE)
74 printf ("Date: %4d-%02d-%02d Time: %2d:%02d:%02d\n",
75 tm.tm_year, tm.tm_mon, tm.tm_mday,
76 tm.tm_hour, tm.tm_min, tm.tm_sec);
78 NetState = NETLOOP_SUCCESS;
84 debug ("%s\n", __FUNCTION__);
86 NetSetTimeout (SNTP_TIMEOUT * CFG_HZ, SntpTimeout);
87 NetSetHandler(SntpHandler);
88 memset (NetServerEther, 0, 6);