Skip to content

Commit

Permalink
Merge branch 'backport/openthread_related_bacport_to_5_2' into 'relea…
Browse files Browse the repository at this point in the history
…se/v5.2'

Backport some openthread related features (Backport v5.2)

See merge request espressif/esp-idf!32250
  • Loading branch information
chshu committed Jul 31, 2024
2 parents 4426adf + 7d9b334 commit f7dd52f
Show file tree
Hide file tree
Showing 16 changed files with 241 additions and 85 deletions.
6 changes: 4 additions & 2 deletions components/openthread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ execute_process(

string(TIMESTAMP OT_BUILD_TIMESTAMP " %Y-%m-%d %H:%M:%S UTC" UTC)
string(CONCAT OT_FULL_VERSION_STRING
"openthread-esp32/"
"${CONFIG_OPENTHREAD_PACKAGE_NAME}/"
"${IDF_VERSION_FOR_OPENTHREAD_PACKAGE}-${OPENTHREAD_VERSION}\; "
"${CONFIG_IDF_TARGET}\; ${OT_BUILD_TIMESTAMP}")
"${CONFIG_OPENTHREAD_PLATFORM_INFO}\; ${OT_BUILD_TIMESTAMP}")

idf_component_register(SRC_DIRS "${src_dirs}"
EXCLUDE_SRCS "${exclude_srcs}"
Expand All @@ -266,6 +266,8 @@ if(CONFIG_OPENTHREAD_ENABLED OR CONFIG_OPENTHREAD_SPINEL_ONLY)
PUBLIC
"OPENTHREAD_CONFIG_FILE=\"openthread-core-esp32x-${CONFIG_FILE_TYPE}-config.h\""
"${device_type}"
"OPENTHREAD_PROJECT_LIB_CONFIG_FILE=\"openthread-core-esp32x-${CONFIG_FILE_TYPE}-config.h\""
"${device_type}"
PRIVATE
"PACKAGE_VERSION=\"${IDF_VERSION_FOR_OPENTHREAD_PACKAGE}-${OPENTHREAD_VERSION}\""
"OPENTHREAD_BUILD_DATETIME=\"${OT_BUILD_TIMESTAMP}\""
Expand Down
21 changes: 19 additions & 2 deletions components/openthread/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,26 @@ menu "OpenThread"
Select this to enable SPI connection to host.
endchoice

menu "OpenThread version message"
depends on OPENTHREAD_ENABLED

config OPENTHREAD_PACKAGE_NAME
string "OpenThread package name"
default "openthread-esp32"
help
The OpenThread package name.

config OPENTHREAD_PLATFORM_INFO
string "platform information"
default IDF_TARGET
help
The OpenThread platform information.
endmenu

config OPENTHREAD_NCP_VENDOR_HOOK
bool "Enable vendor command for RCP"
depends on OPENTHREAD_RADIO
default n
default y
help
Select this to enable OpenThread NCP vendor commands.

Expand Down Expand Up @@ -259,7 +275,8 @@ menu "OpenThread"
config OPENTHREAD_SPINEL_RX_FRAME_BUFFER_SIZE
int "The size of openthread spinel rx frame buffer"
depends on OPENTHREAD_ENABLED || OPENTHREAD_SPINEL_ONLY
default 2048
default 1024 if OPENTHREAD_MTD || OPENTHREAD_RADIO
default 2048 if OPENTHREAD_FTD || OPENTHREAD_SPINEL_ONLY

config OPENTHREAD_MAC_MAX_CSMA_BACKOFFS_DIRECT
int "Maximum backoffs times before declaring a channel access failure."
Expand Down
2 changes: 1 addition & 1 deletion components/openthread/openthread
Submodule openthread updated 1560 files
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* The platform-specific string to insert into the OpenThread version string.
*
*/
#define OPENTHREAD_CONFIG_PLATFORM_INFO CONFIG_IDF_TARGET
#define OPENTHREAD_CONFIG_PLATFORM_INFO CONFIG_OPENTHREAD_PLATFORM_INFO

/**
* @def OPENTHREAD_CONFIG_PLATFORM_ASSERT_MANAGEMENT
Expand Down Expand Up @@ -317,7 +317,7 @@
* Define to the full name of this package.
*
*/
#define PACKAGE_NAME "openthread-esp32"
#define PACKAGE_NAME CONFIG_OPENTHREAD_PACKAGE_NAME

/**
* @def PACKAGE_STRING
Expand Down Expand Up @@ -355,13 +355,13 @@
#define OPENTHREAD_CONFIG_MAX_STATECHANGE_HANDLERS 3

/**
* @def OPENTHREAD_CONFIG_PLATFORM_RADIO_SPINEL_RX_FRAME_BUFFER_SIZE
* @def OPENTHREAD_LIB_SPINEL_RX_FRAME_BUFFER_SIZE
*
* Specifies the rx frame buffer size used by `SpinelInterface` in RCP host code. This is applicable/used when
* `RadioSpinel` platform is used.
*
*/
#define OPENTHREAD_CONFIG_PLATFORM_RADIO_SPINEL_RX_FRAME_BUFFER_SIZE CONFIG_OPENTHREAD_SPINEL_RX_FRAME_BUFFER_SIZE
#define OPENTHREAD_LIB_SPINEL_RX_FRAME_BUFFER_SIZE CONFIG_OPENTHREAD_SPINEL_RX_FRAME_BUFFER_SIZE

/**
* @def OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* The platform-specific string to insert into the OpenThread version string.
*
*/
#define OPENTHREAD_CONFIG_PLATFORM_INFO CONFIG_IDF_TARGET
#define OPENTHREAD_CONFIG_PLATFORM_INFO CONFIG_OPENTHREAD_PLATFORM_INFO

/**
* @def OPENTHREAD_CONFIG_PLATFORM_ASSERT_MANAGEMENT
Expand Down Expand Up @@ -131,7 +131,7 @@
* Define to the full name of this package.
*
*/
#define PACKAGE_NAME "openthread-esp32"
#define PACKAGE_NAME CONFIG_OPENTHREAD_PACKAGE_NAME

/**
* @def PACKAGE_STRING
Expand Down Expand Up @@ -169,13 +169,13 @@
#define OPENTHREAD_CONFIG_MAX_STATECHANGE_HANDLERS 3

/**
* @def OPENTHREAD_CONFIG_PLATFORM_RADIO_SPINEL_RX_FRAME_BUFFER_SIZE
* @def OPENTHREAD_LIB_SPINEL_RX_FRAME_BUFFER_SIZE
*
* Specifies the rx frame buffer size used by `SpinelInterface` in RCP host code. This is applicable/used when
* `RadioSpinel` platform is used.
*
*/
#define OPENTHREAD_CONFIG_PLATFORM_RADIO_SPINEL_RX_FRAME_BUFFER_SIZE 1024
#define OPENTHREAD_LIB_SPINEL_RX_FRAME_BUFFER_SIZE CONFIG_OPENTHREAD_SPINEL_RX_FRAME_BUFFER_SIZE

/**
* @def OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* The platform-specific string to insert into the OpenThread version string.
*
*/
#define OPENTHREAD_CONFIG_PLATFORM_INFO CONFIG_IDF_TARGET
#define OPENTHREAD_CONFIG_PLATFORM_INFO CONFIG_OPENTHREAD_PLATFORM_INFO

/**
* @def OPENTHREAD_CONFIG_PLATFORM_ASSERT_MANAGEMENT
Expand Down Expand Up @@ -112,7 +112,7 @@
* Define to the full name of this package.
*
*/
#define PACKAGE_NAME "openthread-esp32"
#define PACKAGE_NAME CONFIG_OPENTHREAD_PACKAGE_NAME

/**
* @def PACKAGE_STRING
Expand Down Expand Up @@ -142,13 +142,13 @@
#define OPENTHREAD_CONFIG_MAX_STATECHANGE_HANDLERS 3

/**
* @def OPENTHREAD_CONFIG_PLATFORM_RADIO_SPINEL_RX_FRAME_BUFFER_SIZE
* @def OPENTHREAD_LIB_SPINEL_RX_FRAME_BUFFER_SIZE
*
* Specifies the rx frame buffer size used by `SpinelInterface` in RCP host code. This is applicable/used when
* `RadioSpinel` platform is used.
*
*/
#define OPENTHREAD_CONFIG_PLATFORM_RADIO_SPINEL_RX_FRAME_BUFFER_SIZE 1024
#define OPENTHREAD_LIB_SPINEL_RX_FRAME_BUFFER_SIZE CONFIG_OPENTHREAD_SPINEL_RX_FRAME_BUFFER_SIZE

/**
* @def OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@

#pragma once

#include "sdkconfig.h"
/**
* @def OPENTHREAD_CONFIG_PLATFORM_INFO
*
* The platform-specific string to insert into the OpenThread version string.
*
*/
#define OPENTHREAD_CONFIG_PLATFORM_INFO CONFIG_OPENTHREAD_PLATFORM_INFO

/**
* @def PACKAGE_NAME
*
* Define to the full name of this package.
*
*/
#define PACKAGE_NAME CONFIG_OPENTHREAD_PACKAGE_NAME

/**
* @def OPENTHREAD_SPINEL_CONFIG_OPENTHREAD_MESSAGE_ENABLE
*
Expand All @@ -25,9 +42,11 @@
*/
#ifndef OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT
// TZ-567: Set OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT to 3 after adding rcp failure notification mechanism
#define OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT 0
#define OPENTHREAD_SPINEL_CONFIG_RCP_RESTORATION_MAX_COUNT 3
#endif

#define OPENTHREAD_SPINEL_CONFIG_VENDOR_HOOK_ENABLE 1

/**
* @def OPENTHREAD_SPINEL_CONFIG_RCP_CUSTOM_RESTORATION
*
Expand All @@ -39,13 +58,13 @@
#endif

/**
* @def OPENTHREAD_CONFIG_PLATFORM_RADIO_SPINEL_RX_FRAME_BUFFER_SIZE
* @def OPENTHREAD_LIB_SPINEL_RX_FRAME_BUFFER_SIZE
*
* Specifies the rx frame buffer size used by `SpinelInterface` in RCP host code. This is applicable/used when
* `RadioSpinel` platform is used.
*
*/
#define OPENTHREAD_CONFIG_PLATFORM_RADIO_SPINEL_RX_FRAME_BUFFER_SIZE CONFIG_OPENTHREAD_SPINEL_RX_FRAME_BUFFER_SIZE
#define OPENTHREAD_LIB_SPINEL_RX_FRAME_BUFFER_SIZE CONFIG_OPENTHREAD_SPINEL_RX_FRAME_BUFFER_SIZE

/**
* @def OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT
Expand Down
2 changes: 1 addition & 1 deletion components/openthread/sbom_openthread.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ supplier: 'Organization: Espressif Systems (Shanghai) CO LTD'
originator: 'Organization: Google LLC'
description: OpenThread released by Google is an open-source implementation of the Thread networking
url: https://github.com/espressif/openthread
hash: be7d36e4ff9cf7df6dfce54e58a31163c87b93f7
hash: f32c18bc0840f400182456e58ae3900fc2fb4af7
2 changes: 1 addition & 1 deletion components/openthread/src/esp_openthread_netif_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void *esp_openthread_netif_glue_init(const esp_openthread_platform_config_t *con
otIp6SetAddressCallback(instance, process_thread_address, instance);
otIp6SetReceiveCallback(instance, process_thread_receive, instance);
otIp6SetReceiveFilterEnabled(instance, true);
otIcmp6SetEchoMode(instance, OT_ICMP6_ECHO_HANDLER_DISABLED);
otIcmp6SetEchoMode(instance, OT_ICMP6_ECHO_HANDLER_RLOC_ALOC_ONLY);

s_openthread_netif_glue.event_fd = eventfd(0, 0);
if (s_openthread_netif_glue.event_fd < 0) {
Expand Down
26 changes: 20 additions & 6 deletions components/openthread/src/port/esp_openthread_radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,13 @@ static otRadioFrame s_ack_frame;
static int s_ed_power;
static esp_ieee802154_tx_error_t s_tx_error;
static int s_radio_event_fd = -1;
static bool s_diag_mode = false;
static const char *s_radio_workflow = "radio";
static uint8_t s_txrx_events;

#if CONFIG_OPENTHREAD_DIAG
static bool s_diag_mode = false;
#endif

#if OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
static otRadioIeInfo s_transmit_ie_info;
#endif // OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
Expand Down Expand Up @@ -113,7 +116,7 @@ static inline bool get_event(uint8_t event)
esp_err_t esp_openthread_radio_init(const esp_openthread_platform_config_t *config)
{
ESP_RETURN_ON_FALSE(s_radio_event_fd == -1, ESP_ERR_INVALID_STATE, OT_PLAT_LOG_TAG,
"Radio was initalized already!");
"Radio was initialized already!");

s_radio_event_fd = eventfd(0, EFD_SUPPORT_ISR);

Expand Down Expand Up @@ -165,7 +168,7 @@ esp_err_t esp_openthread_radio_process(otInstance *aInstance, const esp_openthre

if (get_event(EVENT_TX_DONE)) {
clr_event(EVENT_TX_DONE);
#if OPENTHREAD_CONFIG_DIAG_ENABLE
#if CONFIG_OPENTHREAD_DIAG
if (otPlatDiagModeGet()) {
otPlatDiagRadioTransmitDone(aInstance, &s_transmit_frame, OT_ERROR_NONE);
} else
Expand All @@ -183,7 +186,7 @@ esp_err_t esp_openthread_radio_process(otInstance *aInstance, const esp_openthre

if (get_event(EVENT_TX_FAILED)) {
clr_event(EVENT_TX_FAILED);
#if OPENTHREAD_CONFIG_DIAG_ENABLE
#if CONFIG_OPENTHREAD_DIAG
if (otPlatDiagModeGet()) {
otPlatDiagRadioTransmitDone(aInstance, &s_transmit_frame, OT_ERROR_CHANNEL_ACCESS_FAILURE);
} else
Expand Down Expand Up @@ -219,7 +222,7 @@ esp_err_t esp_openthread_radio_process(otInstance *aInstance, const esp_openthre

while (atomic_load(&s_recv_queue.used)) {
if (s_receive_frame[s_recv_queue.head].mPsdu != NULL) {
#if OPENTHREAD_CONFIG_DIAG_ENABLE
#if CONFIG_OPENTHREAD_DIAG
if (otPlatDiagModeGet()) {
otPlatDiagRadioReceiveDone(aInstance, &s_receive_frame[s_recv_queue.head], OT_ERROR_NONE);
} else
Expand Down Expand Up @@ -302,7 +305,7 @@ otError otPlatRadioTransmit(otInstance *aInstance, otRadioFrame *aFrame)
{
esp_ieee802154_set_channel(aFrame->mChannel);

aFrame->mPsdu[-1] = aFrame->mLength; // lenth locates one byte before the psdu (esp_openthread_radio_tx_psdu);
aFrame->mPsdu[-1] = aFrame->mLength; // length locates one byte before the psdu (esp_openthread_radio_tx_psdu);

if (otMacFrameIsSecurityEnabled(aFrame) && !aFrame->mInfo.mTxInfo.mIsSecurityProcessed) {
if (!s_transmit_frame.mInfo.mTxInfo.mIsARetx) {
Expand Down Expand Up @@ -447,6 +450,15 @@ int8_t otPlatRadioGetReceiveSensitivity(otInstance *aInstance)
return ESP_RECEIVE_SENSITIVITY;
}

#if CONFIG_OPENTHREAD_DIAG

void otPlatDiagSetOutputCallback(otInstance *aInstance, otPlatDiagOutputCallback aCallback, void *aContext)
{
OT_UNUSED_VARIABLE(aInstance);
OT_UNUSED_VARIABLE(aCallback);
OT_UNUSED_VARIABLE(aContext);
}

void otPlatDiagModeSet(bool mode)
{
s_diag_mode = mode;
Expand Down Expand Up @@ -479,6 +491,8 @@ void otPlatDiagAlarmCallback(otInstance *aInstance)
OT_UNUSED_VARIABLE(aInstance);
}

#endif // CONFIG_OPENTHREAD_DIAG

#if OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2
void otPlatRadioSetMacKey(otInstance *aInstance, uint8_t aKeyIdMode, uint8_t aKeyId, const otMacKeyMaterial *aPrevKey,
const otMacKeyMaterial *aCurrKey, const otMacKeyMaterial *aNextKey, otRadioKeyType aKeyType)
Expand Down
Loading

0 comments on commit f7dd52f

Please sign in to comment.