Compare commits

...

733 Commits

Author SHA1 Message Date
copilot-swe-agent[bot] 587160a019 Initial plan 2026-02-02 02:54:42 +00: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
liuxiang18 3071f321df sal: bugfix for build error.
bug: v/84474

1. ../../frameworks/connectivity/bluetooth/service/stacks/zephyr/include/sal_zblue.h:36:30: error: unknown type name 'bt_transport_t'
2. ../../frameworks/connectivity/bluetooth/service/stacks/zephyr/sal_zblue.error: 'GATT_ROLE_SERVER' undeclared

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-02-01 15:15:06 +08:00
zhongzhijie1 4b24310592 bluetooth: improve LE connection event reporting with profile tracking
bug: v/64642

Root cause:
The original mechanism could not accurately identify which profile (e.g., GATTC, GATTS) initiated the connection. The connection callback relied only on link role, which led to edge cases and incorrect profile dispatch.

Changes:

Extend g_acl (now g_le_conn_info) array to include connection role flags.

Use addr-based slot matching to associate connection events with the correct profile after le_create_connect() calls.

Add helper APIs to manage and access g_le_conn_info:

le_conn_find() to locate connection info by address

le_conn_add() to allocate a new entry

le_conn_remove() to free an entry

le_conn_set_role() to set role flags and trigger profile callbacks

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-02-01 15:15:06 +08:00
liuxiang18 23f6535cef bluetooth: adapter ZEPHYR 4.0 SAL.
bug: v/60917

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-02-01 15:15:06 +08:00
zhongzhijie1 1ef939c9c7 support legacy advertising when ext adv is not supported
bug: v/82053

Root cause:
- The code assumed extended advertising is always supported.
- On some controllers, advertising start/stop could fail.
What changed:
- If ext adv is not supported, use `bt_le_adv_start()` (legacy path).
- If app asks for ext adv but controller does not support it, return `BT_STATUS_UNSUPPORTED`.
- If ext not support, also try `bt_le_adv_stop()` to stop legacy advertising.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-29 23:53:13 +08:00
zhongzhijie1 43c69af388 Extract AD/ScanRsp data parsing code
bug: v/84426

AD/ScanRsp parsing code was duplicated, Move parsing to a shared helper `parse_bt_adv_data()`.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-29 23:53:13 +08:00
zhongzhijie1 784bb0fd16 support filter_policy for LE advertising
bug: v/82052

`filter_policy` was ignored, so whitelist filtering did not work as expected.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-29 23:53:13 +08:00
liuxiang18 924643514c gatts: add gatts over br notification & indication
bug: v/84886

Added notification and indication handling for the gatt_over_br event in the sal layer

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-01-29 09:49:19 +08:00
liuxiang18 e694c837bf gatts:Implement the bt_sal_gatt_server_connect_bear interface
bug: v/84474

add att_over_br connected and disconnected callback, and replace le_conn_xx as bt_conn_xx

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-01-29 09:49:19 +08:00
liuxiang18 6d2a8219d2 sal: Change le_conn_info to bt_conn_info to make it compatible with both BREDR and BLE.
bug: v/84474

The modifications include the following:
1. rename le_conn_xx as bt_conn_xx
2. move interface from sal_adapter_le_interface.c to sal_zblue.c
3. add new formal parameters: transport

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-01-29 09:49:19 +08:00
liuxiang18 09d4d46be8 gatts: Implementation of GATT Service Registration
bug: v/84473

When a user defines a service using GATT_H_PRIMARY_SERVICE_OVER_BREDR, the corresponding start_hdl, end_hdl, and service UUID are registered in the SDP attribute.and service UUID are registered to the SDP.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-01-29 09:49:19 +08:00
liuxiang18 f168377115 gatts:Implement the `bt_sal_gatt_server_connect_bear` interface
bug: v/84474

Implement the bt_sal_gatt_server_connect_bear interface and connect att_over_br to the profile direct connection.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-01-29 09:49:19 +08:00
Lu Jia d167cc2478 avrcp: Fix the issue where the AVRCP CT cannot control the TG to switch songs.
bug: v/83779

When handling the handle_avrcp_passthrough_cmd function, the AVRCP Target (TG) does not report the PASSTHROUGH_CMD_ID_FORWARD and PASSTHROUGH_CMD_ID_BACKWARD events to the service. Instead, it directly responds to the peer device with BT_AVRCP_RSP_NOT_IMPLEMENTED, causing the peer device’s track switching control to fail.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-01-28 09:23:26 +08:00
chejinxian1 0d1d12fc66 L2CAP: add configuration parameter validation
bug: v/84214

- Add `l2cap_config_param` to validate MTU, MPS and credits
- Validate MTU does not exceed maximum buffer size
- Validate MPS is non-zero and MTU >= MPS for BLE transport
- Auto-adjust `init_credits` to valid range [min_credits, max_credits]
- Apply validation in both listen and connect operations
- Add rx_buf_size clamping to L2CAP_MAX_RX_BUF_SIZE in handle_channel_conneted() and l2cap_send_sdu_to_app_cb()

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-01-28 00:57:45 +08:00
chejinxian1 994a8c18f5 L2CAP: fix memory leak in `free_l2cap_channel`
bug: v/84457

Add missing cleanup for `rx_sdu` to prevent memory leak when freeing L2CAP channel. The `rx_sdu` buffer should be freed before the channel structure is released.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-01-28 00:57:45 +08:00
chejinxian1 e13928b015 bttool: L2CAP: add configurable mtu/mps/credits parameters
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>
2026-01-28 00:57:45 +08:00
chejinxian1 8c21590bdf bttool: L2CAP: add flow control commands for testing
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>
2026-01-28 00:57:45 +08:00
chejinxian1 c3190cf47c L2CAP: implement incoming credits refill mechanism
bug: v/84210

- Calculate additional credits based on available rx buffer space
- Call `bt_sal_l2cap_give_incoming_credits` to refill credits
- Update channel incoming credits after successful refill
- Initialize `rx_buf_size` based on initial credits and MPS
- Add `rx_buf_size` to connection log for debugging

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-01-28 00:57:45 +08:00
chejinxian1 70d8bd4720 L2CAP: add incoming credits validation and auto-refill mechanism
bug: v/84210

- Add credits validation before processing received packets
- Abort channel when receiving data without available credits
- Implement auto-refill mechanism when credits drop below `L2CAP_LE_CREDITS_LOW_WATERMARK`
- Ensure flow control compliance to prevent buffer overflow

This change enhances L2CAP flow control by validating incoming credits before accepting packets and automatically refilling credits when they fall below the low watermark threshold, preventing potential data loss and ensuring proper credit-based flow control operation.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-01-28 00:57:45 +08:00
chejinxian1 4714c37b7f L2CAP: improve error handling with unified channel abort
bug: v/84383

- Add `local_cid` validation in `handle_channel_conneted()` before disconnect
- Add `l2cap_abort_channel()` calls in error paths for consistent cleanup
- Call `l2cap_abort_channel()` in `l2cap_send_sdu_to_app()` on pipe write failure
- Call `l2cap_abort_channel()` in `handle_packet_received()` on MTU validation failure and SDU append overflow
- Ensure proper cleanup of pipe and L2CAP connection in all error conditions

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-01-28 00:57:45 +08:00
chejinxian1 0ccfab8279 L2CAP: Add SDU delivery and buffer management
bug: v/84209

- Add `rx_list` and `rx_buf_size` fields to `l2cap_channel_t` for SDU tracking
- Define `L2CAP_MAX_RX_BUF_SIZE` macro for maximum receive buffer size
- Initialize `rx_list` in `alloc_free_channel()`
- Initialize `rx_buf_size` in `handle_channel_conneted()` with overflow protection
- Clean up `rx_list` in `free_l2cap_channel()` to prevent memory leaks
- Implement `l2cap_send_sdu_to_app()` to deliver reassembled SDUs to app
- Add `l2cap_send_sdu_to_app_cb()` stub for write completion handling
- Track buffer usage with `rx_buf_size` (decremented on segment recieved)
- Queue delivered SDUs in `rx_list` for lifecycle management
- Handle pipe write failures with proper SDU cleanup

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-01-28 00:57:45 +08:00
chejinxian1 5294ad21bd L2CAP: add SDU reassembly support for segmented packets
bug: v/84190

- Add `rx_sdu` field to `l2cap_channel_t` for receiving SDU segments
- Implement SDU reassembly logic in `handle_packet_received()`
- Add validation for SDU length against MTU
- Handle single-segment and multi-segment SDU scenarios
- Decrease incoming credits for BLE transport
- Add `l2cap_send_sdu_to_app()` stub for future implementation

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-01-28 00:57:45 +08:00
chejinxian1 00271cfaae L2CAP: rename `init_credits` to `credits` for dynamic tracking
bug: v/84211

Change field name from `init_credits` to `credits` in `l2cap_endpoint_param_t` to better reflect its purpose of tracking credit changes dynamically, rather than just storing the initial credit value.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-01-28 00:57:45 +08:00
chejinxian1 fac056bc7d L2CAP: Add segmented SDU reception support with unified packet structure
bug: v/84189

This commit implements segmented SDU (Service Data Unit) reception handling for L2CAP channels, introducing a unified packet structure to manage both complete packets and segmented data reception.

Key changes:
- Define `L2CAP_CID_DYNAMIC_MIN` macro to specify the minimum dynamic CID value per Bluetooth Core Spec
- Define `l2cap_pkt_t` structure to unify packet data handling for both complete and segmented reception with length tracking
- Fix event name typo: `PACKET_RECEVIED_EVT` to `PACKET_RECEIVED_EVT`
- Implement `l2cap_on_segment_received()` function to handle segmented SDU reception with parameter validation and memory management

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2026-01-28 00:57:45 +08:00
v-yichenxi 3b306ae982 bluetooth: check remote address retrieval in HFP AG
bug: v/83166

Check bt_sal_get_remote_address() return value when creating HFP AG connection to avoid using an uninitialized address on failure.

Signed-off-by: v-yichenxi <v-yichenxi@xiaomi.com>
2026-01-27 15:03:39 +08:00
v-yichenxi 8a9ab0c65a bluetooth: check remote address retrieval
bug: v/83166

Check bt_sal_get_remote_address() return value in HID accept callback to avoid using an uninitialized address on failure.

Signed-off-by: v-yichenxi <v-yichenxi@xiaomi.com>
2026-01-27 15:03:39 +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 c7f1c0675f MultiConnect: add log for volume changed.
bug: v/84794

Rootcause: The current avrcp ct cannot quickly determine whether the media has set the volume to Bluetooth; logging is needed.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-01-26 14:02:53 +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
zhangyuan20 8456ee94d7 bluetooth: add dfx in android.
bug: v/84700

Rootcause: dfx should be added in android, or it will cause compilation problems.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-01-25 13:50:27 +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
v-chenghuijin 57ebf5d7f9 SPP: Fix race condition crash by unifying thread context for resource cleanup
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>
2026-01-23 09:22:13 +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
YuhengLi 2c35a23f62 zblue: hfp: ag: fix mem leak
bug: v/82382

Rootcause: mem not free in some case.
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-01-23 01:58:51 +08:00
Lu Jia 459c1fc3e3 Fix the issue where disable does not disconnect le ACL.
bug: v/84222

The safe disable method should disconnect the ACL connection.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-01-23 00:50:42 +08:00
Lu Jia 6fb9902889 Fix the issue where disabling fails when only BLE is enabled.
bug: v/84222

The bttool calls the disable API. While the SYS_TURN_OFF_SAFE event is received in ble_on_state, the ble_on_process_event handler fails to process this event, causing the disable operation to fail. Add handling for the SYS_TURN_OFF_SAFE event in ble_on_process_event and transition to the ble_turning_off_state.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-01-23 00:50:42 +08:00
liuxiang18 1b6e6215fe aync adv/scan: fix build error
bug: v/83666

The callback macro `CALLBACK_REMOTE` currently used in gatts/gattc employs the member variable `callbacks`. For enhanced versatility, the callback member variables in adv and scan have been modified from `callback` to `callbacks`.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-01-22 09:28:28 +08:00
liuxiang18 3bfade5f48 scan: fix coding error
bug: v/84177

The on_scan_start_status callback was incorrectly used in BT_LE_ON_SCAN_STOPPED. It has now been reverted to on_scan_stopped.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-01-22 09:28:28 +08:00
liuxiang18 c5b8a64347 socket: fix nullptr access when callback->member is NULL.
bug: v/84177

When a member variable is NULL within the scan_callback or adv_callback of the client call interface, the bt_socket_scan/adv fails to check for nullptr, resulting in a null address access.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-01-22 09:28:28 +08:00
liuxiang18 b95024eee5 adv/scan: rename member variables callback as callbacks
bug: v/83666

The callback macro `CALLBACK_REMOTE` currently used in gatts/gattc employs the member variable `callbacks`. For enhanced versatility, the callback member variables in adv and scan have been modified from `callback` to `callbacks`.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2026-01-22 09:28:28 +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
zhangyuan20 02745b9a3f Android-Vela: Fix AirPods silent issue.
bug: v/84346

Rootcause: Some older AirPods have a default volume of 0, resulting in no sound during calls and music playback. Therefore, should manually set the current volume when the device is connected.
Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-01-20 23:22:58 +08:00
zhongzhijie1 a83dced527 Fix build warning in zblue board.
bug: v/51103

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-14 14: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
zhongzhijie1 1f4cd62f5e Ensure that the app specifies a UUID instead of forcibly converting it to 128-bit.
bug: v/83302

rootcause:
The original design would directly convert all bt_uuid parameters to 128 bits. However, when adding a service using GATT, we need to consider the uuid_type. If a 16-bit UUID is registered as a 128-bit UUID, some GATT clients that only use discover by UUID with 16 bits might not be able to find the registered service.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-14 10:36:14 +08:00
Lu Jia f9754a49b5 gatts: Fix the issue of GATTs sending two write responses.
bug: v/83303

When the stack receives an att_write_req, it calls attr->write(). If the return value from SAL is -EINPROGRESS, the stack does not send a response, as the response will be handled by the service. Otherwise, the stack sends a response. In the SAL layer, bt_sal_on_ccc_written notifies the service, which then calls bt_sal_gatt_server_send_response. Since the return value from SAL is not -EINPROGRESS, the stack also sends a response, causing a conflict.

Signed-off-by: jialu <jialu@xiaomi.com>
2026-01-13 16:32:23 +08:00
zhongzhijie1 9ca633b9bd Add get db hash/service change_ind api only and implemnt it in furture
bug: v/65182

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-12 10:39:46 +08:00
liuxiang18 ae93faf1b4 storage update: add items-GATT HASH for storage update.
bug: v/65131

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>
2026-01-12 10:39:46 +08:00
zhongzhijie1 6730ed14a8 Patch for Clang format check.
bug: v/65203

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-12 10:39:46 +08:00
zhongzhijie1 098029d3e3 Add internal sal API to trigger GATT Service Changed indication.
bug: v/65182

Add bt_sal_gatt_server_change_indicate(start_hdl, end_hdl) with parameter validation.
Use the new SAL API from gatts_service when a hash mismatch is detected.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-12 10:39:46 +08:00
zhongzhijie1 483df41283 Add internal logic to request GATT database hash.
bug: v/65160

The server did not track the peer-synced GATT database hash.
Peers could keep a stale GATT cache and the stack could not detect a database change.
Request the latest database hash on GATT connection.
On hash event, compare with the stored value and decide the next action.
Update the stored hash after handling the event.
Compile the feature under CONFIG_BLUETOOTH_GATTS_CACHE_SUPPORT.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-12 10:39:46 +08:00
zhongzhijie1 79d3290d96 adapter_service: expose GATT hash operations for internel modules such
as gatts_service.

bug: v/65146

gatts_service could not access the adapter device database to read or update the stored GATT database hash.
Hash update and persistence were handled inside adapter_service only, so other modules could not drive cache sync.
Add adapter_get_device_gatt_hash() and adapter_set_device_gatt_hash() under CONFIG_BLUETOOTH_GATTS_CACHE_SUPPORT.
Only allow bonded devices and keep a zero hash when no valid hash is present.
Avoid duplicate db hash requests when DFLAG_GATT_HASH_VALID is already set.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-12 10:39:46 +08:00
zhongzhijie1 6d50d86c54 adapter_service: add support functions for GATT hash load/save.
bug: v/65142

Adapter did not load or persist the per-device GATT database hash state.
After reboot or unpair, the stack lost hash data and cache validation became unreliable.
Load GATT hash entries on LE enable and restore them into device objects.
Save updated hash list when bond state changes and clear hash on unpair.
Use bt_storage_load_gatt_cache_device and bt_storage_save_gatt_cache_device under CONFIG_BLUETOOTH_GATTS_CACHE_SUPPORT.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-12 10:39:46 +08:00
zhongzhijie1 7720b13e29 adapter remote_device: add 16 Bytes field for GATT database hash.
bug: v/65139

The device object had no field to keep the GATT database hash.
The stack could not persist and validate GATT cache state per bonded peer.
Add a 16-byte gatt_hash field under CONFIG_BLUETOOTH_GATTS_CACHE_SUPPORT.
Add get/set/delete helpers and export remote_device_gatt_properties_t data.
Add DFLAG_GATT_HASH_VALID to mark hash presence.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-12 10:39:46 +08:00
zhongzhijie1 24b6482b8e Add persistent storage of the GATT server database hash using KVDB.
bug: v/65135

KVDB backend had no key and no save/load path for GATT server database hash.
The system could not restore the hash after reboot and cache validation failed.
Add BT_KVDB_BLEGATTDBHASH and helpers to save/load remote_device_gatt_properties_t entries.
Count and delete old hash properties before saving new data.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-12 10:39:46 +08:00
zhongzhijie1 5526ca9f76 implement storage logic for GATT database hash.
bug: v/65131

There was no persistent storage for the server GATT database hash.
The system could not compare hashes after reboot and peers could keep a stale GATT cache.
Add remote_device_gatt_properties_t with 16-byte hash field.
Add save/load APIs for GATT hash cache using the uv_db backend (BT_KEY_BLEGATTHASH).

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-12 10:39:46 +08:00
zhongzhijie1 4d4f15eeb1 trigger GATT DB hash computation on first BLE bond.
bug: v/65129

Root cause:
The stack did not compute and store the server GATT database hash on initial bonding.
Peers could keep a stale GATT cache because no hash update was triggered.
When a bonded LE device is connected, send PROFILE_EVT_GATTS_REQUEST_DB_HASH.
Force hash update to start cache sync for the new bond.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-12 10:39:46 +08:00
zhongzhijie1 ff16970d67 implement handle_adapter_to_profile_event for generic message dispatch from adapter to profile.
bug: v/65126

Root cause:
Adapter had no generic message path to deliver events to profile services.
GATTS could not receive a request to fetch the server database hash.
Add adapter handler to forward profile_msg_t to service_manager.
Add PROFILE_EVT_GATTS_REQUEST_DB_HASH and handle it in gatts_service via process_msg.
Wire bt_sal_gatt_server_get_database_hash() call when the event is received.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-12 10:39:46 +08:00
zhongzhijie1 a74b84a6f9 Add SAL API and framework/service callback to retrieve current GATTS global database hash.
bug :v/65095

The logic is implemented in gatts_service.c to trigger hash calculation
and return the result via a registered callback, for trusted device sync and DB change tracking.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-12 10:39:46 +08:00
zhongzhijie1 6dd955a9ef Add Kconfig macro in framework service to control GATT server cache
support.

bug: v/65087

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-12 10:39:46 +08:00
zhongzhijie1 d70c16ccf7 update code ownwers of frameworks/bluetooth
Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-08 09:56:30 +08:00
YuhengLi 0cf595fdbf zblue: hfp: hf: add check when get remote address
bug: v/82928

Rootcause: bt_sal_get_remote_address may fail

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-01-07 20:57:01 +08:00
YuhengLi dd6e58afe6 zblue: hfp: hf: remove the redundant stack variable
bug: v/82928

Remove the redundant stack variable bd_addr, which already exists in sal_conn.

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-01-07 20:57:01 +08:00
v-yichenxi 54e536407f bluetooth: Fix null pointer dereference before null check issues.
bug: v/81520

In `spp_find_connection_by_sdp_param` and `spp_connect_with_uuid`, the pointer `spp_conn` was dereferenced before the NULL check. This patch ensures the pointer is validated before access to avoid potential crashes.

Signed-off-by: v-yichenxi <v-yichenxi@xiaomi.com>
2026-01-07 16:47:47 +08:00
YuhengLi 49a0c0ffce Android-Vela: fix problem that client can not receive cind callback
bug: v/61170

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2026-01-07 14:11:18 +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 ca8142629f Supports user confirmation during Just Work pairing in the app.
bug: v/81924

By default, just working (no I/O) should automatically accept user confirmation, but for compatibility with the watch app, app confirmation is required.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-07 11:41:13 +08:00
YuhengLi 13dae0fee7 zblue: hfp: hf: fix mem leak
bug: v/81701

Rootcause: unnecessary malloc
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2026-01-06 22:48:20 +08:00
YuhengLi abd1eaf88f zblue: hfp: hf: fix coverity issue
bug: v/81701

Rootcause: dereference null.
Signed-off-by: Yuheng Li <liyuheng@xiaomi.com>
2026-01-06 22:47:58 +08:00
zhongzhijie1 e829611cbc resolve gatts sal DB attribute quantity limit insufficient miwear total
bug: v/82104

The number of gatts sal DB attributes was insufficient for miwear's needs, so it was increased to a margin of 60. Future memory optimization projects will no longer maintain static arrays.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-05 13:09:54 +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
zhongzhijie1 77f6bff7a4 gatt: workaround BR/EDR service force to ble service.
bug: v/81958

Some services are marked with GATT_PROP_EXPOSED_OVER_BREDR, but current
not implement gatt over bredr. As a temporary workaround, clear
this flag when calling add_service() so the service is exposed over BLE.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-05 13:09:54 +08:00
zhongzhijie1 4835b315d8 support generic descriptors in alloc_descriptor()
bug: v/81925

Add a generic descriptor allocation path, matching alloc_characteristic() style.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-05 13:09:54 +08:00
zhongzhijie1 9cf4c8e9de fix: resolve SPP connection lookup failure
bug: v/82095

The spp_connect_handler was attempting to look up the SPP connection
by rfcomm_dlc before it was added to the connection list, causing
"SPP connection not found for rfcomm_dlc" error.

Root Cause:
The connection object wasn't in the global connection list at the
time of lookup, making spp_find_connection_by_dlc() always fail.

Fix:
Pass the spp_conn pointer directly as user_data to avoid the lookup,
and add it to the connection list after successful initialization.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-05 13:09:54 +08:00
zhongzhijie1 04870f29b7 fix build warning when close avrcp control
bug: v/74709

only open CONFIG_BLUETOOTH_AVRCP_CONTROL or CONFIG_BLUETOOTH_AVRCP_ABSOLUTE_VOLUME can build in bt_avrcp_control_notification_cb.

error: 'bt_avrcp_info_find_by_ct' undeclared (first use in this function); did you mean 'bt_avrcp_info_find_by_tg'?
 1501 |     avrcp_info = bt_list_find(bt_avrcp_conn, bt_avrcp_info_find_by_ct, ct);
      |                                              ^~~~~~~~~~~~~~~~~~~~~~~~
      |                                              bt_avrcp_info_find_by_tg

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2026-01-05 13:09:54 +08:00
chejinxian1 58d2179d91 SPP: Enhance SPP device cleanup and connection handling with new close callback
bug: v/80808

Rootcause: In high-throughput reception scenarios, situations may arise where the `write_cb` for SPP data transmission to the application has not yet completed, yet the SPP device is released due to an abrupt disconnection, thereby preventing notification to the protocol stack that data reception has concluded.

To circumvent this issue, it is imperative to ensure all write operations are finalised before releasing the SPP device. Consequently, an `euv_pipe` close callback implementation has been introduced to guarantee that all `write_cb` operations execute successfully prior to severing the data pathway.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-12-29 10:35:53 +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
Lu Jia 71f0c43ff1 bluetooth: Fix resource leak issues when initializing the client with an asynchronous API.
bug: v/81682

When priv dynamically allocates memory successfully but fails later due to other reasons before reaching the assignment ins->priv = priv;, the memory allocated to priv cannot be freed in bt_socket_async_client_deinit, leading to a resource leak.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-12-26 18:39:37 +08:00
YuhengLi 42e243c03c zblue: hfp: ag: fix cannot connect ag after disconnect ag.
bug: v/81968

Rootcause: disconnected_callback not called caused connect info not cleared in connection manager module

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-26 12:05:40 +08:00
YuhengLi fe34376458 zblue: hfp: ag: fix crash when connect sco
bug: v/81752

Rootcause: audio_connect should not be called in bluetoothd task
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-25 14:15:38 +08:00
YuhengLi 9902692ca3 zblue: hfp: ag: fix crash in some cases
bug: v/80258

Rootcause: attributes in bt_sdp_discover_params may be modified by ZBlue SDP. Using const could cause a crash in some cases
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-25 14:15:38 +08:00
liuxiang18 a5bb09a566 coverity: fix memleak.
bug: v/81702

Fixed memory leak caused by premature return.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-12-24 14:29:42 +08:00
Lu Jia f3ba3987b7 bluetooth: fix the logical dead code issue.
bug: v/81522

When event_id == BT_AVRCP_EVT_VOLUME_CHANGED, flag = true is set only if both CONFIG_BLUETOOTH_AVRCP_ABSOLUTE_VOLUME and CONFIG_BLUETOOTH_AVRCP_CONTROL are enabled.
Otherwise in the else branch, flag = true is set only if CONFIG_BLUETOOTH_AVRCP_TARGET is enabled. All configurations are enabled, treating flag as always true, making the if (!flag) condition unreachable.

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-24 14:25:12 +08:00
YuhengLi 94d4fa1c2a zblue: hfp: ag: fix crash when enable bluetooth after disable
bug: v/80268

Rootcause: Not unregister callbacks when cleanup.
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi f53d2576a8 zblue: hfp: ag: using BT_HFP_AG_CALL_STATUS_UNKNOWN instead of -1
bug: v/81504
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 2709e30e08 zblue: hfp: ag: remove global var g_sal_ag_sync_conn
bug: v/81589

remove global var g_sal_ag_sync_conn and sync  call by addr

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 8aaad71be6 zblue: hfp: remove unused functions
bug: v/81567

remove unused functions

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi c36eb5d4db zblue: hfp: ag: use real dial result
bug: v/81504

return -EINPROGRESS dial callback and send OK after dial response

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi b04a2fab3a zblue: hfp: ag: add logs to print call number when sync
bug: v/80269

Rootcause: add logs to print call number when sync
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi a6f9d1cea4 zblue: hfp: ag: fix connect fail
bug: v/80268

Rootcause: should not call unref at this time
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 7a45da74ca zblue: hfp: ag: adapt new profile direct connect api
bug: v/80268

Rootcause: profile direct connect api has changed
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 744a902e29 zblue: hfp: ag: fix ARRAY_SIZE redefine warning.
bug: v/80258

Rootcause: ARRAY_SIZE redefined
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi b6d1040bb9 zblue: hfp: ag: profile direct connect
bug: v/80268

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi e7001f10d6 zblue: hfp: ag: fix: CIND value send fail when connect
bug: v/81589

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi ee89f146e6 zblue: hfp: ag: fix: unexpected disconnect when connect.
bug: v/80268

Rootcause: unref conn before use
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 99def1db98 zblue: hfp: ag: disconnect profile when remote does not support HFP HF.
bug: v/80268

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 0b0934b93e zblue: hfp: implement bt_sal_hfp_ag_send_at_cmd API and callback
bug: v/80270

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 63076eac76 zblue: hfp: ag: implement transmit_dtmf_code callback
bug: v/81606

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi ce8374972d zblue: hfp: ag: implement voice_recognition callback
bug: v/80279

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 40baac46b6 zblue: hfp: ag: implement vgm/vgs callback
bug: v/80279

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 647d483d41 zblue: hfp: ag: implement terminate callback
bug: v/81606

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 7464dd39ff zblue: hfp: implement reject callback
bug: v/81606

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 21e6488814 zblue: hfp: ag: implement retieve callback
bug: v/81606

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 8039443ac9 zblue: hfp: ag: implement held callback
bug: v/81606

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi fba96936bf zblue: hfp: implement answer callback
bug: v/81606

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 82f3d007ed zblue: hfp: implement incoming_held callback
bug: v/81606

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi dfe890ea6c zblue: hfp: ag: implement incoming callback
bug: v/80269

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 1d4e47a9ec zblue: hfp: ag: implement outgoing callback
bug: v/81504

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 34f599b1be zblue: hfp: ag: implement bt_sal_hfp_ag_set_volume
bug: v/81589

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 00e65e4dae zblue: hfp: implement bt_sal_hfp_ag_set_inband_ring_enable
bug: v/81567

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 6c492b47aa zblue: hfp: ag: implement bt_sal_hfp_ag_notify_device_status_changed
bug: v/81589

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi cf5f1df054 zblue: hfp: ag: implement bt_sal_hfp_ag_cops_response
bug: v/81589

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 876dc70179 zblue: hfp: ag: implement bt_sal_hfp_ag_dial_response
bug: v/81504

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi a03b00b116 zblue: hfp: ag: implement bt_sal_hfp_ag_clcc_response
bug: v/81604

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi abc873e5b7 zblue: hfp: ag: implement bt_sal_hfp_ag_phone_state_change API
bug: v/81589

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 32b4aac49d zblue: hfp: implement vr start/stop API
bug: v/80279

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 0c4353c644 zblue: hfp: ag: implement number_call callback
bug: v/81504

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi c4ab84ddb3 zblue: hfp: ag: implement bt_sal_hfp_ag_cind_response API
bug: v/81589

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi de4875d2df zblue: hfp: ag: implement audio disconnect API and callback
bug: v/80279

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 3602dac941 zblue: hfp: ag: implement audio connect API and callback
bug: v/80279

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 1ef3d009af zblue: hfp: ag: implement ag disconnect API and callback
bug: v/80268

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
YuhengLi 3281ce6841 zblue: hfp: ag: implement ag connect API and callback
bug: v/80268

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-23 23:48:03 +08:00
wuxiaodong6 7bbb16b160 delete spp_lock in spps
bug: v/80501

rootcause: in spps, all locks are called by a single thread called bluetoothd, and there are no race conditions, so locks can be optimized.

Signed-off-by: wuxiaodong6 <wuxiaodong6@xiaomi.com>
2025-12-23 00:31:25 +08:00
Lu Jia 6c9dc5503b bluetooth: Fix resource leak issue.
bug: v/80614

When the family is not AF_LOCAL or AF_RPMSG, the function returns immediately without freeing the memory allocated for 'priv', leading to a memory leak.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-12-20 12:56:06 +08:00
Lu Jia cbea408ece bluetooth: Add initialization for local variables.
bug: v/80616

When passed to bt_socket_client_send_with_reply , it may contain undefined values, leading to unpredictable behavior. Initialize packet explicitly before using it.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-12-20 12:56:06 +08:00
Lu Jia 373a30ccc0 bluetooth: Add initialization for local variables.
bug: v/80617

When passed to bt_socket_client_send_with_reply , it may contain undefined values, leading to unpredictable behavior. Initialize packet explicitly  before using it.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-12-20 12:56:06 +08:00
Zihao Gao d7c85ed056 IPC: Add nullptr protection.
bug: v/80282

Rootcause: missing NULL check before uv_read_stop.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-12-19 17:33:17 +08:00
liuxiang18 3187ead586 storage: fix build error - add config dependency
bug: v/73508

During build ap_test, BLUETOOTH_SERVICE was not enabled, resulting in `service_loop.c` used by the storage module not being compiled. This caused an LD error.

/home/work/data/miui_codes/build_home_rom/out/bes_o62_ap_performance_test/../../frameworks/connectivity/bluetooth/service/common/storage_property.c:72:(.text.bt_storage_save_le_remote_device.constprop.0+0x78): undefined reference to `service_loop_work'

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-12-19 16:12:53 +08:00
liuxiang18 080d24168b storage_update: fix build error - main(void) error
bug: v/73508

change `int main(void)` to `int main(int argc, char** argv)`;

apps/builtin/builtin_proto.h:44: error: type of 'bt_storage_update_main' does not match original declaration [-Werror=lto-type-mismatch]

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-12-19 16:12:53 +08:00
liuxiang18 2468a9a090 storage: fix build warning
bug: v/73508

1. error: 'ret' may be used uninitialized [-Werror=maybe-uninitialized]
2. tools/storage_update/storage_version_4.c:62:74: error: format ‘%d’ expects argument of type ‘int’, but argument 6 has type ‘long unsigned int’ [-Werror=format=]

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-12-19 16:12:53 +08:00
liuxiang18 2aa93386fd storage update: enable storage update module.
bug: v/80712

change BLUETOOTH_STORAGE_UPDATE default value to 'y'.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-12-19 16:12:53 +08:00
liuxiang18 def4c56f8f stroage: change default storage to BLUETOOTH_STORAGE_PROPERTY_SUPPORT.
bug: v/80711

Migrate storage from Unqlite to KVDB.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-12-19 16:12: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
zhongzhijie1 6426035e6f always report BONDED on pairing_complete callbacks
bug: v/80684

Treat pairing_complete as a successful bonding result and always report
BOND_STATE_BONDED to upper layers for both BR/EDR and BLE.

The business logic doesn't need to distinguish the no_bonding state.
This behavior is consistent with the legacy Bluetooth stack.

Also remove bond state reporting from link_key_notify and rely on
pairing_complete to deliver bond state updates.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-12-18 15:42:18 +08:00
zhongzhijie1 c3237bd37f remove connection state check in security changed callback
bug: v/78493

rootcause:
ACL state changes can occur before security changes, causing the
BT_CONN_STATE_CONNECTED check to incorrectly skip bond key removal
when authentication fails.

Remove the state guard to ensure failed bond keys are always cleaned
up via bt_br_unpair() and bond state changes are properly reported,
regardless of current connection state.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-12-18 15:39:10 +08:00
zhongzhijie1 54b81bb936 fix uninitialized profile handler list in CM manager
bug: v/79367

Root cause:
A connection manager could be allocated and added to the disconnecting list
without initializing profile_conn_handler_list.

In this case, bt_connection_manager_find() may successfully match the manager
by device address, but subsequent operations (e.g. bt_list_is_empty()) access
a NULL handler list, leading to assertion failure and use-after-free issues.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-12-18 15:38:43 +08:00
zhongzhijie1 f8626513d0 fix: Add missing disconnect callbacks following service callback pattern
bug: v/79519

Adjust profile callbacks to properly follow service callback principles,
Ensures proper integration with connection manager state tracking.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-12-18 15:38:43 +08:00
Kai Cheng 231cca859e fix: resolve SPP connection lookup failure
bug: v/79519

The spp_connect_handler was attempting to look up the SPP connection
by rfcomm_dlc before it was added to the connection list, causing
"SPP connection not found for rfcomm_dlc" error.

Root Cause:
The connection object wasn't in the global connection list at the
time of lookup, making spp_find_connection_by_dlc() always fail.

Fix:
Pass the spp_conn pointer directly as user_data to avoid the lookup,
and add it to the connection list after successful initialization.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-18 15:38:43 +08:00
zhongzhijie1 02425b18dc drop async dispatch for CM profile callbacks
bug: v/80258

Root cause:
bt_sal_cm_profile_connected_callback was dispatched asynchronously via the
service loop, while bt_sal_profile_disconnect_register is synchronous.

This mixed async/sync execution model caused a lifetime mismatch of CM manager
resources. The async connected callback could run after the manager state had
already been updated or released by the synchronous disconnect path, leading
to a use-after-free issue in the manager.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-12-18 15:38:43 +08:00
duqunbo 665a1768d7 AVRCP: Use the media stream of A2DP sink to manage the AVRCP volume.
bug: v/58697

rootcause: Separate the a2dp sink stream from the music stream to avoid mutual influence with other music streams.

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2025-12-16 22:34:47 +08:00
YuhengLi b25151d2dd zblue: hfp: hf: format code
bug: v/80258

Rootcause: clang-format

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-15 17:34:01 +08:00
YuhengLi 77c516ccec zblue: hfp: hf: fix crash in some cases
bug: v/80258

Rootcause: attributes in bt_sdp_discover_params may be modified by ZBlue SDP. Using const could cause a crash in some cases
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-15 17:34:01 +08:00
chejinxian1 208eef2765 bttool: Implement cleanup function for L2CAP channels on uninitialization
bug: v/78842

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>
2025-12-15 10:54:59 +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 9e5c9ecb2f bttool: Implementation of L2CAP throughput testing commands
bug: v/78789

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>
2025-12-15 10:54:59 +08:00
chejinxian1 b422587be5 bttool: Refactor connection parameters to use defined constants and improve command parameters input
bug: v/78788

Replace hard-coded connection parameters with macro definitions.

Introduce `strtoul` to optimise command parameter reading.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-12-15 10:54:59 +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 f8c2561c83 bttool: Implement the stoplisten command in L2CAP
bug: v/70058

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>
2025-12-15 10:54:59 +08:00
chejinxian1 125cd50688 bttool: Rename `l2cap_channel_t` to `l2cap_chnl_t` for consistency
bug: v/73869

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>
2025-12-15 10:54:59 +08:00
chejinxian1 f688ab0987 bttool: Add usage function to display l2cap command information
bug: v/70058

Add L2CAP command usage prompts to guide testing operations.

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
chejinxian1 78b6dc609d L2CAP: Free index on allocation failure in channel creation
bug: v/78758

Rootcause: There exists a potential error scenario wherein the creation of an `l2cap_channel_t` instance fails due to memory allocation failure. Previously, such scenarios failed to release the allocated ID, resulting in the loss of ID resources.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-12-15 10:54:59 +08:00
chejinxian1 3eb5bb4697 L2CAP: Add a resource release functionality when the app unregister.
bug: v/70790

Rootcause: Only the corresponding app has the authority to operate on the L2CAP channels it created. Therefore, when the app unregister, it should release all associated resource allocations.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-12-15 10:54:59 +08:00
chejinxian1 50f6ee3817 L2CAP: Add transmit flow control to the L2CAP Service.
bug: v/70062

Rootcause: Add transmit flow control to the L2CAP Service to prevent packet buildup in the protocol stack.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-12-15 10:54:59 +08:00
chejinxian1 8982a80624 L2CAP: Rename channel roles for clarity in server operations
bug: v/78758

Rootcause: As the role types `L2CAP_CHANNEL_ROLE_SERVER` and `L2CAP_CHANNEL_ROLE_ACCEPT` within `l2cap_channel_t` conflate the concepts of listen and accept in connection contexts, these two enumeration types shall be renamed.

`L2CAP_CHANNEL_ROLE_SERVER` corresponds to `L2CAP_CHANNEL_ROLE_SERVER_LISTEN`, identifying an `l2cap_channel_t` instance on the Server side awaiting incoming connections.

`L2CAP_CHANNEL_ROLE_SERVER_ACCEPT` corresponds to `L2CAP_CHANNEL_ROLE_ACCEPT`, identifying a server-side l2cap_channel_t instance that has established an L2CAP connection with a specific client.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-12-15 10:54:59 +08:00
liuxiang18 5495c21435 ble: fix the issue where `key->addr` is empety due to keys clear.
bug: v/79394

bt_unpair invokes the unpair function, where the bond_delete callback occurs before keys_clear. keys_clear sets memset(&keys->addr, 0, sizeof(bt_addr_le_t)), causing the bond_delete callback to reference an empty address.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-12-14 21:07:54 +08:00
liuxiang18 554d99be98 storage_update: fix build error.
bug: v/73508

ARRAY_SIZE() is defined at "bt_utils.h"

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-12-14 21:07:54 +08:00
liuxiang18 c97efa56c1 storage_update: update from v5_0_2 to v5_0_3.
bug: v/79395

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>
2025-12-14 21:07:54 +08:00
liuxiang18 b6bcfdfc12 storage: add "irk" notify and load callback implement.
bug: v/79393

Implement the SAL layer callback function for settings storage.
include:
BLE: zblue_on_irk_notify
     zblue_on_irk_load

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-12-14 21:07:54 +08:00
liuxiang18 635db1a6a5 bluetooth: add zblue settings save & load implement - BREDR linkkey.
bug: v/79394

Implement the SAL layer callback function for settings storage.
include:
1. SAL zblue_on_linkkey_notify & zblue_on_linkkey_load
2. add adapter_get_link_key API
3. add adapter_get_link_key_type API

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-12-14 21:07:54 +08:00
liuxiang18 26cdd597f0 bluetooth: add zblue settings save & load implement - BLE keys.
bug: v/79394

Implement the SAL layer callback function for settings storage.
include:
1. SAL zblue_on_ltk_notify & zblue_on_ltk_load
2. add adapter_get_smp_data API
3. add adapter_get_local_csrk API

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-12-14 21:07:54 +08:00
YuhengLi 6af982c3fb Bluetooth: Sal: initlize device before using it.
bug: v/74408

Rootcause: var device not initlized before using.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2025-12-14 15:13:32 +08:00
Lu Jia 7ac84381f7 bluetooth: Fix the heap-use-after-free issue in the A2DP module.
bug: v/80443

After calling int bt_a2dp_stream_release(struct bt_a2dp_stream *stream), both release_rsp and released events will be triggered. When rsp_err_code in release_rsp is non-zero, bt_a2dp_stream_released is invoked, causing the SAL stream memory to be freed. If the protocol stack accesses stream afterward, it leads to a heap-use-after-free error.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-12-11 23:45:40 +08:00
gaoyuan28 48361b8611 bluetooth: Fix the heap-use-after-free issue in the A2DP module.
bug: v/80443

The protocol stack uses ep->stream = stream, where the 'stream' variable comes from SAL. After a2dp_info_destroy is called, SAL's 'stream' is freed, but the protocol stack still references ep->stream, causing a heap-use-after-free error. To fix this, change the 'stream' variable to a pointer and set it to NULL after SAL releases the 'stream' memory.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-12-11 23:45:40 +08:00
Kai Cheng 9166bbb3f6 Bluetooth: SPP: Add ACL connection manager feature
bug: v/79672

Add ACL connection manager feature, include acl
connect request feature, and many conenctions
feature.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-11 18:17:54 +08:00
zhongzhijie1 c4109efec5 support hfp hf profile connect interface.
bug: v/77997

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-12-11 18:17:54 +08:00
Kai Cheng 1279dc71aa Bluetooth: HID: Add ACL connection manager feature
bug: v/79672

Add ACL connection manager feature, include acl
connect request feature, and many conenctions
feature.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-11 18:17:54 +08:00
zhongzhijie1 13dba37e5f use micro CONN_ID_DEFAULT 0x0001 instead of number 0.
bug: v/78961

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-12-11 18:17:54 +08:00
zhongzhijie1 cbd8486e0c adapt avrcp profile to latest profile connection manager API.
bug: v/78961

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-12-11 18:17:54 +08:00
zhongzhijie1 58fd5d5bd9 adapt adapter interface to latest profile connection manager API.
bug: v/78961

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-12-11 18:17:54 +08:00
zhongzhijie1 2d7665563f adapt a2dp profile to latest multi conn instance and user data API.
bug: v/78961

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-12-11 18:17:54 +08:00
zhongzhijie1 6c1b11cfed implement user_data and multi connection instannce per profile manager
bug: v/78961

remove redundant flag based judge logic, instead of conn node's busy
state.

Each handler node represents a conn instance.

User_data can be transmitted through the cb Profile register, and the conn_id and profile_id are used to identify the conn instance of a specific profile.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-12-11 18:17:54 +08:00
zhongzhijie1 a39f1ad0e2 sal_connection_manager API support user_data field and multi connection
instance para.

bug: v/78961

add user_data and conn_id per profile feature.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-12-11 18:17:54 +08:00
zhongzhijie1 b18438ec89 refine security changed handling for BR/EDR authen fail case
bug: v/78493

1. send bond_none and delete store key bt_br_unpair like
adapter_le_interface.

2. updates BR/EDR security handling to avoid actively
disconnecting the ACL link when err is not AUTH_FAIL (e.g. key
missing). In these cases keeping the link alive in
Host allows to trigger a re-pairing procedure as required
by the Bluetooth BR/EDR security model.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-12-11 13:24:39 +08:00
zhongzhijie1 1903a03ff2 fix wrong return branch in zblue_inquiry_eir_name.
bug: v/79125

use correct 'return false;' instead of 'false', and if eir[0] <= 1,
means there is no valid name field, need return false.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-12-11 13:23:24 +08:00
Kai Cheng 55a3787b27 Bluetooth: SPP: delay cleanup rfcomm dlc
bug: v/79519

zblue worker would refer rfcomm dlc worker even if
rfcomm has disconnected. then we need to delay cleanup.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-11 11:57:32 +08:00
Kai Cheng 1c6809b88c Bluetooth: SPP: fix spp cleanup exception
bug: v/79519

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-11 11:57:32 +08:00
Kai Cheng 1bd69b1d62 Bluetooth: SPP: fix spp send buffer overflow
bug: v/79520

SPP buffer referenced in stack bufer manager

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-11 11:57:32 +08:00
Kai Cheng db042f72d4 Bluetooth: SPP: fix spp sdp access wild discover_params
bug: v/79670

fix spp sdp access wild discover_params when remote spp
sdp record was invalid

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-11 11:57:32 +08:00
Kai Cheng 73e28f7fd9 Bluetooth: SPP: add rfcomm unregister feature
bug: v/79519

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-11 11:57:32 +08:00
Kai Cheng fb7b326081 Bluetooth: SPP: fix spp write invlad rfcomm dlc
bug: v/79520

when get spp connection, it maybe get wild ptr,
then we need to check rfcomm dlc.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-11 11:57:32 +08:00
Kai Cheng dffc5d9bed Bluetooth: SPP: fix not support multi spp conn
bug: v/79672

fix mult spp conn match exception

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-11 11:57:32 +08:00
Kai Cheng ce6724811c Bluetooth: SPP: fix sdp buf pool exception
bug: v/79670

SDP memory management error occurs when operations
are performed repeatedly.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-11 11:57:32 +08:00
YuhengLi ef7c892b27 zblue: hfp: hf: fix crash when enable bluetooth after disable
bug: v/80021

Rootcause: Not unregister callbacks when cleanup.
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 033c0487de zblue: hfp: hf: fix hangup fail when multicall using
bug: v/80184

Rootcause: Use terminate stact API which is designed for single call control when multicall using

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 28a2de9356 zblue: hfp: hf: fix SCO context not found when disconnect
bug: v/80025

Rootcause: SCO context not recorded when connect

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi a52ae77f97 zblue: hfp: hf: profile direct connect
bug: v/77997

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
Yuheng Li fea1edd625 zblue: hfp: hf: fix ARRAY_SIZE redefine warning.
bug: v/80258

Rootcause: ARRAY_SIZE redefined

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 67b309f087 zblue: hfp: hf: implement cleanup api
bug: v/77997

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 6a76432632 zblue: hfp: hf: add command complete callback
bug: v/78600

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi a9c98b6d3d zblue: hfp: hf: fix crash when connect after disconnect.
bug: v/80258

Rootcause: unnesessary unref.

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi ca49e1e291 zblue: hfp: hf: redial when bt_sal_hfp_hf_dial_number was called with a NULL number
bug: v/80258

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 3102f5af68 zblue: hfp: hf: fix: crash when connect
bug: v/80258

Rootcause: unref connection context before use

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 6d0913d78a zblue: hfp: hf: add command complete queue
bug: v/78600

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 6976814da4 zblue: hfp: hf: implement vendor_specific API and callback
bug: v/78306

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi f7a22f985a zblue: hfp: implement bt_sal_hfp_hf_send_dtmf API
bug: v/78000

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 199e1ae9bf zblue: hfp: implement bt_sal_hfp_hf_send_battery_level API
bug: v/78000

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 0565f7e313 zblue: hfp: implement bt_sal_hfp_hf_start/stop_voice_recognition API
bug: v/80257

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi fa04c40172 zblue: hfp: implement bt_sal_hfp_hf_set_volume API
bug: v/78000

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 0a93bc305e zblue: hfp: implement bt_sal_hfp_hf_call_control API
bug: v/80256

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi c33cd7ae1d zblue: hfp: implement bt_sal_hfp_hf_hangup_call API
bug: v/80256

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi ca4130187a zblue: hfp: implement bt_sal_hfp_hf_hold_call API
bug: v/80256

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi c5b098cdc7 zblue: hfp: implement audio connect/disconnect API and callback
bug: v/80257

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 7624b23453 zblue: hfp: implement bt_sal_hfp_hf_connect_audio API
bug: v/80257

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 34149e5b9e zblue: hfp: implement ring_indication callback
bug: v/78000

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 4f88e893dc zblue: hfp: implement remote_ringing callback
bug: v/78000

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 243240e3ab zblue: hfp: implement voice_recognition callback
bug: v/77999

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 8595a5c088 zblue: hfp: implement codec_negotiate callback
bug: v/77999

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi a2706334f8 zblue: hfp: implement vgm and vgs callback
bug: v/77999

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 5827ad0aef zblue: hfp: implement CLIP callback
bug: v/77999

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 03e521ee13 zblue: hfp: implement call retrieve callback
bug: v/80256

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 6647769e81 zblue: hfp: implement call held callback.
bug: v/80256

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi a316e2185b zblue: hfp: implement call terminate callback.
bug: v/80256

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 31e94dd8c9 zblue: hfp: implement outgoing call callback
bug: v/80256

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 0f7aba71c8 zblue: hfp: implement call accept callback.
bug: v/80256

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 086fa564b8 zblue: hfp: implement call rejected callback.
bug: v/80256

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 8dd48f0430 zblue: hfp: implement reject call api
bug: v/80256

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi 0f68596808 zblue: hfp: implement disconnect API and callback
bug: v/77997

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi e1986c51b1 zblue: hfp: implement CNUM API and callback.
bug: v/78000

Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
YuhengLi fa97c92438 zblue: hfp: hf: disconnect profile when sdp fails
bug: v/77997
Signed-off-by: YuhengLi <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
liyuheng 191be9d2ec zblue: hfp: implement CLCC API and callback
bug: v/78002

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
liyuheng 6b9f1c7361 zblue: hfp: implement ATD API
bug: v/78000

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
liyuheng 699e7a382b zblue: hfp: implement ATA
bug: v/78000

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
liyuheng 2614fcde85 zblue: hfp: implement incoming call callback
bug: v/77999

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
liyuheng e221f5facb zblue: hfp: implement hf connect
bug: v/77997

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
liyuheng f821eff90c zblue: hfp: add connections list to store connection info
bug: v/77997

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
liyuheng dc57b9ac6e zblue: hfp: add empty HFP AG implementation
bug: v/77997

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
liyuheng 5a35671379 zblue: hfp: add empty HFP HF implementation
bug: v/77997

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
liyuheng 48c01df5b3 zblue: add sal hfp C file
bug: v/77997

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
liyuheng f446c71611 zblue: add sal API declarations
bug: v/77997

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2025-12-10 21:33:32 +08:00
Lu Jia e0730d4d64 bluetooth: Fix the bluetoothd hang issue.
bug: v/79594

During music playback, the SAL (Stream Abstraction Layer) sends audio data to the protocol stack depending on the number of buffers available in the pool (CONFIG_BT_MAX_CONN). When no buffers are available, bluetoothd gets stuck due to the K_FOREVER setting used during buffer allocation. Changing K_FOREVER to K_NO_WAIT ensures the bluetoothd thread will not be blocked.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-12-10 19:57:19 +08:00
Lu Jia 3f76d3a763 bluetoth: Fix the issue of duplicate initialization in AVRCP.
bug: v/79703

When both AVRCP CT and AVRCP ABSOLUTE VOLUME are enabled, the AVRCP CT service invokes bt_sal_avrcp_target_init. If AVRCP TG is also enabled, its service will invoke bt_sal_avrcp_target_init again, registering avrcp_tg_rec twice. However, the protocol stack lacks a deduplication mechanism, resulting in duplicate entries and a cyclic linked list.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-12-10 17:52:18 +08:00
Lu Jia c4b59ecfb6 bluetooth: Fix the issue where AVRCP fails to retrieve song information.
bug: v/79788

When the length of a song's attribute is 0, both types and chr_sets of that attribute are set to the default value 0. During message processing on the client side, the attribute's text is not assigned a NULL value due to types = 0. This leads to an error during string length calculation (strlen) when the feature processes the callback.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-12-10 16:22:40 +08:00
zhongzhijie1 cc3669acd9 fix dangling user_data pointer in characteristic allocation
bug: v/79370

Previously, when allocating GATT characteristic attributes, we directly
passed the gatt_element_t* pointer as user_data with user_data_len=0,
triggering shallow copy in gatt_db_add():

    attr->user_data = pattern->user_data;  // Direct pointer assignment

This created issue:
Memory management conflict: remove_service() unconditionally calls free()
   on all user_data pointers:

    for (i = 0; i < count; i++) {
        free(start[i].user_data);  // Assumes heap-allocated memory
        free((void*)start[i].uuid);
    }

Solution: Introduce gatt_user_data wrapper with deep copy to ensure
consistent heap-based memory management:

    struct gatt_user_data {
        gatt_element_t* element;
        uint16_t len;
        uint8_t value[];
    };

In alloc_characteristic():
    struct gatt_user_data user_data = { 0 };
    user_data.element = ch->element;

    // Pass sizeof(user_data) to trigger malloc + memcpy in gatt_db_add()
    attr_value = gatt_db_add(..., sizeof(user_data));

Update accessor functions (read_value, write_value, send_indication_result)
to unwrap the pointer:
    struct gatt_user_data* user_data = attr->user_data;
    gatt_element_t* element = user_data->element;

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-12-10 16:00:36 +08:00
Lu Jia a2a7026bca bluetooth: Resolve reconnection abnormalities after removing the bond.
bug: v/79367

During removebond, when all profiles have been disconnected, the manager is removed from the connection manager list in remove_from_connection_manager_list. However, bt_sal_remove_bond_internal is not called in bt_sal_cm_acl_disconnected, leading to the link key not being deleted. As a result, when the phone initiates a connection next time, the pairing dialog does not pop up, and the connection succeeds directly.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-12-10 15:53:32 +08:00
wuxiaodong6 8b8bdf8518 delete pan_lock in panus
bug: v/79341

rootcause: in panus, all locks are called by a single thread called bluetoothd, and there are no race conditions, so locks can be optimized.

Signed-off-by: wuxiaodong6 <wuxiaodong6@xiaomi.com>
2025-12-10 00:32:22 +08:00
Kai Cheng d90ac58a8b bluetooth: fix SMP build warning
bug: v/76636

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-08 23:11:13 +08:00
Kai Cheng 080b681c38 bluetooth: fix build warning when close BT_LOGD
bug: v/76636

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-08 23:11:13 +08:00
Kai Cheng 73b5a6d862 bluetooth: fix bt_adapter_set_debug_mode warning
bug: v/76636

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-08 23:11:13 +08:00
Kai Cheng 8d8dc017e6 blueototh: fix audio build break in le only mode
bug: v/76636

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-08 23:11:13 +08:00
Kai Cheng 10ec9d0ff6 bluetooth: fix gatt moudle ci break
bug: v/76636

fix gatt moudle ci break with condition config

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-08 23:11:13 +08:00
Kai Cheng 3a88f890a9 bluetooth: fix connectionmgr ci break
bug: v/76636

fix connectionmgr ci break with CONFIG_BLUETOOTH_CONNECTION_MANAGER

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-08 23:11:13 +08:00
Kai Cheng 35551deab8 bluetooth: fix bt_trace module ci break
bug: v/76636

fix bt_trace module ci break with
CONFIG_BLUETOOTH_DEBUG_TRACE

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-08 23:11:13 +08:00
Kai Cheng 6426ecc981 bluetooth: fix hci hal build break
bug: v/76636

CC:  string/lib_bsdstrchr.c service/stacks/bluelet/sal_adapter_interface.c: In function ‘transport_write_packet_callback’:
service/stacks/bluelet/sal_adapter_interface.c:357:5: warning: implicit declaration of function ‘bt_sal_hci_send_packet’ [-Wimplicit-function-declaration]
  357 |     bt_sal_hci_send_packet(hci_packet, length);
      |     ^~~~~~~~~~~~~~~~~~~~~~
service/stacks/bluelet/sal_adapter_interface.c: In function ‘hci_poll_recv’:
service/stacks/bluelet/sal_adapter_interface.c:666:9: warning: implicit declaration of function ‘bt_sal_hci_transport_recv’; did you mean ‘bt_sal_hci_transport_init’? [-Wimplicit-function-declaration]
  666 |         bt_sal_hci_transport_recv();
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~
      |         bt_sal_hci_transport_init

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-08 23:11:13 +08:00
Kai Cheng a54b568616 bluetooth: fix bt_socket_server build break
bug: v/76636

rootcasue: fix ci break
./frameworks/connectivity/bluetooth/service/ipc/socket/src/bt_socket_server.c:171:96: error: code should be clang-formatted [-Wclang-format-violations]
      if (BT_IPC_CODE_CHECK_RANGE(packet->code, BT_MANAGER_MESSAGE_START, BT_MANAGER_MESSAGE_END)
./frameworks/connectivity/bluetooth/service/ipc/socket/src/bt_socket_server.c:174:103: error: code should be clang-formatted [-Wclang-format-violations]
      } else if (BT_IPC_CODE_CHECK_RANGE(packet->code, BT_ADAPTER_MESSAGE_START, BT_ADAPTER_MESSAGE_END)
./frameworks/connectivity/bluetooth/service/ipc/socket/src/bt_socket_server.c:177:78: error: code should be clang-formatted [-Wclang-format-violations]
      } else if (BT_IPC_CODE_CHECK_RANGE(packet->code, BT_DEVICE_MESSAGE_START,BT_DEVICE_MESSAGE_END)

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-12-08 23:11:13 +08:00
Lu Jia d18babcbcc bluetooth: Fix the AVRCP Use-After-Free issue.
bug: v/79798

Resolve node access crash after bt_list_remove in Bluetooth stack

Signed-off-by: jialu <jialu@xiaomi.com>
2025-12-04 18:02:53 +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
wuxiaodong6 34bfb85fcc fix the double release issue.
bug: v/79099

rootcause: memory is repeatedly released.

Signed-off-by: wuxiaodong6 <wuxiaodong6@xiaomi.com>
2025-12-03 09:34:47 +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
chejinxian1 5d3d0ee6e3 bluetooth: Remove unused source file and add AVRCP control source to library
bug: v/79115

Rootcause: Update the source file path used by the `libbt-framework-client` library.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-11-28 21:36:20 +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
chejinxian1 132453c0d7 IPC: Update the include for RPMSG
bug: v/79112

Rootcause: Within the Android build system, the RPMSG service is inaccessible. Consequently, the corresponding library path has been added to Android.bp, and the include header file for the source file utilising RPMSG has been updated.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-11-28 21:36:20 +08:00
liuxiang18 9128199bb7 storage: fix memleak.
bug: v/74815

Resolved three memory leak issues:
1. Memory leak in the uv_db_get interface caused by premature return.
2. Failure to execute bt_storage_unqlite_cleanup after deletion of original db files following upgrade.
3. Incomplete release of queue_work resources after uv exit.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-11-28 21:04:53 +08:00
liuxiang18 74663d6cf7 bluetooth: fix build warning.
bug: v/73508

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-11-28 21:04:53 +08:00
liuxiang18 1d6a2cc803 bluetooth: adapt property_list display string.
bug: v/71143

getprop currently only prints values that pass isprint() and are terminated by ‘\0’ as strings; all others are printed as %02x.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-11-28 21:04:53 +08:00
liuxiang18 fe229135f8 bluetooth: add bttool-storage
bug: v/70895

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-11-28 21:04:53 +08:00
liuxiang18 4659711387 bluetooth: add KVDB storage save API.
bug: v/71150

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-11-28 21:04:53 +08:00
liuxiang18 bee2b50a6d bluetooth: add unqlite storage save API.
bug: v/71151

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-11-28 21:04:53 +08:00
liuxiang18 a04b919dae bluetooth: add storage version 5_0_2
bug: v/71133

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-11-28 21:04:53 +08:00
liuxiang18 6c0f5fffce bluetooth: add storage version number.
bug: v/71118

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-11-28 21:04:53 +08:00
liuxiang18 10ef8e9b0f bluetooth: add KVDB storage load function.
bug: v/71138

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-11-28 21:04:53 +08:00
liuxiang18 61962200bf bluetooth: add KVDB properties remove function.
bug: v/71117

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-11-28 21:04:53 +08:00
liuxiang18 da9b273239 bluetooth: Expose a subset of the universal interfaces for usage in storage updates.
bug: v/71112

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-11-28 21:04:53 +08:00
liuxiang18 f08c82b2e3 bluetooth: add storage version 5_0_1
bug: v/71119

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-11-28 21:04:53 +08:00
liuxiang18 1aa2545d51 bluetooth: adapt storage update module Makefile & CMakeLists
bug: v/71113

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-11-28 21:04:53 +08:00
liuxiang18 2c1e50516a bluetooth: Implementation of the Storage Update Module.
bug: v/70894

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-11-28 21:04:53 +08:00
zhongzhijie1 513a6b1063 trigger exit_sniff when 'sco open' state change to 'sco close'
bug: v/79133

rootcause: In our design, sco_open will set sniff interval to 50 ~ 150
ms, then the bluetooth call finish, power manager will enter sco_close
to set the sniff interval to 500ms. However, only change sniff interval
is not allowed when the link is already during sniff mode, must exit sniff before
make it.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-11-27 18:41:28 +08:00
wuxiaodong6 06fc0eefe8 delete device_lock in gatts
bug: v/78167

rootcause: In gatts, all locks are called by a single thread called bluetoothd, and there are no race conditions, so locks can be optimized.

Signed-off-by: wuxiaodong6 <wuxiaodong6@xiaomi.com>
2025-11-27 10:03:56 +08:00
Kai Cheng d800bf1f8e SPP: fix sdp discovery uuid param invalid
bug: v/73971

sdp_discover type should be set with BT_SDP_DISCOVER_SERVICE_SEARCH_ATTR,
when request sdp discovery in last btstack

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-11-25 16:41:04 +08:00
zhongzhijie1 7ebe4b65b6 add direct profile connect/disconnect flow and API docs
bug: v/77661

- Add profile connection handler type and bt_profile_conn_handler_node_t structure.
- Introduce bt_sal_profile_connect_request, bt_sal_profile_disconnect_register and bt_sal_profile_disconnect APIs.
- Add internal worker APIs: bt_sal_remove_bond_internal, bt_sal_disconnect_internal.
- Expand connection manager data model:
  - separate connecting / disconnecting manager lists
  - support dynamic profile_conn_handler_node per device
  - change profile flags to 64-bit and add profile_id -> flag helper
  - add async request wrapper and service-worker invocation for profile actions
- Implement profile connect/disconnect orchestration:
  - trigger profile actions on ACL connect
  - ensure profile disconnect handlers run before ACL teardown
  - handle unpair flow by removing bond after ACL disconnect
- Update A2DP/AVRCP and adapter code to use new APIs:
  - register profile disconnect handlers and notify profile-connected events
  - use bt_sal_profile_connect_request / bt_sal_profile_disconnect wrappers
  - invoke cm callbacks on ACL connect/disconnect paths

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-11-24 22:23:32 +08:00
zhongzhijie1 013be33246 Remove redundant gatt server local read/write implement.
bug: v/78372

cause of open-vela/external_zblue/pull/107, now use async way for gatts
read/write response, so no need local way.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-11-24 22:20:06 +08:00
zhongzhijie1 5f3c369a71 Manager GATT server test: Normalize read-only/read-write/pts char access.
bug: v/78372

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>
2025-11-24 22:20:06 +08:00
zhongzhijie1 af3f4e8e9f GATTS: Support deferred write/read responses
bug: v/78372

Root cause: Receive and app reply run in different threads, require async handling.
Use 32-bit request_id encoding handle and opcode for framework service compatibility.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-11-24 22:20:06 +08:00
Kai Cheng 4ca53866fe blueooth: add HID SAL feature
bug: v/78803

This commit implements the HID Service Abstraction Layer (SAL) for
Zephyr Bluetooth stack integration. The main changes include:

- Add HID device compilation support in Makefile when
  CONFIG_BLUETOOTH_HID_DEVICE is enabled
- Implement HID device service abstraction layer interface
  (sal_hid_device_interface) with complete API set
- Support HID device registration and SDP service record management
- Provide connection management for HID device profiles
- Implement report data handling (send/receive) and error reporting
- Support virtual cable unplug functionality

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-11-24 17:03:16 +08:00
Kai Cheng bcc830ea10 bluetooth: remove invalid BLUETOOTH_SPP depend
bug: v/73970

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-11-24 02:50:44 +08:00
Kai Cheng 2a10e69528 bluetooth: add SAL SPP feature for zblue stack
bug: v/73971

This patch adds SPP feature to the Bluetooth stack, including server and client implementation based on RFCOMM and SDP.
Changes:
Add SPP compilation option in Makefile.
Add debug log in spp_service.c.
Implement SPP interface in sal_spp_interface.h and sal_spp_interface.c.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-11-24 02:50:44 +08:00
Zhijie Zhong 82b06b1468 a2dp: Fix missing SEP and stream fields during peer endpoint copy
bug: v/78393

The previous code only performed a shallow copy of the peer endpoint by
copying the pointer, leaving several fields (codec_type, sep, stream)
uninitialized.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-11-23 17:49:01 +08:00
wuxiaodong6 45138d77a1 Feature error code mapping
bug: v/77522

Rootcause: mapping of Bluetooth error codes and feature error codes

Signed-off-by: wuxiaodong6 <wuxiaodong6@xiaomi.com>
2025-11-23 04:11:55 +08:00
zhongzhijie1 a8307e10b6 adapt zephyr smp ctkd bond state report.
bug: v/76519

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-11-23 03:58:50 +08:00
zhongzhijie1 f3654daa06 Adjust BLE address management logic.
bug: v/76534

Unify BLE address management logic.

When no connection info, use first connection address (remote->addr) as base.

For CTKD bonded device, address saved in service kvdb, so use le.dist (identity address) to match with service storage first.

If not found, treat as first connection and use remote (ACL connection address) to match.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-11-23 03:58:50 +08:00
Lu Jia bcbf5f9c55 bluetooth: Upgrade AVRCP from 3.0 to 4.0
bug: v/72076

Signed-off-by: jialu <jialu@xiaomi.com>
2025-11-23 03:34:50 +08:00
Lu Jia d47164b2b0 bluetooth: Add AVRCP CT (Controller) callback handling in the client
bug: v/74551

The client fails to handle AVRCP (Audio/Video Remote Control Profile) callbacks, resulting in the application missing track metadata notifications.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-11-23 01:26:15 +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
Lu Jia 6cb50db5bd bluetooth: Check the validity of ins->context before use
bug: v/77564

When deleting the instance, ins->context is set to NULL. During asynchronous callback execution, ins->context may already be NULL.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-11-20 18:14:35 +08:00
Lu Jia 65fbc3c6b6 bluetooth: In GATTC discovery, report results as a single array per discovery event.
bug: v/77564

Report one service per discovery event. Data caching is required in this feature module. If the application exits during the discovery process, releasing the cached services becomes highly complex.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-11-20 18:14:35 +08:00
Lu Jia 35c3d85823 bluetooth: In the asynchronous callback of GATTC deletion, release resources regardless of the operation status (success or failure).
bug: v/77564

Signed-off-by: jialu <jialu@xiaomi.com>
2025-11-20 18:14:35 +08:00
Lu Jia dc9897fb67 bluetooth: Release resources within the callback during deletion of the GATTC asynchronous instance.
bug: v/77564

Signed-off-by: jialu <jialu@xiaomi.com>
2025-11-20 18:14:35 +08:00
Lu Jia 4baa9477e4 bluetooth: Before releasing the IPC pending_queue, invoke the asynchronous callbacks for all messages contained within it.
bug: v/77564

When deleting the Bluetooth asynchronous instance, the IPC cached messages are directly released, and their asynchronous callbacks will not be invoked. This could lead to memory leaks if resources are released within the callbacks.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-11-20 18:14:35 +08:00
Zhijie Zhong 95cd2488e8 Add bluetooth code owners configuration
Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-11-18 15:30:56 +08:00
chejinxian1 91aa677c78 L2CAP: Avoid holding locks for long periods of time.
bug: v/77783

Rootcause: There is a possibility of a sleep operation in uv_close, which may cause euv_pipe_close2 to hold the lock for a long time.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-11-17 22:20:28 +08:00
chejinxian1 01cc4da180 L2CAP: Fix potential risks in shift operations in L2CAP Service.
bug: v/777831

Rootcause: By default, the shift operation uses variables of type int, but when the code involves operations wider than 32 bits, it leads to security vulnerabilities in the shift operation.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-11-17 22:20:28 +08:00
chejinxian1 12f20c8d34 L2CAP: Fix the memory leak issue in the L2CAP module of bttool.
bug: v/77798

Rootcause: When the write command fails to generate a message, the data already read into the buffer needs to be released.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-11-17 22:20:28 +08:00
liuxiang18 e81000ad6e IPC: adapt l2cap new message code
buv: v/52485

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-11-17 22:20:28 +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 eeaf6ff389 L2CAP: Implement 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 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 7ac5a15b96 L2CAP: Develop tool to debug L2CAP Service.
bug: v/57733

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-11-17 22:20:28 +08:00
chejinxian1 d543c05d87 L2CAP: Add L2CAP command handling and initialization functions.
bug: v/57733

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-11-17 22:20:28 +08:00
chejinxian1 df6bc0fa3c L2CAP: Enhance dynamic PSM allocation and availability checks.
bug: v/59130

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-11-17 22:20:28 +08:00
chejinxian1 c91905096a L2CAP: Modify channel connection handling.
bug: v/57284

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-11-17 22:20:28 +08:00
chejinxian1 c5c31b4e9d L2CAP: Add channel management functions for data path handling and improve connection logic.
bug: v/57284

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-11-17 22:20:28 +08:00
chejinxian1 f680a26f87 L2CAP: Implement CID allocation handling and update channel parameters
bug: v/57418

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
chejinxian1 6a8860b384 L2CAP: Implement alloc_free_channel function for channel allocation.
bug: v/57366

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-11-17 22:20:28 +08:00
chejinxian1 02fa7ce1ef L2CAP: Enhances L2CAP channel management and connection handling.
bug: v/57366

Introduces role-based L2CAP channel struct with added fields for local/remote IDs, connection status, and proxy management. Replaces pty with pipe abstraction and adds ID allocator for channel management. Updates initialization and cleanup routines for resource handling. Improves scalability and modularity of L2CAP service.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-11-17 22:20:28 +08:00
liuxiang18 7f01e2630d bluetooth: fixed the issue where the thread_loop_work_sync semaphore blocking when client_loop without run.
bug: v/78154

If bluetoothd initialization fails, it causes the client_loop to execute the deinit operation before it runs, which blocks thread_loop_work_sync and consequently blocks the bluetooth_create_instance API.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-11-17 21:30:22 +08:00
zhangyuan20 2a71b51066 bugfix: fix bttool hf get state error
bug: v/77780

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2025-11-17 20:10:54 +08:00
Zihao Gao fb8676e715 A2DP: replace net_buf_reserve by bt_a2dp_stream_create_pdu
bug: v/78150

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-11-17 19:54:15 +08:00
Zihao Gao b3d4132dfc A2DP: Adapter for Get All Capabilities.
bug: v/74826

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-11-17 19:54:15 +08:00
chejinxian1 fe8e66ab8b SPP: add logs for reporting resource allocation anomalies and proactive disconnection events.
bug: v/78035

Rootcause: It is currently difficult to determine which resource allocation has failed during API calls. Furthermore, if the SPP disconnection information reported by the app's unregister process contains no logs, this makes the disconnection information heavily reliant on HCI logs.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-11-14 12:05:00 +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
Lu Jia 824e6d0fca bluetooth: Optimize code
bug: v/74718

Too much duplicated code increases the number of code lines; refactor the duplicated code using macros.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-11-13 14:23:17 +08:00
Lu Jia 772495f561 bluetooth: Free the list storing the peer device's codec information before the set configuration process.
bug: v/74718

Before the set configuration process, compare the local codec, remote codec, and preferred codec. After the comparison, delete the locally stored codec information to reduce memory usage.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-11-13 14:23:17 +08:00
Lu Jia 236b16d55f bluetooth: Fix configuration setting errors.
bug: v/74718

When configuring, the local codec, remote codec, and selected codec must be passed. Using the preferred codec as the selected codec may cause errors because the bitpool value is a subset of the local codec, remote codec, and preferred codec.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-11-13 14:23:17 +08:00
Lu Jia 450da945b1 bluetooth: Change the resource release logic for the A2DP list
bug: v/74718

Signed-off-by: jialu <jialu@xiaomi.com>
2025-11-13 14:23:17 +08:00
Lu Jia 59c0cba029 bluetooth: Optimize A2DP list
bug: v/74718

Signed-off-by: jialu <jialu@xiaomi.com>
2025-11-13 14:23:17 +08:00
Lu Jia 3c131992d2 bluetooth: Adapt for A2DP Source
bug: v/74718

Signed-off-by: jialu <jialu@xiaomi.com>
2025-11-13 14:23:17 +08:00
wuxiaodong6 e739721b93 fix sal_gatts_interface memory leaks
bug: v/75464

Rootcause: the memory may not be released.

Signed-off-by: wuxiaoodong6 <wuxiaodong6@xiaomi.com>
2025-11-13 11:57:33 +08:00
wuxiaodong6 429d25a953 fix sal_adapter_interface memory leaks
bug: v/76245

Rootcause: the memory may not be released.

Signed-off-by: wuxiaodong6 <wuxiaodong6@xiaomi.com>
2025-11-13 11:57:33 +08:00
wuxiaodong6 5fc0f5b754 fix sal_adapter_le memory leaks
bug: v/76229

Rootcause: the memory may not be released.

Signed-off-by: wuxiaoodong6 <wuxiaodong6@xiaomi.com>
2025-11-13 11:57:33 +08:00
wuxiaodong6 84fc3cefee fix sal_(gattc & le_adv & le_scan) _interface memory leaks
bug: v/76702

Rootcause: the memory may not be released.

Signed-off-by: wuxiaodong6 <wuxiaodong6@xiaomi.com>
2025-11-13 11:57:33 +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
wuxiaodong6 355d7f6b36 typo: duplicated
bug: v/76597

Rootcause: this is a repetitive callback

Signed-off-by: wuxiaodong6 <wuxiaodong6@xiaomi.com>
2025-11-12 20:18:28 +08:00
wuxiaodong6 73f0f0bf5c Delete device_lock in gattc
bug: v/75033

rootcause: In gattc, all locks are called by a single thread called bluetoothd, and there are no race conditions, so locks can be optimized.

Signed-off-by: wuxiaodong6 <wuxiaodong6@xiaomi.com>
2025-11-12 20:18:28 +08:00
zhongzhijie1 f71477ec12 hci: fix missing poll remove when close
bug: v/76968

Before only open was handled, poll fd was added in h4_open() but never removed when close device. When Bluetooth reopen many times, old poll fd still stay inside service loop, cause invalid fd crash in uv__io_poll assert.

Add missing h4_close() to remove poll fd before close fd, avoid invalid fd access during reopen.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-11-12 11:52:23 +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
zhongzhijie1 6defd04a82 Fix memleak issue of cm_data.
bug: v/74008

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-10-31 10:56:01 +08:00
liyuheng f9ac81dbc5 Fix overflow before widen
bug: v/76743

Rootcause: 2 * stream->interval_ms * 1000 will use 32-bit integer when calculate on a 32-bit platform.

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2025-10-30 15:01:17 +08:00
Kai Cheng 7bc1dc468d bluetooth: fix open fail in multi-device case
bug: v/76638

adapter device name  for multi-controller case.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-10-30 14:19:51 +08:00
Kai Cheng cd36c0d88b bluetooth: add sample adapter state debug
bug: v/76637

add more adapter state debug log

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-10-30 14:19:51 +08:00
Kai Cheng a1039206f9 bluetooth: add mc h4 device init select
bug: v/76638

add marco config for mult-controller

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-10-30 14:19:51 +08:00
Kai Cheng a71b5614c0 bluetooth: change enable sample tool stack to 4k
bug: v/76637

change enable test tool stack size to 4K, which would
save 4k memory

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-10-30 14:19:51 +08:00
Kai Cheng ca3e8d9dbc bluetooth: fix sample code cmake build break
bug: v/76637

fix enable sample build break

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-10-30 14:19:51 +08:00
Kai Cheng 59146f40ed bluetooth: add ipc and service module for cmake
bug: v/76636

disable unused ipc and service module in small
memory case.

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-10-30 14:19:51 +08:00
Kai Cheng 14eff59179 bluetooth: merged bt driver thread to btservice loop thread
bug: v/76633

remove bt driver thread, and merger it to service loop thread

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-10-30 14:19:51 +08:00
Lu Jia 541f21384a bluetooth: Fix the memory leak issue in GATTC.
bug: v/66837

When deleting GATTC, if the application does not provide a callback, the Bluetooth async API cannot be invoked, leading to the inability to release gattc remote list and causing a memory leak.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-27 20:16:48 +08:00
zhongzhijie1 06abe5ece2 fix pm device use after free issue.
bug: v/76319

when pm device is free, the request timer may keep alive, and the
timeout callback use device pointer directly, so the smallest change is
stop timer before remove devcie.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-10-27 16:15:24 +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 d35f3f99b2 bluetooth: Fix A2DP code quality issues
bug: v/74399

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-22 19:15:36 +08:00
Lu Jia 3f861153ba bluetooth: Fix the memory leak issue in gattc.
bug: v/74542

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-22 19:15:36 +08:00
Zihao Gao 6e195fa9d1 A2DP: Clear PENDING_STOP on stream suspended
bug: v/74836

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-10-22 15:50:00 +08:00
gaoyuan28 0e7628a6fe fix the type of FtUInt32 for jidl-rust
bug: v/53049

Signed-off-by: gaoyuan28 <gaoyuan28@xiaomi.com>
2025-10-15 23:00:58 +08:00
gaoyuan28 07669fe207 use jidl-rust tool to add bluetooth features
bug: v/53049

Signed-off-by: gaoyuan28 <gaoyuan28@xiaomi.com>
2025-10-15 23:00:58 +08:00
gaoyuan28 ac288113c5 use enhanced uttx_add_jidl to add bluetooth features
bug: v/58982

Signed-off-by: gaoyuan28 <gaoyuan28@xiaomi.com>
2025-10-15 23:00:58 +08:00
Lu Jia 48a9a6066f bluetooth: Fix code formatting issues
bug: v/73266

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia 8b659f13db bluetooth: Add macro control for the feature bluetooth gattc.
bug: v/66837

Signed-off-by: jialu <jialu@xiaomi.com
2025-10-15 10:20:50 +08:00
Lu Jia 9b72792378 bluetooth: Add macro control for the feature bluetooth scan.
bug: v/66836

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia 5d1cd7287d bluetooth: Add macro control for the feature bluetooth adv.
bug: v/67404

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia 3e2247c9cf bluetooth: Remove the macro control for bluetooth_ble_impl.c in Makefile and CMakeLists.
bug: v/67404

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia ad524e3705 bluetooth: Change the addressType parameter of bluetooth.BLE.createGattClientDevice to be an optional parameter.
bug: v/71688

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
gaoyuan28 afd9853b99 bluetooth: Correct event name
bug: v/71687

Signed-off-by: gaoyuan28 <gaoyuan28@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia 4c2e407954 bluetooth: Change the scan state parameter reported to the application to a struct type.
bug: v/71507

Root Cause: The return value parameter defined by the API for obtaining scan status is of type object.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia b55d78a905 bluetooth: Fix the issue of scanner state not being cleared due to closing Bluetooth during scanning, which leads to scan failure again.
bug: v/71516

Root cause: The state of the scanner is only cleared when the scan is stopped or closed. When Bluetooth is turned off while scanning is in progress, the state of the scanner is not cleared. This leads to the failure to start scanning when Bluetooth is turned back on.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia a80eabc810 bluetooth: Fix the issue of obtaining the scan status abnormally when there is no scan.
bug: v/71507

Root cause: The request for connection status was directly denied before starting the scan, it should return STATE_NON_SCAN.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia d33cd6eeff bluetooth: Add close functionality for advertiser, scanner, and GattClientDevice in the bluetooth.ble feature.
bug: v/71034

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia 576781a69c bluetooth: Implement the features bluetooth BLE gattc.
bug: v/66837

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +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 4cb3f47aac bluetooth: Implement the features bluetooth BLE scan.
bug: v/66836

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia d1cc10ef68 bluetooth: Add instance in the handle returned by the callback in scan.
bug: v/62058

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
Lu Jia 1b53740d2a bluetooth: Add instance in the handle returned by the callback in adv.
bug: v/67404

Root cause: The interface handle and other information of the feature exist on the instance of Bluetooth. If the callback does not have instance information, it cannot obtain feature-related information, resulting in the JavaScript application not receiving the callback.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia 4318f050cf bluetooth: Modify the Bluetooth feature implementation plan.
bug: v/67404

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia 0215688d0e bluetooth: Increase the dependencies for the bluetooth feature.
bug: v/69934

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia 04ec6b20de bluetooth: Fix the issue of Overflowed integer argument.
bug: v/69458

rootcause: The cast of packet->code to a signed type could result in a negative number.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia 9a57a90ba0 bluetooth: Fix the issue of crashing caused by memory usage after freeing.
bug: v/68983

If priv->pipe == NULL, freeing priv first and then freeing priv->packet will cause a crash.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia a18a42e98a bluetooth: Fix the issue of crashing caused by memory usage after freeing.
bug: v/68983

uv_close is asynchronous. After free(priv), the internal implementation of uv_close will use priv->conn_req, which will result in "Use After Free" error.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia 39007dc02d bluetooth: use legacy adv
VELAPLATFO-74091

iOS cannot search for the extension adv, we need to change the adv type to legacy.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia 32d1b33221 bluetooth: Dereference before null check.
bug: v/65888

Root cause: The function advertiser_data_new() may return NULL. It is used without checking if the pointer is empty after calling the function.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-15 10:20:50 +08:00
Lu Jia 5101ff90ef bluetooth: Rename the macro for modifying A2DP SBC parameters.
bug: v/60871

Root cause: The macro names A2DP_SBC_SUBBAND_MSK and A2DP_SBC_SUBBAND_4 conflict with the macros defined in zblue, causing warnings to appear. The names of the macros in the framework were prefixed with BT to resolve the conflict, and the macro names for A2DP SBC defined in the framework were also uniformly prefixed with BT to maintain consistency in style.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-10-14 21:13:45 +08:00
zhangyuan20 fb4c45a360 bugfix: modify a2dp version from 1.3 to 1.4
bug:v/72307

Rootcause:a2dp version has been modified in 1.4.1

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2025-09-29 11:39:23 +08:00
Zihao Gao a9efc84189 A2DP: Add timeout detection for source stream timer.
bug: v/72047

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-09-28 14:15:00 +08:00
yuzihan1025 2bbdc67958 A2DP frame structure detection
bug: v/71791

Signed-off-by:Zihan Yu <167994520@qq.com>
2025-09-28 14:15:00 +08:00
liuxiang18 eacc6cfc9a bluetooth: fixed crash caused by disable during scanning.
bug: v/69290

When disable is executed, scanner_manager.scanning_list is cleared. This causes node = scanner_manager.scanning_list->next = NULL. At this point, executing scanner->filter is equivalent to NULL->filter, causing an exception address access.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-09-26 21:42:22 +08:00
liuxiang18 24937cdb38 bluetooth: fix an issue where connection failure was still reported as connection success callback.
bug: v/69527

When the connection fails and the connected callback is returned, err is not checked, resulting in the connection status being reported even though the connection has not been established. When disconnecting is subsequently executed, conn = NULL, triggering a crash.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-09-26 21:42:22 +08:00
liuxiang18 9a0a9b8e29 bluetooth: fix problem that gatt_permission in frameworks is different from permission in zblue.
bug: v/68883

The permissions for GATT attributes in the current framework are not synchronized with the permissions in zblue, so a conversion function has been added for compatibility.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-09-26 21:42:22 +08:00
v-yichenxi df5904a41b bluetooth: fix visibility not disabled before bt_disable
bug: v/64223

rootcause: device remained visible after bt_disable

Signed-off-by: v-yichenxi <v-yichenxi@xiaomi.com>
2025-09-26 21:42:22 +08:00
Lu Jia 1d0b558090 bluetooth: Use a secure disable API.
bug: v/63458

Signed-off-by: jialu <jialu@xiaomi.com>
2025-09-26 21:42:22 +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 e482b92d11 Support start security encryption connect when le link is established.
bug: v/70809

GAP/DM/BON/BV-01-C

Signed-off-by: zhongzhijie1 <zhongzhijie1@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 c0d54593a9 Check the required security level when reporting encrypted events.
bug: v/70809

GAP/SEC/SEM/BI-14-C
When the security level is insufficient, the key length verification and security level do not meet the requirements, and the disconnection reply is auten fail.

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
zhongzhijie1 f5b26f71cb Don't remove temp devices when discovery stopped.
bug: v/72850

rootcause: Get device cod failed after the upper layer canceled discovery because temp devices info is cleanup.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-09-25 20:01:14 +08:00
chengkai 85db3a228b bleutooth: clean cached devices when discovery start stop
bug: v/57740

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-09-25 20:01:14 +08:00
liuxiang18 8b3a1a0f57 gatts: add characteristic for Authentication & signed cmd
bug: v/71347

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-09-25 20:01:14 +08:00
zhongzhijie1 33368edc2a Add set_security_level API for bredr link.
bug: v/70809

Call it by bttool: set security <level> <transport: 0/1>, Security level defines pairing MITM requirements.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-09-25 20:01:14 +08:00
zhongzhijie1 9890f09e3f gattc: Support discovery of included services in client discovery flow
bug: v/69619

When a primary service is discovered, the client will now perform an
additional include discovery within the service handle range before
proceeding to characteristic discovery. This is required for PTS test
cases that validate correct handling and parsing of include declarations.

Tested with PTS test case GATT/CL/GAD/BV-03-C.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-09-25 20:01:14 +08:00
zhongzhijie1 b69a099c4a GATT/SR/GAC/BV-01-C, Support PTS read test requiring ATT_MTU - 1 response length.
bug: v/69612

When the characteristic UUID is 0xFF06 and the stored value is "Hello PTS!",
the server responds with a dummy buffer of length (MTU - 1), filled with 0xAA.

This behavior is required by PTS test case GATT/SR/GAD/BV-01-C to verify that
the server handles edge-case read responses just below the MTU limit.

not effect on normal application logic or production behavior.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-09-25 20:01:14 +08:00
liuxiang18 d967ffe918 zblue: Fixed the issue that when BR and BLE coexist, framework BREDR monitors and responds to the BLE callback.
bug: v/71320

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-09-25 20:01:14 +08:00
liuxiang18 95bededfaf bluetooth: Add customized adv data in adv tools.
bug: v/67374

Signed-off-by: liuxiang18 <liuxiang18@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
Kai Cheng e5d182aa9d blueototh: add ipc and service config
bug: v/51584

add ipc and service profile config

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-09-25 15:29:53 +08:00
Kai Cheng 0535700f63 blueotooth: add log config
bug: v/51584

add CONFIG_BLUETOOTH_LOG config

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-09-25 15:29:53 +08:00
Kai Cheng 7b3c6fa5ec blueototh: add connection mgr config
bug: v/51584

add BLUETOOTH_CONNECTION_MANAGER config

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-09-25 15:29:53 +08:00
Kai Cheng f5d6efd185 bluetooth: add hci filter config
bug: v/51584

add BLUETOOTH_HCI_FILTER config  to  build

Signed-off-by: Kai Cheng <chengkai@xiaomi.com>
2025-09-25 15:29:53 +08:00
duqunbo fb6d1b8cbc HFP HF:Modify compilation warning.
bug: v/46476

rootcause:voip_call_number is used only when HFP_HF_WEBCHAT_BLOCKER is enabled.

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2025-09-23 01:05:29 +08:00
duqunbo 13a289fc79 Fix Coverity issue
bug: v/48491

rootcause: 1. The return value is not checked when the remove function is used
2. After the check is complete, if the file is changed, the deletion may fail, and the failure is not processed

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2025-09-22 13:07:15 +08:00
liyuheng 2763b29d55 Update Bluetooth Kconfig with new structure.
bug:v/68430

modified:   Kconfig

Signed-off-by: liyuheng <liyuheng@xiaomi.com>
2025-09-18 21:01:29 +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
v-yichenxi 7e23f12812 bluetooth: fix visibility not disabled before bt_disable
bug: v/64223

rootcause: device remained visible after bt_disable

Signed-off-by: v-yichenxi <v-yichenxi@xiaomi.com>
2025-09-08 18:20:39 +08:00
Lu Jia 72a9f431c0 bluetooth: Keep CMakeLists.txt and makefile consistent.
bug: v/68024

Signed-off-by: jialu <jialu@xiaomi.com>
2025-09-01 14:44: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 1ab07c7d83 SAL: Remove unused HFP HF callback registration in zblue_register_callback.
bug: v/67405

Rootcause: The registration of HF here is only limited to maintaining the ACL connection during the connection debugging process with the phone, and HF services should not actually be registered here.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-08-26 17:20:36 +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
chejinxian1 6c388b677b SPP: Fix the potential memory leak after SPP disconnection.
bug: v/68679

Rootcause: When the SPP Proxy connection has not been successfully established, disconnection occurs, causing the cached data to be released by the protocol stack, and then the list managing the cached data cannot be released. Therefore, when releasing the software resources of the SPP connection, the cache management list needs to be released.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-08-19 10:35:23 +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
Lu Jia 72d85f9bc5 bluetooth: Fix compilation warning issue after enabling AVRCP in Zephyr.
bug: v/68551

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-13 15:11:15 +08:00
Lu Jia 92fa9fbe63 bluetooth: Fix compilation errors.
bug: v/60871

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-13 15:09:29 +08:00
liuxiang18 789f134a1f bluetooth: fix bond fail(peer initiate pair) fail when peer devcice deletes bond Info.
bug: v/66770

The previous modification only addressed the removal of the key when pairing as the central device failed again. The processing logic for the device acting as both the central and peripheral devices is not consistent. When acting as the central device, if a key is detected during this session, the encryption process is initiated directly. The peer returns BT_SECURITY_ERR_PIN_OR_KEY_MISSING. When acting as the peripheral device, BT_SECURITY_ERR_AUTH_REQUIREMENT is reported.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-08-13 09:52:00 +08:00
liuxiang18 ad452fd077 bluetooth: fix bond fail after peer device deletes the bond information.
bug: v/66770

The local bond information remains when peer removes bond information. Then peer initiates the SMP Pairing request, will callback zblue_on_security_changed with err(BT_SMP_ERR_AUTH_REQUIREMENTS). So add the remove bond information logic on zblue_on_security_changed. When security_changed with an error, remove bond information.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-08-13 09:52:00 +08:00
zhongzhijie1 014124af81 manager: Fix missing unlocks to avoid potential deadlocks.
bug: v/66226

Fix missing uv_mutex_unlock calls in functions like manager_find_async_instance, etc.. the global mutex g_mutex was not properly unlocked before returning, leading to potential deadlocks or thread stalls.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-08-12 21:13:26 +08:00
zhongzhijie1 6e4815ed97 fix conn address resolution in early MTU callback
bug: v/67775

In some cases, the MTU callback may be triggered before the connected
callback, causing g_le_conn_info to be uninitialized when resolving
the connection address. This patch introduces a fallback mechanism
that uses bt_conn_get_info() to retrieve the remote address when the
local table lookup fails.

Additionally, it resolves Resolvable Private Addresses (RPA) to identity
addresses using adapter_get_le_remote_address(), ensuring consistent
address representation.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-08-08 17:02:12 +08:00
zhongzhijie1 92b05a9cd1 gatt: Fix incorrect MTU reporting by using the minimum of tx and rx
bug: v/66910

Problem:
When acting as a GATT server, if the local supported MTU is 498 and the client sends an Exchange MTU Request of 517,
we incorrectly report 517 to the upper layer in the MTU update callback.

This causes issues in throughput tests — tools like bttool attempt to send full 517-byte packets, which exceed the local limit.
As a result, the stack rejects the buffers and the data fails to reach the controller.

Fix:
Always report the minimum of tx and rx as the effective MTU to the upper layer, ensuring compatibility between both sides.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-08-08 17:02:12 +08:00
zhongzhijie1 1e0cde373b fix CCC callback crash due to early instance cleanup on disconnect
bug: v/66753

Calling `bt_conn_disconnect()` previously led to an immediate `memset` of
GATT instance resources, including CCC callback information.

However, during Zephyr's internal disconnect process, the CCC callbacks are
still invoked. Because the instance had already been cleared, this caused
null pointer dereference issues.

This patch defers instance cleanup until `zblue_on_disconnected()` is called,
ensuring CCC callbacks remain valid throughout the disconnection sequence.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-08-08 17:02:12 +08:00
zhongzhijie1 718d712aa3 Remove redundant zblue_conn_get_addr
bug: v/66768

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-08-08 17:02:12 +08:00
zhongzhijie1 1f4cfaba27 gatts: add client address reporting in ccc written callback
bug: v/66330

In Zephyr's GATT stack, the ccc_cfg_changed callback does not provide
the client's address, making it difficult for application-level logic
to track CCC configuration changes per client.

This patch adds address handling in bt_sal_on_ccc_written, where the
client address is retrieved and passed to upper layers. This enables
application logic to correctly identify which connection updated CCC
state and manage per-client notification or indication settings.

This fixes an issue where the application could not distinguish
which device updated CCC, potentially causing incomplete or
incorrect notification management.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-08-08 17:02:12 +08:00
zhongzhijie1 79ab44208f bluetooth: improve LE connection event reporting with profile tracking
bug: v/64642

Root cause:
The original mechanism could not accurately identify which profile (e.g., GATTC, GATTS) initiated the connection. The connection callback relied only on link role, which led to edge cases and incorrect profile dispatch.

Changes:

Extend g_acl (now g_le_conn_info) array to include connection role flags.

Use addr-based slot matching to associate connection events with the correct profile after le_create_connect() calls.

Add helper APIs to manage and access g_le_conn_info:

le_conn_find() to locate connection info by address

le_conn_add() to allocate a new entry

le_conn_remove() to free an entry

le_conn_set_role() to set role flags and trigger profile callbacks

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-08-08 17:02:12 +08:00
zhongzhijie1 c39d471958 Fix crash caused by bt_conn_cb_register(NULL)
bug: v/66402

The code call bt_conn_cb_register(NULL) to unregister a callback caused a crash when accessed cb->node.
This patch uses bt_conn_cb_unregister instead to avoids the NULL pointer crash.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-08-08 17:02:12 +08:00
chejinxian1 ace9f8f530 Bluetooth: DLF supports multiple Controller APIs.
bug: v/65471

Rootcause: Due to support for multiple controllers, some functions have been modified. Therefore, DLF needs to adapt to multiple controllers to address compatibility issues.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-08-08 16:53:52 +08:00
chejinxian1 69776d00c2 Bluetooth: Fix typo in DLF source file path.
bug: v/65471

Rootcause: The incorrect DLF source file paths are provided in the CMakelist.txt file.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-08-08 16:53:52 +08:00
chejinxian1 94cef6a956 64-bit: Fix the issue of different size when casting a function pointer on a 64-bit platform to an unsigned integer variable.
bug: v/59352

Rootcause: The original code forcibly converts the function pointer to a 32-bit unsigned integer variable. This statement causes problems when correctly converting pointer variables on a 64-bit platform. Therefore, a variable type was redefined to solve this problem.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-08-08 16:53:38 +08:00
chejinxian1 88fa9ddde8 64-bit: Fix the issue of different size when casting a function pointer on a 64-bit platform to an unsigned integer variable.
bug: v/59352

Rootcause: The original code forcibly converts the function pointer to a 32-bit unsigned integer variable. This statement causes problems when correctly converting pointer variables on a 64-bit platform. Therefore, a variable type was redefined to solve this problem.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-08-08 16:53:38 +08:00
v-hanjing3 b2ade67903 64-bit: Fix type mismatch issues.
bug: v/59352

Rootcause: On 64-bit platforms, some Log statements have format strings that do not match the variable types.

Signed-off-by: v-hanjing3 <v-hanjing3@xiaomi.com>
2025-08-08 16:53:38 +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 ec2b64173d bluetooth: Fix compilation errors when opening multiple sample codes.
bug: v/58892

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 14:05:00 +08:00
Lu Jia 8608698fb3 bluetooth: Fix the issue of bt_client of asynchronous not being able to recognize the new ipc code.
bug: v/66587

Root cause: After the asynchronous bt_client receives a message, it can only recognize traditional IPC codes. When the client receives a new IPC code, it directly asserts.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +08:00
zhongzhijie1 add354a647 bluetooth: open bluetooth dfx
bug: v/65804

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +08:00
Lu Jia cd2dfdae83 bluetooth: Increase bt others data analytics with dfx.
bug: v/65804

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +08:00
Lu Jia 56da446e29 bluetooth: Increase HID data analytics with dfx.
bug: v/65804

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +08:00
Lu Jia 62b6c92dc1 bluetooth: Increase HFP data analytics with dfx.
bug: v/65632

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +08:00
Lu Jia e724d91aca bluetooth: Increase AVRCP data analytics with dfx.
bug: v/65632

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +08:00
Lu Jia 586e7ffc7d bluetooth: Increase A2DP data analytics with dfx.
bug: v/65632

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +08:00
Lu Jia ac9cffc528 bluetooth: Increase spp data analytics with dfx.
bug: v/65630

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +08:00
Lu Jia a2d23015b0 bluetooth: Increase BLE gap data analytics with dfx.
bug: v/65489

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +08:00
Lu Jia 4e23ad3edd bluetooth: Increase BR gap data analytics with dfx.
bug: v/65489

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +08:00
Lu Jia a785db9cf8 Fix memory leak issue when ADV timeout occurs.
bug: v/64755

Root Cause: When bt_client applies for memory at adv start, it fails to release the memory when adv start fails, resulting in a problem of insufficient memory allocation during the stress test of adv start.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +08:00
Lu Jia a234906bb0 Fix the issue of the broadcast not being able to be stopped.
bug: v/64755

Root Cause: An advertiser can only keep track of one handle for a adv. If an application calls start advertising multiple times, it may result in some broadcasts not being able to be turned off.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +08:00
Lu Jia 6cafa60b13 bluetooth: After starting the advertisement multiple times, stopping the advertisement failed.
bug: v/64397

Root cause: Multiple start adv operations were performed, and the feature called the Bluetooth interface to send broadcasts. However, the feature only recorded the first broadcast and only stopped the broadcast once when stopping it, causing the second broadcast to not stop.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +08:00
Lu Jia 472d428534 bluetooth: Modify the printing of asynchronous API.
bug: v/62017

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +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
Lu Jia 182cc4016a bluetooth: Add kconfig and makefile for the asynchronous API feature.
bug: v/63431

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +08:00
Lu Jia e3d7e82cc2 bluetooth: Implement the features of Bluetooth and Bluetooth BLE.
bug: v/63431

getAddressAsync
createAdvertiser
startAdvertising
stopAdvertising

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +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 47fe1432e4 bluetooth: Fix bugs in asynchronous API.
bug: v/62017

Root cause:
1. The application does not pass asynchronous callback when it should directly return an error code. The message should not be sent to the server, and the entire callback list should not be freed.
2. The application registers multiple callbacks, but it should not return the asynchronous callback first and then return the return value of the asynchronous call. This behavior is inconsistent for the application between the first registration of a callback and subsequent registrations. When the application registers multiple callbacks, the message can be sent to the server, and the server will handle duplicate registrations.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +08:00
Lu Jia 87fd88b9f2 bluetooth: Fix bugs in asynchronous API.
bug: v/62017

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-08 13:52:12 +08:00
liuxiang18 780ab736d2 bluetooth: fix le disconnected_cb error called when bredr disconnected.
bug: v/67560

zblue's connection callback uses broadcast, and the connection callback is sent to all registered conn_cbs in a round-robin manner. This causes bredr to incorrectly execute the ble disconnection logic when it disconnects.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-08-07 18:04:38 +08:00
Lu Jia 703e8fff17 bluetooth: add sample code config
bug: v/58892

Signed-off-by: jialu <jialu@xiaomi.com>
2025-08-07 17:07:19 +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 4700a26a6e bluetooth-media: fix problem that a2dp can not be stopped when media send A2DP_CTRL_CMD_STOP
bug: v/65796

Rootcause: After media sending A2DP_CTRL_CMD_STOP, still remain some bytes in circlebuf and too short to send, result in a2dp can not go to stop.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2025-07-25 17:52:18 +08:00
Zihao Gao 57d9d81a2d storage: add initialization for uuids
bug: v/58506

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-07-24 23:28:03 +08:00
zhongzhijie1 3fb6d3affb Fix service matching logic by adding UUID comparison
bug: v/65358

Previously, the matching logic only checked if the attribute type was BT_UUID_GATT_PRIMARY, without verifying the actual service UUID. This could lead to incorrect matches when multiple services shared the same attribute type.

This commit updates the logic to also compare the service UUID stored in attrs.user_data to ensure accurate service identification.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-07-23 14:17:48 +08:00
zhongzhijie1 a63ae64dc5 pm: fix SPP always holding ACTIVE and blocking other profiles from entering SNIFF.
bug: v/65520

Fix an issue where SPP connections that are never used remain in ACTIVE state,
causing the power manager to always select ACTIVE mode due to SPP's higher
priority over other BR profiles like GATT-over-BR/EDR.

Now idle or unused SPP won't block other profiles from falling back to SNIFF.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-07-23 14:15:39 +08:00
openvela-robot 0adf299235 update .github 2025-07-23 10:59:15 +08:00
openvela-robot 7e9b8a9efb update .github 2025-07-23 00:25:25 +08:00
chengkai 7f826f188f bluetooth: fix multi-contoller ble enable fail
bug: v/57425

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-07-20 20:08:20 +08:00
chengkai cd3208b767 bluetooth: fix multi-contoller br enable fail
bug: v/57425

rootcause: bt_conn_cb_register_mc would refer null conn_ctx when do
conn init before enable.

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-07-20 20:08:20 +08:00
chengkai 32ad49291f bluetooth:fix zblue multi-controller build break
bug: v/57425

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-07-20 20:08:20 +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
Zihao Gao 7febb53baf SPP: fix memleak
bug: v/61175

Rootcause: the input argument `buffer` is supposed to be freed when `euv_pipe_write` completed. Memory leak may occurs when `device` does not exist but `buffer` is not null. Same when `euv_pipe_write` fails.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-07-14 09:08:26 +08:00
liuxiang18 b6a6bda7bf bluetooth: fix compile warning-disbale CONFIG_BLUETOOTH_BLE_SUPPORT.
bug: v/62114

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-07-08 11:03:13 +08:00
liuxiang18 4c4e720aec framework: Fix for bredr and ble sharing a single auth_cb.
bug: v/63282

Currently bredr and ble share an interface that assigns cb to bt_auth. smp and ssp both use this interface, resulting in a ble bond callback into bredr. It is impossible to find the corresponding device instance by address(BT_TRANSPORT_BREDR), eventually generate a crash.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-07-08 11:03:13 +08:00
liuxiang18 c09dcd2266 bluetooth: fix removebond failure in disconnected scenarios.
bug: v/63773

Currently, we get the Identity address from info via conn, but in a disconnected scenario(conn = NULL), which will directly return an error, making it impossible to remove the bond info in a disconnected scenario.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-07-08 11:03:13 +08:00
liuxiang18 6fb4b08cf1 bluetooth: fix for addr_type not being reported.
bug: v/62114

No address type is currently reported, resulting in all device instances having a default address type: 0(public addr type).

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-07-08 11:03:13 +08:00
liuxiang18 7f80aee687 bluetooth: fix the problem of unsynchronized callback of connection address and bond address.
bug: v/62114

The current callback uses the info.le.dst as the callback address, but the dst addr is the random address of the peer when it is unbound. After bonded, the dst addr is updated to the public address after parsing. The result is that after bonded, the connected/disconnect callback is public address, which will result in first connected random address cannot to be removed.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-07-08 11:03:13 +08:00
liuxiang18 983819c21d bluetooth: fix createbond fail error.
bug: v/60837

BT_SECURITY_L4 has a dependency on iocap, the current default iocap does not support L4 level detection.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-07-08 11:03:13 +08:00
liuxiang18 80e172b56c bluetooth: add set/get le_iocap bttool.
bug: v/60837

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-07-08 11:03:13 +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 e6d21b1ff7 SPP: Fix the memory leak when SPP disconnects.
bug: v/65151

Rootcause: The SPP Service has a send buffer to aggregate sending data smaller than the MFS into larger SPP Payloads. However, if an SPP disconnection occurs before the cached data is transferred to the protocol stack, the cache buffer cannot complete memory free based on the information returned by the protocol stack.

Signed-off-by: chejinxian1 <chejinxian1@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
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
zhongzhijie1 1d6f4ae504 gattc: allow discovery all characteristics by passing NULL UUID
bug: v/64571

When a UUID pointer is specified, discovery will only return characteristics within the start and end handle range that match the UUID.

However, for "discover all characteristics" operations, we need to return all characteristics in the given range without filtering by UUID.
This change allows passing a NULL UUID to disable UUID filtering.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-07-05 08:32:05 +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 b299900972 Fix build Warning.
bug: v/58061

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 eb2a2c4c86 zblue: Fix reporting of the connected event even on abnormal connection attempts (e.g., timeout) in OpenVela.
bug: v/60514

rootcause: The zphyr stack will send connection failure callbacks such as timeout through the on_connected callback. You need to identify it through the error code to trigger the correct sal callback.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 58c0ed2c8b zblue: Fix GATT reconnection failure after disconnection.
bug: v/60493

Root cause:
The Zephyr BLE stack automatically unreferences connection resources used internally, such as ATT and L2CAP.
However, when acting as a CENTRAL (initiator) and calling `bt_conn_le_create()`, an explicit reference to the connection is returned.
This reference is not automatically released by the stack, so it must be explicitly unref'd by the application.

Fix:
In the disconnection callback, call `bt_conn_unref()` for CENTRAL role connections to avoid reference leaks
and ensure that future reconnections are not blocked.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 cc7fc545c7 title: Fix crash when removing services in reverse order
bug: v/63298

rootcause:
When adding service 2 followed by service 3, then removing service 2 before service 3,
the attribute array `server_db` is compacted via memmove(). However, `server_svcs`
still holds stale `attrs` pointers for services registered after the removed one,
leading to invalid memory access or crash.

This patch adjusts the `attrs` pointer of remaining services after compaction to ensure consistency.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 11af0c8d1c fix write crash issue when user space not set specific value length.
bug: v/61901

Set default max value len: CONFIG_GATT_SERVER_MAX_CHARSIZE

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 64938efdd8 feat: support GATTS write callback for write_request and write_cmd.
bug: v/61901

rootcause:
Implement write callback reporting for both write_request and write_cmd types.
This allows upper layer to receive write events regardless of write type.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 669fbe371f Implements sal layer gatts notify/indicate features using callbacks for compatibility.
bug: v/60804

rootcause:
1. Callback needs to find the framework element by element_id.
   This patch passes the stack-side value elements pointer to link each attribute to its element.

2. This patch also fixes parameter lifetime issues in callback logic.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 f15a286ee5 fix: cannot find primary service when removing attribute by element pointer
bug: v/60792

Ensure UUID matching during attribute removal is consistent with addition.
This patch aligns with Vela BT framework and Zephyr's UUID storage methods.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 a125dd37d2 Implement asynchronous callback mechanism for adding/removing GATT server attributes.
bug: v/60755

1. Implement async callbacks for GATT server attribute add/remove.
2. Allocate and free characteristic value resources in a proper manner.
3. Support add/remove service pressure test.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 9dc6be64e4 bttool: support UUID-based GATTC discover command
bug: v/62360

rootcause:

Add optional UUID parameter to gattc discover command for targeted service discovery.

This change maintains backward compatibility:

- gattc discover 0 — discovers all primary services.

- gattc discover 0 1800 — discovers the primary service with UUID 0x1800 and its attributes.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 5c5301a1f8 bttool: adds command support for GATTC write_request interface to adapt to PTS testing.
bug: v/62359

Root cause:

1. The original write_request command actually invoked the write command (write_without_response API), which has now been corrected.

2. A new write_request command has been added, using the write no response API.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 63376f1c9b zblue: Fix incorrect callback on gattc disable_cccd, and support
indicate and notify sub toghether.

bug: v/61259

Zephyr uses the same API for subscribe and unsubscribe.
Use a separate bt_gatt_subscribe_params and callback for unsubscribe to avoid confusion.
Add slots method to manager multi subscribe res.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 fdc346edaa feat: Implement GATTC discovery procedure.
bug: v/60677

rootcause:
We follow the bluelet stack discovery flow:
1. Discover primary services
2. For each service, discover its characteristics
3. For each characteristic, discover its descriptors

All discovered elements must be stored in strict sequential order as follows:

- Primary Service 1
  - Characteristic 1.1
    - Descriptor 1.1.1
    - Descriptor 1.1.2
  - Characteristic 1.2
    - Descriptor 1.2.1
- Primary Service 2
  - Characteristic 2.1
    - Descriptor 2.1.1

Misordering elements may lead to incorrect behavior when accessing characteristics or descriptors by index.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 abfbbfa4e9 zblue: Implement gatt exchange mtu, callback registration and deregistration.
bug: v/62141

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 b7d946ff1d zblue: Fix the problem that sal and service free element resources are wrong after openvela gattc is disabled.
bug: v/62140

rootcause:
In order to be compatible with the bluelet design, the zphyr gattc sal layer uses the global element array as a container. Therefore, there is no need for the service to perform free. The sal layer will perform memset processing.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 201a62a6a1 zblue: Patch for gattc discover res alloc fail due to static arrow size limts,
and cleanup when discover completed.

bug: v/60649

rootcause: code implementation uses element to store all attribute information. However, batch reporting is required(follow barrot code implement), so the sal layer elements are divided into primary service, char, and descriptor for reporting.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 4b05991160 zblue: Fix bt_sal_gatt_server_disable call null pointer access.
bug: v/59087

rootcause:
    bt_gatt_cb_register(NULL) will call null pointer assert, and we also
need a method to remove usercallback in zphyr sys_callback_lists.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 99913e9f83 zblue: Fix null pointer check fail when zblue need to temporate return conn
info.

bug: v/60488

rootcause:
In zephyr ble connect implement:

    CHECKIF(*ret_conn != NULL) {
        /* This rule helps application developers prevent leaks of connection references. If
         * a bt_conn variable is not null, it presumably holds a reference and must not be
         * overwritten. To avoid this warning, initialize the variables to null, and set
         * them to null when moving the reference.
         */
        LOG_WRN("*conn should be unreferenced and initialized to NULL");

        if (IS_ENABLED(CONFIG_BT_CONN_CHECK_NULL_BEFORE_CREATE)) {
            return -EINVAL;
        }
    }
So, we need pass through a null pointer in connect state.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 4e05072afa bttool: Update gattc gatts command, the last parameter is the address type.
bug: v/60490

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 1655e1832e zblue: Add disconnect reason report in zblue_on_disconnected callback.
bug: v/60510

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
zhongzhijie1 80083a6c6e zblue: Fixed the issue that when BR and BLE coexist, framework BREDR monitors and responds to the BLE connection success event callback.
bug: v/60489

rootcause:
The ble connection event will invoke trigger the classic bluetooth connection event.
So we only need to determine whether conn belongs to bredr and then return.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-25 17:24:47 +08:00
chejinxian1 55f2b71865 SPP: Fix compilation warnings.
bug: v/59353

Rootcause: The size_t type should be formatted using the %zu specified in the C standard.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-06-25 10:33:26 +08:00
chejinxian1 f582b08c10 Bluetooth: add the stack size configuration option for the Bluetooth task.
bug: v/61147

Rootcause:The stack size parameter of the Bluetooth task should be set through configuration options to allow adaptation on different platforms.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-06-25 10:33:26 +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
zhangyuan20 794e8ab6e2 Android-Vela: add clip callback for hf
bug: v/63275

Rootcause: The application wants to get the name of the hf call by clip. The order is clip first, then clcc, but clip can only be called back after clcc, resulting in the application not being able to get the name. A separate callback needs to be added to clip.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2025-06-19 13:59:48 +08:00
Zihao Gao b78c45b51e Bluetooth: defer LE scan results if IPC blocked.
bug: v/57341

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-06-17 23:25:06 +08:00
zhongzhijie1 676764447c Fix build warning: -Werror=int-to-pointer-cast.
bug: v/58186

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-17 23:25:06 +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
zhongzhijie1 219d6c1547 Reduce MAX_SCAN_RESULTS_PER_PACKET from 15 to 13 for compatible with bt_message_packet_t union size.
bug: v/58186

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-17 23:25:06 +08:00
zhongzhijie1 64768a4d6a Redefine new ipc callback code BT_LE_ON_BATCH_SCAN_RESULT.
bug: v/52485

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-17 23:25:06 +08:00
zhongzhijie1 1316e86843 Support batch scan result report.
bug: v/58186

Detail:
- Implemented batch reporting for BLE scan results via 1024-byte pipe buffer.
  Supports up to 15 scan packets per batch.
- Added 150ms flush timeout to ensure timely reporting in low-traffic environments.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-17 23:25:06 +08:00
liuxiang18 408af3e872 Scan: fix discards scan_rsp as length of scan_rsp is Zero.
bug: v/58804

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-06-17 23:25:06 +08:00
zhongzhijie1 1a68e3e697 Reserve le scan filter feature with micro config.
bug: v/58804

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-17 23:25:06 +08:00
chejinxian1 f0dafbb834 bttool: Fix using bt_addr_str2ba without checking the return value.
bug: v/57019

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-06-17 22:39:38 +08:00
zhangyuan20 c932ccd18e fix problem that pair pin command do not send accept
bug: v/60422

Rootcause: Pair pin command do not send accept, The default value is 0, thus rejecting the pair process, So add accept when send to socket.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2025-06-12 15:03:22 +08:00
zhangyuan20 c726342078 zephyr-pts: add register notification interface for avrcp ct
bug: v/58789

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2025-06-12 10:45:11 +08:00
zhangyuan20 e52900eb16 zephyr-pts: add get playback state interface for avrcp ct
bug: v/58789

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2025-06-12 10:45:11 +08:00
zhangyuan20 ad343e7331 zephyr-pts: add get subunit info interface for avrcp ct
bug: v/58789

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2025-06-12 10:45:11 +08:00
zhangyuan20 114f7d188c zephyr-pts: add get unit info interface for avrcp ct
bug: v/58789

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2025-06-12 10:45:11 +08:00
zhangyuan20 8c3353e282 zephyr-pts: add send passthrough cmd for avrcp ct
bug: v/58789

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2025-06-12 10:45:11 +08:00
zhangyuan20 91fba2c49d zephyr-pts: fix crash problem in avrcp ct
bug: v/58789

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2025-06-12 10:45:11 +08:00
zhangyuan20 f782c2da0d zephyr-pts: add sdp for avrcp ct
bug: v/58789

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2025-06-12 10:45:11 +08:00
Lu Jia 72518eb7cd bluetooth: When removing the bond, first disconnect the profile and then disconnect the ACL.
bug: v/59903

Root cause: When removing the bond, zblue only disconnects the ACL, not the profile. As a result, the A2DP connection fails when reconnecting next time.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-06-09 23:02:02 +08:00
Lu Jia 4a65c71d2f bluetooth: Fix compilation issues.
bug: v/62519

Signed-off-by: jialu <jialu@xiaomi.com>
2025-06-06 17:32:03 +08:00
zhongzhijie1 5ee3452176 Optimize pm method, add pending state to avoid duplicate request cmd,
add pending wait timeout method as well.

bug: v/62261

rootcause: when request active cmd completed event not trigger, pm will
always call request unsniff until it trigger. So, counts of link mode
changed event callback will be sent from controller.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-05 23:00:33 +08:00
Lu Jia 22a56f142e Bluetooth: Modify function name
bug: v/62017

Signed-off-by: jialu <jialu@xiaomi.com>
2025-06-05 13:36:49 +08:00
liuxiang18 684d6932da IPC: fix build error conversion from 'int' to 'bt_message_type_t'.
bug: v/52485

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-06-05 13:36:49 +08:00
zhongzhijie1 af88ad07e8 Distinguish legacy msg code in bt_socket_client_receive.
bug: v/52485

rootcause: Legacy codes have bit 31 as 0. The check BT_IPC_CODE_CHECK_TYPE(...) misclassifies legacy callbacks as command types. This causes the wrong branch to run.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-06-05 13:36:49 +08:00
Haishen Zhang 1921f5a056 Redefine IPC message/callback code
bug: v/52485

1. Add extended IPC message/callback code
2. Update bt_socket_client_callback_process()
3. Update bt_socket_server_receive()

Signed-off-by: Haishen Zhang <zhanghaishen@xiaomi.com>
2025-06-05 13:36:49 +08:00
youhaopan 2f66660084 bluetooth: Fix hfp hf loop logic error causing skipped nodes during linked list traversal. 2025-06-05 11:43:36 +08:00
Lu Jia 1fad1f6b36 bluetooth: Replace the macro definition with a function.
bug: v/60457

Signed-off-by: jialu <jialu@xiaomi.com>
2025-06-05 00:45:49 +08:00
Lu Jia 65beb47901 bluetooth: Fix the issue of incorrect a2dp_info information.
bug: v/60457

rootcause: When the signaling channel is disconnected before the media channel, the a2dp_info information will not be deleted. When connecting to a new device, if the a2dp_info information does not match, it will result in the service receiving incorrect address information.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-06-05 00:45:49 +08:00
liuxiang18 72dd24a7fb bluetooth: Fix compilation errors in adaptation.
bug: v/61048

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-05-30 15:03:30 +08:00
liuxiang18 de5f442be9 bluetooth: fix compile error when open BLE but close GATT.
bug: v/61048

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-05-30 15:03:30 +08:00
zhongzhijie1 7a47f711bc fix when open ble feature zblue shell be opened.
bug: v/60487

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-05-30 15:03:30 +08:00
liuxiang18 97342ef5d9 Makegile: fix adapter sal API undefined error when close bredr
bug: v/61048

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-05-30 15:03:30 +08:00
zhongzhijie1 3d0422ff26 fix return miss branch to run in adapter_le_add_whitelist.
bug: v/52011

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-05-30 13:02:35 +08:00
liuxiang18 27c2138205 Optimization of power consumption in re-connect when disconnected(0x08).
bug: v/62139

Increase in re-connect interval from 8s to 12s. In the current power consumption test, the power consumption is 4.67% per half hour when the pullback interval is 8s, and 3.72% when it is increased to 12s. Moreover, the reconnection interval is too long, resulting in poor user experience. Considering the power consumption and user experience, 12s is finally chosen as the reconnection interval.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-05-29 14:07:30 +08:00
zhongzhijie1 e5c9d6ce0b update bt gdb tool to latest nxgdb version.
bug: v/46055

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-05-27 01:05:23 +08:00
zhongzhijie1 96ebb6b886 Modify module name support latest nxgdb script.
bug: v/59631

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-05-27 01:05:23 +08:00
Zihao Gao 4f18cfa087 log server: Fix the possible termination of non-null string
bug: v/60150

rootcause: Only accept chars whose length of the char array is reduced by one to ensure that the char array ends with \0.

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2025-05-22 08:40:00 +08:00
Haishen Zhang 56b10ab0b5 BTS: Add Bond Tool
bug: v/57723

1. Add Bond Tool
2025-05-20 12:13:00 +08:00
Haishen Zhang 4970ea3f54 BTS: Add Bluetooth Socket test tool
bug: v/57368

1. Add test tool of SPP
2. Add test tool of L2CAP over BREDR
3. Add test tool of L2CAP over BLE
4. Add Watch UI
2025-05-20 12:13:00 +08:00
Haishen Zhang c177eccf90 BTS: Add layout for watch devices
bug: v/57133

1. Add layout for watch devices: ScrollView + ConstraintLayout
2025-05-20 12:13:00 +08:00
Haishen Zhang 51b2361e0e BTS: Adjust the layout of MainActivity
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
2025-05-20 12:13:00 +08:00
Haishen Zhang b3f8703c6d BTS: remove "android:screenOrientation"
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.
2025-05-20 12:13:00 +08:00
Haishen Zhang f82c4786ed Update Gradle and AGP
bug: v/57133

Upgrade AGP dependency from 8.7.2 to 8.9.0
Upgrade Gradle version to 8.11.1
2025-05-20 12:13:00 +08:00
chengkai 2353c89ad7 bluetooth: fix not report br/edr disconnect reason
bug: v/59936

rootcause: add disconnect reason report

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-05-14 21:53:12 +08:00
chengkai ea67d12ace bluetooth: fix not update remote name
bug: v/59741

rootcause: it would not request remote when local has bonded info, then add
remote name request when acl connected.

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-05-14 10:40:54 +08:00
zhangyuan20 a555fb1198 Android-Vela: add clcc interface and callback
bug: v/60610

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2025-05-13 17:13:40 +08:00
liuxiang18 a34d9a71fa Bluetooth: Fix the problem of missing "break" statements in the switch case.
bug: v/50798

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-05-12 19:58:51 +08:00
liuxiang18 c87b7142bc bluetooth: fix memory leaks-a2dp_conn_timer.
bug: v/50798

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-05-12 19:58:51 +08:00
liuxiang18 72143ef6bd bluetooth:connect/disconnect profile API
bug: v/50798

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-05-12 19:58:51 +08:00
liuxiang18 9341d0e028 bluetooth: implement re-connect method - timeout re-connect
bug: v/50798

re-connect as connection timeout(0x08)

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-05-12 19:58:51 +08:00
Lu Jia 771d59fdbb bluetooth: Fix crash caused by bt_conn_unref(NULL)
bug: v/60000

Signed-off-by: jialu <jialu@xiaomi.com>
2025-05-12 19:28:25 +08:00
Lu Jia 23dbf0c246 A2DP: Increase codec information check.
bug: v/58342

fix PTS issue:
A2DP/SNK/AVP/BI-08-C
A2DP/SNK/AVP/BI-03-C
A2DP/SNK/AVP/BI-16-C
A2DP/SNK/AVP/BI-12-C
A2DP/SNK/AVP/BI-14-C
A2DP/SNK/AVP/BI-13-C
A2DP/SNK/AVP/BI-15-C

Signed-off-by: Lu Jia <jialu@xiaomi.com>
2025-05-12 19:26:26 +08:00
Lu Jia 8d34cbb7f2 bluetooth: add basic sample code
bug: v/58892

Signed-off-by: jialu <jialu@xiaomi.com>
2025-05-09 20:44:16 +08:00
Lu Jia bfc7554b42 bluetooth: add discovery sample code
bug: v/58892

Signed-off-by: jialu <jialu@xiaomi.com>
2025-05-09 20:42:59 +08:00
Lu Jia 74eae9b1a7 bluetooth: add enable sample code
bug: v/58892

Signed-off-by: jialu <jialu@xiaomi.com>
2025-05-09 20:42:03 +08:00
Lu Jia fba1d12530 bluetooth: add passive connect sample code
bug: v/58892

Signed-off-by: jialu <jialu@xiaomi.com>
2025-05-09 20:40:51 +08:00
Lu Jia 285532f922 bluetooth: a2dp: Fix A2DP stuttering issue.
bug: v/54099

rootcause: Before playing music, a vendor specific command is sent, but when using the dongle, the controller does not recognize this command and responds slowly, causing audio packets to accumulate in the HCI, resulting in music stuttering.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-05-09 20:11:26 +08:00
Zihao Gao 6b28b88fdf Adapter: allow to check local support profiles via uuid.
bug: v/59759

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-05-09 20:03:04 +08:00
liuxiang18 a3bc392737 bluetooth: fix build error.
bug: v/55753

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-05-09 12:17:30 +08:00
liuxiang18 5fcee896a0 bluetooth: fix adv stop failure after disable stack.
bug: v/58061

disable stack won't reset controller, causing still transmit advertising if disable without stop adv.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-05-09 12:16:42 +08:00
liuxiang18 a055c287f5 Adv: adapt ext_adv duration paramter.
bug: v/55694

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-05-09 12:14:20 +08:00
Lu Jia 752ca9d372 Bluetooth: Increase supported codec parameters.
bug: v/58343

Signed-off-by: jialu <jialu@xiaomi.com>
2025-05-08 12:14:12 +08:00
Lu Jia 1d39d82188 bluetooth: A2DP zblue 4.0 SAL
bug: v/55032

zephyr4.0 A2DP adapter

Signed-off-by: Lu Jia <jialu@xiaomi.com>
2025-05-08 12:14:12 +08:00
openvela-robot cb559fec01 workflows add stale.yml 2025-05-06 16:36:56 +08:00
Lu Jia 91fde75c9d bluetooth: add active connect sample code
bug: v/58892

Signed-off-by: jialu <jialu@xiaomi.com>
2025-05-06 11:28:30 +08:00
chengkai 5c05c4cd6c bluetooth: add bt trace tool
bug: v/59594

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-04-30 18:00:41 +08:00
chengkai 0ec062c156 bluetooth: add spp ping test tool
bug: v/59588

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-04-29 18:11:53 +08:00
chengkai 86c303c964 bluetooth: add bt memory debug tool.
bug: v/59567

rootcause: add bt memory debug, support memory out-of-bounds check,
peak memory printing, and memory leak check
2025-04-29 18:10:26 +08:00
Lu Jia c74e543123 bluetooth: core: release reference after using ACL conn.
bug: v/56422

rootcause: In the bt_conn_lookup_addr_br() function used by AVRCP and A2DP, a reference to a conn is obtained. After using the conn, the reference is not released, causing the reference to remain non-zero after the ACL is disconnected, leading to uncleaned resources. When the connection attempts exceed 5 times, connection failures may occur.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-04-24 17:26:58 +08:00
chengkai 8320a53a5a bluetooth: fix bredr noinputoutput pair fail
bug: v/46022

rootcause: noinputoutput do not meet unauthenticated request, then
set to level l2.

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-04-22 19:22:02 +08:00
chengkai 7c2f1803f5 bluetooth: fix le addr invlaid
bug: v/55753

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-04-22 19:22:02 +08:00
chengkai 86d940940e bluetooth: fix SCAN_TYPE build break
bug: v/55753

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-04-22 19:22:02 +08:00
liuxiang18 aa49836aba Adv: adapt ext_adv channel map choice.
bug: v/55672

adapt adv paramter for channel map field.
Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-04-22 16:34:41 +08:00
liuxiang18 579dac6b73 adv: fix adv data and scan rsp set error.
bug: v/58660

scan_rsp must be NULL when adv is not scannable if adv is ext_adv. And adv_data is the same.
Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-04-22 16:34:41 +08:00
liuxiang18 491c2f1b60 adv: fix different adv type paramters set.
bug: v/58660

Setting different advertising parameters for different advertising type.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-04-22 16:34:41 +08:00
Lu Jia 271630faff bluetooth: adapter: Solve the problem of scanmode setting failure.
bug: v/55642

rootcause: When the discoverable mode changes and iscan=false, bt_br_set_discoverable will not be called. Additionally, when the discoverable or connectable mode changes, it does not necessarily mean that the value of scanmode in storage will change.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-04-16 15:40:37 +08:00
fangzhenwei 52df36641d Fix bttool stackoverflow
bug: v/55027

increase bttool-cmd-exec stacksize to 8192, uv and IPC packet buffer
used 3200, high risk stackoverflow when executing cmd.

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2025-04-16 12:04:17 +08:00
fangzhenwei 6044eb74d2 adapter: try get remote name when linkkey report
bug: v/56645

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2025-04-16 10:18:58 +08:00
Lu Jia f0821e7bef bluetooth: Fix the HFP memory leak issue.
bug: v/57317

rootcause: When shutdown, the started status of HFP is set to false, and subsequent events will not be processed, causing the memory of messages to not be released, leading to memory leaks.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-04-14 22:41:11 +08:00
Zihao Gao 0e7a35ff72 HFP: report direction change if happens.
bug: v/57592

Root cause: the direction of the current call
is not reported correctly if two calls have
identical indexes but opposite directions in
consecutive CLCC responses.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-04-10 14:10:22 +08:00
Zihao Gao cf7f09a7cc HFP: prevent repeated SCO disconnection
bug: v/57380

Root cause: The duplicated SCO disconnection won't complete and would obstruct the HCI queue for 10 seconds.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-04-03 11:33:56 +08:00
zhangyuan20 092c0b6c09 Android-Vela: reset call status when hf is disconnected
bug: v/57401

rootcause: When hfp is disconnected, “last_reported” is not reset, causing the call status to be out of sync after reconnection

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2025-04-01 21:07:22 +08:00
chejinxian1 8f70665715 Adapter: Cancel reporting BOND_STATE_CANCELING.
bug: v/54141

Rootcause: BOND_STATE_CANCELING is the transitional state from BOND_STATE_BONDING to BOND_STATE_BONDED in the case of actively canceling the pairing. Since only the upper layer initiates the pairing cancellation will enter this state, the upper layer application does not care about entering BOND_STATE_CANCELING, so filter out this state report. This is more in line with the habits of Bluetooth software development.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-03-26 11:09:41 +08:00
chejinxian1 f8c2b0e210 bttool: Adapt to the latest bond status callback interface.
bug: v/54141

Rootcause: Modify the callback function for obtaining the bond state in bttool.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-03-26 11:09:41 +08:00
chejinxian1 b5e7cfe53a Adapter: Modify the timing of entering bonding state.
bug: v/54141

Rootcause: After agreeing to exchange IO capabilities, the upper layer was notified to enter the bonding state, but the Framework did not actually enter bonding. The purpose of entering bonding here is to avoid the situation where insufficient IO capabilities prevent the corresponding information from being obtained from the protocol stack to enter bonding.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-03-26 11:09:41 +08:00
chejinxian1 2274c91efe Adapter: Modify bond state notification method.
bug: v/54141

Rootcause: Modify the implementation of the bond state notification to support reporting the previous state. To more accurately report the bond state at the Framework layer, this modification will trigger a notification event when changing the bond state. To avoid long-term occupation of the adapter_lock, the method of do_in_service_loop is used to execute the actual notification.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-03-26 11:09:41 +08:00
chejinxian1 cee7569f30 API: Add a new callback interface to obtain bond states.
bug: v/54141

Rootcause: The new interface will inform the upper-layer application of the previous bond state, thus distinguishing the different scenarios that may occur during the bonding process.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-03-26 11:09:41 +08:00
chengkai 04d1e7d974 bluetooth: fix spp coverity null reference
bug: v/20042

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-03-25 09:59:41 +08:00
Zihao Gao d90ff374fc Audio Control: update socket control procedures.
bug: v/55255

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-03-17 14:17:41 +08:00
zhangyuan20 f2a34393cf framework/bluetooth: Fixed the problem that bt_device_get_alias method returns wrong alias.
bug: v/54666

bt_device_get_alias method returns 62 bytes when alias length is 63 bytes, because the length is reduced by 1 when using strlcpy.
2025-03-15 07:32:34 +08:00
duqunbo 8084aa14fc BTsnoop: Use uv_work to resolve contention when multiple threads write snoop files at the same time.
bug: v/52618

rootcause:there is competition when both multiplethreads write HCI to snoop at the same time.

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2025-03-13 11:50:01 +08:00
fangzhenwei d7a1ee939f sal: set pairing_confirm cb to NULL by default
bug: v/53803

SSP just work pairing confirm dont notify app

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2025-03-07 11:50:53 +08:00
duqunbo 97e17530fb Remove the restriction that prevents entering the A2DP started state before the local media codec configuration is fully set up.
bug: v/54811

rootcause:Once the codec negotiation is completed, regardless of whether the local media codec configuration has been set up, the A2DP should not be restricted from entering the started state.

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2025-03-06 23:17:54 +08:00
duqunbo 189519c95c Move the save adapter property to the uv_work thread.
bug: v/54729

rootcause:The number of KVDB connections that can be established is limited. If multiple one-way modification operations are triggered rapidly, it may cause the number of connections to exceed the upper limit.

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2025-02-28 21:59:00 +08:00
Zihao Gao a936a45d4b Bluetooth: update the include path for Vela Bluetooth interfaces.
bug: v/46835

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-02-26 00:18:51 +08:00
liuxiang18 bfed81c014 Vela-Android: fix IPC disconnect processing
bug: v/53702

Rootcause: Android(socket client) becomes blocked indefinitely when awaiting a semaphore, as the Vela(socket server) undergoes an unexpected reboot without properly releasing the semaphore. This failure in semaphore release prevents the client from proceeding with subsequent operations, resulting in a system deadlock.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-02-26 00:07:37 +08:00
jialu 2575f85332 Bluetooth: Introducing the AVRCP function.
bug: v/46573

Rootcause: Add comments to the AVRCP .h file and improve function documentation.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-02-26 00:06:24 +08:00
jialu 956f6864a7 Bluetooth: Introducing the A2DP function.
bug: v/43699

Rootcause: Add comments to the A2DP .h file and improve function documentation.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-02-26 00:06:04 +08:00
youhaopan 20270e05f6 After processing the AVRC_GET_ELEMENT_ATTRIBUTES_RSP message, the AVRCP CT service does not free the allocated memory, which leads to memory leaks. 2025-02-21 12:42:44 +08:00
chengkai 768f262d18 bluetooth: fix ci build break with clang format check
bug: v/53041

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-02-21 11:22:38 +08:00
chengkai 15819261f9 bluetooth: fix bredr and gatt co-exist connection fail
bug: v/53041

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-02-21 11:22:38 +08:00
chengkai 6be4791c4f bluetooth: fix zephyr 4.0 gatt build break
bug: v/53041

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-02-21 11:22:38 +08:00
fangzhenwei 0d728445fe bttool: add adapter async api test cmd
bug: v/46323

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2025-02-18 18:21:13 +08:00
fangzhenwei e112fa753a bttool: create uvloop thread to execute command
bug: v/46315

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2025-02-18 18:21:13 +08:00
fangzhenwei be87c6a634 ipc: device async api
bug: v/44888

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2025-02-18 18:21:13 +08:00
fangzhenwei 902b19394c ipc: adapter async api
bug: v/44888

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2025-02-18 18:21:13 +08:00
fangzhenwei 6f4f52ecf7 ipc: add bt-async-api common callback type
bug: v/44888

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2025-02-18 18:21:13 +08:00
fangzhenwei 9f81e8fa18 ipc: add framework async api config
bug: v/44888

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2025-02-18 18:21:13 +08:00
fangzhenwei 97982aedca ipc: socket ipc support async call
bug: v/46316

1.add api bt_socket_client_send_with_reply

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2025-02-18 18:21:13 +08:00
liuxiang18 f5dac27fdd Android-Vela: Adapter SPP in Android 14
bug: v/53727

open flag CONFIG_RPMSG_UART if defined(Android14)

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-02-18 18:07:35 +08:00
duqunbo 9565ad4c38 storage: Delete the commit action after the db is modified.
bug: v/53723

rootcause: The uv_db performs the commit operation automatically.

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2025-02-18 17:55:38 +08:00
duqunbo 255019b202 Perform the property_commit operation in uv_work.
bug: v/53341

rootcasue:Synchronizing the property_commit operation will block the bluetoothd thread, so it needs to be performed asynchronously.

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2025-02-18 17:55:38 +08:00
duqunbo e1c6555f89 A2DP sink: Switch stream.ready to false when A2DP sink is disconnected.
bug: v/53677

rootcause:When the A2DP sink disconnects, it does not send the A2DP_CTRL_CMD_STOP command. As a result, the bluetoothd daemon does not receive the STOP action, and the stream.ready flag is not reset. If stream.ready remains unreset, during the next connection, audio data may start being sent to the media layer before the media component issues the A2DP_CTRL_CMD_START command. This could lead to unintended audio streaming behavior.

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2025-02-18 12:21:14 +08:00
liuxiang18 5b1900f1ef Android-vela: bt_server-add bt_socket disconnect handling
bug: v/53721

Fix lost BT connection between android and vela as vela/Android reboot.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-02-14 18:16:58 +08:00
liuxiang18 fd36cb8242 Android-vela: bt_client-add bt_socket disconnect handling
bug: v/53721

Fix lost BT connection between android and vela as vela/Android reboot.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-02-14 18:16:58 +08:00
liuxiang18 3343f40412 Android-vela: profile-add bt_socket disconnect handling
bug: v/53721

destory profile resource as bt_socket disconnect.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-02-14 18:16:58 +08:00
jialu c2df26241e Bluetooth: Fix memory leak.
bug: v/51671

Rootcause: When open transport fails, the memory of transport is not released, leading to memory leakage.
2025-02-14 11:12:56 +08:00
duqunbo 07593fac23 Revert "HFP: Adds a function to delete list node resources"
bug: v/53473

This reverts commit 34efc6ea903f48edaac7d39dc4d2a3f269ae16b5.

Reason for revert: The release function causes repeated releases

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2025-02-12 09:58:51 +08:00
Zihao Gao a9e15be513 HFP: hold +CIEV responses until current call list is updated.
bug: v/52252

Rootcause: Android behavior requires AT+CLCC command only after +CIEV received, and shall not be updated when not requested.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-02-11 00:10:44 +08:00
zhangyuan20 8a88ef679a [bugfix]Vela-Android:fix build error
bug: v/46742

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2025-02-11 00:09:06 +08:00
duqunbo 4ac6a35970 BT Snoop: Add persist property to configure the location of the snoop log
bug: v/42717

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2025-02-10 22:30:28 +08:00
duqunbo 12a4df19ac BTsnoop: Fixed cherry-pick conflicts.
bug: v/42717

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2025-02-10 22:30:28 +08:00
duqunbo e9d4f928ca BTsnoop: add btsnoop API
bug: v/42717

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2025-02-10 22:30:28 +08:00
duqunbo 3d1589f15a BTsnoop: Add a snoop log write mechanism.
bug: v/42800

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2025-02-10 22:30:28 +08:00
duqunbo cb9703c7f9 BTsnoop: add snoop log filter for a2dp audio
bug: v/42934

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2025-02-10 22:30:28 +08:00
shenyangsi 76e7ec3fe8 test_suite: add BluetoothTest APP based on AndroidStudio
bug: v/52280

Signed-off-by: shenyangsi <shenyangsi@xiaomi.com>
2025-02-10 22:11:10 +08:00
duqunbo b5cf97d741 Use the property_set_xx_oneway interface
bug: v/53341

rootcasue: Setting property may block the bluetoothd thread, so change it to the property_set_xx_oneway interface, which does not wait for the setting result to return.

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2025-02-10 21:58:27 +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
chejinxian1 2fcf8b131b SPP: Fix the issue of invalid address input for the SPP disconnection command in bttool.
bug: v/52256

Rootcause: Because the Bluetooth service did not actually use the remote device address parameter during the previous disconnection, the SPP disconnection in bttool did not pass on the remote device address entered in the command.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-02-10 17:56:41 +08:00
chejinxian1 b787bd00dc SPP: Add the matching check on the use of ports and remote addresses when disconnecting SPP.
bug: v/52256

Rootcause: When an application initiates an SPP disconnection, it should provide the correct remote device address and the Port currently used for the SPP connection to avoid ambiguity.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-02-10 17:56:41 +08:00
chejinxian1 d12c6023d9 SPP: Optimizing the unregistration logic of SPP applications.
bug: v/52214

Rootcause: When the application exits directly, there may be services that are not properly closed. If the process to stop the service is not called, Bluetooth may provide incorrect service discovery information, resulting in errors in SPP connection.

Signed-off-by: chejinxian1 <chejinxian1@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
chejinxian1 bb8fae4cd1 API Comments: Add comments to the API related to SPP.
bug: v/49544

Rootcause:To better assist the use of Bluetooth services for Bluetooth applications, this submission will add commentary descriptions for certain APIs in order to provide instructions for application reference

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-02-10 17:56:41 +08:00
chengkai e6ae25e935 bluetooth: adapt spp socket tools
bug: v/47180

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-02-10 17:56:41 +08:00
chengkai 155a501a1e bluetooth: adapt spp socket api
bug: v/47179

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-02-10 17:56:41 +08:00
chengkai 2f1c434288 bluetooth: adapt spp from pty to socket pipe
bug: v/47178

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
chejinxian1 9735bb6cba Log: Reduce redundant log information.
bug: v/53336

Rootcause: The log of PM will output information about the mode switching between sniff and active.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-02-10 16:54:50 +08:00
duqunbo fb175719dd HFP: Adds a function to delete list node resources
bug: v/53343

rootcause: The memory allocated when the node is deleted is not freed because there is no delete function.

Signed-off-by: duqunbo <duqunbo@xiaomi.com>
2025-02-10 12:13:08 +08:00
chejinxian1 510764ce62 API Comments: Add comments to the API related to PAN and LE Advertiser.
bug: v/49546

Rootcause:To better assist the use of Bluetooth services for Bluetooth applications, this submission will add commentary descriptions for certain APIs in order to provide instructions for application reference.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-02-09 13:57:11 +08:00
chejinxian1 940a011664 API Comments: Add comments to the API related to HFP.
bug: v/46611

Rootcause:To better assist the use of Bluetooth services for Bluetooth applications, this submission will add commentary descriptions for certain APIs in order to provide instructions for application reference.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-02-09 13:57:11 +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
jialu d7fe4826cf AVRCP/A2DP zephyr4.0
bug: v/52947

Signed-off-by: jialu <jialu@xiaomi.com>
2025-02-06 17:43:39 +08:00
zhongzhijie1 b999116e63 bluetooth: For Whitelist-related apis, enhanced debug log print address.
bug: v/52011

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-01-22 09:44:59 +08:00
zhongzhijie1 c30ed5e991 bluetooth: Fixed an issue that whitelist failed to be added again after successfully deleted it.
bug: v/52011

rootcause: 'process_le_whitelist_update_evt' callback did not process the device flag. So it's still added state in device lists.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2025-01-22 09:44:59 +08:00
jialu 741a829251 HFP: Adding vendor specific AT command process for AG
bug: v/17775

In order to implement the PTT function of headphone control, it is necessary to add the process of AG send and receive vendor specific AT commands.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-01-16 23:03:41 +08:00
fangzhenwei 789ce69bb5 sal: update zephyr 4.0 SAL
bug: v/49964

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2025-01-16 20:16:25 +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 5194f75a88 Update the ci trigger from pull_request to pull_request_target 2025-01-09 23:57:10 +08:00
Zihao Gao 6bf0867a11 zephyr: fix compiling issues.
bug: v/45540

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-01-05 21:25:19 +08:00
Zihao Gao 5b610ed733 Kconfig: add absolute volume support for zblue.
bug: v/47586

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-01-05 21:25:19 +08:00
Zihao Gao bc64b0a366 AVRCP: add AVRCP interfaces for zephyr.
bug: v/44597

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-01-05 21:25:19 +08:00
Zihao Gao d3562fcfce A2DP: add A2DP interfaces for zephyr.
bug: v/44599

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-01-05 21:25:19 +08:00
Zihao Gao a92b9c7d61 AVRCP: update AVRCP methods in service adaption layer.
bug: v/44597

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-01-05 21:25:19 +08:00
Zihao Gao 3358946297 A2DP: update A2DP methods in service adaption layer.
bug: v/44595

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-01-05 21:25:19 +08:00
Zihao Gao 8f1fd61775 Bluetooth: add service adapter layer for AVRCP.
bug: v/42603

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-01-05 21:25:19 +08:00
Zihao Gao aea63ec2e4 Bluetooth: add service adapter layer for A2DP.
bug: v/42283

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2025-01-05 21:25:19 +08:00
chejinxian1 dd06f6ec56 Bluetooth: Add the VSC used for DLF.
bug: v/46086

Rootcause: Other vendors have supported DLF's VSC.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-01-05 21:24:38 +08:00
zhangyuan20 952b7651af bluetooth/framework: fix resource leak
bug: v/47331

Rootcause: The result provided by metadata to feature is a pointer, and the memory is not released after it is allocated.

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2025-01-03 18:07:52 +08:00
zhangyuan20 7ca0b725aa framework/avrcp: get metadata when NOTIFICATION_EVT_TRACK_CHANGED
bug: v/42362

Rootcause: Get metadata when NOTIFICATION_EVT_TRACK_CHANGED received

Signed-off-by: zhangyuan20 <zhangyuan20@xiaomi.com>
2025-01-03 18:07:52 +08:00
zhangyuan20 090d7d3034 framework/avrcp: add metadata support for avrcp control in BT Service
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>
2025-01-03 18:07:52 +08:00
liuxiang18 ee90fdddf0 Bluetooth: framework/include/bt_gattc.h
bug: v/46654

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-01-03 18:06:48 +08:00
liuxiang18 a47e504046 Bluetooth: framework/include/bt_gatts.h
bug: v/46654

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-01-03 18:06:33 +08:00
chejinxian1 a08d3053d9 OS-Upgrade: Add a BT storage transformation tool.
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>
2025-01-03 18:06:15 +08:00
chengkai dbde6f0ed4 bluetooth: add gatt client interface
bug: v/42618

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-01-03 12:10:17 +08:00
chengkai 620861c24f bluetooth: add sal le scan interface
bug: v/42616

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-01-03 12:10:17 +08:00
chengkai da5cb009e0 bluetooth: add sal gatt server
bug: v/42619

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-01-03 12:10:17 +08:00
chengkai 28d441b9c8 bluetooth: add zblue le bond and connection
bug: v/47699

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-01-03 12:10:17 +08:00
chengkai a2e37ef189 bluetooth: add sal le advertise
bug: v/42617

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-01-03 12:10:17 +08:00
chengkai 3ab1f9e8bd bluetooth: add zblue le enable/disable
bug: v/43329

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-01-03 12:10:17 +08:00
chengkai f5c7c0a9ff bluetooth: fix le only mode build error
bug: v/43327

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-01-03 12:10:17 +08:00
chengkai 5558d6bcf7 bluetooth: fix BT_UUID_DECLARE_XX build warning
bug: v/43328

Signed-off-by: chengkai <chengkai@xiaomi.com>
2025-01-03 12:10:17 +08:00
liuxiang18 aa90d14c0a spp: fix resources are not emptied as SPP profile shutdown
bug: v/46456

rootcause: registered not set to 0 as SPP showdown, resulting in register reach RESGISTER_MAX(5) in spp_register_app.

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2025-01-03 00:00:39 +08:00
shenyangsi d1d133e78c GATT: fix type mismatch for cookie of socket ipc
bug: v/45006

Rootcause: The 32-bit pointer stored by the Vela socket server may truncate the 64-bit pointer from Android client

Signed-off-by: shenyangsi <shenyangsi@xiaomi.com>
2025-01-02 22:46:44 +08:00
jialu d920be649b bluetooth: Solving heap-buffer-overflow caused by memcpy.
bug: v/49166

rootcause: The third parameter of memcpy is greater than the length of the source string, resulting in a heap-buffer-overflow error.

Signed-off-by: jialu <jialu@xiaomi.com>
2025-01-02 22:46:24 +08:00
chejinxian1 ee6adc9e8d Bluetooth: Rename list.h to avoid name conflicts.
bug: v/46057

Rootcause:The header files are accessible by all modules all modules, which makes it easy for the list.h to conflict with other file names, so the file name should be renamed.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-01-02 22:46:01 +08:00
openvela-robot 754aa99c39 update CODEOWNERS, delete xiaoxiang781216 GUIDINGLI 2025-01-02 10:02:48 +08:00
Haishen Zhang 56f0be77a1 Fix: compiling warning
bug: v/51418

1. Fix compiling warning. Print uint32_t as "%lu".

Signed-off-by: Haishen Zhang <zhanghaishen@xiaomi.com>
2025-01-01 22:32:39 +08:00
chejinxian1 ca5e623a85 Config: Correct the name of the Bluetooth driver.
bug: v/47087

Rootcause: The SIM platform's Bluetooth thread failed to obtain the driver, resulting in the inability to start the Bluetooth function.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2025-01-01 15:09:06 +08:00
openvela-robot 4e5b6aa830 update workflows ci.yml, delete pull_request_review trigger 2024-12-28 00:06:12 +08:00
openvela-robot a6b7ccc2fd add .github/CODEOWNERS PULL_REQUEST_TEMPLATE.md 2024-12-27 19:50:28 +08:00
jialu c7a5d181aa AVRCP: add avrcp metadata feature
bug:v/42364

Adding AVRCP metadata feature

Signed-off-by: jialu <jialu@xiaomi.com>
2024-12-26 22:49:19 +08:00
zhongzhijie1 82a9a94f01 Bluetooth: framework/include/bt_le_scan.h, comments.
bug: V/45986

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2024-12-26 22:48:57 +08:00
zhongzhijie1 a4da7f4162 Bluetooth: framework/include/bt_hid_device.h, comments.
bug: v/45986

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2024-12-26 22:48:57 +08:00
zhongzhijie1 efd2771ffc Bluetooth: framework/include/bt_device.h, comments.
bug: V/45984

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2024-12-26 22:48:57 +08:00
zhongzhijie1 e506ee2f86 Bluetooth: framework/include/bt_addr.h, comments.
bug: V/45984

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2024-12-26 22:48:57 +08:00
zhongzhijie1 80ae7e89e9 Bluetooth: framework/include/bt_adapter.h, comments.
bug: V/45984

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2024-12-26 22:48:57 +08:00
zhongzhijie1 79b78e9629 Bluetooth: framework/include/advertiser_data.h, comments.
bug: V/45986

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2024-12-26 22:48:57 +08:00
buxiasen 667bd4abba gdbtool/btsnoop: fix get_inode_by_path
bug: V/49345

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-12-26 22:41:40 +08:00
zhongzhijie1 1e182085a6 [VelaBT Gdb] Added script to show all BT commands help usage info.
bug: V/46055

Example:
(gdb) bthelp

========================================
Help for command: btsocket
========================================
usage: [-h] [-s] [-c] [-d] [-t {scan}]

Command to traverse socket lists and print IPC server/client msg_queue lengths.

options:
  -h, --help            show this help message and exit
  -s, --server          Traverse g_instances_list for server.
  -c, --client          Traverse g_bt_ins for client.
  -d, --detail          Show detailed packet information.
  -t {scan}, --type {scan}
                        Specify the packet type to process (e.g., 'scan', 'gatt', 'state').

========================================
Help for command: btdev
========================================
usage: [-h] -t {le,br}

Command to traverse device lists and print detailed device information.

options: -h, --help            show this help message and exit
  -t {le,br}, --type {le,br}
                        Specify the device type to traverse (e.g., 'le' for BLE, 'br' for BR/EDR).
Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2024-12-26 22:41:40 +08:00
zhongzhijie1 d6f87b8550 [VelaBT Gdb] Added initial script to automatically register nxgdb and all BT commands.
bug: V/46055

Example:
(gdb) source frameworks/bluetooth/tools/gdb/btdiag_init.py

Registering NuttX GDB commands from ... /gdb/nuttxgdb
Register Vela Bluetooth GDB command module: ... /gdb/service/btsocket.py
...
...
Register Other Vela Bluetooth GDB command module

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2024-12-26 22:41:40 +08:00
zhongzhijie1 269303eea6 [feat] Implement easy insertion of timeval measurements in service_loop.c
bug: V/43595

Implement time debug in service_loop.c

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2024-12-26 22:41:40 +08:00
zhongzhijie1 000d78ac06 [feat] Implement easy insertion of timeval measurements.
bug: V/43595

Changes:
1. Enabled Kconfig option BLUETOOTH_DEBUG_TIMEVAL, choice BLUETOOTH_DEBUG_TIME_UNIT_US enable or not.
2. Included 'bt_debug.h' in Bluetooth service or Bluetooth stack (bluelet).
3. Usage instructions:
   - In any function, first define the timeval structure by calling BT_DEBUG_MKTIMEVAL_S(name_s); at the global scope of the .c file.
   - Then, within the function, call BT_DEBUG_ENTER_TIME_SECTION(name_s); to record the entry time.
   - Finally, call BT_DEBUG_EXIT_TIME_SECTION(name_s); to record the exit time.

Example:

BT_DEBUG_MKTIMEVAL_S(hci_poll_recv);  // Suggest using the function name; since '__func__' cannot be used in precompile state, you need to input it manually.

static void hci_poll_recv(service_poll_t* poll, int revent, void* userdata)
{
    (void)poll;
    (void)userdata;

    if (revent & (POLL_ERROR | POLL_DISCONNECT))
        hci_remove_recv(NULL);

    if (revent & POLL_READABLE) {
        BT_DEBUG_ENTER_TIME_SECTION(hci_poll_recv); // Record entry time.
        bt_sal_hci_transport_recv();
        BT_DEBUG_EXIT_TIME_SECTION(hci_poll_recv);  // Record exit time.
    }
}

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2024-12-26 22:41:40 +08:00
zhongzhijie1 ebb8787391 [VelaBT Gdb] btstack dump support, now only gatt pending list info.
bug: V/45628

(gdb) btstack -h

usage: [-h] -t {gatt}

Command to interact with the Bluetooth stack and display information.

options:

-h, --help show this help message and exit

-t {gatt}, --type {gatt}

Specify the type of stack to display, e.g., 'gatt'.

Example:

(gdb) btstack -t gatt

Pending request Type: WRITE_IND, no. 1

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2024-12-26 22:41:40 +08:00
zhongzhijie1 b99da67e94 [VelaBT Gdb] Add Bluetooth driver data dump commands
bug: V/45135

(gdb) btsnoop -h
usage: [-h] [-p PATH] [-f FILE] [-a]

Command to capture Bluetooth snoop data and save it to a specified file.

options:
  -h, --help            show this help message and exit
  -p PATH, --path PATH  Device path, e.g., /dev/ttyBT0.
  -f FILE, --file FILE  Output log file path, e.g., /snoop_circlebuffer_01.log.
  -a, --all             Dump the entire buffer content.

Examples:
(gdb) btsnoop -p /dev/ttyBT0 -f snoop_circlebuffer_01.log -a

Successfully dumped circular buffer to bt snoop log 'snoop_circlebuffer_01.log'.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2024-12-26 22:41:40 +08:00
zhongzhijie1 b7d9776e45 [VelaBT Gdb] add Bluetooth dump commands: 'bttimeval'
bug: V/43595

3. bttimeval: Display timeval information for specified structures.
   - Usage:
     (gdb) bttimeval -s service_message_callback
   - Options:
     - -s, --structures: One or more structure names to display timeval information for.

Usage Example:
(gdb) bttimeval -s  service_message_callback hci_poll_recv ScheduleLoop

(Tips: Time units (ms or us) are configurable via framework Kconfig settings!)

========= service_message_callback Timeval Information =========
max_timeval: 30 ms, pre_timeval: 0 ms
entrystamp: 6967 ms, exitstamp: 6968 ms
--------- End of Timeval Information ---------

========= hci_poll_recv Timeval Information =========
max_timeval: 1 ms, pre_timeval: 1 ms
entrystamp: 6963 ms, exitstamp: 6964 ms
--------- End of Timeval Information ---------

========= ScheduleLoop Timeval Information =========
max_timeval: 4 ms, pre_timeval: 2 ms
entrystamp: 6964 ms, exitstamp: 6967 ms
--------- End of Timeval Information ---------

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2024-12-26 22:41:40 +08:00
zhongzhijie1 d9706d87f4 [VelaBT Gdb] add Bluetooth dump commands: 'btdev'
bug: V/43339

btdev: Traverse and display detailed information of BLE or BR/EDR devices.
   - Usage Example:
     (gdb) btdev -t br
     Traversing BR/EDR device lists and outputting detailed info...
     Device Name: *****
     Alias: *****'s*****
     Bluetooth Address: A8:9C:ED:1F:F0:16
     ACL Handle: 0x0000
     Connection State: Unknown Connection State
     Bond State: Unknown Bond State
     --------- End of Device Info ---------

     Device Name: Xiaomi Watch ****
     Alias: Xiaomi Watch ****
     Bluetooth Address: 14:16:9E:B3:93:5D
     ACL Handle: 0x0000
     Connection State: Unknown Connection State
     Bond State: Unknown Bond State
     --------- End of Device Info ---------

     Device Name: vela-****
     Alias: vela-****
     Bluetooth Address: 00:1A:7D:DA:71:11
     ACL Handle: 0x0000
     Connection State: Unknown Connection State
     Bond State: Unknown Bond State
     --------- End of Device Info ---------

   - Options:
     - -t, --type: Specify the device type to traverse (le for BLE, br for BR/EDR).

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2024-12-26 22:41:40 +08:00
zhongzhijie1 6bcf91c339 [VelaBT Gdb] add Bluetooth dump commands: 'btsocket'
bug: v/43338

1. btsocket: Traverse and analyze IPC server or client socket lists.
   - Supports detailed packet information (-d) and specific packet type (-t scan).
   - Usage Example:
     (gdb) btsocket -s -d
     Traversing IPC server's msg queue and outputting bt_message_packet_t code...
     NO. 1 BT_LE_ON_SCAN_RESULT (312)
     ...
     NO. 35 BT_LE_ON_SCAN_RESULT (312)
     --------- End of msg queue ---------
     msg_queue length for remote_ins 1 is 35

   - Options:
     - -s, --server: Traverse g_instances_list for server.
     - -c, --client: Traverse g_bt_ins for client.
     - -d, --detail: Display detailed packet information.
     - -t, --type: Specify packet type to process (scan).

Example:
(gdb) btsocket -s -d

Traversing IPC server's msg queue and outputting bt_message_packet_t code...
NO. 1 ADAPTER_ON_CONNECTION_STATE_CHANGED (243)
--------- End of msg queue ---------
msg_queue length for remote_ins 1 is 1

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2024-12-26 22:41:40 +08:00
fangzhenwei 8952e6ddb7 adapter: service adapte to new sal2.0 api
bug: v/42144

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2024-12-26 22:39:45 +08:00
fangzhenwei 18cd71b81d sal: bluelet adapt to new sal api
bug: v/42604

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2024-12-26 22:39:45 +08:00
fangzhenwei 4e888cbbe4 sal: stack adapter layer api version 2.0
bug: v/42144

1. define controller id type 'bt_controller_id_t'
2. new parameter 'devid' for all api
3. modified some api name and optimization parameters
4. remove useless api

Signed-off-by: fangzhenwei <fangzhenwei@xiaomi.com>
2024-12-26 22:39:45 +08:00
Zihao Gao 58ffd85d61 CMake: fix typo.
bug: v/50139

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2024-12-26 22:38:24 +08:00
Zihao Gao f919c9c490 CMake: correct cmake dependencies.
bug: v/46045

Rootcause: Incorrect dependencies.

Signed-off-by: Zihao Gao <gaozihao@xiaomi.com>
2024-12-26 22:38:24 +08:00
shenyangsi 0df7598fde ipc: fix the truncation issue of socket receiving or sending.
bug: v/45789

Rootcause: Missing return value handling for send() & recv() of socket

Signed-off-by: shenyangsi <shenyangsi@xiaomi.com>
2024-12-24 23:51:30 +08:00
liuxiang18 97841e32c5 storage:patch for KVDB storage feature
bug: v/42051

rootcause: implement the KVDB storage feature

Signed-off-by: liuxiang18 <liuxiang18@xiaomi.com>
2024-12-24 01:57:55 +08:00
openvela-robot dec5c58daf update ci pull_request types to [opened, reopened, synchronize] 2024-12-24 01:17:19 +08:00
chejinxian1 ec305935f9 Bluetooth: Disable Latency Feature(DLF) implementation.
bug: v/43848

Rootcause: DLF is an enhanced feature for optimizing latency performance, which is managed by Connection Manager. This submission is for the implementation of this feature.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2024-12-23 00:07:54 +08:00
chejinxian1 dac351422b Bluetooth: Add API for supplying enhanced mode for application calling.
bug: v/43848

Rootcause: Due to the diversity of application scenarios, the API for invoking the Connection Enhanced Mode is provided for applications to call. Applications can enable or disable specific enhanced modes according to their own needs.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2024-12-23 00:07:54 +08:00
chejinxian1 de6f8f5b1c Bluetooth: Add the Connection Manager(CM) module to manage performance enhancement features on different ACLs.
bug: v/43848

Rootcause: Some ACL need to add some enhanced features to provide a better Bluetooth communication experience. This submission is a part of the project and is intended for building a management framework.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2024-12-23 00:07:54 +08:00
chejinxian1 b6a3d495e2 Bluetooth: Add support for VSC of DLF.
bug: v/43848

Rootcause: DLF needs to be activated or deactivated through VSC.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2024-12-23 00:07:54 +08:00
chejinxian1 d6204bc1bf Bluetooth: Modify the protocol stack adaptation layer interface to obtain the LE ACL Handle.
bug: v/43848

Rootcause: Sometimes it is necessary to perform certain operations on a designated LE connection, and in this case, it is necessary to know the LE ACL Handle. The current adaptation layer interface is unable to perform this function.

Signed-off-by: chejinxian1 <chejinxian1@xiaomi.com>
2024-12-23 00:07:54 +08:00
zhongzhijie1 77d785f814 [bugfix] Add global mutex to prevent multiple processors from modifying shared resources at the same time.
bug: v/50507

All processes can operate instance resources through the global pointer 'g_instances'. In order to avoid errors caused by common modifications, add mutex protection.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2024-12-23 00:04:55 +08:00
zhongzhijie1 6d5025dc55 [bugfix] Power manager now uses the last used profile_id to determine the pm_action, instead of the first profile in the g_pm_cfg table.
bug: v/50506

Rootcause: For example, if the previous SPP profile request entered idle mode, the device will enter sniff mode after 1 second. However, if the peer device later requests entering active mode, the power manager will query `g_pm_cfg` to find the matching current action and get the AG's `pm_action`. This results in using the AG's idle timeout of 7 seconds. But at this point, we want the power manager to use the SPP profile's `pm_action` with a timeout of 1 second.

Signed-off-by: zhongzhijie1 <zhongzhijie1@xiaomi.com>
2024-12-23 00:04:27 +08:00
liujinye f6ff415e55 workflows add ci.yaml 2024-12-17 10:25:50 +08:00
openvela-robot c3c60105fa workflows add checkpatch.yaml 2024-12-12 16:14:45 +08:00
openvela-robot 339de05938 update issue template 2024-12-10 22:13:51 +08:00
openvela-robot cc84ed0b6f update workflows ci 2024-12-10 15:55:25 +08:00
openvela-robot a3d9b24322 add issue template 2024-12-09 21:39:46 +08:00
Haishen Zhang 675dc80db6 Doc: Remove QuickAPP API details
Remove QuickAPP API details, for they've not been published yet.

Change-Id: Ie25d6c5088b118fadf681ba076ea984de7c15297
Signed-off-by: Haishen Zhang <zhanghaishen@xiaomi.com>
2024-12-09 18:08:02 +08:00
openvela-robot 5805376c2b add ci.yml
Change-Id: Ica3c29801931a43fa5fb0bc327ece0f609e56cd3
2024-11-25 19:44:17 +08:00
openvela-robot cf07bea530 Merge commit
Change-Id: If26995eebd18a82ac4cd827e6801458e57a6ead3
2024-11-25 17:34:53 +08:00
687 changed files with 164393 additions and 0 deletions

3
.clang-format Normal file
View File

@ -0,0 +1,3 @@
---
Language: Cpp
BasedOnStyle: WebKit

View File

@ -0,0 +1,40 @@
name: 缺陷反馈 | Bug
description: 当您发现了一个缺陷,需要向社区反馈时,请使用此模板。
title: "[BUG] <标题>"
labels: [👀 needs triage, "Type: Bug"]
body:
- type: markdown
attributes:
value: |
感谢您对 openvela 社区的支持与关注,欢迎反馈缺陷。
- type: textarea
attributes:
label: "重现问题的步骤"
description: "简洁地描述错误是什么,为什么您认为它是一个错误,以及如何重现它的步骤"
placeholder: |
重现问题的步骤,可能包括日志和截图。
1. 步骤 1
2. 步骤 2
validations:
required: true
- type: dropdown
id: architecture
attributes:
label: Issue Architecture
multiple: true
options:
- "Arch: arm"
- "Arch: arm64"
- "Arch: x86_64"
validations:
required: true
- type: markdown
attributes:
value: |
提交前请确认您已遵循以下步骤:
- 确认问题在 [**dev**](../) 上可重现。
- 遇到构建问题时运行 `make distclean`。
- 搜索 [现有问题](./)

View File

@ -0,0 +1,34 @@
name: 新需求 | Feature
description: 当您需要反馈或实现一个新需求时,使用此模板。
title: "[FEATURE] <标题>"
body:
- type: markdown
attributes:
value: |
感谢您对 openvela 社区的支持与关注。
- type: textarea
id: question-description
attributes:
label: 您的需求是否和问题相关?
description: 请简单描述问题并提供issue链接。
validations:
required: true
- type: textarea
id: solution
attributes:
label: 请描述您想要的解决方案
validations:
required: true
- type: textarea
id: 替代方案
attributes:
label: 请描述您考虑过的替代解决方案
- type: markdown
attributes:
value: |
提交前请搜索 [现有功能需求](./)

View File

@ -0,0 +1,22 @@
name: 问题咨询
title: "[问题咨询]"
body:
- type: markdown
attributes:
value: |
感谢您对 openvela 社区的支持与关注。
- type: textarea
id: question-description
attributes:
label: 描述
description: 请解释您的问题的背景或上下文,这有助于其他人更好地理解您的问题或疑问。
validations:
required: true
- type: markdown
attributes:
value: |
提交前请确认您已遵循以下步骤:
- 我已搜索 [openvela 文档](../),但未找到问题的答案。
- 已搜索 [现有问题](./)

View File

@ -0,0 +1 @@
blank_issues_enabled: false

View File

@ -0,0 +1,11 @@
## 概要
*在此部分更新信息,说明更改的必要性、具体做了什么以及如何实现的,如果有新功能出现,请提供参考资料(依赖关系、类似问题和解决方案等)。*
## 影响
*在此部分更新信息(如适用),说明更改如何影响用户、构建过程、硬件、文档、安全性、兼容性等。*
## 测试
*在此部分更新信息详细说明如何验证更改使用什么主机进行构建操作系统、CPU、编译器等使用什么目标进行验证架构、板子配置等。提供更改前后的构建和运行日志将非常有帮助。*

1
.github/CODEOWNERS vendored Normal file
View File

@ -0,0 +1 @@
* @hyson710 @gzh-terry @chengkai15 @huangyulong3 @zhongzhijie1 @zhangyuan376

View File

@ -0,0 +1,60 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: Bug report
description: Report a bug to improve openvela stability
title: "[BUG] <title>"
labels: [👀 needs triage, "Type: Bug"]
body:
- type: markdown
attributes:
value: |
Hello openvela Community member! Please keep things tidy by putting your post in the proper place:
Reporting a bug: use this form.
Asking a question or getting help: use the [General Help](./new?assignees=&labels=Community%3A+Question&projects=&template=003_help.yml&title=%5BHELP%5D+%3Ctitle%3E) form.
Requesting a new feature: use the [Feature request](./new?assignees=&labels=Type%3A+Enhancement&projects=&template=002_feature_request.yml&title=%5BFEATURE%5D+%3Ctitle%3E) form.
- type: textarea
attributes:
label: "Description / Steps to reproduce the issue"
description: "A clear and concise description of what the bug is, and why you consider it to be a bug, and steps for how to reproduce it"
placeholder: |
A description with steps to reproduce the issue.
May include logs, images, or videos.
1. Step 1
2. Step 2
validations:
required: true
- type: dropdown
id: architecture
attributes:
label: Issue Architecture
description: What architecture(s) are you seeing the problem on?
multiple: true
options:
- "[Arch: arm]"
- "[Arch: arm64]"
- "[Arch: x86_64]"
validations:
required: true
- type: markdown
attributes:
value: |
### Before You Submit
Please verify that you've followed these steps:
- Confirm the problem is reproducible on [**dev**](../).
- Run `make distclean` when encountering build issues.
- Search [existing issues](./) (including [closed](./?q=is%3Aissue+is%3Aclosed))

View File

@ -0,0 +1,55 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: Feature request
description: Request an enhancement for openvela
title: "[FEATURE] <title>"
labels: ["Type: Enhancement"]
body:
- type: markdown
attributes:
value: |
Hello openvela Community member! Please keep things tidy by putting your post in the proper place:
Requesting a new feature: use this form.
Asking a question or getting help: use the [General Help](./new?assignees=&labels=Community%3A+Question&projects=&template=003_help.yml&title=%5BHELP%5D+%3Ctitle%3E) form.
Reporting a bug: use the [Bug report](./new?assignees=&labels=%F0%9F%91%80+needs+triage%2CType%3A+Bug&projects=&template=001_bug_report.yml&title=%5BBUG%5D+%3Ctitle%3E) form.
- type: textarea
id: question-description
attributes:
label: Is your feature request related to a problem? Please describe.
description: Please provide a clear and concise description of what the problem is. Add relevant issue link.
validations:
required: true
- type: textarea
id: solution
attributes:
label: Describe the solution you'd like
description: Please provide a clear and concise description of what you want to happen.
validations:
required: true
- type: textarea
id: alternatives
attributes:
label: Describe alternatives you've considered
description: Please provide a clear and concise description of any alternative solutions or features you've considered.
- type: markdown
attributes:
value: |
### Before You Submit
Please verify that you've followed these steps:
- Search [existing feature requests](./) (including [closed](./?q=is%3Aissue+is%3Aclosed))

47
.github/ISSUE_TEMPLATE/003_help.yml vendored Normal file
View File

@ -0,0 +1,47 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: General Help
description: Get general support regarding openvela
title: "[HELP] <title>"
labels: ["Community: Question"]
body:
- type: markdown
attributes:
value: |
Hello openvela Community member! Please keep things tidy by putting your post in the proper place:
Asking a question or getting help: use this form.
Reporting a bug: use the [Bug report](./new?assignees=&labels=%F0%9F%91%80+needs+triage%2CType%3A+Bug&projects=&template=001_bug_report.yml&title=%5BBUG%5D+%3Ctitle%3E) form.
Requesting a new feature: use the [Feature request](./new?assignees=&labels=Type%3A+Enhancement&projects=&template=002_feature_request.yml&title=%5BFEATURE%5D+%3Ctitle%3E) form
- type: markdown
attributes:
value: |
### Whether you're a beginner or an experienced developer, openvela Help is here to assist you with all your openvela questions and concerns.
- type: textarea
id: question-description
attributes:
label: Description
description: Explain the background or context of your question. This helps others understand your problem or inquiry better.
validations:
required: true
- type: markdown
attributes:
value: |
### Before You Submit
Please verify that you've followed these steps:
- I have searched [openvela Documentation](../) and didn't find an answer to my question.
- Search [existing issues](./) (including [closed](./?q=is%3Aissue+is%3Aclosed))

1
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@ -0,0 +1 @@
blank_issues_enabled: false

20
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,20 @@
*Note: Please adhere to [Contributing Guidelines](https://github.com/open-vela/docs/blob/dev/CONTRIBUTING.md).*
## Summary
*Update this section with information on why change is necessary,
what it exactly does and how, if new feature shows up, provide
references (dependencies, similar problems and solutions), etc.*
## Impact
*Update this section, where applicable, on how change affects users,
build process, hardware, documentation, security, compatibility, etc.*
## Testing
*Update this section with details on how did you verify the change,
what Host was used for build (OS, CPU, compiler, ..), what Target was
used for verification (arch, board:config, ..), etc. Providing build
and runtime logs from before and after change is highly appreciated.*

14
.github/workflows/checkpatch.yml vendored Normal file
View File

@ -0,0 +1,14 @@
# This is a basic workflow to help you get started with Actions
name: checkpatch
# Controls when the workflow will run
on:
pull_request:
types: [opened, reopened, synchronize]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
checkpatch:
uses: open-vela/public-actions/.github/workflows/checkpatch.yml@dev
secrets: inherit

14
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,14 @@
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
pull_request_target:
types: [opened, reopened, synchronize]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
ci:
uses: open-vela/public-actions/.github/workflows/ci.yml@dev
secrets: inherit

13
.github/workflows/clang-format.yml vendored Normal file
View File

@ -0,0 +1,13 @@
# This is a basic workflow to help you get started with Actions
name: clang-format
# Controls when the workflow will run
on:
pull_request:
types: [opened, reopened, synchronize]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
clang-format:
uses: open-vela/public-actions/.github/workflows/clang-format.yml@dev

11
.github/workflows/stale.yml vendored Normal file
View File

@ -0,0 +1,11 @@
name: 'Close stale issues and PR'
on:
schedule:
- cron: '30 1 * * *'
workflow_dispatch: # 允许手动触发
jobs:
stale:
uses: open-vela/public-actions/.github/workflows/stale.yml@dev
secrets: inherit

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.o
*.built
*.depend
*.dep

133
Android.bp Normal file
View File

@ -0,0 +1,133 @@
bootstrap_go_package {
name: "soong-frameworkBluetooth",
pkgPath: "android/soong/frameworkBluetooth",
deps: [
"soong-android",
"soong-cc",
],
srcs: [
"frameworkBluetooth.go",
"frameworkBluetoothBin.go",
],
pluginFor: ["soong_build"],
}
frameworkBluetooth_cc_library {
name : "libbt-framework-client",
min_sdk_version: "33",
srcs : [
"framework/common/*.c",
"framework/socket/*.c",
"service/common/index_allocator.c",
"service/ipc/socket/src/bt_socket_client.c",
"service/ipc/socket/src/bt_socket_adapter.c",
"service/ipc/socket/src/bt_socket_advertiser.c",
"service/ipc/socket/src/bt_socket_avrcp_control.c",
"service/ipc/socket/src/bt_socket_scan.c",
"service/ipc/socket/src/bt_socket_gattc.c",
"service/ipc/socket/src/bt_socket_gatts.c",
"service/ipc/socket/src/bt_socket_a2dp_sink.c",
"service/ipc/socket/src/bt_socket_a2dp_source.c",
"service/ipc/socket/src/bt_socket_avrcp_target.c",
"service/ipc/socket/src/bt_socket_hfp_ag.c",
"service/ipc/socket/src/bt_socket_hfp_hf.c",
"service/ipc/socket/src/bt_socket_hid_device.c",
"service/ipc/socket/src/bt_socket_l2cap.c",
"service/ipc/socket/src/bt_socket_spp.c",
"service/src/manager_service.c",
],
include_dirs : [
"vendor/vela/apps/system/libuv/libuv/include",
"vendor/vela/apps/system/libuv/libuv/src",
],
local_include_dirs : [
"framework/include",
"service",
"service/common",
"service/ipc",
"service/ipc/socket/include",
"service/profiles",
"service/profiles/include",
"service/src",
"dfx",
],
static_libs : [
"libuv",
],
shared_libs : [
"liblog",
],
cflags : [
//"-DANDROID",
"-Werror",
"-Wno-unused-parameter",
"-Wno-unused-function",
"-Wno-unused-variable",
"-Wno-typedef-redefinition",
],
apex_available : [
"//apex_available:platform",
"com.android.btservices",
],
header_libs: [
"kernel_modules_headers",
],
}
frameworkBluetooth_cc_binary {
name : "bttool",
srcs : [
"tools/bt_tools.c",
"tools/adv.c",
"tools/scan.c",
"tools/gatt_client.c",
"tools/gatt_server.c",
"tools/a2dp_sink.c",
"tools/a2dp_source.c",
"tools/hfp_ag.c",
"tools/hfp_hf.c",
"tools/hid_device.c",
"tools/l2cap.c",
"tools/spp.c",
"tools/log.c",
"tools/utils.c",
],
include_dirs : [
"vendor/vela/apps/system/libuv/libuv/include",
"vendor/vela/apps/system/libuv/libuv/src",
],
local_include_dirs : [
"framework/include",
"service",
"service/common",
"service/utils",
],
static_libs : [
"libuv",
],
shared_libs : [
"liblog",
"libbt-framework-client",
],
cflags : [
//"-DANDROID",
"-Werror",
"-Wno-unused-parameter",
"-Wno-unused-function",
"-Wno-unused-variable",
],
}

1002
CMakeLists.txt Normal file

File diff suppressed because it is too large Load Diff

878
Kconfig Normal file
View File

@ -0,0 +1,878 @@
#
# Copyright (C) 2020 Xiaomi Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
menuconfig BLUETOOTH
bool "Bluetooth"
default n
depends on LIBUV
depends on LIBUV_EXTENSION
if BLUETOOTH
menuconfig BLUETOOTH_FRAMEWORK
bool "Framework API"
default n
help
Enable Bluetooth Framework API
if BLUETOOTH_FRAMEWORK
choice
prompt "Select Bluetooth framework type"
default BLUETOOTH_FRAMEWORK_LOCAL
config BLUETOOTH_FRAMEWORK_LOCAL
bool "Use local API without IPC"
config BLUETOOTH_FRAMEWORK_SOCKET_IPC
bool "Use socket IPC API"
endchoice
if BLUETOOTH_FRAMEWORK_SOCKET_IPC
config BLUETOOTH_RPMSG_CPUNAME
string "Bluetooth RPMsg CPU name"
default "cp"
help
Bluetooth default server name
config BLUETOOTH_SOCKET_BUF_SIZE
int "Bluetooth socket buffer size"
default 1024
help
Bluetooth socket buffer size
config BLUETOOTH_SOCKET_PORT
int "Bluetooth socket port num"
default 140704
help
Socket port of inet
endif #BLUETOOTH_FRAMEWORK_SOCKET_IPC
config BLUETOOTH_FRAMEWORK_ASYNC
bool "Enable Bluetooth Framework async API"
default n
help
Enable Bluetooth Framework async API
choice
prompt "Select feature API"
default BLUETOOTH_FEATURE_NONE
config BLUETOOTH_FEATURE_NONE
bool "Not supporting Bluetooth feature API."
config BLUETOOTH_FEATURE
bool "Support Bluetooth synchronization API."
depends on FEATURE_FRAMEWORK
config BLUETOOTH_FEATURE_ASYNC
bool "Support Bluetooth asynchronous API."
depends on FEATURE_FRAMEWORK
depends on BLUETOOTH_FRAMEWORK_ASYNC
endchoice
endif #BLUETOOTH_FRAMEWORK
menu "Core"
config BLUETOOTH_BREDR_SUPPORT
bool "Bluetooth BREDR"
default y
config BLUETOOTH_BLE_SUPPORT
bool "Bluetooth LE"
default n
config BLUETOOTH_BLE_ADV
bool "LE Advertising support"
default n
config BLUETOOTH_BLE_SCAN
bool "LE Scan support"
default n
config BLUETOOTH_BLE_SCAN_FILTER
bool "LE Scan Filter support"
default n
depends on BLUETOOTH_BLE_SCAN
config BLUETOOTH_HCI_FILTER
bool "Enable Bluetooth HCI filter"
default y
help
Enable Bluetooth HCI filter
config BLUETOOTH_L2CAP
bool "L2CAP dynamic channel support"
default n
if BLUETOOTH_L2CAP
config BLUETOOTH_L2CAP_OUTGOING_MTU
int "Outgoing MTU"
default 2048
help
config L2CAP Outgoing MTU
endif #BLUETOOTH_L2CAP
choice
prompt "Select BT vendor"
default BLUETOOTH_VENDOR_NONE
config BLUETOOTH_VENDOR_BES
bool "Bluetooth vendor BES"
config BLUETOOTH_VENDOR_ACTIONS
bool "Bluetooth vendor ACTIONS"
config BLUETOOTH_VENDOR_NONE
bool "Bluetooth vendor NONE"
endchoice
config BLUETOOTH_PM_MAX_TIMER_NUMBER
int "Bluetooth PM maximum number of timers"
default 16
config BLUETOOTH_UPGRADE
bool "Enable Bluetooth Storage transformation tool for upgrading OS"
default n
depends on KVDB
depends on UNQLITE
config BLUETOOTH_TASK_STACK_SIZE
int "Bluetooth task stack size"
default 8192
help
This cofiguration is used to set the stack size of bluetooth task.
config BLUETOOTH_SERVICE_LOOP_THREAD_STACK_SIZE
int "Bluetooth Service loop thread stack size"
default 8192
config BLUETOOTH_SERVICE_LOOP_THREAD_PRIORITY
int "Bluetooth Service loop thread priority"
default 103
config BLUETOOTH_MAX_SAVED_REMOTE_UUIDS_LEN
int "Bluetooth saved remote uuids length"
default 80
config BLUETOOTH_MAX_REGISTER_NUM
int "Max register callback nums"
default 4
endmenu #Core
menuconfig BLUETOOTH_SERVICE
bool "Service"
default n
help
Enable Bluetooth Service
if BLUETOOTH_SERVICE
menuconfig BLUETOOTH_SERVER
bool "Bluetooth Server"
default n
help
Enable Bluetooth server
if BLUETOOTH_SERVER
config BLUETOOTH_SERVER_NAME
string "Blutooth Server name"
default "bluetoothd"
help
Bluetooth default server name
config BLUETOOTH_IPC_JOIN_LOOP
bool "Let IPC join service loop"
default n
help
Bluetooth IPC join service loop
config BLUETOOTH_NET_IPv4
bool "Let Bluetooth Server listen message from network"
default n
depends on NET_IPv4
help
Bluetooth server listen message
endif #BLUETOOTH_SERVER
if BLUETOOTH_BREDR_SUPPORT
menu "Bluetooth BREDR Config"
choice
prompt "Select BR stack"
default BLUETOOTH_STACK_BREDR_BLUELET
config BLUETOOTH_STACK_BREDR_BLUELET
bool "Classic BT stack use bluelet"
select LIB_BLUELET
config BLUETOOTH_STACK_BREDR_ZBLUE
bool "Classic BT stack use zblue"
config BLUETOOTH_STACK_NOT_SUPPORT_CLASSIC_BT
bool "Not support classic BT stack"
endchoice
endmenu #Bluetooth BREDR Config
endif #BLUETOOTH_BREDR_SUPPORT
if BLUETOOTH_BLE_SUPPORT
menu "Bluetooth LE Config"
choice
prompt "Select LE stack"
default BLUETOOTH_STACK_LE_BLUELET
config BLUETOOTH_STACK_LE_BLUELET
bool "BLE Stack use Bluelet"
select LIB_BLUELET
config BLUETOOTH_STACK_LE_ZBLUE
bool "BLE Stack use Zblue"
config BLUETOOTH_STACK_NOT_SUPPORT_LE
bool "Not support BLE Stack"
endchoice
config BLUETOOTH_LE_SCANNER_MAX_NUM
int "LE Scanner max register number"
default 2
help
LE Scanner max register number
config BLUETOOTH_LE_ADVERTISER_MAX_NUM
int "LE Advertiser max register number"
default 2
help
LE Advertiser max register number
config BLUETOOTH_CONNECTION_MANAGER
bool "Bluetooth connection manager support"
default y
config LE_DLF_SUPPORT
bool "Enable LE DLF support"
depends on BLUETOOTH_CONNECTION_MANAGER
default n
endmenu #Bluetooth LE Config
endif #BLUETOOTH_BLE_SUPPORT
choice
prompt "Select Bluetooth Storage Method(Unqlite, KVDB)"
default BLUETOOTH_STORAGE_PROPERTY_SUPPORT
config BLUETOOTH_STORAGE_PROPERTY_SUPPORT
bool "Bluetooth Storage KVDB Property support"
depends on KVDB
config BLUETOOTH_STORAGE_UNQLITE_SUPPORT
bool "Bluetooth Storage uv_db support"
depends on UNQLITE
endchoice
config BLUETOOTH_STORAGE_UPDATE
bool "Bluetooth Storage update"
default y
depends on BLUETOOTH_STORAGE_PROPERTY_SUPPORT
config BLUETOOTH_SERVICE_HCI_UART_NAME
string "HCI uart driver name"
default "/dev/ttyHCI0"
config BLUETOOTH_HCI_BRIDGE_MODE
bool "HCI bridge mode"
default n
config CONFIG_BLUETOOTH_DEFAULT_COD
hex "Default class of device"
default 0x00280704
help
Set default class of device
endif #BLUETOOTH_SERVICE
menu "Profiles"
menuconfig BLUETOOTH_A2DP
bool "Advanced Audio Distribution Profile (A2DP)"
default n
depends on MEDIA
if BLUETOOTH_A2DP
config BLUETOOTH_A2DP_SOURCE
bool "A2DP source role support"
default n
select BLUETOOTH_AVRCP_TARGET
config ZBLUE_A2DP_SBC_MAX_BIT_POOL
int "A2DP sbc codec max bit pool"
default 32
depends on BLUETOOTH_STACK_BREDR_ZBLUE
help
A2DP sbc codec max bit pool 1~53
if BLUETOOTH_A2DP_SOURCE
config BLUETOOTH_A2DP_PEER_PARTIAL_RECONN
bool "Bluetooth A2DP peer partial reconnect support"
default y
help
Bluetooth A2DP peer partial reconnect support
config ZBLUE_A2DP_SOURCE_BUF_SIZE
int "A2DP source buffer size"
default 660
depends on BLUETOOTH_STACK_BREDR_ZBLUE
help
Buffer size is related to L2CAP TX MTU
endif #BLUETOOTH_A2DP_SOURCE
config BLUETOOTH_A2DP_SINK
bool "A2DP sink role support"
default n
select BLUETOOTH_AVRCP_CONTROL
config BLUETOOTH_A2DP_AAC_CODEC
bool "Bluetooth A2DP AAC codec support"
default n
config BLUETOOTH_A2DP_MAX_CONNECTIONS
int "Maximum A2DP connections"
default 1
help
Maximum A2DP connections
endif #BLUETOOTH_A2DP
menu "Audio/Video Remote Control Profile (AVRCP)"
config BLUETOOTH_AVRCP_TARGET
bool "Audio/Video Remote Control Profile (Target) support"
default n
config BLUETOOTH_AVRCP_CONTROL
bool "Audio/Video Remote Control Profile (Control) support"
default n
config BLUETOOTH_AVRCP_ABSOLUTE_VOLUME
bool "Audio/Video Remote Control Profile support absolute volume"
default n
depends on (BLUETOOTH_AVRCP_CONTROL || BLUETOOTH_AVRCP_TARGET) && ((BLUETOOTH_STACK_BREDR_BLUELET && BLUELET_AVRCP_TG_ABSVOL_SUPPORT) || (BLUETOOTH_STACK_BREDR_ZBLUE))
endmenu #Audio/Video Remote Control Profile
menu "Hands-Free Profile (HFP)"
config BLUETOOTH_HFP_HF
bool "HFP hands-free profile support"
default n
if BLUETOOTH_HFP_HF
config HFP_HF_MAX_CONNECTIONS
int "HFP hands-free max connections"
default 1
config HFP_HF_WEBCHAT_BLOCKER
bool "Block webchat automatically"
default y
endif #BLUETOOTH_HFP_HF
config BLUETOOTH_HFP_AG
bool "HFP audio-gateway profile support"
default n
if BLUETOOTH_HFP_AG
config HFP_AG_MAX_CONNECTIONS
int "HFP audio-gateway max connections"
default 1
config BLUETOOTH_HFP_AG_PRIMARY_SLOT
int "HFP select primary modem slot"
default 0
endif # BLUETOOTH_HFP_AG
config BLUETOOTH_SCO_CTRL_PATH
string "Bluetooth SCO Transport Ctrl Path"
default "sco_ctrl"
endmenu #Hands-Free Profile
menu "LE Audio"
comment "There should be two \"LE Audio support\" options, if you only see one, please enable \"Bluetooth BLE support\" in Framework"
config BLUETOOTH_BLE_AUDIO
bool "LE Audio support"
default n
if BLUETOOTH_BLE_SUPPORT
config BLUETOOTH_LE_AUDIO_SUPPORT
bool "LE Audio support"
default n
endif #BLUETOOTH_BLE_SUPPORT
menuconfig BLUETOOTH_LEAUDIO_CLIENT
bool "Bluetooth LE Audio Client"
default n
if BLUETOOTH_LEAUDIO_CLIENT
config BLUETOOTH_LEAUDIO_TBS
bool "Enable Bluetooth LE Audio TBS feature"
default n
if BLUETOOTH_LEAUDIO_TBS
config BLUETOOTH_LEAUDIO_TBS_PRIMARY_SLOT
int "LE Audio TBS select primary modem slot"
default 0
config BLUETOOTH_LEAUDIO_TBS_CALL_NAME
string "LE Audio call name"
default "/ril_0/voicecall0"
endif # BLUETOOTH_LEAUDIO_TBS
config BLUETOOTH_LEAUDIO_MCS
bool "Enable Bluetooth LE Audio MCS feature"
default n
config BLUETOOTH_LEAUDIO_VMICP
bool "Enable Bluetooth LE Audio VMICP feature"
default n
config BLUETOOTH_LEAUDIO_CLIENT_MAX_CONNECTIONS
int "LE Audio Client max connections"
default 4
help
LE Audio Client max connections
config BLUETOOTH_LEAUDIO_CLIENT_MAX_GROUP
int "LE Audio Client max group"
default 4
help
LE Audio Client max HFP_AG_MAX_CONNECTIONS
config BLUETOOTH_LEAUDIO_CLIENT_MAX_DEVICES
int "LE Audio Client max devices"
default 8
help
LE Audio Client max devices
config BLUETOOTH_LEAUDIO_CLIENT_MAX_ALLOC_NUMBER
int "LE Audio Client max alloc number"
default 64
help
LE Audio Client max group
config BLUETOOTH_LEAUDIO_CLIENT_ASE_MAX_NUMBER
int "LE Audio Client max ase number"
default 2
help
LE Audio Client max ase number
config BLUETOOTH_LEAUDIO_CLIENT_PAC_MAX_NUMBER
int "LE Audio Client max pac number"
default 3
help
LE Audio Client max pac number
config BLUETOOTH_LEAUDIO_CLIENT_CIS_MAX_NUMBER
int "LE Audio Client max cis number"
default 2
help
LE Audio Client max cis number
config BLUETOOTH_LEAUDIO_CLIENT_METADATA_MAX_NUMBER
int "LE Audio Client max metadata number"
default 4
help
LE Audio Client max metadata number
endif # BLUETOOTH_LEAUDIO_CLIENT
menuconfig BLUETOOTH_LEAUDIO_SERVER
bool "Bluetooth LE Audio Server"
default n
if BLUETOOTH_LEAUDIO_SERVER
config BLUETOOTH_LEAUDIO_CCP
bool "Enable Bluetooth LE Audio CCP feature"
default n
if BLUETOOTH_LEAUDIO_CCP
config BLUETOOTH_LEAUDIO_SERVER_CALL_CONTROL_NUMBER
int "LE Audio TBS server number"
default 1
help
LE Audio TBS server number
endif # BLUETOOTH_LEAUDIO_CCP
config BLUETOOTH_LEAUDIO_MCP
bool "Enable Bluetooth LE Audio MCP feature"
default n
if BLUETOOTH_LEAUDIO_MCP
config BLUETOOTH_LEAUDIO_SERVER_MEDIA_CONTROL_NUMBER
int "LE Audio MCS server number"
default 1
help
LE Audio MCS server number
endif # BLUETOOTH_LEAUDIO_MCP
menuconfig BLUETOOTH_LEAUDIO_VMICS
bool "Enable Bluetooth LE Audio VMICS feature"
default n
if BLUETOOTH_LEAUDIO_VMICS
config BLUETOOTH_LEAUDIO_VCS_VOLUME_STEP
int "LE Audio Server VCS volume step size"
default 2
help
LE Audio Server VCS volume step size
config BLUETOOTH_LEAUDIO_VOCS_NUMBER
int "LE Audio Server VOCS numnber"
default 0
help
LE Audio Server VOCS number
config BLUETOOTH_LEAUDIO_AICS_NUMBER
int "LE Audio Server AICS numnber"
default 0
help
LE Audio Server AICS numnber
config BLUETOOTH_LEAUDIO_VCS_VOLUME_INITIAL
int "LE Audio Server VCS initial volume value"
default 125
help
LE Audio Server VCS volume initial value
config BLUETOOTH_LEAUDIO_VCS_UNMUTED
int "LE Audio Server VCS unmute"
default 0
help
LE Audio Server VCS unmute
config BLUETOOTH_LEAUDIO_VCS_VOLUME_DEFAULT_SETTING
int "LE Audio Server VCS vol settings"
default 0
help
LE Audio Server VCS vol settings
config BLUETOOTH_LEAUDIO_MICS_NUMBER
int "LE Audio Server MICS numnber"
default 0
help
LE Audio Server MICS number
endif # BLUETOOTH_LEAUDIO_VMICS
config BLUETOOTH_LEAUDIO_SERVER_SINK_ASE_NUMBER
int "LE Audio Server Sink number"
default 1
help
LE Audio Server Sink ase number
config BLUETOOTH_LEAUDIO_SERVER_SOURCE_ASE_NUMBER
int "LE Audio Server Source number"
default 1
help
LE Audio Server Source ase number
config BLUETOOTH_LEAUDIO_SERVER_BASS_STATE_NUMBER
int "LE Audio Server Bass state number"
default 1
help
LE Audio Server Bass state number
config BLUETOOTH_LEAUDIO_SERVER_SOURCE
bool "Enable LE Audio Server source"
default y
config BLUETOOTH_LEAUDIO_SERVER_SOURCE_LOCATION
int "LE Audio Server source location"
default 1
help
LE Audio Server source location
config BLUETOOTH_LEAUDIO_SERVER_SINK_LOCATION
int "LE Audio Server sink location"
default 1
help
LE Audio Server sink location
config BLUETOOTH_LEAUDIO_SERVER_CSIS_SIZE
int "LE Audio Server CSIS set size"
default 1
help
LE Audio Server CSIS set size
config BLUETOOTH_LEAUDIO_SERVER_CSIS_RANK
int "LE Audio Server CSIS rank"
default 1
help
LE Audio Server CSIS rank
endif # BLUETOOTH_LEAUDIO_SERVER
endmenu #Bluetooth LE Audio
menu "Bluetooth Audio Transport"
config BLUETOOTH_AUDIO_TRANS_RPSMG_SERVER
bool "RPMsg audio transport server"
default n
config BLUETOOTH_AUDIO_TRANS_ID_SOURCE_CTRL
int "Bluetooth Audio Transport Source Ctrl Channel ID"
default 0
config BLUETOOTH_AUDIO_TRANS_ID_SOURCE_AUDIO
int "Bluetooth Audio Transport Source Audio Channel ID"
default 1
config BLUETOOTH_AUDIO_TRANS_ID_SINK_CTRL
int "Bluetooth Audio Transport Sink Ctrl Channel ID"
default 2
config BLUETOOTH_AUDIO_TRANS_ID_SINK_AUDIO
int "Bluetooth Audio Transport Sink Audio Channel ID"
default 3
config BLUETOOTH_AUDIO_TRANS_ID_HFP_CTRL
int "Bluetooth Audio Transport SCO Ctrl Channel ID"
default 4
config BLUETOOTH_LEA_SINK_CTRL_PATH
string "Bluetooth LE Audio Transport Sink Ctrl Path"
default "lea_sink_ctrl"
config BLUETOOTH_LEA_SINK_DATA_PATH
string "Bluetooth LE Audio Transport Sink Data Path"
default "lea_sink_data"
config BLUETOOTH_LEA_SOURCE_CTRL_PATH
string "Bluetooth LE Audio Transport Source Ctrl Path"
default "lea_source_ctrl"
config BLUETOOTH_LEA_SOURCE_DATA_PATH
string "Bluetooth LE Audio Transport Source Data Path"
default "lea_source_data"
config BLUETOOTH_A2DP_SINK_CTRL_PATH
string "Bluetooth A2DP Audio Transport Sink Ctrl Path"
default "a2dp_sink_ctrl"
config BLUETOOTH_A2DP_SINK_DATA_PATH
string "Bluetooth A2DP Audio Transport Sink Data Path"
default "a2dp_sink_data"
config BLUETOOTH_A2DP_SOURCE_CTRL_PATH
string "Bluetooth A2DP Audio Transport Source Ctrl Path"
default "a2dp_source_ctrl"
config BLUETOOTH_A2DP_SOURCE_DATA_PATH
string "Bluetooth A2DP Audio Transport Source Data Path"
default "a2dp_source_data"
endmenu #Bluetooth Audio Transport config
config BLUETOOTH_GATT
bool "Generic ATT Profile Support(deprecated)"
default y
menuconfig BLUETOOTH_GATT_CLIENT
bool "Generic Attribute Profile (GATT) Client"
default n if !BLUETOOTH_GATT
default y if BLUETOOTH_GATT
if BLUETOOTH_GATT_CLIENT
config BLUETOOTH_GATTC_MAX_CONNECTIONS
int "GATT Client max connections"
default 8
config GATT_CLIENT_SERVICE_MAX
int "Maximum number of discovered services per connection"
default 20
depends on BLUETOOTH_GATT_CLIENT && BLUETOOTH_STACK_LE_ZBLUE && BT_GATT_CLIENT
help
The maximum number of GATT services that can be stored per BLE connection
when using the ZBLUE stack.
config GATT_CLIENT_ELEMENT_MAX
int "Maximum number of discovered GATT attributes per connection"
default 200
depends on BLUETOOTH_GATT_CLIENT && BLUETOOTH_STACK_LE_ZBLUE && BT_GATT_CLIENT
help
The maximum number of GATT attribute elements (e.g., characteristics
and descriptors) that can be stored per BLE connection
when using the ZBLUE stack.
config GATT_CLIENT_CHAR_PER_SERVICE_MAX
int "Maximum number of characteristics per service"
default 100
depends on BLUETOOTH_GATT_CLIENT && BLUETOOTH_STACK_LE_ZBLUE && BT_GATT_CLIENT
help
The maximum number of characteristics that can be discovered and stored
under a single GATT service when using the ZBLUE stack.
endif # BLUETOOTH_GATT_CLIENT
menuconfig BLUETOOTH_GATT_SERVER
bool "Generic Attribute Profile (GATT) Server"
default n if !BLUETOOTH_GATT
default y if BLUETOOTH_GATT
if BLUETOOTH_GATT_SERVER
config BLUETOOTH_GATTS_MAX_CONNECTIONS
int "GATT Server max connections"
default 4
config BLUETOOTH_GATTS_MAX_ATTRIBUTE_NUM
int "GATT Server max number of attributes contained in a table"
default 10
config BLUETOOTH_GATTS_CACHE_SUPPORT
bool "Enable GATT Server Cache Support"
default y
depends on BLUETOOTH_BLE_SUPPORT
help
Enable internal GATT attribute table hash comparison.
On reconnect, trusted devices may receive Service Changed indications
if attribute changes are detected.
endif # BLUETOOTH_GATT_SERVER
menuconfig BLUETOOTH_SPP
bool "Serial Port Profile (SPP)"
default n
if BLUETOOTH_SPP
config BLUETOOTH_SPP_MAX_CONNECTIONS
int "SPP max connections"
default 1
config BLUETOOTH_SPP_SERVER_MAX_CONNECTIONS
int "SPP Server max connections"
default 8
config BLUETOOTH_SPP_RPMSG_NET
bool "SPP RPMsg net support"
default n
depends on NET_RPMSG
endif #BLUETOOTH_SPP
config BLUETOOTH_HID_DEVICE
bool "Human Interface Device Profile (HID)"
default n
config BLUETOOTH_PAN
bool "Personal Area Network Profile (PAN)"
default n
depends on ALLOW_BSD_COMPONENTS
help
config NET_TUN_PKTSIZE should set 1518
endmenu #Profiles
menu "Debug"
config BLUETOOTH_DEBUG_TIMEVAL
bool "Enable Bluetooth debug time"
default n
help
Enable this option to include Bluetooth debug time functionality.
config BLUETOOTH_DEBUG_TIME_UNIT_US
bool "Use microseconds for Bluetooth debug time"
default n
depends on BLUETOOTH_DEBUG_TIMEVAL
help
Enable this option to use microseconds (us) for Bluetooth debug time.
If disabled, milliseconds (ms) will be used by default.
config BLUETOOTH_DEBUG_MEMORY
bool "Enable Bluetooth debug memory"
default n
help
Enable this option to override standard memory allocation functions
(malloc, calloc, free) with Bluetooth-specific versions (bt_malloc, etc).
Useful for tracking memory usage and debugging in Bluetooth modules.
config BLUETOOTH_DEBUG_TRACE
bool "Enable Bluetooth debug trace"
default n
help
Enable Bluetooth debug trace tools.
if BLUETOOTH_DEBUG_TRACE
config BLUETOOTH_TRACE_BUFFER_SIZE
int "Bluetooth trace buffer size"
default 512
endif #BLUETOOTH_DEBUG_TRACE
config MAX_SNOOP_FILE_SIZE
int "Maximum size of the snoop log file"
default 1048576
help
Maximum size of the snoop log file
config BLUETOOTH_DUMPBUFFER
bool "Bluetooth dumpbuffer"
default n
config BLUETOOTH_DFX
bool "Enable Bluetooth DFX"
default y
depends on DFX_EVENT
help
Enable Bluetooth DFX
config BLUETOOTH_LOG
bool "Enable Bluetooth log"
default y
help
Enable Bluetooth log
if BLUETOOTH_LOG
config BLUETOOTH_SERVICE_LOG_LEVEL
int "Bluetooth Service log level"
default 7
depends on BLUETOOTH_SERVICE
help
Set BT Service log level <0~7>
endif #BLUETOOTH_LOG
endmenu #Debug
config BLUETOOTH_TOOLS
bool "Bluetooth profile test tools (BT_TOOLS)"
default n
select BLUETOOTH_FRAMEWORK
menuconfig APP_BT_SAMPLE_CODE
bool "Sample Code"
default n
select BLUETOOTH_FRAMEWORK
if APP_BT_SAMPLE_CODE
config APP_BT_SAMPLE_CODE_BASIC
bool "Bluetooth basic sample code"
default n
config APP_BT_SAMPLE_CODE_ENABLE
bool "Bluetooth enable sample code"
default n
config APP_BT_SAMPLE_CODE_DISCOVERY
bool "Bluetooth discovery sample code"
default n
config APP_BT_SAMPLE_CODE_CREATEBOND
bool "Bluetooth createbond sample code"
default n
config APP_BT_SAMPLE_CODE_ACCEPTBOND
bool "Bluetooth acceptbond sample code"
default n
endif #APP_BT_SAMPLE_CODE
endif #BLUETOOTH

10
LICENSE Normal file
View File

@ -0,0 +1,10 @@
Copyright (C) 2024 Xiaomi Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

23
Make.defs Normal file
View File

@ -0,0 +1,23 @@
#
# Copyright (C) 2020 Xiaomi Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
ifeq ($(CONFIG_BLUETOOTH), y)
CONFIGURED_APPS += $(APPDIR)/frameworks/connectivity/bluetooth
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/framework/include
CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/framework/include
endif

711
Makefile Normal file
View File

@ -0,0 +1,711 @@
#
# Copyright (C) 2020 Xiaomi Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
include $(APPDIR)/Make.defs
ifeq ($(CONFIG_BLUETOOTH), y)
CSRCS += framework/common/*.c
CSRCS += framework/api/bluetooth.c
CSRCS += framework/api/bt_adapter.c
CSRCS += framework/api/bt_device.c
ifeq ($(CONFIG_BLUETOOTH_A2DP_SINK), y)
CSRCS += framework/api/bt_a2dp_sink.c
endif #CONFIG_BLUETOOTH_A2DP_SINK
ifeq ($(CONFIG_BLUETOOTH_A2DP_SOURCE), y)
CSRCS += framework/api/bt_a2dp_source.c
endif #CONFIG_BLUETOOTH_A2DP_SOURCE
ifeq ($(CONFIG_BLUETOOTH_AVRCP_TARGET), y)
CSRCS += framework/api/bt_avrcp_target.c
endif #CONFIG_BLUETOOTH_AVRCP_TARGET
ifeq ($(CONFIG_BLUETOOTH_AVRCP_CONTROL), y)
CSRCS += framework/api/bt_avrcp_control.c
endif #CONFIG_BLUETOOTH_AVRCP_CONTROL
ifeq ($(CONFIG_BLUETOOTH_HFP_HF), y)
CSRCS += framework/api/bt_hfp_hf.c
endif #CONFIG_BLUETOOTH_HFP_HF
ifeq ($(CONFIG_BLUETOOTH_HFP_AG), y)
CSRCS += framework/api/bt_hfp_ag.c
endif #CONFIG_BLUETOOTH_HFP_AG
ifeq ($(CONFIG_BLUETOOTH_SPP), y)
CSRCS += framework/api/bt_spp.c
endif #CONFIG_BLUETOOTH_SPP
ifeq ($(CONFIG_BLUETOOTH_HID_DEVICE), y)
CSRCS += framework/api/bt_hid_device.c
endif #CONFIG_BLUETOOTH_HID_DEVICE
ifeq ($(CONFIG_BLUETOOTH_GATT_CLIENT), y)
CSRCS += framework/api/bt_gattc.c
endif #CONFIG_BLUETOOTH_GATT_CLIENT
ifeq ($(CONFIG_BLUETOOTH_GATT_SERVER), y)
CSRCS += framework/api/bt_gatts.c
endif #CONFIG_BLUETOOTH_GATT_SERVER
ifeq ($(CONFIG_BLUETOOTH_L2CAP), y)
CSRCS += framework/api/bt_l2cap.c
endif #CONFIG_BLUETOOTH_L2CAP
ifeq ($(CONFIG_BLUETOOTH_BLE_ADV), y)
CSRCS += framework/api/bt_le_advertiser.c
endif #CONFIG_BLUETOOTH_BLE_ADV
ifeq ($(CONFIG_BLUETOOTH_BLE_SCAN), y)
CSRCS += framework/api/bt_le_scan.c
endif #CONFIG_BLUETOOTH_BLE_SCAN
ifeq ($(CONFIG_BLUETOOTH_LOG), y)
CSRCS += framework/api/bt_trace.c
endif
ifeq ($(CONFIG_BLUETOOTH_PAN), y)
CSRCS += framework/api/bt_pan.c
endif #CONFIG_BLUETOOTH_PAN
ifeq ($(CONFIG_BLUETOOTH_BLE_AUDIO), y)
CSRCS := framework/api/bt_lea*.c
endif #CONFIG_BLUETOOTH_BLE_AUDIO
ifeq ($(CONFIG_BLUETOOTH_FRAMEWORK_SOCKET_IPC), y)
CSRCS += service/ipc/bluetooth_ipc.c
CSRCS += framework/socket/bt_device.c
CSRCS += framework/socket/bt_adapter.c
CSRCS += framework/socket/bluetooth.c
CSRCS += service/ipc/socket/src/bt_socket.c
CSRCS += service/ipc/socket/src/bt_socket_manager.c
CSRCS += service/ipc/socket/src/bt_socket_client.c
CSRCS += service/ipc/socket/src/bt_socket_server.c
CSRCS += service/ipc/socket/src/bt_socket_device.c
CSRCS += service/ipc/socket/src/bt_socket_adapter.c
CSRCS += service/ipc/socket/src/bt_socket_bluetooth.c
ifeq ($(CONFIG_BLUETOOTH_A2DP_SINK), y)
CSRCS += framework/socket/bt_a2dp_sink.c
CSRCS += service/ipc/socket/src/bt_socket_a2dp_sink.c
endif #CONFIG_BLUETOOTH_A2DP_SINK
ifeq ($(CONFIG_BLUETOOTH_A2DP_SOURCE), y)
CSRCS += framework/socket/bt_a2dp_source.c
CSRCS += service/ipc/socket/src/bt_socket_a2dp_source.c
endif #CONFIG_BLUETOOTH_A2DP_SOURCE
ifeq ($(CONFIG_BLUETOOTH_AVRCP_TARGET), y)
CSRCS += framework/socket/bt_avrcp_target.c
CSRCS += service/ipc/socket/src/bt_socket_avrcp_target.c
endif #CONFIG_BLUETOOTH_AVRCP_TARGET
ifeq ($(CONFIG_BLUETOOTH_AVRCP_CONTROL), y)
CSRCS += framework/socket/bt_avrcp_control.c
CSRCS += service/ipc/socket/src/bt_socket_avrcp_control.c
endif #CONFIG_BLUETOOTH_AVRCP_CONTROL
ifeq ($(CONFIG_BLUETOOTH_HFP_HF), y)
CSRCS += framework/socket/bt_hfp_hf.c
CSRCS += service/ipc/socket/src/bt_socket_hfp_hf.c
endif #CONFIG_BLUETOOTH_HFP_HF
ifeq ($(CONFIG_BLUETOOTH_HFP_AG), y)
CSRCS += framework/socket/bt_hfp_ag.c
CSRCS += service/ipc/socket/src/bt_socket_hfp_ag.c
endif #CONFIG_BLUETOOTH_HFP_AG
ifeq ($(CONFIG_BLUETOOTH_SPP), y)
CSRCS += framework/socket/bt_spp.c
CSRCS += service/ipc/socket/src/bt_socket_spp.c
endif #CONFIG_BLUETOOTH_SPP
ifeq ($(CONFIG_BLUETOOTH_HID_DEVICE), y)
CSRCS += framework/socket/bt_hid_device.c
CSRCS += service/ipc/socket/src/bt_socket_hid_device.c
endif #CONFIG_BLUETOOTH_HID_DEVICE
ifeq ($(CONFIG_BLUETOOTH_GATT_CLIENT), y)
CSRCS += framework/socket/bt_gattc.c
CSRCS += service/ipc/socket/src/bt_socket_gattc.c
endif #CONFIG_BLUETOOTH_GATT_CLIENT
ifeq ($(CONFIG_BLUETOOTH_GATT_SERVER), y)
CSRCS += framework/socket/bt_gatts.c
CSRCS += service/ipc/socket/src/bt_socket_gatts.c
endif #CONFIG_BLUETOOTH_GATT_SERVER
ifeq ($(CONFIG_BLUETOOTH_L2CAP), y)
CSRCS += framework/socket/bt_l2cap.c
CSRCS += service/ipc/socket/src/bt_socket_l2cap.c
endif #CONFIG_BLUETOOTH_L2CAP
ifeq ($(CONFIG_BLUETOOTH_BLE_ADV), y)
CSRCS += framework/socket/bt_le_advertiser.c
CSRCS += service/ipc/socket/src/bt_socket_advertiser.c
endif #CONFIG_BLUETOOTH_BLE_ADV
ifeq ($(CONFIG_BLUETOOTH_BLE_SCAN), y)
CSRCS += framework/socket/bt_le_scan.c
CSRCS += service/ipc/socket/src/bt_socket_scan.c
endif #CONFIG_BLUETOOTH_BLE_SCAN
ifeq ($(CONFIG_BLUETOOTH_PAN), y)
CSRCS += framework/socket/bt_pan.c
CSRCS += service/ipc/socket/src/bt_socket_pan.c
endif #CONFIG_BLUETOOTH_PAN
ifeq ($(CONFIG_BLUETOOTH_LOG), y)
CSRCS += framework/socket/bt_trace.c
CSRCS += service/ipc/socket/src/bt_socket_log.c
endif #CONFIG_BLUETOOTH_BLE_AUDIO
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/ipc/socket/include
ifeq ($(CONFIG_BLUETOOTH_FRAMEWORK_ASYNC), y)
CSRCS += framework/socket/async/*.c
CSRCS += framework/btwrap/async/*.c
endif #CONFIG_BLUETOOTH_FRAMEWORK_ASYNC
endif #CONFIG_BLUETOOTH_FRAMEWORK_SOCKET_IPC
CSRCS += service/src/manager_service.c
CSRCS += service/common/index_allocator.c
ifeq ($(CONFIG_BLUETOOTH_CONNECTION_MANAGER), y)
CSRCS += service/src/connection_manager.c
endif #CONFIG_BLUETOOTH_CONNECTION_MANAGER
ifeq ($(CONFIG_BLUETOOTH_STORAGE_PROPERTY_SUPPORT), y)
CSRCS += service/common/storage_property.c
else
CSRCS += service/common/storage.c
endif
ifeq ($(CONFIG_BLUETOOTH_STORAGE_UPDATE), y)
CSRCS += tools/storage_update/storage_version_4.c
CSRCS += tools/storage_update/storage_version_5.c
endif #CONFIG_BLUETOOTH_STORAGE_UPDATE
ifeq ($(CONFIG_BLUETOOTH_DEBUG_MEMORY),y)
CSRCS += debug/bt_memory.c
endif
ifeq ($(CONFIG_BLUETOOTH_DEBUG_TRACE), y)
CSRCS += service/debug/bt_trace.c
endif
ifeq ($(CONFIG_BLUETOOTH_SERVICE), y)
CSRCS += service/common/service_loop.c
CSRCS += service/src/adapter_service.c
CSRCS += service/src/adapter_state.c
CSRCS += service/src/btservice.c
CSRCS += service/src/device.c
ifeq ($(CONFIG_BLUETOOTH_BREDR_SUPPORT), y)
CSRCS += service/src/power_manager.c
endif #CONFIG_BLUETOOTH_BREDR_SUPPORT
CSRCS += service/vendor/bt_vendor.c
CSRCS += service/src/hci_parser.c
ifeq ($(CONFIG_BLUETOOTH_BLE_ADV), y)
CSRCS += service/src/advertising.c
endif #CONFIG_BLUETOOTH_BLE_ADV
ifeq ($(CONFIG_BLUETOOTH_BLE_SCAN), y)
CSRCS += service/src/scan_manager.c
CSRCS += service/src/scan_record.c
CSRCS += service/src/scan_filter.c
endif #CONFIG_BLUETOOTH_BLE_SCAN
ifeq ($(CONFIG_BLUETOOTH_L2CAP), y)
CSRCS += service/src/l2cap_service.c
endif #CONFIG_BLUETOOTH_L2CAP
ifeq ($(CONFIG_LE_DLF_SUPPORT), y)
CSRCS += service/src/connection_manager_dlf.c
endif #CONFIG_LE_DLF_SUPPORT
CSRCS += service/stacks/*.c
ifneq ($(CONFIG_BLUETOOTH_STACK_BREDR_BLUELET)$(CONFIG_BLUETOOTH_STACK_LE_BLUELET),)
CSRCS += service/stacks/bluelet/*.c
endif
ifneq ($(CONFIG_BLUETOOTH_STACK_BREDR_ZBLUE)$(CONFIG_BLUETOOTH_STACK_LE_ZBLUE),)
CSRCS += service/stacks/zephyr/hci_h4.c
CSRCS += service/stacks/zephyr/sal_debug_interface.c
CSRCS += service/stacks/zephyr/sal_zblue.c
CSRCS += service/stacks/zephyr/sal_adapter_interface.c
ifeq ($(CONFIG_BLUETOOTH_CONNECTION_MANAGER), y)
CSRCS += service/stacks/zephyr/sal_connection_manager.c
endif
ifeq ($(CONFIG_BLUETOOTH_SPP), y)
CSRCS += service/stacks/zephyr/sal_spp_interface.c
endif #CONFIG_BLUETOOTH_SPP
ifeq ($(CONFIG_BLUETOOTH_A2DP), y)
CSRCS += service/stacks/zephyr/sal_a2dp_interface.c
endif #CONFIG_BLUETOOTH_A2DP
ifneq ($(CONFIG_BLUETOOTH_AVRCP_CONTROL)$(CONFIG_BLUETOOTH_AVRCP_TARGET),)
CSRCS += service/stacks/zephyr/sal_avrcp_interface.c
endif #CONFIG_BLUETOOTH_AVRCP_CONTROL/CONFIG_BLUETOOTH_AVRCP_TARGET
ifeq ($(CONFIG_BLUETOOTH_HFP_HF), y)
CSRCS += service/stacks/zephyr/sal_hfp_hf_interface.c
endif #CONFIG_BLUETOOTH_HFP_HF
ifeq ($(CONFIG_BLUETOOTH_HFP_AG), y)
CSRCS += service/stacks/zephyr/sal_hfp_ag_interface.c
endif #CONFIG_BLUETOOTH_HFP_AG
ifeq ($(CONFIG_BLUETOOTH_HID_DEVICE), y)
CSRCS += service/stacks/zephyr/sal_hid_device_interface.c
endif #CONFIG_BLUETOOTH_HID_DEVICE
ifeq ($(CONFIG_BLUETOOTH_STACK_LE_ZBLUE), y)
CSRCS += service/stacks/zephyr/sal_adapter_le_interface.c
ifeq ($(CONFIG_BLUETOOTH_BLE_ADV), y)
CSRCS += service/stacks/zephyr/sal_le_advertise_interface.c
endif #CONFIG_BLUETOOTH_BLE_ADV
ifeq ($(CONFIG_BLUETOOTH_BLE_SCAN), y)
CSRCS += service/stacks/zephyr/sal_le_scan_interface.c
endif #CONFIG_BLUETOOTH_BLE_SCAN
ifeq ($(CONFIG_BLUETOOTH_GATT_CLIENT), y)
CSRCS += service/stacks/zephyr/sal_gatt_client_interface.c
endif #CONFIG_BLUETOOTH_GATT_CLIENT
ifeq ($(CONFIG_BLUETOOTH_GATT_SERVER), y)
CSRCS += service/stacks/zephyr/sal_gatt_server_interface.c
endif #CONFIG_BLUETOOTH_GATT_SERVER
endif #CONFIG_BLUETOOTH_STACK_LE_ZBLUE
endif
ifeq ($(CONFIG_BLUETOOTH_BLE_AUDIO),)
CSRCS := $(filter-out $(wildcard service/stacks/bluelet/sal_lea_*),$(wildcard $(CSRCS)))
endif #CONFIG_BLUETOOTH_BLE_AUDIO
CSRCS += service/profiles/*.c
CSRCS += service/profiles/system/*.c
ifeq ($(CONFIG_BLUETOOTH_A2DP),)
CSRCS := $(filter-out $(wildcard service/profiles/system/bt_player.c),$(wildcard $(CSRCS)))
endif #CONFIG_BLUETOOTH_A2DP
ifeq ($(findstring y, $(CONFIG_BLUETOOTH_A2DP)_$(CONFIG_BLUETOOTH_HFP_AG)_$(CONFIG_BLUETOOTH_HFP_HF)_$(CONFIG_BLUETOOTH_BLE_AUDIO)), )
CSRCS := $(filter-out $(wildcard service/profiles/system/media_system.c),$(wildcard $(CSRCS)))
else
CSRCS += service/profiles/audio_interface/*.c
endif #CONFIG_BLUETOOTH_A2DP/CONFIG_BLUETOOTH_HFP_AG/CONFIG_BLUETOOTH_HFP_HF
ifeq ($(CONFIG_MICO_MEDIA_MAIN_PLAYER),y)
CFLAGS += ${INCDIR_PREFIX}${TOPDIR}/../vendor/xiaomi/miai/mediaplayer/include
endif #CONFIG_MICO_MEDIA_MAIN_PLAYER
ifeq ($(CONFIG_BLUETOOTH_GATT_CLIENT), y)
CSRCS += service/profiles/gatt/gattc_event.c
CSRCS += service/profiles/gatt/gattc_service.c
endif #CONFIG_BLUETOOTH_GATT_CLIENT
ifeq ($(CONFIG_BLUETOOTH_GATT_SERVER), y)
CSRCS += service/profiles/gatt/gatts_event.c
CSRCS += service/profiles/gatt/gatts_service.c
endif #CONFIG_BLUETOOTH_GATT_SERVER
ifeq ($(CONFIG_BLUETOOTH_A2DP), y)
CSRCS += service/profiles/a2dp/*.c
CSRCS += service/profiles/a2dp/codec/*.c
CSRCS += service/profiles/avrcp/*.c
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/profiles/a2dp
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/profiles/a2dp/codec
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/profiles/avrcp
endif #CONFIG_BLUETOOTH_A2DP
ifeq ($(CONFIG_BLUETOOTH_A2DP_SOURCE), y)
CSRCS += service/profiles/a2dp/source/*.c
endif #CONFIG_BLUETOOTH_A2DP_SOURCE
ifeq ($(CONFIG_BLUETOOTH_A2DP_SINK), y)
CSRCS += service/profiles/a2dp/sink/*.c
endif #CONFIG_BLUETOOTH_A2DP_SINK
ifeq ($(CONFIG_BLUETOOTH_AVRCP_TARGET), y)
CSRCS += service/profiles/avrcp/target/*.c
endif #CONFIG_BLUETOOTH_A2DP_SOURCE
ifeq ($(CONFIG_BLUETOOTH_AVRCP_CONTROL), y)
CSRCS += service/profiles/avrcp/control/*.c
endif #CONFIG_BLUETOOTH_A2DP_SINK
ifeq ($(CONFIG_BLUETOOTH_HFP_HF), y)
CSRCS += service/profiles/hfp_hf/*.c
endif #CONFIG_BLUETOOTH_HFP_HF
ifeq ($(CONFIG_BLUETOOTH_HFP_AG), y)
CSRCS += service/profiles/hfp_ag/*.c
endif #CONFIG_BLUETOOTH_HFP_AG
ifeq ($(CONFIG_BLUETOOTH_SPP), y)
CSRCS += service/profiles/spp/*.c
endif #CONFIG_BLUETOOTH_SPP
ifeq ($(CONFIG_BLUETOOTH_HID_DEVICE), y)
CSRCS += service/profiles/hid/*.c
endif #CONFIG_BLUETOOTH_HID_DEVICE
ifeq ($(CONFIG_BLUETOOTH_PAN), y)
CSRCS += service/profiles/pan/*.c
endif #CONFIG_BLUETOOTH_PAN
ifneq ($(findstring y, $(CONFIG_BLUETOOTH_LEAUDIO_CLIENT)_$(CONFIG_BLUETOOTH_LEAUDIO_SERVER)), )
CSRCS += service/profiles/leaudio/audio_ipc/*.c
CSRCS += service/profiles/leaudio/*.c
CSRCS += service/profiles/leaudio/codec/*.c
endif #CONFIG_BLUETOOTH_LEAUDIO_CLIENT/CONFIG_BLUETOOTH_LEAUDIO_SERVER
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_SERVER), y)
CSRCS += service/profiles/leaudio/server/*.c
endif #CONFIG_BLUETOOTH_LEAUDIO_SERVER
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_CCP), y)
CSRCS += service/profiles/leaudio/ccp/*.c
endif #CONFIG_BLUETOOTH_LEAUDIO_CCP
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_MCP), y)
CSRCS += service/profiles/leaudio/mcp/*.c
endif #CONFIG_BLUETOOTH_LEAUDIO_MCP
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_VMICS), y)
CSRCS += service/profiles/leaudio/vmics/*.c
endif #CONFIG_BLUETOOTH_LEAUDIO_VMICS
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_CLIENT), y)
CSRCS += service/profiles/leaudio/client/*.c
endif #CONFIG_BLUETOOTH_LEAUDIO_CLIENT
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_MCS), y)
CSRCS += service/profiles/leaudio/mcs/*.c
endif #CONFIG_BLUETOOTH_LEAUDIO_MCS
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_TBS), y)
CSRCS += service/profiles/leaudio/tbs/*.c
endif #CONFIG_BLUETOOTH_LEAUDIO_TBS
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_VMICP), y)
CSRCS += service/profiles/leaudio/vmicp/*.c
endif #CONFIG_BLUETOOTH_LEAUDIO_VMICP
ifeq ($(CONFIG_BLUETOOTH_LOG), y)
CSRCS += service/utils/log_server.c
CSRCS += service/utils/btsnoop_log.c
CSRCS += service/utils/btsnoop_writer.c
CSRCS += service/utils/btsnoop_filter.c
endif #CONFIG_BLUETOOTH_LOG
ifeq ($(CONFIG_BLUETOOTH_HCI_FILTER), y)
CSRCS += service/vhal/bt_hci_filter.c
endif
CSRCS += service/vhal/bt_vhal.c
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/vhal
endif #CONFIG_BLUETOOTH_SERVICE
ifeq ($(CONFIG_APP_BT_SAMPLE_CODE), y)
ifeq ($(CONFIG_APP_BT_SAMPLE_CODE_BASIC), y)
CSRCS += sample_code/basic/*.c
endif
ifeq ($(CONFIG_APP_BT_SAMPLE_CODE_ENABLE), y)
CSRCS += sample_code/enable/*.c
endif
ifeq ($(CONFIG_APP_BT_SAMPLE_CODE_DISCOVERY), y)
CSRCS += sample_code/discovery/*.c
endif
ifeq ($(CONFIG_APP_BT_SAMPLE_CODE_CREATEBOND), y)
CSRCS += sample_code/createbond/*.c
endif
ifeq ($(CONFIG_APP_BT_SAMPLE_CODE_ACCEPTBOND), y)
CSRCS += sample_code/acceptbond/*.c
endif
endif #CONFIG_APP_BT_SAMPLE_CODE
ifeq ($(CONFIG_BLUETOOTH_TOOLS), y)
CSRCS += tools/utils.c
CSRCS += tools/uv_thread_loop.c
ifeq ($(CONFIG_BLUETOOTH_FRAMEWORK_ASYNC), y)
CSRCS += tools/async/gap.c
CSRCS += tools/async/log.c
ifeq ($(CONFIG_BLUETOOTH_BLE_ADV), y)
CSRCS += tools/async/adv.c
endif #CONFIG_BLUETOOTH_BLE_ADV
ifeq ($(CONFIG_BLUETOOTH_BLE_SCAN), y)
CSRCS += tools/async/scan.c
endif
ifeq ($(CONFIG_BLUETOOTH_GATT), y)
CSRCS += tools/async/gatt_client.c
endif #CONFIG_BLUETOOTH_GATT
endif
ifeq ($(CONFIG_BLUETOOTH_BLE_ADV), y)
CSRCS += tools/adv.c
endif
ifeq ($(CONFIG_BLUETOOTH_BLE_SCAN), y)
CSRCS += tools/scan.c
endif
ifeq ($(CONFIG_BLUETOOTH_L2CAP), y)
CSRCS += tools/l2cap.c
endif #CONFIG_BLUETOOTH_L2CAP
ifeq ($(CONFIG_BLUETOOTH_A2DP_SINK), y)
CSRCS += tools/a2dp_sink.c
endif #CONFIG_BLUETOOTH_A2DP_SINK
ifeq ($(CONFIG_BLUETOOTH_A2DP_SOURCE), y)
CSRCS += tools/a2dp_source.c
endif #CONFIG_BLUETOOTH_A2DP_SOURCE
ifeq ($(CONFIG_BLUETOOTH_AVRCP_CONTROL), y)
CSRCS += tools/avrcp_control.c
endif #CONFIG_BLUETOOTH_AVRCP_CONTROL
ifeq ($(CONFIG_BLUETOOTH_GATT_CLIENT), y)
CSRCS += tools/gatt_client.c
endif #CONFIG_BLUETOOTH_GATT_CLIENT
ifeq ($(CONFIG_BLUETOOTH_GATT_SERVER), y)
CSRCS += tools/gatt_server.c
endif #CONFIG_BLUETOOTH_GATT_SERVER
ifeq ($(CONFIG_BLUETOOTH_HFP_HF), y)
CSRCS += tools/hfp_hf.c
endif #CONFIG_BLUETOOTH_HFP_HF
ifeq ($(CONFIG_BLUETOOTH_HFP_AG), y)
CSRCS += tools/hfp_ag.c
endif #CONFIG_BLUETOOTH_HFP_AG
ifeq ($(CONFIG_BLUETOOTH_LOG), y)
CSRCS += tools/log.c
endif #CONFIG_BLUETOOTH_LOG
ifeq ($(CONFIG_BLUETOOTH_SPP), y)
CSRCS += tools/spp.c
endif
ifeq ($(CONFIG_BLUETOOTH_HID_DEVICE), y)
CSRCS += tools/hid_device.c
endif
ifeq ($(CONFIG_BLUETOOTH_PAN), y)
CSRCS += tools/panu.c
endif
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_SERVER), y)
CSRCS += tools/lea_server.c
endif
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_MCP), y)
CSRCS += tools/lea_mcp.c
endif
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_CCP), y)
CSRCS += tools/lea_ccp.c
endif
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_VMICS), y)
CSRCS += tools/lea_vmics.c
endif
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_CLIENT), y)
CSRCS += tools/lea_client.c
endif
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_VMICP), y)
CSRCS += tools/lea_vmicp.c
endif
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_MCS), y)
CSRCS += tools/lea_mcs.c
endif
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_TBS), y)
CSRCS += tools/lea_tbs.c
endif
ifeq ($(CONFIG_BLUETOOTH_STORAGE_UPDATE), y)
CSRCS += tools/storage_update/storage_tool.c
endif #CONFIG_BLUETOOTH_STORAGE_UPDATE
endif
# framework/service/stack/tools dependence
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/framework/include
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/framework/common
ifneq ($(CONFIG_LIB_DBUS_RPMSG_SERVER_CPUNAME)$(CONFIG_OFONO),)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/dbus/dbus
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/glib/glib/glib
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/glib/glib
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/glib
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/system/utils/gdbus
endif
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/src
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/common
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/profiles
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/profiles/include
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/profiles/system
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/stacks
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/stacks/include
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/vendor
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/dfx
ifeq ($(CONFIG_BLUETOOTH_SERVICE), y)
ifneq ($(CONFIG_BLUETOOTH_STACK_BREDR_BLUELET)$(CONFIG_BLUETOOTH_STACK_LE_BLUELET),)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/stacks/bluelet/include
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/bluelet/bluelet/src/samples/stack_adapter/inc
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/vendor/xiaomi/vela/bluelet/inc
endif
ifneq ($(CONFIG_BLUETOOTH_STACK_BREDR_ZBLUE)$(CONFIG_BLUETOOTH_STACK_LE_ZBLUE),)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/stacks/zephyr/include
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/zblue/zblue/port/include/
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/zblue/zblue/subsys/bluetooth/host
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/zblue/zblue/subsys/settings/include/settings
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/zblue/zblue/port/include/kernel/include
endif
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/ipc
endif
ifeq ($(CONFIG_APP_BT_SAMPLE_CODE), y)
ifeq ($(CONFIG_APP_BT_SAMPLE_CODE_BASIC), y)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/sample_code/basic
endif
ifeq ($(CONFIG_APP_BT_SAMPLE_CODE_ENABLE), y)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/sample_code/enable
endif
ifeq ($(CONFIG_APP_BT_SAMPLE_CODE_DISCOVERY), y)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/sample_code/discovery
endif
ifeq ($(CONFIG_APP_BT_SAMPLE_CODE_CREATEBOND), y)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/sample_code/createbond
endif
ifeq ($(CONFIG_APP_BT_SAMPLE_CODE_ACCEPTBOND), y)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/sample_code/acceptbond
endif
endif #CONFIG_APP_BT_SAMPLE_CODE
ifeq ($(CONFIG_BLUETOOTH_TOOLS), y)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/tools
endif
ifeq ($(CONFIG_BLUETOOTH_STORAGE_UPDATE), y)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/tools/storage_update
endif #CONFIG_BLUETOOTH_STORAGE_UPDATE
ifeq ($(CONFIG_ARCH_SIM),y)
CFLAGS += -O0
endif
CFLAGS += -Wno-strict-prototypes #-fno-short-enums -Wl,-no-enum-size-warning #-Werror
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = $(CONFIG_BLUETOOTH_TASK_STACK_SIZE)
MODULE = $(CONFIG_BLUETOOTH)
# if enabled bluetoothd
ifeq ($(CONFIG_BLUETOOTH_SERVER), y)
PROGNAME += $(CONFIG_BLUETOOTH_SERVER_NAME)
MAINSRC += service/src/main.c
endif
ifeq ($(CONFIG_APP_BT_SAMPLE_CODE), y)
ifeq ($(CONFIG_APP_BT_SAMPLE_CODE_BASIC), y)
PROGNAME += bt_basic
MAINSRC += sample_code/basic/basic.c
endif
ifeq ($(CONFIG_APP_BT_SAMPLE_CODE_ENABLE), y)
PROGNAME += bt_enable
MAINSRC += sample_code/enable/enable.c
endif
ifeq ($(CONFIG_APP_BT_SAMPLE_CODE_DISCOVERY), y)
PROGNAME += bt_discovery
MAINSRC += sample_code/discovery/discovery.c
endif
ifeq ($(CONFIG_APP_BT_SAMPLE_CODE_CREATEBOND), y)
PROGNAME += bt_createbond
MAINSRC += sample_code/createbond/createbond.c
endif
ifeq ($(CONFIG_APP_BT_SAMPLE_CODE_ACCEPTBOND), y)
PROGNAME += bt_acceptbond
MAINSRC += sample_code/acceptbond/acceptbond.c
endif
endif #CONFIG_APP_BT_SAMPLE_CODE
# if enabled bttool
ifeq ($(CONFIG_BLUETOOTH_TOOLS), y)
PROGNAME += bttool
MAINSRC += tools/bt_tools.c
PROGNAME += adapter_test
MAINSRC += tests/adapter_test.c
endif
ifeq ($(CONFIG_BLUETOOTH_UPGRADE), y)
PROGNAME += bt_upgrade
MAINSRC += tools/storage_transform.c
endif
ifeq ($(CONFIG_BLUETOOTH_STORAGE_UPDATE), y)
PROGNAME += bt_storage_update
MAINSRC += tools/storage_update/storage_update.c
endif #CONFIG_BLUETOOTH_STORAGE_UPDATE
endif
ASRCS := $(wildcard $(ASRCS))
CSRCS := $(wildcard $(CSRCS))
CXXSRCS := $(wildcard $(CXXSRCS))
MAINSRC := $(wildcard $(MAINSRC))
NOEXPORTSRCS = $(ASRCS)$(CSRCS)$(CXXSRCS)$(MAINSRC)
ifeq ($(CONFIG_BLUETOOTH_FEATURE),y)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/feature/include
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/runtimes/feature/include
CSRCS += feature/src/system_bluetooth.c
CSRCS += feature/src/system_bluetooth_impl.c
CSRCS += feature/src/feature_bluetooth_util.c
CSRCS += feature/src/system_bluetooth_bt.c
CSRCS += feature/src/system_bluetooth_bt_impl.c
CSRCS += feature/src/feature_bluetooth_callback.c
ifeq ($(CONFIG_BLUETOOTH_A2DP_SINK), y)
CSRCS += feature/src/system_bluetooth_bt_a2dpsink.c
CSRCS += feature/src/system_bluetooth_bt_a2dpsink_impl.c
endif
ifeq ($(CONFIG_BLUETOOTH_AVRCP_CONTROL), y)
CSRCS += feature/src/system_bluetooth_bt_avrcpcontrol.c
CSRCS += feature/src/system_bluetooth_bt_avrcpcontrol_impl.c
endif
depend::
$(APPDIR)/../prebuilts/tools/rust/bin/jidl/jidl_gen_cpp \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/jidl/bluetooth.jidl --out-dir \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/src --header system_bluetooth.h --source system_bluetooth.c
$(APPDIR)/../prebuilts/tools/rust/bin/jidl/jidl_gen_cpp \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/jidl/bluetooth_bt.jidl --out-dir \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/src --header system_bluetooth_bt.h --source system_bluetooth_bt.c
ifeq ($(CONFIG_BLUETOOTH_A2DP_SINK), y)
$(APPDIR)/../prebuilts/tools/rust/bin/jidl/jidl_gen_cpp \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/jidl/bluetooth_bt_a2dpsink.jidl --out-dir \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/src --header system_bluetooth_bt_a2dpsink.h --source system_bluetooth_bt_a2dpsink.c
endif
ifeq ($(CONFIG_BLUETOOTH_AVRCP_CONTROL), y)
@python3 $(APPDIR)/frameworks/runtimes/feature/tools/jidl/jsongensource.py \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/jidl/bluetooth_bt_avrcpcontrol.jidl -out-dir \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/src -header system_bluetooth_bt_avrcpcontrol.h -source system_bluetooth_bt_avrcpcontrol.c
endif
else ifeq ($(CONFIG_BLUETOOTH_FEATURE_ASYNC), y)
include $(APPDIR)/frameworks/runtimes/feature/Make.defs
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/feature/feature_async/include
CSRCS += feature/feature_async/src/bluetooth.c
CSRCS += feature/feature_async/src/bluetooth_impl.c
CSRCS += feature/feature_async/src/feature_bluetooth_util.c
CSRCS += feature/feature_async/src/bluetooth_ble.c
CSRCS += feature/feature_async/src/bluetooth_ble_impl.c
depend::
@python3 $(APPDIR)/frameworks/runtimes/feature/tools/jidl/jsongensource.py \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/feature_async/jidl/bluetooth.jidl -out-dir \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/feature_async/src -header bluetooth.h -source bluetooth.c
@python3 $(APPDIR)/frameworks/runtimes/feature/tools/jidl/jsongensource.py \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/feature_async/jidl/bluetooth_ble.jidl -out-dir \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/feature_async/src -header bluetooth_ble.h -source bluetooth_ble.c
else
endif
ifneq ($(NOEXPORTSRCS),)
BIN := $(APPDIR)/staging/libbluetooth.a
endif
include $(APPDIR)/Application.mk

92
Makefile.host Normal file
View File

@ -0,0 +1,92 @@
############################################################################
# apps/system/lzf/Makefile.host
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
############################################################################
# USAGE:
#
# 1. TOPDIR and APPDIR must be defined on the make command line: TOPDIR
# is the full path to the nuttx/ directory; APPDIR is the full path to
# the apps/ directory. For example:
#
# make -f Makefile.host TOPDIR=/home/me/projects/nuttx
# APPDIR=/home/me/projects/apps
#
# 2. Add CONFIG_DEBUG_FEATURES=y to the make command line to enable debug output
# 3. Make sure to clean old target .o files before making new host .o
# files.
#
############################################################################
include $(APPDIR)/Make.defs
BIN = bttool$(HOSTEXEEXT)
CFLAGS := -I.
CFLAGS += -I service/src
CFLAGS += -I framework/include
CFLAGS += -I tools
CFLAGS += -I service
CFLAGS += -I service/common
CFLAGS += -I service/ipc/socket/include
CFLAGS += -I service/stacks
CFLAGS += -I service/stacks/include
CFLAGS += -I service/profiles
CFLAGS += -I service/profiles/include
CFLAGS += -DFAR= -DOK=0 -m32
LDLIBS += -lpthread -lreadline -luv
BTDIR = $(APPDIR)/frameworks/bluetooth
CSRCS := $(wildcard framework/common/*.c)
CSRCS += $(wildcard framework/socket/*.c)
CSRCS += $(wildcard tools/*.c)
CSRCS := $(filter-out $(wildcard tools/lea*) tools/log.c,$(wildcard $(CSRCS)))
CSRCS += service/ipc/socket/src/bt_socket_client.c
CSRCS += service/ipc/socket/src/bt_socket_adapter.c
CSRCS += service/common/service_loop.c
CSRCS += service/src/manager_service.c
CSRCS += service/common/callbacks_list.c
CSRCS += service/common/index_allocator.c
CSRCS += service/utils/log.c
CINC := nuttx/config.h
CINC += nuttx/list.h
CINC += nuttx/nuttx.h
all: $(BIN)
.PHONY: clean
nuttx/config.h:
$(Q) mkdir -p nuttx
$(Q) ln -sf $(TOPDIR)/include/nuttx/config.h nuttx/
nuttx/list.h:
$(Q) mkdir -p nuttx
$(Q) ln -sf $(TOPDIR)/include/nuttx/list.h nuttx/
nuttx/nuttx.h:
$(Q) mkdir -p nuttx
$(Q) ln -sf $(TOPDIR)/include/nuttx/nuttx.h nuttx/
$(BIN): $(CINC) $(CSRCS)
$(Q) $(HOSTCC) $(CFLAGS) -o $@ $(filter-out $(CINC), $^) $(LDLIBS)
clean:
rm -rf $(BIN) nuttx

65
README.md Normal file
View File

@ -0,0 +1,65 @@
# Overview of openvela Bluetooth
\[ English | [简体中文](README_zh-cn.md) \]
## 1. Introduction to openvela Bluetooth
openvela Bluetooth has been certified for Bluetooth 5.4. It currently supports Bluetooth profiles listed as below:
- Core
- BR/EDR/BLE
- GAP
- L2CAP
- GATT Client/Server
- A2DP SRC/SNK
- AVRCP CT/TG
- HFP AG/HF
- PAN
- SPP
- HID
- HOGP
- LEA
- TMAP
- CAP
- BAP/ASCS/PACS/BASS
- CSIP/CSIS
- MCP/MCS
- CCP/TBS
- VCP/VCS
- Mesh
openvela Bluetooth currently also supports a variety of open source and proprietary stacks such as Zephyr, Bluez, Bluedroid, Barrot, etc.
## 2. openvela Bluetooth Application Development
Third-party application developers may utilize the openvela QuickApp Feature to acquire system access capabilities.
Additionally, NDK interfaces are also provided to utilize all Bluetooth system-level capabilities. Please refer to header files in folder framework/include for more details.
## 3. openvela Bluetooth Driver Development
openvela Bluetooth supports multiple driver architectures. Taking the widely used BTH4 driver architecture as an example, chip manufacturers can implement a variable of the **struct bt_driver_s** structure type, and initialize the following member functions for it.
- CODE int (*open)(FAR struct bt_driver_s *btdev);
- CODE int (*send)(FAR struct bt_driver_s *btdev, enum bt_buf_type_e type, FAR void *data, size_t len);
- CODE int (*ioctl)(FAR struct bt_driver_s *btdev, int cmd, unsigned long arg);
- CODE void (*close)(FAR struct bt_driver_s *btdev);
The implementation of the above member functions depends on the specific type of HCI utilized, which refers to the physical bus linking the Host and the Controller.
Then, register the driver instance by passing the variable of the above structure type via the API bt_driver_register().
- int **bt_driver_register**(FAR struct bt_driver_s *drv);
Please refer to the type definition in header file nuttx/include/nuttx/wireless/bluetooth/bt_driver.h. The figure below helps to provide a comprehensive understanding of its functioning within the openvela OS.
![](img/bt_driver.png)
Note: chip manufacturers are not required to implement the receive() member function, for it will be initialized by the BTH4 driver.
- CODE int (*receive)(FAR struct bt_driver_s *btdev, enum bt_buf_type_e type, FAR void *data, size_t len);
Upon receipt of HCI data from the chip, the vendor drivers should invoke the **bt_netdev_receive**() function, which in turn will trigger the receive() function to store the received HCI data.

65
README_zh-cn.md Normal file
View File

@ -0,0 +1,65 @@
# 蓝牙概述
\[ [English](README.md) | 简体中文 \]
## 一、 openvela 蓝牙能力介绍
openvela 蓝牙已经通过 Bluetooth 5.4 认证。目前支持的蓝牙能力包括:
- Core
- BR/EDR/BLE
- GAP
- L2CAP
- GATT Client/Server
- A2DP SRC/SNK
- AVRCP CT/TG
- HFP AG/HF
- PAN
- SPP
- HID
- HOGP
- LEA
- TMAP
- CAP
- BAP/ASCS/PACS/BASS
- CSIP/CSIS
- MCP/MCS
- CCP/TBS
- VCP/VCS
- Mesh
openvela 蓝牙目前还能够支持多种开源、闭源协议栈如Zephyr、Bluez、Bluedroid、Barrot等。
## 二、 openvela 蓝牙应用开发
对于第三方应用开发者,可以使用 openvela 快应用 QuickApp Feature ,它是基于 QuickJS 引擎使用 C++ 实现的一系列 API 接口,为三方应用提供系统访问能力。
另外,还提供了 NDK 接口来使用蓝牙系统的所有能力。可以参阅目录 framework/include 中的头文件获取更多信息。
## 三、 openvela 蓝牙驱动开发
openvela 蓝牙支持多种驱动架构。以目前常用的 BTH4 驱动架构为例,芯片厂商可以实现一个 **struct bt_driver_s** 结构体类型的变量,并为其初始化以下成员函数:
- CODE int (*open)(FAR struct bt_driver_s *btdev);
- CODE int (*send)(FAR struct bt_driver_s *btdev, enum bt_buf_type_e type, FAR void *data, size_t len);
- CODE int (*ioctl)(FAR struct bt_driver_s *btdev, int cmd, unsigned long arg);
- CODE void (*close)(FAR struct bt_driver_s *btdev);
上面成员函数的实现依赖于 HCI 的实际工作方式,也就是 Host 和 Controller 之间的物理总线。
然后,将上述结构体类型的变量通过 API **bt_driver_register**()注册该驱动实例。
- int **bt_driver_register**(FAR struct bt_driver_s *drv);
类型定义可参考头文件 nuttx/include/nuttx/wireless/bluetooth/bt_driver.h。调用关系如下图所示
![](img/bt_driver.png)
备注:对于 receive() 成员函数芯片厂商无需定义BTH4 驱动会为其初始化。
- CODE int (*receive)(FAR struct bt_driver_s *btdev, enum bt_buf_type_e type, FAR void *data, size_t len);
当收到来自芯片的 HCI 数据时,只要调用 **bt_netdev_receive**()即可,它会调用这个 receive()函数来保存收到 HCI 数据。

166
debug/bt_memory.c Normal file
View File

@ -0,0 +1,166 @@
/****************************************************************************
* Copyright (C) 2025 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include "bt_memory.h"
#include <assert.h>
#include <pthread.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#define GUARD_SIZE 16
#define GUARD_HEAD 0xAA
#define GUARD_TAIL 0xBB
typedef struct bt_mem_node {
void* addr;
size_t size;
const char* file;
int line;
unsigned char guard[GUARD_SIZE];
struct bt_mem_node* next;
} bt_mem_node_t;
typedef struct bt_mem_manager {
bt_mem_node_t* mem_list;
pthread_mutex_t list_lock;
size_t current_mem;
size_t peak_mem;
} bt_mem_manager_t;
static bt_mem_manager_t g_mem_manager = {
.mem_list = NULL,
.list_lock = PTHREAD_MUTEX_INITIALIZER,
.current_mem = 0,
.peak_mem = 0,
};
void* bt_malloc_hook(size_t size, const char* file, int line)
{
bt_mem_manager_t* mem_manager = &g_mem_manager;
void* raw;
bt_mem_node_t* head;
raw = malloc(size + sizeof(bt_mem_node_t) + GUARD_SIZE);
if (!raw) {
syslog(LOG_ALERT, "[bt_memory] malloc failed, size: %zu, file: %s, line: %d", size, file, line);
return NULL;
}
head = (bt_mem_node_t*)raw;
*head = (bt_mem_node_t) {
.addr = (char*)raw + sizeof(bt_mem_node_t),
.size = size,
.file = file,
.line = line,
.next = NULL
};
memset(head->guard, GUARD_HEAD, sizeof(head->guard));
memset((char*)head->addr + size, GUARD_TAIL, GUARD_SIZE);
pthread_mutex_lock(&mem_manager->list_lock);
mem_manager->current_mem += size;
if (mem_manager->current_mem > mem_manager->peak_mem) {
mem_manager->peak_mem = mem_manager->current_mem;
}
head->next = mem_manager->mem_list;
mem_manager->mem_list = head;
pthread_mutex_unlock(&mem_manager->list_lock);
return head->addr;
}
void* bt_calloc_hook(size_t num, size_t size, const char* file, int line)
{
size_t total;
void* ptr;
total = num * size;
ptr = bt_malloc_hook(total, file, line);
if (!ptr) {
syslog(LOG_ALERT, "[bt_memory] calloc failed, num: %zu, size: %zu, file: %s, line: %d", num, size, file, line);
return NULL;
}
memset(ptr, 0, total);
return ptr;
}
void bt_free_hook(void* ptr)
{
bt_mem_manager_t* mem_manager = &g_mem_manager;
bt_mem_node_t** pp;
bool found = false;
if (!ptr) {
return;
}
pthread_mutex_lock(&mem_manager->list_lock);
pp = &mem_manager->mem_list;
while (*pp) {
if ((*pp)->addr == ptr) {
bt_mem_node_t* node = *pp;
for (int i = 0; i < GUARD_SIZE; i++) {
if (((uint8_t)node->guard[i] != GUARD_HEAD) || ((uint8_t)((char*)ptr + node->size)[i] != GUARD_TAIL)) {
syslog(LOG_ALERT, "[bt_memory] Buffer overflow at %s:%d", node->file, node->line);
assert(0);
}
}
mem_manager->current_mem -= node->size;
*pp = node->next;
found = true;
free(node);
break;
}
pp = &(*pp)->next;
}
pthread_mutex_unlock(&mem_manager->list_lock);
if (!found) {
syslog(LOG_ALERT, "[bt_memory] Freeing unallocated memory %p", ptr);
assert(0);
}
}
void bt_report_leak(void)
{
bt_mem_manager_t* mem_manager = &g_mem_manager;
bt_mem_node_t* node;
pthread_mutex_lock(&mem_manager->list_lock);
syslog(LOG_ALERT, "[bt_memory] ===== Memory Leak Report =====");
syslog(LOG_ALERT, "[bt_memory] Peak memory: %zu bytes", mem_manager->peak_mem);
node = mem_manager->mem_list;
while (node) {
syslog(LOG_ALERT, "[bt_memory] Leak %p (%zu bytes) at %s:%d",
node->addr, node->size, node->file, node->line);
node = node->next;
}
syslog(LOG_ALERT, "[bt_memory] ===== End of Report =====");
pthread_mutex_unlock(&mem_manager->list_lock);
}

53
debug/bt_memory_sample.c Normal file
View File

@ -0,0 +1,53 @@
/****************************************************************************
* Copyright (C) 2025 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdio.h>
#include <string.h>
#include "bt_memory.h"
void test_leak()
{
void* p1 = bt_malloc(128);
void* p2 = bt_malloc(256);
}
void test_overflow()
{
char* buf = (char*)bt_malloc(16);
memset(buf, 0, 20);
bt_free(buf);
}
void test_double_free()
{
void* p = bt_malloc(64);
bt_free(p);
bt_free(p);
}
int main()
{
test_leak();
test_overflow();
test_double_free();
void* p2 = bt_malloc(500);
bt_report_leak();
return 0;
}

111
debug/bt_trace.c Normal file
View File

@ -0,0 +1,111 @@
/****************************************************************************
* Copyright (C) 2025 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include "bt_sched_trace.h"
#include <stdatomic.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "utils/log.h"
#define DUMP_THRESHOLD 256
typedef struct {
char tag[MAX_TAG_LEN];
uint64_t timestamp;
uint32_t latency_us;
} bt_latency_record_t;
typedef struct {
bt_latency_record_t buffer[CONFIG_BLUETOOTH_TRACE_BUFFER_SIZE];
atomic_uint head;
atomic_uint tail;
} bt_trace_manager_t;
static bt_trace_manager_t g_trace_manager = { 0 };
static inline uint64_t get_monotonic_ns()
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return (uint64_t)ts.tv_sec * 1000000000UL + ts.tv_nsec;
}
void bt_note_start(void)
{
bt_trace_manager_t* trace_manager = &g_trace_manager;
atomic_store(&trace_manager->head, 0);
atomic_store(&trace_manager->tail, 0);
}
void bt_note_stop(void)
{
bt_trace_manager_t* trace_manager = &g_trace_manager;
char log_buf[DUMP_THRESHOLD];
int written = 0;
while (trace_manager->tail != trace_manager->head) {
bt_latency_record_t* p = &trace_manager->buffer[trace_manager->tail % CONFIG_BLUETOOTH_TRACE_BUFFER_SIZE];
written += snprintf(log_buf + written, sizeof(log_buf) - written,
"[TAG=%s][TS=%lu][LAT=%uus]\n",
p->tag, p->timestamp, p->latency_us);
trace_manager->tail = (trace_manager->tail + 1) % CONFIG_BLUETOOTH_TRACE_BUFFER_SIZE;
written = written % DUMP_THRESHOLD;
if (written > DUMP_THRESHOLD) {
BT_LOGD("%s", log_buf);
written = 0;
}
}
if (written > 0) {
BT_LOGD("%s", log_buf);
}
}
void bt_note_begin(const char* tag, bt_timepoint_t* point)
{
if (strlen(tag) > MAX_TAG_LEN) {
BT_LOGD("tag is too long, max length is %d\n", MAX_TAG_LEN);
return;
}
strlcpy(point->tag, tag, MAX_TAG_LEN);
point->start_ns = get_monotonic_ns();
}
void bt_note_end(const char* tag, bt_timepoint_t* point)
{
bt_trace_manager_t* trace_manager = &g_trace_manager;
uint64_t end;
uint32_t idx;
if (strlen(tag) > MAX_TAG_LEN) {
BT_LOGD("tag is too long, max length is %d\n", MAX_TAG_LEN);
return;
}
end = get_monotonic_ns();
idx = atomic_fetch_add(&trace_manager->head, 1) % CONFIG_BLUETOOTH_TRACE_BUFFER_SIZE;
strlcpy(trace_manager->buffer[idx].tag, point->tag, MAX_TAG_LEN);
trace_manager->buffer[idx].timestamp = end;
trace_manager->buffer[idx].latency_us = (end - point->start_ns) / 1000;
}

124
debug/bt_trace_analyzer.py Normal file
View File

@ -0,0 +1,124 @@
############################################################################
# Copyright (C) 2025 Xiaomi Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
############################################################################
import re
import argparse
import pandas as pd
import matplotlib.pyplot as plt
from datetime import datetime
from pathlib import Path
def parse_args():
parser = argparse.ArgumentParser(description='Latency log analyzer with tag support')
parser.add_argument('--log', required=True,
help='Input log file path')
parser.add_argument('--output-img', default='latency_by_tag.png',
help='Output image path (default: latency_by_tag.png)')
parser.add_argument('--output-report',
help='Output report file path (optional)')
return parser.parse_args()
def parse_log_line(line):
pattern = r"\[TAG=([^$$]+)\]\[TS=(\d+)\]\[LAT=(\d+)us\]"
if match := re.search(pattern, line):
return {
"tag": match.group(1),
"timestamp": datetime.fromtimestamp(int(match.group(2))/1e9),
"latency": int(match.group(3))
}
return None
def load_log_data(log_path):
try:
with open(log_path, 'r') as f:
records = []
for line in f:
if record := parse_log_line(line.strip()):
records.append(record)
return pd.DataFrame(records)
except FileNotFoundError:
raise SystemExit(f"Error: Log file {log_path} not found")
def generate_latency_plot(df, output_path):
plt.figure(figsize=(15, 8))
colors = plt.cm.tab10.colors
for idx, (tag, group) in enumerate(df.groupby('tag')):
group = group.sort_values('timestamp')
plt.plot(group['timestamp'], group['latency'],
color=colors[idx % 10],
marker='o', markersize=3,
linestyle='-', linewidth=1,
label=tag)
plt.title('Latency Timeline by Tag')
plt.xlabel('Timestamp')
plt.ylabel('Latency (μs)')
plt.legend(loc='upper left', bbox_to_anchor=(1, 1))
plt.grid(True, alpha=0.3)
plt.xticks(rotation=45)
plt.tight_layout()
Path(output_path).parent.mkdir(parents=True, exist_ok=True)
plt.savefig(output_path, dpi=300, bbox_inches='tight')
plt.close()
def generate_stat_report(df, output_path=None):
stats = []
for tag, group in df.groupby('tag'):
desc = group['latency'].describe(percentiles=[.5, .95, .99])
stats.append({
'Tag': tag,
'Count': desc['count'],
'Mean': desc['mean'],
'Min': desc['min'],
'50%': desc['50%'],
'95%': desc['95%'],
'99%': desc['max'],
'Max': desc['max']
})
report_df = pd.DataFrame(stats)
report_str = report_df.to_string(index=False, float_format='%.2f')
if output_path:
Path(output_path).parent.mkdir(parents=True, exist_ok=True)
with open(output_path, 'w') as f:
f.write("=== Latency Statistics Report ===\n")
f.write(report_str)
print(f"Report saved to {output_path}")
else:
print("\n" + report_str)
def main():
args = parse_args()
df = load_log_data(args.log)
if df.empty:
raise SystemExit("Error: No valid records found in log file")
generate_latency_plot(df, args.output_img)
print(f"Visualization saved to {args.output_img}")
if args.output_report:
generate_stat_report(df, args.output_report)
else:
generate_stat_report(df)
if __name__ == "__main__":
main()

54
debug/bt_trace_sample.c Normal file
View File

@ -0,0 +1,54 @@
/****************************************************************************
* Copyright (C) 2025 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include "bt_sched_trace.h"
#include <stdlib.h>
void test_func1()
{
bt_timepoint_t tp1;
bt_trace_begin("test_func1", &tp1);
usleep(rand() % 1000);
bt_trace_end("test_func1", &tp1);
}
void test_func2()
{
bt_timepoint_t tp1;
bt_trace_begin("test_func2", &tp1);
usleep(rand() % 1000);
bt_trace_end("test_func2", &tp1);
}
int main(int argc, char* argv[])
{
bt_trace_start();
test_func1();
test_func2();
test_func1();
test_func2();
test_func1();
test_func2();
bt_trace_stop();
return 0;
}

BIN
debug/latency_by_tag.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 KiB

276
dfx/bt_dfx.h Normal file
View File

@ -0,0 +1,276 @@
/****************************************************************************
* Copyright (C) 2025 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#ifndef _BT_DFX_H_
#define _BT_DFX_H_
#ifdef CONFIG_DFX
#include <dfx.h>
#endif
#include "bt_dfx_event.h"
#include "bt_dfx_reason.h"
// br
#if defined(CONFIG_BLUETOOTH_DFX) && defined(CONFIG_BLUETOOTH_BREDR_SUPPORT)
#define BT_DFX_SEND_BR_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_BR_EVENT(...)
#endif
#define BT_DFX_BR_GAP_INQUIRY_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: brInquiryError: %s", reason); \
BT_DFX_SEND_BR_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_BR_GAP, BT_DFXC_BR_GAP_INQUIRY), \
"%s:%s", "brInquiryError", reason); \
} while (0)
#define BT_DFX_BR_GAP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: brConnectError: %s", reason); \
BT_DFX_SEND_BR_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_BR_GAP, BT_DFXC_BR_GAP_CONN), \
"%s:%s", "brConnectError", reason); \
} while (0)
#define BT_DFX_BR_GAP_DISCONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: brDisconnectError: %s", reason); \
BT_DFX_SEND_BR_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_BR_GAP, BT_DFXC_BR_GAP_DISCONN), \
"%s:%s", "brDisconnectError", reason); \
} while (0)
#define BT_DFX_BR_GAP_PAIR_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: brPairError: %s", reason); \
BT_DFX_SEND_BR_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_BR_GAP, BT_DFXC_BR_GAP_PAIR), \
"%s:%s", "brPairError", reason); \
} while (0)
// ble
#if defined(CONFIG_BLUETOOTH_DFX) && defined(CONFIG_BLUETOOTH_BLE_SUPPORT)
#define BT_DFX_SEND_LE_GAP_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_LE_GAP_EVENT(...)
#endif
#ifdef CONFIG_BLUETOOTH_BLE_SCAN
#define BT_DFX_LE_GAP_SCAN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: bleScanError: %s", reason); \
BT_DFX_SEND_LE_GAP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_LE_GAP, BT_DFXC_LE_GAP_SCAN), \
"%s:%s", "bleScanError", reason); \
} while (0)
#endif
#define BT_DFX_LE_GAP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: bleConnectError: %s", reason); \
BT_DFX_SEND_LE_GAP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_LE_GAP, BT_DFXC_LE_GAP_CONN), \
"%s:%s", "bleConnectError", reason); \
} while (0)
#define BT_DFX_LE_GAP_DISCONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: bleDisconnectError: %s", reason); \
BT_DFX_SEND_LE_GAP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_LE_GAP, BT_DFXC_LE_GAP_DISCONN), \
"%s:%s", "bleDisconnectError", reason); \
} while (0)
#define BT_DFX_LE_GAP_PAIR_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: blePairError: %s", reason); \
BT_DFX_SEND_LE_GAP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_LE_GAP, BT_DFXC_LE_GAP_PAIR), \
"%s:%s", "blePairError", reason); \
} while (0)
// spp
#if defined(CONFIG_BLUETOOTH_DFX) && defined(CONFIG_BLUETOOTH_SPP)
#define BT_DFX_SEND_SPP_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_SPP_EVENT(...)
#endif
#define BT_DFX_SPP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btSppConnectError: %s", reason); \
BT_DFX_SEND_SPP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_RFCOMM, BT_DFXC_SPP_CONN), \
"%s:%s", "btSppConnectError", reason); \
} while (0)
#define BT_DFX_SPP_DISCONN_ERROR(reason, scn, port, role) \
do { \
BT_LOGE("BT_DFX: btSppDisconnected: %s, scn: %d, port: %d, role: %d", \
reason, scn, port, role); \
BT_DFX_SEND_SPP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_RFCOMM, BT_DFXC_SPP_DISCONN), \
"%s:%s,%s:%d,%s:%d,%s:%s", "btSppDisconnected", reason, "scn", scn, \
"port", port, "role", role); \
} while (0)
// a2dp
#if defined(CONFIG_BLUETOOTH_DFX) && defined(CONFIG_BLUETOOTH_A2DP)
#define BT_DFX_SEND_A2DP_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_A2DP_EVENT(...)
#endif
#define BT_DFX_A2DP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btA2dpConnectError: %s", reason); \
BT_DFX_SEND_A2DP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_A2DP, BT_DFXC_A2DP_CONN), \
"%s:%s", "btA2dpConnectError", reason); \
} while (0)
#define BT_DFX_A2DP_MEDIA_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btA2dpMediaError: %s", reason); \
BT_DFX_SEND_A2DP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_A2DP, BT_DFXC_A2DP_MEDIA), \
"%s:%s", "btA2dpMediaError", reason); \
} while (0)
#define BT_DFX_A2DP_OFFLOAD_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btA2dpOffloadError: %s", reason); \
BT_DFX_SEND_A2DP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_A2DP, BT_DFXC_A2DP_OFFLOAD), \
"%s:%s", "btA2dpOffloadError", reason); \
} while (0)
// avrcp
#if defined(CONFIG_BLUETOOTH_DFX) && (defined(CONFIG_BLUETOOTH_AVRCP_CONTROL) || defined(CONFIG_BLUETOOTH_AVRCP_TARGET))
#define BT_DFX_SEND_AVRCP_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_AVRCP_EVENT(...)
#endif
#define BT_DFX_AVRCP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btAvrcpConnectError: %s", reason); \
BT_DFX_SEND_AVRCP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_AVRCP, BT_DFXC_AVRCP_CONN), \
"%s:%s", "btAvrcpConnectError", reason); \
} while (0)
#define BT_DFX_AVRCP_CTRL_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btAvrcpCtrlError: %s", reason); \
BT_DFX_SEND_AVRCP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_AVRCP, BT_DFXC_AVRCP_CTRL), \
"%s:%s", "btAvrcpCtrlError", reason); \
} while (0)
#define BT_DFX_AVRCP_VOL_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btAvrcpVolError: %s", reason); \
BT_DFX_SEND_AVRCP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_AVRCP, BT_DFXC_AVRCP_VOL), \
"%s:%s", "btAvrcpVolError", reason); \
} while (0)
// hfp
#if defined(CONFIG_BLUETOOTH_DFX) && (defined(CONFIG_BLUETOOTH_HFP_HF) || defined(CONFIG_BLUETOOTH_HFP_AG))
#define BT_DFX_SEND_HFP_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_HFP_EVENT(...)
#endif
#define BT_DFX_HFP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btHfpConnectError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_CONN), \
"%s:%s", "btHfpConnectError", reason); \
} while (0)
#define BT_DFX_HFP_SCO_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btHfpScoConnectError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_SCO_CONN), \
"%s:%s", "btHfpScoConnectError", reason); \
} while (0)
#define BT_DFX_HFP_VOL_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btHfpVolError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_VOL), \
"%s:%s", "btHfpVolError", reason); \
} while (0)
#define BT_DFX_HFP_MEDIA_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btHfpMediaError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_MEDIA), \
"%s:%s", "btHfpMediaError", reason); \
} while (0)
#define BT_DFX_HFP_OFFLOAD_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btHfpOffloadError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_OFFLOAD), \
"%s:%s", "btHfpOffloadError", reason); \
} while (0)
// hid
#if defined(CONFIG_BLUETOOTH_DFX) && defined(CONFIG_BLUETOOTH_HID_DEVICE)
#define BT_DFX_SEND_HID_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_HID_EVENT(...)
#endif
#define BT_DFX_HID_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btHidConnectError: %s", reason); \
BT_DFX_SEND_HID_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HID, BT_DFXC_HID_CONN), \
"%s:%s", "btHidConnectError", reason); \
} while (0)
// others
#if defined(CONFIG_BLUETOOTH_DFX)
#define BT_DFX_SEND_OTHERS_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_OTHERS_EVENT(...)
#endif
#define BT_DFX_SOCKET_ERROR(reason, port) \
do { \
BT_LOGE("BT_DFX: btSocketError: %s, port: %d", reason, port); \
BT_DFX_SEND_OTHERS_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_OTHERS, BT_DFXC_SOCKET), \
"%s:%s,%s:%d", "btSocketError", reason, "port", port); \
} while (0)
#define BT_DFX_IPC_CONN_ERROR(type, reason) \
do { \
BT_LOGE("BT_DFX: btIpcConnectError: %s, reason: %s", type, reason); \
BT_DFX_SEND_OTHERS_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_OTHERS, BT_DFXC_IPC_CONN), \
"%s:%s,%s:%s", "btIpcConnectError", type, "reason", reason); \
} while (0)
#define BT_DFX_IPC_ALLOC_ERROR(reason, packet_code) \
do { \
BT_LOGE("BT_DFX: btIpcAllocError: %s, packetCode: %" PRIu32, reason, packet_code); \
BT_DFX_SEND_OTHERS_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_OTHERS, BT_DFXC_IPC_ALLOC), \
"%s:%s,%s:%" PRIu32 "", "btIpcAllocError", reason, "packetCode", packet_code); \
} while (0)
#define BT_DFX_DRIVER_ERROR(type, name, reason) \
do { \
BT_LOGE("BT_DFX: btDriverError: %s, name: %s, reason: %s", type, name, reason); \
BT_DFX_SEND_OTHERS_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_OTHERS, BT_DFXC_DRIVER), \
"%s:%s,%s:%s,%s:%s", "btDriverError", type, "name", name, "reason", reason); \
} while (0)
#define BT_DFX_OPEN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btOpenError: %s", reason); \
BT_DFX_SEND_OTHERS_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_OTHERS, BT_DFXC_OPEN), \
"%s:%s", "btOpenError", reason); \
} while (0)
#endif /* _BT_DFX_H_ */

87
dfx/bt_dfx_event.h Normal file
View File

@ -0,0 +1,87 @@
/****************************************************************************
* Copyright (C) 2025 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#ifndef _BT_DFX_EVENT_H_
#define _BT_DFX_EVENT_H_
// vela bluetooth event id
#define BT_DFX_BASE_VELA_BLUETOOTH (923020000)
// event group
#define BT_DFXG_BR_GAP (0)
#define BT_DFXG_LE_GAP (500)
#define BT_DFXG_RFCOMM (1000)
#define BT_DFXG_L2CAP (1100)
#define BT_DFXG_GATT (1200)
#define BT_DFXG_A2DP (3000)
#define BT_DFXG_AVRCP (3200)
#define BT_DFXG_HFP (3400)
#define BT_DFXG_LE_AUDIO (4000)
#define BT_DFXG_HID (6000)
#define BT_DFXG_MESH (6100)
#define BT_DFXG_CHANNEL_SOUNDING (7000)
#define BT_DFXG_OTHERS (9000)
// event subcode
// group: BT_DFXG_BR_GAP
#define BT_DFXC_BR_GAP_INQUIRY (0)
#define BT_DFXC_BR_GAP_CONN (100)
#define BT_DFXC_BR_GAP_DISCONN (110)
#define BT_DFXC_BR_GAP_PAIR (200)
// group: BT_DFXG_LE_GAP
#define BT_DFXC_LE_GAP_SCAN (0)
#define BT_DFXC_LE_GAP_CONN (100)
#define BT_DFXC_LE_GAP_DISCONN (110)
#define BT_DFXC_LE_GAP_PAIR (200)
// group: BT_DFXG_RFCOMM
#define BT_DFXC_SPP_CONN (0)
#define BT_DFXC_SPP_DISCONN (10)
// group: BT_DFXG_A2DP
#define BT_DFXC_A2DP_CONN (0)
#define BT_DFXC_A2DP_MEDIA (10)
#define BT_DFXC_A2DP_OFFLOAD (20)
// group: BT_DFXG_AVRCP
#define BT_DFXC_AVRCP_CONN (0)
#define BT_DFXC_AVRCP_CTRL (10)
#define BT_DFXC_AVRCP_VOL (20)
// group: BT_DFXG_HFP
#define BT_DFXC_HFP_CONN (0)
#define BT_DFXC_HFP_SCO_CONN (10)
#define BT_DFXC_HFP_VOL (20)
#define BT_DFXC_HFP_MEDIA (30)
#define BT_DFXC_HFP_OFFLOAD (40)
// group: BT_DFXG_HID
#define BT_DFXC_HID_CONN (0)
// group: BT_DFXG_MESH
// group: BT_DFXG_CHANNEL_SOUNDING
// group: BT_DFXG_OTHERS
#define BT_DFXC_SOCKET (0)
#define BT_DFXC_IPC_CONN (10)
#define BT_DFXC_IPC_ALLOC (20)
#define BT_DFXC_DRIVER (100)
#define BT_DFXC_OPEN (200)
#define BT_DFX_BUILD_CODE(group, subcode) ((BT_DFX_BASE_VELA_BLUETOOTH) + (group) + (subcode))
#endif /* _BT_DFX_EVENT_H_ */

76
dfx/bt_dfx_reason.h Normal file
View File

@ -0,0 +1,76 @@
/****************************************************************************
* Copyright (C) 2025 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#ifndef _BT_DFX_REASON_H_
#define _BT_DFX_REASON_H_
// error reason
#define BT_DFXE_REPEATED_ATTEMPT "btRepeatedAttempt"
#define BT_DFXE_ADAPTER_STATE_NOT_ON "btAdapterStateNotOn"
#define BT_DFXE_PAGE_TIMEOUT "btPageTimeout"
#define BT_DFXE_CONN_TIMEOUT "btConnTimeout"
#define BT_DFXE_CONN_FAILED_TO_BE_ESTABLISHED "btConnFailedToBeEstablished"
#define BT_DFXE_SCANNER_EXCEED_MAX_NUM "btScannerExceedMaxNum"
#define BT_DFXE_SPP_NOT_STARTUP "btSppNotStartup"
#define BT_DFXE_SPP_SCN_ALLOC_FAIL "btSppScnAllocFail"
#define BT_DFXE_SPP_NO_RESOURCES "btSppNoResources"
#define BT_DFXE_A2DP_CONN_TIMEOUT "btA2dpConnTimeout"
#define BT_DFXE_SET_A2DP_AVAILABLE_FAIL "btSetA2dpAvailableFail"
#define BT_DFXE_GET_A2DP_AVAILABLE_FAIL "btGetA2dpAvailableFail"
#define BT_DFXE_OFFLOAD_START_TIMEOUT "btOffloadStartTimeout"
#define BT_DFXE_OFFLOAD_HCI_UNSPECIFIED_ERROR "btOffloadHciUnspecifiedError"
#define BT_DFXE_GET_MEDIA_VOLUME_RANGE_FAIL "btGetMediaVolumeRangeFail"
#define BT_DFXE_SET_MEDIA_VOLUME_FAIL "btSetMediaVolumeFail"
#define BT_DFXE_SET_UI_VOLUME_FAIL "btSetUiVolumeFail"
#define BT_DFXE_MEDIA_PLAYER_CREATE_FAIL "btMediaPlayerCreateFail"
#define BT_DFXE_GET_STREAM_VOLUME_FAIL "btGetStreamVolumeFail"
#define BT_DFXE_MEDIA_SESSION_OPEN_FAIL "btMediaSessionOpenFail"
#define BT_DFXE_MEDIA_SESSION_SET_EVENT_CB_FAIL "btMediaSessionSetEventCbFail"
#define BT_DFXE_MEDIA_SESSION_START_FAIL "btMediaSessionStartFail"
#define BT_DFXE_MEDIA_SESSION_STOP_FAIL "btMediaSessionStopFail"
#define BT_DFXE_MEDIA_SESSION_PAUSE_FAIL "btMediaSessionPauseFail"
#define BT_DFXE_MEDIA_SESSION_NEXT_SONG_FAIL "btMediaSessionNextSongFail"
#define BT_DFXE_MEDIA_SESSION_PREV_SONG_FAIL "btMediaSessionPrevSongFail"
#define BT_DFXE_HFP_AG_CONN_TIMEOUT "btHfpAgConnTimeout"
#define BT_DFXE_HFP_AG_CONN_RETRY_FAIL "btHfpAgConnRetryFail"
#define BT_DFXE_HFP_HF_CONN_TIMEOUT "btHfpHfConnTimeout"
#define BT_DFXE_HFP_HF_CONN_RETRY_FAIL "btHfpHfConnRetryFail"
#define BT_DFXE_SET_VOICE_CALL_VOLUME_FAIL "btSetVoiceCallVolumeFail"
#define BT_DFXE_GET_VOICE_CALL_VOLUME_FAIL "btGetVoiceCallVolumeFail"
#define BT_DFXE_MEDIA_POLICY_SUBSCRIBE_FAIL "btMediaPolicySubscribeFail"
#define BT_DFXE_SET_HFP_SAMPLERATE_FAIL "btSetHfpSamplerateFail"
#define BT_DFXE_SET_SCO_AVAILABLE_FAIL "btSetScoAvailableFail"
#define BT_DFXE_SET_SCO_UNAVAILABLE_FAIL "btSetScoUnavailableFail"
#define BT_DFXE_SET_ANC_ENABLE_FAIL "btSetAncEnableFail"
#define BT_DFXE_HID_CONNECT_BUSY "btHidConnectBusy"
#define BT_DFXE_CLIENT_CONNECT_FAIL "btClientConnectFail"
#define BT_DFXE_ASYNC_CLIENT_CONN_FAIL "btAsyncClientConnectFail"
#define BT_DFXE_FILE_DESCRIPTOR_ERROR "btFileDescriptorError"
#define BT_DFXE_SPP_CONN_FAIL "btSppConnFail"
#define BT_DFXE_CLIENT_MSG_ALLOC_FAIL "btClientMsgAllocFail"
#define BT_DFXE_SERVER_CACHE_ALLOC_FAIL "btServerCacheAllocFail"
#define BT_DFXE_OPEN_HCI_UART_FAIL "btOpenHciUartFail"
#define BT_DFXE_LE_ENABLE_FAIL "btLeEnableFail"
#define BT_DFXE_BR_ENABLE_FAIL "btBrEnableFail"
#endif /* _BT_DFX_REASON_H_ */

View File

@ -0,0 +1,137 @@
/*
* Copyright (C) 2025 Xiaomi Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef _FEATURE_BLUETOOTH_H_
#define _FEATURE_BLUETOOTH_H_
#include "bluetooth.h"
#include "bt_device.h"
#include "bt_list.h"
#include "bt_message_gattc.h"
#include "feature_exports.h"
#define FEATURE_MANAGER_BLUETOOTH_DATA "bluetooth"
#define FEATURE_BT_NO_RESOURCES 10013
#define FEATURE_BT_IPC_ERROR 10012
#define FEATURE_BT_UNKNOWN_ERROR 10008
#define FEATURE_BT_NOT_ENABLED 10001
#define FEATURE_BT_NOT_FOUND 10014
typedef enum {
STATE_NON_SCAN = 0,
STATE_SCANING = 1,
} ScanState;
typedef struct {
FtCallbackId feature_callback_id;
void* feature;
void* data;
} callback_info_t;
typedef struct {
FeatureInstanceHandle* feature_ins;
// There will be additional events related to subscribing to features in the future.
} feature_bluetooth_ins_t;
typedef struct {
FeatureInstanceHandle* feature_ins;
// There will be additional events related to subscribing to features in the future.
} feature_bluetooth_ble_ins_t;
typedef struct {
FtPromiseId pid;
union {
FeatureInstanceHandle feature_ins;
FeatureInterfaceHandle interface;
};
} feature_data_t;
typedef struct {
bt_instance_t* ins;
FeatureInterfaceHandle interface;
void* adv;
void* start_userdata;
bool busy;
} feature_bluetooth_adv_info_t;
typedef struct {
FtInt id;
FtCallbackId callback;
FtCallbackId fail;
} scan_subscribe_info_t;
typedef struct {
bt_instance_t* ins;
FeatureInterfaceHandle interface;
void* scan;
void* start_userdata;
bool busy;
bt_list_t* subscribe_info;
FtInt subscribe_id;
} feature_bluetooth_scan_info_t;
typedef struct {
gattc_handle_t handle;
bt_address_t remote_address;
ble_addr_type_t addr_type;
connection_state_t conn_state;
uint16_t gatt_mtu;
} gattc_t;
typedef enum {
FEATURE_GATTC_CONN,
FEATURE_GATTC_DISCONN,
FEATURE_GATTC_DISCOVERY,
FEATURE_GATTC_READ_CHAR,
FEATURE_GATTC_READ_DESC,
FEATURE_GATTC_WRITE_CHAR,
FEATURE_GATTC_WRITE_DESC,
FEATURE_GATTC_SET_MTU,
FEATURE_GATTC_SET_NOTIFY,
} gattc_userdata_type_t;
typedef struct {
FtPromiseId pid;
gattc_userdata_type_t userdata_type;
FeatureInterfaceHandle interface;
} gattc_data_t;
typedef struct {
bool created;
bt_instance_t* ins;
FeatureInterfaceHandle interface;
gattc_t* gattc;
bt_list_t* userdata_list;
} feature_bluetooth_gattc_info_t;
typedef struct {
bt_list_t* feature_ble_adv;
bt_list_t* feature_ble_scan;
bt_list_t* feature_ble_gattc;
} feature_bluetooth_features_info_t;
char* StringToFtString(const char* str);
bool js_event_cb_added();
void feature_bluetooth_post_task(FeatureInstanceHandle handle, FtCallbackId callback_id, void* data);
FeatureErrorCode bt_status_to_feature_error(uint8_t status);
void feature_bluetooth_init_bt_ins_async(FeatureProtoHandle handle);
void feature_bluetooth_uninit_bt_ins_async(void* data);
bt_instance_t* feature_bluetooth_get_bt_ins(FeatureInstanceHandle feature);
void feature_ble_list_free(void* data);
#endif // _FEATURE_BLUETOOTH_H_

View File

@ -0,0 +1,3 @@
module system.bluetooth@2.0
promise<object> getAddressAsync()

View File

@ -0,0 +1,169 @@
module system.bluetooth.ble@2.0
struct AdvertiseSetting {
int interval
int txPower
boolean connectable
}
struct ManufactureData {
string manufactureId
object manufactureValue
}
struct ServiceData {
string serviceUuid
object serviceValue
}
struct AdvertiseData {
string[] serviceUuids
ManufactureData[] manufactureData
ServiceData[] serviceData
}
struct StartAdvertisingParams {
AdvertiseSetting setting
AdvertiseData advData
AdvertiseData advResponse = null
}
interface Advertiser {
promise<void> startAdvertising(StartAdvertisingParams params)
void stopAdvertising()
void close()
}
[ctor="true", target="adv"] Advertiser createAdvertiser()
struct ScanFilter {
string deviceId
string name
string serviceUuid
}
const ScanDuty = {
SCAN_MODE_LOW_POWER = 0,
SCAN_MODE_BALANCED = 1,
SCAN_MODE_LOW_LATENCY = 2
}
struct ScanOptions {
int interval
int dutyMode
}
struct StartScanParams {
ScanFilter[] filters
ScanOptions options = null
}
const ScanState = {
STATE_NON_SCAN = 0,
STATE_SCANING = 1
}
struct ScanResult {
string deviceId
int rssi
object data
string addressType
}
callback deviceFoundResult(ScanResult[] result)
callback deviceFindFail()
struct DeviceFindParams {
callback deviceFoundResult callback
callback deviceFindFail fail
}
struct ScanStateParams {
int scanState
}
interface Scanner {
promise<void> startBLEScan(StartScanParams params)
void stopBLEScan()
promise<ScanStateParams> getScanState()
int subscribeBLEDeviceFind(DeviceFindParams params)
void unsubscribeBLEDeviceFind(int SubscribeId)
void close()
}
[ctor="true", target="scan"] Scanner createScanner()
struct BLEDescriptor {
string serviceUuid
string characteristicUuid
string descriptorUuid
object descriptorValue
}
struct GattProperties {
boolean read
boolean write
boolean writeNoResponse
boolean notify
boolean indicate
}
struct BLECharacteristic {
string serviceUuid
string characteristicUuid
object characteristicValue
BLEDescriptor[] descriptors
GattProperties properties
}
struct GattService {
string serviceUuid
boolean isPrimary
BLECharacteristic[] characteristics
GattService[] includeServices
}
struct SetNotifyCharChangedParams {
BLECharacteristic characteristic
boolean enable
}
const ProfileConnectionState = {
STATE_DISCONNECTED = 0,
STATE_CONNECTING = 1,
STATE_CONNECTED = 2,
STATE_DISCONNECTING = 3
}
struct ReadCharacteristicValue {
BLECharacteristic characteristic
}
struct ReadDescriptorValue {
BLEDescriptor descriptor
}
struct WriteCharacteristicValue {
BLECharacteristic characteristic
}
struct WriteDescriptorValue {
BLEDescriptor descriptor
}
struct SetBLEMtuSize {
int mtu
}
interface GattClient {
promise<void> connect()
promise<void> disconnect()
promise<GattService[]> getServices()
promise<BLECharacteristic> readCharacteristicValue(ReadCharacteristicValue params)
promise<BLEDescriptor> readDescriptorValue(ReadDescriptorValue params)
promise<void> writeCharacteristicValue(WriteCharacteristicValue params)
promise<void> writeDescriptorValue(WriteDescriptorValue params)
promise<void> setBLEMtuSize(SetBLEMtuSize params)
promise<void> setNotifyCharacteristicChanged(SetNotifyCharChangedParams params)
boolean close()
event onBLECharacteristicChange(BLECharacteristic params)
event onBLEConnectionStateChange(int state)
}
[ctor="true", target="gattc"] GattClient createGattClientDevice(string deviceId, string addressType = "UNKNOWN")

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,104 @@
/*
* Copyright (C) 2025 Xiaomi Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "bluetooth.h"
#include "bt_adapter.h"
#include "feature_bluetooth.h"
#include "feature_exports.h"
#include "feature_log.h"
#define file_tag "bluetooth"
void system_bluetooth_onRegister(const char* feature_name)
{
FEATURE_LOG_INFO("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_onCreate(FeatureRuntimeContext ctx, FeatureProtoHandle handle)
{
feature_bluetooth_init_bt_ins_async(handle);
FEATURE_LOG_INFO("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_onRequired(FeatureRuntimeContext ctx, FeatureInstanceHandle handle)
{
FEATURE_LOG_INFO("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_onDetached(FeatureRuntimeContext ctx, FeatureInstanceHandle handle)
{
FEATURE_LOG_INFO("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_onDestroy(FeatureRuntimeContext ctx, FeatureProtoHandle handle)
{
FEATURE_LOG_INFO("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_onUnregister(const char* feature_name)
{
FEATURE_LOG_INFO("%s::%s()", file_tag, __FUNCTION__);
}
static void get_addr_cb(bt_instance_t* ins, bt_status_t status, bt_address_t* addr, void* userdata)
{
feature_data_t* data = (feature_data_t*)userdata;
if (FeatureInstanceIsDetached(data->feature_ins)) {
FeatureFreeInstanceHandle(data->feature_ins);
free(data);
return;
}
if (addr != NULL) {
ft_context_ref ft_ctx = FeatureGetContext(data->feature_ins);
ft_value_t ret_obj = ft_new_object(ft_ctx);
char addr_str[BT_ADDR_STR_LENGTH] = { 0 };
bt_addr_ba2str(addr, addr_str);
ft_value_t ret_data = ft_from_string(ft_ctx, addr_str);
ft_obj_set_property(ft_ctx, ret_obj, "address", ret_data);
FeaturePromiseResolve(data->feature_ins, data->pid, &ret_obj);
ft_free_value(ft_ctx, ret_obj);
} else {
FeaturePromiseReject(data->feature_ins, data->pid, bt_status_to_feature_error(status), "get address failed!");
}
FeatureFreeInstanceHandle(data->feature_ins);
free(data);
}
void system_bluetooth_wrap_getAddressAsync(FeatureInstanceHandle feature, AppendData append_data, FtPromiseId pid)
{
feature_data_t* data;
bt_status_t status;
data = (feature_data_t*)malloc(sizeof(feature_data_t));
if (!data)
return;
data->feature_ins = FeatureDupInstanceHandle(feature);
data->pid = pid;
status = bt_adapter_get_address_async(feature_bluetooth_get_bt_ins(feature), get_addr_cb, (void*)data);
if (status == BT_STATUS_SUCCESS)
return;
FeaturePromiseReject(feature, pid, bt_status_to_feature_error(status), "get address failed!");
FeatureFreeInstanceHandle(data->feature_ins);
free(data);
}

View File

@ -0,0 +1,178 @@
/*
* Copyright (C) 2025 Xiaomi Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "feature_bluetooth.h"
#include "feature_log.h"
#include <kvdb.h>
#define KVDB_USE_FEATURE "persist.using_bluetooth_feature"
char* StringToFtString(const char* str)
{
if (!str) {
return NULL;
}
int len = strlen(str);
char* ftStr = (char*)FeatureMalloc(len + 1, FT_CHAR);
strcpy(ftStr, str);
return ftStr;
}
static bool feature_bluetooth_using_feature()
{
static int using_bluetoothd_feature = -1;
if (using_bluetoothd_feature == -1) {
using_bluetoothd_feature = property_get_bool(KVDB_USE_FEATURE, 1);
}
return using_bluetoothd_feature;
}
void feature_ble_list_free(void* data)
{
free(data);
}
static void feature_bluetooth_list_init(bt_instance_t* bt_ins)
{
feature_bluetooth_features_info_t* features_info;
if (!bt_ins) {
return;
}
features_info = (feature_bluetooth_features_info_t*)calloc(1, sizeof(feature_bluetooth_features_info_t));
assert(features_info);
features_info->feature_ble_adv = bt_list_new(feature_ble_list_free);
features_info->feature_ble_scan = bt_list_new(feature_ble_list_free);
features_info->feature_ble_gattc = bt_list_new(feature_ble_list_free);
bt_ins->context = features_info;
}
static void feature_bluetooth_list_uninit(bt_instance_t* bt_ins)
{
feature_bluetooth_features_info_t* features_info;
if (!bt_ins) {
return;
}
features_info = (feature_bluetooth_features_info_t*)bt_ins->context;
bt_list_free(features_info->feature_ble_adv);
bt_list_free(features_info->feature_ble_scan);
bt_list_free(features_info->feature_ble_gattc);
free(bt_ins->context);
bt_ins->context = NULL;
}
static void ipc_connected(bt_instance_t* ins, void* userdata)
{
FEATURE_LOG_ERROR("ipc connected");
}
static void ipc_disconnected(bt_instance_t* ins, void* userdata, int status)
{
FEATURE_LOG_ERROR("ipc disconnected");
}
void feature_bluetooth_init_bt_ins_async(FeatureProtoHandle handle)
{
uv_loop_t* loop;
FeatureManagerHandle manager = FeatureGetManagerHandleFromProto(handle);
void* data = FeatureGetManagerUserData(manager, FEATURE_MANAGER_BLUETOOTH_DATA);
bt_instance_t* bluetooth_ins = (bt_instance_t*)data;
if (!feature_bluetooth_using_feature()) {
FeatureSetProtoData(handle, NULL);
return;
}
if (bluetooth_ins) {
FeatureSetProtoData(handle, bluetooth_ins);
return;
}
loop = FeatureGetUVLoop(manager);
bluetooth_ins = bluetooth_create_async_instance(loop, ipc_connected, ipc_disconnected, NULL);
if (bluetooth_ins == NULL) {
FEATURE_LOG_ERROR("Failed to get Bluetooth instance.");
return;
}
FeatureSetManagerUserDataWithFreeCallback(manager, FEATURE_MANAGER_BLUETOOTH_DATA, bluetooth_ins, feature_bluetooth_uninit_bt_ins_async);
feature_bluetooth_list_init(bluetooth_ins);
FeatureSetProtoData(handle, bluetooth_ins);
}
void feature_bluetooth_uninit_bt_ins_async(void* data)
{
bt_instance_t* bluetooth_ins = (bt_instance_t*)data;
feature_bluetooth_features_info_t* features_info;
if (!feature_bluetooth_using_feature()) {
return;
}
features_info = (feature_bluetooth_features_info_t*)bluetooth_ins->context;
if (!features_info) {
FEATURE_LOG_ERROR("Feature context not found.");
return;
}
feature_bluetooth_list_uninit(bluetooth_ins);
bluetooth_delete_async_instance(bluetooth_ins);
}
bt_instance_t* feature_bluetooth_get_bt_ins(FeatureInstanceHandle feature)
{
FeatureProtoHandle protoHandle = FeatureGetProtoHandle(feature);
return FeatureGetProtoData(protoHandle);
}
FeatureErrorCode bt_status_to_feature_error(uint8_t status)
{
switch (status) {
case BT_STATUS_FAIL:
return FT_ERR_GENERAL;
case BT_STATUS_NOMEM:
return FT_ERR_GENERAL;
case BT_STATUS_NOT_ENABLED:
return FEATURE_BT_NOT_ENABLED;
case BT_STATUS_DONE:
return FT_ERR_DUPLICATE_SUBMISSION;
case BT_STATUS_NOT_SUPPORTED:
return FT_ERR_NOT_SUPPORTED;
case BT_STATUS_NO_RESOURCES:
return FEATURE_BT_NO_RESOURCES;
case BT_STATUS_IPC_ERROR:
return FEATURE_BT_IPC_ERROR;
case BT_STATUS_DEVICE_NOT_FOUND:
return FEATURE_BT_NOT_FOUND;
case BT_STATUS_PARM_INVALID:
return FT_ERR_ARGS;
case BT_STATUS_NOT_FOUND:
return FEATURE_BT_NOT_FOUND;
case BT_STATUS_ERROR_BUT_UNKNOWN:
return FEATURE_BT_UNKNOWN_ERROR;
default:
return FT_ERR_GENERAL;
}
}

View File

@ -0,0 +1,103 @@
/*
* This file is auto-generated by jsongensource.py, Do not modify it directly!
*/
/*
* Copyright (C) 2023 Xiaomi Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef FEATURE_BLUETOOTH_CONSTANT_H_
#define FEATURE_BLUETOOTH_CONSTANT_H_
#include "bluetooth.h"
#include "bt_list.h"
#include "feature_exports.h"
typedef enum {
A2DP_SINK,
A2DP_SOURCE,
HFP_AG,
HFP_HF,
HID_DEVICE,
PAN_USE,
MAX_FEATURE_ID,
} feature_bluetooth_profile_t;
typedef enum {
ON_ADAPTER_STATE_CHANGE,
ON_DISCOVERY_RESULT,
ON_BOND_STATE_CHANGE,
A2DPSINK_ON_CONNECT_STATE_CHANGE,
AVRCPCONTROL_ELEMENT_ATTRIBUTE_CALLBACK,
} feature_bluetooth_callback_t;
typedef enum {
FEATURE_BLUETOOTH,
FEATURE_BLUETOOTH_BT,
FEATURE_BLUETOOTH_A2DPSINK,
FEATURE_BLUETOOTH_AVRCPCONTROL,
} feature_bluetooth_feature_type_t;
typedef struct {
FeatureInstanceHandle* feature_ins;
FtCallbackId on_adapter_state_changed_cb_id;
} feature_bluetooth_bluetooth_callbacks_t;
typedef struct {
FeatureInstanceHandle* feature_ins;
FtCallbackId on_discovery_result_cb_id;
FtCallbackId on_bond_state_changed_cb_id;
} feature_bluetooth_bluetooth_bt_callbacks_t;
typedef struct {
FeatureInstanceHandle* feature_ins;
FtCallbackId a2dp_sink_connection_state_cb_id;
} feature_bluetooth_a2dp_sink_callbacks_t;
typedef struct {
FeatureInstanceHandle* feature_ins;
FtCallbackId avrcp_control_element_attribute_cb_id;
} feature_bluetooth_avrcp_control_callbacks_t;
typedef struct {
FtCallbackId feature_callback_id;
void* feature;
void* data;
} callback_info_t;
typedef struct {
uv_mutex_t mutex;
bt_list_t* feature_bluetooth_callbacks;
bt_list_t* feature_bluetooth_bt_callbacks;
bt_list_t* feature_a2dp_sink_callbacks;
bt_list_t* feature_avrcp_control_callbacks;
uint32_t created_features;
} feature_bluetooth_features_info_t;
void feature_bluetooth_deal_callback(int status, void* data);
void feature_bluetooth_remove_callback(int status, void* data);
void feature_bluetooth_post_task(FeatureInstanceHandle handle, FtCallbackId callback_id, void* data);
char* StringToFtString(const char* str);
void feature_bluetooth_init_bt_ins(feature_bluetooth_feature_type_t feature, FeatureProtoHandle handle);
void feature_bluetooth_uninit_bt_ins(feature_bluetooth_feature_type_t feature, FeatureProtoHandle handle);
bt_instance_t* feature_bluetooth_get_bt_ins(FeatureInstanceHandle feature);
void feature_bluetooth_add_feature_callback(FeatureInstanceHandle handle, feature_bluetooth_feature_type_t feature_type);
void feature_bluetooth_free_feature_callback(FeatureInstanceHandle handle, feature_bluetooth_feature_type_t feature_type);
void feature_bluetooth_set_feature_callback(FeatureInstanceHandle handle, FtCallbackId callback_id, feature_bluetooth_callback_t callback_type);
FtCallbackId feature_bluetooth_get_feature_callback(FeatureInstanceHandle handle, feature_bluetooth_callback_t callback_type);
void feature_bluetooth_callback_init(bt_instance_t* bt_ins);
void feature_bluetooth_callback_uninit(bt_instance_t* bt_ins);
#endif // FEATURE_BLUETOOTH_CONSTANT_H_

View File

@ -0,0 +1,45 @@
module system.bluetooth@1.0
callback openAdapterSuccess()
callback openAdapterFail(string data, int code)
callback openAdapterComplete()
struct OpenAdapterParams {
boolean operateAdapter = false
callback openAdapterSuccess success
callback openAdapterFail fail
callback openAdapterComplete complete
}
void openAdapter(OpenAdapterParams params)
callback closeAdapterSuccess()
callback closeAdapterFail(string data, int code)
callback closeAdapterComplete()
struct CloseAdapterParams {
boolean operateAdapter = false
callback closeAdapterSuccess success
callback closeAdapterFail fail
callback closeAdapterComplete complete
}
void closeAdapter(CloseAdapterParams params)
struct GetAdapterSuccessResult {
boolean available
boolean discovering
}
callback getAdapterStateSuccess(GetAdapterSuccessResult data)
callback getAdapterStateFail(string data, int code)
callback getAdapterStateComplete()
struct GetAdapterStateParams {
callback getAdapterStateSuccess success
callback getAdapterStateFail fail
callback getAdapterStateComplete complete
}
void getAdapterState(GetAdapterStateParams params)
struct adapterStateCallbackData {
boolean available
boolean discovering
}
callback adapterStateChange(adapterStateCallbackData data)
property adapterStateChange onadapterstatechange

View File

@ -0,0 +1,105 @@
module system.bluetooth.bt@1.0
callback startDiscoverySuccess()
callback startDiscoveryFail(string data, int code)
callback startDiscoveryComplete()
struct StartDiscoveryParams {
callback startDiscoverySuccess success
callback startDiscoveryFail fail
callback startDiscoveryComplete complete
}
void startDiscovery(StartDiscoveryParams params)
callback stopDiscoverySuccess()
callback stopDiscoveryFail(string data, int code)
callback stopDiscoveryComplete()
struct StopDiscoveryParams {
callback stopDiscoverySuccess success
callback stopDiscoveryFail fail
callback stopDiscoveryComplete complete
}
void stopDiscovery(StopDiscoveryParams params)
struct DiscoveryResultCallbackData {
string deviceId
string name
uint cod
uint rssi
}
callback discoveryResultChange(DiscoveryResultCallbackData data)
property discoveryResultChange ondiscoveryresult
callback connectProfilesSuccess()
callback connectProfilesFail(string data, int code)
callback connectProfilesComplete()
struct ConnectProfilesParams {
string deviceId
int[] profiles
callback connectProfilesSuccess success
callback connectProfilesFail fail
callback connectProfilesComplete complete
}
void connectProfiles(ConnectProfilesParams params)
callback disconnectProfilesSuccess()
callback disconnectProfilesFail(string data, int code)
callback disconnectProfilesComplete()
struct DisconnectProfilesParams{
string deviceId
int[] profiles
callback disconnectProfilesSuccess success
callback disconnectProfilesFail fail
callback disconnectProfilesComplete complete
}
void disconnectProfiles(DisconnectProfilesParams params)
callback disconnectSuccess()
callback disconnectFail(string data, int code)
callback disconnectComplete()
struct DisconnectParams{
string deviceId
callback disconnectSuccess success
callback disconnectFail fail
callback disconnectComplete complete
}
void disconnect(DisconnectParams params)
boolean getConnectState(string deviceId)
struct connectedDevice {
string deviceId
string name
int cod
}
string[] getConnectedDevices()
string[] getBondedDevices()
struct onBondStateChangeData {
string deviceId
int bondState
}
callback onBondStateChangeCallback(onBondStateChangeData data)
property onBondStateChangeCallback onbondstatechange
callback removeBondedSuccess()
callback removeBondedFail(string data, int code)
callback removeBondedComplete()
struct RemoveBondedParams{
string deviceId
callback removeBondedSuccess success
callback removeBondedFail fail
callback removeBondedComplete complete
}
void removeBondedDevice(RemoveBondedParams params)
boolean setScanMode(int scanMode)
int getScanMode()
string getDeviceName(string deviceId)
uint getDeviceClass(string deviceId)

View File

@ -0,0 +1,9 @@
module system.bluetooth.bt.a2dpsink@1.0
struct OnConnectStateChangeData {
string deviceId
int connectState
}
callback onConnectStateChangeCallback(OnConnectStateChangeData data)
property onConnectStateChangeCallback onconnectstatechange

View File

@ -0,0 +1,27 @@
module system.bluetooth.bt.avrcpcontrol@1.0
callback startGetElementAttributeSuccess()
callback startGetElementAttributeFail(string data, int code)
callback startGetElementAttributeComplete()
struct StartGetElementAttributeParams {
string deviceId
callback startGetElementAttributeSuccess success
callback startGetElementAttributeFail fail
callback startGetElementAttributeComplete complete
}
void startGetElementAttribute(StartGetElementAttributeParams params)
struct attr_info_t {
int attrId
int chrSet
string text
}
struct OnElementAttributeData {
string deviceId
int attrsCount
attr_info_t[] attrs;
}
callback ElementAttributeCallback(OnElementAttributeData data)
property ElementAttributeCallback onElementattribute

View File

@ -0,0 +1,784 @@
/*
* Copyright (C) 2024 Xiaomi Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "bt_a2dp_sink.h"
#include "bt_adapter.h"
#include "bt_avrcp_control.h"
#include "bt_list.h"
#include "feature_bluetooth.h"
#include "feature_exports.h"
#include "feature_log.h"
#include "system_bluetooth.h"
#include "system_bluetooth_bt.h"
#include "system_bluetooth_bt_a2dpsink.h"
#include "system_bluetooth_bt_avrcpcontrol.h"
#include "uv.h"
#define REMOVE_CALLBACK(feature_callback, callback_type) \
do { \
if (feature_callback->callback_type != -1) { \
feature_bluetooth_post_task(feature_callback->feature_ins, feature_callback->callback_type, NULL); \
} \
feature_callback->callback_type = -1; \
} while (0);
#define add_feature_callback(feature_callbacks, new_callbacks_type, handle) \
{ \
new_callbacks_type* new_callback = (new_callbacks_type*)malloc(sizeof(new_callbacks_type)); \
/* The hexadecimal representation of -1 is 0xFF */ \
memset(new_callback, -1, sizeof(new_callbacks_type)); \
new_callback->feature_ins = handle; \
bt_list_add_tail(feature_callbacks, new_callback); \
}
#define set_feature_callback(feature_callbacks, callbacks_type, find_func, handle, callback_id, callback_type) \
{ \
callbacks_type* callbacks = (callbacks_type*)bt_list_find(feature_callbacks, find_func, handle); \
REMOVE_CALLBACK(callbacks, callback_type) \
callbacks->callback_type = callback_id; \
};
#define get_feature_callback(feature_callbacks, callbacks_type, find_func, handle, callback_id, callback_type) \
{ \
callbacks_type* callbacks = (callbacks_type*)bt_list_find(feature_callbacks, find_func, handle); \
callback_id = callbacks->callback_type; \
};
static bool get_callback_bluetooth(void* data, void* feature_ins)
{
feature_bluetooth_bluetooth_callbacks_t* callbacks = (feature_bluetooth_bluetooth_callbacks_t*)data;
if (!callbacks) {
return false;
}
return callbacks->feature_ins == feature_ins;
}
static bool get_callback_bluetooth_bt(void* data, void* feature_ins)
{
feature_bluetooth_bluetooth_bt_callbacks_t* callbacks = (feature_bluetooth_bluetooth_bt_callbacks_t*)data;
if (!callbacks) {
return false;
}
return callbacks->feature_ins == feature_ins;
}
static bool get_callback_a2dp_sink(void* data, void* feature_ins)
{
feature_bluetooth_a2dp_sink_callbacks_t* callbacks = (feature_bluetooth_a2dp_sink_callbacks_t*)data;
if (!callbacks) {
return false;
}
return callbacks->feature_ins == feature_ins;
}
static bool get_callback_avrcp_control(void* data, void* feature_ins)
{
feature_bluetooth_avrcp_control_callbacks_t* callbacks = (feature_bluetooth_avrcp_control_callbacks_t*)data;
if (!callbacks) {
return false;
}
return callbacks->feature_ins == feature_ins;
}
static void free_feature_callback(bt_list_t* callbacks, FeatureInstanceHandle handle, bt_list_find_cb find_func)
{
void* data;
if (!callbacks) {
return;
}
data = bt_list_find(callbacks, find_func, handle);
if (data) {
bt_list_remove(callbacks, data);
}
}
static void free_feature_bluetooth_node(void* node)
{
feature_bluetooth_bluetooth_callbacks_t* feature_callback = (feature_bluetooth_bluetooth_callbacks_t*)node;
if (!feature_callback) {
return;
}
REMOVE_CALLBACK(feature_callback, on_adapter_state_changed_cb_id);
free(feature_callback);
}
static void free_feature_bluetooth_bt_node(void* node)
{
feature_bluetooth_bluetooth_bt_callbacks_t* feature_callback = (feature_bluetooth_bluetooth_bt_callbacks_t*)node;
if (!feature_callback) {
return;
}
REMOVE_CALLBACK(feature_callback, on_bond_state_changed_cb_id);
REMOVE_CALLBACK(feature_callback, on_discovery_result_cb_id);
free(feature_callback);
}
static void free_feature_bluetooth_a2dp_sink_node(void* node)
{
feature_bluetooth_a2dp_sink_callbacks_t* feature_callback = (feature_bluetooth_a2dp_sink_callbacks_t*)node;
if (!feature_callback) {
return;
}
REMOVE_CALLBACK(feature_callback, a2dp_sink_connection_state_cb_id);
free(feature_callback);
}
static void free_feature_bluetooth_avrcp_control_node(void* node)
{
feature_bluetooth_avrcp_control_callbacks_t* feature_callback = (feature_bluetooth_avrcp_control_callbacks_t*)node;
if (!feature_callback) {
return;
}
REMOVE_CALLBACK(feature_callback, avrcp_control_element_attribute_cb_id);
free(feature_callback);
}
static void on_adapter_state_changed_cb(void* cookie, bt_adapter_state_t state)
{
bt_instance_t* bt_ins = (bt_instance_t*)cookie;
feature_bluetooth_features_info_t* features_callbacks;
bt_list_t* callbacks;
bt_list_node_t* node;
FEATURE_LOG_DEBUG("adapter state change callback, state: %d", state);
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return;
}
uv_mutex_lock(&features_callbacks->mutex);
callbacks = features_callbacks->feature_bluetooth_callbacks;
if (!callbacks) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
node = bt_list_head(callbacks);
if (!node) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
while (node) {
feature_bluetooth_bluetooth_callbacks_t* feature_callback;
system_bluetooth_adapterStateCallbackData* data;
feature_callback = (feature_bluetooth_bluetooth_callbacks_t*)bt_list_node(node);
if (!feature_callback) {
break;
}
FEATURE_LOG_DEBUG("feature:%p, callbackId:%d", feature_callback->feature_ins, feature_callback->on_adapter_state_changed_cb_id);
if (state != BT_ADAPTER_STATE_ON && state != BT_ADAPTER_STATE_OFF) {
break;
}
data = system_bluetoothMallocadapterStateCallbackData();
if (!data) {
continue;
}
data->available = state == BT_ADAPTER_STATE_ON;
data->discovering = bt_adapter_is_discovering(bt_ins);
feature_bluetooth_post_task(feature_callback->feature_ins, feature_callback->on_adapter_state_changed_cb_id, data);
node = bt_list_next(callbacks, node);
}
uv_mutex_unlock(&features_callbacks->mutex);
}
static void on_discovery_state_changed_cb(void* cookie, bt_discovery_state_t state)
{
bt_instance_t* bt_ins = (bt_instance_t*)cookie;
feature_bluetooth_features_info_t* features_callbacks;
bt_list_t* callbacks;
bt_list_node_t* node;
FEATURE_LOG_DEBUG("discovery state change callback, state: %d", state);
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return;
}
uv_mutex_lock(&features_callbacks->mutex);
callbacks = features_callbacks->feature_bluetooth_callbacks;
if (!callbacks) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
node = bt_list_head(callbacks);
if (!node) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
while (node) {
feature_bluetooth_bluetooth_callbacks_t* feature_callback;
system_bluetooth_adapterStateCallbackData* data;
feature_callback = (feature_bluetooth_bluetooth_callbacks_t*)bt_list_node(node);
if (!feature_callback) {
break;
}
FEATURE_LOG_DEBUG("feature:%p, callbackId:%d", feature_callback->feature_ins, feature_callback->on_adapter_state_changed_cb_id);
data = system_bluetoothMallocadapterStateCallbackData();
if (!data) {
continue;
}
data->available = bt_adapter_get_state(bt_ins) == BT_ADAPTER_STATE_ON;
data->discovering = state == BT_DISCOVERY_STATE_STARTED;
feature_bluetooth_post_task(feature_callback->feature_ins, feature_callback->on_adapter_state_changed_cb_id, data);
node = bt_list_next(callbacks, node);
}
uv_mutex_unlock(&features_callbacks->mutex);
}
static void on_discovery_result_cb(void* cookie, bt_discovery_result_t* result)
{
bt_instance_t* bt_ins = (bt_instance_t*)cookie;
feature_bluetooth_features_info_t* features_callbacks;
bt_list_t* callbacks;
bt_list_node_t* node;
FEATURE_LOG_DEBUG("discovery result callback");
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return;
}
uv_mutex_lock(&features_callbacks->mutex);
callbacks = features_callbacks->feature_bluetooth_bt_callbacks;
if (!callbacks) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
node = bt_list_head(callbacks);
if (!node) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
while (node) {
feature_bluetooth_bluetooth_bt_callbacks_t* feature_callback;
system_bluetooth_bt_DiscoveryResultCallbackData* data;
char addr_str[BT_ADDR_STR_LENGTH] = { 0 };
feature_callback = (feature_bluetooth_bluetooth_bt_callbacks_t*)bt_list_node(node);
if (!feature_callback) {
break;
}
FEATURE_LOG_DEBUG("feature:%p, callbackId:%d", feature_callback->feature_ins, feature_callback->on_discovery_result_cb_id);
data = system_bluetooth_btMallocDiscoveryResultCallbackData();
if (!data) {
continue;
}
data->name = StringToFtString(result->name);
bt_addr_ba2str(&result->addr, addr_str);
data->deviceId = StringToFtString(addr_str);
data->cod = result->cod;
data->rssi = -result->rssi;
feature_bluetooth_post_task(feature_callback->feature_ins, feature_callback->on_discovery_result_cb_id, data);
node = bt_list_next(callbacks, node);
}
uv_mutex_unlock(&features_callbacks->mutex);
}
static void on_bond_state_changed_cb(void* cookie, bt_address_t* addr, bt_transport_t transport, bond_state_t state, bool is_ctkd)
{
bt_instance_t* bt_ins = (bt_instance_t*)cookie;
feature_bluetooth_features_info_t* features_callbacks;
bt_list_t* callbacks;
bt_list_node_t* node;
FEATURE_LOG_DEBUG("bond state callback");
if (transport != BT_TRANSPORT_BREDR) {
return;
}
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return;
}
uv_mutex_lock(&features_callbacks->mutex);
callbacks = features_callbacks->feature_bluetooth_bt_callbacks;
if (!callbacks) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
node = bt_list_head(callbacks);
if (!node) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
while (node) {
feature_bluetooth_bluetooth_bt_callbacks_t* feature_callback;
system_bluetooth_bt_onBondStateChangeData* data;
char addr_str[BT_ADDR_STR_LENGTH] = { 0 };
feature_callback = (feature_bluetooth_bluetooth_bt_callbacks_t*)bt_list_node(node);
if (!feature_callback) {
break;
}
FEATURE_LOG_DEBUG("feature:%p, callbackId:%d", feature_callback->feature_ins, feature_callback->on_bond_state_changed_cb_id);
data = system_bluetooth_btMalloconBondStateChangeData();
if (!data) {
continue;
}
bt_addr_ba2str(addr, addr_str);
data->deviceId = StringToFtString(addr_str);
data->bondState = state;
feature_bluetooth_post_task(feature_callback->feature_ins, feature_callback->on_bond_state_changed_cb_id, data);
node = bt_list_next(callbacks, node);
}
uv_mutex_unlock(&features_callbacks->mutex);
}
const static adapter_callbacks_t g_adapter_cbs = {
.on_adapter_state_changed = on_adapter_state_changed_cb,
.on_discovery_state_changed = on_discovery_state_changed_cb,
.on_discovery_result = on_discovery_result_cb,
.on_bond_state_changed = on_bond_state_changed_cb,
};
static void a2dp_sink_connection_state_cb(void* cookie, bt_address_t* addr, profile_connection_state_t state)
{
bt_instance_t* bt_ins = (bt_instance_t*)cookie;
feature_bluetooth_features_info_t* features_callbacks;
bt_list_t* callbacks;
bt_list_node_t* node;
FEATURE_LOG_DEBUG("a2dp sink connection state cb");
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return;
}
uv_mutex_lock(&features_callbacks->mutex);
callbacks = features_callbacks->feature_a2dp_sink_callbacks;
if (!callbacks) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
node = bt_list_head(callbacks);
if (!node) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
while (node) {
feature_bluetooth_a2dp_sink_callbacks_t* feature_callback;
system_bluetooth_bt_a2dpsink_OnConnectStateChangeData* data;
char addr_str[BT_ADDR_STR_LENGTH] = { 0 };
feature_callback = (feature_bluetooth_a2dp_sink_callbacks_t*)bt_list_node(node);
if (!feature_callback) {
break;
}
FEATURE_LOG_DEBUG("feature:%p, callbackId:%d", feature_callback->feature_ins, feature_callback->a2dp_sink_connection_state_cb_id);
bt_addr_ba2str(addr, addr_str);
data = system_bluetooth_bt_a2dpsinkMallocOnConnectStateChangeData();
if (!data) {
continue;
}
data->deviceId = StringToFtString(addr_str);
data->connectState = state;
feature_bluetooth_post_task(feature_callback->feature_ins, feature_callback->a2dp_sink_connection_state_cb_id, data);
node = bt_list_next(callbacks, node);
}
uv_mutex_unlock(&features_callbacks->mutex);
}
static const a2dp_sink_callbacks_t a2dp_sink_cbs = {
sizeof(a2dp_sink_cbs),
a2dp_sink_connection_state_cb,
};
system_bluetooth_bt_avrcpcontrol_attr_info_t* get_attr_info(avrcp_element_attr_val_t* attr)
{
system_bluetooth_bt_avrcpcontrol_attr_info_t* attr_info = system_bluetooth_bt_avrcpcontrolMallocattr_info_t();
attr_info->attrId = attr->attr_id;
attr_info->chrSet = attr->chr_set;
attr_info->text = StringToFtString((char*)attr->text);
return attr_info;
}
static void avrcp_control_get_element_attribute_cb(void* cookie, bt_address_t* addr, uint8_t attrs_count, avrcp_element_attr_val_t* attrs)
{
int attr_index;
bt_instance_t* bt_ins = (bt_instance_t*)cookie;
feature_bluetooth_features_info_t* features_callbacks;
bt_list_t* callbacks;
bt_list_node_t* node;
FEATURE_LOG_DEBUG("avrcp control element attribute cb");
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return;
}
uv_mutex_lock(&features_callbacks->mutex);
callbacks = features_callbacks->feature_avrcp_control_callbacks;
if (!callbacks) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
node = bt_list_head(callbacks);
if (!node) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
while (node) {
feature_bluetooth_avrcp_control_callbacks_t* feature_callback;
system_bluetooth_bt_avrcpcontrol_OnElementAttributeData* data;
FtArray* attributes;
char addr_str[BT_ADDR_STR_LENGTH] = { 0 };
feature_callback = (feature_bluetooth_avrcp_control_callbacks_t*)bt_list_node(node);
if (!feature_callback) {
break;
}
FEATURE_LOG_DEBUG("feature:%p, callbackId:%d", feature_callback->feature_ins, feature_callback->avrcp_control_element_attribute_cb_id);
bt_addr_ba2str(addr, addr_str);
data = system_bluetooth_bt_avrcpcontrolMallocOnElementAttributeData();
attributes = system_bluetooth_bt_avrcpcontrol_malloc_attr_info_t_struct_type_array();
if (!data || !attributes) {
continue;
}
data->deviceId = StringToFtString(addr_str);
data->attrsCount = attrs_count;
attributes->_size = attrs_count;
attributes->_element = malloc(attributes->_size * sizeof(struct Attribute*));
if (!attributes->_element) {
continue;
}
for (attr_index = 0; attr_index < attributes->_size; attr_index++) {
system_bluetooth_bt_avrcpcontrol_attr_info_t* attr_info = get_attr_info(&attrs[attr_index]);
((system_bluetooth_bt_avrcpcontrol_attr_info_t**)attributes->_element)[attr_index] = attr_info;
}
data->attrs = attributes;
feature_bluetooth_post_task(feature_callback->feature_ins, feature_callback->avrcp_control_element_attribute_cb_id, data);
node = bt_list_next(callbacks, node);
}
uv_mutex_unlock(&features_callbacks->mutex);
}
static const avrcp_control_callbacks_t avrcp_control_cbs = {
.size = sizeof(avrcp_control_cbs),
.get_element_attribute_cb = avrcp_control_get_element_attribute_cb,
};
void feature_bluetooth_add_feature_callback(FeatureInstanceHandle handle, feature_bluetooth_feature_type_t feature_type)
{
bt_instance_t* bt_ins;
feature_bluetooth_features_info_t* features_callbacks;
bt_ins = feature_bluetooth_get_bt_ins(handle);
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return;
}
uv_mutex_lock(&features_callbacks->mutex);
switch (feature_type) {
case FEATURE_BLUETOOTH:
add_feature_callback(features_callbacks->feature_bluetooth_callbacks, feature_bluetooth_bluetooth_callbacks_t, handle);
break;
case FEATURE_BLUETOOTH_BT:
add_feature_callback(features_callbacks->feature_bluetooth_bt_callbacks, feature_bluetooth_bluetooth_bt_callbacks_t, handle);
break;
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
case FEATURE_BLUETOOTH_A2DPSINK:
add_feature_callback(features_callbacks->feature_a2dp_sink_callbacks, feature_bluetooth_a2dp_sink_callbacks_t, handle);
break;
#endif
#ifdef CONFIG_BLUETOOTH_AVRCP_CONTROL
case FEATURE_BLUETOOTH_AVRCPCONTROL:
add_feature_callback(features_callbacks->feature_avrcp_control_callbacks, feature_bluetooth_avrcp_control_callbacks_t, handle);
break;
#endif
default:
break;
}
uv_mutex_unlock(&features_callbacks->mutex);
}
void feature_bluetooth_free_feature_callback(FeatureInstanceHandle handle, feature_bluetooth_feature_type_t feature_type)
{
bt_instance_t* bt_ins;
feature_bluetooth_features_info_t* features_callbacks;
bt_ins = feature_bluetooth_get_bt_ins(handle);
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return;
}
uv_mutex_lock(&features_callbacks->mutex);
switch (feature_type) {
case FEATURE_BLUETOOTH:
free_feature_callback(features_callbacks->feature_bluetooth_callbacks, handle, get_callback_bluetooth);
break;
case FEATURE_BLUETOOTH_BT:
free_feature_callback(features_callbacks->feature_bluetooth_bt_callbacks, handle, get_callback_bluetooth_bt);
break;
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
case FEATURE_BLUETOOTH_A2DPSINK:
free_feature_callback(features_callbacks->feature_a2dp_sink_callbacks, handle, get_callback_a2dp_sink);
break;
#endif
#ifdef CONFIG_BLUETOOTH_AVRCP_CONTROL
case FEATURE_BLUETOOTH_AVRCPCONTROL:
free_feature_callback(features_callbacks->feature_avrcp_control_callbacks, handle, get_callback_avrcp_control);
break;
#endif
default:
break;
}
uv_mutex_unlock(&features_callbacks->mutex);
}
void feature_bluetooth_set_feature_callback(FeatureInstanceHandle handle, FtCallbackId callback_id, feature_bluetooth_callback_t callback_type)
{
bt_instance_t* bt_ins;
feature_bluetooth_features_info_t* features_callbacks;
bt_ins = feature_bluetooth_get_bt_ins(handle);
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return;
}
uv_mutex_lock(&features_callbacks->mutex);
switch (callback_type) {
case ON_ADAPTER_STATE_CHANGE:
set_feature_callback(features_callbacks->feature_bluetooth_callbacks, feature_bluetooth_bluetooth_callbacks_t, get_callback_bluetooth, handle, callback_id, on_adapter_state_changed_cb_id);
break;
case ON_DISCOVERY_RESULT:
set_feature_callback(features_callbacks->feature_bluetooth_bt_callbacks, feature_bluetooth_bluetooth_bt_callbacks_t, get_callback_bluetooth_bt, handle, callback_id, on_discovery_result_cb_id);
break;
case ON_BOND_STATE_CHANGE:
set_feature_callback(features_callbacks->feature_bluetooth_bt_callbacks, feature_bluetooth_bluetooth_bt_callbacks_t, get_callback_bluetooth_bt, handle, callback_id, on_bond_state_changed_cb_id);
break;
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
case A2DPSINK_ON_CONNECT_STATE_CHANGE:
set_feature_callback(features_callbacks->feature_a2dp_sink_callbacks, feature_bluetooth_a2dp_sink_callbacks_t, get_callback_a2dp_sink, handle, callback_id, a2dp_sink_connection_state_cb_id);
break;
#endif
#ifdef CONFIG_BLUETOOTH_AVRCP_CONTROL
case AVRCPCONTROL_ELEMENT_ATTRIBUTE_CALLBACK:
set_feature_callback(features_callbacks->feature_avrcp_control_callbacks, feature_bluetooth_avrcp_control_callbacks_t, get_callback_avrcp_control, handle, callback_id, avrcp_control_element_attribute_cb_id);
break;
#endif
default:
break;
}
uv_mutex_unlock(&features_callbacks->mutex);
}
FtCallbackId feature_bluetooth_get_feature_callback(FeatureInstanceHandle handle, feature_bluetooth_callback_t callback_type)
{
bt_instance_t* bt_ins;
feature_bluetooth_features_info_t* features_callbacks;
FtCallbackId callback_id = -1;
bt_ins = feature_bluetooth_get_bt_ins(handle);
if (!bt_ins) {
return callback_id;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return callback_id;
}
uv_mutex_lock(&features_callbacks->mutex);
switch (callback_type) {
case ON_ADAPTER_STATE_CHANGE:
set_feature_callback(features_callbacks->feature_bluetooth_callbacks, feature_bluetooth_bluetooth_callbacks_t, get_callback_bluetooth, handle, callback_id, on_adapter_state_changed_cb_id);
break;
case ON_DISCOVERY_RESULT:
set_feature_callback(features_callbacks->feature_bluetooth_bt_callbacks, feature_bluetooth_bluetooth_bt_callbacks_t, get_callback_bluetooth_bt, handle, callback_id, on_discovery_result_cb_id);
break;
case ON_BOND_STATE_CHANGE:
set_feature_callback(features_callbacks->feature_bluetooth_bt_callbacks, feature_bluetooth_bluetooth_bt_callbacks_t, get_callback_bluetooth_bt, handle, callback_id, on_bond_state_changed_cb_id);
break;
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
case A2DPSINK_ON_CONNECT_STATE_CHANGE:
get_feature_callback(features_callbacks->feature_a2dp_sink_callbacks, feature_bluetooth_a2dp_sink_callbacks_t, get_callback_a2dp_sink, handle, callback_id, a2dp_sink_connection_state_cb_id);
break;
#endif
#ifdef CONFIG_BLUETOOTH_AVRCP_CONTROL
case AVRCPCONTROL_ELEMENT_ATTRIBUTE_CALLBACK:
get_feature_callback(features_callbacks->feature_avrcp_control_callbacks, feature_bluetooth_avrcp_control_callbacks_t, get_callback_avrcp_control, handle, callback_id, avrcp_control_element_attribute_cb_id);
break;
#endif
default:
break;
}
uv_mutex_unlock(&features_callbacks->mutex);
return callback_id;
}
void feature_bluetooth_callback_init(bt_instance_t* bt_ins)
{
feature_bluetooth_features_info_t* features_callbacks;
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)calloc(1, sizeof(feature_bluetooth_features_info_t));
assert(features_callbacks);
uv_mutex_init(&features_callbacks->mutex);
features_callbacks->feature_bluetooth_callbacks = bt_list_new(free_feature_bluetooth_node);
features_callbacks->feature_bluetooth_bt_callbacks = bt_list_new(free_feature_bluetooth_bt_node);
bt_ins->adapter_cookie = bt_adapter_register_callback(bt_ins, &g_adapter_cbs);
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
features_callbacks->feature_a2dp_sink_callbacks = bt_list_new(free_feature_bluetooth_a2dp_sink_node);
bt_ins->a2dp_sink_cookie = bt_a2dp_sink_register_callbacks(bt_ins, &a2dp_sink_cbs);
#endif
#ifdef CONFIG_BLUETOOTH_AVRCP_CONTROL
features_callbacks->feature_avrcp_control_callbacks = bt_list_new(free_feature_bluetooth_avrcp_control_node);
bt_ins->avrcp_control_cookie = bt_avrcp_control_register_callbacks(bt_ins, &avrcp_control_cbs);
#endif
bt_ins->context = features_callbacks;
}
void feature_bluetooth_callback_uninit(bt_instance_t* bt_ins)
{
feature_bluetooth_features_info_t* features_callbacks;
if (!bt_ins) {
return;
}
features_callbacks = bt_ins->context;
bt_ins->context = NULL;
if (!features_callbacks) {
return;
}
bt_adapter_unregister_callback(bt_ins, bt_ins->adapter_cookie);
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
bt_a2dp_sink_unregister_callbacks(bt_ins, bt_ins->a2dp_sink_cookie);
#endif
#ifdef CONFIG_BLUETOOTH_AVRCP_CONTROL
bt_avrcp_control_unregister_callbacks(bt_ins, bt_ins->avrcp_control_cookie);
#endif
uv_mutex_lock(&features_callbacks->mutex);
bt_list_free(features_callbacks->feature_bluetooth_callbacks);
bt_list_free(features_callbacks->feature_bluetooth_bt_callbacks);
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
bt_list_free(features_callbacks->feature_a2dp_sink_callbacks);
#endif
#ifdef CONFIG_BLUETOOTH_AVRCP_CONTROL
bt_list_free(features_callbacks->feature_avrcp_control_callbacks);
#endif
uv_mutex_unlock(&features_callbacks->mutex);
uv_mutex_destroy(&features_callbacks->mutex);
free(features_callbacks);
}

View File

@ -0,0 +1,170 @@
/*
* Copyright (C) 2024 Xiaomi Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "feature_bluetooth.h"
#include "feature_log.h"
#include <kvdb.h>
#define KVDB_USE_FEATURE "persist.using_bluetooth_feature"
static void free_callback_info(callback_info_t* info)
{
if (info->data)
FeatureFreeValue(info->data);
free(info);
}
void feature_bluetooth_deal_callback(int status, void* data)
{
callback_info_t* info = (callback_info_t*)data;
FEATURE_LOG_DEBUG("callback type:%d, feature:%p, callback id: %d", info->callback_id, info->feature, info->feature_callback_id);
if (!FeatureCheckCallbackId(info->feature, info->feature_callback_id)) {
goto freeData;
}
if (!FeatureInvokeCallback(info->feature, info->feature_callback_id, info->data)) {
FEATURE_LOG_ERROR("feature:%p, callback id: %d, invoke discoveryresult callback failed!",
info->feature, info->feature_callback_id);
}
freeData:
free_callback_info(info);
}
void feature_bluetooth_remove_callback(int status, void* data)
{
callback_info_t* info = (callback_info_t*)data;
FEATURE_LOG_DEBUG("remove callback, feature:%p, callback id: %d", info->feature, info->feature_callback_id);
FeatureRemoveCallback(info->feature, info->feature_callback_id);
free_callback_info(info);
}
void feature_bluetooth_post_task(FeatureInstanceHandle handle, FtCallbackId callback_id, void* data)
{
callback_info_t* callback_info;
callback_info = (callback_info_t*)calloc(1, sizeof(callback_info_t));
if (!callback_info) {
if (data)
FeatureFreeValue(data);
return;
}
callback_info->feature_callback_id = callback_id;
callback_info->feature = handle;
callback_info->data = data;
if (!FeaturePost(handle, feature_bluetooth_deal_callback, callback_info)) {
FEATURE_LOG_WARN("feature:%p, callback id: %d, post callback failed!", handle, callback_id);
free_callback_info(callback_info);
}
}
char* StringToFtString(const char* str)
{
if (!str) {
return NULL;
}
int len = strlen(str);
char* ftStr = (char*)FeatureMalloc(len + 1, FT_CHAR);
strcpy(ftStr, str);
return ftStr;
}
static bool feature_bluetooth_using_feature()
{
static int using_bluetoothd_feature = -1;
if (using_bluetoothd_feature == -1) {
using_bluetoothd_feature = property_get_bool(KVDB_USE_FEATURE, 1);
}
return using_bluetoothd_feature;
}
void feature_bluetooth_init_bt_ins(feature_bluetooth_feature_type_t feature, FeatureProtoHandle handle)
{
bt_instance_t* bluetooth_ins;
if (!feature_bluetooth_using_feature()) {
FeatureSetProtoData(handle, NULL);
return;
}
bluetooth_ins = bluetooth_get_instance();
if (bluetooth_ins == NULL) {
FEATURE_LOG_ERROR("Failed to get Bluetooth instance.");
return;
}
if (bluetooth_ins->context == NULL) {
feature_bluetooth_callback_init(bluetooth_ins);
}
((feature_bluetooth_features_info_t*)bluetooth_ins->context)->created_features |= (1UL << feature);
FeatureSetProtoData(handle, bluetooth_ins);
}
void feature_bluetooth_uninit_bt_ins(feature_bluetooth_feature_type_t feature, FeatureProtoHandle handle)
{
bt_instance_t* bluetooth_ins;
feature_bluetooth_features_info_t* features_info;
if (!feature_bluetooth_using_feature()) {
return;
}
FeatureSetProtoData(handle, NULL);
bluetooth_ins = bluetooth_find_instance(getpid());
if (bluetooth_ins == NULL) {
FEATURE_LOG_ERROR("Bluetooth instance not found.");
return;
}
features_info = (feature_bluetooth_features_info_t*)bluetooth_ins->context;
if (!features_info) {
FEATURE_LOG_ERROR("Feature context not found.");
return;
}
features_info->created_features &= ~(1UL << feature);
if (features_info->created_features) {
return;
}
feature_bluetooth_callback_uninit(bluetooth_ins);
bluetooth_delete_instance(bluetooth_ins);
}
void feature_bluetooth_set_bt_ins(FeatureProtoHandle protoHandle)
{
bt_instance_t* bluetooth_ins = bluetooth_get_instance();
FeatureSetProtoData(protoHandle, bluetooth_ins);
}
bt_instance_t* feature_bluetooth_get_bt_ins(FeatureInstanceHandle feature)
{
FeatureProtoHandle protoHandle = FeatureGetProtoHandle(feature);
return FeatureGetProtoData(protoHandle);
}

View File

@ -0,0 +1,70 @@
/*
* This file is auto-generated by jsongensource.py, Do not modify it directly!
*/
/*
* Copyright (C) 2023 Xiaomi Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "bt_a2dp_sink.h"
#include "feature_bluetooth.h"
#include "system_bluetooth_bt_a2dpsink.h"
#define file_tag "system_bluetooth_bt_a2dpsnk"
void system_bluetooth_bt_a2dpsink_onRegister(const char* feature_name)
{
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_a2dpsink_onCreate(FeatureRuntimeContext ctx, FeatureProtoHandle handle)
{
feature_bluetooth_init_bt_ins(FEATURE_BLUETOOTH_A2DPSINK, handle);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_a2dpsink_onRequired(FeatureRuntimeContext ctx, FeatureInstanceHandle handle)
{
feature_bluetooth_add_feature_callback(handle, FEATURE_BLUETOOTH_A2DPSINK);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_a2dpsink_onDetached(FeatureRuntimeContext ctx, FeatureInstanceHandle handle)
{
feature_bluetooth_free_feature_callback(handle, FEATURE_BLUETOOTH_A2DPSINK);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_a2dpsink_onDestroy(FeatureRuntimeContext ctx, FeatureProtoHandle handle)
{
feature_bluetooth_uninit_bt_ins(FEATURE_BLUETOOTH_A2DPSINK, handle);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_a2dpsink_onUnregister(const char* feature_name)
{
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
FtCallbackId system_bluetooth_bt_a2dpsink_get_onconnectstatechange(void* feature, AppendData append_data)
{
return feature_bluetooth_get_feature_callback(feature, A2DPSINK_ON_CONNECT_STATE_CHANGE);
}
void system_bluetooth_bt_a2dpsink_set_onconnectstatechange(void* feature, AppendData append_data, FtCallbackId onconnectstatechange)
{
FEATURE_LOG_DEBUG("set on a2dpsink set on connect state change callback: %p, callbackId: %d", feature, onconnectstatechange);
feature_bluetooth_set_feature_callback(feature, onconnectstatechange, A2DPSINK_ON_CONNECT_STATE_CHANGE);
}

View File

@ -0,0 +1,103 @@
/*
* This file is auto-generated by jsongensource.py, Do not modify it directly!
*/
/*
* Copyright (C) 2024 Xiaomi Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "bt_avrcp_control.h"
#include "feature_bluetooth.h"
#include "system_bluetooth_bt_avrcpcontrol.h"
#define file_tag "system_bluetooth_bt_avrcpcontrol"
void system_bluetooth_bt_avrcpcontrol_onRegister(const char* feature_name)
{
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_avrcpcontrol_onCreate(FeatureRuntimeContext ctx, FeatureProtoHandle handle)
{
feature_bluetooth_init_bt_ins(FEATURE_BLUETOOTH_AVRCPCONTROL, handle);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_avrcpcontrol_onRequired(FeatureRuntimeContext ctx, FeatureInstanceHandle handle)
{
feature_bluetooth_add_feature_callback(handle, FEATURE_BLUETOOTH_AVRCPCONTROL);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_avrcpcontrol_onDetached(FeatureRuntimeContext ctx, FeatureInstanceHandle handle)
{
feature_bluetooth_free_feature_callback(handle, FEATURE_BLUETOOTH_AVRCPCONTROL);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_avrcpcontrol_onDestroy(FeatureRuntimeContext ctx, FeatureProtoHandle handle)
{
feature_bluetooth_uninit_bt_ins(FEATURE_BLUETOOTH_AVRCPCONTROL, handle);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_avrcpcontrol_onUnregister(const char* feature_name)
{
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
FtCallbackId system_bluetooth_bt_avrcpcontrol_get_onElementattribute(void* feature, union AppendData append_data)
{
return feature_bluetooth_get_feature_callback(feature, AVRCPCONTROL_ELEMENT_ATTRIBUTE_CALLBACK);
}
void system_bluetooth_bt_avrcpcontrol_set_onElementattribute(void* feature, union AppendData append_data, FtCallbackId onElementattribute)
{
FEATURE_LOG_DEBUG("set on avrcpcontrol set element attribute callback: %p, callbackId: %d", feature, onElementattribute);
feature_bluetooth_set_feature_callback(feature, onElementattribute, AVRCPCONTROL_ELEMENT_ATTRIBUTE_CALLBACK);
}
void system_bluetooth_bt_avrcpcontrol_wrap_startGetElementAttribute(FeatureInstanceHandle feature, union AppendData append_data, system_bluetooth_bt_avrcpcontrol_StartGetElementAttributeParams* params)
{
bt_address_t addr;
bt_status_t status;
if (bt_addr_str2ba(params->deviceId, &addr) < 0) {
if (!FeatureInvokeCallback(feature, params->fail, "invalid addr!", BT_STATUS_PARM_INVALID)) {
FEATURE_LOG_ERROR("invoke get element attribute fail callback failed!");
}
goto COMPLETE_CALLBACK;
}
status = bt_avrcp_control_get_element_attributes(feature_bluetooth_get_bt_ins(feature), &addr);
if (status == BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke get element attribute success failed!");
}
} else {
if (!FeatureInvokeCallback(feature, params->fail, "get element attribute failed!", status)) {
FEATURE_LOG_ERROR("invoke get element attribute fail callback failed!");
}
}
COMPLETE_CALLBACK:
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke disconnect complete callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}

View File

@ -0,0 +1,457 @@
/*
* This file is auto-generated by jsongensource.py, Do not modify it directly!
*/
/*
* Copyright (C) 2023 Xiaomi Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "bluetooth.h"
#include "bt_a2dp_sink.h"
#include "bt_a2dp_source.h"
#include "bt_adapter.h"
#include "bt_hfp_ag.h"
#include "bt_hfp_hf.h"
#include "bt_hid_device.h"
#include "bt_pan.h"
#include "feature_bluetooth.h"
#include "system_bluetooth_bt.h"
#define file_tag "system_bluetooth_bt"
static bool bt_feature_allocator(void** data, uint32_t size)
{
*data = malloc(size);
if (!(*data))
return false;
return true;
}
static bt_status_t bluetooth_connect_profiles(FeatureInstanceHandle feature, bt_address_t* addr, feature_bluetooth_profile_t profile_id)
{
bt_status_t status = BT_STATUS_SUCCESS;
bt_instance_t* bt_ins = feature_bluetooth_get_bt_ins(feature);
if (!bt_ins) {
return BT_STATUS_FAIL;
}
switch (profile_id) {
case A2DP_SINK:
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
status = bt_a2dp_sink_connect(bt_ins, addr);
#endif
break;
case A2DP_SOURCE:
#ifdef CONFIG_BLUETOOTH_A2DP_SOURCE
status = bt_a2dp_source_connect(bt_ins, addr);
#endif
break;
case HFP_AG:
#ifdef CONFIG_BLUETOOTH_HFP_AG
status = bt_hfp_ag_connect(bt_ins, addr);
#endif
break;
case HFP_HF:
#ifdef CONFIG_BLUETOOTH_HFP_HF
status = bt_hfp_hf_connect(bt_ins, addr);
#endif
break;
case HID_DEVICE:
#ifdef CONFIG_BLUETOOTH_HID_DEVICE
status = bt_hid_device_connect(bt_ins, addr);
#endif
break;
case PAN_USE:
#ifdef CONFIG_BLUETOOTH_PAN
status = bt_pan_connect(bt_ins, addr);
#endif
break;
default:
status = BT_STATUS_NOT_SUPPORTED;
break;
}
return status;
}
static bt_status_t bluetooth_disconnect_profiles(FeatureInstanceHandle feature, bt_address_t* addr, feature_bluetooth_profile_t profile_id)
{
bt_status_t status = BT_STATUS_SUCCESS;
bt_instance_t* bt_ins = feature_bluetooth_get_bt_ins(feature);
if (!bt_ins) {
return BT_STATUS_FAIL;
}
switch (profile_id) {
case A2DP_SINK:
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
status = bt_a2dp_sink_disconnect(bt_ins, addr);
#endif
break;
case A2DP_SOURCE:
#ifdef CONFIG_BLUETOOTH_A2DP_SOURCE
status = bt_a2dp_source_disconnect(bt_ins, addr);
#endif
break;
case HFP_AG:
#ifdef CONFIG_BLUETOOTH_HFP_AG
status = bt_hfp_ag_disconnect(bt_ins, addr);
#endif
break;
case HFP_HF:
#ifdef CONFIG_BLUETOOTH_HFP_HF
status = bt_hfp_hf_disconnect(bt_ins, addr);
#endif
break;
case HID_DEVICE:
#ifdef CONFIG_BLUETOOTH_HID_DEVICE
status = bt_hid_device_disconnect(bt_ins, addr);
#endif
break;
case PAN_USE:
#ifdef CONFIG_BLUETOOTH_PAN
status = bt_pan_disconnect(bt_ins, addr);
#endif
break;
default:
status = BT_STATUS_NOT_SUPPORTED;
break;
}
return status;
}
void system_bluetooth_bt_onRegister(const char* feature_name)
{
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_onCreate(FeatureRuntimeContext ctx, FeatureProtoHandle handle)
{
feature_bluetooth_init_bt_ins(FEATURE_BLUETOOTH_BT, handle);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_onRequired(FeatureRuntimeContext ctx, FeatureInstanceHandle handle)
{
feature_bluetooth_add_feature_callback(handle, FEATURE_BLUETOOTH_BT);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_onDetached(FeatureRuntimeContext ctx, FeatureInstanceHandle handle)
{
feature_bluetooth_free_feature_callback(handle, FEATURE_BLUETOOTH_BT);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_onDestroy(FeatureRuntimeContext ctx, FeatureProtoHandle handle)
{
feature_bluetooth_uninit_bt_ins(FEATURE_BLUETOOTH_BT, handle);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_onUnregister(const char* feature_name)
{
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_wrap_startDiscovery(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_bt_StartDiscoveryParams* params)
{
int timeout = 8;
bt_status_t status = bt_adapter_start_discovery(feature_bluetooth_get_bt_ins(feature), timeout);
if (status == BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke start discovery success failed!");
}
} else {
if (!FeatureInvokeCallback(feature, params->fail, "start discovery failed!", status)) {
FEATURE_LOG_ERROR("invoke start discovery fail callback failed!");
}
}
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke start discovery complete callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}
void system_bluetooth_bt_wrap_stopDiscovery(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_bt_StopDiscoveryParams* params)
{
bt_status_t status = bt_adapter_cancel_discovery(feature_bluetooth_get_bt_ins(feature));
if (status == BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke stop discovery success callback failed!");
}
} else {
if (!FeatureInvokeCallback(feature, params->fail, "stop discovery failed!", status)) {
FEATURE_LOG_ERROR("invoke stop discovery fail callback failed!");
}
}
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke stop discovery complete callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}
void system_bluetooth_bt_wrap_connectProfiles(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_bt_ConnectProfilesParams* params)
{
int profiles_num = params->profiles->_size;
int* profiles = (int*)(params->profiles->_element);
bt_address_t addr;
int status = BT_STATUS_SUCCESS;
if (bt_addr_str2ba(params->deviceId, &addr) < 0) {
if (!FeatureInvokeCallback(feature, params->fail, "invalid addr!", BT_STATUS_PARM_INVALID)) {
FEATURE_LOG_ERROR("invoke connect profiles fail callback failed!");
}
goto COMPLETE_CALLBACK;
}
for (int i = 0; i < profiles_num; ++i) {
status |= bluetooth_connect_profiles(feature, &addr, (feature_bluetooth_profile_t)(profiles[i]));
}
if (status != BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->fail, "connect all passing profiles failed!", status)) {
FEATURE_LOG_ERROR("invoke connect profiles fail callback failed!");
}
} else {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke connect profiles success callback failed!");
}
}
COMPLETE_CALLBACK:
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke connect profiles complete callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}
void system_bluetooth_bt_wrap_disconnectProfiles(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_bt_DisconnectProfilesParams* params)
{
int profiles_num = params->profiles->_size;
int* profiles = (int*)params->profiles->_element;
bt_address_t addr;
int status = BT_STATUS_SUCCESS;
if (bt_addr_str2ba(params->deviceId, &addr) < 0) {
if (!FeatureInvokeCallback(feature, params->fail, "invalid addr!", BT_STATUS_PARM_INVALID)) {
FEATURE_LOG_ERROR("invoke disconnect profiles fail callback failed!");
}
goto COMPLETE_CALLBACK;
}
for (int i = 0; i < profiles_num; ++i) {
status |= bluetooth_disconnect_profiles(feature, &addr, (feature_bluetooth_profile_t)profiles[i]);
}
if (status != BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->fail, "disconnect all passing profiles failed!", status)) {
FEATURE_LOG_ERROR("invoke disconnect profiles fail callback failed!");
}
} else {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke disconnect profiles success callback failed!");
}
}
COMPLETE_CALLBACK:
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke disconnect profiles complete callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}
void system_bluetooth_bt_wrap_disconnect(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_bt_DisconnectParams* params)
{
bt_address_t addr;
bt_status_t status = BT_STATUS_SUCCESS;
if (bt_addr_str2ba(params->deviceId, &addr) < 0) {
if (!FeatureInvokeCallback(feature, params->fail, "invalid addr!", BT_STATUS_PARM_INVALID)) {
FEATURE_LOG_ERROR("invoke disconnect fail callback failed!");
}
goto COMPLETE_CALLBACK;
}
status = bt_device_disconnect(feature_bluetooth_get_bt_ins(feature), &addr);
if (status != BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->fail, "disconnect failed!", status)) {
FEATURE_LOG_ERROR("invoke disconnect fail callback failed!");
}
} else {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke disconnect success callback failed!");
}
}
COMPLETE_CALLBACK:
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke disconnect complete callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}
FtBool system_bluetooth_bt_wrap_getConnectState(FeatureInstanceHandle feature, AppendData append_data, FtString deviceId)
{
FtBool connected = false;
bt_address_t addr;
if (bt_addr_str2ba(deviceId, &addr) < 0) {
return false;
}
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
connected |= bt_a2dp_sink_get_connection_state(feature_bluetooth_get_bt_ins(feature), &addr);
#endif
return connected;
}
FtArray* system_bluetooth_bt_wrap_getConnectedDevices(FeatureInstanceHandle feature, AppendData append_data)
{
bt_address_t* addrs = NULL;
int num = 0;
bt_adapter_get_connected_devices(feature_bluetooth_get_bt_ins(feature), BT_TRANSPORT_BREDR, &addrs, &num, bt_feature_allocator);
FtArray* devices = system_bluetooth_bt_malloc_string_array();
devices->_size = num;
devices->_element = malloc(devices->_size * sizeof(char*));
for (int i = 0; i < devices->_size; ++i) {
char addr_str[BT_ADDR_STR_LENGTH] = { 0 };
bt_addr_ba2str(addrs + i, addr_str);
((char**)devices->_element)[i] = StringToFtString(addr_str);
}
free(addrs);
return devices;
}
FtArray* system_bluetooth_bt_wrap_getBondedDevices(FeatureInstanceHandle feature, AppendData append_data)
{
bt_address_t* addrs = NULL;
int num = 0;
bt_adapter_get_bonded_devices(feature_bluetooth_get_bt_ins(feature), BT_TRANSPORT_BREDR, &addrs, &num, bt_feature_allocator);
FtArray* devices = system_bluetooth_bt_malloc_string_array();
devices->_size = num;
devices->_element = malloc(devices->_size * sizeof(char*));
for (int i = 0; i < devices->_size; ++i) {
char addr_str[BT_ADDR_STR_LENGTH] = { 0 };
bt_addr_ba2str(addrs + i, addr_str);
((char**)devices->_element)[i] = StringToFtString(addr_str);
}
free(addrs);
return devices;
}
void system_bluetooth_bt_wrap_removeBondedDevice(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_bt_RemoveBondedParams* params)
{
bt_address_t addr;
bt_status_t status;
if (bt_addr_str2ba(params->deviceId, &addr) < 0) {
if (!FeatureInvokeCallback(feature, params->fail, "invalid addr!", BT_STATUS_PARM_INVALID)) {
FEATURE_LOG_ERROR("invoke remove bonded fail callback failed!");
}
goto COMPLETE_CALLBACK;
}
if (!bt_device_is_bonded(feature_bluetooth_get_bt_ins(feature), &addr, BT_TRANSPORT_BREDR)) {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke remove bonded success callback failed!");
}
goto COMPLETE_CALLBACK;
}
status = bt_device_remove_bond(feature_bluetooth_get_bt_ins(feature), &addr, BT_TRANSPORT_BREDR);
if (status != BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->fail, "remove bonded failed!", status)) {
FEATURE_LOG_ERROR("invoke remove bonded fail callback failed!");
}
} else {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke remove bonded success callback failed!");
}
}
COMPLETE_CALLBACK:
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke remove bonded complete callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}
FtBool system_bluetooth_bt_wrap_setScanMode(FeatureInstanceHandle feature, AppendData append_data, FtInt scanMode)
{
FEATURE_LOG_DEBUG("set scanmode: %d!", scanMode);
if (scanMode < 0 || scanMode > 2) {
return false;
}
if (bt_adapter_set_scan_mode(feature_bluetooth_get_bt_ins(feature), (bt_scan_mode_t)scanMode, 1) == BT_STATUS_SUCCESS) {
return true;
} else {
return false;
}
}
FtInt system_bluetooth_bt_wrap_getScanMode(FeatureInstanceHandle feature, AppendData append_data)
{
return bt_adapter_get_scan_mode(feature_bluetooth_get_bt_ins(feature));
}
FtString system_bluetooth_bt_wrap_getDeviceName(FeatureInstanceHandle feature, AppendData append_data, FtString deviceId)
{
bt_address_t addr;
char name[64] = { 0 };
if (bt_addr_str2ba(deviceId, &addr) < 0) {
return StringToFtString("");
}
bt_device_get_name(feature_bluetooth_get_bt_ins(feature), &addr, name, 64);
return StringToFtString(name);
}
FtUint32 system_bluetooth_bt_wrap_getDeviceClass(FeatureInstanceHandle feature, AppendData append_data, FtString deviceId)
{
bt_address_t addr;
if (bt_addr_str2ba(deviceId, &addr) < 0) {
return 0;
}
return bt_device_get_device_class(feature_bluetooth_get_bt_ins(feature), &addr);
}
FtCallbackId system_bluetooth_bt_get_ondiscoveryresult(void* feature, AppendData append_data)
{
return feature_bluetooth_get_feature_callback(feature, ON_DISCOVERY_RESULT);
}
void system_bluetooth_bt_set_ondiscoveryresult(void* feature, AppendData append_data, FtCallbackId ondiscoveryresult)
{
FEATURE_LOG_DEBUG("set ondiscoveryresult feature: %p, callbackId: %d", feature, ondiscoveryresult);
feature_bluetooth_set_feature_callback(feature, ondiscoveryresult, ON_DISCOVERY_RESULT);
}
FtCallbackId system_bluetooth_bt_get_onbondstatechange(void* feature, AppendData append_data)
{
return feature_bluetooth_get_feature_callback(feature, ON_BOND_STATE_CHANGE);
}
void system_bluetooth_bt_set_onbondstatechange(void* feature, AppendData append_data, FtCallbackId onbondstatechange)
{
FEATURE_LOG_DEBUG("set onbondstatechange feature: %p, callbackId: %d", feature, onbondstatechange);
feature_bluetooth_set_feature_callback(feature, onbondstatechange, ON_BOND_STATE_CHANGE);
}

View File

@ -0,0 +1,140 @@
/*
* This file is auto-generated by jsongensource.py, Do not modify it directly!
*/
/*
* Copyright (C) 2023 Xiaomi Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "bluetooth.h"
#include "bt_adapter.h"
#include "feature_bluetooth.h"
#include "feature_exports.h"
#include "feature_log.h"
#include "system_bluetooth.h"
#include "system_bluetooth_bt.h"
#define file_tag "system_bluetooth"
void system_bluetooth_onRegister(const char* feature_name)
{
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_onCreate(FeatureRuntimeContext ctx, FeatureProtoHandle handle)
{
feature_bluetooth_init_bt_ins(FEATURE_BLUETOOTH, handle);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_onRequired(FeatureRuntimeContext ctx, FeatureInstanceHandle handle)
{
feature_bluetooth_add_feature_callback(handle, FEATURE_BLUETOOTH);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_onDetached(FeatureRuntimeContext ctx, FeatureInstanceHandle handle)
{
feature_bluetooth_free_feature_callback(handle, FEATURE_BLUETOOTH);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_onDestroy(FeatureRuntimeContext ctx, FeatureProtoHandle handle)
{
feature_bluetooth_uninit_bt_ins(FEATURE_BLUETOOTH, handle);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_onUnregister(const char* feature_name)
{
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_wrap_openAdapter(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_OpenAdapterParams* params)
{
bt_status_t status = bt_adapter_enable(feature_bluetooth_get_bt_ins(feature));
if (status == BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke success openAdapter callback failed, feature is %p, params->success is %d!", feature, params->success);
}
} else {
if (!FeatureInvokeCallback(feature, params->fail, "enable fail!", status)) {
FEATURE_LOG_ERROR("invoke fail openAdapter callback failed!");
}
}
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke complete openAdapter callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}
void system_bluetooth_wrap_closeAdapter(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_CloseAdapterParams* params)
{
bt_status_t status = bt_adapter_disable(feature_bluetooth_get_bt_ins(feature));
if (status == BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke success closeAdapter callback failed!");
}
} else {
if (!FeatureInvokeCallback(feature, params->fail, "enable fail!", status)) {
FEATURE_LOG_ERROR("invoke fail closeAdapter callback failed!");
}
}
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke complete closeAdapter callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}
void system_bluetooth_wrap_getAdapterState(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_GetAdapterStateParams* params)
{
bt_instance_t* ins = feature_bluetooth_get_bt_ins(feature);
bt_adapter_state_t state = bt_adapter_get_state(ins);
bool is_discovering = bt_adapter_is_discovering(ins);
system_bluetooth_GetAdapterSuccessResult* success_result = system_bluetoothMallocGetAdapterSuccessResult();
success_result->available = state == BT_ADAPTER_STATE_ON;
success_result->discovering = is_discovering;
if (!FeatureInvokeCallback(feature, params->success, success_result)) {
FEATURE_LOG_ERROR("invoke success getAdapterState callback failed!");
}
FeatureFreeValue(success_result);
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke complete getAdapterState callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}
FtCallbackId system_bluetooth_get_onadapterstatechange(void* feature, AppendData append_data)
{
return feature_bluetooth_get_feature_callback(feature, ON_ADAPTER_STATE_CHANGE);
}
void system_bluetooth_set_onadapterstatechange(void* feature, AppendData append_data, FtCallbackId onadapterstatechange)
{
FEATURE_LOG_DEBUG("set onadapterstatechange feature: %p, callbackId: %d", feature, onadapterstatechange);
feature_bluetooth_set_feature_callback(feature, onadapterstatechange, ON_ADAPTER_STATE_CHANGE);
}

109
framework/api/bluetooth.c Normal file
View File

@ -0,0 +1,109 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdlib.h>
#include <unistd.h>
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_LOCAL
#include "btservice.h"
#include "manager_service.h"
#include "service_loop.h"
#endif
#include "bluetooth.h"
#include "bt_internal.h"
#include "manager_service.h"
/*
*/
bt_instance_t* BTSYMBOLS(bluetooth_create_instance)(void)
{
uint32_t app_id;
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_LOCAL
service_loop_init();
bt_service_init();
service_loop_run(true, "bt_service");
#endif
bt_instance_t* ins = zalloc(sizeof(bt_instance_t));
if (!ins) {
return NULL;
}
bt_status_t status = manager_create_instance(PTR2INT(uint64_t) ins, BLUETOOTH_SYSTEM, "local", getpid(), 0, &app_id);
if (status != BT_STATUS_SUCCESS) {
free(ins);
return NULL;
}
ins->app_id = app_id;
return ins;
}
bt_instance_t* BTSYMBOLS(bluetooth_get_instance)(void)
{
bt_status_t status;
uint64_t handle;
status = manager_get_instance("local", getpid(), &handle);
if (status == BT_STATUS_SUCCESS && handle)
return INT2PTR(bt_instance_t*) handle;
else
return BTSYMBOLS(bluetooth_create_instance)();
}
void* BTSYMBOLS(bluetooth_get_proxy)(bt_instance_t* ins, enum profile_id id)
{
switch (id) {
case PROFILE_HFP_HF:
/* for binder ipc*/
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_BINDER_IPC
if (!ins->hfp_hf_proxy) {
ins->hfp_hf_proxy = NULL;
}
return ins->hfp_hf_proxy;
#endif
default:
break;
}
return NULL;
}
void BTSYMBOLS(bluetooth_delete_instance)(bt_instance_t* ins)
{
manager_delete_instance(ins->app_id);
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_LOCAL
bt_service_cleanup();
service_loop_exit();
#endif
free(ins);
}
bt_status_t BTSYMBOLS(bluetooth_start_service)(bt_instance_t* ins, enum profile_id id)
{
return manager_start_service(ins->app_id, id);
}
bt_status_t BTSYMBOLS(bluetooth_stop_service)(bt_instance_t* ins, enum profile_id id)
{
return manager_stop_service(ins->app_id, id);
}
#include "uv.h"
bool BTSYMBOLS(bluetooth_set_external_uv)(bt_instance_t* ins, uv_loop_t* ext_loop)
{
return false;
}

View File

@ -0,0 +1,86 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "a2dp_sink_api"
#include <stdint.h>
#include "a2dp_sink_service.h"
#include "bt_a2dp_sink.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "service_manager.h"
#include "utils/log.h"
static a2dp_sink_interface_t* get_profile_service(void)
{
return (a2dp_sink_interface_t*)service_manager_get_profile(PROFILE_A2DP_SINK);
}
void* BTSYMBOLS(bt_a2dp_sink_register_callbacks)(bt_instance_t* ins, const a2dp_sink_callbacks_t* callbacks)
{
a2dp_sink_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool BTSYMBOLS(bt_a2dp_sink_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
a2dp_sink_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bool BTSYMBOLS(bt_a2dp_sink_is_connected)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_sink_interface_t* profile = get_profile_service();
return profile->is_connected(addr);
}
bool BTSYMBOLS(bt_a2dp_sink_is_playing)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_sink_interface_t* profile = get_profile_service();
return profile->is_playing(addr);
}
profile_connection_state_t BTSYMBOLS(bt_a2dp_sink_get_connection_state)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_sink_interface_t* profile = get_profile_service();
return profile->get_connection_state(addr);
}
bt_status_t BTSYMBOLS(bt_a2dp_sink_connect)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_sink_interface_t* profile = get_profile_service();
return profile->connect(addr);
}
bt_status_t BTSYMBOLS(bt_a2dp_sink_disconnect)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_sink_interface_t* profile = get_profile_service();
return profile->disconnect(addr);
}
bt_status_t BTSYMBOLS(bt_a2dp_sink_set_active_device)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_sink_interface_t* profile = get_profile_service();
return profile->set_active_device(addr);
}

View File

@ -0,0 +1,93 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "a2dp_source_api"
#include <stdint.h>
#include "a2dp_source_service.h"
#include "bt_a2dp_source.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "service_manager.h"
#include "utils/log.h"
static a2dp_source_interface_t* get_profile_service(void)
{
return (a2dp_source_interface_t*)service_manager_get_profile(PROFILE_A2DP);
}
void* BTSYMBOLS(bt_a2dp_source_register_callbacks)(bt_instance_t* ins, const a2dp_source_callbacks_t* callbacks)
{
a2dp_source_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool BTSYMBOLS(bt_a2dp_source_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
a2dp_source_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bool BTSYMBOLS(bt_a2dp_source_is_connected)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_source_interface_t* profile = get_profile_service();
return profile->is_connected(addr);
}
bool BTSYMBOLS(bt_a2dp_source_is_playing)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_source_interface_t* profile = get_profile_service();
return profile->is_playing(addr);
}
profile_connection_state_t BTSYMBOLS(bt_a2dp_source_get_connection_state)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_source_interface_t* profile = get_profile_service();
return profile->get_connection_state(addr);
}
bt_status_t BTSYMBOLS(bt_a2dp_source_connect)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_source_interface_t* profile = get_profile_service();
return profile->connect(addr);
}
bt_status_t BTSYMBOLS(bt_a2dp_source_disconnect)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_source_interface_t* profile = get_profile_service();
return profile->disconnect(addr);
}
bt_status_t BTSYMBOLS(bt_a2dp_source_set_silence_device)(bt_instance_t* ins, bt_address_t* addr, bool silence)
{
a2dp_source_interface_t* profile = get_profile_service();
return profile->set_silence_device(addr, silence);
}
bt_status_t BTSYMBOLS(bt_a2dp_source_set_active_device)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_source_interface_t* profile = get_profile_service();
return profile->set_active_device(addr);
}

252
framework/api/bt_adapter.c Normal file
View File

@ -0,0 +1,252 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "adapter_internel.h"
#include "bt_adapter.h"
#include "bt_internal.h"
void* BTSYMBOLS(bt_adapter_register_callback)(bt_instance_t* ins, const adapter_callbacks_t* adapter_cbs)
{
return adapter_register_callback(NULL, adapter_cbs);
}
bool BTSYMBOLS(bt_adapter_unregister_callback)(bt_instance_t* ins, void* cookie)
{
return adapter_unregister_callback(NULL, cookie);
}
bt_status_t BTSYMBOLS(bt_adapter_enable)(bt_instance_t* ins)
{
return adapter_enable(SYS_SET_BT_ALL);
}
bt_status_t BTSYMBOLS(bt_adapter_disable)(bt_instance_t* ins)
{
return adapter_disable(SYS_SET_BT_ALL);
}
bt_status_t BTSYMBOLS(bt_adapter_disable_safe)(bt_instance_t* ins)
{
return adapter_disable_safe(SYS_SET_BT_ALL);
}
bt_status_t BTSYMBOLS(bt_adapter_enable_le)(bt_instance_t* ins)
{
return adapter_enable(APP_SET_LE_ONLY);
}
bt_status_t BTSYMBOLS(bt_adapter_disable_le)(bt_instance_t* ins)
{
return adapter_disable(APP_SET_LE_ONLY);
}
bt_adapter_state_t BTSYMBOLS(bt_adapter_get_state)(bt_instance_t* ins)
{
return adapter_get_state();
}
bool BTSYMBOLS(bt_adapter_is_le_enabled)(bt_instance_t* ins)
{
return adapter_is_le_enabled();
}
bt_device_type_t BTSYMBOLS(bt_adapter_get_type)(bt_instance_t* ins)
{
return adapter_get_type();
}
bt_status_t BTSYMBOLS(bt_adapter_set_discovery_filter)(bt_instance_t* ins)
{
return 0;
}
bt_status_t BTSYMBOLS(bt_adapter_start_limited_discovery)(bt_instance_t* ins, uint32_t timeout)
{
return adapter_start_discovery(timeout, true);
}
bt_status_t BTSYMBOLS(bt_adapter_set_debug_mode)(bt_instance_t* ins, bt_debug_mode_t mode, uint8_t operation)
{
return adapter_set_debug_mode(mode, operation);
}
bt_status_t BTSYMBOLS(bt_adapter_start_discovery)(bt_instance_t* ins, uint32_t timeout)
{
return adapter_start_discovery(timeout, false);
}
bt_status_t BTSYMBOLS(bt_adapter_cancel_discovery)(bt_instance_t* ins)
{
return adapter_cancel_discovery();
}
bool BTSYMBOLS(bt_adapter_is_discovering)(bt_instance_t* ins)
{
return adapter_is_discovering();
}
void BTSYMBOLS(bt_adapter_get_address)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_get_address(addr);
}
bt_status_t BTSYMBOLS(bt_adapter_set_name)(bt_instance_t* ins, const char* name)
{
return adapter_set_name(name);
}
void BTSYMBOLS(bt_adapter_get_name)(bt_instance_t* ins, char* name, int length)
{
return adapter_get_name(name, length);
}
bt_status_t BTSYMBOLS(bt_adapter_get_uuids)(bt_instance_t* ins, bt_uuid_t* uuids, uint16_t* size)
{
return adapter_get_uuids(uuids, size);
}
bt_status_t BTSYMBOLS(bt_adapter_set_scan_mode)(bt_instance_t* ins, bt_scan_mode_t mode, bool bondable)
{
return adapter_set_scan_mode(mode, bondable);
}
bt_scan_mode_t BTSYMBOLS(bt_adapter_get_scan_mode)(bt_instance_t* ins)
{
return adapter_get_scan_mode();
}
bt_status_t BTSYMBOLS(bt_adapter_set_device_class)(bt_instance_t* ins, uint32_t cod)
{
return adapter_set_device_class(cod);
}
uint32_t BTSYMBOLS(bt_adapter_get_device_class)(bt_instance_t* ins)
{
return adapter_get_device_class();
}
bt_status_t BTSYMBOLS(bt_adapter_set_io_capability)(bt_instance_t* ins, bt_io_capability_t cap)
{
return adapter_set_io_capability(cap);
}
bt_io_capability_t BTSYMBOLS(bt_adapter_get_io_capability)(bt_instance_t* ins)
{
return adapter_get_io_capability();
}
bt_status_t BTSYMBOLS(bt_adapter_set_inquiry_scan_parameters)(bt_instance_t* ins, bt_scan_type_t type,
uint16_t interval, uint16_t window)
{
return adapter_set_inquiry_scan_parameters(type, interval, window);
}
bt_status_t BTSYMBOLS(bt_adapter_set_page_scan_parameters)(bt_instance_t* ins, bt_scan_type_t type,
uint16_t interval, uint16_t window)
{
return adapter_set_page_scan_parameters(type, interval, window);
}
bt_status_t BTSYMBOLS(bt_adapter_set_le_io_capability)(bt_instance_t* ins, uint32_t le_io_cap)
{
return adapter_set_le_io_capability(le_io_cap);
}
uint32_t BTSYMBOLS(bt_adapter_get_le_io_capability)(bt_instance_t* ins)
{
return adapter_get_le_io_capability();
}
bt_status_t BTSYMBOLS(bt_adapter_get_le_address)(bt_instance_t* ins, bt_address_t* addr, ble_addr_type_t* type)
{
return adapter_get_le_address(addr, type);
}
bt_status_t BTSYMBOLS(bt_adapter_set_le_address)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_set_le_address(addr);
}
bt_status_t BTSYMBOLS(bt_adapter_set_le_identity_address)(bt_instance_t* ins, bt_address_t* addr, bool is_public)
{
return adapter_set_le_identity_address(addr, is_public);
}
bt_status_t BTSYMBOLS(bt_adapter_set_le_appearance)(bt_instance_t* ins, uint16_t appearance)
{
return adapter_set_le_appearance(appearance);
}
uint16_t BTSYMBOLS(bt_adapter_get_le_appearance)(bt_instance_t* ins)
{
return adapter_get_le_appearance();
}
bt_status_t BTSYMBOLS(bt_adapter_le_enable_key_derivation)(bt_instance_t* ins,
bool brkey_to_lekey,
bool lekey_to_brkey)
{
return adapter_le_enable_key_derivation(brkey_to_lekey, lekey_to_brkey);
}
bt_status_t BTSYMBOLS(bt_adapter_le_add_whitelist)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_le_add_whitelist(addr);
}
bt_status_t BTSYMBOLS(bt_adapter_le_remove_whitelist)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_le_remove_whitelist(addr);
}
bt_status_t BTSYMBOLS(bt_adapter_get_bonded_devices)(bt_instance_t* ins, bt_transport_t transport, bt_address_t** addr, int* num, bt_allocator_t allocator)
{
return adapter_get_bonded_devices(transport, addr, num, allocator);
}
bt_status_t BTSYMBOLS(bt_adapter_get_connected_devices)(bt_instance_t* ins, bt_transport_t transport, bt_address_t** addr, int* num, bt_allocator_t allocator)
{
return adapter_get_connected_devices(transport, addr, num, allocator);
}
bt_status_t BTSYMBOLS(bt_adapter_set_afh_channel_classification)(bt_instance_t* ins, uint16_t central_frequency,
uint16_t band_width, uint16_t number)
{
return adapter_set_afh_channel_classification(central_frequency, band_width, number);
}
void BTSYMBOLS(bt_adapter_disconnect_all_devices)(bt_instance_t* ins)
{
}
bool BTSYMBOLS(bt_adapter_is_support_bredr)(bt_instance_t* ins)
{
return adapter_is_support_bredr();
}
bool BTSYMBOLS(bt_adapter_is_support_le)(bt_instance_t* ins)
{
return adapter_is_support_le();
}
bool BTSYMBOLS(bt_adapter_is_support_leaudio)(bt_instance_t* ins)
{
return adapter_is_support_leaudio();
}

View File

@ -0,0 +1,86 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "avrcp_control_api"
#include <stdint.h>
#include "avrcp_control_service.h"
#include "bt_avrcp_control.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "service_manager.h"
#include "utils/log.h"
static avrcp_control_interface_t* get_profile_service(void)
{
return (avrcp_control_interface_t*)service_manager_get_profile(PROFILE_AVRCP_CT);
}
void* BTSYMBOLS(bt_avrcp_control_register_callbacks)(bt_instance_t* ins, const avrcp_control_callbacks_t* callbacks)
{
avrcp_control_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool BTSYMBOLS(bt_avrcp_control_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
avrcp_control_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t BTSYMBOLS(bt_avrcp_control_get_element_attributes)(bt_instance_t* ins, bt_address_t* addr)
{
avrcp_control_interface_t* profile = get_profile_service();
return profile->avrcp_control_get_element_attributes(addr);
}
bt_status_t BTSYMBOLS(bt_avrcp_control_send_passthrough_cmd)(bt_instance_t* ins, bt_address_t* addr, uint8_t cmd, uint8_t state)
{
avrcp_control_interface_t* profile = get_profile_service();
return profile->avrcp_control_send_passthrough_cmd(addr, cmd, state);
}
bt_status_t BTSYMBOLS(bt_avrcp_control_get_unit_info)(bt_instance_t* ins, bt_address_t* addr)
{
avrcp_control_interface_t* profile = get_profile_service();
return profile->avrcp_control_get_unit_info(addr);
}
bt_status_t BTSYMBOLS(bt_avrcp_control_get_subunit_info)(bt_instance_t* ins, bt_address_t* addr)
{
avrcp_control_interface_t* profile = get_profile_service();
return profile->avrcp_control_get_subunit_info(addr);
}
bt_status_t BTSYMBOLS(bt_avrcp_control_get_playback_state)(bt_instance_t* ins, bt_address_t* addr)
{
avrcp_control_interface_t* profile = get_profile_service();
return profile->avrcp_control_get_playback_state(addr);
}
bt_status_t BTSYMBOLS(bt_avrcp_control_register_notification)(bt_instance_t* ins, bt_address_t* addr, uint8_t event, uint32_t interval)
{
avrcp_control_interface_t* profile = get_profile_service();
return profile->avrcp_control_register_notification(addr, event, interval);
}

View File

@ -0,0 +1,59 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "avrcp_target_api"
#include <stdint.h>
#include "avrcp_target_service.h"
#include "bt_avrcp_target.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "service_manager.h"
#include "utils/log.h"
static avrcp_target_interface_t* get_profile_service(void)
{
return (avrcp_target_interface_t*)service_manager_get_profile(PROFILE_AVRCP_TG);
}
void* BTSYMBOLS(bt_avrcp_target_register_callbacks)(bt_instance_t* ins, const avrcp_target_callbacks_t* callbacks)
{
avrcp_target_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool BTSYMBOLS(bt_avrcp_target_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
avrcp_target_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t BTSYMBOLS(bt_avrcp_target_get_play_status_response)(bt_instance_t* ins, bt_address_t* addr, avrcp_play_status_t play_status,
uint32_t song_len, uint32_t song_pos)
{
avrcp_target_interface_t* profile = get_profile_service();
return profile->get_play_status_rsp(addr, play_status, song_len, song_pos);
}
bt_status_t BTSYMBOLS(bt_avrcp_target_play_status_notify)(bt_instance_t* ins, bt_address_t* addr, avrcp_play_status_t play_status)
{
avrcp_target_interface_t* profile = get_profile_service();
return profile->play_status_notify(addr, play_status);
}

240
framework/api/bt_device.c Normal file
View File

@ -0,0 +1,240 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include <stdlib.h>
#include "adapter_internel.h"
#include "bluetooth.h"
#include "bt_addr.h"
#include "bt_device.h"
#include "bt_internal.h"
#include "connection_manager.h"
#include "device.h"
bt_status_t BTSYMBOLS(bt_device_get_identity_address)(bt_instance_t* ins, bt_address_t* bd_addr, bt_address_t* id_addr)
{
return adapter_get_remote_identity_address(bd_addr, id_addr);
}
ble_addr_type_t BTSYMBOLS(bt_device_get_address_type)(bt_instance_t* ins, bt_address_t* addr)
{
return 0;
}
bt_device_type_t BTSYMBOLS(bt_device_get_device_type)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_get_remote_device_type(addr);
}
bool BTSYMBOLS(bt_device_get_name)(bt_instance_t* ins, bt_address_t* addr, char* name, uint32_t length)
{
return adapter_get_remote_name(addr, name);
}
uint32_t BTSYMBOLS(bt_device_get_device_class)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_get_remote_device_class(addr);
}
bt_status_t BTSYMBOLS(bt_device_get_uuids)(bt_instance_t* ins, bt_address_t* addr, bt_uuid_t** uuids, uint16_t* size, bt_allocator_t allocator)
{
return adapter_get_remote_uuids(addr, uuids, size, allocator);
}
uint16_t BTSYMBOLS(bt_device_get_appearance)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_get_remote_appearance(addr);
}
int8_t BTSYMBOLS(bt_device_get_rssi)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_get_remote_rssi(addr);
}
bool BTSYMBOLS(bt_device_get_alias)(bt_instance_t* ins, bt_address_t* addr, char* alias, uint32_t length)
{
return adapter_get_remote_alias(addr, alias);
}
bt_status_t BTSYMBOLS(bt_device_set_alias)(bt_instance_t* ins, bt_address_t* addr, const char* alias)
{
return adapter_set_remote_alias(addr, alias);
}
bool BTSYMBOLS(bt_device_is_connected)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
return adapter_is_remote_connected(addr, transport);
}
bool BTSYMBOLS(bt_device_is_encrypted)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
return adapter_is_remote_encrypted(addr, transport);
}
bool BTSYMBOLS(bt_device_is_bond_initiate_local)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
return adapter_is_bond_initiate_local(addr, transport);
}
bond_state_t BTSYMBOLS(bt_device_get_bond_state)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
return adapter_get_remote_bond_state(addr, transport);
}
bool BTSYMBOLS(bt_device_is_bonded)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
return adapter_is_remote_bonded(addr, transport);
}
bt_status_t BTSYMBOLS(bt_device_connect)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_connect(addr);
}
bt_status_t BTSYMBOLS(bt_device_disconnect)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_disconnect(addr);
}
bt_status_t BTSYMBOLS(bt_device_background_connect)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
#ifdef CONFIG_BLUETOOTH_CONNECTION_MANAGER
return bt_cm_device_connect(addr, transport);
#else
return BT_STATUS_UNSUPPORTED;
#endif
}
bt_status_t BTSYMBOLS(bt_device_background_disconnect)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
#ifdef CONFIG_BLUETOOTH_CONNECTION_MANAGER
return bt_cm_device_disconnect(addr, transport);
#else
return BT_STATUS_UNSUPPORTED;
#endif
}
bt_status_t BTSYMBOLS(bt_device_connect_le)(bt_instance_t* ins,
bt_address_t* addr,
ble_addr_type_t type,
ble_connect_params_t* param)
{
return adapter_le_connect(addr, type, param);
}
bt_status_t BTSYMBOLS(bt_device_disconnect_le)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_le_disconnect(addr);
}
bt_status_t BTSYMBOLS(bt_device_connect_request_reply)(bt_instance_t* ins, bt_address_t* addr, bool accept)
{
return adapter_connect_request_reply(addr, accept);
}
void BTSYMBOLS(bt_device_connect_all_profile)(bt_instance_t* ins, bt_address_t* addr)
{
}
void BTSYMBOLS(bt_device_disconnect_all_profile)(bt_instance_t* ins, bt_address_t* addr)
{
}
bt_status_t BTSYMBOLS(bt_device_set_le_phy)(bt_instance_t* ins, bt_address_t* addr,
ble_phy_type_t tx_phy,
ble_phy_type_t rx_phy)
{
return adapter_le_set_phy(addr, tx_phy, rx_phy);
}
bt_status_t BTSYMBOLS(bt_device_create_bond)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
return adapter_create_bond(addr, transport);
}
bt_status_t BTSYMBOLS(bt_device_set_security_level)(bt_instance_t* ins, uint8_t level, bt_transport_t transport)
{
return adapter_set_security_level(level, transport);
}
bt_status_t BTSYMBOLS(bt_device_set_bondable_le)(bt_instance_t* ins, bool bondable)
{
return adapter_le_set_bondable(bondable);
}
bt_status_t BTSYMBOLS(bt_device_remove_bond)(bt_instance_t* ins, bt_address_t* addr, uint8_t transport)
{
return adapter_remove_bond(addr, transport);
}
bt_status_t BTSYMBOLS(bt_device_cancel_bond)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_cancel_bond(addr);
}
bt_status_t BTSYMBOLS(bt_device_pair_request_reply)(bt_instance_t* ins, bt_address_t* addr, bool accept)
{
return adapter_pair_request_reply(addr, accept);
}
bt_status_t BTSYMBOLS(bt_device_set_pairing_confirmation)(bt_instance_t* ins, bt_address_t* addr, uint8_t transport, bool accept)
{
return adapter_set_pairing_confirmation(addr, transport, accept);
}
bt_status_t BTSYMBOLS(bt_device_set_pin_code)(bt_instance_t* ins, bt_address_t* addr, bool accept,
char* pincode, int len)
{
return adapter_set_pin_code(addr, accept, pincode, len);
}
bt_status_t BTSYMBOLS(bt_device_set_pass_key)(bt_instance_t* ins, bt_address_t* addr, uint8_t transport, bool accept, uint32_t passkey)
{
return adapter_set_pass_key(addr, transport, accept, passkey);
}
bt_status_t BTSYMBOLS(bt_device_set_le_legacy_tk)(bt_instance_t* ins, bt_address_t* addr, bt_128key_t tk_val)
{
return adapter_le_set_legacy_tk(addr, tk_val);
}
bt_status_t BTSYMBOLS(bt_device_set_le_sc_remote_oob_data)(bt_instance_t* ins, bt_address_t* addr, bt_128key_t c_val, bt_128key_t r_val)
{
return adapter_le_set_remote_oob_data(addr, c_val, r_val);
}
bt_status_t BTSYMBOLS(bt_device_get_le_sc_local_oob_data)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_le_get_local_oob_data(addr);
}
bt_status_t BTSYMBOLS(bt_device_enable_enhanced_mode)(bt_instance_t* ins, bt_address_t* addr, bt_enhanced_mode_t mode)
{
#ifdef CONFIG_BLUETOOTH_CONNECTION_MANAGER
return bt_cm_enable_enhanced_mode(addr, mode);
#else
return BT_STATUS_UNSUPPORTED;
#endif
}
bt_status_t BTSYMBOLS(bt_device_disable_enhanced_mode)(bt_instance_t* ins, bt_address_t* addr, bt_enhanced_mode_t mode)
{
#ifdef CONFIG_BLUETOOTH_CONNECTION_MANAGER
return bt_cm_disable_enhanced_mode(addr, mode);
#else
return BT_STATUS_UNSUPPORTED;
#endif
}

157
framework/api/bt_gattc.c Normal file
View File

@ -0,0 +1,157 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "gattc"
#include "bt_gattc.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "gattc_service.h"
#include "service_manager.h"
#include "utils/log.h"
#include <stdint.h>
static gattc_interface_t* get_profile_service(void)
{
return (gattc_interface_t*)service_manager_get_profile(PROFILE_GATTC);
}
bt_status_t BTSYMBOLS(bt_gattc_create_connect)(bt_instance_t* ins, gattc_handle_t* phandle, gattc_callbacks_t* callbacks)
{
gattc_interface_t* profile = get_profile_service();
return profile->create_connect(NULL, phandle, callbacks);
}
bt_status_t BTSYMBOLS(bt_gattc_delete_connect)(gattc_handle_t conn_handle)
{
gattc_interface_t* profile = get_profile_service();
return profile->delete_connect(conn_handle);
}
bt_status_t BTSYMBOLS(bt_gattc_connect)(gattc_handle_t conn_handle, bt_address_t* addr, ble_addr_type_t addr_type)
{
gattc_interface_t* profile = get_profile_service();
return profile->connect(conn_handle, addr, addr_type);
}
bt_status_t BTSYMBOLS(bt_gattc_disconnect)(gattc_handle_t conn_handle)
{
gattc_interface_t* profile = get_profile_service();
return profile->disconnect(conn_handle);
}
bt_status_t BTSYMBOLS(bt_gattc_discover_service)(gattc_handle_t conn_handle, bt_uuid_t* filter_uuid)
{
gattc_interface_t* profile = get_profile_service();
return profile->discover_service(conn_handle, filter_uuid);
}
bt_status_t BTSYMBOLS(bt_gattc_get_attribute_by_handle)(gattc_handle_t conn_handle, uint16_t attr_handle, gatt_attr_desc_t* attr_desc)
{
gattc_interface_t* profile = get_profile_service();
return profile->get_attribute_by_handle(conn_handle, attr_handle, attr_desc);
}
bt_status_t BTSYMBOLS(bt_gattc_get_attribute_by_uuid)(gattc_handle_t conn_handle, uint16_t start_handle, uint16_t end_handle, bt_uuid_t* attr_uuid, gatt_attr_desc_t* attr_desc)
{
gattc_interface_t* profile = get_profile_service();
return profile->get_attribute_by_uuid(conn_handle, start_handle, end_handle, attr_uuid, attr_desc);
}
bt_status_t BTSYMBOLS(bt_gattc_read)(gattc_handle_t conn_handle, uint16_t attr_handle)
{
gattc_interface_t* profile = get_profile_service();
return profile->read(conn_handle, attr_handle);
}
bt_status_t BTSYMBOLS(bt_gattc_write)(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
gattc_interface_t* profile = get_profile_service();
return profile->write(conn_handle, attr_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gattc_write_without_response)(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
gattc_interface_t* profile = get_profile_service();
return profile->write_without_response(conn_handle, attr_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gattc_write_with_signed)(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
gattc_interface_t* profile = get_profile_service();
return profile->write_signed(conn_handle, attr_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gattc_subscribe)(gattc_handle_t conn_handle, uint16_t attr_handle, uint16_t ccc_value)
{
gattc_interface_t* profile = get_profile_service();
return profile->subscribe(conn_handle, attr_handle, ccc_value);
}
bt_status_t BTSYMBOLS(bt_gattc_unsubscribe)(gattc_handle_t conn_handle, uint16_t attr_handle)
{
gattc_interface_t* profile = get_profile_service();
return profile->unsubscribe(conn_handle, attr_handle);
}
bt_status_t BTSYMBOLS(bt_gattc_exchange_mtu)(gattc_handle_t conn_handle, uint32_t mtu)
{
gattc_interface_t* profile = get_profile_service();
return profile->exchange_mtu(conn_handle, mtu);
}
bt_status_t BTSYMBOLS(bt_gattc_update_connection_parameter)(gattc_handle_t conn_handle, uint32_t min_interval, uint32_t max_interval, uint32_t latency,
uint32_t timeout, uint32_t min_connection_event_length, uint32_t max_connection_event_length)
{
gattc_interface_t* profile = get_profile_service();
return profile->update_connection_parameter(conn_handle, min_interval, max_interval, latency,
timeout, min_connection_event_length, max_connection_event_length);
}
bt_status_t BTSYMBOLS(bt_gattc_read_phy)(gattc_handle_t conn_handle)
{
gattc_interface_t* profile = get_profile_service();
return profile->read_phy(conn_handle);
}
bt_status_t BTSYMBOLS(bt_gattc_update_phy)(gattc_handle_t conn_handle, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy)
{
gattc_interface_t* profile = get_profile_service();
return profile->update_phy(conn_handle, tx_phy, rx_phy);
}
bt_status_t BTSYMBOLS(bt_gattc_read_rssi)(gattc_handle_t conn_handle)
{
gattc_interface_t* profile = get_profile_service();
return profile->read_rssi(conn_handle);
}

127
framework/api/bt_gatts.c Normal file
View File

@ -0,0 +1,127 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "gatts"
#include "bt_gatts.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "gatts_service.h"
#include "service_manager.h"
#include "utils/log.h"
#include <stdint.h>
static gatts_interface_t* get_profile_service(void)
{
return (gatts_interface_t*)service_manager_get_profile(PROFILE_GATTS);
}
bt_status_t BTSYMBOLS(bt_gatts_register_service)(bt_instance_t* ins, gatts_handle_t* phandle, gatts_callbacks_t* callbacks)
{
gatts_interface_t* profile = get_profile_service();
return profile->register_service(NULL, phandle, callbacks);
}
bt_status_t BTSYMBOLS(bt_gatts_unregister_service)(gatts_handle_t srv_handle)
{
gatts_interface_t* profile = get_profile_service();
return profile->unregister_service(srv_handle);
}
bt_status_t BTSYMBOLS(bt_gatts_connect)(gatts_handle_t srv_handle, bt_address_t* addr, ble_addr_type_t addr_type)
{
gatts_interface_t* profile = get_profile_service();
return profile->connect(srv_handle, addr, addr_type);
}
bt_status_t BTSYMBOLS(bt_gatts_connect_bear)(gatts_handle_t srv_handle, bt_address_t* addr, ble_addr_type_t addr_type, uint8_t bear_type)
{
gatts_interface_t* profile = get_profile_service();
return profile->connect_bear(srv_handle, addr, addr_type, bear_type);
}
bt_status_t BTSYMBOLS(bt_gatts_disconnect)(gatts_handle_t srv_handle, bt_address_t* addr)
{
gatts_interface_t* profile = get_profile_service();
return profile->disconnect(srv_handle, addr);
}
bt_status_t BTSYMBOLS(bt_gatts_add_attr_table)(gatts_handle_t srv_handle, gatt_srv_db_t* srv_db)
{
gatts_interface_t* profile = get_profile_service();
return profile->add_attr_table(srv_handle, srv_db);
}
bt_status_t BTSYMBOLS(bt_gatts_remove_attr_table)(gatts_handle_t srv_handle, uint16_t attr_handle)
{
gatts_interface_t* profile = get_profile_service();
return profile->remove_attr_table(srv_handle, attr_handle);
}
bt_status_t BTSYMBOLS(bt_gatts_set_attr_value)(gatts_handle_t srv_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
gatts_interface_t* profile = get_profile_service();
return profile->set_attr_value(srv_handle, attr_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gatts_get_attr_value)(gatts_handle_t srv_handle, uint16_t attr_handle, uint8_t* value, uint16_t* length)
{
gatts_interface_t* profile = get_profile_service();
return profile->get_attr_value(srv_handle, attr_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gatts_response)(gatts_handle_t srv_handle, bt_address_t* addr, uint32_t req_handle, uint8_t* value, uint16_t length)
{
gatts_interface_t* profile = get_profile_service();
return profile->response(srv_handle, addr, req_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gatts_notify)(gatts_handle_t srv_handle, bt_address_t* addr, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
gatts_interface_t* profile = get_profile_service();
return profile->notify(srv_handle, addr, attr_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gatts_indicate)(gatts_handle_t srv_handle, bt_address_t* addr, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
gatts_interface_t* profile = get_profile_service();
return profile->indicate(srv_handle, addr, attr_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gatts_read_phy)(gatts_handle_t srv_handle, bt_address_t* addr)
{
gatts_interface_t* profile = get_profile_service();
return profile->read_phy(srv_handle, addr);
}
bt_status_t BTSYMBOLS(bt_gatts_update_phy)(gatts_handle_t srv_handle, bt_address_t* addr, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy)
{
gatts_interface_t* profile = get_profile_service();
return profile->update_phy(srv_handle, addr, tx_phy, rx_phy);
}

178
framework/api/bt_hfp_ag.c Normal file
View File

@ -0,0 +1,178 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "hfp_ag_api"
#include "bt_hfp_ag.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "hfp_ag_service.h"
#include "service_manager.h"
#include "utils/log.h"
#include <stdint.h>
static hfp_ag_interface_t* get_profile_service(void)
{
return (hfp_ag_interface_t*)service_manager_get_profile(PROFILE_HFP_AG);
}
void* BTSYMBOLS(bt_hfp_ag_register_callbacks)(bt_instance_t* ins, const hfp_ag_callbacks_t* callbacks)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool BTSYMBOLS(bt_hfp_ag_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bool BTSYMBOLS(bt_hfp_ag_is_connected)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->is_connected(addr);
}
bool BTSYMBOLS(bt_hfp_ag_is_audio_connected)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->is_audio_connected(addr);
}
profile_connection_state_t BTSYMBOLS(bt_hfp_ag_get_connection_state)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->get_connection_state(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_connect)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->connect(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_disconnect)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->disconnect(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_connect_audio)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->connect_audio(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_disconnect_audio)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->disconnect_audio(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_start_virtual_call)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->start_virtual_call(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_stop_virtual_call)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->stop_virtual_call(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_start_voice_recognition)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->start_voice_recognition(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_stop_voice_recognition)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->stop_voice_recognition(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_phone_state_change)(bt_instance_t* ins, bt_address_t* addr,
uint8_t num_active, uint8_t num_held,
hfp_ag_call_state_t call_state, hfp_call_addrtype_t type,
const char* number, const char* name)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->phone_state_change(addr, num_active, num_held, call_state, type, number, name);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_notify_device_status)(bt_instance_t* ins, bt_address_t* addr,
hfp_network_state_t network, hfp_roaming_state_t roam,
uint8_t signal, uint8_t battery)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->device_status_changed(addr, network, roam, signal, battery);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_volume_control)(bt_instance_t* ins, bt_address_t* addr, hfp_volume_type_t type, uint8_t volume)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->volume_control(addr, type, volume);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_send_at_command)(bt_instance_t* ins, bt_address_t* addr, const char* at_command)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->send_at_command(addr, at_command);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_send_vendor_specific_at_command)(bt_instance_t* ins, bt_address_t* addr, const char* command, const char* value)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->send_vendor_specific_at_command(addr, command, value);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_send_clcc_response)(bt_instance_t* ins, bt_address_t* addr,
uint32_t index, hfp_call_direction_t dir, hfp_ag_call_state_t call, hfp_call_mode_t mode,
hfp_call_mpty_type_t mpty, hfp_call_addrtype_t type, const char* number)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->send_clcc_response(addr, index, dir, call, mode, mpty, type, number);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_send_cind_response)(bt_instance_t* ins, bt_address_t* addr,
hfp_network_state_t network, hfp_call_t call, hfp_callheld_t call_held, hfp_callsetup_t call_setup,
uint8_t signal, hfp_roaming_state_t roam, uint8_t battery)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->send_cind_response(addr, network, call, call_held, call_setup, signal, roam, battery);
}

212
framework/api/bt_hfp_hf.c Normal file
View File

@ -0,0 +1,212 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "hfp_hf_api"
#include "bt_hfp_hf.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "hfp_hf_service.h"
#include "service_manager.h"
#include "utils/log.h"
#include <stdint.h>
static hfp_hf_interface_t* get_profile_service(void)
{
return (hfp_hf_interface_t*)service_manager_get_profile(PROFILE_HFP_HF);
}
void* BTSYMBOLS(bt_hfp_hf_register_callbacks)(bt_instance_t* ins, const hfp_hf_callbacks_t* callbacks)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, (hfp_hf_callbacks_t*)callbacks);
}
bool BTSYMBOLS(bt_hfp_hf_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bool BTSYMBOLS(bt_hfp_hf_is_connected)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->is_connected(addr);
}
bool BTSYMBOLS(bt_hfp_hf_is_audio_connected)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->is_audio_connected(addr);
}
profile_connection_state_t BTSYMBOLS(bt_hfp_hf_get_connection_state)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->get_connection_state(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_connect)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->connect(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_disconnect)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->disconnect(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_set_connection_policy)(bt_instance_t* ins, bt_address_t* addr, connection_policy_t policy)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->set_connection_policy(addr, policy);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_connect_audio)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->connect_audio(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_disconnect_audio)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->disconnect_audio(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_start_voice_recognition)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->start_voice_recognition(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_stop_voice_recognition)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->stop_voice_recognition(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_dial)(bt_instance_t* ins, bt_address_t* addr, const char* number)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->dial(addr, number);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_dial_memory)(bt_instance_t* ins, bt_address_t* addr, uint32_t memory)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->dial_memory(addr, memory);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_redial)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->redial(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_accept_call)(bt_instance_t* ins, bt_address_t* addr, hfp_call_accept_t flag)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->accept_call(addr, flag);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_reject_call)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->reject_call(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_hold_call)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->hold_call(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_terminate_call)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->terminate_call(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_control_call)(bt_instance_t* ins, bt_address_t* addr, hfp_call_control_t chld, uint8_t index)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->control_call(addr, chld, index);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_query_current_calls)(bt_instance_t* ins, bt_address_t* addr, hfp_current_call_t** calls, int* num, bt_allocator_t allocator)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->query_current_calls(addr, calls, num, allocator);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_send_at_cmd)(bt_instance_t* ins, bt_address_t* addr, const char* cmd)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->send_at_cmd(addr, cmd);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_update_battery_level)(bt_instance_t* ins, bt_address_t* addr, uint8_t level)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->update_battery_level(addr, level);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_volume_control)(bt_instance_t* ins, bt_address_t* addr, hfp_volume_type_t type, uint8_t volume)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->volume_control(addr, type, volume);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_send_dtmf)(bt_instance_t* ins, bt_address_t* addr, char dtmf)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->send_dtmf(addr, dtmf);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_get_subscriber_number)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->get_subscriber_number(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_query_current_calls_with_callback)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->query_current_calls_with_callback(addr);
}

View File

@ -0,0 +1,100 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "hid_device_api"
#include <stdint.h>
#include "bt_hid_device.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "hid_device_service.h"
#include "service_manager.h"
#include "utils/log.h"
static hid_device_interface_t* get_profile_service(void)
{
return (hid_device_interface_t*)service_manager_get_profile(PROFILE_HID_DEV);
}
void* BTSYMBOLS(bt_hid_device_register_callbacks)(bt_instance_t* ins, const hid_device_callbacks_t* callbacks)
{
hid_device_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool BTSYMBOLS(bt_hid_device_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
hid_device_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t BTSYMBOLS(bt_hid_device_register_app)(bt_instance_t* ins, hid_device_sdp_settings_t* sdp, bool le_hid)
{
hid_device_interface_t* profile = get_profile_service();
return profile->register_app(sdp, le_hid);
}
bt_status_t BTSYMBOLS(bt_hid_device_unregister_app)(bt_instance_t* ins)
{
hid_device_interface_t* profile = get_profile_service();
return profile->unregister_app();
}
bt_status_t BTSYMBOLS(bt_hid_device_connect)(bt_instance_t* ins, bt_address_t* addr)
{
hid_device_interface_t* profile = get_profile_service();
return profile->connect(addr);
}
bt_status_t BTSYMBOLS(bt_hid_device_disconnect)(bt_instance_t* ins, bt_address_t* addr)
{
hid_device_interface_t* profile = get_profile_service();
return profile->disconnect(addr);
}
bt_status_t BTSYMBOLS(bt_hid_device_send_report)(bt_instance_t* ins, bt_address_t* addr, uint8_t rpt_id, uint8_t* rpt_data, int rpt_size)
{
hid_device_interface_t* profile = get_profile_service();
return profile->send_report(addr, rpt_id, rpt_data, rpt_size);
}
bt_status_t BTSYMBOLS(bt_hid_device_response_report)(bt_instance_t* ins, bt_address_t* addr, uint8_t rpt_type, uint8_t* rpt_data, int rpt_size)
{
hid_device_interface_t* profile = get_profile_service();
return profile->response_report(addr, rpt_type, rpt_data, rpt_size);
}
bt_status_t BTSYMBOLS(bt_hid_device_report_error)(bt_instance_t* ins, bt_address_t* addr, hid_status_error_t error)
{
hid_device_interface_t* profile = get_profile_service();
return profile->report_error(addr, error);
}
bt_status_t BTSYMBOLS(bt_hid_device_virtual_unplug)(bt_instance_t* ins, bt_address_t* addr)
{
hid_device_interface_t* profile = get_profile_service();
return profile->virtual_unplug(addr);
}

58
framework/api/bt_l2cap.c Normal file
View File

@ -0,0 +1,58 @@
/****************************************************************************
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "L2CAP_api"
#include <stdint.h>
#include "bt_internal.h"
#include "bt_l2cap.h"
#include "l2cap_service.h"
#include "utils/log.h"
void* BTSYMBOLS(bt_l2cap_register_callbacks)(bt_instance_t* ins, const l2cap_callbacks_t* callbacks)
{
return l2cap_register_callbacks(ins, callbacks);
}
bool BTSYMBOLS(bt_l2cap_unregister_callbacks)(bt_instance_t* ins, void* handle)
{
return l2cap_unregister_callbacks(NULL, handle);
}
bt_status_t BTSYMBOLS(bt_l2cap_listen)(bt_instance_t* ins, void* handle, l2cap_config_option_t* option)
{
return l2cap_listen_channel(handle, option);
}
bt_status_t BTSYMBOLS(bt_l2cap_connect)(bt_instance_t* ins, void* handel, bt_address_t* addr, l2cap_config_option_t* option)
{
return l2cap_connect_channel(handel, addr, option);
}
bt_status_t BTSYMBOLS(bt_l2cap_disconnect)(bt_instance_t* ins, void* handle, uint16_t id)
{
return l2cap_disconnect_channel(handle, id);
}
bt_status_t BTSYMBOLS(bt_l2cap_stop_listen)(bt_instance_t* ins, void* handle, uint16_t psm)
{
return l2cap_stop_listen_channel(handle, BT_TRANSPORT_BLE, psm);
}
bt_status_t BTSYMBOLS(bt_l2cap_stop_listen_with_transport)(bt_instance_t* ins, void* handle, bt_transport_t transport, uint16_t psm)
{
return l2cap_stop_listen_channel(handle, transport, psm);
}

View File

@ -0,0 +1,52 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "adv"
#include <stdlib.h>
#include "advertising.h"
#include "bluetooth.h"
#include "bt_internal.h"
#include "bt_le_advertiser.h"
#include "bt_list.h"
#include "utils/log.h"
bt_advertiser_t* BTSYMBOLS(bt_le_start_advertising)(bt_instance_t* ins,
ble_adv_params_t* params,
uint8_t* adv_data,
uint16_t adv_len,
uint8_t* scan_rsp_data,
uint16_t scan_rsp_len,
advertiser_callback_t* cbs)
{
return start_advertising(NULL, params, adv_data, adv_len,
scan_rsp_data, scan_rsp_len, cbs);
}
void BTSYMBOLS(bt_le_stop_advertising)(bt_instance_t* ins, bt_advertiser_t* adver)
{
stop_advertising(adver);
}
void BTSYMBOLS(bt_le_stop_advertising_id)(bt_instance_t* ins, uint8_t adv_id)
{
stop_advertising_id(adv_id);
}
bool BTSYMBOLS(bt_le_advertising_is_supported)(bt_instance_t* ins)
{
return advertising_is_supported();
}

View File

@ -0,0 +1,55 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "scan"
#include <stdlib.h>
#include "bluetooth.h"
#include "bt_internal.h"
#include "bt_le_scan.h"
#include "bt_list.h"
#include "scan_manager.h"
#include "utils/log.h"
bt_scanner_t* BTSYMBOLS(bt_le_start_scan)(bt_instance_t* ins, const scanner_callbacks_t* cbs)
{
return scanner_start_scan(NULL, cbs);
}
bt_scanner_t* BTSYMBOLS(bt_le_start_scan_settings)(bt_instance_t* ins,
ble_scan_settings_t* settings,
const scanner_callbacks_t* cbs)
{
return scanner_start_scan_settings(NULL, settings, cbs);
}
bt_scanner_t* BTSYMBOLS(bt_le_start_scan_with_filters)(bt_instance_t* ins,
ble_scan_settings_t* settings,
ble_scan_filter_t* filter,
const scanner_callbacks_t* cbs)
{
return scanner_start_scan_with_filters(NULL, settings, filter, cbs);
}
void BTSYMBOLS(bt_le_stop_scan)(bt_instance_t* ins, bt_scanner_t* scanner)
{
scanner_stop_scan(scanner);
}
bool BTSYMBOLS(bt_le_scan_is_supported)(bt_instance_t* ins)
{
return scan_is_supported();
}

160
framework/api/bt_lea_ccp.c Normal file
View File

@ -0,0 +1,160 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include "bt_lea_ccp.h"
#include "bt_profile.h"
#include "lea_ccp_service.h"
#include "service_manager.h"
#include "utils/log.h"
#include <stdint.h>
static lea_ccp_interface_t* get_profile_service(void)
{
return (lea_ccp_interface_t*)service_manager_get_profile(PROFILE_LEAUDIO_CCP);
}
void* bt_lea_ccp_register_callbacks(bt_instance_t* ins, const lea_ccp_callbacks_t* callbacks)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, (lea_ccp_callbacks_t*)callbacks);
}
bool bt_lea_ccp_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t bt_lea_ccp_read_bearer_provider_name(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_bearer_provider_name(addr);
}
bt_status_t bt_lea_ccp_read_bearer_uci(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_bearer_uci(addr);
}
bt_status_t bt_lea_ccp_read_bearer_technology(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_bearer_technology(addr);
}
bt_status_t bt_lea_ccp_read_bearer_uri_schemes_supported_list(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_bearer_uri_schemes_supported_list(addr);
}
bt_status_t bt_lea_ccp_read_bearer_signal_strength(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_bearer_signal_strength(addr);
}
bt_status_t bt_lea_ccp_read_bearer_signal_strength_report_interval(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_bearer_signal_strength_report_interval(addr);
}
bt_status_t bt_lea_ccp_read_content_control_id(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_content_control_id(addr);
}
bt_status_t bt_lea_ccp_read_status_flags(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_status_flags(addr);
}
bt_status_t bt_lea_ccp_read_call_control_optional_opcodes(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_call_control_optional_opcodes(addr);
}
bt_status_t bt_lea_ccp_read_incoming_call(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_incoming_call(addr);
}
bt_status_t bt_lea_ccp_read_incoming_call_target_bearer_uri(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_incoming_call_target_bearer_uri(addr);
}
bt_status_t bt_lea_ccp_read_call_state(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_call_state(addr);
}
bt_status_t bt_lea_ccp_read_bearer_list_current_calls(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_bearer_list_current_calls(addr);
}
bt_status_t bt_lea_ccp_read_call_friendly_name(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_call_friendly_name(addr);
}
bt_status_t bt_lea_ccp_call_control_by_index(bt_instance_t* ins, bt_address_t* addr, uint8_t opcode)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->call_control_by_index(addr, opcode);
}
bt_status_t bt_lea_ccp_originate_call(bt_instance_t* ins, bt_address_t* addr, uint8_t* uri)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->originate_call(addr, uri);
}
bt_status_t bt_lea_ccp_join_calls(bt_instance_t* ins, bt_address_t* addr, uint8_t number,
uint8_t* call_indexes)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->join_calls(addr, number, call_indexes);
}

View File

@ -0,0 +1,141 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include "bt_lea_server.h"
#include "bt_profile.h"
#include "lea_client_service.h"
#include "service_manager.h"
static lea_client_interface_t* get_profile_service(void)
{
return (lea_client_interface_t*)service_manager_get_profile(
PROFILE_LEAUDIO_CLIENT);
}
void* bt_lea_client_register_callbacks(bt_instance_t* ins,
const lea_client_callbacks_t* callbacks)
{
lea_client_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool bt_lea_client_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
lea_client_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t bt_lea_client_connect(bt_instance_t* ins, bt_address_t* addr)
{
lea_client_interface_t* profile = get_profile_service();
return profile->connect(addr);
}
bt_status_t bt_lea_client_connect_audio(bt_instance_t* ins, bt_address_t* addr, uint8_t context)
{
lea_client_interface_t* profile = get_profile_service();
return profile->connect_audio(addr, context);
}
bt_status_t bt_lea_client_disconnect(bt_instance_t* ins, bt_address_t* addr)
{
lea_client_interface_t* profile = get_profile_service();
return profile->disconnect(addr);
}
bt_status_t bt_lea_client_disconnect_audio(bt_instance_t* ins, bt_address_t* addr)
{
lea_client_interface_t* profile = get_profile_service();
return profile->disconnect_audio(addr);
}
profile_connection_state_t bt_lea_client_get_connection_state(bt_instance_t* ins, bt_address_t* addr)
{
lea_client_interface_t* profile = get_profile_service();
return profile->get_connection_state(addr);
}
bt_status_t bt_lea_client_get_group_id(bt_instance_t* ins, bt_address_t* addr, uint32_t* group_id)
{
lea_client_interface_t* profile = get_profile_service();
return profile->get_group_id(addr, group_id);
}
bt_status_t bt_lea_client_discovery_member_start(bt_instance_t* ins, uint32_t group_id)
{
lea_client_interface_t* profile = get_profile_service();
return profile->discovery_member_start(group_id);
}
bt_status_t bt_lea_client_discovery_member_stop(bt_instance_t* ins, uint32_t group_id)
{
lea_client_interface_t* profile = get_profile_service();
return profile->discovery_member_stop(group_id);
}
bt_status_t bt_lea_client_group_add_member(bt_instance_t* ins, uint32_t group_id, bt_address_t* addr)
{
lea_client_interface_t* profile = get_profile_service();
return profile->group_add_member(group_id, addr);
}
bt_status_t bt_lea_client_group_remove_member(bt_instance_t* ins, uint32_t group_id, bt_address_t* addr)
{
lea_client_interface_t* profile = get_profile_service();
return profile->group_remove_member(group_id, addr);
}
bt_status_t bt_lea_client_group_connect_audio(bt_instance_t* ins, uint32_t group_id, uint8_t context)
{
lea_client_interface_t* profile = get_profile_service();
return profile->group_connect_audio(group_id, context);
}
bt_status_t bt_lea_client_group_disconnect_audio(bt_instance_t* ins, uint32_t group_id)
{
lea_client_interface_t* profile = get_profile_service();
return profile->group_disconnect_audio(group_id);
}
bt_status_t bt_lea_client_group_lock(bt_instance_t* ins, uint32_t group_id)
{
lea_client_interface_t* profile = get_profile_service();
return profile->group_lock(group_id);
}
bt_status_t bt_lea_client_group_unlock(bt_instance_t* ins, uint32_t group_id)
{
lea_client_interface_t* profile = get_profile_service();
return profile->group_unlock(group_id);
}

View File

@ -0,0 +1,61 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include "bt_lea_mcp.h"
#include "bt_profile.h"
#include "lea_mcp_service.h"
#include "service_manager.h"
#include "utils/log.h"
#include <stdint.h>
static lea_mcp_interface_t* get_profile_service(void)
{
return (lea_mcp_interface_t*)service_manager_get_profile(PROFILE_LEAUDIO_MCP);
}
void* bt_lea_mcp_register_callbacks(bt_instance_t* ins, const lea_mcp_callbacks_t* callbacks)
{
lea_mcp_interface_t* profile = get_profile_service();
return profile->set_callbacks(NULL, (lea_mcp_callbacks_t*)callbacks);
}
bool bt_lea_mcp_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
lea_mcp_interface_t* profile = get_profile_service();
return profile->reset_callbacks(NULL, cookie);
}
bt_status_t bt_lea_mcp_read_info(bt_instance_t* ins, bt_address_t* addr, uint8_t opcode)
{
lea_mcp_interface_t* profile = get_profile_service();
return profile->read_remote_mcs_info(addr, opcode);
}
bt_status_t bt_lea_mcp_media_control_request(bt_instance_t* ins, bt_address_t* addr, uint32_t opcode, int32_t n)
{
lea_mcp_interface_t* profile = get_profile_service();
return profile->media_control_request(addr, opcode, n);
}
bt_status_t bt_lea_mcp_search_control_request(bt_instance_t* ins, bt_address_t* addr, uint8_t number, uint32_t type, uint8_t* parameter)
{
lea_mcp_interface_t* profile = get_profile_service();
return profile->search_control_request(addr, number, type, parameter);
}

145
framework/api/bt_lea_mcs.c Normal file
View File

@ -0,0 +1,145 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include "bt_lea_mcs.h"
#include "bt_profile.h"
#include "lea_mcs_service.h"
#include "service_manager.h"
#include "utils/log.h"
#include <stdint.h>
static lea_mcs_interface_t* get_profile_service(void)
{
return (lea_mcs_interface_t*)service_manager_get_profile(PROFILE_LEAUDIO_MCS);
}
void* bt_lea_mcs_register_callbacks(bt_instance_t* ins, const lea_mcs_callbacks_t* callbacks)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->set_callbacks(NULL, (lea_mcs_callbacks_t*)callbacks);
}
bool bt_lea_mcs_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->reset_callbacks(NULL, cookie);
}
bt_status_t bt_lea_mcs_service_add(bt_instance_t* ins)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->mcs_add();
}
bt_status_t bt_lea_mcs_service_remove(bt_instance_t* ins)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->mcs_remove();
}
bt_status_t bt_lea_mcs_playing_order_changed(bt_instance_t* ins, uint8_t order)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->playing_order_changed(order);
}
bt_status_t bt_lea_mcs_media_state_changed(bt_instance_t* ins, uint8_t state)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->media_state_changed(state);
}
bt_status_t bt_lea_mcs_playback_speed_changed(bt_instance_t* ins, int8_t speed)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->playback_speed_changed(speed);
}
bt_status_t bt_lea_mcs_seeking_speed_changed(bt_instance_t* ins, int8_t speed)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->seeking_speed_changed(speed);
}
bt_status_t bt_lea_mcs_track_title_changed(void* handl, uint8_t* title)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->track_title_changed(title);
}
bt_status_t bt_lea_mcs_track_duration_changed(bt_instance_t* ins, int32_t duration)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->track_duration_changed(duration);
}
bt_status_t bt_lea_mcs_track_position_changed(bt_instance_t* ins, int32_t position)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->track_position_changed(position);
}
bt_status_t bt_lea_mcs_current_track_change(bt_instance_t* ins, lea_object_id track_id)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->current_track_changed(track_id);
}
bt_status_t bt_lea_mcs_next_track_changed(bt_instance_t* ins, lea_object_id track_id)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->next_track_changed(track_id);
}
bt_status_t bt_lea_mcs_current_group_changed(bt_instance_t* ins, lea_object_id group_id)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->current_group_changed(group_id);
}
bt_status_t bt_lea_mcs_parent_group_changed(bt_instance_t* ins, lea_object_id group_id)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->parent_group_changed(group_id);
}
bt_status_t bt_lea_mcs_set_media_player_info(bt_instance_t* ins)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->set_media_player_info();
}
bt_status_t bt_lea_mcs_media_control_point_response(bt_instance_t* ins, lea_adpt_mcs_media_control_result_t result)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->media_control_response(result);
}

View File

@ -0,0 +1,81 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include "bt_lea_server.h"
#include "bt_profile.h"
#include "lea_server_service.h"
#include "service_manager.h"
static lea_server_interface_t* get_profile_service(void)
{
return (lea_server_interface_t*)service_manager_get_profile(
PROFILE_LEAUDIO_SERVER);
}
void* bt_lea_server_register_callbacks(bt_instance_t* ins,
const lea_server_callbacks_t* callbacks)
{
lea_server_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool bt_lea_server_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
lea_server_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t bt_lea_server_start_announce(bt_instance_t* ins, uint8_t adv_id,
uint8_t announce_type, uint8_t* adv_data, uint16_t adv_size,
uint8_t* md_data, uint16_t md_size)
{
lea_server_interface_t* profile = get_profile_service();
return profile->start_announce(adv_id, announce_type, adv_data,
adv_size, md_data, md_size);
}
bt_status_t bt_lea_server_stop_announce(bt_instance_t* ins, uint8_t adv_id)
{
lea_server_interface_t* profile = get_profile_service();
return profile->stop_announce(adv_id);
}
bt_status_t bt_lea_server_disconnect(bt_instance_t* ins, bt_address_t* addr)
{
lea_server_interface_t* profile = get_profile_service();
return profile->disconnect(addr);
}
bt_status_t bt_lea_server_disconnect_audio(bt_instance_t* ins, bt_address_t* addr)
{
lea_server_interface_t* profile = get_profile_service();
return profile->disconnect_audio(addr);
}
profile_connection_state_t bt_lea_server_get_connection_state(bt_instance_t* ins, bt_address_t* addr)
{
lea_server_interface_t* profile = get_profile_service();
return profile->get_connection_state(addr);
}

145
framework/api/bt_lea_tbs.c Normal file
View File

@ -0,0 +1,145 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include "bt_lea_tbs.h"
#include "bt_profile.h"
#include "lea_tbs_service.h"
#include "service_manager.h"
#include "utils/log.h"
#include <stdint.h>
static lea_tbs_interface_t* get_profile_service(void)
{
return (lea_tbs_interface_t*)service_manager_get_profile(PROFILE_LEAUDIO_TBS);
}
void* bt_lea_tbs_register_callbacks(bt_instance_t* ins, const lea_tbs_callbacks_t* callbacks)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, (lea_tbs_callbacks_t*)callbacks);
}
bool bt_lea_tbs_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t bt_lea_tbs_service_add(bt_instance_t* ins)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->tbs_add();
}
bt_status_t bt_lea_tbs_service_remove(bt_instance_t* ins)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->tbs_remove();
}
bt_status_t bt_lea_tbs_set_telephone_bearer_info(bt_instance_t* ins,
lea_tbs_telephone_bearer_t* bearer)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->set_telephone_bearer(bearer);
}
bt_status_t bt_lea_tbs_add_call(bt_instance_t* ins, lea_tbs_calls_t* call_s)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->add_call(call_s);
}
bt_status_t bt_lea_tbs_remove_call(bt_instance_t* ins, uint8_t call_index)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->remove_call(call_index);
}
bt_status_t bt_lea_tbs_provider_name_changed(bt_instance_t* ins, uint8_t* name)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->provider_name_changed(name);
}
bt_status_t bt_lea_tbs_bearer_technology_changed(bt_instance_t* ins,
lea_adpt_bearer_technology_t technology)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->bearer_technology_changed(technology);
}
bt_status_t bt_lea_tbs_uri_schemes_supported_list_changed(bt_instance_t* ins,
uint8_t* uri_schemes)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->uri_schemes_supported_list_changed(uri_schemes);
}
bt_status_t bt_lea_tbs_rssi_value_changed(bt_instance_t* ins, uint8_t strength)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->rssi_value_changed(strength);
}
bt_status_t bt_lea_tbs_rssi_interval_changed(bt_instance_t* ins,
uint8_t interval)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->rssi_interval_changed(interval);
}
bt_status_t bt_lea_tbs_status_flags_changed(bt_instance_t* ins, uint16_t status_flags)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->status_flags_changed(status_flags);
}
bt_status_t bt_lea_tbs_call_state_changed(bt_instance_t* ins, uint8_t number,
lea_tbs_call_state_t* state_s)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->call_state_changed(number, state_s);
}
bt_status_t bt_lea_tbs_notify_termination_reason(bt_instance_t* ins, uint8_t call_index,
lea_adpt_termination_reason_t reason)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->notify_termination_reason(call_index, reason);
}
bt_status_t bt_lea_tbs_call_control_response(bt_instance_t* ins, uint8_t call_index,
lea_adpt_call_control_result_t result)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->call_control_response(call_index, result);
}

View File

@ -0,0 +1,89 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include "bt_lea_vmicp.h"
#include "bt_profile.h"
#include "lea_vmicp_service.h"
#include "service_manager.h"
#include "utils/log.h"
#include <stdint.h>
static lea_vmicp_interface_t* get_profile_service(void)
{
return (lea_vmicp_interface_t*)service_manager_get_profile(PROFILE_LEAUDIO_VMICP);
}
void* bt_lea_vmicp_register_callbacks(bt_instance_t* ins, const lea_vmicp_callbacks_t* callbacks)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, (lea_vmicp_callbacks_t*)callbacks);
}
bool bt_lea_vmicp_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t bt_lea_vmicp_get_volume_state(bt_instance_t* ins, bt_address_t* addr)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->vol_get(addr);
}
bt_status_t bt_lea_vmicp_get_volume_flags(bt_instance_t* ins, bt_address_t* addr)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->flags_get(addr);
}
bt_status_t bt_lea_vmicp_change_volume(bt_instance_t* ins, bt_address_t* addr, int dir)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->vol_change(addr, dir);
}
bt_status_t bt_lea_vmicp_change_unmute_volume(bt_instance_t* ins, bt_address_t* addr, int dir)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->vol_unmute_change(addr, dir);
}
bt_status_t bt_lea_vmicp_set_volume(bt_instance_t* ins, bt_address_t* addr, int vol)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->vol_set(addr, vol);
}
bt_status_t bt_lea_vmicp_set_volume_mute(bt_instance_t* ins, bt_address_t* addr, int mute)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->mute_state_set(addr, mute);
}
bt_status_t bt_lea_vmicp_get_mic_state(bt_instance_t* ins, bt_address_t* addr)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->mic_mute_get(addr);
}
bt_status_t bt_lea_vmicp_set_mic_mute(bt_instance_t* ins, bt_address_t* addr, int mute)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->mic_mute_set(addr, mute);
}

View File

@ -0,0 +1,65 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include "bt_lea_vmics.h"
#include "bt_profile.h"
#include "lea_vmics_service.h"
#include "service_manager.h"
static lea_vmics_interface_t* get_profile_service(void)
{
return (lea_vmics_interface_t*)service_manager_get_profile(PROFILE_LEAUDIO_VMICS);
}
void* bt_lea_vmics_register_callbacks(bt_instance_t* ins, const lea_vmics_callbacks_t* callbacks)
{
lea_vmics_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, (lea_vmics_callbacks_t*)callbacks);
}
bool bt_lea_vmics_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
lea_vmics_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t bt_lea_vcs_volume_set(bt_instance_t* ins, int vol)
{
lea_vmics_interface_t* profile = get_profile_service();
return profile->vcs_volume_notify(ins, vol);
}
bt_status_t bt_lea_vcs_mute_set(bt_instance_t* ins, int mute)
{
lea_vmics_interface_t* profile = get_profile_service();
return profile->vcs_mute_notify(ins, mute);
}
bt_status_t bt_lea_vcs_volume_flags_set(bt_instance_t* ins, int flags)
{
lea_vmics_interface_t* profile = get_profile_service();
return profile->vcs_volume_flags_notify(ins, flags);
}
bt_status_t bt_lea_mics_mute_set(bt_instance_t* ins, int mute)
{
lea_vmics_interface_t* profile = get_profile_service();
return profile->mics_mute_notify(ins, mute);
}

58
framework/api/bt_pan.c Normal file
View File

@ -0,0 +1,58 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "pan_api"
#include <stdint.h>
#include "bt_internal.h"
#include "bt_pan.h"
#include "bt_profile.h"
#include "pan_service.h"
#include "service_manager.h"
#include "utils/log.h"
static pan_interface_t* get_profile_service(void)
{
return (pan_interface_t*)service_manager_get_profile(PROFILE_PANU);
}
void* BTSYMBOLS(bt_pan_register_callbacks)(bt_instance_t* ins, const pan_callbacks_t* callbacks)
{
pan_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool BTSYMBOLS(bt_pan_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
pan_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t BTSYMBOLS(bt_pan_connect)(bt_instance_t* ins, bt_address_t* addr, uint8_t dst_role, uint8_t src_role)
{
pan_interface_t* profile = get_profile_service();
return profile->connect(addr, dst_role, src_role);
}
bt_status_t BTSYMBOLS(bt_pan_disconnect)(bt_instance_t* ins, bt_address_t* addr)
{
pan_interface_t* profile = get_profile_service();
return profile->disconnect(addr);
}

82
framework/api/bt_spp.c Normal file
View File

@ -0,0 +1,82 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "spp_api"
#include <stdint.h>
#include "bt_internal.h"
#include "bt_profile.h"
#include "bt_spp.h"
#include "service_manager.h"
#include "spp_service.h"
#include "utils/log.h"
static spp_interface_t* get_profile_service(void)
{
return (spp_interface_t*)service_manager_get_profile(PROFILE_SPP);
}
void* BTSYMBOLS(bt_spp_register_app_with_name)(bt_instance_t* ins, const char* name, const spp_callbacks_t* callbacks)
{
spp_interface_t* profile = get_profile_service();
return profile->register_app(NULL, name, callbacks);
}
void* BTSYMBOLS(bt_spp_register_app)(bt_instance_t* ins, const spp_callbacks_t* callbacks)
{
return BTSYMBOLS(bt_spp_register_app_with_name)(ins, NULL, callbacks);
}
void* BTSYMBOLS(bt_spp_register_app_ext)(bt_instance_t* ins, const char* name, int port_type, const spp_callbacks_t* callbacks)
{
return BTSYMBOLS(bt_spp_register_app_with_name)(ins, name, callbacks);
}
bt_status_t BTSYMBOLS(bt_spp_unregister_app)(bt_instance_t* ins, void* handle)
{
spp_interface_t* profile = get_profile_service();
return profile->unregister_app(NULL, handle);
}
bt_status_t BTSYMBOLS(bt_spp_server_start)(bt_instance_t* ins, void* handle, uint16_t scn, bt_uuid_t* uuid, uint8_t max_connection)
{
spp_interface_t* profile = get_profile_service();
return profile->server_start(handle, scn, uuid, max_connection);
}
bt_status_t BTSYMBOLS(bt_spp_server_stop)(bt_instance_t* ins, void* handle, uint16_t scn)
{
spp_interface_t* profile = get_profile_service();
return profile->server_stop(handle, scn);
}
bt_status_t BTSYMBOLS(bt_spp_connect)(bt_instance_t* ins, void* handle, bt_address_t* addr, int16_t scn, bt_uuid_t* uuid, uint16_t* port)
{
spp_interface_t* profile = get_profile_service();
return profile->connect(handle, addr, scn, uuid, port);
}
bt_status_t BTSYMBOLS(bt_spp_disconnect)(bt_instance_t* ins, void* handle, bt_address_t* addr, uint16_t port)
{
spp_interface_t* profile = get_profile_service();
return profile->disconnect(handle, addr, port);
}

40
framework/api/bt_trace.c Normal file
View File

@ -0,0 +1,40 @@
/****************************************************************************
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include "bt_trace.h"
#include "bluetooth.h"
#include "bt_internal.h"
#include "utils/btsnoop_log.h"
#include "utils/log.h"
void BTSYMBOLS(bluetooth_enable_btsnoop_log)(bt_instance_t* ins)
{
bt_log_module_enable(LOG_ID_SNOOP, false);
}
void BTSYMBOLS(bluetooth_disable_btsnoop_log)(bt_instance_t* ins)
{
bt_log_module_disable(LOG_ID_SNOOP, false);
}
void BTSYMBOLS(bluetooth_set_btsnoop_filter)(bt_instance_t* ins, btsnoop_filter_flag_t filter_flag)
{
btsnoop_set_filter(filter_flag);
}
void BTSYMBOLS(bluetooth_remove_btsnoop_filter)(bt_instance_t* ins, btsnoop_filter_flag_t filter_flag)
{
btsnoop_remove_filter(filter_flag);
}

View File

@ -0,0 +1,177 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdlib.h>
#include <unistd.h>
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_BINDER_IPC
#include "adapter_proxy.h"
#include "adapter_stub.h"
#include "bluetooth_proxy.h"
#include "gattc_proxy.h"
#include "gatts_proxy.h"
#include "hfp_ag_proxy.h"
#include "hfp_hf_proxy.h"
#include "hid_device_proxy.h"
#include "pan_proxy.h"
#include "spp_proxy.h"
#endif
#include "bluetooth.h"
bt_instance_t* bluetooth_create_instance(void)
{
AIBinder* binder;
char name[64] = { 0 };
bt_instance_t* ins = zalloc(sizeof(bt_instance_t));
if (!ins) {
return NULL;
}
binder = BtManager_getService((BpBtManager**)&ins->manager_proxy, MANAGER_BINDER_INSTANCE);
if (!binder)
goto bail;
gethostname(name, 64);
bt_status_t status = BpBtManager_createInstance(binder, (uint32_t)ins, BLUETOOTH_SYSTEM, name, &ins->app_id);
if (status != BT_STATUS_SUCCESS)
goto bail;
BtAdapter_getService((BpBtAdapter**)&ins->adapter_proxy, ADAPTER_BINDER_INSTANCE);
Bluetooth_startThreadPool();
return ins;
bail:
free(ins);
return NULL;
}
bt_instance_t* bluetooth_get_instance(void)
{
uint32_t handle;
char name[64] = { 0 };
AIBinder* binder;
BpBtManager* proxy = NULL;
/* find instance from bluetooth manager by hostname,
if not found, create new instance for this hostname
*/
binder = BtManager_getService(&proxy, MANAGER_BINDER_INSTANCE);
if (!binder)
return NULL;
gethostname(name, 64);
bt_status_t status = BpBtManager_getInstance(binder, name, &handle);
BpBtManager_delete(proxy);
if (status == BT_STATUS_SUCCESS && handle)
return (bt_instance_t*)handle;
else
return bluetooth_create_instance();
}
void* bluetooth_get_proxy(bt_instance_t* ins, enum profile_id id)
{
switch (id) {
case PROFILE_HFP_HF:
/* for binder ipc*/
if (!ins->hfp_hf_proxy) {
ins->hfp_hf_proxy = BpBtHfpHf_new(HFP_HF_BINDER_INSTANCE);
}
return ins->hfp_hf_proxy;
case PROFILE_HFP_AG: {
if (!ins->hfp_ag_proxy) {
ins->hfp_ag_proxy = BpBtHfpAg_new(HFP_AG_BINDER_INSTANCE);
}
return ins->hfp_ag_proxy;
}
case PROFILE_SPP: {
if (!ins->spp_proxy) {
ins->spp_proxy = BpBtSpp_new(SPP_BINDER_INSTANCE);
}
return ins->spp_proxy;
}
case PROFILE_HID_DEV: {
if (!ins->hidd_proxy) {
ins->hidd_proxy = BpBtHidd_new(HID_DEVICE_BINDER_INSTANCE);
}
return ins->hidd_proxy;
}
case PROFILE_PANU: {
if (!ins->pan_proxy) {
ins->pan_proxy = BpBtPan_new(PAN_BINDER_INSTANCE);
}
return ins->pan_proxy;
}
case PROFILE_GATTC: {
if (!ins->gattc_proxy) {
ins->gattc_proxy = BpBtGattClient_new(GATT_CLIENT_BINDER_INSTANCE);
}
return ins->gattc_proxy;
}
case PROFILE_GATTS: {
if (!ins->gatts_proxy) {
ins->gatts_proxy = BpBtGattServer_new(GATT_SERVER_BINDER_INSTANCE);
}
return ins->gatts_proxy;
}
default:
break;
}
return NULL;
}
void bluetooth_delete_instance(bt_instance_t* ins)
{
if (ins->hfp_hf_proxy)
BpBtHfpHf_delete(ins->hfp_hf_proxy);
if (ins->hfp_ag_proxy)
BpBtHfpAg_delete(ins->hfp_ag_proxy);
if (ins->spp_proxy)
BpBtSpp_delete(ins->spp_proxy);
if (ins->pan_proxy)
BpBtPan_delete(ins->pan_proxy);
if (ins->gattc_proxy)
BpBtGattClient_delete(ins->gattc_proxy);
if (ins->gatts_proxy)
BpBtGattServer_delete(ins->gatts_proxy);
BpBtAdapter_delete(ins->adapter_proxy);
BpBtManager_deleteInstance(ins->manager_proxy, ins->app_id);
BpBtManager_delete(ins->manager_proxy);
free(ins);
}
bt_status_t bluetooth_start_service(bt_instance_t* ins, enum profile_id id)
{
return BpBtManager_startService(ins->manager_proxy, ins->app_id, id);
}
bt_status_t bluetooth_stop_service(bt_instance_t* ins, enum profile_id id)
{
return BpBtManager_stopService(ins->manager_proxy, ins->app_id, id);
}
#include "uv.h"
bool bluetooth_set_external_uv(bt_instance_t* ins, uv_loop_t* ext_loop)
{
return false;
}

View File

@ -0,0 +1,231 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "adapter_callbacks_stub.h"
#include "adapter_proxy.h"
#include "adapter_stub.h"
#include "bt_adapter.h"
void* bt_adapter_register_callback(bt_instance_t* ins, const adapter_callbacks_t* adapter_cbs)
{
BpBtAdapter* bpAdapter = ins->adapter_proxy;
if (!BtAdapter_getService(&bpAdapter, ADAPTER_BINDER_INSTANCE))
return NULL;
IBtAdapterCallbacks* cbks = BtAdapterCallbacks_new(adapter_cbs);
AIBinder* binder = BtAdapterCallbacks_getBinder(cbks);
if (!binder) {
BtAdapterCallbacks_delete(cbks);
return NULL;
}
void* rmt_cookie = BpBtAdapter_registerCallback(bpAdapter, binder);
AIBinder_decStrong(binder);
if (!rmt_cookie) {
BtAdapterCallbacks_delete(cbks);
return NULL;
}
cbks->cookie = rmt_cookie;
return (void*)cbks;
}
bool bt_adapter_unregister_callback(bt_instance_t* ins, void* cookie)
{
IBtAdapterCallbacks* cbks = cookie;
bool ret = BpBtAdapter_unRegisterCallback((BpBtAdapter*)ins->adapter_proxy, cbks->cookie);
if (ret)
BtAdapterCallbacks_delete(cbks);
return ret;
}
bt_status_t bt_adapter_enable(bt_instance_t* ins)
{
return BpBtAdapter_enable((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_disable(bt_instance_t* ins)
{
return BpBtAdapter_disable((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_enable_le(bt_instance_t* ins)
{
return BpBtAdapter_enableLe((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_disable_le(bt_instance_t* ins)
{
return BpBtAdapter_disableLe((BpBtAdapter*)ins->adapter_proxy);
}
bt_adapter_state_t bt_adapter_get_state(bt_instance_t* ins)
{
return BpBtAdapter_getState((BpBtAdapter*)ins->adapter_proxy);
}
bool bt_adapter_is_le_enabled(bt_instance_t* ins)
{
return BpBtAdapter_isLeEnabled((BpBtAdapter*)ins->adapter_proxy);
}
bt_device_type_t bt_adapter_get_type(bt_instance_t* ins)
{
return BpBtAdapter_getType((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_set_discovery_filter(bt_instance_t* ins)
{
return BpBtAdapter_setDiscoveryFilter((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_start_discovery(bt_instance_t* ins, uint32_t timeout)
{
return BpBtAdapter_startDiscovery((BpBtAdapter*)ins->adapter_proxy, timeout);
}
bt_status_t bt_adapter_cancel_discovery(bt_instance_t* ins)
{
return BpBtAdapter_cancelDiscovery((BpBtAdapter*)ins->adapter_proxy);
}
bool bt_adapter_is_discovering(bt_instance_t* ins)
{
return BpBtAdapter_isDiscovering((BpBtAdapter*)ins->adapter_proxy);
}
void bt_adapter_get_address(bt_instance_t* ins, bt_address_t* addr)
{
BpBtAdapter_getAddress((BpBtAdapter*)ins->adapter_proxy, addr);
}
bt_status_t bt_adapter_set_name(bt_instance_t* ins, const char* name)
{
assert(strlen(name) <= 64);
return BpBtAdapter_setName((BpBtAdapter*)ins->adapter_proxy, name);
}
void bt_adapter_get_name(bt_instance_t* ins, char* name, int length)
{
BpBtAdapter_getName((BpBtAdapter*)ins->adapter_proxy, name, length);
}
bt_status_t bt_adapter_get_uuids(bt_instance_t* ins, bt_uuid_t* uuids, uint16_t* size)
{
return BpBtAdapter_getUuids((BpBtAdapter*)ins->adapter_proxy, uuids, size);
}
bt_status_t bt_adapter_set_scan_mode(bt_instance_t* ins, bt_scan_mode_t mode, bool bondable)
{
return BpBtAdapter_setScanMode((BpBtAdapter*)ins->adapter_proxy, mode, bondable);
}
bt_scan_mode_t bt_adapter_get_scan_mode(bt_instance_t* ins)
{
return BpBtAdapter_getScanMode((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_set_device_class(bt_instance_t* ins, uint32_t cod)
{
return BpBtAdapter_setDeviceClass((BpBtAdapter*)ins->adapter_proxy, cod);
}
uint32_t bt_adapter_get_device_class(bt_instance_t* ins)
{
return BpBtAdapter_getDeviceClass((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_set_io_capability(bt_instance_t* ins, bt_io_capability_t cap)
{
return BpBtAdapter_setIOCapability((BpBtAdapter*)ins->adapter_proxy, cap);
}
bt_io_capability_t bt_adapter_get_io_capability(bt_instance_t* ins)
{
return BpBtAdapter_getIOCapability((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_set_le_io_capability(bt_instance_t* ins, uint32_t le_io_cap)
{
return BpBtAdapter_SetLeIOCapability((BpBtAdapter*)ins->adapter_proxy, le_io_cap);
}
uint32_t bt_adapter_get_le_io_capability(bt_instance_t* ins)
{
return BpBtAdapter_getLeIOCapability((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_get_le_address(bt_instance_t* ins, bt_address_t* addr, ble_addr_type_t* type)
{
return BpBtAdapter_getLeAddress((BpBtAdapter*)ins->adapter_proxy, addr, type);
}
bt_status_t bt_adapter_set_le_address(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_setLeAddress((BpBtAdapter*)ins->adapter_proxy, addr);
}
bt_status_t bt_adapter_set_le_identity_address(bt_instance_t* ins, bt_address_t* addr, bool is_public)
{
return BpBtAdapter_setLeIdentityAddress((BpBtAdapter*)ins->adapter_proxy, addr, is_public);
}
bt_status_t bt_adapter_set_le_appearance(bt_instance_t* ins, uint16_t appearance)
{
return BpBtAdapter_setLeAppearance((BpBtAdapter*)ins->adapter_proxy, appearance);
}
uint16_t bt_adapter_get_le_appearance(bt_instance_t* ins)
{
return BpBtAdapter_getLeAppearance((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_get_bonded_devices(bt_instance_t* ins, bt_transport_t transport, bt_address_t** addr, int* num, bt_allocator_t allocator)
{
return BpBtAdapter_getBondedDevices((BpBtAdapter*)ins->adapter_proxy, addr, num, allocator);
}
bt_status_t bt_adapter_get_connected_devices(bt_instance_t* ins, bt_transport_t transport, bt_address_t** addr, int* num, bt_allocator_t allocator)
{
return BpBtAdapter_getConnectedDevices((BpBtAdapter*)ins->adapter_proxy, addr, num, allocator);
}
void bt_adapter_disconnect_all_devices(bt_instance_t* ins)
{
}
bool bt_adapter_is_support_bredr(bt_instance_t* ins)
{
return false;
}
bool bt_adapter_is_support_le(bt_instance_t* ins)
{
return false;
}
bool bt_adapter_is_support_leaudio(bt_instance_t* ins)
{
return false;
}

View File

@ -0,0 +1,176 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include <stdlib.h>
#include "adapter_internel.h"
#include "bluetooth.h"
#include "bt_addr.h"
#include "bt_device.h"
#include "device.h"
#include "adapter_proxy.h"
#include "adapter_stub.h"
bt_address_t* bt_device_get_identity_address(bt_instance_t* ins, bt_address_t* addr)
{
return NULL;
}
ble_addr_type_t bt_device_get_address_type(bt_instance_t* ins, bt_address_t* addr)
{
return 0;
}
bt_device_type_t bt_device_get_device_type(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_getRemoteDeviceType((BpBtAdapter*)ins->adapter_proxy, addr);
}
bool bt_device_get_name(bt_instance_t* ins, bt_address_t* addr, char* name, uint32_t length)
{
return BpBtAdapter_getRemoteName((BpBtAdapter*)ins->adapter_proxy, addr, name, length);
}
uint32_t bt_device_get_device_class(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_getRemoteDeviceClass((BpBtAdapter*)ins->adapter_proxy, addr);
}
bt_status_t bt_device_get_uuids(bt_instance_t* ins, bt_address_t* addr, bt_uuid_t** uuids, uint16_t* size, bt_allocator_t allocator)
{
return BpBtAdapter_getRemoteUuids((BpBtAdapter*)ins->adapter_proxy, addr, uuids, size, allocator);
}
uint16_t bt_device_get_appearance(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_getRemoteAppearance((BpBtAdapter*)ins->adapter_proxy, addr);
}
int8_t bt_device_get_rssi(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_getRemoteRssi((BpBtAdapter*)ins->adapter_proxy, addr);
}
bool bt_device_get_alias(bt_instance_t* ins, bt_address_t* addr, char* alias, uint32_t length)
{
return BpBtAdapter_getRemoteAlias((BpBtAdapter*)ins->adapter_proxy, addr, alias, length);
}
bt_status_t bt_device_set_alias(bt_instance_t* ins, bt_address_t* addr, const char* alias)
{
return BpBtAdapter_setRemoteAlias((BpBtAdapter*)ins->adapter_proxy, addr, alias);
}
bool bt_device_is_connected(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_isRemoteConnected((BpBtAdapter*)ins->adapter_proxy, addr);
}
bool bt_device_is_encrypted(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_isRemoteEncrypted((BpBtAdapter*)ins->adapter_proxy, addr);
}
bool bt_device_is_bond_initiate_local(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_isBondInitiateLocal((BpBtAdapter*)ins->adapter_proxy, addr);
}
bond_state_t bt_device_get_bond_state(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_getRemoteBondState((BpBtAdapter*)ins->adapter_proxy, addr);
}
bool bt_device_is_bonded(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_isRemoteBonded((BpBtAdapter*)ins->adapter_proxy, addr);
}
bt_status_t bt_device_connect(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_connect((BpBtAdapter*)ins->adapter_proxy, addr);
}
bt_status_t bt_device_disconnect(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_disconnect((BpBtAdapter*)ins->adapter_proxy, addr);
}
bt_status_t bt_device_connect_le(bt_instance_t* ins,
bt_address_t* addr,
ble_addr_type_t type,
ble_connect_params_t* param)
{
return BpBtAdapter_leConnect((BpBtAdapter*)ins->adapter_proxy, addr, type, param);
}
bt_status_t bt_device_disconnect_le(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_leDisconnect((BpBtAdapter*)ins->adapter_proxy, addr);
}
void bt_device_connect_all_profile(bt_instance_t* ins, bt_address_t* addr)
{
}
void bt_device_disconnect_all_profile(bt_instance_t* ins, bt_address_t* addr)
{
}
bt_status_t bt_device_set_le_phy(bt_instance_t* ins,
bt_address_t* addr,
ble_phy_type_t tx_phy,
ble_phy_type_t rx_phy)
{
return BpBtAdapter_leSetPhy((BpBtAdapter*)ins->adapter_proxy, addr, tx_phy, rx_phy);
}
bt_status_t bt_device_create_bond(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
return BpBtAdapter_createBond((BpBtAdapter*)ins->adapter_proxy, addr, transport);
}
bt_status_t bt_device_remove_bond(bt_instance_t* ins, bt_address_t* addr, uint8_t transport)
{
return BpBtAdapter_removeBond((BpBtAdapter*)ins->adapter_proxy, addr, transport);
}
bt_status_t bt_device_cancel_bond(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_cancelBond((BpBtAdapter*)ins->adapter_proxy, addr);
}
bt_status_t bt_device_pair_request_reply(bt_instance_t* ins, bt_address_t* addr, bool accept)
{
return BpBtAdapter_pairRequestReply((BpBtAdapter*)ins->adapter_proxy, addr, accept);
}
bt_status_t bt_device_set_pairing_confirmation(bt_instance_t* ins, bt_address_t* addr, uint8_t transport, bool accept)
{
return BpBtAdapter_setPairingConfirmation((BpBtAdapter*)ins->adapter_proxy, addr, transport, accept);
}
bt_status_t bt_device_set_pin_code(bt_instance_t* ins, bt_address_t* addr, bool accept,
char* pincode, int len)
{
return BpBtAdapter_setPinCode((BpBtAdapter*)ins->adapter_proxy, addr, accept, pincode, len);
}
bt_status_t bt_device_set_pass_key(bt_instance_t* ins, bt_address_t* addr, uint8_t transport, bool accept, uint32_t passkey)
{
return BpBtAdapter_setPassKey((BpBtAdapter*)ins->adapter_proxy, addr, transport, accept, passkey);
}

132
framework/binder/bt_gattc.c Normal file
View File

@ -0,0 +1,132 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "gattc"
#include "bt_gattc.h"
#include "bt_profile.h"
#include "gattc_callbacks_stub.h"
#include "gattc_proxy.h"
#include "gattc_stub.h"
#include "utils/log.h"
#include <stdint.h>
bt_status_t bt_gattc_create_connect(bt_instance_t* ins, gattc_handle_t* phandle, gattc_callbacks_t* callbacks)
{
BpBtGattClient* gattc = (BpBtGattClient*)bluetooth_get_proxy(ins, PROFILE_GATTC);
IBtGattClientCallbacks* cbks = BtGattClientCallbacks_new(callbacks);
AIBinder* binder = BtGattClientCallbacks_getBinder(cbks);
if (!binder) {
BtGattClientCallbacks_delete(cbks);
return BT_STATUS_FAIL;
}
void* handle = BpBtGattClient_createConnect(gattc, binder);
if (!handle) {
BtGattClientCallbacks_delete(cbks);
return BT_STATUS_FAIL;
}
cbks->proxy = gattc;
cbks->cookie = handle;
*phandle = cbks;
return BT_STATUS_SUCCESS;
}
bt_status_t bt_gattc_delete_connect(gattc_handle_t conn_handle)
{
IBtGattClientCallbacks* cbks = conn_handle;
bt_status_t status = BpBtGattClient_deleteConnect(cbks->proxy, cbks->cookie);
if (status == BT_STATUS_SUCCESS)
BtGattClientCallbacks_delete(cbks);
return status;
}
bt_status_t bt_gattc_connect(gattc_handle_t conn_handle, bt_address_t* addr, ble_addr_type_t addr_type)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_connect(cbks->proxy, cbks->cookie, addr, addr_type);
}
bt_status_t bt_gattc_disconnect(gattc_handle_t conn_handle)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_disconnect(cbks->proxy, cbks->cookie);
}
bt_status_t bt_gattc_discover_service(gattc_handle_t conn_handle, bt_uuid_t* filter_uuid)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_discoverService(cbks->proxy, cbks->cookie, filter_uuid);
}
bt_status_t bt_gattc_get_attribute_by_handle(gattc_handle_t conn_handle, uint16_t attr_handle, gatt_attr_desc_t* attr_desc)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_getAttributeByHandle(cbks->proxy, cbks->cookie, attr_handle, attr_desc);
}
bt_status_t bt_gattc_get_attribute_by_uuid(gattc_handle_t conn_handle, bt_uuid_t* attr_uuid, gatt_attr_desc_t* attr_desc)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_getAttributeByUUID(cbks->proxy, cbks->cookie, attr_uuid, attr_desc);
}
bt_status_t bt_gattc_read(gattc_handle_t conn_handle, uint16_t attr_handle)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_read(cbks->proxy, cbks->cookie, attr_handle);
}
bt_status_t bt_gattc_write(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_write(cbks->proxy, cbks->cookie, attr_handle, value, length);
}
bt_status_t bt_gattc_write_without_response(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_writeWithoutResponse(cbks->proxy, cbks->cookie, attr_handle, value, length);
}
bt_status_t bt_gattc_subscribe(gattc_handle_t conn_handle, uint16_t value_handle, uint16_t cccd_handle)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_subscribe(cbks->proxy, cbks->cookie, value_handle, cccd_handle);
}
bt_status_t bt_gattc_unsubscribe(gattc_handle_t conn_handle, uint16_t value_handle, uint16_t cccd_handle)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_unsubscribe(cbks->proxy, cbks->cookie, value_handle, cccd_handle);
}
bt_status_t bt_gattc_exchange_mtu(gattc_handle_t conn_handle, uint32_t mtu)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_exchangeMtu(cbks->proxy, cbks->cookie, mtu);
}
bt_status_t bt_gattc_update_connection_parameter(gattc_handle_t conn_handle, uint32_t min_interval, uint32_t max_interval, uint32_t latency,
uint32_t timeout, uint32_t min_connection_event_length, uint32_t max_connection_event_length)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_updateConnectionParameter(cbks->proxy, cbks->cookie, min_interval, max_interval, latency,
timeout, min_connection_event_length, max_connection_event_length);
}

109
framework/binder/bt_gatts.c Normal file
View File

@ -0,0 +1,109 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "gatts"
#include "bt_gatts.h"
#include "bt_profile.h"
#include "gatts_callbacks_stub.h"
#include "gatts_proxy.h"
#include "gatts_stub.h"
#include "utils/log.h"
#include <stdint.h>
bt_status_t bt_gatts_register_service(bt_instance_t* ins, gatts_handle_t* phandle, gatts_callbacks_t* callbacks)
{
BpBtGattServer* gatts = (BpBtGattServer*)bluetooth_get_proxy(ins, PROFILE_GATTS);
IBtGattServerCallbacks* cbks = BtGattServerCallbacks_new(callbacks);
AIBinder* binder = BtGattServerCallbacks_getBinder(cbks);
if (!binder) {
BtGattServerCallbacks_delete(cbks);
return BT_STATUS_FAIL;
}
void* handle = BpBtGattServer_registerService(gatts, binder);
if (!handle) {
BtGattServerCallbacks_delete(cbks);
return BT_STATUS_FAIL;
}
cbks->proxy = gatts;
cbks->cookie = handle;
*phandle = cbks;
return BT_STATUS_SUCCESS;
}
bt_status_t bt_gatts_unregister_service(gatts_handle_t srv_handle)
{
IBtGattServerCallbacks* cbks = srv_handle;
bt_status_t status = BpBtGattServer_unregisterService(cbks->proxy, cbks->cookie);
if (status == BT_STATUS_SUCCESS)
BtGattServerCallbacks_delete(cbks);
return status;
}
bt_status_t bt_gatts_connect(gatts_handle_t srv_handle, bt_address_t* addr, ble_addr_type_t addr_type)
{
IBtGattServerCallbacks* cbks = srv_handle;
return BpBtGattServer_connect(cbks->proxy, cbks->cookie, addr, addr_type);
}
bt_status_t bt_gatts_disconnect(gatts_handle_t srv_handle)
{
IBtGattServerCallbacks* cbks = srv_handle;
return BpBtGattServer_disconnect(cbks->proxy, cbks->cookie);
}
bt_status_t bt_gatts_create_service_table(gatts_handle_t srv_handle, gatt_srv_db_t* srv_db)
{
IBtGattServerCallbacks* cbks = srv_handle;
bt_status_t status = BpBtGattServer_createServiceTable(cbks->proxy, cbks->cookie, srv_db);
if (status == BT_STATUS_SUCCESS)
cbks->srv_db = srv_db;
return status;
}
bt_status_t bt_gatts_start(gatts_handle_t srv_handle)
{
IBtGattServerCallbacks* cbks = srv_handle;
return BpBtGattServer_start(cbks->proxy, cbks->cookie);
}
bt_status_t bt_gatts_stop(gatts_handle_t srv_handle)
{
IBtGattServerCallbacks* cbks = srv_handle;
return BpBtGattServer_stop(cbks->proxy, cbks->cookie);
}
bt_status_t bt_gatts_response(gatts_handle_t srv_handle, uint32_t req_handle, uint8_t* value, uint16_t length)
{
IBtGattServerCallbacks* cbks = srv_handle;
return BpBtGattServer_response(cbks->proxy, cbks->cookie, req_handle, value, length);
}
bt_status_t bt_gatts_notify(gatts_handle_t srv_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
IBtGattServerCallbacks* cbks = srv_handle;
return BpBtGattServer_notify(cbks->proxy, cbks->cookie, attr_handle, value, length);
}
bt_status_t bt_gatts_indicate(gatts_handle_t srv_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
IBtGattServerCallbacks* cbks = srv_handle;
return BpBtGattServer_indicate(cbks->proxy, cbks->cookie, attr_handle, value, length);
}

View File

@ -0,0 +1,122 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "hfp_ag_api"
#include "bt_hfp_ag.h"
#include "bt_profile.h"
#include "hfp_ag_callbacks_stub.h"
#include "hfp_ag_proxy.h"
#include "hfp_ag_stub.h"
#include "utils/log.h"
#include <stdint.h>
void* bt_hfp_ag_register_callbacks(bt_instance_t* ins, const hfp_ag_callbacks_t* callbacks)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
IBtHfpAgCallbacks* cbks = BtHfpAgCallbacks_new(callbacks);
AIBinder* binder = BtHfpAgCallbacks_getBinder(cbks);
if (!binder) {
BtHfpAgCallbacks_delete(cbks);
return NULL;
}
void* remote_cbks = BpBtHfpAg_registerCallback(ag, binder);
if (!remote_cbks) {
BtHfpAgCallbacks_delete(cbks);
return NULL;
}
cbks->cookie = remote_cbks;
return cbks;
}
bool bt_hfp_ag_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
IBtHfpAgCallbacks* cbks = cookie;
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
bool ret = BpBtHfpAg_unRegisterCallback(ag, cbks->cookie);
if (ret)
BtHfpAgCallbacks_delete(cbks);
return ret;
}
bool bt_hfp_ag_is_connected(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
return BpBtHfpAg_isConnected(ag, addr);
}
bool bt_hfp_ag_is_audio_connected(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
return BpBtHfpAg_isAudioConnected(ag, addr);
}
profile_connection_state_t bt_hfp_ag_get_connection_state(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
return BpBtHfpAg_getConnectionState(ag, addr);
}
bt_status_t bt_hfp_ag_connect(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
return BpBtHfpAg_connect(ag, addr);
}
bt_status_t bt_hfp_ag_disconnect(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
return BpBtHfpAg_disconnect(ag, addr);
}
bt_status_t bt_hfp_ag_connect_audio(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
return BpBtHfpAg_connectAudio(ag, addr);
}
bt_status_t bt_hfp_ag_disconnect_audio(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
return BpBtHfpAg_disconnectAudio(ag, addr);
}
bt_status_t bt_hfp_ag_start_voice_recognition(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
return BpBtHfpAg_startVoiceRecognition(ag, addr);
}
bt_status_t bt_hfp_ag_stop_voice_recognition(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
return BpBtHfpAg_stopVoiceRecognition(ag, addr);
}

View File

@ -0,0 +1,192 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_THF "hfp_hf_api"
#include "bt_hfp_hf.h"
#include "bt_profile.h"
#include "hfp_hf_callbacks_stub.h"
#include "hfp_hf_proxy.h"
#include "hfp_hf_stub.h"
#include "utils/log.h"
#include <stdint.h>
void* bt_hfp_hf_register_callbacks(bt_instance_t* ins, const hfp_hf_callbacks_t* callbacks)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
IBtHfpHfCallbacks* cbks = BtHfpHfCallbacks_new(callbacks);
AIBinder* binder = BtHfpHfCallbacks_getBinder(cbks);
if (!binder) {
BtHfpHfCallbacks_delete(cbks);
return NULL;
}
void* remote_cbks = BpBtHfpHf_registerCallback(hf, binder);
if (!remote_cbks) {
BtHfpHfCallbacks_delete(cbks);
return NULL;
}
cbks->cookie = remote_cbks;
return cbks;
}
bool bt_hfp_hf_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
IBtHfpHfCallbacks* cbks = cookie;
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
bool ret = BpBtHfpHf_unRegisterCallback(hf, cbks->cookie);
if (ret)
BtHfpHfCallbacks_delete(cbks);
return ret;
}
bool bt_hfp_hf_is_connected(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_isConnected(hf, addr);
}
bool bt_hfp_hf_is_audio_connected(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_isAudioConnected(hf, addr);
}
profile_connection_state_t bt_hfp_hf_get_connection_state(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_getConnectionState(hf, addr);
}
bt_status_t bt_hfp_hf_connect(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_connect(hf, addr);
}
bt_status_t bt_hfp_hf_disconnect(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_disconnect(hf, addr);
}
bt_status_t bt_hfp_hf_connect_audio(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_connectAudio(hf, addr);
}
bt_status_t bt_hfp_hf_disconnect_audio(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_disconnectAudio(hf, addr);
}
bt_status_t bt_hfp_hf_start_voice_recognition(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_startVoiceRecognition(hf, addr);
}
bt_status_t bt_hfp_hf_stop_voice_recognition(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_stopVoiceRecognition(hf, addr);
}
bt_status_t bt_hfp_hf_dial(bt_instance_t* ins, bt_address_t* addr, const char* number)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_dial(hf, addr, number);
}
bt_status_t bt_hfp_hf_dial_memory(bt_instance_t* ins, bt_address_t* addr, uint32_t memory)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_dialMemory(hf, addr, memory);
}
bt_status_t bt_hfp_hf_redial(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_redial(hf, addr);
}
bt_status_t bt_hfp_hf_accept_call(bt_instance_t* ins, bt_address_t* addr, hfp_call_accept_t flag)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_acceptCall(hf, addr, flag);
}
bt_status_t bt_hfp_hf_reject_call(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_rejectCall(hf, addr);
}
bt_status_t bt_hfp_hf_hold_call(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_holdCall(hf, addr);
}
bt_status_t bt_hfp_hf_terminate_call(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_terminateCall(hf, addr);
}
bt_status_t bt_hfp_hf_control_call(bt_instance_t* ins, bt_address_t* addr, hfp_call_control_t chld, uint8_t index)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_controlCall(hf, addr, chld, index);
}
bt_status_t bt_hfp_hf_query_current_calls(bt_instance_t* ins, bt_address_t* addr, hfp_current_call_t** calls, int* num, bt_allocator_t allocator)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_queryCurrentCalls(hf, addr, calls, num, allocator);
}
bt_status_t bt_hfp_hf_send_at_cmd(bt_instance_t* ins, bt_address_t* addr, const char* cmd)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_sendAtCmd(hf, addr, cmd);
}

View File

@ -0,0 +1,117 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "hid_device_api"
#include <stdint.h>
#include "bluetooth.h"
#include "bt_hid_device.h"
#include "bt_profile.h"
#include "hid_device_callbacks_stub.h"
#include "hid_device_proxy.h"
#include "hid_device_stub.h"
#include "utils/log.h"
void* bt_hid_device_register_callbacks(bt_instance_t* ins, const hid_device_callbacks_t* callbacks)
{
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
IBtHiddCallbacks* cbks = BtHiddCallbacks_new(callbacks);
AIBinder* binder = BtHiddCallbacks_getBinder(cbks);
if (!binder) {
BtHiddCallbacks_delete(cbks);
return NULL;
}
void* remote_cbks = BpBtHidd_registerCallback(hidd, binder);
if (!remote_cbks) {
BtHiddCallbacks_delete(cbks);
return NULL;
}
cbks->cookie = remote_cbks;
return cbks;
}
bool bt_hid_device_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
IBtHiddCallbacks* cbks = cookie;
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
bool ret = BpBtHidd_unRegisterCallback(hidd, cbks->cookie);
if (ret)
BtHiddCallbacks_delete(cbks);
return ret;
}
bt_status_t bt_hid_device_register_app(bt_instance_t* ins, hid_device_sdp_settings_t* sdp, bool le_hid)
{
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
return BpBtHidd_registerApp(hidd, sdp, le_hid);
}
bt_status_t bt_hid_device_unregister_app(bt_instance_t* ins)
{
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
return BpBtHidd_unregisterApp(hidd);
}
bt_status_t bt_hid_device_connect(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
return BpBtHidd_connect(hidd, addr);
}
bt_status_t bt_hid_device_disconnect(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
return BpBtHidd_disconnect(hidd, addr);
}
bt_status_t bt_hid_device_send_report(bt_instance_t* ins, bt_address_t* addr, uint8_t rpt_id, uint8_t* rpt_data, int rpt_size)
{
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
return BpBtHidd_sendReport(hidd, addr, rpt_id, rpt_data, rpt_size);
}
bt_status_t bt_hid_device_response_report(bt_instance_t* ins, bt_address_t* addr, uint8_t rpt_type, uint8_t* rpt_data, int rpt_size)
{
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
return BpBtHidd_responseReport(hidd, addr, rpt_type, rpt_data, rpt_size);
}
bt_status_t bt_hid_device_report_error(bt_instance_t* ins, bt_address_t* addr, hid_status_error_t error)
{
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
return BpBtHidd_reportError(hidd, addr, error);
}
bt_status_t bt_hid_device_virtual_unplug(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
return BpBtHidd_virtualUnplug(hidd, addr);
}

View File

@ -0,0 +1,77 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "adv"
#include <stdlib.h>
#include "adapter_proxy.h"
#include "adapter_stub.h"
#include "advertiser_callbacks_stub.h"
#include "bluetooth.h"
#include "bt_le_advertiser.h"
#include "bt_list.h"
#include "utils/log.h"
bt_advertiser_t* bt_le_start_advertising(bt_instance_t* ins,
ble_adv_params_t* params,
uint8_t* adv_data,
uint16_t adv_len,
uint8_t* scan_rsp_data,
uint16_t scan_rsp_len,
advertiser_callback_t* cbs)
{
BpBtAdapter* bpAdapter = ins->adapter_proxy;
IBtAdvertiserCallbacks* cbks = BtAdvertiserCallbacks_new(cbs);
AIBinder* binder = BtAdvertiserCallbacks_getBinder(cbks);
if (!binder) {
BtAdvertiserCallbacks_delete(cbks);
return NULL;
}
void* rmt_adver = BpBtAdapter_startAdvertising(bpAdapter, params,
adv_data, adv_len,
scan_rsp_data,
scan_rsp_len, binder);
AIBinder_decStrong(binder);
if (!rmt_adver) {
BtAdvertiserCallbacks_delete(cbks);
return NULL;
}
cbks->cookie = rmt_adver;
return (bt_advertiser_t*)cbks;
}
void bt_le_stop_advertising(bt_instance_t* ins, bt_advertiser_t* adver)
{
BpBtAdapter* bpAdapter = ins->adapter_proxy;
IBtAdvertiserCallbacks* cbks = adver;
BpBtAdapter_stopAdvertising(bpAdapter, cbks->cookie);
}
void bt_le_stop_advertising_id(bt_instance_t* ins, uint8_t adv_id)
{
BpBtAdapter* bpAdapter = ins->adapter_proxy;
BpBtAdapter_stopAdvertisingId(bpAdapter, adv_id);
}
bool bt_le_advertising_is_supported(bt_instance_t* ins)
{
return false;
}

View File

@ -0,0 +1,73 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "adv"
#include <stdlib.h>
#include "adapter_proxy.h"
#include "adapter_stub.h"
#include "bluetooth.h"
#include "bt_le_scan.h"
#include "bt_list.h"
#include "scanner_callbacks_stub.h"
#include "utils/log.h"
bt_scanner_t* bt_le_start_scan(bt_instance_t* ins, const scanner_callbacks_t* cbs)
{
return bt_le_start_scan_settings(ins, NULL, cbs);
}
bt_scanner_t* bt_le_start_scan_settings(bt_instance_t* ins,
ble_scan_settings_t* settings,
const scanner_callbacks_t* cbs)
{
BpBtAdapter* bpAdapter = ins->adapter_proxy;
void* rmt_scanner = NULL;
IBtScannerCallbacks* cbks = BtScannerCallbacks_new(cbs);
AIBinder* binder = BtScannerCallbacks_getBinder(cbks);
if (!binder) {
BtScannerCallbacks_delete(cbks);
return NULL;
}
if (settings)
rmt_scanner = BpBtAdapter_startScanSettings(bpAdapter, settings, binder);
else
rmt_scanner = BpBtAdapter_startScan(bpAdapter, binder);
AIBinder_decStrong(binder);
if (!rmt_scanner) {
BtScannerCallbacks_delete(cbks);
return NULL;
}
cbks->cookie = rmt_scanner;
return (bt_scanner_t*)cbks;
}
void bt_le_stop_scan(bt_instance_t* ins, bt_scanner_t* scanner)
{
BpBtAdapter* bpAdapter = ins->adapter_proxy;
IBtScannerCallbacks* cbks = scanner;
BpBtAdapter_stopScan(bpAdapter, cbks->cookie);
}
bool bt_le_scan_is_supported(bt_instance_t* ins)
{
return false;
}

75
framework/binder/bt_pan.c Normal file
View File

@ -0,0 +1,75 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "pan_api"
#include <stdint.h>
#include "bluetooth.h"
#include "bt_pan.h"
#include "bt_profile.h"
#include "pan_callbacks_stub.h"
#include "pan_proxy.h"
#include "pan_stub.h"
#include "utils/log.h"
void* bt_pan_register_callbacks(bt_instance_t* ins, const pan_callbacks_t* callbacks)
{
BpBtPan* pan = (BpBtPan*)bluetooth_get_proxy(ins, PROFILE_PANU);
IBtPanCallbacks* cbks = BtPanCallbacks_new(callbacks);
AIBinder* binder = BtPanCallbacks_getBinder(cbks);
if (!binder) {
BtPanCallbacks_delete(cbks);
return NULL;
}
void* remote_cbks = BpBtPan_registerCallback(pan, binder);
if (!remote_cbks) {
BtPanCallbacks_delete(cbks);
return NULL;
}
cbks->cookie = remote_cbks;
return cbks;
}
bool bt_pan_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
IBtPanCallbacks* cbks = cookie;
BpBtPan* pan = (BpBtPan*)bluetooth_get_proxy(ins, PROFILE_PANU);
bool ret = BpBtPan_unRegisterCallback(pan, cbks->cookie);
if (ret)
BtPanCallbacks_delete(cbks);
return ret;
}
bt_status_t bt_pan_connect(bt_instance_t* ins, bt_address_t* addr, uint8_t dst_role, uint8_t src_role)
{
BpBtPan* pan = (BpBtPan*)bluetooth_get_proxy(ins, PROFILE_PANU);
return BpBtPan_connect(pan, addr, dst_role, src_role);
}
bt_status_t bt_pan_disconnect(bt_instance_t* ins, bt_address_t* addr)
{
BpBtPan* pan = (BpBtPan*)bluetooth_get_proxy(ins, PROFILE_PANU);
return BpBtPan_disconnect(pan, addr);
}

93
framework/binder/bt_spp.c Normal file
View File

@ -0,0 +1,93 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "spp_api"
#include <stdint.h>
#include "bluetooth.h"
#include "bt_profile.h"
#include "bt_spp.h"
#include "spp_callbacks_stub.h"
#include "spp_proxy.h"
#include "spp_stub.h"
#include "utils/log.h"
void* bt_spp_register_app(bt_instance_t* ins, const spp_callbacks_t* callbacks)
{
BpBtSpp* spp = (BpBtSpp*)bluetooth_get_proxy(ins, PROFILE_SPP);
IBtSppCallbacks* cbks = BtSppCallbacks_new(callbacks);
AIBinder* binder = BtSppCallbacks_getBinder(cbks);
if (!binder) {
BtSppCallbacks_delete(cbks);
return NULL;
}
void* handle = BpBtSpp_registerApp(spp, binder);
if (!handle) {
BtSppCallbacks_delete(cbks);
return NULL;
}
cbks->cookie = handle;
return cbks;
}
bt_status_t bt_spp_unregister_app(bt_instance_t* ins, void* handle)
{
IBtSppCallbacks* cbks = handle;
BpBtSpp* spp = (BpBtSpp*)bluetooth_get_proxy(ins, PROFILE_SPP);
bt_status_t status = BpBtSpp_unRegisterApp(spp, cbks->cookie);
if (status == BT_STATUS_SUCCESS)
BtSppCallbacks_delete(cbks);
return status;
}
bt_status_t bt_spp_server_start(bt_instance_t* ins, void* handle, uint16_t scn, bt_uuid_t* uuid, uint8_t max_connection)
{
IBtSppCallbacks* cbks = handle;
BpBtSpp* spp = (BpBtSpp*)bluetooth_get_proxy(ins, PROFILE_SPP);
return BpBtSpp_serverStart(spp, cbks->cookie, scn, uuid, max_connection);
}
bt_status_t bt_spp_server_stop(bt_instance_t* ins, void* handle, uint16_t scn)
{
IBtSppCallbacks* cbks = handle;
BpBtSpp* spp = (BpBtSpp*)bluetooth_get_proxy(ins, PROFILE_SPP);
return BpBtSpp_serverStop(spp, cbks->cookie, scn);
}
bt_status_t bt_spp_connect(bt_instance_t* ins, void* handle, bt_address_t* addr, int16_t scn, bt_uuid_t* uuid, uint16_t* port)
{
IBtSppCallbacks* cbks = handle;
BpBtSpp* spp = (BpBtSpp*)bluetooth_get_proxy(ins, PROFILE_SPP);
return BpBtSpp_connect(spp, cbks->cookie, addr, scn, uuid, port);
}
bt_status_t bt_spp_disconnect(bt_instance_t* ins, void* handle, bt_address_t* addr, uint16_t port)
{
IBtSppCallbacks* cbks = handle;
BpBtSpp* spp = (BpBtSpp*)bluetooth_get_proxy(ins, PROFILE_SPP);
return BpBtSpp_disconnect(spp, cbks->cookie, addr, port);
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,230 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "bt_addr.h"
#include "bt_debug.h"
#include "bt_list.h"
#include "bt_utils.h"
#include "advertiser_data.h"
typedef struct advertiser_data_ {
bt_list_t* data;
uint8_t* buffer;
} advertiser_data_t;
static void advertiser_data_calc_len(void* data, void* context)
{
adv_data_t* adata = data;
*(uint16_t*)context += adata->len + 1;
}
advertiser_data_t* advertiser_data_new(void)
{
advertiser_data_t* ad = malloc(sizeof(advertiser_data_t));
if (!ad)
return NULL;
ad->data = bt_list_new((bt_list_free_cb_t)free);
ad->buffer = NULL;
return ad;
}
void advertiser_data_free(advertiser_data_t* ad)
{
if (ad->buffer)
free(ad->buffer);
bt_list_free(ad->data);
free(ad);
}
uint8_t* advertiser_data_build(advertiser_data_t* ad, uint16_t* len)
{
uint16_t total_len = 0;
bt_list_node_t* node;
uint8_t* p;
if (ad->buffer)
free(ad->buffer);
if (!bt_list_length(ad->data))
return NULL;
bt_list_foreach(ad->data, advertiser_data_calc_len, &total_len);
*len = total_len;
ad->buffer = malloc(total_len);
p = ad->buffer;
for (node = bt_list_head(ad->data); node != NULL;
node = bt_list_next(ad->data, node)) {
adv_data_t* adata = bt_list_node(node);
memcpy(p, adata, adata->len + 1);
p += adata->len + 1;
}
return ad->buffer;
}
void advertiser_data_set_name(advertiser_data_t* ad, const char* name)
{
uint8_t name_len = strlen(name);
adv_data_t* data = zalloc(sizeof(adv_data_t) + name_len + 1);
if (name_len > BT_LE_AD_NAME_LEN) {
name_len = BT_LE_AD_NAME_LEN;
data->type = BT_AD_NAME_SHORT;
} else
data->type = BT_AD_NAME_COMPLETE;
data->len = name_len + 1;
memcpy(data->data, name, name_len);
bt_list_add_tail(ad->data, data);
}
void advertiser_data_set_flags(advertiser_data_t* ad, uint8_t flags)
{
adv_data_t* data = malloc(sizeof(adv_data_t) + 1);
data->len = 2;
data->type = BT_AD_FLAGS;
data->data[0] = flags;
bt_list_add_tail(ad->data, data);
}
void advertiser_data_set_appearance(advertiser_data_t* ad, uint16_t appearance)
{
adv_data_t* data = malloc(sizeof(adv_data_t) + 2);
uint8_t* p = data->data;
data->len = 3;
data->type = BT_AD_GAP_APPEARANCE;
UINT16_TO_STREAM(p, appearance);
bt_list_add_tail(ad->data, data);
}
void advertiser_data_add_data(advertiser_data_t* ad, uint8_t type, uint8_t* data, uint8_t len)
{
adv_data_t* adata = malloc(sizeof(adv_data_t) + len);
adata->type = type;
adata->len = len;
memcpy(adata->data, data, len);
bt_list_add_tail(ad->data, adata);
}
void advertiser_data_remove_data(advertiser_data_t* ad, uint8_t type, uint8_t* data, uint8_t len)
{
}
void advertiser_data_add_manufacture_data(advertiser_data_t* ad,
uint16_t manufacture_id,
uint8_t* data, uint8_t length)
{
adv_data_t* mdata = malloc(sizeof(adv_data_t) + 2 + length);
uint8_t* p = mdata->data;
mdata->len = length + 2 + 1;
mdata->type = BT_AD_MANUFACTURER_DATA;
UINT16_TO_STREAM(p, manufacture_id);
memcpy(p, data, length);
bt_list_add_tail(ad->data, mdata);
}
bool advertiser_data_add_service_uuid(advertiser_data_t* ad, const bt_uuid_t* uuid)
{
adv_data_t* data;
uint8_t* p;
switch (uuid->type) {
case BT_UUID16_TYPE:
data = malloc(sizeof(adv_data_t) + 2);
data->len = 2 + 1;
data->type = BT_AD_UUID16_ALL;
p = data->data;
UINT16_TO_STREAM(p, uuid->val.u16);
break;
case BT_UUID32_TYPE:
data = malloc(sizeof(adv_data_t) + 4);
data->len = 4 + 1;
data->type = BT_AD_UUID32_ALL;
p = data->data;
UINT32_TO_STREAM(p, uuid->val.u32);
case BT_UUID128_TYPE:
data = malloc(sizeof(adv_data_t) + 16);
data->len = 16 + 1;
data->type = BT_AD_UUID128_ALL;
memcpy(data->data, uuid->val.u128, 16);
break;
default:
return false;
}
bt_list_add_tail(ad->data, data);
return true;
}
bool advertiser_data_add_service_data(advertiser_data_t* ad,
const bt_uuid_t* uuid,
uint8_t* data, uint8_t len)
{
adv_data_t* sdata;
uint8_t* p;
switch (uuid->type) {
case BT_UUID16_TYPE:
sdata = malloc(sizeof(adv_data_t) + len + 2);
sdata->len = 2 + 1;
sdata->type = BT_AD_SERVICE_DATA16;
p = sdata->data;
UINT16_TO_STREAM(p, uuid->val.u16);
break;
case BT_UUID32_TYPE:
sdata = malloc(sizeof(adv_data_t) + len + 4);
sdata->len = 4 + 1;
sdata->type = BT_AD_SERVICE_DATA32;
p = sdata->data;
UINT32_TO_STREAM(p, uuid->val.u32);
case BT_UUID128_TYPE:
sdata = malloc(sizeof(adv_data_t) + len + 16);
sdata->len = 16 + 1;
sdata->type = BT_AD_SERVICE_DATA128;
memcpy(sdata->data, uuid->val.u128, 16);
p = sdata->data + 16;
break;
default:
return false;
}
memcpy(p, data, len);
sdata->len += len;
bt_list_add_tail(ad->data, sdata);
return true;
}

View File

@ -0,0 +1,215 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdbool.h>
#include <stdint.h>
#include "advertiser_data.h"
#include "bt_debug.h"
typedef struct {
uint8_t ad_type;
const char* desc;
} ad_type_desc_t;
static const ad_type_desc_t ad_type_map[] = {
{ BT_AD_FLAGS, "Flags" },
{ BT_AD_UUID16_SOME, "Incomplete List of 16­bit Service Class UUIDs" },
{ BT_AD_UUID16_ALL, "Complete List of 16­bit Service Class UUIDs" },
{ BT_AD_UUID32_SOME, "Incomplete List of 32­bit Service Class UUIDs" },
{ BT_AD_UUID32_ALL, "Complete List of 32­bit Service Class UUIDs" },
{ BT_AD_UUID128_SOME, "Incomplete List of 128­bit Service Class UUIDs" },
{ BT_AD_UUID128_ALL, "Complete List of 128­bit Service Class UUIDs" },
{ BT_AD_NAME_SHORT, "Shortened Local Name" },
{ BT_AD_NAME_COMPLETE, "Complete Local Name" },
{ BT_AD_TX_POWER, "Tx Power Level" },
{ BT_AD_CLASS_OF_DEV, "Class of Device" },
{ BT_AD_SSP_HASH, "Simple Pairing Hash C­192" },
{ BT_AD_SSP_RANDOMIZER, "Simple Pairing Randomizer R­192" },
{ BT_AD_SMP_TK, "Security Manager TK Value" },
{ BT_AD_SMP_OOB_FLAGS, "Security Manager Out of Band Flags" },
{ BT_AD_PERIPHERAL_CONN_INTERVAL, "Peripheral Connection Interval Range" },
{ BT_AD_SOLICIT16, "List of 16­bit Service Solicitation UUIDs" },
{ BT_AD_SOLICIT128, "List of 128­bit Service Solicitation UUIDs" },
{ BT_AD_SERVICE_DATA16, "Service Data ­ 16­bit UUID" },
{ BT_AD_PUBLIC_ADDRESS, "Public Target Address" },
{ BT_AD_RANDOM_ADDRESS, "Random Target Address" },
{ BT_AD_GAP_APPEARANCE, "Appearance" },
{ BT_AD_ADVERTISING_INTERVAL, "Advertising Interval" },
{ BT_AD_LE_DEVICE_ADDRESS, "LE Bluetooth Device Address" },
{ BT_AD_LE_ROLE, "LE Role" },
{ BT_AD_SSP_HASH_P256, "Simple Pairing Hash C­256" },
{ BT_AD_SSP_RANDOMIZER_P256, "Simple Pairing Randomizer R­256" },
{ BT_AD_SOLICIT32, "List of 32­bit Service Solicitation UUIDs" },
{ BT_AD_SERVICE_DATA32, "Service Data ­ 32­bit UUID" },
{ BT_AD_SERVICE_DATA128, "Service Data ­ 128­bit UUID" },
{ BT_AD_LE_SC_CONFIRM_VALUE, "LE Secure Connections Confirmation Value" },
{ BT_AD_LE_SC_RANDOM_VALUE, "LE Secure Connections Random Value" },
{ BT_AD_URI, "URI" },
{ BT_AD_INDOOR_POSITIONING, "Indoor Positioning" },
{ BT_AD_TRANSPORT_DISCOVERY, "Transport Discovery Data" },
{ BT_AD_LE_SUPPORTED_FEATURES, "LE Supported Features" },
{ BT_AD_CHANNEL_MAP_UPDATE_IND, "Channel Map Update Indication" },
{ BT_AD_MESH_PROV, "PB­ADV" },
{ BT_AD_MESH_DATA, "Mesh Message" },
{ BT_AD_MESH_BEACON, "Mesh Beacon" },
{ BT_AD_BIG_INFO, "BIGInfo" },
{ BT_AD_BROADCAST_CODE, "Broadcast_Code" },
{ BT_AD_RESOLVABLE_SET_IDENTIFIER, "Resolvable Set Identifier" },
{ BT_AD_ADV_INTERVAL_LONG, "Advertising Interval ­ long" },
{ BT_AD_BROADCAST_NAME, "Broadcast_Name" },
{ BT_AD_ENCRYPTED_ADV_DATA, "Encrypted Advertising Data" },
{ BT_AD_PERIODIC_ADV_RSP_TIMING, "Periodic Advertising Response Timing Information" },
{ BT_AD_3D_INFO_DATA, "3D Information Data" },
{ BT_AD_MANUFACTURER_DATA, "Manufacturer Specific Data" },
};
static const char* show_ad_type_desc(uint8_t type)
{
for (int i = 0; i < sizeof(ad_type_map) / sizeof(ad_type_map[0]); i++) {
if (ad_type_map[i].ad_type == type)
return ad_type_map[i].desc;
}
return "Unknown";
}
static void advertiser_data_info(adv_data_t* ad)
{
if (ad->len < 1) {
return;
}
syslog(4, "AdvType:(%s)\n", show_ad_type_desc(ad->type));
BT_DUMPBUFFER("AdvData:", ad->data, ad->len - 1);
switch (ad->type) {
case BT_AD_FLAGS:
break;
case BT_AD_UUID16_SOME:
break;
case BT_AD_UUID16_ALL:
break;
case BT_AD_UUID32_SOME:
break;
case BT_AD_UUID32_ALL:
break;
case BT_AD_UUID128_SOME:
break;
case BT_AD_UUID128_ALL:
break;
case BT_AD_NAME_SHORT:
break;
case BT_AD_NAME_COMPLETE:
break;
case BT_AD_TX_POWER:
break;
case BT_AD_CLASS_OF_DEV:
break;
case BT_AD_SSP_HASH:
break;
case BT_AD_SSP_RANDOMIZER:
break;
case BT_AD_SMP_TK:
/* if ad->len == 8, ad type is SMP_TK */
break;
case BT_AD_SMP_OOB_FLAGS:
break;
case BT_AD_PERIPHERAL_CONN_INTERVAL:
break;
case BT_AD_SOLICIT16:
break;
case BT_AD_SOLICIT128:
break;
case BT_AD_SERVICE_DATA16:
break;
case BT_AD_PUBLIC_ADDRESS:
break;
case BT_AD_RANDOM_ADDRESS:
break;
case BT_AD_GAP_APPEARANCE:
break;
case BT_AD_ADVERTISING_INTERVAL:
break;
case BT_AD_LE_DEVICE_ADDRESS:
break;
case BT_AD_LE_ROLE:
break;
case BT_AD_SSP_HASH_P256:
break;
case BT_AD_SSP_RANDOMIZER_P256:
break;
case BT_AD_SOLICIT32:
break;
case BT_AD_SERVICE_DATA32:
break;
case BT_AD_SERVICE_DATA128:
break;
case BT_AD_LE_SC_CONFIRM_VALUE:
break;
case BT_AD_LE_SC_RANDOM_VALUE:
break;
case BT_AD_URI:
break;
case BT_AD_INDOOR_POSITIONING:
break;
case BT_AD_TRANSPORT_DISCOVERY:
break;
case BT_AD_LE_SUPPORTED_FEATURES:
break;
case BT_AD_CHANNEL_MAP_UPDATE_IND:
break;
case BT_AD_MESH_PROV:
break;
case BT_AD_MESH_DATA:
break;
case BT_AD_MESH_BEACON:
break;
case BT_AD_BIG_INFO:
break;
case BT_AD_BROADCAST_CODE:
break;
case BT_AD_RESOLVABLE_SET_IDENTIFIER:
break;
case BT_AD_ADV_INTERVAL_LONG:
break;
case BT_AD_BROADCAST_NAME:
break;
case BT_AD_ENCRYPTED_ADV_DATA:
break;
case BT_AD_PERIODIC_ADV_RSP_TIMING:
break;
case BT_AD_3D_INFO_DATA:
break;
case BT_AD_MANUFACTURER_DATA:
break;
default:
break;
}
}
bool advertiser_data_dump(uint8_t* data, uint16_t len, ad_dump_cb_t dump)
{
uint16_t offset = 0;
while (offset < len) {
adv_data_t* ad = (adv_data_t*)&data[offset];
advertiser_data_info(ad);
offset += ad->len + 1;
};
return true;
}

115
framework/common/bt_addr.c Normal file
View File

@ -0,0 +1,115 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bt_addr.h"
static const bt_address_t bt_addr_empty = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
};
static char g_bdaddr_str[18];
static int bachk(const char* str)
{
if (!str)
return -1;
if (strlen(str) != 17)
return -1;
while (*str) {
if (!isxdigit(*str++))
return -1;
if (!isxdigit(*str++))
return -1;
if (*str == 0)
break;
if (*str++ != ':')
return -1;
}
return 0;
}
bool bt_addr_is_empty(const bt_address_t* addr)
{
return memcmp(addr->addr, bt_addr_empty.addr, BT_ADDR_LENGTH) == 0;
}
void bt_addr_set_empty(bt_address_t* addr)
{
assert(addr != NULL);
memcpy(addr, &bt_addr_empty, sizeof(bt_address_t));
}
int bt_addr_compare(const bt_address_t* a, const bt_address_t* b)
{
return memcmp(a, b, sizeof(bt_address_t));
}
int bt_addr_ba2str(const bt_address_t* addr, char* str)
{
return sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
addr->addr[5], addr->addr[4], addr->addr[3],
addr->addr[2], addr->addr[1], addr->addr[0]);
}
char* bt_addr_bastr(const bt_address_t* addr)
{
if (!addr) {
return NULL;
}
bt_addr_ba2str(addr, g_bdaddr_str);
g_bdaddr_str[17] = '\0';
return g_bdaddr_str;
}
int bt_addr_str2ba(const char* str, bt_address_t* addr)
{
int i;
if (bachk(str) < 0) {
memset(addr, 0, sizeof(bt_address_t));
return -1;
}
for (i = 5; i >= 0; i--, str += 3)
addr->addr[i] = strtol(str, NULL, 16);
return 0;
}
void bt_addr_set(bt_address_t* addr, const uint8_t* bd)
{
memcpy(addr->addr, bd, 6);
}
void bt_addr_swap(const bt_address_t* src, bt_address_t* dest)
{
for (int i = 0; i < 6; i++)
dest->addr[5 - i] = src->addr[i];
}

View File

@ -0,0 +1,51 @@
/****************************************************************************
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include "bt_hash.h"
#define HASH4 h = ((h << 5) + h + *key++);
uint32_t bt_hash4(const void* keyarg, size_t len)
{
const uint8_t* key = keyarg;
uint32_t h = 0;
size_t loop;
if (len > 0) {
loop = (len + 8 - 1) >> 3;
switch (len & (8 - 1)) {
case 0:
do {
HASH4;
case 7:
HASH4;
case 6:
HASH4;
case 5:
HASH4;
case 4:
HASH4;
case 3:
HASH4;
case 2:
HASH4;
case 1:
HASH4;
} while (--loop);
}
}
return h;
}

View File

@ -0,0 +1,32 @@
/****************************************************************************
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#ifndef __BT_HASH_H__
#define __BT_HASH_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdio.h>
uint32_t bt_hash4(const void* keyarg, size_t len);
#ifdef __cplusplus
}
#endif
#endif /* __BT_HASH_H__ */

View File

@ -0,0 +1,59 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#ifndef _BT_INTERNAL_H__
#define _BT_INTERNAL_H__
#include "bt_config.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef BTSYMBOLS
#undef BTSYMBOLS
#endif
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_SOCKET_IPC
#define BTSYMBOLS(s) server_##s
#else
#define BTSYMBOLS(s) s
#endif
#if defined(CONFIG_CPU_BIT64) // CONFIG_CPU_BIT64
#define PTR uint64_t
#define PRTx PRIx64
#if !defined(INT2PTR)
#define INT2PTR(pt) (pt)(uint64_t) // For example, INT2PTR(pt)(int): (int)=>uint64_t=>(pt)/pointer type
#endif
#if !defined(PTR2INT)
#define PTR2INT(it) (it)(uint64_t) // For example, PTR2INT(it)(pointer): (pointer)=>uint64_t=>(it)/int type
#endif
#else // CONFIG_CPU_BIT32 and others
#define PTR uint32_t
#define PRTx PRIx32
#if !defined(INT2PTR)
#define INT2PTR(pt) (pt)(uint32_t) // For example, INT2PTR(pt)(int): (int)=>uint32_t=>(pt)/pointer type
#endif
#if !defined(PTR2INT)
#define PTR2INT(it) (it)(uint32_t) // For example, PTR2INT(it)(pointer): (pointer)=>uint32_t=>(it)/int type
#endif
#endif // End of else
#ifdef __cplusplus
}
#endif
#endif /* _BT_INTERNAL_H__ */

224
framework/common/bt_list.c Normal file
View File

@ -0,0 +1,224 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include "bt_list.h"
typedef struct _bt_list {
struct list_node list;
size_t length;
bt_list_free_cb_t free_cb;
} bt_list_t;
typedef struct _bt_list_node {
struct list_node node;
void* data;
} bt_list_node_t;
bt_list_t* bt_list_new(bt_list_free_cb_t cb)
{
bt_list_t* list = malloc(sizeof(bt_list_t));
if (!list)
return NULL;
list->length = 0;
list->free_cb = cb;
list_initialize(&list->list);
return list;
}
void bt_list_free(bt_list_t* list)
{
if (!list)
return;
bt_list_clear(list);
list_delete(&list->list);
free(list);
}
void bt_list_clear(bt_list_t* list)
{
assert(list);
struct list_node* node;
struct list_node* tmp;
list_for_every_safe(&list->list, node, tmp)
{
bt_list_node_t* bt_node = (bt_list_node_t*)node;
list_delete(&bt_node->node);
if (list->free_cb)
list->free_cb(bt_node->data);
free(bt_node);
list->length--;
}
}
bool bt_list_is_empty(bt_list_t* list)
{
assert(list);
return list->length == 0;
}
size_t bt_list_length(bt_list_t* list)
{
assert(list);
return list->length;
}
bt_list_node_t* bt_list_head(bt_list_t* list)
{
assert(list);
return (bt_list_node_t*)list_peek_head(&list->list);
}
bt_list_node_t* bt_list_tail(bt_list_t* list)
{
assert(list);
return (bt_list_node_t*)list_peek_tail(&list->list);
}
bt_list_node_t* bt_list_next(bt_list_t* list, bt_list_node_t* bt_node)
{
assert(list);
if (!bt_node)
return NULL;
return (bt_list_node_t*)list_next(&list->list, &bt_node->node);
}
void* bt_list_node(bt_list_node_t* bt_node)
{
assert(bt_node);
if (!bt_node)
return NULL;
return bt_node->data;
}
void bt_list_add_head(bt_list_t* list, void* data)
{
assert(list);
bt_list_node_t* node = malloc(sizeof(bt_list_node_t));
assert(node);
node->data = data;
list_add_head(&list->list, &node->node);
list->length++;
}
void bt_list_add_tail(bt_list_t* list, void* data)
{
assert(list);
bt_list_node_t* node = malloc(sizeof(bt_list_node_t));
assert(node);
node->data = data;
list_add_tail(&list->list, &node->node);
list->length++;
}
void bt_list_remove_node(bt_list_t* list, bt_list_node_t* node)
{
list_delete(&node->node);
list->length--;
if (list->free_cb)
list->free_cb(node->data);
free(node);
}
void bt_list_remove(bt_list_t* list, void* data)
{
assert(list);
struct list_node* node;
struct list_node* tmp;
list_for_every_safe(&list->list, node, tmp)
{
bt_list_node_t* bt_node = (bt_list_node_t*)node;
if (bt_node->data == data) {
list_delete(&bt_node->node);
if (list->free_cb)
list->free_cb(bt_node->data);
free(bt_node);
list->length--;
break;
}
}
}
void bt_list_move(bt_list_t* src, bt_list_t* dst, void* data, bool move_to_head)
{
assert(src);
assert(dst);
struct list_node* node;
struct list_node* tmp;
list_for_every_safe(&src->list, node, tmp)
{
bt_list_node_t* bt_node = (bt_list_node_t*)node;
if (bt_node->data != data)
continue;
list_delete(&bt_node->node);
src->length--;
if (move_to_head) {
list_add_head(&dst->list, &bt_node->node);
} else {
list_add_tail(&dst->list, &bt_node->node);
}
dst->length++;
break;
}
}
void bt_list_foreach(bt_list_t* list, bt_list_iter_cb cb, void* context)
{
assert(list);
struct list_node* node;
struct list_node* tmp;
list_for_every_safe(&list->list, node, tmp)
{
bt_list_node_t* bt_node = (bt_list_node_t*)node;
cb(bt_node->data, context);
}
}
void* bt_list_find(bt_list_t* list, bt_list_find_cb cb, void* context)
{
assert(list);
struct list_node* node;
struct list_node* tmp;
list_for_every_safe(&list->list, node, tmp)
{
bt_list_node_t* bt_node = (bt_list_node_t*)node;
if (cb(bt_node->data, context))
return bt_node->data;
}
return NULL;
}

View File

@ -0,0 +1,38 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include <time.h>
#include "bt_time.h"
uint64_t bt_get_os_timestamp_us(void)
{
struct timespec ts;
clock_gettime(CLOCK_BOOTTIME, &ts);
return (uint64_t)(((uint64_t)ts.tv_sec * 1000000L) + ((uint64_t)ts.tv_nsec / 1000));
}
uint32_t bt_get_os_timestamp_ms(void)
{
struct timespec ts;
clock_gettime(CLOCK_BOOTTIME, &ts);
return (uint32_t)((ts.tv_sec * 1000) + (ts.tv_nsec / 1000000UL));
}

View File

@ -0,0 +1,83 @@
/****************************************************************************
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#ifndef __BT_LOG_API_H__
#define __BT_LOG_API_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "bluetooth.h"
#ifndef BTSYMBOLS
#define BTSYMBOLS(s) s
#endif
typedef enum {
BTSNOOP_FILTER_A2DP_AUDIO,
BTSNOOP_FILTER_AVCTP_BROWSING,
BTSNOOP_FILTER_ATT,
BTSNOOP_FILTER_SPP,
BTSNOOP_FILTER_NOCP,
BTSNOOP_FILTER_MAX,
BTSNOOP_FILTER_UNFILTER,
} btsnoop_filter_flag_t;
/**
* @brief Enable bluetooth btsnoop log
*
* @param ins - bluetooth client instance.
*/
void BTSYMBOLS(bluetooth_enable_btsnoop_log)(bt_instance_t* ins);
/**
* @brief Disable bluetooth btsnoop log
*
* @param ins - bluetooth client instance.
*/
void BTSYMBOLS(bluetooth_disable_btsnoop_log)(bt_instance_t* ins);
/**
* @brief Set a filter flag in the btsnoop log
*
* @param ins - bluetooth client instance.
* @param filter_flag - the flag bit for filtering specified data in the btsnoop log.
*/
void BTSYMBOLS(bluetooth_set_btsnoop_filter)(bt_instance_t* ins, btsnoop_filter_flag_t filter_flag);
/**
* @brief Remove a filter flag in the btsnoop log
*
* @param ins - bluetooth client instance.
* @param filter_flag - the flag bit for filtering specified data in the btsnoop log.
*/
void BTSYMBOLS(bluetooth_remove_btsnoop_filter)(bt_instance_t* ins, btsnoop_filter_flag_t filter_flag);
// async
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_ASYNC
#include "bt_async.h"
bt_status_t bluetooth_enable_btsnoop_log_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
bt_status_t bluetooth_disable_btsnoop_log_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
bt_status_t bluetooth_set_btsnoop_filter_async(bt_instance_t* ins, btsnoop_filter_flag_t filter_flag,
bt_status_cb_t cb, void* userdata);
bt_status_t bluetooth_remove_btsnoop_filter_async(bt_instance_t* ins, btsnoop_filter_flag_t filter_flag,
bt_status_cb_t cb, void* userdata);
#endif // CONFIG_BLUETOOTH_FRAMEWORK_ASYNC
#ifdef __cplusplus
}
#endif
#endif /* __BT_LOG_API_H__ */

Some files were not shown because too many files have changed in this diff Show More