Skip to content

Commit

Permalink
Merge branch 'fix/join_mcast_group_using_null_netif' into 'master'
Browse files Browse the repository at this point in the history
fix(openthread): add netif check when call udp api for ot

Closes TZ-484

See merge request espressif/esp-idf!27915
  • Loading branch information
chshu committed Dec 18, 2023
2 parents eaf4fb9 + e1a414a commit ff89cf5
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions components/openthread/src/port/esp_openthread_udp.c
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 Down Expand Up @@ -57,6 +57,7 @@ typedef struct {
TaskHandle_t source_task;
struct udp_pcb *pcb;
uint8_t netif_index;
esp_err_t err;
} udp_bind_netif_task_t;

typedef struct {
Expand Down Expand Up @@ -255,8 +256,13 @@ otError otPlatUdpBind(otUdpSocket *udp_socket)
static void udp_bind_netif_task(void *ctx)
{
udp_bind_netif_task_t *task = (udp_bind_netif_task_t *)ctx;

udp_bind_netif(task->pcb, netif_get_by_index(task->netif_index));
struct netif* target = netif_get_by_index(task->netif_index);
if (target == NULL) {
task->err = ESP_FAIL;
ESP_LOGE(OT_PLAT_LOG_TAG, "Failed to bind udp on index%d netif", task->netif_index);
} else {
udp_bind_netif(task->pcb, target);
}
xTaskNotifyGive(task->source_task);
}

Expand All @@ -276,16 +282,20 @@ static uint8_t get_netif_index(otNetifIdentifier netif_identifier)

otError otPlatUdpBindToNetif(otUdpSocket *udp_socket, otNetifIdentifier netif_identifier)
{
otError err = OT_ERROR_NONE;
udp_bind_netif_task_t task = {
.source_task = xTaskGetCurrentTaskHandle(),
.pcb = (struct udp_pcb *)udp_socket->mHandle,
.netif_index = get_netif_index(netif_identifier),
.err = ESP_OK,
};

tcpip_callback(udp_bind_netif_task, &task);
wait_for_task_notification();

return OT_ERROR_NONE;
if (task.err != ESP_OK) {
err = OT_ERROR_FAILED;
}
return err;
}

static void udp_connect_task(void *ctx)
Expand Down Expand Up @@ -424,14 +434,20 @@ otError otPlatUdpSend(otUdpSocket *udp_socket, otMessage *message, const otMessa
static void udp_multicast_join_leave_task(void *ctx)
{
udp_multicast_join_leave_task_t *task = (udp_multicast_join_leave_task_t *)ctx;
struct netif *target = netif_get_by_index(task->netif_index);

if (task->is_join) {
if (mld6_joingroup_netif(netif_get_by_index(task->netif_index), &task->addr) != ERR_OK) {
ESP_LOGE(OT_PLAT_LOG_TAG, "Failed to join multicast group");
}
if (target == NULL) {
ESP_LOGE(OT_PLAT_LOG_TAG, "Failed to %s multicast group, index%d netif is not ready",
task->is_join ? "join" : "leave", task->netif_index);
} else {
if (mld6_leavegroup_netif(netif_get_by_index(task->netif_index), &task->addr) != ERR_OK) {
ESP_LOGE(OT_PLAT_LOG_TAG, "Failed to leave multicast group");
if (task->is_join) {
if (mld6_joingroup_netif(target, &task->addr) != ERR_OK) {
ESP_LOGE(OT_PLAT_LOG_TAG, "Failed to join multicast group");
}
} else {
if (mld6_leavegroup_netif(target, &task->addr) != ERR_OK) {
ESP_LOGE(OT_PLAT_LOG_TAG, "Failed to leave multicast group");
}
}
}
free(task);
Expand Down

0 comments on commit ff89cf5

Please sign in to comment.