Skip to content

Commit

Permalink
feat(platform): add child handling callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
thcu-gp committed May 16, 2024
1 parent 39b7c15 commit 5949caa
Show file tree
Hide file tree
Showing 21 changed files with 913 additions and 75 deletions.
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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")

Expand Down
21 changes: 21 additions & 0 deletions etc/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 2 additions & 4 deletions src/gp712/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions src/gp712/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,45 @@ otError otPlatRadioGetRegion(otInstance *aInstance, uint16_t *aRegionCode)

return OT_ERROR_NOT_IMPLEMENTED;
}

#if QORVO_FTD
#include <openthread/thread_ftd.h>

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
31 changes: 31 additions & 0 deletions src/gp712/radio_qorvo.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <stdint.h>

#include <openthread/error.h>
#include <openthread/thread_ftd.h>
#include <openthread/platform/radio.h>

/**
Expand Down Expand Up @@ -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.
*
Expand Down
11 changes: 6 additions & 5 deletions src/qpg6105/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,6 +47,7 @@ set(PLATFORM_SOURCES
platform.c
radio.c
settings.c
syscalls_stubs.c
uart.c
)

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
106 changes: 71 additions & 35 deletions src/qpg6105/crypto/common-mbedtls-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
#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
Expand All @@ -48,58 +42,66 @@
#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
#define MBEDTLS_X509_USE_C
#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. */
Expand All @@ -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
Loading

0 comments on commit 5949caa

Please sign in to comment.