Linux bluetooth development
 help / color / mirror / Atom feed
From: Simon Mikuda <simon.mikuda@streamunlimited.com>
To: linux-bluetooth@vger.kernel.org
Cc: Simon Mikuda <simon.mikuda@streamunlimited.com>
Subject: [PATCH BlueZ 1/3] l2test: Size frames to the channel's current MTU
Date: Fri, 27 Nov 2026 13:27:03 +0100	[thread overview]
Message-ID: <20261127122705.2393602-2-simon.mikuda@streamunlimited.com> (raw)
In-Reply-To: <20261127122705.2393602-1-simon.mikuda@streamunlimited.com>

Without -b, a frame was as large as the output MTU at connection time.
An enhanced credit based channel can be reconfigured to a larger MTU
later, so each frame is now as large as BT_SNDMTU says when it is sent.

Assisted-by: Claude:claude-opus-5-5
---
 tools/l2test.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/tools/l2test.c b/tools/l2test.c
index d7a52fe0d..dbfeae50a 100644
--- a/tools/l2test.c
+++ b/tools/l2test.c
@@ -1059,8 +1059,24 @@ static void recv_mode(int sk)
 	}
 }
 
+/* The channel's MTU now: the peer may have reconfigured it since connection
+ * (enhanced credit based mode).
+ */
+static int current_omtu(int sk)
+{
+	uint16_t mtu;
+	socklen_t len = sizeof(mtu);
+
+	if (getsockopt(sk, SOL_BLUETOOTH, BT_SNDMTU, &mtu, &len) < 0 || !mtu)
+		return omtu;
+
+	return mtu > buffer_size ? buffer_size : mtu;
+}
+
 static void do_send(int sk)
 {
+	/* Without -b each frame is as large as the channel's MTU */
+	bool follow_mtu = data_size < 0;
 	uint32_t seq;
 	int i, fd, len, buflen, size, sent;
 
@@ -1096,7 +1112,7 @@ static void do_send(int sk)
 		close(fd);
 		return;
 	} else {
-		for (i = 6; i < data_size; i++)
+		for (i = 6; i < buffer_size; i++)
 			buf[i] = 0x7f;
 	}
 
@@ -1105,6 +1121,9 @@ static void do_send(int sk)
 
 	seq = seq_start;
 	while ((num_frames == -1) || (num_frames-- > 0)) {
+		if (follow_mtu)
+			data_size = omtu = current_omtu(sk);
+
 		put_le32(seq, buf);
 		put_le16(data_size, buf + 4);
 
-- 
2.43.0


  reply	other threads:[~2026-11-27 12:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 12:27 [PATCH BlueZ 0/3] l2test: Several ECFC channels and sends on demand Simon Mikuda
2026-11-27 12:27 ` Simon Mikuda [this message]
2026-11-27 15:47   ` bluez.test.bot
2026-11-27 12:27 ` [PATCH BlueZ 2/3] l2test: Add -j to send a burst for each line on stdin Simon Mikuda
2026-11-27 12:27 ` [PATCH BlueZ 3/3] l2test: Add -k to open several enhanced credit based channels Simon Mikuda

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=20261127122705.2393602-2-simon.mikuda@streamunlimited.com \
    --to=simon.mikuda@streamunlimited.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