Skip to content

Commit

Permalink
Merge branch 'backport/openthread_feature' into 'release/v5.1'
Browse files Browse the repository at this point in the history
Backport some Openthread related MR to 5.1(Backport5.1)

See merge request espressif/esp-idf!24285
  • Loading branch information
chshu committed Jul 12, 2023
2 parents 9fb1b59 + 181ed29 commit 65bf500
Show file tree
Hide file tree
Showing 50 changed files with 716 additions and 358 deletions.
20 changes: 20 additions & 0 deletions components/lwip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,26 @@ menu "LWIP"

endchoice

choice LWIP_HOOK_IP6_SELECT_SRC_ADDR
prompt "IPv6 source address selection Hook"
depends on LWIP_IPV6
default LWIP_HOOK_IP6_SELECT_SRC_ADDR_NONE
help
Enables custom IPv6 source address selection.
Setting this to "default" provides weak implementation
stub that could be overwritten in application code.
Setting this to "custom" provides hook's declaration
only and expects the application to implement it.

config LWIP_HOOK_IP6_SELECT_SRC_ADDR_NONE
bool "No hook declared"
config LWIP_HOOK_IP6_SELECT_SRC_ADDR_DEFAULT
bool "Default (weak) implementation"
config LWIP_HOOK_IP6_SELECT_SRC_ADDR_CUSTOM
bool "Custom implementation"

endchoice

choice LWIP_HOOK_NETCONN_EXTERNAL_RESOLVE
prompt "Netconn external resolve Hook"
default LWIP_HOOK_NETCONN_EXT_RESOLVE_DEFAULT if OPENTHREAD_DNS64_CLIENT
Expand Down
2 changes: 1 addition & 1 deletion components/lwip/lwip
12 changes: 11 additions & 1 deletion components/lwip/port/hooks/lwip_default_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,17 @@ const ip6_addr_t *__weak lwip_hook_nd6_get_gw(struct netif *netif, const ip6_add
LWIP_UNUSED_ARG(netif);
LWIP_UNUSED_ARG(dest);

return 0;
return NULL;
}
#endif

#ifdef CONFIG_LWIP_HOOK_IP6_SELECT_SRC_ADDR_DEFAULT
const ip_addr_t *__weak lwip_hook_ip6_select_source_address(struct netif *netif, const ip6_addr_t *dest)
{
LWIP_UNUSED_ARG(netif);
LWIP_UNUSED_ARG(dest);

return NULL;
}
#endif

Expand Down
6 changes: 6 additions & 0 deletions components/lwip/port/include/lwip_default_hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ const ip6_addr_t *lwip_hook_nd6_get_gw(struct netif *netif, const ip6_addr_t *de
#define LWIP_HOOK_ND6_GET_GW lwip_hook_nd6_get_gw
#endif /* CONFIG_LWIP_HOOK_ND6_GET_GATEWAY... */

#if defined(CONFIG_LWIP_HOOK_IP6_SELECT_SRC_ADDR_CUSTOM) || defined(CONFIG_LWIP_HOOK_IP6_SELECT_SRC_ADDR_DEFAULT)
const ip_addr_t *lwip_hook_ip6_select_source_address(struct netif *netif, const ip6_addr_t *dest);

#define LWIP_HOOK_IP6_SELECT_SRC_ADDR lwip_hook_ip6_select_source_address
#endif /* CONFIG_LWIP_HOOK_IP6_SELECT_SRC_ADDR... */

#if defined(CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_CUSTOM) || defined(CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_DEFAULT)
int lwip_hook_netconn_external_resolve(const char *name, ip_addr_t *addr, u8_t addrtype, err_t *err);

Expand Down
16 changes: 9 additions & 7 deletions components/openthread/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ if(CONFIG_OPENTHREAD_ENABLED)
"private_include")

set(src_dirs
"port"
"src"
"src/port"
"openthread/examples/platforms/utils"
"openthread/src/core/api"
"openthread/src/core/common"
Expand Down Expand Up @@ -57,6 +58,7 @@ if(CONFIG_OPENTHREAD_ENABLED)
"openthread/examples/apps/ncp")

list(APPEND exclude_srcs
"src/port/esp_openthread_state.c"
"openthread/examples/apps/ncp/main.c"
"openthread/src/core/api/backbone_router_api.cpp"
"openthread/src/core/api/child_supervision_api.cpp"
Expand Down Expand Up @@ -113,13 +115,13 @@ if(CONFIG_OPENTHREAD_ENABLED)

if(CONFIG_OPENTHREAD_RADIO_NATIVE)
list(APPEND exclude_srcs
"port/esp_openthread_radio_spinel.cpp"
"port/esp_spi_spinel_interface.cpp"
"port/esp_uart_spinel_interface.cpp"
"src/port/esp_openthread_radio_spinel.cpp"
"src/port/esp_spi_spinel_interface.cpp"
"src/port/esp_uart_spinel_interface.cpp"
)
elseif(CONFIG_OPENTHREAD_RADIO_SPINEL_UART OR CONFIG_OPENTHREAD_RADIO_SPINEL_SPI)
list(APPEND exclude_srcs
"port/esp_openthread_radio.c")
"src/port/esp_openthread_radio.c")
endif()

if(CONFIG_OPENTHREAD_BORDER_ROUTER)
Expand All @@ -135,7 +137,7 @@ if(CONFIG_OPENTHREAD_ENABLED)

if(NOT CONFIG_OPENTHREAD_DNS64_CLIENT)
list(APPEND exclude_srcs
"port/esp_openthread_dns64.c")
"src/esp_openthread_dns64.c")
endif()

if(CONFIG_OPENTHREAD_FTD)
Expand Down Expand Up @@ -173,7 +175,7 @@ idf_component_register(SRC_DIRS "${src_dirs}"
REQUIRES esp_netif lwip driver
LDFRAGMENTS linker.lf
PRIV_REQUIRES console esp_event esp_partition esp_timer
ieee802154 mbedtls spi_flash)
ieee802154 mbedtls nvs_flash)

if(CONFIG_OPENTHREAD_ENABLED)
if(CONFIG_OPENTHREAD_RADIO)
Expand Down
34 changes: 34 additions & 0 deletions components/openthread/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,40 @@ menu "OpenThread"
bool "Debug logs"
endchoice #OPENTHREAD_LOG_LEVEL

menu "Thread Operational Dataset"
config OPENTHREAD_NETWORK_NAME
string "OpenThread network name"
default "OpenThread-ESP"

config OPENTHREAD_NETWORK_CHANNEL
int "OpenThread network channel"
range 11 26
default 15

config OPENTHREAD_NETWORK_PANID
hex "OpenThread network pan id"
range 0 0xFFFE
default 0x1234

config OPENTHREAD_NETWORK_EXTPANID
string "OpenThread extended pan id"
default "dead00beef00cafe"
help
The OpenThread network extended pan id in hex string format

config OPENTHREAD_NETWORK_MASTERKEY
string "OpenThread network key"
default "00112233445566778899aabbccddeeff"
help
The OpenThread network network key in hex string format

config OPENTHREAD_NETWORK_PSKC
string "OpenThread pre-shared commissioner key"
default "104810e2315100afd6bc9215a6bfac53"
help
The OpenThread pre-shared commissioner key in hex string format
endmenu

config OPENTHREAD_LOG_LEVEL
int
depends on OPENTHREAD_ENABLED && !OPENTHREAD_LOG_LEVEL_DYNAMIC
Expand Down
16 changes: 15 additions & 1 deletion components/openthread/include/esp_openthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "esp_err.h"
#include "esp_openthread_types.h"
#include "openthread/dataset.h"
#include "openthread/error.h"
#include "openthread/instance.h"
#include "lwip/ip_addr.h"
Expand All @@ -32,10 +33,23 @@ extern "C" {
*/
esp_err_t esp_openthread_init(const esp_openthread_platform_config_t *init_config);

/**
* @brief Starts the Thread protocol operation and attaches to a Thread network.
*
* @param[in] datasetTlvs The operational dataset (TLV encoded), if it's NULL, the function will generate the dataset
* based on the configurations from kconfig.
*
* @return
* - ESP_OK on success
* - ESP_FAIL on failures
*
*/
esp_err_t esp_openthread_auto_start(otOperationalDatasetTlvs *datasetTlvs);

/**
* @brief Launches the OpenThread main loop.
*
* @note Thie function will not return unless error happens when running the OpenThread stack.
* @note This function will not return unless error happens when running the OpenThread stack.
*
* @return
* - ESP_OK on success
Expand Down
2 changes: 2 additions & 0 deletions components/openthread/include/esp_openthread_dns64.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#ifdef __cplusplus
extern "C" {
#endif
// The network data change callback sets the dns server address of index 0, while the CLI sets the dns server address of index 1.
#define OPENTHREAD_DNS_SERVER_INDEX 0

/**
* @brief This function initiizes the dns64 client.
Expand Down
14 changes: 14 additions & 0 deletions components/openthread/include/esp_openthread_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
#include "driver/gpio.h"
#include "driver/spi_master.h"
#include "driver/spi_slave.h"
#include "driver/uart.h"
#include "hal/gpio_types.h"
#include "hal/uart_types.h"
#include "openthread/thread.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -28,6 +30,9 @@ extern "C" {
typedef enum {
OPENTHREAD_EVENT_START, /*!< OpenThread stack start */
OPENTHREAD_EVENT_STOP, /*!< OpenThread stack stop */
OPENTHREAD_EVENT_DETACHED, /*!< OpenThread detached */
OPENTHREAD_EVENT_ATTACHED, /*!< OpenThread attached */
OPENTHREAD_EVENT_ROLE_CHANGED, /*!< OpenThread role changed */
OPENTHREAD_EVENT_IF_UP, /*!< OpenThread network interface up */
OPENTHREAD_EVENT_IF_DOWN, /*!< OpenThread network interface down */
OPENTHREAD_EVENT_GOT_IP6, /*!< OpenThread stack added IPv6 address */
Expand All @@ -46,6 +51,15 @@ typedef enum {
*/
ESP_EVENT_DECLARE_BASE(OPENTHREAD_EVENT);

/**
* @brief OpenThread role changed event data
*
*/
typedef struct {
otDeviceRole previous_role; /*!< Previous Thread role */
otDeviceRole current_role; /*!< Current Thread role */
} esp_openthread_role_changed_event_t;

/**
* This structure represents a context for a select() based mainloop.
*
Expand Down
96 changes: 0 additions & 96 deletions components/openthread/port/esp_openthread.cpp

This file was deleted.

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 @@ -14,15 +14,6 @@
extern "C" {
#endif

/**
* @brief The state handler to be called when OpenThread state changes
*
* @param[in] changed_flags The changed Openthread states
* @param[in] ctx A pointer to application-specific context
*
*/
void esp_openthread_netif_glue_state_callback(otChangedFlags changed_flags, void *ctx);

/**
* @brief This function updates the netif fds and timeouts to the main loop.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ void esp_openthread_platform_update(esp_openthread_mainloop_context_t *mainloop)
*/
esp_err_t esp_openthread_platform_process(otInstance *instance, const esp_openthread_mainloop_context_t *mainloop);

/**
* @brief This function set the OpenThread storage name
*
* @param[in] name The OpenThread storage name.
*
*/
void esp_openthread_set_storage_name(const char *name);
#ifdef __cplusplus
} // end of extern "C"
#endif
Loading

0 comments on commit 65bf500

Please sign in to comment.