All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ v2 0/8] Fix GATT over BR/EDR
@ 2026-11-25 16:58 Simon Mikuda
  2026-11-25 16:58 ` [PATCH BlueZ v2 1/8] tools/btgatt-client: Add BR/EDR support Simon Mikuda
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: Simon Mikuda @ 2026-11-25 16:58 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Simon Mikuda

We need GATT over BR/EDR to pass PTS qualification of a dual-mode
device, and bluetoothd only handled it when the remote opened ATT and
both L2CAP MTUs matched:

- the ATT_MTU was our incoming MTU instead of the smaller of the two,
  so a remote with a smaller MTU never finished discovery (2-3)
- GATT discovery marked the BR/EDR services resolved before SDP had
  finished (4)
- EATT was connected to the LE address next to a BR/EDR bearer (5)
- LE only profiles (BAP, VCP, MCP, BASS, RAP, ...) attached over
  BR/EDR (6-7)
- bluetoothd couldn't open ATT over BR/EDR itself (8): it now does on
  ConnectProfile with the GATT UUID, Connect() is unchanged

btgatt-client gets BR/EDR support (1) to reproduce the MTU case. Tested
between two BlueZ boards (Intel BE200 and Broadcom BCM4359) over BR/EDR,
next to A2DP.

Changes in v2:
- device: cancel a pending ATT connect over BR/EDR on DisconnectProfile

Simon Mikuda (8):
  tools/btgatt-client: Add BR/EDR support
  shared/att: Use the smaller L2CAP MTU as ATT MTU
  device: Don't override the ATT MTU over BR/EDR
  device: Don't resolve services on GATT over BR/EDR
  gatt-client: Don't connect EATT on an ATT bearer over BR/EDR
  profiles: Set the LE bearer for TMAP, GMAP and RAP
  device: Don't accept LE profiles over ATT on BR/EDR
  device: Connect GATT over BR/EDR with ConnectProfile

 profiles/audio/gmap.c  |   1 +
 profiles/audio/tmap.c  |   1 +
 profiles/ranging/rap.c |   1 +
 src/device.c           | 161 +++++++++++++++++++++++++++++++++++++----
 src/gatt-client.c      |   4 +
 src/shared/att.c       |  43 +++++++++--
 tools/btgatt-client.c  |  53 +++++++++++---
 7 files changed, 230 insertions(+), 34 deletions(-)


base-commit: 1608f836188610aabeff5a3164169ebe0360e443
-- 
2.43.0


^ permalink raw reply	[flat|nested] 13+ messages in thread
* [PATCH BlueZ 1/8] tools/btgatt-client: Add BR/EDR support
@ 2026-11-24 14:46 Simon Mikuda
  2026-11-24 20:44 ` Fix GATT over BR/EDR bluez.test.bot
  0 siblings, 1 reply; 13+ messages in thread
From: Simon Mikuda @ 2026-11-24 14:46 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Simon Mikuda

Add the bredr address type: btgatt-client then connects ATT over the
BR/EDR ATT PSM, and -m sets the L2CAP MTU, which is the ATT MTU there.

  btgatt-client -t bredr -d 00:11:22:33:44:55 -m 48

Assisted-by: Claude:claude-opus-5-5
---
 tools/btgatt-client.c | 53 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 42 insertions(+), 11 deletions(-)

diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
index 667b3d651..5a2f5fc09 100644
--- a/tools/btgatt-client.c
+++ b/tools/btgatt-client.c
@@ -1631,8 +1631,8 @@ static void signal_cb(int signum, void *user_data)
 	}
 }
 
-static int l2cap_le_att_connect(bdaddr_t *src, bdaddr_t *dst, uint8_t dst_type,
-									int sec)
+static int l2cap_att_connect(bdaddr_t *src, bdaddr_t *dst, uint8_t dst_type,
+							int sec, uint16_t mtu)
 {
 	int sock;
 	struct sockaddr_l2 srcaddr, dstaddr;
@@ -1644,9 +1644,10 @@ static int l2cap_le_att_connect(bdaddr_t *src, bdaddr_t *dst, uint8_t dst_type,
 		ba2str(src, srcaddr_str);
 		ba2str(dst, dstaddr_str);
 
-		printf("btgatt-client: Opening L2CAP LE connection on ATT "
-					"channel:\n\t src: %s\n\tdest: %s\n",
-					srcaddr_str, dstaddr_str);
+		printf("btgatt-client: Opening L2CAP %s connection on ATT "
+				"channel:\n\t src: %s\n\tdest: %s\n",
+				dst_type == BDADDR_BREDR ? "BR/EDR" : "LE",
+				srcaddr_str, dstaddr_str);
 	}
 
 	sock = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
@@ -1658,7 +1659,8 @@ static int l2cap_le_att_connect(bdaddr_t *src, bdaddr_t *dst, uint8_t dst_type,
 	/* Set up source address */
 	memset(&srcaddr, 0, sizeof(srcaddr));
 	srcaddr.l2_family = AF_BLUETOOTH;
-	srcaddr.l2_cid = htobs(BT_ATT_CID);
+	if (dst_type != BDADDR_BREDR)
+		srcaddr.l2_cid = htobs(BT_ATT_CID);
 	srcaddr.l2_bdaddr_type = 0;
 	bacpy(&srcaddr.l2_bdaddr, src);
 
@@ -1678,10 +1680,35 @@ static int l2cap_le_att_connect(bdaddr_t *src, bdaddr_t *dst, uint8_t dst_type,
 		return -1;
 	}
 
+	/* On BR/EDR the ATT MTU is the L2CAP MTU */
+	if (dst_type == BDADDR_BREDR && mtu) {
+		struct l2cap_options l2o;
+		socklen_t len = sizeof(l2o);
+
+		memset(&l2o, 0, sizeof(l2o));
+		if (getsockopt(sock, SOL_L2CAP, L2CAP_OPTIONS, &l2o,
+								&len) < 0) {
+			perror("Failed to get L2CAP options");
+			close(sock);
+			return -1;
+		}
+
+		l2o.imtu = mtu;
+		if (setsockopt(sock, SOL_L2CAP, L2CAP_OPTIONS, &l2o,
+								len) < 0) {
+			perror("Failed to set L2CAP MTU");
+			close(sock);
+			return -1;
+		}
+	}
+
 	/* Set up destination address */
 	memset(&dstaddr, 0, sizeof(dstaddr));
 	dstaddr.l2_family = AF_BLUETOOTH;
-	dstaddr.l2_cid = htobs(BT_ATT_CID);
+	if (dst_type == BDADDR_BREDR)
+		dstaddr.l2_psm = htobs(BT_ATT_PSM);
+	else
+		dstaddr.l2_cid = htobs(BT_ATT_CID);
 	dstaddr.l2_bdaddr_type = dst_type;
 	bacpy(&dstaddr.l2_bdaddr, dst);
 
@@ -1707,8 +1734,10 @@ static void usage(void)
 	printf("Options:\n"
 		"\t-i, --index <id>\t\tSpecify adapter index, e.g. hci0\n"
 		"\t-d, --dest <addr>\t\tSpecify the destination address\n"
-		"\t-t, --type [random|public] \tSpecify the LE address type\n"
-		"\t-m, --mtu <mtu> \t\tThe ATT MTU to use\n"
+		"\t-t, --type [random|public|bredr] \tSpecify the address "
+								"type\n"
+		"\t-m, --mtu <mtu> \t\tThe ATT MTU to use (BR/EDR: the "
+							"L2CAP MTU)\n"
 		"\t-s, --security-level <sec> \tSet security level (low|medium|"
 								"high|fips)\n"
 		"\t-v, --verbose\t\t\tEnable extra logging\n"
@@ -1783,9 +1812,11 @@ int main(int argc, char *argv[])
 				dst_type = BDADDR_LE_RANDOM;
 			else if (strcmp(optarg, "public") == 0)
 				dst_type = BDADDR_LE_PUBLIC;
+			else if (strcmp(optarg, "bredr") == 0)
+				dst_type = BDADDR_BREDR;
 			else {
 				fprintf(stderr,
-					"Allowed types: random, public\n");
+					"Allowed types: random, public, bredr\n");
 				return EXIT_FAILURE;
 			}
 			break;
@@ -1841,7 +1872,7 @@ int main(int argc, char *argv[])
 
 	mainloop_init();
 
-	fd = l2cap_le_att_connect(&src_addr, &dst_addr, dst_type, sec);
+	fd = l2cap_att_connect(&src_addr, &dst_addr, dst_type, sec, mtu);
 	if (fd < 0)
 		return EXIT_FAILURE;
 
-- 
2.43.0


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

end of thread, other threads:[~2026-12-01 16:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 16:58 [PATCH BlueZ v2 0/8] Fix GATT over BR/EDR Simon Mikuda
2026-11-25 16:58 ` [PATCH BlueZ v2 1/8] tools/btgatt-client: Add BR/EDR support Simon Mikuda
2026-11-25 23:31   ` Fix GATT over BR/EDR bluez.test.bot
2026-12-01 16:00     ` Luiz Augusto von Dentz
2026-11-25 16:59 ` [PATCH BlueZ v2 2/8] shared/att: Use the smaller L2CAP MTU as ATT MTU Simon Mikuda
2026-11-25 16:59 ` [PATCH BlueZ v2 3/8] device: Don't override the ATT MTU over BR/EDR Simon Mikuda
2026-11-25 16:59 ` [PATCH BlueZ v2 4/8] device: Don't resolve services on GATT " Simon Mikuda
2026-11-25 16:59 ` [PATCH BlueZ v2 5/8] gatt-client: Don't connect EATT on an ATT bearer " Simon Mikuda
2026-11-25 16:59 ` [PATCH BlueZ v2 6/8] profiles: Set the LE bearer for TMAP, GMAP and RAP Simon Mikuda
2026-11-25 16:59 ` [PATCH BlueZ v2 7/8] device: Don't accept LE profiles over ATT on BR/EDR Simon Mikuda
2026-11-25 16:59 ` [PATCH BlueZ v2 8/8] device: Connect GATT over BR/EDR with ConnectProfile Simon Mikuda
  -- strict thread matches above, loose matches on Subject: below --
2026-11-24 14:46 [PATCH BlueZ 1/8] tools/btgatt-client: Add BR/EDR support Simon Mikuda
2026-11-24 20:44 ` Fix GATT over BR/EDR bluez.test.bot
2026-11-25 15:07   ` Luiz Augusto von Dentz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.