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