Merge branch 'feat/ble_mesh_ble_50_micellaneous_fix' into 'master'

fix(ble_mesh): resolve issues in long packet mode

Closes BLERP-2324, BLERP-2323, BLERP-2322, BLERP-2321, BLERP-2320, and BLERP-2319

See merge request espressif/esp-idf!42745
This commit is contained in:
Island
2025-10-22 10:46:54 +08:00
9 changed files with 119 additions and 48 deletions
@@ -32,6 +32,27 @@ static inline void btc_ble_mesh_set_client_common_param(esp_ble_mesh_client_comm
output->ctx.send_cred = input->ctx.send_cred;
output->ctx.send_tag = input->ctx.send_tag;
output->msg_timeout = input->msg_timeout;
if (input->ctx.enh.adv_cfg_used) {
output->ctx.enh.adv_cfg_used = input->ctx.enh.adv_cfg_used;
output->ctx.enh.adv_cfg.adv_cnt = input->ctx.enh.adv_cfg.adv_cnt;
output->ctx.enh.adv_cfg.adv_itvl = input->ctx.enh.adv_cfg.adv_itvl;
output->ctx.enh.adv_cfg.channel_map = input->ctx.enh.adv_cfg.channel_map;
}
#if CONFIG_BLE_MESH_EXT_ADV
if (input->ctx.enh.ext_adv_cfg_used) {
output->ctx.enh.ext_adv_cfg_used = input->ctx.enh.ext_adv_cfg_used;
output->ctx.enh.ext_adv_cfg.primary_phy = input->ctx.enh.ext_adv_cfg.primary_phy;
output->ctx.enh.ext_adv_cfg.secondary_phy = input->ctx.enh.ext_adv_cfg.secondary_phy;
output->ctx.enh.ext_adv_cfg.include_tx_power = input->ctx.enh.ext_adv_cfg.include_tx_power;
output->ctx.enh.ext_adv_cfg.tx_power = input->ctx.enh.ext_adv_cfg.tx_power;
}
#if CONFIG_BLE_MESH_LONG_PACKET
if (input->ctx.enh.long_pkt_cfg_used) {
output->ctx.enh.long_pkt_cfg_used = input->ctx.enh.long_pkt_cfg_used;
output->ctx.enh.long_pkt_cfg = input->ctx.enh.long_pkt_cfg;
}
#endif
#endif
}
}
+4 -4
View File
@@ -362,6 +362,10 @@ void bt_mesh_adv_update(void)
void bt_mesh_adv_init(void)
{
bt_mesh_adv_common_init();
adv_queue = bt_mesh_adv_queue_get();
assert(adv_queue && adv_queue->q.handle && adv_queue->send);
#if CONFIG_BLE_MESH_RELAY_ADV_BUF
bt_mesh_relay_adv_init();
@@ -370,10 +374,6 @@ void bt_mesh_adv_init(void)
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
bt_mesh_ble_adv_init();
#endif
bt_mesh_adv_common_init();
adv_queue = bt_mesh_adv_queue_get();
assert(adv_queue && adv_queue->q.handle && adv_queue->send);
#if CONFIG_BLE_MESH_RELAY_ADV_BUF && !CONFIG_BLE_MESH_SUPPORT_MULTI_ADV
QueueHandle_t relay_adv_handle =
+8 -2
View File
@@ -748,6 +748,12 @@ uint16_t ble_mesh_adv_buf_count_get(void)
adv_count += CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT;
#endif
#endif
#if (CONFIG_BLE_MESH_SUPPORT_BLE_ADV && \
!(CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE))
adv_count += CONFIG_BLE_MESH_BLE_ADV_BUF_COUNT;
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
return adv_count;
}
@@ -822,13 +828,13 @@ void bt_mesh_adv_common_init(void)
#if CONFIG_BLE_MESH_EXT_ADV
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_PROV);
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_DATA);
#if !CONFIG_BLE_MESH_RELAY_ADV_BUF
#if CONFIG_BLE_MESH_RELAY && !CONFIG_BLE_MESH_RELAY_ADV_BUF
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_RELAY_DATA);
#endif
#if CONFIG_BLE_MESH_LONG_PACKET
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_LONG_PROV);
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_LONG_DATA);
#if !CONFIG_BLE_MESH_RELAY_ADV_BUF
#if CONFIG_BLE_MESH_RELAY && !CONFIG_BLE_MESH_RELAY_ADV_BUF
bt_mesh_adv_inst_supported_adv_type_add(BLE_MESH_ADV_INS, BLE_MESH_ADV_EXT_LONG_RELAY_DATA);
#endif /* !CONFIG_BLE_MESH_RELAY_ADV_BUF */
#endif /* CONFIG_BLE_MESH_LONG_PACKET */
+29 -10
View File
@@ -2,7 +2,7 @@
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -15,8 +15,12 @@
#include "mesh/buf.h"
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
#if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE
/* Use independent ble adv queue only if multi adv instance is used */
static struct bt_mesh_adv_queue ble_adv_queue;
static void bt_mesh_ble_task_post(bt_mesh_msg_t *msg, uint32_t timeout, bool front);
#endif
static struct bt_mesh_adv_queue *p_ble_adv_queue;
#define BLE_MESH_BLE_ADV_QUEUE_SIZE (CONFIG_BLE_MESH_BLE_ADV_BUF_COUNT + 1)
/* length + advertising data + length + scan response data */
NET_BUF_POOL_DEFINE(ble_adv_buf_pool, CONFIG_BLE_MESH_BLE_ADV_BUF_COUNT,
@@ -28,8 +32,6 @@ static struct bt_mesh_ble_adv_tx ble_adv_tx[CONFIG_BLE_MESH_BLE_ADV_BUF_COUNT];
#define SEND_BLE_ADV_INFINITE 0xFFFF
static void bt_mesh_ble_task_post(bt_mesh_msg_t *msg, uint32_t timeout, bool front);
static struct bt_mesh_adv *ble_adv_alloc(int id, enum bt_mesh_adv_type type)
{
memset(&ble_adv_pool[id], 0, sizeof(struct bt_mesh_adv));
@@ -37,27 +39,30 @@ static struct bt_mesh_adv *ble_adv_alloc(int id, enum bt_mesh_adv_type type)
return &ble_adv_pool[id];
}
#if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE
/* A separate post function is required only when using a separate queue */
static void bt_mesh_ble_task_post(bt_mesh_msg_t *msg, uint32_t timeout, bool front)
{
BT_DBG("%s", __func__);
if (ble_adv_queue.q.handle == NULL) {
if (p_ble_adv_queue->q.handle == NULL) {
BT_ERR("Invalid adv queue");
return;
}
if (front) {
if (xQueueSendToFront(ble_adv_queue.q.handle, msg, timeout) != pdTRUE) {
if (xQueueSendToFront(p_ble_adv_queue->q.handle, msg, timeout) != pdTRUE) {
BT_ERR("Failed to send item to adv queue front");
bt_mesh_unref_buf(msg);
}
} else {
if (xQueueSend(ble_adv_queue.q.handle, msg, timeout) != pdTRUE) {
if (xQueueSend(p_ble_adv_queue->q.handle, msg, timeout) != pdTRUE) {
BT_ERR("Failed to send item to adv queue back");
bt_mesh_unref_buf(msg);
}
}
}
#endif
static struct net_buf *bt_mesh_ble_adv_create(enum bt_mesh_adv_type type, int32_t timeout)
{
@@ -282,10 +287,20 @@ int bt_mesh_stop_ble_advertising(uint8_t index)
return 0;
}
struct bt_mesh_adv_queue *bt_mesh_ble_adv_queue_get(void)
{
#if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE
bt_mesh_adv_queue_init(&ble_adv_queue, CONFIG_BLE_MESH_BLE_ADV_BUF_COUNT, bt_mesh_ble_task_post);
return &ble_adv_queue;
#else
return bt_mesh_adv_queue_get();
#endif
}
void bt_mesh_ble_adv_init(void)
{
bt_mesh_adv_queue_init(&ble_adv_queue, CONFIG_BLE_MESH_BLE_ADV_BUF_COUNT, bt_mesh_ble_task_post);
bt_mesh_adv_type_init(BLE_MESH_ADV_BLE, &ble_adv_queue, &ble_adv_buf_pool, ble_adv_alloc);
p_ble_adv_queue = bt_mesh_ble_adv_queue_get();
bt_mesh_adv_type_init(BLE_MESH_ADV_BLE, p_ble_adv_queue, &ble_adv_buf_pool, ble_adv_alloc);
#if CONFIG_BLE_MESH_USE_BLE_50
#if CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE
bt_mesh_adv_inst_init(BLE_MESH_BLE_ADV_INS, CONFIG_BLE_MESH_BLE_ADV_INST_ID);
@@ -308,7 +323,11 @@ void bt_mesh_ble_adv_deinit(void)
bt_mesh_unref_buf_from_pool(&ble_adv_buf_pool);
memset(ble_adv_pool, 0, sizeof(ble_adv_pool));
bt_mesh_adv_queue_deinit(&ble_adv_queue);
#if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE
/* In other cases, ble_adv queue is an adv queue,
* so ble does not need to deinit separately */
bt_mesh_adv_queue_deinit(p_ble_adv_queue);
#endif
bt_mesh_adv_type_deinit(BLE_MESH_ADV_BLE);
#if CONFIG_BLE_MESH_USE_BLE_50
#if CONFIG_BLE_MESH_SEPARATE_BLE_ADV_INSTANCE
@@ -929,20 +929,6 @@ int bt_mesh_ble_ext_adv_start(const uint8_t inst_id,
tBTA_DM_BLE_EXT_ADV ext_adv = {0};
struct bt_mesh_hci_cp_set_adv_data set = {0};
if (data && param->adv_type != BLE_MESH_ADV_DIRECT_IND &&
param->adv_type != BLE_MESH_ADV_DIRECT_IND_LOW_DUTY) {
if (data->adv_data_len) {
set.len = data->adv_data_len;
memcpy(set.data, data->adv_data, data->adv_data_len);
BTA_DmBleGapConfigExtAdvDataRaw(false, inst_id, set.len, set.data);
}
if (data->scan_rsp_data_len && param->adv_type != BLE_MESH_ADV_NONCONN_IND) {
set.len = data->scan_rsp_data_len;
memcpy(set.data, data->scan_rsp_data, data->scan_rsp_data_len);
BTA_DmBleGapConfigExtAdvDataRaw(true, inst_id, set.len, set.data);
}
}
switch (param->adv_type) {
case BLE_MESH_ADV_IND:
case BLE_MESH_ADV_DIRECT_IND:
@@ -983,6 +969,20 @@ int bt_mesh_ble_ext_adv_start(const uint8_t inst_id,
/* Check if we can start adv using BTM_BleSetAdvParamsStartAdvCheck */
BTA_DmBleGapExtAdvSetParams(inst_id, &ext_adv_params);
if (data && param->adv_type != BLE_MESH_ADV_DIRECT_IND &&
param->adv_type != BLE_MESH_ADV_DIRECT_IND_LOW_DUTY) {
if (data->adv_data_len) {
set.len = data->adv_data_len;
memcpy(set.data, data->adv_data, data->adv_data_len);
BTA_DmBleGapConfigExtAdvDataRaw(false, inst_id, set.len, set.data);
}
if (data->scan_rsp_data_len && param->adv_type != BLE_MESH_ADV_NONCONN_IND) {
set.len = data->scan_rsp_data_len;
memcpy(set.data, data->scan_rsp_data, data->scan_rsp_data_len);
BTA_DmBleGapConfigExtAdvDataRaw(true, inst_id, set.len, set.data);
}
}
BTA_DmBleGapExtAdvEnable(true, 1, &ext_adv);
#if !CONFIG_BLE_MESH_SUPPORT_MULTI_ADV
+3
View File
@@ -430,6 +430,9 @@ static void bt_mesh_scan_cb(struct bt_mesh_adv_report *adv_rpt)
#endif
adv_rpt->adv_type != BLE_MESH_ADV_NONCONN_IND &&
adv_rpt->adv_type != BLE_MESH_ADV_IND
#if CONFIG_BLE_MESH_EXT_ADV
&& adv_rpt->adv_type != BLE_MESH_EXT_ADV_NONCONN_IND
#endif
#if CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN
&& adv_rpt->adv_type != BLE_MESH_ADV_SCAN_RSP
#endif
+11 -8
View File
@@ -800,16 +800,19 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
}
#if CONFIG_BLE_MESH_LONG_PACKET
if (tx->ctx->enh.long_pkt_cfg_used == true &&
(tx->ctx->enh.long_pkt_cfg == BLE_MESH_LONG_PACKET_FORCE ||
tx->ctx->enh.long_pkt_cfg == BLE_MESH_LONG_PACKET_PREFER) &&
msg->len > BLE_MESH_EXT_SDU_UNSEG_MAX) {
if (tx->ctx->enh.long_pkt_cfg_used == true) {
if (tx->ctx->enh.long_pkt_cfg == BLE_MESH_LONG_PACKET_FORCE &&
msg->len > BLE_MESH_EXT_SDU_UNSEG_MAX) {
tx->ctx->send_tag |= BLE_MESH_TAG_SEND_SEGMENTED;
} else if (tx->ctx->enh.long_pkt_cfg == BLE_MESH_LONG_PACKET_PREFER &&
msg->len > BLE_MESH_SDU_UNSEG_MAX) {
tx->ctx->send_tag |= BLE_MESH_TAG_SEND_SEGMENTED;
} else {
if (msg->len > BLE_MESH_SDU_UNSEG_MAX) {
tx->ctx->send_tag |= BLE_MESH_TAG_SEND_SEGMENTED;
}
}
} else {
if (msg->len > BLE_MESH_SDU_UNSEG_MAX) {
tx->ctx->send_tag |= BLE_MESH_TAG_SEND_SEGMENTED;
}
}
#else
if (msg->len > BLE_MESH_SDU_UNSEG_MAX) {
tx->ctx->send_tag |= BLE_MESH_TAG_SEND_SEGMENTED;
@@ -1151,11 +1151,14 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
}
#if CONFIG_BLE_MESH_LONG_PACKET
if (tx->ctx->enh.long_pkt_cfg_used == true &&
(tx->ctx->enh.long_pkt_cfg == BLE_MESH_LONG_PACKET_FORCE ||
tx->ctx->enh.long_pkt_cfg == BLE_MESH_LONG_PACKET_PREFER) &&
msg->len > BLE_MESH_EXT_SDU_UNSEG_MAX) {
tx->ctx->send_tag |= BLE_MESH_TAG_SEND_SEGMENTED;
if (tx->ctx->enh.long_pkt_cfg_used == true) {
if (tx->ctx->enh.long_pkt_cfg == BLE_MESH_LONG_PACKET_FORCE &&
msg->len > BLE_MESH_EXT_SDU_UNSEG_MAX) {
tx->ctx->send_tag |= BLE_MESH_TAG_SEND_SEGMENTED;
} else if (tx->ctx->enh.long_pkt_cfg == BLE_MESH_LONG_PACKET_PREFER &&
msg->len > BLE_MESH_SDU_UNSEG_MAX) {
tx->ctx->send_tag |= BLE_MESH_TAG_SEND_SEGMENTED;
}
} else {
if (msg->len > BLE_MESH_SDU_UNSEG_MAX) {
tx->ctx->send_tag |= BLE_MESH_TAG_SEND_SEGMENTED;
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -183,12 +183,28 @@ static int32_t bt_mesh_client_calc_timeout(struct bt_mesh_msg_ctx *ctx,
{
int32_t seg_rtx_to = 0, duration = 0, time = 0;
uint8_t seg_count = 0, seg_rtx_num = 0;
bool need_seg = false;
bool need_seg = bt_mesh_tag_send_segmented(ctx->send_tag);
uint8_t mic_size = 0;
if (msg->len > BLE_MESH_SDU_UNSEG_MAX ||
bt_mesh_tag_send_segmented(ctx->send_tag)) {
need_seg = true; /* Needs segmentation */
if (!need_seg) {
#if CONFIG_BLE_MESH_LONG_PACKET
if (ctx->enh.long_pkt_cfg_used == true) {
if ((ctx->enh.long_pkt_cfg == BLE_MESH_LONG_PACKET_FORCE &&
msg->len > BLE_MESH_EXT_SDU_UNSEG_MAX) ||
(ctx->enh.long_pkt_cfg == BLE_MESH_LONG_PACKET_PREFER &&
msg->len > BLE_MESH_SDU_UNSEG_MAX)) {
need_seg = true; /* Needs segmentation */
}
} else {
if (msg->len > BLE_MESH_SDU_UNSEG_MAX) {
need_seg = true; /* Needs segmentation */
}
}
#else
if (msg->len > BLE_MESH_SDU_UNSEG_MAX) {
need_seg = true; /* Needs segmentation */
}
#endif
}
mic_size = (need_seg && ctx->send_szmic == BLE_MESH_SEG_SZMIC_LONG &&