linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonas Maes <jonas@dptechnics.com>
To: linux-bluetooth@vger.kernel.org
Cc: Jonas Maes <jonas@dptechnics.com>
Subject: [PATCH BlueZ 1/1] Fix bug where bluetooth-meshd stops sending
Date: Thu,  9 Jun 2022 11:08:32 +0200	[thread overview]
Message-ID: <20220609090832.9945-2-jonas@dptechnics.com> (raw)
In-Reply-To: <20220609090832.9945-1-jonas@dptechnics.com>

When there is a backlog of mesh packets to be sent, the packet sender
incorrectly infers that the tx worker thread is already running
and therefore needn't be invoked. As a result, the mesh daemon will
sometimes stop broadcasting while there are still packets in the queue.
It will not resume broadcasting.

This patch will invoke the tx worker thread correctly in that case.

The logic to send packets at least twice when the transmitter is idle
was slightly modified accordingly, and should behave the same way as
before.
---
 mesh/mesh-io-generic.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/mesh/mesh-io-generic.c b/mesh/mesh-io-generic.c
index 50a2a6a86..eed77a7a8 100644
--- a/mesh/mesh-io-generic.c
+++ b/mesh/mesh-io-generic.c
@@ -725,7 +725,6 @@ static bool send_tx(struct mesh_io *io, struct mesh_io_send_info *info,
 {
 	struct mesh_io_private *pvt = io->pvt;
 	struct tx_pkt *tx;
-	bool sending = false;
 
 	if (!info || !data || !len || len > sizeof(tx->pkt))
 		return false;
@@ -739,23 +738,20 @@ static bool send_tx(struct mesh_io *io, struct mesh_io_send_info *info,
 	if (info->type == MESH_IO_TIMING_TYPE_POLL_RSP)
 		l_queue_push_head(pvt->tx_pkts, tx);
 	else {
-		if (pvt->tx)
-			sending = true;
-		else
-			sending = !l_queue_isempty(pvt->tx_pkts);
-
-		l_queue_push_tail(pvt->tx_pkts, tx);
-
 		/*
 		 * If transmitter is idle, send packets at least twice to
 		 * guard against in-line cancelation of HCI command chain.
 		 */
-		if (info->type == MESH_IO_TIMING_TYPE_GENERAL && !sending &&
+		if (info->type == MESH_IO_TIMING_TYPE_GENERAL && !pvt->tx &&
+							l_queue_isempty(pvt->tx_pkts) &&
 							tx->info.u.gen.cnt == 1)
 			tx->info.u.gen.cnt++;
+
+		l_queue_push_tail(pvt->tx_pkts, tx);
 	}
 
-	if (!sending) {
+    /* If not already sending, schedule the tx worker */
+	if (!pvt->tx) {
 		l_timeout_remove(pvt->tx_timeout);
 		pvt->tx_timeout = NULL;
 		l_idle_oneshot(tx_worker, pvt, NULL);
-- 
2.34.1


  reply	other threads:[~2022-06-09  9:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-09  9:08 [PATCH BlueZ 0/1] Fix bug where bluetooth-meshd stops sending Jonas Maes
2022-06-09  9:08 ` Jonas Maes [this message]
2022-06-09 11:02   ` bluez.test.bot
2022-06-10 15:29 [PATCH BlueZ 0/1] " Jonas Maes
2022-06-10 15:29 ` [PATCH BlueZ 1/1] " Jonas Maes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220609090832.9945-2-jonas@dptechnics.com \
    --to=jonas@dptechnics.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).