Zephyr Project API 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
sntp.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Linaro Limited
3 * Copyright (c) 2019 Intel Corporation
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
12
13#ifndef ZEPHYR_INCLUDE_NET_SNTP_H_
14#define ZEPHYR_INCLUDE_NET_SNTP_H_
15
16#include <zephyr/net/socket.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
31
33struct sntp_time {
42#if defined(CONFIG_SNTP_UNCERTAINTY)
44 uint64_t uptime_us;
46 uint32_t uncertainty_us;
47#endif
48};
49
51struct sntp_ctx {
52
54 struct {
55 struct zsock_pollfd fds[1];
56 int nfds;
57 int fd;
58 } sock;
60
66};
67
77int sntp_init(struct sntp_ctx *ctx, struct net_sockaddr *addr,
78 net_socklen_t addr_len);
79
90int sntp_query(struct sntp_ctx *ctx, uint32_t timeout, struct sntp_time *ts);
91
102int sntp_recv_response(struct sntp_ctx *ctx, uint32_t timeout, struct sntp_time *ts);
103
109void sntp_close(struct sntp_ctx *ctx);
110
123int sntp_init_async(struct sntp_ctx *ctx, struct net_sockaddr *addr, net_socklen_t addr_len,
124 const struct net_socket_service_desc *service);
125
133int sntp_send_async(struct sntp_ctx *ctx);
134
148
154void sntp_close_async(const struct net_socket_service_desc *service);
155
169int sntp_simple(const char *server, uint32_t timeout,
170 struct sntp_time *ts);
171
187int sntp_simple_addr(struct net_sockaddr *addr, net_socklen_t addr_len, uint32_t timeout,
188 struct sntp_time *ts);
189
190#ifdef __cplusplus
191}
192#endif
193
197
198#endif
uint32_t net_socklen_t
Length of a socket address.
Definition net_ip.h:171
void sntp_close(struct sntp_ctx *ctx)
Release SNTP context.
int sntp_simple(const char *server, uint32_t timeout, struct sntp_time *ts)
Convenience function to query SNTP in one-shot fashion.
int sntp_query(struct sntp_ctx *ctx, uint32_t timeout, struct sntp_time *ts)
Perform SNTP query.
int sntp_init(struct sntp_ctx *ctx, struct net_sockaddr *addr, net_socklen_t addr_len)
Initialize SNTP context.
int sntp_recv_response(struct sntp_ctx *ctx, uint32_t timeout, struct sntp_time *ts)
Attempt to receive an SNTP response after issuing a query.
int sntp_init_async(struct sntp_ctx *ctx, struct net_sockaddr *addr, net_socklen_t addr_len, const struct net_socket_service_desc *service)
Initialise SNTP context for async operation.
int sntp_send_async(struct sntp_ctx *ctx)
Send the SNTP query.
int sntp_read_async(struct net_socket_service_event *event, struct sntp_time *ts)
Read the result of the SNTP query.
int sntp_simple_addr(struct net_sockaddr *addr, net_socklen_t addr_len, uint32_t timeout, struct sntp_time *ts)
Convenience function to query SNTP in one-shot fashion using a pre-initialized address struct.
void sntp_close_async(const struct net_socket_service_desc *service)
Release SNTP context.
BSD Sockets compatible API definitions.
BSD Socket service API.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
Generic sockaddr struct.
Definition net_ip.h:448
Main structure holding socket service configuration information.
Definition socket_service.h:70
This struct contains information which socket triggered calls to the callback function.
Definition socket_service.h:49
SNTP context.
Definition sntp.h:51
struct sntp_time expected_orig_ts
Timestamp when the request was sent from client to server.
Definition sntp.h:65
Time as returned by SNTP API, fractional seconds since 1 Jan 1970.
Definition sntp.h:33
uint32_t rsp_delay_us
Estimated delay between server sending response and client receiving in microseconds.
Definition sntp.h:41
uint64_t seconds
Second value.
Definition sntp.h:35
uint32_t fraction
Fractional seconds value.
Definition sntp.h:37
Definition of the monitored socket/file descriptor.
Definition socket_poll.h:31