diff --git a/sys/include/net/credman.h b/sys/include/net/credman.h index 183c6f4b2d..86b30d0579 100644 --- a/sys/include/net/credman.h +++ b/sys/include/net/credman.h @@ -34,12 +34,18 @@ extern "C" { #endif +/** + * @defgroup net_credman_conf (D)TLS Credential Manager compile configurations + * @ingroup config + * @{ + */ /** * @brief Maximum number of credentials in credential pool */ -#ifndef CREDMAN_MAX_CREDENTIALS -#define CREDMAN_MAX_CREDENTIALS (2) +#ifndef CONFIG_CREDMAN_MAX_CREDENTIALS +#define CONFIG_CREDMAN_MAX_CREDENTIALS (2) #endif +/** @} */ /** * @brief Buffer of the credential @@ -173,7 +179,7 @@ void credman_delete(credman_tag_t tag, credman_type_t type); /** * @brief Gets the number of credentials currently in the credential pool * - * Maximum number of allowed credentials is defined by CREDMAN_MAX_CREDENTIALS + * Maximum number of allowed credentials is defined by CONFIG_CREDMAN_MAX_CREDENTIALS * * @return number of credentials currently in the credential pool */ diff --git a/sys/net/Kconfig b/sys/net/Kconfig index 4a3aae0696..8c6b6c7525 100644 --- a/sys/net/Kconfig +++ b/sys/net/Kconfig @@ -7,6 +7,7 @@ menu "Networking" rsource "application_layer/Kconfig" +rsource "credman/Kconfig" rsource "gnrc/Kconfig" rsource "sock/Kconfig" rsource "link_layer/Kconfig" diff --git a/sys/net/credman/Kconfig b/sys/net/credman/Kconfig new file mode 100644 index 0000000000..1131c41f12 --- /dev/null +++ b/sys/net/credman/Kconfig @@ -0,0 +1,23 @@ +# Copyright (c) 2020 Freie Universitaet Berlin +# +# 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. +# +menuconfig KCONFIG_MODULE_CREDMAN + bool "Configure CREDMAN" + depends on MODULE_CREDMAN + help + Configure CREDMAN, Credentials management module for (D)TLS, using + Kconfig. + +if KCONFIG_MODULE_CREDMAN + +config CREDMAN_MAX_CREDENTIALS + int "MAX number of credentials in credential pool" + default 2 + help + Configure 'CONFIG_CREDMAN_MAX_CREDENTIALS', the maximum number of + allowed credentials in the credential pool. + +endif # KCONFIG_MODULE_CREDMAN diff --git a/sys/net/credman/credman.c b/sys/net/credman/credman.c index 7694d83503..fe662e5bd3 100644 --- a/sys/net/credman/credman.c +++ b/sys/net/credman/credman.c @@ -26,7 +26,7 @@ static mutex_t _mutex = MUTEX_INIT; -static credman_credential_t credentials[CREDMAN_MAX_CREDENTIALS]; +static credman_credential_t credentials[CONFIG_CREDMAN_MAX_CREDENTIALS]; static unsigned used = 0; static int _find_credential_pos(credman_tag_t tag, credman_type_t type, @@ -129,7 +129,7 @@ int credman_get_used_count(void) static int _find_credential_pos(credman_tag_t tag, credman_type_t type, credman_credential_t **empty) { - for (unsigned i = 0; i < CREDMAN_MAX_CREDENTIALS; i++) { + for (unsigned i = 0; i < CONFIG_CREDMAN_MAX_CREDENTIALS; i++) { credman_credential_t *c = &credentials[i]; if ((c->tag == tag) && (c->type == type)) { return i; @@ -148,7 +148,7 @@ void credman_reset(void) { mutex_lock(&_mutex); memset(credentials, 0, - sizeof(credman_credential_t) * CREDMAN_MAX_CREDENTIALS); + sizeof(credman_credential_t) * CONFIG_CREDMAN_MAX_CREDENTIALS); used = 0; mutex_unlock(&_mutex); } diff --git a/tests/unittests/tests-credman/tests-credman.c b/tests/unittests/tests-credman/tests-credman.c index c722f04f10..c73180a6b6 100644 --- a/tests/unittests/tests-credman/tests-credman.c +++ b/tests/unittests/tests-credman/tests-credman.c @@ -73,7 +73,7 @@ static void test_credman_add(void) /* fill the pool */ memcpy(&credential.params.psk, &exp_psk_params, sizeof(psk_params_t)); - while (credman_get_used_count() < CREDMAN_MAX_CREDENTIALS) { + while (credman_get_used_count() < CONFIG_CREDMAN_MAX_CREDENTIALS) { /* increase tag number so that it is not recognized as duplicate */ credential.tag++; TEST_ASSERT_EQUAL_INT(CREDMAN_OK, credman_add(&credential)); @@ -176,7 +176,7 @@ static void test_credman_delete_random_order(void) }; TEST_ASSERT_EQUAL_INT(0, credman_get_used_count()); - /* fill the credential pool, assume CREDMAN_MAX_CREDENTIALS is 2 */ + /* fill the credential pool, assume CONFIG_CREDMAN_MAX_CREDENTIALS is 2 */ TEST_ASSERT_EQUAL_INT(CREDMAN_OK, credman_add(&in_credential)); in_credential.tag = tag2; TEST_ASSERT_EQUAL_INT(CREDMAN_OK, credman_add(&in_credential));