diff --git a/components/esp_phy/src/phy_common.c b/components/esp_phy/src/phy_common.c
index b71b3aa0e8..c4824841c7 100644
--- a/components/esp_phy/src/phy_common.c
+++ b/components/esp_phy/src/phy_common.c
@@ -15,7 +15,7 @@ static volatile int64_t s_previous_timestamp;
static void phy_track_pll_timer_callback(void* arg)
{
-#if IEEE802154_ENABLED || BT_ENABLED
+#if CONFIG_IEEE802154_ENABLED || CONFIG_BT_ENABLED
bt_track_pll_cap();
#endif
s_previous_timestamp = esp_timer_get_time();
diff --git a/components/openthread/CMakeLists.txt b/components/openthread/CMakeLists.txt
index cbe7369ac4..2a018a6de0 100644
--- a/components/openthread/CMakeLists.txt
+++ b/components/openthread/CMakeLists.txt
@@ -101,6 +101,7 @@ if(CONFIG_OPENTHREAD_ENABLED)
"openthread/src/core/thread/mesh_forwarder_ftd.cpp"
"openthread/src/core/thread/mesh_forwarder_mtd.cpp"
"openthread/src/core/thread/mle.cpp"
+ "openthread/src/core/thread/mle_types.cpp"
"openthread/src/core/thread/neighbor_table.cpp"
"openthread/src/core/thread/network_data.cpp"
"openthread/src/core/thread/network_data_leader.cpp"
diff --git a/components/openthread/Kconfig b/components/openthread/Kconfig
index 219bd8b697..51af2e36ec 100644
--- a/components/openthread/Kconfig
+++ b/components/openthread/Kconfig
@@ -39,6 +39,13 @@ menu "OpenThread"
string "OpenThread network name"
default "OpenThread-ESP"
+ config OPENTHREAD_MESH_LOCAL_PREFIX
+ string "OpenThread mesh local prefix, format
/"
+ default "fd00:db8:a0:0::/64"
+ help
+ A string in the format "/", where `` is an IPv6
+ address and `` is a prefix length. For example "fd00:db8:a0:0::/64"
+
config OPENTHREAD_NETWORK_CHANNEL
int "OpenThread network channel"
range 11 26
diff --git a/components/openthread/lib b/components/openthread/lib
index c9c17a0b66..64c77643c9 160000
--- a/components/openthread/lib
+++ b/components/openthread/lib
@@ -1 +1 @@
-Subproject commit c9c17a0b6634af016111c9817f0be1fe0e7112f6
+Subproject commit 64c77643c92b76fff36bd13211f6b821c4beb8ef
diff --git a/components/openthread/openthread b/components/openthread/openthread
index 5beae14370..4ae691476f 160000
--- a/components/openthread/openthread
+++ b/components/openthread/openthread
@@ -1 +1 @@
-Subproject commit 5beae143700db54c6e9bd4b15a568abe2f305723
+Subproject commit 4ae691476f07164dee3d12d304a9eb0b4f0ea0a3
diff --git a/components/openthread/src/esp_openthread.cpp b/components/openthread/src/esp_openthread.cpp
index e907584b70..5c35003da9 100644
--- a/components/openthread/src/esp_openthread.cpp
+++ b/components/openthread/src/esp_openthread.cpp
@@ -22,6 +22,10 @@
#include "openthread/tasklet.h"
#include "openthread/thread.h"
+#if CONFIG_OPENTHREAD_FTD
+#include "openthread/dataset_ftd.h"
+#endif
+
static int hex_digit_to_int(char hex)
{
if ('A' <= hex && hex <= 'F') {
@@ -87,13 +91,14 @@ esp_err_t esp_openthread_auto_start(otOperationalDatasetTlvs *datasetTlvs)
if (datasetTlvs) {
ESP_RETURN_ON_FALSE(otDatasetSetActiveTlvs(instance, datasetTlvs) == OT_ERROR_NONE, ESP_FAIL, OT_PLAT_LOG_TAG,
"Failed to set OpenThread active dataset");
- }
- else {
+ } else {
otOperationalDataset dataset;
size_t len = 0;
-
+#if CONFIG_OPENTHREAD_FTD
+ otDatasetCreateNewNetwork(instance, &dataset);
+#else
memset(&dataset, 0, sizeof(otOperationalDataset));
-
+#endif
// Active timestamp
dataset.mActiveTimestamp.mSeconds = 1;
dataset.mActiveTimestamp.mTicks = 0;
@@ -117,6 +122,16 @@ esp_err_t esp_openthread_auto_start(otOperationalDatasetTlvs *datasetTlvs)
"Cannot convert OpenThread extended pan id");
dataset.mComponents.mIsExtendedPanIdPresent = true;
+ // Mesh Local Prefix
+ otIp6Prefix prefix;
+ memset(&prefix, 0, sizeof(otIp6Prefix));
+ if (otIp6PrefixFromString(CONFIG_OPENTHREAD_MESH_LOCAL_PREFIX, &prefix) == OT_ERROR_NONE) {
+ memcpy(dataset.mMeshLocalPrefix.m8, prefix.mPrefix.mFields.m8, sizeof(dataset.mMeshLocalPrefix.m8));
+ dataset.mComponents.mIsMeshLocalPrefixPresent = true;
+ } else {
+ ESP_LOGE("Falied to parse mesh local prefix", CONFIG_OPENTHREAD_MESH_LOCAL_PREFIX);
+ }
+
// Network Key
len = hex_string_to_binary(CONFIG_OPENTHREAD_NETWORK_MASTERKEY, dataset.mNetworkKey.m8,
sizeof(dataset.mNetworkKey.m8));
diff --git a/components/openthread/src/port/esp_openthread_settings.c b/components/openthread/src/port/esp_openthread_settings.c
index 8bc08be482..f9064ee437 100644
--- a/components/openthread/src/port/esp_openthread_settings.c
+++ b/components/openthread/src/port/esp_openthread_settings.c
@@ -39,6 +39,7 @@ static esp_err_t get_next_empty_index(uint16_t aKey, uint8_t *index)
for (uint8_t i = 0; i != UINT8_MAX; i++) {
s_unused_pos++;
+ found = false;
snprintf(ot_nvs_key, sizeof(ot_nvs_key), OT_KEY_INDEX_PATTERN, (uint8_t)aKey, s_unused_pos);
ret = nvs_entry_find(OT_PART_NAME, OT_NAMESPACE, NVS_TYPE_BLOB, &nvs_it);
while (ret == ESP_OK) {
diff --git a/examples/openthread/ot_cli/main/Kconfig.projbuild b/examples/openthread/ot_cli/main/Kconfig.projbuild
new file mode 100644
index 0000000000..32146234e0
--- /dev/null
+++ b/examples/openthread/ot_cli/main/Kconfig.projbuild
@@ -0,0 +1,9 @@
+menu "OpenThread CLI Example"
+
+ config OPENTHREAD_AUTO_START
+ bool 'Enable the automatic start mode.'
+ default False
+ help
+ If enabled, the Openthread Device will create or connect to thread network with pre-configured
+ network parameters automatically. Otherwise, user need to configure Thread via CLI command manually.
+endmenu
diff --git a/examples/openthread/ot_cli/main/esp_ot_cli.c b/examples/openthread/ot_cli/main/esp_ot_cli.c
index 9b7f29ec05..7baf80062d 100644
--- a/examples/openthread/ot_cli/main/esp_ot_cli.c
+++ b/examples/openthread/ot_cli/main/esp_ot_cli.c
@@ -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: CC0-1.0
*
@@ -86,6 +86,11 @@ static void ot_task_worker(void *aContext)
// Run the main loop
#if CONFIG_OPENTHREAD_CLI
esp_openthread_cli_create_task();
+#endif
+#if CONFIG_OPENTHREAD_AUTO_START
+ otOperationalDatasetTlvs dataset;
+ otError error = otDatasetGetActiveTlvs(esp_openthread_get_instance(), &dataset);
+ ESP_ERROR_CHECK(esp_openthread_auto_start((error == OT_ERROR_NONE) ? &dataset : NULL));
#endif
esp_openthread_launch_mainloop();