Commit Graph

30 Commits

Author SHA1 Message Date
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
chejinxian1 8c3f60e878 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-01-26 10:03:18 +08:00
v-chenghuijin e1032e6693 Revert "Bluetooth: Prevent crash when calling uv_run after event loop closure."
bug: v/80385

This reverts commit 1974e4be0e.

Signed-off-by: v-chenghuijin <v-chenghuijin@xiaomi.com>
2026-01-23 09:22:13 +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
v-chenghuijin 1974e4be0e Bluetooth: Prevent crash when calling uv_run after event loop closure.
bug: V/80385

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>
2025-12-19 10:39:29 +08:00
chejinxian1 e76f082bdb Bluetooth: Fix conditional compilation for RPMSG pipe closure
bug: v/80592

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>
2025-12-15 10:54:59 +08:00
chejinxian1 32e1c81391 bluetooth: Replace `calloc` with malloc for `signal_work_t` allocation in `thread_loop_work_sync`
bug: v/79115

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

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-11-28 21:36:20 +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
liuxiang18 4e966c8997 scan: Replace lib_dumpbuffer with BT_DUMPBUFFER.
bug: v/74823

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>
2025-11-13 11:35:55 +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
chejinxian1 b368f97316 Bluetooth: Adjust some logs to locate the problem.
bug: v/68679

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>
2025-08-19 10:35:23 +08:00
Lu Jia 243acecda5 bluetooth: Fix the issue of incorrect length when adding service data to broadcast data.
bug: v/63976

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>
2025-08-08 13:52:12 +08:00
chengkai d793ddf6df bluetooth: fix euv pipe ptr leak
bug: v/65152

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>
2025-07-08 11:00:19 +08:00
chejinxian1 d03e02610a Bluetooth: Fix the issue of the reader in euv_pipe not being correctly released.
bug: v/65151

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>
2025-07-08 11:00:19 +08:00
chejinxian1 2c95b3db74 Socket: Optimize the connection operation of the socket pipe.
bug: v/54416

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>
2025-07-08 10:58:08 +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
zhongzhijie1 98a50be547 Modiy bt_time.h and bt_time.c to framework common field.
bug: v/59638

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>
2025-06-19 21:19:12 +08:00
zhongzhijie1 9ff81d7dd9 Adjust the priority of bt_client to always be 1 higher than that of bluetoothd.
bug: v/58744

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-17 23:25:06 +08:00
chejinxian1 11272ce67a SPP: Fix the issue of improperly closing the pipe.
bug: v/53158

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>
2025-02-10 17:56:41 +08:00
chengkai af2adab4ef bluetooth: fix app disconnect and read_stop cause pipe assert
bug: v/51694

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-02-10 17:56:41 +08:00
chengkai d19f0b2009 bluetooth: fix spp euv read buf free
bug: v/47177

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-02-10 17:56:41 +08:00
chengkai 5f87453562 bluetooth: add spp pipe close check
bug: v/51694

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-02-10 17:56:41 +08:00
Haishen Zhang d4fdcf87f4 Vela-Android: Add support to multiple SPP client connections
bug: v/50094

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>
2025-02-10 17:56:41 +08:00
chengkai bb358f5ef0 bluetooth: fix spp euv assert when disconnect
bug: v/50976

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-02-10 17:56:41 +08:00
chengkai 3a670aaecb bluetooth: add spp rx cached handle
bug: v/50976

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-02-10 17:56:41 +08:00
chengkai d214aed78f bluetooth: add sockect pipe api
bug: v/47177

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-02-10 17:56:41 +08:00
zhangyuan20 2f9ed21f73 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>
2025-02-07 13:55:03 +08:00
fangzhenwei b0f21a417d addr: fix bt_addr_str multiple define
bug: v/49964

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2025-01-16 20:16:25 +08:00
openvela-robot cf07bea530 Merge commit
Change-Id: If26995eebd18a82ac4cd827e6801458e57a6ead3
2024-11-25 17:34:53 +08:00