Commit Graph

2963 Commits

Author SHA1 Message Date
Pisit Sawangvonganan c120ffb31d bluetooth: shell: avoid multiple `strlen` calls
Add `len` to store the result of `strlen(addr_arg)` to avoid
multiple calls to `strlen` within the `for-loop` in
`cmd_scan_filter_set_addr`.
While the performance impact may be minimal in a shell context,
storing `strlen(addr_arg)` in `len` ensures a single call,
making the code more predictable and consistent.

Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
2024-11-16 13:50:58 -05:00
Emil Gydesen c32210b003 Bluetooth: Host: ID: Log resolve list conflicts
In case of conflicts when calling bt_id_find_conflict
there was no way to easily determine what conflicted.

This is a rare occurance, but has happened when testing
against PTS.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-11-16 13:43:59 -05:00
Håvard Reierstad 42ae483795 Bluetooth: Host: Ensure only connected peers affect `_bt_gatt_ccc.value`
The doc on `_bt_gatt_ccc.value` specifies that only connected peers
contribute to that value. But before this change, it was computed from
all entries in `_bt_gatt_ccc.cfg`, which include bonded but not
connected peers when `CONFIG_BT_SETTINGS_CCC_LAZY_LOADING` is set.

Co-authored-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
2024-11-08 11:35:42 -06:00
Johan Hedberg d1a3f4f4fe Bluetooth: Host: Fix monitor UART selection
Most boards set zephyr,bt-mon-uart to point at the same device as
zephyr,console. It's still useful to have the possibility of having these
as two different devices, however it's useful to fall back to the UART
console in case a dedicated monitor UART hasn't been specified.

This also ensures that the fallback only happens if the console UART isn't
enabled, but a DT chosen property exists for it. Additionally, we now get a
user friendly error in case the Bluetooth UART monitor feature has been
enabled in Kconfig but there isn't a suitable UART available for it in
devicetree.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2024-11-01 09:56:52 -05:00
Håvard Reierstad 0b88078b28 Bluetooth: host: Fix unsafe cast in is_subscribed
The current implementation casts the user data to the attribute value,
which makes an assumption about the user data. This commit changes the
implementation to use the attribute value read function when extracting
the characteristic properties.

Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
2024-11-01 09:55:25 -05:00
Alberto Escolar Piedras 2af45d1d78 subsys/bluetooth/host/keys.h: Add include guard and required include
This header requires bluetooth.h but was not including it itself.
Due to this we had 2 tests failing to build.
Let's just include the dependencies to this header instead of
relaying on users including the dependencies dependencies in
the right order.

Also, let's add an include guard as in a test this header was
included twice leading to weird build errors.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
2024-10-29 09:24:13 -07:00
Aleksander Wasaznik 5f89a6b8f1 Bluetooth: Host: Add BT_TESTING trace event for ACL pool destroy
This is needed for a test to catch a double-free.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2024-10-26 17:13:45 +02:00
Aleksander Wasaznik 70ad45d4d9 Bluetooth: Host: Upgrade log severity for L2CAP user error
For ease of development, we should log the event as an error.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2024-10-26 17:13:45 +02:00
Aleksander Wasaznik 200de7c00a Bluetooth: Host: Fix `bt_l2cap_chan_ops.recv` `-EINPROGRESS`
Fix discrepancy in reference management between calls to
`bt_l2cap_chan_ops.recv` when the application returns `-EINPROGRESS`.

There are two call sites, `l2cap_chan_le_recv_sdu` and
`l2cap_chan_le_recv`, that were inconsistent.

`l2cap_chan_le_recv_sdu` moves the reference, and this patch updates
`l2cap_chan_le_recv` to do the same.

This behavior is also now documented.

This bug has existed since the introduction of this feature in
3151d26572.

Signed-off-by: Aleksander Wasaznik <aleksander.wasaznik@nordicsemi.no>
2024-10-26 17:13:45 +02:00
Lars Knudsen c966eac722 Bluetooth: Shell: Fix missing RX QoS param and MSE check
The bis_iso_qos.rx was missing in param sent in bt_iso_big_sync

Also, MSE = 0 is valid (fixed error check)

Signed-off-by: Lars Knudsen <LAKD@demant.com>
2024-10-25 12:55:32 -05:00
Lars Knudsen 09546ff3e3 Bluetooth: Shell: Set err to 0 before shell_strtoul
The value of err was not initialized to 0 prior
to calling shell_strtoul, which only sets err
on actual error.

Signed-off-by: Lars Knudsen <LAKD@demant.com>
2024-10-25 12:50:23 -05:00
Lars Knudsen c15f8edd60 Bluetooth: Shell: Fix iso sync timeout range check
Using BT_ISO_SYNC_TIMEOUT_MIN and BT_ISO_SYNC_TIMEOUT_MAX now.

Signed-off-by: Lars Knudsen <LAKD@demant.com>
2024-10-25 12:49:38 -05:00
Olivier Lesage 7e72d46e2e bluetooth: host: Add helper function for parsing PCTs
The 12-bit signed values for the results of PBR are a bit
cumbersome, so this adds a helper function to make it easier to work
with the HCI formatted steps.

Signed-off-by: Olivier Lesage <olivier.lesage@nordicsemi.no>
2024-10-25 14:06:25 +02:00
Olivier Lesage 635d03b7e0 bluetooth: host: Unit tests for bt_le_cs_step_data_parse
Add unit tests for bt_le_cs_step_data_parse.
Also exit early (without calling the function pointer) if the next
step would seem to read out of bounds.

Signed-off-by: Olivier Lesage <olivier.lesage@nordicsemi.no>
2024-10-25 14:06:25 +02:00
Emil Gydesen 25c993e5b7 Bluetooth: Host: Remove implicit conversions of own_addr_type
Remove implicit conversions and assignment to the
own_addr_type variables.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-10-23 16:53:23 +02:00
Emil Gydesen da2e8c3c96 Bluetooth: Add and use missing own_addr_type defines
The own_addr_type used for various HCI commands sometimes
had a BT_HCI_OWN_ADDR_* type value or a BT_ADDR_* type
value. Those are 2 different value spaces, and if the public
address types would ever change, it would start have incorrect
behavior.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2024-10-23 16:53:23 +02:00
Pavel Vasilyev 8acb1cc577 bluetooth: host: conn: Check if *conn is not NULL
This commit adds a warning and a Kconfig option to `bt_conn_le_create`
and `bt_conn_le_create_synced` functions which are meant to warn a user
of a potential leakage of an active connection object.

This change is implemented due to frequent incorrect use of the
connection pointer where a pointer to an existing connection object
is overwritten by `bt_conn_le_create` and `bt_conn_le_create_synced`
functions which in turns leads to sporadic critical bugs. See
https://github.com/zephyrproject-rtos/zephyr/pull/78284#discussion_r1754304535
for more details.

The Kconfig option is introduced instead of always returning the error
to not affect current implementations. However, it is recommended to
keep this option enabled to avoid potential bugs.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2024-10-18 17:46:04 +01:00
Adam Cavender 18f508144e bluetooth: host: CS support for various HCI commands
Adds HCI support for:
- LE CS Security Enable
- LE CS Procedure Enable
- LE CS Set Procedure Parameters
- LE CS Set Channel Classification
- LE CS Read Local Supported Capabilities
- LE CS Write Cached Remote Supported Capabilities
- LE CS Write Cached Remote FAE Table

Signed-off-by: Adam Cavender <adam.cavender@nordicsemi.no>
2024-10-18 14:15:49 +02:00
Sungwoo Kim 2f50e26c40 Bluetooth: HCI: Add validation for data from controllers
Like 2ca179c, check and warn if incoming HCI event parameters exceed
the specification. This helps debugging controllers by detecting the
out-of-spec value that shouldn't appear.

Signed-off-by: Sungwoo Kim <iam@sung-woo.kim>
2024-10-18 09:17:57 +02:00
Szymon Janc 5b232bf1d7 Bluetooth: GATT: Allow to tune writable device appearance permissions
This allows to select if device appearance requires encryption or
authentication or none. This makes it similar to what is implemented
for device name characteristic.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2024-10-16 16:35:56 +01:00
Szymon Janc 398487f841 Bluetooth: GATT: Convert writable device name to KConfig choice
This makes it clear on how security requirements are set and avoid
confusion on how encryption and authentication are handled.

Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2024-10-16 16:35:56 +01:00
Lyle Zhu 0e4561bed2 Bluetooth: SSP: No MITM if required level is less than L3
Regardless IO capabilities, clear MITM flag for pairing
initiator if the required security level is less than
BT_SECURITY_L3.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-10-16 09:59:38 +02:00
Burak Gorduk c5a126cedb bluetooth: host: LE CS subevent result reassembly
Adds HCI support for LE CS subevent result continue
event and the reassembly logic for the partial results.

When subevent results are completed or the subevent is
aborted, the user callback is invoked with a buffer
pointing to the HCI event buffer, so no copy is done.

When subevent results are incomplete, then a reassembly
buffer is allocated from a fixed sized pool. This buffer
is used for the reassembling of the subevent result
containing all of the step data, which is then passed
to the user via the callback. kconfigs have been added
to set the size and the count of the reassembly buffer.

Signed-off-by: Burak Gorduk <burak.gorduk@nordicsemi.no>
2024-10-15 19:09:05 -04:00
Erik Sandgren 5f59b35b42 Bluetooth: Host: Fix issue where uninitialized value was used
This change makes sure that when a call to `bt_id_set_scan_own_addr` is
sucessful, i.e., the return value is 0, the `own_addr_type` will
be set by the `bt_id_set_scan_own_addr`.

Not setting the `own_addr_type` in a successful call to
`bt_id_set_scan_own_addr` causes, for example,
the `start_le_scan_ext` method in `scan.c` to use an
uninitialized `own_addr_type`.

Eventually this results in an unexpected failure further down in
`start_le_scan_ext`, when sending HCI command to controller with
an uninitialized `own_addr_type`.

Signed-off-by: Erik Sandgren <erik.sandgren@nordicsemi.no>
2024-10-15 04:07:50 -04:00
Marek Pieta 341f1f502d bluetooth: conn: Use a separate workqueue for connection TX notify
Use a separate workqueue instead of system workqueue for connection TX
notify processing. This makes Bluetooth stack more independent from the
system workqueue.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2024-10-11 13:16:26 -04:00
Lars Knudsen 7f1589e23b Bluetooth: ISO: Add ISO BIS bitfield check macro
Checks validity of ISO BIS bitfield (BIT(0)|...|BIT(30))

Signed-off-by: Lars Knudsen <LAKD@demant.com>
2024-10-10 20:22:39 -04:00
Jordan Yates 257c5e6aff bluetooth: conn: increase log level of timeout ignore
Notifying users that the supplied timeout is being ignored is worthy of
a higher log level than debug. Any such usage should be changed at the
application level.

Signed-off-by: Jordan Yates <jordan@embeint.com>
2024-10-10 14:59:16 -04:00
Pavel Vasilyev 74972e694b bluetooth: host: l2cap: Check conn state before queueing PDU
In case of UATT, if a connection was lost while user was holding a read
or write attribute callback, `bt_l2cap_send_pdu` (called from
`att.c::chan_send`) will anyway queue a PDU and trigger tx work. The PDU
won't be sent eventually, but neither will hold an error code, which
will allow it to bypass the error check in `att_on_sent_cb` and call
`att_sent` function.

For EATT `bt_l2cap_chan_send` is used which already handles this case
and the error code is passed to `att_on_sent_cb`.

This change adds connection state check to `bt_l2cap_send_pdu`
preventing from unnecessary code execution when connection does not
exist anymore.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2024-10-10 14:59:02 -04:00
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
Pavel Vasilyev f712bde122 bluetooth: host: att: Implement disconnect on ATT timeout
The timeout state is local and can block new ATT operations, but does
not affect the remote side. Disconnecting the GATT connection upon ATT
timeout simplifies error handling for developers. This reduces rare
failure conditions to a common one, without needing special cases for
ATT timeouts.

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
Lyle Zhu 3756429b6c Bluetooth: BREDR: L2CAP: Recover ident when conn is pending
The `ident` of L2CAP BR connection req will be cleared if
function l2cap_br_conn_req_reply called to send L2CAP BR
connection rsp with result `BT_L2CAP_BR_PENDING`.

Then the invalid `ident` (it is zero) will be filled in
the L2CAP BR connection rsp after the ACL connection is
encrypted.

Recover `ident` if the result of the connection rsp is
`BT_L2CAP_BR_PENDING`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-10-05 14:07:24 -04:00
Lyle Zhu c7c1f73045 Bluetooth: SSP: Support security level 4
Currently, error code `-ENOTSUP` will be
returned if start security with security
level 4.

For SC supported case, level 4 for ssp
should be supported.

Remove the code limitation to support
security level 4.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-10-05 14:07:15 -04:00
Lyle Zhu 7e54f13e7b Bluetooth: l2cap_br: Support Multi-Command Packet
Improve L2CAP BR to handle more than one
signaling command in one receiving L2CAP packet.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-10-05 14:07:09 -04:00
Lyle Zhu 3561540110 Bluetooth: L2CAP_BR: Set flags in CFG RSP
The flags of L2CAP_CONFIGURATION_REQ are set.
But in L2CAP_CONFIGURATION_RSP, all bits of
flags are cleared.

When used in the L2CAP_CONFIGURATION_RSP
packet, the continuation flag shall be set
to one if the flag is set to one in the
Request.

Copy flags from Request to Response if it
is a successful result.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-10-05 14:07:00 -04:00
Lyle Zhu b7ab7c9d45 Bluetooth: L2CAP_BR: Process all defined OPTs
Currently, Only configuration opt MTU is handled.

For opt `Flush timeout`, `QOS`, `Retransmission
and Flow Control`, and `FCS`, response wilt
result `BT_L2CAP_CONF_UNACCEPT`.

For opt `extended flow specification` and
`extended windows size`, response wilt result
`BT_L2CAP_CONF_REJECT`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-10-05 14:06:55 -04:00
Lyle Zhu c5648044a8 Bluetooth: L2CAP_BR: incorrect result returned if config opt unsupported
The `BT_L2CAP_CONF_SUCCESS` is returned as result for the config
req with supported opt.

Result `BT_L2CAP_CONF_UNKNOWN_OPT` should be returned for this case.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-10-05 14:06:55 -04:00
Olivier Lesage 9e3943d13e bluetooth: host: Add CONFIG_BT_CHANNEL_SOUNDING_TEST
Makes it easier to make sure the CS test code is removed if desired.
It should hopefully allow for a clean split in general.

Signed-off-by: Olivier Lesage <olivier.lesage@nordicsemi.no>
2024-10-04 16:34:45 +01:00
Olivier Lesage a12b869eac bluetooth: host: Add support for processing CS subevent results
Adds support for:
- LE CS Subevent Result event
- LE CS Test End Complete event

For now, recombination of subevent results with more steps than could
fit within a single HCI event is not supported, and such events
are discarded.

Signed-off-by: Olivier Lesage <olivier.lesage@nordicsemi.no>
2024-10-04 16:34:45 +01:00
Lyle Zhu 0ed8866eb6 Bluetooth: host: Kconfig: Correct `help` of `BT_BONDABLE`
Correct the `help` of the configuration `BT_BONDABLE`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-10-02 15:54:30 +02:00
Lyle Zhu aaab223574 Bluetooth: SSP: Incorrect bonding status notified
The `bonded` flag of the callback `pairing_complete` is always true,
event if the SSP pairing is non-bondable.

Check the bonding status in SSP complete event instead of in link key
notify event.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-10-02 15:54:30 +02:00
Lyle Zhu a00d5089d5 Bluetooth: shell: Add command `conn-bondable`
Add command `conn-bondable` to enable/disable the pairing bondable
flag of a specific ACL connection.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-10-02 15:54:30 +02:00
Lyle Zhu d5160f663a Bluetooth: BR: Improve `bt_conn_set_bondable`
In current, the bondable flag cannot be configured for each specific
BR connection.
But for LE conn, there is a function `bt_conn_set_bondable` for this
purpose.

Improve `bt_conn_set_bondable` to support BR conn.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-10-02 15:54:30 +02:00
Lyle Zhu e772c45e6b Bluetooth: SSP: Support non-bondable mode
If the return value of function bt_get_bondable is false, clear the
bonding flag when controller requiring `Authentication_Requirements`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-10-02 15:54:30 +02:00
Lyle Zhu c0ce5b419b Bluetooth: Host: smp: Add function to get bonding setting
Add a function bt_get_bondable to get the bonding setting.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-10-02 15:54:30 +02:00
Lyle Zhu 4c09f5cce3 Bluetooth: BR: Shell: Remove duplicated `else` statement
Remove duplicate `else` statement if the function is returned from
corresponding `if` statement.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-10-02 10:15:14 +02:00
Lyle Zhu 0270f91c1c Bluetooth: BR: Shell: Return error if command is failed
Return error code if the command is failed instead of `0`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-10-02 10:15:14 +02:00
Lyle Zhu 3b74ed3f54 Bluetooth: BR: shell: Rename `int res` to `int err`
Rename `int res` to `int err`. Make variable naming consistent.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-10-02 10:15:14 +02:00
Lyle Zhu 17cfe36195 Bluetooth: BR: Return `SHELL_CMD_HELP_PRINTED` if calls shell_help
If the function `shell_help` is called, return SHELL_CMD_HELP_PRINTED
instead of `0`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-10-02 10:15:14 +02:00
Lyle Zhu 0b6684d8e3 Bluetooth: l2cap_br: Comment on l2cap->info_fixed_chan
Comment on the l2cap->info_fixed_chan why the size of it is one octet.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2024-10-02 10:14:18 +02:00