4 * Masami Komiya <mkomiya@sonare.it> 2005
15 #define SNTP_TIMEOUT 10000UL
17 static int sntp_our_port;
19 static void sntp_send(void)
21 struct sntp_pkt_t pkt;
22 int pktlen = SNTP_PACKET_LEN;
25 debug("%s\n", __func__);
27 memset(&pkt, 0, sizeof(pkt));
29 pkt.li = NTP_LI_NOLEAP;
31 pkt.mode = NTP_MODE_CLIENT;
33 memcpy((char *)net_tx_packet + net_eth_hdr_size() + IP_UDP_HDR_SIZE,
34 (char *)&pkt, pktlen);
36 sntp_our_port = 10000 + (get_timer(0) % 4096);
37 sport = NTP_SERVICE_PORT;
39 net_send_udp_packet(net_server_ethaddr, net_ntp_server, sport,
40 sntp_our_port, pktlen);
43 static void sntp_timeout_handler(void)
46 net_set_state(NETLOOP_FAIL);
50 static void sntp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
51 unsigned src, unsigned len)
53 struct sntp_pkt_t *rpktp = (struct sntp_pkt_t *)pkt;
57 debug("%s\n", __func__);
59 if (dest != sntp_our_port)
63 * As the RTC's used in U-Boot sepport second resolution only
64 * we simply ignore the sub-second field.
66 memcpy(&seconds, &rpktp->transmit_timestamp, sizeof(ulong));
68 to_tm(ntohl(seconds) - 2208988800UL + net_ntp_time_offset, &tm);
69 #if defined(CONFIG_CMD_DATE)
72 printf("Date: %4d-%02d-%02d Time: %2d:%02d:%02d\n",
73 tm.tm_year, tm.tm_mon, tm.tm_mday,
74 tm.tm_hour, tm.tm_min, tm.tm_sec);
76 net_set_state(NETLOOP_SUCCESS);
81 debug("%s\n", __func__);
83 net_set_timeout_handler(SNTP_TIMEOUT, sntp_timeout_handler);
84 net_set_udp_handler(sntp_handler);
85 memset(net_server_ethaddr, 0, sizeof(net_server_ethaddr));