From 6c8a9a86612cb137ec0568390eb07c47503ddef1 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Mon, 15 Jul 2019 16:03:45 -0700 Subject: [PATCH] [config] coap (#4020) --- .travis/script.sh | 8 +- Android.mk | 2 +- Makefile.am | 2 - configure.ac | 63 ---------- examples/common-switches.mk | 4 +- include/openthread/coap.h | 3 +- include/openthread/coap_secure.h | 4 +- src/cli/cli.cpp | 16 +-- src/cli/cli.hpp | 16 +-- src/cli/cli_coap.cpp | 4 +- src/cli/cli_coap.hpp | 4 +- src/cli/cli_coap_secure.cpp | 4 +- src/cli/cli_coap_secure.hpp | 4 +- src/cli/x509_cert_key.hpp | 4 +- src/core/Makefile.am | 1 + src/core/api/coap_api.cpp | 4 +- src/core/api/coap_secure_api.cpp | 4 +- src/core/api/message_api.cpp | 2 +- src/core/coap/coap_message.cpp | 4 +- src/core/coap/coap_message.hpp | 4 +- src/core/coap/coap_secure.cpp | 4 +- src/core/coap/coap_secure.hpp | 4 +- src/core/common/instance.cpp | 4 +- src/core/common/instance.hpp | 8 +- src/core/config/coap.h | 112 ++++++++++++++++++ .../config/openthread-core-default-config.h | 60 +--------- src/core/meshcop/dtls.cpp | 52 ++++---- src/core/meshcop/dtls.hpp | 20 ++-- src/core/openthread-core-config.h | 3 +- third_party/mbedtls/mbedtls-config.h | 7 +- 30 files changed, 211 insertions(+), 220 deletions(-) create mode 100644 src/core/config/coap.h diff --git a/.travis/script.sh b/.travis/script.sh index 059e190ce..c756adfce 100755 --- a/.travis/script.sh +++ b/.travis/script.sh @@ -60,11 +60,11 @@ python --version || die -DOPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE=1 \ -DOPENTHREAD_CONFIG_CHANNEL_MANAGER_ENABLE=1 \ -DOPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE=1 \ - -DOPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE=1" + -DOPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE=1 \ + -DOPENTHREAD_CONFIG_COAP_API_ENABLE=1 \ + -DOPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE=1" scan-build ./configure \ - --enable-application-coap \ - --enable-application-coap-secure \ --enable-builtin-mbedtls=no \ --enable-cert-log \ --enable-cli \ @@ -95,8 +95,6 @@ python --version || die # SPI transport scan-build ./configure \ - --enable-application-coap \ - --enable-application-coap-secure \ --enable-builtin-mbedtls=no \ --enable-cert-log \ --enable-cli \ diff --git a/Android.mk b/Android.mk index c4b45580f..aa019e639 100644 --- a/Android.mk +++ b/Android.mk @@ -53,7 +53,7 @@ endif # Enable all optional features for CI tests. ifeq ($(TARGET_PRODUCT),generic) OPENTHREAD_COMMON_FLAGS += \ - -DOPENTHREAD_ENABLE_APPLICATION_COAP=1 \ + -DOPENTHREAD_CONFIG_COAP_API_ENABLE=1 \ -DOPENTHREAD_ENABLE_COMMISSIONER=1 \ -DOPENTHREAD_ENABLE_DHCP6_CLIENT=1 \ -DOPENTHREAD_ENABLE_DHCP6_SERVER=1 \ diff --git a/Makefile.am b/Makefile.am index 3700e4096..3c1772ddc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -32,8 +32,6 @@ AM_MAKEFLAGS = --no-print-directory AM_DISTCHECK_CONFIGURE_FLAGS = \ --enable-address-sanitizer \ - --enable-application-coap \ - --enable-application-coap-secure \ --enable-cert-log \ --enable-cli \ --enable-commissioner \ diff --git a/configure.ac b/configure.ac index 9ad04b055..34d886b36 100644 --- a/configure.ac +++ b/configure.ac @@ -839,37 +839,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.]) -# -# Application CoAP Secure -# - -AC_ARG_ENABLE(application_coap_secure, - [AS_HELP_STRING([--enable-application-coap-secure],[Enable CoAP Secure to an application.@<:@default=no@:>@.])], - [ - case "${enableval}" in - - no|yes) - enable_application_coap_secure=${enableval} - ;; - - *) - AC_MSG_ERROR([Invalid value ${enable_application_coap_secure} for --enable-application-coap_secure]) - ;; - esac - ], - [enable_application_coap_secure=no]) - -if test "$enable_application_coap_secure" = "yes"; then - OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE=1 - enable_application_coap="yes" -else - OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE=0 -fi - -AC_SUBST(OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE) -AM_CONDITIONAL([OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE], [test "${enable_application_coap_secure}" = "yes"]) -AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE],[${OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE}],[Define to 1 if you want to enable CoAP Secure to an application.]) - # # Platform UDP # @@ -1326,36 +1295,6 @@ 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]) -# -# Application CoAP -# - -AC_ARG_ENABLE(application_coap, - [AS_HELP_STRING([--enable-application-coap],[Enable CoAP to an application.@<:@default=no@:>@.])], - [ - case "${enableval}" in - - no|yes) - enable_application_coap=${enableval} - ;; - - *) - AC_MSG_ERROR([Invalid value ${enable_application_coap} for --enable-application-coap]) - ;; - esac - ], - [enable_application_coap=no]) - -if test "$enable_application_coap" = "yes"; then - OPENTHREAD_ENABLE_APPLICATION_COAP=1 -else - OPENTHREAD_ENABLE_APPLICATION_COAP=0 -fi - -AC_SUBST(OPENTHREAD_ENABLE_APPLICATION_COAP) -AM_CONDITIONAL([OPENTHREAD_ENABLE_APPLICATION_COAP], [test "${enable_application_coap}" = "yes"]) -AC_DEFINE_UNQUOTED([OPENTHREAD_ENABLE_APPLICATION_COAP],[${OPENTHREAD_ENABLE_APPLICATION_COAP}],[Define to 1 if you want to enable CoAP to an application.]) - # # otLinkRaw API # @@ -1885,8 +1824,6 @@ AC_MSG_NOTICE([ OpenThread DHCPv6 Client support : ${enable_dhcp6_client} OpenThread DNS Client support : ${enable_dns_client} OpenThread SNTP Client support : ${enable_sntp_client} - OpenThread Application CoAP support : ${enable_application_coap} - OpenThread Application CoAP Secure support: ${enable_application_coap_secure} OpenThread Raw Link-Layer support : ${enable_raw_link_api} OpenThread Service support : ${enable_service} OpenThread ECDSA support : ${enable_ecdsa} diff --git a/examples/common-switches.mk b/examples/common-switches.mk index 3a9091930..97889c6b9 100644 --- a/examples/common-switches.mk +++ b/examples/common-switches.mk @@ -75,11 +75,11 @@ COMMONCFLAGS += -DOPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE=1 endif ifeq ($(COAP),1) -configure_OPTIONS += --enable-application-coap +COMMONCFLAGS += -DOPENTHREAD_CONFIG_COAP_API_ENABLE=1 endif ifeq ($(COAPS),1) -configure_OPTIONS += --enable-application-coap-secure +COMMONCFLAGS += -DOPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE=1 endif ifeq ($(COMMISSIONER),1) diff --git a/include/openthread/coap.h b/include/openthread/coap.h index f0fd0ca26..b6fd55583 100644 --- a/include/openthread/coap.h +++ b/include/openthread/coap.h @@ -50,8 +50,7 @@ extern "C" { * @brief * This module includes functions that control CoAP communication. * - * The functions in this module are available when application-coap feature (`OPENTHREAD_ENABLE_APPLICATION_COAP`) is - * enabled. + * The functions in this module are available when CoAP API feature (`OPENTHREAD_CONFIG_COAP_API_ENABLE`) is enabled. * * @{ * diff --git a/include/openthread/coap_secure.h b/include/openthread/coap_secure.h index a632174bd..ab1236202 100644 --- a/include/openthread/coap_secure.h +++ b/include/openthread/coap_secure.h @@ -55,8 +55,8 @@ extern "C" { * @brief * This module includes functions that control CoAP Secure (CoAP over DTLS) communication. * - * The functions in this module are available when application-coap-secure feature - * (`OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE`) is enabled. + * The functions in this module are available when CoAP Secure API feature + * (`OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE`) is enabled. * * @{ * diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 0f982142d..a3cf3fea2 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -100,10 +100,10 @@ const struct Command Interpreter::sCommands[] = { {"childmax", &Interpreter::ProcessChildMax}, #endif {"childtimeout", &Interpreter::ProcessChildTimeout}, -#if OPENTHREAD_ENABLE_APPLICATION_COAP +#if OPENTHREAD_CONFIG_COAP_API_ENABLE {"coap", &Interpreter::ProcessCoap}, #endif -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE {"coaps", &Interpreter::ProcessCoapSecure}, #endif #if OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD @@ -231,10 +231,10 @@ Interpreter::Interpreter(Instance *aInstance) #endif , mUdp(*this) , mDataset(*this) -#if OPENTHREAD_ENABLE_APPLICATION_COAP +#if OPENTHREAD_CONFIG_COAP_API_ENABLE , mCoap(*this) #endif -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE , mCoapSecure(*this) #endif #if OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD @@ -759,7 +759,7 @@ exit: AppendResult(error); } -#if OPENTHREAD_ENABLE_APPLICATION_COAP +#if OPENTHREAD_CONFIG_COAP_API_ENABLE void Interpreter::ProcessCoap(int argc, char *argv[]) { @@ -768,9 +768,9 @@ void Interpreter::ProcessCoap(int argc, char *argv[]) AppendResult(error); } -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP +#endif // OPENTHREAD_CONFIG_COAP_API_ENABLE -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE void Interpreter::ProcessCoapSecure(int argc, char *argv[]) { @@ -779,7 +779,7 @@ void Interpreter::ProcessCoapSecure(int argc, char *argv[]) AppendResult(error); } -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #if OPENTHREAD_FTD void Interpreter::ProcessContextIdReuseDelay(int argc, char *argv[]) diff --git a/src/cli/cli.hpp b/src/cli/cli.hpp index ae8eb0452..4acbc5444 100644 --- a/src/cli/cli.hpp +++ b/src/cli/cli.hpp @@ -49,11 +49,11 @@ #include "cli/cli_joiner.hpp" #include "cli/cli_udp.hpp" -#if OPENTHREAD_ENABLE_APPLICATION_COAP +#if OPENTHREAD_CONFIG_COAP_API_ENABLE #include "cli/cli_coap.hpp" #endif -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #include "cli/cli_coap_secure.hpp" #endif @@ -202,12 +202,12 @@ private: void ProcessChildMax(int argc, char *argv[]); #endif void ProcessChildTimeout(int argc, char *argv[]); -#if OPENTHREAD_ENABLE_APPLICATION_COAP +#if OPENTHREAD_CONFIG_COAP_API_ENABLE void ProcessCoap(int argc, char *argv[]); -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_API_ENABLE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE void ProcessCoapSecure(int argc, char *argv[]); -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP +#endif // OPENTHREAD_CONFIG_COAP_API_ENABLE #if OPENTHREAD_ENABLE_COMMISSIONER && OPENTHREAD_FTD void ProcessCommissioner(int argc, char *argv[]); #endif @@ -389,11 +389,11 @@ private: UdpExample mUdp; Dataset mDataset; -#if OPENTHREAD_ENABLE_APPLICATION_COAP +#if OPENTHREAD_CONFIG_COAP_API_ENABLE Coap mCoap; #endif -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE CoapSecure mCoapSecure; #endif diff --git a/src/cli/cli_coap.cpp b/src/cli/cli_coap.cpp index 6330875b9..15128ae1e 100644 --- a/src/cli/cli_coap.cpp +++ b/src/cli/cli_coap.cpp @@ -33,7 +33,7 @@ #include "cli_coap.hpp" -#if OPENTHREAD_ENABLE_APPLICATION_COAP +#if OPENTHREAD_CONFIG_COAP_API_ENABLE #include @@ -385,4 +385,4 @@ void Coap::HandleResponse(otMessage *aMessage, const otMessageInfo *aMessageInfo } // namespace Cli } // namespace ot -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP +#endif // OPENTHREAD_CONFIG_COAP_API_ENABLE diff --git a/src/cli/cli_coap.hpp b/src/cli/cli_coap.hpp index 0728222c8..cc534a3df 100644 --- a/src/cli/cli_coap.hpp +++ b/src/cli/cli_coap.hpp @@ -36,7 +36,7 @@ #include "openthread-core-config.h" -#if OPENTHREAD_ENABLE_APPLICATION_COAP +#if OPENTHREAD_CONFIG_COAP_API_ENABLE #include "coap/coap_message.hpp" @@ -106,6 +106,6 @@ private: } // namespace Cli } // namespace ot -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP +#endif // OPENTHREAD_CONFIG_COAP_API_ENABLE #endif // CLI_COAP_HPP_ diff --git a/src/cli/cli_coap_secure.cpp b/src/cli/cli_coap_secure.cpp index 2535fa34b..d9ed1d5b5 100644 --- a/src/cli/cli_coap_secure.cpp +++ b/src/cli/cli_coap_secure.cpp @@ -33,7 +33,7 @@ #include "cli_coap_secure.hpp" -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #include #include @@ -586,4 +586,4 @@ exit: } // namespace Cli } // namespace ot -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE diff --git a/src/cli/cli_coap_secure.hpp b/src/cli/cli_coap_secure.hpp index 3c9bd08b8..c6ecec7d0 100644 --- a/src/cli/cli_coap_secure.hpp +++ b/src/cli/cli_coap_secure.hpp @@ -36,7 +36,7 @@ #include "openthread-core-config.h" -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #include "coap/coap_message.hpp" #include "coap/coap_secure.hpp" @@ -130,6 +130,6 @@ private: } // namespace Cli } // namespace ot -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #endif // CLI_COAP_SECURE_HPP_ diff --git a/src/cli/x509_cert_key.hpp b/src/cli/x509_cert_key.hpp index 45eb96e41..5f6d6befa 100644 --- a/src/cli/x509_cert_key.hpp +++ b/src/cli/x509_cert_key.hpp @@ -40,7 +40,7 @@ extern "C" { #endif -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED) /**SERVER @@ -103,7 +103,7 @@ extern "C" { "-----END CERTIFICATE-----\r\n" #endif // MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE /** * @} diff --git a/src/core/Makefile.am b/src/core/Makefile.am index 0114fd5a6..b5b166671 100644 --- a/src/core/Makefile.am +++ b/src/core/Makefile.am @@ -323,6 +323,7 @@ HEADERS_COMMON = \ config/channel_manager.h \ config/channel_monitor.h \ config/child_supervision.h \ + config/coap.h \ config/openthread-core-config-check.h \ config/openthread-core-default-config.h \ crypto/aes_ccm.hpp \ diff --git a/src/core/api/coap_api.cpp b/src/core/api/coap_api.cpp index ce8eaabae..faf7c8d2b 100644 --- a/src/core/api/coap_api.cpp +++ b/src/core/api/coap_api.cpp @@ -39,7 +39,7 @@ #include "common/instance.hpp" #include "common/locator-getters.hpp" -#if OPENTHREAD_ENABLE_APPLICATION_COAP +#if OPENTHREAD_CONFIG_COAP_API_ENABLE using namespace ot; @@ -225,4 +225,4 @@ otError otCoapSendResponse(otInstance *aInstance, otMessage *aMessage, const otM *static_cast(aMessageInfo)); } -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP +#endif // OPENTHREAD_CONFIG_COAP_API_ENABLE diff --git a/src/core/api/coap_secure_api.cpp b/src/core/api/coap_secure_api.cpp index 4027bb52e..c1a5811ac 100644 --- a/src/core/api/coap_secure_api.cpp +++ b/src/core/api/coap_secure_api.cpp @@ -41,7 +41,7 @@ #include "common/instance.hpp" #include "common/locator-getters.hpp" -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE using namespace ot; @@ -239,4 +239,4 @@ otError otCoapSecureSendResponse(otInstance *aInstance, otMessage *aMessage, con *static_cast(aMessageInfo)); } -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE diff --git a/src/core/api/message_api.cpp b/src/core/api/message_api.cpp index 75600cdf7..511b2dccc 100644 --- a/src/core/api/message_api.cpp +++ b/src/core/api/message_api.cpp @@ -207,7 +207,7 @@ void otMessageGetBufferInfo(otInstance *aInstance, otBufferInfo *aBufferInfo) aBufferInfo->mCoapSecureBuffers = 0; #endif -#if OPENTHREAD_ENABLE_APPLICATION_COAP +#if OPENTHREAD_CONFIG_COAP_API_ENABLE instance.GetApplicationCoap().GetRequestMessages().GetInfo(aBufferInfo->mApplicationCoapMessages, aBufferInfo->mApplicationCoapBuffers); instance.GetApplicationCoap().GetCachedResponses().GetInfo(messages, buffers); diff --git a/src/core/coap/coap_message.cpp b/src/core/coap/coap_message.cpp index 4798cd5f4..c8c336668 100644 --- a/src/core/coap/coap_message.cpp +++ b/src/core/coap/coap_message.cpp @@ -405,7 +405,7 @@ exit: return message; } -#if OPENTHREAD_ENABLE_APPLICATION_COAP +#if OPENTHREAD_CONFIG_COAP_API_ENABLE const char *Message::CodeToString(void) const { const char *codeString; @@ -500,7 +500,7 @@ const char *Message::CodeToString(void) const return codeString; } -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP +#endif // OPENTHREAD_CONFIG_COAP_API_ENABLE } // namespace Coap } // namespace ot diff --git a/src/core/coap/coap_message.hpp b/src/core/coap/coap_message.hpp index e0557dc12..d045d2ffc 100644 --- a/src/core/coap/coap_message.hpp +++ b/src/core/coap/coap_message.hpp @@ -188,7 +188,7 @@ public: */ void SetCode(Code aCode) { GetHelpData().mHeader.mCode = static_cast(aCode); } -#if OPENTHREAD_ENABLE_APPLICATION_COAP +#if OPENTHREAD_CONFIG_COAP_API_ENABLE /** * This method returns the CoAP Code as human readable string. * @@ -196,7 +196,7 @@ public: * */ const char *CodeToString(void) const; -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP +#endif // OPENTHREAD_CONFIG_COAP_API_ENABLE /** * This method returns the Message ID value. diff --git a/src/core/coap/coap_secure.cpp b/src/core/coap/coap_secure.cpp index 219f420fe..9901dce6f 100644 --- a/src/core/coap/coap_secure.cpp +++ b/src/core/coap/coap_secure.cpp @@ -115,7 +115,7 @@ otError CoapSecure::SetPsk(const uint8_t *aPsk, uint8_t aPskLength) return mDtls.SetPsk(aPsk, aPskLength); } -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED otError CoapSecure::SetCertificate(const uint8_t *aX509Cert, @@ -160,7 +160,7 @@ void CoapSecure::SetSslAuthMode(bool aVerifyPeerCertificate) mDtls.SetSslAuthMode(aVerifyPeerCertificate); } -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE otError CoapSecure::SendMessage(Message &aMessage, otCoapResponseHandler aHandler, void *aContext) { diff --git a/src/core/coap/coap_secure.hpp b/src/core/coap/coap_secure.hpp index 9b7e831a9..e32ea3cf7 100644 --- a/src/core/coap/coap_secure.hpp +++ b/src/core/coap/coap_secure.hpp @@ -160,7 +160,7 @@ public: */ otError SetPsk(const uint8_t *aPsk, uint8_t aPskLength); -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #ifdef MBEDTLS_KEY_EXCHANGE_PSK_ENABLED /** @@ -253,7 +253,7 @@ public: */ void SetSslAuthMode(bool aVerifyPeerCertificate); -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE /** * This method sends a CoAP message over secure DTLS connection. diff --git a/src/core/common/instance.cpp b/src/core/common/instance.cpp index 7156f7bd8..b7bc35be5 100644 --- a/src/core/common/instance.cpp +++ b/src/core/common/instance.cpp @@ -71,10 +71,10 @@ Instance::Instance(void) , mEnergyScanCallbackContext(NULL) , mIp6(*this) , mThreadNetif(*this) -#if OPENTHREAD_ENABLE_APPLICATION_COAP +#if OPENTHREAD_CONFIG_COAP_API_ENABLE , mApplicationCoap(*this) #endif -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE , mApplicationCoapSecure(*this, /* aLayerTwoSecurity */ true) #endif #if OPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE diff --git a/src/core/common/instance.hpp b/src/core/common/instance.hpp index 5537bf9c0..e976ba7a1 100644 --- a/src/core/common/instance.hpp +++ b/src/core/common/instance.hpp @@ -259,7 +259,7 @@ public: Utils::Heap &GetHeap(void) { return mHeap; } #endif -#if OPENTHREAD_ENABLE_APPLICATION_COAP +#if OPENTHREAD_CONFIG_COAP_API_ENABLE /** * This method returns a reference to application COAP object. * @@ -269,7 +269,7 @@ public: Coap::Coap &GetApplicationCoap(void) { return mApplicationCoap; } #endif -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE /** * This method returns a reference to application COAP Secure object. * @@ -339,11 +339,11 @@ private: Ip6::Ip6 mIp6; ThreadNetif mThreadNetif; -#if OPENTHREAD_ENABLE_APPLICATION_COAP +#if OPENTHREAD_CONFIG_COAP_API_ENABLE Coap::Coap mApplicationCoap; #endif -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE Coap::CoapSecure mApplicationCoapSecure; #endif diff --git a/src/core/config/coap.h b/src/core/config/coap.h new file mode 100644 index 000000000..d958c9d75 --- /dev/null +++ b/src/core/config/coap.h @@ -0,0 +1,112 @@ +/* + * 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 CoAP. + * + */ + +#ifndef CONFIG_COAP_H_ +#define CONFIG_COAP_H_ + +/** + * @def OPENTHREAD_CONFIG_COAP_ACK_TIMEOUT + * + * Minimum spacing before first retransmission when ACK is not received (RFC7252 default value is 2). + * + */ +#ifndef OPENTHREAD_CONFIG_COAP_ACK_TIMEOUT +#define OPENTHREAD_CONFIG_COAP_ACK_TIMEOUT 2 +#endif + +/** + * @def OPENTHREAD_CONFIG_COAP_ACK_RANDOM_FACTOR_NUMERATOR + * + * Numerator of ACK_RANDOM_FACTOR used to calculate maximum spacing before first retransmission when + * ACK is not received (RFC7252 default value of ACK_RANDOM_FACTOR is 1.5, must not be decreased below 1). + * + */ +#ifndef OPENTHREAD_CONFIG_COAP_ACK_RANDOM_FACTOR_NUMERATOR +#define OPENTHREAD_CONFIG_COAP_ACK_RANDOM_FACTOR_NUMERATOR 3 +#endif + +/** + * @def OPENTHREAD_CONFIG_COAP_ACK_RANDOM_FACTOR_DENOMINATOR + * + * Denominator of ACK_RANDOM_FACTOR used to calculate maximum spacing before first retransmission when + * ACK is not received (RFC7252 default value of ACK_RANDOM_FACTOR is 1.5, must not be decreased below 1). + * + */ +#ifndef OPENTHREAD_CONFIG_COAP_ACK_RANDOM_FACTOR_DENOMINATOR +#define OPENTHREAD_CONFIG_COAP_ACK_RANDOM_FACTOR_DENOMINATOR 2 +#endif + +/** + * @def OPENTHREAD_CONFIG_COAP_MAX_RETRANSMIT + * + * Maximum number of retransmissions for CoAP Confirmable messages (RFC7252 default value is 4). + * + */ +#ifndef OPENTHREAD_CONFIG_COAP_MAX_RETRANSMIT +#define OPENTHREAD_CONFIG_COAP_MAX_RETRANSMIT 4 +#endif + +/** + * @def OPENTHREAD_CONFIG_COAP_SERVER_MAX_CACHED_RESPONSES + * + * Maximum number of cached responses for CoAP Confirmable messages. + * + * Cached responses are used for message deduplication. + * + */ +#ifndef OPENTHREAD_CONFIG_COAP_SERVER_MAX_CACHED_RESPONSES +#define OPENTHREAD_CONFIG_COAP_SERVER_MAX_CACHED_RESPONSES 10 +#endif + +/** + * @def OPENTHREAD_CONFIG_COAP_API_ENABLE + * + * Define to 1 to enable the CoAP API. + * + */ +#ifndef OPENTHREAD_CONFIG_COAP_API_ENABLE +#define OPENTHREAD_CONFIG_COAP_API_ENABLE 0 +#endif + +/** + * @def OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE + * + * Define to 1 to enable the CoAP Secure API. + * + */ +#ifndef OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE +#define OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE 0 +#endif + +#endif // CONFIG_COAP_H_ diff --git a/src/core/config/openthread-core-default-config.h b/src/core/config/openthread-core-default-config.h index eebb507a5..b19e99cd5 100644 --- a/src/core/config/openthread-core-default-config.h +++ b/src/core/config/openthread-core-default-config.h @@ -429,60 +429,6 @@ #define OPENTHREAD_CONFIG_MAX_STATECHANGE_HANDLERS 1 #endif -/** - * @def OPENTHREAD_CONFIG_COAP_ACK_TIMEOUT - * - * Minimum spacing before first retransmission when ACK is not received (RFC7252 default value is 2). - * - */ -#ifndef OPENTHREAD_CONFIG_COAP_ACK_TIMEOUT -#define OPENTHREAD_CONFIG_COAP_ACK_TIMEOUT 2 -#endif - -/** - * @def OPENTHREAD_CONFIG_COAP_ACK_RANDOM_FACTOR_NUMERATOR - * - * Numerator of ACK_RANDOM_FACTOR used to calculate maximum spacing before first retransmission when - * ACK is not received (RFC7252 default value of ACK_RANDOM_FACTOR is 1.5, must not be decreased below 1). - * - */ -#ifndef OPENTHREAD_CONFIG_COAP_ACK_RANDOM_FACTOR_NUMERATOR -#define OPENTHREAD_CONFIG_COAP_ACK_RANDOM_FACTOR_NUMERATOR 3 -#endif - -/** - * @def OPENTHREAD_CONFIG_COAP_ACK_RANDOM_FACTOR_DENOMINATOR - * - * Denominator of ACK_RANDOM_FACTOR used to calculate maximum spacing before first retransmission when - * ACK is not received (RFC7252 default value of ACK_RANDOM_FACTOR is 1.5, must not be decreased below 1). - * - */ -#ifndef OPENTHREAD_CONFIG_COAP_ACK_RANDOM_FACTOR_DENOMINATOR -#define OPENTHREAD_CONFIG_COAP_ACK_RANDOM_FACTOR_DENOMINATOR 2 -#endif - -/** - * @def OPENTHREAD_CONFIG_COAP_MAX_RETRANSMIT - * - * Maximum number of retransmissions for CoAP Confirmable messages (RFC7252 default value is 4). - * - */ -#ifndef OPENTHREAD_CONFIG_COAP_MAX_RETRANSMIT -#define OPENTHREAD_CONFIG_COAP_MAX_RETRANSMIT 4 -#endif - -/** - * @def OPENTHREAD_CONFIG_COAP_SERVER_MAX_CACHED_RESPONSES - * - * Maximum number of cached responses for CoAP Confirmable messages. - * - * Cached responses are used for message deduplication. - * - */ -#ifndef OPENTHREAD_CONFIG_COAP_SERVER_MAX_CACHED_RESPONSES -#define OPENTHREAD_CONFIG_COAP_SERVER_MAX_CACHED_RESPONSES 10 -#endif - /** * @def OPENTHREAD_CONFIG_DNS_RESPONSE_TIMEOUT * @@ -1074,12 +1020,12 @@ * */ #ifndef OPENTHREAD_CONFIG_HEAP_SIZE -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #define OPENTHREAD_CONFIG_HEAP_SIZE (3072 * sizeof(void *)) #else #define OPENTHREAD_CONFIG_HEAP_SIZE (1536 * sizeof(void *)) -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE -#endif // OPENTHREAD_CONFIG_HEAP_SIZE +#endif +#endif /** * @def OPENTHREAD_CONFIG_HEAP_SIZE_NO_DTLS diff --git a/src/core/meshcop/dtls.cpp b/src/core/meshcop/dtls.cpp index 5433313a6..416aefae6 100644 --- a/src/core/meshcop/dtls.cpp +++ b/src/core/meshcop/dtls.cpp @@ -78,7 +78,7 @@ Dtls::Dtls(Instance &aInstance, bool aLayerTwoSecurity) , mMessageSubType(Message::kSubTypeNone) , mMessageDefaultSubType(Message::kSubTypeNone) { -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #ifdef MBEDTLS_KEY_EXCHANGE_PSK_ENABLED mPreSharedKey = NULL; mPreSharedKeyIdentity = NULL; @@ -97,7 +97,7 @@ Dtls::Dtls(Instance &aInstance, bool aLayerTwoSecurity) memset(&mOwnCert, 0, sizeof(mOwnCert)); memset(&mPrivateKey, 0, sizeof(mPrivateKey)); #endif // MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE memset(mCipherSuites, 0, sizeof(mCipherSuites)); memset(mPsk, 0, sizeof(mPsk)); @@ -114,13 +114,13 @@ void Dtls::FreeMbedtls(void) #ifdef MBEDTLS_SSL_COOKIE_C mbedtls_ssl_cookie_free(&mCookieCtx); #endif -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED mbedtls_x509_crt_free(&mCaChain); mbedtls_x509_crt_free(&mOwnCert); mbedtls_pk_free(&mPrivateKey); #endif // MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE mbedtls_ssl_config_free(&mConf); mbedtls_ssl_free(&mSsl); } @@ -254,19 +254,19 @@ otError Dtls::Setup(bool aClient) mbedtls_ssl_init(&mSsl); mbedtls_ssl_config_init(&mConf); -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED mbedtls_x509_crt_init(&mCaChain); mbedtls_x509_crt_init(&mOwnCert); mbedtls_pk_init(&mPrivateKey); #endif // MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE rval = mbedtls_ssl_config_defaults(&mConf, aClient ? MBEDTLS_SSL_IS_CLIENT : MBEDTLS_SSL_IS_SERVER, MBEDTLS_SSL_TRANSPORT_DATAGRAM, MBEDTLS_SSL_PRESET_DEFAULT); VerifyOrExit(rval == 0); -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE if (mVerifyPeerCertificate && mCipherSuites[0] == MBEDTLS_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8) { mbedtls_ssl_conf_authmode(&mConf, MBEDTLS_SSL_VERIFY_REQUIRED); @@ -277,7 +277,7 @@ otError Dtls::Setup(bool aClient) } #else OT_UNUSED_VARIABLE(mVerifyPeerCertificate); -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE mbedtls_ssl_conf_rng(&mConf, mbedtls_ctr_drbg_random, Random::Crypto::MbedTlsContextGet()); mbedtls_ssl_conf_min_version(&mConf, MBEDTLS_SSL_MAJOR_VERSION_3, MBEDTLS_SSL_MINOR_VERSION_3); @@ -311,12 +311,12 @@ otError Dtls::Setup(bool aClient) { rval = mbedtls_ssl_set_hs_ecjpake_password(&mSsl, mPsk, mPskLength); } -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE else { rval = SetApplicationCoapSecureKeys(); } -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE VerifyOrExit(rval == 0); mReceiveMessage = NULL; @@ -327,12 +327,12 @@ otError Dtls::Setup(bool aClient) { otLogInfoMeshCoP("DTLS started"); } -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE else { otLogInfoCoap("Application Coap Secure DTLS started"); } -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE mState = kStateConnecting; @@ -348,7 +348,7 @@ exit: return Crypto::MbedTls::MapError(rval); } -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE int Dtls::SetApplicationCoapSecureKeys(void) { int rval = 0; @@ -403,7 +403,7 @@ void Dtls::SetSslAuthMode(bool aVerifyPeerCertificate) mVerifyPeerCertificate = aVerifyPeerCertificate; } -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE void Dtls::Close(void) { @@ -450,7 +450,7 @@ exit: return error; } -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED otError Dtls::SetCertificate(const uint8_t *aX509Certificate, @@ -535,7 +535,7 @@ exit: } #endif // MBEDTLS_BASE64_C -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #ifdef MBEDTLS_SSL_SRV_C otError Dtls::SetClientId(const uint8_t *aClientId, uint8_t aLength) @@ -591,12 +591,12 @@ int Dtls::HandleMbedtlsTransmit(const unsigned char *aBuf, size_t aLength) { otLogDebgMeshCoP("Dtls::HandleMbedtlsTransmit"); } -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE else { otLogDebgCoap("Dtls::ApplicationCoapSecure HandleMbedtlsTransmit"); } -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE error = HandleDtlsSend(aBuf, static_cast(aLength), mMessageSubType); @@ -635,12 +635,12 @@ int Dtls::HandleMbedtlsReceive(unsigned char *aBuf, size_t aLength) { otLogDebgMeshCoP("Dtls::HandleMbedtlsReceive"); } -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE else { otLogDebgCoap("Dtls:: ApplicationCoapSecure HandleMbedtlsReceive"); } -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE VerifyOrExit(mReceiveMessage != NULL && mReceiveLength != 0, rval = MBEDTLS_ERR_SSL_WANT_READ); @@ -670,12 +670,12 @@ int Dtls::HandleMbedtlsGetTimer(void) { otLogDebgMeshCoP("Dtls::HandleMbedtlsGetTimer"); } -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE else { otLogDebgCoap("Dtls:: ApplicationCoapSecure HandleMbedtlsGetTimer"); } -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE if (!mTimerSet) { @@ -708,12 +708,12 @@ void Dtls::HandleMbedtlsSetTimer(uint32_t aIntermediate, uint32_t aFinish) { otLogDebgMeshCoP("Dtls::SetTimer"); } -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE else { otLogDebgCoap("Dtls::ApplicationCoapSecure SetTimer"); } -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE if (aFinish == 0) { @@ -760,12 +760,12 @@ int Dtls::HandleMbedtlsExportKeys(const unsigned char *aMasterSecret, { otLogDebgMeshCoP("Generated KEK"); } -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE else { otLogDebgCoap("ApplicationCoapSecure Generated KEK"); } -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE return 0; } diff --git a/src/core/meshcop/dtls.hpp b/src/core/meshcop/dtls.hpp index e07e1e0da..31a56bba7 100644 --- a/src/core/meshcop/dtls.hpp +++ b/src/core/meshcop/dtls.hpp @@ -41,7 +41,7 @@ #include #include -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED #include #include @@ -49,7 +49,7 @@ #include #include #endif // MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #include "common/locator.hpp" #include "common/message.hpp" @@ -71,11 +71,11 @@ public: { kPskMaxLength = 32, kGuardTimeNewConnectionMilli = 2000, -#if !OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if !OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE kApplicationDataMaxLength = 512, #else kApplicationDataMaxLength = OPENTHREAD_CONFIG_DTLS_APPLICATION_DATA_MAX_LENGTH, -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE }; enum State @@ -247,7 +247,7 @@ public: */ otError SetPsk(const uint8_t *aPsk, uint8_t aPskLength); -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #ifdef MBEDTLS_KEY_EXCHANGE_PSK_ENABLED /** * This method sets the Pre-Shared Key (PSK) for DTLS sessions- @@ -333,7 +333,7 @@ public: * */ void SetSslAuthMode(bool aVerifyPeerCertificate); -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #ifdef MBEDTLS_SSL_SRV_C /** @@ -393,7 +393,7 @@ private: void FreeMbedtls(void); otError Setup(bool aClient); -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE /** * Set keys and/or certificates for dtls session dependent of used cipher suite. * @@ -401,7 +401,7 @@ private: * */ int SetApplicationCoapSecureKeys(void); -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE static void HandleMbedtlsDebug(void *ctx, int level, const char *file, int line, const char *str); @@ -450,7 +450,7 @@ private: uint8_t mPsk[kPskMaxLength]; uint8_t mPskLength; -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED const uint8_t * mCaChainSrc; @@ -470,7 +470,7 @@ private: uint16_t mPreSharedKeyLength; uint16_t mPreSharedKeyIdLength; #endif // MBEDTLS_KEY_EXCHANGE_PSK_ENABLED -#endif // OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE bool mVerifyPeerCertificate; diff --git a/src/core/openthread-core-config.h b/src/core/openthread-core-config.h index bfb63f80e..fc1b835c3 100644 --- a/src/core/openthread-core-config.h +++ b/src/core/openthread-core-config.h @@ -49,8 +49,9 @@ #include "config/channel_manager.h" #include "config/channel_monitor.h" #include "config/child_supervision.h" +#include "config/coap.h" -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE || OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE || \ +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE || OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE || \ OPENTHREAD_ENABLE_COMMISSIONER || OPENTHREAD_ENABLE_JOINER #define OPENTHREAD_CONFIG_DTLS_ENABLE 1 #endif diff --git a/third_party/mbedtls/mbedtls-config.h b/third_party/mbedtls/mbedtls-config.h index 96c195ff9..396d8ea47 100644 --- a/third_party/mbedtls/mbedtls-config.h +++ b/third_party/mbedtls/mbedtls-config.h @@ -76,13 +76,12 @@ #define MBEDTLS_SSL_PROTO_DTLS #define MBEDTLS_SSL_TLS_C -#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE || OPENTHREAD_ENABLE_COMMISSIONER || \ - OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE || OPENTHREAD_ENABLE_COMMISSIONER || OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #define MBEDTLS_SSL_COOKIE_C #define MBEDTLS_SSL_SRV_C #endif -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED #define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED #endif @@ -121,7 +120,7 @@ #define MBEDTLS_MEMORY_BUFFER_ALLOC_C #endif -#if OPENTHREAD_ENABLE_APPLICATION_COAP_SECURE +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE #define MBEDTLS_SSL_MAX_CONTENT_LEN 900 /**< Maxium fragment length in bytes */ #else #define MBEDTLS_SSL_MAX_CONTENT_LEN 768 /**< Maxium fragment length in bytes */