Commit graph

9523 commits

Author SHA1 Message Date
Troels Nilsson
7c6eb242a9 Bluetooth: Fix endianness handling for ext scan reports evt_type
evt_type is 16 bits and thus requires endianness conversion over HCI

Signed-off-by: Troels Nilsson <trnn@demant.com>
2023-06-21 16:06:36 +02:00
Vinayak Kariappa Chettimada
8c7140a9c0 Bluetooth: Controller: Fix BT_CTLR_CENTRAL_SPACING to ticks conversion
Fix missing BT_CTLR_CENTRAL_SPACING in microseconds to ticks
conversion.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-06-21 14:49:36 +02:00
Emil Gydesen
8b9815aff6 Bluetooth: IAS: Fix alert level loop
The loop was supposed to set the alert level to the highest
value by any device. The loop, however, only made sense if
CONFIG_BT_MAX_CONN > 1.

It has been modified to start from [0] instead of [1] and
the initial condition was modified.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-21 09:34:49 +02:00
Emil Gydesen
1f1e51ad6b Bluetooth: Shell: Fix typo in disconnected
A callback function had a typo where disconencted should
have been disconnected.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-20 10:44:07 +00:00
Aleksandr Khromykh
a13157f997 Bluetooth: Mesh: fix missed old encryption in dfu metadata
PR fixes the old internal encryption api usage
for dfu metadata.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2023-06-20 10:10:19 +02:00
Aleksandr Khromykh
327eb119b6 Bluetooth: Mesh: add tf-m support for ble mesh
This PR adds ability to build mesh with tf-m psa
for platforms those support tf-m.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2023-06-19 15:04:17 +02:00
Michał Grochala
5ac063d793 bluetooth: controller: Fix build with BT_HCI_VS_EXT disabled.
Fixing error: undefined reference to 'vs_set_min_used_chans'
when building with 'BT_HCI_VS_EXT' option disabled.

Signed-off-by: Michał Grochala <michal.grochala@nordicsemi.no>
2023-06-19 11:02:14 +02:00
Aleksandr Khromykh
a322e4d20d Bluetooth: Mesh: clarification about adv local identity
BT_ID_DEFAULT is hardcoded in mesh. Added clarification about
the necessity of another local identity allocation for BLE
if it coexists with mesh.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2023-06-19 11:01:30 +02:00
Ingar Kulbrandstad
ce3317d03e Bluetooth: Mesh: Updated ACL configuration settings
Setting default value for BT_BUF_ACL_TX/RX_SIZE and
BT_CTLR_DATA_LENGTH_MAX to 37, as this will process the
incoming data the most efficient way.
When GATT is enable BT_BUF_ACL_RX_SIZE does not have to be 73,
as this will just give segmented messages for the public keys
exchange during provisioning.

Signed-off-by: Ingar Kulbrandstad <ingar.kulbrandstad@nordicsemi.no>
2023-06-17 08:06:16 -04:00
Pavel Vasilyev
47e3c5386a Bluetooth: Mesh: Add option to disable Label UUIDs recovery
After adding support for virtual addresses with collision (where two
Label UUIDs have the same virtual address), the format of the data in
the persistent storage with the Label UUIDs which a model is subscribed
to or publishes to has been changed. The recovery code is added and the
Label UUIDs will be recovered by picking first Label UUID matching to
the virtual address in the subscription list or model publication. This
options can disable the recovery code and save some flash if the
recovery is not required (e.g. virtual address support wasn't enabled
before this option was added, or the devices were unprovisioned before
upgrading to the version with this option).

Making this option as deprecated to be able to drop support of this
option and remove the recovery code eventually.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-06-17 08:00:55 -04:00
Pavel Vasilyev
648378b292 Bluetooth: Mesh: Add full virtual addresses support
This commit adds the following features related to virtual addresses
support:
- Allows to store Label UUIDs which virtual addresses collide;
- Allows to decrypt messages encrypted with a virtual address with
collision;
- Allows to publish a message to a specific Label UUID to avoid virtual
addresses collision by adding a pointer to Label UUID to
struct bt_mesh_msg_ctx and struct bt_mesh_model_pub;
- Allows to differentiate Label UUIDs in the model's Subscription List
by storing all subscribed UUIDs in struct bt_mesh_model.uuids field.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-06-17 08:00:55 -04:00
Pavel Vasilyev
1956b06ecc Bluetooth: Mesh: Don't poll friend when sending over loopback
When LPN sends a segmented message to itself, it unnecesseraly polls
Friend. Since Friend doesn't receive this message, the segmented message
transmission will eventually fail (send end callback will return error),
while the message will actually be passed to the access layer.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-06-17 08:00:55 -04:00
Théo Battrel
37cac7f2e2 Bluetooth: Host: Use custom API for Bluetooth settings
This commit wrap the `settings_set_one` and `settings_delete` functions
in `bt_settings_store_one` and `bt_settings_delete`. By doing that the
Bluetooth settings can be managed in a single place.

This commit also introduce a new API to manage Bluetooth storage with
`bt_settings_store_*` and `bt_settings_delete_*` functions. Each
Bluetooth settings key have their own store and delete functions. Doing
that so custom behavior for key can be done if necessary.

This change is motivated by a need of keeping track of different
persistently stored settings inside the Bluetooth subsystem. This will
allow a better management of the settings that the Bluetooth subsystem
is responsible of.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2023-06-17 07:58:07 -04:00
Gerard Marull-Paretas
b617f03439 bluetooth: controller: rv32m1: configure debug pins in DEBUG_INIT
The debug pins were configured in a board specific file, however, the
subsys/bluetooth/controller/ll_sw/openisa/hal/RV32M1/debug.h file
already contains board-specific pins, meaning there's no need to split
the information in 2 places. Move the GPIO configuration calls to the
DEBUG_INIT() macro in the controller debug header.

Note that in the future, Devicetree should be used to provide a
hardware-agnostic debug module.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2023-06-17 07:50:21 -04:00
Morten Priess
3cecb92e53 Bluetooth: controller: Fix CIS peripheral conditional offset_min
When config BT_CTLR_PERIPHERAL_ISO_EARLY_CIG_START is enabled, the
minimum accepted offset value in the CIS_REQ is the minimum defined by
the spec.
Add define CIS_MIN_OFFSET_MIN with value 500 us, as defined in the Core
spec. The previously used value of 400 us was incorrect.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2023-06-17 07:48:01 -04:00
Aleksandr Khromykh
29895d8275 Bluetooth: Mesh: refactor mesh to use both tinycrypt and psa based crypto
A mesh key type has been added to be able to choose the different
key representation for different security libraries.
The type as well as some functionality related to Mesh key
management has been added as a public API.
If tynicrypt is chosen then keys have representation
as 16 bytes array. If mbedTLS with PSA is used then keys are
the PSA key id. Raw value is not kept within BLE Mesh stack
for mbedTLS. Keys are imported into the security library
and key ids are gotten back. This refactoring has been done
for the network(including all derivated keys), application,
device, and session keys.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2023-06-17 07:46:03 -04:00
Emil Gydesen
118a68518a Bluetooth: Shell: bt connect-name should only attempt connectable
The auto-connect by name did not verify that the found device
was connectable before attempting to connect.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-17 07:38:40 -04:00
Pavel Vasilyev
c301ed07ca Bluetooth: Mesh: Regenerate private beacon even when disabled
Even if PRB state is disabled, PRB can still be sent over GATT if Proxy
Privacy parameter is enabled. In such case PRB won't be regenerated.
To keep the privacy of the network, PRB should be regenerated when sent
over GATT regardless of PRB state.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-06-17 07:37:20 -04:00
Pavel Vasilyev
dfb8bcaf38 Bluetooth: Mesh: Fix Proxy Privacy parameter support
According to section 6.7, upon connection Proxy Server shall determine
value of Proxy Privacy parameter (sections 6.5 and 7.2.2.2.6). Depending
on that, it will either send Secure Network Beacon or Private Beacon to
Proxy Client, but never both.

Proxy Privacy parameter is determined by GATT Proxy, Node Identity
states and their private counterparts (section 7.2.2.2.6). Since
non-private and private states are mutually exclusive, it is enough to
only check either Private GATT Proxy state or Private Node Identity
state of any known subnet for which the state is currenty enabled.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-06-17 07:37:20 -04:00
Pavel Vasilyev
c952cf4818 Bluetooth: Mesh: Fix binding between proxy related states
Fix binding between GATT Proxy, Node Identity and their private
counterpart states according to sections 4.2.45.1 and 4.2.46.1
accordingly. When non-private state is enabled, the private counterpart
is disabled. The reverse binding prohibits change of non-private state.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-06-17 07:37:20 -04:00
Pavel Vasilyev
2d13329eca Bluetooth: Mesh: Store Private GATT Proxy state persistently
State should be stored persistently.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-06-17 07:37:20 -04:00
Jonathan Rico
931a089e2c Bluetooth: host: invalidate the RPA when starting legacy adv
This fixes the failure to use a resolvable private address in this
scenario.

1. call `bt_le_oob_get_local`, will generate and mark RPA as valid
2. start connectable adv w/ IDENTITY bit
3. start connectable adv w/o IDENTITY
4. RPA is not set (in `bt_id_set_private_addr`) because RPA
   is still marked as valid

When EXT_ADV is enabled and the controller supports it, a different code
path is taken that doesn't have this issue.

Unconditionally invalidating the RPA when starting advertising works around
this issue.

Fixes #56326

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2023-06-17 07:36:58 -04:00
Donatien Garnier
cf0350e021 Bluetooth: Host: Re-order LE L2CAP connection accept procedure
Currently, when an incoming dynamic LE L2CAP connection is requested by
a peer, the connected() callback provided by the user is raised
*before* a L2CAP_LE_CREDIT_BASED_CONNECTION_RSP is sent back to the
peer.
In some cases the user will start sending data in the connected()
callback which would be received too early by the peer.
This commit fixes this behavior by making sure the connected() callback
is raised only after the connection response has been sent to the peer.

Signed-off-by: Donatien Garnier <donatien.garnier@blecon.net>
2023-06-17 07:33:11 -04:00
Théo Battrel
363676764a Bluetooth: Host: Fix wrong ID being stored
Fix an issue causing a wrong Bluetooth identity value to be stored. It
was happening because the `bt_dev.id_count` was incremented after the
settings being stored.

To fix this, `bt_dev.id_count` is now incremented right before the ID
creation and is decremented if the ID creation failed.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2023-06-16 07:57:46 -04:00
Pavel Vasilyev
8902de75eb Bluetooth: Mesh: Print UUID with correct endianess
bt_uuid_str expects UUID in little endian while UUID encoded into
unprovisioned mesh beacon is encoded in big endian. sys_memcpy_swap will
change endianess of uuid so that bt_uuid_str can be used.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-06-13 07:05:21 -04:00
Pavel Vasilyev
21b5d423e8 Bluetooth: Mesh: Fix printing UUID log message
CONFIG_BT_MESH_PROV_DEVICE_LOG_LEVEL_INF may not be present while
CONFIG_BT_MESH_PROV_DEVICE_LOG_LEVEL is always present.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-06-13 07:05:21 -04:00
Emil Gydesen
bb81b42861 Bluetooth: TBS: Ensure that inst exist when notifying terminate
When calling the `terminate_call` the `inst` would always be NULL
as we had just terminated the call that we attempted to look up.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-13 07:00:02 -04:00
Vinayak Kariappa Chettimada
fc210a8cee Bluetooth: Controller: Fix disable all advertising sets
BlueZ stack in Linux distributions use disable all
advertising sets when advertising is turned off.

Add missing implementation to support disabling all
active advertising sets.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-06-12 07:28:25 -04:00
Vinayak Kariappa Chettimada
05aabdc6d9 Bluetooth: Controller: Rework internal header includes
Rework internal header files to not have includes, rather
have the required includes in the c source files.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-06-12 06:20:24 -04:00
Carles Cufi
22f73992b2 Bluetooth: Rework the HCI header set
In order to have clean, self-contained HCI headers that do not have any
dependencies towards the Host or any other part of the system (except
types), reorganize the headers in the following way:

- Split out the macros and structs from hci.h to a new hci_types.h
- Merge the existing hci_err.h into the new hci_types.h

Fixes #58214.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2023-06-12 06:20:24 -04:00
Lars Knudsen
a7254b85e1 shell: Fix BT verbose scan logging
Fix endianness printout of values.

Handle service data output with initial UUID.

Signed-off-by: Lars Knudsen <lakd@demant.com>
2023-06-11 05:08:08 -04:00
Emil Gydesen
7712f81171 Bluetooth: CAP: Shell: Add cmd_cap_initiator_unicast_cancel
Add cmd_cap_initiator_unicast_cancel to call the cancel
function.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-10 05:16:39 -04:00
Emil Gydesen
e9c1be88ca Bluetooth: CAP: Add Initiator cancel procedure
Add function to cancel any current proecedure. This is useful
in cases where the connection to one or more acceptors is lost
or if some acceptor does not respond to our requests for whatever
reason.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-10 05:16:39 -04:00
Emil Gydesen
65c2f8ef37 Bluetooth: BAP: Release stream on codec config if requested
An ASCS endpoint may go into either the idle or codec configured
state when a stream is released. However since we have such a high
coupling between audio streams and endpoints, we need to consider
the endpoint as having been released (i.e. gone to the IDLE state).

This is handled by a boolean state variable for now, but we may
want to consider a more generic approach where streams and
endpoints may be less coupled.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-10 05:15:37 -04:00
Emil Gydesen
f3f8380296 Bluetooth: BAP: modify when ASCS disconnects the CIS
When an audio stream in a bidirectional CIS is released,
it should not disconnect the CIS if there is still a stream
for the opposite direction streaming. Only if both streams
are not in a streaming state, should ASCS attempt to disconnect
the CIS.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-10 05:15:37 -04:00
Emil Gydesen
bc89eabfdd Bluetooth: BAP: Remove bad log error from bt_audio_valid_codec
There was a LOG_ERR from debugging.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-10 05:14:12 -04:00
Emil Gydesen
1a3fd597a8 Bluetooth: ISO: Log status as hex instead of decimal
Log status values in events as hex instead of decimal
to make it easier to compare to the spec and hci_err.h

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-09 14:16:15 -04:00
Emil Gydesen
028e0a3c8d Bluetooth: Shell: On disconnect set new default_conn
When a device disconnects we previously just unref'ed it and
set default_conn = NULL. However, if we are connected to mulitple
devices, it makes sense to set the default_conn to one of the
other connections.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-08 11:50:34 -04:00
Emil Gydesen
f282ce90cc Bluetooth: MPL: Modify parse_search to use bt_data_parse
Modify the implementation of parse_search to use a
net_buf_simple and bt_data_parse to parse the LTV
search structure.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-08 11:49:58 -04:00
Carles Cufi
c0c2c6e35c Bluetooth: Host: Set valid default for secondary adv phy
Set the secondary advertising PHY to a valid value when using
legacy advertising through the LE Set Extended Advertising Parameters
command.

Fixes #57885.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2023-06-08 09:33:30 -04:00
Vinayak Kariappa Chettimada
466f3e8e70 Bluetooth: Controller: Fix cis_offset_min to have additional margin
As the coarse tick of ACL prepare and CIG prepare jitter by
+/- 1 tick, hence when initially scheduling the CIG place it
with enough margin so that cis_offset_min calculated when
there already exists a CIG can be larger than peer's
cis_offset_min being negotiated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-06-08 06:50:41 -04:00
Vinayak Kariappa Chettimada
4195ba5870 Bluetooth: Controller: Fix read ISO Tx Sync for Broadcast ISO
Fix missing read ISO Tx Sync for Broadcast ISO feature.

Co-authored-by: Nirosharn Amarasinghe <niag@demant.com>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-06-08 06:47:48 -04:00
Vinayak Kariappa Chettimada
48f6411416 Bluetooth: Controller: Fix Broadcast ISO interval unit
Fix incorrectly stored Broadcast ISO interval in
microseconds instead of storing in 1.25 ms units.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-06-08 06:47:48 -04:00
Vinayak Kariappa Chettimada
52c5ce97d4 Bluetooth: Controller: Update BT_CTLR_ISOAL_SN_STRICT help text
Update BT_CTLR_ISOAL_SN_STRICT help text.

Co-authored-by: Nirosharn Amarasinghe <niag@demant.com>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-06-08 06:47:25 -04:00
Vinayak Kariappa Chettimada
5f38c4ba71 Bluetooth: Controller: Fix Tx ISO SDUs dropped due to strict SN check
Introduce a Kconfig BT_CTLR_ISOAL_SN_STRICT to relax the Tx
ISO Data SDUs being dropped due to strict check of sequence
numbers in ISOAL, i.e. dropped when ISO Data SDUs are
delayed from upper layer with respect to the current
payload number in the ISO radio events.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-06-08 06:47:25 -04:00
Vinayak Kariappa Chettimada
54aa6f1075 Bluetooth: Controller: Fix ISOAL sink create role for ISO Receiver
Fix ISOAL sink create role for ISO Receiver.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-06-08 12:25:31 +02:00
Pavel Vasilyev
242c8f1c77 Bluetooth: Mesh: Avoid undefined behavior in bit shift in blob_cli.c
block_size_log can be 0x20 which will shift 1 by 32 bits which will
cause undefined behavior. Adding ULL to 1 is an option but this will add
little bit more code when debug option is enabled. So simply print the
logarithmic value.

Coverity-ID: 316387
Fixes #58951

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-06-08 04:11:29 -04:00
Théo Battrel
cfd368fef1 Bluetooth: Host: Fix GATT server handling of CCC
GATT server was not doing enough check before udpating the CCC.

For example, a non-bonded client could update the CCC of a bonded client
by spoofing his address.

This fix the issue by dissociating the CCC configuration of a bonded and
a non-bonded peer. To do that, a new field is added to the CCC config:
`link_encrypted`.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2023-06-08 04:10:58 -04:00
Lingao Meng
b6fc474777 Bluetooth: Mesh: Fix unable sent mesh message
In PR (#58723) has introduce another bug, that,
the flag ADV_FLAG_PROXY set before actually enabled.

When ctx:: BT RX call schedule_send will atomic_test_and_clear
ADV_FLAG_PROXY, but at this time, the proxy advertising will
not at advertising state, maybe in update params or set adverting
data phase,

so that, call bt_le_ext_adv_stop will nothing, and then call
k_work_reschedule --> send_pending_adv(at this time, the proxy
advertising actually enabled, but the upper layer clear proxy flags),
cause latest advertising unable start, because unable in advertising
state to update params(-EINVAL).

Fixes: #58721

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2023-06-08 04:09:04 -04:00
Mariusz Skamra
a84ecc2f96 Bluetooth: audio: tbs_client: Remove GATT subscriptions upon disconnection
As long as we do not have NVS support in TBS, the subscriptions shall be
removed once ACL is disconnected to avoid potential crash on
reconnection, as the subscription parameters might be not valid anymore.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-06-06 11:10:10 -04:00