Skip to content

Commit

Permalink
Merge branch 'backport/fix_br_issues_of_cert' into 'release/v5.1'
Browse files Browse the repository at this point in the history
OpenThread: fix issues found in certification(backport v5.1)

See merge request espressif/esp-idf!24079
  • Loading branch information
chshu committed Jul 14, 2023
2 parents fabe338 + e6ddff6 commit 1296991
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 42 deletions.
2 changes: 2 additions & 0 deletions components/openthread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ if(CONFIG_OPENTHREAD_ENABLED)
"openthread/src/core/api/message_api.cpp"
"openthread/src/core/api/nat64_api.cpp"
"openthread/src/core/api/netdata_api.cpp"
"openthread/src/core/api/netdiag_api.cpp"
"openthread/src/core/api/random_crypto_api.cpp"
"openthread/src/core/api/tcp_api.cpp"
"openthread/src/core/api/udp_api.cpp"
Expand Down Expand Up @@ -106,6 +107,7 @@ if(CONFIG_OPENTHREAD_ENABLED)
"openthread/src/core/thread/network_data_leader_ftd.cpp"
"openthread/src/core/thread/network_data_types.cpp"
"openthread/src/core/thread/network_data_service.cpp"
"openthread/src/core/thread/network_diagnostic.cpp"
"openthread/src/core/thread/panid_query_server.cpp"
"openthread/src/core/thread/thread_netif.cpp"
"openthread/src/core/thread/tmf.cpp"
Expand Down
7 changes: 7 additions & 0 deletions components/openthread/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,11 @@ menu "OpenThread"
default n
help
Select this option to set rx on when sleep in CSL feature, only for debug

config OPENTHREAD_DUA_ENABLE
bool "Enable Domain Unicast Address feature"
depends on OPENTHREAD_ENABLED
default n
help
Only used for Thread1.2 certification
endmenu
2 changes: 1 addition & 1 deletion components/openthread/openthread
Submodule openthread updated 932 files
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ class SpiSpinelInterface {
* @param[in] mainloop The mainloop context
*
*/
void Process(const esp_openthread_mainloop_context_t &mainloop);
void Process(const void *mainloop);

/**
* This methods updates the mainloop context.
*
* @param[inout] mainloop The mainloop context.
*
*/
void Update(esp_openthread_mainloop_context_t &mainloop);
void Update(void *mainloop);

/**
* This methods registers the callback for RCP failure.
Expand All @@ -114,7 +114,7 @@ class SpiSpinelInterface {
* This method is called when RCP failure detected and resets internal states of the interface.
*
*/
void OnRcpReset(void);
otError HardwareReset(void);

private:
static constexpr uint8_t kSPIFrameHeaderSize = 5;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -11,6 +11,7 @@
#include "esp_openthread_types.h"
#include "hal/uart_types.h"
#include "lib/spinel/spinel_interface.hpp"
#include "lib/hdlc/hdlc.hpp"
#include "openthread/error.h"

namespace esp {
Expand Down Expand Up @@ -90,15 +91,15 @@ class UartSpinelInterface {
* @param[in] mainloop The mainloop context
*
*/
void Process(const esp_openthread_mainloop_context_t &mainloop);
void Process(const void *mainloop);

/**
* This methods updates the mainloop context.
*
* @param[inout] mainloop The mainloop context.
*
*/
void Update(esp_openthread_mainloop_context_t &mainloop);
void Update(void *mainloop);

/**
* This methods registers the callback for RCP failure.
Expand All @@ -108,8 +109,17 @@ class UartSpinelInterface {
*/
void RegisterRcpFailureHandler(esp_openthread_rcp_failure_handler handler) { mRcpFailureHandler = handler; }

void OnRcpReset(void);
/**
* This method is called when RCP failure detected and resets internal states of the interface.
*
*/
otError HardwareReset(void);

/**
* This method is called when RCP is reset to recreate the connection with it.
* Intentionally empty.
*
*/
otError ResetConnection(void) { return OT_ERROR_NONE; }

private:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -371,15 +371,17 @@
*/
#define OPENTHREAD_CONFIG_PING_SENDER_ENABLE 1

#if CONFIG_OPENTHREAD_DUA_ENABLE
/**
* @def OPENTHREAD_CONFIG_DUA_ENABLE
*
* Define as 1 to support Thread 1.2 Domain Unicast Address feature.
*
*/
#ifndef OPENTHREAD_CONFIG_DUA_ENABLE
#define OPENTHREAD_CONFIG_DUA_ENABLE 0
#define OPENTHREAD_CONFIG_DUA_ENABLE 1
#endif
#endif //CONFIG_OPENTHREAD_DUA_ENABLE

/**
* @def OPENTHREAD_CONFIG_MLR_ENABLE
Expand Down Expand Up @@ -495,4 +497,14 @@
#endif
#endif //CONFIG_OPENTHREAD_LINK_METRICS

/**
* @def OPENTHREAD_CONFIG_OPERATIONAL_DATASET_AUTO_INIT
*
* Define as 1 to enable support for locally initializing an Active Operational Dataset.
*
*/
#ifndef OPENTHREAD_CONFIG_OPERATIONAL_DATASET_AUTO_INIT
#define OPENTHREAD_CONFIG_OPERATIONAL_DATASET_AUTO_INIT 1
#endif

#define OPENTHREAD_FTD 1
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@

#define OPENTHREAD_RADIO 1

#if CONFIG_OPENTHREAD_LINK_METRICS
/**
* @def OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
*
Expand All @@ -216,3 +217,4 @@
#ifndef OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
#define OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE 1
#endif
#endif //CONFIG_OPENTHREAD_LINK_METRICS
10 changes: 5 additions & 5 deletions components/openthread/src/port/esp_openthread_radio_spinel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ using ot::Spinel::RadioSpinel;

#if CONFIG_OPENTHREAD_RADIO_SPINEL_UART
using esp::openthread::UartSpinelInterface;
static RadioSpinel<UartSpinelInterface, esp_openthread_mainloop_context_t> s_radio;
static RadioSpinel<UartSpinelInterface> s_radio;
#else // CONFIG_OPENTHREAD_RADIO_SPINEL_SPI
using esp::openthread::SpiSpinelInterface;
static RadioSpinel<SpiSpinelInterface, esp_openthread_mainloop_context_t> s_radio;
static RadioSpinel<SpiSpinelInterface> s_radio;
#endif // CONFIG_OPENTHREAD_RADIO_SPINEL_UART

static const char *radiospinel_workflow = "radio_spinel";
Expand All @@ -42,7 +42,7 @@ esp_err_t esp_openthread_radio_init(const esp_openthread_platform_config_t *conf
ESP_RETURN_ON_ERROR(s_radio.GetSpinelInterface().Init(config->radio_config.radio_spi_config), OT_PLAT_LOG_TAG,
"Spinel interface init failed");
#endif // CONFIG_OPENTHREAD_RADIO_SPINEL_UART
s_radio.Init(/*reset_radio=*/true, /*restore_dataset_from_ncp=*/false, /*skip_rcp_compatibility_check=*/false);
s_radio.Init(/*reset_radio=*/true, /*skip_rcp_compatibility_check=*/false);
return esp_openthread_platform_workflow_register(&esp_openthread_radio_update, &esp_openthread_radio_process,
radiospinel_workflow);
}
Expand All @@ -65,14 +65,14 @@ void esp_openthread_radio_deinit(void)

esp_err_t esp_openthread_radio_process(otInstance *instance, const esp_openthread_mainloop_context_t *mainloop)
{
s_radio.Process(*mainloop);
s_radio.Process((void *)mainloop);

return ESP_OK;
}

void esp_openthread_radio_update(esp_openthread_mainloop_context_t *mainloop)
{
s_radio.GetSpinelInterface().Update(*mainloop);
s_radio.GetSpinelInterface().Update((void *)mainloop);
}

void otPlatRadioGetIeeeEui64(otInstance *instance, uint8_t *ieee_eui64)
Expand Down
3 changes: 3 additions & 0 deletions components/openthread/src/port/esp_openthread_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ otError otPlatUdpConnect(otUdpSocket *udp_socket)
};

task.addr = map_openthread_addr_to_lwip_addr(&udp_socket->mPeerName.mAddress);
if (ip_addr_isany_val(task.addr) && task.port == 0) {
return OT_ERROR_NONE;
}
tcpip_callback(udp_connect_task, &task);
wait_for_task_notification();

Expand Down
27 changes: 14 additions & 13 deletions components/openthread/src/port/esp_spi_spinel_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "hal/gpio_types.h"
#include "ncp/ncp_spi.hpp"

using ot::Ncp::SpiFrame;
using ot::Spinel::SpiFrame;
using ot::Spinel::SpinelInterface;

namespace esp {
Expand Down Expand Up @@ -180,26 +180,26 @@ void SpiSpinelInterface::GpioIntrHandler(void *arg)
write(instance->m_event_fd, &event, sizeof(event));
}

void SpiSpinelInterface::Update(esp_openthread_mainloop_context_t &mainloop)
void SpiSpinelInterface::Update(void *mainloop)
{
if (m_pending_data_len > 0) {
mainloop.timeout.tv_sec = 0;
mainloop.timeout.tv_usec = 0;
((esp_openthread_mainloop_context_t *)mainloop)->timeout.tv_sec = 0;
((esp_openthread_mainloop_context_t *)mainloop)->timeout.tv_usec = 0;
}
FD_SET(m_event_fd, &mainloop.read_fds);
FD_SET(m_event_fd, &mainloop.error_fds);
if (m_event_fd > mainloop.max_fd) {
mainloop.max_fd = m_event_fd;
FD_SET(m_event_fd, &((esp_openthread_mainloop_context_t *)mainloop)->read_fds);
FD_SET(m_event_fd, &((esp_openthread_mainloop_context_t *)mainloop)->error_fds);
if (m_event_fd > ((esp_openthread_mainloop_context_t *)mainloop)->max_fd) {
((esp_openthread_mainloop_context_t *)mainloop)->max_fd = m_event_fd;
}
}

void SpiSpinelInterface::Process(const esp_openthread_mainloop_context_t &mainloop)
void SpiSpinelInterface::Process(const void *mainloop)
{
if (FD_ISSET(m_event_fd, &mainloop.error_fds)) {
if (FD_ISSET(m_event_fd, &((esp_openthread_mainloop_context_t *)mainloop)->error_fds)) {
ESP_LOGE(OT_PLAT_LOG_TAG, "SPI INTR GPIO error event");
return;
}
if (FD_ISSET(m_event_fd, &mainloop.read_fds)) {
if (FD_ISSET(m_event_fd, &((esp_openthread_mainloop_context_t *)mainloop)->read_fds)) {
uint64_t event;
read(m_event_fd, &event, sizeof(event));
m_pending_data_len = SpinelInterface::kMaxFrameSize;
Expand Down Expand Up @@ -240,13 +240,14 @@ otError SpiSpinelInterface::WaitForFrame(uint64_t timeout_us)
return OT_ERROR_NONE;
}

void SpiSpinelInterface::OnRcpReset(void)
otError SpiSpinelInterface::HardwareReset(void)
{
if (mRcpFailureHandler) {
mRcpFailureHandler();
ConductSPITransaction(true, 0, 0); // clear
}
return OT_ERROR_NONE;
}

} // namespace openthread
} // namespace esp
}
19 changes: 10 additions & 9 deletions components/openthread/src/port/esp_uart_spinel_interface.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -69,7 +69,7 @@ esp_err_t UartSpinelInterface::Deinit(void)
otError UartSpinelInterface::SendFrame(const uint8_t *frame, uint16_t length)
{
otError error = OT_ERROR_NONE;
ot::Hdlc::FrameBuffer<kMaxFrameSize> encoder_buffer;
ot::Spinel::FrameBuffer<kMaxFrameSize> encoder_buffer;
ot::Hdlc::Encoder hdlc_encoder(encoder_buffer);

SuccessOrExit(error = hdlc_encoder.BeginFrame());
Expand All @@ -88,21 +88,21 @@ otError UartSpinelInterface::SendFrame(const uint8_t *frame, uint16_t length)
return error;
}

void UartSpinelInterface::Process(const esp_openthread_mainloop_context_t &mainloop)
void UartSpinelInterface::Process(const void *mainloop)
{
if (FD_ISSET(m_uart_fd, &mainloop.read_fds)) {
if (FD_ISSET(m_uart_fd, &((esp_openthread_mainloop_context_t *)mainloop)->read_fds)) {
ESP_LOGD(OT_PLAT_LOG_TAG, "radio uart read event");
TryReadAndDecode();
}
}

void UartSpinelInterface::Update(esp_openthread_mainloop_context_t &mainloop)
void UartSpinelInterface::Update(void *mainloop)
{
// Register only READ events for radio UART and always wait
// for a radio WRITE to complete.
FD_SET(m_uart_fd, &mainloop.read_fds);
if (m_uart_fd > mainloop.max_fd) {
mainloop.max_fd = m_uart_fd;
FD_SET(m_uart_fd, &((esp_openthread_mainloop_context_t *)mainloop)->read_fds);
if (m_uart_fd > ((esp_openthread_mainloop_context_t *)mainloop)->max_fd) {
((esp_openthread_mainloop_context_t *)mainloop)->max_fd = m_uart_fd;
}
}

Expand Down Expand Up @@ -285,12 +285,13 @@ esp_err_t UartSpinelInterface::TryRecoverUart(void)
return ESP_OK;
}

void UartSpinelInterface::OnRcpReset(void)
otError UartSpinelInterface::HardwareReset(void)
{
if (mRcpFailureHandler) {
mRcpFailureHandler();
TryRecoverUart();
}
return OT_ERROR_NONE;
}

} // namespace openthread
Expand Down
4 changes: 0 additions & 4 deletions examples/openthread/pytest_otbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,6 @@ def test_service_discovery_of_WiFi_device(Init_interface:bool, Init_avahi:bool,
ocf.execute_command(cli, command)
cli.expect('Done', timeout=5)
ocf.wait(cli, 1)
command = 'dns resolve FA000123.default.service.arpa.'
ocf.clean_buffer(cli)
ocf.execute_command(cli, command)
cli.expect('Error', timeout=15)
domain_name = ocf.get_domain()
print('domain name is: ', domain_name)
command = 'dns resolve ' + domain_name + '.default.service.arpa.'
Expand Down

0 comments on commit 1296991

Please sign in to comment.