Implements a method for discarding fragmented extended advertising. In
order to acheive this, we need to consider past and future fragments
of the advertising report we discard.
The future fragments are on its way from the controller, and will result
in either a complete- or incomplete event. These are handled by tracking
the adv SID and address until the controller sends either a complete or
incomplete event. Once an advertising report is marked as discarded,
consecutive fragments will be silently discarded.
The past fragments are either already in the reassembler (in scan.c),
or on their way through the rx_queue. To handle these, and allow the
reassembler to recover from a in-progress reassembly which is discarded,
we add a work item which is rescheduled when each consecutive fragment
is received. The timeout is configurable through the new Kconfig option
`CONFIG_BT_EXT_ADV_REASSEMBLY_TIMEOUT`. On timeout, the reassembler will
change its state to discard incoming fragments from the same advertiser.
The reassembler will start assembling new fragments if it recognises a
new advertiser, or if a final fragment (either marked as complete
or incomplete) from the advertiser it is currently tracking is received.
This functionality needs to be added at a HCI driver level by using the
new `hci_ext_adv_report_process` function. It is added the the
IPC HCI driver to fixzephyrproject-rtos/zephyr#50786
Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
Add new inline function entropy_get_default_device which returns
the "zephyr,entropy" device or the architectural entropy device,
if the former is not set, and use that in all places to query the
entropy device.
This allows using architectural drivers which do not have a DT
node.
Signed-off-by: Christoph Busold <cbusold@qti.qualcomm.com>
The right_ring_buf_fail_cnt field was never read.
Remove the dead field.
Assisted-by: Claude:claude-sonnet-4.6
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Apply ARG_UNUSED() to unused function arguments as per the Zephyr
coding guidelines
A few functions were modified to remove unused parameters
or to actually use the parameters.
Assisted-by: GitHub Copilot
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The scanning field was set to false in broadcast_assistant_reset() but
never read anywhere. The scanning state is tracked via the
BAP_BA_FLAG_SCANNING atomic bit; the bool field is leftover dead code.
Assisted-by: Claude:claude-sonnet-4.6
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Introduce HAL_EVENT_TIMER_US_TO_TICKS macro to explicitly map the 1 MHz
hardware timer resolution to the radio configuration, preventing unintended
unit mixing between microseconds and hardware ticks.
Fixes#105085
Signed-off-by: Bhavin Umatiya <umatiyabhavin@gmail.com>
The broadcast_sink pointer was written in three places (set and
cleared) in bap_broadcast_sink.c but never read or dereferenced
anywhere in the codebase. Remove the field, its three write sites,
and the now-unneeded forward declaration of struct bt_bap_broadcast_sink
in bap_endpoint.h.
Assisted-by: Claude:claude-sonnet-4.6
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Adds IRK update call to internal bt_le_adv_start_ext. And rename it to
adv_start_ext to prevent confusion with public functions.
There are two paths to start ext advertising:
- bt_le_adv_start can start extended advertising if enabled by calling
internal bt_le_adv_start_ext else it starts legacy advertisements.
- bt_le_ext_adv_start specifically starts extended advertisements.
This commit misses the first path for ext advertisement:
6d137ae015
Signed-off-by: Alperen Sener <alperen.sener@nordicsemi.no>
Fix a race condition in RFCOMM session disconnection when both local
and peer devices initiate disconnection simultaneously.
Add state check in `rfcomm_session_disconnected()` to only transition
to `DISCONNECTED` state if the session is not already in
`DISCONNECTING` state. This prevents the race condition where both
sides set the session to disconnected, causing the disconnection
process to not complete properly and leaving the L2CAP connection
unreleased.
Without this check, subsequent RFCOMM channel connection requests
would fail due to the invalid session state (the expected state is
`IDLE`, while the actual state is `DISCONNECTED`).
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
The technology values defined in tbs.h are actually defined
in assigned numbers under the HFP. They have been moved to
the assigned_numbers.h file, and name to match the placement
in Assigned Numbers. They have been defined in an enum instead
of multiple #define's, to more easily refer to them.
The callback for reading technology was likewise updated to use
the new enum.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add SPP test shell commands, support client and server features.
include register, connect, send and disconnect.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Add bt_conn_br_set_sniff_subrating() API to configure sniff subrating
parameters for BR/EDR connections. Sniff subrating allows further
power savings by reducing the number of sniff anchor points the
device needs to listen on.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Introduce struct bt_conn_br_cb to group all BR/EDR specific connection
callbacks (role_changed, mode_changed) into a dedicated sub-struct
within bt_conn_cb. This replaces the previously scattered callbacks
that were individually guarded by CONFIG_BT_CLASSIC or
CONFIG_BT_POWER_MODE_CONTROL.
Application code now uses the .br. accessor:
.br.role_changed = my_role_changed_cb,
.br.mode_changed = my_mode_changed_cb,
The br_ prefix is dropped from callback names since the struct
hierarchy already conveys the BR/EDR scope, aligning with the
pattern suggested during review.
Also fix bt_conn_notify_mode_changed() to use
BT_CONN_CB_DYNAMIC_FOREACH instead of SYS_SLIST_FOR_EACH_CONTAINER
for consistency with other callback notification functions.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
The VOCS discover callback may call vcp_vol_ctlr_discover_complete()
with a NULL vol_ctlr when lookup_vcp_by_vocs() fails.
This leads to a potential NULL pointer dereference as
vcp_vol_ctlr_discover_complete() unconditionally accesses
vol_ctlr->flags.
Fix this by returning early when vol_ctlr is NULL.
Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
Core spec defines the range of adv intervals for extended advertising to
0x0020 to 0xFFFFFF, but the code currently only allows up to 0x4000.
This change enables the full range of intervals for extended advertising
Signed-off-by: Kyra Lengfeld <kyra.lengfeld@nordicsemi.no>
Remove the logic that silently clamps the MTU to valid ranges and
instead return an error if the configured MTU is below the minimum
required size.
The MTU is now always set to the maximum value that the configuration
can support, rather than conditionally using a default only when
set to 0.
Change log level from WRN to ERR for the minimum MTU check since
this now represents a fatal configuration error.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
ISO connections basically have 2 connection states:
1 for the `bt_iso_chan`, and one for the underlying
`bt_conn`. Due to how hci_disconn_complete_prio works,
these may be out of sync while disconnecting, and
bt_iso_chan_send could return 0 after we have received
a disconnect event from the controller. In this case
the number of pending SDUs in the host for the ISO
channel could be non-0, which could cause issues.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Make the Coordinated Set Size, Set Member Lock and Set Member Rank
characteristic optional by adding three new Kconfig options
BT_CSIP_SET_MEMBER_SIZE_SUPPORT, BT_CSIP_SET_MEMBER_LOCK_SUPPORT and
BT_CSIP_SET_MEMBER_RANK_SUPPORT. Also updates the existing examples
and tests to compile correctly.
Signed-off-by: Maximilian Zimmermann <gitmz@posteo.de>
Reorder some of the large and complex shell command
functions, to make each function simpler to follow.
This also makes the code pass the Sonarcloud complexity
rule.
This also contain a few other various fixes and updates.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Instead of defining the same arguments in all 3 CAP files,
we declare them in audio.h and initiate them in either
the initiator or commander, depending on their use.
The reason for this change, is that the CAP Handover API
require several of the parameter to be globally/statically
allocated, and cannot just rely on stack allocated parameters.
By doing this, we can use the same argument among the
CAP shell modules, while keeping the memory usage down.
This has the additional postive effect that we do not allocate
some of these arrays, which can be quite larger, on the stack.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Implement the shell command for handing over broadcast to
unicast. The command supports various configurations.
It is currently limited to cases with
- 1 connection and multiple streams
- Multiple connections and 1 stream
- Equal amount of streams and connections
Cases with e.g. 3 connections and 2 streams,
or vice versa, are not support given the complexity
of these cases.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The two cached handles did not provide anything useful
and can be removed, thus freeing up some memory.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Instead of allocating a generic uuid and copying the BASS UUID
to it for each discovery, we can just use declare and use it
as a constant as it won't change.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Fix insufficient buffer length validation in bt_sdp_parse_attribute().
The original check only verified space for the type byte and attribute
ID, but did not account for the type variable itself that is read from
the buffer immediately after the check.
This could lead to a buffer over-read if the buffer contains exactly
sizeof(uint8_t) + sizeof(attr->id) bytes but not enough for the
additional type field.
Add sizeof(type) to the length check to ensure all required data is
present before parsing.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
Add checks to verify the valid length of broadcast names
in codec_cfg and codec_cap, both in terms of size in octets,
but also in terms of length in characters.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add checks to verify the valid length of broadcast names
in codec_cfg and codec_cap, both in terms of size in octets,
but also in terms of length in characters.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
MISRA-C requires essentially boolean type in control flow.
Convert all if/while conditions using err or ret
as implicit booleans to explicit comparisons:
- if (err) -> if (err != 0)
- Same rules applied to while statements and ret variable
Assisted-by: GitHub Copilot
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Move the AVRCP cover art initialization from bt_avrcp_init() to
bt_avrcp_tg_register_cb(). This ensures that cover art is initialized
only when the target callback is registered, aligning with the
initialization flow of other AVRCP target features.
Additionally, add a check in bt_avrcp_tg_cover_art_init() to prevent
re-initialization if the PSM is already set, returning success if
cover art is already initialized.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
The bt_bap_unicast_client_discover and
bt_bap_broadcast_assistant_discover functions now require security
to have already been done before any operations are done.
The BAP require a specific security level and properties,
and checking the security earlier will prevent any unncessary
operations if the expected security requirement cannot be met.
Additionally, ensuring that there is an appropriate pairing with
the provided connection, ensures that we can rely on CONFIG_BT_MAX_PAIR
for soem arrays in the future.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Make the qos parameter of the BAP can CAP APIs const,
as they are now only used as one-time parameters, and not stored.
This also means that any uses of this can place the qos
parameter in the stack, rather than static memory.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The pointer represent the qos configuration
for a stream based on the ASE or broadcast configuration,
and serves as a read-only value. Changing it to `const` makes
this more clear.
Some minor changes were done to existing code to help
support this change.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
In some cases the stream->qos pointer pointed to the
qos argument, and sometimes it pointed to the ep->qos.
Now all qos arguments are copied to ep->qos, and
stream->qos always points to stream->ep.qos.
Some modules had some refactoring done to properly store
the QoS. The unicast client had some additional checks
done or redone, and some now-unused code removed.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Standardize error handling for bt_conn_get_info()
across the Bluetooth shell.
- Use a local 'err' variable instead of inline calls
- Check for (err != 0) consistently
- Include error code in all error messages
- Improve log messages for better debugging context
This ensures consistent behavior and more
informative diagnostics when retrieving connection
information fails.
Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
Use shell_error() instead of shell_print() when
bt_conn_get_info() fails and include the returned
error code in the log.
This makes failures easier to diagnose.
Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
Coverity (CID 525133) reported that the return
value of bt_conn_get_info() was not checked in
disconnected(), which could lead to use of
uninitialized data.
Fix this by validating the return value before
using the connection info structure.
If retrieving the information fails, fall back to
using the generic connection type to preserve the
existing behavior.
This prevents undefined behavior while maintaining
the original logic.
Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
Coverity (CID 333394) reported that the return
value of bt_conn_get_info() was not checked in
remote_info_available(), which could lead to use
of uninitialized data.
Fix this by checking the return value and aborting
early in case of error, ensuring that the
connection info structure is valid before use.
Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
The scan parameter is in units of 10ms in the Zephyr API, however the same
value was being treated differently for active and passive scanning. For
passive scanning the value got passed to the timeout as 10ms units, however
with active scanning it was treated as seconds by passing it to the
K_SECONDS() macro. Fix this by treating it as 10ms units in both cases.
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Convert the scan command parameters to use getopt. While we're at it, get
rid of the confusing "dups" "nodups" options which actually behaved in the
inverse to their names ("nodups" would give you duplicate results while
"dups" would not). The new parameter is called the same as in the Zephyr
API and HCI, namely --filter-dups.
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Add support for specifying the exact advertising interval for the
"advertise" shell command. The new support is done with the help of
getopt, and since this is the first user of it in the Bluetooth shell the
appropriate select statement is added in Kconfig.
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Add Message Access Profile (MAP) shell command support to the
Bluetooth shell module.
Add map.c to the CMakeLists.txt build configuration when
CONFIG_BT_MAP is enabled, allowing MAP shell commands to be
compiled into the shell module.
Enable MAP configuration options in the Bluetooth shell test
configuration, including both MCE (Messaging Client Equipment)
and MSE (Messaging Server Equipment) functionality.
This enables testing and demonstration of MAP profile features
through the Bluetooth shell interface.
Signed-off-by: Can Wang <can.wang@nxp.com>
Add source files and Kconfig options for Bluetooth Message Access
Profile (MAP) support.
MAP enables remote access to messages stored on a Messaging Server
Equipment (MSE) device from a Messaging Client Equipment (MCE) device.
The profile supports browsing folder hierarchies, listing messages,
retrieving message content, sending messages, and receiving event
notifications.
Add Kconfig options to enable MAP profile with separate options for
MCE and MSE functions.
Add logging configuration for MAP module.
Signed-off-by: Can Wang <can.wang@nxp.com>
Remove casting of the attr->user_data for short vendor value and
instead directly use the defined `vnd_value`.
Use the same defined max length for the long_vnd functions, instead
of the sizeof operator on one of the arrays.
Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>