From a4d7c29313a3624f4d0df791a84959f53dc0dc83 Mon Sep 17 00:00:00 2001 From: "Florek, Bartlomiej" Date: Wed, 25 Feb 2026 10:18:56 +0000 Subject: [PATCH] fix(config): enhance Zephyr configuration for libcoap --- include/coap3/coap_session_internal.h | 3 ++ zephyr/CMakeLists.txt | 13 +++++++-- zephyr/Kconfig | 42 +++++++++++++++++++++++++-- 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/include/coap3/coap_session_internal.h b/include/coap3/coap_session_internal.h index aa14c24e..f1948d82 100644 --- a/include/coap3/coap_session_internal.h +++ b/include/coap3/coap_session_internal.h @@ -24,7 +24,10 @@ extern "C" { #endif +#ifndef COAP_DEFAULT_SESSION_TIMEOUT #define COAP_DEFAULT_SESSION_TIMEOUT 300 +#endif /* !COAP_DEFAULT_SESSION_TIMEOUT */ + #define COAP_PARTIAL_SESSION_TIMEOUT_TICKS (30 * COAP_TICKS_PER_SECOND) #define COAP_DEFAULT_MAX_HANDSHAKE_SESSIONS 100 diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 3604931c..8a36ae6f 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -171,8 +171,17 @@ if(CONFIG_LIBCOAP) endif() add_subdirectory(.. build) - target_compile_definitions(coap-3 PUBLIC WITH_ZEPHYR) - target_compile_definitions(coap-3 PUBLIC COAP_MEMORY_TYPE_TRACK=1) + target_compile_definitions(coap-3 + PUBLIC + WITH_ZEPHYR + COAP_MEMORY_TYPE_TRACK=1 + $<$:COAP_OBS_MAX_NON=${CONFIG_LIBCOAP_OBS_MAX_NON}> + $<$:COAP_DEFAULT_MAX_PDU_RX_SIZE=${CONFIG_LIBCOAP_DEFAULT_MAX_PDU_RX_SIZE}> + $<$:COAP_RXBUFFER_SIZE=${CONFIG_LIBCOAP_RXBUFFER_SIZE}> + $<$:COAP_DEFAULT_MTU=${CONFIG_LIBCOAP_DEFAULT_MTU}> + $<$:COAP_DEFAULT_SESSION_TIMEOUT=${CONFIG_LIBCOAP_DEFAULT_SESSION_TIMEOUT}> + ) + target_link_libraries(coap-3 PUBLIC zephyr_interface) set_property(GLOBAL APPEND PROPERTY ZEPHYR_INTERFACE_LIBS coap-3) diff --git a/zephyr/Kconfig b/zephyr/Kconfig index e692bc65..6dd68b1b 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -83,7 +83,7 @@ config LIBCOAP_ASYNC_SUPPORT help Enable async separate responses functionality for CoAP. - If this option is disabled, redundent CoAP async separate responses code is removed. + If this option is disabled, redundant CoAP async separate responses code is removed. config LIBCOAP_THREAD_SAFE_SUPPORT bool "Enable thread safe support within CoAP" @@ -121,7 +121,7 @@ config LIBCOAP_CLIENT_SUPPORT If this option is disabled, redundant CoAP client only code is removed. If both this option and LIBCOAP_SERVER_SUPPORT are disabled, then - both are automatically enabled for backwards compatability. + both are automatically enabled for backwards compatibility. config LIBCOAP_SERVER_SUPPORT bool "Enable Server functionality within CoAP" @@ -133,7 +133,7 @@ config LIBCOAP_SERVER_SUPPORT If this option is disabled, redundant CoAP server only code is removed. If both this option and LIBCOAP_CLIENT_SUPPORT are disabled, then - both are automatically enabled for backwards compatability. + both are automatically enabled for backwards compatibility. config LIBCOAP_DEBUGGING bool "Enable CoAP debugging" @@ -186,6 +186,42 @@ config LIBCOAP_LOG_DEFAULT_LEVEL default 7 if LIBCOAP_LOG_DEBUG default 8 if LIBCOAP_LOG_OSCORE +config LIBCOAP_DEFAULT_MAX_PDU_RX_SIZE + int "Default max PDU RX size in bytes" + default 1152 + help + Maximum size of incoming CoAP PDU. RFC7252 4.6 suggests 1152. + Increase for larger block-wise transfers (e.g. 1024-4096). + +config LIBCOAP_RXBUFFER_SIZE + int "Receive buffer size in bytes" + default 1472 + help + Size of the socket receive buffer for incoming CoAP/UDP packets. + Should be at least as large as the largest expected PDU (e.g. 1472 + for typical Ethernet MTU minus headers). + +config LIBCOAP_DEFAULT_MTU + int "Default MTU in bytes" + default 1152 + help + Default path/session MTU used for CoAP (RFC7252 4.6 suggests 1152). + Used for session MTU and PDU sizing; increase for larger block-wise + transfers. + +config LIBCOAP_OBS_MAX_NON + int "Observe: max NON notifications before CON" + default 5 + range 1 255 + help + Number of NON notifications before sending a CON (RFC7641 4.5). + +config LIBCOAP_DEFAULT_SESSION_TIMEOUT + int "Default session timeout" + default 300 + help + This setting refers to the COAP_DEFAULT_SESSION_TIMEOUT, which defines server session's timeout. + if MBEDTLS config MBEDTLS_CIPHER_CCM_ENABLED