Commit graph

9523 commits

Author SHA1 Message Date
Carles Cufi
b41d7f0f0c Bluetooth: Controller: Implement bt_hci_driver::close
The open source controller did not expose support for shutting it down
via the close() API in the HCI driver. Add support for it, which
completes the support for disabling and enabling the Bluetooth stack in
Zephyr.

Closes #3192.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-06-06 12:04:30 +02:00
Carles Cufi
4349a475a8 Bluetooth: Controller: Add deinit() infrastructure
Allow the controller to be deinitialized, adding the whole chain of
calls:

- ll_deinit()
- lll_deinit()
- lll_clock_deinit()

in order to be able to turn everything off, including the controller's
refcount of the LF clock.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-06-06 12:04:30 +02:00
Carles Cufi
11da95bb4d Bluetooth: Host: Properly handle disable()/enable() cycles
When bt_disable() was introduced, some of the global variables that
handle key aspects of Bluetooth were not converted to be also
re-initialized every time that the stack was disabled and the enabled
again. This meant that the FIFO and semaphore in the device structure
were not reset whenever the corresponding threads using them were shut
down and then restarted.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2022-06-06 12:04:30 +02:00
Kamil Gawor
0843ef1cfa bluetooth: host: Fix reading current PHY when using extended advertising
The current PHY is read only when automatic PHY
update procedure is enabled, 2M PHY is supported and
extended advertising is enabled and this is done after
application is notified about connection. This leads
to invalid connection info PHY data which always returns
1M PHY because when using extended advertising the connection
can be established on different PHY and host does not read
this value from the controller in most cases. In order to
have a current PHY value updated we need to read it in
connection complete event before the user application
is notified about connection.

Signed-off-by: Kamil Gawor <Kamil.Gawor@nordicsemi.no>
2022-06-05 14:48:14 +02:00
Herman Berget
c3c7b54ccf Bluetooth: Host: Option for disabling of ATT auto retry
The automatic elevation of security and retry of ATT requests interferes
with some tests that expect authentication failures.

Affecting GATT/CL/GAR/BI-42-C

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-06-05 14:45:32 +02:00
Yuriy Vynnychek
cca221e928 drivers: bluetooth: hci: introduce new Telink B91 HCI driver
Telink B91 Bluetooth HCI driver basic support.

Signed-off-by: Yuriy Vynnychek <yura.vynnychek@telink-semi.com>
2022-06-05 14:45:10 +02:00
Herman Berget
5febfac02c Bluetooth: Allow support for Multiple Variable Length Read without EATT
EATT is not a requirement for the Multiple Variable Length Read
procedure, but previously one had to enable CONFIG_BT_EATT to enable
support for it.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-06-05 14:44:58 +02:00
Mariusz Skamra
33991f2dde Bluetooth: audio: Expose API methods to change the available contexts
This exposes API methods to change the available context types.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-06-05 14:44:21 +02:00
Mariusz Skamra
893f49ea88 Bluetooth: audio: Build PACS only if Sink or Source enabled
This fixes Kconfig that allowed to build PACS without support for sink
or source PACS. Few conditionals that no longer apply were removed.
Enabling ASCS support in specific direction enables related PACS
support.
Since PACS does `depends on` anything, it's safe to make use of `select`
statement.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-06-05 14:44:21 +02:00
Mariusz Skamra
eddfc89ebf Bluetooth: uuid: Rename PACS Available Contexts UUID define
This renames the UUID to follow the same naming scheme as for
BT_UUID_PACS_SUPPORTED_CONTEXT.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-06-05 14:44:21 +02:00
Emil Gydesen
0eb5b3ac03 Bluetooth: Shell: Add gatt notify-mult command
Add GATT command to test the bt_gatt_notify_multiple
function.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-06-05 14:29:33 +02:00
Emil Gydesen
edb30d53d9 Bluetooth: Audio: Fix issues with unicast audio group lifetime
The unicast audio group can not have streams removed after the
CIG has been created as part of the QoS set procedure.

The bt_audio_unicast_group_remove_streams function may
leave the unicast group without streams, and thus the
check for "free" group was not correct, and has been replaced
with a simple boolean value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-06-05 14:13:33 +02:00
Emil Gydesen
2baa0ba710 Bluetooth: Audio: Use bidirectional CIS for unicast audio
The unicast client and server will attempt to use a
bidirectional CIS instead of two unidirectional CIS
whenever possible.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-06-05 14:13:33 +02:00
Emil Gydesen
cc94fa763b Bluetooth: Audio: Make bt_audio_codec_qos_to_iso_qos return void
Change the return type of bt_audio_codec_qos_to_iso_qos to
void as it cannot fail, and this will make it easier to use.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-06-05 14:13:33 +02:00
Emil Gydesen
f77355aaa5 Bluetooth: Audio: Add sink/source ep ref to bt_audio_iso
Add supporting for referercing either a sink endpoint,
a source endpoint or both in the bt_audio_iso struct.

This way a single bt_audio_iso can have references to up
to 2 endpoints.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-06-05 14:13:33 +02:00
Emil Gydesen
e8e1920577 Bluetooth: Audio: Move ISO struct from audio_endpoint
Moves the bt_iso_chan and bt_iso_chan_qos structs
out from the bt_audio_ep struct, and instead use a
reference.

This is due to the fact that an endpoint can ever
only be unidirectional, and a CIS can be bidrectional.

The support for using a single bididrectional CIS
for two audio streams/endpoints is not implemented
in this commit.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-06-05 14:13:33 +02:00
Emil Gydesen
73e8fd6684 Bluetooth: ISO: Move iso_server NULL check for inc. reqs
Move the NULL-check for the iso_server to an earlier point.
There's no need to do anything on the device if no iso_server
has been registered.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-06-05 14:12:50 +02:00
Emil Gydesen
e2e56da061 Bluetooth: Shell: Add security level option to "iso connect"
The "iso connect" now also takes a security level option like
"iso listen", so that the central can easily encrypt
and connect a CIS in a single command.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-06-05 14:12:50 +02:00
Emil Gydesen
57e1056bef Bluetooth: ISO: Guard sec_level with CONFIG_BT_SMP
The ISO security implementation works by verifying
against the acl (bt_conn) sec_level field. The
bt_conn sec_level field is only available
if CONFIG_BT_SMP is enabled, so this commit
adds guards for all ISO security checks as well.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-06-05 14:12:50 +02:00
Emil Gydesen
b3cddc6d27 Bluetooth: ISO: Central security request
If the required_sec_level is lower than the
conn->sec_level, the central will now initialize the
security procecure to ensure that the CIS is encrypted
properly.

The algorithm implemented is as follows:
1) Check security levels for each (acl, iso) pair
2) For those with insufficient security,
   call bt_conn_set_security
3) For those with sufficient security, connect the CIS
4) Once the ISO from 2) has been encrypted, connect the
   CIS for the specific ACL

The idea behind this was to implement similar support
for autonomous encryption as we have for L2CAP.
It is more complex for ISO as we are dealing with
an array of (acl, iso) pairs, meaning more can go
wrong.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-06-05 14:12:50 +02:00
Emil Gydesen
2ace9cb256 Bluetooth: ISO: Add server security check
Add check for connection and server security
levels, and reject the CIS if the ACL security
level is too low.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-06-05 14:12:50 +02:00
Vinayak Kariappa Chettimada
f31b974243 Bluetooth: Host: Fix incorrect ACL buffer count
Fix incorrect ACL buffer count use when Controller used
supports separate ISO buffers.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-06-03 15:11:33 +02:00
Herman Berget
ed0dfb9dd2 Bluetooth: Host: Fix ATT PDU alloc being non-blocking.
The API is documented as being blocking. Making it nonblocking was an
unintentional API change.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-06-03 14:41:09 +02:00
Herman Berget
e494d9c072 Bluetooth: Host: Handle err in l2cap_chan_sdu_sent and l2cap_chan_seg_sent
The error will be propagated to the higher levels.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-06-03 12:52:16 +02:00
Herman Berget
eff10664bd Bluetooth: Host: Do not require the ops->sent callback
The L2CAP channel ops->sent callback was required to call the
l2cap_chan_sdu_sent callback.

Previously, the only difference between the l2cap_chan_sdu_sent and
l2cap_chan_seg_sent callbacks was that l2cap_chan_sdu_sent called
ops->sent. This is no longer true and l2cap_chan_sdu_sent should always
be called when an SDU is sent.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-06-03 12:52:16 +02:00
Herman Berget
bbe5143b95 Bluetooth: Host: Call bt_conn_tx callback with error in error cases
This allows the higher layers to to any required cleanup.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-06-03 12:52:16 +02:00
Herman Berget
5e93b3f192 Bluetooth: Host: Free ATT metadata before calling user callback
In case the user callback tries to allocate metadata for a new ATT PDU.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-06-03 12:52:16 +02:00
Herman Berget
695e5915f8 Bluetooth: Host: Add err parameter to bt_conn_tx_cb_t
This gives more information back to the supplier of the callback.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-06-03 12:52:16 +02:00
Herman Berget
03f941ccb0 Bluetooth: Host: Use correct type for func in ATT metadata
The type should be the user-facing gatt callback, not the internal conn
callback.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-06-03 12:52:16 +02:00
Mariusz Skamra
0492ef5bbf Bluetooth: audio: Fix call control client build
error: 'CONFIG_BT_TBS_MAX_PROVIDER_NAME_LENGTH' undeclared (first use
			in this function); did you mean
			'CONFIG_BT_TBS_CLIENT_MAX_PROVIDER_NAME_LENGTH'?
  292 |            CONFIG_BT_TBS_MAX_PROVIDER_NAME_LENGTH);
      |            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |            CONFIG_BT_TBS_CLIENT_MAX_PROVIDER_NAME_LENGTH
etc.

This fixes build errors that were seen while building call control
client without server side (`CONFIG_BT_TBS`) enabled.
The options like BT_TBS_CLIENT_MAX_URI_LENGTH and
BT_TBS_CLIENT_MAX_PROVIDER_NAME_LENGTH have been removed because those
were not used in the code. In fact the client implementation used the
common options for BT_TBS_MAX_URI_LENGTH and
BT_TBS_MAX_PROVIDER_NAME_LENGTH that were moved in this patch to the
common Kconfig section.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-05-27 17:47:58 -07:00
Emil Gydesen
0813966545 Bluetooth: GATT: Remove use of BT_GATT_ATTRIBUTE macro for discover results
The macro was remove for the GATT discover callbacks,
as only 2 out of 5 parameters for
BT_GATT_ATTRIBUTE were used.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-05-27 15:29:36 -07:00
Vinayak Kariappa Chettimada
192e2a8f94 Bluetooth: Controller: Fix Data Length Request Cmd parameter checking
Fix Data Length Request CMD parameter checking to not
restrict invalid maximum Tx time values. This addresses
conformance test cases that provide maximum Tx time values
of 2128 us when not supporting Coded PHY in the Controller
implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-05-27 15:19:06 -07:00
Jonathan Rico
d3138c937f Bluetooth: host: don't timeout when reconfiguring an l2cap channel
The request timer started on the first l2cap channel when doing an MTU
reconfiguration has to be stopped when the response is received. Else the
channel will get into a bad state.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-05-27 16:03:33 +02:00
Piotr Pryga
131c089aaf Bluetooth: Controller: llcp: Fix wrong eff time calc if PHY changed
If there is a PHY change on a connection it may happen that effective
RX and TX time changes also. That change is applied after an instant.

Implemented handling of effective time calculation is based on the
maximum PDU length, new PHY and local (default) maximum TX or RX time.

The maximum TX value is set to default one that corresponds to PHY 1M
during the Controller initialization. It can be updated by host to other
value. By default Zephyr Host updates it to max possible TX time for all
supported PHYs. If PHY CODED is enabled, it is the longest possible TX
duration 17040 us.

The maximum RX value is set to default during connection creation.
In case of use of legacy advertising, the value is also related with
PHY 1M. It can be updated by data length extension procedure.

If the maximum RX value is set to some value and there is a change
of a PHY to one that requires more time to send a PDU with the same
length, then the maximum RX value is wrongly calculated.

Function pu_calc_eff_time returns a value that is the default_time
argument. The problem is that the default_time should be adjusted
to new maximum RX time required for a new PHY.

To solve that there should be an evaluation of a new maximum RX and
TX time based on new PHY.

The commit adds missing evaluation.

The problem occurred in DF tests that check collision mitigation
between PHY update control procedure and CTE request control procedure.

There was missing CONFIG_BT_CTLR_PHY_CODED option in CTE request
unit tests. The code was working because the ULL implementation of
PHY change control procedure does not verify if PHY CODED is supported.

When missing support was enabled, tests showed wrong evaluation of
maximum RX time. It also unveiled error in CTE request unit tests
implementation. The default_tx_time was set to wrong value 2120 us
as if PHY CODED was not supported. To fix it, the value was changed
to PDU_DC_PAYLOAD_TIME_MAX_CODED.

There was also added a mock for a feature exchange procedure done
during unit tests setup step. That allows to correctly calculate
maximum TX time by ull_dle_max_time_get function.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-05-26 16:29:10 +02:00
Vinayak Kariappa Chettimada
e79c48f7c6 Bluetooth: Controller: Fix missing DUP_FILTER_ADV_SET_MAX dependency
Fix missing BT_CTLR_DUP_FILTER_ADV_SET_MAX dependency on
BT_CTLR_ADV_EXT.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-05-26 12:26:43 +02:00
Vinayak Kariappa Chettimada
59eef60665 Bluetooth: Controller: Fix filter accept list and privacy default
Fix filter accept list and privacy feature Kconfig default
based on whether host has them enabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-05-26 12:26:43 +02:00
Vinayak Kariappa Chettimada
1791a154dc Bluetooth: Controller: nRF5: Fix missing BT_CTLR_PRIVACY cond compile
Fix missing BT_CTLR_PRIVACY conditional compilations that
included redundant HAL code when Controller privacy is
disabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-05-26 12:26:43 +02:00
Vinayak Kariappa Chettimada
5f670fa9c3 Bluetooth: Controller: openisa/RV32M1: Fix BT_CTLR_PRIVACY cond compile
Fix missing BT_CTLR_PRIVACY conditional compilations that
causes compile errors when Controller Privacy is disabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-05-26 12:26:43 +02:00
Vinayak Kariappa Chettimada
620a5524a5 Bluetooth: Controller: Fix PHY update for unsupported PHY
Fix PHY update procedure to handle unsupported PHY requested
by peer central device. PHY update complete will not be
generated to Host, connection is maintained on the old
PHY and the Controller will not respond to PDUs received on
the unsupported PHY.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-05-26 12:24:54 +02:00
Erik Brockhoff
25e6279493 Bluetooth: controller: llcp: fix for failing LL qualification tests
Fixes issue re. sending packets after sending TERMINATE_IND.
Fixes issue re. erroneous error code on 'timed out' termination (ie
when peer does not ack terminate_ind)

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-05-25 16:29:24 +02:00
Erik Brockhoff
7daba33f2d Bluetooth: controller: llcp: update max dle times on feature exchange
On a completion of feature exchange the max DLE times needs to be
updated if Coded PHY has become supported.
For this now also keep a separate store of the default_tx_octets/time
for the sake of re-calculation of local versions of DLE values

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-05-25 16:29:18 +02:00
Casper Bonde
e2dad8fa11 Bluetooth: Broadcast: Fix codec and meta data encoding
Length filed was 1 off.

Signed-off-by: Casper Bonde <casper_bonde@bose.com>
2022-05-25 14:57:33 +02:00
Vinayak Kariappa Chettimada
742173c314 Bluetooth: Controller: Fix prepare pipeline stall
Fix prepare pipeline from not resuming non-resume events
in pipeline when more than one resume events are present
before a non-resume event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-05-25 14:38:18 +02:00
Azizah Ibrahim
e11ff7df48 bluetooth: host: Avoid sending duplicate device to resolving list.
Core v5.3, Vol 4, Part E, 7.8.38
Controller has the option to accept or reject when the same device
is added to RL.
If a remote device has been added to RL before, then local device
change it's advertsing address, and the remote device tries to pair
with the new address, we could end up trying to add the same data to RL.
If a remote device's public/static address is known, this patch deletes
the old entry from RL before adding it.

Signed-off-by: Azizah Ibrahim <azizah.ibrahim@nordicsemi.no>
2022-05-25 14:25:14 +02:00
Szymon Janc
b3de861d15 Bluetooth: Controller: Fix not clearing Static Random Address on reset
When host issue HCI Reset controller should clear LE Static Random
address. Otherwise controller may incorrectly use one from before
HCI reset insread of rejecting HCI commands.

This was affecting following qualification test cases:
HCI/CCO/BI-51-C
HCI/CCO/BI-53-C
HCI/CCO/BI-54-C
HCI/CCO/BI-56-C
HCI/DDI/BI-06-C
HCI/DDI/BI-07-C

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2022-05-25 14:20:21 +02:00
Szymon Janc
42d461d3a2 Bluetooth: Controller: Fix HCI supported commands bitmask
This was affecting HCI/GEV/BV-01-C qualification test case.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2022-05-25 14:19:59 +02:00
Szymon Janc
f0b6774191 Bluetooth: Controller: Fix validating PHY bitmask in HCI
At least one supported PHY bit shall be set and none of
non-supported or RFU bits should be set.

This was affecting HCI/DDI/BI-05-C qualification test case.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2022-05-25 14:19:41 +02:00
Piotr Pryga
f3d460ff5a Bluetooth: Controller: df: Remove experimental for direction finding
Removes label experimental for direction finding feature in
Bluetooth Controller.

The feature stays disabled by default because it requires additional
dedicated hardware to be used. Besides that it significantly enlarges
amount of memory used by the Controller.

End user has to enable the feature explicitly by use of configuration
options.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-05-25 11:48:43 +02:00
Vinayak Kariappa Chettimada
0d7bd277a9 Bluetooth: Controller: Fix preempt timeout not skip first in pipeline
Fix preempt timeout scheduling to not skip first prepare in
pipeline when there are no previous preempt timeout
scheduled already.

Fix related to commit 27b8beaa22 ("Bluetooth: Controller:
Fix to handle relative short preempt timeout").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-05-25 11:14:58 +02:00
Piotr Pryga
729e4f5b1e Bluetooth: Controller: df: Fix check for max CTE num to sample or adv
Maximum number of CTE to be send in a periodic advertising chain is
limited by BT 5.3 Vol 4 Part E, section 7.8.80 and is 16.
Maximum number of samples CTE in a periodic advertising chain is
limited by BT 5.3 Vol 4 Part E, section 7.8.82 and is also 16.
Both values are limited by amount of memory reserved in Controller
by Kcofigs, respectfully: CONFIG_BT_CTLR_DF_PER_ADV_CTE_NUM_MAX and
CONFIG_BT_CTLR_DF_PER_SCAN_CTE_NUM_MAX.

Functions ll_df_set_cl_cte_tx_params and ll_df_set_cl_iq_sampling_enable
check limits against Bluetooth specification provided values.
That can end with memory overwrite if number of requested CTEs is
greater that number provided in configuration.

The commit changes mentioned functions to validate HCI commands
parameters against configuration values.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-05-25 11:09:48 +02:00