Commit graph

9523 commits

Author SHA1 Message Date
Mariusz Skamra
2d593a1e8d Bluetooth: audio: tbs_client: Fix missing cleanup
This fixes repeated attempt to bt_tbs_client_discover that failed
because srv_inst->current_inst was not cleared during previous discovery
process. The issue seen in case the GATT Read CCID returned an error.
The code has been factored out to separate helper function.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-06-06 11:10:10 -04:00
Mariusz Skamra
6656d33a90 Bluetooth: audio: tbs_client: Fix possible override of GATT read parameters
This fixes missing guard access to GATT read parameters.
The code checks `busy` flag and returns an error in case there's ongoing
GATT Read operation already.

Fixes: #58425
Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-06-06 11:10:10 -04:00
Nirosharn Amarasinghe
ff89e98cc6 Bluetooth: controller: Release missing / lost SDUs for framed PDUs
-- Implemented reporting of lost / missing SDUs for framed PDUs. This
   should result in SDUs being released when only framed padding PDUs or
   error PDUs are received.
-- Removed unused configuration params structure, storage and linked
   APIs.
-- Reduced default logging level to INF instead of DBG.
-- Included debug logging messaged for framed consumption.
-- Removed separate latency_unframed and latency_framed and replaced
   with a common sdu_sync_const as they are mutually exclusive for each
   sink.
-- Restricted framed time stamp calculation only to situations where all
   dependent information is available.
-- Corrected SDU sequence numbering to release starting at zero.

Signed-off-by: Nirosharn Amarasinghe <niag@demant.com>
2023-06-06 13:34:45 +02:00
Nirosharn Amarasinghe
40dde5b7bd Bluetooth: controller: fix time-wrapping of cig_ref_point
Time wrapping was omitted at some points. These were corrected or
clarified.

Signed-off-by: Nirosharn Amarasinghe <niag@demant.com>
2023-06-06 13:34:45 +02:00
Nirosharn Amarasinghe
0398d8ddf6 Bluetooth: controller: Release SDU as missing if RX only unf. padding
Based on interpretation of Clarification Errata ES-22876 Request for
Clarification - Recombination actions when only padding unframed PDUs
are received, it was decided that an SDU should be released as "Missing"
when only padding PDUs are received for any SDU.
- https://bluetooth.atlassian.net/browse/ES-22876

This change will also assist streaming in the Common Central design
where the central was found to send only padding PDUs before streaming
starts.

Signed-off-by: Nirosharn Amarasinghe <niag@demant.com>
2023-06-06 13:34:45 +02:00
Emil Gydesen
c764c34232 Bluetooth: BAP: Improve handling of ASCS notification error
If the num_ase == 0xff then it is a special case that needs to be
handled like if num_ase == 0x01.

If there is an error with ase_id = 0x00 then the error cannot
be translated to a specific stream, so the callbacks may now get
NULL for the stream object.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-06 09:35:16 +02:00
Théo Battrel
7d9fe3d0b1 Bluetooth: Host: Fix GATT Store on Write
When CCC or CF store on write is disabled and the other one is enabled,
leading to the delayed store being enabled. This cause the value of the
corresponding `n` selected option to not be stored at all.

To fix this, the checks to know if we need to store the CCC or the CF,
happening at the disconnection, are now ensuring that the CCC or the CF
are stored even if the one of them does not enable store on write.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2023-06-05 13:54:37 -04:00
Emil Gydesen
6652eb7be8 Bluetooth: Shell: Update framing and packing checks in cmd_cig_create
The checks are now less generic and avoids a coverity issue.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-05 10:50:11 -04:00
Emil Gydesen
07f986b2e8 Bluetooth: BAP: Remove lower check in BT_BAP_BASS_VALID_OPCODE
Remove the lower check (BT_BAP_BASS_OP_SCAN_STOP) in
BT_BAP_BASS_VALID_OPCODE as it is always used on unsigned
variables, so no point in check if it is lower than 0.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-05 10:49:29 -04:00
Emil Gydesen
1b9645c6a6 Bluetooth: BAP: Broadcast assistant add idx check for read recv state
Add check for the index in the function itself, as well as where
we call it internally, to ensure that we do not attempt to access
invalid indexes of broadcast_assistant.recv_state_handles.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-05 10:48:45 -04:00
Mariusz Skamra
0f44fac75c Bluetooth: audio: has: Fix conditional check
This fixes missing `CONFIG_*` prefix.
The `BT_HAS_PRESET_CONTROL_POINT_NOTIFIABLE` option is already guarded
with `BT_HAS_PRESET_SUPPORT`, so it has been removed from `depends on`
condition.

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-06-05 16:24:18 +02:00
Mariusz Skamra
21599a6b14 Bluetooth: audio: has: Fix building with preset support disabled
This fixes regression causing compilation errors seen when the
code is built without preset support (BT_HAS_PRESET_COUNT = 0).

Signed-off-by: Mariusz Skamra <mariusz.skamra@codecoup.pl>
2023-06-05 16:24:18 +02:00
Emil Gydesen
192a236c0f Bluetooth: TBS: Added assert in discover_next_instance for inst lookup
Added assert when looking up the next instance, as the caller of this
function should ensure that the index is correct before calling
discover_next_instance.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-05 08:33:16 -04:00
Emil Gydesen
ba7fde1bae Bluetooth: Audio: Shell: Fix use of IN_RANGE when MIN is 0
If the minimal value of an IN_RANGE is 0, then it is
a useless check, and the cases have been modified to
not use IN_RANGE. This also fixes some coverity issues.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-05 08:32:43 -04:00
Emil Gydesen
4e1020e742 Bluetooth: BAP: Fix bad check in audio_stream_qos_cleanup
The check was a && but should have been an ||. Fixed by moving
the check to a new if statement.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-05 08:32:27 -04:00
Emil Gydesen
bff6eca6d4 Bluetooth: TBS: Add missing NULL check when notifying terminate
When notify_app is called for BT_TBS_CALL_OPCODE_TERMINATE
we did a lookup on the call index, but never did a NULL check
before dereferecing it.

This does not fix the issue that the instance will always
be NULL in this case, as we have terminated the call so
we cannot possibly look up the call afterwards.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-05 08:32:03 -04:00
Emil Gydesen
738e23efb8 Bluetooth: TBS: Fix copy of friendly name
The friendly copy always assumed that the friendly name could
fit in memory, which could cause overflows. Fixed by using
utf8_lcpy as that not only ensures that the copy is truncated
to fit in memory, but also ensures that it is null terminated
and truncated in a way that supports multi-byte UTF8 characters.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-05 08:31:46 -04:00
Aleksander Wasaznik
a4e7b53d4b Bluetooth: Host: Fix bt_addr_from_str for str starting with ':'
The previous implementation would read from `addr->val[0]` before it was
initialized if the input string started with a colon ':'.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2023-06-05 08:31:06 -04:00
Emil Gydesen
09c1d412af Bluetooth: ASCS: Add missing return check for bt_conn_get_info
We never checked the return value before accessing the
returned information.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-05 08:30:10 -04:00
Anders Storrø
e4c7ce3316 Bluetooth: Mesh: Remove unintentional dbg string
Remove debug string that accidentally got merged to
the mesh shell cfg file.

Signed-off-by: Anders Storrø <anders.storro@nordicsemi.no>
2023-06-05 08:29:14 -04:00
Emil Gydesen
b49d981e36 Bluetooth: BAP: Unicast client add stream->conn checks
Add checks for the stream->conn before we attempt to use it.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-05 07:07:28 -04:00
Emil Gydesen
9c13b85665 Bluetooth: OTS: Fix offset maximum range check
If offset is only 32-bit, then it can never be > UINT32_MAX,
so added another conditional that only if the type (off_t) is
larger than 32-bit, we perform the maximum value check.

off_t is not a standard type and thus the size of it is poorly
defined, and are just defined as a signed integer type.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-05 07:06:19 -04:00
Emil Gydesen
7435c66972 Bluetooth: IAS: Fix coverity issue with IAS client lvl check
The check compared the levels against < BT_IAS_ALERT_LVL_NO_ALERT
which of course does not make sense given than the lvl_u8 is an
unsigned value that can never be < BT_IAS_ALERT_LVL_NO_ALERT.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-05 07:05:59 -04:00
Emil Gydesen
448bb4ca55 Bluetooth: Audio: Shell: Use unsigned long long for OTS IDs
Use unsigned long long and shell_strtoull to get the ID of
OTS objects, as unsigned long may not be able to store all 48
bits.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-05 07:05:20 -04:00
Emil Gydesen
578acd8cee Bluetooth: Shell: Ensure scan_filter.addr is null terminated
Ensure that scan_filter.addr is NULL terminated by only copying
the sizeof the buffer -1 and then always setting the last byte to
\0.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-05 07:05:00 -04:00
Pirun Lee
5ba418c442 Bluetooth: OTS: Fix coverity issue
Fixed issue Coverity CID: 316293 https://github.com/zephyrproject-rtos/zephyr/issues/58518

Signed-off-by: Pirun Lee <pirun.lee@nordicsemi.no>
2023-06-02 18:57:44 -04:00
Pavel Vasilyev
24bd211d77 Bluetooth: Mesh: Avoid dead code in access
Use if-else-endif construction to avoid dead code.

Coverity-CID: 316484, GitHub issue #58539

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-06-02 18:57:14 -04:00
Pavel Vasilyev
2b3175f2fa Bluetooth: Mesh: Avoid divizion by zero when chunk_size is zero
Avoid divizion by zero when chunk_size is zero.

Coverity-CID: 316406, GitHub issue #58531

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-06-02 18:57:14 -04:00
Pavel Vasilyev
ee548488cc Bluetooth: Mesh: Drop PENDING_RESET flag without checking it
Just drop PENDING_RESET flag without checking it.

Coverity-CID: 316394, GitHub issue #58530

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-06-02 18:57:14 -04:00
Pavel Vasilyev
617154f9d5 Bluetooth: Mesh: Avoid undefined behavior when block_size_log is 0x20
Use ULL suffix to promote the type of the shift operand to uint64_t to
avoid undefined behavior when block_size_log is 32.

Coverity-CID: 316387, GitHub issue #58528

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-06-02 18:57:14 -04:00
Pavel Vasilyev
395f250ef8 Bluetooth: Mesh: Check return value in blob server
Ignore return value of bt_mesh_model_send().

Coverity-CID: 316126, GitHub issue #58506
Coverity-CID: 316272, GitHub issue #58517
Coverity-CID: 316430, GitHub issue #58533
Coverity-CID: 316567, GitHub issue #58549

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2023-06-02 18:57:14 -04:00
Emil Gydesen
208908e293 Bluetooth: Audio: Shell: Fix long/int32_t value checks
In places where we verify that the value of the long
variable does not exceed the limits of int32_t, we do
actually not need to compare the values if the two
types are the same size, which is often the case for
32-bit systems.

This fixes a variety of coverity reported issues.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-02 18:56:17 -04:00
Emil Gydesen
1767621f6f Bluetooth: Shell: Change strcpy to strncpy for addr copy
When copying the address in cmd_scan_filter_set_addr we now
use strncpy to not copy more bytes than what fits. This
should already have been fixed with a check earlier in the
function, but coverity still complains.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-02 18:52:20 -04:00
Théo Battrel
3937b25dd6 Bluetooth: Host: Fix GATT delayed store
When `CONFIG_BT_SETTINGS_DELAYED_STORE` is enabled (by default it is),
the local GATT server will delay the write to flash of the CCC and CF
values. The delay is defined by `CONFIG_BT_SETTINGS_DELAYED_STORE_MS`.
If a disconnection happen before that delay, the `bt_gatt_disconnected`
will reschedule the delayed store operation. But that operation will not
happen before `bt_gatt_disconnected` is complete, at this moment, the
CCC and CF values will have already been cleared.

To fix this issue, the delayed store operation is now done during the
`bt_gatt_disconnected` function.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2023-06-01 14:58:39 +02:00
Lingao Meng
5f9ac54e2f Bluetooth: Mesh: Fix unable sent mesh message
When proxy advertising enabled, but at same time, the
connection event report, will cause `ADV_FLAG_PROXY` not
set, so cb `connected` will not be process, cause mesh message
unable to sent.

Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/58721

Signed-off-by: Lingao Meng <menglingao@xiaomi.com>
2023-06-01 04:52:45 -04:00
Jordan Yates
c61818b065 Bluetooth: host: hci_core: handle additional error code
Some Bluetooth controllers (Nordic Softdevice) now use
`BT_HCI_ERR_INSUFFICIENT_RESOURCES` to signify when advertising sets
cannot be created, instead of the old `BT_HCI_ERR_CONN_LIMIT_EXCEEDED`.

Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
2023-06-01 10:04:46 +02:00
Emil Gydesen
0229dad6d2 Bluetooth: Host: ISO: Fix issue with removing central data paths
On CIS disconnect, the central will clear all data paths.

However hci_le_remove_iso_data_path will fail if attempting to remove a
data path that has not been setup, so if only the CTLR_TO_HOST
direction was set, and the HOST_TO_CTLR bit was set, the
function returned an error and never attempted to clear the other
direction.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-01 10:04:36 +02:00
Emil Gydesen
e31713de27 Bluetooth: Controller: ISO: Fix issue with removing peripheral data paths
On CIS disconnect, the peripheral will clear all data paths.

However ll_remove_iso_path will fail if attempting to remove a
data path that has not been setup, so if only the CTLR_TO_HOST
direction was set, and the HOST_TO_CTLR bit was set, the
function returned an error and never attempted to clear the other
direction.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-06-01 10:04:36 +02:00
Morten Priess
5db51d3679 Bluetooth: controller: Fix reconfiguring of CIG and CISes
Up until now, it has not been possible to reconfigure a CIG and its
CISes after initial configuration, without first removing the CIG.

With this commit, le_set_cig_parameters allows the following
reconfiguration operations in configuration state:
- Set new CIG configuration parameters on existing CIG
- Iteratively configure single CIS (of more CISes)
- Increment number of CISes via multiple configuration calls
- Keep handle- and CIS_ID relation

Changes:
- Pass handles in le_set_cig_parameters from ll_cig_parameters_commit
  via output variable.
- Implement CIG state variable instead of 'started', with states
  IDLE/CONFIGURABLE, ACTIVE and INACTIVE.
- Implement ll_conn_iso_stream_get_by_id for easier access to specific
  CIS.

This fixes the following CIS Central EBQ tests:
- HCI/CIS/BI-10-C
- HCI/CIS/BI-11-C
- HCI/CIS/BI-13-C
- HCI/CIS/BV-05-C

Signed-off-by: Morten Priess <mtpr@oticon.com>
2023-05-30 08:59:16 -04:00
Morten Priess
3fd1fbeff8 Bluetooth: controller: Validate parameters for CIG configuration
Parameter checking updates for passing HCI/CIS/BI* EBQ tests.

Signed-off-by: Morten Priess <mtpr@oticon.com>
2023-05-30 08:59:16 -04:00
Morten Priess
03faaa9e45 Bluetooth: host: Fix hci_le_remove_iso_data_path direction parameters
The path_dir variable of BT_HCI_OP_LE_REMOVE_ISO_PATH must be bitflags,
with the following meaning:
- BIT(0) : DIR_HOST_TO_CTLR
- BIT(1) : DIR_CTLR_TO_HOST

Signed-off-by: Morten Priess <mtpr@oticon.com>
2023-05-30 08:59:16 -04:00
Morten Priess
acd83ad794 Bluetooth: controller: Fix ll_remove_iso_path direction parameter
According to the Core spec, the direction parameter passed to this function
should be bitfields, i.e.:
- BIT(0) : DIR_HOST_TO_CTLR
- BIT(1) : DIR_CTLR_TO_HOST

Signed-off-by: Morten Priess <mtpr@oticon.com>
2023-05-30 08:59:16 -04:00
Krzysztof Kopyściński
67a33ed1a0 Bluetooth: Mesh: fix Random value generation for Private Beacons
In `private_random_update`, when first beacon is advertised, there could
be a case when uptime is less then interval * 10s
(`priv_random.timestamp` is equal to 0 for first beacon). Then, Private
Random value will not be generated and will be set to all zeros.

New Private Random must also be generated  before Random Interval
expires, when KR or IVU flags are changed. Reset timestamp to 0 on
`bt_mesh_beacon_update` to generate new Random value.

Do not generate new private random if it won't be used (Private Beacon
state is not enabled).

Signed-off-by: Krzysztof Kopyściński <krzysztof.kopyscinski@codecoup.pl>
2023-05-30 06:30:25 -04:00
Vinayak Kariappa Chettimada
c23c5f39e7 Bluetooth: Controller: Cleanup Periodic Adv Channel Map Update
Remove redundant code and cleanup Periodic Advertising
Channel Map Update implementation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2023-05-26 14:57:22 -04:00
Rubin Gerritsen
9e617bdd86 Bluetooth: KConfig: Enable ISO CTLR features if host has enabled them
This ensures that when running a combined host + controller build, the
ISO features in the controller are enabled automatically.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2023-05-26 09:51:09 -04:00
Fredrik Danebjer
7457bcf0a2 Bluetooth: Audio: Make HAS optional notify characteristics optional
Added Kconfig options to make HAS characteristics that has notify as
optional property selectable and thus optional. These settings are
global, meaning that a chosen notify property will be used for all
registered has instances.

Signed-off-by: Fredrik Danebjer <frdn@demant.com>
2023-05-26 09:09:06 -04:00
Emil Gydesen
527591a766 Bluetooth: BAP: Fix off-by-one in shell cmd add_broadcast_id
The arguments in the shell start from [1] as [0] is the command
itself.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-26 09:08:42 -04:00
Andrei Emeltchenko
75637bd44a bluetooth: audio: Fix buffer overflow
Add missing return preventing memcpy() with buffer overflow.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
2023-05-26 09:08:23 -04:00
Emil Gydesen
19c2bd28a4 Bluetooth: BAP: Unicast client optimize long notify reads
Optimize the read procedure when receiving long notifications
by storing the already notified data in the buffer if the
client instance is not already busy. If it is busy we have
no way to store it, and will just need to read the entire thing
later.

This also modifies when we reset the ATT buffer. Instead of reseting
when we want to use it, we reset it when we are done using it.
The reason for this is to avoid making state checks before calling
long_ase_read to determine whether it should reset the buffer
or not.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-26 05:55:15 -04:00
Emil Gydesen
870d8b350a Bluetooth: BAP: Add support for long ASE notifications
Add support for long notifications ASE notifications
by doing a long read if the notification has length of
the maximum MTU.

This behavior is currently not defined by the BAP spec,
so may not work with all devices.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2023-05-26 05:55:15 -04:00