From 4803f161f01fdae45ba4760eb4f57aa19eea30b9 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Wed, 2 Oct 2024 08:50:06 +0100 Subject: [PATCH] zephyr: Examples support New examples/zephyr directory that contains a sample coap-client. Building the coap-client assumes that the zephyrproject has already been installed and set up (default directory ~/zephyrproject). --- BUILDING | 8 + CMakeLists.txt | 24 ++- examples/zephyr/.gitignore | 2 + examples/zephyr/Makefile | 16 ++ examples/zephyr/README | 12 ++ examples/zephyr/client-src/CMakeLists.txt | 9 + examples/zephyr/client-src/Kconfig | 33 ++++ examples/zephyr/client-src/prj.conf | 44 +++++ examples/zephyr/client-src/src/main.c | 212 ++++++++++++++++++++++ src/coap_mbedtls.c | 6 +- zephyr/CMakeLists.txt | 14 ++ zephyr/Kconfig | 63 ++++++- zephyr/config-mbedtls-libcoap.h | 15 ++ zephyr/libcoap-mbedtls.conf | 16 ++ zephyr/libcoap.conf | 4 - 15 files changed, 462 insertions(+), 16 deletions(-) create mode 100644 examples/zephyr/.gitignore create mode 100644 examples/zephyr/Makefile create mode 100644 examples/zephyr/README create mode 100644 examples/zephyr/client-src/CMakeLists.txt create mode 100644 examples/zephyr/client-src/Kconfig create mode 100644 examples/zephyr/client-src/prj.conf create mode 100644 examples/zephyr/client-src/src/main.c create mode 100644 zephyr/libcoap-mbedtls.conf delete mode 100644 zephyr/libcoap.conf diff --git a/BUILDING b/BUILDING index a3422119..6dc5f97e 100644 --- a/BUILDING +++ b/BUILDING @@ -142,6 +142,14 @@ Contiki-NG Executable is ./server.native. See examples/contiki/README for further information. +Zephyr +====== + + cd examples/zephyr + make + +See examples/zephyr/README for further information. + Windows ======= diff --git a/CMakeLists.txt b/CMakeLists.txt index d33eb72d..9d1e14f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,15 +25,16 @@ option( BUILD_SHARED_LIBS "Build shared libs" OFF) -else() +else() # ! ZEPHYR_BASE # provided by the zephyr build system -endif() +endif() # ! ZEPHYR_BASE # # global compiler options # (need to do it before add_library()) # +if(NOT ZEPHYR_BASE) add_compile_options( $<$,$,$>:-pedantic> $<$,$,$>:-Wall> @@ -51,6 +52,9 @@ add_compile_options( $<$,$,$>:-Wswitch-enum> $<$,$,$>:-Wunused> $<$,$,$>:-Wwrite-strings>) +else() # ! ZEPHYR_BASE + # provided by the zephyr build system +endif() # ! ZEPHYR_BASE if(MINGW) add_compile_options( @@ -76,7 +80,9 @@ endif() # add_library(${COAP_LIBRARY_NAME}) -set_property(TARGET ${COAP_LIBRARY_NAME} PROPERTY C_STANDARD 99) +if(NOT ZEPHYR_BASE) +# set_property(TARGET ${COAP_LIBRARY_NAME} PROPERTY C_STANDARD 99) +endif() # ! ZEPHYR_BASE if(${CMAKE_VERSION} VERSION_GREATER "3.20.0") cmake_policy(SET CMP0115 OLD) # Supresses libcoap configuration warning endif() @@ -392,7 +398,6 @@ else() message(STATUS "compiling without Q-Block (RFC9177) support") endif() - if(${WITH_OBSERVE_PERSIST}) set(COAP_WITH_OBSERVE_PERSIST "1") message(STATUS "compiling with observe persistence support") @@ -413,17 +418,17 @@ else() message(STATUS "compiling without epoll support") endif() -if(ENABLE_THREAD_SAFE) +if(${ENABLE_THREAD_SAFE}) set(COAP_THREAD_SAFE "${ENABLE_THREAD_SAFE}") message(STATUS "compiling with thread safe support") endif() -if(ENABLE_THREAD_RECURSIVE_LOCK_CHECK) +if(${ENABLE_THREAD_RECURSIVE_LOCK_CHECK}) set(COAP_THREAD_RECURSIVE_CHECK "${ENABLE_THREAD_RECURSIVE_LOCK_CHECK}") message(STATUS "compiling with thread recursive lock detection support") endif() -if(ENABLE_SMALL_STACK) +if(${ENABLE_SMALL_STACK}) set(COAP_CONSTRAINED_STACK "${ENABLE_SMALL_STACK}") message(STATUS "compiling with small stack support") endif() @@ -646,6 +651,7 @@ if(WITH_WOLFSSL) endif() execute_process(COMMAND git describe --tags --dirty --always + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} RESULT_VARIABLE USING_GIT OUTPUT_VARIABLE LIBCOAP_PACKAGE_BUILD OUTPUT_STRIP_TRAILING_WHITESPACE @@ -847,7 +853,7 @@ if(ZEPHYR_BASE) target_compile_options( ${COAP_LIBRARY_NAME} PUBLIC -DMBEDTLS_CONFIG_FILE="${CONFIG_MBEDTLS_CFG_FILE}" -I${ZEPHYR_MBEDTLS_CMAKE_DIR}/configs) -endif() +endif() # ! ZEPHYR_BASE add_library( ${PROJECT_NAME}::${COAP_LIBRARY_NAME} @@ -984,7 +990,7 @@ install( DESTINATION ${LIBCOAP_CONFIG_INSTALL_DIR} NAMESPACE ${PROJECT_NAME}:: COMPONENT dev) -endif() +endif() # ! ZEPHYR_BASE configure_package_config_file( cmake/Config.cmake.in diff --git a/examples/zephyr/.gitignore b/examples/zephyr/.gitignore new file mode 100644 index 00000000..5e0f3398 --- /dev/null +++ b/examples/zephyr/.gitignore @@ -0,0 +1,2 @@ +# never objects, and not the resulting binary +coap-client diff --git a/examples/zephyr/Makefile b/examples/zephyr/Makefile new file mode 100644 index 00000000..fac278bb --- /dev/null +++ b/examples/zephyr/Makefile @@ -0,0 +1,16 @@ +ZEPHYR_PROJECT?=~/zephyrproject + +all: coap-client + +coap-client: client-src/src/main.c client-src/* + LIBCOAP_DIR=`pwd`/../.. ;\ + (. $(ZEPHYR_PROJECT)/.venv/bin/activate ;\ + cd $(ZEPHYR_PROJECT)/zephyr ;\ + west build -p always -b native_sim \ + $${LIBCOAP_DIR}/examples/zephyr/client-src -- \ + -DCONF_FILE=prj.conf \ + -DEXTRA_ZEPHYR_MODULES=$${LIBCOAP_DIR} \ + -DEXTRA_CONF_FILE=$${LIBCOAP_DIR}/zephyr/libcoap-mbedtls.conf \ + --fresh ;\ + deactivate) ;\ + cp -f $(ZEPHYR_PROJECT)/zephyr/build/zephyr/zephyr.exe coap-client diff --git a/examples/zephyr/README b/examples/zephyr/README new file mode 100644 index 00000000..0ec393d0 --- /dev/null +++ b/examples/zephyr/README @@ -0,0 +1,12 @@ +Example of libcoap running in Zephyr +==================================== + +The Zephyr project environment needs to be pre-installed. By default, the +libcoap Makefile assumes that this is located at ~/zephyrproject . + +To build the coap-client example, do + + $ make + +The executable gets built in ~/zephyrproject/zephyr/build/zephyr/zephyr.exe +which is then copied to coap-client . diff --git a/examples/zephyr/client-src/CMakeLists.txt b/examples/zephyr/client-src/CMakeLists.txt new file mode 100644 index 00000000..2a7e9f06 --- /dev/null +++ b/examples/zephyr/client-src/CMakeLists.txt @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.20.0) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(coap_client) + +target_sources(app PRIVATE src/main.c) + +include(${ZEPHYR_BASE}/samples/net/common/common.cmake) diff --git a/examples/zephyr/client-src/Kconfig b/examples/zephyr/client-src/Kconfig new file mode 100644 index 00000000..257c28b2 --- /dev/null +++ b/examples/zephyr/client-src/Kconfig @@ -0,0 +1,33 @@ +# Private config options for coap-client sample app + +# Copyright (c) 2020 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +mainmenu "Networking coap-client sample application" + +config LIBCOAP_TARGET_DOMAIN_URI + string "Target Uri" + default "coaps://libcoap.net" + help + Target uri for the example to use. Use coaps:// prefix for encrypted traffic + using Pre-Shared Key (PSK) or Public Key Infrastructure (PKI). + +if MBEDTLS +config LIBCOAP_PSK_KEY + string "Preshared Key (PSK) to used in the connection to the CoAP server" + default "secretPSK" + help + The Preshared Key to use to encrypt the communicatons. The same key must be + used at both ends of the CoAP connection, and the CoaP client must request + an URI prefixed with coaps:// instead of coap:// for DTLS to be used. + +config LIBCOAP_PSK_IDENTITY + string "PSK Client identity (username)" + default "user" + help + The identity (or username) to use to identify to the CoAP server which + PSK key to use. + +endif # MBEDTLS + +source "Kconfig.zephyr" diff --git a/examples/zephyr/client-src/prj.conf b/examples/zephyr/client-src/prj.conf new file mode 100644 index 00000000..31b42b9d --- /dev/null +++ b/examples/zephyr/client-src/prj.conf @@ -0,0 +1,44 @@ +CONFIG_NETWORKING=y +CONFIG_NET_UDP=y +CONFIG_NET_TCP=y +CONFIG_NET_IPV6=y +CONFIG_NET_IPV4=y +#CONFIG_NET_DHCPV4=y + +CONFIG_ENTROPY_GENERATOR=y +CONFIG_TEST_RANDOM_GENERATOR=y +CONFIG_INIT_STACKS=y + +CONFIG_NET_LOG=y +CONFIG_LOG=y + +CONFIG_NET_STATISTICS=y + +CONFIG_NET_PKT_RX_COUNT=32 +CONFIG_NET_PKT_TX_COUNT=32 +CONFIG_NET_BUF_RX_COUNT=32 +CONFIG_NET_BUF_TX_COUNT=32 + +CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT=3 +CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT=4 +CONFIG_NET_MAX_CONTEXTS=10 + +CONFIG_NET_SHELL=y + +CONFIG_NET_CONFIG_SETTINGS=y +CONFIG_NET_CONFIG_NEED_IPV6=y +CONFIG_NET_CONFIG_NEED_IPV4=y +CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1" +CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2" +CONFIG_NET_CONFIG_MY_IPV4_ADDR="192.0.2.1" +CONFIG_NET_CONFIG_PEER_IPV4_ADDR="192.0.2.2" + +CONFIG_NET_L2_ETHERNET=y + +CONFIG_ETH_NATIVE_POSIX=y +CONFIG_ETH_NATIVE_POSIX_RANDOM_MAC=y +#CONFIG_ETH_NATIVE_POSIX_MAC_ADDR="00:00:5e:00:53:2a" + +CONFIG_LIBCOAP=y + +CONFIG_HEAP_MEM_POOL_SIZE=16384 diff --git a/examples/zephyr/client-src/src/main.c b/examples/zephyr/client-src/src/main.c new file mode 100644 index 00000000..8a7685d6 --- /dev/null +++ b/examples/zephyr/client-src/src/main.c @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2018 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +LOG_MODULE_REGISTER(coap_client, LOG_LEVEL_DBG); + +#include +#include +#include "coap3/coap.h" +#include + +#include + +#ifdef CONFIG_MBEDTLS +#define COAP_USE_PSK CONFIG_LIBCOAP_PSK_KEY +#define COAP_USE_PSK_ID CONFIG_LIBCOAP_PSK_IDENTITY +#endif /* CONFIG_MBEDTLS */ +#define COAP_TARGET_DOMAIN_URI CONFIG_LIBCOAP_TARGET_DOMAIN_URI + +const char *coap_uri = COAP_TARGET_DOMAIN_URI; + +static int quit; + +static int resolve_address(const char *host, const char *service, coap_address_t *dst, + int scheme_hint_bits) +{ + uint16_t port = service ? atoi(service) : 0; + int ret = 0; + coap_str_const_t str_host; + coap_addr_info_t *addr_info; + + str_host.s = (const uint8_t *)host; + str_host.length = strlen(host); + addr_info = coap_resolve_address_info(&str_host, port, port, port, port, AF_UNSPEC, + scheme_hint_bits, COAP_RESOLVE_TYPE_REMOTE); + if (addr_info) { + ret = 1; + *dst = addr_info->addr; + } + + coap_free_address_info(addr_info); + return ret; +} + +static coap_response_t message_handler(coap_session_t *session, const coap_pdu_t *sent, + const coap_pdu_t *received, const coap_mid_t id) +{ + const uint8_t *data; + size_t len; + size_t offset; + size_t total; + + (void)session; + (void)sent; + (void)id; + if (coap_get_data_large(received, &len, &data, &offset, &total)) { + printf("%*.*s", (int)len, (int)len, (const char *)data); + if (len + offset == total) { + printf("\n"); + quit = 1; + } + } + return COAP_RESPONSE_OK; +} + +static int coap_client_init(coap_context_t *ctx) +{ + coap_session_t *session = NULL; + coap_pdu_t *pdu; + coap_address_t dst; + coap_mid_t mid; + int len; + coap_uri_t uri; + char portbuf[8]; + coap_optlist_t *optlist = NULL; + +#define BUFSIZE 100 + unsigned char buf[BUFSIZE]; + int res; + + /* Parse the URI */ + len = coap_split_uri((const unsigned char *)coap_uri, strlen(coap_uri), &uri); + if (len != 0) { + coap_log_warn("Failed to parse uri %s\n", coap_uri); + goto fail; + } + + snprintf(portbuf, sizeof(portbuf), "%d", uri.port); + snprintf((char *)buf, sizeof(buf), "%*.*s", (int)uri.host.length, (int)uri.host.length, + (const char *)uri.host.s); + /* resolve destination address where packet should be sent */ + len = resolve_address((const char *)buf, portbuf, &dst, 1 << uri.scheme); + if (len <= 0) { + coap_log_warn("Failed to resolve address %*.*s\n", (int)uri.host.length, + (int)uri.host.length, (const char *)uri.host.s); + goto fail; + } + + if (uri.scheme == COAP_URI_SCHEME_COAP) { + session = coap_new_client_session(ctx, NULL, &dst, COAP_PROTO_UDP); + } else if (uri.scheme == COAP_URI_SCHEME_COAP_TCP) { + goto fail; + } else if (uri.scheme == COAP_URI_SCHEME_COAPS_TCP) { + goto fail; + } else if (uri.scheme == COAP_URI_SCHEME_COAPS) { +#if defined(COAP_USE_PSK) && defined(COAP_USE_PSK_ID) + static coap_dtls_cpsk_t dtls_psk; + static char client_sni[256]; + + memset(client_sni, 0, sizeof(client_sni)); + memset(&dtls_psk, 0, sizeof(dtls_psk)); + dtls_psk.version = COAP_DTLS_CPSK_SETUP_VERSION; + if (uri.host.length) { + memcpy(client_sni, uri.host.s, + MIN(uri.host.length, sizeof(client_sni) - 1)); + } else { + memcpy(client_sni, "localhost", 9); + } + dtls_psk.client_sni = client_sni; + dtls_psk.psk_info.identity.s = (const uint8_t *)COAP_USE_PSK_ID; + dtls_psk.psk_info.identity.length = strlen(COAP_USE_PSK_ID); + dtls_psk.psk_info.key.s = (const uint8_t *)COAP_USE_PSK; + dtls_psk.psk_info.key.length = strlen(COAP_USE_PSK); + + session = coap_new_client_session_psk2(ctx, NULL, &dst, COAP_PROTO_DTLS, &dtls_psk); +#else /* ! COAP_USE_PSK && ! COAP_USE_PSK_ID */ + coap_log_err("CONFIG_LIBCOAP_USE_PSK and CONFIG_LIBCOAP_USE_PSK_ID not defined\n"); + goto fail; +#endif /* ! COAP_USE_PSK && ! COAP_USE_PSK_ID */ + } + + if (!session) { + coap_log_warn("Failed to create session\n"); + goto fail; + } + + coap_register_response_handler(ctx, message_handler); + + /* construct CoAP message */ + pdu = coap_pdu_init(COAP_MESSAGE_CON, COAP_REQUEST_CODE_GET, coap_new_message_id(session), + coap_session_max_pdu_size(session)); + if (!pdu) { + coap_log_warn("Failed to create PDU\n"); + goto fail; + } + + len = coap_uri_into_options(&uri, &dst, &optlist, 1, buf, sizeof(buf)); + if (len) { + coap_log_warn("Failed to create options\n"); + goto fail; + } + + /* Add option list (which will be sorted) to the PDU */ + if (optlist) { + res = coap_add_optlist_pdu(pdu, &optlist); + if (res != 1) { + coap_log_warn("Failed to add options to PDU\n"); + goto fail; + } + } + + /* and send the PDU */ + mid = coap_send(session, pdu); + if (mid == COAP_INVALID_MID) { + coap_log_warn("Failed to send PDU\n"); + goto fail; + } + coap_delete_optlist(optlist); + return 1; + +fail: + coap_delete_optlist(optlist); + return 0; +} + +/* This application itself does nothing as there is net-shell that can be used + * to monitor things. + */ +int main(void) +{ + LOG_INF("Start application"); + coap_context_t *coap_context; + + /* Initialize libcoap library */ + coap_startup(); + + coap_set_log_level(COAP_MAX_LOGGING_LEVEL); + + coap_context = coap_new_context(NULL); + if (!coap_context) { + goto fail; + } + coap_context_set_block_mode(coap_context, COAP_BLOCK_USE_LIBCOAP); + + /* Set up and initiate client logic */ + coap_client_init(coap_context); + coap_log_info("libcoap test client started\n"); + + /* Keep on processing until response is back in ... */ + while (quit == 0) { + coap_io_process(coap_context, 1000); + } +fail: + /* Clean up library usage so client can be run again */ + coap_free_context(coap_context); + + coap_cleanup(); + return 0; +} diff --git a/src/coap_mbedtls.c b/src/coap_mbedtls.c index c932740e..23c34bf8 100644 --- a/src/coap_mbedtls.c +++ b/src/coap_mbedtls.c @@ -1733,9 +1733,13 @@ coap_dtls_new_mbedtls_env(coap_session_t *c_session, #endif /* ESPIDF_VERSION && CONFIG_MBEDTLS_DEBUG */ if ((ret = mbedtls_ctr_drbg_seed(&m_env->ctr_drbg, mbedtls_entropy_func, &m_env->entropy, NULL, 0)) != 0) { + if (ret != MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED) { + coap_log_info("mbedtls_ctr_drbg_seed returned -0x%x: '%s'\n", + -ret, get_error_string(ret)); + goto fail; + } coap_log_err("mbedtls_ctr_drbg_seed returned -0x%x: '%s'\n", -ret, get_error_string(ret)); - goto fail; } if (role == COAP_DTLS_ROLE_CLIENT) { diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 9d0a1300..e7c4cb93 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -33,6 +33,10 @@ if(CONFIG_LIBCOAP) else() set (ENABLE_SERVER_MODE OFF) endif() + if (NOT CONFIG_LIBCOAP_CLIENT_SUPPORT AND NOT CONFIG_LIBCOAP_SERVER_SUPPORT) + set (ENABLE_CLIENT_MODE ON) + set (ENABLE_SERVER_MODE ON) + endif() if (CONFIG_LIBCOAP_OSCORE_SUPPORT) set (ENABLE_OSCORE ON) else() @@ -78,13 +82,23 @@ if(CONFIG_LIBCOAP) else() set (ENABLE_Q_BLOCK OFF) endif() + if (CONFIG_LIBCOAP_THREAD_SAFE_SUPPORT) + set (ENABLE_THREAD_SAFE ON) + else() + set (ENABLE_THREAD_SAFE OFF) + endif() + if (CONFIG_LIBCOAP_LOG_DEFAULT_LEVEL) + set (MAX_LOGGING_LEVEL ${CONFIG_LIBCOAP_LOG_DEFAULT_LEVEL}) + endif() set (ENABLE_SMALL_STACK ON) set (ENABLE_AF_UNIX OFF) set (WITH_EPOLL OFF) set (ENABLE_TESTS OFF) set (ENABLE_EXAMPLES OFF) + set (ENABLE_DOCS OFF) set (WARNING_TO_ERROR OFF) + set (ENABLE_THREAD_RECURSIVE_LOCK_CHECK OFF) if(CONFIG_MBEDTLS) target_include_directories(mbedTLS INTERFACE ${ZEPHYR_LIBCOAP_MODULE_DIR}/include) diff --git a/zephyr/Kconfig b/zephyr/Kconfig index 86ea0ab6..17768ea8 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -85,6 +85,14 @@ config LIBCOAP_ASYNC_SUPPORT If this option is disabled, redundent CoAP async separate responses code is removed. +config LIBCOAP_THREAD_SAFE_SUPPORT + bool "Enable thread safe support within CoAP" + default y + help + Enable thread safe support functionality for CoAP. + + If this option is disabled, multi-thread safe use of libcoap is not available. + config LIBCOAP_CLIENT_SUPPORT bool "Enable Client functionality within CoAP" default n @@ -111,6 +119,57 @@ config LIBCOAP_SERVER_SUPPORT If both this option and LIBCOAP_CLIENT_SUPPORT are disabled, then both are automatically enabled for backwards compatability. +config LIBCOAP_DEBUGGING + bool "Enable CoAP debugging" + default y + help + Enable CoAP debugging functions at compile time for the example code. + + If this option is enabled, call coap_set_log_level() + at runtime in order to enable CoAP debug output. + +choice LIBCOAP_DEBUGGING_LEVEL + bool "Set CoAP debugging level" + depends on LIBCOAP_DEBUGGING + default LIBCOAP_LOG_DEBUG + help + Set CoAP debugging level + + Note: reducing the logging level also reduces the code size. + + config LIBCOAP_LOG_EMERG + bool "Emergency" + config LIBCOAP_LOG_ALERT + bool "Alert" + config LIBCOAP_LOG_CRIT + bool "Critical" + config LIBCOAP_LOG_ERROR + bool "Error" + config LIBCOAP_LOG_WARNING + bool "Warning" + config LIBCOAP_LOG_NOTICE + bool "Notice" + config LIBCOAP_LOG_INFO + bool "Info" + config LIBCOAP_LOG_DEBUG + bool "Debug" + config LIBCOAP_LOG_OSCORE + bool "OSCORE" +endchoice + +config LIBCOAP_LOG_DEFAULT_LEVEL + int + default 0 if !LIBCOAP_DEBUGGING + default 0 if LIBCOAP_LOG_EMERG + default 1 if LIBCOAP_LOG_ALERT + default 2 if LIBCOAP_LOG_CRIT + default 3 if LIBCOAP_LOG_ERROR + default 4 if LIBCOAP_LOG_WARNING + default 5 if LIBCOAP_LOG_NOTICE + default 6 if LIBCOAP_LOG_INFO + default 7 if LIBCOAP_LOG_DEBUG + default 8 if LIBCOAP_LOG_OSCORE + if MBEDTLS config MBEDTLS_CIPHER_CCM_ENABLED @@ -145,10 +204,10 @@ config MBEDTLS_KEY_EXCHANGE_ALL_ENABLED default y config MBEDTLS_CIPHER_ALL_ENABLED bool - default y + default n config MBEDTLS_ECP_ALL_ENABLED bool - default y + default n config MBEDTLS_MAC_ALL_ENABLED bool default y diff --git a/zephyr/config-mbedtls-libcoap.h b/zephyr/config-mbedtls-libcoap.h index f74d2360..a5c1af17 100644 --- a/zephyr/config-mbedtls-libcoap.h +++ b/zephyr/config-mbedtls-libcoap.h @@ -19,6 +19,18 @@ #define MBEDTLS_VERSION_C #endif /* ! MBEDTLS_VERSION_C */ +#ifndef MBEDTLS_CTR_DRBG_C +#define MBEDTLS_CTR_DRBG_C +#endif /* ! MBEDTLS_CTR_DRBG_C */ + +#ifndef MBEDTLS_AES_C +#define MBEDTLS_AES_C +#endif /* ! MBEDTLS_AES_C */ + +#ifndef MBEDTLS_ENTROPY_C +#define MBEDTLS_ENTROPY_C +#endif /* ! MBEDTLS_ENTROPY_C */ + #if defined(MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED) #ifndef MBEDTLS_CAN_ECDH #define MBEDTLS_CAN_ECDH @@ -75,6 +87,9 @@ #ifndef PSA_WANT_ECC_SECP_R1_256 #define PSA_WANT_ECC_SECP_R1_256 #endif /* ! PSA_WANT_ECC_SECP_R1_256 */ +#ifndef PMBEDTLS_ECP_DP_SECP256R1_ENABLED +#define MBEDTLS_ECP_DP_SECP256R1_ENABLED +#endif /* ! MBEDTLS_ECP_DP_SECP256R1_ENABLED */ #endif /* MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED */ #if defined(MBEDTLS_MD_C) diff --git a/zephyr/libcoap-mbedtls.conf b/zephyr/libcoap-mbedtls.conf new file mode 100644 index 00000000..69ab2f2b --- /dev/null +++ b/zephyr/libcoap-mbedtls.conf @@ -0,0 +1,16 @@ +# TLS configuration +CONFIG_MBEDTLS=y +CONFIG_MBEDTLS_BUILTIN=y +CONFIG_MBEDTLS_ENABLE_HEAP=y +CONFIG_MBEDTLS_HEAP_SIZE=60000 +CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=2048 + +CONFIG_MAIN_STACK_SIZE=3072 +CONFIG_NET_BUF_RX_COUNT=80 +CONFIG_NET_BUF_TX_COUNT=80 + +CONFIG_ZVFS_OPEN_MAX=20 +# +CONFIG_MBEDTLS_USER_CONFIG_ENABLE=y +CONFIG_MBEDTLS_USER_CONFIG_FILE="../zephyr/config-mbedtls-libcoap.h" +# diff --git a/zephyr/libcoap.conf b/zephyr/libcoap.conf deleted file mode 100644 index e2991e7a..00000000 --- a/zephyr/libcoap.conf +++ /dev/null @@ -1,4 +0,0 @@ -# -CONFIG_MBEDTLS_USER_CONFIG_ENABLE=y -CONFIG_MBEDTLS_USER_CONFIG_FILE="../zephyr/config-mbedtls-libcoap.h" -#