bug: v/85832
Fix defects causing bttool resource leak during BT enable/disable
stress test:
1. Store bttool_t pointer in g_bttool_loop->data so TURNING_OFF callback
can access the async queue (previously always 0, cleanup was skipped)
2. Replace do_in_thread_loop with bttool_uninit() in TURNING_OFF callback
to send _uninit command via uv_async_queue_send, ensuring bt_tool_uninit
runs on g_bttool_loop thread (mirrors bttool_quit pattern). Guard with
CONFIG_LIBUV_EXTENSION only.
3. Add re-entry guard in bt_tool_uninit to prevent double cleanup on
repeated BT disable cycles
Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
bug: v/87852
This commit performs an architecture-level refactoring of cs_ras.c and cs_ras.h. The core change replaces the shared global buffer and static arrays used for Real-time and On-demand mode data storage with independent dynamically-allocated linked list queues, resolving memory safety issues and concurrent processing defects in the original architecture.
Signed-off-by: jialu <jialu@xiaomi.com>
Bug: v/87379
Define BT_UUID_STR_LENGTH macro (40) in bt_uuid.h to replace hardcoded
magic numbers for UUID string buffer size. Use LENGTH suffix to avoid
conflict with Zephyr's BT_UUID_STR_LEN definition.
Update all usages across the codebase to use the new macro.
Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
bug: v/87430
- Replace strncpy with memcpy for non-string delimiter field
to avoid non-null terminated buffer warning
- Remove dead comparison msg->id < 0 on unsigned type and
change msg->len <= 0 to msg->len == 0 to fix
unsigned compared against 0 warning
Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
bug: v/85866
Implemented Cross-Transport Key Derivation (CTKD) functionality to enable
secure key derivation between BR/EDR and BLE transports.
Changes:
- service/stacks/zephyr/sal_adapter_le_interface.c:
* Added ctkd_mode field to sal_adapter_args_t union
* Implemented enable_key_derivation() function
* Completed bt_sal_le_enable_key_derivation() implementation with support
for bidirectional key derivation (BR->LE and LE->BR)
* Added proper CONFIG_BT_CLASSIC conditional compilation
- tools/bt_tools.c:
* Added set_ctkd_mode_cmd() function for CLI control
* Registered 'setctkd' and 'set ctkd' commands in command tables
* Provides user-friendly interface to enable/disable CTKD modes
This feature allows devices to derive encryption keys across different
Bluetooth transports, improving security and user experience during
dual-mode connections.
Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
bug: v/86588
Rootcase: the rssi is never changed after BR/EDR inquiry scan, and is never assigned a value for LE.
Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
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>
bug: v/84420
Add support for configurable MTU, MPS, and credits parameters in L2CAP connect and listen commands with proper validation.
Changes:
- Add optional [mtu] [mps] [credits] parameters to connect/listen commands
- Use default values when parameters are not specified
- Add validate_l2cap_params() function for parameter validation
- Validate MTU >= 23, MPS range 23-65533, credits >= 1, and MPS <= MTU
- Provide clear error messages with specific validation failures
- Update command help text to reflect new optional parameters
Usage:
connect <address> <psm> [mtu] [mps] [credits]
listen <psm> [mtu] [mps] [credits]
Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
bug: v/84215
Add stoprecv/startrecv commands to manually control data reception on L2CAP channels for flow control testing purposes.
Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
bug: v/80850
Rootcause: uv_loop_close() marks internal data structures as invalid, 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:To address the issues described above, the solution removes
uv_loop_t from the bttool_t struct and changes it to dynamic allocation,
introducing a global pointer g_bttool_loop to centrally manage its
lifecycle. Specific modifications include: dynamically allocating and
initializing the uv_loop_t instance within the bttool_thread function and
assigning it to the global pointer; modifying the bttool_command_uvloop_run
function to operate using the global g_bttool_loop pointer; and adjusting
the asynchronous API initialization logic in async/gap.c to ensure it
uses the global pointer instead of a local pointer. Furthermore, the
solution enhances error handling, ensuring proper resource cleanup if
memory allocation fails, and optimizes the bt_tool_uninit_cb function to
prevent premature clearing of the global pointer, which could lead to
access exceptions.
Signed-off-by: v-chenghuijin <v-chenghuijin@xiaomi.com>
bug: v/57133
1. Change LinearLayout to ConstraintLayout + ScrollView to make it more responsive
2. Add OnOffActivity.java and activity_on_off.xml to do Bluetooth On/Off operations
3. Add permissions in AndroidManifest.xml and request them during runtime
4. Add more debug logs
5. Remove Bluetooth On/Off operations from MainActivity.java
bug: v/57133
The <activity> element should not be locked to any orientation so that users can take advantage of the multi-window environments and larger screens available on Android.
bug: v/42362
Rootcause: Avrcp control lacks metadata interface, add get metadata interface and callback for avrcp control
Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
bug: v/47945
Rootcause: Due to the differences in the storage format of Bluetooth information in different system versions, in order to ensure that saved information can continue to be used after system upgrades, the storage transformation tool has been added.
Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
Since the current version_5_0_3 has no business logic and does not impact the existing storage structure, the GATT hash is reused in version_5_0_3.
New GATT hash items added in version_5_0_3 include:
1. Added enumeration value: BT_STORAGE_UPDATE_GATT_HASH_INFO
2. Added GATT hash removal logic within the bt_storage_properties_destroy function
3. Modified the bt_storage_update_item_size table
4. Added GATT hash items to the callback_cnt_list
5. Added GATT_cache save logic to the bt_storage_update_save_info function
Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
Rootcause: In scenarios where the test server listens, channel instances exist for awaiting accept operations. When the `bttool` exits directly, although the service can be notified to release corresponding resources via `bt_l2cap_unregister_callbacks`, the channel instances on the `bttool` side still require manual release to prevent memory leaks.
Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
Rootcause: An assessment of the throughput performance of the L2CAP service is required; consequently, the command `speed` has been added to measure the throughput of L2CAP connections.
Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
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>
Rootcause: The command stoplisten is provided to simulate scenarios where an application no longer accepts new L2CAP connections.
To implement this functionality, the is_listening flag has been introduced to assist in releasing channels used for listening.
Additionally, this modification optimises the input for the listen command, supporting both decimal and hexadecimal PSM input.
Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
Rootcause: The `l2cap_channel_t` structure type definition in `bttool` is identical to the Service type definition, resulting in GDB being unable to correctly parse variable contents when analysing coredump.
Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
1. adaptInfo add 'irk', and remote_device_le_properties_t add 'local_csrk'.
2. change storage version number to v5_0_3
3. add v5_0_2->v5_0_3 storage update function
Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
move PTS test char to tools/manager (replace SAL workaround); place Manager char value at tool (app) level.
Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>