forked from espressif/esp-idf
feat(openthread): add mesh local prefix configuration
This commit is contained in:
@@ -39,6 +39,13 @@ menu "OpenThread"
|
|||||||
string "OpenThread network name"
|
string "OpenThread network name"
|
||||||
default "OpenThread-ESP"
|
default "OpenThread-ESP"
|
||||||
|
|
||||||
|
config OPENTHREAD_MESH_LOCAL_PREFIX
|
||||||
|
string "OpenThread mesh local prefix, format <address>/<plen>"
|
||||||
|
default "fd00:db8:a0:0::/64"
|
||||||
|
help
|
||||||
|
A string in the format "<address>/<plen>", where `<address>` is an IPv6
|
||||||
|
address and `<plen>` is a prefix length. For example "fd00:db8:a0:0::/64"
|
||||||
|
|
||||||
config OPENTHREAD_NETWORK_CHANNEL
|
config OPENTHREAD_NETWORK_CHANNEL
|
||||||
int "OpenThread network channel"
|
int "OpenThread network channel"
|
||||||
range 11 26
|
range 11 26
|
||||||
|
@@ -22,6 +22,10 @@
|
|||||||
#include "openthread/tasklet.h"
|
#include "openthread/tasklet.h"
|
||||||
#include "openthread/thread.h"
|
#include "openthread/thread.h"
|
||||||
|
|
||||||
|
#if CONFIG_OPENTHREAD_FTD
|
||||||
|
#include "openthread/dataset_ftd.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
static int hex_digit_to_int(char hex)
|
static int hex_digit_to_int(char hex)
|
||||||
{
|
{
|
||||||
if ('A' <= hex && hex <= 'F') {
|
if ('A' <= hex && hex <= 'F') {
|
||||||
@@ -87,13 +91,14 @@ esp_err_t esp_openthread_auto_start(otOperationalDatasetTlvs *datasetTlvs)
|
|||||||
if (datasetTlvs) {
|
if (datasetTlvs) {
|
||||||
ESP_RETURN_ON_FALSE(otDatasetSetActiveTlvs(instance, datasetTlvs) == OT_ERROR_NONE, ESP_FAIL, OT_PLAT_LOG_TAG,
|
ESP_RETURN_ON_FALSE(otDatasetSetActiveTlvs(instance, datasetTlvs) == OT_ERROR_NONE, ESP_FAIL, OT_PLAT_LOG_TAG,
|
||||||
"Failed to set OpenThread active dataset");
|
"Failed to set OpenThread active dataset");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
otOperationalDataset dataset;
|
otOperationalDataset dataset;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
#if CONFIG_OPENTHREAD_FTD
|
||||||
|
otDatasetCreateNewNetwork(instance, &dataset);
|
||||||
|
#else
|
||||||
memset(&dataset, 0, sizeof(otOperationalDataset));
|
memset(&dataset, 0, sizeof(otOperationalDataset));
|
||||||
|
#endif
|
||||||
// Active timestamp
|
// Active timestamp
|
||||||
dataset.mActiveTimestamp.mSeconds = 1;
|
dataset.mActiveTimestamp.mSeconds = 1;
|
||||||
dataset.mActiveTimestamp.mTicks = 0;
|
dataset.mActiveTimestamp.mTicks = 0;
|
||||||
@@ -117,6 +122,16 @@ esp_err_t esp_openthread_auto_start(otOperationalDatasetTlvs *datasetTlvs)
|
|||||||
"Cannot convert OpenThread extended pan id");
|
"Cannot convert OpenThread extended pan id");
|
||||||
dataset.mComponents.mIsExtendedPanIdPresent = true;
|
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
|
// Network Key
|
||||||
len = hex_string_to_binary(CONFIG_OPENTHREAD_NETWORK_MASTERKEY, dataset.mNetworkKey.m8,
|
len = hex_string_to_binary(CONFIG_OPENTHREAD_NETWORK_MASTERKEY, dataset.mNetworkKey.m8,
|
||||||
sizeof(dataset.mNetworkKey.m8));
|
sizeof(dataset.mNetworkKey.m8));
|
||||||
|
9
examples/openthread/ot_cli/main/Kconfig.projbuild
Normal file
9
examples/openthread/ot_cli/main/Kconfig.projbuild
Normal file
@@ -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
|
@@ -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
|
* SPDX-License-Identifier: CC0-1.0
|
||||||
*
|
*
|
||||||
@@ -86,6 +86,11 @@ static void ot_task_worker(void *aContext)
|
|||||||
// Run the main loop
|
// Run the main loop
|
||||||
#if CONFIG_OPENTHREAD_CLI
|
#if CONFIG_OPENTHREAD_CLI
|
||||||
esp_openthread_cli_create_task();
|
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
|
#endif
|
||||||
esp_openthread_launch_mainloop();
|
esp_openthread_launch_mainloop();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user