From 0f87363e3ece0ecbe2a421a25d5d3d303a270237 Mon Sep 17 00:00:00 2001 From: luoxu Date: Wed, 21 Dec 2022 14:43:58 +0800 Subject: [PATCH 1/5] ble_mesh: stack: for the case MESH/PVNR/PBADV/BV-01, add the close link reason before reset link --- components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c index 9f039132d0..8ff6ce83ce 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c @@ -2725,6 +2725,11 @@ static void prov_retransmit(struct k_work *work) #endif if (k_uptime_get() - link[idx].tx.start > timeout) { BT_WARN("Provisioner timeout, giving up transaction"); + /** + * For the case MESH/PVNR/PBADV/BV-01, provisoner should + * sends link close with reason. + */ + close_link(idx,CLOSE_REASON_TIMEOUT); reset_link(idx, CLOSE_REASON_TIMEOUT); return; } From d63200c0b479839e9ff567023eb0205c04300143 Mon Sep 17 00:00:00 2001 From: luoxu Date: Fri, 30 Dec 2022 16:15:37 +0800 Subject: [PATCH 2/5] ble_mesh: stack: add send transaction ack befor provisioner send prov failed msg --- components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c index 8ff6ce83ce..41e358c903 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c @@ -2871,6 +2871,12 @@ static void prov_msg_recv(const uint8_t idx) return; fail: + /** + * FOR the case MESH/PVNR/PROV/BV-10-C and MESH/PVNR/PROV/BI-14-C + * Provisioner should send transaction ack before closing the link + */ + gen_prov_ack_send(idx, link[idx].rx.trans_id); + close_link(idx, CLOSE_REASON_FAILED); return; } From d63bcc75a4b592a3f8d05afe9deb883d8a5f0695 Mon Sep 17 00:00:00 2001 From: luoxu Date: Fri, 30 Dec 2022 11:27:29 +0800 Subject: [PATCH 3/5] ble_mesh: stack: forward rfu dst for the case NODE/RLY/BV-01 --- components/bt/esp_ble_mesh/mesh_core/net.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/bt/esp_ble_mesh/mesh_core/net.c b/components/bt/esp_ble_mesh/mesh_core/net.c index d202b6db2f..c87eab38e0 100644 --- a/components/bt/esp_ble_mesh/mesh_core/net.c +++ b/components/bt/esp_ble_mesh/mesh_core/net.c @@ -1387,10 +1387,12 @@ int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if, } /* For case MESH/NODE/RLY/BV-01-C, even the DST is RFU, it needs to be forwarded. */ +#if !CONFIG_BLE_MESH_BQB_TEST if (BLE_MESH_ADDR_IS_RFU(rx->ctx.recv_dst)) { BT_ERR("Destination address is RFU; dropping packet 0x%02x", rx->ctx.recv_dst); return -EBADMSG; } +#endif if (net_if != BLE_MESH_NET_IF_LOCAL && bt_mesh_elem_find(rx->ctx.addr)) { BT_DBG("Dropping locally originated packet"); From 353eade320c20d3d8e5589e869e0500e8b5b44d1 Mon Sep 17 00:00:00 2001 From: wangjialiang Date: Wed, 15 Mar 2023 17:50:46 +0800 Subject: [PATCH 4/5] ble_mesh: add BQB LOG --- components/bt/esp_ble_mesh/mesh_core/cfg_srv.c | 6 ++++++ components/bt/esp_ble_mesh/mesh_core/net.c | 5 +++++ .../bt/esp_ble_mesh/mesh_core/provisioner_prov.c | 4 ++-- .../bt/esp_ble_mesh/mesh_core/proxy_server.c | 2 ++ components/bt/esp_ble_mesh/mesh_core/transport.c | 16 ++++++++++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c b/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c index 2818936d91..1cbb569ee6 100644 --- a/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c +++ b/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c @@ -1464,6 +1464,9 @@ static void mod_sub_add(struct bt_mesh_model *model, goto send_status; } + BT_BQB(BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_NODE | BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_TNPT, + "SubGroupAddr: 0x%x", sub_addr); + for (i = 0; i < ARRAY_SIZE(mod->groups); i++) { if (mod->groups[i] == BLE_MESH_ADDR_UNASSIGNED) { mod->groups[i] = sub_addr; @@ -1865,6 +1868,9 @@ static void mod_sub_va_add(struct bt_mesh_model *model, goto send_status; } + BT_BQB(BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_NODE | BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_TNPT, + "SubVirtualAddr: 0x%x", sub_addr); + for (i = 0; i < ARRAY_SIZE(mod->groups); i++) { if (mod->groups[i] == BLE_MESH_ADDR_UNASSIGNED) { mod->groups[i] = sub_addr; diff --git a/components/bt/esp_ble_mesh/mesh_core/net.c b/components/bt/esp_ble_mesh/mesh_core/net.c index c87eab38e0..2ca480f186 100644 --- a/components/bt/esp_ble_mesh/mesh_core/net.c +++ b/components/bt/esp_ble_mesh/mesh_core/net.c @@ -1472,6 +1472,11 @@ void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi, /* Save the state so the buffer can later be relayed */ net_buf_simple_save(&buf, &state); + BT_BQB(BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_NODE | BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_NET, + "\nNetRecv: ctl: %d, src: %d, dst: %d, ttl: %d, data: 0x%s", + CTL(buf.data), SRC(buf.data), DST(buf.data), TTL(buf.data), + bt_hex(buf.data + BLE_MESH_NET_HDR_LEN, buf.len - BLE_MESH_NET_HDR_LEN)); + rx.local_match = (bt_mesh_fixed_group_match(rx.ctx.recv_dst) || bt_mesh_elem_find(rx.ctx.recv_dst)); diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c index 41e358c903..c98e4902dd 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c @@ -2872,8 +2872,8 @@ static void prov_msg_recv(const uint8_t idx) fail: /** - * FOR the case MESH/PVNR/PROV/BV-10-C and MESH/PVNR/PROV/BI-14-C - * Provisioner should send transaction ack before closing the link + * For the case MESH/PVNR/PROV/BV-10-C and MESH/PVNR/PROV/BI-14-C, + * provisioner should send transaction ack before closing the link. */ gen_prov_ack_send(idx, link[idx].rx.trans_id); diff --git a/components/bt/esp_ble_mesh/mesh_core/proxy_server.c b/components/bt/esp_ble_mesh/mesh_core/proxy_server.c index 55cecd32e1..897c18005b 100644 --- a/components/bt/esp_ble_mesh/mesh_core/proxy_server.c +++ b/components/bt/esp_ble_mesh/mesh_core/proxy_server.c @@ -22,9 +22,11 @@ #if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_SERVER +#if !CONFIG_BLE_MESH_BQB_TEST /* Not support enabling Proxy Client and Proxy Server simultaneously */ _Static_assert(!(IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)), "Not support Proxy Server and Proxy Client simultaneously"); +#endif #define PDU_TYPE(data) (data[0] & BIT_MASK(6)) #define PDU_SAR(data) (data[0] >> 6) diff --git a/components/bt/esp_ble_mesh/mesh_core/transport.c b/components/bt/esp_ble_mesh/mesh_core/transport.c index 5f127e4f0f..7d3f45310d 100644 --- a/components/bt/esp_ble_mesh/mesh_core/transport.c +++ b/components/bt/esp_ble_mesh/mesh_core/transport.c @@ -782,6 +782,11 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, uint32_t seq, uint8_t hdr, continue; } + BT_BQB(BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_NODE | BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_TNPT, + "\nTNPTRecv: ctl: 0x%04x, ttl: 0x%04x, src: 0x%04x, dst: 0x%04x, payload: 0x%s", + rx->ctl, rx->ctx.recv_ttl, rx->ctx.addr, rx->ctx.recv_dst, + bt_hex(sdu->data, sdu->len)); + rx->ctx.app_idx = BLE_MESH_KEY_DEV; bt_mesh_model_recv(rx, sdu); @@ -827,6 +832,12 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, uint32_t seq, uint8_t hdr, sdu, ad, rx->ctx.addr, rx->ctx.recv_dst, seq, BLE_MESH_NET_IVI_RX(rx)); + + BT_BQB(BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_NODE | BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_TNPT, + "\nTNPTRecv: ctl: 0x%04x, ttl: 0x%04x, src: 0x%04x, dst: 0x%04x, payload: 0x%s", + rx->ctl, rx->ctx.recv_ttl, rx->ctx.addr, rx->ctx.recv_dst, + bt_hex(sdu->data, sdu->len)); + if (err) { BT_DBG("Unable to decrypt with AppKey 0x%03x", key->app_idx); @@ -997,6 +1008,11 @@ static int ctl_recv(struct bt_mesh_net_rx *rx, uint8_t hdr, BT_DBG("OpCode 0x%02x len %u", ctl_op, buf->len); + BT_BQB(BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_NODE | BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_TNPT, + "\nTNPTRecv: ctl: 0x%04x, ttl: 0x%04x, src: 0x%04x, dst: 0x%04x, payload: 0x%s", + rx->ctl, rx->ctx.recv_ttl, rx->ctx.addr, rx->ctx.recv_dst, + bt_hex(buf->data, buf->len)); + switch (ctl_op) { case TRANS_CTL_OP_ACK: return trans_ack(rx, hdr, buf, seq_auth); From f92ee6d70b7cf807b17cb9acd0256c965f410a1d Mon Sep 17 00:00:00 2001 From: lly Date: Thu, 23 Mar 2023 10:26:23 +0800 Subject: [PATCH 5/5] ble_mesh: stack: Minor fix for provisioner provisioning timeout --- components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c index c98e4902dd..fb2d2bd019 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c @@ -2725,12 +2725,8 @@ static void prov_retransmit(struct k_work *work) #endif if (k_uptime_get() - link[idx].tx.start > timeout) { BT_WARN("Provisioner timeout, giving up transaction"); - /** - * For the case MESH/PVNR/PBADV/BV-01, provisoner should - * sends link close with reason. - */ - close_link(idx,CLOSE_REASON_TIMEOUT); - reset_link(idx, CLOSE_REASON_TIMEOUT); + /* Provisioner should send Link Close here */ + close_link(idx, CLOSE_REASON_TIMEOUT); return; }