forked from espressif/esp-idf
feat(openthread): support openthread ephemeral key
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -16,7 +16,7 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Default configuration reference of OT esp-netif
|
* @brief Default configuration reference of OpenThread esp-netif
|
||||||
*/
|
*/
|
||||||
#define ESP_NETIF_INHERENT_DEFAULT_OPENTHREAD() \
|
#define ESP_NETIF_INHERENT_DEFAULT_OPENTHREAD() \
|
||||||
{ \
|
{ \
|
||||||
@@ -67,6 +67,15 @@ void esp_openthread_netif_glue_deinit(void);
|
|||||||
*/
|
*/
|
||||||
esp_netif_t *esp_openthread_get_netif(void);
|
esp_netif_t *esp_openthread_get_netif(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief This function register a handler for meshcop-e service publish event and remove event.
|
||||||
|
*
|
||||||
|
* @param[in] handler The handler.
|
||||||
|
* @param[in] for_publish The usage of handler, true for publish event and false for remove event.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void esp_openthread_register_meshcop_e_handler(esp_event_handler_t handler, bool for_publish);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -44,6 +44,8 @@ typedef enum {
|
|||||||
OPENTHREAD_EVENT_TREL_REMOVE_IP6, /*!< OpenThread stack removed TREL IPv6 address */
|
OPENTHREAD_EVENT_TREL_REMOVE_IP6, /*!< OpenThread stack removed TREL IPv6 address */
|
||||||
OPENTHREAD_EVENT_TREL_MULTICAST_GROUP_JOIN, /*!< OpenThread stack joined TREL IPv6 multicast group */
|
OPENTHREAD_EVENT_TREL_MULTICAST_GROUP_JOIN, /*!< OpenThread stack joined TREL IPv6 multicast group */
|
||||||
OPENTHREAD_EVENT_SET_DNS_SERVER, /*!< OpenThread stack set DNS server >*/
|
OPENTHREAD_EVENT_SET_DNS_SERVER, /*!< OpenThread stack set DNS server >*/
|
||||||
|
OPENTHREAD_EVENT_PUBLISH_MESHCOP_E, /*!< OpenThread stack start to publish meshcop-e service >*/
|
||||||
|
OPENTHREAD_EVENT_REMOVE_MESHCOP_E, /*!< OpenThread stack start to remove meshcop-e service >*/
|
||||||
} esp_openthread_event_t;
|
} esp_openthread_event_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Submodule components/openthread/lib updated: fcee30db4b...a0f6a77960
Submodule components/openthread/openthread updated: 456c448284...be7d36e4ff
@@ -632,4 +632,8 @@
|
|||||||
#define OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT CONFIG_OPENTHREAD_MAC_MAX_CSMA_BACKOFFS_DIRECT
|
#define OPENTHREAD_CONFIG_MAC_MAX_CSMA_BACKOFFS_DIRECT CONFIG_OPENTHREAD_MAC_MAX_CSMA_BACKOFFS_DIRECT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef OPENTHREAD_CONFIG_THREAD_VERSION
|
||||||
|
#define OPENTHREAD_CONFIG_THREAD_VERSION OT_THREAD_VERSION_1_4
|
||||||
|
#endif
|
||||||
|
|
||||||
#define OPENTHREAD_FTD 1
|
#define OPENTHREAD_FTD 1
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@@ -203,6 +203,33 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static esp_event_handler_t meshcop_e_publish_handler = NULL;
|
||||||
|
static void esp_openthread_meshcop_e_publish_handler(void *args, esp_event_base_t base, int32_t event_id, void *data)
|
||||||
|
{
|
||||||
|
if (meshcop_e_publish_handler) {
|
||||||
|
meshcop_e_publish_handler(args, base, event_id, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static esp_event_handler_t meshcop_e_remove_handler = NULL;
|
||||||
|
static void esp_openthread_meshcop_e_remove_handler(void *args, esp_event_base_t base, int32_t event_id, void *data)
|
||||||
|
{
|
||||||
|
if (meshcop_e_remove_handler) {
|
||||||
|
meshcop_e_remove_handler(args, base, event_id, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void esp_openthread_register_meshcop_e_handler(esp_event_handler_t handler, bool for_publish)
|
||||||
|
{
|
||||||
|
if (for_publish) {
|
||||||
|
meshcop_e_publish_handler = handler;
|
||||||
|
} else if (!for_publish) {
|
||||||
|
meshcop_e_remove_handler = handler;
|
||||||
|
} else {
|
||||||
|
ESP_ERROR_CHECK(ESP_FAIL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static esp_err_t register_openthread_event_handlers(esp_netif_t *esp_netif)
|
static esp_err_t register_openthread_event_handlers(esp_netif_t *esp_netif)
|
||||||
{
|
{
|
||||||
ESP_RETURN_ON_ERROR(
|
ESP_RETURN_ON_ERROR(
|
||||||
@@ -229,6 +256,12 @@ static esp_err_t register_openthread_event_handlers(esp_netif_t *esp_netif)
|
|||||||
ESP_RETURN_ON_ERROR(esp_event_handler_register(OPENTHREAD_EVENT, OPENTHREAD_EVENT_MULTICAST_GROUP_LEAVE,
|
ESP_RETURN_ON_ERROR(esp_event_handler_register(OPENTHREAD_EVENT, OPENTHREAD_EVENT_MULTICAST_GROUP_LEAVE,
|
||||||
esp_netif_action_leave_ip6_multicast_group, esp_netif),
|
esp_netif_action_leave_ip6_multicast_group, esp_netif),
|
||||||
OT_PLAT_LOG_TAG, "OpenThread interface leave ip6 multicast group event register failed");
|
OT_PLAT_LOG_TAG, "OpenThread interface leave ip6 multicast group event register failed");
|
||||||
|
ESP_RETURN_ON_ERROR(esp_event_handler_register(OPENTHREAD_EVENT, OPENTHREAD_EVENT_PUBLISH_MESHCOP_E,
|
||||||
|
esp_openthread_meshcop_e_publish_handler, NULL),
|
||||||
|
OT_PLAT_LOG_TAG, "OpenThread publish meshcop-e service event register failed");
|
||||||
|
ESP_RETURN_ON_ERROR(esp_event_handler_register(OPENTHREAD_EVENT, OPENTHREAD_EVENT_REMOVE_MESHCOP_E,
|
||||||
|
esp_openthread_meshcop_e_remove_handler, NULL),
|
||||||
|
OT_PLAT_LOG_TAG, "OpenThread remove meshcop-e service event register failed");
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,6 +277,8 @@ static void unregister_openthread_event_handlers(void)
|
|||||||
esp_netif_action_join_ip6_multicast_group);
|
esp_netif_action_join_ip6_multicast_group);
|
||||||
esp_event_handler_unregister(OPENTHREAD_EVENT, OPENTHREAD_EVENT_MULTICAST_GROUP_LEAVE,
|
esp_event_handler_unregister(OPENTHREAD_EVENT, OPENTHREAD_EVENT_MULTICAST_GROUP_LEAVE,
|
||||||
esp_netif_action_leave_ip6_multicast_group);
|
esp_netif_action_leave_ip6_multicast_group);
|
||||||
|
esp_event_handler_unregister(OPENTHREAD_EVENT, OPENTHREAD_EVENT_PUBLISH_MESHCOP_E, esp_openthread_meshcop_e_publish_handler);
|
||||||
|
esp_event_handler_unregister(OPENTHREAD_EVENT, OPENTHREAD_EVENT_REMOVE_MESHCOP_E, esp_openthread_meshcop_e_remove_handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
static esp_err_t openthread_netif_post_attach(esp_netif_t *esp_netif, void *args)
|
static esp_err_t openthread_netif_post_attach(esp_netif_t *esp_netif, void *args)
|
||||||
|
@@ -1,8 +1,10 @@
|
|||||||
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||||
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
# !/usr/bin/env python3
|
# !/usr/bin/env python3
|
||||||
|
import copy
|
||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
|
import secrets
|
||||||
import subprocess
|
import subprocess
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
@@ -16,7 +18,7 @@ from pytest_embedded_idf.dut import IdfDut
|
|||||||
# This file contains the test scripts for Thread:
|
# This file contains the test scripts for Thread:
|
||||||
|
|
||||||
# Case 1: Thread network formation and attaching
|
# Case 1: Thread network formation and attaching
|
||||||
# A Thread Border Router forms a Thread network, Thread devices attache to it, then test ping connection between them.
|
# A Thread Border Router forms a Thread network, Thread devices attach to it, then test ping connection between them.
|
||||||
|
|
||||||
# Case 2: Bidirectional IPv6 connectivity
|
# Case 2: Bidirectional IPv6 connectivity
|
||||||
# Test IPv6 ping connection between Thread device and Linux Host (via Thread Border Router).
|
# Test IPv6 ping connection between Thread device and Linux Host (via Thread Border Router).
|
||||||
@@ -27,10 +29,10 @@ from pytest_embedded_idf.dut import IdfDut
|
|||||||
# Case 4: Multicast forwarding from Thread to Wi-Fi network
|
# Case 4: Multicast forwarding from Thread to Wi-Fi network
|
||||||
# Linux Host joins the multicast group, test group communication from Thread to Wi-Fi network.
|
# Linux Host joins the multicast group, test group communication from Thread to Wi-Fi network.
|
||||||
|
|
||||||
# Case 5: discover Serice published by Thread device
|
# Case 5: discover Service published by Thread device
|
||||||
# Thread device publishes the service, Linux Host discovers the service on Wi-Fi network.
|
# Thread device publishes the service, Linux Host discovers the service on Wi-Fi network.
|
||||||
|
|
||||||
# Case 6: discover Serice published by W-Fi device
|
# Case 6: discover Service published by W-Fi device
|
||||||
# Linux Host device publishes the service on Wi-Fi network, Thread device discovers the service.
|
# Linux Host device publishes the service on Wi-Fi network, Thread device discovers the service.
|
||||||
|
|
||||||
# Case 7: ICMP communication via NAT64
|
# Case 7: ICMP communication via NAT64
|
||||||
@@ -627,3 +629,64 @@ def test_basic_startup(dut: Tuple[IdfDut, IdfDut]) -> None:
|
|||||||
finally:
|
finally:
|
||||||
ocf.execute_command(br, 'factoryreset')
|
ocf.execute_command(br, 'factoryreset')
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
|
|
||||||
|
# Case 12: Curl a website via DNS and NAT64
|
||||||
|
# @pytest.mark.openthread_bbr is not supported on release 5.1, skip this check
|
||||||
|
|
||||||
|
|
||||||
|
# Case 13: Meshcop discovery of Border Router
|
||||||
|
@pytest.mark.supported_targets
|
||||||
|
@pytest.mark.esp32c6
|
||||||
|
@pytest.mark.openthread_br
|
||||||
|
@pytest.mark.flaky(reruns=1, reruns_delay=1)
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
'config, count, app_path, target', [
|
||||||
|
('rcp|br', 2,
|
||||||
|
f'{os.path.join(os.path.dirname(__file__), "ot_rcp")}'
|
||||||
|
f'|{os.path.join(os.path.dirname(__file__), "ot_br")}',
|
||||||
|
'esp32c6|esp32s3'),
|
||||||
|
],
|
||||||
|
indirect=True,
|
||||||
|
)
|
||||||
|
def test_br_meshcop(Init_interface:bool, Init_avahi:bool, dut: Tuple[IdfDut, IdfDut]) -> None:
|
||||||
|
br = dut[1]
|
||||||
|
assert Init_interface
|
||||||
|
assert Init_avahi
|
||||||
|
dut[0].serial.stop_redirect_thread()
|
||||||
|
|
||||||
|
result = None
|
||||||
|
output_bytes = b''
|
||||||
|
try:
|
||||||
|
ocf.init_thread(br)
|
||||||
|
br_wifi_para = copy.copy(default_br_wifi_para)
|
||||||
|
ipv4_address = ocf.joinWiFiNetwork(br, br_wifi_para)[0]
|
||||||
|
br_thread_para = copy.copy(default_br_ot_para)
|
||||||
|
networkname = 'OTCI-' + str(secrets.token_hex(1))
|
||||||
|
br_thread_para.setnetworkname(networkname)
|
||||||
|
ocf.joinThreadNetwork(br, br_thread_para)
|
||||||
|
ocf.wait(br, 10)
|
||||||
|
assert ocf.is_joined_wifi_network(br)
|
||||||
|
command = 'timeout 3 avahi-browse -r _meshcop._udp'
|
||||||
|
try:
|
||||||
|
result = subprocess.run(command, capture_output=True, check=True, shell=True)
|
||||||
|
if result:
|
||||||
|
output_bytes = result.stdout
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
output_bytes = e.stdout
|
||||||
|
finally:
|
||||||
|
print('out_bytes: ', output_bytes)
|
||||||
|
output_str = str(output_bytes)
|
||||||
|
print('out_str: ', output_str)
|
||||||
|
|
||||||
|
assert 'hostname = [esp-ot-br.local]' in str(output_str)
|
||||||
|
assert ('address = [' + ipv4_address + ']') in str(output_str)
|
||||||
|
assert 'dn=DefaultDomain' in str(output_str)
|
||||||
|
assert 'tv=1.4.0' in str(output_str)
|
||||||
|
assert ('nn=' + networkname) in str(output_str)
|
||||||
|
assert 'mn=BorderRouter' in str(output_str)
|
||||||
|
assert 'vn=OpenThread' in str(output_str)
|
||||||
|
assert 'rv=1' in str(output_str)
|
||||||
|
finally:
|
||||||
|
ocf.execute_command(br, 'factoryreset')
|
||||||
|
time.sleep(3)
|
||||||
|
Reference in New Issue
Block a user