Commit graph

9523 commits

Author SHA1 Message Date
Ahmed Moheb
eea982e91e bluetooth: host: keys: Check if returned key matches keys pool item
bt_keys_find_addr() is used to find key by both ID and address.
Following checks must continue to compare ID and address as well.
Or, we can compare key references which is faster.

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2022-09-05 12:22:13 +02:00
Ahmed Moheb
21882c5779 bluetooth: host: keys: Add assertions to check arguments
Check arguments passed to APIs with assertions.

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2022-09-05 12:22:13 +02:00
Ahmed Moheb
ad5b154250 bluetooth: host: keys: Add APIs docs
Add API documentation to describe behavior, args and return value.

Signed-off-by: Ahmed Moheb <ahmed.moheb@nordicsemi.no>
2022-09-05 12:22:13 +02:00
Emil Gydesen
68e17426ac Bluetooth: Audio: Support setting non-HCI data path for audio streams
Add support for setting a vendor specific data path using
the BAP API, instead of only support the HCI data path.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-09-02 14:16:49 +02:00
Emil Gydesen
1099030210 Bluetooth: ISO: Modify cc in bt_iso_chan_path
The CC/Codec Configuration in bt_iso_chan_path was
defined as an array of size 0. This meant that the
CC always had to be allocated right after the
bt_iso_chan_path struct.

This does not give a very flexible API, and also makes
it impossible for two bt_iso_chan_path to share the same
CC.

The API is modified so that the CC is simply a pointer
to a an array now.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-09-02 14:16:49 +02:00
Emil Gydesen
e2055e158c Bluetooth: Audio: Fix error check for bt_gatt_subscribe error log
We shouldn't log an error if we are already subscribed to the device.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-09-02 10:59:23 +00:00
Herman Berget
e65fdd4c5e Bluetooth: Host: Clean up buffer user data in case of error
`bt_l2cap_chan_send_cb()` overwrote the buffer user data for internal
use. In the case where sending fails, this would be visible for the
caller. If the caller relied on the buffer user data to be unchanged,
this could cause unexpected behavior.

L2CAP tx metadata was also not freed in the error case.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-09-01 14:58:08 +00:00
Vinayak Kariappa Chettimada
b294b6e648 Bluetooth: Controller: Fix prepare pipeline preempt timeout stop
Fix prepare pipeline preempt timeout stop from stopping a
a prevously started timeout for the next in pipeline event.

The preempt timeout started prior for the current event that
has its prepare that is invoked is to be not explicitly
stopped. If there is a next prepare event in pipeline, then
the prior preempt timeout if started will be stopped before
starting the new preempt timeout. Refer to implementation in
preempt_ticker_start().

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-01 13:18:11 +02:00
Vinayak Kariappa Chettimada
ddf04997a5 Bluetooth: Controller: Add abort fairness in overlapping Periodic Sync
Add implementation in Periodic Sync LLL abort to use near
fair scheduling to ensure overlapping multiple Periodic
Sync set each get to use the radio and not lead to Sync
Loss.

The implementation is used when overlap in radio event
happens in unreserved time space of the event. An abort
count is maintain in each Periodic Sync instance and is
used to decide whether the current event or the next
event is to be aborted when they overlap.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-01 13:18:11 +02:00
Vinayak Kariappa Chettimada
1a1f347ad3 Bluetooth: Controller: Add Kconfig for minimal time reservation
Add Kconfig to use minimal time reservation for auxiliary
and sync PDU reception. A peer device could be scheduling
multiple advertising sets in a short duration with small
PDUs hence using the minimal time reservation would avoid
skipping closely scheduled reception of multiple auxiliary
PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-09-01 13:18:11 +02:00
Adam Augustyn
6986185c81 Bluetooth: Host: Clear random address field in bt_dev in bt_disable()
This commit clears cached random address in bt_dev when calling
bt_disable(). This change makes future calls of set_random_address()
function possible with previously used address value, after BLE stack
re-initialization. Without this change no HCI command was sent, see this
condition in set_random_address():

/* Do nothing if we already have the right address */
if (!bt_addr_cmp(addr, &bt_dev.random_addr.a)) {
	return 0;
}

Signed-off-by: Adam Augustyn <adam.augustyn@hidglobal.com>
2022-09-01 10:36:40 +02:00
Jonathan Rico
f10db5e5cb Bluetooth: smp: Fix SC with fixed passkey
passkey confirm should not be called when secure connections are enforced.

Fixes #49599

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-09-01 10:27:34 +02:00
Pavel Vasilyev
52b423e18c Bluetooth: Mesh: Replace segack tx delay with Kconfig options
Additional uncontrolled delay for transmitting segack affects throughput
of the segmented messages. Though the best throughput can be achieved
with the smallest allowed values, move them to Kconfig option so that
the segack delay can be controlled by a user.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-09-01 10:27:27 +02:00
Morten Priess
da402c0830 Bluetooth: controller: Implements ISO Test Mode HCI commands
Implements the flollowing HCI commands:
- HCI_LE_ISO_Transmit_Test
- HCI_LE_ISO_Receive_Test
- HCI_LE_ISO_Read_Test_Counters
- HCI_LE_ISO_Test_End

Signed-off-by: Morten Priess <mtpr@oticon.com>
2022-08-31 21:50:13 +00:00
Adam Wojasinski
47db797236 Bluetooth: controller: Replace deprecated nrfx API
This commit replaces API that became deprecated with the release
of nrfx2.9 - see CHANGELOG in zephyrproject-rtos:hal_nordic repository

Signed-off-by: Adam Wojasinski <adam.wojasinski@nordicsemi.no>
2022-08-31 10:43:14 +02:00
Pirun Lee
c4bd693d9a Bluetooth: OTS - Client APIs add Object Write sub-procedure
OTS client: Add object write function.
Also add write object callback.

Signed-off-by: Pirun Lee <pirun.lee@nordicsemi.no>
2022-08-31 10:39:33 +02:00
Vinayak Kariappa Chettimada
94710e0f6d Bluetooth: Controller: Kconfig to permit periodic sync event skip
When AUX_ADV_IND or AUX_CHAIN_IND auxiliary channel PDU scan
radio event overlaps Periodic Sync radio event in unreserved
time space, let the Periodic Sync radio event be aborted so
that the auxiliary channel PDU can be received to generate
Extended Advertising Reports. Added a new Kconfig to enable
this.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-30 10:30:16 +02:00
Emil Gydesen
32b2a3e218 Bluetooth: Audio: Update audio shell with location in cmd_init
Set the location in the init command. Also updates the
available context to the CONTEXT macro value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-08-30 10:27:00 +02:00
Hang Fan
5b8b3a74d6 Bluetooth: audio: mcc: add NULL check for mcs instance
Add NULL check for mcs instance to avoid access violation crash.

Signed-off-by: Hang Fan <fanhang@xiaomi.com>
2022-08-30 10:25:36 +02:00
Herman Berget
096fc3b826 Bluetooth: Increase RX thread stack size
Normal usage for Bluetooth applications are getting close to or
already overflowing the default BT RX stack size of 1024.

For example:
 - Discovery using the fixed ATT channel used 984 bytes.
 - Discovery using an enhanced ATT channel used 1048 bytes,
   which would lead to stack overflow using the default BT RX thread
   stack size.

Signed-off-by: Herman Berget <herman.berget@nordicsemi.no>
2022-08-26 12:52:22 +02:00
Jakob Krantz
605d8c85d8 Bluetooth: Host: Fix invalid sync term callback params
When using periodic advertising list and receiving
hci_le_per_adv_sync_established event from controller with
an error code the bt_le_per_adv_sync_term_info would be
incorrectly populated with le_addr and sid. This is because
the current pending advertising sync object is not populated
with any le_addr and sid from bt_le_per_adv_sync_create as
those are not used when option
BT_LE_PER_ADV_SYNC_OPT_USE_PER_ADV_LIST is set.

Instead the bt_le_per_adv_sync_term_info shall be populated
with the le_addr and sid coming in the event from controller.

Signed-off-by: Jakob Krantz <jakob.krantz@u-blox.com>
2022-08-26 12:51:05 +02:00
Erik Brockhoff
7719bc6785 Bluetooth: controller: llcp: fix unhandled rsp in periph phy upd proc
Re. peripheral phy update procedure: UNKNOWN_RSP from central was not
handled, leading to stall of procedure and subsequent procedure timeout

Proper handle and unit test for case added.

Signed-off-by: Erik Brockhoff <erbr@oticon.com>
2022-08-26 11:56:33 +02:00
Emil Gydesen
70dfbb6747 Bluetooth: Audio: Add missing NULL checks when looking up audio_iso streams
Multiple places we assumed that we could simply just do
sink_stream->iso == chan without checking if sink_stream
was NULL.

This commit fixes that by adding proper NULL checks for that,
as well as additional checks before defaulting to the
source_stream.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-08-26 11:56:15 +02:00
Stephanos Ioannidis
074b7f4ecd Bluetooth: Define global Bluetooth address constants
The Bluetooth address constants (BT_ADDR[_LE]_ANY, BT_ADDR[_LE]_NONE)
are currently defined as the address of the local anonymous structs
that are initialised to the corresponding address values, and assigning
them to a variable whose scope is greater than that of a function may
end up creating dangling pointers (for instance, as done in the
`bt_conn_get_info` function).

This commit defines the Bluetooth address constants as global constant
variables that are placed in the read-only data section, and modifies
the Bluetooth address constant macros to use the address of these
variables instead.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-08-25 12:18:09 +02:00
Stephanos Ioannidis
13885bd6d5 Bluetooth: Host: Monitor: Make addr param const in bt_monitor_new_index
This commit adds the `const` qualifier to the `addr` parameter of the
`bt_monitor_new_index` function because this parameter is and should
never be modified within this function.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-08-25 12:18:09 +02:00
Stephanos Ioannidis
97f9a16ed1 Bluetooth: Host: GATT: Make addr param const in find_sc_cfg
This commit adds the `const` qualifier to the `addr` parameter of the
`find_sc_cfg` function because this parameter is and should never be
modified within this function.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2022-08-25 12:18:09 +02:00
Vinayak Kariappa Chettimada
689bf9b015 Bluetooth: Controller: Fix uninitialized adv mode in scan rsp PDU
Fix uninitialized adv mode value in the scan response PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-24 12:41:21 +02:00
Vinayak Kariappa Chettimada
4938d2a0d4 Bluetooth: Controller: Fix regression in overlapping 1M and Coded Scan
Fix regression in overlapping 1M and Coded PHY scan window
by considering rounding margins when checking for same
interval and same window durations.

Relates to commit c14bde45b6 ("Bluetooth: Controller: Fix
overlapping 1M and Coded PHY scannning").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-24 10:04:20 +02:00
Emil Gydesen
d62223e930 Bluetooth: Audio: Fix unicast_client avail ctx dir check
The unicast_client_pacs_avail_ctx_notify_cb had a direction
check that was a leftover copy from the location notification.

However the context notification is always for both sink and
source, and thus does not need any direction checks (in fact
the dir variable was unused).

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2022-08-23 16:24:24 +02:00
Mariusz Skamra
a120af8f33 Bluetooth: audio: ascs: Fix missing metadata reset before update
The old metadata shall be reset (simply set the couynt to zero) before
reuse or update.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-23 16:22:11 +02:00
Mariusz Skamra
c57ba529dc Bluetooth: audio: ascs: Remove invalid check
This fixes invalid check, which is redundant in fact as the length
is already checked in ascs_parse_metadata function.
The check be test 'greater than' only, as 'equal' condition is valid.
Moreover this fixes return value from ascs_verify_metadata function.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-23 16:22:11 +02:00
Anders Storrø
5f8168d5dd Bluetooth: Mesh: Health_cli: Fix fault test rsp
Swaps response scheme for Fault_test command so that it
aligns with description of the documentation.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2022-08-23 16:21:54 +02:00
Vinayak Kariappa Chettimada
ce0f65e768 Bluetooth: Controller: Enable back-to-back PDU chaining
When AD data length of greater than 191 bytes support is
enabled then default to using the back-to-back PDU chaining
feature in the Controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-23 16:21:00 +02:00
Vinayak Kariappa Chettimada
f736498b2a Bluetooth: Controller: Fix parent PDU's aux offset in aux ptr field
Fix Extended Advertising and Periodic Advertising's parent
PDU's aux ptr field to contain correct aux offset value to
its chain PDU.

Uninitialized pointer reference to aux ptr in the parent PDU
was used before the pointer reference was returned by the
function adding the aux ptr fields in the parent PDU.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-23 16:21:00 +02:00
Vinayak Kariappa Chettimada
a08e8ef88d Bluetooth: Controller: Use local variable for current PDU's flags
Use local variable to update current PDU's Common Extended
Header Format flags instead of updating it directly in the
PDU buffer. This is required to be able to non-destructively
be able to manipulate the PDU's header flags and contents
many time before a final commit of the updated PDU.

In order to calculate overflowed AD data length, PDU is
manipulated couple of times to determine the overflow length
and next to be able to add aux ptr field when chain PDU is
appended.

The changes are now consistent with how Periodic Advertising
PDU's Common Extended Header Format is manipulated.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-23 16:21:00 +02:00
Vinayak Kariappa Chettimada
5ed463008b Bluetooth: Controller: Fix regression in adding ADI in scan rsp PDU
Fix regression in adding ADI in scan response PDU introduced
in implementation adding support for AD data fragment
operation.

Setting scan response data with ADI failed with too long
data error. This was caused by a bug in calculating the
offset to the overflow length returned back by the call
to set_clear function.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2022-08-23 14:50:17 +02:00
Anders Storrø
3dccd319b6 Bluetooth: Mesh: Cfg_cli: Fix appkey get rsp
Adds missing feature so that the config client is able to receive
odd number of app index entries.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2022-08-23 10:20:34 +00:00
Pavel Vasilyev
1659ac4392 Bluetooth: Mesh: Use mesh settings API only if settings are enabled
Don't call bt_mesh_settings_store_pending if CONFIG_BT_SETTINGS is not
enabled.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2022-08-22 16:38:02 +00:00
Piotr Pryga
2b57c0716b Bluetooth: Remove default n from common Kconfig
The commit is a minor refactor of the common Host and Controller
Kconfig. There were used "default n" that should be avoided.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-08-19 16:26:10 +02:00
Piotr Pryga
939578e79d Bluetooth: hci: df: Fix unnecessary IQ sample storage
In case Controller reports to Host insufficient resources to store IQ
samples, according to BT 5.3 Core spec. Vol 4, Part E, sections
7.7.65.21 and 7.7.65.22:
1) packet_status shall be set to BT_HCI_LE_CTE_INSUFFICIENT_RESOURCES
2) sample_count shall be set to zero.
That means there should be no IQ samples stored in IQ report.

HCI implementation stored single IQ sample with value BT_HCI_LE_CTE-
_REPORT_NO_VALID_SAMPLE.

The commit fixes that. No additional memory is added to event buffer
and no IQ sample is stored if sample_count is zero.

Also there is added code that handles situation where ULL provides
IQ report with packet_status indicating valid IQ samples report
but sample_count is zero. In such case Host event stores single IQ
sample with value BT_HCI_LE_CTE_REPORT_NO_VALID_SAMPLE.
In case of vendor specific counter part of the event the value is
BT_HCI_VS_LE_CTE_REPORT_NO_VALID_SAMPLE.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-08-19 16:26:10 +02:00
Piotr Pryga
56262f8207 Bluetooth: Host: Add common handling of VS IQ report
Bluetooth Controller has a vendor specific extensions that allows it
to send IQ report events with IQ samples that are 8 bits or 16 bits
signed integer. To use that functionality, there is added common
handler of vendor specific events.

Vendor specific events handling is prioritized to be done by user
provided event handler. If that is not available, then Host generic
implementation enters.

Added vendor specific events that are handled by common Host code
are BT_HCI_EVT_VS_LE_CONNECTIONLESS_IQ_REPORT and BT_HCI_EVT_VS_LE-
_CONNECTION_IQ_REPORT.

The only difference between regular IQ report events is size of
IQ samples, hence implementation of IQ report events is changed to
use the same user callback. To avoid differentiation of user callbacks
new member sample_type was added to bt_df_per_adv_sync_iq_samples-
_report. Also sample member is changed to be a union, to allow easy
access to IQ samples without type casting.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-08-19 16:26:10 +02:00
Piotr Pryga
d8d8ef74ce Bluetooth: hci: Add VS IQ samples report using 16 bit sign integer sampl
Add vendor specific IQ samples report that holds IQ data in 16 bits
signed integer format. Thanks to that we preserve complete accuracy of
IQ samples provided by Nordic Direction Finding Extension in Radio
peripheral. That helps to maintain better accuracy of evaluated
angles with use of reported IQ samples.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
2022-08-19 16:26:10 +02:00
Jonathan Rico
43e1ae1452 Bluetooth: host: gatt: Properly check subscription status
We had two bugs:

- we didn't check the subscription, only the fact that the passed chrc can
be subscribed to.

- that check only worked if we passed the chrc descriptor handle, not its
value handle.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-08-19 14:09:43 +02:00
Jonathan Rico
fae5dd3643 Bluetooth: gatt: allow disabling subscription enforcement
This introduces a new option that allows the user to disable the
subscription checking when notifying or indicating.

Some users might have use-cases where they would like to send notifications
or indications without the peer having to go through the subscription
process, as that is allowed by the Bluetooth specification.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2022-08-19 12:14:21 +02:00
Mariusz Skamra
9c7ef8ea06 Bluetooth: audio: tbs: Fix List_Item_Length value in CCL
This fixes setting invalid List_Item_Length in Current Calls List.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-19 12:09:46 +02:00
Mariusz Skamra
3253ad2ab8 Bluetooth: audio: tbs: Make bt_tbs_client_call to contain URI pointer
To avoid compilation issues when including tbs.h header file when
CONFIG_BT_TBS_MAX_URI_LENGTH is not set, just pass the URI pointer
instead of an array in bt_tbs_client_call structure.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-19 12:09:46 +02:00
Mariusz Skamra
1b7aafc424 Bluetooth: audio: tbs: Factor out bearer_list_current_calls function
To avoid code duplicates, this factors out common code to separate
function.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-19 12:09:46 +02:00
Aleksandr Khromykh
5a0aa47383 Bluetooth: Mesh: fix adding in sublist the same addresses
If LPN loses Subscription List Add Confirmation it repeats
Subscription List Add frame. Friend doesn't check both
transaction number and presence addresses in the list.
That causes situation when Friend fills the same address
full list.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2022-08-19 12:08:27 +02:00
Aleksandr Khromykh
3f88dcaaff Bluetooth: Mesh: add more latency for scanner in lpn
With extended advertiser a precision of transmission becomes high.
The first frame is emitted quite quickly. The scanner latency
config option to enable scanner a bit in advance is not sufficient.
Sometimes replays on Friend Poll are lost.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2022-08-19 12:08:27 +02:00
Mariusz Skamra
ea5f59f896 Bluetooth: shell: Add LE Audio related advertisement data
This adds LE Audio related data to the shell advertisement data.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2022-08-19 12:07:31 +02:00