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", __func__
);
28 memset(&pkt
, 0, sizeof(pkt
));
30 pkt
.li
= NTP_LI_NOLEAP
;
32 pkt
.mode
= NTP_MODE_CLIENT
;
34 memcpy((char *)NetTxPacket
+ NetEthHdrSize() + IP_UDP_HDR_SIZE
,
35 (char *)&pkt
, pktlen
);
37 SntpOurPort
= 10000 + (get_timer(0) % 4096);
38 sport
= NTP_SERVICE_PORT
;
40 NetSendUDPPacket(NetServerEther
, NetNtpServerIP
, sport
, SntpOurPort
,
48 net_set_state(NETLOOP_FAIL
);
53 SntpHandler(uchar
*pkt
, unsigned dest
, IPaddr_t sip
, unsigned src
,
56 struct sntp_pkt_t
*rpktp
= (struct sntp_pkt_t
*)pkt
;
60 debug("%s\n", __func__
);
62 if (dest
!= SntpOurPort
)
66 * As the RTC's used in U-Boot sepport second resolution only
67 * we simply ignore the sub-second field.
69 memcpy(&seconds
, &rpktp
->transmit_timestamp
, sizeof(ulong
));
71 to_tm(ntohl(seconds
) - 2208988800UL + NetTimeOffset
, &tm
);
72 #if defined(CONFIG_CMD_DATE)
75 printf("Date: %4d-%02d-%02d Time: %2d:%02d:%02d\n",
76 tm
.tm_year
, tm
.tm_mon
, tm
.tm_mday
,
77 tm
.tm_hour
, tm
.tm_min
, tm
.tm_sec
);
79 net_set_state(NETLOOP_SUCCESS
);
85 debug("%s\n", __func__
);
87 NetSetTimeout(SNTP_TIMEOUT
, SntpTimeout
);
88 net_set_udp_handler(SntpHandler
);
89 memset(NetServerEther
, 0, sizeof(NetServerEther
));