diff --git a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_model_common.h b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_model_common.h index 11114418f9c..73b00db41ff 100644 --- a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_model_common.h +++ b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_model_common.h @@ -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 } } diff --git a/components/bt/esp_ble_mesh/core/adv.c b/components/bt/esp_ble_mesh/core/adv.c index 0258c24c62f..fa4249c1875 100644 --- a/components/bt/esp_ble_mesh/core/adv.c +++ b/components/bt/esp_ble_mesh/core/adv.c @@ -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 = diff --git a/components/bt/esp_ble_mesh/core/adv_common.c b/components/bt/esp_ble_mesh/core/adv_common.c index 2f3d01e346a..96b4ac773ae 100644 --- a/components/bt/esp_ble_mesh/core/adv_common.c +++ b/components/bt/esp_ble_mesh/core/adv_common.c @@ -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 */ diff --git a/components/bt/esp_ble_mesh/core/ble_adv.c b/components/bt/esp_ble_mesh/core/ble_adv.c index ec2e0cc2274..110e52e2204 100644 --- a/components/bt/esp_ble_mesh/core/ble_adv.c +++ b/components/bt/esp_ble_mesh/core/ble_adv.c @@ -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 diff --git a/components/bt/esp_ble_mesh/core/bluedroid_host/adapter.c b/components/bt/esp_ble_mesh/core/bluedroid_host/adapter.c index a74dc749f85..d6f51bfc9d7 100644 --- a/components/bt/esp_ble_mesh/core/bluedroid_host/adapter.c +++ b/components/bt/esp_ble_mesh/core/bluedroid_host/adapter.c @@ -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 diff --git a/components/bt/esp_ble_mesh/core/scan.c b/components/bt/esp_ble_mesh/core/scan.c index 0742ddc099d..d161061ca74 100644 --- a/components/bt/esp_ble_mesh/core/scan.c +++ b/components/bt/esp_ble_mesh/core/scan.c @@ -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 diff --git a/components/bt/esp_ble_mesh/core/transport.c b/components/bt/esp_ble_mesh/core/transport.c index bb3575e6f76..88a6158b89e 100644 --- a/components/bt/esp_ble_mesh/core/transport.c +++ b/components/bt/esp_ble_mesh/core/transport.c @@ -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; diff --git a/components/bt/esp_ble_mesh/core/transport.enh.c b/components/bt/esp_ble_mesh/core/transport.enh.c index 434ec0c73a2..318b21bb099 100644 --- a/components/bt/esp_ble_mesh/core/transport.enh.c +++ b/components/bt/esp_ble_mesh/core/transport.enh.c @@ -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; diff --git a/components/bt/esp_ble_mesh/models/client/client_common.c b/components/bt/esp_ble_mesh/models/client/client_common.c index d10aa244a3d..5917b69cdf7 100644 --- a/components/bt/esp_ble_mesh/models/client/client_common.c +++ b/components/bt/esp_ble_mesh/models/client/client_common.c @@ -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 &&