diff options
author | Philippe Reynes <philippe.reynes@softathome.com> | 2020-09-18 14:13:02 +0200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-09-30 16:55:03 -0400 |
commit | 912ece4c3dd486bcd62f0d0dfee760b9f01caac6 (patch) | |
tree | 4bc13b0c8d593e9012b58ce22c65d52e916e14bf /net | |
parent | 6b981a224e86b77a983438fd90cc90dd511fbb1a (diff) | |
download | u-boot-912ece4c3dd486bcd62f0d0dfee760b9f01caac6.tar.gz |
sntp: use udp frameworkWIP/30Sep2020-next2
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>
Diffstat (limited to 'net')
-rw-r--r-- | net/net.c | 31 | ||||
-rw-r--r-- | net/sntp.c | 29 | ||||
-rw-r--r-- | net/sntp.h | 57 |
3 files changed, 28 insertions, 89 deletions
@@ -72,12 +72,6 @@ * We want: - load the boot file * Next step: none * - * SNTP: - * - * Prerequisites: - own ethernet address - * - own IP address - * We want: - network time - * Next step: none * * WOL: * @@ -119,9 +113,6 @@ #include "nfs.h" #include "ping.h" #include "rarp.h" -#if defined(CONFIG_CMD_SNTP) -#include "sntp.h" -#endif #if defined(CONFIG_CMD_WOL) #include "wol.h" #endif @@ -185,13 +176,6 @@ u32 net_boot_file_size; /* Boot file size in blocks as reported by the DHCP server */ u32 net_boot_file_expected_size_in_blocks; -#if defined(CONFIG_CMD_SNTP) -/* NTP server IP address */ -struct in_addr net_ntp_server; -/* offset time from UTC */ -int net_ntp_time_offset; -#endif - static uchar net_pkt_buf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN]; /* Receive packets */ uchar *net_rx_packets[PKTBUFSRX]; @@ -521,11 +505,6 @@ restart: nc_start(); break; #endif -#if defined(CONFIG_CMD_SNTP) - case SNTP: - sntp_start(); - break; -#endif #if defined(CONFIG_CMD_DNS) case DNS: dns_start(); @@ -1352,14 +1331,6 @@ static int net_check_prereq(enum proto_t protocol) } goto common; #endif -#if defined(CONFIG_CMD_SNTP) - case SNTP: - if (net_ntp_server.s_addr == 0) { - puts("*** ERROR: NTP server address not given\n"); - return 1; - } - goto common; -#endif #if defined(CONFIG_CMD_DNS) case DNS: if (net_dns_server.s_addr == 0) { @@ -1385,7 +1356,7 @@ static int net_check_prereq(enum proto_t protocol) puts("*** ERROR: `serverip' not set\n"); return 1; } -#if defined(CONFIG_CMD_PING) || defined(CONFIG_CMD_SNTP) || \ +#if defined(CONFIG_CMD_PING) || \ defined(CONFIG_CMD_DNS) || defined(CONFIG_PROT_UDP) common: #endif diff --git a/net/sntp.c b/net/sntp.c index 39d7664a22..d5d5671933 100644 --- a/net/sntp.c +++ b/net/sntp.c @@ -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; } diff --git a/net/sntp.h b/net/sntp.h deleted file mode 100644 index d3cbfbc69a..0000000000 --- a/net/sntp.h +++ /dev/null @@ -1,57 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0+ */ -/* - * (C) Masami Komiya <mkomiya@sonare.it> 2005 - */ - -#ifndef __SNTP_H__ -#define __SNTP_H__ - -#define NTP_SERVICE_PORT 123 -#define SNTP_PACKET_LEN 48 - - -/* Leap Indicator */ -#define NTP_LI_NOLEAP 0x0 -#define NTP_LI_61SECS 0x1 -#define NTP_LI_59SECS 0x2 -#define NTP_LI_ALARM 0x3 - -/* Version */ - -#define NTP_VERSION 4 - -/* Mode */ -#define NTP_MODE_RESERVED 0 -#define NTP_MODE_SYMACTIVE 1 /* Symmetric Active */ -#define NTP_MODE_SYMPASSIVE 2 /* Symmetric Passive */ -#define NTP_MODE_CLIENT 3 -#define NTP_MODE_SERVER 4 -#define NTP_MODE_BROADCAST 5 -#define NTP_MODE_NTPCTRL 6 /* Reserved for NTP control message */ -#define NTP_MODE_PRIVATE 7 /* Reserved for private use */ - -struct sntp_pkt_t { -#if __LITTLE_ENDIAN - uchar mode:3; - uchar vn:3; - uchar li:2; -#else - uchar li:2; - uchar vn:3; - uchar mode:3; -#endif - uchar stratum; - uchar poll; - uchar precision; - uint root_delay; - uint root_dispersion; - uint reference_id; - unsigned long long reference_timestamp; - unsigned long long originate_timestamp; - unsigned long long receive_timestamp; - unsigned long long transmit_timestamp; -} __attribute__((packed)); - -void sntp_start(void); /* Begin SNTP */ - -#endif /* __SNTP_H__ */ |