Commit graph

9787 commits

Author SHA1 Message Date
Lyle Zhu
0dfae64699 Bluetooth: OBEX: Check if the added string is valid
There are types of string can be added by using OBEX adding header
function bt_obex_add_header_*(). One is byte sequence. Another is null
terminated Unicode text.

Add a function bt_obex_string_is_valid() to check if the added string
is valid. And add a function bt_obex_unicode_is_valid() dedicated to
check Unicode string.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-08-08 10:43:07 -05:00
Lyle Zhu
ccad303d50 Bluetooth: shell: Add OBEX commands for GOEP
Add commands for GOEP to test OBEX features.

Add command `alloc-buf` and `release-buf` to allocate and release TX
buffer.

Add command set `add-header` to add the OBEX headers to allocated TX
buffer.

Add command set `client` to send OBEX client requests with allocated
TX buffer.

Add command set `server` to send OBEX responses with allocated TX
buffer.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-08-08 10:43:07 -05:00
Lyle Zhu
8d1b3e9111 Bluetooth: shell: Add transport commands for GOEP
Add commands for GOEP to test transport features.

Add commands for transport over RFCOMM, including `register-rfcomm`,
`connect-rfcomm`, and `disconnect-rfcomm`.

Add commands for transport over L2CAP, including `register-l2cap`,
`connect-l2cap`, and `disconnect-l2cap`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-08-08 10:43:07 -05:00
Lyle Zhu
bfd42f5c80 Bluetooth: GOEP: Improve the MTU configuration
The MTU of the GOEP should be not less than 255. So, if the transport
is RFCOMM, the CONFIG_BT_BUF_ACL_RX_SIZE should be not less than 264.
It includes,
- 255 bytes for the minimum MTU of GOEP,
- 4 bytes for L2CAP Header,
- 5 bytes for RFCOMM header and FCS.

And if the transport is L2CAP, the CONFIG_BT_BUF_ACL_RX_SIZE should
be not less than 259.
It includes,
- 255 bytes for the minimum MTU of GOEP,
- 4 bytes for L2CAP Header.

Add Kconfig `BT_GOEP_RFCOMM_MTU` to configure the maximum size for
RFCOMM transport. The range of `BT_GOEP_RFCOMM_MTU` is
`[264, BT_RFCOMM_L2CAP_MTU]`. And the GOEP MTU via RFCOMM transport
should be in the range `[255, (BT_GOEP_RFCOMM_MTU-9)]`.

Add Kconfig `BT_GOEP_L2CAP_MTU` to configure the maximum size for
L2CAP transport. The range of `BT_GOEP_L2CAP_MTU` is
`[259, BT_BUF_ACL_RX_SIZE]`. And the GOEP MTU via L2CAP transport
should be in the range `[255, (BT_GOEP_L2CAP_MTU-4)]`.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-08-08 10:43:07 -05:00
Lyle Zhu
3d91b89ed0 Bluetooth: GOEP: Enable GOEP feature
Add a Kconfig BT_GOEP to control the GOEP feature.

Implement the GOEP protocol and transport, both for GOEP 1.1 and GOEP
2.x.

For GOEP transport, OBEX over RFCOMM, and OBEX over L2CAP are
supported.

For GOEP protocol, `put`, `get`, `abort`, `setpath`, and `action` are
supported. And only one operation can be processed at the same time.
The feature `Reliable Session` is unsupported.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-08-08 10:43:07 -05:00
Håvard Reierstad
f231c5f070 Bluetooth: Host: Add req/rsp l2cap validation
L2CAP channels will now, along with the ident, store the opcode of the
pending request. This commit expands the ident lookup function to also
compare received response types to this opcode, and will ignore
unsolicited responses.

Setting of idents for channels are moved after verification of buffer
allocation for the request to be sent. A TODO is added for improving
this functionality at a later time.

Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
2025-08-08 11:53:43 +03:00
Tyler Joseph Huffman
e57dd8e12d Bluetooth: Controller: Adds path loss monitoring functionality
This functionality is implemented in the HCI-facing side of the
controller and the ULL. LLL functionality is not implemented in this
commit.

Furthermore, this removes a dependency for LE Power Control, as the
features are related, but not necessarily required.

Signed-off-by: Tyler Joseph Huffman <tyhu@demant.com>
2025-08-08 11:52:03 +03:00
Emil Gydesen
b0f1eb30fb Bluetooth: AICS: Remove bad check in handle_set_gain_op
AICS gain mode does not prevent local nor remote operations from changing
the gain setting value. The gain setting value shall simply be ignored if
in the BT_AICS_MODE_AUTO_ONLY or BT_AICS_MODE_AUTO modes, but the local
application and remote devices can still modify the gain setting value.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-08-06 17:12:27 +03:00
Sean Madigan
1b7b6af785 bluetooth: host: add frame space update support
This commit adds support for the frame space update feature
to the bluetooth host.

This is mainly just a wrapper around the frame space update
HCI command and event.

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
2025-08-06 17:11:04 +03:00
Sean Madigan
9bbc906b30 bluetooth: host: Fix BT_LE_LOCAL_SUPPORTED_FEATURES_SIZE define
Fix BT_LE_LOCAL_SUPPORTED_FEATURES_SIZE define, as this was
not working correctly without brackets around
CONFIG_BT_LE_MAX_LOCAL_SUPPORTED_FEATURE_PAGE.

Also fix CONFIG_BT_LE_MAX_LOCAL_SUPPORTED_FEATURE_PAGE help,
as this was talking about remote featues, where this only
applies for local features.

Also update for new CONFIG_BT_CONN_DYNAMIC_CALLBACKS kconfig

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
2025-08-06 17:11:04 +03:00
Emil Gydesen
eef2aa88b3 Bluetooth: CTS: Fix issue with writing without subscription
The write_ct function calls bt_cts_send_notification and if
bt_cts_send_notification fails to send a notification (e.g.
if there are no clients subscribed), it would return an
error, and thus send a ATT error response to the client,
even if the value was actually written.

This commit changes the behavior so that the notification
does not affect the return value (as it is not directly
linked to the write itself), but rather just logs it if
it fails to send the notification.

The notification can failed to be send for 2 main reasons:
1) The application returns an error on fill_current_cts_time
2) bt_gatt_notify fails to notify due to missing buffers

The first we cannot do much about. For the latter we can
either just live with the missing notification, or implement
a retry if we run out of buffers. For this simple fix the
former was chosen, but can be revisited if it turns out
to be a significant problem.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-08-06 12:12:07 +03:00
Emil Gydesen
8e5e9922c5 Bluetooth: ISO: Fix sonarcloud issues in valid_chan_qos
Fixes some sonarcloud issues relating to the if statements.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-08-05 13:37:13 -04:00
Emil Gydesen
3a963e5286 Bluetooth: ISO: Remove check for SDU size
Since the SDUs are now allocated by the application
and the host does not care about the SDU sizes, the check
is useless.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-08-05 13:37:13 -04:00
Yago Fontoura do Rosario
ca06a1d80d Bluetooth: Add configuration to control the dynamic connection callbacks
This commit allows to the user to control the use or not of dynamic
connection callbacks.
The stack is not using the dynamic connection callbacks so they are
only needed if the applications want to use it.
Setting it to true for backwards compatibility.

With dynamic connection callbacks

           FLASH:      176600 B       512 KB     33.68%
             RAM:       27428 B        64 KB     41.85%
        IDT_LIST:          0 GB        32 KB      0.00%

Without dynamic connection callbacks

           FLASH:      176376 B       512 KB     33.64%
             RAM:       27428 B        64 KB     41.85%
        IDT_LIST:          0 GB        32 KB      0.00%

Signed-off-by: Yago Fontoura do Rosario <yafo@demant.com>
2025-08-05 13:28:06 -04:00
Yago Fontoura do Rosario
e0d22a308e Bluetooth: Host: Conn callbacks registration with BT_CONN_CB_DEFINE
This commit registers the connection callbacks using BT_CONN_CB_DEFINE,
which ensures they are set up at link time rather than runtime.

Signed-off-by: Yago Fontoura do Rosario <yafo@demant.com>
2025-08-05 13:28:06 -04:00
Yago Fontoura do Rosario
b1eaf02ec1 Bluetooth: Audio: Conn callbacks registration with BT_CONN_CB_DEFINE
This commit registers the connection callbacks using BT_CONN_CB_DEFINE,
which ensures they are set up at link time rather than runtime.

Signed-off-by: Yago Fontoura do Rosario <yafo@demant.com>
2025-08-05 13:28:06 -04:00
Vinayak Kariappa Chettimada
c8d4016e04 Bluetooth: Controller: Fix minimal Kconfig depends and defaults
Fix default value of BT_TICKER_REMAINDER_GET, it will be
selected based on enabled Controller features. This is not
needed by minimal peripheral role.

Fix depends on for BT_CTLR_CONN_RANDOM_FORCE as it is
applicable when more than one simultaneous connections is
supported. Again, this is not needed by minimal peripheral
role.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-08-04 17:02:19 -04:00
Mark Wang
f19e7983d0 bluetooth: remove the unnecessary macro wrapper in header files
It eliminates the possibility of using IS_ENABLE(), so it is better to
remove them.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2025-08-04 19:57:30 +01:00
Håvard Reierstad
7debc8a8f5 Bluetooth: Host: Add conn rsp param check
Check whether the connection response parameters both with and without
ECRED are within the valid ranges from the Bluetooth Core Specification
(part 3.A.4 v6.0). Changes validation checks in requests to match the
same pattern.

Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
2025-08-04 11:52:01 +01:00
Emil Gydesen
8788f8ba26 Bluetooth: BAP: Add target latency and phy to codec_cfg
The codec configuration operation for unicast (ASCS) contain
both a target PHY and a target latency value that was previously
just hardcoded by the client and unavailable by the server.

This commit adds them to the bt_audio_codec_cfg struct so that
applications can both set and get these values.

The default values used by BT_AUDIO_CODEC_CFG use the same
values as the client would previously set.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-08-01 19:37:31 +01:00
Håvard Reierstad
2b42a1d81d Bluetooth: Host: Add l2cap credit param checks
Adds a missing requirement from Core Spec V6.0 Vol 3.A chapters 10.1
and 10.2 to ignore L2CAP_FLOW_CONTROL_CREDIT_IND packets with the
credit value set to 0.

Matches existing credit-related functions by checking that the CID
is in the dynamic range (you can't add credits to fixed channels).

Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
2025-08-01 12:20:43 -04:00
Emil Gydesen
b76f09dc04 Bluetooth: ISO: Fix issue with BIS tx_complete
BIS termination as broadcaster is handled different
than ACL and CIS, and in rare chances the
tx_complete for BIS may not have been completed in
the system workqueue before iso_new was called for the
same bt_conn struct (e.g. via bt_iso_cig_create), which
would perform

k_work_init(&conn->tx_complete_work, tx_complete_work);

but where conn->tx_complete_work still existed in
the system workqueue, which would cause the list
of pending items on the system workqueue to be removed
as the `next` pointer would be NULL.

This also adds an assert in bt_conn_new to prevent this
issue from appearing again.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-07-31 17:14:21 -04:00
Jonas Spinner
91ec38d7e0 Bluetooth: Classic: SDP: Replace magic numbers
Replace magic UUID sizes with `sizeof(uint8_t) +
BT_UUID_SIZE_{16,32,128}`.

Signed-off-by: Jonas Spinner <jonas.spinner@burkert.com>
2025-07-31 17:10:57 -04:00
Flavio Ceolin
56e2b01e53 bt: controller: Use proper flexible array
0 length array is a GNU extension. Use proper C99 flexible
array.

Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
2025-07-31 10:52:49 +01:00
Flavio Ceolin
4ae867b12d bt: audio: Use proper flexible array
0 length array is a GNU extension. Use proper C99 flexible
array.

Signed-off-by: Flavio Ceolin <flavio@hubblenetwork.com>
2025-07-31 10:52:49 +01:00
Flavio Ceolin
805701da49 bt: host: Use proper flexible array
0 length array is a GNU extension. Use proper C99 flexible
array.

Signed-off-by: Flavio Ceolin <flavio.ceolin@gmail.com>
2025-07-31 10:52:49 +01:00
Yago Fontoura do Rosario
d3cc63ac71 Bluetooth: PACS: Fix duplicated entries in client list
The client list is filled from the bonding table at registration
but this should only be done once like the callback registration

Signed-off-by: Yago Fontoura do Rosario <yafo@demant.com>
2025-07-29 11:21:58 +01:00
Lyle Zhu
af42036ca6 Bluetooth: Classic: SDP: Improve UUID 128 support
In current implementation, the UUID 128 is not well supported. The
found issue includes,
Issue 1: No clear byte order of the UUID 128 in local SDP record.
Issue 2: No clear byte order of the UUID 128 of the SDP discover
parameter.

For issue 1,
Add the description to note that if the SDP attribute type is
`BT_SDP_UINT128`, `BT_SDP_INT128`, and `BT_SDP_UUID128`, the byte
order should be little-endian.

And swap the 128bit from little-endian to big-endian when responding
the peer SDP discovery request.

For issue 2,
Add the description to note that if the SDP discovery type is
`Service Search` and `Service Search Attribute`, and UUID is UUID 128,
the passed UUID data of the discovery request parameter should be
represented as the little-endian byte-order sequence.

And swap the 128bit from little-endian to big-endian when packing the
SDP discovery packet.

Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
2025-07-29 11:21:37 +01:00
Emil Gydesen
220571efcb Bluetooth: CCP: Check conn type before access by index
Ensure that the connection type of the provided bt_conn is
an LE connection.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-07-28 16:45:17 -04:00
Emil Gydesen
0347d92072 Bluetooth: BAP: SD: Add missing error checks for mutex locks
Add missing error checks for mutex locks after the mutexes
were changed to not use K_FOREVER which should not be done in
the BT RX thread.

A larger overhaul of how mutexes are using within the scan delegator
should be considered, as there are a lot of locks and unlocks when
handling the callbacks.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
2025-07-28 16:44:58 -04:00
Cheng Chang
afcce53220 bluetooth: host: a2dp:error_code should be detailed in set_config_rsp
Error codes fall into two main categories:
case 1: NOT_SUPPORT_XXX. This means that the configuration of the
parameter is not supported locally.
case 2: INVALID_XXX. This means that the parameter is not configured or
duplicated in the set_config_req command.

Currently the protocol only supports SBC, so it is only checked for SBC
parameters.

Signed-off-by: Cheng Chang <cheng.chang@nxp.com>
2025-07-28 16:43:29 -04:00
Cheng Chang
f4153476cd bluetooth: host: a2dp: Fix null ops before calling configured callback
If stream->ops is NULL and not checked, it works fail.

Signed-off-by: Cheng Chang <cheng.chang@nxp.com>
2025-07-28 16:40:39 -04:00
Cheng Kai
cf61573ce9 Bluetooth: L2CAP: add br l2cap unregister interface
It needs to do l2cap unregister operation from app

Signed-off-by: Cheng Kai <chengkai@xiaomi.com>
2025-07-28 08:52:01 -04:00
Sean Madigan
3adae8bd9a bluetooth: host: Add support for extended feature set feature
This commit adds support for the extended feature set
feature. This includes:
- hci boilerplate
- kconfigs, including one for a max local feature page
- reading remote features is done by a command and callback
- this is not linked into the auto feature request on
connection as this procedure can take quite a few connection
events, and we do not want to delay the user
- added the commands to the bt shell

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
2025-07-28 08:48:30 -04:00
Sean Madigan
cddea431eb bluetooth: host: hci_core: allow both orders of version and feature events
Previously, the version complete event had to come after
the remote feature complete event for the notify_remote_info
function to be called.

This becomes less practical when adding the read all remote
features complete event, as this can take some time. Meaning
the order of events is not predictable.

Signed-off-by: Sean Madigan <sean.madigan@nordicsemi.no>
2025-07-28 08:48:30 -04:00
Vinayak Kariappa Chettimada
5b1c209498 Bluetooth: Controller: Add missing atomic_get call
Add missing atomic_get call to access atomic value.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-07-28 08:45:59 -04:00
Vinayak Kariappa Chettimada
0a2934d1d2 Bluetooth: Controller: Fix assertion in ull_conn on HCI Reset
Fix assertion in ull_conn under race between connection
termination and processing of HCI Reset command.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-07-28 08:45:47 -04:00
Vinayak Kariappa Chettimada
e1541cc712 Bluetooth: Controller: Fix ULL Tx Ack index corruption under race
Fix ULL Tx Ack FIFO's first index being advanced beyond a
recorded ack_last value in a node_rx when under race.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-07-28 08:45:33 -04:00
Aleksandr Khromykh
c02ec1f645 bluetooth: mesh: remove persisted psa key if mesh does not own it
Commit adds destruction of the persisted in PSA ITS key if
mesh does not own it (zero bit in the bitmap of persisted keys).

This is not standard mesh behavior, but might happen
if something happens between removing key data in mesh and
in the crypto library (for example power off in bettwen).

Previously, mesh wasn't able to import key with gotten stuck
key id. The current fix reproduces more robust behavior.

Signed-off-by: Aleksandr Khromykh <aleksandr.khromykh@nordicsemi.no>
2025-07-25 08:17:24 -04:00
Omkar Kulkarni
602fd0d889 Bluetooth: Mesh: Blob Server considers friendship
Fix Max Chunk reporting during Block_Information_Get:
If friendship is established, then max possible chunk size for transfer
is reported according to friend's queue size.

ChunkSize = (FndQ sz * Bytes per seg (12)) - Opcode(1) - Chunk_Num (2)-
            8 byte MIC (max)
	  = (FndQ sz * 12) - 11

This allows all segments of Chunk_Transfer messages to fit in a friend
queue. If this is not done, friend queue keeps overflowing
systematically causing unstable PULL_MODE transfers.

Fix Chunk requests:
Adapt number of requested chunks according to current friend queue size.
If friend queue is too small, at least 1 chunk is requested.

Signed-off-by: Omkar Kulkarni <omkar.kulkarni@nordicsemi.no>
2025-07-25 08:14:26 -04:00
Vinayak Kariappa Chettimada
ede31d39f0 Bluetooth: Controller: Fix assertion using BT_CTLR_LOW_LAT_ULL_DONE
BT_CTLR_LOW_LAT_ULL_DONE is used to reduce CPU usage in LLL
context by delegating the done event dequeue to ULL_HIGH
context.

Building a HCI Controller with BT_CTLR_LOW_LAT_ULL_DONE had
assertion when used with BlueZ stack.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-07-21 13:04:44 -04:00
Vinayak Kariappa Chettimada
cebaad33b1 Bluetooth: Controller: Fix missing ticker force reset on being lazy
Fix missing ticker force reset when the ticker expiry was
skipped or rescheduled.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-07-21 13:04:36 -04:00
Vinayak Kariappa Chettimada
0ad4d86354 Bluetooth: Controller: Fix flash sync start from starving connection
Fix flash sync start from repeatedly forcing connection
event be skipped. Space new flash operation to be placed
in the past so that it does not force itself on to an
overlapping connection event.

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-07-21 13:04:36 -04:00
Cheng Chang
c9651c6710 Bluetooth: host: a2dp: Fix stream recv callback not be checked
Now when role is sink and source sends data, stream recv callback is
not registered, apps works fail. so stream recv callback should be
checked.

Signed-off-by: Cheng Chang <cheng.chang@nxp.com>
2025-07-21 07:23:15 -04:00
Nirav Agrawal
b59d8d56bf bluetooth: bap_unicast_client: fix PTS BAP/UCL/SCC/BV-103-C failure
- In bap_unicast_client, it was assumed that ASE is binded with CIS
 handler during sending "received_stop_ready" to unicast_server.
- In case where unicast_client has not started the stream with
 "receiver_start_ready" att command to server, but wants to disable
 ASE which was Enabled previously (but not stream!) causes failure
 since there is no cis_create has happened and linked to ASE.
- In BAP_TS, "BAP/UCL/SCC/BV-103-C" has a same test conditions where
 client first enables the ASE, disable the ASE, and expecting
 "receiver_stop_ready" att command from client to server followed by
 server notification to enter its ASE in QoS_configured state.
- Removed this condition checks to send expected att command to
 server from Enabling ASE state to Disable ASE.

Signed-off-by: Nirav Agrawal <nirav.agrawal@nxp.com>
2025-07-20 12:24:43 -04:00
Vinayak Kariappa Chettimada
e3e410aeed Bluetooth: Controller: Fix LLCP event_counter value used during prepare
Fix LLCP to use event_counter value used during prepare to
compare instant to be the value as when in prepare and not
incorrectly use a stale value (when two radio events
overlap).

Signed-off-by: Vinayak Kariappa Chettimada <vich@nordicsemi.no>
2025-07-19 15:47:45 -04:00
Loic Domaigne
f314560b4a Bluetooth: Controller: Fix a potential NULL pointer dereference
Fix a potential NULL pointer dereference for skip_fields in the function
ull_adv_sync_copy_pdu_header. This issue been reported by Coverity.

Coverity CID: 392529

Signed-off-by: Loic Domaigne <tech@domaigne.com>
2025-07-19 13:50:57 -04:00
Håvard Reierstad
d989188f29 Bluetooth: Host: l2cap: Fix MPS/MTU confusion
The implementation used BT_L2CAP_ECRED_MIN_MTU to check the lower limits
of both MTU and MPS, instead of BT_L2CAP_ECRED_MIN_MPS for MPS. While
these are the same here, confusion may arise. This commit fixes the
confusion.

Signed-off-by: Håvard Reierstad <haavard.reierstad@nordicsemi.no>
2025-07-19 13:26:29 -04:00
Mark Wang
e71b5122f7 bluetooth: classic: add role switch API
add bt_conn_br_switch_role and bt_conn_br_set_role_switchable to control
the role switch, add DEFAULT_ROLE_SWITCHABLE Kconfig to control the default
role switch state.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2025-07-19 09:59:16 +02:00
Mark Wang
31fba83fb3 bluetooth: classic: add role changed callback
add `role_changed` to `struct bt_conn_cb` to notify the HCI_Role_Change
event to application.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
2025-07-19 09:59:16 +02:00