Skip to content

Commit 4e88543

Browse files
committed
Merge branch 'feat/openthread_dataset_changed_event_v5_2' into 'release/v5.2'
feat(openthread): Add dataset changed event and post it in state change callback(v5.2) See merge request espressif/esp-idf!34545
2 parents d90d20d + cc128d7 commit 4e88543

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

components/openthread/include/esp_openthread_types.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -46,6 +46,7 @@ typedef enum {
4646
OPENTHREAD_EVENT_SET_DNS_SERVER, /*!< OpenThread stack set DNS server >*/
4747
OPENTHREAD_EVENT_PUBLISH_MESHCOP_E, /*!< OpenThread stack start to publish meshcop-e service >*/
4848
OPENTHREAD_EVENT_REMOVE_MESHCOP_E, /*!< OpenThread stack start to remove meshcop-e service >*/
49+
OPENTHREAD_EVENT_DATASET_CHANGED, /*!< OpenThread dataset changed >*/
4950
} esp_openthread_event_t;
5051

5152
/**
@@ -63,6 +64,24 @@ typedef struct {
6364
otDeviceRole current_role; /*!< Current Thread role */
6465
} esp_openthread_role_changed_event_t;
6566

67+
/**
68+
* @brief OpenThread dataset type
69+
*
70+
*/
71+
typedef enum {
72+
OPENTHREAD_ACTIVE_DATASET, /*!< Active dataset */
73+
OPENTHREAD_PENDING_DATASET, /*!< Pending dataset */
74+
} esp_openthread_dataset_type_t;
75+
76+
/**
77+
* @brief OpenThread dataset changed event data
78+
*
79+
*/
80+
typedef struct {
81+
esp_openthread_dataset_type_t type; /*!< Dataset type */
82+
otOperationalDataset new_dataset; /*!< New dataset */
83+
} esp_openthread_dataset_changed_event_t;
84+
6685
/**
6786
* This structure represents a context for a select() based mainloop.
6887
*

components/openthread/src/port/esp_openthread_state.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -80,6 +80,21 @@ static void handle_ot_role_change(otInstance* instance)
8080
s_previous_role = role;
8181
}
8282

83+
static void handle_ot_dataset_change(esp_openthread_dataset_type_t type, otInstance *instance)
84+
{
85+
esp_openthread_dataset_changed_event_t event_data;
86+
event_data.type = type;
87+
memset(&event_data.new_dataset, 0, sizeof(event_data.new_dataset));
88+
if (type == OPENTHREAD_ACTIVE_DATASET) {
89+
(void)otDatasetGetActive(instance, &event_data.new_dataset);
90+
} else if (type == OPENTHREAD_PENDING_DATASET) {
91+
(void)otDatasetGetPending(instance, &event_data.new_dataset);
92+
}
93+
if (esp_event_post(OPENTHREAD_EVENT, OPENTHREAD_EVENT_DATASET_CHANGED, &event_data, sizeof(event_data), 0) != ESP_OK) {
94+
ESP_LOGE(TAG, "Failed to post dataset changed event");
95+
}
96+
}
97+
8398
static void ot_state_change_callback(otChangedFlags changed_flags, void* ctx)
8499
{
85100
OT_UNUSED_VARIABLE(ctx);
@@ -99,6 +114,14 @@ static void ot_state_change_callback(otChangedFlags changed_flags, void* ctx)
99114
if (changed_flags & OT_CHANGED_THREAD_NETIF_STATE) {
100115
handle_ot_netif_state_change(instance);
101116
}
117+
118+
if (changed_flags & OT_CHANGED_ACTIVE_DATASET) {
119+
handle_ot_dataset_change(OPENTHREAD_ACTIVE_DATASET, instance);
120+
}
121+
122+
if (changed_flags & OT_CHANGED_PENDING_DATASET) {
123+
handle_ot_dataset_change(OPENTHREAD_PENDING_DATASET, instance);
124+
}
102125
}
103126

104127
esp_err_t esp_openthread_state_event_init(otInstance* instance)

0 commit comments

Comments
 (0)