From 3dae0ddde5d67bab09cf65be4d25ecdeeb680dcb Mon Sep 17 00:00:00 2001 From: Einhornhool <26007369+Einhornhool@users.noreply.github.com> Date: Tue, 28 Jan 2020 18:34:32 +0100 Subject: [PATCH] sys/auto_init: add security module and cryptoauth init --- sys/auto_init/Makefile | 4 +++ sys/auto_init/auto_init.c | 9 ++++++ sys/auto_init/security/Makefile | 3 ++ sys/auto_init/security/auto_init_atca.c | 40 +++++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 sys/auto_init/security/Makefile create mode 100644 sys/auto_init/security/auto_init_atca.c diff --git a/sys/auto_init/Makefile b/sys/auto_init/Makefile index e14091c42d..5fedf1d828 100644 --- a/sys/auto_init/Makefile +++ b/sys/auto_init/Makefile @@ -22,4 +22,8 @@ ifneq (,$(filter auto_init_usbus,$(USEMODULE))) DIRS += usb endif +ifneq (,$(filter auto_init_security,$(USEMODULE))) + DIRS += security +endif + include $(RIOTBASE)/Makefile.base diff --git a/sys/auto_init/auto_init.c b/sys/auto_init/auto_init.c index 5b7d842793..10efdf4d16 100644 --- a/sys/auto_init/auto_init.c +++ b/sys/auto_init/auto_init.c @@ -619,6 +619,15 @@ void auto_init(void) suit_init_conditions(); #endif /* MODULE_SUIT */ +#ifdef MODULE_AUTO_INIT_SECURITY + +#ifdef MODULE_CRYPTOAUTHLIB + extern void auto_init_atca(void); + auto_init_atca(); +#endif /* MODULE_CRYPTOAUTHLIB */ + +#endif /* MODULE_AUTO_INIT_SECURITY */ + #ifdef MODULE_TEST_UTILS_INTERACTIVE_SYNC #if !defined(MODULE_SHELL_COMMANDS) || !defined(MODULE_SHELL) test_utils_interactive_sync(); diff --git a/sys/auto_init/security/Makefile b/sys/auto_init/security/Makefile new file mode 100644 index 0000000000..7c09373a3c --- /dev/null +++ b/sys/auto_init/security/Makefile @@ -0,0 +1,3 @@ +MODULE = auto_init_security + +include $(RIOTBASE)/Makefile.base diff --git a/sys/auto_init/security/auto_init_atca.c b/sys/auto_init/security/auto_init_atca.c new file mode 100644 index 0000000000..41a4474027 --- /dev/null +++ b/sys/auto_init/security/auto_init_atca.c @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2019 HAW Hamburg + * + * 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. + */ + +/** + * @ingroup sys_auto_init + * @{ + * @file + * @brief Initializes cryptoauth devices + * + * @author Lena Boeckmann + * @} + */ + +#ifdef MODULE_CRYPTOAUTHLIB +#include "log.h" +#include "atca.h" +#include "atca_params.h" + +#define ENABLE_DEBUG (0) +#include "debug.h" + +#define ATCA_NUMOF (ARRAY_SIZE(atca_params)) + +void auto_init_atca(void) +{ + for (unsigned i = 0; i < ATCA_NUMOF; i++) { + if (atcab_init((ATCAIfaceCfg *)&atca_params[i]) != ATCA_SUCCESS) { + LOG_ERROR("[auto_init_atca] error initializing cryptoauth device #%u\n", i); + continue; + } + } +} +#else +typedef int dont_be_pedantic; +#endif