diff --git a/sys/include/net/unicoap.h b/sys/include/net/unicoap.h index 58e9126686..aaa82135d0 100644 --- a/sys/include/net/unicoap.h +++ b/sys/include/net/unicoap.h @@ -10,6 +10,7 @@ #pragma once #include "net/unicoap/constants.h" /* IWYU pragma: export */ +#include "net/unicoap/config.h" /* IWYU pragma: export */ #include "net/unicoap/message.h" /* IWYU pragma: export */ /** diff --git a/sys/include/net/unicoap/config.h b/sys/include/net/unicoap/config.h new file mode 100644 index 0000000000..f25eb077f0 --- /dev/null +++ b/sys/include/net/unicoap/config.h @@ -0,0 +1,163 @@ +/* + * Copyright (C) 2024-2025 Carl Seifert + * Copyright (C) 2024-2025 TU Dresden + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License v2.1. See the file LICENSE in the top level directory for + * more details. + */ + +#pragma once + +#include + +#include "modules.h" + +/** + * @defgroup net_unicoap_config unicoap Compile-Time Configuration + * @ingroup net_unicoap + * @ingroup config + * @brief Customize limits and capabilities of unicoap + * @{ + */ + +/** + * @file + * @brief Compile-time configuration parameters + * @author Carl Seifert + */ + +/* MARK: - Essentials */ +/** + * @name Essentials + * @{ + */ +/** + * @brief Enables debug logging in all `unicoap` source files, except where locally overwritten + * + * **Default**: enabled + */ +#if !defined(CONFIG_UNICOAP_DEBUG_LOGGING) || defined(DOXYGEN) +# define CONFIG_UNICOAP_DEBUG_LOGGING 0 +#endif +/** @} */ + +/* MARK: - Limits */ +/** + * @name Limits + * @{ + */ +/** + * @brief Maximum number of options that can be present in a request or response + * + * **Default**: 16 options + */ +#if !defined(CONFIG_UNICOAP_OPTIONS_MAX) || defined(DOXYGEN) +# define CONFIG_UNICOAP_OPTIONS_MAX (16) +#endif + +/** + * @brief Default buffer capacity unicoap chooses when you invoke @ref UNICOAP_OPTIONS_ALLOC_DEFAULT + * + * Options are stored in a contiguous memory region according to the format specified in + * [RFC 7252, Section 3.1](https://datatracker.ietf.org/doc/html/rfc7252#section-3.1). + * This parameter does not affect @ref UNICOAP_OPTIONS_ALLOC. + * + * **Default**: 32 bytes + */ +#if !defined(CONFIG_UNICOAP_OPTIONS_BUFFER_DEFAULT_CAPACITY) || defined(DOXYGEN) +# define CONFIG_UNICOAP_OPTIONS_BUFFER_DEFAULT_CAPACITY (32) +#endif + +/** + * @brief Size of buffer unicoap allocates for a CoAP message header, + * including token length. + */ +#define UNICOAP_HEADER_SIZE_MAX (15) +/* MARK: unicoap_driver_extension_point */ +/* Developer note: If you are adding another CoAP driver, you may need to increase this value. */ + +/** + * @brief Maximum length of a token received from a client + * + * **Default**: 8 bytes + */ +#if !defined(CONFIG_UNICOAP_EXTERNAL_TOKEN_LENGTH_MAX) || defined(DOXYGEN) +# define CONFIG_UNICOAP_EXTERNAL_TOKEN_LENGTH_MAX (8) +#endif + +static_assert(CONFIG_UNICOAP_EXTERNAL_TOKEN_LENGTH_MAX > 0, + "CONFIG_UNICOAP_EXTERNAL_TOKEN_LENGTH_MAX must not be zero"); + +/** + * @brief Length of tokens generated by the unicoap client API + * + * **Default**: 2 bytes + */ +#if !defined(CONFIG_UNICOAP_GENERATED_TOKEN_LENGTH) || defined(DOXYGEN) +# define CONFIG_UNICOAP_GENERATED_TOKEN_LENGTH (2) +#endif + +static_assert(CONFIG_UNICOAP_GENERATED_TOKEN_LENGTH > 0, + "CONFIG_UNICOAP_GENERATED_TOKEN_LENGTH must not be zero"); + +/** + * @brief Numbers of bits needed to represent a given ETag's length + */ +#define UNICOAP_ETAG_LENGTH_FIXED_WIDTH 4 +/** @} */ + +/* MARK: - Timing */ +/** + * @name Timing + * + * These parameters are defined as being configurable in [RFC 7252, section 4.8.1] + * (https://tools.ietf.org/html/rfc7252#section-4.8.1). + * @{ + */ + +/** + * @brief `NSTART` constant for multicast delay calculation + */ +#define UNICOAP_NSTART (1) + +/** + * @brief `DEFAULT_LEISURE` constant for multicast delay calculation + */ +#define UNICOAP_DEFAULT_LEISURE (5) +/** @} */ + +/* MARK: - Resource observation */ +/** + * @name Resource observation + * @{ + */ +/** + * @brief Width in bytes of the Observe option value for a notification + * + * **Maximum allowed value**: 3 bytes + */ +#if !defined(CONFIG_UNICOAP_OBSERVE_VALUE_WIDTH) || defined(DOXYGEN) +# define CONFIG_UNICOAP_OBSERVE_VALUE_WIDTH (3) +#endif + +/** + * @brief See @ref CONFIG_UNICOAP_OBSERVE_VALUE_WIDTH + */ +#if (CONFIG_UNICOAP_OBSERVE_VALUE_WIDTH == 3) +# define UNICOAP_OBS_TICK_EXPONENT (0) +#elif (CONFIG_UNICOAP_OBSERVE_VALUE_WIDTH == 2) +# define UNICOAP_OBS_TICK_EXPONENT (6) +#elif (CONFIG_UNICOAP_OBSERVE_VALUE_WIDTH == 1) +# define UNICOAP_OBS_TICK_EXPONENT (14) +#else +# error CONFIG_UNICOAP_OBSERVE_VALUE_WIDTH must not exceed 3 +#endif +/** @} */ + +#ifdef __cplusplus +extern "C" { +} +#endif + +/** @} */ diff --git a/sys/net/application_layer/Kconfig b/sys/net/application_layer/Kconfig index 0f521861fe..2e27157f85 100644 --- a/sys/net/application_layer/Kconfig +++ b/sys/net/application_layer/Kconfig @@ -6,6 +6,7 @@ # menu "CoAP" +rsource "unicoap/Kconfig" rsource "Kconfig.coap" rsource "gcoap/Kconfig" rsource "nanocoap/Kconfig" diff --git a/sys/net/application_layer/unicoap/Kconfig b/sys/net/application_layer/unicoap/Kconfig new file mode 100644 index 0000000000..94fec6d92c --- /dev/null +++ b/sys/net/application_layer/unicoap/Kconfig @@ -0,0 +1,61 @@ +menu "CoAP Unified Suite (unicoap)" + depends on USEMODULE_UNICOAP + + comment "******************" + comment "SUITE" + + menu "Buffers" + + config UNICOAP_OPTIONS_MAX + int "Maximum number of options in a message" + range 0 9999999 + default 16 + help + Maximum number of options that can be present in a request or response + + config UNICOAP_OPTIONS_BUFFER_DEFAULT_CAPACITY + int "Default option buffer capacity (bytes)" + range 0 9999999 + default 32 + help + Default buffer capacity unicoap chooses when you invoke @ref UNICOAP_OPTIONS_ALLOC + + config UNICOAP_EXTERNAL_TOKEN_LENGTH_MAX + int "Maximum length of a token received from a client (bytes)" + range 1 8 + default 8 + help + External = generated by another node + + config UNICOAP_GENERATED_TOKEN_LENGTH + int "Length of generated tokens (bytes)" + range 1 8 + default 2 + help + Generated = generated by unicoap + + endmenu + + menu "Behaviors" + + config UNICOAP_DEBUG_LOGGING + bool "Enable debug logging" + default n + help + When enabled, debug logs are printed. Helps trace messages through layers. + + endmenu + + comment "******************" + comment "EXTENSIONS" + + menu "Resource Observation" + + config UNICOAP_OBSERVE_VALUE_WIDTH + int "Observe option value width (bytes)" + range 1 3 + default 3 + + endmenu + +endmenu # unicoap