4 * Masami Komiya <mkomiya@sonare.it> 2005
15 #define SNTP_TIMEOUT 10000UL
17 static int SntpOurPort;
22 struct sntp_pkt_t pkt;
23 int pktlen = SNTP_PACKET_LEN;
26 debug ("%s\n", __FUNCTION__);
28 memset (&pkt, 0, sizeof(pkt));
30 pkt.li = NTP_LI_NOLEAP;
32 pkt.mode = NTP_MODE_CLIENT;
34 memcpy ((char *)NetTxPacket + NetEthHdrSize() + IP_HDR_SIZE, (char *)&pkt, pktlen);
36 SntpOurPort = 10000 + (get_timer(0) % 4096);
37 sport = NTP_SERVICE_PORT;
39 NetSendUDPPacket (NetServerEther, NetNtpServerIP, sport, SntpOurPort, pktlen);
46 NetState = NETLOOP_FAIL;
51 SntpHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len)
53 struct sntp_pkt_t *rpktp = (struct sntp_pkt_t *)pkt;
57 debug ("%s\n", __FUNCTION__);
59 if (dest != SntpOurPort) return;
62 * As the RTC's used in U-Boot sepport second resolution only
63 * we simply ignore the sub-second field.
65 memcpy (&seconds, &rpktp->transmit_timestamp, sizeof(ulong));
67 to_tm(ntohl(seconds) - 2208988800UL + NetTimeOffset, &tm);
68 #if defined(CONFIG_CMD_DATE)
71 printf ("Date: %4d-%02d-%02d Time: %2d:%02d:%02d\n",
72 tm.tm_year, tm.tm_mon, tm.tm_mday,
73 tm.tm_hour, tm.tm_min, tm.tm_sec);
75 NetState = NETLOOP_SUCCESS;
81 debug ("%s\n", __FUNCTION__);
83 NetSetTimeout (SNTP_TIMEOUT, SntpTimeout);
84 NetSetHandler(SntpHandler);
85 memset (NetServerEther, 0, 6);