Commit Graph

163 Commits

Author SHA1 Message Date
Fredrik Danebjer f970b066d2 Bluetooth: audio: Add possibility to use static broadcast id
Removed the generation of broadcast id inside the stack. It is now up
to the application to generate this by itself. The CAP sample has
been modified to allow either a static broadcast, or a random one.
All of this is handled in the application.

Signed-off-by: Fredrik Danebjer <frdn@demant.com>
2024-10-25 14:07:25 +02:00
Emil Gydesen fb6c4427b8 Bluetooth: Audio: Add helpers for broadcast name
Added helper functions to set and get broadcast name
for codec capabilities and codec configs.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-10-23 16:54:28 +02:00
Emil Gydesen 2dc1113a94 Bluetooth: CAP: Add support for handling ASE errors
If we get an error/rejection from the CAP acceptor when
performing the Unicast Audio Start or Stop procedure then
we need to abort the procedure and let the application determine
what the next step is.

This change triggered a corner case when connecting to multiple
CAP acceptors as the CAP initiatior. This was also fixed as part
of this.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-10-23 16:53:44 +02:00
Babak Arisian 7f820d59c0 Bluetooth: Audio: Update SCAN_DELEGATOR dependency to GATT_DYNAMIC_DB
Changed dependency of the BT_BAP_SCAN_DELEGATOR to GATT_DYNAMIC_DB
from 'select' to 'depends on' and solved all loop dependencies
caused by this change.

Fixes #79108

Signed-off-by: Babak Arisian <bbaa@demant.com>
2024-10-23 16:53:37 +02:00
Emil Gydesen cd5a9f62bb tests: Bluetooth: CCID: Add unit testing of CCID
Add unit tests of the CCID functions.
To support these new tests, the GATT mocks need to
support dynamic GATT DB so we can add and remove
a service that contains CCIDs.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-10-15 04:10:28 -04:00
Emil Gydesen dc97bbd35f Bluetooth: Audio: Rename bt_audio_codec_qos -> bt_bap_qos_cfg
The QoS structure is not related to a codec, but rather a
stream, and should thus not use the "Codec" name.

The BAP and ASCS specs refer to the QoS as
"QoS configuration" several places, so it is an obvious
choice for a name.

Since the structure is defined and used by BAP, the prefix
was changed from bt_audio to bt_bap.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-10-04 16:34:22 +01:00
Andries Kruithof a63665438a Bluetooth: Audio: improve broadcast reception stop unittest
Add more parameter checking for the unittests for the
CAP procedure 'broadcast reception stop'

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2024-10-02 09:59:23 +02:00
Andries Kruithof 8295deb966 Bluetooth: Audio: CAP implement broadcast reception stop
Implement the CAP broadcast reception stop procedures and
add unit tests

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2024-10-02 09:59:23 +02:00
Emil Gydesen fa4f2ffc47 Bluetooth: CAP: Add support for doing just disable for unicast stop
The unicast_stop function is changed to primarily do a
BAP disable instead of a release, with optional
support for releasing the streams once they have been disabled.

This also adds unittests for the procedure which also
allow us to remove the invalid param testing from the BSIM tests.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-10-01 09:54:04 +02:00
Emil Gydesen 7ef2f81413 Bluetooth: Audio: Add helpers for assisted listening stream
Added helper functions to set and get assisted listening
stream values for codec capabilities and codec configs.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-09-23 10:03:47 +02:00
Emil Gydesen f57a040808 Bluetooth: BAP: Add bondable requirement for BAP
BAP mandates support for bondable mode for all central and
peripheral roles.

Due to Kconfig circular dependencies, some additional
Kconfig changes had to be made.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-09-19 18:27:53 +01:00
Emil Gydesen 594bef84f8 tests: Bluetooth: Fix minor issues for bap_base unit tests
An unused variable was removed and some callbacks were
corrected.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-09-11 14:01:46 -04:00
Emil Gydesen 069619a4ee tests: Bluetooth: BAP: Fix BT_BAP_BASE dependency for unit tests
The unit tests needed to enable the hidden Kconfig
BT_BAP_BASE. Instead of adding an additional Kconfig for this,
just enable one of the roles that enable it.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-09-11 14:01:46 -04:00
Fredrik Danebjer c9da274eb2 Bluetooth: ascs: Add dynamic ASE registration
Added option to set the ASE count through the bap API, making ASE
configuration runtime available. The upper limit of ASEs are still
bound by the Kconfig options set for ASEs.

Signed-off-by: Fredrik Danebjer <frdn@demant.com>
2024-09-11 07:41:12 -04:00
Henrik Brix Andersen 159f7dbbb1 lib: net_buf: rename header file from zephyr/net/buf.h to zephyr/net_buf.h
Move the network buffer header file from zephyr/net/buf.h to
zephyr/net_buf.h as the implementation now lives outside of the networking
subsystem.

Add (deprecated) zephyr/net/buf.h header to maintain compatibility with old
file path.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2024-09-07 11:19:05 -05:00
Henrik Brix Andersen ced80b13bf lib: net_buf: move the network buffer implementation to lib
Move the net_buf implementation from the networking subsystem to a library
as they have no dependency on the networking subsystem.

Network buffers are used in subsystems outside of networking
(e.g. Bluetooth, USB).

Fixes: #36374

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2024-09-07 11:19:05 -05:00
Emil Gydesen f500f7c22f Bluetooth: CAP: Fix dependency on BT_BAP_STREAM
The CAP commander used bt_audio_valid_ltv which required
BT_BAP_STREAM to be enabled, but the CAP Commander does not
need BT_BAP_STREAM to be enabled.

Moved the function to audio.c which is always compiled for
the CAP Commander, thus removing the requirement for
BT_BAP_STREAM and the accompanying bt_bap_stream.c file.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-09-05 12:24:16 +01:00
Emil Gydesen 0e4e7628fd Bluetooth: CAP: Add check for streaming state when starting unicast
When calling bt_cap_initiator_unicast_audio_start on a set of streams
that are all in the streaming state we return early with -EALREADY.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-09-03 10:43:59 +02:00
Emil Gydesen 4279cebcbd tests: Bluetooth: CAP: Ensure that unicast_start works in any state
The unicast_start procedure should take a stream in any state
and put it in the streaming state. Adds tests with streams
in various states.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-09-03 10:43:59 +02:00
Emil Gydesen eaf92a1494 tests: Bluetooth: CAP: Initiator unicast start unittests
Adds unittests for the CAP Initiator start procedure, simply
verifying that the procedure works as well as
testing invalid parameters.
This also allows us to remove the invalid behavior checks
from the babblesim test implementation.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-08-26 17:27:36 -04:00
Jonathan Rico 0b3c67c31b Bluetooth: audio: Make unit tests compile
The tests manually include sources that are normally conditionally
included (ie based on kconfig values) in the stack.

The tests should be fixed by the original authors.
For now, force-on the hidden kconfig that enables the log options.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-08-21 16:44:44 -04:00
Torsten Rasmussen b939e720a6 tests: source Zephyr before project() call
Fixes: #73831

find_package(Zephyr) should be called before first project() call.

Zephyr package will test and force-set the correct toolchain, especially
the C compiler.
The project() will also set the C compiler, if not set already.

If project() is called first, then conflict arises on the C compiler
selection and thus the following message is seen:
> You have changed variables that require your cache to be deleted.
> Configure will be re-run and you may have to reset some variables.
> The following variables have changed:
> CMAKE_C_COMPILER= /usr/bin/gcc

This cache deletion results in other errors, such as a missing BOARD
setting.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2024-08-05 16:27:09 +02:00
Emil Gydesen a94bfe03a4 tests: Bluetooth: Audio: Move role specific mocks files
For the LE Audio unittests there exists a few mock files
that implement mock versions, or callbacks, for some of the
roles and features tested.

These have been moved to where they are actually used,
reducing the scope of these files.

This both allows the individual tests to implement their own
versions of it, but more importantly it prevents issues when
adding tests for these roles. For example, due to the
bap_unicast_client.c mock file, it is impossible to implement
unit tests for the unicast client, as the functions are already
defined.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-07-30 18:25:47 +01:00
Emil Gydesen 8be6db67fc Bluetooth: ISO/BAP: Refactor BIS bitfield
Refactors teh BIS bitfield values used for ISO
and BAP.

Previously BIT(1) meant BIS index 1, which was a Zephyr choice
in the early days of ISO, as the BT Core spec did not use
a bitfield for BIS indexes.

Later the BASS specification came along and defined that
BIT(0) meant BIS index 1, which meant that we had to shift BIS
bitfields between BAP and ISO.

This commit refactors the ISO layer to use BIT(0) for Index 1 now,
which means that there is no longer a need for conversion
between the BAP and ISO layers, and that we can use a value
range defined by a BT Core spec (BASS).

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-07-27 15:19:46 +03:00
Emil Gydesen 7b0784c1f6 Bluetooth: ASCS: Validate num_ases in CP requests
Add validation of the number of ASEs in control point
write requests.

This validates that the number of ASEs
in the control point is not greater than the total number
of ASEs we support.

This also validates that the GATT MTU is large enough to
hold all the responses from the write since those can only be
sent as notifications and never be truncated.

Finally this validates and updates the size of the buffer used to
hold the responses, which may be an optimization for some builds.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-28 07:20:47 -04:00
Jordan Yates 07870934e3 everywhere: replace double words
Treewide search and replace on a range of double word combinations:
    * `the the`
    * `to to`
    * `if if`
    * `that that`
    * `on on`
    * `is is`
    * `from from`

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-22 05:40:22 -04:00
Jens Rehhoff Thomsen ab9fd0b5c9 Bluetooth: BAP: Add bt_bap_base_get_size function
bt_bap_base_get_size function returns the size of the BASE.

Fixes #73847

Signed-off-by: Jens Rehhoff Thomsen <jthm@demant.com>
2024-06-14 15:34:23 +02:00
Andries Kruithof 7902457437 Bluetooth: audio: test: Unittests for broadcast reception start
Implement unit tests for the broadcast reception start procedure,
both with proper and with improper parameters.

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2024-06-13 16:48:58 -04:00
Alberto Escolar Piedras 5d1afa1a3b tests: Bluetooth: bap_broadcast_source: Fix call
bt_audio_codec_cfg_get_chan_allocation() now takes an
extra parameter.
Let's set it to the value which keeps the old behaviour.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-06-13 11:47:14 -04:00
Nithin Ramesh Myliattil df45858d0f Bluetooth: BAP: Broadcast Source: Update stream codec config data
When creating a BAP broadcast source with bt_bap_broadcast_source_create
only the subgroup information is stored in the streams and the remaining
BIS specific information is not stored in the stream->codec_cfg,
which it should.
Fix is to store bis specific information also in stream codec config.
Updated broadcast source BSIM test to verify above usecase.

Signed-off-by: Nithin Ramesh Myliattil <niym@demant.com>
2024-06-13 08:04:27 -04:00
Emil Gydesen a62ee400dc tests: Bluetooth: CAP: Add initial CAP initiator unit tests
These test only test the basic functionality of
bt_cap_initiator_unicast_discover so far, but will be expanded.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-13 05:42:04 -04:00
Emil Gydesen db4d4cfda2 Bluetooth: Audio: Add fallback to cfg_meta_get_pref_context
Added a fallback parameter to
bt_audio_codec_cfg_meta_get_pref_context
as absence of pref context in BAP implicitly means a unspecified
for LC3.

In the case that it is absent BT_AUDIO_CONTEXT_TYPE_UNSPECIFIED
is the returned value.

While the metadata for codec cfg and codec cap are similar,
this only applies for codec cfg as per BAP.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-13 05:41:47 -04:00
Emil Gydesen c4b3b72b07 Bluetooth: Audio: Add fallback to max_codec_frames_per_sdu
Added a fallback parameter to
bt_audio_codec_cap_get_max_codec_frames_per_sdu
as absence of max codec frames per SDU in BAP implicitly
means a single frame for LC3.

In the case that it is absent 1 is the returned value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-13 05:41:47 -04:00
Emil Gydesen 579b4f7e37 Bluetooth: Audio: Add fallback to supported_audio_chan_counts
Added a fallback parameter to
bt_audio_codec_cap_get_supported_audio_chan_counts
as absence of channel count in BAP implicitly means a single channel
for Lc3.

In the case that it is absent 1 is the returned value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-13 05:41:47 -04:00
Emil Gydesen a33543f02e tests: Bluetooth: Audio: Fix bad values in codec cap unit tests
Some codec cap unit tests were using codec cfg values.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-13 05:41:47 -04:00
Emil Gydesen c6cc034b5c Bluetooth: Audio: Add fallback to get_chan_allocation
Added a fallback parameter to
bt_audio_codec_cfg_get_chan_allocation as absence of
channel allocation in BAP implicitly means Mono.
In the case that it is absent,
BT_AUDIO_LOCATION_MONO_AUDIO is the returned value.

This commit also fixes the implementation of
bt_audio_codec_cfg_get_frame_blocks_per_sdu as it only applies to
LC3 (as per the BAP spec). It also adds additional testing of it

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-13 05:41:47 -04:00
Emil Gydesen be307f8ad9 Bluetooth: Audio: Change lang to 3-byte value from uint32_t
The 3-byte value suits the assigned number much better,
and also allows for less memory copies when getting and
setting the values.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-12 12:54:16 -04:00
Emil Gydesen f08bc644a1 Bluetooth: Audio: Rename stream_lang to lang
Remove the "stream" part of the value and functions to
better fit with the name in the assigned numbers document.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-12 12:54:16 -04:00
Yong Cong Sin e54b27b967 arch: define `struct arch_esf` and deprecate `z_arch_esf_t`
Make `struct arch_esf` compulsory for all architectures by
declaring it in the `arch_interface.h` header.

After this commit, the named struct `z_arch_esf_t` is only used
internally to generate offsets, and is slated to be removed
from the `arch_interface.h` header in the future.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-04 14:02:51 -05:00
Emil Gydesen d2fbeffaa9 Bluetooth: BAP: Unicast client Split start and connect
Removes the CIS connection establishment from bt_bap_stream_start
and move the behavior to a new funciton bt_bap_stream_connect.

This has 2 advantages:
1) The behavior of bt_bap_stream_start is much more clear and more aligned
with the spec's behavior for the receiver start ready opcode.
2) It is possible to connect streams in both the enabling
and the QoS configured state with bt_bap_stream_connect as
per the spec. This allows us to pass additional PTS test cases.

To implement this new behavior, samples and tests have been updated.

The CAP Initiator implementation has also been updated
to accomodate for the change in BAP, but the CAP
initiator implementation should work the same for application, except
that it's now possible to do unicast start on ASEs in any order
(https://github.com/zephyrproject-rtos/zephyr/issues/72138).

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-03 15:42:33 +02:00
Emil Gydesen 1af717430a Bluetooth: CAP: Do not require CAS unless necessary
Removes the requirement that CAS is found on the remove
device for ad-hoc sets. This makes the CAP API more
versatile as it allows applications to use it with
remote non-CAP devices.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-03 03:39:07 -07:00
Emil Gydesen f93b9dee5c Bluetooth: CSIP: Make set_member_by_conn a public function
The function is useful for application to lookup set
members from bt_conn pointers, e.g. when iterating on
connected devices.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-06-03 09:48:48 +02:00
Emil Gydesen 96c1cfcfb0 tests: Bluetooth: CAP: Add missing CSIP function
The bt_csip_set_coordinator_csis_member_by_conn function
was seemingly missing, causing the CAP unit tests to not build.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-05-21 18:01:38 +02:00
Emil Gydesen f58ac3476f Bluetooth: CAP: Add reference to the set member for CAP discover
Since the CSIP API expects a set member struct for nearly all
functionality, the reference to the full set member (along with
the CAS specific CSIS) should be given to the application.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-05-18 15:51:26 +03:00
Andries Kruithof 6a0cdb4eaa Bluetooth: CAP: Commander Reception start procedure
Add the CAP commander reception start procedure which starts reception
on one or more CAP acceptors

With the implementation of broadcast reception start procedure we also need
some mockups for unit testing

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2024-05-07 09:34:01 +02:00
Emil Gydesen 353a05b116 Bluetooth: BAP: Unicast server depend on PACS
When in the BAP unicast server role, at least PAC sink
or PAC source shall be set.

In order to fulfill this new requirement, a few other Kconfig
options had to be changed to a `depends on` from `select` to
avoid recursive Kconfig requirements. This change may require
some applications to update their configurations according
to the migration guide.

The change from `select` to `depends on` is ideal anyhow
as that is the recommended way to add dependencies.

This can checked via the combined BT_PACS Kconfig value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-04-30 14:30:45 -04:00
Emil Gydesen f70ba925ea tests: Bluetooth: CAP Commander Change Microphone mute unittests
Adds unittests for the CAP Commander Change Microphone mute
procedure.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-04-05 12:21:38 +02:00
Andries Kruithof f967e08364 Bluetooth: audio: test: Refactor unit test
The unittest for cap commander is refactored, so that tests
for volumecontrol is in its own module.
This avoids the problem of having all tests in one huge file.

Due to their small size the tests for registering callbacks and
discovery haven't been put into their own module.

Signed-off-by: Andries Kruithof <andries.kruithof@nordicsemi.no>
2024-03-26 09:46:50 +00:00
Emil Gydesen 6f405f6b80 tests: Bluetooth: CAP Commander Change Microphone Gain unittests
Adds unittests for the CAP Commander Change Microphone Gain
procedure.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-03-12 17:56:09 +00:00
Emil Gydesen 8a6c1d9bfa Bluetooth: BAP: Broadcast source: Add LTV validation for LC3 data
When using the LC3 codec, all codec configuration are LTV encoded.
The broadcast source did not properly validate this, and it also
uncovered a bug in the bsim test for broadcast sources.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-03-01 16:04:19 +01:00