Take advantage of the new string conversion helpers to avoid having to
declare explicit on-stack variables.
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Add a helper API to convert inline (on the stack) the peer address of a
connection to a string.
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
The Bluetooth stack has until now had private helpers to return an inline
pointer to a string - something which can be useful e.g. as part of
printk()/printf() call parameters. The reason these were never made public
is that they are not safe when a format string contains more than one
invocation of these.
This commit introduces replacement APIs which allocate an on-stack buffer,
thereby allowing arbitrary number of calls within the parameters of an
output formatting call. The new APIs are defines, since the solution uses
an encapsulating struct to force an on-stack copy, which then requires a
translation to access the struct-internal string member variable.
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
The usage of CHECKIF has been replaced with a regular
if. The reason for this is that higher layer may depend
on some of the checks defined by the API, and the higher
layers cannot do that properly if the checks can be
removed via a Kconfig option.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add a new bt write-eir-name shell command to set the Extended
Inquiry Response (EIR) name for BR/EDR connections.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Add bt_br_write_eir() API to set the extended inquiry response (EIR)
data for BR/EDR device discovery. EIR allows remote devices to
obtain more information during the inquiry process without needing
to establish a connection.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Add an initial assign and check for subgroup == NULL before
calling SYS_SLIST_PEEK_NEXT_CONTAINER as some compilers
consider subgroup otherwise considers it uninitialized:
In function ‘z_snode_next_peek’,
inlined from ‘sys_slist_peek_next_no_check’ at
/__w/zephyr/zephyr/include/zephyr/sys/slist.h:281:1,
inlined from ‘sys_slist_peek_next’ at
/__w/zephyr/zephyr/include/zephyr/sys/slist.h:292:1,
inlined from ‘bt_bap_broadcast_source_reconfig’ at
/__w/zephyr/zephyr/subsys/bluetooth/audio/bap_broadcast_source.c:1008:15:
/__w/zephyr/zephyr/include/zephyr/sys/slist.h:213:20: error:
‘subgroup’ may be used uninitialized [-Werror=maybe-uninitialized]
213 | return node->next;
| ~~~~^~~~~~
/__w/zephyr/zephyr/subsys/bluetooth/audio/bap_broadcast_source.c:
In function ‘bt_bap_broadcast_source_reconfig’:
/__w/zephyr/zephyr/subsys/bluetooth/audio/bap_broadcast_source.c:975:43:
note: ‘subgroup’ was declared here
975 | struct bt_bap_broadcast_subgroup *subgroup;
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Make the codec_cfg 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 codec_cfg
parameter in the stack, rather than static memory.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The pointer represent the codec 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 codec_cfg pointer pointed to the
codec_cfg argument, and sometimes it pointed to the ep->codec_cfg.
Now all codec_cfg arguments are copied to ep->codec_cfg, and
stream->codec_cfg always points to stream->ep.codec_cfg.
This also fixes a bug where metadata updates initiated
by the server was not properly stored by the client.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The function name `avdtp_tx_signal` is misleading as it is used to
transmit single-fragment packets, not specifically signal packets.
Rename it to `avdtp_tx_single` to better reflect its actual purpose
and improve code clarity. Rename `avdtp_tx_frags` as `avdtp_tx_multi`
because AVDTP spec use `multi`.
Signed-off-by: Mark Wang <yichang.wang@nxp.com>
Some resources in MCS were accessed (both read and write) by
multiple threads without any thread protection.
This commit adds a mutex to ensure thread safety.
Since the flags were previously using atomic to
prevent race condition between threads, and since there is
now a mutex, those flags have been modified to be simple
boolean values instead.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add bt_conn_br_set_supervision_timeout() API to configure the
link supervision timeout for a BR/EDR connection via the HCI
Write Link Supervision Timeout command.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Add bt_conn_br_get_supervision_timeout() API to read the current
link supervision timeout value for a BR/EDR connection via the
HCI Read Link Supervision Timeout command.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
NRPA should be rotated every TGAP(private_addr_int)
according to spec, which is also checked in PTS.
Signed-off-by: Artur Dobrynin <artur.dobrynin@nordicsemi.no>
Stop scheduling bt_id_add() as workqueue work during settings load.
Mark keys BT_KEYS_ID_PENDING_ADD only, then flush them synchronously
in start_scan(), adv_start_legacy()/bt_le_ext_adv_start(),
bt_conn_le_create and bt_conn_le_create_auto when
BT_DEV_ID_PENDING is set.
We don't necessarily need to update resolving list in controller
unless actively start using it, also eliminates a race where a
workqueue-issued bt_id_add() blocks on HCI while bt_keys_clear()
concurrently zeroes the same key slot.
Signed-off-by: alperen sener <alperen.sener@nordicsemi.no>
validate the assumptions about buffers returned by alloc_buf() in the
LE CoC receive path.
if the returned buffer does not provide enough user_data space for the
internal segment counter, disconnect and drop the buffer instead of
reading or writing past the metadata area.
also document that alloc_buf() must return a buffer with at least
sizeof(uint16_t) bytes of user_data.
Signed-off-by: Oleh Konko <security@1seal.org>
If `attr` or `attr->user_data` is NULL, then the include
characteristic is invalid. However the function,
bt_gatt_attr_read_included, should not return an errno value, but
a GATT error. The reason why errno cannot be used, is that the
return value is parsed through err_to_att which would make
-EINVAL become 0x16 (depending on the libc implementation),
which is an invalid ATT error code.
This was incorrectly introduced by commit
5a8189bf2a.
Changed the return value from errno to a proper GATT/ATT error.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Update the HW models module to:
63ccab2988bf4c144b3cd324a0277e03206fa413
Including the following:
63ccab2 RADIO: Adjust Tx rampup timings
72d7680 RADIO: Correct note
AND
Adjust Bluetooth controller radio hal timings to match this new timings.
AND
Change the random seed in a very long test which is relatively sensitive
to timing, and fails due to this rampup timing change.
Repeat of note from 63ccab2:
--
IMPORTANT!: This commit changes the timing of the radio model, and
therefore requires controller SW to adjust its constants accordingly.
Even after such an adjustment it is likely some tests timing will change
marginally (if for example some advertisement event anchoring is done
as soon as possible by the controller or the like), and therefore that
some tests execution will change, and that too time sensitive test may
fail.
--
Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
The supported contexts were read but never provided to the
upper layers. Additionally if the supported contexts are
notifible we also subscribe to it.
This commit also fixed some other various things related
to the change to supported contexts.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
If we get a remote request to originate a call via a control
point write, we lookup a TBS instance based on the URI.
However for the local API function bt_tbs_originate we did
not, so the same operation, if the target bearer was GTBS,
had different behavior depending on whether it was locally or
remotely invoked.
This commit makes the two behave the same.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This allows to tune L2CAP RTX timer value for L2CAP connection
requests. Allowed range is 1-60 seconds while defaults to 40.
Since this is mainly useful for BI (behavior invalid) qualification
tests allows to tune it only if BT_TESTING is selected.
This is required for running L2CAP/COS/CED/BI-29-C qualification
test in reasonable time since it requires 255 iterations of
failed (timed out) connection requests.
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
Add missing notification clearing for the GTBS instance
in the disconnected callback.
Fixes#104568
Signed-off-by: Maximilian Zimmermann <gitmz@posteo.de>
If the client removes its subscription to any of the TBS
characteristics at any time, the pending appropriate flags
are now being cleared.
Fixeszephyrproject-rtos/zephyr#104511
Signed-off-by: Hanliang Xu <leonxu2004@outlook.com>
This removes dead code. Since bt_bap_stream_detach sets
stream->ep = NULL then the call to bt_bap_stream_iso_chan_get
will always return NULL since stream->ep is NULL, and thus
the call to bt_bap_stream_disconnect would always be a no-op.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Modify foreach functions in LE Audio to follow the same pattern:
Return true to continue iterating.
Return false to stop iterating.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The usage of CHECKIF has been replaced with a regular
if. The reason for this is that higher layer may depend
on some of the checks defined by the API, and the higher
layers cannot do that properly if the checks can be
removed via a Kconfig option.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The usage of CHECKIF has been replaced with a regular
if. The reason for this is that higher layer may depend
on some of the checks defined by the API, and the higher
layers cannot do that properly if the checks can be
removed via a Kconfig option.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The usage of CHECKIF has been replaced with a regular
if. The reason for this is that higher layer may depend
on some of the checks defined by the API, and the higher
layers cannot do that properly if the checks can be
removed via a Kconfig option.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Use a code spell-checking tool to detect and fix spelling errors in
the files under `subsys/bluetooth`.
Signed-off-by: Pisit Sawangvonganan <pisit@ndrsolution.com>
When reading the value of the vendor attribute, strlen was used instead
of sizeof, causing a unpredictable read size. This commit changes the
implementation to use sizeof instead.
Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
If CONFIG_LOG_TIMESTAMP_64BIT is enabled, then the call to
log_set_timestamp_func in the Bluetooth monitor is type-invalid,
which may fail to build with -Werror.
To avoid this type inconsistency let's use the type `log_timestamp_t`,
which accounts for the correct size, depending on selected config.
Even though the monitoring protocol only seems to support 32b timestamps,
the rest of the module is already based on 64b timestamps, so the
truncation is only done when encoding the timestamp for transmission
to the host in encode_hdr()
Signed-off-by: Titouan Christophe <titouan.christophe@mind.be>
The way that ASCS registers and unregisters for the ASCS
unittests does not work properly with UUIDs and local variables.
Hotfix is to use a `static` backup instead of a stack-allocated
backup. A proper fix will be provided later.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The usage of CHECKIF has been replaced with a regular
if. The reason for this is that higher layer may depend
on some of the checks defined by the API, and the higher
layers cannot do that properly if the checks can be
removed via a Kconfig option.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Add bt_uuid_compress() to compact a 128-bit Bluetooth UUID into its
16-bit or 32-bit short form when it matches the Bluetooth Base UUID.
If the UUID does not match the Base UUID pattern the 128-bit value is
copied unchanged and -ENOTSUP is returned, allowing callers to
distinguish compressible from non-compressible UUIDs.
16-bit and 32-bit source UUIDs are copied as-is.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Implement bt_uuid_from_str() function to convert string representations
to Bluetooth UUID structures. This provides bidirectional conversion
between UUID structures and their string representations, complementing
the existing bt_uuid_to_str() function.
Features:
- Supports 16-bit UUID format (4 hex characters, e.g., "180d")
- Supports 32-bit UUID format (8 hex characters, e.g., "abcdef12")
- Supports 128-bit UUID standard format (with hyphens)
- Comprehensive input validation and error handling
- Automatic UUID type detection based on string length
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Refactor the Bluetooth UUID module to use the generic UUID library
(lib/uuid) instead of hand-rolled byte manipulation.
Changes:
- Replace bt_uuid_128-based base UUID with struct uuid (RFC 9562 order)
- Replace uuid_to_uuid128() with bt_uuid_to_uuid() for BT-to-generic
UUID conversion using proper big-endian / byte-swap operations
- Simplify bt_uuid_to_str() 128-bit case via uuid_to_string()
- Add Kconfig 'select UUID' dependency for BT_HCI_HOST
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
Fix three command handlers that were incorrectly returning the result
of callback functions with void return type:
- avrcp_unit_info_cmd_handler
- avrcp_subunit_info_cmd_handler
- avrcp_pass_through_cmd_handler
Split the callback invocation and return statement to properly handle
the void return type, avoiding potential compiler warnings or errors.
Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
The bt_hci_cmd_create() function was deprecated several releases ago (in
Zephyr 4.2) and can therefore now be removed.
Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
Add a check of the URI scheme length before comparing it
to any instance's supported URI schemes. If the incoming
URI scheme is longer than what we support, then there's
no point in checking if we support it, as we cannot.
Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
The BT_GATT_INCLUDE_SERVICE is always included in
BT_MCS_SERVICE_DEFINITION even when CONFIG_BT_OTS=n,
this fixes it such that it is only included when OTS is enabled.
Fixes zephyrproject-rtos#105345
Signed-off-by: Vedant Malkar <vedantitsme@gmail.com>
When the controller supports BR/EDR and CONFIG_BT_CLASSIC is
enabled, call bt_br_init() to perform the full BR/EDR Classic
initialization (SSP mode, inquiry mode, local name, Class of
Device, etc.).
For non-Classic builds that still need BR/EDR buffer sizes,
gate the hci_read_buffer_size() fallback with
IS_ENABLED(CONFIG_BT_CONN) to make the build-time condition
explicit at the call site.
Signed-off-by: Kai Cheng <chengkai@xiaomi.com>