diff --git a/CMakeLists.txt b/CMakeLists.txt index ef5385259..a4d3601fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,10 +2,10 @@ cmake_minimum_required(VERSION 2.6.4) project (cryptoauthlib) # Set the current release version -set(VERSION "3.2.2") +set(VERSION "3.2.3") set(VERSION_MAJOR 3) set(VERSION_MINOR 2) -set(VERSION_PATCH 2) +set(VERSION_PATCH 3) # Build Options option(BUILD_TESTS "Create Test Application with library" OFF) diff --git a/app/pkcs11/example_pkcs11_config.c b/app/pkcs11/example_pkcs11_config.c index 91b26b762..24758e24e 100644 --- a/app/pkcs11/example_pkcs11_config.c +++ b/app/pkcs11/example_pkcs11_config.c @@ -21,7 +21,7 @@ #define pkcs11configLABEL_DEVICE_PUBLIC_KEY_FOR_TLS pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS #endif -/** Standard Configuration Structure for ATECC608A devices */ +/** Standard Configuration Structure for ATECC608 devices */ const uint8_t atecc608_config[] = { 0x01, 0x23, 0x00, 0x00, 0x00, 0x00, 0x60, 0x01, 0x00, 0x00, 0x00, 0x00, 0xEE, 0x01, 0x01, 0x00, 0xC0, 0x00, 0x00, 0x01, 0x8F, 0x20, 0xC4, 0x44, 0x87, 0x20, 0x87, 0x20, 0x8F, 0x0F, 0xC4, 0x36, diff --git a/cryptoauthlib-manual.pdf b/cryptoauthlib-manual.pdf index 5add33240..146775995 100644 Binary files a/cryptoauthlib-manual.pdf and b/cryptoauthlib-manual.pdf differ diff --git a/harmony/config/hal_common.py b/harmony/config/hal_common.py deleted file mode 100644 index d9ab2a6e9..000000000 --- a/harmony/config/hal_common.py +++ /dev/null @@ -1,36 +0,0 @@ -# coding: utf-8 -"""***************************************************************************** -* Copyright (C) 2019 Microchip Technology Inc. and its subsidiaries. -* -* Subject to your compliance with these terms, you may use Microchip software -* and any derivatives exclusively with Microchip products. It is your -* responsibility to comply with third party license terms applicable to your -* use of third party software (including open source software) that may -* accompany Microchip software. -* -* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER -* EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED -* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A -* PARTICULAR PURPOSE. -* -* IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, -* INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND -* WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS -* BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE -* FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN -* ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, -* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. -*****************************************************************************""" - -def instantiateComponent(halComponent): - - hal_id = halComponent.getID().upper() - - halComponent.addMultiCapability(hal_id, 'CAL_HAL', 'CAL_HAL') - - if 'I2C' in hal_id.upper(): - halComponent.addMultiDependency('DEP_PLIB_I2C', 'I2C', 'I2C', True) - elif 'SWI_UART' in hal_id.upper(): - halComponent.addMultiDependency('DEP_PLIB_SWI_UART', 'UART', 'UART', True) - - diff --git a/harmony/config/hal_instance.py b/harmony/config/hal_instance.py deleted file mode 100644 index 76c9e06c2..000000000 --- a/harmony/config/hal_instance.py +++ /dev/null @@ -1,68 +0,0 @@ -# coding: utf-8 -"""***************************************************************************** -* Copyright (C) 2018 Microchip Technology Inc. and its subsidiaries. -* -* Subject to your compliance with these terms, you may use Microchip software -* and any derivatives exclusively with Microchip products. It is your -* responsibility to comply with third party license terms applicable to your -* use of third party software (including open source software) that may -* accompany Microchip software. -* -* THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER -* EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED -* WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A -* PARTICULAR PURPOSE. -* -* IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, -* INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND -* WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS -* BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE -* FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN -* ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, -* THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. -*****************************************************************************""" - - -def updatePlibList(plib, inc): - Database.sendMessage('cryptoauthlib', 'UPDATE_PLIB_LIST', {'id': plib.lower(), 'inc': inc}) - - -def instantiateComponent(deviceComponent, index): - global devicePartType - deviceID = deviceComponent.getID().upper() - configName = Variables.get('__CONFIGURATION_NAME') - - #I2C Configuration - devicePLIB = deviceComponent.createStringSymbol("DRV_PLIB", None) - devicePLIB.setLabel("PLIB Used") - devicePLIB.setReadOnly(True) - devicePLIB.setDefaultValue("") - - -def onAttachmentConnected(source, target): - sourceID = source['id'].upper() - targetID = target['component'].getID().upper() - - plib_type = target['id'].split('_')[1].upper() - - if plib_type in ['I2C', 'UART']: - source['component'].getSymbolByID('DRV_PLIB').setValue(targetID) - updatePlibList(target['id'], True) - - - -def onAttachmentDisconnected(source, target): - sourceID = source['id'].upper() - targetID = target['component'].getID().upper() - - plib_type = target['id'].split('_')[1].upper() - - if plib_type in ['I2C', 'UART']: - try: - source['component'].getSymbolByID('DRV_PLIB').clearValue() - except AttributeError: - # Happens when the instance is deleted while attached - pass - updatePlibList(target['id'], False) - - diff --git a/harmony/templates/atca_main.c.ftl b/harmony/templates/atca_main.c.ftl deleted file mode 100644 index 35d1de6ba..000000000 --- a/harmony/templates/atca_main.c.ftl +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Code generated from MPLAB Harmony. - * - * This file will be overwritten when reconfiguring your MPLAB Harmony project. - * Please copy examples or other code you want to keep to a separate file or main.c - * to avoid loosing it when reconfiguring. - */ - -#include "cryptoauthlib_main.h" -#include "cryptoauthlib_interface_config.h" -#include "cryptoauthlib.h" - -ATCAIfaceCfg CRYPTO_AUTHENTICATION_INTERFACE_0_desc = { - .iface_type = ${.vars["${CAL_LIB_DEVICE?lower_case}"].DEVICE_INTF_USED}, - .devtype = ${CAL_LIB_DEVICE}, - .atcai2c.slave_address = CONF_CRYPTO_AUTHENTICATION_INTERFACE_0_I2C_ADDRESS, - .atcai2c.bus = 0, - .atcai2c.baud = CONF_CRYPTO_AUTHENTICATION_INTERFACE_0_I2C_FREQUENCY, - .wake_delay = CONF_CRYPTO_AUTHENTICATION_INTERFACE_0_I2C_WAKEUP_DELAY, - .rx_retries = CONF_CRYPTO_AUTHENTICATION_INTERFACE_0_I2C_RXRETRY, - .cfg_data = NULL -}; - -void CRYPTO_AUTHENTICATION_INTERFACE_0_init(void) -{ - atcab_init(&CRYPTO_AUTHENTICATION_INTERFACE_0_desc); -} - -void CRYPTO_AUTHENTICATION_INTERFACE_0_example(void) -{ - ATCA_STATUS status; - uint8_t serialnum[ATCA_SERIAL_NUM_SIZE]; - uint8_t random_number[ATCA_KEY_SIZE]; - uint8_t loop_count = 10; - - /* Init CRYPTO_AUTHENTICATION_INTERFACE_0 */ - CRYPTO_AUTHENTICATION_INTERFACE_0_init(); - - do { - /* Read device serial number... Unique value for each device and same on every read */ - if (ATCA_SUCCESS != (status = atcab_read_serial_number(serialnum))) - break; - - /* Read random number... Unique value on every read */ - if (ATCA_SUCCESS != (status = atcab_random(random_number))) - break; - } while (loop_count--); -} diff --git a/harmony/templates/device_instance.c.ftl b/harmony/templates/device_instance.c.ftl index 2d383b0a8..1185bf2b2 100644 --- a/harmony/templates/device_instance.c.ftl +++ b/harmony/templates/device_instance.c.ftl @@ -8,6 +8,8 @@ #include "cryptoauthlib.h" +<#assign PLIB_NAME = core.PORT_API_PREFIX?string> + ATCAIfaceCfg ${NAME?lower_case}_${INDEX?string}_init_data = { .iface_type = ${INTERFACE}, .devtype = ${NAME?upper_case}, @@ -19,8 +21,12 @@ ATCAIfaceCfg ${NAME?lower_case}_${INDEX?string}_init_data = { <#elseif INTERFACE == "ATCA_SPI_IFACE"> <#assign plib_type = "spi"> .atcaspi.bus = 0, - .atcaspi.select_pin = PORT_PIN_${SPI_CS_PIN?upper_case}, + .atcaspi.select_pin = ${PLIB_NAME}_PIN_${SPI_CS_PIN?upper_case}, +<#if HAL_INTERFACE?contains("FLEXCOM")> + .atcaspi.baud = ${.vars["${HAL_INTERFACE?lower_case}"].FLEXCOM_SPI_BAUD_RATE}, +<#else> .atcaspi.baud = ${.vars["${HAL_INTERFACE?lower_case}"].SPI_BAUD_RATE}, + .wake_delay = ${WAKEUP_DELAY}, .rx_retries = ${RECEIVE_RETRY}, diff --git a/harmony/templates/hal_harmony_init.c.ftl b/harmony/templates/hal_harmony_init.c.ftl index b199441b2..85485fb66 100644 --- a/harmony/templates/hal_harmony_init.c.ftl +++ b/harmony/templates/hal_harmony_init.c.ftl @@ -33,6 +33,7 @@ #include "cryptoauthlib.h" <#assign pliblist = CAL_PLIB_LIST?word_list> +<#assign PLIB_NAME = core.PORT_API_PREFIX?string> <#if pliblist?size != 0> <#list pliblist as plib_id> <#assign plib_info = plib_id?split("_")> @@ -46,7 +47,7 @@ atca_plib_i2c_api_t ${plib_info[0]}_plib_i2c_api = { <#elseif plib_info[1] == "spi"> static void ${plib_info[0]}_select_pin(uint32_t pin, bool value) { - PORT_PinWrite(pin, value); + ${PLIB_NAME}_PinWrite(pin, value); } atca_plib_spi_api_t ${plib_info[0]}_plib_spi_api = { diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 8a1f2e885..7353c343f 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -77,6 +77,7 @@ source_group("App/Tng" FILES ${TNG_SRC}) endif() if (ATCA_MBEDTLS) +if (NOT TARGET mbedtls) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../third_party/CMakeLists-mbedtls.txt.in ${CMAKE_BINARY_DIR}/${DEPENDENCY_DIR}/mbedtls_downloader/CMakeLists.txt) execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${DEPENDENCY_DIR}/mbedtls_downloader/) @@ -88,7 +89,7 @@ add_library(mbedtls STATIC ${MBEDTLS_LIB_SRC}) target_compile_definitions(mbedtls PUBLIC -DMBEDTLS_CMAC_C) include_directories(mbedtls PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/mbedtls/include) - +endif() file(GLOB MBEDTLS_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "mbedtls/*.c") if(${CMAKE_VERSION} VERSION_GREATER "3.8.0") diff --git a/lib/atca_version.h b/lib/atca_version.h index eab012ee8..63d7425db 100644 --- a/lib/atca_version.h +++ b/lib/atca_version.h @@ -30,9 +30,9 @@ #define _ATCA_VERSION_H // Version format yyyymmdd -#define ATCA_LIBRARY_VERSION_DATE "20200728" +#define ATCA_LIBRARY_VERSION_DATE "20200912" #define ATCA_LIBRARY_VERSION_MAJOR 3 #define ATCA_LIBRARY_VERSION_MINOR 2 -#define ATCA_LIBRARY_VERSION_BUILD 2 +#define ATCA_LIBRARY_VERSION_BUILD 3 #endif /* _ATCA_VERSION_H */ diff --git a/lib/hal/hal_all_platforms_kit_hidapi.c b/lib/hal/hal_all_platforms_kit_hidapi.c index c096e1416..931853712 100644 --- a/lib/hal/hal_all_platforms_kit_hidapi.c +++ b/lib/hal/hal_all_platforms_kit_hidapi.c @@ -29,11 +29,8 @@ #include #include #include "hidapi.h" -//#include "unistd.h" -//#include #include "atca_hal.h" -#include "hal_all_platforms_kit_hidapi.h" #include "hal/kit_protocol.h" /** \defgroup hal_ Hardware abstraction layer (hal_) @@ -43,8 +40,7 @@ * @{ */ -// File scope globals -atcahid_t _gHid; +#define HID_PACKET_MAX 512 //! Maximum number of bytes for a HID send/receive packet (typically 64) /** \brief discover cdc buses available for this hardware * this maintains a list of logical to physical bus mappings freeing the application @@ -76,9 +72,7 @@ ATCA_STATUS hal_kit_hid_discover_devices(int bus_num, ATCAIfaceCfg cfg[], int *f ATCA_STATUS hal_kit_hid_init(void* hal, ATCAIfaceCfg* cfg) { ATCAHAL_t *phal = (ATCAHAL_t*)hal; - hid_device *handle; - struct hid_device_info *devs = NULL; - struct hid_device_info *cur_dev = NULL; + int i = 0; int index = 0; @@ -88,59 +82,15 @@ ATCA_STATUS hal_kit_hid_init(void* hal, ATCAIfaceCfg* cfg) return ATCA_BAD_PARAM; } - // Initialize the _gHid structure - memset(&_gHid, 0, sizeof(_gHid)); - for (i = 0; i < HID_DEVICES_MAX; i++) - { - _gHid.kits[i] = NULL; - } - _gHid.num_kits_found = 0; - // Create the enumerate object #ifdef KIT_DEBUG printf("Enumerate HID device(s)\n"); #endif hid_init(); - devs = hid_enumerate(cfg->atcahid.vid, cfg->atcahid.pid); - - cur_dev = devs; - if (cur_dev == NULL) - { -#ifdef KIT_DEBUG - printf("no HID device found\n"); -#endif - hid_exit(); - return ATCA_COMM_FAIL; - } - while (cur_dev != NULL) - { - if ((handle = hid_open(cur_dev->vendor_id, cur_dev->product_id, cur_dev->serial_number))) - { - _gHid.kits[index] = handle; -#ifdef KIT_DEBUG - printf("Kit USB Device Node: %s\n", cur_dev->path); - printf(" Manufacturer %s (%s)\n", - (char*)cur_dev->manufacturer_string, - (char*)cur_dev->product_string); - printf(" PID %d\n", cur_dev->product_id); - printf(" VID %d\n\n", cur_dev->vendor_id); -#endif - index++; - } - cur_dev = cur_dev->next; - } - - hid_free_enumeration(devs); + phal->hal_data = hid_open(cfg->atcahid.vid, cfg->atcahid.pid, NULL); - // Save the results of this discovery of HID - if (index > 0) - { - _gHid.num_kits_found = index; - phal->hal_data = &_gHid; - } - - return ATCA_SUCCESS; + return (phal->hal_data) ? ATCA_SUCCESS : ATCA_COMM_FAIL; } /** \brief HAL implementation of Kit HID post init @@ -151,7 +101,7 @@ ATCA_STATUS hal_kit_hid_post_init(ATCAIface iface) { ATCA_STATUS status = ATCA_SUCCESS; - atcahid_t* pHid = atgetifacehaldat(iface); + hid_device* pHid = (hid_device*)atgetifacehaldat(iface); ATCAIfaceCfg *pCfg = atgetifacecfg(iface); int i = 0; @@ -160,18 +110,13 @@ ATCA_STATUS hal_kit_hid_post_init(ATCAIface iface) return ATCA_BAD_PARAM; } - // Perform the kit protocol init - for (i = 0; i < pHid->num_kits_found; i++) - { - status = kit_init(iface); - if (status != ATCA_SUCCESS) + status = kit_init(iface); + if (status != ATCA_SUCCESS) #ifdef KIT_DEBUG - { printf("kit_init() Failed"); } + { printf("kit_init() Failed"); } #endif - { - ATCA_TRACE(status, "kit_init() failed"); - break; - } + { + ATCA_TRACE(status, "kit_init() failed"); } return status; @@ -186,7 +131,7 @@ ATCA_STATUS hal_kit_hid_post_init(ATCAIface iface) ATCA_STATUS kit_phy_send(ATCAIface iface, uint8_t* txdata, int txlength) { ATCAIfaceCfg *cfg = atgetifacecfg(iface); - atcahid_t* pHid = (atcahid_t*)atgetifacehaldat(iface); + hid_device* pHid = (hid_device*)atgetifacehaldat(iface); int bytes_written = 0; int bytes_left; int bytes_to_send; @@ -197,11 +142,6 @@ ATCA_STATUS kit_phy_send(ATCAIface iface, uint8_t* txdata, int txlength) return ATCA_BAD_PARAM; } - if (pHid->kits[cfg->atcahid.idx] == NULL) - { - return ATCA_COMM_FAIL; - } - #ifdef KIT_DEBUG printf("HID layer: Write: %s", txdata); #endif @@ -223,7 +163,7 @@ ATCA_STATUS kit_phy_send(ATCAIface iface, uint8_t* txdata, int txlength) memcpy(&buffer[1], &txdata[(txlength - bytes_left)], bytes_to_send); - bytes_written = hid_write(pHid->kits[cfg->atcahid.idx], buffer, cfg->atcahid.packetsize + 1); + bytes_written = hid_write(pHid, buffer, (size_t)cfg->atcahid.packetsize + 1); if (bytes_written != cfg->atcahid.packetsize + 1) { return ATCA_TX_FAIL; @@ -244,8 +184,7 @@ ATCA_STATUS kit_phy_send(ATCAIface iface, uint8_t* txdata, int txlength) ATCA_STATUS kit_phy_receive(ATCAIface iface, uint8_t* rxdata, int* rxsize) { ATCAIfaceCfg *cfg = atgetifacecfg(iface); - atcahid_t* pHid = (atcahid_t*)atgetifacehaldat(iface); - bool continue_read = true; + hid_device* pHid = (hid_device*)atgetifacehaldat(iface); size_t bytes_read = 0; size_t total_bytes_read = 0; size_t bytes_to_read = *rxsize; @@ -256,34 +195,23 @@ ATCA_STATUS kit_phy_receive(ATCAIface iface, uint8_t* rxdata, int* rxsize) return ATCA_BAD_PARAM; } - if (pHid->kits[cfg->atcahid.idx] == NULL) - { - return ATCA_COMM_FAIL; - } - bytes_to_read--; - //hid_get_product_string(pHid->kits[cfg->atcahid.idx], &rxdata[total_bytes_read], bytes_to_read); - //printf("%s\n", rxdata); + // Receive the data from the kit USB device do { - bytes_read = hid_read(pHid->kits[cfg->atcahid.idx], &rxdata[total_bytes_read], bytes_to_read); + bytes_read = hid_read(pHid, &rxdata[total_bytes_read], bytes_to_read); if (bytes_read == -1) { return ATCA_RX_FAIL; } + + location = memchr(&rxdata[total_bytes_read], '\n', bytes_read); + total_bytes_read += bytes_read; bytes_to_read -= bytes_read; - - // Check if the kit protocol message has been received - if (strstr((char*)rxdata, "\n") != NULL) - { - continue_read = false; - } } - while (continue_read == true); - - location = strchr((char*)rxdata, '\n'); + while (!location && 0 < bytes_to_read); // Save the total bytes read if (location != NULL) @@ -308,9 +236,7 @@ ATCA_STATUS kit_phy_receive(ATCAIface iface, uint8_t* rxdata, int* rxsize) */ ATCA_STATUS kit_phy_num_found(int8_t* num_found) { - *num_found = _gHid.num_kits_found; - - return ATCA_SUCCESS; + return ATCA_UNIMPLEMENTED; } /** \brief HAL implementation of kit protocol send over USB HID @@ -375,22 +301,15 @@ ATCA_STATUS hal_kit_hid_sleep(ATCAIface iface) */ ATCA_STATUS hal_kit_hid_release(void* hal_data) { - atcahid_t* phaldat = (atcahid_t*)hal_data; + hid_device* pHid = (hid_device*)hal_data; int i = 0; - if (phaldat == NULL) + if (pHid == NULL) { return ATCA_BAD_PARAM; } - // Close all kit USB devices - for (i = 0; i < phaldat->num_kits_found; i++) - { - if (_gHid.kits[i] != NULL) - { - hid_close(_gHid.kits[i]); - } - } + hid_close(pHid); return ATCA_SUCCESS; } diff --git a/lib/hal/hal_all_platforms_kit_hidapi.h b/lib/hal/hal_all_platforms_kit_hidapi.h deleted file mode 100644 index b10d030ce..000000000 --- a/lib/hal/hal_all_platforms_kit_hidapi.h +++ /dev/null @@ -1,55 +0,0 @@ -/** - * \file - * \brief HAL for kit protocol over HID for any platform. - * - * \copyright (c) 2015-2020 Microchip Technology Inc. and its subsidiaries. - * - * \page License - * - * Subject to your compliance with these terms, you may use Microchip software - * and any derivatives exclusively with Microchip products. It is your - * responsibility to comply with third party license terms applicable to your - * use of third party software (including open source software) that may - * accompany Microchip software. - * - * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER - * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED - * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, - * SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE - * OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF - * MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE - * FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL - * LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED - * THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR - * THIS SOFTWARE. - */ - -#ifndef HAL_MACOS_KIT_HID_H_ -#define HAL_MACOS_KIT_HID_H_ - -#include "hidapi.h" - -/** \defgroup hal_ Hardware abstraction layer (hal_) - * - * \brief - * These methods define the hardware abstraction layer for communicating with a CryptoAuth device - * - @{ */ - -// Kit USB defines -#define HID_DEVICES_MAX 10 //! Maximum number of supported Kit USB devices -#define HID_PACKET_MAX 512 //! Maximum number of bytes for a HID send/receive packet (typically 64) - - - - -// A structure to hold HID information -typedef struct atcahid -{ - hid_device* kits[HID_DEVICES_MAX]; - int8_t num_kits_found; -} atcahid_t; - -/** @} */ -#endif /* HAL_LINUX_KIT_HID_H_ */ diff --git a/lib/hal/hal_harmony.h b/lib/hal/hal_harmony.h deleted file mode 100644 index 86178c08c..000000000 --- a/lib/hal/hal_harmony.h +++ /dev/null @@ -1,57 +0,0 @@ -/** - * \file - * \brief Harmony PLIB Definitions for Cryptoauthlib Drivers. - * - * \copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries. - * - * \page License - * - * Subject to your compliance with these terms, you may use Microchip software - * and any derivatives exclusively with Microchip products. It is your - * responsibility to comply with third party license terms applicable to your - * use of third party software (including open source software) that may - * accompany Microchip software. - * - * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER - * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED - * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, - * SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE - * OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF - * MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE - * FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL - * LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED - * THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR - * THIS SOFTWARE. - */ - -#ifndef HAL_HARMONY_H -#define HAL_HARMONY_H - -typedef bool (* atca_i2c_plib_read)(uint16_t, uint8_t *, PLIB_SIZE_VAR_TYPE); -typedef bool (* atca_i2c_plib_write)(uint16_t, uint8_t *, PLIB_SIZE_VAR_TYPE); -typedef bool (* atca_i2c_plib_is_busy)(void); -typedef PLIB_I2C_ERROR (* atca_i2c_error_get)(void); -typedef bool (* atca_i2c_plib_transfer_setup)(PLIB_I2C_TRANSFER_SETUP* setup, uint32_t srcClkFreq); - -typedef struct atca_plib_i2c_api -{ - atca_i2c_plib_read read; - atca_i2c_plib_write write; - atca_i2c_plib_is_busy is_busy; - atca_i2c_error_get error_get; - atca_i2c_plib_transfer_setup transfer_setup; -} atca_plib_api_t; - -typedef struct atca_plib_uart_api -{ - atca_uart_plib_read read; - atca_uart_plib_write write; - atca_uart_plib_is_busy is_busy; - atca_uart_error_get error_get; - atca_uart_plib_transfer_setup transfer_setup; -} atca_plib_api_t; - - - -#endif /* HAL_HARMONY_H */ \ No newline at end of file diff --git a/lib/hal/hal_i2c_harmony.c b/lib/hal/hal_i2c_harmony.c index 3924c0e97..00b17ee13 100644 --- a/lib/hal/hal_i2c_harmony.c +++ b/lib/hal/hal_i2c_harmony.c @@ -74,6 +74,29 @@ ATCA_STATUS hal_i2c_discover_devices(int bus_num, ATCAIfaceCfg cfg[], int *found return ATCA_UNIMPLEMENTED; } +static ATCA_STATUS hal_i2c_wait(atca_plib_i2c_api_t* plib, uint32_t rate, uint16_t length) +{ + ATCA_STATUS status = ATCA_SUCCESS; + /* Maximum packet size is 1024 bytes (TA device) and 200 bytes (CA device) */ + /* so assume rate can be sub 1kHz */ + uint32_t timeout = (uint32_t)length * 9 * 1000; + + rate /= 1000; + timeout /= rate; + timeout += 1; /* Make sure the timeout value is non zero */ + + while ((true == plib->is_busy()) && (timeout--)) + { + atca_delay_us(1); + } + + if (0 == timeout) + { + status = ATCA_COMM_FAIL; + } + + return status; +} /** \brief @@ -119,6 +142,7 @@ ATCA_STATUS hal_i2c_send(ATCAIface iface, uint8_t word_address, uint8_t *txdata, { ATCAIfaceCfg* cfg = atgetifacecfg(iface); atca_plib_i2c_api_t * plib; + ATCA_STATUS status = ATCA_COMM_FAIL; if (!cfg) { @@ -131,6 +155,7 @@ ATCA_STATUS hal_i2c_send(ATCAIface iface, uint8_t word_address, uint8_t *txdata, return ATCA_BAD_PARAM; } + if (0xFF != word_address) { txdata[0] = word_address; // insert the Word Address Value, Command token @@ -138,25 +163,29 @@ ATCA_STATUS hal_i2c_send(ATCAIface iface, uint8_t word_address, uint8_t *txdata, } /* Wait for the I2C bus to be ready */ - while (plib->is_busy() == true); + /* Since the wait time is unknown, waiting for 30 bytes duration */ + status = hal_i2c_wait(plib, cfg->atcai2c.baud, 30); - if (plib->write(cfg->atcai2c.slave_address>>1, txdata, txlength) == true) + if (ATCA_SUCCESS == status) { - /* Wait for the I2C transfer to complete */ - while (plib->is_busy() == true); - - /* Transfer complete. Check if the transfer was successful */ - if (plib->error_get() != PLIB_I2C_ERROR_NONE) + status = ATCA_COMM_FAIL; + if (plib->write(cfg->atcai2c.slave_address>>1, txdata, txlength) == true) { - return ATCA_COMM_FAIL; + /* Wait for the I2C transfer to complete */ + status = hal_i2c_wait(plib, cfg->atcai2c.baud, txlength); + + if (ATCA_SUCCESS == status) + { + /* Transfer complete. Check if the transfer was successful */ + if (plib->error_get() != PLIB_I2C_ERROR_NONE) + { + status = ATCA_TRACE(ATCA_COMM_FAIL, "plib->write failed"); + } + } } } - else - { - return ATCA_COMM_FAIL; - } - return ATCA_SUCCESS; + return status; } /** \brief HAL implementation of I2C receive function for START I2C @@ -169,7 +198,7 @@ ATCA_STATUS hal_i2c_send(ATCAIface iface, uint8_t word_address, uint8_t *txdata, */ ATCA_STATUS hal_i2c_receive(ATCAIface iface, uint8_t word_address, uint8_t *rxdata, uint16_t *rxlength) { - ATCA_STATUS status = !ATCA_SUCCESS; + ATCA_STATUS status = ATCA_COMM_FAIL; ATCAIfaceCfg* cfg = atgetifacecfg(iface); uint16_t rxdata_max_size; uint16_t read_length = 2; @@ -179,12 +208,12 @@ ATCA_STATUS hal_i2c_receive(ATCAIface iface, uint8_t word_address, uint8_t *rxda if ((NULL == cfg) || (NULL == rxlength) || (NULL == rxdata)) { - return ATCA_TRACE(ATCA_INVALID_POINTER, "NULL pointer encountered"); + return ATCA_TRACE(ATCA_BAD_PARAM, "NULL pointer encountered"); } - if(NULL == (plib = (atca_plib_i2c_api_t*)cfg->cfg_data)) + if (NULL == (plib = (atca_plib_i2c_api_t*)cfg->cfg_data)) { - return ATCA_TRACE(ATCA_INVALID_POINTER, "NULL pointer encountered"); + return ATCA_TRACE(ATCA_BAD_PARAM, "NULL pointer encountered"); } rxdata_max_size = *rxlength; @@ -198,7 +227,7 @@ ATCA_STATUS hal_i2c_receive(ATCAIface iface, uint8_t word_address, uint8_t *rxda { status = hal_i2c_send(iface, word_address, &word_address, 0); } - if(ATCA_SUCCESS != status) + if (ATCA_SUCCESS != status) { ATCA_TRACE(status, "hal_i2c_send - failed"); break; @@ -218,27 +247,29 @@ ATCA_STATUS hal_i2c_receive(ATCAIface iface, uint8_t word_address, uint8_t *rxda if (plib->read(cfg->atcai2c.slave_address>>1, rxdata, read_length) == true) { /* Wait for the I2C transfer to complete */ - while (plib->is_busy() == true); - /* Transfer complete. Check if the transfer was successful */ - if (plib->error_get() == PLIB_I2C_ERROR_NONE) + if (ATCA_SUCCESS == (status = hal_i2c_wait(plib, cfg->atcai2c.baud, read_length))) { - status = ATCA_SUCCESS; + /* Transfer complete. Check if the transfer was successful */ + if (plib->error_get() != PLIB_I2C_ERROR_NONE) + { + status = ATCA_COMM_FAIL; + } } } - if(ATCA_SUCCESS != status) + if (ATCA_SUCCESS != status) { ATCA_TRACE(status, "plib->read - failed"); break; } - if(1 == read_length) + if (1 == read_length) { ATCA_TRACE(status, "1 byte read completed"); break; } /*Calculate bytes to read based on device response*/ - if(cfg->devtype == TA100) + if (cfg->devtype == TA100) { read_length = ((uint16_t)rxdata[0] * 256) + rxdata[1]; min_resp_size += 1; @@ -259,20 +290,22 @@ ATCA_STATUS hal_i2c_receive(ATCAIface iface, uint8_t word_address, uint8_t *rxda status = ATCA_TRACE(ATCA_RX_FAIL, "packet size is invalid"); break; } - + /* Read given length bytes from device */ status = ATCA_COMM_FAIL; if (plib->read(cfg->atcai2c.slave_address>>1, &rxdata[2], read_length - 2) == true) { /* Wait for the I2C transfer to complete */ - while (plib->is_busy() == true); - /* Transfer complete. Check if the transfer was successful */ - if (plib->error_get() == PLIB_I2C_ERROR_NONE) + if (ATCA_SUCCESS == (status = hal_i2c_wait(plib, cfg->atcai2c.baud, read_length - 2))) { - status = ATCA_SUCCESS; + /* Transfer complete. Check if the transfer was successful */ + if (plib->error_get() != PLIB_I2C_ERROR_NONE) + { + status = ATCA_COMM_FAIL; + } } } - if(ATCA_SUCCESS != status) + if (ATCA_SUCCESS != status) { status = ATCA_TRACE(status, "plib->read - failed"); break; @@ -288,29 +321,36 @@ ATCA_STATUS hal_i2c_receive(ATCAIface iface, uint8_t word_address, uint8_t *rxda * \param[in] iface interface on which to change bus speed * \param[in] speed baud rate (typically 100000 or 400000) */ -void change_i2c_speed(ATCAIface iface, uint32_t speed) +ATCA_STATUS change_i2c_speed(ATCAIface iface, uint32_t speed) { ATCAIfaceCfg* cfg = atgetifacecfg(iface); atca_plib_i2c_api_t * plib; + ATCA_STATUS status = ATCA_COMM_FAIL; if (!cfg) { - return; + return ATCA_BAD_PARAM; } plib = (atca_plib_i2c_api_t*)cfg->cfg_data; if (!plib) { - return; + return ATCA_BAD_PARAM; } PLIB_I2C_TRANSFER_SETUP setup; setup.clkSpeed = speed; /* Make sure I2C is not busy before changing the I2C clock speed */ - while (plib->is_busy() == true); + /* Since wait time is unknown, wait for 30 bytes */ + status = hal_i2c_wait(plib, cfg->atcai2c.baud, 30); + + if (ATCA_SUCCESS == status) + { + (void)plib->transfer_setup(&setup, 0); + } - (void)plib->transfer_setup(&setup, 0); + return status; } /** \brief wake up CryptoAuth device using I2C bus @@ -320,72 +360,86 @@ void change_i2c_speed(ATCAIface iface, uint32_t speed) ATCA_STATUS hal_i2c_wake(ATCAIface iface) { + ATCA_STATUS status = ATCA_SUCCESS; ATCAIfaceCfg* cfg = atgetifacecfg(iface); atca_plib_i2c_api_t * plib; int retries; uint32_t bdrt; uint8_t data[4] = {0}; - bool isSuccess = false; if (!cfg) { - return ATCA_BAD_PARAM; + return ATCA_TRACE(ATCA_BAD_PARAM, "NULL pointer received"); } plib = (atca_plib_i2c_api_t*)cfg->cfg_data; if (!plib) { - return ATCA_BAD_PARAM; + return ATCA_TRACE(ATCA_BAD_PARAM, "NULL pointer received"); } + retries = cfg->rx_retries; bdrt = cfg->atcai2c.baud; if (bdrt != 100000) // if not already at 100KHz, change it { - change_i2c_speed(iface, 100000); + status = change_i2c_speed(iface, 100000); } - while (plib->is_busy() == true); - - // Send the 00 address as the wake pulse; part will NACK, so don't check for status - (void)plib->write(0x00, (uint8_t*)&data[0], 1); - - /* Wait for the I2C transfer to complete */ - while (plib->is_busy() == true); - - // wait tWHI + tWLO which is configured based on device type and configuration structure - atca_delay_us(cfg->wake_delay); - - while (retries-- > 0 && isSuccess == false) + if (ATCA_SUCCESS == status) { - if (plib->read(cfg->atcai2c.slave_address>>1, (uint8_t*)&data[0], 4) == true) + /* Wait for the I2C bus to be ready */ + /* Since the wait time is unknown, waiting for 30 bytes duration */ + if (ATCA_SUCCESS == (status = hal_i2c_wait(plib, cfg->atcai2c.baud, 30))) { + // Send the 00 address as the wake pulse; part will NACK, so don't check for status + (void)plib->write(0x00, (uint8_t*)&data[0], 1); + /* Wait for the I2C transfer to complete */ - while (plib->is_busy() == true); + status = hal_i2c_wait(plib, cfg->atcai2c.baud, 1); + } + } + + if (ATCA_SUCCESS == status) + { + // wait tWHI + tWLO which is configured based on device type and configuration structure + atca_delay_us(cfg->wake_delay); - /* Transfer complete. Check if the transfer was successful */ - if (plib->error_get() == PLIB_I2C_ERROR_NONE) + status = ATCA_COMM_FAIL; + while (retries-- > 0 && status == ATCA_COMM_FAIL) + { + if (plib->read(cfg->atcai2c.slave_address>>1, (uint8_t*)&data[0], 4) == true) { - isSuccess = true; + /* Wait for the I2C transfer to complete */ + status = hal_i2c_wait(plib, cfg->atcai2c.baud, 4); + + if (ATCA_SUCCESS == status) + { + /* Transfer complete. Check if the transfer was successful */ + if (plib->error_get() != PLIB_I2C_ERROR_NONE) + { + status = ATCA_COMM_FAIL; + } + } + } + } + if (ATCA_SUCCESS == status) + { + // if necessary, revert baud rate to what came in. + if (bdrt != 100000) + { + status = change_i2c_speed(iface, bdrt); } } - } - if (isSuccess == true) - { - // if necessary, revert baud rate to what came in. - if (bdrt != 100000) + if (ATCA_SUCCESS == status) { - change_i2c_speed(iface, bdrt); + status = hal_check_wake(data, 4); } } - else - { - return ATCA_COMM_FAIL; - } - return hal_check_wake(data, 4); + return status; } /** \brief idle CryptoAuth device using I2C bus @@ -395,6 +449,7 @@ ATCA_STATUS hal_i2c_wake(ATCAIface iface) ATCA_STATUS hal_i2c_idle(ATCAIface iface) { + ATCA_STATUS status = ATCA_COMM_FAIL; ATCAIfaceCfg* cfg = atgetifacecfg(iface); atca_plib_i2c_api_t * plib; uint8_t data[1]; @@ -413,25 +468,29 @@ ATCA_STATUS hal_i2c_idle(ATCAIface iface) data[0] = 0x02; // idle word address value /* Wait for the I2C bus to be ready */ - while (plib->is_busy() == true); + /* Since wait time is unknown, wait for 30 bytes time */ + status = hal_i2c_wait(plib, cfg->atcai2c.baud, 30); - if (plib->write(cfg->atcai2c.slave_address>>1, (uint8_t*)&data[0], 1) == true) + if (ATCA_SUCCESS == status) { - /* Wait for the I2C transfer to complete */ - while (plib->is_busy() == true); - - /* Transfer complete. Check if the transfer was successful */ - if (plib->error_get() != PLIB_I2C_ERROR_NONE) + status = ATCA_COMM_FAIL; + if (plib->write(cfg->atcai2c.slave_address>>1, (uint8_t*)&data[0], 1) == true) { - return ATCA_COMM_FAIL; + /* Wait for the I2C transfer to complete */ + status = hal_i2c_wait(plib, cfg->atcai2c.baud, 1); + + if (ATCA_SUCCESS == status) + { + /* Transfer complete. Check if the transfer was successful */ + if (plib->error_get() != PLIB_I2C_ERROR_NONE) + { + status = ATCA_TRACE(ATCA_COMM_FAIL, "plib->write failed"); + } + } } } - else - { - return ATCA_COMM_FAIL; - } - return ATCA_SUCCESS; + return status; } /** \brief sleep CryptoAuth device using I2C bus @@ -441,6 +500,7 @@ ATCA_STATUS hal_i2c_idle(ATCAIface iface) ATCA_STATUS hal_i2c_sleep(ATCAIface iface) { + ATCA_STATUS status = ATCA_COMM_FAIL; ATCAIfaceCfg* cfg = atgetifacecfg(iface); atca_plib_i2c_api_t * plib; uint8_t data[4]; @@ -459,25 +519,29 @@ ATCA_STATUS hal_i2c_sleep(ATCAIface iface) data[0] = 0x01; // sleep word address value /* Wait for the I2C bus to be ready */ - while (plib->is_busy() == true); + /* Since wait time is unknown, wait for 30 bytes time */ + status = hal_i2c_wait(plib, cfg->atcai2c.baud, 30); - if (plib->write(cfg->atcai2c.slave_address>>1, (uint8_t*)&data[0], 1) == true) + if (ATCA_SUCCESS == status) { - /* Wait for the I2C transfer to complete */ - while (plib->is_busy() == true); - - /* Transfer complete. Check if the transfer was successful */ - if (plib->error_get() != PLIB_I2C_ERROR_NONE) + status = ATCA_COMM_FAIL; + if (plib->write(cfg->atcai2c.slave_address>>1, (uint8_t*)&data[0], 1) == true) { - return ATCA_COMM_FAIL; + /* Wait for the I2C transfer to complete */ + status = hal_i2c_wait(plib, cfg->atcai2c.baud, 1); + + if (ATCA_SUCCESS == status) + { + /* Transfer complete. Check if the transfer was successful */ + if (plib->error_get() != PLIB_I2C_ERROR_NONE) + { + status = ATCA_TRACE(ATCA_COMM_FAIL, "plib->write failed"); + } + } } } - else - { - return ATCA_COMM_FAIL; - } - return ATCA_SUCCESS; + return status; } /** \brief manages reference count on given bus and releases resource if no more refences exist diff --git a/lib/hal/hal_linux_kit_hid.c b/lib/hal/hal_linux_kit_hid.c deleted file mode 100644 index 71ecc7edf..000000000 --- a/lib/hal/hal_linux_kit_hid.c +++ /dev/null @@ -1,426 +0,0 @@ -/** - * \file - * \brief ATCA Hardware abstraction layer for Linux using kit protocol over a USB HID device. - * - * \copyright (c) 2015-2020 Microchip Technology Inc. and its subsidiaries. - * - * \page License - * - * Subject to your compliance with these terms, you may use Microchip software - * and any derivatives exclusively with Microchip products. It is your - * responsibility to comply with third party license terms applicable to your - * use of third party software (including open source software) that may - * accompany Microchip software. - * - * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER - * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED - * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, - * SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE - * OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF - * MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE - * FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL - * LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED - * THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR - * THIS SOFTWARE. - */ - -#include -#include -#include -#include - -#include "atca_hal.h" -#include "hal_linux_kit_hid.h" -#include "hal/kit_protocol.h" - -/** \defgroup hal_ Hardware abstraction layer (hal_) - * - * \brief - * These methods define the hardware abstraction layer for communicating with a CryptoAuth device - * - @{ */ - -// File scope globals -atcahid_t _gHid; - -/** \brief discover hid buses available for this hardware - * this maintains a list of logical to physical bus mappings freeing the application - * of the a-priori knowledge.This function is currently not implemented. - * \param[in] hid_buses - an array of logical bus numbers - * \param[in] max_buses - maximum number of buses the app wants to attempt to discover - * \return ATCA_UNIMPLEMENTED - */ - -ATCA_STATUS hal_kit_hid_discover_buses(int hid_buses[], int max_buses) -{ - return ATCA_UNIMPLEMENTED; -} - -/** \brief discover any CryptoAuth devices on a given logical bus number.This function is currently not implemented. - * \param[in] bus_num - logical bus number on which to look for CryptoAuth devices - * \param[out] cfg[] - pointer to head of an array of interface config structures which get filled in by this method - * \param[out] *found - number of devices found on this bus - * \return ATCA_UNIMPLEMENTED - */ -ATCA_STATUS hal_kit_hid_discover_devices(int bus_num, ATCAIfaceCfg cfg[], int *found) -{ - return ATCA_UNIMPLEMENTED; -} - -/** \brief HAL implementation of Kit USB HID init - * \param[in] hal pointer to HAL specific data that is maintained by this HAL - * \param[in] cfg pointer to HAL specific configuration data that is used to initialize this HAL - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS hal_kit_hid_init(void* hal, ATCAIfaceCfg* cfg) -{ - ATCAHAL_t *phal = (ATCAHAL_t*)hal; - int status = 0; - struct udev *udev = NULL; - struct udev_enumerate *enumerate = NULL; - struct udev_list_entry *list = NULL; - struct udev_list_entry *list_entry = NULL; - struct udev_device *syspath_device = NULL; - struct udev_device *device = NULL; - int i = 0; - char hid_filter[20]; - char device_hid[20]; - FILE *file_descriptor = NULL; - int index = 0; - - // Check the input variables - if ((cfg == NULL) || (phal == NULL)) - { - return ATCA_BAD_PARAM; - } - - // Initialize the _gHid structure - memset(&_gHid, 0, sizeof(_gHid)); - for (i = 0; i < HID_DEVICES_MAX; i++) - { - _gHid.kits[i].read_handle = NULL; - _gHid.kits[i].write_handle = NULL; - } - - _gHid.num_kits_found = 0; - - // Create the udev object - udev = udev_new(); - if (udev == NULL) - { - return ATCA_COMM_FAIL; - } - - // Create the enumerate object - enumerate = udev_enumerate_new(udev); - if (enumerate == NULL) - { - // Free the udev object - udev_unref(udev); - - return ATCA_COMM_FAIL; - } - - // Create the list of available USB devices - status = udev_enumerate_add_match_subsystem(enumerate, "hidraw"); - if (status >= 0) - { - status = udev_enumerate_scan_devices(enumerate); - if (status >= 0) - { - list = udev_enumerate_get_list_entry(enumerate); - } - } - - // Create the HID filter string - memset(hid_filter, 0, sizeof(hid_filter)); - sprintf(hid_filter, "vid_%04x&pid_%04x", cfg->atcahid.vid, cfg->atcahid.pid); - - // Find the available kit USB devices - udev_list_entry_foreach(list_entry, list) - { - // Get the udev device - syspath_device = udev_device_new_from_syspath(udev, udev_list_entry_get_name(list_entry)); - device = udev_device_get_parent_with_subsystem_devtype(syspath_device, "usb", "usb_device"); - - // Create the device HID string - memset(device_hid, 0, sizeof(device_hid)); - sprintf(device_hid, "vid_%s&pid_%s", - udev_device_get_sysattr_value(device, "idVendor"), - udev_device_get_sysattr_value(device, "idProduct")); - - // Determine if this is the correct kit USB device - if (strcasecmp(device_hid, hid_filter) == 0) - { - // Open the kit USB device for reading and writing - if (_gHid.kits[index].read_handle != NULL) - { - fclose(_gHid.kits[index].read_handle); - } - if (_gHid.kits[index].write_handle != NULL) - { - fclose(_gHid.kits[index].write_handle); - } - - file_descriptor = fopen(udev_device_get_devnode(syspath_device), "rb+"); - if (file_descriptor != NULL) - { - _gHid.kits[index].read_handle = file_descriptor; - _gHid.kits[index].write_handle = file_descriptor; - - // Increment the opened kit USB device index - index++; - -#ifdef KIT_DEBUG - printf("Kit USB Device Node: %s\n", udev_device_get_devnode(syspath_device)); - printf(" Manufacturer %s (%s)\n", - udev_device_get_sysattr_value(device, "manufacturer"), - udev_device_get_sysattr_value(device, "product")); - printf(" VID/PID: %s %s\n", - udev_device_get_sysattr_value(device, "idVendor"), - udev_device_get_sysattr_value(device, "idProduct")); -#endif // KIT_DEBUG - } - else - { -#ifdef KIT_DEBUG - printf("fopen(\"%s\") failed with errno=%d\n", - udev_device_get_devnode(syspath_device), - errno); -#endif // KIT_DEBUG - } - } - - // Free the udev device object - udev_device_unref(syspath_device); - } - - // Save the results of this discovery of HID - if (index > 0) - { - _gHid.num_kits_found = index; - phal->hal_data = &_gHid; - } - - // Free the enumerator object - udev_enumerate_unref(enumerate); - - // Free the udev object - udev_unref(udev); - - return ATCA_SUCCESS; -} - -/** \brief HAL implementation of Kit HID post init - * \param[in] iface instance - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS hal_kit_hid_post_init(ATCAIface iface) -{ - ATCA_STATUS status = ATCA_SUCCESS; - atcahid_t* pHid = atgetifacehaldat(iface); - ATCAIfaceCfg *pCfg = atgetifacecfg(iface); - int i = 0; - - if ((pHid == NULL) || (pCfg == NULL)) - { - return ATCA_BAD_PARAM; - } - - // Perform the kit protocol init - for (i = 0; i < pHid->num_kits_found; i++) - { - status = kit_init(iface); - if (status != ATCA_SUCCESS) - { - ATCA_TRACE(status, "kit_init() Failed"); - break; - } - } - - return status; -} - -/** \brief HAL implementation of send over Kit protocol.This function is called by the top layer. - * \param[in] iface instance - * \param[in] txdata pointer to bytes to send - * \param[in] txlength number of bytes to send - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS kit_phy_send(ATCAIface iface, uint8_t* txdata, int txlength) -{ - ATCAIfaceCfg *cfg = atgetifacecfg(iface); - atcahid_t* pHid = (atcahid_t*)atgetifacehaldat(iface); - size_t bytes_written = 0; - - if ((txdata == NULL) || (cfg == NULL) || (pHid == NULL)) - { - return ATCA_BAD_PARAM; - } - - if (pHid->kits[cfg->atcahid.idx].write_handle == NULL) - { - return ATCA_COMM_FAIL; - } - - // Send the data to the kit USB device - if (txlength > 0) - { - bytes_written = fwrite(txdata, sizeof(uint8_t), txlength, - pHid->kits[cfg->atcahid.idx].write_handle); - if (bytes_written != txlength) - { - clearerr(pHid->kits[cfg->atcahid.idx].write_handle); - return ATCA_TX_FAIL; - } - } - - return ATCA_SUCCESS; -} - -/** \brief HAL implementation of kit protocol receive.This function is called by the top layer. - * \param[in] iface instance - * \param[out] rxdata pointer to space to receive the data - * \param[in,out] rxsize ptr to expected number of receive bytes to request - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS kit_phy_receive(ATCAIface iface, uint8_t* rxdata, int* rxsize) -{ - ATCAIfaceCfg *cfg = atgetifacecfg(iface); - atcahid_t* pHid = (atcahid_t*)atgetifacehaldat(iface); - bool continue_read = true; - size_t bytes_read = 0; - size_t total_bytes_read = 0; - - if ((rxdata == NULL) || (rxsize == NULL) || (cfg == NULL) || (pHid == NULL)) - { - return ATCA_BAD_PARAM; - } - - if (pHid->kits[cfg->atcahid.idx].read_handle == NULL) - { - return ATCA_COMM_FAIL; - } - - // Receive the data from the kit USB device - do - { - bytes_read = fread(&rxdata[total_bytes_read], sizeof(uint8_t), 1, - pHid->kits[cfg->atcahid.idx].read_handle); - if (ferror(pHid->kits[cfg->atcahid.idx].read_handle) != 0) - { - clearerr(pHid->kits[cfg->atcahid.idx].read_handle); - return ATCA_RX_FAIL; - } - - total_bytes_read += bytes_read; - - // Check if the kit protocol message has been received - if (strstr((char*)rxdata, "\n") != NULL) - { - continue_read = false; - } - } - while (continue_read == true); - - // Save the total bytes read - *rxsize = total_bytes_read; - - return ATCA_SUCCESS; -} - -/** \brief Number of USB HID devices found - * \param[out] num_found - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS kit_phy_num_found(int8_t* num_found) -{ - *num_found = _gHid.num_kits_found; - - return ATCA_SUCCESS; -} - -/** \brief HAL implementation of kit protocol send over USB HID - * \param[in] iface instance - * \param[in] txdata pointer to bytes to send - * \param[in] txlength number of bytes to send - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS hal_kit_hid_send(ATCAIface iface, uint8_t word_address, uint8_t* txdata, int txlength) -{ - // Call the kit_send() function that will call phy_send() implemented below - return kit_send(iface, word_address, txdata, txlength); -} - -/** \brief HAL implementation of send over USB HID - * \param[in] iface instance - * \param[in] rxdata pointer to space to receive the data - * \param[in,out] rxsize ptr to expected number of receive bytes to request - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS hal_kit_hid_receive(ATCAIface iface, uint8_t word_address, uint8_t* rxdata, uint16_t* rxsize) -{ - // Call the kit_receive() function that will call phy_receive() implemented below - return kit_receive(iface, word_address, rxdata, rxsize); -} - -/** \brief Call the wake for kit protocol over USB HID - * \param[in] iface ATCAIface instance that is the interface object to send the bytes over - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS hal_kit_hid_wake(ATCAIface iface) -{ - // Call the kit_wake() function that will call phy_send() and phy_receive() - return kit_wake(iface); -} - -/** \brief Call the idle for kit protocol over USB HID - * \param[in] iface ATCAIface instance that is the interface object to send the bytes over - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS hal_kit_hid_idle(ATCAIface iface) -{ - // Call the kit_idle() function that will call phy_send() and phy_receive() - return kit_idle(iface); -} - -/** \brief Call the sleep for kit protocol over USB HID - * \param[in] iface ATCAIface instance that is the interface object to send the bytes over - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS hal_kit_hid_sleep(ATCAIface iface) -{ - // Call the kit_sleep() function that will call phy_send() and phy_receive() - return kit_sleep(iface); -} - -/** \brief Close the physical port for HID - * \param[in] hal_data The hardware abstraction data specific to this HAL - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS hal_kit_hid_release(void* hal_data) -{ - atcahid_t* phaldat = (atcahid_t*)hal_data; - int i = 0; - - if (phaldat == NULL) - { - return ATCA_BAD_PARAM; - } - - // Close all kit USB devices - for (i = 0; i < phaldat->num_kits_found; i++) - { - if (_gHid.kits[i].read_handle != NULL) - { - fclose(_gHid.kits[i].read_handle); - _gHid.kits[i].read_handle = NULL; - _gHid.kits[i].write_handle = NULL; - } - } - - return ATCA_SUCCESS; -} - -/** @} */ diff --git a/lib/hal/hal_linux_kit_hid.h b/lib/hal/hal_linux_kit_hid.h deleted file mode 100644 index c29a259cc..000000000 --- a/lib/hal/hal_linux_kit_hid.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - * \file - * \brief ATCA Hardware abstraction layer for Linux using kit protocol over a USB HID device. - * - * \copyright (c) 2015-2020 Microchip Technology Inc. and its subsidiaries. - * - * \page License - * - * Subject to your compliance with these terms, you may use Microchip software - * and any derivatives exclusively with Microchip products. It is your - * responsibility to comply with third party license terms applicable to your - * use of third party software (including open source software) that may - * accompany Microchip software. - * - * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER - * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED - * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, - * SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE - * OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF - * MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE - * FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL - * LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED - * THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR - * THIS SOFTWARE. - */ - -#ifndef HAL_LINUX_KIT_HID_H_ -#define HAL_LINUX_KIT_HID_H_ - -/** \defgroup hal_ Hardware abstraction layer (hal_) - * - * \brief - * These methods define the hardware abstraction layer for communicating with a CryptoAuth device - * - @{ */ - -// Kit USB defines -#define HID_DEVICES_MAX 10 //! Maximum number of supported Kit USB devices -#define HID_PACKET_MAX 512 //! Maximum number of bytes for a HID send/receive packet (typically 64) - -// Each device that is found will have a read handle and a write handle -typedef struct hid_device -{ - FILE *read_handle; //! The kit USB read file handle - FILE *write_handle; //! The kit USB write file handle -} hid_device_t; - - -// A structure to hold HID information -typedef struct atcahid -{ - hid_device_t kits[HID_DEVICES_MAX]; - int8_t num_kits_found; -} atcahid_t; - -/** @} */ -#endif /* HAL_LINUX_KIT_HID_H_ */ diff --git a/lib/hal/hal_win_kit_hid.c b/lib/hal/hal_win_kit_hid.c deleted file mode 100644 index d5f939372..000000000 --- a/lib/hal/hal_win_kit_hid.c +++ /dev/null @@ -1,470 +0,0 @@ -/** - * \file - * \brief ATCA Hardware abstraction layer for Windows using kit protocol over a USB HID device. - * - * \copyright (c) 2015-2020 Microchip Technology Inc. and its subsidiaries. - * - * \page License - * - * Subject to your compliance with these terms, you may use Microchip software - * and any derivatives exclusively with Microchip products. It is your - * responsibility to comply with third party license terms applicable to your - * use of third party software (including open source software) that may - * accompany Microchip software. - * - * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER - * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED - * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, - * SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE - * OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF - * MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE - * FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL - * LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED - * THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR - * THIS SOFTWARE. - */ - -#include "atca_hal.h" -#include "hal_win_kit_hid.h" -#include "kit_protocol.h" -#include "kit_phy.h" -#include -#include -#include -#include - -/** \defgroup hal_ Hardware abstraction layer (hal_) - * - * \brief - * These methods define the hardware abstraction layer for communicating with a CryptoAuth device - * - @{ */ - -// File scope globals -atcahid_t _gHid; - -// The HID GUID filter -#define HID_GUID { 0x4d1e55b2, 0xf16f, 0x11cf, 0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 } - - - -/** \brief HAL implementation of Kit USB HID init - * \param[in] hal pointer to HAL specific data that is maintained by this HAL - * \param[in] cfg pointer to HAL specific configuration data that is used to initialize this HAL - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS hal_kit_hid_init(void* hal, ATCAIfaceCfg* cfg) -{ - ATCA_STATUS status = ATCA_SUCCESS; - ATCAHAL_t *phal = NULL; - GUID hid_guid = HID_GUID; - HDEVINFO dev_info; - SP_DEVICE_INTERFACE_DATA dev_data; - PSP_DEVICE_INTERFACE_DETAIL_DATA dev_detail_data; - DWORD required_size = 0; - BOOL result = FALSE; - DWORD device_index = 0; - int i = 0; - int index = 0; - TCHAR hid_filter[32]; - - // Check the input variables - if ((hal == NULL) || (cfg == NULL)) - { - return ATCA_BAD_PARAM; - } - - // Cast the hal to the ATCAHAL_t strucure - phal = (ATCAHAL_t*)hal; - - // Initialize the _gHid structure - memset(&_gHid, 0, sizeof(_gHid)); - for (i = 0; i < HID_DEVICES_MAX; i++) - { - _gHid.kits[i].read_handle = INVALID_HANDLE_VALUE; - _gHid.kits[i].write_handle = INVALID_HANDLE_VALUE; - } - - _gHid.num_kits_found = 0; - - // Initialize the GUID -// UuidFromString(cfg->atcahid.guid, &hid_guid); - - // Query the devices - dev_info = SetupDiGetClassDevs(&hid_guid, NULL, NULL, (DIGCF_PRESENT | DIGCF_DEVICEINTERFACE)); - if (dev_info == INVALID_HANDLE_VALUE) - { - return ATCA_COMM_FAIL; - } - - // Initialize the dev_data object - memset(&dev_data, 0, sizeof(SP_DEVICE_INTERFACE_DATA)); - dev_data.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); - - // Construct the filter string - memset(hid_filter, 0, sizeof(hid_filter)); - _stprintf(hid_filter, _T("vid_%04x&pid_%04x"), cfg->atcahid.vid, cfg->atcahid.pid); - - // Find the Microchip CryptoAuthentication kit protocol devices - while (SetupDiEnumDeviceInterfaces(dev_info, NULL, &hid_guid, device_index, &dev_data)) - { - // Get the required buffer size of the detailed data - SetupDiGetDeviceInterfaceDetail(dev_info, &dev_data, NULL, 0, &required_size, NULL); - - // Allocate the required space for the detailed interface data - dev_detail_data = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(required_size); - - // Retrieve the detailed interface data - dev_detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); - result = SetupDiGetDeviceInterfaceDetail(dev_info, &dev_data, dev_detail_data, - required_size, &required_size, NULL); - - // Determine if this is the correct kit USB device - - if (_tcsstr(dev_detail_data->DevicePath, hid_filter) != NULL) - { - // Open the kit USB device for reading and writing - if (_gHid.kits[index].read_handle != INVALID_HANDLE_VALUE) - { - CloseHandle(_gHid.kits[index].read_handle); - } - if (_gHid.kits[index].write_handle != INVALID_HANDLE_VALUE) - { - CloseHandle(_gHid.kits[index].write_handle); - } - - _gHid.kits[index].read_handle = CreateFile(dev_detail_data->DevicePath, - GENERIC_READ, - (FILE_SHARE_READ | FILE_SHARE_WRITE), - NULL, - OPEN_EXISTING, - 0, - NULL); - _gHid.kits[index].write_handle = CreateFile(dev_detail_data->DevicePath, - GENERIC_WRITE, - (FILE_SHARE_READ | FILE_SHARE_WRITE), - NULL, - OPEN_EXISTING, - 0, - NULL); - - // Increment the opened kit USB device index - index++; - } - // Deallocate the required space for the detailed interface data - free(dev_detail_data); - - // Break the while loop, if the maximum number of supported - // kit USB devices have been found - if (index == HID_DEVICES_MAX) - { - break; - } - - // Increment the device member index - device_index++; - } - - // Delete device info now that we're done - SetupDiDestroyDeviceInfoList(dev_info); - - // Save the results of this discovery of HID - _gHid.num_kits_found = index; - phal->hal_data = &_gHid; - - if (_gHid.num_kits_found == 0) - { - status = ATCA_NO_DEVICES; - } - - return status; -} - - -/** \brief discover all HID kits available.This function is currently not implemented. - * this maintains a list of logical to physical bus mappings freeing the application - * of the a-priori knowledge - * \param[in] hid_buses an array of logical bus numbers - * \param[in] max_buses maximum number of buses the app wants to attempt to discover - * \return ATCA_UNIMPLEMENTED - */ -ATCA_STATUS hal_kit_hid_discover_buses(int hid_buses[], int max_buses) -{ - // TODO: This should be set to the com port index(s) - return ATCA_UNIMPLEMENTED; -} - -/** \brief discover any CryptoAuth devices on a given logical bus number.This function is currently not implemented. - * \param[in] bus_num - logical bus number on which to look for CryptoAuth devices - * \param[out] cfg[] - pointer to head of an array of interface config structures which get filled in by this method - * \param[out] *found - number of devices found on this bus - * \return ATCA_UNIMPLEMENTED - */ -ATCA_STATUS hal_kit_hid_discover_devices(int bus_num, ATCAIfaceCfg cfg[], int *found) -{ - // TODO: Add kitg protocol calls to discover all devices - return ATCA_UNIMPLEMENTED; -} - -/** \brief HAL implementation of Kit HID post init - * \param[in] iface instance - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS hal_kit_hid_post_init(ATCAIface iface) -{ - ATCA_STATUS status = ATCA_SUCCESS; - atcahid_t* pHid = atgetifacehaldat(iface); - ATCAIfaceCfg *pCfg = atgetifacecfg(iface); - int i = 0; - - do - { - // Check the pointers - if (pHid == NULL || pCfg == NULL) - { - status = ATCA_BAD_PARAM; - ATCA_TRACE(status, "NULL pointers in hal_kit_hid_post_init"); - break; - } - // Init all kit USB HID devices - for (i = 0; i < pHid->num_kits_found; i++) - { - // Perform the kit protocol init - status = kit_init(iface); - if (status != ATCA_SUCCESS) - { - ATCA_TRACE(status, "kit_init() Failed"); - break; - } - } - - } - while (0); - return status; -} - -/** \brief HAL implementation of kit protocol send .It is called by the top layer. - * \param[in] iface instance - * \param[in] txdata pointer to bytes to send - * \param[in] txlength number of bytes to send - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS kit_phy_send(ATCAIface iface, const char* txdata, int txlength) -{ - ATCA_STATUS status = ATCA_SUCCESS; - ATCAIfaceCfg *cfg = atgetifacecfg(iface); - int hidid = cfg->atcahid.idx; - atcahid_t* pHid = (atcahid_t*)atgetifacehaldat(iface); - uint8_t buffer[HID_PACKET_MAX]; - DWORD bytes_to_send = 0; - DWORD bytes_left = 0; - DWORD bytes_sent = 0; - BOOL result = FALSE; - - if ((txdata == NULL) || (pHid == NULL)) - { - return ATCA_BAD_PARAM; - } - - if (pHid->kits[hidid].write_handle == INVALID_HANDLE_VALUE) - { - return ATCA_COMM_FAIL; - } - - bytes_left = txlength; - - while (bytes_left > 0) - { - memset(buffer, 0, (HID_PACKET_MAX)); - - if (bytes_left >= cfg->atcahid.packetsize) - { - bytes_to_send = cfg->atcahid.packetsize; - } - else - { - bytes_to_send = bytes_left; - } - - memcpy(&buffer[1], &txdata[(txlength - bytes_left)], bytes_to_send); - - result = WriteFile(pHid->kits[hidid].write_handle, buffer, (cfg->atcahid.packetsize + 1), &bytes_sent, NULL); - if (result == FALSE) - { - return ATCA_TX_FAIL; - } - - bytes_left -= bytes_to_send; - } - return status; -} - -/** \brief HAL implementation of kit protocol receive data.It is called by the top layer. - * \param[in] iface instance - * \param[out] rxdata pointer to space to receive the data - * \param[inout] rxsize ptr to expected number of receive bytes to request - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS kit_phy_receive(ATCAIface iface, char* rxdata, int* rxsize) -{ - ATCAIfaceCfg *cfg = atgetifacecfg(iface); - int hidid = cfg->atcahid.idx; - atcahid_t* pHid = (atcahid_t*)atgetifacehaldat(iface); - uint8_t buffer[HID_PACKET_MAX] = { 0 }; - BOOL continue_read = TRUE; - DWORD bytes_read = 0; - DWORD total_bytes = 0; - BOOL result = true; - char* location = NULL; - int bytes_remain = 0; - int bytes_to_cpy = 0; - int size_adjust = 0; - - // Verify the input variables - if ((rxdata == NULL) || (rxsize == NULL) || (pHid == NULL)) - { - return ATCA_BAD_PARAM; - } - - if (pHid->kits[hidid].read_handle == INVALID_HANDLE_VALUE) - { - return ATCA_COMM_FAIL; - } - - while (continue_read == true) - { - result = ReadFile(pHid->kits[hidid].read_handle, buffer, (cfg->atcahid.packetsize + 1), &bytes_read, NULL); - if (result == false) - { - return ATCA_RX_FAIL; - } - // Find the location of the '\n' character in read buffer - // todo: generalize this read... it only applies if there is an ascii protocol with an of \n and if the exists - location = strchr((char*)&buffer[1], '\n'); - if (location == NULL) - { - // Copy all of the bytes - bytes_to_cpy = bytes_read; - // An extra byte is prepended to HID communication - size_adjust = 1; - } - else - { - // Copy only the bytes remaining in the read buffer to the - bytes_to_cpy = (uint8_t)(location - (char*)buffer); - size_adjust = 0; - // The response has been received, stop receiving more data - continue_read = false; - } - // Protect rxdata from overwriting, this will have the result of truncating the returned bytes - // Remaining space in rxdata - //bytes_remain = (*rxsize - total_bytes); - // Use the minimum between number of bytes read and remaining space - //bytes_to_cpy = min(bytes_remain, bytes_to_cpy); - - // Copy the received data - memcpy(&rxdata[total_bytes], &buffer[1], bytes_to_cpy); - total_bytes += bytes_to_cpy - size_adjust; - } - *rxsize = total_bytes; - return ATCA_SUCCESS; -} - -/** \brief Number of USB HID devices found - * \param[out] num_found - * \return SUCCESS - */ -ATCA_STATUS kit_phy_num_found(int8_t* num_found) -{ - *num_found = _gHid.num_kits_found; - return ATCA_SUCCESS; -} - -/** \brief HAL implementation of kit protocol send over USB HID - * \param[in] iface instance - * \param[in] txdata pointer to bytes to send - * \param[in] txlength number of bytes to send - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS hal_kit_hid_send(ATCAIface iface, uint8_t word_address, uint8_t* txdata, int txlength) -{ - // Call the kit_send() function that will call phy_send() implemented below - return kit_send(iface, word_address, txdata, txlength); -} - -/** \brief HAL implementation of send over USB HID - * \param[in] iface instance - * \param[in] rxdata pointer to space to receive the data - * \param[inout] rxsize ptr to expected number of receive bytes to request - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS hal_kit_hid_receive(ATCAIface iface, uint8_t word_address, uint8_t* rxdata, uint16_t* rxsize) -{ - // Call the kit_receive() function that will call phy_receive() implemented below - return kit_receive(iface, word_address, rxdata, rxsize); -} - -/** \brief Call the wake for kit protocol over USB HID - * \param[in] iface ATCAIface instance that is the interface object to send the bytes over - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS hal_kit_hid_wake(ATCAIface iface) -{ - // Call the kit_wake() function that will call phy_send() and phy_receive() - return kit_wake(iface); -} - -/** \brief Call the idle for kit protocol over USB HID - * \param[in] iface ATCAIface instance that is the interface object to send the bytes over - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS hal_kit_hid_idle(ATCAIface iface) -{ - // Call the kit_idle() function that will call phy_send() and phy_receive() - return kit_idle(iface); -} - -/** \brief Call the sleep for kit protocol over USB HID - * \param[in] iface ATCAIface instance that is the interface object to send the bytes over - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS hal_kit_hid_sleep(ATCAIface iface) -{ - // Call the kit_sleep() function that will call phy_send() and phy_receive() - return kit_sleep(iface); -} - -/** \brief Close the physical port for HID - * \param[in] hal_data The hardware abstraction data specific to this HAL - * \return ATCA_SUCCESS on success, otherwise an error code. - */ -ATCA_STATUS hal_kit_hid_release(void* hal_data) -{ - int i = 0; - atcahid_t* phaldat = (atcahid_t*)hal_data; - - if ((hal_data == NULL)) - { - return ATCA_BAD_PARAM; - } - - // Close all kit USB devices - for (i = 0; i < phaldat->num_kits_found; i++) - { - if (phaldat->kits[i].read_handle != INVALID_HANDLE_VALUE) - { - CloseHandle(phaldat->kits[i].read_handle); - phaldat->kits[i].read_handle = INVALID_HANDLE_VALUE; - } - - if (phaldat->kits[i].write_handle != INVALID_HANDLE_VALUE) - { - CloseHandle(phaldat->kits[i].write_handle); - phaldat->kits[i].write_handle = INVALID_HANDLE_VALUE; - } - } - return ATCA_SUCCESS; -} - -/** @} */ \ No newline at end of file diff --git a/lib/hal/hal_win_kit_hid.h b/lib/hal/hal_win_kit_hid.h deleted file mode 100644 index 8d6c5c367..000000000 --- a/lib/hal/hal_win_kit_hid.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * \file - * \brief ATCA Hardware abstraction layer for Windows using kit protocol over a USB HID device. - * - * \copyright (c) 2015-2020 Microchip Technology Inc. and its subsidiaries. - * - * \page License - * - * Subject to your compliance with these terms, you may use Microchip software - * and any derivatives exclusively with Microchip products. It is your - * responsibility to comply with third party license terms applicable to your - * use of third party software (including open source software) that may - * accompany Microchip software. - * - * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER - * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED - * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A - * PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, - * SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE - * OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF - * MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE - * FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL - * LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED - * THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR - * THIS SOFTWARE. - */ - -#ifndef HAL_WIN_KIT_HID_H_ -#define HAL_WIN_KIT_HID_H_ - -#include - -/** \defgroup hal_ Hardware abstraction layer (hal_) - * - * \brief - * These methods define the hardware abstraction layer for communicating with a CryptoAuth device - * - @{ */ - -// Kit USB defines -#define HID_DEVICES_MAX 10 //! Maximum number of supported Kit USB devices -#define HID_PACKET_MAX 512 //! Maximum number of bytes for a HID send/receive packet (typically 64) - -// Each device that is found will have a read handle and a write handle -typedef struct hid_device -{ - HANDLE read_handle; //! The kit USB read file handle - HANDLE write_handle; //! The kit USB write file handle -} hid_device_t; - - -// A structure to hold HID information -typedef struct atcahid -{ - hid_device_t kits[HID_DEVICES_MAX]; - int8_t num_kits_found; -} atcahid_t; - -/** @} */ -#endif /* HAL_WIN_KIT_HID_H_ */ \ No newline at end of file diff --git a/lib/hal/kit_protocol.c b/lib/hal/kit_protocol.c index 9511c02a0..0085d74e4 100644 --- a/lib/hal/kit_protocol.c +++ b/lib/hal/kit_protocol.c @@ -195,7 +195,7 @@ ATCA_STATUS kit_init(ATCAIface iface) /*Selects the device only if the device type, device interface and device identity matches*/ - if ((strcmp(device_match, dev_type) == 0) && (iface->mIfaceCFG->atcahid.dev_identity == address) && (strcmp(interface_match, dev_interface) == 0)) + if ((strncmp(device_match, dev_type, 4) == 0) && (iface->mIfaceCFG->atcahid.dev_identity == address) && (strcmp(interface_match, dev_interface) == 0)) { diff --git a/lib/host/atca_host.h b/lib/host/atca_host.h index 530386a61..057e4fb3d 100644 --- a/lib/host/atca_host.h +++ b/lib/host/atca_host.h @@ -108,7 +108,7 @@ */ typedef struct atca_temp_key { - uint8_t value[ATCA_KEY_SIZE * 2]; //!< Value of TempKey (64 bytes for ATECC608A only) + uint8_t value[ATCA_KEY_SIZE * 2]; //!< Value of TempKey (64 bytes for ATECC608 only) unsigned key_id : 4; //!< If TempKey was derived from a slot or transport key (GenDig or GenKey), that key ID is saved here. unsigned source_flag : 1; //!< Indicates id TempKey started from a random nonce (0) or not (1). unsigned gen_dig_data : 1; //!< TempKey was derived from the GenDig command. diff --git a/lib/mbedtls/atca_mbedtls_ecdh.c b/lib/mbedtls/atca_mbedtls_ecdh.c index 3ce2bd65b..f73a1df2d 100644 --- a/lib/mbedtls/atca_mbedtls_ecdh.c +++ b/lib/mbedtls/atca_mbedtls_ecdh.c @@ -133,7 +133,7 @@ int mbedtls_ecdh_compute_shared(mbedtls_ecp_group *grp, mbedtls_mpi *z, if (!ret) { slotid = *(uint16_t*)d->p; - if (atIsECC608Family(atcab_get_device()->mIface->mIfaceCFG->devtype)) + if (ATECC608 == atcab_get_device()->mIface->mIfaceCFG->devtype) { ret = atca_mbedtls_ecdh_ioprot_cb(secret); if (!ret) diff --git a/lib/pkcs11/pkcs11_config.c b/lib/pkcs11/pkcs11_config.c index a9f6e8983..79ca27f29 100644 --- a/lib/pkcs11/pkcs11_config.c +++ b/lib/pkcs11/pkcs11_config.c @@ -336,11 +336,11 @@ static CK_RV pkcs11_config_parse_interface(pkcs11_slot_ctx_ptr slot_ctx, char* c } if (argc > 2) { - slot_ctx->interface_config.atcaspi.select_pin = (uint8_t)strtol(argv[1], NULL, 16); + slot_ctx->interface_config.atcaspi.select_pin = (uint8_t)strtol(argv[2], NULL, 16); } if (argc > 3) { - slot_ctx->interface_config.atcaspi.baud = (uint32_t)strtol(argv[1], NULL, 16); + slot_ctx->interface_config.atcaspi.baud = (uint32_t)strtol(argv[3], NULL, 10); } rv = CKR_OK; #endif diff --git a/license.txt b/license.txt index 207f8ea35..56a8a7bd3 100644 --- a/license.txt +++ b/license.txt @@ -1,4 +1,4 @@ -(c) 2015-2018 Microchip Technology Inc. and its subsidiaries. +(c) 2015-2020 Microchip Technology Inc. and its subsidiaries. Subject to your compliance with these terms, you may use Microchip software and any derivatives exclusively with Microchip products. It is your @@ -49,51 +49,6 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -=============================================================================== -If using the Linux HID driver (lib/hal/hal_linux_kit_hid.c), this code depends -on the libudev.h header file with the following license: - -Copyright 2008-2012 Kay Sievers - -systemd is free software; you can redistribute it and/or modify it -under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or -(at your option) any later version. - -systemd is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Lesser General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with systemd; If not, see . - - -=============================================================================== -If using the Linux I2C driver (lib/hal/hal_linux_i2c_userspace.c), this code -depends on the linux i2c-dev.h header with the following license: - -SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note - -Copyright (C) 1995-97 Simon G. Vogl -Copyright (C) 1998-99 Frodo Looijaard - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -MA 02110-1301 USA. - - =============================================================================== If using the Espressif ESP32 I2C driver (lib/hal/hal_esp32_i2c.c), this code has the following license: @@ -136,871 +91,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - - -=============================================================================== -If using the mbed TLS wrapper, then the mbed TLS license is under the -Apache 2.0 license. - - -=============================================================================== - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - - -=============================================================================== - NOTE! This copyright does *not* cover user programs that use kernel - services by normal system calls - this is merely considered normal use - of the kernel, and does *not* fall under the heading of "derived work". - Also note that the GPL below is copyrighted by the Free Software - Foundation, but the instance of code that it refers to (the Linux - kernel) is copyrighted by me and others who actually wrote it. - - Also note that the only valid version of the GPL as far as the kernel - is concerned is _this_ particular version of the license (ie v2, not - v2.2 or v3.x or whatever), unless explicitly otherwise stated. - - Linus Torvalds - ----------------------------------------- - - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. \ No newline at end of file diff --git a/module.xml b/module.xml index 956f48065..f7546240c 100644 --- a/module.xml +++ b/module.xml @@ -1,4 +1,4 @@ - + diff --git a/release_notes.md b/release_notes.md index 5cb2e4863..78e976f4f 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,6 +1,22 @@ # Microchip Cryptoauthlib Release Notes +## Release v3.2.3 (09/12/2020) + +### New features + - Additional TA100 command support (requires NDA, consult with your FAE or + submit a request through your myMicrochip account) + +### Fixes + - Security patch for USB HALs. Removed deprecated HALs and removed enumeration + from the hidapi HAL. + - Fix device matching logic to support older kits when using "auto detect" + settings in the interface configuration + - Fix SPI HAL generation errors for SAMG55 & SAM71 (flexcom) devices + - Added a timeout for Harmony I2C calls to prevent infinite loops on peripheral + failures. If a loop exists inside the peripheral library then it may still + cause processor spins until a watchdog reset. + ## Release v3.2.2 (07/28/2020) ### New Features diff --git a/test/api_talib/test_ecc_certificate_chain.c b/test/api_talib/test_ecc_certificate_chain.c index 38d39e8ed..1e9b41ac2 100644 --- a/test/api_talib/test_ecc_certificate_chain.c +++ b/test/api_talib/test_ecc_certificate_chain.c @@ -28,7 +28,7 @@ #include "test_ecc_certificate_chain.h" -const uint8_t test_ecc_root_public_key[] = { +const uint8_t test_ecc_root_public_key[] = { 0x57, 0x7c, 0xbe, 0xe3, 0x8d, 0x4c, 0xcc, 0x47, 0x27, 0x3b, 0xb0, 0x47, 0x1e, 0x81, 0x7a, 0xf9, 0x7a, 0xf4, 0xb0, 0xf8, 0xc0, 0xc4, 0x2e, 0xf1, 0xae, 0x80, 0x66, 0xc2, 0xb0, 0xc3, 0x31, 0x74, 0xd2, 0xbf, 0x77, 0x71, 0x20, 0xa4, 0xca, 0xee, 0x33, 0x40, 0xd0, 0xef, 0x57, 0x2a, 0x5b, 0x08, @@ -75,7 +75,7 @@ const uint8_t test_ecc_signer_cert[] = { }; -const uint8_t test_ecc_leaf_public_key[]= { +const uint8_t test_ecc_leaf_public_key[] = { 0x4b, 0x7a, 0x45, 0xb6, 0x65, 0x15, 0xab, 0x5d, 0x5d, 0x5c, 0x2a, 0x83, 0xb7, 0x26, 0xf4, 0x9d, 0x3b, 0xa9, 0x72, 0x5d, 0xec, 0xd7, 0x1d, 0xac, 0xef, 0x0a, 0xd9, 0xd9, 0x13, 0x57, 0x38, 0x7e, 0x68, 0xb3, 0xa7, 0x61, 0x2c, 0x46, 0x0b, 0xba, 0x41, 0xa2, 0x68, 0x12, 0xe7, 0x26, 0x9d, 0x43, diff --git a/test/api_talib/test_ecc_certificate_chain.h b/test/api_talib/test_ecc_certificate_chain.h index 4f9a84fe5..d2a6368b5 100644 --- a/test/api_talib/test_ecc_certificate_chain.h +++ b/test/api_talib/test_ecc_certificate_chain.h @@ -39,7 +39,7 @@ extern const uint8_t test_ecc_root_public_key[64]; extern const uint8_t test_ecc_signer_cert[571]; -extern const uint8_t test_ecc_leaf_cert[629] ; +extern const uint8_t test_ecc_leaf_cert[629]; extern const uint8_t test_ecc_leaf_public_key[64]; diff --git a/test/api_talib/test_talib_config.c b/test/api_talib/test_talib_config.c index 4eb0b399b..59d5d81d4 100644 --- a/test/api_talib/test_talib_config.c +++ b/test/api_talib/test_talib_config.c @@ -41,8 +41,8 @@ const uint8_t test_ta100_configdata[TA_CONFIG_SIZE] = { }; static ta_element_attributes_t attr_rw_data = { 3, 72, 0, 0, 0, 0x54, 4 }; -static ta_element_attributes_t attr_ecc_private = { 1, 0x1700, 0, 0, 0, 0x01, 0}; -static ta_element_attributes_t attr_ecc_public = { 0, 0x00, 0, 0, 0, 0x55, 4}; +static ta_element_attributes_t attr_ecc_private = { 1, 0x1700, 0, 0, 0, 0x01, 0 }; +static ta_element_attributes_t attr_ecc_public = { 0, 0x00, 0, 0, 0, 0x55, 4 }; static ta_element_attributes_t attr_hmac_key = { 0x42, 0x0600, 0, 0, 0, 0x55, 8 }; static ta_element_attributes_t attr_aes_key = { 0x62, 0x0600, 0, 0, 0, 0x55, 8 }; static ta_element_attributes_t attr_ecc_root_public = { 0, 0x06FF, 0, 0, 0, 0x55, 4 }; @@ -53,18 +53,18 @@ uint8_t auth_hmac_key[] = { 0xa2, 0x26, 0xe1, 0x65, 0x69, 0x01, 0x80, 0xeb, 0x1a static device_object_meta_t talib_config_object_data[] = { - {TEST_TYPE_ECC_SIGN, 0x8102, &attr_ecc_private }, - {TEST_TYPE_ECC_VERIFY, 0x8103, &attr_ecc_public }, - {TEST_TYPE_ECC_GENKEY, TA_HANDLE_VOLATILE_REGISTER0, &attr_ecc_private }, - {TEST_TYPE_ECDH, TA_HANDLE_VOLATILE_REGISTER1, &attr_ecc_private }, - {TEST_TYPE_AES, 0x8106, &attr_aes_key }, - {TEST_TYPE_HMAC, 0x8105, &attr_hmac_key }, - {TEST_TYPE_AUTH_HMAC, 0xAB1D, &attr_hmac_key }, - {TEST_TYPE_AUTH_GCM, 0xAAD1, &attr_aes_key }, - {TEST_TYPE_AUTH_CMAC, 0x9492, &attr_aes_key }, - {TEST_TYPE_DATA, 0x8101, &attr_rw_data }, - {TEST_TYPE_ECC_ROOT_KEY, 0x8107, &attr_ecc_root_public }, - {0, 0, NULL} + { TEST_TYPE_ECC_SIGN, 0x8102, &attr_ecc_private }, + { TEST_TYPE_ECC_VERIFY, 0x8103, &attr_ecc_public }, + { TEST_TYPE_ECC_GENKEY, TA_HANDLE_VOLATILE_REGISTER0, &attr_ecc_private }, + { TEST_TYPE_ECDH, TA_HANDLE_VOLATILE_REGISTER1, &attr_ecc_private }, + { TEST_TYPE_AES, 0x8106, &attr_aes_key }, + { TEST_TYPE_HMAC, 0x8105, &attr_hmac_key }, + { TEST_TYPE_AUTH_HMAC, 0xAB1D, &attr_hmac_key }, + { TEST_TYPE_AUTH_GCM, 0xAAD1, &attr_aes_key }, + { TEST_TYPE_AUTH_CMAC, 0x9492, &attr_aes_key }, + { TEST_TYPE_DATA, 0x8101, &attr_rw_data }, + { TEST_TYPE_ECC_ROOT_KEY, 0x8107, &attr_ecc_root_public }, + { 0, 0, NULL } }; ATCA_STATUS talib_config_get_handle_by_test(uint8_t test_type, uint16_t* handle) @@ -163,8 +163,8 @@ int talib_configure_device(int argc, char* argv[]) if (ATCA_SUCCESS == status) { device_object_meta_t * create_ptr = talib_config_object_data; - - for (;create_ptr->test_type; create_ptr++) + + for (; create_ptr->test_type; create_ptr++) { ta_element_attributes_t* attr_ptr = (ta_element_attributes_t*)create_ptr->attributes; @@ -224,11 +224,13 @@ extern t_test_case_info* talib_create_tests[]; extern t_test_case_info* talib_aes_tests[]; extern t_test_case_info* talib_counter_tests[]; extern t_test_case_info* talib_ecdh_tests[]; +extern t_test_case_info* talib_export_import_tests[]; extern t_test_case_info* talib_genkey_tests[]; extern t_test_case_info* talib_info_tests[]; extern t_test_case_info* talib_kdf_tests[]; extern t_test_case_info* talib_mac_tests[]; extern t_test_case_info* talib_managecert_tests[]; +extern t_test_case_info* talib_power_tests[]; extern t_test_case_info* talib_random_tests[]; extern t_test_case_info* talib_rsa_enc_tests[]; extern t_test_case_info* talib_selftest_tests[]; @@ -245,10 +247,12 @@ void run_all_talib_tests(void) RunAllTests(talib_counter_tests); RunAllTests(talib_create_tests); RunAllTests(talib_ecdh_tests); + RunAllTests(talib_export_import_tests); RunAllTests(talib_genkey_tests); RunAllTests(talib_info_tests); RunAllTests(talib_kdf_tests); RunAllTests(talib_mac_tests); + RunAllTests(talib_power_tests); RunAllTests(talib_random_tests); RunAllTests(talib_rsa_enc_tests); RunAllTests(talib_selftest_tests); diff --git a/test/api_talib/test_talib_export_import.c b/test/api_talib/test_talib_export_import.c new file mode 100644 index 000000000..e295137cc --- /dev/null +++ b/test/api_talib/test_talib_export_import.c @@ -0,0 +1,349 @@ +/** + * \file + * \brief Basic test for Export/Import command api - TA100 + * + * \copyright (c) 2015-2020 Microchip Technology Inc. and its subsidiaries. + * + * \page License + * + * Subject to your compliance with these terms, you may use Microchip software + * and any derivatives exclusively with Microchip products. It is your + * responsibility to comply with third party license terms applicable to your + * use of third party software (including open source software) that may + * accompany Microchip software. + * + * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED + * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A + * PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, + * SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE + * OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + * MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + * FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL + * LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED + * THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR + * THIS SOFTWARE. + */ + +#include "atca_test.h" +#include "test_talib.h" + +#if ATCA_TA_SUPPORT + +/** \brief This test case export the private key from data handle and import it to + * different handle and verify by its public key + * NOTE: Both export and import handle should match value of its attribute fields + * except link keys (usage key, read key, write key) + */ +TEST(atca_cmd_basic_test, export_import_private_key) +{ + ATCA_STATUS status = ATCA_SUCCESS; + uint8_t encrypted_blob[TA_EXPORT_BLOB_MAX_LEN]; + uint16_t encrypted_blob_len = sizeof(encrypted_blob); + uint16_t export_priv_key_handle; + uint16_t import_priv_key_handle; + ta_element_attributes_t export_attr_priv_key_handle; + ta_element_attributes_t import_attr_priv_key_handle; + uint8_t exp_public_key[TA_ECC256_PUB_KEY_SIZE]; + uint8_t imp_public_key[TA_ECC256_PUB_KEY_SIZE]; + size_t pub_key_len = TA_ECC256_PUB_KEY_SIZE; + + // Create export and import handle without link keys and setting req attributes for handles + status = talib_handle_init_private_key(&export_attr_priv_key_handle, TA_KEY_TYPE_ECCP256, + TA_ALG_MODE_ECC_ECDSA, TA_PROP_SIGN_INT_EXT_DIGEST, + TA_PROP_NO_KEY_AGREEMENT); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + export_attr_priv_key_handle.byte7_settings |= TA_EXPORTABLE_FROM_CHIP_MASK; + + status = talib_create_element(atcab_get_device(), &export_attr_priv_key_handle, &export_priv_key_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + // import handle + status = talib_handle_init_private_key(&import_attr_priv_key_handle, TA_KEY_TYPE_ECCP256, + TA_ALG_MODE_ECC_ECDSA, TA_PROP_SIGN_INT_EXT_DIGEST, + TA_PROP_NO_KEY_AGREEMENT); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + import_attr_priv_key_handle.byte7_settings |= TA_EXPORTABLE_FROM_CHIP_MASK; + + status = talib_create_element(atcab_get_device(), &import_attr_priv_key_handle, &import_priv_key_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + + + // Genarate new private key on export handle and get the public key of it + status = talib_genkey(atcab_get_device(), export_priv_key_handle, exp_public_key, &pub_key_len); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + + + status = talib_export(atcab_get_device(), export_priv_key_handle, encrypted_blob, &encrypted_blob_len); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + status = talib_import_handle(atcab_get_device(), import_priv_key_handle, encrypted_blob, encrypted_blob_len); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + + + // verify the imported handle by match its public key + status = talib_get_pubkey_compat(atcab_get_device(), import_priv_key_handle, imp_public_key); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + TEST_ASSERT_EQUAL_MEMORY(exp_public_key, imp_public_key, TA_ECC256_PUB_KEY_SIZE); + + + // delete handles + status = talib_delete_handle(atcab_get_device(), export_priv_key_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + status = talib_delete_handle(atcab_get_device(), import_priv_key_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); +} + +/** \brief This test case export the data from shared data handle and import it to + * different handle + * NOTE: Both export and import handle should match value of its attribute fields + * except link keys (usage key, read key, write key) + */ +TEST(atca_cmd_basic_test, export_import_data_element_with_links) +{ + ATCA_STATUS status = ATCA_SUCCESS; + uint8_t encrypted_blob[TA_EXPORT_BLOB_MAX_LEN]; + uint16_t encrypted_blob_len = sizeof(encrypted_blob); + uint16_t write_key_handle; + uint16_t exp_data_handle; + uint16_t imp_data_handle; + ta_element_attributes_t attr_data_handle; + ta_element_attributes_t attr_write_key_handle; + uint8_t write_data[64]; + uint8_t read_data[64]; + uint16_t data_size = sizeof(write_data); + uint8_t hmac_key[] = { 0xa2, 0x26, 0xe1, 0x65, 0x69, 0x01, 0x80, 0xeb, 0x1a, 0x0c, 0x9c, 0x5b, 0x64, 0x5e, 0x42, 0x02, + 0xfa, 0x2f, 0x4f, 0xfd, 0x68, 0x75 }; + uint8_t hmac_i_nonce[] = { 0xd4, 0xe4, 0x9a, 0x02, 0x9f, 0xf2, 0xca, 0xff, 0x5e, 0x7c, 0xda, 0x2f, 0x13, 0x07, 0xa8, 0xb6 }; + uint8_t hmac_r_nonce[] = { 0xad, 0x23, 0x38, 0x09, 0x4e, 0xd3, 0xbf, 0xc3, 0x89, 0xc6, 0xf6, 0x35, 0xb6, 0xcf, 0xcf, 0xf0 }; + uint8_t key_buf[32] = { 0 }; + uint16_t auth_id = 0x4100; + uint16_t details = (uint16_t)TA_CREATE_DETAILS_HMAC_KEY_LENGTH(sizeof(hmac_key)); + + // Skip test if setup isn't locked + test_assert_data_is_locked(); + + // Create link (write) key, because export and import handle dependent on this keys + // Here only one link key is created and shared by both export and import handle + status = talib_handle_init_symmetric_key(&attr_write_key_handle, TA_KEY_TYPE_HMAC, TA_PROP_SYMM_KEY_USAGE_ANY); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + attr_write_key_handle.property |= TA_PROP_SYMM_KEY_EITHER_OPTIONAL_MASK; + + status = talib_create_linked_shared_data(atcab_get_device(), details, &attr_write_key_handle, + &write_key_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + + // write symmetric key into link (write) key + status = talib_write_element(atcab_get_device(), write_key_handle, sizeof(hmac_key), hmac_key); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + + + // Create export and import handle and setting req attributes + status = talib_handle_init_data(&attr_data_handle, data_size); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + status = talib_handle_set_write_permission(&attr_data_handle, TA_PERM_AUTH); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + attr_data_handle.write_key = (uint8_t)(write_key_handle & 0x00FF); + attr_data_handle.byte7_settings |= TA_EXPORTABLE_FROM_CHIP_MASK; + + status = talib_create_element(atcab_get_device(), &attr_data_handle, &exp_data_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + status = talib_create_element(atcab_get_device(), &attr_data_handle, &imp_data_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + + + // Generate randome data to be written to export data handle + status = talib_random(atcab_get_device(), NULL, write_data, data_size); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + // Establish Auth session to write a data into export data handle + status = talib_auth_generate_nonce(atcab_get_device(), auth_id, 0, hmac_i_nonce); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + // copying session key into key buf to start the suth session + memcpy(key_buf, hmac_key, sizeof(hmac_key)); + + status = talib_auth_startup(atcab_get_device(), write_key_handle, TA_AUTH_ALG_ID_HMAC, 2, 32, + key_buf, hmac_i_nonce, hmac_r_nonce); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + status = talib_write_element(atcab_get_device(), exp_data_handle, data_size, write_data); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + // Terminate auth session + status = talib_auth_terminate(atcab_get_device()); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + + + status = talib_export(atcab_get_device(), exp_data_handle, encrypted_blob, &encrypted_blob_len); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + status = talib_import_handle(atcab_get_device(), imp_data_handle, encrypted_blob, encrypted_blob_len); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + + + + // verifying the imported handle by reading the data from it and match with original data + status = talib_read_element(atcab_get_device(), imp_data_handle, &data_size, read_data); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + TEST_ASSERT_EQUAL_MEMORY(write_data, read_data, data_size); + + + // delete handles + status = talib_delete_handle(atcab_get_device(), write_key_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + status = talib_delete_handle(atcab_get_device(), exp_data_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + status = talib_delete_handle(atcab_get_device(), imp_data_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); +} + +/** \brief This test case export the symmetric key from data handle and import it to + * different handle + * NOTE: Both export and import handle should match value of its attribute fields + * except link keys (usage key, read key, write key) + */ +TEST(atca_cmd_basic_test, export_import_symm_key_with_target_links) +{ + ATCA_STATUS status = ATCA_SUCCESS; + uint16_t export_symm_key_handle; + uint16_t import_symm_key_handle; + ta_element_attributes_t export_attr_symm_key_handle; + ta_element_attributes_t import_attr_symm_key_handle; + ta_element_attributes_t attr_read_key_handle; + uint16_t exp_read_key_handle; + uint16_t imp_read_key_handle; + uint8_t encrypted_blob[TA_EXPORT_BLOB_MAX_LEN]; + uint16_t encrypted_blob_len = sizeof(encrypted_blob); + uint8_t plain_text[ATCA_AES128_BLOCK_SIZE] = { 0x1A, 0x3A, 0xA5, 0x45, 0x04, 0x94, 0x53, 0xAF, + 0xDF, 0x17, 0xE9, 0x89, 0xA4, 0x1F, 0xA0, 0x97 }; + uint8_t cipher_text[ATCA_AES128_BLOCK_SIZE]; + uint8_t plain_text_out[ATCA_AES128_BLOCK_SIZE]; + uint16_t details = (uint16_t)TA_CREATE_DETAILS_HMAC_KEY_LENGTH(TA_MAC_COMMAND_HMAC_SIZE); + + // Create link keys (read), because export and import handles are dependent on this keys. + // Here two link keys are created and shared with export and import handle respectively. + status = talib_handle_init_symmetric_key(&attr_read_key_handle, TA_KEY_TYPE_HMAC, TA_PROP_SYMM_KEY_USAGE_ANY); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + status = talib_create_linked_shared_data(atcab_get_device(), details, &attr_read_key_handle, + &exp_read_key_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + status = talib_create_linked_shared_data(atcab_get_device(), details, &attr_read_key_handle, + &imp_read_key_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + + // write symmetric key into link read keys + status = talib_write_element(atcab_get_device(), exp_read_key_handle, TA_MAC_COMMAND_HMAC_SIZE, g_slot4_key); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + status = talib_write_element(atcab_get_device(), imp_read_key_handle, TA_MAC_COMMAND_HMAC_SIZE, g_slot4_key); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + + + // Create export and import handle and set req attributes for handle + status = talib_handle_init_symmetric_key(&export_attr_symm_key_handle, TA_KEY_TYPE_AES128, TA_PROP_SYMM_KEY_USAGE_ANY); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + status = talib_handle_set_read_permission(&export_attr_symm_key_handle, TA_PERM_AUTH); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + export_attr_symm_key_handle.read_key = (uint8_t)(exp_read_key_handle & 0x00FF); + export_attr_symm_key_handle.byte7_settings |= TA_EXPORTABLE_FROM_CHIP_MASK; + + status = talib_create_hmac_element(atcab_get_device(), TA_KEY_TYPE_AES128_SIZE, &export_attr_symm_key_handle, + &export_symm_key_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + // Import handle + status = talib_handle_init_symmetric_key(&import_attr_symm_key_handle, TA_KEY_TYPE_AES128, TA_PROP_SYMM_KEY_USAGE_ANY); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + status = talib_handle_set_read_permission(&import_attr_symm_key_handle, TA_PERM_AUTH); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + import_attr_symm_key_handle.read_key = (uint8_t)(imp_read_key_handle & 0x00FF); + import_attr_symm_key_handle.byte7_settings |= TA_EXPORTABLE_FROM_CHIP_MASK; + + status = talib_create_hmac_element(atcab_get_device(), TA_KEY_TYPE_AES128_SIZE, &import_attr_symm_key_handle, + &import_symm_key_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + + + // Generate new symmetric key for the export handle + status = talib_genkey_symmetric_key(atcab_get_device(), export_symm_key_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + // Encrypt using the export handle + status = atcab_aes_encrypt(export_symm_key_handle, 0, plain_text, cipher_text); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + + + status = talib_export(atcab_get_device(), export_symm_key_handle, encrypted_blob, &encrypted_blob_len); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + status = talib_import_handle_with_target_links(atcab_get_device(), import_symm_key_handle, encrypted_blob, + encrypted_blob_len); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + + + // verifying the imported handle by decrypting cipher text and match with plain text + status = atcab_aes_decrypt(import_symm_key_handle, 0, cipher_text, plain_text_out); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + TEST_ASSERT_EQUAL_MEMORY(plain_text_out, plain_text, ATCA_AES128_BLOCK_SIZE); + + + // delete handles + status = talib_delete_handle(atcab_get_device(), export_symm_key_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + status = talib_delete_handle(atcab_get_device(), import_symm_key_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + status = talib_delete_handle(atcab_get_device(), exp_read_key_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + status = talib_delete_handle(atcab_get_device(), imp_read_key_handle); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); +} + +// *INDENT-OFF* - Preserve formatting +t_test_case_info talib_export_import_basic_test_info[] = +{ + { REGISTER_TEST_CASE(atca_cmd_basic_test, export_import_symm_key_with_target_links), DEVICE_MASK(TA100) }, + { REGISTER_TEST_CASE(atca_cmd_basic_test, export_import_private_key), DEVICE_MASK(TA100) }, + { REGISTER_TEST_CASE(atca_cmd_basic_test, export_import_data_element_with_links), DEVICE_MASK(TA100) }, + { (fp_test_case)NULL, (uint8_t)0 }, /* Array Termination element*/ +}; +// *INDENT-OFN* + +t_test_case_info* talib_export_import_tests[] = { + talib_export_import_basic_test_info, + /* Array Termination element*/ + (t_test_case_info*)NULL +}; + +#endif \ No newline at end of file diff --git a/test/api_talib/test_talib_kdf.c b/test/api_talib/test_talib_kdf.c index b4620c877..1122f6cd2 100644 --- a/test/api_talib/test_talib_kdf.c +++ b/test/api_talib/test_talib_kdf.c @@ -113,7 +113,7 @@ TEST(atca_cmd_basic_test, kdf_hkdf_stored) TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); // Create the handle for the output data - status = talib_create_hmac_element(atcab_get_device(), hkdf_output_len, &attr_symm_hmac, + status = talib_create_hmac_element(atcab_get_device(), hkdf_output_len, &attr_symm_hmac, &hkdf_out_stored_handle); TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); @@ -122,7 +122,7 @@ TEST(atca_cmd_basic_test, kdf_hkdf_stored) TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); // perform the hkdf operation with the given data, key in HMAC handle and store the output to handle in device. - status = talib_hkdf_stored(atcab_get_device(), hmac_key_handle, hkdf_salt, sizeof(hkdf_salt), hkdf_info, + status = talib_hkdf_stored(atcab_get_device(), hmac_key_handle, hkdf_salt, sizeof(hkdf_salt), hkdf_info, sizeof(hkdf_info), hkdf_out_stored_handle, &hkdf_output_len); TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); @@ -166,7 +166,7 @@ TEST(atca_cmd_basic_test, kdf_prf_io) TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); // perform the kdf prf operation with the given data and key in HMAC handle - status = talib_kdf_prf_io(atcab_get_device(), hmac_handle, sizeof(prf_key), prf_label_seed, + status = talib_kdf_prf_io(atcab_get_device(), hmac_handle, sizeof(prf_key), prf_label_seed, sizeof(prf_label_seed), prf_output, &prf_output_len); TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); @@ -214,7 +214,7 @@ TEST(atca_cmd_basic_test, kdf_prf_stored) TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); // perform the kdf prf operation with the given data, key in HMAC handle and store the output to handle in device. - status = talib_kdf_prf_stored(atcab_get_device(), hmac_handle, sizeof(prf_key), prf_label_seed, + status = talib_kdf_prf_stored(atcab_get_device(), hmac_handle, sizeof(prf_key), prf_label_seed, sizeof(prf_label_seed), data_handle, &prf_output_len); TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); @@ -270,7 +270,7 @@ TEST(atca_cmd_basic_test, kdf_hmac_counter_io) // perform the hmac-counter operation with the data and key in HMAC handle. - status = talib_kdf_hmac_counter_io(atcab_get_device(), hmac_handle, label, sizeof(label), context, + status = talib_kdf_hmac_counter_io(atcab_get_device(), hmac_handle, label, sizeof(label), context, sizeof(context), hmac_counter_output, &hmac_counter_output_len); TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); @@ -322,7 +322,7 @@ TEST(atca_cmd_basic_test, kdf_hmac_counter_stored) TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); // perform the hmac-counter operation with the given data, key in HMAC handle and store the output to handle in device. - status = talib_kdf_hmac_counter_stored(atcab_get_device(), hmac_handle, label, sizeof(label), + status = talib_kdf_hmac_counter_stored(atcab_get_device(), hmac_handle, label, sizeof(label), context, sizeof(context), data_handle, &hmac_counter_output_len); TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); @@ -371,7 +371,7 @@ TEST(atca_cmd_basic_test, kdf_sha256_io) TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); // perform the kdf-sha256 operation with the given data and key in HMAC handle - status = talib_kdf_sha256_io(atcab_get_device(), hmac_handle, pre_pad, sizeof(pre_pad), post_pad, + status = talib_kdf_sha256_io(atcab_get_device(), hmac_handle, pre_pad, sizeof(pre_pad), post_pad, sizeof(post_pad), sha_output, &sha_output_len); TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); @@ -442,7 +442,7 @@ TEST(atca_cmd_basic_test, kdf_sha256_stored) TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); // perform the kdf-sha256 operation with the given data and key in HMAC handle - status = talib_kdf_sha256_stored(atcab_get_device(), hmac_handle, pre_pad, sizeof(pre_pad), + status = talib_kdf_sha256_stored(atcab_get_device(), hmac_handle, pre_pad, sizeof(pre_pad), post_pad, sizeof(post_pad), sha256_stored_handle, &sha_output_len); TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); @@ -479,14 +479,14 @@ TEST(atca_cmd_basic_test, kdf_sha256_stored) t_test_case_info talib_kdf_info[] = { - { REGISTER_TEST_CASE(atca_cmd_basic_test, kdf_hkdf_io), DEVICE_MASK(TA100) }, - { REGISTER_TEST_CASE(atca_cmd_basic_test, kdf_hkdf_stored), DEVICE_MASK(TA100) }, - { REGISTER_TEST_CASE(atca_cmd_basic_test, kdf_prf_io), DEVICE_MASK(TA100) }, - { REGISTER_TEST_CASE(atca_cmd_basic_test, kdf_prf_stored), DEVICE_MASK(TA100) }, - { REGISTER_TEST_CASE(atca_cmd_basic_test, kdf_hmac_counter_io), DEVICE_MASK(TA100) }, - { REGISTER_TEST_CASE(atca_cmd_basic_test, kdf_hmac_counter_stored), DEVICE_MASK(TA100) }, - { REGISTER_TEST_CASE(atca_cmd_basic_test, kdf_sha256_io), DEVICE_MASK(TA100) }, - { REGISTER_TEST_CASE(atca_cmd_basic_test, kdf_sha256_stored), DEVICE_MASK(TA100) }, + { REGISTER_TEST_CASE(atca_cmd_basic_test, kdf_hkdf_io), DEVICE_MASK(TA100) }, + { REGISTER_TEST_CASE(atca_cmd_basic_test, kdf_hkdf_stored), DEVICE_MASK(TA100) }, + { REGISTER_TEST_CASE(atca_cmd_basic_test, kdf_prf_io), DEVICE_MASK(TA100) }, + { REGISTER_TEST_CASE(atca_cmd_basic_test, kdf_prf_stored), DEVICE_MASK(TA100) }, + { REGISTER_TEST_CASE(atca_cmd_basic_test, kdf_hmac_counter_io), DEVICE_MASK(TA100) }, + { REGISTER_TEST_CASE(atca_cmd_basic_test, kdf_hmac_counter_stored), DEVICE_MASK(TA100) }, + { REGISTER_TEST_CASE(atca_cmd_basic_test, kdf_sha256_io), DEVICE_MASK(TA100) }, + { REGISTER_TEST_CASE(atca_cmd_basic_test, kdf_sha256_stored), DEVICE_MASK(TA100) }, /* Array Termination element*/ { (fp_test_case)NULL, (uint8_t)0 }, diff --git a/test/api_talib/test_talib_mac.c b/test/api_talib/test_talib_mac.c index 95e4877e1..b73b099b6 100644 --- a/test/api_talib/test_talib_mac.c +++ b/test/api_talib/test_talib_mac.c @@ -26,7 +26,7 @@ TEST(atca_cmd_basic_test, mac_test_cmac) for (key_block = 0; key_block < 4; key_block++) { - // Load AES keys into slot + // Load AES keys into slot status = atcab_write_bytes_zone(ATCA_ZONE_DATA, key_id, 0, &g_aes_keys[key_block][0], 16); TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); @@ -35,7 +35,7 @@ TEST(atca_cmd_basic_test, mac_test_cmac) { status = talib_cmac(atcab_get_device(), key_id, 0, - g_plaintext, g_cmac_msg_sizes[msg_index], cmac); + g_plaintext, g_cmac_msg_sizes[msg_index], cmac); TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); TEST_ASSERT_EQUAL_MEMORY(g_cmacs[key_block][msg_index], cmac, sizeof(cmac)); @@ -47,9 +47,9 @@ TEST(atca_cmd_basic_test, mac_test_cmac) t_test_case_info talib_mac_info[] = { - { REGISTER_TEST_CASE(atca_cmd_basic_test, mac_test_cmac), DEVICE_MASK(TA100) }, + { REGISTER_TEST_CASE(atca_cmd_basic_test, mac_test_cmac), DEVICE_MASK(TA100) }, /* Array Termination element*/ - { (fp_test_case)NULL, (uint8_t)0 }, + { (fp_test_case)NULL, (uint8_t)0 }, }; t_test_case_info* talib_mac_tests[] = { diff --git a/test/api_talib/test_talib_managecert.c b/test/api_talib/test_talib_managecert.c index d4e35418e..444ac72bd 100644 --- a/test/api_talib/test_talib_managecert.c +++ b/test/api_talib/test_talib_managecert.c @@ -50,7 +50,7 @@ TEST(atca_cmd_basic_test, managecert_verify_cert_shared_memory) TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); //Write the complete signer certificate to the data handle in device - status = talib_write_element(atcab_get_device(), certificate_handle, sizeof(test_ecc_signer_cert), + status = talib_write_element(atcab_get_device(), certificate_handle, sizeof(test_ecc_signer_cert), test_ecc_signer_cert); TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); @@ -96,12 +96,12 @@ TEST(atca_cmd_basic_test, managecert_verify_cert_chain_volatile) TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); //Verify the given signer certificate with root public key and store the signer extracted certificate to volatile handle - status = talib_store_extracted_cert_io(atcab_get_device(), root_key_id, extracted_cert_handle, + status = talib_store_extracted_cert_io(atcab_get_device(), root_key_id, extracted_cert_handle, test_ecc_signer_cert, sizeof(test_ecc_signer_cert)); TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); //The signer extracted certificate verifies the given leaf certificate and it stores leaf extraced certificate to same volatile handle - status = talib_store_extracted_cert_io(atcab_get_device(), extracted_cert_handle, extracted_cert_handle, + status = talib_store_extracted_cert_io(atcab_get_device(), extracted_cert_handle, extracted_cert_handle, test_ecc_leaf_cert, sizeof(test_ecc_leaf_cert)); TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); @@ -148,7 +148,7 @@ TEST(atca_cmd_basic_test, managecert_verify_cert_chain_data_shared_memory) TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); //Write the complete leaf certificate to the data handle in device - status = talib_write_element(atcab_get_device(), leaf_cert_handle, sizeof(test_ecc_leaf_cert), + status = talib_write_element(atcab_get_device(), leaf_cert_handle, sizeof(test_ecc_leaf_cert), test_ecc_leaf_cert); TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); @@ -202,14 +202,14 @@ TEST(atca_cmd_basic_test, managecert_verify_cert_chain_data_shared_memory) t_test_case_info talib_managecert_info[] = { - { REGISTER_TEST_CASE(atca_cmd_basic_test, managecert_verify_cert_io_buffer), DEVICE_MASK(TA100) }, - { REGISTER_TEST_CASE(atca_cmd_basic_test, managecert_verify_cert_shared_memory), DEVICE_MASK(TA100) }, - { REGISTER_TEST_CASE(atca_cmd_basic_test, managecert_verify_cert_chain_volatile), DEVICE_MASK(TA100) }, - { REGISTER_TEST_CASE(atca_cmd_basic_test, managecert_verify_cert_chain_data_shared_memory), DEVICE_MASK(TA100) }, + { REGISTER_TEST_CASE(atca_cmd_basic_test, managecert_verify_cert_io_buffer), DEVICE_MASK(TA100) }, + { REGISTER_TEST_CASE(atca_cmd_basic_test, managecert_verify_cert_shared_memory), DEVICE_MASK(TA100) }, + { REGISTER_TEST_CASE(atca_cmd_basic_test, managecert_verify_cert_chain_volatile), DEVICE_MASK(TA100) }, + { REGISTER_TEST_CASE(atca_cmd_basic_test, managecert_verify_cert_chain_data_shared_memory), DEVICE_MASK(TA100) }, /* Array Termination element*/ - { (fp_test_case)NULL, (uint8_t)0 }, + { (fp_test_case)NULL, (uint8_t)0 }, }; t_test_case_info* talib_managecert_tests[] = { diff --git a/test/api_talib/test_talib_power.c b/test/api_talib/test_talib_power.c new file mode 100644 index 000000000..9c08293ac --- /dev/null +++ b/test/api_talib/test_talib_power.c @@ -0,0 +1,99 @@ +/** + * \file + * \brief Basic test for Power command api - TA100 + * + * \copyright (c) 2015-2020 Microchip Technology Inc. and its subsidiaries. + * + * \page License + * + * Subject to your compliance with these terms, you may use Microchip software + * and any derivatives exclusively with Microchip products. It is your + * responsibility to comply with third party license terms applicable to your + * use of third party software (including open source software) that may + * accompany Microchip software. + * + * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER + * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED + * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A + * PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, + * SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE + * OF ANY KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF + * MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE + * FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL + * LIABILITY ON ALL CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED + * THE AMOUNT OF FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR + * THIS SOFTWARE. + */ + +#include "atca_test.h" +#include "test_talib.h" + +#if ATCA_TA_SUPPORT + +/** \brief The function put the device in sleep mode + */ +TEST(atca_cmd_basic_test, power_sleep) +{ + ATCA_STATUS status = ATCA_GEN_FAIL; + + status = talib_power_sleep(atcab_get_device()); + + // wait for the device to enter into sleep mode + atca_delay_ms(2); + + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); +} + +/** \brief The function reboot the device + */ +TEST(atca_cmd_basic_test, power_reboot) +{ + ATCA_STATUS status = ATCA_GEN_FAIL; + uint8_t check_config_soft_reboot_enable; + uint16_t config_size = sizeof(check_config_soft_reboot_enable); + + // skip if config is not locked + test_assert_config_is_locked(); + + // skip if setup is not locked + test_assert_data_is_locked(); + + // Read the soft reboot configuration byte + status = talib_read_partial_element(atcab_get_device(), TA_HANDLE_CONFIG_MEMORY, 29, &config_size, + &check_config_soft_reboot_enable); + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + if (check_config_soft_reboot_enable & TA_POWER_SOFT_REBOOT_CONFIG) + { + status = talib_power_reboot(atcab_get_device()); + + // Wait for the device to reboot + atca_delay_ms(7); + + TEST_ASSERT_EQUAL(ATCA_SUCCESS, status); + + } + else + { + + TEST_IGNORE_MESSAGE("Ignoring the test as soft reboot is not enabled in configuration"); + + } +} + +// *INDENT-OFF* - Preserve formatting +t_test_case_info talib_power_basic_test_info[] = +{ + { REGISTER_TEST_CASE(atca_cmd_basic_test, power_sleep), DEVICE_MASK(TA100) }, + { REGISTER_TEST_CASE(atca_cmd_basic_test, power_reboot), DEVICE_MASK(TA100) }, + { (fp_test_case)NULL, (uint8_t)0 }, /* Array Termination element*/ +}; +// *INDENT-OFN* + +t_test_case_info* talib_power_tests[] = { + talib_power_basic_test_info, + /* Array Termination element*/ + (t_test_case_info*)NULL +}; + +#endif \ No newline at end of file diff --git a/test/atca_test_config.c b/test/atca_test_config.c index c2034083c..14fe380f2 100644 --- a/test/atca_test_config.c +++ b/test/atca_test_config.c @@ -258,9 +258,33 @@ static int opt_iface_type(int argc, char* argv[]) { gCfg->iface_type = ATCA_SPI_IFACE; - gCfg->atcaspi.bus = 0; - gCfg->atcaspi.select_pin = 0; - gCfg->atcaspi.baud = 200000; + if (argc >= 3 && argv[2][0] != '-') + { + gCfg->atcaspi.bus = (uint8_t)strtol(argv[2], NULL, 16); + ret = 3; + } + else + { + gCfg->atcaspi.bus = 0; + } + + if (argc >= 4 && argv[3][0] != '-') + { + gCfg->atcaspi.select_pin = (uint8_t)strtol(argv[3], NULL, 16); + } + else + { + gCfg->atcaspi.select_pin = 0; + } + + if (argc >= 5 && argv[4][0] != '-') + { + gCfg->atcaspi.baud = (uint32_t)strtol(argv[4], NULL, 10); + } + else + { + gCfg->atcaspi.baud = 200000; + } } } return ret;