mirror of
https://github.com/espressif/esp-idf
synced 2025-03-10 09:39:10 -04:00
fix(openthread): add netif check when call udp api for ot
This commit is contained in:
parent
abe36b97a5
commit
d799d361ea
@ -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
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
@ -57,6 +57,7 @@ typedef struct {
|
|||||||
TaskHandle_t source_task;
|
TaskHandle_t source_task;
|
||||||
struct udp_pcb *pcb;
|
struct udp_pcb *pcb;
|
||||||
uint8_t netif_index;
|
uint8_t netif_index;
|
||||||
|
esp_err_t err;
|
||||||
} udp_bind_netif_task_t;
|
} udp_bind_netif_task_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -255,8 +256,13 @@ otError otPlatUdpBind(otUdpSocket *udp_socket)
|
|||||||
static void udp_bind_netif_task(void *ctx)
|
static void udp_bind_netif_task(void *ctx)
|
||||||
{
|
{
|
||||||
udp_bind_netif_task_t *task = (udp_bind_netif_task_t *)ctx;
|
udp_bind_netif_task_t *task = (udp_bind_netif_task_t *)ctx;
|
||||||
|
struct netif* target = netif_get_by_index(task->netif_index);
|
||||||
udp_bind_netif(task->pcb, 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);
|
xTaskNotifyGive(task->source_task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,16 +282,20 @@ static uint8_t get_netif_index(otNetifIdentifier netif_identifier)
|
|||||||
|
|
||||||
otError otPlatUdpBindToNetif(otUdpSocket *udp_socket, otNetifIdentifier netif_identifier)
|
otError otPlatUdpBindToNetif(otUdpSocket *udp_socket, otNetifIdentifier netif_identifier)
|
||||||
{
|
{
|
||||||
|
otError err = OT_ERROR_NONE;
|
||||||
udp_bind_netif_task_t task = {
|
udp_bind_netif_task_t task = {
|
||||||
.source_task = xTaskGetCurrentTaskHandle(),
|
.source_task = xTaskGetCurrentTaskHandle(),
|
||||||
.pcb = (struct udp_pcb *)udp_socket->mHandle,
|
.pcb = (struct udp_pcb *)udp_socket->mHandle,
|
||||||
.netif_index = get_netif_index(netif_identifier),
|
.netif_index = get_netif_index(netif_identifier),
|
||||||
|
.err = ESP_OK,
|
||||||
};
|
};
|
||||||
|
|
||||||
tcpip_callback(udp_bind_netif_task, &task);
|
tcpip_callback(udp_bind_netif_task, &task);
|
||||||
wait_for_task_notification();
|
wait_for_task_notification();
|
||||||
|
if (task.err != ESP_OK) {
|
||||||
return OT_ERROR_NONE;
|
err = OT_ERROR_FAILED;
|
||||||
|
}
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void udp_connect_task(void *ctx)
|
static void udp_connect_task(void *ctx)
|
||||||
@ -424,14 +434,20 @@ exit:
|
|||||||
static void udp_multicast_join_leave_task(void *ctx)
|
static void udp_multicast_join_leave_task(void *ctx)
|
||||||
{
|
{
|
||||||
udp_multicast_join_leave_task_t *task = (udp_multicast_join_leave_task_t *)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 (target == NULL) {
|
||||||
if (mld6_joingroup_netif(netif_get_by_index(task->netif_index), &task->addr) != ERR_OK) {
|
ESP_LOGE(OT_PLAT_LOG_TAG, "Failed to %s multicast group, index%d netif is not ready",
|
||||||
ESP_LOGE(OT_PLAT_LOG_TAG, "Failed to join multicast group");
|
task->is_join ? "join" : "leave", task->netif_index);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (mld6_leavegroup_netif(netif_get_by_index(task->netif_index), &task->addr) != ERR_OK) {
|
if (task->is_join) {
|
||||||
ESP_LOGE(OT_PLAT_LOG_TAG, "Failed to leave multicast group");
|
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);
|
free(task);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user