diff --git a/boards/common/saml1x/include/board.h b/boards/common/saml1x/include/board.h index afa934b7deb5..9e3534064632 100644 --- a/boards/common/saml1x/include/board.h +++ b/boards/common/saml1x/include/board.h @@ -28,6 +28,15 @@ extern "C" { #endif +/** + * @brief ATCA device type on SAML11 XPro boards + * @{ + */ +#ifdef BOARD_SAML11_XPRO +#define ATCA_DEVTYPE (ATECC508A) +#endif +/** @} */ + /** * @name PORT selection macros * @{ diff --git a/pkg/cryptoauthlib/Kconfig b/pkg/cryptoauthlib/Kconfig index abbfdf29e889..7c74e16fb9e2 100644 --- a/pkg/cryptoauthlib/Kconfig +++ b/pkg/cryptoauthlib/Kconfig @@ -23,6 +23,11 @@ config MODULE_CRYPTOAUTHLIB_CONTRIB config MODULE_CRYPTOAUTHLIB_TEST bool "Module for cryptoauthlib tests" depends on TEST_KCONFIG + select MODULE_CRYPTOAUTHLIB_TEST_THIRD_PARTY_UNITY + select MODULE_CRYPTOAUTHLIB_TEST_API_ATCAB + select MODULE_CRYPTOAUTHLIB_TEST_API_CALIB + select MODULE_CRYPTOAUTHLIB_TEST_API_CRYPTO + select MODULE_CRYPTOAUTHLIB_TEST_VECTORS select MODULE_CRYPTOAUTHLIB_TEST_JWT select MODULE_CRYPTOAUTHLIB_TEST_TNG select MODULE_CRYPTOAUTHLIB_TEST_ATCACERT @@ -36,4 +41,19 @@ config MODULE_CRYPTOAUTHLIB_TEST_TNG config MODULE_CRYPTOAUTHLIB_TEST_ATCACERT bool +config MODULE_CRYPTOAUTHLIB_TEST_THIRD_PARTY_UNITY + bool + +config MODULE_CRYPTOAUTHLIB_TEST_API_ATCAB + bool + +config MODULE_CRYPTOAUTHLIB_TEST_API_CALIB + bool + +config MODULE_CRYPTOAUTHLIB_TEST_API_CRYPTO + bool + +config MODULE_CRYPTOAUTHLIB_TEST_VECTORS + bool + endif diff --git a/pkg/cryptoauthlib/Makefile b/pkg/cryptoauthlib/Makefile index 587e11554984..b6eebf6efbdd 100644 --- a/pkg/cryptoauthlib/Makefile +++ b/pkg/cryptoauthlib/Makefile @@ -1,6 +1,6 @@ PKG_NAME=cryptoauthlib PKG_URL=https://github.com/MicrochipTech/cryptoauthlib -PKG_VERSION=af8187776cd3f3faf8bed412eaf6ff7221862e19 +PKG_VERSION=055dd4afafb019db1f4d61880aa441832139faa2 PKG_LICENSE=LGPL-2.1 PKG_TEST_NAME=cryptoauthlib_test @@ -23,6 +23,7 @@ CFLAGS += -Wno-type-limits CFLAGS += -Wno-unused-function CFLAGS += -Wno-unused-parameter CFLAGS += -Wno-unused-variable +CFLAGS += -Wno-format-nonliteral TOOLCHAIN_FILE=$(PKG_SOURCE_DIR)/xcompile-toolchain.cmake @@ -39,7 +40,6 @@ cryptoauth: $(PKG_BUILD_DIR)/Makefile $(PKG_BUILD_DIR)/Makefile: $(TOOLCHAIN_FILE) cmake -DCMAKE_TOOLCHAIN_FILE=$(TOOLCHAIN_FILE) \ -Wno-dev \ - -DATCA_HAL_I2C:BOOL=TRUE \ -B$(PKG_BUILD_DIR) \ -H$(PKG_SOURCE_DIR)/lib @@ -47,10 +47,15 @@ $(TOOLCHAIN_FILE): git-download $(RIOTTOOLS)/cmake/generate-xcompile-toolchain.sh > $(TOOLCHAIN_FILE) build_tests: + $(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/third_party/unity -f $(RIOTBASE)/Makefile.base MODULE=$(PKG_TEST_NAME)_third_party_unity $(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/test -f $(RIOTBASE)/Makefile.base MODULE=$(PKG_TEST_NAME) $(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/test/jwt -f $(RIOTBASE)/Makefile.base MODULE=$(PKG_TEST_NAME)_jwt $(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/test/tng -f $(RIOTBASE)/Makefile.base MODULE=$(PKG_TEST_NAME)_tng $(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/test/atcacert -f $(RIOTBASE)/Makefile.base MODULE=$(PKG_TEST_NAME)_atcacert + $(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/test/api_atcab -f $(RIOTBASE)/Makefile.base MODULE=$(PKG_TEST_NAME)_api_atcab + $(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/test/api_calib -f $(RIOTBASE)/Makefile.base MODULE=$(PKG_TEST_NAME)_api_calib + $(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/test/api_crypto -f $(RIOTBASE)/Makefile.base MODULE=$(PKG_TEST_NAME)_api_crypto + $(QQ)"$(MAKE)" -C $(PKG_SOURCE_DIR)/test/vectors -f $(RIOTBASE)/Makefile.base MODULE=$(PKG_TEST_NAME)_vectors git-download: | ..cmake_version_supported diff --git a/pkg/cryptoauthlib/Makefile.dep b/pkg/cryptoauthlib/Makefile.dep index 4da909472184..0544351a583e 100644 --- a/pkg/cryptoauthlib/Makefile.dep +++ b/pkg/cryptoauthlib/Makefile.dep @@ -9,6 +9,11 @@ ifneq (,$(filter cryptoauthlib_test,$(USEMODULE))) USEMODULE += cryptoauthlib_test_jwt USEMODULE += cryptoauthlib_test_tng USEMODULE += cryptoauthlib_test_atcacert + USEMODULE += cryptoauthlib_test_api_atcab + USEMODULE += cryptoauthlib_test_api_calib + USEMODULE += cryptoauthlib_test_api_crypto + USEMODULE += cryptoauthlib_test_vectors + USEMODULE += cryptoauthlib_test_third_party_unity endif # Some EFM32 CPU families define AES_COUNT, which is also defined by this diff --git a/pkg/cryptoauthlib/Makefile.include b/pkg/cryptoauthlib/Makefile.include index 82cd2a0a39df..cf37947461ce 100644 --- a/pkg/cryptoauthlib/Makefile.include +++ b/pkg/cryptoauthlib/Makefile.include @@ -4,6 +4,7 @@ PKG_TESTINCLDIR = $(PKG_SOURCE_DIR)/test INCLUDES += -I$(PKG_SOURCE_DIR) INCLUDES += -I$(PKG_SOURCE_DIR)/lib INCLUDES += -I$(PKG_SOURCE_DIR)/app +INCLUDES += -I$(PKG_SOURCE_DIR)/lib/calib INCLUDES += -I$(RIOTPKG)/cryptoauthlib/include DIRS += $(RIOTPKG)/cryptoauthlib/contrib @@ -14,4 +15,9 @@ ifneq (,$(filter cryptoauthlib_test,$(USEMODULE))) INCLUDES += -I$(PKG_TESTINCLDIR)/jwt INCLUDES += -I$(PKG_TESTINCLDIR)/tng INCLUDES += -I$(PKG_TESTINCLDIR)/atcacert + INCLUDES += -I$(PKG_TESTINCLDIR)/api_atcab + INCLUDES += -I$(PKG_TESTINCLDIR)/api_calib + INCLUDES += -I$(PKG_TESTINCLDIR)/api_crypto + INCLUDES += -I$(PKG_TESTINCLDIR)/vectors + INCLUDES += -I$(PKG_SOURCE_DIR)/third_party/unity endif diff --git a/pkg/cryptoauthlib/contrib/atca.c b/pkg/cryptoauthlib/contrib/atca.c index 78aaa522ccce..9670909a7a0d 100644 --- a/pkg/cryptoauthlib/contrib/atca.c +++ b/pkg/cryptoauthlib/contrib/atca.c @@ -27,6 +27,7 @@ #include "atca.h" #include "atca_params.h" + /* Timer functions */ void atca_delay_us(uint32_t delay) { @@ -44,9 +45,9 @@ void atca_delay_ms(uint32_t delay) } /* Hal I2C implementation */ -ATCA_STATUS hal_i2c_init(void *hal, ATCAIfaceCfg *cfg) +ATCA_STATUS hal_i2c_init(ATCAIface iface, ATCAIfaceCfg *cfg) { - (void)hal; + (void)iface; if (cfg->iface_type != ATCA_I2C_IFACE) { return ATCA_BAD_PARAM; } @@ -62,17 +63,15 @@ ATCA_STATUS hal_i2c_post_init(ATCAIface iface) return ATCA_SUCCESS; } -ATCA_STATUS hal_i2c_send(ATCAIface iface, uint8_t *txdata, int txlength) +ATCA_STATUS hal_i2c_send(ATCAIface iface, uint8_t word_address, uint8_t *txdata, int txlength) { + (void) word_address; ATCAIfaceCfg *cfg = atgetifacecfg(iface); int ret; - /* The first byte of the command package contains the word address */ - txdata[0] = ATCA_DATA_ADDR; - i2c_acquire(cfg->atcai2c.bus); - ret = i2c_write_bytes(cfg->atcai2c.bus, (cfg->atcai2c.slave_address >> 1), - txdata, txlength + 1, 0); + ret = i2c_write_bytes(cfg->atcai2c.bus, (cfg->atcai2c.address >> 1), + txdata, txlength, 0); i2c_release(cfg->atcai2c.bus); if (ret != 0) { @@ -82,53 +81,20 @@ ATCA_STATUS hal_i2c_send(ATCAIface iface, uint8_t *txdata, int txlength) return ATCA_SUCCESS; } -ATCA_STATUS hal_i2c_receive(ATCAIface iface, uint8_t *rxdata, +ATCA_STATUS hal_i2c_receive(ATCAIface iface, uint8_t word_address, uint8_t *rxdata, uint16_t *rxlength) { + (void) word_address; ATCAIfaceCfg *cfg = atgetifacecfg(iface); uint8_t retries = cfg->rx_retries; - uint8_t length_package = 0; - uint8_t bytes_to_read; int ret = -1; - /* Every command needs some time to be executed. We check whether the device is done - by polling, so we don't have to wait for the max execution time. For that there's - a number of retries (specified in the device descriptor). If polling is not successful - this function returns an error code. */ - - i2c_acquire(cfg->atcai2c.bus); - while (retries-- > 0 && ret != 0) { - /* read first byte (size of output data) and store it in variable length_package - to check if output will fit into rxdata */ - ret = i2c_read_byte(cfg->atcai2c.bus, (cfg->atcai2c.slave_address >> 1), - &length_package, 0); - } - i2c_release(cfg->atcai2c.bus); - - if (ret != 0) { - return ATCA_RX_TIMEOUT; - } - - bytes_to_read = length_package - 1; - - if (bytes_to_read > *rxlength) { - return ATCA_SMALL_BUFFER; - } - - /* CRC function calculates value of the whole output package, so to get a correct - result we need to include the length of the package we got before into rxdata as first byte. */ - rxdata[0] = length_package; - - /* reset ret and retries to read the rest of the output */ - ret = -1; - retries = cfg->rx_retries; - /* read rest of output and insert into rxdata array after first byte */ i2c_acquire(cfg->atcai2c.bus); while (retries-- > 0 && ret != 0) { ret = i2c_read_bytes(cfg->atcai2c.bus, - (cfg->atcai2c.slave_address >> 1), (rxdata + 1), - bytes_to_read, 0); + (cfg->atcai2c.address >> 1), (rxdata), + *rxlength, 0); } i2c_release(cfg->atcai2c.bus); @@ -136,8 +102,6 @@ ATCA_STATUS hal_i2c_receive(ATCAIface iface, uint8_t *rxdata, return ATCA_RX_TIMEOUT; } - *rxlength = length_package; - return ATCA_SUCCESS; } @@ -173,7 +137,7 @@ ATCA_STATUS hal_i2c_wake(ATCAIface iface) i2c_acquire(cfg->atcai2c.bus); while (retries-- > 0 && status != 0) { status = i2c_read_bytes(cfg->atcai2c.bus, - (cfg->atcai2c.slave_address >> 1), + (cfg->atcai2c.address >> 1), &data[0], 4, 0); } i2c_release(cfg->atcai2c.bus); @@ -181,7 +145,6 @@ ATCA_STATUS hal_i2c_wake(ATCAIface iface) if (status != ATCA_SUCCESS) { return ATCA_COMM_FAIL; } - return hal_check_wake(data, 4); } @@ -190,7 +153,7 @@ ATCA_STATUS hal_i2c_idle(ATCAIface iface) ATCAIfaceCfg *cfg = atgetifacecfg(iface); i2c_acquire(cfg->atcai2c.bus); - i2c_write_byte(cfg->atcai2c.bus, (cfg->atcai2c.slave_address >> 1), + i2c_write_byte(cfg->atcai2c.bus, (cfg->atcai2c.address >> 1), ATCA_IDLE_ADDR, 0); i2c_release(cfg->atcai2c.bus); return ATCA_SUCCESS; @@ -201,12 +164,34 @@ ATCA_STATUS hal_i2c_sleep(ATCAIface iface) ATCAIfaceCfg *cfg = atgetifacecfg(iface); i2c_acquire(cfg->atcai2c.bus); - i2c_write_byte(cfg->atcai2c.bus, (cfg->atcai2c.slave_address >> 1), + i2c_write_byte(cfg->atcai2c.bus, (cfg->atcai2c.address >> 1), ATCA_SLEEP_ADDR, 0); i2c_release(cfg->atcai2c.bus); return ATCA_SUCCESS; } +ATCA_STATUS hal_i2c_control(ATCAIface iface, uint8_t option, void* param, size_t paramlen) +{ + (void) param; + (void) paramlen; + switch (option) { + case ATCA_HAL_CONTROL_WAKE: + return hal_i2c_wake(iface); + case ATCA_HAL_CONTROL_IDLE: + return hal_i2c_idle(iface); + case ATCA_HAL_CONTROL_SLEEP: + return hal_i2c_sleep(iface); + case ATCA_HAL_CHANGE_BAUD: + return ATCA_UNIMPLEMENTED; + case ATCA_HAL_CONTROL_SELECT: + case ATCA_HAL_CONTROL_DESELECT: + return ATCA_SUCCESS; + default: + return ATCA_BAD_PARAM; + } + return ATCA_UNIMPLEMENTED; +} + ATCA_STATUS hal_i2c_release(void *hal_data) { (void)hal_data; diff --git a/pkg/cryptoauthlib/include/atca_config.h b/pkg/cryptoauthlib/include/atca_config.h new file mode 100644 index 000000000000..de9491b4d9da --- /dev/null +++ b/pkg/cryptoauthlib/include/atca_config.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2022 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 pkg_cryptoauthlib + * @{ + * + * @file + * @brief Minimal configuration for the library build. + * For documentation please see https://github.com/MicrochipTech/cryptoauthlib#readme + * + * @author Lena Boeckmann + * + */ + +#ifndef ATCA_CONFIG_H +#define ATCA_CONFIG_H + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief ATECC508A device support + */ +#define ATCA_ATECC508A_SUPPORT + +/** + * @brief ATECC608A device support + */ +#define ATCA_ATECC608A_SUPPORT + +/** + * @brief Map atca delay function to hal delay ms implementation + */ +#define atca_delay_ms hal_delay_ms + +/** + * @brief Map atca delay function to hal delay us implementation + */ +#define atca_delay_us hal_delay_us + +#ifdef __cplusplus +} +#endif +#endif /* ATCA_CONFIG_H */ +/** @} */ \ No newline at end of file diff --git a/pkg/cryptoauthlib/include/atca_params.h b/pkg/cryptoauthlib/include/atca_params.h index 96d8c9deb34c..3a49d585f722 100644 --- a/pkg/cryptoauthlib/include/atca_params.h +++ b/pkg/cryptoauthlib/include/atca_params.h @@ -21,6 +21,7 @@ #define ATCA_PARAMS_H #include "board.h" +#include "periph/i2c.h" #include "cryptoauthlib.h" #ifdef __cplusplus @@ -53,15 +54,15 @@ extern "C" { #define ATCA_RX_RETRIES (20) #endif #ifndef ATCA_DEVTYPE -#define ATCA_DEVTYPE (ATECC508A) +#define ATCA_DEVTYPE (ATECC608A) #endif #ifndef ATCA_PARAMS #define ATCA_PARAMS { .iface_type = ATCA_I2C_IFACE, \ .devtype = ATCA_DEVTYPE, \ - .atcai2c.slave_address = ATCA_PARAM_ADDR, \ + .atcai2c.address = ATCA_PARAM_ADDR, \ .atcai2c.bus = ATCA_PARAM_I2C, \ - .atcai2c.baud = -1, /**< Not used in RIOT */ \ + .atcai2c.baud = -1, /**< Not used in RIOT */ \ .wake_delay = 1500, \ .rx_retries = ATCA_RX_RETRIES } #endif diff --git a/pkg/cryptoauthlib/include/cryptoauthlib_test.h b/pkg/cryptoauthlib/include/cryptoauthlib_test.h index 8a66d5809119..bbb2d7aa248b 100644 --- a/pkg/cryptoauthlib/include/cryptoauthlib_test.h +++ b/pkg/cryptoauthlib/include/cryptoauthlib_test.h @@ -32,15 +32,7 @@ extern "C" { * This function is defined in the cryptoauth library via patch. * It is used to pass commands to run built-in unit tests of the library. */ -int atca_run_cmd(const char *command); - -/** - * @brief Function switches the default cfg in cryptoauthlib test to RIOT cfg - */ -void riot_switch_cfg(ATCAIfaceCfg *cfg) -{ - *cfg = atca_params[0]; -} +int atca_run_cmd(char *command, size_t len); #ifdef __cplusplus } diff --git a/pkg/cryptoauthlib/patches/0001-Change-include-dirs-to-target-include-dirs.patch b/pkg/cryptoauthlib/patches/0001-Change-include-dirs-to-target-include-dirs.patch new file mode 100644 index 000000000000..b06401b36937 --- /dev/null +++ b/pkg/cryptoauthlib/patches/0001-Change-include-dirs-to-target-include-dirs.patch @@ -0,0 +1,25 @@ +From a2e9f91dfc331f06ae5ac6376102368f5b162a14 Mon Sep 17 00:00:00 2001 +From: Lena Boeckmann +Date: Wed, 8 Jun 2022 13:44:46 +0200 +Subject: [PATCH 1/2] Change include dirs to target include dirs + +--- + lib/CMakeLists.txt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt +index 749ee727..1c474a40 100644 +--- a/lib/CMakeLists.txt ++++ b/lib/CMakeLists.txt +@@ -354,7 +354,7 @@ configure_file(pkcs11/pkcs11_config.h.in pkcs11_config.h @ONLY) + set(PKCS11_INC ${PKCS11_INC} ${CMAKE_CURRENT_BINARY_DIR}/pkcs11_config.h) + endif() + +-include_directories(cryptoauth PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ../app/tng ../third_party ../third_party/hidapi/hidapi ${USB_INCLUDE_DIR}) ++target_include_directories(cryptoauth PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ../app/tng ../third_party ../third_party/hidapi/hidapi ${USB_INCLUDE_DIR}) + + if(ATCA_MBEDTLS) + target_link_libraries(cryptoauth mbedtls) +-- +2.35.1 + diff --git a/pkg/cryptoauthlib/patches/0001-change-include_directories-to-target_include_directo.patch b/pkg/cryptoauthlib/patches/0001-change-include_directories-to-target_include_directo.patch deleted file mode 100644 index 03d4eb1297de..000000000000 --- a/pkg/cryptoauthlib/patches/0001-change-include_directories-to-target_include_directo.patch +++ /dev/null @@ -1,25 +0,0 @@ -From ab9a5b8af22158512060079e931c964fb0bc2303 Mon Sep 17 00:00:00 2001 -From: Lena Boeckmann -Date: Tue, 7 Jan 2020 14:36:09 +0100 -Subject: [PATCH 1/2] change include_directories to target_include_directories - ---- - lib/CMakeLists.txt | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt -index b15ec66..2168e47 100644 ---- a/lib/CMakeLists.txt -+++ b/lib/CMakeLists.txt -@@ -123,7 +123,7 @@ if(ATCA_PRINTF) - add_definitions(-DATCAPRINTF) - endif(ATCA_PRINTF) - --include_directories(cryptoauth PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ../third_party/hidapi/hidapi ${USB_INCLUDE_DIR}) -+target_include_directories(cryptoauth PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ../third_party/hidapi/hidapi ${USB_INCLUDE_DIR}) - - if(WIN32) - set_target_properties(cryptoauth PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS true) --- -2.23.0 - diff --git a/pkg/cryptoauthlib/patches/0002-Add-parseCmd-function-for-RIOT.patch b/pkg/cryptoauthlib/patches/0002-Add-parseCmd-function-for-RIOT.patch new file mode 100644 index 000000000000..64512c48b0b2 --- /dev/null +++ b/pkg/cryptoauthlib/patches/0002-Add-parseCmd-function-for-RIOT.patch @@ -0,0 +1,32 @@ +From b4ed40ad3f474cb26a883f1748643a54ac1695cd Mon Sep 17 00:00:00 2001 +From: Lena Boeckmann +Date: Wed, 8 Jun 2022 13:44:59 +0200 +Subject: [PATCH 2/2] Add parseCmd function for RIOT + +--- + test/cmd-processor.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/test/cmd-processor.c b/test/cmd-processor.c +index 837361d2..a98f3169 100644 +--- a/test/cmd-processor.c ++++ b/test/cmd-processor.c +@@ -267,6 +267,15 @@ int main(int argc, char* argv[]) + + return exit_code; + } ++#elif defined(RIOT_APPLICATION) ++#include ++#include ++#include "cmd-processor.h" ++ ++int atca_run_cmd(char *command, size_t len) ++{ ++ return parse_cmd(command, len); ++} + #else + int processCmd(void) + { +-- +2.35.1 + diff --git a/pkg/cryptoauthlib/patches/0002-add-defines-and-functions-for-riot-usage.patch b/pkg/cryptoauthlib/patches/0002-add-defines-and-functions-for-riot-usage.patch deleted file mode 100644 index d34de7392337..000000000000 --- a/pkg/cryptoauthlib/patches/0002-add-defines-and-functions-for-riot-usage.patch +++ /dev/null @@ -1,65 +0,0 @@ -From ee9792298bffa657e016d64790a4489ad1ead80f Mon Sep 17 00:00:00 2001 -From: Lena Boeckmann -Date: Tue, 7 Jan 2020 14:37:10 +0100 -Subject: [PATCH 2/2] add defines and functions for riot usage - ---- - test/cmd-processor.c | 15 ++++++++++++++- - test/cmd-processor.h | 1 + - 2 files changed, 15 insertions(+), 1 deletion(-) - -diff --git a/test/cmd-processor.c b/test/cmd-processor.c -index 2be06a8..c450b2f 100644 ---- a/test/cmd-processor.c -+++ b/test/cmd-processor.c -@@ -28,7 +28,7 @@ - // Undefine the Unity FAIL macro so it doesn't conflict with the ASF definition - #undef FAIL - --#if !defined(_WIN32) && !defined(__linux__) && !defined(__XC32__) && !defined(__APPLE__) && !defined(ESP32) -+#if !defined(_WIN32) && !defined(__linux__) && !defined(__XC32__) && !defined(__APPLE__) && !defined(ESP32) && !defined(RIOT_APPLICATION) - #ifdef ATMEL_START - #include "atmel_start.h" - #else -@@ -155,6 +155,15 @@ int main(int argc, char* argv[]) - - return exit_code; - } -+#elif defined(RIOT_APPLICATION) -+#include -+#include -+#include "cmd-processor.h" -+ -+int atca_run_cmd(const char *command) -+{ -+ return parse_cmd(command); -+} - #else - int processCmd(void) - { -@@ -927,6 +936,10 @@ static ATCA_STATUS set_test_config(ATCADeviceType deviceType) - gCfg->atcai2c.bus = 1; - #endif - -+ #ifdef MODULE_CRYPTOAUTHLIB_TEST -+ riot_switch_cfg(gCfg); -+ #endif -+ - return ATCA_SUCCESS; - } - -diff --git a/test/cmd-processor.h b/test/cmd-processor.h -index a8af58a..fe51b6a 100644 ---- a/test/cmd-processor.h -+++ b/test/cmd-processor.h -@@ -52,6 +52,7 @@ typedef struct - fp_menu_handler fp_handler; - }t_menu_info; - -+void riot_switch_cfg(ATCAIfaceCfg*); - - int run_tests(int test); - --- -2.23.0 - diff --git a/pkg/cryptoauthlib/patches/0003-Cast-DEVICE_MASK-to-32-bit.patch b/pkg/cryptoauthlib/patches/0003-Cast-DEVICE_MASK-to-32-bit.patch new file mode 100644 index 000000000000..5d6777d71bba --- /dev/null +++ b/pkg/cryptoauthlib/patches/0003-Cast-DEVICE_MASK-to-32-bit.patch @@ -0,0 +1,25 @@ +From 33e403483a2eb3ce299949762dad636ddff07212 Mon Sep 17 00:00:00 2001 +From: Lena Boeckmann +Date: Tue, 5 Jul 2022 16:00:27 +0200 +Subject: [PATCH] Cast DEVICE_MASK to 32 bit + +--- + test/atca_test.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/test/atca_test.h b/test/atca_test.h +index fbf9be02..f3ec11fe 100644 +--- a/test/atca_test.h ++++ b/test/atca_test.h +@@ -58,7 +58,7 @@ typedef struct + fp_menu_handler fp_handler; + } t_menu_info; + +-#define DEVICE_MASK(device) ((uint8_t)1 << device) ++#define DEVICE_MASK(device) ((uint32_t)1 << device) + #define REGISTER_TEST_CASE(group, name) TEST_ ## group ## _ ## name ## _run + + #define DEVICE_MASK_ECC (DEVICE_MASK(ATECC108A) | DEVICE_MASK(ATECC508A) | DEVICE_MASK(ATECC608)) +-- +2.37.0 + diff --git a/tests/pkg_cryptoauthlib_internal-tests/Makefile b/tests/pkg_cryptoauthlib_internal-tests/Makefile index 09ec1d9b348b..61a9ae576f89 100644 --- a/tests/pkg_cryptoauthlib_internal-tests/Makefile +++ b/tests/pkg_cryptoauthlib_internal-tests/Makefile @@ -2,6 +2,7 @@ BOARD ?= nucleo-f767zi include ../Makefile.tests_common +CFLAGS += -DTHREAD_STACKSIZE_MAIN=\(3*THREAD_STACKSIZE_DEFAULT\) # Test fails to build for these boards fails due to # redefinition of define AES_COUNT in library, which # is also defined in board header files diff --git a/tests/pkg_cryptoauthlib_internal-tests/README.md b/tests/pkg_cryptoauthlib_internal-tests/README.md new file mode 100644 index 000000000000..142c511012bb --- /dev/null +++ b/tests/pkg_cryptoauthlib_internal-tests/README.md @@ -0,0 +1,5 @@ +Tests provided by the cryptoauthlib driver +========================================== + +Some of the tests require the device config zone to be locked. +Test that require the use of key slots will fail, if the slot configuration differs from the default configuration. diff --git a/tests/pkg_cryptoauthlib_internal-tests/main.c b/tests/pkg_cryptoauthlib_internal-tests/main.c index 2377ebebf6a4..2974a3da0a1b 100644 --- a/tests/pkg_cryptoauthlib_internal-tests/main.c +++ b/tests/pkg_cryptoauthlib_internal-tests/main.c @@ -20,22 +20,29 @@ #include #include "cryptoauthlib_test.h" +#include "atca_test.h" + +const char atecc508[] = "ecc508"; +const char atecc608[] = "ecc608"; +const char unit[] = "basic"; int main(void) { + atca_test_config_set_ifacecfg((ATCAIfaceCfg *) &atca_params[0]); + /* Set device to ATECC508A */ if (ATCA_DEVTYPE == ATECC608A) { - atca_run_cmd("608"); + atca_run_cmd((char *) atecc608, sizeof(atecc608)); } else if (ATCA_DEVTYPE == ATECC508A) { - atca_run_cmd("508"); + atca_run_cmd((char *) atecc508, sizeof(atecc508)); } else { printf("This device is currently not supported."); return 0; } - atca_run_cmd("unit"); + atca_run_cmd((char *) unit, sizeof(unit)); return 0; }