Bluetooth: Remove unused mask parameter in sco_conn_defer_accept

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 <frederic.dalleau@linux.intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Bluetooth: Add bluetooth socket voice option

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 <frederic.dalleau@linux.intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Bluetooth: Constants declaration for SCO airmode

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 <frederic.dalleau@linux.intel.com>
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Bluetooth: Use voice setting in defered SCO connection request

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 <frederic.dalleau@linux.intel.com>
Bluetooth: Parameters for outgoing SCO connections

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 <frederic.dalleau@linux.intel.com>
Bluetooth: SCO connection fallback

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 <frederic.dalleau@linux.intel.com>
Bluetooth: Prevent transparent SCO on older devices

Older Bluetooth devices may not support Setup Synchronous Connection. This is
indicated by the eSCO support feature bit. It is not possible to know if the
adapter support eSCO 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 requested something else than
BT_VOICE_CVSD_16BIT, outgoing connections fail on connect() and returns
-ECONNABORTED. 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 <frederic.dalleau@linux.intel.com>