Skip to content

Commit 6653fd9

Browse files
mniestrojcarlescufi
authored andcommitted
modules: mbedtls: set mbedTLS debug threshold during module initialization
mbedTLS library threshold initialization was done in native TLS socket implementation (which tends to use mbedTLS now) and inside mbedTLS benchmark test. Move that to mbedTLS module initialization, as this is a global setting. Update description of CONFIG_MBEDTLS_DEBUG_LEVEL to clarify when mbedtls_debug_set_threshold() is called. Signed-off-by: Marcin Niestroj <[email protected]>
1 parent a418ad4 commit 6653fd9

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

modules/mbedtls/Kconfig

+3
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ config MBEDTLS_DEBUG_LEVEL
108108
3 Information
109109
4 Verbose
110110

111+
This makes Zephyr call mbedtls_debug_set_threshold() function during
112+
mbedTLS initialization, with the configured debug log level.
113+
111114
config MBEDTLS_MEMORY_DEBUG
112115
bool "mbed TLS memory debug activation"
113116
depends on MBEDTLS_BUILTIN

modules/mbedtls/zephyr_init.c

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <zephyr/random/rand32.h>
1717
#include <mbedtls/entropy.h>
1818

19+
#include <mbedtls/debug.h>
20+
1921
#if defined(CONFIG_MBEDTLS)
2022
#if !defined(CONFIG_MBEDTLS_CFG_FILE)
2123
#include "mbedtls/config.h"
@@ -85,6 +87,10 @@ static int _mbedtls_init(const struct device *device)
8587

8688
init_heap();
8789

90+
#if defined(CONFIG_MBEDTLS_DEBUG_LEVEL)
91+
mbedtls_debug_set_threshold(CONFIG_MBEDTLS_DEBUG_LEVEL);
92+
#endif
93+
8894
return 0;
8995
}
9096

subsys/net/lib/sockets/sockets_tls.c

-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ LOG_MODULE_REGISTER(net_sock_tls, CONFIG_NET_SOCKETS_LOG_LEVEL);
4545
#include <mbedtls/ssl.h>
4646
#include <mbedtls/ssl_cookie.h>
4747
#include <mbedtls/error.h>
48-
#include <mbedtls/debug.h>
4948
#include <mbedtls/platform.h>
5049
#include <mbedtls/ssl_cache.h>
5150
#endif /* CONFIG_MBEDTLS */
@@ -312,10 +311,6 @@ static int tls_init(const struct device *unused)
312311

313312
k_mutex_init(&context_lock);
314313

315-
#if defined(MBEDTLS_DEBUG_C) && (CONFIG_NET_SOCKETS_LOG_LEVEL >= LOG_LEVEL_DBG)
316-
mbedtls_debug_set_threshold(CONFIG_MBEDTLS_DEBUG_LEVEL);
317-
#endif
318-
319314
#if defined(MBEDTLS_SSL_CACHE_C)
320315
mbedtls_ssl_cache_init(&server_cache);
321316
#endif

tests/benchmarks/mbedtls/src/benchmark.c

-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ void main(void)
309309

310310
printk("\tMBEDTLS Benchmark sample\n");
311311

312-
mbedtls_debug_set_threshold(CONFIG_MBEDTLS_DEBUG_LEVEL);
313312
#if defined(MBEDTLS_PLATFORM_PRINTF_ALT)
314313
mbedtls_platform_set_printf(MBEDTLS_PRINT);
315314
#endif

0 commit comments

Comments
 (0)