Merge pull request #14513 from akshaim/Kconfig_credman

net/credman : Expose configurations to Kconfig
This commit is contained in:
Leandro Lanzieri 2020-07-15 10:10:54 +02:00 committed by GitHub
commit db29db330b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 8 deletions

View File

@ -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
*/

View File

@ -7,6 +7,7 @@
menu "Networking"
rsource "application_layer/Kconfig"
rsource "credman/Kconfig"
rsource "gnrc/Kconfig"
rsource "sock/Kconfig"
rsource "link_layer/Kconfig"

23
sys/net/credman/Kconfig Normal file
View File

@ -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

View File

@ -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);
}

View File

@ -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));