diff --git a/.travis/script.sh b/.travis/script.sh index 29d3b6f37..3d2d93ab5 100755 --- a/.travis/script.sh +++ b/.travis/script.sh @@ -71,7 +71,8 @@ python --version || die -DOPENTHREAD_CONFIG_JOINER_ENABLE=1 \ -DOPENTHREAD_CONFIG_LINK_RAW_ENABLE=1 \ -DOPENTHREAD_CONFIG_MAC_FILTER_ENABLE=1 \ - -DOPENTHREAD_CONFIG_NCP_UART_ENABLE=1" + -DOPENTHREAD_CONFIG_NCP_UART_ENABLE=1 \ + -DOPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE=1" scan-build ./configure \ --enable-builtin-mbedtls=no \ @@ -87,7 +88,6 @@ python --version || die --enable-ncp \ --enable-radio-only \ --enable-service \ - --enable-sntp-client \ --enable-udp-forward \ --with-examples=posix || die @@ -108,7 +108,6 @@ python --version || die --enable-ncp \ --enable-radio-only \ --enable-service \ - --enable-sntp-client \ --enable-udp-forward \ --with-examples=posix || die diff --git a/configure.ac b/configure.ac index 1d645b71d..f1c2966ff 100644 --- a/configure.ac +++ b/configure.ac @@ -946,36 +946,6 @@ AC_SUBST(OPENTHREAD_NCP_SPINEL_ENCRYPTER_LIBS) AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER],[${OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER}],[Define to 1 if using NCP Spinel Encrypter]) AM_CONDITIONAL([OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER], [test "${OPENTHREAD_ENABLE_NCP_SPINEL_ENCRYPTER}" = "1"]) -# -# SNTP Client -# - -AC_ARG_ENABLE(sntp_client, - [AS_HELP_STRING([--enable-sntp-client],[Enable SNTP client support @<:@default=no@:>@.])], - [ - case "${enableval}" in - - no|yes) - enable_sntp_client=${enableval} - ;; - - *) - AC_MSG_ERROR([Invalid value ${enable_sntp_client} for --enable-sntp-client]) - ;; - esac - ], - [enable_sntp_client=no]) - -if test "$enable_sntp_client" = "yes"; then - OPENTHREAD_ENABLE_SNTP_CLIENT=1 -else - OPENTHREAD_ENABLE_SNTP_CLIENT=0 -fi - -AC_SUBST(OPENTHREAD_ENABLE_SNTP_CLIENT) -AM_CONDITIONAL([OPENTHREAD_ENABLE_SNTP_CLIENT], [test "${enable_sntp_client}" = "yes"]) -AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_SNTP_CLIENT],[${OPENTHREAD_ENABLE_SNTP_CLIENT}],[Define to 1 if you want to enable SNTP Client]) - # # Service # @@ -1466,7 +1436,6 @@ AC_MSG_NOTICE([ OpenThread UDP forward support : ${enable_udp_forward} OpenThread Jam Detection support : ${enable_jam_detection} OpenThread Legacy network support : ${enable_legacy} - OpenThread SNTP Client support : ${enable_sntp_client} OpenThread Service support : ${enable_service} OpenThread ECDSA support : ${enable_ecdsa} OpenThread Examples : ${with_examples} diff --git a/examples/common-switches.mk b/examples/common-switches.mk index f556f3cb2..32bc0af75 100644 --- a/examples/common-switches.mk +++ b/examples/common-switches.mk @@ -173,7 +173,7 @@ COMMONCFLAGS += -DOPENTHREAD_CONFIG_IP6_SLAAC_ENABLE=1 endif ifeq ($(SNTP_CLIENT),1) -configure_OPTIONS += --enable-sntp-client +COMMONCFLAGS += -DOPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE=1 endif ifeq ($(TIME_SYNC),1) diff --git a/include/openthread/sntp.h b/include/openthread/sntp.h index abafed77c..34a7817aa 100644 --- a/include/openthread/sntp.h +++ b/include/openthread/sntp.h @@ -85,7 +85,7 @@ typedef void (*otSntpResponseHandler)(void *aContext, uint64_t aTime, otError aR /** * This function sends a SNTP query. * - * This function is available only if feature `OPENTHREAD_ENABLE_SNTP_CLIENT` is enabled. + * This function is available only if feature `OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE_CLIENT` is enabled. * * @param[in] aInstance A pointer to an OpenThread instance. * @param[in] aQuery A pointer to specify SNTP query parameters. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index f98926128..8270793de 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -208,7 +208,7 @@ const struct Command Interpreter::sCommands[] = { {"service", &Interpreter::ProcessService}, #endif {"singleton", &Interpreter::ProcessSingleton}, -#if OPENTHREAD_ENABLE_SNTP_CLIENT +#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE {"sntp", &Interpreter::ProcessSntp}, #endif {"state", &Interpreter::ProcessState}, @@ -2857,7 +2857,7 @@ void Interpreter::ProcessSingleton(int argc, char *argv[]) AppendResult(error); } -#if OPENTHREAD_ENABLE_SNTP_CLIENT +#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE void Interpreter::ProcessSntp(int argc, char *argv[]) { otError error = OT_ERROR_NONE; diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index c0b51ae8e..141fc8994 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -315,7 +315,7 @@ private: void ProcessRloc16(int argc, char *argv[]); void ProcessScan(int argc, char *argv[]); void ProcessSingleton(int argc, char *argv[]); -#if OPENTHREAD_ENABLE_SNTP_CLIENT +#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE void ProcessSntp(int argc, char *argv[]); #endif void ProcessState(int argc, char *argv[]); @@ -349,7 +349,7 @@ private: otError aResult); #endif -#if OPENTHREAD_ENABLE_SNTP_CLIENT +#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE static void HandleSntpResponse(void *aContext, uint64_t aTime, otError aResult); #endif @@ -362,7 +362,7 @@ private: #if OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE void HandleDnsResponse(const char *aHostname, Ip6::Address &aAddress, uint32_t aTtl, otError aResult); #endif -#if OPENTHREAD_ENABLE_SNTP_CLIENT +#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE void HandleSntpResponse(uint64_t aTime, otError aResult); #endif static Interpreter &GetOwner(OwnerLocator &aOwnerLocator); @@ -382,7 +382,7 @@ private: char mResolvingHostname[OT_DNS_MAX_HOSTNAME_LENGTH]; #endif -#if OPENTHREAD_ENABLE_SNTP_CLIENT +#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE bool mSntpQueryingInProgress; #endif diff --git a/src/core/Makefile.am b/src/core/Makefile.am index b4490d5c7..c17a781de 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -340,6 +340,7 @@ HEADERS_COMMON = \ config/openthread-core-default-config.h \ config/parent_search.h \ config/platform.h \ + config/sntp_client.h \ crypto/aes_ccm.hpp \ crypto/aes_ecb.hpp \ crypto/ecdsa.hpp \ diff --git a/src/core/api/sntp_api.cpp b/src/core/api/sntp_api.cpp index 15fb113ec..2c1cab8ba 100644 --- a/src/core/api/sntp_api.cpp +++ b/src/core/api/sntp_api.cpp @@ -40,7 +40,7 @@ using namespace ot; -#if OPENTHREAD_ENABLE_SNTP_CLIENT +#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE otError otSntpClientQuery(otInstance * aInstance, const otSntpQuery * aQuery, otSntpResponseHandler aHandler, diff --git a/src/core/common/instance.hpp b/src/core/common/instance.hpp index 703b37b6f..4807b43b6 100644 --- a/src/core/common/instance.hpp +++ b/src/core/common/instance.hpp @@ -626,7 +626,7 @@ template <> inline Utils::JamDetector &Instance::Get(void) } #endif -#if OPENTHREAD_ENABLE_SNTP_CLIENT +#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE template <> inline Sntp::Client &Instance::Get(void) { return mThreadNetif.mSntpClient; diff --git a/src/core/config/openthread-core-default-config.h b/src/core/config/openthread-core-default-config.h index f6dae7570..5e0ef36d3 100644 --- a/src/core/config/openthread-core-default-config.h +++ b/src/core/config/openthread-core-default-config.h @@ -217,26 +217,6 @@ #define OPENTHREAD_CONFIG_MAX_STATECHANGE_HANDLERS 1 #endif -/** - * @def OPENTHREAD_CONFIG_SNTP_RESPONSE_TIMEOUT - * - * Maximum time that SNTP Client waits for response in milliseconds. - * - */ -#ifndef OPENTHREAD_CONFIG_SNTP_RESPONSE_TIMEOUT -#define OPENTHREAD_CONFIG_SNTP_RESPONSE_TIMEOUT 3000 -#endif - -/** - * @def OPENTHREAD_CONFIG_SNTP_MAX_RETRANSMIT - * - * Maximum number of retransmissions for SNTP client. - * - */ -#ifndef OPENTHREAD_CONFIG_SNTP_MAX_RETRANSMIT -#define OPENTHREAD_CONFIG_SNTP_MAX_RETRANSMIT 2 -#endif - /** * @def OPENTHREAD_CONFIG_STORE_FRAME_COUNTER_AHEAD * diff --git a/src/core/config/sntp_client.h b/src/core/config/sntp_client.h new file mode 100644 index 000000000..bd8d5fa5a --- /dev/null +++ b/src/core/config/sntp_client.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2019, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * @file + * This file includes compile-time configurations for the SNTP Client. + * + */ + +#ifndef CONFIG_SNTP_CLIENT_H_ +#define CONFIG_SNTP_CLIENT_H_ + +/** + * @def OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE + * + * Define to 1 to enable SNTP Client support. + * + */ +#ifndef OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE +#define OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE 0 +#endif + +/** + * @def OPENTHREAD_CONFIG_SNTP_CLIENT_RESPONSE_TIMEOUT + * + * Maximum time that SNTP Client waits for response in milliseconds. + * + */ +#ifndef OPENTHREAD_CONFIG_SNTP_CLIENT_RESPONSE_TIMEOUT +#define OPENTHREAD_CONFIG_SNTP_CLIENT_RESPONSE_TIMEOUT 3000 +#endif + +/** + * @def OPENTHREAD_CONFIG_SNTP_CLIENT_MAX_RETRANSMIT + * + * Maximum number of retransmissions for SNTP client. + * + */ +#ifndef OPENTHREAD_CONFIG_SNTP_CLIENT_MAX_RETRANSMIT +#define OPENTHREAD_CONFIG_SNTP_CLIENT_MAX_RETRANSMIT 2 +#endif + +#endif // CONFIG_SNTP_CLIENT_H_ diff --git a/src/core/net/sntp_client.cpp b/src/core/net/sntp_client.cpp index fd9c051cf..4c9a9ba19 100644 --- a/src/core/net/sntp_client.cpp +++ b/src/core/net/sntp_client.cpp @@ -38,7 +38,7 @@ #include "net/udp6.hpp" #include "thread/thread_netif.hpp" -#if OPENTHREAD_ENABLE_SNTP_CLIENT +#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE /** * @file @@ -399,4 +399,4 @@ exit: } // namespace Sntp } // namespace ot -#endif // OPENTHREAD_ENABLE_SNTP_CLIENT +#endif // OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE diff --git a/src/core/net/sntp_client.hpp b/src/core/net/sntp_client.hpp index 4c518e308..7f05ac8d1 100644 --- a/src/core/net/sntp_client.hpp +++ b/src/core/net/sntp_client.hpp @@ -596,8 +596,8 @@ private: */ enum { - kResponseTimeout = OPENTHREAD_CONFIG_SNTP_RESPONSE_TIMEOUT, - kMaxRetransmit = OPENTHREAD_CONFIG_SNTP_MAX_RETRANSMIT, + kResponseTimeout = OPENTHREAD_CONFIG_SNTP_CLIENT_RESPONSE_TIMEOUT, + kMaxRetransmit = OPENTHREAD_CONFIG_SNTP_CLIENT_MAX_RETRANSMIT, }; Message *NewMessage(const Header &aHeader); diff --git a/src/core/openthread-core-config.h b/src/core/openthread-core-config.h index 2a56396b3..96753492f 100644 --- a/src/core/openthread-core-config.h +++ b/src/core/openthread-core-config.h @@ -64,6 +64,7 @@ #include "config/mle.h" #include "config/parent_search.h" #include "config/platform.h" +#include "config/sntp_client.h" #if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE || OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE || \ OPENTHREAD_CONFIG_COMMISSIONER_ENABLE || OPENTHREAD_CONFIG_JOINER_ENABLE diff --git a/src/core/thread/thread_netif.cpp b/src/core/thread/thread_netif.cpp index 2fd246023..221e9801d 100644 --- a/src/core/thread/thread_netif.cpp +++ b/src/core/thread/thread_netif.cpp @@ -62,9 +62,9 @@ ThreadNetif::ThreadNetif(Instance &aInstance) #if OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE , mDnsClient(Get()) #endif // OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE -#if OPENTHREAD_ENABLE_SNTP_CLIENT +#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE , mSntpClient(Get()) -#endif // OPENTHREAD_ENABLE_SNTP_CLIENT +#endif // OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE , mActiveDataset(aInstance) , mPendingDataset(aInstance) , mKeyManager(aInstance) @@ -131,7 +131,7 @@ void ThreadNetif::Up(void) #if OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE Get().Start(); #endif -#if OPENTHREAD_ENABLE_SNTP_CLIENT +#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE Get().Start(); #endif Get().Signal(OT_CHANGED_THREAD_NETIF_STATE); @@ -147,7 +147,7 @@ void ThreadNetif::Down(void) #if OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE Get().Stop(); #endif -#if OPENTHREAD_ENABLE_SNTP_CLIENT +#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE Get().Stop(); #endif #if OPENTHREAD_CONFIG_DTLS_ENABLE diff --git a/src/core/thread/thread_netif.hpp b/src/core/thread/thread_netif.hpp index 15de1e352..6c704dc1c 100644 --- a/src/core/thread/thread_netif.hpp +++ b/src/core/thread/thread_netif.hpp @@ -176,9 +176,9 @@ private: #if OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE Dns::Client mDnsClient; #endif // OPENTHREAD_CONFIG_DNS_CLIENT_ENABLE -#if OPENTHREAD_ENABLE_SNTP_CLIENT +#if OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE Sntp::Client mSntpClient; -#endif // OPENTHREAD_ENABLE_SNTP_CLIENT +#endif // OPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE MeshCoP::ActiveDataset mActiveDataset; MeshCoP::PendingDataset mPendingDataset; Ip6::Filter mIp6Filter;