Commit Graph

192 Commits

Author SHA1 Message Date
Pavel Vasilyev f7e8a8717b tests: bsim: bluetooth: host: att: Add ATT timeout test
This commit tests that the host correctly disconnects from peer when ATT
timeout happens.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2024-10-10 14:59:02 -04:00
Aleksander Wasaznik 8cfad44852 Bluetooth: Deprecate adv auto-resume
The host-based adv auto-resume function has both a problematic
implementation and disagreement in the community around how it should
behave. See the issue linked resolved below for details.

This patch makes the deprecation visible to the user. The user will be
better served by a auto-resume tailored their applications use case,
based on more primitive host API like `conn_cb.recycled`, which has
obvious behavior that is unlikely to change.

Resolves: https://github.com/zephyrproject-rtos/zephyr/issues/72567

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2024-10-08 16:57:01 +02:00
Emil Gydesen ec2c5b0c1f Bluetooth: GATT: Replace magic number 0 with macro for auto ccc
Replace the magic number 0 with a #defined value for
the auto CCC discovery feature.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-09-26 17:41:24 -04:00
Emil Gydesen 390528101a test: Bluetooth: ext_adv_scanner: Fix bad use of adv_type
The adv_type is not a bitfield but was used as such.
Changed to do a proper comparison.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-09-25 04:04:46 -04:00
Alberto Escolar Piedras 3726cf369c tests/bsim/bluetooth/host/adv/encrypted: Enable RealEncryption
Let's run tests with security/privacy with the HW models acutually
running the encryptions, so in case of missaligned keys
tests fail.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-09-19 15:13:10 +02:00
Alberto Escolar Piedras 9182a7e8c4 tests/bsim/bluetooth/host/security: Enable RealEncryption
Let's run tests with security/privacy with the HW models acutually
running the encryptions, so in case of missaligned keys
tests fail.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-09-19 15:13:10 +02:00
Alberto Escolar Piedras 342e2988bb tests/bsim/bluetooth/host/gatt: Enable RealEncryption
Let's run tests with security/privacy with the HW models acutually
running the encryption, so in case of missaligned keys
tests fail.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-09-19 15:13:10 +02:00
Alberto Escolar Piedras 53adf2c617 tests/bsim/bluetooth/host/att: Enable RealEncryption
Let's run tests with security/privacy with the HW models acutually
running the encryptions, so in case of missaligned keys
tests fail.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-09-19 15:13:10 +02:00
Jonathan Rico edeb529c9f Bluetooth: Host: Add advertising events stress test
More information in the test description.

Why: At the time of writing, this test exposes a bug in the Bluetooth stack
where all the RX buffers are in use, and the controller driver fails to
synchronously allocate a command response buffer.

This is manifested in an assertion failure in `hci_common.c`.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-09-17 17:45:50 +01:00
Rubin Gerritsen f6712c43d4 tests: Bluetooth: Add some more tests for bt_le_create_conn()
Adds coverage for attempting to connect while already connecting
or connecting to a device that already exists.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-09-17 09:09:56 -05: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
Jan Müller c910520f4d Bluetooth: Host: Rework enabling of scanner
To make the scanner module more understandable and more streamlined, I
reworked the update mechanism of the scanner. The scanner tracks now the
parameters that were used to enable it and the reason why it is running.
This facilitates state logic and allows other modules to "start the
scanner", altough it is already running.
This is mostly a refactoring and not a functional change.

Added a test to verify the behavior.

Signed-off-by: Jan Müller <jan.mueller@nordicsemi.no>

add to task
2024-08-20 14:54:25 -04:00
Jonathan Rico 6fa6c4c256 Bluetooth: L2CAP: Downgrade user_data API error to a warning
When user_data is not zeroed-out, the API returns an error. Downgrade
the API error to a warning log instead.

Introducing this check (#76489) broke a few PTS tests, as user_data is
not initialized by `net_buf_alloc()`. Doing so is in discussion:

https://github.com/zephyrproject-rtos/zephyr/issues/77088

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-08-19 09:55:49 -04:00
Jonathan Rico 043de7da2a Bluetooth: Host: Add disconnection during TX fragmentation test
Verifies that we don't leak connection references when the peer goes out
of range whilst we are fragmenting and sending data to the controller.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-08-16 16:29:41 +01:00
Théo Battrel f3dcaaee35 Tests: Bluetooth: Add another ISO frag test
This test create a setup where an ISO broadcaster will send fragmented
data and get stopped after sending the first fragment and repeating that
operation multiple time to verify that buffers are not leaked.

Signed-off-by: Théo Battrel <theo.battrel@nordicsemi.no>
2024-08-16 11:20:14 +01:00
Henrik Brix Andersen 69fe9b0c50 net: buf: remove use of special putter and getter functions
Convert users of net_buf_put() and net_buf_get() functions to use
non-wrapped putters and getters k_fifo_put() and k_fifo_get().

Special handling of net_bufs in k_fifos is no longer needed after commit
3d306c181f, since these actions are now
atomic regardless of any net_buf fragments.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
2024-08-16 09:55:11 +02:00
Luis Ubieda 75f70c4636 tests: bsim: bluetooth: Refactor MTU Update test
To isolate Central and Peripheral in two separate builds.

Signed-off-by: Luis Ubieda <luisf@croxel.com>
2024-08-15 10:17:13 +01:00
Aleksander Wasaznik 8b4907ee97 Bluetooth: bsim: deduplicate compile scripts
Some tests have a compile script for that test alone, named
`_compile.sh` or `_build.sh`. These scripts are useful for developers to
avoid compiling the world. But these scripts were not run in the CI.

These scripts were previously not suitable for running in the CI because
would put the artefact in the source directory, but this is no longer
the case, and the CI could run these scripts now.

This commit renames any `<test>/test_scripts/_compile.sh` and
`<test>/test_scripts/_build.sh` to `<test>/compile.sh`. The test runner
in CI will ignores any file named `compile.sh`, so there is no need for
a underscore prefix.

This fits into and extends the hierarchical structure of `compile.sh`
chain that starts at `:/test/bsim/compile.sh`, the CI build script tree.

The newly moved scripts now become a part of the build script tree,
called from a `compile.sh` where a duplicate set of build commands was
before. The sub scripts use `run_in_background` to preserve the
parallelism as it was before this change.

This removes an error-prone duplication and makes the CI test all the
build scripts.

Tests that did not have any compile script are not given one for now.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2024-08-14 12:33:53 -04:00
Jonathan Rico e489ec2b95 Bluetooth: L2CAP: Add re-assembly stress test
Add a test that verifies no resources are leaked when re-assembling L2CAP
PDUs over an unreliable channel (ie. lots of disconnects).

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-08-12 10:10:48 +02:00
Jonathan Rico 76ece09cb4 Bluetooth: Host: Add ISO HCI fragmentation test
Purpose is to verify we don't fragment ISO SDUs when they should fit the
controller's MTU.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-08-08 06:07:08 -04:00
Guru Mehar Rachaputi f20ac87536 tests: bsim: set log level from command-line argument
Implementation to take command-line arguments to set log level in run
time for bsim module. Set default log level if no log level is passed
at runtime

Signed-off-by: Guru Mehar Rachaputi <gurumeharrachaputi@gmail.com>
2024-08-05 10:16:36 +02:00
Vinayak Kariappa Chettimada bc4442ece7 tests: bsim: Bluetooth: Host: Fix RPA expired old time value
Fix RPA expired old time value used for rotation timeout
validation.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-08-02 13:40:59 +02:00
Jonathan Rico 08706f98bc Bluetooth: adapt l2cap/userdata test
Modify the test so it checks that user_data is used and then cleared by
the stack.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-08-01 16:49:37 +01:00
Jonathan Rico 11b3aa1f1f tests: Bluetooth: Add multi-central robustness test
This test's purpose is to verify we (as a peripheral) don't leak resources
when communicating with multiple centrals that connect and disconnect
intermittently.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-08-01 12:38:36 +02: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
Vinayak Kariappa Chettimada 04e3d0081b Bluetooth: Controller: Fix Advertising PDU memory allocation
Fix Advertising PDU memory allocation for redundant Periodic
Advertising related PDU allocations. The buffer count
related to Periodic Advertising was included twice.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-07-27 15:09:39 +03:00
Anas Nashif 83bd3658c3 tests: do not get ZEPHYR_BASE from ENV
find_package() already deals with finding ZEPHYR_BASE, so do not rely on
it being set in ENV, use the variable directly adter find_package() was
called.

Fixes #75387

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2024-07-11 13:09:53 -04:00
Jonathan Rico 4afe745a1d Bluetooth: host: Add lower bound for `CONFIG_BT_BUF_ACL_RX_COUNT`
See comment above assert for more.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-07-10 11:47:26 -04:00
Jonathan Rico ff5c577aa8 tests: Bluetooth: Add ACL re-assembly test
This tests shows that there is a problematic buffer configuration.

The host locks up when `CONFIG_BT_BUF_ACL_RX_COUNT` is smaller or equal
to the number of connected peers, and all those peers send an L2CAP PDU
that needs re-assembly at the same time.

Although this seems far-fetched, this bug has been observed in a
real-life situation on actual hardware.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-07-10 11:47:26 -04:00
Jonathan Rico 3af358d6fd Bluetooth: remove host/adv/resume test
This test verifies a convoluted interaction between the scanner and the
resumable advertiser feature in the host.

That feature is going away, see #72567.

Prepare that work by removing this test that's in the way.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-07-04 18:01:03 +02:00
Aleksander Wasaznik c33e721c01 Bluetooth: host: test: remove adv/resume2
I am the original author of the test that is being removed. The test was
added in https://github.com/zephyrproject-rtos/zephyr/pull/70670 to try
to specify the behavior of automatic advertiser resuming in the Host.

It turns out now that the behavior of this feature depends on which
Controller is in use and can fail incorrectly.

The test assumes the DUT will be able to create `CONFIG_BT_MAX_CONN`
peripheral connections. But this is not necessarily true. E.g. Some
Controllers, like the SoftDevice Controller, may reserve some Host
connection slots for central roles, making the max number of peripheral
connections smaller.

In conclusion, the test is not correct and should be removed.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2024-07-04 13:26:01 +02:00
Jordan Yates cf870e8350 bluetooth: correct `bt_le_scan_param` scan type
The `type` parameter of `struct bt_le_scan_param` is documented as
taking a `BT_LE_SCAN_TYPE_*` value, not a `BT_HCI_LE_SCAN_*` value.

In practice this makes no difference as the values are defined as the
same integer, but does result in `<zephyr/bluetooth/hci.h>` not needing
to be included.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-06-28 11:34:36 +02:00
Aleksander Wasaznik 8cd98b139d Bluetooth: test: privacy/legacy: Scan continuously
Some controllers, like the SoftDevice Controller can miss the first few
advertisements after the host tells it to start scanning. The DUT would
assumes the first RPA advertisements report it gets is the first that
was sent, but it was actually not the first. This would skew the
tester's judgement about the timing of RPA rotations.

To remedy this, the tester will scan continuously and switch between
expecting the identity address and the RPA without stopping the scanner.

The tester will tell the DUT to switch to RPA after it has received the
identity address advertisement. This ensures that the tester will not
miss the first RPA advertisement.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2024-06-27 10:55:55 -04:00
Carles Cufi 06d7d763bd Bluetooth: gatt: Remove deprecated write struct member
The struct member was deprecated back in Zephyr 3.1.0.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2024-06-24 12:42:30 -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
Jonathan Rico d3dbf890bf tests: Bluetooth: make an L2CAP multilink stress test
This test's purpose is to stress the TX data path in the case of multiple
connections.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-06-19 13:38:49 +02:00
Yong Cong Sin 1899e4f667 bluetooth: remove CONFIG_BT_DEBUG_LOG
`CONFIG_BT_DEBUG_LOG` has been deprecated for more than 2
releases, replace it with `CONFIG_BT` + `CONFIG_LOG`:

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
2024-06-18 14:33:58 -04:00
Valerio Setti e9687c7e5c bsim: add tests for BT_USE_PSA_API
Add a couple PSA overlay configs for the BT tests in order to evaluate
PSA API support introduced by CONFIG_BT_USE_PSA_API. These test are
performed on nrf52840dk platform.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2024-06-14 15:41:34 +02:00
Jonathan Rico 28be8909a6 Bluetooth: host: remove TX thread
We don't need the TX thread anymore.

Generalizing the pull-based architecture (ie. `tx_processor`) to HCI
commands makes it possible to run the whole TX path from the the system
workqueue, or any workqueue really.

There is an edge-case, where we call `bt_hci_cmd_send_sync()` from the
syswq, stalling the system. The proposed mitigation is to attempt to drain
the command queue from within `bt_hci_cmd_send_sync()`.

My spidey sense tingles however, and it would be better to just remove the
capability of calling this fn from the syswq. But doing this requires
refactoring a bunch of synchronous procedures in the stack (e.g. stack
init, connection establishment, address setting etc), dragging in more
work. I will do it, but in a later patch.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-06-12 18:51:34 +02:00
Jonathan Rico 1c8cae30a8 Bluetooth: host: Introduce "view" buffer concept
Instead of allocating segments/fragments and copying data into them, we
allocate segments as "views" (or slices) into the original buffer.

The view also gives access to the headroom of the original buffer, allowing
lower layers to push their headers.

We choose not to allow multiple views into the same buffer as the headroom
of a view would overlap with the data of the previous view.

We mark a buffer as locked (or "in-view") by temporarily setting its
headroom to zero. This effectively stops create_view because the requested
headroom is not available.

Each layer that does some kind of fragmentation and wants to use views for
that needs to maintain a buffer pool (bufsize 0, count = max views) and a
metadata array (size = max views) for the view mechanism to work.

Maximum number of views: number of parallel buffers from the upper layer,
e.g. number of L2CAP channels for L2CAP segmentation or number of ACL
connections for HCI fragmentation.

Reason for the change:
1. prevent deadlocks or (ATT/SMP) requests timing out
2. save time (zero-copy)
3. save memory (gets rid of frag pools)

L2CAP CoC: would either allocate from the `alloc_seg` application callback,
or worse _steal_ from the same pool, or allocate from the global ACL pool.

Conn/HCI: would either allocate from `frag_pool` or the global ACL pool.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
Co-authored-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2024-06-12 18:51:34 +02:00
Rubin Gerritsen b30d2d1bf5 Bluetooth: Host: Add a test for connection creation timeout
It seemed like there was lacking test coverage for this
functionality.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-06-11 16:17:35 +02:00
Rubin Gerritsen 1aa33fe368 tests: bsim: Use the pre_init_f instead of post_init_f
When using the post_init_f to initialize the `bst_result`,
it is not possible to mark the test as
passed immediately as the `bst_result` will be
initialized after the test completes.

This change should overcome this limitation.

Bluetooth mesh tests are kept as is as we are not
sure if this will change the behavior.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-05-30 03:00:58 -07:00
Rubin Gerritsen ff80c0b926 Bluetooth: Host: Fix connection establishment upon RPA timeout
Before this commit, the following bugs were present:
- When `CONFIG_BT_FILTER_ACCEPT_LIST` was set, connection establishment
  was cancelled upon RPA timeout. This required the application
  to restart the initiator every RPA timeout.
- When `CONFIG_BT_FILTER_ACCEPT_LIST` was not set, the RPA was not updated
  while the initiator was running.

This commit unifies the RPA timeout handling for both these cases.
Upon RPA timeout the initiator is cancelled and restarted when
the controller raises the LE Connection Complete event.
The workqueue state is checked when restarting the initiator to prevent
it being restarted when the timeout is hit.

Corresponding test cases have been added to ensure that this
feature works.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-05-28 09:12:05 -07:00
Rubin Gerritsen 3ce106c620 Bluetooth: Host: Fix not clearing IDs and keys upon bt_disable()
Expectation: After calling `bt_disable()` it is possible to
use the Bluetooth APIs as if `bt_enable()` was never called.

This was not the case for `bt_id_create()`, it was not possible
to set the default identity. This prevented an application
developer to restart the stack as a different identity.

Keys also need to be cleared to avoid the following pattern:
1. Pair two devices
2. Central calls `bt_disable()` and `bt_enable()`.
   The central will now generate a new identity address.
3. Connect the two devices.
4. Re-establish encryption. Now the central will try to use
   the previously used keys. The procedure will fail
   because the peripheral does not have any keys associated
   with the new central address.

The API documentation is updated accordingly.

Signed-off-by: Rubin Gerritsen <rubin.gerritsen@nordicsemi.no>
2024-05-28 09:11:52 -07:00
Jonathan Rico ea41a24d3a Bluetooth: tests: fix double-registering of callbacks
This was the source of assert failures.
If only they were enabled in the first place...

The issue is that in order to save on build time, these two tests build
only one image, from which two devices are
instantiated (`gatt_client_test.c` and `gatt_server_test.c`).

The double-registration happens as `BT_CONN_CB_DEFINE()` is build-time, and
is included in two files of the same image. Then _both_ images will end up
with both `connected()` `disconnected()` etc callbacks, which have logic
specific to their respective images/devices.

The patch uses runtime registration instead so each device only ever
registers its own callbacks and not the other device's too.

Signed-off-by: Jonathan Rico <jonathan.rico@nordicsemi.no>
2024-05-27 03:39:50 -07:00
Emil Gydesen cc602a6941 tests: Bluetooth: Fix incorrect comments about adv sets
Several places we simply had
/* Create a non-connectable non-scannable advertising set */
regardless of the type of advertising it was.

Modified the comment to omit the scannable part
and corrected the connectable part.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-05-24 07:46:43 -04:00
Aleksander Wasaznik 765b244c27 Bluetooth: host: tests: Switch to one-time adv
This patch removes all uses of the adv auto-resume feature in the host
bsim tests, except for the test of that feature itself, and instead
makes all adv starts explicit.

The auto-resume feature is planned for deprecation. And, explicit
starting of adv makes what happens in the test more explicit as well.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2024-05-23 11:51:07 -04:00
Emil Gydesen c476456c59 Tests: Bluetooth: Add BSIM test of ISO BIS
Adds 2 tests for ISO broadcast.

First test is just a minimal test that sets up a BIG,
transmits data and verifies that it is being received
on the ISO sync receiver.

The second test creates a BIG, disables BT, enables BT,
and the verifies the above.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-05-18 15:54:19 +03:00
Emil Gydesen c40856e5aa Bluetooth: ISO: Support bt_disable
Add support for bt_disable in the ISO implementation.
This involves clearing all information related to states
in the controller, such as the BIGs and CIGs.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-05-18 15:54:19 +03:00
Vinayak Kariappa Chettimada 2c6306d099 Bluetooth: Controller: BT_CTLR_ISO_TX_BUFFER_SIZE from BT_ISO_TX_MTU
Derive BT_CTLR_ISO_TX_BUFFER_SIZE from BT_ISO_TX_MTU to have
optimal Controller memory allocations.
BT_CTLR_ISO_TX_BUFFER_SIZE can be set lower than
BT_ISO_TX_MTU in which case upper layer can send fragmented
SDU to the Controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2024-05-10 15:02:10 +02:00