Commit Graph

106 Commits

Author SHA1 Message Date
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 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
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
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
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
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
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
ouyangxiangzhen 0f0f42875e bluetooth: Fix list conflicts.
bug: v/59949

This commit fixed list conflicts by directly including nuttx/list.h.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
2026-02-02 09:31:42 +08:00
v-chenghuijin a91f2a311c fix: prevent crash by ensuring non-null string for sched_note_printf
bug: v/84212

Rootcase: The lightweight sched_note_printf function in the NuttX backend does not
perform NULL safety checks for the %s format specifier. Passing a NULL pointer from
hsm_get_state_name leads to a NULL pointer dereference, triggering a data abort
exception on systems with memory protection (MMU/MPU) and causing a system crash.

Solution: This commit addresses the issue by modifying the HSM_SAFE_NAME macro to
use the ternary operator. It now explicitly returns the "None" string literal when
hsm_get_state_name returns NULL, guaranteeing that a valid, non-null C-string is always
passed to the logging function.

Signed-off-by: v-chenghuijin <v-chenghuijin@xiaomi.com>
2026-01-26 23:46:10 +08:00
zhangyuan20 1a1526791b bluetooth: add android15 config control.
bug: v/84700

Rootcause: Some configurations are not enabled in Android 15 and require the addition of macro controls in Android 15.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-01-25 13:50:27 +08:00
liuxiang18 765755dbb2 socket: Move the generic macro to the public header file.
bug: v/83666

In the current bt_socket_profile file, all client-side callbacks use the generic macro interface
BREDR & common: CALLBACK_FOREACH
BLE: CALLBACK_REMOTE

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-01-22 09:28:28 +08:00
chengkai 6e4d1c3380 bluetooth: add gatts_connect_bear api [1/2]
bug: v/51103

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-01-14 14:28:28 +08:00
YuhengLi 8db9b23dca Android-Vela:add cind interface for android
bug: v/59050

Rootcause:When reconnect to the headset during a call, the headset will obtain the call status through the cind command. Since Vela does not have modem, the status will be error. So, get cind from Android.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-01-07 14:11:18 +08:00
zhongzhijie1 0d0fddd4d1 Remove the zephyr header file from the Bluetooth global header directory
bug: v/82081

`bt_le_scan.h` is a globally exposed header file. Then, Zephyr's `#include <zephyr/bluetooth/bluetooth.h>` is declared as a private inclusion of Zephyr in CMake. However, the problem is that when third-party apps use my global `bt_le_scan.h`, the CMake system doesn't know where `zephyr/bluetooth/bluetooth.h` is and throws an error. One solution is for the third-party app to also declare a private inclusion of Zephyr in CMake, but this doesn't conform to design principles. The app only needs to be concerned with my framework layer. If the app also needs to include Zephyr's header files, then the framework layer is not properly configured. Therefore, `zephyr/bluetooth/bluetooth.h` must not be explicitly included in `bt_le_scan`.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-05 13:09:54 +08:00
chejinxian1 02c5e94088 Bluetooth: Add close callback support to `euv_pipe` structure and close functions
bug: v/80811

Rootcause: In certain scenarios, users of `euv_pipe` must ensure all UV requests have completed execution before releasing resources. Consequently, it is necessary to notify users that `euv_pipe` has been fully released after its close operation is completed, thereby permitting subsequent operational procedures to proceed. Support for the close callback has therefore been added.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-12-29 10:35:53 +08:00
chejinxian1 1b99dbd833 L2CAP: Resolved the issue where the L2CAP Server was unable to accept new connections
bug: v/70057

Rootcause: There exists a specific scenario where an application may fail to correctly accept connections. In L2CAP multi-role, multi-connection scenarios, if an instance with ID 0 is released due to disconnection, subsequent connection events will utilise ID 0 for identification. Should the server accept a connection and adopt ID 0 as the new listen channel ID, the application will be unable to distinguish whether a new listen channel ID requires processing. This results in the application being unable to accept further L2CAP connection requests from peer devices.

Therefore, `INVALID_L2CAP_LISTEN_ID` is introduced to distinguish this scenario. When the Client connects, the default `new_listen_id` uses `INVALID_L2CAP_LISTEN_ID`, indicating that the application need not add a new listen channel; otherwise, it must.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-12-15 10:54:59 +08:00
chejinxian1 977bb0838d L2CAP: Update stop listen function to include transport parameter
bug: v/70057

Rootcause: The PSM employed by L2CAP in LE and BR/EDR contexts are not identical concepts. The LE scenario utilises a simplified PSM, whereas the BR/EDR scenario employs the standard PSM. These differ fundamentally in their allocation methods and are not interoperable.

Consequently, the current implementation of listen and stop listen operations requires distinguishing between connection types. Add a new API `bt_l2cap_stop_listen_with_transport` to support stop listen on BR/EDR PSM. This modification will rectify the error where `bt_l2cap_stop_listen` fails to recognise connection types, whilst filtering operations specific to the BR/EDR type.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-12-15 10:54:59 +08:00
Lu Jia c4cec4f868 bluetooth: Fix the issue of failed GATTC deletion.
bug: v/79667

When deleting a GATTC instance, the Advanced API identifies clients based on their device address. If an application creates two GATTC instances with the same device address, and attempts to delete the second instance before the server has returned the asynchronous callback for the first deletion, both deletion operations will effectively target the same underlying GATTC instance due to the identical device address.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-12-03 09:48:19 +08:00
chejinxian1 efe2486d8d bluetooth: Restrict the scope of use for `bt_oob_data_t`
bug: v/79135

Rootcause: The current definition of `bt_oob_data_t` conflicts with the Android Bluetooth. In practice, this type definition is restricted to internal service usage and is not currently exposed externally.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-11-28 21:36:20 +08:00
zhongzhijie1 026db6dfa4 Extend feature get-service callback to report service array
bug: v/77564

The original bt_gattc_feature_get_service_cb_t callback only returned a
single gatt_service_t pointer. This is insufficient for feature-layer
use cases that require receiving all discovered services at once.

This patch updates the callback signature by adding:

- const gatt_service_t *services[] : array of discovered service pointers
- size_t count                     : number of services in the array

This allows the feature layer to receive a batch of services in a single
notification and avoids repeated per-service callbacks.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-11-20 18:25:31 +08:00
Lu Jia 4cb36ccf47 bluetooth: Using macros to reduce boilerplate code in asynchronous callbacks.
bug: v/77564

Some processing logic in asynchronous callbacks is identical; extract this common code into a macro.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-11-20 18:14:35 +08:00
chejinxian1 085770f5a3 L2CAP: Enable L2CAP configuration.
bug: v/58030

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-11-17 22:20:28 +08:00
chejinxian1 64d4df2bca L2CAP: Add function to stop listening on a specific PSM.
bug: v/57319

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-11-17 22:20:28 +08:00
chejinxian1 68ef63520d L2CAP: Refactor L2CAP API to support to multiple application and socket pipe.
bug: v/57319

Refactor L2CAP API to use handles instead of cookies for callback registration and management.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-11-17 22:20:28 +08:00
liuxiang18 9cb39dc0db bluetooth: fixed a use-after-free issue caused by ins->client_loop & ins have been released during worker execution.
bug: v/77699

When the client clears resources, if tasks are still executing in the worker thread at that time, it will lead to a use-after-free issue.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-11-13 21:14:16 +08:00
chejinxian1 e361130272 Bluetooth: Enhance euv_pipe status management and add new status flags.
bug: v/76708

Rootcause: `uv_close` does not guarantee the order in which close callbacks run.
There is a case where `euv_pipe_close2` and `euv_pipe_close` are called in sequence: if the `uv_close` initiated by `euv_pipe_close` completes first and frees the `euv_pipe_t` instance, `euv_pipe_close2` must access the invaliad address during its execution.
Therefore, add a status flag to ensure the `euv_pipe_t` instance is freed safely.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-10-31 22:34:23 +08:00
wuxiaodong6 2ea19a820a Move the internal header files out to include common
bug: v/73268

Signed-off-by: wuxiaodong6 <wuxiaodong6@xiaomi.com>
2025-10-24 01:29:42 +08:00
Lu Jia 92e9a77eb2 ipc: trace async api
bug: v/62087

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
zhongzhijie1 f3aa95cb4b gattc/feature: add high-level GATT client, local DB, and async ops
bug: v/62106

Add feature-layer GATT client (gatt_client_t) wrapping low-level GATTC callbacks.
Build a local services DB from discovery (service/characteristic/descriptor).
Provide stable UUID handle lookups and helpers (service/char/desc finders).
Implement async read/write for characteristics and descriptors, notify subscribe/unsubscribe, and MTU exchange.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia 7d68d3fe06 ipc: gattc async api
bug: v/62106

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia 474067591a ipc: le scan async api
bug: v/62058

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
zhongzhijie1 9e14193b3c [bug fix] When bt off is executed, disconnect all acl connections.
bug: v/43852

Originally, only the "adapter_disable" function was executed. An additional step was added before that, which disconnects all ACL connections. A timer was also started to wait for the "disconnect" event for 2 seconds, followed by cleaning up profile resources (by following the normal disable procedure).

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-09-26 21:42:22 +08:00
liuxiang18 3f7b0c707c PTS: add pts property for dynamic control disconnect or not when pair failed.
bug: v/71321

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-09-25 20:01:14 +08:00
zhongzhijie1 6302f4e2c3 Support the signed write function, which requires BT_SIGNING micro to open.
bug: v/69041

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-09-25 20:01:14 +08:00
zhongzhijie1 42aeb49c23 Add API for limited Discovery.
bug: v/70809

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-09-25 20:01:14 +08:00
liuxiang18 140f414f65 bluetooth: implement bt_device_set_bondable_le API to change bond mode.
bug: v/67335

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-09-25 20:01:14 +08:00
liuxiang18 abb204078c bluetooth: implement bt_device_set_security_level API to change bond security level.
bug: v/67009

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-09-25 20:01:14 +08:00
Kai Cheng 35ed1ce372 bluetooth: add gatt client and server config
bug: v/51584

add gatt client and server config

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-09-25 15:29:53 +08:00
liyuheng f63df58228 Add new interface: hfp_hf_query_current_calls_with_callback.
bug: v/67238

Rootcause: Currently, when the bt_hfp_hf_query_current_calls interface receives a request, it retrieves the result from the state machine cache and returns it immediately. However, since the cache may not be updated in a timely manner, the returned data may not be the latest.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2025-09-17 10:41:29 +08:00
zhangyuan20 0ac0044e05 Android-Vela:add cnum interface for android
bug: v/67447

Rootcause: Adapt the cnum interface to obtain the virtual call mobile phone number.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2025-08-28 21:14:05 +08:00
chejinxian1 4690eba325 SPP: Add SPP Proxy connection states to handle different events.
bug: v/68679

Rootcause: Since the SPP Proxy's state is closely tied to the SPP connection status, but socket-related operations make it impossible for the two to maintain full synchronization. When an SPP disconnection occurs, the server-side Proxy will be closed directly. If bt_client subsequently attempts to connect to the Proxy via Socket, there may be a thread blocking risk. Therefore, adding two states - SPP_PROXY_STATE_CONNECTING and SPP_PROXY_STATE_CLOSING - better describes the Proxy's status under different scenarios, enabling differentiated operations for handling disconnection events. In such risk scenarios, the SPP Proxy will enter the SPP_PROXY_STATE_CLOSING state to delay the closure of the Proxy, ensuring synchronization between the Proxy connection and SPP connection.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-08-19 10:35:23 +08:00
chejinxian1 d494e289e7 64-bit: Adjust the platform configuration macros in bt_config.h.
bug: v/59352

Rootcause: The configuration file of NUTTX is included after the platform macro configuration, which causes the inability to identify the compilation platform bit of Vela. To properly define the platform configuration macro, the following two adjustments are made: 1. Move the platform configuration macro to the end of bt_config.h; 2. Add compilation detection for the x86_64 platform.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-08-08 16:53:38 +08:00
Lu Jia 2f7d2053ac bluetooth: Add bluetooth_get_async_instance()
bug: v/63432

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +08:00
Lu Jia 4b3f987d31 ipc: le advertiser async api
bug: v/62058

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +08:00
Lu Jia 979b66f3bf bluetooth: Fix compilation errors when calling Bluetooth in C++ files.
bug: v/67883

Root Cause: When a C++ file references a Bluetooth file, compilation errors occur due to the Bluetooth file using C++ keywords.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-07 15:57:53 +08:00
Zihao Gao 045702fd61 btsnoop: allow to remove RFCOMM data and NoCP events.
bug: v/61175

Rootcause: RFCOMM and NoCP events are too frequent
and may cause memory issues.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-07-14 09:08:26 +08:00
chejinxian1 e0181c9f95 bttool: Remove the dependency of SPP on CONFIG_BLUETOOTH_SPP_RPMSG_NET in bttool.
bug: v/54416

Rootcause: The new euv_pipe_connect interface will automatically help the application select the socket connection method, without requiring the application to determine whether it is in a cross-core scenario.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-07-08 10:58:08 +08:00
Zihao Gao 0eef976b0c bttool: add test tool for vendor at response.
bug: v/64274

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-06-30 01:34:30 +08:00
zhongzhijie1 43018e3c48 Rename helper func get_os_timestamp_xx to bt_get_os_timestamp_xx avoid
naming confict.

bug: v/59638

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-19 21:19:12 +08:00