Commit graph

9787 commits

Author SHA1 Message Date
Mark Wang
0d253c5b45 bluetooth: a2dp: clean few unused codes lines
memset already clean the `buf`, don't need to set as NULL.
`avdtp_set_status` already set `req->status` based on `msg_type`,
don't need to check `msg_type` again.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2025-03-07 19:45:20 +01:00
Mark Wang
935fdd2147 bluetooth: a2dp: improve the readability
add more blank lines before or after the code block {}

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2025-03-07 19:45:20 +01:00
Mark Wang
e531295515 bluetooth: a2dp: optimize bt_a2dp_ep_info
bt_a2dp_ep_info is used in bt_a2dp_discover, and the max
discovered endpoints' info are already given in seps_info
of bt_a2dp_discover_param, so use pointer to point to the
seps_info of bt_a2dp_discover_param.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2025-03-07 19:45:20 +01:00
Mark Wang
8b1b79bf3c bluetooth: avdtp: handle the unsupported signal identifier
reject the cmd if the signal identifier is not supported

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2025-03-07 19:45:20 +01:00
Mark Wang
11c1ccbbc7 bluetooth: avdtp: split packet handler as cmd_handler and rsp_handler
use two handler array to process cmd and response separately,
make the functions shorter and codes more readable.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2025-03-07 19:45:20 +01:00
Mark Wang
1a4de907c8 bluetooth: a2dp: check the invalid avdtp packet
When the packet is invalid, reply the right error code or call
back error code to upper layer.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2025-03-07 19:45:20 +01:00
Vinayak Kariappa Chettimada
ec69ccb681 Bluetooth: Controller: Fix single timer direction finding support
Fix use of single timer software tIFS switching to support
direction finding.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-28 14:55:11 +01:00
Vinayak Kariappa Chettimada
7520742671 Bluetooth: Controller: Fix single timer clear event define name
Rename the single timer clear event define name based on
direction finding support.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-28 14:55:11 +01:00
Vinayak Kariappa Chettimada
23d321d679 Bluetooth: Controller: Fix end time capture be on radio event end
Fix end time capture be on radio event end irrespective of
direction finding support. Let the timer clear use radio
end or radio phy end, for no direction finding or direction
finding support, respectively.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-28 14:55:11 +01:00
Vinayak Kariappa Chettimada
f67a94f47a Bluetooth: Controller: Fix single timer end time capture
Fix single timer use end time capture from being disabled
as end time and timer clear use the same PPI.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-28 14:55:11 +01:00
Vinayak Kariappa Chettimada
65d69ec176 Bluetooth: Controller: Fix active mode extended scanning assert
Fix active mode extended scanning assert raised when calling
radio_tmr_start_us() due to stale radio_tmr_end_get() value.
Active mode extended scanning did not drop reception of
ADV_EXT_IND PDU when setup to receive ADV_SCAN_RSP PDUs.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-28 14:55:11 +01:00
Vinayak Kariappa Chettimada
3a996c570b Bluetooth: Controller: Fix BT_CTLR_LOW_LAT_ULL dependency
Fix BT_CTLR_LOW_LAT_ULL dependency after changes in
commit 5119896c7d ("Bluetooth: Controller: Fix
BT_CTLR_LOW_LAT_ULL conditional code").

BT_CTLR_LOW_LAT_ULL is independent of BT_CTLR_LOW_LAT, where
the later prevents any ULL execution inside a radio event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-28 14:53:27 +01:00
Kyra Lengfeld
6464ffa3f9 Bluetooth: Host: Fix deadlock when failing to alloc on BT RX thread
This commit alignes the timeout value for allocating buffers within att
on the BT RX thread, making it consistent within att.c, see
bt_att_req_alloc.

We are inferring in many bt_gatt_* functions that if called from a BT RX
thread (which is inherently the case if called from a callback when
running a Bluetooth application), we don't block and instead return
-ENOMEM when the ATT request queue is full, avoiding a deadlock.
This promise is fulfilled within bt_att_req_alloc, where the timeout for
allocation of the request slab is set to K_NO_WAIT if we are on the BT
RX thread. Unfortunately, we break this promise in
bt_att_chan_create_pdu, where the timeout for allocation of the att pool
is still K_FOREVER and deadlocks can (and do) occur when too many
requests are sent yet the pool is depleted.

Note: Both req_slab and att_pool sizes are defined by
CONFIG_BT_ATT_TX_COUNT. If applications start getting -ENOMEM with this
change, they were at risk of such a deadlock, and may increase
CONFIG_BT_ATT_TX_COUNT to allocate the att pool for their requests.

Note: This possible deadlock has been flying under the radar, as
att_pools are freed when the HCI driver has sent it to the controller
(instead of when receiving the response, as it happens with req_slabs)
and due to the att_pool and the req_slab being both sized by
CONFIG_BT_ATT_TX_COUNT, and req_slab being allocated before and
returning -ENOMEM already if there is no space, it takes a more specific
situation to deplete the att_pool but not the req_slab pool at this
point.

Note: Ideally, we don't want functions to behave differently depending
on which thread they are running, and while this commit makes it more
consistent, it should be considered a workaround solution.

Signed-off-by: Kyra Lengfeld <kyra.lengfeld@nordicsemi.no>
2025-02-28 10:10:01 +01:00
Johan Hedberg
05b16b971b Bluetoth: Host: Fix buffer allocation warnings in system workqueue
The buffer allocation in conn.c will trigger warnings if we try to use
anything else than K_NO_WAIT for the timeout when called from within the
system workqueue.

The calls in l2cap.c and att.c which may pass non-zero timeouts already
have proper handling for failed allocations, so make sure we use K_NO_WAIT
to avoid unnecessary warnings from conn.c.

Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
2025-02-25 15:14:08 +00:00
Vinayak Kariappa Chettimada
17d695a535 Bluetooth: Controller: Simplify required ISO PDU length and buffer count
Simplify the defines calculating the minimum required ISO
PDU length and the buffer count.

Co-authored-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-24 20:18:37 +00:00
Vinayak Kariappa Chettimada
662acab1ae Bluetooth: Controller: Fix ISO Tx PDU buffer counts for fragmentation
Fix ISO Tx PDU buffer count required when SDU fragmentation
is used.

Rename BT_CTLR_CONN_ISO_SDU_LEN_MAX to
BT_CTLR_ISO_TX_SDU_LEN_MAX so the value is common to both
Broadcast and Connected ISO transmissions.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-24 20:18:37 +00:00
Vinayak Kariappa Chettimada
4161db72cd Bluetooth: Controller: Rename to BT_CTLR_ISO_TX_PDU_BUFFERS
Rename the internal BT_CTLR_ISO_TX_BUFFERS to
BT_CTLR_ISO_TX_PDU_BUFFERS correct represent the number
of actual ISO PDU buffers allocated in the Controller.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-24 20:18:37 +00:00
Yago Fontoura do Rosario
ee8266797c bluetooth: id: Fix logging
* Logging module already adds a new line, no need to add it

Signed-off-by: Yago Fontoura do Rosario <yafo@demant.com>
2025-02-24 15:37:41 +00:00
Yago Fontoura do Rosario
f0af67afa0 bluetooth: id: Fix uninitialized variable
* This variable default value has to be true, so that the
application can return false in the expired callback

Signed-off-by: Yago Fontoura do Rosario <yafo@demant.com>
2025-02-24 15:37:41 +00:00
Luis Ubieda
f1be8afc46 bluetooth: Guard gatt_prepare_write against calls while disconnected
Fixes #84752.

Signed-off-by: Luis Ubieda <luisf@croxel.com>
2025-02-24 15:37:18 +00:00
Ludvig Jordet
0460c9fdae Bluetooth: Mesh: Update Kconfig help about Mesh on System WQ
This updates the help text for the Kconfig option BT_MESH_WORKQ_SYS to
take into account the change made in PR #84282 which causes the host to
no longer return -ENOBUFS. Since the mesh will now instead block the
work queue, a note has been added about a potential consequence of this.

Signed-off-by: Ludvig Jordet <ludvig.jordet@nordicsemi.no>
2025-02-21 18:02:50 +00:00
Vinayak Kariappa Chettimada
d382fca6ff Bluetooth: Controller: Fix HCI command buffer allocation failure
Fix HCI command buffer allocation failure, that can cause
loss of Host Number of Completed Packets command.

Fail by rejecting the HCI Host Buffer Size command if the
required number of HCI command buffers are not allocated in
the Controller implementation.

When Controller to Host data flow control is supported in
the Controller only build, ensure that BT_BUF_CMD_TX_COUNT
is greater than or equal to (BT_BUF_RX_COUNT + Ncmd),
where Ncmd is supported maximum Num_HCI_Command_Packets in
the Controller implementation.

Relates to commit 81614307e9 ("Bluetooth: Add workaround
for no command buffer available")'.

Relates to commit 297f4f481f ("Bluetooth: Split HCI
command & event buffers to two pools").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-21 11:30:38 +00:00
Vinayak Kariappa Chettimada
cc1b53445c Bluetooth: Host: Remove nested allocation of HCI command buffer
Remove nested allocation of HCI command buffer so that one
less HCI command buffer is needed starting extended
advertising with privacy enabled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-21 11:30:38 +00:00
Jens Rehhoff Thomsen
c44334374e Bluetooth: host: Fix bug in scan start
When scanning is started on bt_bap_broadcast_assistant_scan_start then
BAP_BA_FLAG_SCANNING flag for the broadcast assistant instance should
not be cleared.

Fixes #85937

Signed-off-by: Jens Rehhoff Thomsen <jthm@demant.com>
2025-02-20 14:55:56 +00:00
Zihao Gao
7e18f8060a Bluetooth: Shell: fix assert when print address.
This patch fix the assertion caused by null address pointer
that occurs when BR/EDR pairing completed.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-02-20 11:47:39 +01:00
Pavel Vasilyev
9757ffa5fa bluetooth: host: smp: fix deadlock when public key generation fails
When `bt_le_oob_get_local` or `bt_le_ext_adv_oob_get_local` is called
and SMP is enabled, `bt_smp_le_oob_generate_sc_data` is called to
generate a Random Number and a Confirmation Value needed for OOB data.
These values are based on the device's public key.

The public key is generated only once when `bt_smp_init` is called.
If public key generation fails, the callback passed to `bt_pub_key_get`
is called with `pkey` set to NULL. The `bt_smp_pkey_ready` callback
gets called, but it doesn't release the `sc_local_pkey_ready` semaphore
thus leaving `bt_smp_le_oob_generate_sc_data` wait for semaphore with
`K_FOREVER`.

This commit replaces the semaphore with a conditional variable and
requests a public key again if the key is NULL thus solving 2 issues:
- handling the case where the callback was triggered notifying about the
  completion of the public key request, but the key was not generated,
- handling the case where multiple threads trying to acquire the same
  sempahore.

The timeout is used instead of K_FOREVER to avoid cases when callback
has never been triggered.

Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
2025-02-18 18:44:23 +01:00
Lyle Zhu
3f81e81598 Bluetooth: AVDTP: Fix memory leak issue
In function `avdtp_send`, there is case that if the session->req is not
NULL, then the buf will be lost.

Release the allocated buffer by buffer allocated function when the buf
is failed to send.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-02-18 13:30:53 +01:00
Emil Gydesen
1280f432f4 Bluetooth: ASCS: Missing cleanup of stream for idle state
When the stream enters the idle state, some values were not
properly reset (e.g. the stream->ep).

Use the bt_bap_stream_detach function to clean up the stream.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-17 21:16:10 +01:00
Vinayak Kariappa Chettimada
dcdd330895 Bluetooth: Controller: Fix redundant reset of sync aux association
Remove redundant reset of LLL sync aux context association.

Related to commit 3263729020 ("Bluetooth: Controller: Fix
assertion terminating Periodic Sync").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-17 15:47:36 +00:00
Vinayak Kariappa Chettimada
49642efa41 Bluetooth: Controller: Fix regression in scan aux release
Fix regression in scan aux release now that aux context is
retrieved from the node rx when supporting multiple chain
reception.

Relates to commit a8065926ac ("Bluetooth: Controller: Fix
to release aux context stored in node rx").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-17 15:47:36 +00:00
Aleksandr Khromykh
acc752fce4 Bluetooth: Mesh: remove weak attribute and rename functions
Commit removes weak attribute and renames some functions
in crypto_psa.c since there is no centralized distribution
of the PSA key ID in bsim tests and no necessity to
reimplement native mesh approach.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2025-02-17 08:09:28 +01:00
Emil Gydesen
94d5d59be7 Bluetooth: AICS: Fix check for BT_AICS_INPUT_TYPE
The check did not take the highest value into account.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-15 07:23:37 +01:00
Emil Gydesen
907261b619 Bluetooth: BAP: Remove GATT_CACHING req for unicast server
The unicast server does not need GATT caching and it was likely
incorrectly added earlier as a dependency.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-14 19:15:57 +00:00
Emil Gydesen
9eaf232b57 Bluetooth: BAP: Fix notifications for scan delegator
Instead of providing NULL for bt_gatt_notify_uuid we
iterate on the connection objects and ensure that we
properly truncate the notification based on each
connection's GATT MTU.

This ensures that we send the right size for all
connections.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-14 19:15:42 +00:00
Emil Gydesen
7bcd1e78de Bluetooth: Audio: Add common bt_audio_get_max_ntf_size
Add a common function to get the maximum notification
size, instead of having multiple implementations of this.
Ideally this function should be moved to the GATT API,
but for now just implement it for LE audio and then move to
GATT later.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-14 19:15:42 +00:00
Emil Gydesen
317cc9d52e Bluetooth: CCP: Add missing documentation for CCP discover
Added missing documentation for
bt_ccp_call_control_client_discover.

Added missing handling of -ENOTCONN in the function as well.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-14 19:15:31 +00:00
Lyle Zhu
50a3a6ec7c Bluetooth: SDP: Check if frame len is consistent with attr list count
The total attributes list bytes count is only used to check the tail
room of response buffer. And the remaining frame length is used to
copy data from receiving buffer.

It does not check whether the remaining frame length is consistent with
the total attributes list bytes count.

Add the checking to make sure the attributes list is complete. And it
is used to make sure the response buffer can be accessed safety.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-02-14 19:15:02 +00:00
Zihao Gao
53bba45281 Bluetooth: AVRCP: implementation for passthrough commands
This patch alllows to send passthough command from CT to TG.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-02-14 17:13:23 +01:00
alperen sener
3fdb81cd1f bluetooth: mesh: Correct callback check mesh blob client
xfer_progress_complete should be checked instead of end callback

Signed-off-by: alperen sener <alperen.sener@nordicsemi.no>
2025-02-14 17:10:39 +01:00
Thomas Deppe
dcbcbe824d Bluetooth: Host: Add host support for Advertising Coding Selection
Extends the API for Advertising Coding Selection.

The API is extended to set the Advertising Coding Selection
(Host Support) bit. With this feature, the primary and
secondary PHY can now explicitly report S=2 or S=8 coding
in the extended advertising report. Previously, the report
only indicated LE Coded regardless of whether S=2 or S=8
data coding was used. The API now sets the host support bit
and ensures that the advertising PHY coding scheme is
conveyed to the application via the scan callback.

The support is enabled by CONFIG_BT_EXT_ADV_CODING_SELECTION,
and requires a controller that selects
CONFIG_BT_CTLR_ADV_EXT_CODING_SELECTION_SUPPORT.

Signed-off-by: Thomas Deppe <thomas.deppe@nordicsemi.no>
2025-02-14 17:08:23 +01:00
Emil Gydesen
fe6f63f92d Bluetooth: PACS: Add missing break in switch for sup ctx get
Add a missing break in supported_context_get, as it was not
intended to fallthrough to BT_AUDIO_DIR_SOURCE or default.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-14 17:05:47 +01:00
Tomi Fontanilles
0c368e85b1 secure_storage: add a global registry header file for PSA key IDs
We need to make sure that within Zephyr different users of the PSA APIs
don't interfere with each other because of using the same numerical IDs
for persistent assets.

This takes care of the PSA key IDs when using persistent keys through
the PSA Crypto API.
See the comments in `<zephyr/psa/key_ids.h>` for more information.

This removes the recently-introduced Kconfig options that allowed changing
the base IDs subsystems were using for their persistent keys.

Signed-off-by: Tomi Fontanilles <tomi.fontanilles@nordicsemi.no>
2025-02-13 20:22:09 +01:00
Kamil Piszczek
7c828bd232 bluetooth: dis: add Kconfig for disabling optional characteristics
Added new Kconfig option set that allows the user to control the
presence of the following optional characteristics:

- Manufacturer Name String
- Model Number String

Depreacted the old configuration that can be deleted in the future
Zephyr releases.

Signed-off-by: Kamil Piszczek <Kamil.Piszczek@nordicsemi.no>
2025-02-13 16:46:12 +01:00
Make Shi
f8ebbb3fef Bluetooth: AVCTP: Implement the functionality of avctp_l2cap_accept
- Implement the functionality of avctp_l2cap_accept to accept an L2CAP
  connection for the AVCTP protocol.

Signed-off-by: Make Shi <make.shi@nxp.com>
2025-02-13 12:16:30 +01:00
Marek Pieta
c7f3ad6307 bluetooth: host: Allow for ECDH operations through system workq
Change allows performing ECDH operations through system workq. This is
done to allow reducing memory consumption by disabling the long workq on
small SoCs.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2025-02-12 20:26:28 +01:00
Ingar Kulbrandstad
45f233ba61 Bluetooth: Mesh: Remove experimental TF-M PSA
Remove the experimental flag from BT_MESH_USES_TFM_PSA.

Signed-off-by: Ingar Kulbrandstad <ingar.kulbrandstad@nordicsemi.no>
2025-02-12 20:18:16 +01:00
Vinayak Kariappa Chettimada
a8065926ac Bluetooth: Controller: Fix to release aux context stored in node rx
Fix to release aux context stored in node rx, and not in the
superior scan or sync context as the one in the superior scan
or sync context could be reset or have a different new aux
context when multiple advertising chain reception is used.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-12 12:24:52 +01:00
Vinayak Kariappa Chettimada
3263729020 Bluetooth: Controller: Fix assertion terminating Periodic Sync
Fix assertion due to changes introduced to support multiple
advertising chain reception.

Auxiliary context association with the Periodic Sync context
was not cleared due to which when terminating a Periodic
Synchronization triggered an assertion check, under race
conditions, detecting that the auxiliary context was already
released.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-12 12:24:52 +01:00
Vinayak Kariappa Chettimada
2461552e19 Bluetooth: Controller: Fix Periodic Sync for multiple chain reception
Fix regression introduced in Periodic Advertising
Synchronization due to change related to multiple
Advertising chain reception.

Related commit c334ed515b ("Bluetooth: Controller: Fix
multiple Extended Adv chain reception"), and
commit da792a9e17 ("Bluetooth: Controller: Fix interleaved
extended scanning assert").

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-02-12 12:24:52 +01:00
Emil Gydesen
571f26cf1a Bluetooth: Rename BLE to Bluetooth (LE) where applicable
The BLE acronym is not an official description of Bluetooth
LE, and the Bluetooth SIG only ever refers to it as Bluetooth
Low Energy or Bluetooth LE, so Zephyr should as well.

This commit does not change any board or vendor specific
documentation, and the term BLE may still be used in those.
It will be up to the vendors to update it if they want,
since many of them are using the term BLE in their
products.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-02-12 12:24:18 +01:00