linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ 0/3] l2test: Several ECFC channels and sends on demand
@ 2026-11-27 12:27 Simon Mikuda
  2026-11-27 12:27 ` [PATCH BlueZ 1/3] l2test: Size frames to the channel's current MTU Simon Mikuda
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Simon Mikuda @ 2026-11-27 12:27 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Simon Mikuda

These let l2test drive the PTS L2CAP/ECFC cases that need several
channels in one request, or data sent after the tester reconfigured the
channel, which a single l2test channel with a fixed frame size cannot.

Simon Mikuda (3):
  l2test: Size frames to the channel's current MTU
  l2test: Add -j to send a burst for each line on stdin
  l2test: Add -k to open several enhanced credit based channels

 tools/l2test.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 83 insertions(+), 5 deletions(-)


base-commit: 79162c1089110c896cb48118c3f7eb0db1fa0f2b
-- 
2.43.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH BlueZ 1/3] l2test: Size frames to the channel's current MTU
  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
  2026-11-27 15:47   ` l2test: Several ECFC channels and sends on demand 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
  2 siblings, 1 reply; 5+ messages in thread
From: Simon Mikuda @ 2026-11-27 12:27 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Simon Mikuda

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH BlueZ 2/3] l2test: Add -j to send a burst for each line on stdin
  2026-11-27 12:27 [PATCH BlueZ 0/3] l2test: Several ECFC channels and sends on demand Simon Mikuda
  2026-11-27 12:27 ` [PATCH BlueZ 1/3] l2test: Size frames to the channel's current MTU Simon Mikuda
@ 2026-11-27 12:27 ` Simon Mikuda
  2026-11-27 12:27 ` [PATCH BlueZ 3/3] l2test: Add -k to open several enhanced credit based channels Simon Mikuda
  2 siblings, 0 replies; 5+ messages in thread
From: Simon Mikuda @ 2026-11-27 12:27 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Simon Mikuda

With -j, a sending mode waits for a line on stdin before each burst
and sends as many frames as the line says, or -N's when it has no
number. A tester can then ask for data when it is ready for it, for
example after it reconfigured the channel:

    echo 2 | l2test -w -X ext-flowctl -V le_public -j

Assisted-by: Claude:claude-opus-5-5
---
 tools/l2test.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/tools/l2test.c b/tools/l2test.c
index dbfeae50a..e0149c89e 100644
--- a/tools/l2test.c
+++ b/tools/l2test.c
@@ -120,6 +120,7 @@ static int linger = 0;
 static int reliable = 0;
 static int timestamp = 0;
 static int defer_setup = 0;
+static bool stdin_frames;
 static int priority = -1;
 static int rcvbuf = 0;
 static int32_t phy = -1;
@@ -1078,7 +1079,7 @@ 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;
+	int i, fd, len, buflen, size, sent, burst;
 
 	syslog(LOG_INFO, "Sending ...");
 
@@ -1120,6 +1121,19 @@ static void do_send(int sk)
 		usleep(send_delay);
 
 	seq = seq_start;
+	burst = num_frames;
+
+next_burst:
+	/* With -j, a burst for each line: its number of frames, -N's without */
+	if (stdin_frames) {
+		char line[16];
+
+		if (!fgets(line, sizeof(line), stdin))
+			return;
+
+		num_frames = atoi(line) > 0 ? atoi(line) : burst;
+	}
+
 	while ((num_frames == -1) || (num_frames-- > 0)) {
 		if (follow_mtu)
 			data_size = omtu = current_omtu(sk);
@@ -1149,6 +1163,9 @@ static void do_send(int sk)
 						!(seq % (count + seq_start)))
 			usleep(send_delay);
 	}
+
+	if (stdin_frames)
+		goto next_burst;
 }
 
 static void send_mode(int sk)
@@ -1455,6 +1472,8 @@ static void usage(void)
 	printf("Options:\n"
 		"\t[-b bytes] [-i device] [-P psm] [-J cid]\n"
 		"\t[-I imtu] [-O omtu]\n"
+		"\t[-j] send -N frames for each line on stdin (or as many as\n"
+		"\t   the line says)\n"
 		"\t[-L seconds] enable SO_LINGER\n"
 		"\t[-W seconds] enable deferred setup\n"
 		"\t   0: don't enable (default)\n"
@@ -1493,7 +1512,7 @@ int main(int argc, char *argv[])
 
 	bacpy(&bdaddr, BDADDR_ANY);
 
-	while ((opt = getopt(argc, argv, "a:b:cde:f:g:i:mnpqrstuwxyz"
+	while ((opt = getopt(argc, argv, "a:b:cde:f:g:i:jmnpqrstuwxyz"
 		"AB:C:D:EF:GH:I:J:K:L:MN:O:P:Q:RSTUV:W:X:Y:Z:")) != EOF) {
 		switch (opt) {
 		case 'r':
@@ -1564,6 +1583,10 @@ int main(int argc, char *argv[])
 			data_size = atoi(optarg);
 			break;
 
+		case 'j':
+			stdin_frames = true;
+			break;
+
 		case 'i':
 			if (!strncasecmp(optarg, "hci", 3))
 				hci_devba(atoi(optarg + 3), &bdaddr);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH BlueZ 3/3] l2test: Add -k to open several enhanced credit based channels
  2026-11-27 12:27 [PATCH BlueZ 0/3] l2test: Several ECFC channels and sends on demand Simon Mikuda
  2026-11-27 12:27 ` [PATCH BlueZ 1/3] l2test: Size frames to the channel's current MTU Simon Mikuda
  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 ` Simon Mikuda
  2 siblings, 0 replies; 5+ messages in thread
From: Simon Mikuda @ 2026-11-27 12:27 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Simon Mikuda

With -k num, l2test connects num channels in one
L2CAP_ECRED_CONN_REQ, or accepts num channels on one listener. The
first ones are connected with deferred setup, so the kernel puts them
into the request of the last one. The mode runs on the last channel and
the others stay open while it does.

Separate l2test processes cannot do this: the kernel only bundles the
deferred channels of one process.

    l2test -n -X ext-flowctl -V le_public -P 0x80 -k 2 <bdaddr>

Assisted-by: Claude:claude-opus-5-5
---
 tools/l2test.c | 42 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/tools/l2test.c b/tools/l2test.c
index e0149c89e..c432296a3 100644
--- a/tools/l2test.c
+++ b/tools/l2test.c
@@ -121,6 +121,7 @@ static int reliable = 0;
 static int timestamp = 0;
 static int defer_setup = 0;
 static bool stdin_frames;
+static int num_chans = 1;
 static int priority = -1;
 static int rcvbuf = 0;
 static int32_t phy = -1;
@@ -536,6 +537,11 @@ static int do_connect(char *svr)
 	struct l2cap_options opts;
 	socklen_t optlen;
 	int sk, opt;
+	/* All but the last of -k channels are deferred: the kernel puts them
+	 * into the connection request of the last one (enhanced credit based
+	 * mode), and they stay open while its mode runs.
+	 */
+	bool defer = num_chans > 1;
 
 	/* Create socket */
 	sk = socket(PF_BLUETOOTH, socktype, BTPROTO_L2CAP);
@@ -655,12 +661,31 @@ static int do_connect(char *svr)
 	else
 		goto error;
 
-	if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0 ) {
+	if (defer) {
+		opt = 1;
+		if (setsockopt(sk, SOL_BLUETOOTH, BT_DEFER_SETUP, &opt,
+							sizeof(opt)) < 0) {
+			syslog(LOG_ERR, "Can't enable deferred setup: %s (%d)",
+							strerror(errno), errno);
+			goto error;
+		}
+
+		/* Or connect() waits for a request that is not sent yet */
+		fcntl(sk, F_SETFL, fcntl(sk, F_GETFL) | O_NONBLOCK);
+	}
+
+	if (connect(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0 &&
+				!(defer && errno == EINPROGRESS)) {
 		syslog(LOG_ERR, "Can't connect: %s (%d)",
 							strerror(errno), errno);
 		goto error;
 	}
 
+	if (defer) {
+		num_chans--;
+		return do_connect(svr);
+	}
+
 	/* Get current options */
 	if (getopts(sk, &opts, true) < 0) {
 		syslog(LOG_ERR, "Can't get L2CAP options: %s (%d)",
@@ -686,7 +711,7 @@ static void do_listen(void (*handler)(int sk))
 	struct sockaddr_l2 addr;
 	struct l2cap_options opts;
 	socklen_t optlen;
-	int sk, nsk, opt;
+	int sk, nsk, opt, accepted = 0;
 
 	/* Create socket */
 	sk = socket(PF_BLUETOOTH, socktype, BTPROTO_L2CAP);
@@ -807,6 +832,11 @@ static void do_listen(void (*handler)(int sk))
 							strerror(errno), errno);
 			goto error;
 		}
+
+		/* The first -k channels stay open, the mode runs on the last */
+		if (++accepted < num_chans)
+			continue;
+
 		if (fork()) {
 			/* Parent */
 			close(nsk);
@@ -1474,6 +1504,8 @@ static void usage(void)
 		"\t[-I imtu] [-O omtu]\n"
 		"\t[-j] send -N frames for each line on stdin (or as many as\n"
 		"\t   the line says)\n"
+		"\t[-k num] num channels (ext-flowctl): connected in one\n"
+		"\t   request, or accepted; the mode runs on the last one\n"
 		"\t[-L seconds] enable SO_LINGER\n"
 		"\t[-W seconds] enable deferred setup\n"
 		"\t   0: don't enable (default)\n"
@@ -1512,7 +1544,7 @@ int main(int argc, char *argv[])
 
 	bacpy(&bdaddr, BDADDR_ANY);
 
-	while ((opt = getopt(argc, argv, "a:b:cde:f:g:i:jmnpqrstuwxyz"
+	while ((opt = getopt(argc, argv, "a:b:cde:f:g:i:jk:mnpqrstuwxyz"
 		"AB:C:D:EF:GH:I:J:K:L:MN:O:P:Q:RSTUV:W:X:Y:Z:")) != EOF) {
 		switch (opt) {
 		case 'r':
@@ -1587,6 +1619,10 @@ int main(int argc, char *argv[])
 			stdin_frames = true;
 			break;
 
+		case 'k':
+			num_chans = atoi(optarg);
+			break;
+
 		case 'i':
 			if (!strncasecmp(optarg, "hci", 3))
 				hci_devba(atoi(optarg + 3), &bdaddr);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* RE: l2test: Several ECFC channels and sends on demand
  2026-11-27 12:27 ` [PATCH BlueZ 1/3] l2test: Size frames to the channel's current MTU Simon Mikuda
@ 2026-11-27 15:47   ` bluez.test.bot
  0 siblings, 0 replies; 5+ messages in thread
From: bluez.test.bot @ 2026-11-27 15:47 UTC (permalink / raw)
  To: linux-bluetooth, simon.mikuda

[-- Attachment #1: Type: text/plain, Size: 858 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1224446/

---Test result---

Test Summary:
CheckPatch                    PASS      1.10 seconds
GitLint                       PASS      0.76 seconds
BuildEll                      PASS      20.84 seconds
BluezMake                     PASS      299.06 seconds
CheckSmatch                   PASS      308.03 seconds
bluezmakeextell               PASS      98.55 seconds
TestFunctional                PASS      1187.18 seconds
IncrementalBuild              PASS      297.36 seconds
ScanBuild                     PASS      1088.35 seconds



https://github.com/bluez/bluez/pull/2938

---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-27 15:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 12:27 [PATCH BlueZ 0/3] l2test: Several ECFC channels and sends on demand Simon Mikuda
2026-11-27 12:27 ` [PATCH BlueZ 1/3] l2test: Size frames to the channel's current MTU Simon Mikuda
2026-11-27 15:47   ` l2test: Several ECFC channels and sends on demand 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

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).