Skip to contentSkip to conversation

can we disable/enable eSCO by using setsockopt of sco socket?

DISCUSSION Lan Zhu 4 participants 8 messages Sep 14, 2009 – Sep 22, 2009

Subsystems (2)
lore
Share & tools
lore

Lan Zhu

author
#0 lore raw

Hi Marcel,

When we connect a SCO socket, BlueZ decides whether to connect SCO or eSCO type according to the remote feature. If the remote device declares supporting eSCO in the remote feature, BlueZ will select eSCO type to connect with it.

But in fact there are some old carkits or headsets which are only support SCO but wrongly declare to support eSCO, such as Motorola HF850 and HS820 which use a very old CSR chip, so we have problem to create sco connection with them.

We thought a method to resolve this issue, which is force to create SCO type connection if we find the HFP version of one remote device is less than 1.2. So we need a method to control the SCO type from user space. We want to use setsockopt() functon to do that. The code change in net/bluetooth/sco.c is like below,

@@ -653,12 +653,25 @@ static int sco_sock_setsockopt(struct socket *sock, int le

 {
       struct sock *sk = sock->sk;
       int err = 0;

+ u32 opt;

       BT_DBG("sk %p", sk);

       lock_sock(sk);

+ if (level != SOL_SCO) {
+ err = -ENOPROTOOPT;
+ return err;
+ }
+

       switch (optname) {

+ case BT_DISABLE_ESCO:
+ if (get_user(opt, (u32 __user *) optval)) {
+ err = -EFAULT;
+ break;

+               }
+               disable_esco = opt;
+               break;
       default:
               err = -ENOPROTOOPT;
               break;

Then, in the user space, we can call setsockopt(fd, SOL_SCO, BT_DISABLE_ESCO, &disabled, sizeof(disabled)) to force to connect SCO.

Do you agree with this change?

Thanks,
Zhu Lan

maintainer
#1 lore raw

Hi,

Quoted 45 lines

When we connect a SCO socket, BlueZ decides whether to connect SCO or eSCO type according to the remote feature. If the remote device declares supporting eSCO in the remote feature, BlueZ will select eSCO type to connect with it.

But in fact there are some old carkits or headsets which are only support SCO but wrongly declare to support eSCO, such as Motorola HF850 and HS820 which use a very old CSR chip, so we have problem to create sco connection with them.

We thought a method to resolve this issue, which is force to create SCO type connection if we find the HFP version of one remote device is less than 1.2. So we need a method to control the SCO type from user space. We want to use setsockopt() functon to do that. The code change in net/bluetooth/sco.c is like below,

(quoted diff) +13 -0
@@ -653,12 +653,25 @@ static int sco_sock_setsockopt(struct socket *sock, int le
 {
       struct sock *sk = sock->sk;
       int err = 0;
+       u32 opt;
 
       BT_DBG("sk %p", sk);
 
       lock_sock(sk);
 
+       if (level != SOL_SCO) {
+               err = -ENOPROTOOPT;
+               return err;
+       }
+
       switch (optname) {
+       case BT_DISABLE_ESCO:
+               if (get_user(opt, (u32 __user *) optval)) {
+                       err = -EFAULT;
+                       break;
+               }
+               disable_esco = opt;
+               break;
       default:
               err = -ENOPROTOOPT;
               break;
Quoted 4 lines

Then, in the user space, we can call setsockopt(fd, SOL_SCO, BT_DISABLE_ESCO, &disabled, sizeof(disabled)) to force to connect SCO.

Do you agree with this change?

I don't. You first have to prove to me that this change is needed at all. Show me the hcidump -X -V connections attempts for these carkits.

Also your analysis is wrong. BlueZ doesn't care if the remote headset supports eSCO or not. We just care about if our local controller has the synchronous setup commands. It is the job of the link manager inside the controller firmware to either establish SCO or eSCO. And we do retry with SCO if eSCO fails. This sounds more like the case that you have an outdated kernel.

Regards

Marcel

author
#2 lore raw

Hi Marcel,

2009/9/14 Marcel Holtmann <[email protected]>:

Quoted 12 lines

Hi,

Quoted 10 lines

When we connect a SCO socket, BlueZ decides whether to connect SCO or eSCO type according to the remote feature. If the remote device declares supporting eSCO in the remote feature, BlueZ will select eSCO type to connect with it.

But in fact =A0there are some old carkits or headsets which are only support SCO but wrongly declare to support eSCO, such as Motorola HF850 and HS820 which use a very old CSR chip, so we have problem to create sco connection with them.

Quoted 8 lines

Review static int sco_sock_setsockopt(struct socket *sock=

Quoted 8 lines

We thought a method to resolve this issue, which is force to create SCO type connection if we find the HFP version of one remote device is less than 1.2. So we need a method to control the SCO type from user space. We want to use setsockopt() functon to do that. The code change in net/bluetooth/sco.c is like below,

(quoted diff) +0 -0
@@ -653,12 +653,25 @@ static int sco_sock_setsockopt(struct socket *sock=

, int le

Quoted 9 lines
Quoted 9 lines
(quoted diff) +1 -0
 =A0{
 =A0 =A0 =A0 =A0struct sock *sk =3D sock->sk;
 =A0 =A0 =A0 =A0int err =3D 0;
+ =A0 =A0 =A0 u32 opt;
 
 =A0 =A0 =A0 =A0BT_DBG("sk %p", sk);
 
 =A0 =A0 =A0 =A0lock_sock(sk);
 
Quoted 8 lines

Review static int sco_sock_setsockopt(struct socket *sock= · line 669

Quoted 8 lines
(quoted diff) +7 -0
+ =A0 =A0 =A0 if (level !=3D SOL_SCO) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 err =3D -ENOPROTOOPT;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return err;
+ =A0 =A0 =A0 }
+
 =A0 =A0 =A0 =A0switch (optname) {
+ =A0 =A0 =A0 case BT_DISABLE_ESCO:
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (get_user(opt, (u32 __user *) optval)) =

{

Quoted 25 lines
Quoted 10 lines
(quoted diff) +5 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 err =3D -EFAULT;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 disable_esco =3D opt;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;

=A0 =A0 =A0 =A0default:
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err =3D -ENOPROTOOPT; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break;

Quoted 4 lines

Then, in the user space, we can call setsockopt(fd, SOL_SCO, BT_DISABLE_ESCO, &disabled, sizeof(disabled)) to force to connect SCO.

Do you agree with this change?

I don't. You first have to prove to me that this change is needed at all. Show me the hcidump -X -V connections attempts for these carkits.

Also your analysis is wrong. BlueZ doesn't care if the remote headset supports eSCO or not. We just care about if our local controller has the synchronous setup commands. It is the job of the link manager inside the controller firmware to either establish SCO or eSCO. And we do retry with SCO if eSCO fails. This sounds more like the case that you have an outdated kernel.

Quoted 6 lines

Regards

Marcel

Please excuse me for my inaccurate description. Actually it is LMP layer to check the remote feature then decide which SCO type shall be setup. So, if one remote device wrongly declare to support eSCO, it will cause problem. I do know you have a retry mechanism to retry SCO if eSCO failed, it is in below code in net/bluetooth/hci_event.c, right?

	case 0x1c:	/* SCO interval rejected */
	case 0x1f:	/* Unspecified error */
		if (conn->out && conn->attempt < 2) {
			conn->pkt_type =3D (hdev->esco_type & SCO_ESCO_MASK) |
					(hdev->esco_type & EDR_ESCO_MASK);
			hci_setup_sync(conn, conn->link->handle);
			goto unlock;
		}
		/* fall through */

But the problem is, not all the returned error code can bring retry SCO. So, we still got problem when connecting some devices because it returns some error code else.

This is the hcidump log when we test SCO with HF850 carkit.

2009-09-03 17:26:29.093601 < HCI Command: Setup Synchronous Connection (0x0=
1|0x0
028) plen 17
    handle 1 voice setting 0x0060
2009-09-03 17:26:29.094608 > HCI Event: Command Status (0x0f) plen 4
    Setup Synchronous Connection (0x01|0x0028) status 0x00 ncmd 1
2009-09-03 17:26:34.190952 > HCI Event: Synchronous Connect Complete (0x2c)=
 plen
 17
    status 0x10 handle 257 bdaddr 00:50:CD:20:BA:E6 type eSCO
    Error: Connection Accept Timeout Exceeded
2009-09-03 17:26:34.191196 < HCI Command: Setup Synchronous Connection (0x0=
1|0x0
028) plen 17
    handle 1 voice setting 0x0060
Quoted 1 line

From the log you can see, the eSCO connection failed in 5 seconds with

the error "0x10 Timeout Exceeded", and it do not retry SCO again.

In order to resolve such issue, we have thought about two methods to resolve this.

The first one is, add a new case for "0x10" error code and then retry SCO. We do have tested this, SCO can be setup, but the 5 seconds delay can not be eliminated.

The second one is, we hope to force to use the sco type of SCO for some special devices which have compatible issue with eSCO. We can force to connect SCO by calling hci_add_sco() or hci_setup_sync() with limited pkt_type for those kind of devices. This is why we want to add a DISABLE_ESCO option into setsockopt() function.

Thank you,
Zhu Lan

author
#3 lore raw

Hi Marcel,

2009/9/14 Lan Zhu <[email protected]>:

Quoted 15 lines

Hi Marcel,

2009/9/14 Marcel Holtmann <[email protected]>:

Quoted 12 lines

Hi,

Quoted 10 lines

When we connect a SCO socket, BlueZ decides whether to connect SCO or eSCO type according to the remote feature. If the remote device declares supporting eSCO in the remote feature, BlueZ will select eSCO type to connect with it.

But in fact =A0there are some old carkits or headsets which are only support SCO but wrongly declare to support eSCO, such as Motorola HF850 and HS820 which use a very old CSR chip, so we have problem to create sco connection with them.

Quoted 8 lines
Quoted 8 lines

Review static int sco_sock_setsockopt(struct socket *soc=

Quoted 8 lines

We thought a method to resolve this issue, which is force to create SCO type connection if we find the HFP version of one remote device is less than 1.2. So we need a method to control the SCO type from user space. We want to use setsockopt() functon to do that. The code change in net/bluetooth/sco.c is like below,

(quoted diff) +0 -0
@@ -653,12 +653,25 @@ static int sco_sock_setsockopt(struct socket *soc=

k, int le

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
(quoted diff) +1 -0
 =A0{
 =A0 =A0 =A0 =A0struct sock *sk =3D sock->sk;
 =A0 =A0 =A0 =A0int err =3D 0;
+ =A0 =A0 =A0 u32 opt;
 
 =A0 =A0 =A0 =A0BT_DBG("sk %p", sk);
 
 =A0 =A0 =A0 =A0lock_sock(sk);
 
Quoted 8 lines
Quoted 8 lines

Review static int sco_sock_setsockopt(struct socket *soc= · line 669

Quoted 8 lines
(quoted diff) +7 -0
+ =A0 =A0 =A0 if (level !=3D SOL_SCO) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 err =3D -ENOPROTOOPT;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 return err;
+ =A0 =A0 =A0 }
+
 =A0 =A0 =A0 =A0switch (optname) {
+ =A0 =A0 =A0 case BT_DISABLE_ESCO:
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (get_user(opt, (u32 __user *) optval))=

{

Quoted 39 lines
Quoted 25 lines
Quoted 10 lines
(quoted diff) +5 -0
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 err =3D -EFAULT;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 }
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 disable_esco =3D opt;
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 break;

=A0 =A0 =A0 =A0default:
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0err =3D -ENOPROTOOPT; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break;

Quoted 4 lines

Then, in the user space, we can call setsockopt(fd, SOL_SCO, BT_DISABLE_ESCO, &disabled, sizeof(disabled)) to force to connect SCO.

Do you agree with this change?

I don't. You first have to prove to me that this change is needed at all. Show me the hcidump -X -V connections attempts for these carkits.

Also your analysis is wrong. BlueZ doesn't care if the remote headset supports eSCO or not. We just care about if our local controller has the synchronous setup commands. It is the job of the link manager inside the controller firmware to either establish SCO or eSCO. And we do retry with SCO if eSCO fails. This sounds more like the case that you have an outdated kernel.

Quoted 6 lines

Regards

Marcel

Please excuse me for my inaccurate description. Actually it is LMP layer to check the remote feature then decide which SCO type shall be setup. So, if one remote device wrongly declare to support eSCO, it will cause problem. I do know you have a retry mechanism to retry SCO if eSCO failed, it is in below code in net/bluetooth/hci_event.c, right?

Quoted 4 lines

=A0 =A0 =A0 =A0case 0x1c: =A0 =A0 =A0/* SCO interval rejected */ =A0 =A0 =A0 =A0case 0x1f: =A0 =A0 =A0/* Unspecified error */ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (conn->out && conn->attempt < 2) { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0conn->pkt_type =3D (hdev->=

esco_type & SCO_ESCO_MASK) |

Quoted 1 line

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =

=A0 =A0(hdev->esco_type & EDR_ESCO_MASK);

Quoted 6 lines

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0hci_setup_sync(conn, conn-= link->handle);
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto unlock; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* fall through */

Quoted 7 lines

But the problem is, not all the returned error code can bring retry SCO. So, we still got problem when connecting some devices because it returns some error code else.

This is the hcidump log when we test SCO with HF850 carkit.

2009-09-03 17:26:29.093601 < HCI Command: Setup Synchronous Connection (0=

x01|0x0

Quoted 5 lines

028) plen 17
=A0 =A0handle 1 voice setting 0x0060

2009-09-03 17:26:29.094608 > HCI Event: Command Status (0x0f) plen 4
=A0 =A0Setup Synchronous Connection (0x01|0x0028) status 0x00 ncmd 1
2009-09-03 17:26:34.190952 > HCI Event: Synchronous Connect Complete (0x2=

c) plen

Quoted 4 lines

=A017
=A0 =A0status 0x10 handle 257 bdaddr 00:50:CD:20:BA:E6 type eSCO =A0 =A0Error: Connection Accept Timeout Exceeded

2009-09-03 17:26:34.191196 < HCI Command: Setup Synchronous Connection (0=

x01|0x0

Quoted 20 lines

028) plen 17
=A0 =A0handle 1 voice setting 0x0060

From the log you can see, the eSCO connection failed in 5 seconds with the error "0x10 Timeout Exceeded", and it do not retry SCO again.

In order to resolve such issue, we have thought about two methods to resolve this.

The first one is, add a new case for "0x10" error code and then retry SCO. We do have tested this, SCO can be setup, but the 5 seconds delay can not be eliminated.

The second one is, we hope to force to use the sco type of SCO for some special devices which have compatible issue with eSCO. We can force to connect SCO by calling hci_add_sco() or hci_setup_sync() with limited pkt_type for those kind of devices. This is why we want to add a DISABLE_ESCO option into setsockopt() function.

Quoted 3 lines

Thank you,
Zhu Lan

We did some investigation on Mecel Bluetooth stack and Qualcomm's, they both provide the upper layer with the option to specify SCO type or eSCO type when creating synchronous connection. There are plenty of different Bluetooth devices in the world, compatiblility with them is usually a big issue for one Bluetooth product. So the rubestness will be a very important target for a product. Sometimes the Bluetooth developer need enough flexibility to handle many specific cases, because that can not be totally dealt with
in stack layer. Actually Bluez already has an excellent architecture, but still a little weak in the rubestness. Then, why not give the developer more flexibility to deal with some problems?

Thanks,
Zhu Lan

maintainer
#4 lore raw

Hi,

Quoted 119 lines
Quoted 113 lines
Quoted 60 lines
Quoted 45 lines

When we connect a SCO socket, BlueZ decides whether to connect SCO or eSCO type according to the remote feature. If the remote device declares supporting eSCO in the remote feature, BlueZ will select eSCO type to connect with it.

But in fact there are some old carkits or headsets which are only support SCO but wrongly declare to support eSCO, such as Motorola HF850 and HS820 which use a very old CSR chip, so we have problem to create sco connection with them.

We thought a method to resolve this issue, which is force to create SCO type connection if we find the HFP version of one remote device is less than 1.2. So we need a method to control the SCO type from user space. We want to use setsockopt() functon to do that. The code change in net/bluetooth/sco.c is like below,

(quoted diff) +13 -0
@@ -653,12 +653,25 @@ static int sco_sock_setsockopt(struct socket *sock, int le
 {
       struct sock *sk = sock->sk;
       int err = 0;
+       u32 opt;
 
       BT_DBG("sk %p", sk);
 
       lock_sock(sk);
 
+       if (level != SOL_SCO) {
+               err = -ENOPROTOOPT;
+               return err;
+       }
+
       switch (optname) {
+       case BT_DISABLE_ESCO:
+               if (get_user(opt, (u32 __user *) optval)) {
+                       err = -EFAULT;
+                       break;
+               }
+               disable_esco = opt;
+               break;
       default:
               err = -ENOPROTOOPT;
               break;
Quoted 4 lines

Then, in the user space, we can call setsockopt(fd, SOL_SCO, BT_DISABLE_ESCO, &disabled, sizeof(disabled)) to force to connect SCO.

Do you agree with this change?

I don't. You first have to prove to me that this change is needed at all. Show me the hcidump -X -V connections attempts for these carkits.

Also your analysis is wrong. BlueZ doesn't care if the remote headset supports eSCO or not. We just care about if our local controller has the synchronous setup commands. It is the job of the link manager inside the controller firmware to either establish SCO or eSCO. And we do retry with SCO if eSCO fails. This sounds more like the case that you have an outdated kernel.

Quoted 6 lines

Regards

Marcel

Please excuse me for my inaccurate description. Actually it is LMP layer to check the remote feature then decide which SCO type shall be setup. So, if one remote device wrongly declare to support eSCO, it will cause problem. I do know you have a retry mechanism to retry SCO if eSCO failed, it is in below code in net/bluetooth/hci_event.c, right?

       case 0x1c:      /* SCO interval rejected */
       case 0x1f:      /* Unspecified error */
               if (conn->out && conn->attempt < 2) {
                       conn->pkt_type = (hdev->esco_type & SCO_ESCO_MASK) |
                                       (hdev->esco_type & EDR_ESCO_MASK);
                       hci_setup_sync(conn, conn->link->handle);
                       goto unlock;
               }
               /* fall through */

But the problem is, not all the returned error code can bring retry SCO. So, we still got problem when connecting some devices because it returns some error code else.

This is the hcidump log when we test SCO with HF850 carkit.

2009-09-03 17:26:29.093601 < HCI Command: Setup Synchronous Connection (0x01|0x0
028) plen 17
   handle 1 voice setting 0x0060
2009-09-03 17:26:29.094608 > HCI Event: Command Status (0x0f) plen 4
   Setup Synchronous Connection (0x01|0x0028) status 0x00 ncmd 1
2009-09-03 17:26:34.190952 > HCI Event: Synchronous Connect Complete (0x2c) plen
 17
   status 0x10 handle 257 bdaddr 00:50:CD:20:BA:E6 type eSCO
   Error: Connection Accept Timeout Exceeded
2009-09-03 17:26:34.191196 < HCI Command: Setup Synchronous Connection (0x01|0x0

028) plen 17
handle 1 voice setting 0x0060

From the log you can see, the eSCO connection failed in 5 seconds with the error "0x10 Timeout Exceeded", and it do not retry SCO again.

In order to resolve such issue, we have thought about two methods to resolve this.

The first one is, add a new case for "0x10" error code and then retry SCO. We do have tested this, SCO can be setup, but the 5 seconds delay can not be eliminated.

Quoted 5 lines

The second one is, we hope to force to use the sco type of SCO for some special devices which have compatible issue with eSCO. We can force to connect SCO by calling hci_add_sco() or hci_setup_sync() with limited pkt_type for those kind of devices. This is why we want to add a DISABLE_ESCO option into setsockopt() function.

Quoted 11 lines

We did some investigation on Mecel Bluetooth stack and Qualcomm's, they both provide the upper layer with the option to specify SCO type or eSCO type when creating synchronous connection. There are plenty of different Bluetooth devices in the world, compatiblility with them is usually a big issue for one Bluetooth product. So the rubestness will be a very important target for a product. Sometimes the Bluetooth developer need enough flexibility to handle many specific cases, because that can not be totally dealt with
in stack layer. Actually Bluez already has an excellent architecture, but still a little weak in the rubestness. Then, why not give the developer more flexibility to deal with some problems?

BlueZ is not weak in robustness. Do me a favor and get your English right here and do not spread FUD. You are saying that it is important to work around some total broken eSCO capable chip to be robust. I do question that statement. It is nice to have good interoperability with broken devices, but there is a limit of broken devices we can support.

And the userspace option to select between SCO and eSCO is just stupid since you just start hacking some blacklist non-sense into the code that becomes a big magic blob that nobody can track or understand.

The way forward here is to analyze the headset and see what information it gives us to determine that eSCO might not be working good enough. So I want output from hcitool info and detailed hcidump.

Regards

Marcel

#5 lore raw
Quoted 145 lines · Marcel Holtmann

Hi,

Quoted 119 lines
Quoted 113 lines
Quoted 60 lines
Quoted 45 lines

When we connect a SCO socket, BlueZ decides whether to connect SCO or eSCO type according to the remote feature. If the remote device declares supporting eSCO in the remote feature, BlueZ will select eSCO type to connect with it.

But in fact there are some old carkits or headsets which are only support SCO but wrongly declare to support eSCO, such as Motorola HF850 and HS820 which use a very old CSR chip, so we have problem to create sco connection with them.

We thought a method to resolve this issue, which is force to create SCO type connection if we find the HFP version of one remote device is less than 1.2. So we need a method to control the SCO type from user space. We want to use setsockopt() functon to do that. The code change in net/bluetooth/sco.c is like below,

(quoted diff) +13 -0
@@ -653,12 +653,25 @@ static int sco_sock_setsockopt(struct socket *sock, int le
 {
       struct sock *sk = sock->sk;
       int err = 0;
+       u32 opt;
 
       BT_DBG("sk %p", sk);
 
       lock_sock(sk);
 
+       if (level != SOL_SCO) {
+               err = -ENOPROTOOPT;
+               return err;
+       }
+
       switch (optname) {
+       case BT_DISABLE_ESCO:
+               if (get_user(opt, (u32 __user *) optval)) {
+                       err = -EFAULT;
+                       break;
+               }
+               disable_esco = opt;
+               break;
       default:
               err = -ENOPROTOOPT;
               break;
Quoted 5 lines

Then, in the user space, we can call setsockopt(fd, SOL_SCO, BT_DISABLE_ESCO, &disabled, sizeof(disabled)) to force to connect SCO.

Do you agree with this change?

I don't. You first have to prove to me that this change is needed at all. Show me the hcidump -X -V connections attempts for these carkits.

Also your analysis is wrong. BlueZ doesn't care if the remote headset supports eSCO or not. We just care about if our local controller has the synchronous setup commands. It is the job of the link manager inside the controller firmware to either establish SCO or eSCO. And we do retry with SCO if eSCO fails. This sounds more like the case that you have an outdated kernel.

Quoted 7 lines

Regards

Marcel

Please excuse me for my inaccurate description. Actually it is LMP layer to check the remote feature then decide which SCO type shall be setup. So, if one remote device wrongly declare to support eSCO, it will cause problem. I do know you have a retry mechanism to retry SCO if eSCO failed, it is in below code in net/bluetooth/hci_event.c, right?

       case 0x1c:      /* SCO interval rejected */
       case 0x1f:      /* Unspecified error */
               if (conn->out && conn->attempt < 2) {
                       conn->pkt_type = (hdev->esco_type & SCO_ESCO_MASK) |
                                       (hdev->esco_type & EDR_ESCO_MASK);
                       hci_setup_sync(conn, conn->link->handle);
                       goto unlock;
               }
               /* fall through */

But the problem is, not all the returned error code can bring retry SCO. So, we still got problem when connecting some devices because it returns some error code else.

This is the hcidump log when we test SCO with HF850 carkit.

2009-09-03 17:26:29.093601 < HCI Command: Setup Synchronous Connection (0x01|0x0
028) plen 17
   handle 1 voice setting 0x0060
2009-09-03 17:26:29.094608 > HCI Event: Command Status (0x0f) plen 4
   Setup Synchronous Connection (0x01|0x0028) status 0x00 ncmd 1
2009-09-03 17:26:34.190952 > HCI Event: Synchronous Connect Complete (0x2c) plen
 17
   status 0x10 handle 257 bdaddr 00:50:CD:20:BA:E6 type eSCO
   Error: Connection Accept Timeout Exceeded
2009-09-03 17:26:34.191196 < HCI Command: Setup Synchronous Connection (0x01|0x0

028) plen 17
handle 1 voice setting 0x0060

From the log you can see, the eSCO connection failed in 5 seconds with the error "0x10 Timeout Exceeded", and it do not retry SCO again.

In order to resolve such issue, we have thought about two methods to resolve this.

The first one is, add a new case for "0x10" error code and then retry SCO. We do have tested this, SCO can be setup, but the 5 seconds delay can not be eliminated.

Quoted 6 lines

The second one is, we hope to force to use the sco type of SCO for some special devices which have compatible issue with eSCO. We can force to connect SCO by calling hci_add_sco() or hci_setup_sync() with limited pkt_type for those kind of devices. This is why we want to add a DISABLE_ESCO option into setsockopt() function.

Quoted 12 lines

We did some investigation on Mecel Bluetooth stack and Qualcomm's, they both provide the upper layer with the option to specify SCO type or eSCO type when creating synchronous connection. There are plenty of different Bluetooth devices in the world, compatiblility with them is usually a big issue for one Bluetooth product. So the rubestness will be a very important target for a product. Sometimes the Bluetooth developer need enough flexibility to handle many specific cases, because that can not be totally dealt with
in stack layer. Actually Bluez already has an excellent architecture, but still a little weak in the rubestness. Then, why not give the developer more flexibility to deal with some problems?

BlueZ is not weak in robustness. Do me a favor and get your English right here and do not spread FUD. You are saying that it is important to work around some total broken eSCO capable chip to be robust. I do question that statement. It is nice to have good interoperability with broken devices, but there is a limit of broken devices we can support.

And the userspace option to select between SCO and eSCO is just stupid since you just start hacking some blacklist non-sense into the code that becomes a big magic blob that nobody can track or understand.

Quoted 7 lines

The way forward here is to analyze the headset and see what information it gives us to determine that eSCO might not be working good enough. So I want output from hcitool info and detailed hcidump.

Regards

Marcel

Hi Marcel,

There are device incompatibilities with eSCO. I recently posted a report here ("Odd eSCO behavior with BCM2045-based receiver") that explains that (in that case) an eSCO connection *should not even be tried* (much less retried). In the case I provided, the controller's link manager dumps all other connections and becomes unresponsive after a --successful-- eSCO link is established.

Maybe one could argue that supporting a "broken device" is too much to ask but, IMO, the BCM2045 is too common to avoid. The reality is that any code that directly supports hardware needs to account for situations that reflect what actually happens, rather than what the spec describes (again, IMO).

I feel this situation especially applies to Bluetooth. Because of the evolving complexities of Bluetooth (1300 page core spec with countless sub-specs on its 3rd major evolution), there are bound to be plenty of special cases that will continue to emerge. Presumably your implicit understanding of this is what prompted adding the "disable_esco" module parameter to the sco driver. At some point, special casing becomes necessary -- so the real decision is what form that support will take.

Respectfully,
Peter Hurley

maintainer
#6 lore raw

Hi Peter,

Quoted 27 lines
Quoted 19 lines
Quoted 12 lines

We did some investigation on Mecel Bluetooth stack and Qualcomm's, they both provide the upper layer with the option to specify SCO type or eSCO type when creating synchronous connection. There are plenty of different Bluetooth devices in the world, compatiblility with them is usually a big issue for one Bluetooth product. So the rubestness will be a very important target for a product. Sometimes the Bluetooth developer need enough flexibility to handle many specific cases, because that can not be totally dealt with
in stack layer. Actually Bluez already has an excellent architecture, but still a little weak in the rubestness. Then, why not give the developer more flexibility to deal with some problems?

BlueZ is not weak in robustness. Do me a favor and get your English right here and do not spread FUD. You are saying that it is important to work around some total broken eSCO capable chip to be robust. I do question that statement. It is nice to have good interoperability with broken devices, but there is a limit of broken devices we can support.

Quoted 8 lines

And the userspace option to select between SCO and eSCO is just stupid since you just start hacking some blacklist non-sense into the code that becomes a big magic blob that nobody can track or understand.

The way forward here is to analyze the headset and see what information it gives us to determine that eSCO might not be working good enough. So I want output from hcitool info and detailed hcidump.

Quoted 6 lines

There are device incompatibilities with eSCO. I recently posted a report here ("Odd eSCO behavior with BCM2045-based receiver") that explains that (in that case) an eSCO connection *should not even be tried* (much less retried). In the case I provided, the controller's link manager dumps all other connections and becomes unresponsive after a --successful-- eSCO link is established.

that is a bug in your local controller. That is different from a broken remote controller.

Quoted 6 lines

Maybe one could argue that supporting a "broken device" is too much to ask but, IMO, the BCM2045 is too common to avoid. The reality is that any code that directly supports hardware needs to account for situations that reflect what actually happens, rather than what the spec describes (again, IMO).

Quoted 7 lines

I feel this situation especially applies to Bluetooth. Because of the evolving complexities of Bluetooth (1300 page core spec with countless sub-specs on its 3rd major evolution), there are bound to be plenty of special cases that will continue to emerge. Presumably your implicit understanding of this is what prompted adding the "disable_esco" module parameter to the sco driver. At some point, special casing becomes necessary -- so the real decision is what form that support will take.

The reason behind disable_esco is 1) to accommodate controllers that tell that they support eSCO, but they are bluntly lying to you. So that way can either replace them or use this option.

The second reason and more important one is that we need this for testing and from qualification corner cases. We also have disable_cfc for RFCOMM example and some crazy BNEP options. They are needed for reasons that have nothing with this problem at hand. Which is that the remote device is messed up.

Regards

Marcel

#7 lore raw
In reply to Marcel Holtmann
Quoted 2 lines

it gives us to determine that eSCO might not be working good enough. So I want output from hcitool info and detailed hcidump.

We can also reproduce this issue with HF850.

hciinfo

Requesting information ...
BD Address: 00:50:CD:20:C6:84
Device Name: Motorola HF850
LMP Version: 1.2 (0x2) LMP Subversion: 0x638
Manufacturer: Cambridge Silicon Radio (10)
Features: 0xff 0xff 0x8f 0xf8 0x18 0x18 0x00 0x80
<3-slot packets> <5-slot packets> <encryption> <slot offset> <timing accuracy> <role switch> <hold mode> <sniff mode> <park state> <RSSI> <channel quality> <SCO link> <HV2 packets> <HV3 packets> <u-law log> <A-law log> <CVSD> <paging scheme> <power control> <transparent SCO> <broadcast encrypt> <enhanced iscan> <interlaced iscan> <interlaced pscan> <inquiry with RSSI> <extended SCO> <AFH cap. slave> <AFH class. slave> <AFH cap. master> <AFH class. master> <extended features>

Attached is hcidump showing the failed eSCO attempt.

You'll notice in this hcidump we retry with SCO after failed eSCO. This is because I have applied the following patch:

commit d5d0c6bf73b3b44f1d66bf4f9d7f3365cce70ff0

Author: Nick Pelly <[email protected]>
Date:   Tue Sep 22 15:19:46 2009 -0700

Bluetooth: Fallback to SCO on error code 0x10 (Connection Accept Timeout).

This is to support the Motorola HF850 carkit which reports the
error code 0x10

    for an eSCO attempt, even though it advertises eSCO support. Here is the
    hcidump:

    2009-09-22 15:40:24.492391 < HCI Command: Setup Synchronous Connection
    (0x01|0x0028) plen 17
        handle 1 voice setting 0x0060
    2009-09-22 15:40:24.493002 > HCI Event: Command Status (0x0f) plen 4
        Setup Synchronous Connection (0x01|0x0028) status 0x00 ncmd 1
    2009-09-22 15:40:30.594869 > HCI Event: Synchronous Connect Complete (0x2c)
    plen 17
        status 0x10 handle 257 bdaddr 00:50:CD:20:C6:84 type eSCO
        Error: Connection Accept Timeout Exceeded

    With this patch we will retry with a SCO connection, which succeeds.

    Unfortunately the Moto HF850 also takes 5 seconds to return the

error for the
eSCO attempt, so it will still take 5 seconds to fallback to SCO with this patch.

net/bluetooth/hci_event.c +0 -0
index e99fe38..7c6f62a 100644
@@ -1700,6 +1700,7 @@ static inline void

hci_sync_conn_complete_evt(struct hci_dev *hdev, struct sk_bu

        case 0x1c:      /* SCO interval rejected */
        case 0x1f:      /* Unspecified error */
+       case 0x10:      /* Connection accept timeout - for Motorola HF850 */
                if (conn->out && conn->attempt < 2) {
                        conn->pkt_type = (hdev->esco_type & SCO_ESCO_MASK) |
                                        (hdev->esco_type & EDR_ESCO_MASK);