Hi,
v9 is mostly cosmetics. Introduces LMP_TRANSPARENT bit in patch 8/8.
v8 declares BT_VOICE_CVSD_16BIT
Merge T*, S* and D* patches in one
The last patch returns -ECONNABORTED when trying to setup a transparent data
connection if eSCO is not supported.
v7 changes defaults to BT_VOICE_CVSD
Remove mask parameter to sco_conn_defer_accept, it was always 0
check the bits for air codec instead of use constants.
Add S3, S2, S1, D1, D0 settings.
The controller default is now only used to initialize the controller or fill
in the missing information in case of using the old Add_SCO command
v6 fixes style issues
v5 changes interface to SOL_BLUETOOTH, BT_VOICE.
Rework fallback mechanism.
This is the patch version 4 of the socket option for enabling transparent SCO.
As requested by Marcel, this is now a 16-bit voice_setting.
0x0000 is the value corresponding to current behavior.
0x0003 is the value to use for enabling transparent data.
It is easy to allow all possible values from Bluetooth core spec, but I guess
results can be unexpected...
Should we filter allowed values in setsockopt ?
Let me know what you think.
Regards,
Fred
Frédéric Dalleau (9):
Bluetooth: Use hci_connect_sco directly
Bluetooth: Remove unused mask parameter in sco_conn_defer_accept
Bluetooth: Add bluetooth socket voice option
Bluetooth: Constants declaration for SCO airmode
Bluetooth: Use voice setting in defered SCO connection request
Bluetooth: Parameters for outgoing SCO connections
Bluetooth: Constants and macro declaration for transparent data
Bluetooth: Prevent transparent SCO on older devices
Bluetooth: SCO connection fallback
include/net/bluetooth/bluetooth.h | 8 ++++
include/net/bluetooth/hci.h | 1 +
include/net/bluetooth/hci_core.h | 9 +++++
include/net/bluetooth/sco.h | 1 +
net/bluetooth/hci_conn.c | 55 +++++++++++++++++++++-----
net/bluetooth/hci_event.c | 3 +-
net/bluetooth/sco.c | 77 ++++++++++++++++++++++++++++++-------
7 files changed, 130 insertions(+), 24 deletions(-)
--
1.7.9.5
hci_connect is a super function for connecting hci protocols. But the
voice_setting parameter is only needed by SCO and security requirements are not
needed for SCO channels. Thus, it makes sense to have a separate function.
Signed-off-by: Frédéric Dalleau <redacted>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
---
include/net/bluetooth/hci_core.h | 2 ++
net/bluetooth/hci_conn.c | 9 +++------
net/bluetooth/sco.c | 3 +--
3 files changed, 6 insertions(+), 8 deletions(-)
From Bluetooth Core v4.0 specification, 7.1.8 Accept Connection Request Command
"When accepting synchronous connection request, the Role parameter is not used
and will be ignored by the BR/EDR Controller."
Signed-off-by: Frédéric Dalleau <redacted>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
---
net/bluetooth/sco.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
This patch extends the current bluetooth socket option to add BT_VOICE.
This is intended to choose voice data type at runtime. It only applies to SCO
sockets.
Incoming connections shall be setup during defered setup. Outgoing connections
shall be setup before connect(). The desired setting is stored in the sco
socket info.
This patch declares needed members, modifies getsockopt() and setsockopt().
Signed-off-by: Frédéric Dalleau <redacted>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
---
include/net/bluetooth/bluetooth.h | 8 ++++++++
include/net/bluetooth/sco.h | 1 +
net/bluetooth/sco.c | 40 ++++++++++++++++++++++++++++++++++++-
3 files changed, 48 insertions(+), 1 deletion(-)
@@ -735,6 +738,31 @@ static int sco_sock_setsockopt(struct socket *sock, int level, int optname, charclear_bit(BT_SK_DEFER_SETUP,&bt_sk(sk)->flags);break;+caseBT_VOICE:+if(sk->sk_state!=BT_OPEN&&sk->sk_state!=BT_BOUND&&+sk->sk_state!=BT_CONNECT2){+err=-EINVAL;+break;+}++voice.setting=sco_pi(sk)->setting;++len=min_t(unsignedint,sizeof(voice),optlen);+if(copy_from_user((char*)&voice,optval,len)){+err=-EFAULT;+break;+}++/* Explicitly check for these values */+if(voice.setting!=BT_VOICE_TRANSPARENT&&+voice.setting!=BT_VOICE_CVSD_16BIT){+err=-EINVAL;+break;+}++sco_pi(sk)->setting=voice.setting;+break;+default:err=-ENOPROTOOPT;break;
@@ -804,6 +832,7 @@ static int sco_sock_getsockopt(struct socket *sock, int level, int optname, char{structsock*sk=sock->sk;intlen,err=0;+structbt_voicevoice;BT_DBG("sk %p",sk);
@@ -829,6 +858,15 @@ static int sco_sock_getsockopt(struct socket *sock, int level, int optname, charbreak;+caseBT_VOICE:+voice.setting=sco_pi(sk)->setting;++len=min_t(unsignedint,len,sizeof(voice));+if(copy_to_user(optval,(char*)&voice,len))+err=-EFAULT;++break;+default:err=-ENOPROTOOPT;break;
This patchs define constants for SCO airmode from SCO voice setting. It refers
to Bluetooth Core V4.0 specification, Part E, Chap 6.12 which describe SCO
voice setting format.
Signed-off-by: Frédéric Dalleau <redacted>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
---
include/net/bluetooth/hci_core.h | 4 ++++
1 file changed, 4 insertions(+)
When an incoming eSCO connection is requested, check the selected voice setting
and reply appropriately. Voice setting should have been negotiated previously.
For example, in case of HFP, the codec is negotiated using AT commands on the
RFCOMM channel. This patch only changes replies for socket with defered setup
enabled.
Signed-off-by: Frédéric Dalleau <redacted>
---
net/bluetooth/sco.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
In order to establish a transparent SCO connection, the correct settings must
be specified in the Setup Synchronous Connection request. For that,
a setting field is added to ACL connection data to set up the desired
parameters.
Remove usage of hdev->voice_setting in CVSD connection.
Make use of T2 parameters for transparent data.
Signed-off-by: Frédéric Dalleau <redacted>
---
include/net/bluetooth/hci_core.h | 1 +
net/bluetooth/hci_conn.c | 21 +++++++++++++++++----
2 files changed, 18 insertions(+), 4 deletions(-)
This patchs define constants and macro for transparent data LMP features. It
refers to Bluetooth Core V4.0 specification, Part C, Chap 3.3 which defines
LMP feature mask.
Signed-off-by: Frédéric Dalleau <redacted>
---
include/net/bluetooth/hci.h | 1 +
include/net/bluetooth/hci_core.h | 1 +
2 files changed, 2 insertions(+)
Older Bluetooth devices may not support Setup Synchronous Connection or SCO
transparent data. This is indicated by the corresponding LMP feature bits.
It is not possible to know if the adapter support these features before setting
BT_VOICE option since the socket is not bound to an adapter. An adapter can
also be added after the socket is created. The socket can be bound to an
address before adapter is plugged in.
Thus, on a such adapters, if user request BT_VOICE_TRANSPARENT, outgoing
connections fail on connect() and returns -EOPNOTSUPP. Incoming connections
do not fail. However, they should only be allowed depending on what was
specified in Write_Voice_Settings command.
Signed-off-by: Frédéric Dalleau <redacted>
---
net/bluetooth/sco.c | 6 ++++++
1 file changed, 6 insertions(+)
When initiating a transparent eSCO connection, make use of T2 settings at
first try. T2 is the recommended settings from HFP 1.6 WideBand Speech. Upon
connection failure, try T1 settings.
When CVSD is requested and eSCO is supported, try to establish eSCO connection
using S3 settings. If it fails, fallback in sequence to S2, S1, D1, D0 settings.
Failure is detected if Synchronous Connection Complete event fails with
error 0x0d. This error code has been found experimentally by sending a T2
request to a T1 only SCO listener. It means "Connection Rejected due to
Limited resource".
To know which setting should be used, conn->fallback is used. Bluez only
attempt to reconnect twice. Since, more than 2 fallback are required,
conn->fallback is tested as an alternative measure. We want to fallback only if
conn->fallback is positive. Calling hci_setup_sync with conn->fallback == 0
triggers initial connection attempt.
These setting and the fallback order are described in Bluetooth HFP 1.6
specification p. 101.
Signed-off-by: Frédéric Dalleau <redacted>
---
include/net/bluetooth/hci_core.h | 1 +
net/bluetooth/hci_conn.c | 37 +++++++++++++++++++++++++++++++------
net/bluetooth/hci_event.c | 3 ++-
3 files changed, 34 insertions(+), 7 deletions(-)
When an incoming eSCO connection is requested, check the selected voice setting
and reply appropriately. Voice setting should have been negotiated previously.
For example, in case of HFP, the codec is negotiated using AT commands on the
RFCOMM channel. This patch only changes replies for socket with defered setup
enabled.
Signed-off-by: Frédéric Dalleau <redacted>
---
net/bluetooth/sco.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
In order to establish a transparent SCO connection, the correct settings must
be specified in the Setup Synchronous Connection request. For that,
a setting field is added to ACL connection data to set up the desired
parameters.
Remove usage of hdev->voice_setting in CVSD connection.
Make use of T2 parameters for transparent data.
Signed-off-by: Frédéric Dalleau <redacted>
---
include/net/bluetooth/hci_core.h | 1 +
net/bluetooth/hci_conn.c | 21 +++++++++++++++++----
2 files changed, 18 insertions(+), 4 deletions(-)
This patchs define constants and macro for transparent data LMP features. It
refers to Bluetooth Core V4.0 specification, Part C, Chap 3.3 which defines
LMP feature mask.
Signed-off-by: Frédéric Dalleau <redacted>
---
include/net/bluetooth/hci.h | 1 +
include/net/bluetooth/hci_core.h | 1 +
2 files changed, 2 insertions(+)
Older Bluetooth devices may not support Setup Synchronous Connection or SCO
transparent data. This is indicated by the corresponding LMP feature bits.
It is not possible to know if the adapter support these features before setting
BT_VOICE option since the socket is not bound to an adapter. An adapter can
also be added after the socket is created. The socket can be bound to an
address before adapter is plugged in.
Thus, on a such adapters, if user request BT_VOICE_TRANSPARENT, outgoing
connections fail on connect() and returns -EOPNOTSUPP. Incoming connections
do not fail. However, they should only be allowed depending on what was
specified in Write_Voice_Settings command.
Signed-off-by: Frédéric Dalleau <redacted>
---
net/bluetooth/sco.c | 6 ++++++
1 file changed, 6 insertions(+)
When initiating a transparent eSCO connection, make use of T2 settings at
first try. T2 is the recommended settings from HFP 1.6 WideBand Speech. Upon
connection failure, try T1 settings.
When CVSD is requested and eSCO is supported, try to establish eSCO connection
using S3 settings. If it fails, fallback in sequence to S2, S1, D1, D0 settings.
Failure is detected if Synchronous Connection Complete event fails with
error 0x0d. This error code has been found experimentally by sending a T2
request to a T1 only SCO listener. It means "Connection Rejected due to
Limited resource".
To know which setting should be used, conn->fallback is used. Bluez only
attempt to reconnect twice. Since, more than 2 fallback are required,
conn->fallback is tested as an alternative measure. We want to fallback only if
conn->fallback is positive. Calling hci_setup_sync with conn->fallback == 0
triggers initial connection attempt.
These setting and the fallback order are described in Bluetooth HFP 1.6
specification p. 101.
Signed-off-by: Frédéric Dalleau <redacted>
---
include/net/bluetooth/hci_core.h | 1 +
net/bluetooth/hci_conn.c | 37 +++++++++++++++++++++++++++++++------
net/bluetooth/hci_event.c | 3 ++-
3 files changed, 34 insertions(+), 7 deletions(-)
Now this is duplicated code here. Please select the array and then apply it in a generic section.
In addition you can not use __constant_cpu_to_le16 anymore since these values are now coming from a struct and not from a define.
hci_conn_add_sysfs(conn);
break;
+ case 0x0d: /* No resource available */
This should be a separate patch with its own commit message explaining why we handle this error.
case 0x11: /* Unsupported Feature or Parameter Value */
case 0x1c: /* SCO interval rejected */
case 0x1a: /* Unsupported Remote Feature */
case 0x1f: /* Unspecified error */
- if (conn->out && conn->attempt < 2) {
+ if (conn->out && (conn->attempt < 2 || conn->fallback > 0)) {
I wonder if you can not just use conn->attempt and how it counts up here. It should give you the correct position in the parameter array. And conn->fallback becomes obsolete.
In order to establish a transparent SCO connection, the correct settings must
be specified in the Setup Synchronous Connection request. For that,
a setting field is added to ACL connection data to set up the desired
parameters.
Remove usage of hdev->voice_setting in CVSD connection.
Make use of T2 parameters for transparent data.
Signed-off-by: Frédéric Dalleau <redacted>
---
include/net/bluetooth/hci_core.h | 1 +
net/bluetooth/hci_conn.c | 21 +++++++++++++++++----
2 files changed, 18 insertions(+), 4 deletions(-)