Commit Graph

782 Commits

Author SHA1 Message Date
github-actions[bot] f606bf1610
test it 2026-03-14 10:27:45 +00:00
zhangyuan20 68287f1f5e CS: add cs config and makefile.
bug: v/80281

Rootcause: Add CS configuration and makefile to manage CS compilation.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-03-02 12:08:13 +08:00
zhangyuan20 9120f7835c CS: add bttool to test cs.
bug: v/80281

Rootcause: Add bttool to test CS functionality

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-03-02 12:08:04 +08:00
zhangyuan20 49453c7ba7 CS: add cs socket server and client.
bug: v/80281

Rootcause: Add a socket server and client to enable communication between the user and Bluetooth.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-03-02 12:07:54 +08:00
zhangyuan20 67fa0bed68 CS: add cs_ras_common.h
bug: v/80281

Rootcuase: this file used for ras server.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-03-02 12:07:42 +08:00
zhangyuan20 b591e0f409 CS: add cs service.
bug: v/80281

Rootcause: Add a CS service to manage CS.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-03-02 12:07:27 +08:00
zhangyuan20 4ed01f77a1 CS: Add cs state machine.
bug: v/80281

Rootcuase: add cs state machine to manager cs procedure.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-03-02 12:06:58 +08:00
zhangyuan20 d05f068f83 CS: Add sal_le_cs_interface.c
bug: v/80281

Rootcause: Add control interfaces such as CS config to the SAL layer.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-03-02 12:06:47 +08:00
zhangyuan20 e262683cea CS: Add CS callback in sal.
bug: v/80281

Rootcause: CS needs to report config, subevent, and other callbacks.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-03-02 12:06:37 +08:00
chejinxian1 3a93699f9c L2CAP: Fix log format mismatch in `handle_packet_received()`
bug: v/85464

Remove extraneous parameter in `BT_LOGE` call where format string has no corresponding placeholder for `packet->len_received`.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-02-27 19:26:05 +08:00
chejinxian1 c457f89b38 L2CAP: Add MPS validation for received segments
bug: v/85177

Add validation check to ensure received segment length does not exceed the negotiated MPS before processing. Abort channel if validation fails to maintain protocol integrity.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-02-27 19:26:05 +08:00
Lu Jia edff58455d bluetooth: Fix the issue where disabling does not disconnect the AVRCP target (tg) connection.
bug: v/85747

Fix connection manager disconnection logic: Only AVRCP Controller (CT) instances register explicit disconnect callbacks with the connection manager, while AVRCP Target (TG) connections are not proactively terminated during disable operations, leading to stale connection states and potential resource leaks.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-02-27 16:36:10 +08:00
zhongzhijie1 73aea9c852 pm: add bt_cm_enable/disable_enhanced_mode for BR/EDR low-latency sniff
bug: v/67000

Add bt_cm_enable_enhanced_mode() and bt_cm_disable_enhanced_mode().
Support EM_BR_SNIFF_LOW_LATENCY and EM_BR_SNIFF_ULTRA_LOW_LATENCY.
They switch to lower sniff intervals for short-term low latency needs.
Disable API restores the default sniff parameters.

Note: idle timeout is not changed in current design. It may be extended in the future.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-27 14:14:46 +08:00
YuhengLi c7819086a1 zblue: spp: unregister rfcomm server when sdp register fails
bug: v/86062

Rootcause: not unregister rfcomm server when sdp register fails causing memory access after free
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-02-26 16:54:36 +08:00
zhongzhijie1 5512e61919 implement get addrtype api
bug: v/84604

original return 0 default, now use adapter_get_le_remote_address_type

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-26 15:49:37 +08:00
zhongzhijie1 854c944770 Fix GATTC discovery filter UUID handling
bug: v/83024

Restore the type==0 check so a non-NULL filter_uuid with type 0 is treated

as "discover all services," matching bt_gattc_discover_service behavior.

Add an inline comment to document the NULL-to-type=0 contract and avoid

invalid UUID discovery calls that can break subscription flow.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-26 11:50:03 +08:00
zhongzhijie1 aac90e146b Supports user confirm in BLE Just Work pairing mode
bug: v/85869

1. Configure the correct `passkey_confirm` interface.

2. Follow the legacy stack; `le` iocap and `bt_iocap` are consistent.

3. No input/output iocap also supports `passkey confirm cb`.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-26 10:52:36 +08:00
liuxiang18 00781b02be gatts: fix address retrieval for att_over_br
bug: v/85531

When `conn.type = BT_CONN_TYPE_BR`, the original `get_le_addr_from_conn` function fails to locate the corresponding address, resulting in an address exception. The new `bt_sal_get_remote_address` function now incorporates logic to retrieve the LE address, making it a universal address retrieval interface for both BREDR and BLE.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-02-26 09:51:53 +08:00
liuxiang18 24ca21ded6 gatts: add judge about conn_info is NULL.
bug: v/84474

When the SAL layer does not store the BREDR connection information, it returns info as NULL. At this point, attempting an erroneous address offset on info->conn will result in a null pointer return.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-02-26 09:51:53 +08:00
liuxiang18 fc506e6a18 gatts: add `bt_conn_info_t` when att_over_br connected callbacks report.
bug: v/84474

When the peer initiates a connection, the connection callback reporting logic lacks the `bt_conn_add` entry. This prevents the subsequent SAL layer from retrieving the corresponding `bt_conn_info_t` object for the address, leading to subsequent data transmission process failures.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-02-26 09:51:53 +08:00
liuxiang18 0f703ed0f1 gatts: fix an issue where `bt_conn_unref` was not called after using `bt_conn_lookup_addr_br`.
bug: v/84474

1. Add a call to bt_conn_unref(conn)
2. Use the locally stored conn in the sal layer to avoid executing `bt_conn_unref`

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-02-26 09:51:53 +08:00
liuxiang18 091caa7e99 gatts: fix logical exceptions when the registration service exceeds its limit
bug: v/84473

When the number of registered services exceeds the limit, records not captured by `gatt_sdp_records` will be returned. Subsequent attempts to locate pointer indices for release will fail.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-02-26 09:51:53 +08:00
zhongzhijie1 f3d93d336f add ATTR_AUTO_RSP_CCC_READ to keep legacy GATT_H_CCCD behavior
bug: v/86395

rootcause:
Previously, CCC descriptors (defined by `GATT_H_CCCD`) would automatically respond to *read requests* within the stack, while forwarding all *write operations* (including write requests and write commands) to the application. This allowed the app to detect when a characteristic's notify/indicate status changed, without needing to implement `on_read_cb`.

During the Android BTIF porting, CCC read requests started being passed up to the application. This introduced compatibility issues for existing services that used `GATT_H_CCCD` without registering an `on_read_cb`, resulting in unhandled read responses.

To preserve backward compatibility, a new `rsp_type` value — `ATTR_AUTO_RSP_CCC_READ` — is introduced for `GATT_H_CCCD`. It restores the original behavior:

* Automatically respond to CCC descriptor read requests inside the stack
* Still forward write requests and write commands to the application via `on_write_cb`

This allows legacy services to continue functioning without modification.
Apps that require full control over both read and write (e.g. Android BTIF layer) should use `GATT_H_CCCD_USER_RSP`.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-25 13:40:39 +08:00
zhongzhijie1 f5016924f9 support user response for descriptor read requests
bug: v/86395

Provides a hook for business logic to observe and track read requests
without changing existing ATT/CCCD behavior.

Application sees the request but its response data is ignored; stack
still uses internal values for protocol correctness.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-25 13:40:39 +08:00
Kai Cheng 98863c8cb4 SPP: add rx credits mode control
bug: v/85788

rootcause: enable spp rx credits mode control, in order to
fix  HFP/AG not auto credits

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-02-12 11:02:45 +08:00
Kai Cheng 49af0a4d3b SPP: add credits control for recv data
bug: v/85608

rootcause: Adding SPP process handling to the bluetooth
service resolves the issue of non-flow control data
piling up in the protocol stack.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-02-12 11:02:45 +08:00
Kai Cheng 6233530e3b spp: correct SDP UUID endianness and isolate RFCOMM params
bug: v/85645

rootcause: SPP SDP records used the wrong UUID byte order
and reused template data, so later registrations overwrote
previous RFCOMM channel/UUID and triggered false duplicates.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-02-12 10:01:52 +08:00
Kai Cheng 1db3d299d3 spp: fix SDP proto list handling for RFCOMM channel
bug: v/85645

rootcause:The SDP PROTO_DESC list was modified in place
without copying, so the RFCOMM channel element pointer
could become invalid or corrupt, leading to incorrect
SDP records.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2026-02-12 10:01:52 +08:00
zhongzhijie1 355679205d bluetooth: fix adv data parsing for zero-length AD structures
bug: v/85714

The previous implementation did not handle zero-length AD items (len == 0)
and lacked sufficient boundary checks. As a result, padding bytes could be
misinterpreted as valid AD elements, leading to construction of invalid
bt_data entries with oversized data_len values.

This could further cause out-of-bounds memory access during advertising data
processing in the host stack.

This change adds proper handling for zero-length AD items, validates item
length and buffer boundaries, and enforces segment count limits to prevent
invalid bt_data construction.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-12 00:06:49 +08:00
zhongzhijie1 9308c128c7 commit LE bond settings after load
bug: v/85615

After adding LTK/IRK, the stack must trigger the settings commit path so the controller resolving list and related RPA advertise/scan behavior are updated. Previously there was no key-level commit hook for zblue settings, so the commit handler was not invoked for these updates.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-12 00:06:28 +08:00
zhongzhijie1 6045214350 gattc: add CCC handle query for Zephyr stack
bug: v/83024

Zephyr stack needs CCC handle to do CCCD.
Old stack only needs value handle.

So gattc_service.c adds a query helper.
It uses the full service DB to map value_handle to ccc_handle.
sal can use this function to find the correct CCC handle.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-12 00:05:27 +08:00
zhongzhijie1 b4ac008c72 gattc: restore single service DB and fix discover result loss
bug: v/83024

Some apps call bt_sal_gatt_client_discover_service_by_uuid() many times.
But current sal_gatt_client resets element index on every discover call.
So the discover result cannot be accumulated.

After discover finished, the service DB is incomplete.
Read / write by handle, especially CCCD, may fail.

This change copies service data by malloc and passes it to gattc_service.c.
gattc_service.c owns and frees this memory.
So the GATT service DB becomes complete and stable.
CCCD and other operations can work correctly.

Future plan:
Keep only one service DB, maintained by gattc_service.c.
sal_gatt_client_interface will use a dynamic list or array only during discovery.
After discovery, sal will not keep any service memory.
The service DB will be owned only by gattc_service.c.
This part is still TBD.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-12 00:05:27 +08:00
zhongzhijie1 2a5afb8f68 bluetooth: serialize gattc discovery for stack compatibility
bug: v/83024

Some stacks (e.g. zblue) do not support parallel GATT discovery requests.
To improve compatibility, make if_gattc_discover_service transactional and
serialize discovery per connection in the common service layer.

When a discovery is in progress, queue additional discover requests and
start them one by one after receiving DISCOVER_CMPL. Clear pending discovers
on disconnect. Save filter_uuid in the queued gattc_op_t so each queued
request can be executed with its original parameters.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-12 00:05:27 +08:00
zhongzhijie1 d9c398c218 Fix whitelist API typo, use the correct addr type rules.
bug: v/85615

See adapter_service.c. When adding/removing from the whitelist, the unknown type is treated as public, and the random type is passed directly.
The stack also needs a patch to convert random type addresses into identity addresses.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-12 00:05:05 +08:00
zhongzhijie1 7fc6d3360c fix address translation issue and improved subscribe API return value handling.
bug: v/83024

rootcause:
This will result in the upper layer not receiving the GATTC notify.
The `get_le_addr_from_conn` interface correctly retrieves the RPA address for the callback,
not the identity address.

The EALREADY return value indicates that ccc has already been subscribed to, so it is not an error.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-12 00:05:05 +08:00
zhongzhijie1 a9a2bb8ea3 add bt_sal_spp_connect_with_option API in zblue sal
bug: v/79519

this api is for insecure spp connect, implement in furture.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-11 17:27:28 +08:00
chengkai 0114d1c30a bluetooth: add spp insecure feature
bug: v/13885

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-02-11 17:27:28 +08:00
YuhengLi c1dfdc9997 zblue: hfp: hf: avoid call hci_send_sync in bluetoothd
bug: v/84390

Rootcause: should not call hci_send_sync in bluetoothd
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-02-11 16:30:57 +08:00
chejinxian1 3b0b4b04e6 Bluetooth Adapter: add log for scan mode and bondable state
bug: v/85755

Add `BT_LOGI` log to print scan mode and bondable state in `adapter_set_scan_mode` function for better debugging and monitoring of adapter scan mode changes.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-02-11 16:24:28 +08:00
Zihao Gao 75eaf7debb Adapter: disable safe for both BR/EDR and BLE
bug: v/84965

rootcause: safe disable for BR/EDR does not automatically triger safe disable in BLE.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-02-10 21:35:47 +08:00
v-yichenxi 4cf07d574a bluetooth: add libbluetooth dependency on zblue when ZBLUE stack is enabled.
bug: v/85506

When either ZBLUE stack option is enabled, add a dependency on zblue for libbluetooth via nuttx_add_dependencies, so zblue’s include dirs are applied only to libbluetooth and not globally.

Signed-off-by: v-yichenxi <v-yichenxi@xiaomi.com>
2026-02-09 09:49:23 +08:00
v-yuechen1 04ffd264ae spp: increase max connections from 2 to 9
bug: v/85292

spp: increase max connections from 2 to 9
- Modify BLUETOOTH_SPP_MAX_CONNECTIONS constant in kconfig

Signed-off-by: v-yuechen1 <v-yuechen1@xiaomi.com>
2026-02-06 14:27:52 +08:00
zhongzhijie1 b55ea3972c restore svc_attr_count even if att br SDP record registration fails
bug: v/85532

rootcause:
Because of the introduction of ATT over BR, `register_service` needs to complete both BLE service registration and SDP record registration. The original design uniformly cleaned up the intermediate `attr_db svc_attr_count = 0` upon function exit to allow for the registration of the next service.

However, when `gatt_sdp_create_record` fails to add a record, the function returns directly, failing to reach `svc_attr_count = 0`, causing anomalies in the subsequent GATT service registration process.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-04 23:40:39 +08:00
YuhengLi 32f4ad1c0a zblue: a2dpsrc: fix: a2dp connect failure
bug: v/84293

Rootcause: config->delay_report was unexpectedly set to 1 because a2dp_info->config was not initialized.

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-02-03 21:07:39 +08:00
openvela-robot da02d11d79 update workflow files 2026-02-02 19:28:58 +08:00
zhongzhijie1 855a7ae0be add conn null check after bt_conn_lookup_addr_br.
bug: v/85073

rootcause:
For example, an ACL connection might suddenly drop, due to issues such as controller problems or remote device problems.
Therefore, we might get an empty `conn`. We must perform a null check here to avoid operations like `conn->hdev` when calling the API.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-02 17:44:55 +08:00
zhongzhijie1 f98d44cc93 gatt: remove unused service register logic
bug: v/84936

The process sequence:
bt_sal_gatt_server_add_elements->add_service->add_characteristic->
add_descriptor, last register_service, so

if (svc_attr_count) {
    register_service();
}

this part of the code cannot be called, remove it.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-02 15:42:50 +08:00
zhongzhijie1 d6ee69801e gatt: avoid memmove on server_svcs, use free slots for service allocation
bug: v/84936

rootcause:
server_svcs[CONFIG_GATT_SERVER_MAX_SERVICES] is registered into
zblue gatt->ctx->db->slist via bt_gatt_service_register().

Each struct bt_gatt_service contains an slist node:
    struct bt_gatt_service {
        struct bt_gatt_attr *attrs;
        size_t attr_count;
        sys_snode_t node;
    };

So the stack keeps a pointer to &server_svcs[i] in the slist.

When a service is removed, doing memmove on server_svcs will move the
struct bt_gatt_service object in memory.
But the stack still holds the old pointer (&server_svcs[i]) in the slist.
After memmove, that pointer refers to stale or wrong content.
This can break the service list and cause use-after-free / memory corruption.

Fix:
Do not compact server_svcs with memmove.
Keep the bt_gatt_service node address stable after registration.
Only keep server_db[CONFIG_GATT_SERVER_MAX_ATTRIBUTES] linear for attributes,
and allocate new services by finding free slots in server_svcs.
This allows server_svcs storage to be non-linear, while the stack slist still
manages a linear sequence of service attributes via the attrs pointer.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-02 15:42:50 +08:00
Lu Jia 19e6e8db48 Fix CMake compilation errors.
bug: v/85482

In the /service/ipc/socket/src/ directory, the scan-related source file is named bt_socket_scan.c, not bt_socket_le_scan.c.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-02-02 12:32:09 +08:00
Zihao Gao 7eb62f4e7e Bluetooth: fix compile issue
bug: v/59949

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-02-02 09:31:42 +08:00