From 77c60765ca63843ca64207ed4f598cb3aa445274 Mon Sep 17 00:00:00 2001 From: Xu Si Yu Date: Wed, 24 May 2023 17:38:41 +0800 Subject: [PATCH 1/5] openthread rcp: set link metrics feature optional --- .../private_include/openthread-core-esp32x-radio-config.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/openthread/private_include/openthread-core-esp32x-radio-config.h b/components/openthread/private_include/openthread-core-esp32x-radio-config.h index 8bb97355de..6a292f2d6e 100644 --- a/components/openthread/private_include/openthread-core-esp32x-radio-config.h +++ b/components/openthread/private_include/openthread-core-esp32x-radio-config.h @@ -207,6 +207,7 @@ #define OPENTHREAD_RADIO 1 +#if CONFIG_OPENTHREAD_LINK_METRICS /** * @def OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE * @@ -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 From dd0afffde3683c2e321e140c512a429771df01e0 Mon Sep 17 00:00:00 2001 From: Xu Si Yu Date: Wed, 24 May 2023 18:01:17 +0800 Subject: [PATCH 2/5] openthread cli: set dua feature optional --- components/openthread/Kconfig | 7 +++++++ .../private_include/openthread-core-esp32x-ftd-config.h | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/components/openthread/Kconfig b/components/openthread/Kconfig index ff4ca35bb5..219bd8b697 100644 --- a/components/openthread/Kconfig +++ b/components/openthread/Kconfig @@ -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 diff --git a/components/openthread/private_include/openthread-core-esp32x-ftd-config.h b/components/openthread/private_include/openthread-core-esp32x-ftd-config.h index f3ad6f268f..cc75cd9432 100644 --- a/components/openthread/private_include/openthread-core-esp32x-ftd-config.h +++ b/components/openthread/private_include/openthread-core-esp32x-ftd-config.h @@ -371,6 +371,7 @@ */ #define OPENTHREAD_CONFIG_PING_SENDER_ENABLE 1 +#if CONFIG_OPENTHREAD_DUA_ENABLE /** * @def OPENTHREAD_CONFIG_DUA_ENABLE * @@ -378,8 +379,9 @@ * */ #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 From cb29bfa6b40e3be3789473c92c5da53aaf7a0508 Mon Sep 17 00:00:00 2001 From: Xu Si Yu Date: Fri, 26 May 2023 19:20:27 +0800 Subject: [PATCH 3/5] openthread: forbid otPlatUdp to connect to address 0.0.0.0 and port 0 --- components/openthread/src/port/esp_openthread_udp.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/components/openthread/src/port/esp_openthread_udp.c b/components/openthread/src/port/esp_openthread_udp.c index 17f8256a38..08c8e12e6c 100644 --- a/components/openthread/src/port/esp_openthread_udp.c +++ b/components/openthread/src/port/esp_openthread_udp.c @@ -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(); From 6585c521b3584c3322893b415e7c3cf493be7f3b Mon Sep 17 00:00:00 2001 From: zhangwenxu Date: Tue, 11 Jul 2023 20:06:05 +0800 Subject: [PATCH 4/5] feat(openthread): openthread upstream update --- components/openthread/CMakeLists.txt | 2 ++ components/openthread/lib | 2 +- components/openthread/openthread | 2 +- .../esp_spi_spinel_interface.hpp | 6 ++--- .../esp_uart_spinel_interface.hpp | 18 ++++++++++--- .../openthread-core-esp32x-ftd-config.h | 12 ++++++++- .../src/port/esp_openthread_radio_spinel.cpp | 10 +++---- .../src/port/esp_spi_spinel_interface.cpp | 27 ++++++++++--------- .../src/port/esp_uart_spinel_interface.cpp | 19 ++++++------- 9 files changed, 61 insertions(+), 37 deletions(-) diff --git a/components/openthread/CMakeLists.txt b/components/openthread/CMakeLists.txt index 782e2f5dab..cbe7369ac4 100644 --- a/components/openthread/CMakeLists.txt +++ b/components/openthread/CMakeLists.txt @@ -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" @@ -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" diff --git a/components/openthread/lib b/components/openthread/lib index 36cb2202e1..785e946222 160000 --- a/components/openthread/lib +++ b/components/openthread/lib @@ -1 +1 @@ -Subproject commit 36cb2202e10b5ba7484654962ca9e3ceb51f6d51 +Subproject commit 785e946222f6c6ab453d7d47c15c551d4a181f79 diff --git a/components/openthread/openthread b/components/openthread/openthread index 091f68ed70..5beae14370 160000 --- a/components/openthread/openthread +++ b/components/openthread/openthread @@ -1 +1 @@ -Subproject commit 091f68ed706ce7a4831802408cdd0b0b4f309e3b +Subproject commit 5beae143700db54c6e9bd4b15a568abe2f305723 diff --git a/components/openthread/private_include/esp_spi_spinel_interface.hpp b/components/openthread/private_include/esp_spi_spinel_interface.hpp index 3cbb34f0de..6b8ae2833e 100644 --- a/components/openthread/private_include/esp_spi_spinel_interface.hpp +++ b/components/openthread/private_include/esp_spi_spinel_interface.hpp @@ -85,7 +85,7 @@ public: * @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. @@ -93,7 +93,7 @@ public: * @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. @@ -114,7 +114,7 @@ public: * 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; diff --git a/components/openthread/private_include/esp_uart_spinel_interface.hpp b/components/openthread/private_include/esp_uart_spinel_interface.hpp index c5087b2c7b..d21c16a23b 100644 --- a/components/openthread/private_include/esp_uart_spinel_interface.hpp +++ b/components/openthread/private_include/esp_uart_spinel_interface.hpp @@ -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 */ @@ -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 { @@ -90,7 +91,7 @@ public: * @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. @@ -98,7 +99,7 @@ public: * @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. @@ -108,8 +109,17 @@ public: */ 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: diff --git a/components/openthread/private_include/openthread-core-esp32x-ftd-config.h b/components/openthread/private_include/openthread-core-esp32x-ftd-config.h index cc75cd9432..30dbe362ae 100644 --- a/components/openthread/private_include/openthread-core-esp32x-ftd-config.h +++ b/components/openthread/private_include/openthread-core-esp32x-ftd-config.h @@ -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 */ @@ -497,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 diff --git a/components/openthread/src/port/esp_openthread_radio_spinel.cpp b/components/openthread/src/port/esp_openthread_radio_spinel.cpp index 1ea69d5867..2e0cab92f7 100644 --- a/components/openthread/src/port/esp_openthread_radio_spinel.cpp +++ b/components/openthread/src/port/esp_openthread_radio_spinel.cpp @@ -25,10 +25,10 @@ using ot::Spinel::RadioSpinel; #if CONFIG_OPENTHREAD_RADIO_SPINEL_UART using esp::openthread::UartSpinelInterface; -static RadioSpinel s_radio; +static RadioSpinel s_radio; #else // CONFIG_OPENTHREAD_RADIO_SPINEL_SPI using esp::openthread::SpiSpinelInterface; -static RadioSpinel s_radio; +static RadioSpinel s_radio; #endif // CONFIG_OPENTHREAD_RADIO_SPINEL_UART static const char *radiospinel_workflow = "radio_spinel"; @@ -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); } @@ -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) diff --git a/components/openthread/src/port/esp_spi_spinel_interface.cpp b/components/openthread/src/port/esp_spi_spinel_interface.cpp index afcf36f6c3..adaa09ecc0 100644 --- a/components/openthread/src/port/esp_spi_spinel_interface.cpp +++ b/components/openthread/src/port/esp_spi_spinel_interface.cpp @@ -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 { @@ -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; @@ -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 -} diff --git a/components/openthread/src/port/esp_uart_spinel_interface.cpp b/components/openthread/src/port/esp_uart_spinel_interface.cpp index 061bc8044b..6389d8f8da 100644 --- a/components/openthread/src/port/esp_uart_spinel_interface.cpp +++ b/components/openthread/src/port/esp_uart_spinel_interface.cpp @@ -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 */ @@ -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 encoder_buffer; + ot::Spinel::FrameBuffer encoder_buffer; ot::Hdlc::Encoder hdlc_encoder(encoder_buffer); SuccessOrExit(error = hdlc_encoder.BeginFrame()); @@ -88,21 +88,21 @@ exit: 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; } } @@ -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 From e6ddff69dae6ebaa172e56c977a80bdb0d2bebba Mon Sep 17 00:00:00 2001 From: Xu Si Yu Date: Fri, 14 Jul 2023 03:22:41 +0800 Subject: [PATCH 5/5] fix(ci): remove the check of a inexistent host --- examples/openthread/pytest_otbr.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/openthread/pytest_otbr.py b/examples/openthread/pytest_otbr.py index 7af4661aac..06bb1bdcc0 100644 --- a/examples/openthread/pytest_otbr.py +++ b/examples/openthread/pytest_otbr.py @@ -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.'