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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>