diff --git a/configure.ac b/configure.ac index d9e573f6c..1d645b71d 100644 --- a/configure.ac +++ b/configure.ac @@ -796,64 +796,6 @@ AC_SUBST(OPENTHREAD_ENABLE_MTD_NETWORK_DIAGNOSTIC) AM_CONDITIONAL([OPENTHREAD_ENABLE_MTD_NETWORK_DIAGNOSTIC], [test "${enable_mtd_network_diagnostic}" = "yes"]) AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_MTD_NETWORK_DIAGNOSTIC],[${OPENTHREAD_ENABLE_MTD_NETWORK_DIAGNOSTIC}],[Define to 1 to enable network diagnostic for MTD.]) -# -# Platform UDP -# - -AC_ARG_ENABLE(platform_udp, - [AS_HELP_STRING([--enable-platform-udp],[Enable platform UDP support @<:@default=no@:>@.])], - [ - case "${enableval}" in - no|yes) - enable_platform_udp=${enableval} - ;; - *) - AC_MSG_ERROR([Invalid value ${enable_platform_udp} for --enable-platform-udp]) - ;; - esac - ], - [enable_platform_udp=no]) - -if test "$enable_platform_udp" = "yes"; then - OPENTHREAD_ENABLE_PLATFORM_UDP=1 -else - OPENTHREAD_ENABLE_PLATFORM_UDP=0 -fi - -AC_MSG_RESULT(${enable_platform_udp}) -AC_SUBST(OPENTHREAD_ENABLE_PLATFORM_UDP) -AM_CONDITIONAL([OPENTHREAD_ENABLE_PLATFORM_UDP], [test "${enable_platform_udp}" = "yes"]) -AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_PLATFORM_UDP], [${OPENTHREAD_ENABLE_PLATFORM_UDP}], [Define to 1 to enable platform UDP.]) - -# -# Platform Netif -# - -AC_ARG_ENABLE(platform_netif, - [AS_HELP_STRING([--enable-platform-netif],[Enable platform Netif support @<:@default=no@:>@.])], - [ - case "${enableval}" in - no|yes) - enable_platform_netif=${enableval} - ;; - *) - AC_MSG_ERROR([Invalid value ${enable_platform_netif} for --enable-platform-netif]) - ;; - esac - ], - [enable_platform_netif=no]) - -if test "$enable_platform_netif" = "yes"; then - OPENTHREAD_ENABLE_PLATFORM_NETIF=1 -else - OPENTHREAD_ENABLE_PLATFORM_NETIF=0 -fi - -AC_MSG_RESULT(${enable_platform_netif}) -AC_SUBST(OPENTHREAD_ENABLE_PLATFORM_NETIF) -AM_CONDITIONAL([OPENTHREAD_ENABLE_PLATFORM_NETIF], [test "${enable_platform_netif}" = 'yes']) -AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_PLATFORM_NETIF], [${OPENTHREAD_ENABLE_PLATFORM_NETIF}], [Define to 1 to enable platform Netif.]) - # # Jam Detection # diff --git a/examples/common-switches.mk b/examples/common-switches.mk index a91513565..f556f3cb2 100644 --- a/examples/common-switches.mk +++ b/examples/common-switches.mk @@ -155,7 +155,7 @@ configure_OPTIONS += --enable-mtd-network-diagnostic endif ifeq ($(PLATFORM_UDP),1) -configure_OPTIONS += --enable-platform-udp +COMMONCFLAGS += -DOPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE=1 endif # Enable features only required for reference device during certification. diff --git a/examples/platforms/nrf52811/openthread-core-nrf52811-config.h b/examples/platforms/nrf52811/openthread-core-nrf52811-config.h index cbcd5a6a0..bc473d2b8 100644 --- a/examples/platforms/nrf52811/openthread-core-nrf52811-config.h +++ b/examples/platforms/nrf52811/openthread-core-nrf52811-config.h @@ -141,13 +141,13 @@ #endif /** - * @def OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER + * @def OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE * * Define to 1 if you want to support microsecond timer in platform. * */ -#ifndef OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER -#define OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER 1 +#ifndef OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE +#define OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE 1 #endif /** diff --git a/examples/platforms/nrf52840/openthread-core-nrf52840-config.h b/examples/platforms/nrf52840/openthread-core-nrf52840-config.h index f824834fe..ec6efcc7f 100644 --- a/examples/platforms/nrf52840/openthread-core-nrf52840-config.h +++ b/examples/platforms/nrf52840/openthread-core-nrf52840-config.h @@ -163,13 +163,13 @@ #endif /** - * @def OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER + * @def OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE * * Define to 1 if you want to support microsecond timer in platform. * */ -#ifndef OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER -#define OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER 1 +#ifndef OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE +#define OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE 1 #endif /** diff --git a/examples/platforms/posix/alarm.c b/examples/platforms/posix/alarm.c index db613238e..208e0209c 100644 --- a/examples/platforms/posix/alarm.c +++ b/examples/platforms/posix/alarm.c @@ -283,7 +283,7 @@ void platformAlarmProcess(otInstance *aInstance) } } -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE if (sIsUsRunning) { @@ -297,7 +297,7 @@ void platformAlarmProcess(otInstance *aInstance) } } -#endif // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#endif // OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE } uint64_t otPlatTimeGet(void) diff --git a/examples/platforms/posix/openthread-core-posix-config.h b/examples/platforms/posix/openthread-core-posix-config.h index 5c641c50f..4273d4e98 100644 --- a/examples/platforms/posix/openthread-core-posix-config.h +++ b/examples/platforms/posix/openthread-core-posix-config.h @@ -112,12 +112,12 @@ #endif // OPENTHREAD_RADIO /** - * @def OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER + * @def OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE * * Define to 1 if you want to support microsecond timer in platform. * */ -#define OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER 1 +#define OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE 1 /** * @def CLI_COAP_SECURE_USE_COAP_DEFAULT_HANDLER diff --git a/examples/platforms/posix/sim/alarm-sim.c b/examples/platforms/posix/sim/alarm-sim.c index dc4780dc9..75fc72be7 100644 --- a/examples/platforms/posix/sim/alarm-sim.c +++ b/examples/platforms/posix/sim/alarm-sim.c @@ -121,7 +121,7 @@ int32_t platformAlarmGetNext(void) } } -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE if (sIsUsRunning) { @@ -133,7 +133,7 @@ int32_t platformAlarmGetNext(void) } } -#endif // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#endif // OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE return remaining; } @@ -164,7 +164,7 @@ void platformAlarmProcess(otInstance *aInstance) } } -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE if (sIsUsRunning) { @@ -178,7 +178,7 @@ void platformAlarmProcess(otInstance *aInstance) } } -#endif // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#endif // OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE } uint64_t otPlatTimeGet(void) diff --git a/src/core/Makefile.am b/src/core/Makefile.am index f77221539..b4490d5c7 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -339,6 +339,7 @@ HEADERS_COMMON = \ config/openthread-core-config-check.h \ config/openthread-core-default-config.h \ config/parent_search.h \ + config/platform.h \ crypto/aes_ccm.hpp \ crypto/aes_ecb.hpp \ crypto/ecdsa.hpp \ diff --git a/src/core/api/udp_api.cpp b/src/core/api/udp_api.cpp index a51358cdb..30d08156f 100644 --- a/src/core/api/udp_api.cpp +++ b/src/core/api/udp_api.cpp @@ -128,7 +128,7 @@ void otUdpForwardReceive(otInstance * aInstance, } #endif // OPENTHREAD_ENABLE_UDP_FORWARD -#if OPENTHREAD_ENABLE_PLATFORM_UDP +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE otUdpSocket *otUdpGetSockets(otInstance *aInstance) { Instance &instance = *static_cast(aInstance); diff --git a/src/core/common/instance.cpp b/src/core/common/instance.cpp index f530a8f13..2c2745efd 100644 --- a/src/core/common/instance.cpp +++ b/src/core/common/instance.cpp @@ -51,7 +51,7 @@ otDEFINE_ALIGNED_VAR(gInstanceRaw, sizeof(Instance), uint64_t); Instance::Instance(void) : mTaskletScheduler() , mTimerMilliScheduler(*this) -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE , mTimerMicroScheduler(*this) #endif #if OPENTHREAD_MTD || OPENTHREAD_FTD diff --git a/src/core/common/instance.hpp b/src/core/common/instance.hpp index 7146a63fa..703b37b6f 100644 --- a/src/core/common/instance.hpp +++ b/src/core/common/instance.hpp @@ -308,7 +308,7 @@ private: TaskletScheduler mTaskletScheduler; TimerMilliScheduler mTimerMilliScheduler; -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE TimerMicroScheduler mTimerMicroScheduler; #endif @@ -703,7 +703,7 @@ template <> inline TimerMilliScheduler &Instance::Get(void) return mTimerMilliScheduler; } -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE template <> inline TimerMicroScheduler &Instance::Get(void) { return mTimerMicroScheduler; diff --git a/src/core/common/timer.cpp b/src/core/common/timer.cpp index 38079df4e..4e50be166 100644 --- a/src/core/common/timer.cpp +++ b/src/core/common/timer.cpp @@ -212,7 +212,7 @@ exit: return; } -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE const TimerScheduler::AlarmApi TimerMicroScheduler::sAlarmMicroApi = {&otPlatAlarmMicroStartAt, &otPlatAlarmMicroStop, &otPlatAlarmMicroGetNow}; @@ -238,6 +238,6 @@ extern "C" void otPlatAlarmMicroFired(otInstance *aInstance) exit: return; } -#endif // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#endif // OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE } // namespace ot diff --git a/src/core/common/timer.hpp b/src/core/common/timer.hpp index 1032b548c..3e000a388 100644 --- a/src/core/common/timer.hpp +++ b/src/core/common/timer.hpp @@ -412,7 +412,7 @@ private: static const AlarmApi sAlarmMilliApi; }; -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE class TimerMicroScheduler; /** @@ -512,7 +512,7 @@ public: private: static const AlarmApi sAlarmMicroApi; }; -#endif // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#endif // OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE /** * @} diff --git a/src/core/config/openthread-core-config-check.h b/src/core/config/openthread-core-config-check.h index 0f06bd8b7..a5103631d 100644 --- a/src/core/config/openthread-core-config-check.h +++ b/src/core/config/openthread-core-config-check.h @@ -34,8 +34,8 @@ #ifndef OPENTHREAD_CORE_CONFIG_CHECK_H_ #define OPENTHREAD_CORE_CONFIG_CHECK_H_ -#if OPENTHREAD_ENABLE_PLATFORM_UDP && OPENTHREAD_ENABLE_UDP_FORWARD -#error "OPENTHREAD_ENABLE_PLATFORM_UDP and OPENTHREAD_ENABLE_UDP_FORWARD must not both be set." +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE && OPENTHREAD_ENABLE_UDP_FORWARD +#error "OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE and OPENTHREAD_ENABLE_UDP_FORWARD must not both be set." #endif /* diff --git a/src/core/config/openthread-core-default-config.h b/src/core/config/openthread-core-default-config.h index 15c273555..f6dae7570 100644 --- a/src/core/config/openthread-core-default-config.h +++ b/src/core/config/openthread-core-default-config.h @@ -75,16 +75,6 @@ #define OPENTHREAD_CONFIG_STACK_VERSION_MINOR 1 #endif -/** - * @def OPENTHREAD_CONFIG_PLATFORM_INFO - * - * The platform-specific string to insert into the OpenThread version string. - * - */ -#ifndef OPENTHREAD_CONFIG_PLATFORM_INFO -#define OPENTHREAD_CONFIG_PLATFORM_INFO "NONE" -#endif - /** * @def OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS * @@ -247,18 +237,6 @@ #define OPENTHREAD_CONFIG_SNTP_MAX_RETRANSMIT 2 #endif -/** - * @def OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT - * - * The message pool is managed by platform defined logic when this flag is set. - * This feature would typically be used when operating in a multi-threaded system - * and multiple threads need to access the message pool. - * - */ -#ifndef OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT -#define OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT 0 -#endif - /** * @def OPENTHREAD_CONFIG_STORE_FRAME_COUNTER_AHEAD * @@ -308,36 +286,6 @@ #define OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS 1 #endif -/** - * @def OPENTHREAD_CONFIG_PLATFORM_ASSERT_MANAGEMENT - * - * The assert is managed by platform defined logic when this flag is set. - * - */ -#ifndef OPENTHREAD_CONFIG_PLATFORM_ASSERT_MANAGEMENT -#define OPENTHREAD_CONFIG_PLATFORM_ASSERT_MANAGEMENT 0 -#endif - -/** - * @def OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER - * - * Define to 1 if you want to enable microsecond backoff timer implemented in platform. - * - */ -#ifndef OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER -#define OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER 0 -#endif - -/** - * @def OPENTHREAD_CONFIG_ENABLE_PLATFORM_EUI64_CUSTOM_SOURCE - * - * Allows to define custom otPlatRadioGetIeeeEui64 function to retrieve EUI-64. - * - */ -#ifndef OPENTHREAD_CONFIG_ENABLE_PLATFORM_EUI64_CUSTOM_SOURCE -#define OPENTHREAD_CONFIG_ENABLE_PLATFORM_EUI64_CUSTOM_SOURCE 0 -#endif - /** * @def OPENTHREAD_CONFIG_HEAP_SIZE * diff --git a/src/core/config/platform.h b/src/core/config/platform.h new file mode 100644 index 000000000..7507ac082 --- /dev/null +++ b/src/core/config/platform.h @@ -0,0 +1,100 @@ +/* + * 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 platform-specific services. + * + */ + +#ifndef CONFIG_PLATFORM_H_ +#define CONFIG_PLATFORM_H_ + +/** + * @def OPENTHREAD_CONFIG_PLATFORM_INFO + * + * The platform-specific string to insert into the OpenThread version string. + * + */ +#ifndef OPENTHREAD_CONFIG_PLATFORM_INFO +#define OPENTHREAD_CONFIG_PLATFORM_INFO "NONE" +#endif + +/** + * @def OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT + * + * The message pool is managed by platform defined logic when this flag is set. + * This feature would typically be used when operating in a multi-threaded system + * and multiple threads need to access the message pool. + * + */ +#ifndef OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT +#define OPENTHREAD_CONFIG_PLATFORM_MESSAGE_MANAGEMENT 0 +#endif + +/** + * @def OPENTHREAD_CONFIG_PLATFORM_ASSERT_MANAGEMENT + * + * The assert is managed by platform defined logic when this flag is set. + * + */ +#ifndef OPENTHREAD_CONFIG_PLATFORM_ASSERT_MANAGEMENT +#define OPENTHREAD_CONFIG_PLATFORM_ASSERT_MANAGEMENT 0 +#endif + +/** + * @def OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE + * + * Define to 1 to enable platform NETIF support. + * + */ +#ifndef OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE +#define OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE 0 +#endif + +/** + * @def OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE + * + * Define to 1 to enable platform UDP support. + * + */ +#ifndef OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE +#define OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE 0 +#endif + +/** + * @def OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE + * + * Define to 1 if you want to enable microsecond backoff timer implemented in platform. + * + */ +#ifndef OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE +#define OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE 0 +#endif + +#endif // CONFIG_PLATFORM_H_ diff --git a/src/core/mac/sub_mac.cpp b/src/core/mac/sub_mac.cpp index 3049826a9..05352a474 100644 --- a/src/core/mac/sub_mac.cpp +++ b/src/core/mac/sub_mac.cpp @@ -256,7 +256,7 @@ void SubMac::StartCsmaBackoff(void) otPlatRadioSleep(&GetInstance()); } -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE mTimer.Start(backoff); #else mTimer.Start(backoff / 1000UL); @@ -304,7 +304,7 @@ void SubMac::HandleTransmitStarted(Frame &aFrame) { if (ShouldHandleAckTimeout() && aFrame.GetAckRequest()) { -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE mTimer.Start(kAckTimeout * 1000UL); #else mTimer.Start(kAckTimeout); diff --git a/src/core/mac/sub_mac.hpp b/src/core/mac/sub_mac.hpp index 6c86321da..f30d2d022 100644 --- a/src/core/mac/sub_mac.hpp +++ b/src/core/mac/sub_mac.hpp @@ -413,7 +413,7 @@ private: kMinBackoff = 1, ///< Minimum backoff (milliseconds). kAckTimeout = 16, ///< Timeout for waiting on an ACK (milliseconds). -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE kEnergyScanRssiSampleInterval = 128, ///< RSSI sample interval during energy scan, 128 usec #else kEnergyScanRssiSampleInterval = 1, ///< RSSI sample interval during energy scan, 1 ms @@ -467,7 +467,7 @@ private: Callbacks mCallbacks; otLinkPcapCallback mPcapCallback; void * mPcapCallbackContext; -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE TimerMicro mTimer; #else TimerMilli mTimer; diff --git a/src/core/net/ip6.cpp b/src/core/net/ip6.cpp index 374fd7bc8..5cf051a32 100644 --- a/src/core/net/ip6.cpp +++ b/src/core/net/ip6.cpp @@ -732,7 +732,7 @@ otError Ip6::ProcessReceiveCallback(const Message & aMessage, break; -#if OPENTHREAD_ENABLE_PLATFORM_UDP == 0 +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE == 0 case kCoapUdpPort: // do not pass TMF messages @@ -742,7 +742,7 @@ otError Ip6::ProcessReceiveCallback(const Message & aMessage, } break; -#endif // OPENTHREAD_ENABLE_PLATFORM_UDP +#endif // OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE default: #if OPENTHREAD_FTD diff --git a/src/core/net/udp6.cpp b/src/core/net/udp6.cpp index 126ea10a2..13f0c2fcf 100644 --- a/src/core/net/udp6.cpp +++ b/src/core/net/udp6.cpp @@ -48,7 +48,7 @@ using ot::Encoding::BigEndian::HostSwap16; namespace ot { namespace Ip6 { -#if OPENTHREAD_ENABLE_PLATFORM_UDP +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE static bool IsMle(Instance &aInstance, uint16_t aPort) { #if OPENTHREAD_FTD @@ -79,13 +79,13 @@ otError UdpSocket::Open(otUdpReceive aHandler, void *aContext) mHandler = aHandler; mContext = aContext; -#if OPENTHREAD_ENABLE_PLATFORM_UDP +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE SuccessOrExit(error = otPlatUdpSocket(this)); #endif Get().AddSocket(*this); -#if OPENTHREAD_ENABLE_PLATFORM_UDP +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE exit: #endif return error; @@ -102,12 +102,12 @@ otError UdpSocket::Bind(const SockAddr &aSockAddr) do { mSockName.mPort = Get().GetEphemeralPort(); -#if OPENTHREAD_ENABLE_PLATFORM_UDP +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE error = otPlatUdpBind(this); #endif } while (error != OT_ERROR_NONE); } -#if OPENTHREAD_ENABLE_PLATFORM_UDP +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE else if (!IsMle(GetInstance(), mSockName.mPort)) { error = otPlatUdpBind(this); @@ -123,7 +123,7 @@ otError UdpSocket::Connect(const SockAddr &aSockAddr) mPeerName = aSockAddr; -#if OPENTHREAD_ENABLE_PLATFORM_UDP +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE if (!IsMle(GetInstance(), mSockName.mPort)) { error = otPlatUdpConnect(this); @@ -136,7 +136,7 @@ otError UdpSocket::Close(void) { otError error = OT_ERROR_NONE; -#if OPENTHREAD_ENABLE_PLATFORM_UDP +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE SuccessOrExit(error = otPlatUdpClose(this)); #endif @@ -144,7 +144,7 @@ otError UdpSocket::Close(void) memset(&mSockName, 0, sizeof(mSockName)); memset(&mPeerName, 0, sizeof(mPeerName)); -#if OPENTHREAD_ENABLE_PLATFORM_UDP +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE exit: #endif return error; @@ -185,7 +185,7 @@ otError UdpSocket::SendTo(Message &aMessage, const MessageInfo &aMessageInfo) messageInfoLocal.SetSockPort(GetSockName().mPort); -#if OPENTHREAD_ENABLE_PLATFORM_UDP +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE if (!IsMle(GetInstance(), mSockName.mPort) && !(mSockName.mPort == ot::kCoapUdpPort && aMessage.GetSubType() == Message::kSubTypeJoinerEntrust)) { @@ -377,7 +377,7 @@ otError Udp::HandleMessage(Message &aMessage, MessageInfo &aMessageInfo) aMessageInfo.mPeerPort = udpHeader.GetSourcePort(); aMessageInfo.mSockPort = udpHeader.GetDestinationPort(); -#if OPENTHREAD_ENABLE_PLATFORM_UDP +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE VerifyOrExit(IsMle(GetInstance(), aMessageInfo.mSockPort)); #endif diff --git a/src/core/net/udp6.hpp b/src/core/net/udp6.hpp index ff6f340a0..4512624e0 100644 --- a/src/core/net/udp6.hpp +++ b/src/core/net/udp6.hpp @@ -328,7 +328,7 @@ public: */ void UpdateChecksum(Message &aMessage, uint16_t aChecksum); -#if OPENTHREAD_ENABLE_PLATFORM_UDP +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE otUdpSocket *GetUdpSockets(void) { return mSockets; } #endif diff --git a/src/core/openthread-core-config.h b/src/core/openthread-core-config.h index 3651a63b2..2a56396b3 100644 --- a/src/core/openthread-core-config.h +++ b/src/core/openthread-core-config.h @@ -63,6 +63,7 @@ #include "config/mac.h" #include "config/mle.h" #include "config/parent_search.h" +#include "config/platform.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/posix/Makefile-posix b/src/posix/Makefile-posix index 34ee98d75..73c86cc64 100644 --- a/src/posix/Makefile-posix +++ b/src/posix/Makefile-posix @@ -92,7 +92,7 @@ configure_OPTIONS += --host=$(HOST) endif ifeq ($(PLATFORM_NETIF),1) -configure_OPTIONS += --enable-platform-netif +COMMONCFLAGS += -DOPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE=1 endif ifneq ($(READLINE),) diff --git a/src/posix/main.c b/src/posix/main.c index 00da24ae4..5643200af 100644 --- a/src/posix/main.c +++ b/src/posix/main.c @@ -93,7 +93,7 @@ int main(int argc, char *argv[]) #if OPENTHREAD_POSIX_APP_TYPE == OPENTHREAD_POSIX_APP_TYPE_NCP otNcpInit(instance); #elif OPENTHREAD_POSIX_APP_TYPE == OPENTHREAD_POSIX_APP_TYPE_CLI -#if OPENTHREAD_ENABLE_PLATFORM_NETIF +#if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE otSysInitNetif(instance); #endif #if OPENTHREAD_USE_CONSOLE diff --git a/src/posix/platform/Makefile.am b/src/posix/platform/Makefile.am index b0aa68e70..cbc4e260a 100644 --- a/src/posix/platform/Makefile.am +++ b/src/posix/platform/Makefile.am @@ -51,13 +51,8 @@ libopenthread_posix_a_SOURCES = \ sim.c \ system.c \ uart.c \ - $(NULL) - -if OPENTHREAD_ENABLE_PLATFORM_UDP -libopenthread_posix_a_SOURCES += \ udp.cpp \ $(NULL) -endif noinst_HEADERS = \ openthread-system.h \ diff --git a/src/posix/platform/alarm.c b/src/posix/platform/alarm.c index 22a400ddb..bb659af63 100644 --- a/src/posix/platform/alarm.c +++ b/src/posix/platform/alarm.c @@ -44,7 +44,7 @@ static bool sIsMsRunning = false; static uint32_t sMsAlarm = 0; -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE static bool sIsUsRunning = false; static uint32_t sUsAlarm = 0; #endif @@ -96,7 +96,7 @@ void otPlatAlarmMilliStop(otInstance *aInstance) sIsMsRunning = false; } -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE uint32_t otPlatAlarmMicroGetNow(void) { return (uint32_t)(otSysGetTime()); @@ -116,7 +116,7 @@ void otPlatAlarmMicroStop(otInstance *aInstance) sIsUsRunning = false; } -#endif // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#endif // OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE void platformAlarmUpdateTimeout(struct timeval *aTimeout) { @@ -133,7 +133,7 @@ void platformAlarmUpdateTimeout(struct timeval *aTimeout) remaining -= (now % US_PER_MS); } -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE if (sIsUsRunning) { int32_t usRemaining = (int32_t)(sUsAlarm - (uint32_t)now); @@ -143,7 +143,7 @@ void platformAlarmUpdateTimeout(struct timeval *aTimeout) remaining = usRemaining; } } -#endif // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#endif // OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE exit: if (remaining <= 0) @@ -191,7 +191,7 @@ void platformAlarmProcess(otInstance *aInstance) } } -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE if (sIsUsRunning) { @@ -205,5 +205,5 @@ void platformAlarmProcess(otInstance *aInstance) } } -#endif // OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#endif // OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE } diff --git a/src/posix/platform/netif.cpp b/src/posix/platform/netif.cpp index 280a182ef..a634d8c89 100644 --- a/src/posix/platform/netif.cpp +++ b/src/posix/platform/netif.cpp @@ -61,7 +61,7 @@ #include "common/logging.hpp" #include "net/ip6_address.hpp" -#if OPENTHREAD_ENABLE_PLATFORM_NETIF +#if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE #ifndef OPENTHREAD_POSIX_TUN_DEVICE #define OPENTHREAD_POSIX_TUN_DEVICE "/dev/net/tun" @@ -410,7 +410,7 @@ void platformNetifInit(otInstance *aInstance) VerifyOrExit(sTunIndex > 0); strncpy(sTunName, ifr.ifr_name, sizeof(sTunName)); -#if OPENTHREAD_ENABLE_PLATFORM_UDP +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE platformUdpInit(sTunName); #endif @@ -504,4 +504,4 @@ exit: return; } -#endif // OPENTHREAD_ENABLE_PLATFORM_NETIF +#endif // OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE diff --git a/src/posix/platform/system.c b/src/posix/platform/system.c index 7ca077881..4b6f43d17 100644 --- a/src/posix/platform/system.c +++ b/src/posix/platform/system.c @@ -153,7 +153,7 @@ otInstance *otSysInit(int aArgCount, char *aArgVector[]) platformAlarmInit(speedUpFactor); platformRadioInit(radioFile, radioConfig, reset); platformRandomInit(); -#if OPENTHREAD_ENABLE_PLATFORM_UDP && OPENTHREAD_ENABLE_PLATFORM_NETIF == 0 +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE && OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE == 0 platformUdpInit(getenv("PLATFORM_NETIF")); #endif @@ -173,7 +173,7 @@ otInstance *otSysInit(int aArgCount, char *aArgVector[]) return instance; } -#if OPENTHREAD_ENABLE_PLATFORM_NETIF +#if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE void otSysInitNetif(otInstance *aInstance) { platformNetifInit(aInstance); @@ -226,10 +226,10 @@ void otSysMainloopUpdate(otInstance *aInstance, otSysMainloopContext *aMainloop) platformAlarmUpdateTimeout(&aMainloop->mTimeout); platformUartUpdateFdSet(&aMainloop->mReadFdSet, &aMainloop->mWriteFdSet, &aMainloop->mErrorFdSet, &aMainloop->mMaxFd); -#if OPENTHREAD_ENABLE_PLATFORM_UDP +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE platformUdpUpdateFdSet(aInstance, &aMainloop->mReadFdSet, &aMainloop->mMaxFd); #endif -#if OPENTHREAD_ENABLE_PLATFORM_NETIF +#if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE platformNetifUpdateFdSet(&aMainloop->mReadFdSet, &aMainloop->mWriteFdSet, &aMainloop->mErrorFdSet, &aMainloop->mMaxFd); #endif @@ -299,10 +299,10 @@ void otSysMainloopProcess(otInstance *aInstance, const otSysMainloopContext *aMa #endif platformUartProcess(&aMainloop->mReadFdSet, &aMainloop->mWriteFdSet, &aMainloop->mErrorFdSet); platformAlarmProcess(aInstance); -#if OPENTHREAD_ENABLE_PLATFORM_NETIF +#if OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE platformNetifProcess(&aMainloop->mReadFdSet, &aMainloop->mWriteFdSet, &aMainloop->mErrorFdSet); #endif -#if OPENTHREAD_ENABLE_PLATFORM_UDP +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE platformUdpProcess(aInstance, &aMainloop->mReadFdSet); #endif } diff --git a/src/posix/platform/udp.cpp b/src/posix/platform/udp.cpp index 935e43314..46616f8fc 100644 --- a/src/posix/platform/udp.cpp +++ b/src/posix/platform/udp.cpp @@ -53,6 +53,8 @@ #include "common/code_utils.hpp" +#if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE + static uint32_t sPlatNetifIndex = 0; static const size_t kMaxUdpSize = 1280; @@ -447,3 +449,5 @@ void platformUdpProcess(otInstance *aInstance, const fd_set *aReadFdSet) exit: return; } + +#endif // #if OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE diff --git a/tests/fuzz/fuzzer_platform.c b/tests/fuzz/fuzzer_platform.c index 7357f40e3..e07f224fd 100644 --- a/tests/fuzz/fuzzer_platform.c +++ b/tests/fuzz/fuzzer_platform.c @@ -82,7 +82,7 @@ void FuzzerPlatformProcess(otInstance *aInstance) otPlatAlarmMilliFired(aInstance); } -#if OPENTHREAD_CONFIG_ENABLE_PLATFORM_USEC_TIMER +#if OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE if (sAlarmMicro.isRunning && sAlarmNow >= sAlarmMicro.fire) { sAlarmMicro.isRunning = false;