From 3f2f5c722ce0f5f09222c0418c385d3f9145f830 Mon Sep 17 00:00:00 2001 From: Thomas Cuyckens Date: Fri, 3 May 2024 16:29:29 +0200 Subject: [PATCH] feat(platform): add child handling callbacks --- CMakeLists.txt | 9 +- etc/options.cmake | 21 ++ src/gp712/CMakeLists.txt | 6 +- src/gp712/radio.c | 42 ++++ src/gp712/radio_qorvo.h | 31 +++ src/qpg6105/CMakeLists.txt | 11 +- src/qpg6105/crypto/common-mbedtls-config.h | 106 ++++++--- src/qpg6105/crypto/qorvo-mbedtls-config.h | 65 ++++++ src/qpg6105/crypto/qpg6105-mbedtls-config.h | 17 +- src/qpg6105/openthread-core-qpg6105-config.h | 2 +- src/qpg6105/platform.c | 1 + src/qpg6105/radio.c | 42 ++++ src/qpg6105/radio_qorvo.h | 31 +++ src/qpg6105/syscalls_stubs.c | 214 ++++++++++++++++++ src/qpg7015m/CMakeLists.txt | 6 +- src/qpg7015m/radio.c | 42 ++++ src/qpg7015m/radio_qorvo.h | 31 +++ src/qpg7015m/spinel_extension.cpp | 221 +++++++++++++++++++ third_party/Qorvo/CMakeLists.txt | 26 +-- third_party/Qorvo/qorvo-mbedtls.cmake | 62 ++++++ third_party/Qorvo/repo | 2 +- 21 files changed, 913 insertions(+), 75 deletions(-) create mode 100644 src/qpg6105/crypto/qorvo-mbedtls-config.h create mode 100644 src/qpg6105/syscalls_stubs.c create mode 100644 src/qpg7015m/spinel_extension.cpp create mode 100644 third_party/Qorvo/qorvo-mbedtls.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 0588ab7e6..c766445d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,9 +57,9 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) if (DEFINED ENV{QORVO_OT_SDK}) - SET(SDK_DIR "$ENV{QORVO_OT_SDK}") + set(SDK_DIR "$ENV{QORVO_OT_SDK}") else() - SET(SDK_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/Qorvo/repo") + set(SDK_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third_party/Qorvo/repo") if(NOT EXISTS ${SDK_DIR}/${QORVO_PLATFORM}) message(FATAL_ERROR "Please select a correct SDK directory: ${SDK_DIR}/${QORVO_PLATFORM} does not exist") endif() @@ -76,6 +76,11 @@ set(OT_PLATFORM_LIB_MTD "${PLATFORM_TARGET_MTD}") set(PLATFORM_TARGET_RCP "openthread-${QORVO_PLATFORM}-ftd") set(PLATFORM_DRIVER_RCP "${QORVO_PLATFORM}-driver-ftd") set(OT_PLATFORM_LIB_RCP "${PLATFORM_TARGET_RCP}") +if (${QORVO_PLATFORM} EQUAL "qpg7015m") + unset(OT_NCP_VENDOR_HOOK_SOURCE CACHE) + set(OT_NCP_VENDOR_HOOK_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/${QORVO_PLATFORM}/" CACHE STRING "Vendor hook directory") + set(OT_NCP_VENDOR_HOOK_SOURCE "spinel_extension.cpp" CACHE STRING "Vendor hook file") +endif() include("${PROJECT_SOURCE_DIR}/etc/options.cmake") diff --git a/etc/options.cmake b/etc/options.cmake index f3cd2aff5..562ca05b1 100644 --- a/etc/options.cmake +++ b/etc/options.cmake @@ -40,3 +40,24 @@ option(OT_QORVO_SUPPORTED_CHILDREN "The amount of children supported on the plat if (OT_QORVO_SUPPORTED_CHILDREN) add_definitions(-DOPENTHREAD_CONFIG_MLE_MAX_CHILDREN=${OT_QORVO_SUPPORTED_CHILDREN}) endif() + +option(OT_COMMISSIONER "Enable Commissioner role (disabled by default)" OFF) +if (OT_COMMISSIONER) + add_definitions(-DOPENTHREAD_CONFIG_COMMISSIONER_ENABLE=1) +else() + add_definitions(-DOPENTHREAD_CONFIG_COMMISSIONER_ENABLE=0) +endif() + +option(OT_JOINER "Enable Joiner role (enabled by default)" ON) +if (OT_JOINER) + add_definitions(-DOPENTHREAD_CONFIG_JOINER_ENABLE=1) +else() + add_definitions(-DOPENTHREAD_CONFIG_JOINER_ENABLE=0) +endif() + +option(OT_TCP "Enabled TCP/TLS (disabled by default)" OFF) +if (OT_TCP) + add_definitions(-DOPENTHREAD_CONFIG_TCP_ENABLE=1) +else() + add_definitions(-DOPENTHREAD_CONFIG_TCP_ENABLE=0) +endif() diff --git a/src/gp712/CMakeLists.txt b/src/gp712/CMakeLists.txt index d2503c439..159117f84 100644 --- a/src/gp712/CMakeLists.txt +++ b/src/gp712/CMakeLists.txt @@ -72,14 +72,13 @@ add_library(${PLATFORM_TARGET_FTD} set_target_properties(${PLATFORM_TARGET_FTD} PROPERTIES C_STANDARD 99 - CXX_STANDARD 14 + CXX_STANDARD 20 ) target_link_libraries(${PLATFORM_TARGET_FTD} PRIVATE -Wl,--start-group ${PLATFORM_DRIVER_FTD} - ${OT_MBEDTLS} ot-config -Wl,--end-group PUBLIC @@ -113,14 +112,13 @@ add_library(${PLATFORM_TARGET_MTD} set_target_properties(${PLATFORM_TARGET_MTD} PROPERTIES C_STANDARD 99 - CXX_STANDARD 14 + CXX_STANDARD 20 ) target_link_libraries(${PLATFORM_TARGET_MTD} PRIVATE -Wl,--start-group ${PLATFORM_DRIVER_MTD} - ${OT_MBEDTLS} ot-config -Wl,--end-group PUBLIC diff --git a/src/gp712/radio.c b/src/gp712/radio.c index 6ab761dd5..fd184196c 100644 --- a/src/gp712/radio.c +++ b/src/gp712/radio.c @@ -500,3 +500,45 @@ otError otPlatRadioGetRegion(otInstance *aInstance, uint16_t *aRegionCode) return OT_ERROR_NOT_IMPLEMENTED; } + +#if QORVO_FTD +#include + +void qorvoNeighbourTableChanged(otNeighborTableEvent aEvent, const otNeighborTableEntryInfo *aEntryInfo) +{ + if (aEvent == OT_NEIGHBOR_TABLE_EVENT_CHILD_REMOVED) + { + qorvoRadioHandleChildRemoved(aEntryInfo->mInfo.mChild.mRloc16, aEntryInfo->mInfo.mChild.mExtAddress.m8); + } + else if (aEvent == OT_NEIGHBOR_TABLE_EVENT_CHILD_ADDED) + { + qorvoRadioHandleChildAdded(aEntryInfo->mInfo.mChild.mRloc16, aEntryInfo->mInfo.mChild.mExtAddress.m8); + } + // We don't care about the other events +} + +#if QORVO_FTD +void qorvoRegisterNeighbourTableCallback(bool aEnable) +{ + otThreadRegisterNeighborTableCallback(pQorvoInstance, (aEnable) ? qorvoNeighbourTableChanged : NULL); +} +#else +extern void rcpRegisterNeighborTableCallback(bool aEnable); + +void qorvoRegisterNeighbourTableCallback(bool aEnable) +{ + rcpRegisterNeighborTableCallback(aEnable); +} + +OT_TOOL_WEAK void qorvoRadioHandleChildAdded(uint16_t aShortAddress, const uint8_t *aExtAddress) +{ +} +OT_TOOL_WEAK void qorvoRadioHandleChildRemoved(uint16_t aShortAddress, const uint8_t *aExtAddress) +{ +} +#endif // QORVO_FTD +#else +OT_TOOL_WEAK void qorvoRegisterNeighbourTableCallback(bool aEnable) +{ +} +#endif // QORVO_RCP || QORVO_FTD diff --git a/src/gp712/radio_qorvo.h b/src/gp712/radio_qorvo.h index bae778c48..6499461cf 100644 --- a/src/gp712/radio_qorvo.h +++ b/src/gp712/radio_qorvo.h @@ -39,6 +39,7 @@ #include #include +#include #include /** @@ -316,6 +317,36 @@ otError qorvoRadioReceiveAt(uint8_t aChannel, uint32_t aStart, uint32_t aDuratio */ otRadioCaps qorvoRadioGetCaps(void); +/** + * Register the NeighbourTable callback with the openthread stack. + * + */ +void qorvoRegisterNeighbourTableCallback(bool enable); + +/** + * Callback to notify the radio which Neighbour was added removed + * + */ +void qorvoNeighbourTableChanged(otNeighborTableEvent aEvent, const otNeighborTableEntryInfo *aEntryInfo); + +/** + * This function is called when OpenThread adds a Child to the Neigbour table. + * + * @param[in] aShortAddress The child's rloc16 + * @param[in] aExtAddress The child's extended address + * + */ +void qorvoRadioHandleChildAdded(uint16_t aShortAddress, const uint8_t *aExtAddress); + +/** + * This function is called when OpenThread removes a Child from the Neigbour table. + * + * @param[in] aShortAddress The child's rloc16 + * @param[in] aExtAddress The child's extended address + * + */ +void qorvoRadioHandleChildRemoved(uint16_t aShortAddress, const uint8_t *aExtAddress); + /** * This callback is called when the energy scan is finished. * diff --git a/src/qpg6105/CMakeLists.txt b/src/qpg6105/CMakeLists.txt index 7bc0471aa..b9472d0d0 100755 --- a/src/qpg6105/CMakeLists.txt +++ b/src/qpg6105/CMakeLists.txt @@ -27,7 +27,7 @@ # target_compile_definitions(ot-config INTERFACE - "MBEDTLS_CONFIG_FILE=\"${QORVO_PLATFORM}-mbedtls-config.h\"" + "MBEDTLS_CONFIG_FILE=\"${SDK_DIR}/${QORVO_PLATFORM}/inc/${QORVO_PLATFORM}-mbedtls-config.h\"" ) list(APPEND OT_PUBLIC_INCLUDES @@ -47,6 +47,7 @@ set(PLATFORM_SOURCES platform.c radio.c settings.c + syscalls_stubs.c uart.c ) @@ -58,14 +59,14 @@ add_library(${PLATFORM_TARGET_FTD} set_target_properties(${PLATFORM_TARGET_FTD} PROPERTIES C_STANDARD 99 - CXX_STANDARD 14 + CXX_STANDARD 20 ) target_link_libraries(${PLATFORM_TARGET_FTD} PRIVATE + -lc # Required to rearrange linking order to pick up syscalls stubs for libc -Wl,--start-group ${PLATFORM_DRIVER_FTD} - ${OT_MBEDTLS} ot-config -Wl,--end-group PUBLIC @@ -99,14 +100,14 @@ add_library(${PLATFORM_TARGET_MTD} set_target_properties(${PLATFORM_TARGET_MTD} PROPERTIES C_STANDARD 99 - CXX_STANDARD 14 + CXX_STANDARD 20 ) target_link_libraries(${PLATFORM_TARGET_MTD} PRIVATE + -lc # Required to rearrange linking order to pick up syscalls stubs for libc -Wl,--start-group ${PLATFORM_DRIVER_MTD} - ${OT_MBEDTLS} ot-config -Wl,--end-group PUBLIC diff --git a/src/qpg6105/crypto/common-mbedtls-config.h b/src/qpg6105/crypto/common-mbedtls-config.h index d871d9618..1ca84002c 100644 --- a/src/qpg6105/crypto/common-mbedtls-config.h +++ b/src/qpg6105/crypto/common-mbedtls-config.h @@ -26,20 +26,14 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef COMMON_MBEDTLS_CONFIG_H -#define COMMON_MBEDTLS_CONFIG_H +#pragma once -#define MBEDTLS_AES_C -#define MBEDTLS_ECP_C -#define MBEDTLS_ECDH_C -#define MBEDTLS_ENTROPY_C -//#define MBEDTLS_SHA1_C -#define MBEDTLS_SHA224_C -#define MBEDTLS_SHA256_C -#define MBEDTLS_CIPHER_MODE_CTR +#include "qorvo-mbedtls-config.h" +#include #define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf +#define MBEDTLS_AES_C #define MBEDTLS_AES_ROM_TABLES #define MBEDTLS_ASN1_PARSE_C #define MBEDTLS_ASN1_WRITE_C @@ -48,46 +42,50 @@ #define MBEDTLS_CIPHER_C #define MBEDTLS_CMAC_C #define MBEDTLS_CTR_DRBG_C -#define MBEDTLS_ECJPAKE_C +#define MBEDTLS_ECP_C #define MBEDTLS_ECP_DP_SECP256R1_ENABLED #define MBEDTLS_ECP_NIST_OPTIM +#define MBEDTLS_ENTROPY_C #define MBEDTLS_HAVE_ASM #define MBEDTLS_HMAC_DRBG_C -#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED #define MBEDTLS_MD_C +// #define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES #define MBEDTLS_NO_PLATFORM_ENTROPY -#define MBEDTLS_OID_C // what is this ? #define MBEDTLS_PK_C #define MBEDTLS_PK_PARSE_C -#define MBEDTLS_PK_WRITE_C #define MBEDTLS_PLATFORM_C #define MBEDTLS_PLATFORM_MEMORY #define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS +#define MBEDTLS_SHA224_C +#define MBEDTLS_SHA256_C #define MBEDTLS_SHA256_SMALLER #define MBEDTLS_SSL_CLI_C #define MBEDTLS_SSL_DTLS_ANTI_REPLAY #define MBEDTLS_SSL_DTLS_HELLO_VERIFY #define MBEDTLS_SSL_EXPORT_KEYS #define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH -#define MBEDTLS_SSL_PROTO_TLS1_2 #define MBEDTLS_SSL_PROTO_DTLS +#define MBEDTLS_SSL_PROTO_TLS1_2 #define MBEDTLS_SSL_TLS_C -#define MBEDTLS_ERROR_STRERROR_DUMMY -#define MBEDTLS_HKDF_C -#define MBEDTLS_X509_CREATE_C -#define MBEDTLS_X509_CSR_WRITE_C -#define MBEDTLS_X509_CRT_PARSE_C -#define MBEDTLS_X509_USE_C -#define MBEDTLS_X509_REMOVE_INFO -#define MBEDTLS_BASE64_C -#define MBEDTLS_PEM_WRITE_C +#define MBEDTLS_TRNG_C -#define MBEDTLS_ECDH_LEGACY_CONTEXT -#define MBEDTLS_ECDSA_C -#define MBEDTLS_ECDSA_DETERMINISTIC +#if OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE || OPENTHREAD_CONFIG_COMMISSIONER_ENABLE || \ + OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE +#define MBEDTLS_SSL_COOKIE_C +#define MBEDTLS_SSL_SRV_C +#endif + +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE +#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED +#endif + +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE || OPENTHREAD_CONFIG_TCP_ENABLE +#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED +#endif #ifdef MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED #define MBEDTLS_BASE64_C +#define MBEDTLS_ECDH_C #define MBEDTLS_ECDSA_C #define MBEDTLS_OID_C #define MBEDTLS_PEM_PARSE_C @@ -95,11 +93,15 @@ #define MBEDTLS_X509_CRT_PARSE_C #endif -#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS -#define MBEDTLS_SSL_DTLS_CONNECTION_ID 0 -#define MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 0 - -#define MBEDTLS_DEPRECATED_REMOVED +#if OPENTHREAD_CONFIG_ECDSA_ENABLE +#define MBEDTLS_BASE64_C +#define MBEDTLS_ECDH_C +#define MBEDTLS_ECDSA_C +#define MBEDTLS_ECDSA_DETERMINISTIC +#define MBEDTLS_OID_C +#define MBEDTLS_PEM_PARSE_C +#define MBEDTLS_PK_WRITE_C +#endif #define MBEDTLS_MPI_WINDOW_SIZE 1 /**< Maximum windows size used. */ #define MBEDTLS_MPI_MAX_SIZE 32 /**< Maximum number of bytes for usable MPIs. */ @@ -110,10 +112,44 @@ #define MBEDTLS_PLATFORM_STD_CALLOC calloc #define MBEDTLS_PLATFORM_STD_FREE free -#define MBEDTLS_SSL_MAX_CONTENT_LEN 768 /**< Maxium fragment length in bytes */ +#if OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE +#define MBEDTLS_SSL_MAX_CONTENT_LEN 900 /**< Maxium fragment length in bytes */ +#else +#define MBEDTLS_SSL_MAX_CONTENT_LEN 768 /**< Maximmum fragment length in bytes */ +#endif -#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8 +#define MBEDTLS_SSL_IN_CONTENT_LEN MBEDTLS_SSL_MAX_CONTENT_LEN +#define MBEDTLS_SSL_OUT_CONTENT_LEN MBEDTLS_SSL_MAX_CONTENT_LEN +// Matter specific +#define MBEDTLS_ERROR_STRERROR_DUMMY +#define MBEDTLS_HKDF_C +#define MBEDTLS_PEM_WRITE_C #define MBEDTLS_PKCS5_C +#define MBEDTLS_X509_CSR_WRITE_C +#define MBEDTLS_X509_CREATE_C +#define MBEDTLS_X509_REMOVE_INFO + +// OpenThread specific +#if OPENTHREAD_CONFIG_JOINER_ENABLE || OPENTHREAD_CONFIG_COMMISSIONER_ENABLE +#define MBEDTLS_ECJPAKE_C +#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED +#define MBEDTLS_SSL_CIPHERSUITES MBEDTLS_TLS_ECJPAKE_WITH_AES_128_CCM_8 +#endif + +// Others +#define MBEDTLS_DEPRECATED_REMOVED + +// MBEDTLS_SSL_PROTO_TLS1_2 requires at least one MBEDTLS_KEY_EXCHANGE_XXX algorithm +#if (!defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED) && !defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED) && \ + !defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)) +#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED +#endif + +// Fixes wunifdef in ssl.h +#define MBEDTLS_SSL_DTLS_CONNECTION_ID +#define MBEDTLS_SSL_DTLS_CONNECTION_ID_COMPAT 0 -#endif // COMMON_MBEDTLS_CONFIG_H +// Were set at one point, but don't seem to be necessary +// #define MBEDTLS_ECDH_LEGACY_CONTEXT +// #define MBEDTLS_CIPHER_MODE_CTR diff --git a/src/qpg6105/crypto/qorvo-mbedtls-config.h b/src/qpg6105/crypto/qorvo-mbedtls-config.h new file mode 100644 index 000000000..86dd5f540 --- /dev/null +++ b/src/qpg6105/crypto/qorvo-mbedtls-config.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2019, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * 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. + */ + +#pragma once + +#ifdef QORVO_MBEDTLS_DEBUG +#ifndef MBEDTLS_DEBUG_C +#define MBEDTLS_DEBUG_C +#endif // MBEDTLS_DEBUG_C +#endif // QORVO_MBEDTLS_DEBUG + +// Enables secured CoAP, not used by Thread nor Matter +#ifndef OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE +#define OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE 0 +#endif // OPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE + +// Required for SRP client and server and thus in Thread 1.2 and Matter +#ifndef OPENTHREAD_CONFIG_ECDSA_ENABLE +#define OPENTHREAD_CONFIG_ECDSA_ENABLE 1 +#endif // OPENTHREAD_CONFIG_ECDSA_ENABLE + +// Enables the optional Thread Commissioner feature +#ifndef OPENTHREAD_CONFIG_COMMISSIONER_ENABLE +#define OPENTHREAD_CONFIG_COMMISSIONER_ENABLE 0 +#endif // OPENTHREAD_CONFIG_COMMISSIONER_ENABLE + +// Enables TCP, Mandatory for Thread Components, optional for Thread Products +#ifndef OPENTHREAD_CONFIG_TCP_ENABLE +#define OPENTHREAD_CONFIG_TCP_ENABLE 0 +#endif // OPENTHREAD_CONFIG_TCP_ENABLE + +// Enables the Thread Joiner role, Mandatory for Thread Components, optional for Thread Products +#ifndef OPENTHREAD_CONFIG_JOINER_ENABLE +#define OPENTHREAD_CONFIG_JOINER_ENABLE 0 +#endif // OPENTHREAD_CONFIG_JOINER_ENABLE + +// Enables the Thread Border Agent functionality, Mandatory on Border Routers +#ifndef OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE +#define OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE 0 +#endif // OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE diff --git a/src/qpg6105/crypto/qpg6105-mbedtls-config.h b/src/qpg6105/crypto/qpg6105-mbedtls-config.h index 7c6b76491..efd64aff8 100644 --- a/src/qpg6105/crypto/qpg6105-mbedtls-config.h +++ b/src/qpg6105/crypto/qpg6105-mbedtls-config.h @@ -26,19 +26,17 @@ * POSSIBILITY OF SUCH DAMAGE. */ -#ifndef QPG6105_MBEDTLS_CONFIG_H -#define QPG6105_MBEDTLS_CONFIG_H +#pragma once #include "common-mbedtls-config.h" -#ifndef MBEDTLS_SW_ONLY -#define MBEDTLS_SHA1_ALT 1 -#define MBEDTLS_ECP_ALT +#define MBEDTLS_AES_ALT +#define MBEDTLS_ECDH_COMPUTE_SHARED_ALT +#define MBEDTLS_ECDH_GEN_PUBLIC_ALT #define MBEDTLS_ECDSA_VERIFY_ALT #define MBEDTLS_ECDSA_SIGN_ALT +#define MBEDTLS_ECP_ALT #define MBEDTLS_SHA256_ALT -#define MBEDTLS_ECDH_COMPUTE_SHARED_ALT -#endif #define MBEDTLS_ENTROPY_HARDWARE_ALT @@ -46,7 +44,6 @@ #undef MBEDTLS_ECP_WINDOW_SIZE #undef MBEDTLS_ECP_FIXED_POINT_OPTIM -#define MBEDTLS_AES_ALT +#if OPENTHREAD_CONFIG_JOINER_ENABLE || OPENTHREAD_CONFIG_COMMISSIONER_ENABLE #define MBEDTLS_ECJPAKE_ALT - -#endif // QPG6105_MBEDTLS_CONFIG_H +#endif diff --git a/src/qpg6105/openthread-core-qpg6105-config.h b/src/qpg6105/openthread-core-qpg6105-config.h index e703e2a4b..e44b6d2e6 100644 --- a/src/qpg6105/openthread-core-qpg6105-config.h +++ b/src/qpg6105/openthread-core-qpg6105-config.h @@ -89,7 +89,7 @@ * */ #ifndef OPENTHREAD_CONFIG_DIAG_ENABLE -#define OPENTHREAD_CONFIG_DIAG_ENABLE 1 +#define OPENTHREAD_CONFIG_DIAG_ENABLE 0 #endif /** diff --git a/src/qpg6105/platform.c b/src/qpg6105/platform.c index 815df4c41..ca4a848fd 100755 --- a/src/qpg6105/platform.c +++ b/src/qpg6105/platform.c @@ -63,6 +63,7 @@ void otSysInit(int argc, char *argv[]) { OT_UNUSED_VARIABLE(argc); OT_UNUSED_VARIABLE(argv); + qorvoPlatInit((qorvoPlatGotoSleepCheckCallback_t)qorvoPlatGotoSleepCheck); qorvoUartInit(); qorvoAlarmInit(); diff --git a/src/qpg6105/radio.c b/src/qpg6105/radio.c index 7fb2ee4e5..8efeac641 100644 --- a/src/qpg6105/radio.c +++ b/src/qpg6105/radio.c @@ -591,3 +591,45 @@ otError otPlatRadioConfigureEnhAckProbing(otInstance *aInstance, return qorvoRadioConfigureEnhAckProbing(aLinkMetrics, (uint16_t)aShortAddress, aExtAddress->m8); } + +#if QORVO_RCP || QORVO_FTD +#include + +void qorvoNeighbourTableChanged(otNeighborTableEvent aEvent, const otNeighborTableEntryInfo *aEntryInfo) +{ + if (aEvent == OT_NEIGHBOR_TABLE_EVENT_CHILD_REMOVED) + { + qorvoRadioHandleChildRemoved(aEntryInfo->mInfo.mChild.mRloc16, aEntryInfo->mInfo.mChild.mExtAddress.m8); + } + else if (aEvent == OT_NEIGHBOR_TABLE_EVENT_CHILD_ADDED) + { + qorvoRadioHandleChildAdded(aEntryInfo->mInfo.mChild.mRloc16, aEntryInfo->mInfo.mChild.mExtAddress.m8); + } + // We don't care about the other events +} + +#if QORVO_FTD +void qorvoRegisterNeighbourTableCallback(bool aEnable) +{ + otThreadRegisterNeighborTableCallback(pQorvoInstance, (aEnable) ? qorvoNeighbourTableChanged : NULL); +} +#else +extern void rcpRegisterNeighborTableCallback(bool aEnable); + +void qorvoRegisterNeighbourTableCallback(bool aEnable) +{ + rcpRegisterNeighborTableCallback(aEnable); +} + +OT_TOOL_WEAK void qorvoRadioHandleChildAdded(uint16_t aShortAddress, const uint8_t *aExtAddress) +{ +} +OT_TOOL_WEAK void qorvoRadioHandleChildRemoved(uint16_t aShortAddress, const uint8_t *aExtAddress) +{ +} +#endif // QORVO_FTD +#else +OT_TOOL_WEAK void qorvoRegisterNeighbourTableCallback(bool aEnable) +{ +} +#endif // QORVO_RCP || QORVO_FTD diff --git a/src/qpg6105/radio_qorvo.h b/src/qpg6105/radio_qorvo.h index bae778c48..6499461cf 100644 --- a/src/qpg6105/radio_qorvo.h +++ b/src/qpg6105/radio_qorvo.h @@ -39,6 +39,7 @@ #include #include +#include #include /** @@ -316,6 +317,36 @@ otError qorvoRadioReceiveAt(uint8_t aChannel, uint32_t aStart, uint32_t aDuratio */ otRadioCaps qorvoRadioGetCaps(void); +/** + * Register the NeighbourTable callback with the openthread stack. + * + */ +void qorvoRegisterNeighbourTableCallback(bool enable); + +/** + * Callback to notify the radio which Neighbour was added removed + * + */ +void qorvoNeighbourTableChanged(otNeighborTableEvent aEvent, const otNeighborTableEntryInfo *aEntryInfo); + +/** + * This function is called when OpenThread adds a Child to the Neigbour table. + * + * @param[in] aShortAddress The child's rloc16 + * @param[in] aExtAddress The child's extended address + * + */ +void qorvoRadioHandleChildAdded(uint16_t aShortAddress, const uint8_t *aExtAddress); + +/** + * This function is called when OpenThread removes a Child from the Neigbour table. + * + * @param[in] aShortAddress The child's rloc16 + * @param[in] aExtAddress The child's extended address + * + */ +void qorvoRadioHandleChildRemoved(uint16_t aShortAddress, const uint8_t *aExtAddress); + /** * This callback is called when the energy scan is finished. * diff --git a/src/qpg6105/syscalls_stubs.c b/src/qpg6105/syscalls_stubs.c new file mode 100644 index 000000000..a3ba8e10a --- /dev/null +++ b/src/qpg6105/syscalls_stubs.c @@ -0,0 +1,214 @@ +/* + * + * Copyright (c) 2023 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + This file is only used to implement weak syscall stubs + that gcc-arm-none-eabi 12.2.1 expect to link when using Libc + (newlib/libc_nano) +*/ + +#include +#include +#include +#include +#include +#include +#include +#include + +int _open(const char *pathname, int flags, int mode); +int _close(int file); +int _fstat(int file, struct stat *st); +int _isatty(int file); +int _lseek(int file, int ptr, int dir); +int _read(int file, char *ptr, int len); +int _write(int file, const char *ptr, int len); + +/************************************************************************** + * @brief + * Open a file. + * + * @param[in] file + * File you want to open. + * + * @return + * Returns -1 since there is not logic here to open file. + **************************************************************************/ +int __attribute__((weak)) _open(const char *pathname, int flags, int mode) +{ + (void)pathname; + (void)flags; + (void)mode; + return -1; +} + +/************************************************************************** + * @brief + * Close a file. + * + * @param[in] file + * File you want to close. + * + * @return + * Returns 0 when the file is closed. + **************************************************************************/ +int __attribute__((weak)) _close(int file) +{ + (void)file; + return 0; +} + +/************************************************************************** + * @brief Exit the program. + * @param[in] status The value to return to the parent process as the + * exit status (not used). + **************************************************************************/ +void __attribute__((weak)) _exit(int status) +{ + (void)status; + while (true) + { + } /* Hang here forever... */ +} + +/************************************************************************* + * @brief + * Status of an open file. + * + * @param[in] file + * Check status for this file. + * + * @param[in] st + * Status information. + * + * @return + * Returns 0 when st_mode is set to character special. + ************************************************************************/ +int __attribute__((weak)) _fstat(int file, struct stat *st) +{ + (void)file; + (void)st; + return 0; +} + +/************************************************************************** + * @brief Get process ID. + *************************************************************************/ +int __attribute__((weak)) _getpid(void) +{ + return 1; +} + +/************************************************************************** + * @brief + * Query whether output stream is a terminal. + * + * @param[in] file + * Descriptor for the file. + * + * @return + * Returns 1 when query is done. + **************************************************************************/ +int __attribute__((weak)) _isatty(int file) +{ + (void)file; + return 1; +} + +/************************************************************************** + * @brief Send signal to process. + * @param[in] pid Process id (not used). + * @param[in] sig Signal to send (not used). + *************************************************************************/ +int __attribute__((weak)) _kill(int pid, int sig) +{ + (void)pid; + (void)sig; + return -1; +} + +/************************************************************************** + * @brief + * Set position in a file. + * + * @param[in] file + * Descriptor for the file. + * + * @param[in] ptr + * Poiter to the argument offset. + * + * @param[in] dir + * Directory whence. + * + * @return + * Returns 0 when position is set. + *************************************************************************/ +int __attribute__((weak)) _lseek(int file, int ptr, int dir) +{ + (void)file; + (void)ptr; + (void)dir; + return 0; +} + +/************************************************************************** + * @brief + * Read from a file. + * + * @param[in] file + * Descriptor for the file you want to read from. + * + * @param[in] ptr + * Pointer to the chacaters that are beeing read. + * + * @param[in] len + * Number of characters to be read. + * + * @return + * Number of characters that have been read. + *************************************************************************/ +int __attribute__((weak)) _read(int file, char *ptr, int len) +{ + (void)file; + (void)ptr; + (void)len; + return 0; +} + +/************************************************************************** + * @brief + * Write to a file. + * + * @param[in] file + * Descriptor for the file you want to write to. + * + * @param[in] ptr + * Pointer to the text you want to write + * + * @param[in] len + * Number of characters to be written. + * + * @return + * Number of characters that have been written. + **************************************************************************/ +int __attribute__((weak)) _write(int file, const char *ptr, int len) +{ + (void)file; + (void)ptr; + + return len; +} diff --git a/src/qpg7015m/CMakeLists.txt b/src/qpg7015m/CMakeLists.txt index d2503c439..159117f84 100644 --- a/src/qpg7015m/CMakeLists.txt +++ b/src/qpg7015m/CMakeLists.txt @@ -72,14 +72,13 @@ add_library(${PLATFORM_TARGET_FTD} set_target_properties(${PLATFORM_TARGET_FTD} PROPERTIES C_STANDARD 99 - CXX_STANDARD 14 + CXX_STANDARD 20 ) target_link_libraries(${PLATFORM_TARGET_FTD} PRIVATE -Wl,--start-group ${PLATFORM_DRIVER_FTD} - ${OT_MBEDTLS} ot-config -Wl,--end-group PUBLIC @@ -113,14 +112,13 @@ add_library(${PLATFORM_TARGET_MTD} set_target_properties(${PLATFORM_TARGET_MTD} PROPERTIES C_STANDARD 99 - CXX_STANDARD 14 + CXX_STANDARD 20 ) target_link_libraries(${PLATFORM_TARGET_MTD} PRIVATE -Wl,--start-group ${PLATFORM_DRIVER_MTD} - ${OT_MBEDTLS} ot-config -Wl,--end-group PUBLIC diff --git a/src/qpg7015m/radio.c b/src/qpg7015m/radio.c index d502132dc..b03e82bf4 100644 --- a/src/qpg7015m/radio.c +++ b/src/qpg7015m/radio.c @@ -598,3 +598,45 @@ otError otPlatRadioConfigureEnhAckProbing(otInstance *aInstance, return qorvoRadioConfigureEnhAckProbing(aLinkMetrics, (uint16_t)aShortAddress, aExtAddress->m8); } + +#if QORVO_RCP || QORVO_FTD +#include + +void qorvoNeighbourTableChanged(otNeighborTableEvent aEvent, const otNeighborTableEntryInfo *aEntryInfo) +{ + if (aEvent == OT_NEIGHBOR_TABLE_EVENT_CHILD_REMOVED) + { + qorvoRadioHandleChildRemoved(aEntryInfo->mInfo.mChild.mRloc16, aEntryInfo->mInfo.mChild.mExtAddress.m8); + } + else if (aEvent == OT_NEIGHBOR_TABLE_EVENT_CHILD_ADDED) + { + qorvoRadioHandleChildAdded(aEntryInfo->mInfo.mChild.mRloc16, aEntryInfo->mInfo.mChild.mExtAddress.m8); + } + // We don't care about the other events +} + +#if QORVO_FTD +void qorvoRegisterNeighbourTableCallback(bool aEnable) +{ + otThreadRegisterNeighborTableCallback(pQorvoInstance, (aEnable) ? qorvoNeighbourTableChanged : NULL); +} +#else +extern void rcpRegisterNeighborTableCallback(bool aEnable); + +void qorvoRegisterNeighbourTableCallback(bool aEnable) +{ + rcpRegisterNeighborTableCallback(aEnable); +} + +OT_TOOL_WEAK void qorvoRadioHandleChildAdded(uint16_t aShortAddress, const uint8_t *aExtAddress) +{ +} +OT_TOOL_WEAK void qorvoRadioHandleChildRemoved(uint16_t aShortAddress, const uint8_t *aExtAddress) +{ +} +#endif // QORVO_FTD +#else +OT_TOOL_WEAK void qorvoRegisterNeighbourTableCallback(bool aEnable) +{ +} +#endif // QORVO_RCP || QORVO_FTD diff --git a/src/qpg7015m/radio_qorvo.h b/src/qpg7015m/radio_qorvo.h index bae778c48..6499461cf 100644 --- a/src/qpg7015m/radio_qorvo.h +++ b/src/qpg7015m/radio_qorvo.h @@ -39,6 +39,7 @@ #include #include +#include #include /** @@ -316,6 +317,36 @@ otError qorvoRadioReceiveAt(uint8_t aChannel, uint32_t aStart, uint32_t aDuratio */ otRadioCaps qorvoRadioGetCaps(void); +/** + * Register the NeighbourTable callback with the openthread stack. + * + */ +void qorvoRegisterNeighbourTableCallback(bool enable); + +/** + * Callback to notify the radio which Neighbour was added removed + * + */ +void qorvoNeighbourTableChanged(otNeighborTableEvent aEvent, const otNeighborTableEntryInfo *aEntryInfo); + +/** + * This function is called when OpenThread adds a Child to the Neigbour table. + * + * @param[in] aShortAddress The child's rloc16 + * @param[in] aExtAddress The child's extended address + * + */ +void qorvoRadioHandleChildAdded(uint16_t aShortAddress, const uint8_t *aExtAddress); + +/** + * This function is called when OpenThread removes a Child from the Neigbour table. + * + * @param[in] aShortAddress The child's rloc16 + * @param[in] aExtAddress The child's extended address + * + */ +void qorvoRadioHandleChildRemoved(uint16_t aShortAddress, const uint8_t *aExtAddress); + /** * This callback is called when the energy scan is finished. * diff --git a/src/qpg7015m/spinel_extension.cpp b/src/qpg7015m/spinel_extension.cpp new file mode 100644 index 000000000..dd42c62c8 --- /dev/null +++ b/src/qpg7015m/spinel_extension.cpp @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2016-2017, The OpenThread Authors. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN 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. + */ + +/** + * @file + * This file shows how to implement the NCP vendor hook. + */ + +#if OPENTHREAD_ENABLE_NCP_VENDOR_HOOK + +// #include "utils/uart.h" +#include "ncp_base.hpp" +#include +#include "lib/spinel/spinel.h" + +extern "C" void qorvoNeighbourTableChanged(otNeighborTableEvent aEvent, const otNeighborTableEntryInfo *aEntryInfo); +extern "C" otError otPlatUartSend(const uint8_t *aBuf, uint16_t aBufLength); + +#define SPINEL_PROP_VENDOR_CHILD_TABLE SPINEL_PROP_VENDOR__BEGIN + 0 +#define SPINEL_PROP_VENDOR_NEIGHBOR_TABLE_CALLBACK SPINEL_PROP_VENDOR__BEGIN + 1 + +#include "ncp_hdlc.hpp" +#include "common/new.hpp" + +class NcpVendorUart : public ot::Ncp::NcpHdlc +{ + static int SendHdlc(const uint8_t *aBuf, uint16_t aBufLength) + { + otPlatUartSend(aBuf, aBufLength); + return 0; + } + +public: + NcpVendorUart(ot::Instance *aInstance) + : ot::Ncp::NcpHdlc(aInstance, &NcpVendorUart::SendHdlc) + , mRegisterCallback(false) + { + } + + void RegisterNeighborTableCallback(bool enable); + bool mRegisterCallback; + +private: + // Add public/private methods or member variables +}; + +namespace ot { +namespace Ncp { + +otError NcpBase::VendorCommandHandler(uint8_t aHeader, unsigned int aCommand) +{ + otError error = OT_ERROR_NONE; + + switch (aCommand) + { + // TODO: Implement your command handlers here. + + default: + error = PrepareLastStatusResponse(aHeader, SPINEL_STATUS_INVALID_COMMAND); + } + + return error; +} + +void NcpBase::VendorHandleFrameRemovedFromNcpBuffer(Spinel::Buffer::FrameTag aFrameTag) +{ + // This method is a callback which mirrors `NcpBase::HandleFrameRemovedFromNcpBuffer()`. + // It is called when a spinel frame is sent and removed from NCP buffer. + // + // (a) This can be used to track and verify that a vendor spinel frame response is + // delivered to the host (tracking the frame using its tag). + // + // (b) It indicates that NCP buffer space is now available (since a spinel frame is + // removed). This can be used to implement reliability mechanisms to re-send + // a failed spinel command response (or an async spinel frame) transmission + // (failed earlier due to NCP buffer being full). + + OT_UNUSED_VARIABLE(aFrameTag); +} + +otError NcpBase::VendorGetPropertyHandler(spinel_prop_key_t aPropKey) +{ + otError error = OT_ERROR_NONE; + + switch (aPropKey) + { + // TODO: Implement your property get handlers here. + // + // Get handler should retrieve the property value and then encode and write the + // value into the NCP buffer. If the "get" operation itself fails, handler should + // write a `LAST_STATUS` with the error status into the NCP buffer. `OT_ERROR_NO_BUFS` + // should be returned if NCP buffer is full and response cannot be written. + case SPINEL_PROP_VENDOR_NEIGHBOR_TABLE_CALLBACK: + { + bool enable = ((NcpVendorUart *)(ot::Ncp::NcpBase::GetNcpInstance()))->mRegisterCallback; + SuccessOrExit(error = mEncoder.WriteUint8(enable)); + break; + } + + default: + error = OT_ERROR_NOT_FOUND; + break; + } + +exit: + return error; +} + +otError NcpBase::VendorSetPropertyHandler(spinel_prop_key_t aPropKey) +{ + otError error = OT_ERROR_NONE; + + switch (aPropKey) + { + // TODO: Implement your property set handlers here. + // + // Set handler should first decode the value from the input Spinel frame and then + // perform the corresponding set operation. The handler should not prepare the + // spinel response and therefore should not write anything to the NCP buffer. + // The error returned from handler (other than `OT_ERROR_NOT_FOUND`) indicates the + // error in either parsing of the input or the error of the set operation. In case + // of a successful "set", `NcpBase` set command handler will invoke the + // `VendorGetPropertyHandler()` for the same property key to prepare the response. + case SPINEL_PROP_VENDOR_CHILD_TABLE: + uint8_t event; + otNeighborTableEntryInfo child; + uint8_t mode; // Mode is a set of bits in otChildInfo, since we don't care we dumpt it here + + SuccessOrExit(error = mDecoder.ReadUint8(event)); + SuccessOrExit(error = mDecoder.OpenStruct()); + SuccessOrExit(error = mDecoder.ReadEui64(child.mInfo.mChild.mExtAddress)); + SuccessOrExit(error = mDecoder.ReadUint16(child.mInfo.mChild.mRloc16)); + SuccessOrExit(error = mDecoder.ReadUint32(child.mInfo.mChild.mTimeout)); + SuccessOrExit(error = mDecoder.ReadUint32(child.mInfo.mChild.mAge)); + SuccessOrExit(error = mDecoder.ReadUint8(child.mInfo.mChild.mNetworkDataVersion)); + SuccessOrExit(error = mDecoder.ReadUint8(child.mInfo.mChild.mLinkQualityIn)); + SuccessOrExit(error = mDecoder.ReadInt8(child.mInfo.mChild.mAverageRssi)); + SuccessOrExit(error = mDecoder.ReadUint8(mode)); + SuccessOrExit(error = mDecoder.ReadInt8(child.mInfo.mChild.mLastRssi)); + SuccessOrExit(error = mDecoder.CloseStruct()); + + qorvoNeighbourTableChanged((otNeighborTableEvent)event, &child); + break; + + default: + break; + } + +exit: + return error; +} + +} // namespace Ncp +} // namespace ot + +//------------------------------------------------------------------------------------------------------------------- +// When OPENTHREAD_ENABLE_NCP_VENDOR_HOOK is enabled, vendor code is +// expected to provide the `otAppNcpInit()` function. The reason behind +// this is to enable vendor code to define its own sub-class of +// `NcpBase` or `NcpHdlc`/`NcpSpi`. +// +// Example below show how to add a vendor sub-class over `NcpHdlc`. + +void NcpVendorUart::RegisterNeighborTableCallback(bool aEnable) +{ + // Set the value of mRegisterCallback, so we can later use to actually set it + mRegisterCallback = aEnable; + WritePropertyValueIsFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_PROP_VENDOR_NEIGHBOR_TABLE_CALLBACK); +} + +static OT_DEFINE_ALIGNED_VAR(sNcpVendorRaw, sizeof(NcpVendorUart), uint64_t); + +extern "C" void rcpRegisterNeighborTableCallback(bool aEnable) +{ + NcpVendorUart *ncpVendor = ((NcpVendorUart *)(ot::Ncp::NcpBase::GetNcpInstance())); + if (ncpVendor == nullptr) + { + // ncpVendor not (yet) initialized + return; + } + ncpVendor->RegisterNeighborTableCallback(aEnable); +} + +extern "C" void otAppNcpInit(otInstance *aInstance) +{ + NcpVendorUart *ncpVendor = nullptr; + ot::Instance *instance = static_cast(aInstance); + + ncpVendor = new (&sNcpVendorRaw) NcpVendorUart(instance); + + if (ncpVendor == nullptr || ncpVendor != ot::Ncp::NcpBase::GetNcpInstance()) + { + assert(false); + } +} + +#endif // #if OPENTHREAD_ENABLE_NCP_VENDOR_HOOK diff --git a/third_party/Qorvo/CMakeLists.txt b/third_party/Qorvo/CMakeLists.txt index f64e90b4d..734ab0b4c 100644 --- a/third_party/Qorvo/CMakeLists.txt +++ b/third_party/Qorvo/CMakeLists.txt @@ -31,29 +31,30 @@ message(STATUS "Qorvo ${QORVO_PLATFORM} libs in ${SDK_DIR}/${QORVO_PLATFORM}") string(TOUPPER ${QORVO_PLATFORM} QORVO_PLATFORM_UPPER) # setting defaults for the variables -set(MBEDTLSALT "") set(MBEDCRYPTO "") # mbedtls if (${QORVO_MBEDTLS}) if (DEFINED ENV{QORVO_OT_MBEDTLS_SDK}) - SET(QORVO_MBEDTLS_DIR "$ENV{QORVO_OT_MBEDTLS_SDK}") + set(QORVO_MBEDTLS_SDK_DIR "$ENV{QORVO_OT_MBEDTLS_SDK}") else() - SET(QORVO_MBEDTLS_DIR "${SDK_DIR}") + set(QORVO_MBEDTLS_SDK_DIR "${SDK_DIR}/qorvo-mbedtls/mbedtls/v3.3.0") endif() - set(MBEDTLSALT "${SDK_DIR}/${QORVO_PLATFORM}/lib/libmbedtls_alt.a") - set(QORVO_MBEDTLS_SDK_DIR "${QORVO_MBEDTLS_DIR}/qorvo-mbedtls/") - if(NOT EXISTS ${QORVO_MBEDTLS_SDK_DIR}/mbedtls/v3.3.0/include/mbedtls) - message(FATAL_ERROR "'${QORVO_MBEDTLS_SDK_DIR}/mbedtls/v3.3.0/include/mbedtls' does not exist. Try setting 'QORVO_OT_SDK' or 'QORVO_OT_MBEDTLS_SDK'") + + if (DEFINED ENV{QORVO_OT_MBEDTLS_ALT_CONFIG}) + set(QORVO_MBEDTLS_ALT_CONFIG "$ENV{QORVO_OT_MBEDTLS_ALT_CONFIG}") + else() + set(QORVO_MBEDTLS_ALT_CONFIG "${SDK_DIR}/${QORVO_PLATFORM}/inc") endif() - message(STATUS "Including Qorvo MBEDTLS - ${QORVO_MBEDTLS_SDK_DIR}") - include(${QORVO_MBEDTLS_SDK_DIR}/mbedtls.cmake) + set(MBEDCRYPTO "${SDK_DIR}/${QORVO_PLATFORM}/lib/libmbedtls_alt.a") - list(APPEND OT_PUBLIC_INCLUDES "${QORVO_MBEDTLS_SDK_DIR}/mbedtls/v3.3.0/include/mbedtls") - list(APPEND OT_PUBLIC_INCLUDES "${QORVO_MBEDTLS_SDK_DIR}/inc") + if(NOT EXISTS ${QORVO_MBEDTLS_SDK_DIR}/include/mbedtls) + message(FATAL_ERROR "'${QORVO_MBEDTLS_SDK_DIR}/include/mbedtls' does not exist. Try setting 'QORVO_OT_SDK' or 'QORVO_OT_MBEDTLS_SDK'") + endif() + message(STATUS "Including Qorvo MBEDTLS - ${QORVO_MBEDTLS_SDK_DIR}") - set(OT_PUBLIC_INCLUDES ${OT_PUBLIC_INCLUDES} PARENT_SCOPE) + include(qorvo-mbedtls.cmake) else() set(MBEDCRYPTO "mbedcrypto") endif() @@ -66,7 +67,6 @@ foreach(TYPE "FTD" "MTD") target_link_libraries(${PLATFORM_DRIVER_${TYPE}} INTERFACE ${QORVO_PLATFORM_LIB_${TYPE}} - ${MBEDTLSALT} ${MBEDCRYPTO} ) endforeach() diff --git a/third_party/Qorvo/qorvo-mbedtls.cmake b/third_party/Qorvo/qorvo-mbedtls.cmake new file mode 100644 index 000000000..36d3029f0 --- /dev/null +++ b/third_party/Qorvo/qorvo-mbedtls.cmake @@ -0,0 +1,62 @@ +# +# Copyright (c) 2021, The OpenThread Authors. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holder nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# 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 (DEFINED ENV{QORVO_OT_MBEDTLS_ALT_DIR}) + set(QORVO_MBEDTLS_ALT_DIR "$ENV{QORVO_OT_MBEDTLS_ALT_DIR}") +else() + set(QORVO_MBEDTLS_ALT_DIR "${QORVO_MBEDTLS_SDK_DIR}/../../mbedtls_alt_3.3.0/") +endif() + +message(STATUS "Adding static lib `qorvo-mbedtls` from ${MBEDCRYPTO}") +add_library(qorvo-mbedtls STATIC IMPORTED GLOBAL) + +set(INCLUDE_DIRS "${QORVO_MBEDTLS_SDK_DIR}/include" + "${QORVO_MBEDTLS_SDK_DIR}/include/mbedtls" + "${QORVO_MBEDTLS_SDK_DIR}/include/psa" + "${QORVO_MBEDTLS_ALT_DIR}" + "${QORVO_MBEDTLS_ALT_CONFIG}" +) +set_target_properties(qorvo-mbedtls + PROPERTIES + C_STANDARD 99 + CXX_STANDARD 20 + CXX_STANDARD_REQUIRED ON + CXX_EXTENSIONS OFF + IMPORTED_LOCATION "${MBEDCRYPTO}" + INTERFACE_INCLUDE_DIRECTORIES "${INCLUDE_DIRS}" +) + +# target_include_directories(qorvo-mbedtls +# INTERFACE +# ${QORVO_MBEDTLS_SDK_DIR}/include +# ${QORVO_MBEDTLS_SDK_DIR}/include/mbedtls +# ${QORVO_MBEDTLS_SDK_DIR}/include/psa +# ${QORVO_MBEDTLS_ALT_DIR} +# ${QORVO_MBEDTLS_ALT_CONFIG} +# ) + diff --git a/third_party/Qorvo/repo b/third_party/Qorvo/repo index c30753610..e1d007b12 160000 --- a/third_party/Qorvo/repo +++ b/third_party/Qorvo/repo @@ -1 +1 @@ -Subproject commit c307536106b24df5753d4730c48b93d78bb0689f +Subproject commit e1d007b12fd928030603699d557dd57c724d88e6