All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ v2 0/1] Enhanced or Legacy Accept Synchronous Connection Request command
@ 2025-12-24  6:31 Mahesh Talewad
  2025-12-24  6:31 ` [PATCH BlueZ v2 1/1] " Mahesh Talewad
  0 siblings, 1 reply; 5+ messages in thread
From: Mahesh Talewad @ 2025-12-24  6:31 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: devyani.godbole, luiz.dentz, sarveshwar.bajaj, mahesh.talewad,
	vinit.mehta

Hello Maintainers,

	In the current implementation, when Connect request for eSco is received,
	Bluez Kernel is sending 'Accept Synchronous Connection Request comand'
	[legacy command], irrespective of whether controller supports 
	enhanced synchronous connection command or not.
	
	In this PR, When Connect request for eSco is received, if controller
	supports enhanced synchronous connection command then it will go for
	'Enhanced Accept Synchronous Connection Request command' or else it will
	go for legacy command['Accept Synchronous Connection Request command'].
	
Thanks and regards,
Mahesh Vithal Talewad


Mahesh Talewad (1):
  Enhanced or Legacy Accept Synchronous Connection Request command

 include/net/bluetooth/hci.h      | 34 +++++++++++++++
 include/net/bluetooth/hci_sync.h | 13 ++++++
 net/bluetooth/hci_event.c        | 27 +++++++-----
 net/bluetooth/hci_sync.c         | 73 ++++++++++++++++++++++++++++++++
 net/bluetooth/sco.c              | 34 ++-------------
 5 files changed, 140 insertions(+), 41 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 5+ messages in thread
* [PATCH BlueZ v3 1/1] Enhanced or Legacy Accept Synchronous Connection Request command
@ 2025-12-29 10:46 Mahesh Talewad
  2025-12-29 11:08 ` bluez.test.bot
  0 siblings, 1 reply; 5+ messages in thread
From: Mahesh Talewad @ 2025-12-29 10:46 UTC (permalink / raw)
  To: linux-bluetooth
  Cc: devyani.godbole, luiz.dentz, sarveshwar.bajaj, vinit.mehta,
	mahesh.talewad

In current implementaion kernel is sending legacy sco command
['Accept Synchronous Connection Request command'] always even
though controller supports enhanced synchronous connection
command.

In this commit, we have implemented the code in such a way that
when Connect request for eSco is received, if controller supports
enhanced synchronous connection command then it will go for
'Enhanced Accept Synchronous Connection Request command' or else
it will go for legacy command['Accept Synchronous Connection
Request command'].

btmon trace:
> HCI Event: Connect Request (0x04) plen 10
		Address: 10:EC:81:61:71:67
		Class: 0x000000
		  Major class: Miscellaneous
		  Minor class: 0x00
		Link type: eSCO (0x02)
< HCI Command: Enhanced Accept Synchronous Connection
Request (0x01|0x003e) plen 63
		Address: 10:EC:81:61:71:67
		Transmit bandwidth: 8000
		Receive bandwidth: 8000
		Transmit Coding Format:
		  Codec: mSBC (0x05)
		Receive Coding Format:
		  Codec: mSBC (0x05)
		Transmit Codec Frame Size: 60
		Receive Codec Frame Size: 60
		Input Coding Format:
		  Codec: Linear PCM (0x04)
		Output Coding Format:
		  Codec: Linear PCM (0x04)
		Input Coded Data Size: 16
		Output Coded Data Size: 16
		Input PCM Data Format: 2's complement
		Output PCM Data Format: 2's complement
		Input PCM Sample Payload MSB Position: 0
		Output PCM Sample Payload MSB Position: 0
		Input Data Path: HCI
		Output Data Path: HCI
		Input Transport Unit Size: 1
		Output Transport Unit Size: 1
		Max latency: 13
		Packet type: 0x0380
		  3-EV3 may not be used
		  2-EV5 may not be used
		  3-EV5 may not be used
		Retransmission effort: Optimize for link quality (0x02)
> HCI Event: Command Status (0x0f) plen 4
	  Enhanced Accept Synchronous Connection
Request (0x01|0x003e) ncmd 1
		Status: Success (0x00)
> HCI Event: Synchronous Connect Complete (0x2c) plen 17
		Status: Success (0x00)
		Handle: 8
		Address: 10:EC:81:61:71:67
		Link type: eSCO (0x02)
		Transmission interval: 0x0c
		Retransmission window: 0x04
		RX packet length: 60
		TX packet length: 60
		Air mode: Transparent (0x03)

Signed-off-by: Mahesh Talewad <mahesh.talewad@nxp.com>
---
 include/net/bluetooth/hci.h      | 34 ++++++++++++++
 include/net/bluetooth/hci_sync.h |  9 ++++
 net/bluetooth/hci_event.c        | 27 ++++++-----
 net/bluetooth/hci_sync.c         | 78 ++++++++++++++++++++++++++++++++
 net/bluetooth/sco.c              | 34 ++------------
 5 files changed, 141 insertions(+), 41 deletions(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index db76c2d1eeaa..accfa36e7f2c 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -939,6 +939,40 @@ struct hci_cp_accept_sync_conn_req {
 	__le16   pkt_type;
 } __packed;
 
+#define HCI_OP_ENHANCED_ACCEPT_SYNC_CONN_REQ	0x043E
+struct hci_coding_format_en_accpt_sync {
+	__u8    id;
+	__le16  cid;
+	__le16  vid;
+} __packed;
+
+struct hci_cp_enhanced_accept_sync_conn_req {
+	bdaddr_t bdaddr;
+	__le32	tx_bandwidth;
+	__le32	rx_bandwidth;
+	struct	hci_coding_format_en_accpt_sync tx_coding_format;
+	struct	hci_coding_format_en_accpt_sync rx_coding_format;
+	__le16	tx_codec_frame_size;
+	__le16	rx_codec_frame_size;
+	__le32	in_bandwidth;
+	__le32	out_bandwidth;
+	struct	hci_coding_format_en_accpt_sync in_coding_format;
+	struct	hci_coding_format_en_accpt_sync out_coding_format;
+	__le16	in_coded_data_size;
+	__le16	out_coded_data_size;
+	__u8	in_pcm_data_format;
+	__u8	out_pcm_data_format;
+	__u8	in_pcm_sample_payload_msb_pos;
+	__u8	out_pcm_sample_payload_msb_pos;
+	__u8	in_data_path;
+	__u8	out_data_path;
+	__u8	in_transport_unit_size;
+	__u8	out_transport_unit_size;
+	__le16	max_latency;
+	__le16	pkt_type;
+	__u8	retrans_effort;
+} __packed;
+
 #define HCI_OP_REJECT_SYNC_CONN_REQ	0x042a
 struct hci_cp_reject_sync_conn_req {
 	bdaddr_t bdaddr;
diff --git a/include/net/bluetooth/hci_sync.h b/include/net/bluetooth/hci_sync.h
index 73e494b2591d..c739fc6a3d9e 100644
--- a/include/net/bluetooth/hci_sync.h
+++ b/include/net/bluetooth/hci_sync.h
@@ -194,3 +194,12 @@ int hci_le_read_remote_features(struct hci_conn *conn);
 
 int hci_acl_change_pkt_type(struct hci_conn *conn, u16 pkt_type);
 int hci_le_set_phy(struct hci_conn *conn, u8 tx_phys, u8 rx_phys);
+
+struct esco_params {
+	u16 pkt_type;
+	u16 max_latency;
+	u8  retrans_effort;
+};
+
+void hci_cmd_accept_sync_conn_req(struct hci_conn *conn, u16 setting);
+void hci_cmd_enhanced_accept_sync_conn_req(struct hci_conn *conn);
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 467710a42d45..7b1bfdea6715 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -3347,20 +3347,25 @@ static void hci_conn_request_evt(struct hci_dev *hdev, void *data,
 
 		hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp), &cp);
 	} else if (!(flags & HCI_PROTO_DEFER)) {
-		struct hci_cp_accept_sync_conn_req cp;
-		conn->state = BT_CONNECT;
+		if (!enhanced_sync_conn_capable(hdev)) {
+			struct hci_cp_accept_sync_conn_req cp;
 
-		bacpy(&cp.bdaddr, &ev->bdaddr);
-		cp.pkt_type = cpu_to_le16(conn->pkt_type);
+			conn->state = BT_CONNECT;
+
+			bacpy(&cp.bdaddr, &ev->bdaddr);
+			cp.pkt_type = cpu_to_le16(conn->pkt_type);
 
-		cp.tx_bandwidth   = cpu_to_le32(0x00001f40);
-		cp.rx_bandwidth   = cpu_to_le32(0x00001f40);
-		cp.max_latency    = cpu_to_le16(0xffff);
-		cp.content_format = cpu_to_le16(hdev->voice_setting);
-		cp.retrans_effort = 0xff;
+			cp.tx_bandwidth   = cpu_to_le32(0x00001f40);
+			cp.rx_bandwidth   = cpu_to_le32(0x00001f40);
+			cp.max_latency    = cpu_to_le16(0xffff);
+			cp.content_format = cpu_to_le16(hdev->voice_setting);
+			cp.retrans_effort = 0xff;
 
-		hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ, sizeof(cp),
-			     &cp);
+			hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ, sizeof(cp), &cp);
+		} else {
+			conn->state = BT_CONNECT;
+			hci_cmd_enhanced_accept_sync_conn_req(conn);
+		}
 	} else {
 		conn->state = BT_CONNECT2;
 		hci_connect_cfm(conn, 0);
diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index ab0b68faa61c..8e23ac585c2c 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -7519,3 +7519,81 @@ int hci_le_set_phy(struct hci_conn *conn, u8 tx_phys, u8 rx_phys)
 	return hci_cmd_sync_queue_once(hdev, hci_le_set_phy_sync, cp,
 				       le_phy_update_complete);
 }
+
+void hci_cmd_accept_sync_conn_req(struct hci_conn *conn, u16 setting)
+{
+	struct hci_dev *hdev = conn->hdev;
+	struct hci_cp_accept_sync_conn_req cp;
+
+	bacpy(&cp.bdaddr, &conn->dst);
+	cp.pkt_type = cpu_to_le16(conn->pkt_type);
+
+	cp.tx_bandwidth   = cpu_to_le32(0x00001f40);
+	cp.rx_bandwidth   = cpu_to_le32(0x00001f40);
+	cp.content_format = cpu_to_le16(setting);
+
+	switch (setting & SCO_AIRMODE_MASK) {
+	case SCO_AIRMODE_TRANSP:
+		if (conn->pkt_type & ESCO_2EV3)
+			cp.max_latency = cpu_to_le16(0x0008);
+		else
+			cp.max_latency = cpu_to_le16(0x000D);
+		cp.retrans_effort = 0x02;
+		break;
+	case SCO_AIRMODE_CVSD:
+		cp.max_latency = cpu_to_le16(0xffff);
+		cp.retrans_effort = 0xff;
+		break;
+	default:
+		/* use CVSD settings as fallback */
+		cp.max_latency = cpu_to_le16(0xffff);
+		cp.retrans_effort = 0xff;
+		break;
+	}
+
+	hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ, sizeof(cp), &cp);
+}
+
+static const struct esco_params esco_params_msbc[] = {
+	{ EDR_ESCO_MASK & ~ESCO_2EV3, 0x000d,   0x02 }, /* T2 */
+	{ EDR_ESCO_MASK | ESCO_EV3,   0x0008,   0x02 }, /* T1 */
+};
+
+void hci_cmd_enhanced_accept_sync_conn_req(struct hci_conn *conn)
+{
+	struct hci_dev *hdev = conn->hdev;
+	struct hci_cp_enhanced_accept_sync_conn_req cp;
+	const struct esco_params *param;
+
+	memset(&cp, 0x00, sizeof(cp));
+
+	bacpy(&cp.bdaddr, &conn->dst);
+	cp.tx_bandwidth   = cpu_to_le32(0x00001f40);
+	cp.rx_bandwidth   = cpu_to_le32(0x00001f40);
+	cp.tx_coding_format.id = 0x05;
+	cp.rx_coding_format.id = 0x05;
+	cp.tx_codec_frame_size = __cpu_to_le16(60);
+	cp.rx_codec_frame_size = __cpu_to_le16(60);
+	cp.in_bandwidth = __cpu_to_le32(32000);
+	cp.out_bandwidth = __cpu_to_le32(32000);
+	cp.in_coding_format.id = 0x04;
+	cp.out_coding_format.id = 0x04;
+	cp.in_coded_data_size = __cpu_to_le16(16);
+	cp.out_coded_data_size = __cpu_to_le16(16);
+	cp.in_pcm_data_format = 2;
+	cp.out_pcm_data_format = 2;
+	cp.in_pcm_sample_payload_msb_pos = 0;
+	cp.out_pcm_sample_payload_msb_pos = 0;
+	cp.in_data_path = conn->codec.data_path;
+	cp.out_data_path = conn->codec.data_path;
+	cp.in_transport_unit_size = 1;
+	cp.out_transport_unit_size = 1;
+
+	param = &esco_params_msbc[conn->attempt];
+
+	cp.max_latency = __cpu_to_le16(param->max_latency);
+	cp.pkt_type = __cpu_to_le16(param->pkt_type);
+	cp.retrans_effort = param->retrans_effort;
+
+	hci_send_cmd(hdev, HCI_OP_ENHANCED_ACCEPT_SYNC_CONN_REQ, sizeof(cp), &cp);
+}
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 87ba90336e80..278b611d6e20 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -847,36 +847,10 @@ static void sco_conn_defer_accept(struct hci_conn *conn, u16 setting)
 
 		hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp), &cp);
 	} else {
-		struct hci_cp_accept_sync_conn_req cp;
-
-		bacpy(&cp.bdaddr, &conn->dst);
-		cp.pkt_type = cpu_to_le16(conn->pkt_type);
-
-		cp.tx_bandwidth   = cpu_to_le32(0x00001f40);
-		cp.rx_bandwidth   = cpu_to_le32(0x00001f40);
-		cp.content_format = cpu_to_le16(setting);
-
-		switch (setting & SCO_AIRMODE_MASK) {
-		case SCO_AIRMODE_TRANSP:
-			if (conn->pkt_type & ESCO_2EV3)
-				cp.max_latency = cpu_to_le16(0x0008);
-			else
-				cp.max_latency = cpu_to_le16(0x000D);
-			cp.retrans_effort = 0x02;
-			break;
-		case SCO_AIRMODE_CVSD:
-			cp.max_latency = cpu_to_le16(0xffff);
-			cp.retrans_effort = 0xff;
-			break;
-		default:
-			/* use CVSD settings as fallback */
-			cp.max_latency = cpu_to_le16(0xffff);
-			cp.retrans_effort = 0xff;
-			break;
-		}
-
-		hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ,
-			     sizeof(cp), &cp);
+		if (!enhanced_sync_conn_capable(hdev))
+			hci_cmd_accept_sync_conn_req(conn, setting);
+		else
+			hci_cmd_enhanced_accept_sync_conn_req(conn);
 	}
 }
 
-- 
2.34.1


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

end of thread, other threads:[~2025-12-29 11:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-24  6:31 [PATCH BlueZ v2 0/1] Enhanced or Legacy Accept Synchronous Connection Request command Mahesh Talewad
2025-12-24  6:31 ` [PATCH BlueZ v2 1/1] " Mahesh Talewad
2025-12-24  6:58   ` bluez.test.bot
2025-12-25 15:42   ` [PATCH BlueZ v2 1/1] " kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2025-12-29 10:46 [PATCH BlueZ v3 " Mahesh Talewad
2025-12-29 11:08 ` bluez.test.bot

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.