All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] Bluetooth: SCO: Fix codec when using HCI_Enhanced_Setup_Synchronous_Connection
@ 2022-02-22 21:22 Luiz Augusto von Dentz
  2022-02-23  2:55 ` kernel test robot
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Luiz Augusto von Dentz @ 2022-02-22 21:22 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This makes sure BT_CODEC_MSBC is used by default if socket user attempt
to use BT_VOICE_TRANSPARENT.

Fixes: b2af264ad3af ("Bluetooth: Add support for HCI_Enhanced_Setup_Synchronous_Connection command")
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
 net/bluetooth/sco.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 8eabf41b2993..b35c772efc7e 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -879,15 +879,9 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname,
 		}
 
 		sco_pi(sk)->setting = voice.setting;
-		hdev = hci_get_route(&sco_pi(sk)->dst, &sco_pi(sk)->src,
-				     BDADDR_BREDR);
-		if (!hdev) {
-			err = -EBADFD;
-			break;
-		}
-		if (enhanced_sco_capable(hdev) &&
-		    voice.setting == BT_VOICE_TRANSPARENT)
-			sco_pi(sk)->codec.id = BT_CODEC_TRANSPARENT;
+		if (voice.setting == BT_VOICE_TRANSPARENT)
+			sco_pi(sk)->codec.id = BT_CODEC_MSBC;
+
 		hci_dev_put(hdev);
 		break;
 
-- 
2.35.1


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

* Re: [RFC] Bluetooth: SCO: Fix codec when using HCI_Enhanced_Setup_Synchronous_Connection
  2022-02-22 21:22 [RFC] Bluetooth: SCO: Fix codec when using HCI_Enhanced_Setup_Synchronous_Connection Luiz Augusto von Dentz
@ 2022-02-23  2:55 ` kernel test robot
  2022-02-24 13:42 ` Marcel Holtmann
  2022-02-27 16:34 ` [RFC] Bluetooth: don't use ESCO setup for BT_VOICE Pauli Virtanen
  2 siblings, 0 replies; 6+ messages in thread
From: kernel test robot @ 2022-02-23  2:55 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: llvm, kbuild-all

Hi Luiz,

[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on bluetooth-next/master]
[also build test WARNING on linus/master v5.17-rc5 next-20220217]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Luiz-Augusto-von-Dentz/Bluetooth-SCO-Fix-codec-when-using-HCI_Enhanced_Setup_Synchronous_Connection/20220223-052337
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git master
config: x86_64-randconfig-a011-20220221 (https://download.01.org/0day-ci/archive/20220223/202202231010.N2dnVcSC-lkp@intel.com/config)
compiler: clang version 15.0.0 (https://github.com/llvm/llvm-project d271fc04d5b97b12e6b797c6067d3c96a8d7470e)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/0day-ci/linux/commit/04f5ce131261635df1672e71bb21ddd6ed96cbde
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Luiz-Augusto-von-Dentz/Bluetooth-SCO-Fix-codec-when-using-HCI_Enhanced_Setup_Synchronous_Connection/20220223-052337
        git checkout 04f5ce131261635df1672e71bb21ddd6ed96cbde
        # save the config file to linux build tree
        mkdir build_dir
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash net/bluetooth/

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> net/bluetooth/sco.c:885:15: warning: variable 'hdev' is uninitialized when used here [-Wuninitialized]
                   hci_dev_put(hdev);
                               ^~~~
   net/bluetooth/sco.c:833:22: note: initialize the variable 'hdev' to silence this warning
           struct hci_dev *hdev;
                               ^
                                = NULL
   1 warning generated.


vim +/hdev +885 net/bluetooth/sco.c

20714bfef84d3e Frédéric Dalleau       2012-11-21  824  
c4297e8f7f453c Marcel Holtmann        2015-10-26  825  static int sco_sock_setsockopt(struct socket *sock, int level, int optname,
a7b75c5a8c4144 Christoph Hellwig      2020-07-23  826  			       sockptr_t optval, unsigned int optlen)
^1da177e4c3f41 Linus Torvalds         2005-04-16  827  {
^1da177e4c3f41 Linus Torvalds         2005-04-16  828  	struct sock *sk = sock->sk;
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  829  	int len, err = 0;
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  830  	struct bt_voice voice;
b96e9c671b05f9 Frédéric Dalleau       2012-11-21  831  	u32 opt;
f6873401a60865 Kiran K                2021-09-07  832  	struct bt_codecs *codecs;
f6873401a60865 Kiran K                2021-09-07  833  	struct hci_dev *hdev;
f6873401a60865 Kiran K                2021-09-07  834  	__u8 buffer[255];
^1da177e4c3f41 Linus Torvalds         2005-04-16  835  
^1da177e4c3f41 Linus Torvalds         2005-04-16  836  	BT_DBG("sk %p", sk);
^1da177e4c3f41 Linus Torvalds         2005-04-16  837  
^1da177e4c3f41 Linus Torvalds         2005-04-16  838  	lock_sock(sk);
^1da177e4c3f41 Linus Torvalds         2005-04-16  839  
^1da177e4c3f41 Linus Torvalds         2005-04-16  840  	switch (optname) {
b96e9c671b05f9 Frédéric Dalleau       2012-11-21  841  
b96e9c671b05f9 Frédéric Dalleau       2012-11-21  842  	case BT_DEFER_SETUP:
b96e9c671b05f9 Frédéric Dalleau       2012-11-21  843  		if (sk->sk_state != BT_BOUND && sk->sk_state != BT_LISTEN) {
b96e9c671b05f9 Frédéric Dalleau       2012-11-21  844  			err = -EINVAL;
b96e9c671b05f9 Frédéric Dalleau       2012-11-21  845  			break;
b96e9c671b05f9 Frédéric Dalleau       2012-11-21  846  		}
b96e9c671b05f9 Frédéric Dalleau       2012-11-21  847  
a7b75c5a8c4144 Christoph Hellwig      2020-07-23  848  		if (copy_from_sockptr(&opt, optval, sizeof(u32))) {
b96e9c671b05f9 Frédéric Dalleau       2012-11-21  849  			err = -EFAULT;
b96e9c671b05f9 Frédéric Dalleau       2012-11-21  850  			break;
b96e9c671b05f9 Frédéric Dalleau       2012-11-21  851  		}
b96e9c671b05f9 Frédéric Dalleau       2012-11-21  852  
b96e9c671b05f9 Frédéric Dalleau       2012-11-21  853  		if (opt)
b96e9c671b05f9 Frédéric Dalleau       2012-11-21  854  			set_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
b96e9c671b05f9 Frédéric Dalleau       2012-11-21  855  		else
b96e9c671b05f9 Frédéric Dalleau       2012-11-21  856  			clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags);
b96e9c671b05f9 Frédéric Dalleau       2012-11-21  857  		break;
b96e9c671b05f9 Frédéric Dalleau       2012-11-21  858  
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  859  	case BT_VOICE:
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  860  		if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND &&
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  861  		    sk->sk_state != BT_CONNECT2) {
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  862  			err = -EINVAL;
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  863  			break;
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  864  		}
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  865  
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  866  		voice.setting = sco_pi(sk)->setting;
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  867  
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  868  		len = min_t(unsigned int, sizeof(voice), optlen);
a7b75c5a8c4144 Christoph Hellwig      2020-07-23  869  		if (copy_from_sockptr(&voice, optval, len)) {
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  870  			err = -EFAULT;
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  871  			break;
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  872  		}
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  873  
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  874  		/* Explicitly check for these values */
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  875  		if (voice.setting != BT_VOICE_TRANSPARENT &&
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  876  		    voice.setting != BT_VOICE_CVSD_16BIT) {
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  877  			err = -EINVAL;
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  878  			break;
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  879  		}
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  880  
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  881  		sco_pi(sk)->setting = voice.setting;
04f5ce13126163 Luiz Augusto von Dentz 2022-02-22  882  		if (voice.setting == BT_VOICE_TRANSPARENT)
04f5ce13126163 Luiz Augusto von Dentz 2022-02-22  883  			sco_pi(sk)->codec.id = BT_CODEC_MSBC;
04f5ce13126163 Luiz Augusto von Dentz 2022-02-22  884  
b2af264ad3af43 Kiran K                2021-09-07 @885  		hci_dev_put(hdev);
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  886  		break;
ad10b1a48754b1 Frédéric Dalleau       2013-08-19  887  
00398e1d518309 Alain Michaud          2020-06-11  888  	case BT_PKT_STATUS:
83a33b248763f0 David S. Miller        2020-07-31  889  		if (copy_from_sockptr(&opt, optval, sizeof(u32))) {
00398e1d518309 Alain Michaud          2020-06-11  890  			err = -EFAULT;
00398e1d518309 Alain Michaud          2020-06-11  891  			break;
00398e1d518309 Alain Michaud          2020-06-11  892  		}
00398e1d518309 Alain Michaud          2020-06-11  893  
00398e1d518309 Alain Michaud          2020-06-11  894  		if (opt)
00398e1d518309 Alain Michaud          2020-06-11  895  			sco_pi(sk)->cmsg_mask |= SCO_CMSG_PKT_STATUS;
00398e1d518309 Alain Michaud          2020-06-11  896  		else
00398e1d518309 Alain Michaud          2020-06-11  897  			sco_pi(sk)->cmsg_mask &= SCO_CMSG_PKT_STATUS;
00398e1d518309 Alain Michaud          2020-06-11  898  		break;
00398e1d518309 Alain Michaud          2020-06-11  899  
f6873401a60865 Kiran K                2021-09-07  900  	case BT_CODEC:
f6873401a60865 Kiran K                2021-09-07  901  		if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND &&
f6873401a60865 Kiran K                2021-09-07  902  		    sk->sk_state != BT_CONNECT2) {
f6873401a60865 Kiran K                2021-09-07  903  			err = -EINVAL;
f6873401a60865 Kiran K                2021-09-07  904  			break;
f6873401a60865 Kiran K                2021-09-07  905  		}
f6873401a60865 Kiran K                2021-09-07  906  
f6873401a60865 Kiran K                2021-09-07  907  		hdev = hci_get_route(&sco_pi(sk)->dst, &sco_pi(sk)->src,
f6873401a60865 Kiran K                2021-09-07  908  				     BDADDR_BREDR);
f6873401a60865 Kiran K                2021-09-07  909  		if (!hdev) {
f6873401a60865 Kiran K                2021-09-07  910  			err = -EBADFD;
f6873401a60865 Kiran K                2021-09-07  911  			break;
f6873401a60865 Kiran K                2021-09-07  912  		}
f6873401a60865 Kiran K                2021-09-07  913  
f6873401a60865 Kiran K                2021-09-07  914  		if (!hci_dev_test_flag(hdev, HCI_OFFLOAD_CODECS_ENABLED)) {
f6873401a60865 Kiran K                2021-09-07  915  			hci_dev_put(hdev);
f6873401a60865 Kiran K                2021-09-07  916  			err = -EOPNOTSUPP;
f6873401a60865 Kiran K                2021-09-07  917  			break;
f6873401a60865 Kiran K                2021-09-07  918  		}
f6873401a60865 Kiran K                2021-09-07  919  
f6873401a60865 Kiran K                2021-09-07  920  		if (!hdev->get_data_path_id) {
f6873401a60865 Kiran K                2021-09-07  921  			hci_dev_put(hdev);
f6873401a60865 Kiran K                2021-09-07  922  			err = -EOPNOTSUPP;
f6873401a60865 Kiran K                2021-09-07  923  			break;
f6873401a60865 Kiran K                2021-09-07  924  		}
f6873401a60865 Kiran K                2021-09-07  925  
f6873401a60865 Kiran K                2021-09-07  926  		if (optlen < sizeof(struct bt_codecs) ||
f6873401a60865 Kiran K                2021-09-07  927  		    optlen > sizeof(buffer)) {
f6873401a60865 Kiran K                2021-09-07  928  			hci_dev_put(hdev);
f6873401a60865 Kiran K                2021-09-07  929  			err = -EINVAL;
f6873401a60865 Kiran K                2021-09-07  930  			break;
f6873401a60865 Kiran K                2021-09-07  931  		}
f6873401a60865 Kiran K                2021-09-07  932  
f6873401a60865 Kiran K                2021-09-07  933  		if (copy_from_sockptr(buffer, optval, optlen)) {
f6873401a60865 Kiran K                2021-09-07  934  			hci_dev_put(hdev);
f6873401a60865 Kiran K                2021-09-07  935  			err = -EFAULT;
f6873401a60865 Kiran K                2021-09-07  936  			break;
f6873401a60865 Kiran K                2021-09-07  937  		}
f6873401a60865 Kiran K                2021-09-07  938  
f6873401a60865 Kiran K                2021-09-07  939  		codecs = (void *)buffer;
f6873401a60865 Kiran K                2021-09-07  940  
f6873401a60865 Kiran K                2021-09-07  941  		if (codecs->num_codecs > 1) {
f6873401a60865 Kiran K                2021-09-07  942  			hci_dev_put(hdev);
f6873401a60865 Kiran K                2021-09-07  943  			err = -EINVAL;
f6873401a60865 Kiran K                2021-09-07  944  			break;
f6873401a60865 Kiran K                2021-09-07  945  		}
f6873401a60865 Kiran K                2021-09-07  946  
f6873401a60865 Kiran K                2021-09-07  947  		sco_pi(sk)->codec = codecs->codecs[0];
f6873401a60865 Kiran K                2021-09-07  948  		hci_dev_put(hdev);
f6873401a60865 Kiran K                2021-09-07  949  		break;
f6873401a60865 Kiran K                2021-09-07  950  
^1da177e4c3f41 Linus Torvalds         2005-04-16  951  	default:
^1da177e4c3f41 Linus Torvalds         2005-04-16  952  		err = -ENOPROTOOPT;
^1da177e4c3f41 Linus Torvalds         2005-04-16  953  		break;
^1da177e4c3f41 Linus Torvalds         2005-04-16  954  	}
^1da177e4c3f41 Linus Torvalds         2005-04-16  955  
^1da177e4c3f41 Linus Torvalds         2005-04-16  956  	release_sock(sk);
^1da177e4c3f41 Linus Torvalds         2005-04-16  957  	return err;
^1da177e4c3f41 Linus Torvalds         2005-04-16  958  }
^1da177e4c3f41 Linus Torvalds         2005-04-16  959  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

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

* Re: [RFC] Bluetooth: SCO: Fix codec when using HCI_Enhanced_Setup_Synchronous_Connection
  2022-02-22 21:22 [RFC] Bluetooth: SCO: Fix codec when using HCI_Enhanced_Setup_Synchronous_Connection Luiz Augusto von Dentz
  2022-02-23  2:55 ` kernel test robot
@ 2022-02-24 13:42 ` Marcel Holtmann
  2022-02-27 16:34 ` [RFC] Bluetooth: don't use ESCO setup for BT_VOICE Pauli Virtanen
  2 siblings, 0 replies; 6+ messages in thread
From: Marcel Holtmann @ 2022-02-24 13:42 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hi Luiz,

> This makes sure BT_CODEC_MSBC is used by default if socket user attempt
> to use BT_VOICE_TRANSPARENT.
> 
> Fixes: b2af264ad3af ("Bluetooth: Add support for HCI_Enhanced_Setup_Synchronous_Connection command")
> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> ---
> net/bluetooth/sco.c | 12 +++---------
> 1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
> index 8eabf41b2993..b35c772efc7e 100644
> --- a/net/bluetooth/sco.c
> +++ b/net/bluetooth/sco.c
> @@ -879,15 +879,9 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname,
> 		}
> 
> 		sco_pi(sk)->setting = voice.setting;
> -		hdev = hci_get_route(&sco_pi(sk)->dst, &sco_pi(sk)->src,
> -				     BDADDR_BREDR);
> -		if (!hdev) {
> -			err = -EBADFD;
> -			break;
> -		}
> -		if (enhanced_sco_capable(hdev) &&
> -		    voice.setting == BT_VOICE_TRANSPARENT)
> -			sco_pi(sk)->codec.id = BT_CODEC_TRANSPARENT;
> +		if (voice.setting == BT_VOICE_TRANSPARENT)
> +			sco_pi(sk)->codec.id = BT_CODEC_MSBC;
> +
> 		hci_dev_put(hdev);
> 		break;

why are you removing the rest and especially the eSCO check?

Regards

Marcel


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

* [RFC] Bluetooth: don't use ESCO setup for BT_VOICE
  2022-02-22 21:22 [RFC] Bluetooth: SCO: Fix codec when using HCI_Enhanced_Setup_Synchronous_Connection Luiz Augusto von Dentz
  2022-02-23  2:55 ` kernel test robot
  2022-02-24 13:42 ` Marcel Holtmann
@ 2022-02-27 16:34 ` Pauli Virtanen
  2022-02-27 17:16   ` bluez.test.bot
  2022-02-27 17:36   ` Marcel Holtmann
  2 siblings, 2 replies; 6+ messages in thread
From: Pauli Virtanen @ 2022-02-27 16:34 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Pauli Virtanen, Luiz Augusto von Dentz, Kiran K

According to user reports, how HCI_Enhanced_Setup_Synchronous_Connection
is currently used to establish MSBC connections results to broken audio
on some adapters (QCA6174, mt7921e).

Revert to previous behavior of using HCI_Setup_Synchronous_Connection,
unless the user has explicitly set BT_CODEC sockopt. Since bt_codec
contents come from Core specification, use a separate flag for the
setting.

Fixes: b2af264ad3af ("Bluetooth: Add support for HCI_Enhanced_Setup_Synchronous_Connection command")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=215576
Signed-off-by: Pauli Virtanen <pav@iki.fi>
---

Notes:
    Maybe we want to use the ESCO connect setup only when userspace has
    requested the codec offload support.  I don't have any of the broken
    hardware myself, so this is not tested on them.
    
    Alternatively, there should be some driver quirk to indicate the
    enhanced sco connection setup is not broken.

 include/net/bluetooth/hci_core.h |  1 +
 net/bluetooth/hci_conn.c         | 10 ++++++++--
 net/bluetooth/sco.c              | 22 +++++++---------------
 3 files changed, 16 insertions(+), 17 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index dd8840e70e25..3a6a3b80368c 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -717,6 +717,7 @@ struct hci_conn {
 
 	struct hci_conn	*link;
 	struct bt_codec codec;
+	bool		esco_setup;
 
 	void (*connect_cfm_cb)	(struct hci_conn *conn, u8 status);
 	void (*security_cfm_cb)	(struct hci_conn *conn, u8 status);
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index bd669c95b9a7..0aa7f822de32 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -481,7 +481,7 @@ static bool hci_setup_sync_conn(struct hci_conn *conn, __u16 handle)
 
 bool hci_setup_sync(struct hci_conn *conn, __u16 handle)
 {
-	if (enhanced_sco_capable(conn->hdev))
+	if (enhanced_sco_capable(conn->hdev) && conn->esco_setup)
 		return hci_enhanced_setup_sync_conn(conn, handle);
 
 	return hci_setup_sync_conn(conn, handle);
@@ -1477,7 +1477,13 @@ struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
 	hci_conn_hold(sco);
 
 	sco->setting = setting;
-	sco->codec = *codec;
+	if (codec) {
+		sco->codec = *codec;
+		sco->esco_setup = true;
+	} else {
+		memset(&sco->codec, 0, sizeof(sco->codec));
+		sco->esco_setup = false;
+	}
 
 	if (acl->state == BT_CONNECTED &&
 	    (sco->state == BT_OPEN || sco->state == BT_CLOSED)) {
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index 8eabf41b2993..e78063d65c1a 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -70,6 +70,7 @@ struct sco_pinfo {
 	__u16		setting;
 	__u8		cmsg_mask;
 	struct bt_codec codec;
+	bool		esco_setup;
 	struct sco_conn	*conn;
 };
 
@@ -239,6 +240,7 @@ static int sco_connect(struct hci_dev *hdev, struct sock *sk)
 {
 	struct sco_conn *conn;
 	struct hci_conn *hcon;
+	struct bt_codec *codec;
 	int err, type;
 
 	BT_DBG("%pMR -> %pMR", &sco_pi(sk)->src, &sco_pi(sk)->dst);
@@ -252,8 +254,9 @@ static int sco_connect(struct hci_dev *hdev, struct sock *sk)
 	    (!lmp_transp_capable(hdev) || !lmp_esco_capable(hdev)))
 		return -EOPNOTSUPP;
 
+	codec = sco_pi(sk)->esco_setup ? &sco_pi(sk)->codec : NULL;
 	hcon = hci_connect_sco(hdev, type, &sco_pi(sk)->dst,
-			       sco_pi(sk)->setting, &sco_pi(sk)->codec);
+			       sco_pi(sk)->setting, codec);
 	if (IS_ERR(hcon))
 		return PTR_ERR(hcon);
 
@@ -496,10 +499,7 @@ static struct sock *sco_sock_alloc(struct net *net, struct socket *sock,
 	sk->sk_state    = BT_OPEN;
 
 	sco_pi(sk)->setting = BT_VOICE_CVSD_16BIT;
-	sco_pi(sk)->codec.id = BT_CODEC_CVSD;
-	sco_pi(sk)->codec.cid = 0xffff;
-	sco_pi(sk)->codec.vid = 0xffff;
-	sco_pi(sk)->codec.data_path = 0x00;
+	sco_pi(sk)->esco_setup = false;
 
 	bt_sock_link(&sco_sk_list, sk);
 	return sk;
@@ -879,16 +879,7 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname,
 		}
 
 		sco_pi(sk)->setting = voice.setting;
-		hdev = hci_get_route(&sco_pi(sk)->dst, &sco_pi(sk)->src,
-				     BDADDR_BREDR);
-		if (!hdev) {
-			err = -EBADFD;
-			break;
-		}
-		if (enhanced_sco_capable(hdev) &&
-		    voice.setting == BT_VOICE_TRANSPARENT)
-			sco_pi(sk)->codec.id = BT_CODEC_TRANSPARENT;
-		hci_dev_put(hdev);
+		sco_pi(sk)->esco_setup = false;
 		break;
 
 	case BT_PKT_STATUS:
@@ -951,6 +942,7 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname,
 		}
 
 		sco_pi(sk)->codec = codecs->codecs[0];
+		sco_pi(sk)->esco_setup = true;
 		hci_dev_put(hdev);
 		break;
 
-- 
2.35.1


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

* RE: [RFC] Bluetooth: don't use ESCO setup for BT_VOICE
  2022-02-27 16:34 ` [RFC] Bluetooth: don't use ESCO setup for BT_VOICE Pauli Virtanen
@ 2022-02-27 17:16   ` bluez.test.bot
  2022-02-27 17:36   ` Marcel Holtmann
  1 sibling, 0 replies; 6+ messages in thread
From: bluez.test.bot @ 2022-02-27 17:16 UTC (permalink / raw)
  To: linux-bluetooth, pav

[-- Attachment #1: Type: text/plain, Size: 1303 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/project/bluetooth/list/?series=618448

---Test result---

Test Summary:
CheckPatch                    PASS      2.01 seconds
GitLint                       FAIL      1.07 seconds
SubjectPrefix                 PASS      0.86 seconds
BuildKernel                   PASS      34.67 seconds
BuildKernel32                 PASS      30.46 seconds
Incremental Build with patchesPASS      41.73 seconds
TestRunner: Setup             PASS      544.79 seconds
TestRunner: l2cap-tester      PASS      15.36 seconds
TestRunner: bnep-tester       PASS      6.82 seconds
TestRunner: mgmt-tester       PASS      119.15 seconds
TestRunner: rfcomm-tester     PASS      9.02 seconds
TestRunner: sco-tester        PASS      8.56 seconds
TestRunner: smp-tester        PASS      8.42 seconds
TestRunner: userchan-tester   PASS      7.03 seconds

Details
##############################
Test: GitLint - FAIL - 1.07 seconds
Run gitlint with rule in .gitlint
[RFC] Bluetooth: don't use ESCO setup for BT_VOICE
20: B2 Line has trailing whitespace: "    "




---
Regards,
Linux Bluetooth


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

* Re: [RFC] Bluetooth: don't use ESCO setup for BT_VOICE
  2022-02-27 16:34 ` [RFC] Bluetooth: don't use ESCO setup for BT_VOICE Pauli Virtanen
  2022-02-27 17:16   ` bluez.test.bot
@ 2022-02-27 17:36   ` Marcel Holtmann
  1 sibling, 0 replies; 6+ messages in thread
From: Marcel Holtmann @ 2022-02-27 17:36 UTC (permalink / raw)
  To: Pauli Virtanen; +Cc: linux-bluetooth, Luiz Augusto von Dentz, Kiran K

Hi Pauli,

> According to user reports, how HCI_Enhanced_Setup_Synchronous_Connection
> is currently used to establish MSBC connections results to broken audio
> on some adapters (QCA6174, mt7921e).
> 
> Revert to previous behavior of using HCI_Setup_Synchronous_Connection,
> unless the user has explicitly set BT_CODEC sockopt. Since bt_codec
> contents come from Core specification, use a separate flag for the
> setting.
> 
> Fixes: b2af264ad3af ("Bluetooth: Add support for HCI_Enhanced_Setup_Synchronous_Connection command")
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=215576
> Signed-off-by: Pauli Virtanen <pav@iki.fi>
> ---
> 
> Notes:
>    Maybe we want to use the ESCO connect setup only when userspace has
>    requested the codec offload support.  I don't have any of the broken
>    hardware myself, so this is not tested on them.
> 
>    Alternatively, there should be some driver quirk to indicate the
>    enhanced sco connection setup is not broken.

yes, these needs to be marked as my hardware is broken.

From a specification point of view, the Enhanced Setup Sync Conn is a super set of the Setup Sync Conn (which is a super set of Add SCO). If implementers screwed that up, we clear spell that out.

Maybe we messed up the usage of the Enhanced Setup Sync Conn and that should be of course checked. I hope the hardware manufactures can chime in here. Or provide firmware updates.

Regards

Marcel


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

end of thread, other threads:[~2022-02-27 17:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-22 21:22 [RFC] Bluetooth: SCO: Fix codec when using HCI_Enhanced_Setup_Synchronous_Connection Luiz Augusto von Dentz
2022-02-23  2:55 ` kernel test robot
2022-02-24 13:42 ` Marcel Holtmann
2022-02-27 16:34 ` [RFC] Bluetooth: don't use ESCO setup for BT_VOICE Pauli Virtanen
2022-02-27 17:16   ` bluez.test.bot
2022-02-27 17:36   ` Marcel Holtmann

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.