From d98ddc602718dbbf4f1d46bec2fd3bb0bc0d9103 Mon Sep 17 00:00:00 2001 From: luoxu Date: Tue, 9 Sep 2025 15:31:01 +0800 Subject: [PATCH] fix(ble_mesh): resolve miscellaneous logging issues --- components/bt/esp_ble_mesh/core/adv_common.c | 55 ++++--------------- components/bt/esp_ble_mesh/core/adv_common.h | 42 ++++++++++++++ components/bt/esp_ble_mesh/core/ext_adv.c | 3 +- components/bt/esp_ble_mesh/core/friend.c | 4 +- components/bt/esp_ble_mesh/core/net.c | 4 +- components/bt/esp_ble_mesh/core/prov_pvnr.c | 2 +- .../bt/esp_ble_mesh/core/transport.enh.c | 24 ++++---- 7 files changed, 72 insertions(+), 62 deletions(-) diff --git a/components/bt/esp_ble_mesh/core/adv_common.c b/components/bt/esp_ble_mesh/core/adv_common.c index 193dcf4c43b..ff4e50ac1c8 100644 --- a/components/bt/esp_ble_mesh/core/adv_common.c +++ b/components/bt/esp_ble_mesh/core/adv_common.c @@ -158,7 +158,7 @@ int bt_mesh_adv_inst_init(enum bt_mesh_adv_inst_type inst_type, uint8_t inst_id) return -EINVAL; } - if (inst_id == BLE_MESH_ADV_INS_UNUSED) { + if (inst_id == BLE_MESH_ADV_INST_UNUSED) { BT_ERR("UnusedAdvInstID"); return -EINVAL; } @@ -181,7 +181,7 @@ int bt_mesh_adv_inst_deinit(enum bt_mesh_adv_inst_type inst_type) bt_le_ext_adv_stop(adv_insts[inst_type].id); - adv_insts[inst_type].id = BLE_MESH_ADV_INS_UNUSED; + adv_insts[inst_type].id = BLE_MESH_ADV_INST_UNUSED; #if CONFIG_BLE_MESH_SUPPORT_MULTI_ADV adv_insts[inst_type].spt_mask = 0; #endif /* CONFIG_BLE_MESH_SUPPORT_MULTI_ADV */ @@ -243,7 +243,7 @@ struct bt_mesh_adv *ext_long_relay_adv_alloc(int id, enum bt_mesh_adv_type type) #endif /* CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT */ #endif /* CONFIG_BLE_MESH_LONG_PACKET */ -struct bt_mesh_adv_type_manager *bt_mesh_adv_types_mgnt_get(enum bt_mesh_adv_type adv_type) +struct bt_mesh_adv_type_manager *bt_mesh_adv_types_mgmt_get(enum bt_mesh_adv_type adv_type) { BT_DBG("AdvTypeMgmtGet, AdvType %u", adv_type); @@ -668,21 +668,6 @@ uint16_t bt_mesh_get_stored_relay_count(void) return count; } -static ALWAYS_INLINE -uint16_t bt_mesh_relay_adv_buf_count_get(void) -{ - uint16_t relay_adv_count = 2 + CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT; - -#if CONFIG_BLE_MESH_EXT_ADV && CONFIG_BLE_MESH_RELAY - relay_adv_count += CONFIG_BLE_MESH_EXT_RELAY_ADV_BUF_COUNT; -#endif - -#if CONFIG_BLE_MESH_LONG_PACKET && CONFIG_BLE_MESH_RELAY - relay_adv_count += CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT; -#endif - return relay_adv_count; -} - void bt_mesh_relay_adv_init(void) { BT_DBG("RelayAdvInit"); @@ -806,33 +791,6 @@ void bt_mesh_frnd_adv_deinit(void) } #endif /* CONFIG_BLE_MESH_FRIEND */ -static ALWAYS_INLINE -uint16_t bt_mesh_adv_buf_count_get(void) -{ - uint16_t adv_count = 2 + CONFIG_BLE_MESH_ADV_BUF_COUNT; - -#if CONFIG_BLE_MESH_EXT_ADV - adv_count += CONFIG_BLE_MESH_EXT_ADV_BUF_COUNT; -#if !CONFIG_BLE_MESH_RELAY_ADV_BUF && CONFIG_BLE_MESH_RELAY - adv_count += CONFIG_BLE_MESH_EXT_RELAY_ADV_BUF_COUNT; -#endif /* !CONFIG_BLE_MESH_RELAY_ADV_BUF && CONFIG_BLE_MESH_RELAY */ -#endif /* CONFIG_BLE_MESH_EXT_ADV */ - -#if CONFIG_BLE_MESH_LONG_PACKET - adv_count += CONFIG_BLE_MESH_LONG_PACKET_ADV_BUF_COUNT; -#if !CONFIG_BLE_MESH_RELAY_ADV_BUF && CONFIG_BLE_MESH_RELAY - adv_count += CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT; -#endif /* !CONFIG_BLE_MESH_RELAY_ADV_BUF && CONFIG_BLE_MESH_RELAY */ -#endif /* CONFIG_BLE_MESH_LONG_PACKET */ - -#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; -} - void bt_mesh_adv_task_init(void adv_thread(void *p)) { BT_DBG("AdvTaskInit"); @@ -861,7 +819,14 @@ void bt_mesh_adv_task_init(void adv_thread(void *p)) #else /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && (CONFIG_SPIRAM_CACHE_WORKAROUND || !CONFIG_IDF_TARGET_ESP32) && CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY */ int ret = xTaskCreatePinnedToCore(adv_thread, BLE_MESH_ADV_TASK_NAME, BLE_MESH_ADV_TASK_STACK_SIZE, NULL, BLE_MESH_ADV_TASK_PRIO, &adv_task.handle, BLE_MESH_ADV_TASK_CORE); +#if CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE + if (ret != pdTRUE) { + BT_ERR("xTaskCreatePinnedToCore failed, ret %d", ret); + return; + } +#else assert(ret == pdTRUE); +#endif /* CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_DISABLE */ #endif /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && (CONFIG_SPIRAM_CACHE_WORKAROUND || !CONFIG_IDF_TARGET_ESP32) && CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY */ } diff --git a/components/bt/esp_ble_mesh/core/adv_common.h b/components/bt/esp_ble_mesh/core/adv_common.h index f77079a648e..54267ee5222 100644 --- a/components/bt/esp_ble_mesh/core/adv_common.h +++ b/components/bt/esp_ble_mesh/core/adv_common.h @@ -298,6 +298,21 @@ void bt_mesh_adv_inst_type_clear(enum bt_mesh_adv_inst_type inst_type, #endif /* CONFIG_BLE_MESH_SUPPORT_MULTI_ADV */ #if CONFIG_BLE_MESH_RELAY_ADV_BUF +static ALWAYS_INLINE +uint16_t bt_mesh_relay_adv_buf_count_get(void) +{ + uint16_t relay_adv_count = 2 + CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT; + +#if CONFIG_BLE_MESH_EXT_ADV && CONFIG_BLE_MESH_RELAY + relay_adv_count += CONFIG_BLE_MESH_EXT_RELAY_ADV_BUF_COUNT; +#endif + +#if CONFIG_BLE_MESH_LONG_PACKET && CONFIG_BLE_MESH_RELAY + relay_adv_count += CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT; +#endif + return relay_adv_count; +} + void bt_mesh_relay_adv_init(void); bool bt_mesh_ignore_relay_packet(uint32_t timestamp); @@ -325,6 +340,33 @@ void bt_mesh_frnd_adv_deinit(void); #endif /* CONFIG_BLE_MESH_DEINIT */ #endif /* CONFIG_BLE_MESH_FRIEND */ +static ALWAYS_INLINE +uint16_t bt_mesh_adv_buf_count_get(void) +{ + uint16_t adv_count = 2 + CONFIG_BLE_MESH_ADV_BUF_COUNT; + +#if CONFIG_BLE_MESH_EXT_ADV + adv_count += CONFIG_BLE_MESH_EXT_ADV_BUF_COUNT; +#if !CONFIG_BLE_MESH_RELAY_ADV_BUF && CONFIG_BLE_MESH_RELAY + adv_count += CONFIG_BLE_MESH_EXT_RELAY_ADV_BUF_COUNT; +#endif /* !CONFIG_BLE_MESH_RELAY_ADV_BUF && CONFIG_BLE_MESH_RELAY */ +#endif /* CONFIG_BLE_MESH_EXT_ADV */ + +#if CONFIG_BLE_MESH_LONG_PACKET + adv_count += CONFIG_BLE_MESH_LONG_PACKET_ADV_BUF_COUNT; +#if !CONFIG_BLE_MESH_RELAY_ADV_BUF && CONFIG_BLE_MESH_RELAY + adv_count += CONFIG_BLE_MESH_LONG_PACKET_RELAY_ADV_BUF_COUNT; +#endif /* !CONFIG_BLE_MESH_RELAY_ADV_BUF && CONFIG_BLE_MESH_RELAY */ +#endif /* CONFIG_BLE_MESH_LONG_PACKET */ + +#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; +} + void bt_mesh_adv_task_init(void adv_thread(void *p)); void bt_mesh_adv_common_init(void); diff --git a/components/bt/esp_ble_mesh/core/ext_adv.c b/components/bt/esp_ble_mesh/core/ext_adv.c index 37000ce73ef..8b85076aedb 100644 --- a/components/bt/esp_ble_mesh/core/ext_adv.c +++ b/components/bt/esp_ble_mesh/core/ext_adv.c @@ -142,7 +142,8 @@ static int adv_send(struct bt_mesh_adv_inst *inst, uint16_t *adv_duration) err = bt_le_ext_adv_start(inst->id, ¶m, &ad, 1, NULL, 0); } - break; + } + break; #if CONFIG_BLE_MESH_SUPPORT_BLE_ADV case BLE_MESH_ADV_BLE: diff --git a/components/bt/esp_ble_mesh/core/friend.c b/components/bt/esp_ble_mesh/core/friend.c index 41cafbf9e0d..e31810e2632 100644 --- a/components/bt/esp_ble_mesh/core/friend.c +++ b/components/bt/esp_ble_mesh/core/friend.c @@ -813,7 +813,7 @@ int bt_mesh_friend_sub_rem(struct bt_mesh_net_rx *rx, static void enqueue_buf(struct bt_mesh_friend *frnd, struct net_buf *buf) { - BT_DBG("EnqueueBuf, Buf %p QueueSize %u", __func__, buf, frnd->queue_size); + BT_DBG("EnqueueBuf, Buf %p QueueSize %u", buf, frnd->queue_size); net_buf_slist_put(&frnd->queue, buf); frnd->queue_size++; @@ -823,7 +823,7 @@ static void enqueue_update(struct bt_mesh_friend *frnd, uint8_t md) { struct net_buf *buf = NULL; - BT_DBG("EnqueueUpdate, LPN 0x%04x MD %u", __func__, frnd->lpn, md); + BT_DBG("EnqueueUpdate, LPN 0x%04x MD %u", frnd->lpn, md); buf = encode_update(frnd, md); if (!buf) { diff --git a/components/bt/esp_ble_mesh/core/net.c b/components/bt/esp_ble_mesh/core/net.c index b35a43ef32f..209b0fdabd5 100644 --- a/components/bt/esp_ble_mesh/core/net.c +++ b/components/bt/esp_ble_mesh/core/net.c @@ -104,7 +104,7 @@ static bool check_dup(struct net_buf_simple *data) } } - BT_DBG("DupCacheAdd, CacheNext %ld", val, dup_cache_next); + BT_DBG("DupCacheAdd, CacheNext %ld %d", val, dup_cache_next); dup_cache[dup_cache_next++] = val; dup_cache_next %= ARRAY_SIZE(dup_cache); @@ -2013,7 +2013,7 @@ void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi, net_buf_simple_save(&buf, &state); BT_DBG("NetRecv, Src 0x%04x Dst 0x%04x Rssi %d NetIf %u", - rx->ctx.addr, rx->ctx.recv_dst, rx->ctx.recv_rssi, net_if); + rx.ctx.addr, rx.ctx.recv_dst, rx.ctx.recv_rssi, net_if); BT_BQB(BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_NODE | \ BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_NET, diff --git a/components/bt/esp_ble_mesh/core/prov_pvnr.c b/components/bt/esp_ble_mesh/core/prov_pvnr.c index e51c7a8d1d4..d1df4a69e11 100644 --- a/components/bt/esp_ble_mesh/core/prov_pvnr.c +++ b/components/bt/esp_ble_mesh/core/prov_pvnr.c @@ -2812,7 +2812,7 @@ static void protocol_timeout(struct k_work *work) { struct bt_mesh_prov_link *link = work->user_data; - BT_WARN("Protocol timeout,LinkId:%08x", link->link_id); + BT_WARN("Protocol timeout,RmtAddr:%s", bt_hex(link->addr.val, 6)); close_link(link, CLOSE_REASON_TIMEOUT); } diff --git a/components/bt/esp_ble_mesh/core/transport.enh.c b/components/bt/esp_ble_mesh/core/transport.enh.c index 3baca3e6532..00caddac31a 100644 --- a/components/bt/esp_ble_mesh/core/transport.enh.c +++ b/components/bt/esp_ble_mesh/core/transport.enh.c @@ -2005,11 +2005,14 @@ static struct seg_rx *seg_rx_alloc(struct bt_mesh_net_rx *net_rx, { int err = 0; +<<<<<<< HEAD <<<<<<< HEAD for (size_t i = 0; i < ARRAY_SIZE(seg_rx); i++) { struct seg_rx *rx = &seg_rx[i]; ======= <<<<<<< HEAD +======= +>>>>>>> 9fc4381f187 (fix(ble_mesh): resolve miscellaneous logging issues) /* By default, traditional seg_rx is used for allocation. * If the first segment received is the last segment of * the long packet, and its length is the length of the traditional packet, @@ -2029,13 +2032,15 @@ static struct seg_rx *seg_rx_alloc(struct bt_mesh_net_rx *net_rx, for (size_t i = 0; i < rx_buf_size; i++) { struct seg_rx *rx = &seg_rx_buf[i]; -======= - BT_DBG("SegRxAlloc, SegN %u", seg_n); +<<<<<<< HEAD for (size_t i = 0; i < ARRAY_SIZE(seg_rx); i++) { struct seg_rx *rx = &seg_rx[i]; >>>>>>> 7652269a401 (feat(ble_mesh): Miscellaneous log enhancement for BLE Mesh) >>>>>>> bdcd87e62fa (feat(ble_mesh): Miscellaneous log enhancement for BLE Mesh) +======= + BT_DBG("SegRxAlloc, SegN %u", seg_n); +>>>>>>> 9fc4381f187 (fix(ble_mesh): resolve miscellaneous logging issues) if (rx->in_use) { continue; @@ -2253,27 +2258,29 @@ found_rx: /* Set the expected final buffer length */ rx->buf.len = seg_n * seg_len(rx->ctl) + buf->len; +<<<<<<< HEAD <<<<<<< HEAD BT_DBG("Target len %u * %u + %u = %u", seg_n, seg_len(rx->ctl), ======= <<<<<<< HEAD +======= +>>>>>>> 9fc4381f187 (fix(ble_mesh): resolve miscellaneous logging issues) BT_DBG("Target len %u * %u + %u = %u", seg_n, seg_len(&si), >>>>>>> bdcd87e62fa (feat(ble_mesh): Miscellaneous log enhancement for BLE Mesh) buf->len, rx->buf.len); -======= - BT_DBG("Target len %u * %u + %u = %u", - seg_n, seg_len(rx->ctl), buf->len, rx->buf.len); ->>>>>>> 7652269a401 (feat(ble_mesh): Miscellaneous log enhancement for BLE Mesh) /* This should not happen, since we have made sure the whole * SDU could be received while handling the first segment. * But if the peer device sends the segments of a segmented * message with different CTL, then the following could happen. */ +<<<<<<< HEAD <<<<<<< HEAD if (rx->buf.len > CONFIG_BLE_MESH_RX_SDU_MAX) { ======= <<<<<<< HEAD +======= +>>>>>>> 9fc4381f187 (fix(ble_mesh): resolve miscellaneous logging issues) if ((!rx->ext && rx->buf.len > CONFIG_BLE_MESH_RX_SDU_MAX) #if CONFIG_BLE_MESH_LONG_PACKET || (rx->ext && rx->buf.len > BLE_MESH_EXT_RX_SDU_MAX) @@ -2282,11 +2289,6 @@ found_rx: >>>>>>> bdcd87e62fa (feat(ble_mesh): Miscellaneous log enhancement for BLE Mesh) BT_ERR("Too large SDU len %u/%u", rx->buf.len, CONFIG_BLE_MESH_RX_SDU_MAX); -======= - if (rx->buf.len > CONFIG_BLE_MESH_RX_SDU_MAX) { - BT_ERR("Too large SDU len %u/%u", - rx->buf.len, CONFIG_BLE_MESH_RX_SDU_MAX); ->>>>>>> 7652269a401 (feat(ble_mesh): Miscellaneous log enhancement for BLE Mesh) send_ack(net_rx->sub, net_rx->ctx.recv_dst, net_rx->ctx.addr, net_rx->ctx.send_ttl,