feat(ble_mesh): Miscellaneous log enhancement for BLE Mesh

This commit is contained in:
Liu Linyan
2025-11-13 17:12:09 +08:00
committed by luoxu
parent fbf0e15694
commit b73eb03d88
38 changed files with 3815 additions and 1396 deletions
@@ -16,7 +16,7 @@
#if CONFIG_BLE_MESH_V11_SUPPORT
#include "mesh_v1.1/utils.h"
#endif
#endif /* CONFIG_BLE_MESH_V11_SUPPORT */
#define HCI_TIME_FOR_START_ADV K_MSEC(5) /* Three adv related hci commands may take 4 ~ 5ms */
@@ -25,9 +25,13 @@ static bt_mesh_client_node_t *client_pick_node(sys_slist_t *list, uint16_t tx_ds
bt_mesh_client_node_t *node = NULL;
sys_snode_t *cur = NULL;
BT_DBG("ClientPickNode, Dst 0x%04x", tx_dst);
bt_mesh_list_lock();
if (sys_slist_is_empty(list)) {
bt_mesh_list_unlock();
BT_DBG("ListEmpty");
return NULL;
}
@@ -36,22 +40,28 @@ static bt_mesh_client_node_t *client_pick_node(sys_slist_t *list, uint16_t tx_ds
node = (bt_mesh_client_node_t *)cur;
if (node->ctx.addr == tx_dst) {
bt_mesh_list_unlock();
BT_DBG("ListNodeFound");
return node;
}
}
bt_mesh_list_unlock();
BT_DBG("ListNodeNotFound");
return NULL;
}
bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf, bool need_pub)
struct net_buf_simple *buf,
bool need_pub)
{
bt_mesh_client_internal_data_t *data = NULL;
bt_mesh_client_user_data_t *cli = NULL;
bt_mesh_client_node_t *node = NULL;
BT_DBG("ClientRecvPublishMsg");
if (!model || !ctx || !buf) {
BT_ERR("%s, Invalid parameter", __func__);
return NULL;
@@ -63,22 +73,25 @@ bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(struct bt_mesh_model *
return NULL;
}
/** If the received message address is not a unicast address,
* the address may be a group/virtual address, and we push
* this message to the application layer.
BT_DBG("Src 0x%04x Dst 0x%04x RecvOp 0x%08lx",
ctx->addr, ctx->recv_dst, ctx->recv_op);
/* If the received message address is not a unicast address,
* the address may be a group/virtual address, and we push
* this message to the application layer.
*/
if (!BLE_MESH_ADDR_IS_UNICAST(ctx->recv_dst)) {
BT_DBG("Unexpected status message 0x%08x", ctx->recv_op);
BT_DBG("MsgToNonUnicastDst");
if (cli->publish_status && need_pub) {
cli->publish_status(ctx->recv_op, model, ctx, buf);
}
return NULL;
}
/** If the source address of the received status message is
* different with the destination address of the sending
* message, then the message is from another element and
* push it to application layer.
/* If the source address of the received status message is
* different with the destination address of the sending
* message, then the message is from another element and
* push it to application layer.
*/
data = (bt_mesh_client_internal_data_t *)cli->internal_data;
if (!data) {
@@ -87,7 +100,7 @@ bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(struct bt_mesh_model *
}
if ((node = client_pick_node(&data->queue, ctx->addr)) == NULL) {
BT_DBG("Unexpected status message 0x%08x", ctx->recv_op);
BT_DBG("MsgFromUnknownSrc");
if (cli->publish_status && need_pub) {
cli->publish_status(ctx->recv_op, model, ctx, buf);
}
@@ -95,7 +108,7 @@ bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(struct bt_mesh_model *
}
if (node->op_pending != ctx->recv_op) {
BT_DBG("Unexpected status message 0x%08x", ctx->recv_op);
BT_DBG("MsgWithUnknownOp");
if (cli->publish_status && need_pub) {
cli->publish_status(ctx->recv_op, model, ctx, buf);
}
@@ -103,7 +116,7 @@ bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(struct bt_mesh_model *
}
if (k_delayed_work_remaining_get(&node->timer) == 0) {
BT_DBG("Unexpected status message 0x%08x", ctx->recv_op);
BT_DBG("MsgWithTimerExpired");
if (cli->publish_status && need_pub) {
cli->publish_status(ctx->recv_op, model, ctx, buf);
}
@@ -116,6 +129,9 @@ bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(struct bt_mesh_model *
static uint32_t client_get_status_op(const bt_mesh_client_op_pair_t *op_pair,
int size, uint32_t opcode)
{
BT_DBG("ClientGetStatusOp");
BT_DBG("OpPair %p Size %u OpCode 0x%08lx", op_pair, size, opcode);
if (!op_pair || size == 0) {
return 0;
}
@@ -123,11 +139,14 @@ static uint32_t client_get_status_op(const bt_mesh_client_op_pair_t *op_pair,
const bt_mesh_client_op_pair_t *op = op_pair;
for (int i = 0; i < size; i++) {
if (op->cli_op == opcode) {
BT_DBG("OpCodeFound");
return op->status_op;
}
op++;
}
BT_DBG("OpCodeNotFound");
return 0;
}
@@ -139,17 +158,22 @@ static int32_t client_get_adv_duration(struct bt_mesh_msg_ctx *ctx)
/* Initialize with network transmission */
xmit = bt_mesh_net_transmit_get();
BT_DBG("ClientGetAdvDuration, Xmit 0x%02x", xmit);
if (bt_mesh_tag_immutable_cred(ctx->send_tag)) {
#if CONFIG_BLE_MESH_DF_SRV
if (ctx->send_cred == BLE_MESH_DIRECTED_CRED) {
xmit = bt_mesh_direct_net_transmit_get(); /* Directed network transmission */
BT_DBG("UseDFXmit 0x%02x", xmit);
}
#endif
#endif /* CONFIG_BLE_MESH_DF_SRV */
}
adv_int = BLE_MESH_TRANSMIT_INT(xmit);
duration = (BLE_MESH_TRANSMIT_COUNT(xmit) + 1) * (adv_int + 10);
BT_DBG("Duration %ld", (int32_t)duration);
return (int32_t)duration;
}
@@ -187,6 +211,8 @@ static int32_t client_calc_timeout(struct bt_mesh_msg_ctx *ctx,
net_buf_simple_tailroom(msg) >= BLE_MESH_MIC_LONG) ?
BLE_MESH_MIC_LONG : BLE_MESH_MIC_SHORT;
BT_DBG("NeedSeg %u MicSize %u", need_seg, mic_size);
if (need_seg) {
/* Based on the message length, calculate how many segments are needed.
* All the messages sent from here are access messages.
@@ -243,7 +269,7 @@ static void msg_send_start(uint16_t duration, int err, void *cb_data)
{
bt_mesh_client_node_t *node = cb_data;
BT_DBG("%s, duration %ums", __func__, duration);
BT_DBG("MsgSendStart, Duration %u Err %d", duration, err);
if (err) {
if (!k_delayed_work_free(&node->timer)) {
@@ -269,6 +295,8 @@ int bt_mesh_client_send_msg(bt_mesh_client_common_param_t *param,
bt_mesh_client_node_t *node = NULL;
int err = 0;
BT_DBG("ClientSendMsg, NeedAck %u", need_ack);
if (!param || !param->model || !msg) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
@@ -376,6 +404,8 @@ int bt_mesh_client_init(struct bt_mesh_model *model)
bt_mesh_client_internal_data_t *internal = NULL;
bt_mesh_client_user_data_t *client = NULL;
BT_DBG("ClientInit");
if (!model || !model->op) {
BT_ERR("Invalid vendor client model");
return -EINVAL;
@@ -413,6 +443,8 @@ int bt_mesh_client_deinit(struct bt_mesh_model *model)
{
bt_mesh_client_user_data_t *client = NULL;
BT_DBG("ClientDeinit");
if (!model) {
BT_ERR("Invalid vendor client model");
return -EINVAL;
@@ -444,6 +476,8 @@ int bt_mesh_client_free_node(bt_mesh_client_node_t *node)
bt_mesh_client_internal_data_t *internal = NULL;
bt_mesh_client_user_data_t *client = NULL;
BT_DBG("ClientFreeNode");
if (!node || !node->model) {
BT_ERR("Invalid client list item");
return -EINVAL;
@@ -461,12 +495,10 @@ int bt_mesh_client_free_node(bt_mesh_client_node_t *node)
return -EINVAL;
}
// Release the client node from the queue
bt_mesh_list_lock();
sys_slist_find_and_remove(&internal->queue, &node->client_node);
bt_mesh_list_unlock();
// Free the node
bt_mesh_free(node);
return 0;
@@ -477,6 +509,8 @@ int bt_mesh_client_clear_list(void *data)
bt_mesh_client_internal_data_t *internal = NULL;
bt_mesh_client_node_t *node = NULL;
BT_DBG("ClientClearList");
if (!data) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
@@ -485,11 +519,13 @@ int bt_mesh_client_clear_list(void *data)
internal = (bt_mesh_client_internal_data_t *)data;
bt_mesh_list_lock();
while (!sys_slist_is_empty(&internal->queue)) {
node = (void *)sys_slist_get_not_empty(&internal->queue);
k_delayed_work_free(&node->timer);
bt_mesh_free(node);
}
bt_mesh_list_unlock();
return 0;