sntp: use udp framework

This commits update the support of sntp to use
the framework udp. This change allows to remove
all the reference to sntp in the main network
file net/net.c.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Philippe Reynes
2020-09-18 14:13:02 +02:00
committed by Tom Rini
parent 6b981a224e
commit 912ece4c3d
5 changed files with 40 additions and 34 deletions

View File

@@ -12,12 +12,17 @@
#include <net.h>
#include <rtc.h>
#include "sntp.h"
#include <net/sntp.h>
#define SNTP_TIMEOUT 10000UL
static int sntp_our_port;
/* NTP server IP address */
struct in_addr net_ntp_server;
/* offset time from UTC */
int net_ntp_time_offset;
static void sntp_send(void)
{
struct sntp_pkt_t pkt;
@@ -93,7 +98,25 @@ static void sntp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
net_set_state(NETLOOP_SUCCESS);
}
void sntp_start(void)
/*
* SNTP:
*
* Prerequisites: - own ethernet address
* - own IP address
* We want: - network time
* Next step: none
*/
int sntp_prereq(void *data)
{
if (net_ntp_server.s_addr == 0) {
puts("*** ERROR: NTP server address not given\n");
return 1;
}
return 0;
}
int sntp_start(void *data)
{
debug("%s\n", __func__);
@@ -102,4 +125,6 @@ void sntp_start(void)
memset(net_server_ethaddr, 0, sizeof(net_server_ethaddr));
sntp_send();
return 0;
}