Commit Graph

76 Commits

Author SHA1 Message Date
huangyulong3 0cf1898d83 bluetooth: fix compilation errors
Fix various compilation errors across bluetooth framework, service,
and stack layers including:
- Add missing function declarations and header includes
- Fix type mismatches and implicit function declarations
- Add missing macro definitions in dfx headers
- Add stub implementation for hid device interface
- Fix list utility inline function issues

Signed-off-by: openvela <openvela@xiaomi.com>
2026-05-08 09:52:38 +08:00
v-chenghuijin 5e83175f35 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-04-27 23:14:54 +08:00
chejinxian1 ffd449d59e Bluetooth: Fixed an issue where resources could not be released after closing uv_pipe in euv_pipe.
bug: v/83955

Rootcause: euv_pipe_close records the address of the euv_pipe in the data field of each uv_pipe instance to be closed, which is used to release the euv_pipe instance after the close operation completes.

A scenario exists where calling euv_pipe_close followed by euv_pipe_read_stop or euv_pipe_read_start causes the client pipe's data field to be reset to NULL or the reader's address. This prevents the euv_pipe instance from being released after close completes.

This occurs because euv_pipe_read_stop does not check the uv_pipe's state before directly freeing cli_pipe.data, while euv_pipe_read_start only verifies whether cli_pipe is active. Both functions lack a check for the closing state.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-27 23:14:54 +08:00
chejinxian1 ffe9428e8f 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>
2026-04-27 23:14:53 +08:00
wuxiaodong6 616c09ec15 Move the internal header files out to include common
bug: v/73268

Signed-off-by: wuxiaodong6 <wuxiaodong6@xiaomi.com>
2026-04-27 23:14:52 +08:00
zhangyuan20 eb4d0a3ce3 Vela-Android: save bredr remote uuids
bug: v/45250

Rootcause: vela does not save remote uuids, causing android UI to display errors

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-27 23:14:51 +08:00
fangzhenwei 44a24c0a70 addr: fix bt_addr_str multiple define
bug: v/49964

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2026-04-27 23:14:50 +08:00
openvela-robot 9d0c825cbb Merge commit
Change-Id: If26995eebd18a82ac4cd827e6801458e57a6ead3
2026-04-27 23:14:50 +08:00
chejinxian1 942c5b6f6b Bluetooth: Fix conditional compilation for RPMSG pipe closure
Rootcause: The creation of the euv_pipe RPMSG Pipe is conditionally compiled based on the RPMSG configuration, whereas the Close behaviour lacks this restriction. Consequently, in certain scenarios, non-existent RPMSG pipes may be released, triggering an exception.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-20 14:52:54 +08:00
chejinxian1 e3303ae0d2 bluetooth: Replace `calloc` with `malloc` for `signal_work_t` allocation
in `thread_loop_work_sync`

Rootcause: Replace `zalloc` with the C standard library function `calloc` to avoid compilation errors.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
Signed-off-by: miot-robot <miot-robot@xiaomi.com>
2026-04-20 14:52:40 +08:00
v-chenghuijin 4bc6a21afd Bluetooth: Prevent crash when calling uv_run after event loop closure.
Rootcause: uv_loop_close() marks internal data structures as invalid (e.g., set to -1), but pending callbacks in the queue still reference these invalidated structures. When uv_run() is called later, it processes the queue using corrupted pointers, leading to segmentation faults and crashes. Solution: Introduce a new flag in uv_loop_close() to mark the loop as closed and check it in uv_run() and other loop-related functions to prevent execution of callbacks after closure, ensuring memory safety and avoiding invalid pointer access.

Signed-off-by: v-chenghuijin <v-chenghuijin@xiaomi.com>
Signed-off-by: miot-robot <miot-robot@xiaomi.com>
2026-04-20 14:52:40 +08:00
chejinxian1 060df83c75 Bluetooth: Enhance euv_pipe status management and add new status flags.
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>
Signed-off-by: miot-robot <miot-robot@xiaomi.com>
2026-04-20 14:52:32 +08:00
liuxiang18 904d80778e bluetooth: fixed a use-after-free issue caused by ins->client_loop & ins have been released during worker execution.
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>
2026-04-20 14:52:15 +08:00
liuxiang18 c81a2d2870 scan: Replace lib_dumpbuffer with BT_DUMPBUFFER.
The current execution time of `on_scan_result_cb` is excessively long. Replace `lib_dumpbuffer` with `BT_DUMPBUFFER` (disabled by default) to reduce callback execution time, thereby preventing watchdog timeouts.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
Signed-off-by: miot-robot <miot-robot@xiaomi.com>
2026-04-20 14:52:14 +08:00
chejinxian1 e16dfe26a0 Bluetooth: Adjust some logs to locate the problem.
Rootcause:
1. Clear spp tx flow control spam logs.
2. Add spp connect port information output.
3. Add euv_pipe handle information output for matching callback information.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-20 14:52:07 +08:00
chejinxian1 1267222602 Bluetooth: Fix the issue of the reader in euv_pipe not being correctly released.
Rootcause: When a pipe connection is successfully established and ready to read data, a reader will be allocated to handle the reading process, and the reader will be associated with the pipe object. When it is necessary to stop reading from the pipe, the reader needs to be released. Specifically, when a pipe disconnection occurs, the allocated reader also needs to be released. However, when a disconnection is initiated by either end of the pipe, the other end may read the EOF symbol from the reader first, causing the pipe to be set to a non-active state. This prevents the current logic of first checking the pipe status before releasing the reader in euv_pipe_read_stop from releasing the reader.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-20 14:52:02 +08:00
chengkai c93bf090ca bluetooth: fix euv pipe ptr leak
rootcause: it would leak pipe handle when connect and disconnect many time. client pipe would free pipe handle directly, which does not has handle->data.server pipe would free handle->data(euv connection) first when connected, then free pipe handle when closed.

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-20 14:52:02 +08:00
huangyulong3 c702c24d1c ble_adv: The startAdvertising or startAdvertising and stopAdvertising interface crashes after 1000 press tests.
Signed-off-by: huangyulong3 <huangyulong3@xiaomi.com>
2026-04-20 14:52:02 +08:00
Lu Jia 15e60f2d26 bluetooth: Fix the issue of incorrect length when adding service data to broadcast data.
When adding service data to broadcast data, the data length only includes the length of the type and UUID, without the length of the data.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-04-20 14:52:01 +08:00
chejinxian1 b6a632b691 Socket: Optimize the connection operation of the socket pipe.
Rootcause: In order to reduce the application's judgment on whether the connection is across cores, the original two types of socket pipe connection methods are encapsulated into one interface.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-20 14:52:00 +08:00
zhangyuan20 a483b4c678 Vela-Android: save bredr remote uuids
Rootcause: vela does not save remote uuids, causing android UI to display errors

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-04-20 14:51:36 +08:00
fangzhenwei 9fa5efa0b9 addr: fix bt_addr_str multiple define
Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2026-04-20 14:51:35 +08:00
zhongzhijie1 6a6ed8c170 Rename helper func get_os_timestamp_xx to bt_get_os_timestamp_xx avoid
naming confict.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-20 14:51:29 +08:00
zhongzhijie1 6770f27102 Adjust the priority of bt_client to always be 1 higher than that of bluetoothd.
Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-20 14:51:29 +08:00
zhongzhijie1 1b46adb860 Modiy bt_time.h and bt_time.c to framework common field.
Move bt_time.h and bt_time.c from service to the common framework path, making
them publicly accessible for reuse. No functional changes were made to the APIs.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-04-20 14:51:28 +08:00
chejinxian1 f74a6ed60b SPP: Fix the issue of improperly closing the pipe.
Rootcause: When using SPP capability in cross-core scenario, it is necessary to perform cross-core communication through RPMSG. Since the Bluetooth service does not know which pipe connection method the application uses when establishing an SPP connection, it waits for the application to connect using both local and RPMSG pipes, and closes the unused pipe after connecting. When not in a cross-core scenario, the Bluetooth service does not use both pipes, which causes the subsequent closing behavior to result in runtime errors, causing the Bluetooth thread to be cleared by the system, thereby stopping the Bluetooth service.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-04-20 14:51:21 +08:00
chengkai 6646b015b3 bluetooth: fix app disconnect and read_stop cause pipe assert
Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-20 14:51:21 +08:00
chengkai de72019f30 bluetooth: fix spp euv read buf free
Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-20 14:51:21 +08:00
chengkai 163d14d153 bluetooth: add spp pipe close check
Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-20 14:51:20 +08:00
Haishen Zhang 44f12d1c1d Vela-Android: Add support to multiple SPP client connections
1. Enable RPMsg Socket: CONFIG_NET_RPMSG/CONFIG_BLUETOOTH_SPP_RPMSG_NET
2. Disable RPMsg UART: CONFIG_RPMSG_UART ("/dev/ttyDROID")
3. For client connection, we shall use conn_id, instead of scn.
   (scn == 0, all the time.)

Signed-off-by: Haishen Zhang <zhanghaishen@xiaomi.com>
2026-04-20 14:51:20 +08:00
chengkai 967bfd5bf1 bluetooth: fix spp euv assert when disconnect
Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-20 14:51:20 +08:00
chengkai 68032addbc bluetooth: add spp rx cached handle
Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-20 14:51:20 +08:00
chengkai 1646e8903e bluetooth: add sockect pipe api
Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-20 14:51:20 +08:00
chengkai d85380ebc8 bluetooth: add le scan dup feature
rootcause: add le scan dup feature

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-20 14:51:15 +08:00
duqunbo 9b62886c8e Handles cllbacks free work in the client thread.
rootcause: The callbacks list itself is not Locked protection and concurrent access
is incorrect, so releasing it must be done in the client thread.

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2026-04-20 14:51:14 +08:00
Haishen Zhang bc1958f97b Vela-Android: fix compiling failure
1. Add bt_config.h in uv_thread_loop.c
2. Follow the changs on Vela to redefine the prio definition

Signed-off-by: Haishen Zhang <zhanghaishen@xiaomi.com>
2026-04-20 14:51:12 +08:00
Haishen Zhang 764c65400d Bluetooth: adjust prio of BT task/threads
1. bluetoothd
2. bt_client#
3. bluelet_thread
4. bttool
5. default prio: 100->103(>CONFIG_MIWEAR_APPS_PRIORITY=102)

Signed-off-by: Haishen Zhang <zhanghaishen@xiaomi.com>
2026-04-20 14:51:12 +08:00
fangzhenwei 8b2fb1d60a coverity: fix CHECKED_RETURN issue
Calling uv_loop_close without checking the return value, ignore return value

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2026-04-20 14:51:11 +08:00
Zihao Gao cc32ce4ce2 Bluetooth: add free after list_delete to avoid memory leak.
Rootcause: bt_list_add_tail would malloc a new node to save data,
list_delete, however, would not free the previous node.
To solve the memory leak, we use list_add_head and list_add_tail
isdead of bt_list_add_head and bt_list_add_tail

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-04-20 14:51:09 +08:00
Zihao Gao d553ab869d Bluetooth: set SCO offloading on audio transport message.
Signed-off-by: gaozihao <gaozihao@xiaomi.com>
Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2026-04-20 14:51:08 +08:00
fangzhenwei 7c8a2f8008 coverity(FORWARD_NULL): add cbsl [in] param check
Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2026-04-20 14:51:06 +08:00
chengkai dbe2fd9fa1 bluetooth: fix null addr to str
rootcause:1. fix null addr 2. add const

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-20 14:51:05 +08:00
Haishen Zhang 2b61b670a2 Vela-Android: porting bttool over socket(AF_INET) (1/2)
dependson:4036148

1. Enable Socket(AF_INET) first on Android
2. Fix the improper definition of Struct over Socekt between 64 bits and 32 bits system.
3. Modify the bttool to let it work similar to Vela

Signed-off-by: Haishen Zhang <zhanghaishen@xiaomi.com>
2026-04-20 14:51:01 +08:00
Haishen Zhang 6ed1e5e080 Vela-Android: Porting Vela Bluetooth Framework Socket Client to Android x86_64
1. Port Vela Bluetooth Framework Socket Client onto Android.
2. For Socket Server, Service, SAL, we didn't port them onto Android.
3. For bttool, the function is not ready yet.
4. With this libbt-framework-client.so, we can start working on BTIF wrapper over Vela BT Framework Socket Client API.
5. And, we can also start working on bttool over Vela BT Framework Socket Client API later.

Signed-off-by: Haishen Zhang <zhanghaishen@xiaomi.com>
2026-04-20 14:51:00 +08:00
gaozihao 94eedfc13b bttool: correct the usage of "scan start -f"
Signed-off-by: gaozihao <gaozihao@xiaomi.com>
2026-04-20 14:50:59 +08:00
Haishen Zhang 19bc307ac2 Clang-format: Update format of all files based on new .clang-format
1. Update format of all files based on new .clang-format

Signed-off-by: Haishen Zhang <zhanghaishen@xiaomi.com>
2026-04-20 14:50:50 +08:00
duqunbo dd412f6a6b Avoid repeated creation of bluetooth instances during feature registration, and solve the accessing the freed memory during instance destruction
Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2026-04-20 14:50:41 +08:00
fangzhenwei 9c25651c35 fix: uv_loop_init memory leak
Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2026-04-20 14:50:40 +08:00
chengkai 503d4f5ffe bluetooth: fix uuid128 may be used uninitialized warnnings
rootacuse: fix warning: '((const uint8_t *)((char *)&uuid128 + offsetof(bt_uuid_t, val)))[3]' may be used uninitialized [-Wmaybe-uninitialized]
  115 |         (u32) = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + ((((uint32_t)(*((p) + 2)))) << 16) + ((((uint32_t)(*((p) + 3)))) << 24)); \
      |                                          ^
framework/common/bt_uuid.c:141:15: note: '((const uint8_t *)((char *)&uuid128 + offsetof(bt_uuid_t, val)))[3]' was declared here
  141 |     bt_uuid_t uuid128;

Signed-off-by: chengkai <chengkai@xiaomi.com>
2026-04-20 14:50:38 +08:00
fangzhenwei 49d5c962c8 reformat with clang-format 14 coding style
Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2026-04-20 14:50:37 +08:00