[mbedtls] split builtin mbedtls management option from mbedtls build option (#4473)

Add a new OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT flag to
configure builtin mbedtls buffer/debug management separately from the
existing flag which configures the inclusion of the builtin mbedtls
library in the build.
This commit is contained in:
amosolgo-lutron
2020-01-23 08:41:07 -08:00
committed by Jonathan Hui
parent a5369eaa98
commit 1f9118834a
4 changed files with 25 additions and 7 deletions
+4
View File
@@ -209,6 +209,10 @@ ifeq ($(DISABLE_BUILTIN_MBEDTLS),1)
configure_OPTIONS += --disable-builtin-mbedtls
endif
ifneq ($(BUILTIN_MBEDTLS_MANAGEMENT),)
COMMONCFLAGS += -DOPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT=$(BUILTIN_MBEDTLS_MANAGEMENT)
endif
ifeq ($(DISABLE_EXECUTABLE),1)
configure_OPTIONS += --enable-executable=no
endif
+3 -3
View File
@@ -45,7 +45,7 @@
#include <openthread/config.h>
#if !OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS && PLATFORM_OPENTHREAD_VANILLA
#if !OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT && PLATFORM_OPENTHREAD_VANILLA
#include <mbedtls/platform.h>
#include <mbedtls/threading.h>
@@ -79,7 +79,7 @@ void otSysInit(int argc, char *argv[])
NRF_POWER->DCDCEN = 1;
#endif
#if !OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS && PLATFORM_OPENTHREAD_VANILLA
#if !OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT && PLATFORM_OPENTHREAD_VANILLA
mbedtls_platform_set_calloc_free(otHeapCAlloc, otHeapFree);
mbedtls_platform_setup(NULL);
#endif
@@ -146,7 +146,7 @@ void otSysDeinit(void)
nrf5LogDeinit();
#endif
#if !OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS && PLATFORM_OPENTHREAD_VANILLA
#if !OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT && PLATFORM_OPENTHREAD_VANILLA
mbedtls_platform_teardown(NULL);
#endif
}
@@ -242,6 +242,20 @@
#define OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS 1
#endif
/**
* @def OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT
*
* Define as 1 to enable bultin mbedtls management.
*
* OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT determines whether to manage mbedTLS memory
* allocation and debug config internally. If not configured, the default is to enable builtin
* management if builtin mbedtls is enabled and disable it otherwise.
*
*/
#ifndef OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT
#define OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS
#endif
/**
* @def OPENTHREAD_CONFIG_HEAP_INTERNAL_SIZE
*
+4 -4
View File
@@ -49,7 +49,7 @@
namespace ot {
namespace Crypto {
#if !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE && OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS
#if !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE && OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT
static void *CAlloc(size_t aCount, size_t aSize)
{
@@ -61,17 +61,17 @@ static void Free(void *aPointer)
Instance::Get().HeapFree(aPointer);
}
#endif // !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE && OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS
#endif // !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE && OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT
MbedTls::MbedTls(void)
{
#if !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE && OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS
#if !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE && OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT
#ifdef MBEDTLS_DEBUG_C
// mbedTLS's debug level is almost the same as OpenThread's
mbedtls_debug_set_threshold(OPENTHREAD_CONFIG_LOG_LEVEL);
#endif
mbedtls_platform_set_calloc_free(CAlloc, Free);
#endif // !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE && OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS
#endif // !OPENTHREAD_CONFIG_MULTIPLE_INSTANCE_ENABLE && OPENTHREAD_CONFIG_ENABLE_BUILTIN_MBEDTLS_MANAGEMENT
}
otError MbedTls::MapError(int rval)