From 680d778f57eed771d74e66600fbd81369330a7a2 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Tue, 13 Aug 2019 16:29:47 +0300 Subject: [PATCH] Bluetooth: Mesh: Fix not sending all segments through the Friend Queue The code was incorrectly bailing out with "return 0" rather than continue. Also, it was incorrectly making a reference to tx->seg[seg_o] since when a PDU goes through the friend queue we don't use the usual retransmission mechanism. Fixes: #17932 Signed-off-by: Johan Hedberg --- subsys/bluetooth/mesh/transport.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/subsys/bluetooth/mesh/transport.c b/subsys/bluetooth/mesh/transport.c index c9046756142..b3c14dbd572 100644 --- a/subsys/bluetooth/mesh/transport.c +++ b/subsys/bluetooth/mesh/transport.c @@ -383,8 +383,6 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu, net_buf_add_mem(seg, sdu->data, len); net_buf_simple_pull(sdu, len); - tx->seg[seg_o] = net_buf_ref(seg); - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { enum bt_mesh_friend_pdu_type type; @@ -402,10 +400,12 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu, * out through the Friend Queue. */ net_buf_unref(seg); - return 0; + continue; } } + tx->seg[seg_o] = net_buf_ref(seg); + BT_DBG("Sending %u/%u", seg_o, tx->seg_n); err = bt_mesh_net_send(net_tx, seg, @@ -418,6 +418,25 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu, } } + /* This can happen if segments only went into the Friend Queue */ + if (IS_ENABLED(CONFIG_BT_MESH_FRIEND) && !tx->seg[0]) { + seg_tx_reset(tx); + + /* If there was a callback notify sending immediately since + * there's no other way to track this (at least currently) + * with the Friend Queue. + */ + if (cb) { + if (cb->start) { + cb->start(0, 0, cb_data); + } + + if (cb->end) { + cb->end(0, cb_data); + } + } + } + if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER) && bt_mesh_lpn_established()) { bt_mesh_lpn_poll();