NTS client (Network Time Security) More...
#include "core/net.h"#include "ntp/ntp_common.h"#include "nts/nts_common.h"#include "core/crypto.h"#include "tls.h"Go to the source code of this file.
| Data Structures | |
| struct | _NtsClientContext | 
| NTS client context.  More... | |
| Macros | |
| #define | NTS_CLIENT_SUPPORT ENABLED | 
| #define | NTS_CLIENT_DEFAULT_TIMEOUT 30000 | 
| #define | NTS_CLIENT_INIT_NTP_RETRANSMIT_TIMEOUT 2000 | 
| #define | NTS_CLIENT_MAX_NTP_RETRANSMIT_TIMEOUT 15000 | 
| #define | NTS_CLIENT_BUFFER_SIZE 512 | 
| #define | NTS_CLIENT_TLS_TX_BUFFER_SIZE 2048 | 
| #define | NTS_CLIENT_TLS_RX_BUFFER_SIZE 4096 | 
| #define | NTS_CLIENT_MAX_COOKIE_SIZE 128 | 
| #define | NTS_CLIENT_MAX_NTP_SERVER_NAME_LEN 64 | 
| #define | NTS_CLIENT_UNIQUE_ID_SIZE 32 | 
| #define | NTS_CLIENT_NONCE_SIZE 16 | 
| #define | NTS_CLIENT_PRIVATE_CONTEXT | 
| #define | NtsClientContext struct _NtsClientContext | 
| Typedefs | |
| typedef error_t(* | NtsClientTlsInitCallback) (NtsClientContext *context, TlsContext *tlsContext) | 
| TLS initialization callback function.  More... | |
| typedef error_t(* | NtsClientRandCallback) (uint8_t *data, size_t length) | 
| Random data generation callback function.  More... | |
| Enumerations | |
| enum | NtsClientState { NTS_CLIENT_STATE_INIT = 0, NTS_CLIENT_STATE_NTS_KE_INIT = 1, NTS_CLIENT_STATE_NTS_KE_CONNECTING = 2, NTS_CLIENT_STATE_NTS_KE_SENDING = 3, NTS_CLIENT_STATE_NTS_KE_RECEIVING = 4, NTS_CLIENT_STATE_NTS_KE_DISCONNECTING = 5, NTS_CLIENT_STATE_NTP_RESOLVING = 6, NTS_CLIENT_STATE_NTP_INIT = 7, NTS_CLIENT_STATE_NTP_SENDING = 8, NTS_CLIENT_STATE_NTP_RECEIVING = 9, NTS_CLIENT_STATE_COMPLETE = 10 } | 
| NTS client states.  More... | |
| Functions | |
| error_t | ntsClientInit (NtsClientContext *context) | 
| Initialize NTS client context.  More... | |
| error_t | ntsClientRegisterTlsInitCallback (NtsClientContext *context, NtsClientTlsInitCallback callback) | 
| Register TLS initialization callback function.  More... | |
| error_t | ntsClientRegisterRandCallback (NtsClientContext *context, NtsClientRandCallback callback) | 
| Register random data generation callback function.  More... | |
| error_t | ntsClientSetTimeout (NtsClientContext *context, systime_t timeout) | 
| Set communication timeout.  More... | |
| error_t | ntsClientBindToInterface (NtsClientContext *context, NetInterface *interface) | 
| Bind the NTS client to a particular network interface.  More... | |
| error_t | ntsClientSetServerAddr (NtsClientContext *context, const IpAddr *serverIpAddr, uint16_t serverPort) | 
| Specify the IP address of the NTS server.  More... | |
| error_t | ntsClientGetTimestamp (NtsClientContext *context, NtpTimestamp *timestamp) | 
| Retrieve current time from NTS server.  More... | |
| uint32_t | ntsClientGetKissCode (NtsClientContext *context) | 
| Retrieve the kiss code from a Kiss-of-Death message.  More... | |
| void | ntsClientDeinit (NtsClientContext *context) | 
| Release NTS client context.  More... | |
Detailed Description
NTS client (Network Time Security)
License
SPDX-License-Identifier: GPL-2.0-or-later
Copyright (C) 2010-2025 Oryx Embedded SARL. All rights reserved.
This file is part of CycloneTCP Open.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Description
The Simple Network Time Protocol is used to synchronize computer clocks in the Internet. Refer to RFC 4330 for more details
- Version
- 2.5.4
Definition in file nts_client.h.
Macro Definition Documentation
◆ NTS_CLIENT_BUFFER_SIZE
| #define NTS_CLIENT_BUFFER_SIZE 512 | 
Definition at line 76 of file nts_client.h.
◆ NTS_CLIENT_DEFAULT_TIMEOUT
| #define NTS_CLIENT_DEFAULT_TIMEOUT 30000 | 
Definition at line 55 of file nts_client.h.
◆ NTS_CLIENT_INIT_NTP_RETRANSMIT_TIMEOUT
| #define NTS_CLIENT_INIT_NTP_RETRANSMIT_TIMEOUT 2000 | 
Definition at line 62 of file nts_client.h.
◆ NTS_CLIENT_MAX_COOKIE_SIZE
| #define NTS_CLIENT_MAX_COOKIE_SIZE 128 | 
Definition at line 97 of file nts_client.h.
◆ NTS_CLIENT_MAX_NTP_RETRANSMIT_TIMEOUT
| #define NTS_CLIENT_MAX_NTP_RETRANSMIT_TIMEOUT 15000 | 
Definition at line 69 of file nts_client.h.
◆ NTS_CLIENT_MAX_NTP_SERVER_NAME_LEN
| #define NTS_CLIENT_MAX_NTP_SERVER_NAME_LEN 64 | 
Definition at line 104 of file nts_client.h.
◆ NTS_CLIENT_NONCE_SIZE
| #define NTS_CLIENT_NONCE_SIZE 16 | 
Definition at line 118 of file nts_client.h.
◆ NTS_CLIENT_PRIVATE_CONTEXT
| #define NTS_CLIENT_PRIVATE_CONTEXT | 
Definition at line 125 of file nts_client.h.
◆ NTS_CLIENT_SUPPORT
| #define NTS_CLIENT_SUPPORT ENABLED | 
Definition at line 48 of file nts_client.h.
◆ NTS_CLIENT_TLS_RX_BUFFER_SIZE
| #define NTS_CLIENT_TLS_RX_BUFFER_SIZE 4096 | 
Definition at line 90 of file nts_client.h.
◆ NTS_CLIENT_TLS_TX_BUFFER_SIZE
| #define NTS_CLIENT_TLS_TX_BUFFER_SIZE 2048 | 
Definition at line 83 of file nts_client.h.
◆ NTS_CLIENT_UNIQUE_ID_SIZE
| #define NTS_CLIENT_UNIQUE_ID_SIZE 32 | 
Definition at line 111 of file nts_client.h.
◆ NtsClientContext
| #define NtsClientContext struct _NtsClientContext | 
Definition at line 130 of file nts_client.h.
Typedef Documentation
◆ NtsClientRandCallback
Random data generation callback function.
Definition at line 170 of file nts_client.h.
◆ NtsClientTlsInitCallback
| typedef error_t(* NtsClientTlsInitCallback) (NtsClientContext *context, TlsContext *tlsContext) | 
TLS initialization callback function.
Definition at line 162 of file nts_client.h.
Enumeration Type Documentation
◆ NtsClientState
| enum NtsClientState | 
NTS client states.
Definition at line 142 of file nts_client.h.
Function Documentation
◆ ntsClientBindToInterface()
| error_t ntsClientBindToInterface | ( | NtsClientContext * | context, | 
| NetInterface * | interface | ||
| ) | 
Bind the NTS client to a particular network interface.
- Parameters
- 
  [in] context Pointer to the NTS client context [in] interface Network interface to be used 
- Returns
- Error code
Definition at line 155 of file nts_client.c.
◆ ntsClientDeinit()
| void ntsClientDeinit | ( | NtsClientContext * | context | ) | 
Release NTS client context.
- Parameters
- 
  [in] context Pointer to the NTS client context 
Definition at line 452 of file nts_client.c.
◆ ntsClientGetKissCode()
| uint32_t ntsClientGetKissCode | ( | NtsClientContext * | context | ) | 
Retrieve the kiss code from a Kiss-of-Death message.
- Parameters
- 
  [in] context Pointer to the NTS client context 
- Returns
- Kiss code
Definition at line 426 of file nts_client.c.
◆ ntsClientGetTimestamp()
| error_t ntsClientGetTimestamp | ( | NtsClientContext * | context, | 
| NtpTimestamp * | timestamp | ||
| ) | 
Retrieve current time from NTS server.
- Parameters
- 
  [in] context Pointer to the NTS client context [out] timestamp Pointer to the NTP timestamp 
- Returns
- Error code
Definition at line 209 of file nts_client.c.
◆ ntsClientInit()
| error_t ntsClientInit | ( | NtsClientContext * | context | ) | 
Initialize NTS client context.
- Parameters
- 
  [in] context Pointer to the NTS client context 
- Returns
- Error code
Definition at line 56 of file nts_client.c.
◆ ntsClientRegisterRandCallback()
| error_t ntsClientRegisterRandCallback | ( | NtsClientContext * | context, | 
| NtsClientRandCallback | callback | ||
| ) | 
Register random data generation callback function.
- Parameters
- 
  [in] context Pointer to the NTS client context [in] callback Random data generation callback function 
- Returns
- Error code
Definition at line 133 of file nts_client.c.
◆ ntsClientRegisterTlsInitCallback()
| error_t ntsClientRegisterTlsInitCallback | ( | NtsClientContext * | context, | 
| NtsClientTlsInitCallback | callback | ||
| ) | 
Register TLS initialization callback function.
- Parameters
- 
  [in] context Pointer to the NTS client context [in] callback TLS initialization callback function 
- Returns
- Error code
Definition at line 111 of file nts_client.c.
◆ ntsClientSetServerAddr()
| error_t ntsClientSetServerAddr | ( | NtsClientContext * | context, | 
| const IpAddr * | serverIpAddr, | ||
| uint16_t | serverPort | ||
| ) | 
Specify the IP address of the NTS server.
- Parameters
- 
  [in] context Pointer to the NTS client context [in] serverIpAddr IP address of the NTS server [in] serverPort Port number 
- Returns
- Error code
Definition at line 178 of file nts_client.c.
◆ ntsClientSetTimeout()
| error_t ntsClientSetTimeout | ( | NtsClientContext * | context, | 
| systime_t | timeout | ||
| ) | 
Set communication timeout.
- Parameters
- 
  [in] context Pointer to the NTS client context [in] timeout Timeout value, in milliseconds 
- Returns
- Error code
Definition at line 90 of file nts_client.c.
