Compare commits

..

13 Commits

Author SHA1 Message Date
openvela-robot 65fe56749b Update the ci trigger from pull_request to pull_request_target 2025-01-09 23:57:24 +08:00
openvela-robot 95835120ec update CODEOWNERS, delete xiaoxiang781216 GUIDINGLI 2025-01-02 10:02:58 +08:00
openvela-robot e965a8484f update workflows ci.yml, delete pull_request_review trigger 2024-12-28 00:06:22 +08:00
openvela-robot 096afad711 add .github/CODEOWNERS PULL_REQUEST_TEMPLATE.md 2024-12-27 19:50:46 +08:00
openvela-robot a56ade4782 update ci pull_request types to [opened, reopened, synchronize] 2024-12-24 01:17:36 +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
426 changed files with 2945 additions and 75559 deletions

2
.github/CODEOWNERS vendored
View File

@ -1 +1 @@
* @hyson710 @gzh-terry @chengkai15 @huangyulong3 @zhongzhijie1 @zhangyuan376
* @hyson710

View File

@ -10,5 +10,5 @@ on:
# 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
uses: open-vela/public-actions/.github/workflows/checkpatch.yml@trunk
secrets: inherit

View File

@ -6,11 +6,9 @@ name: CI
on:
pull_request_target:
types: [opened, reopened, synchronize]
issue_comment:
types: [created]
# 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
uses: open-vela/public-actions/.github/workflows/ci.yml@trunk
secrets: inherit

View File

@ -10,4 +10,4 @@ on:
# 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
uses: open-vela/public-actions/.github/workflows/clang-format.yml@trunk

View File

@ -1,11 +0,0 @@
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

View File

@ -49,7 +49,6 @@ frameworkBluetooth_cc_library {
"service/profiles",
"service/profiles/include",
"service/src",
"dfx",
],
static_libs : [

View File

@ -28,182 +28,39 @@ if(CONFIG_BLUETOOTH)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/framework/common/*.c)
list(APPEND CSRCS ${APPEND_FILES})
list(
APPEND
CSRCS
${BLUETOOTH_DIR}/framework/api/bluetooth.c
${BLUETOOTH_DIR}/framework/api/bt_adapter.c
${BLUETOOTH_DIR}/framework/api/bt_device.c)
if(CONFIG_BLUETOOTH_LE_CS)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/api/bt_cs.c)
endif()
if(CONFIG_BLUETOOTH_A2DP_SINK)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/api/bt_a2dp_sink.c)
endif()
if(CONFIG_BLUETOOTH_A2DP_SOURCE)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/api/bt_a2dp_source.c)
endif()
if(CONFIG_BLUETOOTH_AVRCP_TARGET)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/api/bt_avrcp_target.c)
endif()
if(CONFIG_BLUETOOTH_AVRCP_CONTROL)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/api/bt_avrcp_control.c)
endif()
if(CONFIG_BLUETOOTH_HFP_AG)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/api/bt_hfp_ag.c)
endif()
if(CONFIG_BLUETOOTH_HFP_HF)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/api/bt_hfp_hf.c)
endif()
if(CONFIG_BLUETOOTH_SPP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/api/bt_spp.c)
endif()
if(CONFIG_BLUETOOTH_HID_DEVICE)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/api/bt_hid_device.c)
endif()
if(CONFIG_BLUETOOTH_GATT_CLIENT)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/api/bt_gattc.c)
endif()
if(CONFIG_BLUETOOTH_GATT_SERVER)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/api/bt_gatts.c)
endif()
if(CONFIG_BLUETOOTH_L2CAP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/api/bt_l2cap.c)
endif()
if(CONFIG_BLUETOOTH_BLE_ADV)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/api/bt_le_advertiser.c)
endif()
if(CONFIG_BLUETOOTH_BLE_SCAN)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/api/bt_le_scan.c)
endif()
if(CONFIG_BLUETOOTH_LOG)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/api/bt_trace.c)
endif()
if(CONFIG_BLUETOOTH_PAN)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/api/bt_pan.c)
endif()
if(CONFIG_BLUETOOTH_BLE_AUDIO)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/framework/api/bt_lea*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_FRAMEWORK_SOCKET_IPC)
list(
APPEND
CSRCS
${BLUETOOTH_DIR}/service/ipc/bluetooth_ipc.c
${BLUETOOTH_DIR}/framework/socket/bt_device.c
${BLUETOOTH_DIR}/framework/socket/bt_adapter.c
${BLUETOOTH_DIR}/framework/socket/bluetooth.c
${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket.c
${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_manager.c
${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_client.c
${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_server.c
${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_device.c
${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_adapter.c)
if(CONFIG_BLUETOOTH_A2DP_SINK)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/socket/bt_a2dp_sink.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_a2dp_sink.c)
endif()
if(CONFIG_BLUETOOTH_A2DP_SOURCE)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/socket/bt_a2dp_source.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_a2dp_source.c)
endif()
if(CONFIG_BLUETOOTH_AVRCP_TARGET)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/socket/bt_avrcp_target.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_avrcp_target.c)
endif()
if(CONFIG_BLUETOOTH_AVRCP_CONTROL)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/socket/bt_avrcp_control.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_avrcp_control.c)
endif()
if(CONFIG_BLUETOOTH_HFP_HF)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/socket/bt_hfp_hf.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_hfp_hf.c)
endif()
if(CONFIG_BLUETOOTH_HFP_AG)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/socket/bt_hfp_ag.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_hfp_ag.c)
endif()
if(CONFIG_BLUETOOTH_SPP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/socket/bt_spp.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_spp.c)
endif()
if(CONFIG_BLUETOOTH_HID_DEVICE)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/socket/bt_hid_device.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_hid_device.c)
endif()
if(CONFIG_BLUETOOTH_GATT_CLIENT)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/socket/bt_gattc.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_gattc.c)
endif()
if(CONFIG_BLUETOOTH_GATT_SERVER)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/socket/bt_gatts.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_gatts.c)
endif()
if(CONFIG_BLUETOOTH_L2CAP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/socket/bt_l2cap.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_l2cap.c)
endif()
if(CONFIG_BLUETOOTH_BLE_ADV)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/socket/bt_le_advertiser.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_advertiser.c)
endif()
if(CONFIG_BLUETOOTH_BLE_SCAN)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/socket/bt_le_scan.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_scan.c)
endif()
if(CONFIG_BLUETOOTH_PAN)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/socket/bt_pan.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_pan.c)
endif()
if(CONFIG_BLUETOOTH_LOG)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/socket/bt_trace.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_log.c)
endif()
if(CONFIG_BLUETOOTH_LE_CS)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/socket/bt_cs.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/ipc/socket/src/bt_socket_cs.c)
endif()
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/ipc/socket/include)
if (CONFIG_BLUETOOTH_FRAMEWORK_ASYNC)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/framework/socket/async/*.c)
if(CONFIG_BLUETOOTH_FRAMEWORK)
if(CONFIG_BLUETOOTH_FRAMEWORK_LOCAL)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/framework/api/*.c)
list(APPEND CSRCS ${APPEND_FILES})
if(NOT CONFIG_BLUETOOTH_BLE_AUDIO)
file(GLOB EXLUDE_FILES ${BLUETOOTH_DIR}/framework/api/bt_lea*)
list(REMOVE_ITEM CSRCS ${EXLUDE_FILES})
endif()
elseif(CONFIG_BLUETOOTH_FRAMEWORK_SOCKET_IPC)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/framework/api/*.c)
list(APPEND CSRCS ${APPEND_FILES})
if(NOT CONFIG_BLUETOOTH_BLE_AUDIO)
file(GLOB EXLUDE_FILES ${BLUETOOTH_DIR}/framework/api/bt_lea*)
list(REMOVE_ITEM EXCLUDE CSRCS ${EXLUDE_FILES})
endif()
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/ipc/*.c)
list(APPEND CSRCS ${APPEND_FILES})
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/ipc/socket/src/*.c)
list(APPEND CSRCS ${APPEND_FILES})
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/framework/socket/*.c)
list(APPEND CSRCS ${APPEND_FILES})
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/ipc/socket/include)
else()
# Other IPC source files
endif()
endif()
@ -211,11 +68,11 @@ if(CONFIG_BLUETOOTH)
APPEND
CSRCS
${BLUETOOTH_DIR}/service/src/manager_service.c
${BLUETOOTH_DIR}/service/common/index_allocator.c)
if(CONFIG_BLUETOOTH_CONNECTION_MANAGER)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/src/connection_manager.c)
endif()
${BLUETOOTH_DIR}/service/src/power_manager.c
${BLUETOOTH_DIR}/service/vendor/bt_vendor.c
${BLUETOOTH_DIR}/service/common/bt_time.c
${BLUETOOTH_DIR}/service/common/index_allocator.c
${BLUETOOTH_DIR}/service/common/service_loop.c)
if(CONFIG_BLUETOOTH_STORAGE_PROPERTY_SUPPORT)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/common/storage_property.c)
@ -223,34 +80,16 @@ if(CONFIG_BLUETOOTH)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/common/storage.c)
endif()
if(CONFIG_BLUETOOTH_STORAGE_UPDATE)
list(
APPEND
CSRCS
${BLUETOOTH_DIR}/tools/storage_update/storage_version_4.c
${BLUETOOTH_DIR}/tools/storage_update/storage_version_5.c)
endif()
if(CONFIG_BLUETOOTH_DEBUG_MEMORY)
list(APPEND CSRCS ${BLUETOOTH_DIR}/debug/bt_memory.c)
endif()
if(CONFIG_BLUETOOTH_SERVICE)
list(
APPEND
CSRCS
${BLUETOOTH_DIR}/service/common/service_loop.c
${BLUETOOTH_DIR}/service/src/adapter_service.c
${BLUETOOTH_DIR}/service/src/adapter_state.c
${BLUETOOTH_DIR}/service/src/btservice.c
${BLUETOOTH_DIR}/service/src/device.c
${BLUETOOTH_DIR}/service/vendor/bt_vendor.c
${BLUETOOTH_DIR}/service/src/hci_parser.c)
if(CONFIG_BLUETOOTH_BREDR_SUPPORT)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/src/power_manager.c)
endif()
if(CONFIG_BLUETOOTH_BLE_ADV)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/src/advertising.c)
endif()
@ -265,14 +104,6 @@ if(CONFIG_BLUETOOTH)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/src/l2cap_service.c)
endif()
if(CONFIG_LE_DLF_SUPPORT)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/src/connection_manager_dlf.c)
endif()
if(CONFIG_BLUETOOTH_HCI_FILTER)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/vhal/bt_hci_filter.c)
endif()
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/stacks/*.c)
list(APPEND CSRCS ${APPEND_FILES})
@ -283,61 +114,8 @@ if(CONFIG_BLUETOOTH)
endif()
if(CONFIG_BLUETOOTH_STACK_BREDR_ZBLUE OR CONFIG_BLUETOOTH_STACK_LE_ZBLUE)
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/stacks/zephyr/include)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/hci_h4.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_debug_interface.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_zblue.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_adapter_interface.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_connection_manager.c)
if(CONFIG_BLUETOOTH_A2DP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_a2dp_interface.c)
endif()
if(CONFIG_BLUETOOTH_AVRCP_CONTROL OR CONFIG_BLUETOOTH_AVRCP_TARGET)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_avrcp_interface.c)
endif()
if(CONFIG_BLUETOOTH_HFP_HF)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_hfp_hf_interface.c)
endif()
if(CONFIG_BLUETOOTH_HFP_AG)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_hfp_ag_interface.c)
endif()
if(CONFIG_BLUETOOTH_SPP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_spp_interface.c)
endif()
if(CONFIG_BLUETOOTH_HID_DEVICE)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_hid_device_stub.c)
endif()
endif()
if(CONFIG_BLUETOOTH_STACK_LE_ZBLUE)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_adapter_le_interface.c)
if(CONFIG_BLUETOOTH_BLE_ADV)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_le_advertise_interface.c)
endif()
if(CONFIG_BLUETOOTH_BLE_SCAN)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_le_scan_interface.c)
endif()
if(CONFIG_BLUETOOTH_GATT_CLIENT)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_gatt_client_interface.c)
endif()
if(CONFIG_BLUETOOTH_GATT_SERVER)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_gatt_server_interface.c)
endif()
if(CONFIG_BLUETOOTH_LE_CS)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_le_cs_interface.c)
endif()
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/stacks/zephyr/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(NOT CONFIG_BLUETOOTH_BLE_AUDIO)
@ -363,25 +141,17 @@ if(CONFIG_BLUETOOTH)
OR CONFIG_BLUETOOTH_BLE_AUDIO))
list(REMOVE_ITEM CSRCS
${BLUETOOTH_DIR}/service/profiles/system/media_system.c)
else()
file(GLOB APPEND_FILES
${BLUETOOTH_DIR}/service/profiles/audio_interface/*.c)
endif()
file(GLOB APPEND_FILES
${BLUETOOTH_DIR}/service/profiles/audio_interface/*.c)
list(APPEND CSRCS ${APPEND_FILES})
if(CONFIG_BLUETOOTH_GATT)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/gatt/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_GATT_CLIENT)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/profiles/gatt/gattc_event.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/profiles/gatt/gattc_service.c)
if(CONFIG_BLUETOOTH_GATT_CLIENT_DEBUG)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/profiles/gatt/gattc_debug.c)
endif()
endif()
if(CONFIG_BLUETOOTH_GATT_SERVER)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/profiles/gatt/gatts_event.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/profiles/gatt/gatts_service.c)
endif()
if(CONFIG_BLUETOOTH_A2DP)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/a2dp/*.c)
list(APPEND CSRCS ${APPEND_FILES})
@ -504,74 +274,18 @@ if(CONFIG_BLUETOOTH)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_LOG)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/utils/log_server.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/utils/btsnoop_log.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/utils/btsnoop_writer.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/utils/btsnoop_filter.c)
endif()
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/utils/*.c)
list(APPEND CSRCS ${APPEND_FILES})
if(CONFIG_BLUETOOTH_LE_CS)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/cs/*.c)
list(APPEND CSRCS ${APPEND_FILES})
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/profiles/cs)
endif()
if(CONFIG_BLUETOOTH_HCI_FILTER)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/vhal/bt_hci_filter.c)
endif()
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/vhal/bt_vhal.c)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/vhal/*.c)
list(APPEND CSRCS ${APPEND_FILES})
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/vhal)
endif()
if(CONFIG_BLUETOOTH_DEBUG_MEMORY)
list(APPEND CSRCS ${BLUETOOTH_DIR}/debug/bt_memory.c)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE)
if(CONFIG_APP_BT_SAMPLE_CODE_BASIC)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/basic/*.c)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_ENABLE)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/enable/*.c)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_DISCOVERY)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/discovery/*.c)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_CREATEBOND)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/createbond/*.c)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_ACCEPTBOND)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/acceptbond/*.c)
endif()
endif()
if(CONFIG_BLUETOOTH_TOOLS)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/utils.c)
if(CONFIG_BLUETOOTH_FRAMEWORK_ASYNC)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/async/gap.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/async/log.c)
if(CONFIG_BLUETOOTH_BLE_ADV)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/async/adv.c)
endif()
if(CONFIG_BLUETOOTH_BLE_SCAN)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/async/scan.c)
endif()
if(CONFIG_BLUETOOTH_GATT)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/async/gatt_client.c)
endif()
endif()
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/log.c)
if(CONFIG_BLUETOOTH_BLE_ADV)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/adv.c)
@ -589,15 +303,8 @@ if(CONFIG_BLUETOOTH)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/a2dp_source.c)
endif()
if(CONFIG_BLUETOOTH_AVRCP_CONTROL)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/avrcp_control.c)
endif()
if(CONFIG_BLUETOOTH_GATT_CLIENT)
if(CONFIG_BLUETOOTH_GATT)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/gatt_client.c)
endif()
if(CONFIG_BLUETOOTH_GATT_SERVER)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/gatt_server.c)
endif()
@ -609,11 +316,6 @@ if(CONFIG_BLUETOOTH)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/hfp_ag.c)
endif()
if(CONFIG_BLUETOOTH_LOG)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/log.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/debug/bt_trace.c)
endif()
if(CONFIG_BLUETOOTH_SPP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/spp.c)
endif()
@ -657,18 +359,9 @@ if(CONFIG_BLUETOOTH)
if(CONFIG_BLUETOOTH_LEAUDIO_TBS)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/lea_tbs.c)
endif()
if(CONFIG_BLUETOOTH_STORAGE_UPDATE)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/storage_update/storage_tool.c)
endif()
if(CONFIG_BLUETOOTH_LE_CS)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/le_cs.c)
endif()
endif()
list(APPEND INCDIR ${BLUETOOTH_DIR}/framework/include)
list(APPEND INCDIR ${BLUETOOTH_DIR}/framework/common)
if(CONFIG_LIB_DBUS_RPMSG_SERVER_CPUNAME OR CONFIG_OFONO)
list(APPEND INCDIR ${NUTTX_APPS_DIR}/external/dbus/dbus)
@ -700,7 +393,7 @@ if(CONFIG_BLUETOOTH)
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/vendor)
list(APPEND INCDIR ${BLUETOOTH_DIR}/dfx)
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/stacks/include)
if(CONFIG_BLUETOOTH_SERVICE)
if(CONFIG_BLUETOOTH_STACK_BREDR_BLUELET
@ -710,54 +403,51 @@ if(CONFIG_BLUETOOTH)
${NUTTX_APPS_DIR}/external/bluelet/bluelet/src/samples/stack_adapter/inc
)
list(APPEND INCDIR ${NUTTX_APPS_DIR}/vendor/xiaomi/vela/bluelet/inc)
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/stacks/bluelet/include)
list(APPEND INCDIR ${NUTTX_APPS_DIR}/vendor/xiaomi/vela/bluelet/inc)
endif()
if(CONFIG_BLUETOOTH_STACK_BREDR_ZBLUE OR CONFIG_BLUETOOTH_STACK_LE_ZBLUE)
nuttx_add_dependencies(TARGET libbluetooth DEPENDS zblue)
list(APPEND INCDIR ${NUTTX_APPS_DIR}/external/zblue/zblue/include/zephyr)
list(APPEND INCDIR ${NUTTX_APPS_DIR}/external/zblue/zblue/port/include/)
list(APPEND INCDIR
${NUTTX_APPS_DIR}/external/zblue/zblue/port/include/kernel/include)
endif()
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/ipc)
endif()
if (CONFIG_APP_BT_SAMPLE_CODE)
if(CONFIG_APP_BT_SAMPLE_CODE_BASIC)
list(APPEND INCDIR ${BLUETOOTH_DIR}/sample_code/basic)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_ENABLE)
list(APPEND INCDIR ${BLUETOOTH_DIR}/sample_code/enable)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_DISCOVERY)
list(APPEND INCDIR ${BLUETOOTH_DIR}/sample_code/discovery)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_CREATEBOND)
list(APPEND INCDIR ${BLUETOOTH_DIR}/sample_code/createbond)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_ACCEPTBOND)
list(APPEND INCDIR ${BLUETOOTH_DIR}/sample_code/acceptbond)
endif()
endif()
if(CONFIG_BLUETOOTH_TOOLS)
list(APPEND INCDIR ${BLUETOOTH_DIR}/tools)
endif()
if(CONFIG_BLUETOOTH_STORAGE_UPDATE)
list(APPEND INCDIR ${BLUETOOTH_DIR}/tools/storage_update)
endif()
if(CONFIG_ARCH_SIM)
list(APPEND CFLAGS -O0)
endif()
list(APPEND CFLAGS -Wno-strict-prototypes)
if(CONFIG_BLUETOOTH_FEATURE)
set(FEATURE_TOP ${NUTTX_APPS_DIR}/frameworks/runtimes/feature)
list(APPEND INCDIR ${FEATURE_TOP}/include)
list(APPEND INCDIR
${NUTTX_APPS_DIR}/frameworks/connectivity/bluetooth/feature/include)
list(APPEND CSRCS ${BLUETOOTH_DIR}/feature/src/system_bluetooth.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/feature/src/system_bluetooth_impl.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/feature/src/feature_bluetooth_util.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/feature/src/system_bluetooth_bt.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/feature/src/system_bluetooth_bt_impl.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/feature/src/feature_bluetooth_callback.c)
if(CONFIG_BLUETOOTH_A2DP_SINK)
list(APPEND CSRCS
${BLUETOOTH_DIR}/feature/src/system_bluetooth_bt_a2dpsink.c)
list(APPEND CSRCS
${BLUETOOTH_DIR}/feature/src/system_bluetooth_bt_a2dpsink_impl.c)
endif()
endif()
nuttx_add_library(libbluetooth STATIC)
# Add Applications
@ -770,7 +460,7 @@ if(CONFIG_BLUETOOTH)
INCLUDE_DIRECTORIES
${INCDIR}
STACKSIZE
${CONFIG_BLUETOOTH_TASK_STACK_SIZE}
8192
PRIORITY
SCHED_PRIORITY_DEFAULT
COMPILE_FLAGS
@ -779,98 +469,6 @@ if(CONFIG_BLUETOOTH)
libbluetooth)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE)
if(CONFIG_APP_BT_SAMPLE_CODE_BASIC)
nuttx_add_application(
NAME
bt_basic
SRCS
${BLUETOOTH_DIR}/sample_code/basic/basic.c
INCLUDE_DIRECTORIES
${INCDIR}
STACKSIZE
8192
PRIORITY
${SCHED_PRIORITY_DEFAULT}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
libbluetooth)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_ENABLE)
nuttx_add_application(
NAME
bt_enable
SRCS
${BLUETOOTH_DIR}/sample_code/enable/enable.c
INCLUDE_DIRECTORIES
${INCDIR}
STACKSIZE
8192
PRIORITY
${SCHED_PRIORITY_DEFAULT}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
libbluetooth)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_DISCOVERY)
nuttx_add_application(
NAME
bt_discovery
SRCS
${BLUETOOTH_DIR}/sample_code/discovery/discovery.c
INCLUDE_DIRECTORIES
${INCDIR}
STACKSIZE
8192
PRIORITY
${SCHED_PRIORITY_DEFAULT}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
libbluetooth)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_ACCEPTBOND)
nuttx_add_application(
NAME
bt_acceptbond
SRCS
${BLUETOOTH_DIR}/sample_code/acceptbond/acceptbond.c
INCLUDE_DIRECTORIES
${INCDIR}
STACKSIZE
8192
PRIORITY
${SCHED_PRIORITY_DEFAULT}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
libbluetooth)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_CREATEBOND)
nuttx_add_application(
NAME
bt_createbond
SRCS
${BLUETOOTH_DIR}/sample_code/createbond/createbond.c
INCLUDE_DIRECTORIES
${INCDIR}
STACKSIZE
8192
PRIORITY
${SCHED_PRIORITY_DEFAULT}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
libbluetooth)
endif()
endif()
if(CONFIG_BLUETOOTH_TOOLS)
nuttx_add_application(
NAME
@ -905,86 +503,17 @@ if(CONFIG_BLUETOOTH)
libbluetooth)
endif()
if(CONFIG_BLUETOOTH_UPGRADE)
nuttx_add_application(
NAME
bt_upgrade
SRCS
${BLUETOOTH_DIR}/tools/storage_transform.c
INCLUDE_DIRECTORIES
${INCDIR}
STACKSIZE
8192
PRIORITY
${SCHED_PRIORITY_DEFAULT}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
libbluetooth)
endif()
if(CONFIG_BLUETOOTH_STORAGE_UPDATE)
nuttx_add_application(
NAME
bt_storage_update
SRCS
${BLUETOOTH_DIR}/tools/storage_update/storage_update.c
INCLUDE_DIRECTORIES
${INCDIR}
STACKSIZE
8192
PRIORITY
${SCHED_PRIORITY_DEFAULT}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
libbluetooth)
endif()
if(CONFIG_BLUETOOTH_FEATURE)
set(FEATURE_SRCS ${BLUETOOTH_DIR}/feature/src/system_bluetooth_impl.c
${BLUETOOTH_DIR}/feature/src/feature_bluetooth_util.c
${BLUETOOTH_DIR}/feature/src/system_bluetooth_bt_impl.c
${BLUETOOTH_DIR}/feature/src/feature_bluetooth_callback.c)
target_include_directories(libbluetooth PRIVATE ${CMAKE_CURRENT_LIST_DIR}/feature/include)
set(JIDL_PATHS ${BLUETOOTH_DIR}/feature/jdil/bluetooth.jidl
${BLUETOOTH_DIR}/feature/jdil/bluetooth_bt.jidl)
set(FEATURE_NAMES system_bluetooth system_bluetooth_bt)
if(CONFIG_BLUETOOTH_A2DP_SINK)
list(APPEND FEATURE_SRCS ${BLUETOOTH_DIR}/feature/src/system_bluetooth_a2dpsink_impl.c)
list(APPEND JIDL_PATHS ${BLUETOOTH_DIR}/feature/jdil/bluetooth_a2dpsink.jidl)
list(APPEND FEATURE_NAMES system_bluetooth_a2dpsink)
endif()
if(CONFIG_BLUETOOTH_AVRCP_CONTROL)
list(APPEND FEATURE_SRCS ${BLUETOOTH_DIR}/feature/src/system_bluetooth_avrcpcontrol_impl.c)
list(APPEND JIDL_PATHS ${BLUETOOTH_DIR}/feature/jdil/bluetooth_avrcpcontrol.jidl)
list(APPEND FEATURE_NAMES system_bluetooth_avrcpcontrol)
endif()
nuttx_add_jidl(
TARGET
libbluetooth
FEATURE_SRCS
${FEATURE_SRCS}
JIDLS
${JIDL_PATHS}
FEATURE_NAMES
${FEATURE_NAMES}
OUT_SRC_EXT
c)
elseif(CONFIG_BLUETOOTH_FEATURE_ASYNC)
include(nuttx_add_jidl)
set(PY_SCRIPT ${FEATURE_TOP}/tools/jidl/jsongensource.py)
set(BINARY_EXT_MODULES_DIR ${CMAKE_BINARY_DIR}/feature/modules/)
set(JIDL_PATHS ${BLUETOOTH_DIR}/feature/feature_async/jidl/bluetooth.jidl)
set(JIDL_PATHS ${BLUETOOTH_DIR}/feature/jdil/bluetooth.jidl
${BLUETOOTH_DIR}/feature/jdil/bluetooth_bt.jidl)
list(APPEND JIDL_PATHS
${BLUETOOTH_DIR}/feature/feature_async/jidl/bluetooth_ble.jidl)
if(CONFIG_BLUETOOTH_A2DP_SINK)
list(APPEND JIDL_PATHS
${BLUETOOTH_DIR}/feature/jdil/bluetooth_a2dpsink.jidl)
endif()
nuttx_add_jidl(
TARGET
@ -997,7 +526,6 @@ if(CONFIG_BLUETOOTH)
${JIDL_PATHS}
OUT_SRC_EXT
c)
else()
endif()
# Add Dependson

1071
Kconfig

File diff suppressed because it is too large Load Diff

439
Makefile
View File

@ -19,196 +19,43 @@ 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_LE_CS), y)
CSRCS += framework/api/bt_cs.c
endif #CONFIG_BLUETOOTH_LE_CS
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
ifeq ($(CONFIG_BLUETOOTH_FRAMEWORK), y)
ifeq ($(CONFIG_BLUETOOTH_FRAMEWORK_LOCAL), y)
CSRCS += framework/api/*.c
ifeq ($(CONFIG_BLUETOOTH_BLE_AUDIO),)
CSRCS := $(filter-out $(wildcard framework/api/bt_lea*),$(wildcard $(CSRCS)))
endif
else ifeq ($(CONFIG_BLUETOOTH_FRAMEWORK_SOCKET_IPC), y)
CSRCS += framework/api/*.c
ifeq ($(CONFIG_BLUETOOTH_BLE_AUDIO),)
CSRCS := $(filter-out $(wildcard framework/api/bt_lea*),$(wildcard $(CSRCS)))
endif
CSRCS += service/ipc/*.c
CSRCS += service/ipc/socket/src/*.c
CSRCS += framework/socket/*.c
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/ipc/socket/include
else
endif
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
ifeq ($(CONFIG_BLUETOOTH_LE_CS), y)
CSRCS += framework/socket/bt_cs.c
CSRCS += service/ipc/socket/src/bt_socket_cs.c
endif #CONFIG_BLUETOOTH_LE_CS
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_LOG), y)
CSRCS += service/debug/bt_trace.c
endif
ifeq ($(CONFIG_BLUETOOTH_SERVICE), y)
CSRCS += service/common/bt_time.c
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)
@ -222,47 +69,12 @@ 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_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_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
ifeq ($(CONFIG_BLUETOOTH_LE_CS), y)
CSRCS += service/stacks/zephyr/sal_le_cs_interface.c
endif #CONFIG_BLUETOOTH_LE_CS
endif #CONFIG_BLUETOOTH_STACK_LE_ZBLUE
CSRCS += service/stacks/zephyr/*.c
endif
ifeq ($(CONFIG_BLUETOOTH_BLE_AUDIO),)
CSRCS := $(filter-out $(wildcard service/stacks/bluelet/sal_lea_*),$(wildcard $(CSRCS)))
@ -274,23 +86,14 @@ ifeq ($(CONFIG_BLUETOOTH_A2DP),)
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
ifeq ($(CONFIG_BLUETOOTH_GATT_CLIENT_DEBUG), y)
CSRCS += service/profiles/gatt/gattc_debug.c
endif
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
CSRCS += service/profiles/audio_interface/*.c
ifeq ($(CONFIG_BLUETOOTH_GATT), y)
CSRCS += service/profiles/gatt/*.c
endif #CONFIG_BLUETOOTH_GATT
ifeq ($(CONFIG_BLUETOOTH_A2DP), y)
CSRCS += service/profiles/a2dp/*.c
@ -375,64 +178,15 @@ 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_LE_CS), y)
CSRCS += service/profiles/cs/*.c
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/profiles/cs
endif #CONFIG_BLUETOOTH_LE_CS
ifeq ($(CONFIG_BLUETOOTH_HCI_FILTER), y)
CSRCS += service/vhal/bt_hci_filter.c
endif
CSRCS += service/vhal/bt_vhal.c
CSRCS += service/utils/*.c
CSRCS += service/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/log.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
@ -445,15 +199,10 @@ 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)
ifeq ($(CONFIG_BLUETOOTH_GATT), 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
endif #CONFIG_BLUETOOTH_GATT
ifeq ($(CONFIG_BLUETOOTH_HFP_HF), y)
CSRCS += tools/hfp_hf.c
endif #CONFIG_BLUETOOTH_HFP_HF
@ -461,9 +210,7 @@ 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
@ -505,19 +252,10 @@ 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
ifeq ($(CONFIG_BLUETOOTH_LE_CS), y)
CSRCS += tools/le_cs.c
endif
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
@ -536,7 +274,7 @@ CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/pr
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
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/stacks/include
ifeq ($(CONFIG_BLUETOOTH_SERVICE), y)
ifneq ($(CONFIG_BLUETOOTH_STACK_BREDR_BLUELET)$(CONFIG_BLUETOOTH_STACK_LE_BLUELET),)
@ -545,52 +283,23 @@ ifneq ($(CONFIG_BLUETOOTH_STACK_BREDR_BLUELET)$(CONFIG_BLUETOOTH_STACK_LE_BLUELE
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/include/zephyr
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/subsys/bluetooth
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)
STACKSIZE = 8192
MODULE = $(CONFIG_BLUETOOTH)
# if enabled bluetoothd
@ -599,33 +308,6 @@ ifeq ($(CONFIG_BLUETOOTH_SERVER), y)
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
@ -633,16 +315,6 @@ ifeq ($(CONFIG_BLUETOOTH_TOOLS), y)
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))
@ -653,6 +325,7 @@ MAINSRC := $(wildcard $(MAINSRC))
NOEXPORTSRCS = $(ASRCS)$(CSRCS)$(CXXSRCS)$(MAINSRC)
ifeq ($(CONFIG_BLUETOOTH_FEATURE),y)
include $(APPDIR)/frameworks/runtimes/feature/Make.defs
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/feature/include
CSRCS += feature/src/system_bluetooth.c
@ -666,46 +339,20 @@ 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
@python3 $(APPDIR)/frameworks/runtimes/feature/tools/jidl/jsongensource.py \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/jidl/bluetooth.jidl -out-dir \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/src -header system_bluetooth.h -source system_bluetooth.c
@python3 $(APPDIR)/frameworks/runtimes/feature/tools/jidl/jsongensource.py \
$(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
@python3 $(APPDIR)/frameworks/runtimes/feature/tools/jidl/jsongensource.py \
$(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),)

View File

@ -1,166 +0,0 @@
/****************************************************************************
* 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);
}

View File

@ -1,53 +0,0 @@
/****************************************************************************
* 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;
}

View File

@ -1,115 +0,0 @@
/****************************************************************************
* 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 <inttypes.h>
#include <stdatomic.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "utils/log.h"
#ifndef CONFIG_BLUETOOTH_TRACE_BUFFER_SIZE
#define CONFIG_BLUETOOTH_TRACE_BUFFER_SIZE 64
#endif
#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=%" PRIu64 "][LAT=%" PRIu32 "us]\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;
}

View File

@ -1,124 +0,0 @@
############################################################################
# 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()

View File

@ -1,54 +0,0 @@
/****************************************************************************
* 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;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 220 KiB

View File

@ -1,170 +0,0 @@
/****************************************************************************
* 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)
// a2dp
#if defined(CONFIG_BLUETOOTH_DFX) && defined(CONFIG_BLUETOOTH_BREDR_SUPPORT)
#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: a2dpConnError: %s", reason); \
BT_DFX_SEND_A2DP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_A2DP, BT_DFXC_A2DP_CONN), \
"%s:%s", "a2dpConnError", reason); \
} while (0)
#define BT_DFX_A2DP_OFFLOAD_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: a2dpOffloadError: %s", reason); \
BT_DFX_SEND_A2DP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_A2DP, BT_DFXC_A2DP_OFFLOAD), \
"%s:%s", "a2dpOffloadError", reason); \
} while (0)
// hfp
#if defined(CONFIG_BLUETOOTH_DFX) && defined(CONFIG_BLUETOOTH_BREDR_SUPPORT)
#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: hfpConnError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_CONN), \
"%s:%s", "hfpConnError", reason); \
} while (0)
#define BT_DFX_HFP_OFFLOAD_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: hfpOffloadError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_OFFLOAD), \
"%s:%s", "hfpOffloadError", reason); \
} while (0)
// open (enable)
#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_OPEN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: openError: %s", reason); \
BT_DFX_SEND_OTHERS_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_OTHERS, BT_DFXC_OPEN), \
"%s:%s", "openError", reason); \
} while (0)
// spp / ipc
#define BT_DFX_SPP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: sppConnError: %s", reason); \
BT_DFX_SEND_BR_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_RFCOMM, 0), \
"%s:%s", "sppConnError", reason); \
} while (0)
#define BT_DFX_IPC_CONN_ERROR(reason, extra) \
do { \
BT_LOGE("BT_DFX: ipcConnError: %s %s", reason, extra); \
BT_DFX_SEND_BR_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_RFCOMM, 0), \
"%s:%s:%s", "ipcConnError", reason, extra); \
} while (0)
#endif /* _BT_DFX_H_ */

View File

@ -1,63 +0,0 @@
/****************************************************************************
* 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_A2DP
#define BT_DFXC_A2DP_CONN (0)
#define BT_DFXC_A2DP_OFFLOAD (100)
// group: BT_DFXG_HFP
#define BT_DFXC_HFP_CONN (0)
#define BT_DFXC_HFP_OFFLOAD (100)
// group: BT_DFXG_OTHERS
#define BT_DFXC_OPEN (0)
#define BT_DFX_BUILD_CODE(group, subcode) ((BT_DFX_BASE_VELA_BLUETOOTH) + (group) + (subcode))
#endif /* _BT_DFX_EVENT_H_ */

View File

@ -1,39 +0,0 @@
/****************************************************************************
* 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_LE_ENABLE_FAIL "btLeEnableFail"
#define BT_DFXE_BR_ENABLE_FAIL "btBrEnableFail"
#define BT_DFXE_A2DP_CONN_TIMEOUT "btA2dpConnTimeout"
#define BT_DFXE_OFFLOAD_START_TIMEOUT "btOffloadStartTimeout"
#define BT_DFXE_OFFLOAD_HCI_UNSPECIFIED_ERROR "btOffloadHciUnspecifiedError"
#define BT_DFXE_HFP_HF_CONN_TIMEOUT "btHfpHfConnTimeout"
#define BT_DFXE_HFP_HF_CONN_RETRY_FAIL "btHfpHfConnRetryFail"
#define BT_DFXE_SPP_CONN_FAIL "btSppConnFail"
#define BT_DFXE_SPP_NOT_STARTUP "btSppNotStartup"
#define BT_DFXE_SPP_SCN_ALLOC_FAIL "btSppScnAllocFail"
#define BT_DFXE_SPP_NO_RESOURCES "btSppNoResources"
#endif /* _BT_DFX_REASON_H_ */

View File

@ -1,121 +0,0 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<EventRoot version="">
<Event id="961020000" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="brInquiryError" type="string"/>
</Event>
<Event id="961020100" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="brConnectError" type="string"/>
</Event>
<Event id="961020110" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="brDisconnectError" type="string"/>
</Event>
<Event id="961020200" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="brPairError" type="string"/>
</Event>
<Event id="961020500" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="bleScanError" type="string"/>
</Event>
<Event id="961020600" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="bleConnectError" type="string"/>
</Event>
<Event id="961020610" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="bleDisconnectError" type="string"/>
</Event>
<Event id="961020700" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="blePairError" type="string"/>
</Event>
<Event id="961021000" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="btSppConnectError" type="string"/>
</Event>
<Event id="961021010" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L2">
<Param id="0" name="btSppDisconnected" type="string"/>
<Param id="1" name="scn" type="int"/>
<Param id="2" name="port" type="int"/>
<Param id="3" name="role" type="string"/>
</Event>
<Event id="961023000" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="btA2dpConnectError" type="string"/>
</Event>
<Event id="961023010" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="btA2dpMediaError" type="string"/>
</Event>
<Event id="961023020" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="btA2dpOffloadError" type="string"/>
</Event>
<Event id="961023200" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="btAvrcpConnectError" type="string"/>
</Event>
<Event id="961023210" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="btAvrcpCtrlError" type="string"/>
</Event>
<Event id="961023220" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="btAvrcpVolError" type="string"/>
</Event>
<Event id="961023400" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="btHfpConnectError" type="string"/>
</Event>
<Event id="961023410" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="btHfpScoConnectError" type="string"/>
</Event>
<Event id="961023420" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="btHfpVolError" type="string"/>
</Event>
<Event id="961023430" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="btHfpMediaError" type="string"/>
</Event>
<Event id="961023440" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="btHfpOffloadError" type="string"/>
</Event>
<Event id="961026000" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="btHidConnectError" type="string"/>
</Event>
<Event id="961029000" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L2">
<Param id="0" name="btSocketError" type="string"/>
<Param id="1" name="port" type="int"/>
</Event>
<Event id="961029010" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="btIpcConnectError" type="string"/>
<Param id="1" name="reason" type="string"/>
</Event>
<Event id="961029020" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="btIpcAllocError" type="string"/>
<Param id="1" name="packetCode" type="int"/>
</Event>
<Event id="961029100" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L2">
<Param id="0" name="btDriverError" type="string"/>
<Param id="1" name="name" type="string"/>
<Param id="2" name="reason" type="string"/>
</Event>
<Event id="961029200" FaultType="FAULT" FaultLevel="CRITICAL" PrivacyLevel="L1">
<Param id="0" name="btOpenError" type="string"/>
</Event>
</EventRoot>

View File

@ -1,137 +0,0 @@
/*
* 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

@ -1,3 +0,0 @@
module system.bluetooth@2.0
promise<object> getAddressAsync()

View File

@ -1,169 +0,0 @@
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

@ -1,104 +0,0 @@
/*
* 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

@ -1,178 +0,0 @@
/*
* 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

@ -40,14 +40,12 @@ typedef enum {
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 {
@ -66,11 +64,6 @@ typedef struct {
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;
@ -82,7 +75,6 @@ typedef struct {
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;

View File

@ -1,27 +0,0 @@
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

@ -16,7 +16,6 @@
*/
#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"
@ -24,7 +23,6 @@
#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) \
@ -87,16 +85,6 @@ static bool get_callback_a2dp_sink(void* data, void* feature_ins)
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;
@ -148,18 +136,6 @@ static void free_feature_bluetooth_a2dp_sink_node(void* node)
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;
@ -461,92 +437,6 @@ static const a2dp_sink_callbacks_t 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;
@ -575,11 +465,6 @@ void feature_bluetooth_add_feature_callback(FeatureInstanceHandle handle, featur
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;
@ -614,11 +499,6 @@ void feature_bluetooth_free_feature_callback(FeatureInstanceHandle handle, featu
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;
@ -656,11 +536,6 @@ void feature_bluetooth_set_feature_callback(FeatureInstanceHandle handle, FtCall
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;
@ -700,11 +575,6 @@ FtCallbackId feature_bluetooth_get_feature_callback(FeatureInstanceHandle handle
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;
@ -737,11 +607,6 @@ void feature_bluetooth_callback_init(bt_instance_t* bt_ins)
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;
}
@ -764,18 +629,11 @@ void feature_bluetooth_callback_uninit(bt_instance_t* bt_ins)
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);

View File

@ -77,9 +77,6 @@ void feature_bluetooth_post_task(FeatureInstanceHandle handle, FtCallbackId call
char* StringToFtString(const char* str)
{
if (!str) {
return NULL;
}
int len = strlen(str);
char* ftStr = (char*)FeatureMalloc(len + 1, FT_CHAR);
strcpy(ftStr, str);

View File

@ -1,103 +0,0 @@
/*
* 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

@ -42,11 +42,6 @@ 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(SYS_SET_BT_ALL);
}
bt_status_t BTSYMBOLS(bt_adapter_enable_le)(bt_instance_t* ins)
{
return adapter_enable(APP_SET_LE_ONLY);
@ -77,19 +72,9 @@ 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, uint8_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);
return adapter_start_discovery(timeout);
}
bt_status_t BTSYMBOLS(bt_adapter_cancel_discovery)(bt_instance_t* ins)
@ -184,9 +169,9 @@ bt_status_t BTSYMBOLS(bt_adapter_set_le_address)(bt_instance_t* ins, bt_address_
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)
bt_status_t BTSYMBOLS(bt_adapter_set_le_identity_address)(bt_instance_t* ins, bt_address_t* addr, bool public)
{
return adapter_set_le_identity_address(addr, is_public);
return adapter_set_le_identity_address(addr, public);
}
bt_status_t BTSYMBOLS(bt_adapter_set_le_appearance)(bt_instance_t* ins, uint16_t appearance)

View File

@ -19,7 +19,6 @@
#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"
@ -29,58 +28,16 @@ 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)
void* 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)
bool 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->get_playback_state(addr);
}
bt_status_t BTSYMBOLS(bt_avrcp_control_register_notification)(bt_instance_t* ins, bt_address_t* addr, avrcp_notification_event_t event, uint32_t interval)
{
avrcp_control_interface_t* profile = get_profile_service();
return profile->avrcp_control_register_notification(addr, event, interval);
}

View File

@ -1,75 +0,0 @@
/****************************************************************************
* 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 <stdint.h>
#include "bt_cs.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "cs_service.h"
#include "service_manager.h"
#include "utils/log.h"
#ifdef CONFIG_BLUETOOTH_LE_CS
static bt_cs_interface_t* get_profile_service(void)
{
return (bt_cs_interface_t*)service_manager_get_profile(PROFILE_CS);
}
void* BTSYMBOLS(bt_cs_register_callbacks)(bt_instance_t* ins, const cs_callbacks_t* callbacks)
{
bt_cs_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool BTSYMBOLS(bt_cs_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
bt_cs_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t BTSYMBOLS(bt_cs_start_distance_measurement)(bt_instance_t* ins, bt_distance_measurement_params_t* params)
{
bt_cs_interface_t* profile = get_profile_service();
return profile->start_distance_measurement(params);
}
bt_status_t BTSYMBOLS(bt_cs_stop_distance_measurement)(bt_instance_t* ins, bt_address_t* addr, uint8_t method, bool timeout)
{
bt_cs_interface_t* profile = get_profile_service();
return profile->stop_distance_measurement(addr, method, timeout);
}
bt_status_t BTSYMBOLS(bt_cs_set_config)(bt_instance_t* ins, bt_address_t* addr, const bt_cs_set_params_t* params)
{
bt_cs_interface_t* profile = get_profile_service();
return profile->set_config(addr, params);
}
#ifdef CONFIG_BT_CS_RAS_TEST
bt_status_t BTSYMBOLS(bt_cs_test)(bt_instance_t* ins, void* data, uint16_t len)
{
bt_cs_interface_t* profile = get_profile_service();
return profile->cs_test(data, len);
}
#endif /* CONFIG_BT_CS_RAS_TEST */
#endif /* CONFIG_BLUETOOTH_LE_CS */

View File

@ -30,11 +30,7 @@ bt_status_t BTSYMBOLS(bt_device_get_identity_address)(bt_instance_t* ins, bt_add
ble_addr_type_t BTSYMBOLS(bt_device_get_address_type)(bt_instance_t* ins, bt_address_t* addr)
{
#ifdef CONFIG_BLUETOOTH_BLE_SUPPORT
return adapter_get_le_remote_address_type(addr);
#else
return 0;
#endif
}
bt_device_type_t BTSYMBOLS(bt_device_get_device_type)(bt_instance_t* ins, bt_address_t* addr)
@ -150,16 +146,6 @@ bt_status_t BTSYMBOLS(bt_device_create_bond)(bt_instance_t* ins, bt_address_t* a
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);

View File

@ -49,13 +49,6 @@ bt_status_t BTSYMBOLS(bt_gatts_connect)(gatts_handle_t srv_handle, bt_address_t*
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();

View File

@ -150,29 +150,4 @@ bt_status_t BTSYMBOLS(bt_hfp_ag_send_at_command)(bt_instance_t* ins, bt_address_
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);
}

View File

@ -198,15 +198,3 @@ bt_status_t BTSYMBOLS(bt_hfp_hf_send_dtmf)(bt_instance_t* ins, bt_address_t* add
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

@ -29,21 +29,18 @@ 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)
void* BTSYMBOLS(bt_spp_register_app)(bt_instance_t* ins, 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);
return profile->register_app(NULL, NULL, SPP_PORT_TYPE_TTY, 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);
spp_interface_t* profile = get_profile_service();
return profile->register_app(NULL, name, port_type, callbacks);
}
bt_status_t BTSYMBOLS(bt_spp_unregister_app)(bt_instance_t* ins, void* handle)
@ -67,18 +64,11 @@ bt_status_t BTSYMBOLS(bt_spp_server_stop)(bt_instance_t* ins, void* handle, uint
return profile->server_stop(handle, scn);
}
bt_status_t BTSYMBOLS(bt_spp_insecure_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, true);
}
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, false);
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)

View File

@ -1,40 +0,0 @@
/****************************************************************************
* 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);
}

File diff suppressed because it is too large Load Diff

View File

@ -21,9 +21,12 @@
#include "bt_addr.h"
static const bt_address_t bt_addr_empty = {
const bt_address_t bt_addr_empty = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
};
const bt_address_t bt_addr_any = {
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
};
static char g_bdaddr_str[18];
@ -76,7 +79,7 @@ int bt_addr_ba2str(const bt_address_t* addr, char* str)
addr->addr[2], addr->addr[1], addr->addr[0]);
}
char* bt_addr_bastr(const bt_address_t* addr)
char* bt_addr_str(const bt_address_t* addr)
{
if (!addr) {
return NULL;

View File

@ -1,38 +0,0 @@
/****************************************************************************
* 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

@ -1,83 +0,0 @@
/****************************************************************************
* 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__ */

View File

@ -21,7 +21,6 @@
#include "bt_utils.h"
#include "bt_uuid.h"
#include "utils/log.h"
static const bt_uuid_t bt_uuid128_base = {
.type = BT_UUID128_TYPE,
@ -43,12 +42,6 @@ static void bt_uuid16_to_uuid128(const bt_uuid_t* uuid16, bt_uuid_t* uuid128)
memcpy(&uuid128->val.u128[BASE_UUID16_OFFSET], uuid, sizeof(uuid));
}
static void bt_uuid128_to_uuid16(const bt_uuid_t* uuid128, bt_uuid_t* uuid16)
{
uuid16->type = BT_UUID16_TYPE;
uuid16->val.u16 = (uint16_t)(uuid128->val.u128[BASE_UUID16_OFFSET + 1] << 8 | uuid128->val.u128[BASE_UUID16_OFFSET]);
}
static void bt_uuid32_to_uuid128(const bt_uuid_t* uuid32, bt_uuid_t* uuid128)
{
uint8_t uuid[4];
@ -76,23 +69,6 @@ void bt_uuid_to_uuid128(const bt_uuid_t* src, bt_uuid_t* uuid128)
}
}
void bt_uuid_to_uuid16(const bt_uuid_t* src, bt_uuid_t* uuid16)
{
switch (src->type) {
case BT_UUID128_TYPE:
bt_uuid128_to_uuid16(src, uuid16);
break;
case BT_UUID32_TYPE:
BT_LOGE("uuid32 to uuid16 not supported!");
break;
case BT_UUID16_TYPE:
*uuid16 = *src;
break;
default:
break;
}
}
static int bt_uuid128_cmp(const bt_uuid_t* u1, const bt_uuid_t* u2)
{
return memcmp(&u1->val.u128, &u2->val.u128, 16);

View File

@ -1,578 +0,0 @@
/****************************************************************************
* 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.
***************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "bt_config.h"
#include "bt_debug.h"
#include "euv_pipe.h"
#include "uv.h"
#ifndef CONFIG_EUV_PIPE_MAX_CONNEXTIONS
#define CONFIG_EUV_PIPE_MAX_CONNEXTIONS 4
#endif
typedef struct {
uv_write_t req;
uint8_t* buffer;
euv_write_cb write_cb;
} euv_write_t;
typedef struct {
euv_read_cb read_cb;
euv_alloc_cb alloc_cb;
uint16_t read_size;
} euv_read_t;
typedef struct {
uv_connect_t req;
euv_connect_cb connect_cb;
void* data;
} euv_connect_t;
static void euv_pipe_listen_callback(uv_stream_t* stream, int status)
{
euv_pipe_t* handle;
euv_connect_t* creq;
int err;
handle = stream->data;
creq = handle->data;
if (!creq) {
BT_LOGE("%s, creq null", __func__);
return;
}
err = uv_pipe_init(stream->loop, &handle->cli_pipe, 0);
if (err != 0) {
BT_LOGE("%s, srv_pipe init failed: %s", __func__, uv_strerror(err));
return;
}
handle->status |= EUV_CLIENT_PIPE_OPENED; // mark client pipe opened
err = uv_accept(stream, (uv_stream_t*)&handle->cli_pipe);
if (err != 0) {
BT_LOGE("%s, srv_pipe accept failed: %s", __func__, uv_strerror(err));
return;
}
if (creq->connect_cb) {
creq->connect_cb(handle, status, creq->data);
}
// only one pipe can be accepted, release creq
handle->data = NULL; // unrefer creq
free(creq);
}
static void euv_local_listen_callback(uv_stream_t* stream, int status)
{
euv_pipe_t* handle;
if (status < 0) {
BT_LOGE("%s,uv listen error: %s", __func__, uv_strerror(status));
return;
}
handle = stream->data;
handle->mode = EUV_PIPE_TYPE_SERVER_LOCAL;
euv_pipe_listen_callback(stream, status);
}
#ifdef CONFIG_NET_RPMSG
static void euv_rpmsg_listen_callback(uv_stream_t* stream, int status)
{
euv_pipe_t* handle;
if (status < 0) {
BT_LOGE("%s,uv listen error: %s", __func__, uv_strerror(status));
return;
}
handle = stream->data;
handle->mode = EUV_PIPE_TYPE_SERVER_RPMSG;
euv_pipe_listen_callback(stream, status);
}
#endif
static void euv_close_callback(uv_handle_t* hdl)
{
euv_pipe_t* handle = hdl->data;
if (!handle) {
BT_LOGE("%s, handle null", __func__);
return;
}
if (hdl == (uv_handle_t*)&handle->cli_pipe) {
handle->status &= ~EUV_CLIENT_PIPE_OPENED; // mark client pipe closed
} else if (hdl == (uv_handle_t*)&handle->srv_pipe[EUV_PIPE_TYPE_SERVER_LOCAL]) {
handle->status &= ~EUV_LOCAL_SERVER_PIPE_OPENED; // mark local server pipe closed
}
#ifdef CONFIG_NET_RPMSG
else if (hdl == (uv_handle_t*)&handle->srv_pipe[EUV_PIPE_TYPE_SERVER_RPMSG]) {
handle->status &= ~EUV_RPMSG_SERVER_PIPE_OPENED; // mark rpmsg server pipe closed
}
#endif
if (handle->status == EUV_ALL_PIPE_CLOSED) {
if (handle->close_cb) {
handle->close_cb(handle);
}
// all pipe closed, free handle
BT_LOGD("%s, free handle 0x%p", __func__, handle);
free(handle);
}
}
static void euv_alloc_callback(uv_handle_t* handle, size_t size, uv_buf_t* buf)
{
euv_read_t* reader;
if (!handle->data) {
BT_LOGE("%s, handle data null", __func__);
return;
}
reader = (euv_read_t*)handle->data;
if (reader->alloc_cb)
reader->alloc_cb((euv_pipe_t*)handle, (uint8_t**)&buf->base, &buf->len);
else {
buf->base = malloc(reader->read_size);
buf->len = reader->read_size;
}
}
static void euv_read_callback(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf)
{
euv_read_t* reader;
bool release;
if (!stream->data) {
BT_LOGE("%s, stream data null", __func__);
return;
}
reader = (euv_read_t*)stream->data;
release = !reader->alloc_cb;
if (reader->read_cb)
reader->read_cb((euv_pipe_t*)stream, (const uint8_t*)buf->base, nread);
if (release) {
free(buf->base);
}
}
static void euv_write_callback(uv_write_t* req, int status)
{
euv_write_t* wreq = (euv_write_t*)req;
if (wreq->write_cb)
wreq->write_cb((euv_pipe_t*)wreq->req.data, wreq->buffer, status);
free(wreq);
}
int euv_pipe_read_start(euv_pipe_t* handle, uint16_t read_size, euv_read_cb read_cb, euv_alloc_cb alloc_cb)
{
euv_read_t* reader;
int ret;
if (!handle) {
BT_LOGE("%s, handle null", __func__);
return -EINVAL;
}
if (uv_is_closing((uv_handle_t*)&handle->cli_pipe)) {
BT_LOGE("%s, handle %p is closing", __func__, handle);
return -EPERM;
}
if (uv_is_active((uv_handle_t*)&handle->cli_pipe)) {
BT_LOGE("%s, client is active", __func__);
return 0;
}
reader = malloc(sizeof(euv_read_t));
if (!reader) {
BT_LOGE("%s, reader malloc fail", __func__);
return -ENOMEM;
}
reader->read_cb = read_cb;
reader->alloc_cb = alloc_cb;
reader->read_size = read_size;
handle->cli_pipe.data = reader;
ret = uv_read_start((uv_stream_t*)&handle->cli_pipe, euv_alloc_callback, euv_read_callback);
if (ret != 0) {
BT_LOGE("%s, read start err:%d", __func__, ret);
handle->cli_pipe.data = NULL;
free(reader);
}
return ret;
}
int euv_pipe_read_stop(euv_pipe_t* handle)
{
if (!handle) {
BT_LOGE("%s, handle null", __func__);
return -EINVAL;
}
if (uv_is_closing((uv_handle_t*)&handle->cli_pipe)) {
/* uv_pipe is closing; cli_pipe.data has been set to handle for cleanup, so don't free it here */
BT_LOGE("%s, handle %p is closing", __func__, handle);
return -EPERM;
}
if (handle->cli_pipe.data) {
free(handle->cli_pipe.data);
handle->cli_pipe.data = NULL;
}
if (!uv_is_active((uv_handle_t*)&handle->cli_pipe)) {
BT_LOGW("%s, cli_pipe is inactive", __func__);
return 0;
}
return uv_read_stop((uv_stream_t*)&handle->cli_pipe);
}
int euv_pipe_write(euv_pipe_t* handle, uint8_t* buffer, int length, euv_write_cb cb)
{
uv_buf_t buf;
euv_write_t* wreq;
int ret;
if (!handle) {
BT_LOGE("%s, handle null", __func__);
return -EINVAL;
}
wreq = (euv_write_t*)malloc(sizeof(euv_write_t));
if (!wreq)
return -ENOMEM;
wreq->req.data = (void*)handle;
wreq->buffer = buffer;
wreq->write_cb = cb;
buf = uv_buf_init((char*)buffer, length);
ret = uv_write(&wreq->req, (uv_stream_t*)&handle->cli_pipe, &buf, 1, euv_write_callback);
if (ret != 0) {
BT_LOGE("%s, write err:%d", __func__, ret);
free(wreq);
}
return ret;
}
static void euv_connect_callback(uv_connect_t* req, int status)
{
euv_connect_t* creq = (euv_connect_t*)req;
if (creq->connect_cb)
creq->connect_cb(creq->req.data, status, creq->data);
free(req);
}
euv_pipe_t* euv_pipe_connect(uv_loop_t* loop, const char* server_path, euv_connect_cb cb, void* user_data)
{
euv_pipe_t* handle;
euv_connect_t* creq;
int err;
if (!loop || !server_path) {
BT_LOGE("%s, invalid arg", __func__);
return NULL;
}
handle = (euv_pipe_t*)zalloc(sizeof(euv_pipe_t));
if (!handle) {
BT_LOGE("%s, zalloc fail", __func__);
return NULL;
}
handle->status = EUV_ALL_PIPE_CLOSED;
err = uv_pipe_init(loop, &handle->cli_pipe, 0);
if (err != 0) {
BT_LOGE("%s, srv_pipe init failed: %s", __func__, uv_strerror(err));
goto err_out;
}
handle->status |= EUV_CLIENT_PIPE_OPENED; // mark client pipe opened
creq = zalloc(sizeof(euv_connect_t));
if (!creq) {
BT_LOGE("%s, zalloc failed", __func__);
goto err_out;
}
creq->connect_cb = cb;
creq->data = user_data;
creq->req.data = handle;
#if defined(CONFIG_BLUETOOTH_SERVER)
uv_pipe_connect(&creq->req, &handle->cli_pipe, server_path, euv_connect_callback);
#elif defined(CONFIG_NET_RPMSG)
uv_pipe_rpmsg_connect(&creq->req, &handle->cli_pipe, server_path, CONFIG_BLUETOOTH_RPMSG_CPUNAME, euv_connect_callback);
#else
uv_pipe_connect(&creq->req, &handle->cli_pipe, server_path, euv_connect_callback); // not using bluetoothd
#endif
BT_LOGD("%s, handle 0x%p", __func__, handle);
return handle;
err_out:
free(handle);
return NULL;
}
#ifdef CONFIG_NET_RPMSG
euv_pipe_t* euv_rpmsg_pipe_connect(uv_loop_t* loop, const char* server_path, const char* cpu_name, euv_connect_cb cb, void* user_data)
{
euv_pipe_t* handle;
euv_connect_t* creq;
int err;
if (!loop || !server_path) {
BT_LOGE("%s, invalid arg", __func__);
return NULL;
}
handle = (euv_pipe_t*)zalloc(sizeof(euv_pipe_t));
if (!handle) {
BT_LOGE("%s, zalloc fail", __func__);
return NULL;
}
handle->status = EUV_ALL_PIPE_CLOSED;
err = uv_pipe_init(loop, &handle->cli_pipe, 0);
if (err != 0) {
BT_LOGE("%s, srv_pipe init failed: %s", __func__, uv_strerror(err));
goto err_out;
}
handle->status |= EUV_CLIENT_PIPE_OPENED; // mark client pipe opened
creq = zalloc(sizeof(euv_connect_t));
if (!creq) {
BT_LOGE("%s, zalloc failed", __func__);
goto err_out;
}
creq->connect_cb = cb;
creq->data = user_data;
creq->req.data = handle;
uv_pipe_rpmsg_connect(&creq->req, &handle->cli_pipe, server_path, cpu_name, euv_connect_callback);
BT_LOGD("%s, handle 0x%p", __func__, handle);
return handle;
err_out:
free(handle);
return NULL;
}
#endif
euv_pipe_t* euv_pipe_open(uv_loop_t* loop, const char* server_path, euv_connect_cb cb, void* user_data)
{
euv_pipe_t* handle;
euv_connect_t* creq;
int err;
uv_fs_t fs;
if (!loop || !server_path) {
BT_LOGE("%s, invalid arg", __func__);
return NULL;
}
handle = (euv_pipe_t*)zalloc(sizeof(euv_pipe_t));
if (!handle) {
BT_LOGE("%s, zalloc handle fail", __func__);
return NULL;
}
handle->mode = EUV_PIPE_TYPE_UNKNOWN;
handle->status = EUV_ALL_PIPE_CLOSED;
creq = (euv_connect_t*)zalloc(sizeof(euv_connect_t));
if (!creq) {
BT_LOGE("%s, zalloc creq fail", __func__);
goto errout_with_handle;
}
creq->data = user_data;
creq->connect_cb = cb;
handle->data = creq;
err = uv_pipe_init(loop, &handle->srv_pipe[EUV_PIPE_TYPE_SERVER_LOCAL], 0);
if (err != 0) {
BT_LOGE("%s, srv_pipe init failed: %s", __func__, uv_strerror(err));
goto errout_with_creq;
}
handle->status |= EUV_LOCAL_SERVER_PIPE_OPENED; // mark local server pipe opened
err = uv_fs_unlink(loop, &fs, server_path, NULL);
if (err != 0 && err != UV_ENOENT) {
BT_LOGE("%s, srv_pipe unlink failed: %s", __func__, uv_strerror(err));
goto errout_with_creq;
}
err = uv_pipe_bind(&handle->srv_pipe[EUV_PIPE_TYPE_SERVER_LOCAL], server_path);
if (err != 0) {
BT_LOGE("%s, srv_pipe bind failed: %s", __func__, uv_strerror(err));
goto errout_with_creq;
}
handle->srv_pipe[EUV_PIPE_TYPE_SERVER_LOCAL].data = handle;
err = uv_listen((uv_stream_t*)&handle->srv_pipe[EUV_PIPE_TYPE_SERVER_LOCAL], CONFIG_EUV_PIPE_MAX_CONNEXTIONS, euv_local_listen_callback);
if (err != 0) {
BT_LOGE("%s, srv_pipe listen failed: %s", __func__, uv_strerror(err));
goto errout_with_creq;
}
#ifdef CONFIG_NET_RPMSG
/* start RPMSG server */
err = uv_pipe_init(loop, &handle->srv_pipe[EUV_PIPE_TYPE_SERVER_RPMSG], 0);
if (err != 0) {
BT_LOGE("%s, rpmsg srv_pipe init failed: %s", __func__, uv_strerror(err));
goto errout_with_creq;
}
handle->status |= EUV_RPMSG_SERVER_PIPE_OPENED; // mark rpmsg server pipe opened
err = uv_pipe_rpmsg_bind(&handle->srv_pipe[EUV_PIPE_TYPE_SERVER_RPMSG], server_path, "");
if (err != 0) {
BT_LOGE("%s, rpmsg srv_pipe bind failed: %s", __func__, uv_strerror(err));
goto errout_with_creq;
}
handle->srv_pipe[EUV_PIPE_TYPE_SERVER_RPMSG].data = handle;
err = uv_listen((uv_stream_t*)&handle->srv_pipe[EUV_PIPE_TYPE_SERVER_RPMSG], CONFIG_EUV_PIPE_MAX_CONNEXTIONS, euv_rpmsg_listen_callback);
if (err != 0) {
BT_LOGE("%s, rpmsg srv_pipe listen failed: %s", __func__, uv_strerror(err));
goto errout_with_creq;
}
#endif
BT_LOGD("%s, handle 0x%p", __func__, handle);
return handle;
errout_with_creq:
free(creq);
errout_with_handle:
free(handle);
return NULL;
}
void euv_pipe_close_with_cb(euv_pipe_t* handle, euv_close_cb cb)
{
if (!handle) {
BT_LOGE("%s, invalid arg", __func__);
return;
}
handle->close_cb = cb;
if (handle->mode == EUV_PIPE_TYPE_UNKNOWN) {
BT_LOGE("%s, unkown mode", __func__);
handle->srv_pipe[EUV_PIPE_TYPE_SERVER_LOCAL].data = handle;
uv_close((uv_handle_t*)&handle->srv_pipe[EUV_PIPE_TYPE_SERVER_LOCAL], euv_close_callback);
#ifdef CONFIG_NET_RPMSG
handle->srv_pipe[EUV_PIPE_TYPE_SERVER_RPMSG].data = handle;
uv_close((uv_handle_t*)&handle->srv_pipe[EUV_PIPE_TYPE_SERVER_RPMSG], euv_close_callback);
#endif
return;
}
if (uv_is_closing((uv_handle_t*)&handle->srv_pipe[handle->mode])) {
BT_LOGE("%s, uv_is_closing", __func__);
return;
}
euv_pipe_disconnect(handle);
handle->srv_pipe[handle->mode].data = handle;
uv_close((uv_handle_t*)&handle->srv_pipe[handle->mode], euv_close_callback);
}
void euv_pipe_close(euv_pipe_t* handle)
{
euv_pipe_close_with_cb(handle, NULL);
}
void euv_pipe_disconnect(euv_pipe_t* handle)
{
if (!handle) {
BT_LOGE("%s, invalid arg", __func__);
return;
}
if (uv_is_closing((uv_handle_t*)&handle->cli_pipe)) {
BT_LOGE("%s, uv_is_closing", __func__);
return;
}
euv_pipe_read_stop(handle);
handle->cli_pipe.data = handle;
uv_close((uv_handle_t*)&handle->cli_pipe, euv_close_callback);
}
#ifdef CONFIG_NET_RPMSG
void euv_pipe_close2(euv_pipe_t* handle)
{
euv_pipe_mode_t mode;
if (!handle) {
BT_LOGE("%s, invalid arg", __func__);
return;
}
if (handle->mode == EUV_PIPE_TYPE_SERVER_LOCAL) {
mode = EUV_PIPE_TYPE_SERVER_RPMSG;
} else if (handle->mode == EUV_PIPE_TYPE_SERVER_RPMSG) {
mode = EUV_PIPE_TYPE_SERVER_LOCAL;
} else {
BT_LOGE("%s, invalid mode", __func__);
return;
}
if (uv_is_closing((uv_handle_t*)&handle->srv_pipe[mode])) {
BT_LOGE("%s, uv_is_closing", __func__);
return;
}
handle->srv_pipe[mode].data = handle;
uv_close((uv_handle_t*)&handle->srv_pipe[mode], euv_close_callback);
}
#endif

View File

@ -63,8 +63,8 @@ const state_t* hsm_get_previous_state(state_machine_t* sm)
const char* hsm_get_current_state_name(state_machine_t* sm)
{
if (!sm || !sm->current_state) {
return HSM_NONE_STR;
if (!sm) {
return NULL;
}
return sm->current_state->state_name;
@ -73,7 +73,7 @@ const char* hsm_get_current_state_name(state_machine_t* sm)
const char* hsm_get_state_name(const state_t* state)
{
if (!state) {
return HSM_NONE_STR;
return NULL;
}
return state->state_name;

View File

@ -56,21 +56,6 @@ extern "C" {
#endif
#endif // End of else
#define CALLBACK_FOREACH(_list, _struct, _cback, ...) \
BT_CALLBACK_FOREACH(_list, _struct, _cback, ##__VA_ARGS__)
#define CALLBACK_REMOTE(_remote, _type, _cback, ...) \
do { \
_type* _cbs = (_type*)_remote->callbacks; \
if (_cbs && _cbs->_cback) { \
_cbs->_cback(_remote, ##__VA_ARGS__); \
} \
} while (0)
#define PRIMARY_ADAPTER 0
typedef uint8_t bt_controller_id_t;
typedef enum {
BT_IO_CAPABILITY_DISPLAYONLY = 0,
BT_IO_CAPABILITY_DISPLAYYESNO,
@ -197,11 +182,6 @@ typedef enum {
BT_LE_ADDR_TYPE_UNKNOWN = 0xFF
} ble_addr_type_t;
typedef enum {
BT_ADDR_TYPE_BREDR,
BT_ADDR_TYPE_UNKNOWN = 0xFF
} bt_addr_type_t;
/* * BLE PHY type */
typedef enum {
BT_LE_1M_PHY,
@ -214,35 +194,8 @@ typedef enum {
BT_LE_CONNECT_FILTER_POLICY_WHITE_LIST
} ble_connect_filter_policy_t;
typedef enum {
/* ---------------- LE Enhanced Modes ---------------- */
EM_LE_MODE_START,
EM_LE_LOW_LATENCY = EM_LE_MODE_START,
EM_LE_HIGH_TPUT,
EM_LE_LOW_POWER,
EM_LE_MODE_END,
/* ---------------- BR/EDR Enhanced Modes ---------------- */
EM_BR_MODE_START = 0xF0,
EM_BR_LOW_LATENCY,
EM_BR_ULTRA_LOW_LATENCY,
EM_BR_HIGH_TPUT,
EM_BR_LOW_POWER,
EM_BR_MODE_END,
} bt_enhanced_mode_t;
typedef enum {
BT_DEBUG_MODE_PTS,
BT_DEBUG_MODE_RSSI,
} bt_debug_mode_t;
typedef uint8_t bt_128key_t[16];
typedef struct {
uint8_t hash[16];
uint8_t rand[16];
} bt_oob_data_t;
#define COD_SERVICE_BITS(c) (c & 0xFFE000) /* The major service classes field */
#define COD_DEVICE_MAJOR_BITS(c) (c & 0x001F00) /* The major device classes field */
#define COD_DEVICE_CLASS_BITS(c) (c & 0x001FFC) /* The device classes field, including major and minor */
@ -367,10 +320,6 @@ typedef struct {
#else
#define BT_DEV_NAME_MAX_LEN (64)
#endif
#define BLUETOOTH_COMPANY_ID_XIAOMI 0x038F
#define BLUETOOTH_COMPANY_ID_GOOGLE 0x00E0
#define BT_LOC_NAME_MAX_LEN BT_DEV_NAME_MAX_LEN
#define BT_REM_NAME_MAX_LEN BT_DEV_NAME_MAX_LEN
@ -439,15 +388,10 @@ enum {
BLUETOOTH_USER,
};
typedef struct bt_instance bt_instance_t;
typedef bool (*bt_allocator_t)(void** data, uint32_t size);
typedef void (*bt_hci_event_callback_t)(bt_hci_event_t* hci_event, void* context);
typedef void (*bt_ipc_connected_cb_t)(bt_instance_t* ins, void* user_data);
typedef void (*bt_ipc_disconnected_cb_t)(bt_instance_t* ins, void* user_data, int status);
typedef struct bt_instance {
uint32_t app_id;
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_BINDER_IPC
@ -481,19 +425,14 @@ typedef struct bt_instance {
void* context;
uv_mutex_t lock;
bt_ipc_disconnected_cb_t disconnected;
callbacks_list_t* adapter_callbacks;
callbacks_list_t* a2dp_sink_callbacks;
callbacks_list_t* a2dp_source_callbacks;
callbacks_list_t* avrcp_target_callbacks;
callbacks_list_t* avrcp_control_callbacks;
callbacks_list_t* cs_callbacks;
void* adapter_cookie;
void* a2dp_sink_cookie;
void* a2dp_source_cookie;
void* avrcp_target_cookie;
void* avrcp_control_cookie;
void* cs_cookie;
callbacks_list_t* hfp_ag_callbacks;
callbacks_list_t* hfp_hf_callbacks;
@ -510,7 +449,6 @@ typedef struct bt_instance {
bt_list_t* gattc_remote_list;
bt_list_t* gatts_remote_list;
void* priv;
#endif
} bt_instance_t;
@ -571,27 +509,6 @@ bt_status_t BTSYMBOLS(bluetooth_stop_service)(bt_instance_t* ins, enum profile_i
bool BTSYMBOLS(bluetooth_set_external_uv)(bt_instance_t* ins, uv_loop_t* ext_loop);
/*
Async instance
*/
/**
* @brief Create bluetooth async client instance
*
* @param loop uv_loop_t
* @param connected client instance connected callback
* @param disconnected client instance disconnected callback
* @return bt_instance_t* - ins on success, NULL on failure.
*/
bt_instance_t* bluetooth_create_async_instance(uv_loop_t* loop, bt_ipc_connected_cb_t connected, bt_ipc_disconnected_cb_t disconnected, void* user_data);
/**
* @brief Delete bluetooth async client instance
*
* @param ins bt_instance_t*
*/
void bluetooth_delete_async_instance(bt_instance_t* ins);
#ifdef __cplusplus
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -26,192 +26,26 @@ extern "C" {
#define BT_ADDR_LENGTH 6 /*define the address length*/
#define BT_ADDR_STR_LENGTH 18
#define bt_addr_str(addr) bt_addr_bastr(addr)
/**
* @cond
*/
typedef struct bt_addr {
uint8_t addr[BT_ADDR_LENGTH];
} bt_address_t;
/**
* @endcond
*/
/**
* @cond
*/
typedef struct bt_le_addr {
uint8_t addr[BT_ADDR_LENGTH];
uint8_t addr_type;
} bt_le_address_t;
/**
* @endcond
*/
/**
* @brief Check if a Bluetooth address is empty.
*
* Determines if the given Bluetooth address is all zeros.
*
* @param addr - Pointer to the Bluetooth address to check.
* This should point to a valid `bt_address_t` structure that contains a 6-byte Bluetooth address.
* @return true - The address is empty (all zeros).
* @return false - The address is not empty.
*
* **Example:**
* @code
* bt_address_t addr = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Example empty address
* if (bt_addr_is_empty(&addr)) {
* // Address is empty
* }
* @endcode
*/
bool bt_addr_is_empty(const bt_address_t* addr);
/**
* @brief Set a Bluetooth address to empty.
*
* Sets the given Bluetooth address to all zeros.
*
* @param addr - Pointer to the Bluetooth address to set to empty.
*
* **Example:**
* @code
* bt_address_t addr;
* bt_addr_set_empty(&addr); // Set the address to all zeros
* @endcode
*/
void bt_addr_set_empty(bt_address_t* addr);
/**
* @brief Compare two Bluetooth addresses.
*
* Compares two Bluetooth addresses.
*
* @param a - Pointer to the first Bluetooth address (type `bt_address_t`).
* @param b - Pointer to the second Bluetooth address (type `bt_address_t`).
* @return int - Returns zero if the addresses are equal, non-zero otherwise.
*
* **Example:**
* @code
* bt_address_t addr1 = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
* bt_address_t addr2 = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
* if (bt_addr_compare(&addr1, &addr2) == 0) {
* // Addresses are equal
* }
* @endcode
*/
int bt_addr_compare(const bt_address_t* a, const bt_address_t* b);
/**
* @brief Convert a Bluetooth address to a string.
*
* Converts a Bluetooth address to its string representation in the format "XX:XX:XX:XX:XX:XX".
*
* @param addr - Pointer to the Bluetooth address.
* This should point to a valid `bt_address_t` structure.
* @param str - Pointer to a buffer to store the string representation. The buffer must be at least `BT_ADDR_STR_LENGTH` bytes long.
* @return int - Returns zero on success, negative value on failure.
*
* **Example:**
* @code
* bt_address_t addr = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
* char str[BT_ADDR_STR_LENGTH];
* if (bt_addr_ba2str(&addr, str) == 0) {
* // str now contains the address string in the format "00:11:22:33:44:55"
* }
* @endcode
*/
int bt_addr_ba2str(const bt_address_t* addr, char* str);
/**
* @brief Convert a string to a Bluetooth address.
*
* Parses a string representation of a Bluetooth address and stores it in a `bt_address_t` structure.
*
* @param str - Pointer to the string containing the Bluetooth address (format "XX:XX:XX:XX:XX:XX").
* @param addr - Pointer to the Bluetooth address structure to store the result.
* After calling this function, `addr` will contain the parsed Bluetooth address.
* @return int - Returns zero on success, negative value on failure.
*
* **Example:**
* @code
* bt_address_t addr;
* if (bt_addr_str2ba("00:11:22:33:44:55", &addr) == 0) {
* // addr now contains the parsed address in the format {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}
* }
* @endcode
*/
int bt_addr_str2ba(const char* str, bt_address_t* addr);
/**
* @brief Get the string representation of a Bluetooth address.
*
* Returns a string representation of the Bluetooth address.
*
* @param addr - Pointer to the Bluetooth address.
* This should point to a valid `bt_address_t` structure.
* @return char* - Pointer to a static string containing the address in "XX:XX:XX:XX:XX:XX" format.
*
* **Note:** The returned string is stored in a static buffer and may be overwritten by subsequent calls.
*
* **Example:**
* @code
* bt_address_t addr = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
* printf("Address: %s\n", bt_addr_bastr(&addr));
* // Output: Address: 00:11:22:33:44:55
* @endcode
*/
char* bt_addr_bastr(const bt_address_t* addr);
/**
* @brief Set a Bluetooth address.
*
* Sets the Bluetooth address from a byte array.
*
* @param addr - Pointer to the Bluetooth address structure to set.
* This should point to a valid `bt_address_t` structure that will be updated with the new address.
* @param bd - Pointer to a byte array containing the address bytes (of length `BT_ADDR_LENGTH`).
* The array should contain exactly 6 bytes representing the Bluetooth address.
*
* **Example:**
* @code
* bt_address_t addr;
* uint8_t bd[BT_ADDR_LENGTH] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
* bt_addr_set(&addr, bd);
* // addr now contains the address {0x00, 0x11, 0x22, 0x33, 0x44, 0x55}
* @endcode
*/
char* bt_addr_str(const bt_address_t* addr);
void bt_addr_set(bt_address_t* addr, const uint8_t* bd);
/**
* @brief Swap byte order of a Bluetooth address.
*
* Swaps the byte order of a Bluetooth address (e.g., from little-endian to big-endian).
*
* @param src - Pointer to the source Bluetooth address (type `bt_address_t`).
* @param dest - Pointer to the destination Bluetooth address where the swapped address will be stored.
* This should point to a valid `bt_address_t` structure.
*
* **Example:**
* @code
* bt_address_t addr = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
* bt_address_t swapped_addr;
* bt_addr_swap(&addr, &swapped_addr);
* // swapped_addr now contains the address with byte order swapped
* @endcode
*/
void bt_addr_swap(const bt_address_t* src, bt_address_t* dest);
#ifdef __cplusplus
}
#endif
#endif /* __BT_ADDR_H__ */
#endif /* __BT_ADDR_H_ */

View File

@ -1,53 +0,0 @@
/****************************************************************************
* 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_ASYNC_H__
#define __BT_ASYNC_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "bluetooth.h"
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_ASYNC
#define HANDLE_BT_ASTNC_CALLBACK(ret_cb, ins, packet, type, userdata) \
do { \
if (!ret_cb) \
return; \
if (!packet) { \
ret_cb(ins, BT_STATUS_UNHANDLED, userdata); \
return; \
} \
ret_cb(ins, packet->type.status, userdata); \
} while (0)
typedef void (*bt_status_cb_t)(bt_instance_t* ins, bt_status_t status, void* userdata);
typedef void (*bt_address_cb_t)(bt_instance_t* ins, bt_status_t status, bt_address_t* addr, void* userdata);
typedef void (*bt_uuids_cb_t)(bt_instance_t* ins, bt_status_t status, bt_uuid_t* uuids, uint16_t size, void* userdata);
typedef void (*bt_device_type_cb_t)(bt_instance_t* ins, bt_status_t status, bt_device_type_t dtype, void* userdata);
typedef void (*bt_bool_cb_t)(bt_instance_t* ins, bt_status_t status, bool bbool, void* userdata);
typedef void (*bt_string_cb_t)(bt_instance_t* ins, bt_status_t status, const char* str, void* userdata);
typedef void (*bt_s8_cb_t)(bt_instance_t* ins, bt_status_t status, int8_t val, void* userdata);
typedef void (*bt_u8_cb_t)(bt_instance_t* ins, bt_status_t status, uint8_t val, void* userdata);
typedef void (*bt_u16_cb_t)(bt_instance_t* ins, bt_status_t status, uint16_t val, void* userdata);
typedef void (*bt_u32_cb_t)(bt_instance_t* ins, bt_status_t status, uint32_t val, void* userdata);
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -21,19 +21,6 @@
#include "bt_addr.h"
#include "bt_device.h"
/**
* @cond
*/
#define AVRCP_MAX_ATTR_COUNT 9
#define AVRCP_ATTR_MAX_TIELE_LEN 64
#define AVRCP_ATTR_MAX_ARTIST_LEN 64
#define AVRCP_ATTR_MAX_ALBUM_LEN 0
#define AVRCP_ATTR_MAX_TRACK_NUMBER_LEN 0
#define AVRCP_ATTR_MAX_TOTAL_TRACK_NUMBER_LEN 0
#define AVRCP_ATTR_MAX_GENER_LEN 0
#define AVRCP_ATTR_MAX_PLAYING_TIMES_LEN 0
#define AVRCP_ATTR_MAX_COVER_ART_HANDLE_LEN 0
typedef enum {
PASSTHROUGH_CMD_ID_SELECT,
PASSTHROUGH_CMD_ID_UP,
@ -146,47 +133,6 @@ typedef enum {
AVRCP_RESPONSE_TIMEOUT
} avrcp_response_t;
typedef enum {
AVRCP_ATTR_TITLE = 1,
AVRCP_ATTR_ARTIST_NAME,
AVRCP_ATTR_ALBUM_NAME,
AVRCP_ATTR_TRACK_NUMBER,
AVRCP_ATTR_TOTAL_NUMBER_OF_TRACKS,
AVRCP_ATTR_GENRE,
AVRCP_ATTR_PLAYING_TIME_MS,
AVRCP_ATTR_COVER_ART_HANDLE
} avrcp_media_attr_type_t;
/**
* @endcond
*/
/**
* @brief Callback for AVRCP connection state changed.
*
* There are four states for an AVRCP connection, namely DISCONNECTED, CONNECTING,
* CONNECTED, and DISCONNECTING. During the initialization phase of the AVRCP,
* it is necessary to register callback functions. This callback is triggered
* when there is a change in the state of the AVRCP connection.
*
* Stable States:
* DISCONNECTED: The initial state.
* CONNECTED: The AVRCP connection is established.
* Transient states:
* CONNECTING: The AVRCP connection is being established.
* DISCONNECTING: The AVRCP connection is being terminated.
*
* @param cookie - Callback cookie.
* @param addr - The Bluetooth address of the peer device.
* @param state - AVRCP profile connection state.
*
* **Example:**
* @code
static void on_connection_state_changed_cb(void* cookie, bt_address_t* addr, profile_connection_state_t state)
{
printf("AVRCP connection state is: %d", state);
}
* @endcode
*/
typedef void (*avrcp_connection_state_callback)(void* cookie, bt_address_t* addr, profile_connection_state_t state);
#endif /* __BT_AVRCP_H__ */

View File

@ -18,131 +18,12 @@
#include "bt_avrcp.h"
/**
* @cond
*/
typedef struct {
uint32_t attr_id;
uint16_t chr_set;
uint8_t* text;
} avrcp_element_attr_val_t;
typedef struct {
uint8_t title[AVRCP_ATTR_MAX_TIELE_LEN + 1];
uint8_t artist[AVRCP_ATTR_MAX_ARTIST_LEN + 1];
uint8_t album[AVRCP_ATTR_MAX_ALBUM_LEN + 1];
uint8_t track_number[AVRCP_ATTR_MAX_TRACK_NUMBER_LEN + 1];
uint8_t total_track_number[AVRCP_ATTR_MAX_TOTAL_TRACK_NUMBER_LEN + 1];
uint8_t gener[AVRCP_ATTR_MAX_GENER_LEN + 1];
uint8_t playing_time_ms[AVRCP_ATTR_MAX_PLAYING_TIMES_LEN + 1];
uint8_t cover_art_handle[AVRCP_ATTR_MAX_COVER_ART_HANDLE_LEN + 1];
} avrcp_socket_element_attr_val_t;
typedef void (*avrcp_get_element_attribute_cb)(void* cookie, bt_address_t* addr, uint8_t attrs_count, avrcp_element_attr_val_t* attrs);
typedef struct {
size_t size;
avrcp_connection_state_callback connection_state_cb;
avrcp_get_element_attribute_cb get_element_attribute_cb;
} avrcp_control_callbacks_t;
/**
* @endcond
*/
/**
* @brief Register callback functions to AVRCP Controller service.
*
* When initializing an AVRCP Controller, an application should register callback functions
* to the AVRCP Controller service. Subsequently, the AVRCP Controller service will
* notify the application of any state changes via the registered callback functions.
*
* Callback functions includes:
* * connection_state_cb
* * get_element_attribute_cb
*
* @param ins - Bluetooth client instance.
* @param callbacks - AVRCP Controller callback functions.
* @return void* - Callbacks cookie, if the callback is registered successfuly. NULL,
* if the callback is already registered or registration fails.
* To obtain more information, refer to bt_remote_callbacks_register().
*
* **Example:**
* @code
static const avrcp_control_callbacks_t avrcp_control_cbs = {
.size = sizeof(avrcp_control_cbs),
.connection_state_cb = avrcp_control_connection_state_cb,
.get_element_attribute_cb = avrcp_control_get_element_attribute_cb,
};
void avrcp_control_init(void* ins)
{
static void* control_cbks_cookie;
control_cbks_cookie = bt_avrcp_control_register_callbacks(ins, &avrcp_control_cbs);
}
* @endcode
*/
void* BTSYMBOLS(bt_avrcp_control_register_callbacks)(bt_instance_t* ins, const avrcp_control_callbacks_t* callbacks);
/**
* @brief Unregister callback functions from AVRCP Controller service.
*
* An application may use this interface to stop listening on the AVRCP Controller
* callbacks and to release the associated resources.
*
* @param ins - Bluetooth client instance.
* @param cookie - Callbacks cookie.
* @return true - Callback unregistration successful.
* @return false - Callback cookie not found or callback unregistration failed.
*
* **Example:**
* @code
void avrcp_control_uninit(void* ins)
{
bt_avrcp_control_unregister_callbacks(ins, control_cbks_cookie);
}
* @endcode
*/
bool BTSYMBOLS(bt_avrcp_control_unregister_callbacks)(bt_instance_t* ins, void* cookie);
/**
* @brief Get element attributes from AVRCP Target.
*
* This function is used when an application wants to obtain song information
* from an AVRCP Target device, including title, artist name, album name, track
* number, total number of tracks, genre, playing time.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
bt_status_t start_get_element_attributes(bt_instance_t* ins, bt_address_t* addr)
{
bt_status_t ret = bt_avrcp_control_get_element_attributes(ins, addr);
return ret;
}
*/
bt_status_t BTSYMBOLS(bt_avrcp_control_get_element_attributes)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Send passthrough cmd to peer device.
*
* @param ins - Bluetooth client instance.
* @param addr - Remote BT address.
* @param cmd - Passthrough cmd.
* @param state - PRESSED or RELEASED.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_avrcp_control_send_passthrough_cmd)(bt_instance_t* ins, bt_address_t* addr, uint8_t cmd, uint8_t state);
bt_status_t BTSYMBOLS(bt_avrcp_control_get_unit_info)(bt_instance_t* ins, bt_address_t* addr);
bt_status_t BTSYMBOLS(bt_avrcp_control_get_subunit_info)(bt_instance_t* ins, bt_address_t* addr);
bt_status_t BTSYMBOLS(bt_avrcp_control_get_playback_state)(bt_instance_t* ins, bt_address_t* addr);
bt_status_t BTSYMBOLS(bt_avrcp_control_register_notification)(bt_instance_t* ins, bt_address_t* addr, avrcp_notification_event_t event, uint32_t interval);
void* bt_avrcp_control_register_callbacks(bt_instance_t* ins, const avrcp_control_callbacks_t* callbacks);
bool bt_avrcp_control_unregister_callbacks(bt_instance_t* ins, void* cookie);
#endif /* __BT_AVRCP_CONTROL_H__ */

View File

@ -25,68 +25,38 @@ extern "C" {
#endif
/**
* @brief Callback for playing status request from AVRCP Controller.
*
* During the initialization process of an AVRCP target, callback functions are registered.
* This callback is triggered when a request for the current player status is received by
* the AVRCP Target from an AVRCP Controller.
*
* The status of the player includes: playing, paused, stopped, seek forward, and seek rewind.
* @brief Received Get Play Status request from CT.
*
* @param cookie - Callback cookie.
* @param addr - The Bluetooth address of the peer device.
*
* **Example:**
* @code
static void on_get_play_status_request_cb(void* cookie, bt_address_t* addr)
{
avrcp_play_status_t status = AVRCP_PLAY_STATUS_PLAYING;
uint32_t song_len = 180000;
uint32_t song_pos = 10000;
bt_instance_t* ins = cookie;
bt_avrcp_target_get_play_status_response(ins, addr, status, song_len, song_pos);
}
* @endcode
* @param addr - Remote BT address.
* @return void.
*/
typedef void (*avrcp_received_get_play_status_request_callback)(void* cookie, bt_address_t* addr);
/**
* @brief Callback for register notification request.
*
* All player application attributes can be registered as events by an AVRCP Controller.
* When an AVRCP Controller has registered a specific event to an AVRCP Target, the Target
* shall notify the Controller on change in value of the registered event. In particular,
* a notify command terminates after providing a corresponding change.
* @brief Received register notification request callback.
*
* @param cookie - Callback cookie.
* @param addr - The Bluetooth address of the peer device.
* @param event - The event that the AVRCP Controller wants to be notified about.
* @param interval - Applicable only for PLAY_POS_CHANGED event.
*
* **Example:**
* @code
uint16_t notify_event = 0;
static void on_register_notification_request_cb(void* cookie, bt_address_t* addr, avrcp_notification_event_t event, uint32_t interval)
{
notify_event |= event;
}
* @endcode
* @param addr - Remote BT address.
* @param event - The event for which the CT requires notifications.
* @param interval - Only works in PLAY_POS_CHANGED event.
*/
typedef void (*avrcp_received_register_notification_request_callback)(void* cookie, bt_address_t* addr, avrcp_notification_event_t event, uint32_t interval);
/**
* @brief Callback for panel operation.
* @brief Received panel operation from CT.
*
* @param cookie - Callback cookie.
* @param addr - The Bluetooth address of the peer device.
* @param addr - Remote BT address.
* @param op - Panel operation.
* @param state - Key state.
* @param state - Key state
*/
typedef void (*avrcp_received_panel_operation_callback)(void* cookie, bt_address_t* addr, uint8_t op, uint8_t state);
/**
* @cond
*/
typedef struct {
size_t size;
avrcp_connection_state_callback connection_state_cb;
@ -94,129 +64,49 @@ typedef struct {
avrcp_received_register_notification_request_callback received_register_notification_request_cb;
avrcp_received_panel_operation_callback received_panel_operation_cb;
} avrcp_target_callbacks_t;
/**
* @endcond
*/
/**
* @brief Register callback functions to AVRCP Target service.
*
* When initializing an AVRCP Target, an application should register callback functions
* to the AVRCP Target service. Subsequently, the AVRCP Target service will notify the
* application of any state changes via the registered callback functions.
*
* Callback functions includes:
* * connection_state_cb
* * received_get_play_status_request_cb
* * received_register_notification_request_cb
* * received_panel_operation_cb
*
* @brief Register callback functions to AVRCP Target
*
* @param ins - Bluetooth client instance.
* @param callbacks - AVRCP Target callback functions.
* @return void* - Callbacks cookie, if the callback is registered successfuly. NULL,
* if the callback is already registered or registration fails.
* To obtain more information, refer to bt_remote_callbacks_register().
*
* **Example:**
* @code
const static avrcp_target_callbacks_t g_avrcp_target_cbs = {
.size = sizeof(avrcp_target_callbacks_t),
.connection_state_cb = on_connection_state_changed_cb,
.received_get_play_status_request_cb = on_get_play_status_request_cb,
.received_register_notification_request_cb = on_register_notification_request_cb,
.received_panel_operation_cb = on_received_panel_operation_cb,
};
void avrcp_target_init(void* ins)
{
static void* target_cbks_cookie;
target_cbks_cookie = bt_avrcp_target_register_callbacks(ins, &g_avrcp_target_cbs);
}
* @endcode
* @return void* - Callbacks cookie.
*/
void* BTSYMBOLS(bt_avrcp_target_register_callbacks)(bt_instance_t* ins, const avrcp_target_callbacks_t* callbacks);
/**
* @brief Unregister callback functions to AVRCP Target service.
*
* An application may use this interface to stop listening on the AVRCP Target
* callbacks and to release the associated resources.
* @brief Unregister callback functions to AVRCP Target
*
* @param ins - Bluetooth client instance.
* @param cookie - Callbacks cookie.
* @return true - Callback unregistration successful.
* @return false - Callback cookie not found or callback unregistration failed.
*
* **Example:**
* @code
void avrcp_target_uninit(void* ins)
{
bt_avrcp_target_unregister_callbacks(ins, target_cbks_cookie);
}
* @return bool - True, if unregister success, false otherwise.
*/
bool BTSYMBOLS(bt_avrcp_target_unregister_callbacks)(bt_instance_t* ins, void* cookie);
/**
* @brief Tell the AVRCP Controller the current state of the player.
*
* An application of an AVRCP Target will call this interface to send the current
* status of the player when "received_get_play_status_request_cb" event is triggered.
* Additionally, the total length and the position of the current song should also
* be returned as described in the AVRCP profile. In particular, if this Target does
* not support total length and current position of the song, then the Target shall
* return 0xFFFFFFFF.
* @brief Send response of Get Play Status request to CT.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @param addr - Remote BT address.
* @param status - Current play status.
* @param song_len - Song length in ms.
* @param song_pos - Current position in ms.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
static void on_get_play_status_request_cb(void* cookie, bt_address_t* addr)
{
avrcp_play_status_t status = AVRCP_PLAY_STATUS_PLAYING;
uint32_t song_len = 0xFFFFFFFF;
uint32_t song_pos = 0xFFFFFFFF;
bt_instance_t* ins = cookie;
bt_avrcp_target_get_play_status_response(ins, addr, status, song_len, song_pos);
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_avrcp_target_get_play_status_response)(bt_instance_t* ins, bt_address_t* addr, avrcp_play_status_t status,
uint32_t song_len, uint32_t song_pos);
/**
* @brief Notify the status of a player if peer device has registered the corresponding event.
*
* If the status of a player changes and an AVRCP Controller has registered for that event,
* the AVRCP target should use that interface to send a change notification to the Controller
* with the current status. In particular, after this notification, the registered notification
* event by the AVRCP Controller becomes invalid.
* @brief Notify playback status if peer device had register playback notification
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @param status - Current play status.
* @param addr - Remote BT address.
* @param status - current play status.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
uint16_t notify_event;
static void avrcp_target_play_status_changed(void* cookie, bt_address_t* addr, avrcp_play_status_t status)
{
bt_instance_t* ins = cookie;
if (notify_event & AVRCP_NOTIFICATION_EVENT_PLAY_STATUS_CHANGED) {
bt_avrcp_target_play_status_notify(ins, addr, status);
notify_event &= ~AVRCP_NOTIFICATION_EVENT_PLAY_STATUS_CHANGED;
}
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_avrcp_target_play_status_notify)(bt_instance_t* ins, bt_address_t* addr, avrcp_play_status_t status);

View File

@ -15,6 +15,7 @@
#elif defined(ANDROID)
#define CONFIG_NET_RPMSG 1
#define CONFIG_LIB_BLUELET 1
#define CONFIG_QBUF_COUNT 20
#define CONFIG_BREDR 1
@ -42,8 +43,7 @@
#define CONFIG_BLUETOOTH_BLE_SUPPORT 1
#define CONFIG_BLUETOOTH_BLE_ADV 1
#define CONFIG_BLUETOOTH_BLE_SCAN 1
#define CONFIG_BLUETOOTH_GATT_CLIENT 1
#define CONFIG_BLUETOOTH_GATT_SERVER 1
#define CONFIG_BLUETOOTH_GATT 1
#define CONFIG_BLUETOOTH_SERVICE_LOOP_THREAD_STACK_SIZE 8192
#define CONFIG_BLUETOOTH_SERVICE_LOOP_THREAD_PRIORITY 103
#define CONFIG_BLUETOOTH_AUDIO_TRANS_RPSMG_SERVER 1
@ -60,9 +60,8 @@
#define CONFIG_BLUETOOTH_LEA_SINK_DATA_PATH "lea_sink_data"
#define CONFIG_BLUETOOTH_LEA_SOURCE_CTRL_PATH "lea_source_ctrl"
#define CONFIG_BLUETOOTH_LEA_SOURCE_DATA_PATH "lea_source_data"
#define CONFIG_BLUETOOTH_MAX_SAVED_REMOTE_UUIDS_LEN 80
#define CONFIG_BLUETOOTH_SCO_CTRL_PATH "sco_ctrl"
// #define CONFIG_BLUETOOTH_L2CAP 1
//#define CONFIG_BLUETOOTH_L2CAP 1
#define CONFIG_BLUETOOTH_L2CAP_OUTGOING_MTU 2048
#define CONFIG_BLUETOOTH_GATTC_MAX_CONNECTIONS 8
#define CONFIG_BLUETOOTH_GATTS_MAX_ATTRIBUTE_NUM 10
@ -79,15 +78,15 @@
#define CONFIG_BLUETOOTH_SPP_SERVER_MAX_CONNECTIONS 8
#define CONFIG_BLUETOOTH_MAX_REGISTER_NUM 4
#define CONFIG_BLUETOOTH_FRAMEWORK 1
// #define CONFIG_BLUETOOTH_FRAMEWORK_LOCAL 1
//#define CONFIG_BLUETOOTH_FRAMEWORK_LOCAL 1
#define CONFIG_BLUETOOTH_FRAMEWORK_SOCKET_IPC 1
#define CONFIG_BLUETOOTH_SOCKET_PORT 6001
#define CONFIG_BLUETOOTH_SERVICE 1
// #define CONFIG_BLUETOOTH_SERVER 1
//#define CONFIG_BLUETOOTH_SERVER 1
#define CONFIG_BLUETOOTH_SERVER_NAME "bluetoothd"
#define CONFIG_BLUETOOTH_IPC_JOIN_LOOP 1
// #define CONFIG_BLUETOOTH_SERVICE_LOG_LEVEL 7
#define CONFIG_BLUETOOTH_SERVICE_HCI_UART_NAME "/dev/ttyHCI0"
//#define CONFIG_BLUETOOTH_SERVICE_LOG_LEVEL 7
#define CONFIG_BLUETOOTH_SERVICE_HCI_UART_NAME "/dev/ttyBT0"
#define CONFIG_BLUETOOTH_STACK_BREDR_BLUELET 1
#define CONFIG_BLUETOOTH_STACK_LE_BLUELET 1
#define CONFIG_BLUETOOTH_LE_SCANNER_MAX_NUM 2
@ -95,26 +94,16 @@
#define CONFIG_BLUETOOTH_TOOLS 1
#define CONFIG_BLUETOOTH_VENDOR_BES 1
// Socket: via RPMsg
#define CONFIG_NET_RPMSG 1
// Socket: via IPv4
// #define CONFIG_NET_IPv4 1
// #define CONFIG_BLUETOOTH_NET_IPv4 1
//#define CONFIG_NET_IPv4 1
#define CONFIG_INADDR_LOOPBACK 0x0A000202
// SPP
#define CONFIG_RPMSG_UART 1
// SPP via RPMsg UART "/dev/ttyDROID"
// #define CONFIG_RPMSG_UART 1
// SPP via RPMsg socket/pipe
#define CONFIG_BLUETOOTH_SPP_RPMSG_NET 1
/********************* O95 Project Only *********************/
#if defined(ANDROID_12)
// Socket: RPMsg
#define CONFIG_BLUETOOTH_RPMSG_CPUNAME "ap"
// SPP
#define CONFIG_RPMSG_UART 1
/********************* O61 Project Only *********************/
#elif defined(ANDROID_14)
@ -131,7 +120,7 @@
#endif
// ############################################################################
//############################################################################
#define CONFIG_y 1
#define CONFIG_m 2

View File

@ -1,203 +0,0 @@
/****************************************************************************
* 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_CS_H__
#define __BT_CS_H__
#include <stdbool.h>
#include <stddef.h>
#include "bluetooth.h"
#include "bt_addr.h"
#ifndef BTSYMBOLS
#define BTSYMBOLS(s) s
#endif
#define MAX_TEST_DATA 128
typedef struct {
uint8_t centimeter;
uint8_t error_centimeter;
uint8_t azimuth_angle;
uint8_t error_azimuthAngle;
uint8_t altitude_angle;
uint8_t error_altitudeAngle;
long elapsed_realtime_nanos;
uint8_t confidence_level;
double delay_spread_meters;
uint8_t detected_attack_level;
double velocity_meters_persecond;
uint8_t method;
} bt_distance_measurement_result_t;
typedef void (*cs_distance_measure_started_cb)(void* cookie, bt_address_t* addr, uint8_t method);
typedef void (*cs_distance_measure_stopped_cb)(void* cookie, bt_address_t* addr, uint8_t reason, uint8_t method);
typedef void (*cs_distance_measure_result_cb)(void* cookie, bt_address_t* addr, bt_distance_measurement_result_t* result);
/**
* @cond
*/
typedef struct {
bt_address_t addr;
uint8_t method;
uint8_t role;
uint16_t interval_ms;
uint16_t duration_ms;
uint8_t submode;
uint8_t max_steps;
uint8_t mode0_steps;
uint8_t rtt_type;
uint8_t sync_phy;
uint8_t channel_map;
uint8_t antenna_paths_mask;
uint8_t vendor_specific;
uint8_t debug_flags;
} bt_distance_measurement_params_t;
typedef struct {
size_t size;
cs_distance_measure_started_cb cs_distance_measure_started_cb;
cs_distance_measure_stopped_cb cs_distance_measure_stopped_cb;
cs_distance_measure_result_cb cs_distance_measure_result_cb;
} cs_callbacks_t;
typedef enum {
METHOD_AUTO,
METHOD_RSSI,
METHOD_CS,
} cs_method_t;
/**
* @endcond
*/
/**
* @brief register cs event callback
*
* register cs event callback.
*
* @param ins bt instance.
* @param callbacks cs event callback function.
* @return cookie of cs event callback.
*/
void* BTSYMBOLS(bt_cs_register_callbacks)(bt_instance_t* ins, const cs_callbacks_t* callbacks);
/**
* @brief unregister cs event callback
*
* unregister cs event callback.
*
* @param ins bt instance.
* @param cookie cookie of cs event callback.
* @return true if success, false otherwise.
*/
bool BTSYMBOLS(bt_cs_unregister_callbacks)(bt_instance_t* ins, void* cookie);
/**
* @brief start distance measurement
*
* start distance measurement.
*
* @param ins bt instance.
* @param params distance measurement parameters.
* @return bt_status_t.
*/
bt_status_t BTSYMBOLS(bt_cs_start_distance_measurement)(bt_instance_t* ins, const bt_distance_measurement_params_t* params);
/**
* @brief stop distance measurement
*
* stop distance measurement.
*
* @param ins bt instance.
* @param addr remote device address.
* @param method method of distance measurement.
* @param timeout timeout flag.
* @return bt_status_t.
*/
bt_status_t BTSYMBOLS(bt_cs_stop_distance_measurement)(bt_instance_t* ins, bt_address_t* addr, uint8_t method, bool timeout);
/**
* @brief get max supported security level
*
* get max supported security level of remote device.
*
* @param ins bt instance.
* @param addr remote device address.
* @return bt_status_t.
*/
bt_status_t BTSYMBOLS(bt_get_cs_max_supported_security_level)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief RAS feature bits for ras_feature field
*/
#define BT_CS_RAS_REAL_TIME_RANGING_DATA 0x01 /**< Bit 0: Real-time Ranging Data */
#define BT_CS_RAS_RETRIEVE_LOST_DATA_SEGMENTS 0x02 /**< Bit 1: Retrieve Lost Ranging Data Segments */
#define BT_CS_RAS_ABORT_OPERATION 0x04 /**< Bit 2: Abort Operation */
#define BT_CS_RAS_FILTER_RANGING_DATA 0x08 /**< Bit 3: Filter Ranging Data */
/**
* @brief CS_SYNC antenna selection values
*/
#define BT_CS_ANTENNA_SEL_1 0x01 /**< Use antenna identifier 1 */
#define BT_CS_ANTENNA_SEL_2 0x02 /**< Use antenna identifier 2 */
#define BT_CS_ANTENNA_SEL_3 0x03 /**< Use antenna identifier 3 */
#define BT_CS_ANTENNA_SEL_4 0x04 /**< Use antenna identifier 4 */
#define BT_CS_ANTENNA_SEL_SINGLE_REPEATE 0xFD /**< Antenna identifiers in repetitive order (0x01, 0x01, ..., Num_Antennae_Supported, Num_Antennae_Supported) */
#define BT_CS_ANTENNA_SEL_DOUBLE_REPEATE 0xFE /**< Antenna identifiers in repetitive order from 0x01 to Num_Antennae_Supported */
#define BT_CS_ANTENNA_SEL_NO_RECOMMEND 0xFF /**< Host does not have a recommendation */
/**
* @brief CS configuration parameters for set command
*/
typedef struct {
uint32_t ras_feature; /**< RAS feature bits: Bit 0 (0x01): Real-time Ranging Data,
Bit 1 (0x02): Retrieve Lost Ranging Data Segments,
Bit 2 (0x04): Abort Operation,
Bit 3 (0x08): Filter Ranging Data */
uint8_t role; /**< CS role bits: Bit 0 (0x01): initiator, Bit 1 (0x02): reflector */
uint8_t cs_sync_antenna_selection; /**< Antenna selection for CS_SYNC packets, see BT_CS_ANTENNA_SEL_* macros */
int8_t max_tx_power; /**< Maximum TX power in dBm (-127 to 20) */
} bt_cs_set_params_t;
/**
* @brief set CS configuration
*
* set CS configuration including RAS feature and default settings.
*
* @param ins bt instance.
* @param addr remote device address.
* @param params CS configuration parameters, see @ref bt_cs_set_params_t.
* @return bt_status_t.
*/
bt_status_t BTSYMBOLS(bt_cs_set_config)(bt_instance_t* ins, bt_address_t* addr, const bt_cs_set_params_t* params);
#ifdef CONFIG_BT_CS_RAS_TEST
/**
* @brief test function
*
* test function.
*
* @param ins bt instance.
* @param data test subevent result data.
* @param len length of test data.
* @return bt_status_t.
* @note only for test.
*/
bt_status_t BTSYMBOLS(bt_cs_test)(bt_instance_t* ins, const void* data, uint16_t len);
#endif /* CONFIG_BT_CS_RAS_TEST */
#endif /* __BT_CS_H__ */

View File

@ -5,69 +5,6 @@
extern "C" {
#endif
#include "bt_time.h"
/* Time value structure for Bluetooth debug timing */
typedef struct timeval_s {
uint64_t entry_time;
uint64_t exit_time;
uint64_t max_timeval;
uint64_t last_timeval;
} bt_timeval_t;
/* Define macro to create a timeval structure for debugging */
#ifdef CONFIG_BLUETOOTH_DEBUG_TIMEVAL
#define BT_DEBUG_MKTIMEVAL_S(name_s) \
bt_timeval_t g_timeval_##name_s = { 0, 0, 0, 0 }
#else
#define BT_DEBUG_MKTIMEVAL_S(name_s) /* No operation */
#endif
/* Macro to get current timestamp */
#ifdef CONFIG_BLUETOOTH_DEBUG_TIMEVAL
#ifdef CONFIG_BLUETOOTH_DEBUG_TIME_UNIT_US
#define _GetCurrTime() ((uint64_t)bt_get_os_timestamp_us())
#else
#define _GetCurrTime() ((uint64_t)bt_get_os_timestamp_ms())
#endif
#else
#define _GetCurrTime() 0
#endif
/* Macro to mark entry of a time section */
#ifdef CONFIG_BLUETOOTH_DEBUG_TIMEVAL
#define BT_DEBUG_ENTER_TIME_SECTION(name_s) \
do { \
g_timeval_##name_s.entry_time = _GetCurrTime(); \
} while (0)
#else
#define BT_DEBUG_ENTER_TIME_SECTION(name_s) /* No operation */
#endif
/* Macro to mark exit of a time section */
#ifdef CONFIG_BLUETOOTH_DEBUG_TIMEVAL
#define BT_DEBUG_EXIT_TIME_SECTION(name_s) \
do { \
if (g_timeval_##name_s.entry_time != 0) { \
g_timeval_##name_s.exit_time = _GetCurrTime(); \
if (g_timeval_##name_s.exit_time >= g_timeval_##name_s.entry_time) { \
g_timeval_##name_s.last_timeval = g_timeval_##name_s.exit_time - g_timeval_##name_s.entry_time; \
if (g_timeval_##name_s.last_timeval > g_timeval_##name_s.max_timeval) { \
g_timeval_##name_s.max_timeval = g_timeval_##name_s.last_timeval; \
} \
} else { \
/* if exit_time < entry_time, reset all to zero */ \
g_timeval_##name_s.entry_time = 0; \
g_timeval_##name_s.exit_time = 0; \
g_timeval_##name_s.last_timeval = 0; \
g_timeval_##name_s.max_timeval = 0; \
} \
} \
} while (0)
#else
#define BT_DEBUG_EXIT_TIME_SECTION(name_s) /* No operation */
#endif
#if defined(__NuttX__) // Vela
#include <debug.h>

View File

@ -29,10 +29,6 @@ extern "C" {
#define BTSYMBOLS(s) s
#endif
/**
* @cond
*/
/**
* @brief Profile connection state
*
@ -90,788 +86,339 @@ typedef enum {
} connection_policy_t;
/**
* @endcond
*/
/**
* @brief Get the BLE Identity Address of a remote device.
* @brief Get identity address of remote device
*
* Retrieves the BLE Identity Address (`id_addr`) of a remote device. The Identity Address is a fixed
* BLE address used to identify the device, distinct from the current BLE address (`bd_addr`) when
* privacy features such as Resolvable Private Address (RPA) are enabled.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param bd_addr - Current BLE address of the remote device:
* - Public Device Address
* - Random Device Address (Static or Resolvable Private Address)
* @param[out] id_addr - Pointer to store the Identity Address, which will be one of:
* - Public Device Address
* - Static Random Address
*
* @return bt_status_t
* - `BT_STATUS_SUCCESS`: Successfully retrieved the Identity Address.
* - Negative error code: Operation failed (e.g., invalid address or device not found).
*
* @note **Difference Between `bd_addr` and `id_addr`:**
* - **`bd_addr`**: The device's current BLE connection address, which may change if privacy
* features such as RPA are used. It is used for ongoing communication.
* - **`id_addr`**: The stable Identity Address, which will always be one of:
* - **Public Device Address**: Globally unique and assigned by the manufacturer.
* - **Static Random Address**: Fixed and randomly generated, persistent across power cycles.
*
* @note **Bluetooth Address Details:**
* - **Public Device Address**: Globally unique address assigned by the manufacturer, also used
* as BD_ADDR for BR/EDR devices.
* - **Random Device Address**: Includes:
* - **Static Address**: Fixed random address when privacy is not enabled.
* - **Resolvable Private Address (RPA)**: Temporary address used for privacy, resolved to
* the Identity Address using the IRK (Identity Resolving Key).
* - **Identity Address**: A fixed address used to identify the device.
*
* The Identity Address is typically obtained during pairing and stored for future use.
*
* **Example:**
* @code
bt_address_t bd_addr; // Current BLE connection address
bt_address_t id_addr; // Identity Address to retrieve
if (bt_device_get_identity_address(ins, &bd_addr, &id_addr) == BT_STATUS_SUCCESS) {
// Successfully retrieved the Identity Address
} else {
// Handle failure
}
* @endcode
* @param ins - bluetooth client instance.
* @param bd_addr - remote device address.
* @param[out] id_addr - identity address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_get_identity_address)(bt_instance_t* ins, bt_address_t* bd_addr, bt_address_t* id_addr);
/**
* @brief Get the BLE address type of a remote device.
* @brief Get identity address of remote device
*
* Retrieves the BLE address type, indicating whether it is Public, Static Random, RPA,
* or other specific types.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @return ble_addr_type_t
* - The BLE address type of the device.
* - Returns `BLE_ADDR_TYPE_UNKNOWN` if the device is not found.
*
* @note **Address Types:**
* - **BT_LE_ADDR_TYPE_PUBLIC**: Public address, globally unique and unchanging.
* - **BT_LE_ADDR_TYPE_RANDOM**: Random address, used during connections (e.g., RPA or static random).
* When used locally (e.g., in advertising), this indicates a static random address
* set via `bt_adapter_set_le_address`.
* - **BT_LE_ADDR_TYPE_PUBLIC_ID**: Public identity address, using public address for identification
* even if a static random address is set.
* - **BT_LE_ADDR_TYPE_RANDOM_ID**: Random identity address (e.g., RPA), used when
* the privacy feature is enabled.
* - **BT_LE_ADDR_TYPE_ANONYMOUS**: Anonymous address, often used with Accept/White Lists.
* - **BT_LE_ADDR_TYPE_UNKNOWN**: The address type cannot be determined.
*
* **Example:**
* @code
ble_addr_type_t addr_type = bt_device_get_address_type(ins, &addr);
if (addr_type != BLE_ADDR_TYPE_UNKNOWN) {
// Handle the specific address type
if (addr_type == BLE_ADDR_TYPE_PUBLIC) {
// Process public address
}
} else {
// Device not found
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return ble_addr_type_t - address type, UNKNOWN on device not found.
*/
ble_addr_type_t BTSYMBOLS(bt_device_get_address_type)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Get device type of a remote device.
* @brief Get remote device type
*
* Retrieves the device type (e.g., BR/EDR, LE, Dual Mode) of a remote device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @return bt_device_type_t - Device type; zero if the device is not found.
*
* **Example:**
* @code
bt_device_type_t device_type = bt_device_get_device_type(ins, &addr);
if (device_type != 0) {
// Use device_type as needed
} else {
// Handle device not found
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return bt_device_type_t - device type, zero on device not found.
*/
bt_device_type_t BTSYMBOLS(bt_device_get_device_type)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Retrieve the name of a remote device.
* @brief Get remote device name
*
* Retrieves the user-friendly name of a remote Bluetooth device in UTF-8 encoding.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param[out] name - Buffer to store the device name. The name is UTF-8 encoded.
* - According to the Bluetooth specification, the buffer size for the device name must not exceed 248 bytes.
* - On the Vela platform, the maximum allowed name length is defined as `BT_DEV_NAME_MAX_LEN`.
* To handle the null terminator properly, the buffer should be sized at `BT_DEV_NAME_MAX_LEN + 1`,
* where the last byte ensures the string is null-terminated.
* @param length - Size of the name buffer.
* @return true - The device name was successfully retrieved.
* @return false - The device was not found or the name could not be retrieved.
*
* @note **Buffer Requirements:**
* - Ensure the `name` buffer is large enough to store the device name, including space for the null terminator.
* - On the Vela platform:
* - The maximum effective name length is `BT_DEV_NAME_MAX_LEN`.
* - Allocate `BT_DEV_NAME_MAX_LEN + 1` bytes to account for the null terminator and avoid buffer overflow issues.
* - According to the Bluetooth specification, the buffer size must not exceed 248 bytes.
*
* **Example:**
* @code
char name[BT_DEV_NAME_MAX_LEN + 1]; // Allocate buffer for the name and null terminator.
if (bt_device_get_name(ins, &addr, name, sizeof(name))) {
// Use name as needed
} else {
// Handle device not found
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param[out] name - remote device name.
* @param length - maximum length of name buffer.
* @return true - on success.
* @return false - on device not found.
*/
bool BTSYMBOLS(bt_device_get_name)(bt_instance_t* ins, bt_address_t* addr, char* name, uint32_t length);
/**
* @brief Get the Class of Device (CoD) of a remote device.
* @brief Get remote device class
*
* Retrieves the Class of Device (CoD) value of a remote device.
* The Class of Device is a parameter received during the device discovery procedure
* on the BR/EDR physical transport, indicating the type of device.
* The Class of Device parameter is only used on BR/EDR and BR/EDR/LE devices
* using the BR/EDR physical transport.
*
* - The CoD parameter consists of:
* - **Major Device Class**: Represents the primary category of the device (e.g., computer, phone, audio).
* - **Minor Device Class**: Provides a more specific classification (e.g., headset, smartphone).
* - **Service Class**: Indicates supported services (e.g., telephony, audio streaming).
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @return uint32_t - CoD value; zero if the device is not found.
*
* **Example:**
* @code
uint32_t cod = bt_device_get_device_class(ins, &addr);
if (cod != 0) {
// Use cod as needed
} else {
// Handle device not found
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return uint32_t - cod, zero on device not found.
*/
uint32_t BTSYMBOLS(bt_device_get_device_class)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Get the list of supported UUIDs of a remote device.
* @brief Get remote device support uuids
*
* Retrieves the list of Universally Unique Identifiers (UUIDs) supported by a remote device.
* A UUID is a universally unique identifier that is expected to be unique across all
* space and time (more precisely, the probability of independently-generated UUIDs
* being the same is negligible). Normally, a client searches for services based on
* specific desired characteristics, each represented by a UUID.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param[out] uuids - Pointer to an array of UUIDs; memory is allocated using the provided allocator.
* @param[out] size - Number of UUIDs retrieved.
* @param allocator - Allocator function used to allocate memory for the UUID array.
* @return bt_status_t
* - `BT_STATUS_SUCCESS`: UUIDs successfully retrieved.
* - Negative error code: Operation failed.
*
* **Example:**
* @code
bt_uuid_t* uuids = NULL;
uint16_t size = 0;
if (bt_device_get_uuids(ins, &addr, &uuids, &size, my_allocator) == BT_STATUS_SUCCESS) {
// Use the UUID array as needed
// Free memory using the allocator's deallocation function
} else {
// Handle the error
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param[out] uuids - out remote device uuids array.
* @param[out] size - out remote device uuid array size.
* @param allocator - array allocator.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
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);
/**
* @brief Get the BLE appearance of a remote device.
*
* Retrieves the Appearance characteristic of a remote device. The Appearance
* characteristic contains a 16-bit number that can be mapped to an icon or string
* that describes the physical representation of the device during the device discovery
* procedure. It is a characteristic of the GAP service located on the devices GATT Server.
*
* @note Currently not supported.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @return uint16_t - Appearance value; zero if the device is not found or the operation is unsupported.
* @brief Get remote device LE apperance
* @note Not support
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return uint16_t - apperance, zero on device not found.
*/
uint16_t BTSYMBOLS(bt_device_get_appearance)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Get the RSSI (Received Signal Strength Indication) of a remote device.
*
* @note This API is applicable only availble for BR/EDR connected devices.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @return int8_t - RSSI value.
* @brief Get remote device RSSI
* @note Not support
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return int8_t - rssi.
*/
int8_t BTSYMBOLS(bt_device_get_rssi)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Get the alias of a remote device.
* @brief Get remote device alias, default use remote name if not set
*
* Retrieves the alias (user-defined name) of a remote device. If an alias is not set, the device name is used.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param[out] alias - Buffer to store the alias.
* @param length -length of the alias buffer, the alias buffer size shall be no smaller than 64.
* @return true - Success.
* @return false - Device not found.
*
* **Example:**
* @code
char alias[64]; // The alias buffer size shall be no smaller than 64
if (bt_device_get_alias(ins, &addr, alias, sizeof(alias))) {
// Use alias as needed
} else {
// Handle device not found
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param[out] alias - out alias buffer.
* @param length - maximum length of alias buffer.
* @return true on success.
* @return false on device not found.
*/
bool BTSYMBOLS(bt_device_get_alias)(bt_instance_t* ins, bt_address_t* addr, char* alias, uint32_t length);
/**
* @brief Set the alias of a remote device.
* @brief Set remote device alias
*
* Assigns an alias (user-defined name) to a remote device.
* The length of the alias name shall be less than BT_LOC_NAME_MAX_LEN.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param alias - New alias for the device.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*
* **Example:**
* @code
if (bt_device_set_alias(ins, &addr, "My Device") == BT_STATUS_SUCCESS) {
// Alias set successfully
} else {
// Handle error
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param alias - alias.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_set_alias)(bt_instance_t* ins, bt_address_t* addr, const char* alias);
/**
* @brief Check if a remote device is connected.
* @brief Check remote deivce is connected
*
* Determines whether a remote device is currently connected.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param transport - Transport type, see @ref bt_transport_t.
* @return true - Device is connected.
* @return false - Device is not connected.
*
* **Example:**
* @code
if (bt_device_is_connected(ins, &addr, BT_TRANSPORT_BR_EDR)) {
// Device is connected
} else {
// Device is not connected
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return true - connected.
* @return false - not connected.
*/
bool BTSYMBOLS(bt_device_is_connected)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport);
/**
* @brief Check if a remote device connection is encrypted.
* @brief Check remote deivce is encrypted
*
* Determines whether the connection to a remote device is encrypted.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param transport - Transport type, see @ref bt_transport_t.
* @return true - Connection is encrypted.
* @return false - Connection is not encrypted.
*
* **Example:**
* @code
if (bt_device_is_encrypted(ins, &addr, BT_TRANSPORT_LE)) {
// Connection is encrypted
} else {
// Connection is not encrypted
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return true - encrypted
* @return false - not encrypted
*/
bool BTSYMBOLS(bt_device_is_encrypted)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport);
/**
* @brief Check if bonding was initiated from the local device.
* @brief Check is bond initiate from local
*
* Determines whether the bonding process with a remote device was initiated locally.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param transport - Transport type, see @ref bt_transport_t.
* @return true - Bonding initiated from local device.
* @return false - Bonding initiated from remote device.
*
* **Example:**
* @code
if (bt_device_is_bond_initiate_local(ins, &addr, BT_TRANSPORT_LE)) {
// Bonding initiated locally
} else {
// Bonding initiated remotely
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return true - initiate from local.
* @return false - initiate from remote.
*/
bool BTSYMBOLS(bt_device_is_bond_initiate_local)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport);
/**
* @brief Get the bond state with a remote device.
* @brief Get remote device bond state
*
* Retrieves the current bonding state with a remote device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param transport - Transport type, see @ref bt_transport_t.
* @return bond_state_t - Current bond state, see @ref bond_state_t.
*
* **Example:**
* @code
bond_state_t bond_state = bt_device_get_bond_state(ins, &addr, BT_TRANSPORT_BR_EDR);
switch (bond_state) {
case BOND_STATE_NONE:
// Not bonded
break;
case BOND_STATE_BONDING:
// Bonding in progress
break;
case BOND_STATE_BONDED:
// Bonded
break;
case BOND_STATE_CANCELING:
// Bonding is being canceled
break;
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return bond_state_t - bond state.
*/
bond_state_t BTSYMBOLS(bt_device_get_bond_state)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport);
/**
* @brief Check if a remote device is bonded.
* @brief Check remote device is bonded
*
* Determines whether a remote device is bonded with the local device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param transport - Transport type, see @ref bt_transport_t.
* @return true - Device is bonded.
* @return false - Device is not bonded.
*
* **Example:**
* @code
if (bt_device_is_bonded(ins, &addr, BT_TRANSPORT_LE)) {
// Device is bonded
} else {
// Device is not bonded
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return true - bonded
* @return false - not bonded
*/
bool BTSYMBOLS(bt_device_is_bonded)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport);
/**
* @brief Initiate bonding with a remote device.
* @brief Initiate bond to remote device
*
* Starts the bonding process with a remote device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param transport - Transport type (0: LE, 1: BR/EDR).
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*
* **Example:**
* @code
if (bt_device_create_bond(ins, &addr, BT_TRANSPORT_BR_EDR) == BT_STATUS_SUCCESS) {
// Bonding initiated successfully
} else {
// Handle error
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param transport - transport type (0:BLE, 1:BREDR).
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_create_bond)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport);
/**
* @brief Set the security level for bond.
* @brief Remove bonded device
*
* Dynamically set the security level when bond with remote device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param level - set the security level(0 ~ 4). Level 0: Only for BR/EDR special cases, like SDP
* @param transport - Transport type (0: LE, 1: BR/EDR).
* @return bt_status_t - BT_STATUS_SUCCESS on success; a error code on failure.
*
* **Example:**
* @code
// bond with Authenticated Secure Connections
bt_device_set_security_level(ins, 4, BT_TRANSPORT_BLE);
bt_device_create_bond(ins, &addr, BT_TRANSPORT_BLE);
* @endcode
*/
bt_status_t BTSYMBOLS(bt_device_set_security_level)(bt_instance_t* ins, uint8_t level, bt_transport_t transport);
/**
* @brief Set LE bond mode.
*
* Dynamically set the bond mode when bond with remote device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param bool - bondable. true for bondable, false for non-bondable.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a error code on failure.
*
* **Example:**
* @code
// pair with non-bondable mode
bt_device_set_bondable_le(ins, false);
bt_device_create_bond(ins, &addr, BT_TRANSPORT_BLE);
* @endcode
*/
bt_status_t BTSYMBOLS(bt_device_set_bondable_le)(bt_instance_t* ins, bool bondable);
/**
* @brief Remove bonding with a remote device.
*
* Removes the bonding information of a remote device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param transport - Transport type (0: LE, 1: BR/EDR).
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*
* **Example:**
* @code
if (bt_device_remove_bond(ins, &addr, BT_TRANSPORT_LE) == BT_STATUS_SUCCESS) {
// Bonding removed successfully
} else {
// Handle error
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param transport - transport type (0:BLE, 1:BREDR).
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_remove_bond)(bt_instance_t* ins, bt_address_t* addr, uint8_t transport);
/**
* @brief Cancel an ongoing bonding process.
* @brief Cancel bonding
*
* Cancels the bonding process with a remote device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*
* **Example:**
* @code
if (bt_device_cancel_bond(ins, &addr) == BT_STATUS_SUCCESS) {
// Bonding canceled successfully
} else {
// Handle error
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_cancel_bond)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Reply to a pairing request.
* @brief Reply pairing request
*
* Responds to a pairing request from a remote device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param accept - true to accept the pairing request; false to reject.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*
* **Example:**
* @code
if (bt_device_pair_request_reply(ins, &addr, true) == BT_STATUS_SUCCESS) {
// Pairing request accepted
} else {
// Handle error
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param accept - true:accept, false:reject.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_pair_request_reply)(bt_instance_t* ins, bt_address_t* addr, bool accept);
/**
* @brief Set pairing confirmation for secure pairing.
* @brief Set pairing confirmation
*
* Confirms or rejects a pairing confirmation request, typically used in Just Works or Passkey Confirmation scenarios.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param transport - Transport type (0: LE, 1: BR/EDR).
* @param accept - true to accept the pairing; false to reject.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*
* **Example:**
* @code
if (bt_device_set_pairing_confirmation(ins, &addr, BT_TRANSPORT_LE, true) == BT_STATUS_SUCCESS) {
// Pairing confirmed
} else {
// Handle error
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param transport - transport type (0:BLE, 1:BREDR).
* @param accept - true:accept, false:reject.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_set_pairing_confirmation)(bt_instance_t* ins, bt_address_t* addr, uint8_t transport, bool accept);
/**
* @brief Set the PIN code for pairing.
* @brief Set pairing PIN code
*
* Provides a PIN code in response to a pairing request that requires one.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param accept - true to accept the pairing; false to reject.
* @param pincode - Pointer to the PIN code string.
* @param len - Length of the PIN code string.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*
* **Example:**
* @code
char pin[] = "1234";
if (bt_device_set_pin_code(ins, &addr, true, pin, strlen(pin)) == BT_STATUS_SUCCESS) {
// PIN code set successfully
} else {
// Handle error
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param accept - true:accept, false:reject.
* @param pincode - pin code string.
* @param len - length of pin code string
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_set_pin_code)(bt_instance_t* ins, bt_address_t* addr, bool accept, char* pincode, int len);
bt_status_t BTSYMBOLS(bt_device_set_pin_code)(bt_instance_t* ins, bt_address_t* addr, bool accept,
char* pincode, int len);
/**
* @brief Set the passkey for pairing.
* @brief Set simple securty pair passkey or LE smp key
*
* Provides a passkey in response to a pairing request that requires one, for both BR/EDR and LE transports.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param transport - Transport type (0: LE, 1: BR/EDR).
* @param accept - true to accept the pairing; false to reject.
* @param passkey - The passkey value.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*
* **Example for BR/EDR:**
* @code
if (bt_device_set_pass_key(ins, &addr, BT_TRANSPORT_BR_EDR, true, 123456) == BT_STATUS_SUCCESS) {
// Passkey set successfully
} else {
// Handle error
}
* @endcode
*
* **Example for LE:**
* @code
if (bt_device_set_pass_key(ins, &addr, BT_TRANSPORT_LE, true, 123456) == BT_STATUS_SUCCESS) {
// Passkey set successfully
} else {
// Handle error
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param transport - transport type (0:BLE, 1:BREDR).
* @param accept - true:accept, false:reject.
* @param passkey - on transport is BREDR, mean ssp passkey; on transport is LE, mean smp key.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
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);
/**
* @brief Set the OOB Temporary Key (TK) for LE legacy pairing.
* @brief Set OOB temporary key for LE legacy pairing
*
* Provides the OOB TK value used during LE legacy pairing.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param tk_val - OOB TK value (128-bit key).
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param tk_val - Legacy pairing OOB TK value.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_set_le_legacy_tk)(bt_instance_t* ins, bt_address_t* addr, bt_128key_t tk_val);
/**
* @brief Set remote OOB data for LE Secure Connections pairing.
* @brief Set remote OOB data for LE secure connection pairing
*
* Provides the remote OOB data (Confirmation and Random values) used during LE Secure Connections pairing.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param c_val - LE Secure Connections Confirmation value (128-bit key).
* @param r_val - LE Secure Connections Random value (128-bit key).
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param c_val - LE secure connection confirmation value.
* @param r_val - LE secure connection random value.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
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);
/**
* @brief Get local OOB data for LE Secure Connections pairing.
* @brief Get local OOB data for LE secure connection pairing
*
* Initiates the generation of local OOB data for LE Secure Connections pairing.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device (can be NULL).
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*
* **Example:**
* @code
if (bt_device_get_le_sc_local_oob_data(ins, &addr) == BT_STATUS_SUCCESS) {
// OOB data generation initiated
} else {
// Handle error
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_get_le_sc_local_oob_data)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Connect to a remote device.
* @brief Connect to peer device
*
* Initiates an ACL connection to a remote BR/EDR device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*
* **Example:**
* @code
if (bt_device_connect(ins, &addr) == BT_STATUS_SUCCESS) {
// Connection initiated successfully
} else {
// Handle error
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_connect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Disconnect from a remote device.
* @brief Disconnect from ACL connection.
*
* Terminates the ACL connection with a remote device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*
* **Example:**
* @code
if (bt_device_disconnect(ins, &addr) == BT_STATUS_SUCCESS) {
// Disconnection initiated successfully
} else {
// Handle error
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_disconnect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Connect to a remote LE device.
* @brief Connect to LE device
*
* Initiates a connection to a remote LE device with specified parameters.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote LE device.
* @param type - LE address type, see @ref ble_addr_type_t.
* @param param - Pointer to connection parameters, see @ref ble_connect_params_t.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
* @param ins - bluetooth client instance.
* @param addr - remote LE device address.
* @param type - LE address type.
* @param param - connect params.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
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);
/**
* @brief Disconnect from a remote LE device.
* @brief Disconnect from LE connection
*
* Terminates the LE connection with a remote device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote LE device.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
* @param ins - bluetooth client instance.
* @param addr - remote LE device address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_disconnect_le)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Reply to a connection request.
* @brief Reply connect request
*
* Responds to a connection request from a remote device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param accept - true to accept the connection; false to reject.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param accept - true:accept, false:reject.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_connect_request_reply)(bt_instance_t* ins, bt_address_t* addr, bool accept);
/**
* @brief Set the LE PHY parameters.
* @brief Set LE phy
*
* Configures the PHY (Physical Layer) parameters for an LE connection.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote LE device.
* @param tx_phy - Preferred TX PHY, see @ref ble_phy_type_t.
* @param rx_phy - Preferred RX PHY, see @ref ble_phy_type_t.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
* @param ins - bluetooth client instance.
* @param addr - remote LE device address.
* @param tx_phy - tx phy (0:1M, 1:2M, 2:CODED).
* @param rx_phy - rx phy (0:1M, 1:2M, 2:CODED).
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
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);
/**
* @brief Connect to all profiles.
*
* @note Currently not supported.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @brief Connect to all profile.
* @note not support.
* @param ins - bluetooth client instance.
*/
void BTSYMBOLS(bt_device_connect_all_profile)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Disconnect from all profiles.
*
* @note Currently not supported.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @brief Disconnect from all profile.
* @note not support.
* @param ins - bluetooth client instance.
*/
void BTSYMBOLS(bt_device_disconnect_all_profile)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Enable enhanced mode for a connection.
*
* Enables an enhanced mode (e.g., eSCO, sniff mode) for a connection with a remote device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param mode - Enhanced mode to enable, see @ref bt_enhanced_mode_t.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*/
bt_status_t BTSYMBOLS(bt_device_enable_enhanced_mode)(bt_instance_t* ins, bt_address_t* addr, bt_enhanced_mode_t mode);
/**
* @brief Disable enhanced mode for a connection.
*
* Disables an enhanced mode (e.g., eSCO, sniff mode) for a connection with a remote device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the remote device.
* @param mode - Enhanced mode to disable, see @ref bt_enhanced_mode_t.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*/
bt_status_t BTSYMBOLS(bt_device_disable_enhanced_mode)(bt_instance_t* ins, bt_address_t* addr, bt_enhanced_mode_t mode);
#ifdef __cplusplus
}
#endif
#endif /* _BT_DEVICE_H__ */
#endif /* _BT_DEVICE_H__ */

View File

@ -23,12 +23,6 @@ extern "C" {
#include <stdbool.h>
#include <stdint.h>
#include "bt_uuid.h"
/**
* @cond
*/
typedef enum {
GATT_STATUS_SUCCESS,
GATT_STATUS_FAILURE,
@ -51,18 +45,8 @@ typedef enum {
typedef enum {
ATTR_AUTO_RSP,
ATTR_RSP_BY_APP,
ATTR_AUTO_RSP_CCC_READ,
} gatt_attr_rsp_t;
typedef enum {
ATT_BEAR_TYPE_NONE,
ATT_BEAR_TYPE_LE_ATT,
ATT_BEAR_TYPE_LE_EATT,
ATT_BEAR_TYPE_BR_ATT,
ATT_BEAR_TYPE_BR_EATT,
ATT_BEAR_TYPE_ANY,
} gatt_bear_type_t;
#ifdef CONFIG_BLUETOOTH_GATTS_MAX_ATTRIBUTE_NUM
#define GATTS_MAX_ATTRIBUTE_NUM CONFIG_BLUETOOTH_GATTS_MAX_ATTRIBUTE_NUM
#else
@ -147,26 +131,19 @@ typedef enum {
/* GATT_H_DESCRIPTOR */
#define GATT_H_CEPD(_value, _length, _handle) \
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(BT_UUID_GATT_CEPD), GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, _value, _length, _handle)
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(0x2900), GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, _value, _length, _handle)
/* GATT_H_DESCRIPTOR */
#define GATT_H_CUDD(_value, _length, _handle) \
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(BT_UUID_GATT_CUDD), GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, _value, _length, _handle)
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(0x2901), GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, _value, _length, _handle)
/* GATT_H_DESCRIPTOR */
#define GATT_H_CCCD(_perm, _change, _handle) \
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(BT_UUID_GATT_CCCD), _perm, ATTR_AUTO_RSP_CCC_READ, NULL, _change, NULL, 0, _handle)
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(0x2902), _perm, ATTR_RSP_BY_APP, NULL, _change, NULL, 0, _handle)
/* GATT_H_DESCRIPTOR for CCCD with user response (APP handles read/write) */
#define GATT_H_CCCD_USER_RSP(_perm, _read, _write, _handle) \
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(BT_UUID_GATT_CCCD), _perm, ATTR_RSP_BY_APP, _read, _write, NULL, 0, _handle)
/* GATT_H_DESCRIPTOR */
#define GATT_H_CPFD(_value, _length, _handle) \
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(BT_UUID_GATT_CPFD), GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, _value, _length, _handle)
/**
* @endcond
*/
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(0x2904), GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, _value, _length, _handle)
#ifdef __cplusplus
}

View File

@ -1,378 +0,0 @@
/****************************************************************************
* 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_GATT_FEATURE_H_
#define _BT_GATT_FEATURE_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include "bt_async.h"
#include "bt_gattc.h"
/* ----------------------------- Struct Definitions ----------------------------- */
typedef struct gatt_service_t gatt_service_t;
typedef struct gatt_characteristic_t gatt_characteristic_t;
typedef struct gatt_descriptor_t gatt_descriptor_t;
typedef struct gatt_include_service_t gatt_include_service_t;
/**
* @brief GATT Descriptor.
*/
struct gatt_descriptor_t {
bt_uuid_t service_uuid; /**< Parent service UUID. */
bt_uuid_t characteristic_uuid; /**< parent characteristic UUID. */
bt_uuid_t uuid; /**< Descriptor UUID. */
uint16_t attr_handle; /**< Descriptor attribute handle. */
uint8_t* value; /**< Value buffer pointer. */
size_t value_len; /**< Length of value. */
};
/**
* @brief GATT Characteristic.
*/
struct gatt_characteristic_t {
bt_uuid_t service_uuid; /**< Parent service UUID. */
bt_uuid_t uuid; /**< Characteristic UUID. */
uint16_t value_handle; /**< Characteristic Value attribute handle. */
uint8_t* value; /**< Value buffer pointer. */
size_t value_len; /**< Length of value. */
uint32_t properties; /**< Properties bitmask. */
gatt_descriptor_t* descriptors; /**< Array of descriptors. */
size_t descriptor_count; /**< Number of descriptors. */
};
/**
* @brief GATT Included Service.
*/
struct gatt_include_service_t {
uint16_t attr_handle; /**< Include declaration attribute handle. */
uint16_t start_handle; /**< Start handle of the referenced service */
uint16_t end_handle; /**< End handle of the referenced service */
bt_uuid_t included_service_uuid; /**< referenced service UUID */
};
/**
* @brief GATT Service.
*/
struct gatt_service_t {
bt_uuid_t uuid; /**< Service UUID. */
uint16_t attr_handle; /**< Service declaration attribute handle. */
bool is_primary; /**< True if primary service. */
gatt_characteristic_t* characteristics; /**< Array of characteristics. */
size_t characteristic_count; /**< Number of characteristics. */
gatt_include_service_t* included_services; /**< Array of included services. */
size_t included_service_count; /**< Number of included services. */
};
/* ----------------------------- Callback Typedefs ----------------------------- */
/**
* @brief Status callback.
* @param ins Bluetooth instance.
* @param status Operation status.
* @param userdata User context.
*/
typedef void (*bt_status_cb_t)(bt_instance_t* ins, bt_status_t status, void* userdata);
/**
* @brief GATT client connection completion callback.
* @param ins Bluetooth instance.
* @param status Operation status.
* @param conn_handle Connection handle.
*/
typedef void (*bt_gattc_feature_on_connected_cb_t)(bt_instance_t* ins, gatt_status_t status, gattc_handle_t conn_handle);
/**
* @brief GATT client disconnected from the remote device or connect fail callback.
* @param ins Bluetooth instance.
* @param status Operation status.
* @param conn_handle Connection handle.
*/
typedef void (*bt_gattc_feature_on_disconnected_cb_t)(bt_instance_t* ins, gatt_status_t status, gattc_handle_t conn_handle);
/**
* @brief Create client completion callback.
* @param ins Bluetooth instance.
* @param status Operation status.
* @param conn_handle Connection handle.
* @param userdata User context.
*/
typedef void (*bt_gattc_feature_create_client_cb_t)(bt_instance_t* ins, gatt_status_t status, gattc_handle_t conn_handle, void* userdata);
/**
* @brief Delete client completion callback.
* @param ins Bluetooth instance.
* @param status Operation status.
* @param conn_handle Connection handle.
* @param userdata User context.
*/
typedef void (*bt_gattc_feature_delete_client_cb_t)(bt_instance_t* ins, gatt_status_t status, gattc_handle_t conn_handle, void* userdata);
/**
* @brief Get service callback.
* @param ins Bluetooth instance.
* @param status Operation status.
* @param conn_handle Connection handle.
* @param service Retrieved service (single entry).
*/
typedef void (*bt_gattc_feature_get_service_cb_t)(bt_instance_t* ins, gatt_status_t status, gattc_handle_t conn_handle,
const gatt_service_t* service);
/**
* @brief Read characteristic callback.
* @param ins Bluetooth instance.
* @param status Operation status.
* @param conn_handle Connection handle.
* @param characteristic Retrieved characteristic (with value).
*/
typedef void (*bt_gattc_feature_read_characteristic_cb_t)(bt_instance_t* ins, gatt_status_t status, gattc_handle_t conn_handle,
const gatt_characteristic_t* characteristic);
/**
* @brief Read descriptor callback.
* @param ins Bluetooth instance.
* @param status Operation status.
* @param conn_handle Connection handle.
* @param descriptor Retrieved descriptor (with value).
*/
typedef void (*bt_gattc_feature_read_descriptor_cb_t)(bt_instance_t* ins, gatt_status_t status, gattc_handle_t conn_handle,
const gatt_descriptor_t* descriptor);
/**
* @brief Write characteristic callback.
* @param ins Bluetooth instance.
* @param status Operation status.
* @param conn_handle Connection handle.
*/
typedef void (*bt_gattc_feature_write_characteristic_cb_t)(bt_instance_t* ins, gatt_status_t status, gattc_handle_t conn_handle);
/**
* @brief Write descriptor callback.
* @param ins Bluetooth instance.
* @param status Operation status.
* @param conn_handle Connection handle.
*/
typedef void (*bt_gattc_feature_write_descriptor_cb_t)(bt_instance_t* ins, gatt_status_t status, gattc_handle_t conn_handle);
/**
* @brief Notification subscription state callback.
* @param ins Bluetooth instance.
* @param status Operation status.
* @param conn_handle Connection handle.
* @param enable True if subscription was enabled, false if disabled.
*/
typedef void (*bt_gattc_feature_on_subscribed_cb_t)(bt_instance_t* ins, gatt_status_t status, gattc_handle_t conn_handle, bool enable);
/**
* @brief MTU exchange result callback.
* @param conn_handle Connection handle.
* @param status Operation status.
* @param mtu Negotiated MTU size.
*/
typedef void (*bt_gattc_feature_on_mtu_changed_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, uint32_t mtu);
/**
* @brief Characteristic change notification callback.
* @param ins Bluetooth instance.
* @param conn_handle Connection handle.
* @param characteristic Updated characteristic (with value).
*/
typedef void (*bt_gattc_feature_characteristic_changed_cb_t)(bt_instance_t* ins, gattc_handle_t conn_handle,
const gatt_characteristic_t* characteristic);
typedef struct {
uint32_t size;
bt_gattc_feature_on_connected_cb_t on_connected;
bt_gattc_feature_on_disconnected_cb_t on_disconnected;
bt_gattc_feature_get_service_cb_t on_discovered;
bt_gattc_feature_read_characteristic_cb_t on_read_char;
bt_gattc_feature_read_descriptor_cb_t on_read_desc;
bt_gattc_feature_write_characteristic_cb_t on_write_char;
bt_gattc_feature_write_descriptor_cb_t on_write_desc;
bt_gattc_feature_on_subscribed_cb_t on_subscribed;
bt_gattc_feature_characteristic_changed_cb_t on_notified;
bt_gattc_feature_on_mtu_changed_cb_t on_mtu_updated;
} bt_gattc_feature_callbacks_t;
/* ----------------------------- API Declarations ----------------------------- */
/**
* @brief Create GATT client.
* @param ins Bluetooth instance.
* @param addr Remote device address.
* @param cb Create completion callback.
* @param callbacks GATT client event callbacks.
* @param userdata User context.
* @return bt_status_t
*/
bt_status_t bt_gattc_feature_create_client_async(bt_instance_t* ins, bt_address_t* addr,
bt_gattc_feature_create_client_cb_t cb,
bt_gattc_feature_callbacks_t* callbacks,
void* userdata);
/**
* @brief Delete GATT client.
* @param ins Bluetooth instance.
* @param addr Remote device address.
* @param cb Delete completion callback.
* @param userdata User context.
* @return bt_status_t
*/
bt_status_t bt_gattc_feature_delete_client_async(bt_instance_t* ins, bt_address_t* addr,
bt_gattc_feature_delete_client_cb_t cb, void* userdata);
/**
* @brief Connect to GATT server.
*
* Initiates a GATT connection to the remote server using the specified connection handle.
*
* Important:
* - Before calling this function, you must have successfully called
* @ref bt_gattc_feature_create_client_async() to create a GATT client and obtained the `conn_handle`.
* - This function reuses the existing `conn_handle` to connect; it does not create a new client.
* - Normally, after client creation, the stack will automatically attempt the first connection.
* You can call this function explicitly if you want to reconnect after a disconnect.
*
* @param conn_handle Connection handle (from create).
* @param addr Remote device address.
* @param addr_type Address type.
* @param cb Async call status callback.
* @param userdata User context.
* @return bt_status_t
*/
bt_status_t bt_gattc_feature_connect_async(gattc_handle_t conn_handle, bt_address_t* addr, ble_addr_type_t addr_type,
bt_status_cb_t cb, void* userdata);
/**
* @brief Disconnect from GATT server.
*
* Terminates the active GATT connection associated with the given connection handle.
*
* Important:
* - The `conn_handle` must be a valid handle previously obtained from
* @ref bt_gattc_feature_create_client_async().
* - After disconnection, the GATT client remains allocated.
* You can reconnect later using @ref bt_gattc_feature_connect_async(),
* or completely remove the client using @ref bt_gattc_feature_delete_client_async().
*
* @param conn_handle Connection handle.
* @param cb Async call status callback.
* @param userdata User context.
* @return bt_status_t
*/
bt_status_t bt_gattc_feature_disconnect_async(gattc_handle_t conn_handle, bt_status_cb_t cb, void* userdata);
/**
* @brief Discover all GATT services (rebuilds local DB).
*
* @param conn_handle Connection handle.
* @param cb Async call status callback.
* @param userdata User context.
* @return bt_status_t
*/
bt_status_t bt_gattc_feature_get_service_async(gattc_handle_t conn_handle, bt_status_cb_t cb, void* userdata);
/**
* @brief Read characteristic value.
*
* @param conn_handle Connection handle.
* @param service_uuid Parent service UUID.
* @param characteristic_uuid Target characteristic UUID.
* @param cb Async call status callback.
* @param userdata User context.
* @return bt_status_t
*/
bt_status_t bt_gattc_feature_read_characteristic_value_async(gattc_handle_t conn_handle,
const bt_uuid_t* service_uuid, const bt_uuid_t* characteristic_uuid,
bt_status_cb_t cb, void* userdata);
/**
* @brief Read descriptor value.
*
* @param conn_handle Connection handle.
* @param service_uuid Parent service UUID.
* @param characteristic_uuid Parent characteristic UUID.
* @param descriptor_uuid Target descriptor UUID.
* @param cb Async call status callback.
* @param userdata User context.
* @return bt_status_t
*/
bt_status_t bt_gattc_feature_read_descriptor_value_async(gattc_handle_t conn_handle,
const bt_uuid_t* service_uuid, const bt_uuid_t* characteristic_uuid,
const bt_uuid_t* descriptor_uuid,
bt_status_cb_t cb, void* userdata);
/**
* @brief Write characteristic value.
*
* @param conn_handle Connection handle.
* @param characteristic Characteristic to write.
* @param cb Async call status callback.
* @param userdata User context.
* @return bt_status_t
*/
bt_status_t bt_gattc_feature_write_characteristic_value_async(gattc_handle_t conn_handle,
const gatt_characteristic_t* characteristic, bt_status_cb_t cb, void* userdata);
/**
* @brief Write descriptor value.
*
* @param conn_handle Connection handle.
* @param descriptor Descriptor to write.
* @param cb Async call status callback.
* @param userdata User context.
* @return bt_status_t
*/
bt_status_t bt_gattc_feature_write_descriptor_value_async(gattc_handle_t conn_handle,
const gatt_descriptor_t* descriptor, bt_status_cb_t cb, void* userdata);
/**
* @brief Exchange MTU size.
*
* @param conn_handle Connection handle.
* @param mtu Desired MTU size.
* @param cb Async call status callback.
* @param userdata User context.
* @return bt_status_t
*/
bt_status_t bt_gattc_feature_exchange_mtu_async(gattc_handle_t conn_handle, uint32_t mtu,
bt_status_cb_t cb, void* userdata);
/**
* @brief Enable or disable characteristic notification.
*
* @param conn_handle Connection handle.
* @param characteristic Target characteristic.
* @param enable True to enable, false to disable.
* @param cb Async call status callback.
* @param userdata User context.
* @return bt_status_t
*/
bt_status_t bt_gattc_feature_set_notify_characteristic_changed_async(gattc_handle_t conn_handle,
const gatt_characteristic_t* characteristic, bool enable, bt_status_cb_t cb, void* userdata);
#ifdef __cplusplus
}
#endif
#endif // _BT_GATT_FEATURE_H_

View File

@ -93,38 +93,6 @@ bt_status_t BTSYMBOLS(bt_gattc_read_phy)(gattc_handle_t 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);
bt_status_t BTSYMBOLS(bt_gattc_read_rssi)(gattc_handle_t conn_handle);
// async
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_ASYNC
#include "bt_async.h"
typedef void (*bt_gattc_create_connect_cb_t)(bt_instance_t* ins, bt_status_t status, gattc_handle_t* phandle, void* userdata);
typedef void (*bt_gattc_delete_connect_cb_t)(bt_instance_t* ins, bt_status_t status, void* userdata);
typedef void (*bt_gattc_get_attribute_cb_t)(bt_instance_t* ins, bt_status_t status, gatt_attr_desc_t* attr_desc, void* userdata);
typedef void (*bt_gattc_write_cb_t)(bt_instance_t* ins, bt_status_t status, void* userdata);
bt_status_t bt_gattc_create_connect_async(bt_instance_t* ins, gattc_handle_t* phandle, gattc_callbacks_t* callbacks,
bt_gattc_create_connect_cb_t cb, void* userdata);
bt_status_t bt_gattc_delete_connect_async(gattc_handle_t conn_handle, bt_status_cb_t bt_gattc_delete_connect_cb_t, void* userdata);
bt_status_t bt_gattc_connect_async(gattc_handle_t conn_handle, bt_address_t* addr, ble_addr_type_t addr_type, bt_status_cb_t cb, void* userdata);
bt_status_t bt_gattc_disconnect_async(gattc_handle_t conn_handle, bt_status_cb_t cb, void* userdata);
bt_status_t bt_gattc_discover_service_async(gattc_handle_t conn_handle, bt_uuid_t* filter_uuid, bt_status_cb_t cb, void* userdata);
bt_status_t bt_gattc_get_attribute_by_handle_async(gattc_handle_t conn_handle, uint16_t attr_handle, bt_gattc_get_attribute_cb_t cb, void* userdata);
bt_status_t bt_gattc_get_attribute_by_uuid_async(gattc_handle_t conn_handle, uint16_t start_handle, uint16_t end_handle, bt_uuid_t* attr_uuid,
bt_gattc_get_attribute_cb_t cb, void* userdata);
bt_status_t bt_gattc_read_async(gattc_handle_t conn_handle, uint16_t attr_handle, bt_status_cb_t cb, void* userdata);
bt_status_t bt_gattc_write_async(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length, bt_status_cb_t cb, void* userdata);
bt_status_t bt_gattc_write_without_response_async(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length,
bt_gattc_write_cb_t cb, void* userdata);
bt_status_t bt_gattc_subscribe_async(gattc_handle_t conn_handle, uint16_t attr_handle, uint16_t ccc_value, bt_status_cb_t cb, void* userdata);
bt_status_t bt_gattc_unsubscribe_async(gattc_handle_t conn_handle, uint16_t attr_handle, bt_status_cb_t cb, void* userdata);
bt_status_t bt_gattc_exchange_mtu_async(gattc_handle_t conn_handle, uint32_t mtu, bt_status_cb_t cb, void* userdata);
bt_status_t bt_gattc_update_connection_parameter_async(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, bt_status_cb_t cb, void* userdata);
bt_status_t bt_gattc_read_phy_async(gattc_handle_t conn_handle, bt_status_cb_t cb, void* userdata);
bt_status_t bt_gattc_update_phy_async(gattc_handle_t conn_handle, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy, bt_status_cb_t cb, void* userdata);
bt_status_t bt_gattc_read_rssi_async(gattc_handle_t conn_handle, bt_status_cb_t cb, void* userdata);
#endif // CONFIG_BLUETOOTH_FRAMEWORK_ASYNC
#ifdef __cplusplus
}
#endif

View File

@ -28,74 +28,16 @@ extern "C" {
#include "bt_uuid.h"
#include <stddef.h>
/**
* @cond
*/
#ifndef BTSYMBOLS
#define BTSYMBOLS(s) s
#endif
typedef void* gatts_handle_t;
/**
* @endcond
*/
/**
* @brief callback for GATT server recveived read request.
*
* This callback is triggered when peer GATT client initiate read request to characteristic with property
* contains the read flag bit.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param addr - remote device address. Address of the peer device that initiated the read request.
* @param attr_handle - attribute handle. The handle identified by each service, not the Attribute handle in spec.
* @param req_handle - request handle. Identifies the order in which the read request was made.
* @return uint16_t.
*
* **Example:**
* @code
uint16_t rx_char_on_read(void* srv_handle, bt_address_t* addr, uint16_t attr_handle, uint32_t req_handle)
{
bt_status_t ret = bt_gatts_response(srv_handle, addr, req_handle, read_char_value, sizeof(read_char_value));
PRINT("gatts service RX char response. status: %d", ret);
return 0;
}
* @endcode
*/
typedef uint16_t (*attribute_read_cb_t)(gatts_handle_t srv_handle, bt_address_t* addr, uint16_t attr_handle, uint32_t req_handle);
/**
* @brief callback for GATT server recveived write request.
*
* This callback is triggered when peer GATT client initiate write request to characteristic with property
* contains the write flag bit.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param addr - remote device address. Address of the peer device that initiated the read request.
* @param attr_handle - attribute handle. The handle identified by each service, not the Attribute handle in spec.
* @param value - attribute value.
* @param length - value length.
* @param offset - value offset.
* @return uint16_t. value length.
*
* **Example:**
* @code
uint16_t rx_char_on_write(void* srv_handle, bt_address_t* addr, uint16_t attr_handle, const uint8_t* value, uint16_t length, uint16_t offset)
{
PRINT_ADDR("gatts service RX char received write request, addr:%s", addr);
return length;
}
* @endcode
*/
typedef uint16_t (*attribute_written_cb_t)(gatts_handle_t srv_handle, bt_address_t* addr, uint16_t attr_handle,
const uint8_t* value, uint16_t length, uint16_t offset);
/**
* @cond
*/
typedef struct {
uint16_t handle;
bt_uuid_t uuid;
@ -115,224 +57,18 @@ typedef struct {
gatt_attr_db_t* attr_db;
} gatt_srv_db_t;
/**
* @endcond
*/
/**
* @brief callback for connected as GATT server.
*
* This callback is triggered when gatts connected. BT Service use this callback to notify the application calling
* bt_gatts_connect that gatts connection has been established.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param addr - remote device address.
* @return void.
*
* **Example:**
* @code
static void connect_callback(void* srv_handle, bt_address_t* addr)
{
PRINT_ADDR("gatts_connect_callback, addr:%s", addr);
add_gatts_device(addr);
}
* @endcode
*/
typedef void (*gatts_connected_cb_t)(gatts_handle_t srv_handle, bt_address_t* addr);
/**
* @brief callback for disconnected as GATT server.
*
* This callback is triggered when gatts disconnected. BT Service use this callback to notify the application that
* the gatts connection is destroyed.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param addr - remote device address.
* @return void.
*
* **Example:**
* @code
static void disconnect_callback(void* srv_handle, bt_address_t* addr)
{
gatts_device_t* device = find_gatts_device(addr);
remove_gatts_device(device);
PRINT_ADDR("gatts_disconnect_callback, addr:%s", addr);
}
* @endcode
*/
typedef void (*gatts_disconnected_cb_t)(gatts_handle_t srv_handle, bt_address_t* addr);
/**
* @brief callback for Addition of GATT service.
*
* This callback is triggered when GATT server add a GATT service.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param status - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @param attr_handle - attribute handle. The handle identified by each service, not the Attribute handle in spec.
* @return void.
*
* **Example:**
* @code
static void attr_table_added_callback(void* srv_handle, gatt_status_t status, uint16_t attr_handle)
{
PRINT("gatts add attribute table complete, handle 0x%" PRIx16 ", status:%d", attr_handle, status);
}
* @endcode
*/
typedef void (*gatts_attr_table_added_cb_t)(gatts_handle_t srv_handle, gatt_status_t status, uint16_t attr_handle);
/**
* @brief callback for Deletion of GATT service.
*
* This callback is triggered when GATT server remove a GATT service.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param status - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @param attr_handle - attribute handle. The handle identified by each service, not the Attribute handle in spec.
* @return void.
*
* **Example:**
* @code
static void attr_table_removed_callback(void* srv_handle, gatt_status_t status, uint16_t attr_handle)
{
PRINT("gatts remove attribute table complete, handle 0x%" PRIx16 ", status:%d", attr_handle, status);
}
* @endcode
*/
typedef void (*gatts_attr_table_removed_cb_t)(gatts_handle_t srv_handle, gatt_status_t status, uint16_t attr_handle);
/**
* @brief callback for GATT server receive Exchange MTU request.
*
* This callback is triggered as server receive Exchange MTU request from peer GATT client.
* BT Service use this callback to Report the results of MTU negotiation.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param addr - remote device address.
* @param mtu - negotiated MTU.
* @return void.
*
* **Example:**
* @code
static void mtu_changed_callback(void* srv_handle, bt_address_t* addr, uint32_t mtu)
{
gatts_device_t* device = find_gatts_device(addr);
if (device) {
device->gatt_mtu = mtu;
}
PRINT_ADDR("gatts_mtu_changed_callback, addr:%s, mtu:%" PRIu32, addr, mtu);
}
* @endcode
*/
typedef void (*gatts_mtu_changed_cb_t)(gatts_handle_t srv_handle, bt_address_t* addr, uint32_t mtu);
/**
* @brief callback for GATT server excute attribute notify operation.
*
* This callback is triggered when GATT server initiate notify to characteristic with property
* contains the notify flag bit.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param addr - remote device address.
* @param status - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @param attr_handle - attribute handle. The handle identified by each service, not the Attribute handle in spec.
* @return void.
*
* **Example:**
* @code
static void notify_complete_callback(void* srv_handle, bt_address_t* addr, gatt_status_t status, uint16_t attr_handle)
{
if (status != GATT_STATUS_SUCCESS) {
PRINT_ADDR("gatts service notify failed, addr:%s, handle 0x%" PRIx16 ", status:%d", addr, attr_handle, status);
return;
}
if (throughtput_cursor) {
throughtput_cursor--;
} else {
PRINT_ADDR("gatts service notify complete, addr:%s, handle 0x%" PRIx16 ", status:%d", addr, attr_handle, status);
}
}
* @endcode
*/
typedef void (*gatts_nofity_complete_cb_t)(gatts_handle_t srv_handle, bt_address_t* addr, gatt_status_t status, uint16_t attr_handle);
/**
* @brief callback for GATT server execute read PHY.
*
* This callback is triggered when application initiating read PHY procedure. BT Service use this callback to Report
* the Tx PHY & Rx PHY.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param tx_phy - current Tx PHY.
* @param rx_phy - current Rx PHY.
* @return void.
*
* **Example:**
* @code
static void phy_read_callback(void* srv_handle, bt_address_t* addr, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy)
{
PRINT_ADDR("gatts read phy complete, addr:%s, tx:%d, rx:%d", addr, tx_phy, rx_phy);
}
* @endcode
*/
typedef void (*gatts_phy_read_cb_t)(gatts_handle_t srv_handle, bt_address_t* addr, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy);
/**
* @brief callback for GATT server execute update PHY operation.
*
* This callback is triggered when application initiating update PHY procedure. BT Service use this callback to Report
* the result of update Tx PHY & Rx PHY.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param addr - remote device address.
* @param status - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @param tx_phy - Tx PHY after update. If update operation failed, keep original value.
* @param rx_phy - Rx PHY after update. If update operation failed, keep original value.
* @return void.
*
* **Example:**
* @code
static void phy_updated_callback(void* srv_handle, bt_address_t* addr, gatt_status_t status, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy)
{
PRINT_ADDR("gatts phy updated, addr:%s, status:%d, tx:%d, rx:%d", addr, status, tx_phy, rx_phy);
}
* @endcode
*/
typedef void (*gatts_phy_updated_cb_t)(gatts_handle_t srv_handle, bt_address_t* addr, gatt_status_t status, ble_phy_type_t tx_phy,
ble_phy_type_t rx_phy);
/**
* @brief callback for connnection parameter update.
*
* This callback is triggered when peer device initiating connnection parameter update procedure. BT Service use this
* callback to Report the connection parameter.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param addr - remote device address.
* @param connection_interval - connection interval(n * 1.25ms).
* @param peripheral_latency - peripheral latency.
* @param supervision_timeout - supervision timeout(n * 10ms).
* @return void.
*
* **Example:**
* @code
static void conn_param_changed_callback(void* srv_handle, bt_address_t* addr, uint16_t connection_interval,
uint16_t peripheral_latency, uint16_t supervision_timeout)
{
PRINT_ADDR("gatts_conn_param_changed_callback, addr:%s, interval:%" PRIu16 ", latency:%" PRIu16 ", timeout:%" PRIu16,
addr, connection_interval, peripheral_latency, supervision_timeout);
}
* @endcode
*/
typedef void (*gatts_connection_parameter_changed_cb_t)(gatts_handle_t srv_handle, bt_address_t* addr, uint16_t connection_interval,
uint16_t peripheral_latency, uint16_t supervision_timeout);
/**
* @cond
*/
typedef struct {
uint32_t size;
gatts_connected_cb_t on_connected;
@ -347,243 +83,18 @@ typedef struct {
} gatts_callbacks_t;
/**
* @endcond
*/
/**
* @brief regsiter a service.
*
* @param ins - Bluetooth client instance.
* @param phandle - pointer of gatts connection handle(void*).
* @param callbacks - gatts service callback table.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
ret = bt_gatts_register_service(handle, &g_dis_handle, &gatts_cbs);
if (ret != BT_STATUS_SUCCESS)
// Handle Error
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gatts_register_service)(bt_instance_t* ins, gatts_handle_t* phandle, gatts_callbacks_t* callbacks);
/**
* @brief unregsiter a service.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gatts_unregister_service(service_handle) != BT_STATUS_SUCCESS)
// Handle Error
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gatts_unregister_service)(gatts_handle_t srv_handle);
/**
* @brief create a connect with peer device.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param addr - remote device address.
* @param addr_type - peer address type(ble_addr_type_t).
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gatts_connect(service_handle, &addr, BT_LE_ADDR_TYPE_UNKNOWN) != BT_STATUS_SUCCESS)
// Handle Error
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gatts_connect)(gatts_handle_t srv_handle, bt_address_t* addr, ble_addr_type_t addr_type);
/**
* @brief create a connect bear with peer device.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param addr - remote device address.
* @param addr_type - peer address type(ble_addr_type_t).
* @param bear_type - perr bear type
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gatts_connect(service_handle, &addr, BT_LE_ADDR_TYPE_UNKNOWN) != BT_STATUS_SUCCESS)
// Handle Error
* @endcode
*/
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);
/**
* @brief initiate a disconnect with peer device.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param addr - remote device address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gatts_disconnect(service_handle, &addr) != BT_STATUS_SUCCESS)
// Handle Error
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gatts_disconnect)(gatts_handle_t srv_handle, bt_address_t* addr);
/**
* @brief add GATT service attribute to attribute table.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param srv_db - GATT service attributes.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gatts_add_attr_table(service_handle, service_db) != BT_STATUS_SUCCESS)
// Handle Error
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gatts_add_attr_table)(gatts_handle_t srv_handle, gatt_srv_db_t* srv_db);
/**
* @brief remove GATT service attribute from attribute table.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param attr_handle - GATT service attributes.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gatts_remove_attr_table(service_handle, attr_handle) != BT_STATUS_SUCCESS)
// Handle Error
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gatts_remove_attr_table)(gatts_handle_t srv_handle, uint16_t attr_handle);
/**
* @brief set GATT service attribute value.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param attr_handle - attribute handle. The handle identified by each service, not the Attribute handle in spec.
* @param value - attribute value.
* @param length - value length.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gatts_set_attr_value(g_bas_handle, BAS_BATTERY_LEVEL_CHR_ID, (uint8_t*)&battery_level, sizeof(battery_level)) != BT_STATUS_SUCCESS)
// Handle Error
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gatts_set_attr_value)(gatts_handle_t srv_handle, uint16_t attr_handle, uint8_t* value, uint16_t length);
/**
* @brief get GATT service attribute value.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param attr_handle - attribute handle. The handle identified by each service, not the Attribute handle in spec.
* @param value - attribute value.
* @param length - value length.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gatts_get_attr_value(g_bas_handle, BAS_BATTERY_LEVEL_CHR_ID, buffer, sizeof(buffer)) != BT_STATUS_SUCCESS)
// Handle Error
// Handle attribute value
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gatts_get_attr_value)(gatts_handle_t srv_handle, uint16_t attr_handle, uint8_t* value, uint16_t* length);
/**
* @brief response attribute value for GATT server recveived read request.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param addr - remote device address. Address of the peer device that initiated the read request.
* @param req_handle - attribute handle. The handle identified by each service, not the Attribute handle in spec.
* @param value - attribute value.
* @param length - value length.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
uint16_t rx_char_on_read(void* srv_handle, bt_address_t* addr, uint16_t attr_handle, uint32_t req_handle)
{
PRINT_ADDR("gatts service RX char received read request, addr:%s", addr);
bt_status_t ret = bt_gatts_response(srv_handle, addr, req_handle, read_char_value, sizeof(read_char_value));
PRINT("gatts service RX char response. status: %d", ret);
return 0;
}
* @endcode
*/
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);
/**
* @brief server notify attribute value to client.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param addr - remote device address. Address of the peer device that initiated the read request.
* @param attr_handle - attribute handle. The handle identified by each service, not the Attribute handle in spec.
* @param value - attribute value.
* @param length - value length.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gatts_notify(g_bas_handle, &addr, BAS_BATTERY_LEVEL_CHR_ID, (uint8_t*)&battery_level, sizeof(battery_level)) != BT_STATUS_SUCCESS)
// Handle Error
* @endcode
*/
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);
/**
* @brief server indicate attribute value to client.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param addr - remote device address. Address of the peer device that initiated the read request.
* @param attr_handle - attribute handle. The handle identified by each service, not the Attribute handle in spec.
* @param value - attribute value.
* @param length - value length.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gatts_indicate(g_custom_handle, &addr, IOT_SERVICE_TX_CHR_ID, (uint8_t*)argv[1], strlen(argv[1])) != BT_STATUS_SUCCESS)
// Handle Error
* @endcode
*/
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);
/**
* @brief read Tx & Rx PHY.
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param addr - remote device address. Address of the peer device that initiated the read request.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gatts_read_phy(service_handle, &addr) != BT_STATUS_SUCCESS)
// Handle Error
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gatts_read_phy)(gatts_handle_t srv_handle, bt_address_t* addr);
/**
* @brief update PHY
*
* @param srv_handle - gatts handle(void*). Each GATT service has its own handle.
* @param addr - remote device address. Address of the peer device that initiated the read request.
* @param tx_phy - Tx PHY type wants to update.
* @param rx_phy - Rx PHY type wants to update.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gatts_update_phy(service_handle, &addr, tx, rx) != BT_STATUS_SUCCESS)
// Handle Error
* @endcode
*/
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);
#ifdef __cplusplus

View File

@ -25,10 +25,6 @@ extern "C" {
#include "bt_device.h"
#include <stddef.h>
/**
* @cond
*/
/* According to HFP 1.9: Phone number string (max. 32 digits) */
#define HFP_PHONENUM_DIGITS_MAX 32
#define HFP_NAME_DIGITS_MAX 64
@ -37,7 +33,6 @@ extern "C" {
Also defined as BTA_HF_CLIENT_AT_MAX_LEN (512) at Android */
#define HFP_AT_LEN_MAX 512
#define HFP_CALL_LIST_MAX 4
#define HFP_COMPANY_PREFIX_LEN_MAX 10
typedef enum {
HFP_AUDIO_STATE_DISCONNECTED,
@ -120,15 +115,6 @@ typedef enum {
HFP_ROAM_STATE_ROAMING,
} hfp_roaming_state_t;
typedef enum {
HFP_HF_SERVICE_VOICE = 4,
HFP_HF_SERVICE_FAX = 5,
} hfp_subscriber_number_service_t;
/**
* @endcond
*/
#ifdef __cplusplus
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -47,11 +47,7 @@ extern "C" {
#define HID_ATTR_MASK_BREDR 0x8000
/**
* @cond
*/
/**
* @brief HID descriptor information
* @brief hid descriptor information
*
*/
typedef struct {
@ -70,7 +66,7 @@ typedef struct {
} hid_info_t;
/**
* @brief HID device settings for SDP server
* @brief hid device settings for SDP server
*
*/
typedef struct {
@ -81,7 +77,7 @@ typedef struct {
} hid_device_sdp_settings_t;
/**
* @brief HID report type
* @brief hid report type
*
*/
typedef enum {
@ -92,7 +88,7 @@ typedef enum {
} hid_report_type_t;
/**
* @brief HID status code
* @brief hid status code
*
*/
typedef enum {
@ -113,160 +109,79 @@ typedef enum {
} hid_status_error_t;
/**
* @brief HID app state
* @brief hid app state
*
*/
typedef enum {
HID_APP_STATE_NOT_REGISTERED,
HID_APP_STATE_REGISTERED,
} hid_app_state_t;
/**
* @endcond
*/
/**
* @brief HID device application state callback.
* @brief hid device app state callback
*
* Callback function invoked when the HID application state changes. This callback
* is used to notify the HID device about the state transition in interaction
* with the remote HID host.
*
* @param cookie - `remote_callback_t*`.
* See `bt_hid_device_register_callbacks`.
* @param state - New HID application state, see @ref hid_app_state_t.
*
* **Example:**
* @code
* void hidd_app_state_callback(void* cookie, hid_app_state_t state)
* {
* // Handle HID application state change
* }
* @endcode
* @param cookie - callback cookie.
* @param state - hid app state
*/
typedef void (*hidd_app_state_callback)(void* cookie, hid_app_state_t state);
/**
* @brief HID device connection state callback.
* @brief hid device connection state callback
*
* Callback function invoked when the HID connection state changes. This callback
* is used to notify the HID device about connection state changes with the remote
* HID host.
*
* @param cookie - `remote_callback_t*`.
* See `bt_hid_device_register_callbacks`.
* @param addr - Address of the peer device, see @ref bt_address_t.
* @param le_hid - TRUE if the connection is over LE; FALSE if over BR/EDR.
* @param state - New HID connection state, see @ref profile_connection_state_t.
*
* **Example:**
* @code
* void hidd_connection_state_callback(void* cookie, bt_address_t* addr, bool le_hid, profile_connection_state_t state)
* {
* // Handle HID connection state change
* }
* @endcode
* @param cookie - callback cookie.
* @param addr - address of peer device.
* @param le_hid - TRUE is le link. FALSE is BREDR link
* @param state - hid connection state
*/
typedef void (*hidd_connection_state_callback)(void* cookie, bt_address_t* addr, bool le_hid,
profile_connection_state_t state);
/**
* @brief Callback for getting a specified report from the remote HID host.
* @brief callback for get the specified report from app
*
* Callback function invoked when a GET_REPORT request is received from the remote HID host.
*
* @param cookie - `remote_callback_t*`.
* See `bt_hid_device_register_callbacks`.
* @param addr - Address of the peer device, see @ref bt_address_t.
* @param rpt_type - Report type, see @ref hid_report_type_t.
* @param rpt_id - Report ID.
* @param buffer_size - Maximum size of the report data to return.
*
* **Example:**
* @code
* void hidd_get_report_callback(void* cookie, bt_address_t* addr, uint8_t rpt_type,
* uint8_t rpt_id, uint16_t buffer_size)
* {
* // Provide the requested report to the remote HID host
* }
* @endcode
* @param cookie - callback cookie.
* @param addr - address of peer device.
* @param rpt_type - report type
* @param rpt_id - report id
* @param buffer_size - max size to return
*/
typedef void (*hidd_get_report_callback)(void* cookie, bt_address_t* addr, uint8_t rpt_type,
uint8_t rpt_id, uint16_t buffer_size);
/**
* @brief Callback for setting a specified report from the remote HID host.
* @brief callback for set the specified report from app
*
* Callback function invoked when a SET_REPORT request is received from the remote HID host.
*
* @param cookie - `remote_callback_t*`.
* See `bt_hid_device_register_callbacks`.
* @param addr - Address of the peer device, see @ref bt_address_t.
* @param rpt_type - Report type, see @ref hid_report_type_t.
* @param rpt_size - Size of the report data.
* @param rpt_data - Pointer to the report data.
*
* **Example:**
* @code
* void hidd_set_report_callback(void* cookie, bt_address_t* addr, uint8_t rpt_type,
* uint16_t rpt_size, uint8_t* rpt_data)
* {
* // Process the report data received from the remote HID host
* }
* @endcode
* @param cookie - callback cookie.
* @param addr - address of peer device.
* @param rpt_type - report type
* @param rpt_size - size of the report data
* @param rpt_data - report data
*/
typedef void (*hidd_set_report_callback)(void* cookie, bt_address_t* addr, uint8_t rpt_type,
uint16_t rpt_size, uint8_t* rpt_data);
/**
* @brief Callback for receiving reports from the remote HID host.
* @brief callback for receiving reports from host
*
* Callback function invoked when an INPUT report is received from the remote HID host.
*
* @param cookie - `remote_callback_t*`.
* See `bt_hid_device_register_callbacks`.
* @param addr - Address of the peer device, see @ref bt_address_t.
* @param rpt_type - Report type, see @ref hid_report_type_t.
* @param rpt_size - Size of the report data.
* @param rpt_data - Pointer to the report data.
*
* **Example:**
* @code
* void hidd_receive_report_callback(void* cookie, bt_address_t* addr, uint8_t rpt_type,
* uint16_t rpt_size, uint8_t* rpt_data)
* {
* // Handle the report data received from the remote HID host
* }
* @endcode
* @param cookie - callback cookie.
* @param addr - address of peer device.
* @param rpt_type - report type
* @param rpt_size - size of the report data
* @param rpt_data - report data
*/
typedef void (*hidd_receive_report_callback)(void* cookie, bt_address_t* addr, uint8_t rpt_type,
uint16_t rpt_size, uint8_t* rpt_data);
/**
* @brief HID device virtual cable unplug callback.
* @brief hid device virtual cable unplug callback
*
* Callback function invoked when a virtual cable unplug request is received from the remote HID host.
*
* @param cookie - `remote_callback_t*`.
* See `bt_hid_device_register_callbacks`.
* @param addr - Address of the peer device, see @ref bt_address_t.
*
* **Example:**
* @code
* void hidd_virtual_unplug_callback(void* cookie, bt_address_t* addr)
* {
* // Handle virtual cable unplug event initiated by the remote HID host
* }
* @endcode
* @param cookie - callback cookie.
* @param addr - address of peer device.
*/
typedef void (*hidd_virtual_unplug_callback)(void* cookie, bt_address_t* addr);
/**
* @cond
*/
/**
* @brief HID device event callbacks structure
* @brief hid device event callbacks structure
*
*/
typedef struct {
@ -278,184 +193,101 @@ typedef struct {
hidd_receive_report_callback receive_report_cb;
hidd_virtual_unplug_callback virtual_unplug_cb;
} hid_device_callbacks_t;
/**
* @endcond
*/
/**
* @brief Register callback functions with the HID device service.
* @brief Register callback functions to hid device service
*
* Registers application callbacks to receive HID device events.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param callbacks - Pointer to the HID device callbacks structure, see @ref hid_device_callbacks_t.
* @return void* - Callback cookie to be used in future calls; NULL on failure.
*
* **Example:**
* @code
void* cookie = bt_hid_device_register_callbacks(ins, &my_hid_device_callbacks);
if (cookie == NULL) {
// Handle error
}
* @endcode
* @param ins - bluetooth client instance.
* @param callbacks - hid device callback functions.
* @return void* - callback cookie, NULL on failure.
*/
void* BTSYMBOLS(bt_hid_device_register_callbacks)(bt_instance_t* ins, const hid_device_callbacks_t* callbacks);
/**
* @brief Unregister HID device callback functions.
* @brief Unregister hid device callback function
*
* Unregisters the application callbacks from the HID device service.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param cookie - Callback cookie obtained from registration.
* @return true - Unregistration successful.
* @return false - Callback cookie not found or unregistration failed.
*
* **Example:**
* @code
if (bt_hid_device_unregister_callbacks(ins, cookie)) {
// Unregistered successfully
} else {
// Handle error
}
* @endcode
* @param ins - bluetooth client instance.
* @param cookie - callbacks cookie.
* @return true - on callback unregister success
* @return false - on callback cookie not found
*/
bool BTSYMBOLS(bt_hid_device_unregister_callbacks)(bt_instance_t* ins, void* cookie);
/**
* @brief Register the HID application.
* @brief Register hid app
*
* Registers the HID device application.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param sdp_setting - Pointer to the HID device SDP settings, see @ref hid_device_sdp_settings_t.
* @param le_hid - TRUE to register as an LE HID device; FALSE for BR/EDR.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*
* **Example:**
* @code
hid_device_sdp_settings_t sdp_settings = {
.name = "My HID Device",
.description = "Example HID Device",
.provider = "My Company",
// Initialize hids_info...
};
if (bt_hid_device_register_app(ins, &sdp_settings, false) == BT_STATUS_SUCCESS) {
// HID application registered
}
* @endcode
* @param ins - bluetooth client instance.
* @param sdp_setting - hid device sdp setting.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_hid_device_register_app)(bt_instance_t* ins, hid_device_sdp_settings_t* sdp_setting, bool le_hid);
/**
* @brief Unregister the HID application.
* @brief Unregister hid app
*
* Unregisters the HID device application.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*
* **Example:**
* @code
if (bt_hid_device_unregister_app(ins) == BT_STATUS_SUCCESS) {
// HID application unregistered
}
* @endcode
* @param ins - bluetooth client instance.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_hid_device_unregister_app)(bt_instance_t* ins);
/**
* @brief Connect to a HID host.
* @brief Connect to hid host
*
* Initiates a connection to a HID host device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the peer device, see @ref bt_address_t.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*
* **Example:**
* @code
if (bt_hid_device_connect(ins, &host_addr) == BT_STATUS_SUCCESS) {
// Connection initiated
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - address of peer device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_hid_device_connect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Disconnect from a HID host.
* @brief Disconnect to hid host
*
* Terminates the connection with a HID host device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the peer device, see @ref bt_address_t.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*
* **Example:**
* @code
if (bt_hid_device_disconnect(ins, &host_addr) == BT_STATUS_SUCCESS) {
// Disconnection initiated
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - address of peer device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_hid_device_disconnect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Send a report to the HID host.
* @brief Send report to hid host
*
* Sends a HID report to the connected HID host device.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the peer device, see @ref bt_address_t.
* @param rpt_id - Report ID.
* @param rpt_data - Pointer to the report data.
* @param rpt_size - Size of the report data.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*
* **Example:**
* @code
uint8_t report_data[] = { report data };
if (bt_hid_device_send_report(ins, &host_addr, rpt_id, report_data, sizeof(report_data)) == BT_STATUS_SUCCESS) {
// Report sent
}
* @endcode
* @param ins - bluetooth client instance.
* @param addr - address of peer device.
* @param rpt_id - report id.
* @param rpt_data - report data.
* @param rpt_size - size of the report data.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
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);
/**
* @brief Respond with a report to the host's GET_REPORT command.
* @brief Response report to the Host using GET_REPORT command
*
* Sends a report in response to a GET_REPORT request from the host.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the peer device, see @ref bt_address_t.
* @param rpt_type - Report type, see @ref hid_report_type_t.
* @param rpt_data - Pointer to the report data.
* @param rpt_size - Size of the report data.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
* @param ins - bluetooth client instance.
* @param addr - address of peer device.
* @param rpt_type - report type.
* @param rpt_data - report data.
* @param rpt_size - size of the report data.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
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);
/**
* @brief Send local HID device error response to remote HID host.
* @brief Notifies status to the Host using SET_REPORT command
*
* Send local HID device error response to remote HID host.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the peer device, see @ref bt_address_t.
* @param error - Error code, see @ref hid_status_error_t.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
* @param ins - bluetooth client instance.
* @param addr - address of peer device.
* @param error - error code.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_hid_device_report_error)(bt_instance_t* ins, bt_address_t* addr, hid_status_error_t error);
/**
* @brief Perform a virtual cable unplug with the current HID host.
* @brief Virtual unplug the current hid host
*
* Simulates the physical disconnection of the HID device from the host.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param addr - Address of the peer device, see @ref bt_address_t.
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
* @param ins - bluetooth client instance.
* @param addr - address of peer device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_hid_device_virtual_unplug)(bt_instance_t* ins, bt_address_t* addr);
@ -463,4 +295,4 @@ bt_status_t BTSYMBOLS(bt_hid_device_virtual_unplug)(bt_instance_t* ins, bt_addre
}
#endif
#endif /* __BT_HID_DEVICE_H__ */
#endif /* __BT_HID_DEVICE_H__ */

View File

@ -68,17 +68,6 @@ typedef enum {
BT_LE_SCAN_TYPE_ACTIVE
} ble_scan_type_t;
/**
* @brief Scan filter policy
*
*/
typedef enum {
BT_LE_SCAN_POLICY_ACCEPT_ALL = 0,
BT_LE_SCAN_POLICY_ONLY_WHITE_LIST,
BT_LE_SCAN_POLICY_ACCEPT_ALL_AND_RPA,
BT_LE_SCAN_POLICY_ONLY_WHITE_LIST_AND_RPA,
} ble_scan_filter_type_t;
/**
* @brief Scan result structure
*
@ -123,7 +112,6 @@ typedef struct {
int scan_window;
ble_scan_type_t scan_type;
ble_phy_type_t scan_phy;
ble_scan_filter_type_t filter_type;
} ble_scan_params_t;
typedef struct {

View File

@ -1,493 +0,0 @@
/****************************************************************************
* 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.
***************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#ifndef __BT_LEA_COMMON_H__
#define __BT_LEA_COMMON_H__
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include "bt_device.h"
#include "bt_list.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define LEA_BIT(_b) (1 << (_b))
#define MAX_PROVIDER_NAME_LENGTH 16
#define MAX_URI_SCHEMES_LENGTH 16
#define MAX_INCOMING_CALL_URI_LENGTH 16
#define MAX_CALL_URI_LENGTH 16
#define MAX_UCI_LENGTH 8
#define MAX_FRIENDLY_NAME_LENGTH 8
#ifndef CONFIG_BLUETOOTH_LEAUDIO_CLIENT_ASE_MAX_NUMBER
#define CONFIG_BLUETOOTH_LEAUDIO_CLIENT_ASE_MAX_NUMBER 2
#endif
#ifndef CONFIG_BLUETOOTH_LEAUDIO_CLIENT_MAX_DEVICES
#define CONFIG_BLUETOOTH_LEAUDIO_CLIENT_MAX_DEVICES 8
#endif
#ifndef CONFIG_BLUETOOTH_LEAUDIO_CLIENT_PAC_MAX_NUMBER
#define CONFIG_BLUETOOTH_LEAUDIO_CLIENT_PAC_MAX_NUMBER 3
#endif
#define LEA_CLIENT_MAX_STREAM_NUM (CONFIG_BLUETOOTH_LEAUDIO_CLIENT_ASE_MAX_NUMBER * CONFIG_BLUETOOTH_LEAUDIO_CLIENT_MAX_DEVICES)
/****************************************************************************
* Public Types
****************************************************************************/
enum { /* UUIDs */
GATT_UUID_MEDIA_CONTROL = 0x1848,
GATT_UUID_GENERIC_MEDIA_CONTROL = 0x1849,
GATT_UUID_TELEPHONE_BEARER = 0x184B,
GATT_UUID_GENERIC_TELEPHONE_BEARER = 0x184C,
};
typedef enum {
ADPT_LEA_GMCS_ID = 1,
ADPT_LEA_MCS1_ID,
ADPT_LEA_GTBS_ID,
ADPT_LEA_TBS1_ID,
ADPT_LEA_CSIS1_ID,
ADPT_LEA_SERVICE_MAX_ID,
} bt_lea_service_id;
typedef enum {
ADPT_LEA_ASE_TARGET_LOW_LATENCY = 1,
ADPT_LEA_ASE_TARGET_BALANCED = 2,
ADPT_LEA_ASE_TARGET_HIGH_RELIABILITY = 3,
} lea_adpt_ase_target_latency_t;
typedef enum {
ADPT_LEA_ASE_TARGET_PHY_1M = 1,
ADPT_LEA_ASE_TARGET_PHY_2M = 2,
ADPT_LEA_ASE_TARGET_PHY_CODED = 3,
} lea_adpt_ase_target_phy_t;
typedef enum {
ADPT_LEA_METADATA_PREFERRED_AUDIO_CONTEXTS = 0x01,
ADPT_LEA_METADATA_STREAMING_AUDIO_CONTEXTS,
ADPT_LEA_METADATA_PROGRAM_INFO,
ADPT_LEA_METADATA_LANGUAGE,
ADPT_LEA_METADATA_CCID_LIST,
ADPT_LEA_METADATA_PARENTAL_RATING,
ADPT_LEA_METADATA_PROGRAM_INFO_URI,
ADPT_LEA_METADATA_EXTENDED_METADATA = 0xFE,
ADPT_LEA_METADATA_VENDOR_SPECIFIC = 0xFF,
} lea_adpt_metadata_type_t;
typedef enum {
ADPT_LEA_ASE_STATE_IDLE,
ADPT_LEA_ASE_STATE_CODEC_CONFIG,
ADPT_LEA_ASE_STATE_QOS_CONFIG,
ADPT_LEA_ASE_STATE_ENABLING,
ADPT_LEA_ASE_STATE_STREAMING,
ADPT_LEA_ASE_STATE_DISABLING,
ADPT_LEA_ASE_STATE_RELEASING,
} lea_adpt_ase_state_t;
typedef enum {
LEA_ASE_OP_CONFIG_CODEC,
LEA_ASE_OP_CONFIG_QOS,
LEA_ASE_OP_ENABLE,
LEA_ASE_OP_DISABLE,
LEA_ASE_OP_UPDATE_METADATA,
LEA_ASE_OP_RELEASE
} lea_ase_opcode;
/* Possible TBS bearer technologies. */
typedef enum {
ADPT_LEA_TBS_BEARER_RESERVED, /**< Reserved */
ADPT_LEA_TBS_BEARER_3G, /**< 3G network */
ADPT_LEA_TBS_BEARER_4G, /**< 4G network */
ADPT_LEA_TBS_BEARER_LTE, /**< LTE network */
ADPT_LEA_TBS_BEARER_WIFI, /**< Wi-Fi network */
ADPT_LEA_TBS_BEARER_5G, /**< 5G network. */
ADPT_LEA_TBS_BEARER_GSM, /**< GSM network. */
ADPT_LEA_TBS_BEARER_CDMA, /**< CDMA network. */
ADPT_LEA_TBS_BEARER_2G, /**< 2G network. */
ADPT_LEA_TBS_BEARER_WCDMA, /**< WCDMA network. */
} lea_adpt_bearer_technology_t;
enum {
ADPT_LEA_CALL_FLAGS_OUTGOING_CALL = 0x01,
ADPT_LEA_CALL_FLAGS_INFORMATION_WITHHELD_BY_SERVER = 0x02,
ADPT_LEA_CALL_FLAGS_INFORMATION_WITHHELD_BY_NETWORK = 0x04
};
typedef enum {
ADPT_LEA_TBS_CALL_STATE_INCOMING, /**< Incoming call: a remote party is calling. */
ADPT_LEA_TBS_CALL_STATE_DIALING, /**< Dialing (outgoing call): Call the remote party, but remote party is not being alerted. */
ADPT_LEA_TBS_CALL_STATE_ALERTING, /**< Alerting (outgoing call): Remote party is being alerted. */
ADPT_LEA_TBS_CALL_STATE_ACTIVE, /**< Active (ongoing call): The call is in an active conversation. */
ADPT_LEA_TBS_CALL_STATE_LOCALLY_HELD, /**< Locally Held: The call is held locally. */
ADPT_LEA_TBS_CALL_STATE_REMOTELY_HELD, /**< Remotely Held: The call is held by the remote party. */
ADPT_LEA_TBS_CALL_STATE_BOTH_HELD, /**< Locally and Remotely Held: The call is held both locally and remotely. */
ADPT_LEA_TBS_CALL_STATE_INVAILD,
} lea_adpt_call_state_t;
/** Call control point opcodes. */
typedef enum {
ADPT_LEA_TBS_CALL_CONTROL_ACCEPT, /**< Accept the specified incoming call. */
ADPT_LEA_TBS_CALL_CONTROL_TERMINATE, /**< End the specified active, alerting, dialing, incoming or held call. */
ADPT_LEA_TBS_CALL_CONTROL_LOCAL_HOLD, /**< Place the specified active or incoming call on local hold. */
ADPT_LEA_TBS_CALL_CONTROL_LOCAL_RETRIEVE, /**< If the specified call is locally held, move it to an active call. Or, if it is locally and remotely held, move it to a remotely held call.*/
ADPT_LEA_TBS_CALL_CONTROL_ORIGINATE, /**< Initiate a call to the remote party identified by the URI. */
ADPT_LEA_TBS_CALL_CONTROL_JOIN, /**< Put calls (not in remotely held state) in the list to active and join the calls. Any calls in one of the remotely held state move to remotely held state and are joined with the other calls. */
} lea_adpt_call_control_opcode_t;
typedef enum {
ADPT_LEA_TBS_REASON_URI, /**< Improperly formed URI value. */
ADPT_LEA_TBS_REASON_CALL_FAILED, /**< The call failed. */
ADPT_LEA_TBS_REASON_ENDED_BY_REMOTE, /**< The remote party ended the call. */
ADPT_LEA_TBS_REASON_ENDED_FROM_SERVER, /**< The call ended from the server. */
ADPT_LEA_TBS_REASON_LINE_WAS_BUSY, /**< The line was busy. */
ADPT_LEA_TBS_REASON_NETWORK_CONGESTION, /**< Network congestion. */
ADPT_LEA_TBS_REASON_ENDED_BY_CLIENT, /**< The client terminated the call. */
ADPT_LEA_TBS_REASON_NO_SERVICE, /**< No service. */
ADPT_LEA_TBS_REASON_NO_ANSWER, /**< No answer. */
ADPT_LEA_TBS_REASON_UNSPECIFIED, /**< Any other unspecified reason. */
} lea_adpt_termination_reason_t;
/** Result of call control operation. */
typedef enum {
ADPT_LEA_TBS_CALL_CONTROL_SUCCESS, /**< The operation was successful. */
ADPT_LEA_TBS_CALL_CONTROL_NOT_SUPPORTED, /**< An invalid opcode was used. */
ADPT_LEA_TBS_CALL_CONTROL_OPEARTION_NOT_POSSIBLE, /**< The requested operation can't be completed. */
ADPT_LEA_TBS_CALL_CONTROL_INVALID_CALL_INDEX, /**< The call index used for the requested action is invalid. */
ADPT_LEA_TBS_CALL_CONTROL_STATE_MISMATCH, /**< The call was not in the expected state for the requested action. */
ADPT_LEA_TBS_CALL_CONTROL_LACK_OF_RESOURCES, /**< Lack of internal resorces to complete the requested action. */
ADPT_LEA_TBS_CALL_CONTROL_INVALID_OUTGOING_URI, /**< The Outgoing URI is incorrect or invalid. */
} lea_adpt_call_control_result_t;
typedef enum {
ADPT_LEA_PAC_TYPE_SINK_PAC = 0x2BC9,
ADPT_LEA_PAC_TYPE_SOURCE_PAC = 0x2BCB,
} lea_pac_type_t;
typedef enum {
ADPT_LEA_FORMAT_TRANSPARENT = 0x03,
ADPT_LEA_FORMAT_LC3 = 0x06,
ADPT_LEA_FORMAT_G729A = 0x07,
ADPT_LEA_FORMAT_VENDOR = 0xFF,
} lea_codec_fromat;
typedef enum {
ADPT_LEA_SUPPORTED_SAMPLE_FREQUENCY_8000 = LEA_BIT(0),
ADPT_LEA_SUPPORTED_SAMPLE_FREQUENCY_11025 = LEA_BIT(1),
ADPT_LEA_SUPPORTED_SAMPLE_FREQUENCY_16000 = LEA_BIT(2),
ADPT_LEA_SUPPORTED_SAMPLE_FREQUENCY_22050 = LEA_BIT(3),
ADPT_LEA_SUPPORTED_SAMPLE_FREQUENCY_24000 = LEA_BIT(4),
ADPT_LEA_SUPPORTED_SAMPLE_FREQUENCY_32000 = LEA_BIT(5),
ADPT_LEA_SUPPORTED_SAMPLE_FREQUENCY_44100 = LEA_BIT(6),
ADPT_LEA_SUPPORTED_SAMPLE_FREQUENCY_48000 = LEA_BIT(7),
ADPT_LEA_SUPPORTED_SAMPLE_FREQUENCY_88200 = LEA_BIT(8),
ADPT_LEA_SUPPORTED_SAMPLE_FREQUENCY_96000 = LEA_BIT(9),
ADPT_LEA_SUPPORTED_SAMPLE_FREQUENCY_176400 = LEA_BIT(10),
ADPT_LEA_SUPPORTED_SAMPLE_FREQUENCY_192000 = LEA_BIT(11),
ADPT_LEA_SUPPORTED_SAMPLE_FREQUENCY_384000 = LEA_BIT(12),
} lea_sample_frequencies_t;
typedef enum {
ADPT_LEA_SUPPORTED_FRAME_DURATION_7_5 = LEA_BIT(0),
ADPT_LEA_SUPPORTED_FRAME_DURATION_10 = LEA_BIT(1),
ADPT_LEA_PREFERRED_FRAME_DURATION_7_5 = LEA_BIT(4),
ADPT_LEA_PREFERRED_FRAME_DURATION_10 = LEA_BIT(5),
} lea_frame_durations_t;
typedef enum {
ADPT_LEA_SUPPORTED_CHANNEL_COUNT_1 = LEA_BIT(0),
ADPT_LEA_SUPPORTED_CHANNEL_COUNT_2 = LEA_BIT(1),
ADPT_LEA_SUPPORTED_CHANNEL_COUNT_3 = LEA_BIT(2),
ADPT_LEA_SUPPORTED_CHANNEL_COUNT_4 = LEA_BIT(3),
ADPT_LEA_SUPPORTED_CHANNEL_COUNT_5 = LEA_BIT(4),
ADPT_LEA_SUPPORTED_CHANNEL_COUNT_6 = LEA_BIT(5),
ADPT_LEA_SUPPORTED_CHANNEL_COUNT_7 = LEA_BIT(6),
ADPT_LEA_SUPPORTED_CHANNEL_COUNT_8 = LEA_BIT(7),
} lea_channal_counts_t;
typedef enum {
ADPT_LEA_SIRK_TYPE_ENCRYPTED,
ADPT_LEA_SIRK_TYPE_PLAIN_TEXT,
ADPT_LEA_SIRK_TYPE_OOB_ONLY = 0xFF,
} lea_sirk_type_t;
/* Context ID */
typedef enum {
ADPT_LEA_CTX_ID_UNSPECIFIED,
ADPT_LEA_CTX_ID_CONVERSATIONAL,
ADPT_LEA_CTX_ID_MEDIA,
ADPT_LEA_CTX_ID_GAME,
ADPT_LEA_CTX_ID_INSTRUCTIONAL,
ADPT_LEA_CTX_ID_VOICE_ASSISTANTS,
ADPT_LEA_CTX_ID_LIVE,
ADPT_LEA_CTX_ID_SOUND_EFFECTS,
ADPT_LEA_CTX_ID_NOTIFICATIONS,
ADPT_LEA_CTX_ID_RINGTONE,
ADPT_LEA_CTX_ID_ALERTS,
ADPT_LEA_CTX_ID_EMERGENCY_ALARM,
ADPT_LEA_CTX_ID_NUMBER,
} lea_adpt_context_id_t;
typedef enum {
ADPT_LEA_CONTEXT_TYPE_PROHIBITED,
ADPT_LEA_CONTEXT_TYPE_UNSPECIFIED = LEA_BIT(ADPT_LEA_CTX_ID_UNSPECIFIED),
ADPT_LEA_CONTEXT_TYPE_CONVERSATIONAL = LEA_BIT(ADPT_LEA_CTX_ID_CONVERSATIONAL),
ADPT_LEA_CONTEXT_TYPE_MEDIA = LEA_BIT(ADPT_LEA_CTX_ID_MEDIA),
ADPT_LEA_CONTEXT_TYPE_GAME = LEA_BIT(ADPT_LEA_CTX_ID_GAME),
ADPT_LEA_CONTEXT_TYPE_INSTRUCTIONAL = LEA_BIT(ADPT_LEA_CTX_ID_INSTRUCTIONAL),
ADPT_LEA_CONTEXT_TYPE_VOICE_ASSISTANTS = LEA_BIT(ADPT_LEA_CTX_ID_VOICE_ASSISTANTS),
ADPT_LEA_CONTEXT_TYPE_LIVE = LEA_BIT(ADPT_LEA_CTX_ID_LIVE),
ADPT_LEA_CONTEXT_TYPE_SOUND_EFFECTS = LEA_BIT(ADPT_LEA_CTX_ID_SOUND_EFFECTS),
ADPT_LEA_CONTEXT_TYPE_NOTIFICATIONS = LEA_BIT(ADPT_LEA_CTX_ID_NOTIFICATIONS),
ADPT_LEA_CONTEXT_TYPE_RINGTONE = LEA_BIT(ADPT_LEA_CTX_ID_RINGTONE),
ADPT_LEA_CONTEXT_TYPE_ALERTS = LEA_BIT(ADPT_LEA_CTX_ID_ALERTS),
ADPT_LEA_CONTEXT_TYPE_EMERGENCY_ALARM = LEA_BIT(ADPT_LEA_CTX_ID_EMERGENCY_ALARM),
} lea_adpt_context_types_t;
typedef enum {
ADPT_LEA_LC3_SET_UNKNOWN,
ADPT_LEA_LC3_SET_8_1_1, /* Odd is 7.5 ms */
ADPT_LEA_LC3_SET_8_2_2, /* Even is 10 ms */
ADPT_LEA_LC3_SET_16_1_3,
ADPT_LEA_LC3_SET_16_2_4,
ADPT_LEA_LC3_SET_24_1_5,
ADPT_LEA_LC3_SET_24_2_6,
ADPT_LEA_LC3_SET_32_1_7,
ADPT_LEA_LC3_SET_32_2_8,
ADPT_LEA_LC3_SET_441_1_9,
ADPT_LEA_LC3_SET_441_2_10,
ADPT_LEA_LC3_SET_48_1_11,
ADPT_LEA_LC3_SET_48_2_12,
ADPT_LEA_LC3_SET_48_3_13,
ADPT_LEA_LC3_SET_48_4_14,
ADPT_LEA_LC3_SET_48_5_15,
ADPT_LEA_LC3_SET_48_6_16,
} lea_lc3_set_id_t;
typedef enum {
ADPT_LEA_SAMPLE_FREQUENCY_UNKNOWN,
ADPT_LEA_SAMPLE_FREQUENCY_8000 = 1,
ADPT_LEA_SAMPLE_FREQUENCY_11025,
ADPT_LEA_SAMPLE_FREQUENCY_16000,
ADPT_LEA_SAMPLE_FREQUENCY_22050,
ADPT_LEA_SAMPLE_FREQUENCY_24000,
ADPT_LEA_SAMPLE_FREQUENCY_32000,
ADPT_LEA_SAMPLE_FREQUENCY_44100,
ADPT_LEA_SAMPLE_FREQUENCY_48000,
ADPT_LEA_SAMPLE_FREQUENCY_88200,
ADPT_LEA_SAMPLE_FREQUENCY_96000,
ADPT_LEA_SAMPLE_FREQUENCY_176400,
ADPT_LEA_SAMPLE_FREQUENCY_192000,
ADPT_LEA_SAMPLE_FREQUENCY_384000,
} lea_sample_frequency_t;
typedef enum {
ADPT_LEA_FRAME_DURATION_7_5,
ADPT_LEA_FRAME_DURATION_10,
} lea_frame_duration;
typedef struct {
uint8_t frequency;
uint8_t duration;
uint16_t octets;
} lea_lc3_config_t;
typedef struct {
uint16_t contexts;
uint8_t set_number;
uint8_t* set_10_ids;
} lea_lc3_prefer_config;
typedef struct {
uint8_t format;
uint16_t company_id;
uint16_t codec_id;
} lea_codec_id_t;
typedef struct {
lea_codec_id_t codec_id;
uint16_t mask;
uint8_t frequency;
uint8_t duration;
uint32_t allocation;
uint16_t octets;
uint8_t blocks;
} lea_codec_config_t;
typedef struct
{
uint16_t stream_handle;
uint32_t channel_allocation;
} lea_stream_info_t;
typedef struct
{
uint16_t mask;
uint16_t frequencies;
uint8_t durations;
uint8_t channels;
uint16_t frame_octets_min;
uint16_t frame_octets_max;
uint8_t max_frames;
} lea_codec_cap_t;
typedef struct
{
uint8_t type;
union {
uint32_t preferred_contexts;
uint32_t streaming_contexts;
uint8_t program_info[64];
uint32_t language;
uint8_t ccid_list[64];
uint32_t parental_rating;
uint8_t program_info_uri[64];
uint8_t extended_metadata[64];
uint8_t vendor_specific[64];
};
} lea_metadata_t;
typedef struct {
lea_pac_type_t pac_type;
uint32_t pac_id;
lea_codec_id_t codec_id;
lea_codec_cap_t codec_pac;
uint8_t md_number;
lea_metadata_t* md_value;
} lea_pac_info_t;
typedef struct
{
uint16_t sink;
uint16_t source;
} lea_audio_context_t;
typedef struct {
uint8_t pac_number;
lea_pac_info_t* pac_list;
uint32_t sink_location;
uint32_t source_location;
lea_audio_context_t supported_ctx;
lea_audio_context_t available_ctx;
} lea_pacs_info_t;
typedef struct {
uint8_t sink_ase_number;
uint8_t source_ase_number;
} lea_ascs_info_t;
typedef struct {
uint8_t bass_number;
} lea_bass_info_t;
typedef struct {
uint32_t csis_id;
uint8_t set_size;
uint8_t sirk[16];
uint8_t sirk_type;
uint8_t rank;
} lea_csis_info_t;
typedef struct {
uint8_t csis_number;
uint8_t rfu;
lea_csis_info_t* csis_info;
} lea_csis_infos_t;
typedef struct {
bool is_source;
bool started;
uint8_t target_latency;
uint8_t target_phy;
uint8_t channal_num;
uint16_t iso_handle;
uint16_t sdu_size;
uint16_t max_sdu;
uint32_t stream_id;
uint32_t group_id;
bt_address_t addr;
lea_codec_config_t codec_cfg;
} lea_audio_stream_t;
typedef struct {
void* reserved_data;
uint16_t iso_handle;
uint8_t reserved_handle;
uint16_t sdu_length;
uint8_t* sdu;
} lea_send_iso_data_t;
typedef struct {
struct list_node node;
uint32_t time_stamp;
uint16_t seq;
uint16_t length;
uint8_t sdu[1];
} lea_recv_iso_data_t;
/* LE Audio TBS struct */
typedef struct {
void* bearer_ref; /**< Application specified bearer identity. */
uint8_t provider_name[MAX_PROVIDER_NAME_LENGTH]; /**< Initial Bearer Provider Name. Zero terminated UTF-8 string. */
uint8_t uci[MAX_UCI_LENGTH]; /**< Bearer UCI. Zero terminated UTF-8 string. */
uint8_t uri_schemes[MAX_URI_SCHEMES_LENGTH]; /**< Initial list of Bearer URI schemes supported. Zero terminated UTF-8 string. */
uint8_t technology; /**< Initial Bearer Technology, one of #SERVICE_LEA_TBS_BEARER_TECHNLOGY. */
uint8_t signal_strength; /**< Initial Bearer Signal Strength, 0 indicates no service; 1 to 100 indicates the valid signal strength. 255 indicates that signal strength is unavailable or has no meaning. */
uint8_t signal_strength_report_interval; /**< Initial Signal Strength reporting interval in seconds. 0 to 255. 0 indicates that reporting signal strength only when it is changed. */
uint16_t status_flags; /**< Server feature status. Bits of #SERVICE_LEA_TBS_STATUS_FLAGS. */
uint16_t optional_opcodes_supported; /**< Call control point optional Opcodes supported. Bits of #SERVICE_LEA_TBS_SUPPORTED_CALL_CONTROL_OPCODES. */
} lea_tbs_telephone_bearer_t;
typedef struct {
uint8_t index; /**< Call Index, 1 to 255. */
uint8_t state; /**< Initial Call State, one of #SERVICE_LEA_TBS_CALL_STATE. */
uint8_t flags; /**< Initial Call flags, bits of #SERVICE_LEA_TBS_CALL_FLAGS. */
uint8_t call_uri[MAX_CALL_URI_LENGTH]; /**< The Incoming Call URI or Outgoing Call URI. Zero terminated UTF-8 string. Set to NULL if the URI is unknown. */
uint8_t incoming_target_uri[MAX_INCOMING_CALL_URI_LENGTH]; /**< The Incoming Call Target Bearer URI. Zero terminated UTF-8 string. Set to NULL for an outgoing call or if the URI is unknown. */
uint8_t friendly_name[MAX_FRIENDLY_NAME_LENGTH]; /**< The Friendly Name of the incoming or outgoing call. Zero terminated UTF-8 string. Set to NULL if the URI is unknown. */
} lea_tbs_calls_t;
typedef struct {
uint8_t index; /**< Call Index, 1 to 255. */
uint8_t state; /**< Call State, one of #SERVICE_LEA_TBS_CALL_STATE. */
uint8_t flags; /**< Call flags, bits of #SERVICE_LEA_TBS_CALL_FLAGS. */
} lea_tbs_call_state_t;
typedef struct {
uint8_t index; /**< Call Index, 1 to 255. */
uint8_t state; /**< Call State, one of #SERVICE_LEA_TBS_CALL_STATE. */
uint8_t flags; /**< Call flags, bits of #SERVICE_LEA_TBS_CALL_FLAGS. */
char call_uri[0]; /**< The Incoming Call URI or Outgoing Call URI. Zero terminated UTF-8 string. Set to NULL if the URI is unknown. */
} lea_tbs_call_list_item_t;
typedef void (*lea_audio_suspend_callback)(void);
typedef void (*lea_audio_resume_callback)(void);
typedef void (*lea_audio_meatadata_updated_callback)(void);
typedef void (*lea_audio_send_callback)(uint8_t* buffer, uint16_t length);
#endif

View File

@ -1,347 +0,0 @@
/****************************************************************************
* include/bt_list_internal.h
*
* Extracted from logic originally written by Travis Geiselbrecht and
* released under a public domain license. Re-released here under the 3-
* clause BSD license by Pinecone, Inc.
*
* Copyright (C) 2008 Travis Geiselbrecht. All rights reserved.
* Author: Travis Geiselbrecht <geist@foobox.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_BT_LIST_INTERNAL_H
#define __INCLUDE_BT_LIST_INTERNAL_H
/****************************************************************************
* Included Files
****************************************************************************/
#ifndef __NuttX__
#include <stdbool.h>
#include <stddef.h>
#define FAR
#define NEAR
#define DSEG
#define CODE
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define LIST_INITIAL_VALUE(list) \
{ \
&(list), &(list) \
}
#define LIST_INITIAL_CLEARED_VALUE \
{ \
NULL, NULL \
}
#define list_in_list(item) ((item)->prev != NULL)
#define list_is_empty(list) ((list)->next == list)
#define list_is_clear(list) ((list)->next == NULL)
#define list_is_singular(list) ((list)->next == (list)->prev)
#define list_initialize(list) \
do { \
FAR struct list_node* __list = (list); \
__list->prev = __list->next = __list; \
} while (0)
#define list_clear_node(item) \
do { \
FAR struct list_node* __item = (item); \
__item->prev = __item->next = NULL; \
} while (0)
#define list_peek_head(list) ((list)->next != (list) ? (list)->next : NULL)
#define list_peek_tail(list) ((list)->prev != (list) ? (list)->prev : NULL)
#define list_prev(list, item) ((item)->prev != (list) ? (item)->prev : NULL)
#define list_prev_wrap(list, item) \
((item)->prev != (list) ? (item)->prev : (item)->prev->prev != (list) ? (item)->prev->prev \
: NULL)
#define list_next(list, item) ((item)->next != (list) ? (item)->next : NULL)
#define list_next_wrap(list, item) \
((item)->next != (list) ? (item)->next : (item)->next->next != (list) ? (item)->next->next \
: NULL)
#define list_entry(ptr, type, member) container_of(ptr, type, member)
#define list_first_entry(list, type, member) container_of((list)->next, type, member)
#define list_last_entry(list, type, member) container_of((list)->prev, type, member)
#define list_next_entry(list, type, member) container_of((list)->member.next, type, member)
#define list_prev_entry(list, type, member) container_of((list)->member.prev, type, member)
#define list_add_after(entry, new_entry) list_add_head(entry, new_entry)
#define list_add_head(list, item) \
do { \
FAR struct list_node* __list = (list); \
FAR struct list_node* __item = (item); \
__item->next = __list->next; \
__item->prev = __list; \
__list->next->prev = __item; \
__list->next = __item; \
} while (0)
#define list_add_before(entry, new_entry) list_add_tail(entry, new_entry)
#define list_add_tail(list, item) \
do { \
FAR struct list_node* __list = (list); \
FAR struct list_node* __item = (item); \
__item->prev = __list->prev; \
__item->next = __list; \
__list->prev->next = __item; \
__list->prev = __item; \
} while (0)
#define list_delete(item) \
do { \
FAR struct list_node* __item = (item); \
__item->next->prev = __item->prev; \
__item->prev->next = __item->next; \
__item->prev = __item->next = NULL; \
} while (0)
#define list_delete_init(item) \
do { \
list_delete(item); \
list_initialize(item); \
} while (0)
#define list_merge(list_dst, list_src) \
do { \
(list_dst)->prev->next = (list_src)->next; \
(list_src)->next->prev = (list_dst)->prev; \
(list_src)->prev->next = (list_dst); \
(list_dst)->prev = (list_src)->prev; \
list_initialize(list_src); \
} while (0)
#define list_remove_head_type(list, type, member) \
({ \
FAR struct list_node* __node = list_remove_head(list); \
FAR type* __t = NULL; \
if (__node) { \
__t = container_of(__node, type, member); \
} \
__t; \
})
#define list_remove_tail_type(list, type, member) \
({ \
FAR struct list_node* __node = list_remove_tail(list); \
FAR type* __t = NULL; \
if (__node) { \
__t = container_of(__node, type, member); \
} \
__t; \
})
#define list_peek_head_type(list, type, member) \
({ \
FAR struct list_node* __node = list_peek_head(list); \
FAR type* __t = NULL; \
if (__node) { \
__t = container_of(__node, type, member); \
} \
__t; \
})
#define list_peek_tail_type(list, type, member) \
({ \
FAR struct list_node* __node = list_peek_tail(list); \
FAR type* __t = NULL; \
if (__node) { \
__t = container_of(__node, type, member); \
} \
__t; \
})
#define list_prev_type(list, item, type, member) \
({ \
FAR struct list_node* __node = list_prev(list, item); \
FAR type* __t = NULL; \
if (__node) { \
__t = container_of(__node, type, member); \
} \
__t; \
})
#define list_prev_wrap_type(list, item, type, member) \
({ \
FAR struct list_node* __node = list_prev_wrap(list, item); \
FAR type* __t = NULL; \
if (__node) { \
__t = container_of(__node, type, member); \
} \
__t; \
})
#define list_next_type(list, item, type, member) \
({ \
FAR struct list_node* __node = list_next(list, item); \
FAR type* __t = NULL; \
if (__node) { \
__t = container_of(__node, type, member); \
} \
__t; \
})
#define list_next_wrap_type(list, item, type, member) \
({ \
FAR struct list_node* __node = list_next_wrap(list, item); \
FAR type* __t = NULL; \
if (__node) { \
__t = container_of(__node, type, member); \
} \
__t; \
})
/* iterates over the list, node should be struct list_node* */
#define list_for_every(list, node) \
for (node = (list)->next; node != (list); node = node->next)
/* iterates over the list in a safe way for deletion of current node
* node and temp_node should be struct list_node*
*/
#define list_for_every_safe(list, node, temp) \
for (node = (list)->next, temp = node->next; \
node != (list); node = temp, temp = node->next)
/* iterates over the list, entry should be the container structure type */
#define list_for_every_entry(list, entry, type, member) \
for (entry = container_of((list)->next, type, member); \
&entry->member != (list); \
entry = container_of(entry->member.next, type, member))
/* iterates over the list in a safe way for deletion of current node
* entry and temp_entry should be the container structure type *
*/
#define list_for_every_entry_safe(list, entry, temp, type, member) \
for (entry = container_of((list)->next, type, member), \
temp = container_of(entry->member.next, type, member); \
&entry->member != (list); entry = temp, \
temp = container_of(temp->member.next, type, member))
/* Iterate from a given entry node in a safe way */
#define list_for_every_entry_safe_from(list, cur, temp, type, member) \
for ((temp) = list_next_entry(cur, type, member); \
&(cur)->member != (list); \
(cur) = (temp), (temp) = list_next_entry(temp, type, member))
#define list_for_every_entry_continue(list, head, type, member) \
for ((list) = list_next_entry(list, type, member); \
&(list)->member != (head); \
(list) = list_next_entry(list, type, member))
/* iterates over the list in reverse order, entry should be the container
* structure type
*/
#define list_for_every_entry_reverse(list, entry, type, member) \
for (entry = container_of((list)->prev, type, member); \
&entry->member != (list); \
entry = container_of(entry->member.prev, type, member))
/****************************************************************************
* Public Type Definitions
****************************************************************************/
struct list_node {
FAR struct list_node* next;
FAR struct list_node* prev;
};
/****************************************************************************
* Inline Functions
****************************************************************************/
static inline FAR struct list_node*
list_remove_head(FAR struct list_node* list)
{
if (list->next != list) {
FAR struct list_node* item = list->next;
list_delete(item);
return item;
} else {
return NULL;
}
}
static inline FAR struct list_node*
list_remove_tail(FAR struct list_node* list)
{
if (list->prev != list) {
FAR struct list_node* item = list->prev;
list_delete(item);
return item;
} else {
return NULL;
}
}
static inline size_t list_length(FAR struct list_node* list)
{
FAR struct list_node* node = list;
size_t cnt = 0;
list_for_every(list, node)
{
cnt++;
}
return cnt;
}
#else // defined(__NuttX__)
#include <nuttx/list.h>
#endif // #ifndef __NuttX__
/* Define Bluetooth proprietary macros hereafter */
#define list_merge(list_dst, list_src) \
do { \
(list_dst)->prev->next = (list_src)->next; \
(list_src)->next->prev = (list_dst)->prev; \
(list_src)->prev->next = (list_dst); \
(list_dst)->prev = (list_src)->prev; \
list_initialize(list_src); \
} while (0)
#endif /* __INCLUDE_BT_LIST_INTERNAL_H */

View File

@ -1,48 +0,0 @@
/****************************************************************************
* 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_MEMORY_H_
#define _BT_MEMORY_H_
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
#if defined(CONFIG_BLUETOOTH_DEBUG_MEMORY)
void* bt_malloc_hook(size_t size, const char* file, int line);
void* bt_calloc_hook(size_t n, size_t size, const char* file, int line);
void bt_free_hook(void* ptr);
void bt_report_leak(void);
#define bt_malloc(size) bt_malloc_hook(size, __FILE__, __LINE__)
#define bt_calloc(n, size) bt_calloc_hook(n, size, __FILE__, __LINE__)
#define bt_free(ptr) bt_free_hook(ptr)
#define bt_zalloc(size) bt_calloc(1, size)
#else
#define bt_malloc(size) malloc(size)
#define bt_calloc(n, size) calloc(n, size)
#define bt_free(ptr) free(ptr)
#define bt_zalloc(size) zalloc(size)
#endif // CONFIG_BLUETOOTH_DEBUG_MEMORY
#ifdef __cplusplus
}
#endif
#endif // _BT_MEMORY_H_

View File

@ -24,7 +24,6 @@ extern "C" {
#define PROFILE_A2DP_SINK_NAME "A2DP-Sink"
#define PROFILE_AVRCP_CT_NAME "AVRCP-CT"
#define PROFILE_AVRCP_TG_NAME "AVRCP-TG"
#define PROFILE_CS_NAME "CS"
#define PROFILE_HFP_HF_NAME "HFP-HF"
#define PROFILE_HFP_AG_NAME "HFP-AG"
#define PROFILE_SPP_NAME "SPP"
@ -61,7 +60,6 @@ enum profile_id {
PROFILE_LEAUDIO_MCS,
PROFILE_LEAUDIO_TBS,
PROFILE_LEAUDIO_VMICP,
PROFILE_CS, // TODO: remove this profile
PROFILE_UNKOWN,
PROFILE_MAX
};

View File

@ -1,45 +0,0 @@
/****************************************************************************
* 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 <stdint.h>
#ifndef _BT_SCHED_TRACE_H_
#define _BT_SCHED_TRACE_H_
#define MAX_TAG_LEN 16
typedef struct {
uint64_t start_ns;
char tag[MAX_TAG_LEN];
} bt_timepoint_t;
#ifdef CONFIG_BLUETOOTH_DEBUG_TRACE
void bt_note_start(void);
void bt_note_stop(void);
void bt_note_begin(const char* tag, bt_timepoint_t* point);
void bt_note_end(const char* tag, bt_timepoint_t* point);
#define bt_trace_start() bt_note_start()
#define bt_trace_stop() bt_note_stop()
#define bt_trace_begin(tag, point) bt_note_begin(tag, point)
#define bt_trace_end(tag, point) bt_note_end(tag, point)
#else
#define bt_trace_start()
#define bt_trace_stop()
#define bt_trace_begin(tag, point)
#define bt_trace_end(tag, point)
#endif
#endif // _BT_SCHED_TRACE_H_

View File

@ -30,10 +30,6 @@ extern "C" {
#define BTSYMBOLS(s) s
#endif
/**
* @cond
*/
/**
* @brief Unknow server channel number
*
@ -46,386 +42,107 @@ extern "C" {
*/
#define BT_UUID_SERVCLASS_SERIAL_PORT 0x1101
#define SPP_PORT_TYPE_TTY 1
/**
* @brief Spp proxy state
* @brief Spp pty mode
*
*/
typedef enum {
SPP_PROXY_STATE_CONNECTED,
SPP_PROXY_STATE_DISCONNECTED,
SPP_PROXY_STATE_CONNECTING,
SPP_PROXY_STATE_CLOSING,
} spp_proxy_state_t;
SPP_PTY_MODE_NORMAL,
SPP_PTY_MODE_RAW
} spp_pty_mode_t;
typedef enum {
SPP_PORT_TYPE_TTY,
SPP_PORT_TYPE_RPMSG_UART,
} spp_port_type_t;
/**
* @brief Callback used to notify SPP connection states.
* @brief Spp connection state callback
*
* When the SPP connection state changes, this callback will be triggered.
* SPP connection states include DISCONNECTED, CONNECTING, CONNECTED, and
* DISCONNECTING. After the callback is triggered, the application will be
* notified with the APP handle corresponding to the SPP connection state,
* the Bluetooth address of the peer device, the server channel number used
* for the SPP connection, the SPP connection port, and the latest SPP connection
* state.
*
* @param handle - SPP APP handle, the return value of bt_spp_register_app.
* @param addr - The Bluetooth address of the peer device.
* @param scn - Server channel number, range in 1-28.
* @param port - The The unique port of connection.
* @param state - SPP connection state
*
* **Example:**
* @code
void spp_connection_state_cb(void* handle, bt_address_t* addr,
uint16_t scn, uint16_t port,
profile_connection_state_t state)
{
printf("spp_connection_state_cb, state: %d\n", state);
}
* @endcode
* @param handle - spp app handle, the return value of bt_spp_register_app.
* @param addr - address of peer device.
* @param scn - server channel number, range in <1-28>.
* @param port - unique port of connection.
* @param state - spp connection state
*/
typedef void (*spp_connection_state_callback)(void* handle, bt_address_t* addr,
uint16_t scn, uint16_t port,
profile_connection_state_t state);
/**
* @brief Callback used to notify SPP PTY open. [deprecated]
* @brief Spp pty opened notification
*
* After a successful establishment of the SPP connection, the PTY will be
* opened. If the PTY is successfully opened, this callback will be triggered
* to notify the application that the PTY has been opened.The APP handle
* corresponding to the SPP connection, the Bluetooth address of the peer device,
* the server channel number, the connection port, and the PTY name also be
* notified.
*
* @note This callback is deprecated, use spp_proxy_state_callback instead.
*
* @param handle - SPP APP handle, the return value of bt_spp_register_app.
* @param addr - The Bluetooth address of the peer device.
* @param scn - Server channel number, range in 1-28.
* @param port - The unique port of connection.
* @param name - PTY slave device name, like "/dev/pts/0"
*
* **Example:**
* @code
void spp_pty_open_cb(void* handle, bt_address_t* addr, uint16_t scn, uint16_t port, char* name)
{
printf("spp_pty_open_cb, scn: %d, port: %d, name: %s\n", scn, port, name);
}
* @endcode
* @param handle - spp app handle, the return value of bt_spp_register_app.
* @param addr - address of peer device.
* @param scn - server channel number, range in <1-28>.
* @param port - unique port of connection.
* @param name - pty slave device name, like "/dev/pts/0"
*/
typedef void (*spp_pty_open_callback)(void* handle, bt_address_t* addr, uint16_t scn, uint16_t port, char* name);
/**
* @brief Callback used to notify SPP proxy states.
*
* When the SPP proxy state changes, this callback will be triggered. The SPP
* proxy states include CONNECTED and DISCONNECTED. After the callback is triggered,
* the application will be notified with the APP handle corresponding to the SPP
* proxy state, the Bluetooth address of the peer device, the server channel number
* used for the SPP connection, the SPP connection port, and the latest SPP proxy
* state.
*
* @param handle - SPP APP handle, the return value of bt_spp_register_app.
* @param addr - The Bluetooth address of the peer device.
* @param state - SPP proxy state.
* @param scn - Server channel number, range in 1-28.
* @param port - The unique port of connection.
* @param name - Proxy name, like "btspp-srv0"
*
* **Example:**
* @code
void spp_proxy_state_cb(void* handle, bt_address_t* addr, spp_proxy_state_t state, uint16_t scn, uint16_t port, char* name)
{
printf("spp_proxy_state_cb, state: %d, scn: %d, port: %d, name: %s\n", state, scn, port, name);
}
* @endcode
*/
typedef void (*spp_proxy_state_callback)(void* handle, bt_address_t* addr, spp_proxy_state_t state, uint16_t scn, uint16_t port, char* name);
/**
* @brief SPP event callbacks structure
*
*/
typedef struct {
size_t size;
spp_pty_open_callback pty_open_cb; /* [deprecated] */
spp_pty_open_callback pty_open_cb;
spp_connection_state_callback connection_state_cb;
spp_proxy_state_callback proxy_state_cb;
} spp_callbacks_t;
/**
* @endcond
*/
/**
* @brief Register an SPP service for applications.
* @brief Register spp app
*
* The application can register an SPP service through this function. Before using
* this function, the application should prepare callback functions for receiving
* SPP connection states notifications and SPP proxy states notifications or PTY open
* information notifications to register the service. After calling this function,
* the application will receive a handle to identify the application entity in the
* SPP service, which is used by the SPP service to find the corresponding application.
*
* @note It should be noted that the callback used for PTY open is not recommended, the
* callback used for SPP proxy states is recommended.
*
* @param ins - Bluetooth client instance.
* @param callbacks - SPP callback functions.
* @return void* - SPP APP handle, NULL represents fail.
*
* **Example:**
* @code
void* spp_handle;
const static spp_callbacks_t callbacks = {
.size = sizeof(spp_callbacks_t),
.connection_state_cb = spp_connection_state_cb,
.spp_proxy_state_cb = spp_proxy_state_cb,
};
void app_init_spp_1(bt_instance_t* ins)
{
spp_handle = bt_spp_register_app(ins, &callbacks);
if(!spp_handle)
printf("register spp app failed\n");
else
printf("register spp app success\n");
}
* @endcode
* @param ins - bluetooth client instance.
* @param callbacks - spp callback functions.
* @return void* - spp app handle, NULL on failure.
*/
void* BTSYMBOLS(bt_spp_register_app)(bt_instance_t* ins, const spp_callbacks_t* callbacks);
/**
* @brief Register an SPP service with specified extended parameters for applications.
* @brief Register spp app with params
*
* The application can register the SPP service with the specified name and port
* type used in the SPP service through this function. Before using this function,
* the application should prepare callback functions for receiving SPP connection
* states notifications and SPP proxy states notifications or PTY open information
* notifications to register the service. After calling this function, the application
* will receive a handle to identify the application entity in the SPP service, which
* is used by the SPP service to find the corresponding application.
*
* @note It should be noted that the callback used for PTY open is not recommended, the
* callback used for SPP proxy states is recommended.
*
* @param ins - Bluetooth client instance.
* @param callbacks - SPP callback functions.
* @param name - SPP application name.
* @param port_type - SPP port type used in SPP service, not used.
* @return void* - SPP application handle, NULL represents fail.
*
* **Example:**
* @code
void* spp_handle;
const static spp_callbacks_t callbacks = {
.size = sizeof(spp_callbacks_t),
.connection_state_cb = spp_connection_state_cb,
.spp_proxy_state_cb = spp_proxy_state_cb,
};
void app_init_spp_2(bt_instance_t* ins)
{
char* name = "spp_app_name";
spp_handle = bt_spp_register_app_ext(ins, name, 0, &callbacks);
if(!spp_handle)
printf("register spp app failed\n");
else
printf("register spp app success\n");
}
* @endcode
* @param ins - bluetooth client instance.
* @param callbacks - spp callback functions.
* @param name - spp app name.
* @param port_type - spp port type.
* @return void* - spp app handle, NULL on failure.
*/
void* BTSYMBOLS(bt_spp_register_app_ext)(bt_instance_t* ins, const char* name, int port_type, const spp_callbacks_t* callbacks);
/**
* @brief Register an SPP service with specified parameters for applications.
* @brief Unregister spp app
*
* The application can register the SPP service with the specified name and port
* type used in the SPP service through this function. Before using this function,
* the application should prepare callback functions for receiving SPP connection
* states notifications and SPP proxy states notifications or PTY open information
* notifications to register the service. After calling this function, the application
* will obtain a handle to identify the application entity in the SPP service, which
* will be used for the SPP service to find the corresponding application.
*
* @note It should be noted that the callback used for PTY open is not recommended, the
* callback used for SPP proxy states is recommended.
*
* @param ins - Bluetooth client instance.
* @param callbacks - SPP callback functions.
* @param name - SPP application name.
* @return void* - SPP application handle, NULL represents fail.
*
* **Example:**
* @code
void* spp_handle;
const static spp_callbacks_t callbacks = {
.size = sizeof(spp_callbacks_t),
.connection_state_cb = spp_connection_state_cb,
.spp_proxy_state_cb = spp_proxy_state_cb,
};
void app_init_spp_3(bt_instance_t* ins)
{
char* name = "spp_app_name";
spp_handle = bt_spp_register_app_with_name(ins, name, &callbacks);
if(!spp_handle)
printf("register spp app failed\n");
else
printf("register spp app success\n");
}
* @endcode
*/
void* BTSYMBOLS(bt_spp_register_app_with_name)(bt_instance_t* ins, const char* name, const spp_callbacks_t* callbacks);
/**
* @brief Unregister SPP service for applications.
*
* This function is used to unregister the SPP service for an application. Before
* using this function, the application should have completed registration
* of the Bluetooth service and obtained a valid handle. After the function returns
* a successful result, the application have unregistered the SPP service.
*
* @param ins - Bluetooth client instance.
* @param handle - SPP APP handle.
* @param ins - bluetooth client instance.
* @param handle - spp app handle.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
void app_unregister_spp_app(bt_instance_t* ins, void* handle)
{
bt_status_t status;
if(spp_handle)
return;
status = bt_spp_unregister_app(ins, spp_handle);
if(status != BT_STATUS_SUCCESS)
printf("unregister spp app failed\n");
else
printf("unregister spp app success\n");
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_spp_unregister_app)(bt_instance_t* ins, void* handle);
/**
* @brief Start the SPP server.
* @brief Start spp server
*
* This function is used to start an SPP server for a application. Before
* using this function, the application should have completed registration
* of the Bluetooth service and obtained a valid handle. In addition, the application
* needs to specify the server channel number, UUID and maximum number of supported
* connections using this function. After the function returns a successful result,
* the application will have started an SPP server that can be connected by SPP clients
* on other devices.
*
* @param ins - Bluetooth client instance.
* @param handle - SPP application handle.
* @param scn - Server channel number, range in 1-28.
* @param uuid - Server uuid, default:0x1101.
* @param max_connection - Maximum of client connections.
* @param ins - bluetooth client instance.
* @param handle - spp app handle.
* @param scn - server channel number, range in <1-28>.
* @param uuid - server uuid, default:0x1101.
* @param max_connection - maximum of client connections.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
void app_start_spp_server(bt_instance_t* ins, void* handle)
{
bt_status_t status;
uint16_t scn = 1;
bt_uuid_t uuid = {
.type = BT_UUID_TYPE_16,
.value = {0x11, 0x01},
};
uint8_t max_connection = 1;
status = bt_spp_server_start(ins, handle, scn, &uuid, max_connection);
if(status != BT_STATUS_SUCCESS)
printf("start spp server failed\n");
else
printf("start spp server success\n");
}
* @endcode
*/
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);
/**
* @brief Stop the SPP server.
* @brief Stop spp server
*
* This function is used to stop an SPP server for a application. Before
* using this function, the application should have started SPP server.
* In addition, the application needs to specify the server channel number using
* this function. After the function returns a successful result, the application
* will have stopped the SPP server.
*
* @param ins - Bluetooth client instance.
* @param handle - SPP application handle.
* @param scn - Server channel number, range in 1-28.
* @param ins - bluetooth client instance.
* @param handle - spp app handle.
* @param scn - server channel number, range in <1-28>.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
void app_stop_spp_server(bt_instance_t* ins, void* handle)
{
bt_status_t status;
uint16_t scn = 1;
status = bt_spp_server_stop(ins, handle, scn);
if(status != BT_STATUS_SUCCESS)
printf("stop spp server failed\n");
else
printf("stop spp server success\n");
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_spp_server_stop)(bt_instance_t* ins, void* handle, uint16_t scn);
/**
* @brief Connect to the SPP server
*
* This function is used to initiate a connection to the SPP server of a specified
* device. Before using this function, the application needs to complete SPP service
* registration and obtain a valid handle. In addition, when the application uses
* this function, it needs to specify the address of the remote device, the server
* channel number, UUID, and port used. If this function returns a successful result,
* an SPP connection will be established with the remote device.
*
* @param[in] ins - Bluetooth client instance.
* @param[in] handle - SPP application handle.
* @param[in] addr - The Bluetooth address of the peer device.
* @param[in] scn - Server channel number, range in 1-28.
* - UNKNOWN_SERVER_CHANNEL_NUM: Not specify scn.
* @param[in] uuid - Server uuid, default:0x1101.
* @param[out] port - The unique port of connection.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
void app_connect_spp_server(bt_instance_t* ins, void* handle)
{
bt_status_t status;
bt_address_t addr = {
.address = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06},
};
uint16_t port;
status = bt_spp_connect(ins, handle, &addr, UNKNOWN_SERVER_CHANNEL_NUM, NULL, &port);
if(status != BT_STATUS_SUCCESS)
printf("connect spp server failed\n");
else
printf("connect spp server success\n");
}
* @endcode
*/
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);
/**
* @brief Connect to spp server with insecure connection
* @brief Connect to spp server
*
* @param[in] ins - bluetooth client instance.
* @param[in] handle - spp app handle.
@ -436,39 +153,16 @@ bt_status_t BTSYMBOLS(bt_spp_connect)(bt_instance_t* ins, void* handle, bt_addre
* @param[out] port - point to unique port of connection.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_spp_insecure_connect)(bt_instance_t* ins, void* handle, bt_address_t* addr, int16_t scn, bt_uuid_t* uuid, uint16_t* port);
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);
/**
* @brief Disconnect to SPP server
* @brief Disconnect to spp server
*
* This function is used to initiate an SPP disconnection to a specified device.
* Before using this function, an SPP connection should have been successfully
* established with the remote device. In addition, the function requires providing
* the address of the remote device and the port used.
*
* @param ins - Bluetooth client instance.
* @param handle - SPP application handle.
* @param addr - The Bluetooth address of the peer device.
* @param port The unique port of connection.
* @param ins - bluetooth client instance.
* @param handle - spp app handle.
* @param addr - address of peer device.
* @param port unique port of connection.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
void app_disconnect_spp_server(bt_instance_t* ins, void* handle)
{
bt_status_t status;
bt_address_t addr = {
.addr = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06},
};
uint16_t port = 1;
status = bt_spp_disconnect(ins, handle, &addr, port);
if(status != BT_STATUS_SUCCESS)
printf("disconnect spp server failed\n");
else
printf("disconnect spp server success\n");
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_spp_disconnect)(bt_instance_t* ins, void* handle, bt_address_t* addr, uint16_t port);

View File

@ -1,25 +0,0 @@
/****************************************************************************
* 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_TIME_H__
#define _BT_TIME_H__
#include <stdint.h>
uint64_t bt_get_os_timestamp_us(void);
uint32_t bt_get_os_timestamp_ms(void);
#endif /* _BT_STORAGE_H__ */

View File

@ -21,9 +21,7 @@
extern "C" {
#endif
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif
#define CASE_RETURN_STR(const) \
case const: \

View File

@ -23,43 +23,12 @@ extern "C" {
#include <stdbool.h>
#include <stdint.h>
/**
* @cond
*/
#define BT_UUID_A2DP_SRC 0x110A
#define BT_UUID_A2DP_SNK 0x110B
#define BT_UUID_HFP 0x111E
#define BT_UUID_HFP_AG 0x111F
/* GATT Descriptor UUIDs (16-bit) */
#define BT_UUID_GATT_CEPD 0x2900
#define BT_UUID_GATT_CUDD 0x2901
#define BT_UUID_GATT_CCCD 0x2902
#define BT_UUID_GATT_CPFD 0x2904
#define BT_UUID_RANGING_VAL 0x185B
#define BT_UUID_RANGE_FEAT_VAL 0x2C14
#define BT_UUID_RANGE_RTT_DT_VAL 0x2C15
#define BT_UUID_RANGE_ON_DEM_DT_VAL 0x2C16
#define BT_UUID_RANGE_RAS_CTR_POINT_VAL 0x2C17
#define BT_UUID_RANGE_DT_RD_VAL 0x2C18
#define BT_UUID_RANGE_DT_OV_WR_VAL 0x2C19
#define BT_UUID_STR_LENGTH 40
typedef enum {
BT_UUID16_TYPE = 2,
BT_UUID32_TYPE = 4,
BT_UUID128_TYPE = 16,
} uuid_type_t;
typedef enum {
BT_HEAD_UUID16_TYPE = 1,
BT_HEAD_UUID32_TYPE = 2,
BT_HEAD_UUID128_TYPE = 3,
} head_uuid_type_t;
typedef struct {
uint8_t type; /* uuid_type_t */
uint8_t pad[3];
@ -71,23 +40,14 @@ typedef struct {
} val;
} bt_uuid_t;
#ifndef BT_UUID_DECLARE_16
#define BT_UUID_DECLARE_16(value) \
((bt_uuid_t) { .type = BT_UUID16_TYPE, .val.u16 = (value) })
#endif
#ifndef BT_UUID_DECLARE_32
#define BT_UUID_DECLARE_32(value) \
((bt_uuid_t) { .type = BT_UUID32_TYPE, .val.u32 = (value) })
#endif
#ifndef BT_UUID_DECLARE_128
#define BT_UUID_DECLARE_128(value...) \
((bt_uuid_t) { .type = BT_UUID128_TYPE, .val.u128 = { value } })
#endif
void bt_uuid_to_uuid128(const bt_uuid_t* src, bt_uuid_t* uuid128);
void bt_uuid_to_uuid16(const bt_uuid_t* src, bt_uuid_t* uuid16);
int bt_uuid_compare(const bt_uuid_t* uuid1, const bt_uuid_t* uuid2);
int bt_uuid16_create(bt_uuid_t* uuid16, uint16_t value);
int bt_uuid32_create(bt_uuid_t* uuid32, uint32_t value);

View File

@ -1,65 +0,0 @@
/****************************************************************************
* 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 __EUV_PIPE_H__
#define __EUV_PIPE_H__
#include "uv.h"
typedef enum {
EUV_PIPE_TYPE_UNKNOWN = -1,
EUV_PIPE_TYPE_SERVER_LOCAL,
EUV_PIPE_TYPE_SERVER_RPMSG,
EUV_PIPE_TYPE_CLIENT_LOCAL,
EUV_PIPE_TYPE_CLIENT_RPMSG,
} euv_pipe_mode_t;
typedef enum {
EUV_ALL_PIPE_CLOSED = 0,
EUV_CLIENT_PIPE_OPENED = 1 << 0,
EUV_LOCAL_SERVER_PIPE_OPENED = 1 << 1,
EUV_RPMSG_SERVER_PIPE_OPENED = 1 << 2,
} euv_pipe_status_t;
typedef struct euv_pipe euv_pipe_t;
typedef void (*euv_read_cb)(euv_pipe_t* handle, const uint8_t* buf, ssize_t size);
typedef void (*euv_write_cb)(euv_pipe_t* handle, uint8_t* buf, int status);
typedef void (*euv_alloc_cb)(euv_pipe_t* handle, uint8_t** buf, size_t* len);
typedef void (*euv_connect_cb)(euv_pipe_t* handle, int status, void* user_data);
typedef void (*euv_close_cb)(euv_pipe_t* handle);
struct euv_pipe {
uv_pipe_t cli_pipe;
uv_pipe_t srv_pipe[2];
euv_pipe_mode_t mode;
euv_pipe_status_t status;
void* data;
euv_close_cb close_cb;
};
euv_pipe_t* euv_pipe_open(uv_loop_t* loop, const char* path, euv_connect_cb cb, void* user_data);
void euv_pipe_close_with_cb(euv_pipe_t* handle, euv_close_cb cb);
void euv_pipe_close(euv_pipe_t* handle);
euv_pipe_t* euv_pipe_connect(uv_loop_t* loop, const char* path, euv_connect_cb cb, void* user_data);
#ifdef CONFIG_NET_RPMSG
euv_pipe_t* euv_rpmsg_pipe_connect(uv_loop_t* loop, const char* path, const char* cpu_name, euv_connect_cb cb, void* user_data);
void euv_pipe_close2(euv_pipe_t* handle);
#endif
void euv_pipe_disconnect(euv_pipe_t* handle);
int euv_pipe_write(euv_pipe_t* handle, uint8_t* buffer, int length, euv_write_cb cb);
int euv_pipe_read_start(euv_pipe_t* handle, uint16_t read_size, euv_read_cb read_cb, euv_alloc_cb alloc_cb);
int euv_pipe_read_stop(euv_pipe_t* handle);
#endif

View File

@ -137,15 +137,6 @@
list_initialize(item); \
} while (0)
#define list_merge(list_dst, list_src) \
do { \
(list_dst)->prev->next = (list_src)->next; \
(list_src)->next->prev = (list_dst)->prev; \
(list_src)->prev->next = (list_dst); \
(list_dst)->prev = (list_src)->prev; \
list_initialize(list_src); \
} while (0)
#define list_remove_head_type(list, type, member) \
({ \
FAR struct list_node* __node = list_remove_head(list); \
@ -281,7 +272,10 @@
* Public Type Definitions
****************************************************************************/
#include <nuttx/list_type.h>
struct list_node {
FAR struct list_node* prev;
FAR struct list_node* next;
};
/****************************************************************************
* Inline Functions

View File

@ -24,9 +24,6 @@ extern "C" {
#include <stdint.h>
#include <stdlib.h>
/* Default string returned when state name is NULL */
#define HSM_NONE_STR "None"
typedef struct _state_machine state_machine_t;
typedef struct _state {

View File

@ -1,743 +0,0 @@
/****************************************************************************
* 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 <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "bt_adapter.h"
#include "bt_async.h"
#include "bt_socket.h"
typedef struct {
void* userdata;
void* cookie;
} bt_register_callback_data_t;
static void adapter_status_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_status_cb_t ret_cb = (bt_status_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, userdata);
return;
}
ret_cb(ins, packet->adpt_r.status, userdata);
}
static void adapter_bool_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_bool_cb_t ret_cb = (bt_bool_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, 0, userdata);
return;
}
ret_cb(ins, packet->adpt_r.status, packet->adpt_r.bbool, userdata);
}
static void adapter_uint16_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_u16_cb_t ret_cb = (bt_u16_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, 0, userdata);
return;
}
ret_cb(ins, packet->adpt_r.status, packet->adpt_r.v16, userdata);
}
static void adapter_uint32_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_u32_cb_t ret_cb = (bt_u32_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, 0, userdata);
return;
}
ret_cb(ins, packet->adpt_r.status, packet->adpt_r.v32, userdata);
}
static void adapter_get_state_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_adapter_get_state_cb_t ret_cb = (bt_adapter_get_state_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, BT_ADAPTER_STATE_OFF, userdata);
return;
}
ret_cb(ins, packet->adpt_r.status, packet->adpt_r.state, userdata);
}
static void adapter_get_device_type_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_device_type_cb_t ret_cb = (bt_device_type_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, BT_DEVICE_TYPE_UNKNOW, userdata);
return;
}
ret_cb(ins, packet->adpt_r.status, packet->adpt_r.dtype, userdata);
}
static void adapter_get_address_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_address_cb_t ret_cb = (bt_address_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, NULL, userdata);
return;
}
ret_cb(ins, packet->adpt_r.status, &packet->adpt_pl._bt_adapter_get_address.addr, userdata);
}
static void adapter_get_name_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_string_cb_t ret_cb = (bt_string_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, NULL, userdata);
return;
}
ret_cb(ins, packet->adpt_r.status, packet->adpt_pl._bt_adapter_get_name.name, userdata);
}
static void adapter_get_uuids_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_uuids_cb_t ret_cb = (bt_uuids_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, NULL, 0, userdata);
return;
}
ret_cb(ins, packet->adpt_r.status, packet->adpt_pl._bt_adapter_get_uuids.uuids, packet->adpt_pl._bt_adapter_get_uuids.size, userdata);
}
static void adapter_get_scan_mode_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_adapter_get_scan_mode_cb_t ret_cb = (bt_adapter_get_scan_mode_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, BT_SCAN_MODE_NONE, userdata);
return;
}
ret_cb(ins, packet->adpt_r.status, packet->adpt_r.mode, userdata);
}
static void adapter_get_io_capability_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_adapter_get_io_capability_cb_t ret_cb = (bt_adapter_get_io_capability_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, BT_IO_CAPABILITY_UNKNOW, userdata);
return;
}
ret_cb(ins, packet->adpt_r.status, packet->adpt_r.ioc, userdata);
}
static void adapter_get_devices_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_adapter_get_devices_cb_t ret_cb = (bt_adapter_get_devices_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, NULL, 0, userdata);
return;
}
ret_cb(ins, packet->adpt_r.status, packet->adpt_pl._bt_adapter_get_bonded_devices.addr,
packet->adpt_pl._bt_adapter_get_bonded_devices.num, userdata);
}
static void adapter_get_le_address_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_adapter_get_le_address_cb_t ret_cb = (bt_adapter_get_le_address_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, NULL, BT_LE_ADDR_TYPE_UNKNOWN, userdata);
return;
}
ret_cb(ins, packet->adpt_r.status, &packet->adpt_pl._bt_adapter_get_le_address.addr,
packet->adpt_pl._bt_adapter_get_le_address.type, userdata);
}
static void adapter_register_callback_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_register_callback_data_t* data = userdata;
bt_socket_async_client_t* priv = ins->priv;
bt_status_t status;
bt_register_callback_cb_t ret_cb = (bt_register_callback_cb_t)cb;
if (!packet) {
status = BT_STATUS_UNHANDLED;
goto error;
}
if (packet->adpt_r.status != BT_STATUS_SUCCESS) {
status = packet->adpt_r.status;
goto error;
}
ret_cb(ins, packet->adpt_r.status, data->cookie, data->userdata);
free(data);
return;
error:
bt_callbacks_list_free(priv->adapter_callbacks);
priv->adapter_callbacks = NULL;
ret_cb(ins, status, data->cookie, data->userdata);
free(data);
}
bt_status_t bt_adapter_register_callback_async(bt_instance_t* ins,
const adapter_callbacks_t* adapter_cbs, bt_register_callback_cb_t cb, void* userdata)
{
bt_register_callback_data_t* data;
bt_socket_async_client_t* priv;
bt_message_packet_t packet;
bt_status_t status;
void* handle;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
BT_SOCKET_PTR_VALID(cb, BT_STATUS_PARM_INVALID);
priv = ins->priv;
if (!priv)
return BT_STATUS_IPC_ERROR;
if (priv->adapter_callbacks) {
handle = bt_remote_callbacks_register(priv->adapter_callbacks, NULL, (void*)adapter_cbs);
if (handle == NULL)
return BT_STATUS_NO_RESOURCES;
goto send_message;
}
priv->adapter_callbacks = bt_callbacks_list_new(CONFIG_BLUETOOTH_MAX_REGISTER_NUM);
if (priv->adapter_callbacks == NULL)
return BT_STATUS_NOMEM;
#ifdef CONFIG_BLUETOOTH_FEATURE
handle = bt_remote_callbacks_register(priv->adapter_callbacks, ins, (void*)adapter_cbs);
#else
handle = bt_remote_callbacks_register(priv->adapter_callbacks, NULL, (void*)adapter_cbs);
#endif
if (handle == NULL) {
bt_callbacks_list_free(priv->adapter_callbacks);
priv->adapter_callbacks = NULL;
return BT_STATUS_NO_RESOURCES;
}
send_message:
data = calloc(1, sizeof(bt_register_callback_data_t));
data->userdata = userdata;
data->cookie = handle;
status = bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_REGISTER_CALLBACK, adapter_register_callback_reply, cb, data);
if (status != BT_STATUS_SUCCESS) {
bt_callbacks_list_free(priv->adapter_callbacks);
priv->adapter_callbacks = NULL;
free(data);
return BT_STATUS_FAIL;
}
return status;
}
bt_status_t bt_adapter_unregister_callback_async(bt_instance_t* ins, void* cookie, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
bt_socket_async_client_t* priv;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
priv = ins->priv;
if (!priv || !priv->adapter_callbacks)
return BT_STATUS_IPC_ERROR;
bt_remote_callbacks_unregister(priv->adapter_callbacks, NULL, cookie);
if (bt_callbacks_list_count(priv->adapter_callbacks) > 0) {
return BT_STATUS_SUCCESS;
}
bt_callbacks_list_free(priv->adapter_callbacks);
priv->adapter_callbacks = NULL;
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_UNREGISTER_CALLBACK, adapter_bool_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_enable_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_ENABLE, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_disable_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_DISABLE, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_enable_le_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_ENABLE_LE, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_disable_le_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_DISABLE_LE, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_get_state_async(bt_instance_t* ins, bt_adapter_get_state_cb_t get_state_cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_GET_STATE, adapter_get_state_reply, (void*)get_state_cb, userdata);
}
bt_status_t bt_adapter_is_le_enabled_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_IS_LE_ENABLED, adapter_bool_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_get_type_async(bt_instance_t* ins, bt_device_type_cb_t get_dtype_cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_GET_TYPE, adapter_get_device_type_reply, (void*)get_dtype_cb, userdata);
}
bt_status_t bt_adapter_set_discovery_filter_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata)
{
return BT_STATUS_NOT_SUPPORTED;
}
bt_status_t bt_adapter_start_discovery_async(bt_instance_t* ins, uint32_t timeout, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.adpt_pl._bt_adapter_start_discovery.v32 = timeout;
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_START_DISCOVERY, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_cancel_discovery_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_CANCEL_DISCOVERY, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_is_discovering_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_IS_DISCOVERING, adapter_bool_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_get_address_async(bt_instance_t* ins, bt_address_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_GET_ADDRESS, adapter_get_address_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_set_name_async(bt_instance_t* ins, const char* name, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
if (strlen(name) > sizeof(packet.adpt_pl._bt_adapter_set_name.name))
return BT_STATUS_PARM_INVALID;
memset(packet.adpt_pl._bt_adapter_set_name.name, 0, sizeof(packet.adpt_pl._bt_adapter_set_name.name));
strncpy(packet.adpt_pl._bt_adapter_set_name.name, name, sizeof(packet.adpt_pl._bt_adapter_set_name.name) - 1);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_SET_NAME, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_get_name_async(bt_instance_t* ins, bt_string_cb_t get_name_cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_GET_NAME, adapter_get_name_reply, (void*)get_name_cb, userdata);
}
bt_status_t bt_adapter_get_uuids_async(bt_instance_t* ins, bt_uuids_cb_t get_uuids_cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_GET_UUIDS, adapter_get_uuids_reply, (void*)get_uuids_cb, userdata);
}
bt_status_t bt_adapter_set_scan_mode_async(bt_instance_t* ins, bt_scan_mode_t mode, bool bondable, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.adpt_pl._bt_adapter_set_scan_mode.mode = mode;
packet.adpt_pl._bt_adapter_set_scan_mode.bondable = bondable;
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_SET_SCAN_MODE, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_get_scan_mode_async(bt_instance_t* ins, bt_adapter_get_scan_mode_cb_t get_scan_mode_cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_GET_SCAN_MODE, adapter_get_scan_mode_reply, (void*)get_scan_mode_cb, userdata);
}
bt_status_t bt_adapter_set_device_class_async(bt_instance_t* ins, uint32_t cod, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.adpt_pl._bt_adapter_set_device_class.v32 = cod;
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_SET_DEVICE_CLASS, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_get_device_class_async(bt_instance_t* ins, bt_u32_cb_t get_cod_cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_GET_DEVICE_CLASS, adapter_uint32_reply, (void*)get_cod_cb, userdata);
}
bt_status_t bt_adapter_set_io_capability_async(bt_instance_t* ins, bt_io_capability_t cap, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.adpt_pl._bt_adapter_set_io_capability.cap = cap;
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_SET_IO_CAPABILITY, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_get_io_capability_async(bt_instance_t* ins, bt_adapter_get_io_capability_cb_t get_ioc_cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_GET_IO_CAPABILITY, adapter_get_io_capability_reply, (void*)get_ioc_cb, userdata);
}
bt_status_t bt_adapter_set_inquiry_scan_parameters_async(bt_instance_t* ins, bt_scan_type_t type,
uint16_t interval, uint16_t window, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.adpt_pl._bt_adapter_set_inquiry_scan_parameters.type = type;
packet.adpt_pl._bt_adapter_set_inquiry_scan_parameters.interval = interval;
packet.adpt_pl._bt_adapter_set_inquiry_scan_parameters.window = window;
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_SET_INQUIRY_SCAN_PARAMETERS, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_set_page_scan_parameters_async(bt_instance_t* ins, bt_scan_type_t type,
uint16_t interval, uint16_t window, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.adpt_pl._bt_adapter_set_page_scan_parameters.type = type;
packet.adpt_pl._bt_adapter_set_page_scan_parameters.interval = interval;
packet.adpt_pl._bt_adapter_set_page_scan_parameters.window = window;
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_SET_PAGE_SCAN_PARAMETERS, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_set_le_io_capability_async(bt_instance_t* ins, uint32_t le_io_cap, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.adpt_pl._bt_adapter_set_le_io_capability.v32 = le_io_cap;
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_SET_LE_IO_CAPABILITY, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_get_le_io_capability_async(bt_instance_t* ins, bt_u32_cb_t get_le_ioc_cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_GET_LE_IO_CAPABILITY, adapter_uint32_reply, (void*)get_le_ioc_cb, userdata);
}
bt_status_t bt_adapter_get_le_address_async(bt_instance_t* ins, bt_adapter_get_le_address_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_GET_LE_ADDRESS, adapter_get_le_address_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_set_le_address_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.adpt_pl._bt_adapter_set_le_address.addr, addr, sizeof(*addr));
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_SET_LE_ADDRESS, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_set_le_identity_address_async(bt_instance_t* ins, bt_address_t* addr, bool is_public, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.adpt_pl._bt_adapter_set_le_identity_address.addr, addr, sizeof(*addr));
packet.adpt_pl._bt_adapter_set_le_identity_address.pub = is_public;
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_SET_LE_IDENTITY_ADDRESS, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_set_le_appearance_async(bt_instance_t* ins, uint16_t appearance, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.adpt_pl._bt_adapter_set_le_appearance.v16 = appearance;
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_SET_LE_APPEARANCE, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_get_le_appearance_async(bt_instance_t* ins, bt_u16_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_GET_LE_APPEARANCE, adapter_uint16_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_le_enable_key_derivation_async(bt_instance_t* ins,
bool brkey_to_lekey, bool lekey_to_brkey, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.adpt_pl._bt_adapter_le_enable_key_derivation.brkey_to_lekey = brkey_to_lekey;
packet.adpt_pl._bt_adapter_le_enable_key_derivation.lekey_to_brkey = lekey_to_brkey;
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_LE_ENABLE_KEY_DERIVATION, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_le_add_whitelist_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.adpt_pl._bt_adapter_le_add_whitelist.addr, addr, sizeof(*addr));
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_LE_ADD_WHITELIST, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_le_remove_whitelist_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.adpt_pl._bt_adapter_le_remove_whitelist.addr, addr, sizeof(*addr));
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_LE_REMOVE_WHITELIST, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_get_bonded_devices_async(bt_instance_t* ins, bt_transport_t transport, bt_adapter_get_devices_cb_t get_bonded_cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.adpt_pl._bt_adapter_get_bonded_devices.transport = transport;
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_GET_BONDED_DEVICES, adapter_get_devices_reply, (void*)get_bonded_cb, userdata);
}
bt_status_t bt_adapter_get_connected_devices_async(bt_instance_t* ins, bt_transport_t transport, bt_adapter_get_devices_cb_t get_connected_cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.adpt_pl._bt_adapter_get_connected_devices.transport = transport;
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_GET_CONNECTED_DEVICES, adapter_get_devices_reply, (void*)get_connected_cb, userdata);
}
bt_status_t bt_adapter_set_afh_channel_classification_async(bt_instance_t* ins, uint16_t central_frequency,
uint16_t band_width, uint16_t number, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.adpt_pl._bt_adapter_set_afh_channel_classification.central_frequency = central_frequency;
packet.adpt_pl._bt_adapter_set_afh_channel_classification.band_width = band_width;
packet.adpt_pl._bt_adapter_set_afh_channel_classification.number = number;
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_SET_AFH_CHANNEL_CLASSFICATION, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_set_auto_sniff_async(bt_instance_t* ins, bt_auto_sniff_params_t* params, bt_status_cb_t cb, void* userdata)
{
return BT_STATUS_NOT_SUPPORTED;
}
bt_status_t bt_adapter_disconnect_all_devices_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_DISCONNECT_ALL_DEVICES, adapter_status_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_is_support_bredr_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_IS_SUPPORT_BREDR, adapter_bool_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_is_support_le_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_IS_SUPPORT_LE, adapter_bool_reply, (void*)cb, userdata);
}
bt_status_t bt_adapter_is_support_leaudio_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_ADAPTER_IS_SUPPORT_LEAUDIO, adapter_bool_reply, (void*)cb, userdata);
}

View File

@ -1,596 +0,0 @@
/****************************************************************************
* 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 <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "bluetooth.h"
#include "bt_addr.h"
#include "bt_async.h"
#include "bt_device.h"
#include "bt_message.h"
#include "bt_socket.h"
static void device_s8_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_s8_cb_t ret_cb = (bt_s8_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, 0, userdata);
return;
}
ret_cb(ins, packet->devs_r.status, (int8_t)packet->devs_r.v8, userdata);
}
static void device_status_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_status_cb_t ret_cb = (bt_status_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, userdata);
return;
}
ret_cb(ins, packet->devs_r.status, userdata);
}
static void device_bool_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_bool_cb_t ret_cb = (bt_bool_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, 0, userdata);
return;
}
ret_cb(ins, packet->devs_r.status, packet->devs_r.bbool, userdata);
}
static void device_u16_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_u16_cb_t ret_cb = (bt_u16_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, 0, userdata);
return;
}
ret_cb(ins, packet->devs_r.status, packet->devs_r.v16, userdata);
}
static void device_u32_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_u32_cb_t ret_cb = (bt_u32_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, 0, userdata);
return;
}
ret_cb(ins, packet->devs_r.status, packet->devs_r.v32, userdata);
}
static void device_get_device_type_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_device_type_cb_t ret_cb = (bt_device_type_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, BT_DEVICE_TYPE_UNKNOW, userdata);
return;
}
ret_cb(ins, packet->devs_r.status, packet->devs_r.dtype, userdata);
}
static void device_get_name_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_string_cb_t ret_cb = (bt_string_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, NULL, userdata);
return;
}
ret_cb(ins, packet->devs_r.status, packet->devs_pl._bt_device_get_name.name, userdata);
}
static void device_get_uuids_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_uuids_cb_t ret_cb = (bt_uuids_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, NULL, 0, userdata);
return;
}
ret_cb(ins, packet->devs_r.status, packet->devs_pl._bt_device_get_uuids.uuids, packet->devs_pl._bt_device_get_uuids.size, userdata);
}
static void device_get_alias_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_string_cb_t ret_cb = (bt_string_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, NULL, userdata);
return;
}
ret_cb(ins, packet->devs_r.status, packet->devs_pl._bt_device_get_alias.alias, userdata);
}
static void device_get_bond_state_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_device_get_bond_state_cb_t ret_cb = (bt_device_get_bond_state_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, BOND_STATE_NONE, userdata);
return;
}
ret_cb(ins, packet->devs_r.status, packet->devs_r.bstate, userdata);
}
static void device_get_identity_address_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_address_cb_t ret_cb = (bt_address_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, NULL, userdata);
return;
}
ret_cb(ins, packet->devs_r.status, &packet->devs_pl._bt_device_addr.addr, userdata);
}
static void device_get_address_type_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_device_get_address_type_cb_t ret_cb = (bt_device_get_address_type_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, BT_LE_ADDR_TYPE_UNKNOWN, userdata);
return;
}
ret_cb(ins, packet->devs_r.status, packet->devs_r.atype, userdata);
}
static int bt_device_send_async(bt_instance_t* ins, bt_address_t* addr,
bt_message_packet_t* packet, bt_message_type_t code, bt_socket_reply_cb_t reply, void* cb, void* userdata)
{
memcpy(&packet->devs_pl._bt_device_addr.addr, addr, sizeof(*addr));
return bt_socket_client_send_with_reply(ins, packet, code, reply, cb, userdata);
}
bt_status_t bt_device_get_identity_address_async(bt_instance_t* ins, bt_address_t* bd_addr, bt_address_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_device_send_async(ins, bd_addr, &packet, BT_DEVICE_GET_IDENTITY_ADDRESS, device_get_identity_address_reply, (void*)cb, userdata);
}
bt_status_t bt_device_get_address_type_async(bt_instance_t* ins, bt_address_t* addr, bt_device_get_address_type_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_device_send_async(ins, addr, &packet, BT_DEVICE_GET_ADDRESS_TYPE, device_get_address_type_reply, (void*)cb, userdata);
}
bt_status_t bt_device_get_device_type_async(bt_instance_t* ins, bt_address_t* addr, bt_device_type_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_device_send_async(ins, addr, &packet, BT_DEVICE_GET_DEVICE_TYPE, device_get_device_type_reply, (void*)cb, userdata);
}
bt_status_t bt_device_get_name_async(bt_instance_t* ins, bt_address_t* addr, bt_string_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_get_name.addr, addr, sizeof(*addr));
return bt_socket_client_send_with_reply(ins, &packet, BT_DEVICE_GET_NAME, device_get_name_reply, (void*)cb, userdata);
}
bt_status_t bt_device_get_device_class_async(bt_instance_t* ins, bt_address_t* addr, bt_u32_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_device_send_async(ins, addr, &packet, BT_DEVICE_GET_DEVICE_CLASS, device_u32_reply, (void*)cb, userdata);
}
bt_status_t bt_device_get_uuids_async(bt_instance_t* ins, bt_address_t* addr, bt_uuids_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_get_uuids.addr, addr, sizeof(*addr));
return bt_socket_client_send_with_reply(ins, &packet, BT_DEVICE_GET_UUIDS, device_get_uuids_reply, (void*)cb, userdata);
}
bt_status_t bt_device_get_appearance_async(bt_instance_t* ins, bt_address_t* addr, bt_u16_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_device_send_async(ins, addr, &packet, BT_DEVICE_GET_APPEARANCE, device_u16_reply, (void*)cb, userdata);
}
bt_status_t bt_device_get_rssi_async(bt_instance_t* ins, bt_address_t* addr, bt_s8_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_device_send_async(ins, addr, &packet, BT_DEVICE_GET_RSSI, device_s8_reply, (void*)cb, userdata);
}
bt_status_t bt_device_get_alias_async(bt_instance_t* ins, bt_address_t* addr, bt_string_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_get_alias.addr, addr, sizeof(*addr));
return bt_socket_client_send_with_reply(ins, &packet, BT_DEVICE_GET_ALIAS, device_get_alias_reply, cb, userdata);
}
bt_status_t bt_device_set_alias_async(bt_instance_t* ins, bt_address_t* addr,
const char* alias, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_set_alias.addr, addr, sizeof(*addr));
strncpy(packet.devs_pl._bt_device_set_alias.alias, alias,
sizeof(packet.devs_pl._bt_device_set_alias.alias) - 1);
return bt_socket_client_send_with_reply(ins, &packet, BT_DEVICE_SET_ALIAS, device_status_reply, (void*)cb, userdata);
}
bt_status_t bt_device_is_connected_async(bt_instance_t* ins, bt_address_t* addr,
bt_transport_t transport, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.devs_pl._bt_device_is_connected.transport = transport;
return bt_device_send_async(ins, addr, &packet, BT_DEVICE_IS_CONNECTED, device_bool_reply, (void*)cb, userdata);
}
bt_status_t bt_device_is_encrypted_async(bt_instance_t* ins, bt_address_t* addr,
bt_transport_t transport, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.devs_pl._bt_device_is_encrypted.transport = transport;
return bt_device_send_async(ins, addr, &packet, BT_DEVICE_IS_ENCRYPTED, device_bool_reply, (void*)cb, userdata);
}
bt_status_t bt_device_is_bond_initiate_local_async(bt_instance_t* ins, bt_address_t* addr,
bt_transport_t transport, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.devs_pl._bt_device_is_bond_initiate_local.transport = transport;
return bt_device_send_async(ins, addr, &packet, BT_DEVICE_IS_BOND_INITIATE_LOCAL, device_bool_reply, (void*)cb, userdata);
}
bt_status_t bt_device_get_bond_state_async(bt_instance_t* ins, bt_address_t* addr,
bt_transport_t transport, bt_device_get_bond_state_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.devs_pl._bt_device_get_bond_state.transport = transport;
return bt_device_send_async(ins, addr, &packet, BT_DEVICE_GET_BOND_STATE, device_get_bond_state_reply, cb, userdata);
}
bt_status_t bt_device_is_bonded_async(bt_instance_t* ins, bt_address_t* addr,
bt_transport_t transport, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.devs_pl._bt_device_is_bonded.transport = transport;
return bt_device_send_async(ins, addr, &packet, BT_DEVICE_IS_BONDED, device_bool_reply, (void*)cb, userdata);
}
bt_status_t bt_device_connect_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_device_send_async(ins, addr, &packet, BT_DEVICE_CONNECT, device_status_reply, (void*)cb, userdata);
}
bt_status_t bt_device_disconnect_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_device_send_async(ins, addr, &packet, BT_DEVICE_DISCONNECT, device_status_reply, (void*)cb, userdata);
}
bt_status_t bt_device_connect_le_async(bt_instance_t* ins,
bt_address_t* addr,
ble_addr_type_t type,
ble_connect_params_t* param, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_connect_le.addr, addr, sizeof(*addr));
packet.devs_pl._bt_device_connect_le.type = type;
memcpy(&packet.devs_pl._bt_device_connect_le.param, param, sizeof(*param));
return bt_device_send_async(ins, addr, &packet, BT_DEVICE_CONNECT_LE, device_status_reply, (void*)cb, userdata);
}
bt_status_t bt_device_disconnect_le_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_device_send_async(ins, addr, &packet, BT_DEVICE_DISCONNECT_LE, device_status_reply, (void*)cb, userdata);
}
bt_status_t bt_device_connect_request_reply_async(bt_instance_t* ins, bt_address_t* addr,
bool accept, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_connect_request_reply.addr, addr, sizeof(*addr));
packet.devs_pl._bt_device_connect_request_reply.accept = accept;
return bt_socket_client_send_with_reply(ins, &packet, BT_DEVICE_CONNECT_REQUEST_REPLY, device_status_reply, (void*)cb, userdata);
}
bt_status_t bt_device_connect_all_profile_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_device_send_async(ins, addr, &packet, BT_DEVICE_CONNECT_ALL_PROFILE, device_status_reply, (void*)cb, userdata);
}
bt_status_t bt_device_disconnect_all_profile_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_device_send_async(ins, addr, &packet, BT_DEVICE_DISCONNECT_ALL_PROFILE, device_status_reply, (void*)cb, userdata);
}
bt_status_t bt_device_set_le_phy_async(bt_instance_t* ins,
bt_address_t* addr,
ble_phy_type_t tx_phy,
ble_phy_type_t rx_phy, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_set_le_phy.addr, addr, sizeof(*addr));
packet.devs_pl._bt_device_set_le_phy.tx_phy = tx_phy;
packet.devs_pl._bt_device_set_le_phy.rx_phy = rx_phy;
return bt_socket_client_send_with_reply(ins, &packet, BT_DEVICE_SET_LE_PHY, device_status_reply, (void*)cb, userdata);
}
bt_status_t bt_device_create_bond_async(bt_instance_t* ins, bt_address_t* addr,
bt_transport_t transport, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_create_bond.addr, addr, sizeof(*addr));
packet.devs_pl._bt_device_create_bond.transport = transport;
return bt_socket_client_send_with_reply(ins, &packet, BT_DEVICE_CREATE_BOND, device_status_reply, (void*)cb, userdata);
}
bt_status_t bt_device_remove_bond_async(bt_instance_t* ins, bt_address_t* addr, uint8_t transport, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_remove_bond.addr, addr, sizeof(*addr));
packet.devs_pl._bt_device_remove_bond.transport = transport;
return bt_socket_client_send_with_reply(ins, &packet, BT_DEVICE_REMOVE_BOND, device_status_reply, (void*)cb, userdata);
}
bt_status_t bt_device_cancel_bond_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_cancel_bond.addr, addr, sizeof(*addr));
return bt_socket_client_send_with_reply(ins, &packet, BT_DEVICE_CANCEL_BOND, device_status_reply, (void*)cb, userdata);
}
bt_status_t bt_device_pair_request_reply_async(bt_instance_t* ins, bt_address_t* addr, bool accept, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_pair_request_reply.addr, addr, sizeof(*addr));
packet.devs_pl._bt_device_pair_request_reply.accept = accept;
return bt_socket_client_send_with_reply(ins, &packet, BT_DEVICE_PAIR_REQUEST_REPLY, device_status_reply, (void*)cb, userdata);
}
bt_status_t bt_device_set_pairing_confirmation_async(bt_instance_t* ins, bt_address_t* addr,
uint8_t transport, bool accept, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_set_pairing_confirmation.addr, addr, sizeof(*addr));
packet.devs_pl._bt_device_set_pairing_confirmation.transport = transport;
packet.devs_pl._bt_device_set_pairing_confirmation.accept = accept;
return bt_socket_client_send_with_reply(ins, &packet, BT_DEVICE_SET_PAIRING_CONFIRMATION, device_status_reply, (void*)cb, userdata);
}
bt_status_t bt_device_set_pin_code_async(bt_instance_t* ins, bt_address_t* addr, bool accept,
char* pincode, int len, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
if (len > sizeof(packet.devs_pl._bt_device_set_pin_code.pincode))
return BT_STATUS_PARM_INVALID;
memcpy(&packet.devs_pl._bt_device_set_pin_code.addr, addr, sizeof(*addr));
memcpy(&packet.devs_pl._bt_device_set_pin_code.pincode, pincode, len);
packet.devs_pl._bt_device_set_pin_code.len = len;
packet.devs_pl._bt_device_set_pin_code.accept = accept;
return bt_socket_client_send_with_reply(ins, &packet, BT_DEVICE_SET_PIN_CODE, device_status_reply, (void*)cb, userdata);
}
bt_status_t bt_device_set_pass_key_async(bt_instance_t* ins, bt_address_t* addr,
uint8_t transport, bool accept, uint32_t passkey, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_set_pass_key.addr, addr, sizeof(*addr));
packet.devs_pl._bt_device_set_pass_key.transport = transport;
packet.devs_pl._bt_device_set_pass_key.accept = accept;
packet.devs_pl._bt_device_set_pass_key.passkey = passkey;
return bt_socket_client_send_with_reply(ins, &packet, BT_DEVICE_SET_PASS_KEY, device_status_reply, (void*)cb, userdata);
}
bt_status_t bt_device_set_le_legacy_tk_async(bt_instance_t* ins, bt_address_t* addr,
bt_128key_t tk_val, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_set_le_legacy_tk.addr, addr, sizeof(packet.devs_pl._bt_device_set_le_legacy_tk.addr));
memcpy(packet.devs_pl._bt_device_set_le_legacy_tk.tk_val, tk_val, sizeof(packet.devs_pl._bt_device_set_le_legacy_tk.tk_val));
return bt_socket_client_send_with_reply(ins, &packet, BT_DEVICE_SET_LE_LEGACY_TK, device_status_reply, (void*)cb, userdata);
}
bt_status_t bt_device_set_le_sc_remote_oob_data_async(bt_instance_t* ins, bt_address_t* addr,
bt_128key_t c_val, bt_128key_t r_val, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_set_le_sc_remote_oob_data.addr, addr, sizeof(packet.devs_pl._bt_device_set_le_sc_remote_oob_data.addr));
memcpy(packet.devs_pl._bt_device_set_le_sc_remote_oob_data.c_val, c_val, sizeof(packet.devs_pl._bt_device_set_le_sc_remote_oob_data.c_val));
memcpy(packet.devs_pl._bt_device_set_le_sc_remote_oob_data.r_val, r_val, sizeof(packet.devs_pl._bt_device_set_le_sc_remote_oob_data.r_val));
return bt_socket_client_send_with_reply(ins, &packet, BT_DEVICE_SET_LE_SC_REMOTE_OOB_DATA, device_status_reply, (void*)cb, userdata);
}
bt_status_t bt_device_get_le_sc_local_oob_data_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_get_le_sc_local_oob_data.addr, addr, sizeof(packet.devs_pl._bt_device_get_le_sc_local_oob_data.addr));
return bt_socket_client_send_with_reply(ins, &packet, BT_DEVICE_GET_LE_SC_LOCAL_OOB_DATA, device_status_reply, (void*)cb, userdata);
}

View File

@ -1,448 +0,0 @@
/****************************************************************************
* 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.
***************************************************************************/
#define LOG_TAG "gattc"
#include <stdint.h>
#include "bt_async.h"
#include "bt_gattc.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "bt_socket.h"
#include "gattc_service.h"
#include "service_manager.h"
#include "utils/log.h"
#define CHECK_NULL_PTR(ptr) \
do { \
if (!ptr) \
return BT_STATUS_PARM_INVALID; \
} while (0)
typedef struct {
void* userdata;
void* gattc_remote;
gattc_handle_t* user_phandle;
} bt_gattc_create_connect_data_t;
static void gattc_status_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_status_cb_t ret_cb = (bt_status_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, userdata);
return;
}
ret_cb(ins, packet->gattc_r.status, userdata);
}
static void gattc_get_attribute_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_gattc_get_attribute_cb_t ret_cb = (bt_gattc_get_attribute_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, NULL, userdata);
return;
}
ret_cb(ins, packet->gattc_r.status, &packet->gattc_r.attr_desc, userdata);
}
static void gattc_create_connect_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_gattc_create_connect_data_t* data = userdata;
bt_socket_async_client_t* priv = ins->priv;
bt_gattc_create_connect_cb_t ret_cb = (bt_gattc_create_connect_cb_t)cb;
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)data->gattc_remote;
if (!packet || packet->gattc_r.status != BT_STATUS_SUCCESS)
goto error;
gattc_remote->cookie = INT2PTR(void*) packet->gattc_r.handle;
gattc_remote->user_phandle = data->user_phandle;
bt_list_add_tail(priv->gattc_remote_list, gattc_remote);
*(data->user_phandle) = gattc_remote;
ret_cb(ins, packet->gattc_r.status, data->user_phandle, data->userdata);
free(userdata);
return;
error:
if (gattc_remote) {
free(gattc_remote);
}
if (!bt_list_length(priv->gattc_remote_list)) {
bt_list_free(priv->gattc_remote_list);
priv->gattc_remote_list = NULL;
}
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, data->user_phandle, data->userdata);
free(userdata);
return;
}
ret_cb(ins, packet->gattc_r.status, data->user_phandle, data->userdata);
free(userdata);
}
static void gattc_delete_connect_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_gattc_delete_connect_cb_t ret_cb = (bt_gattc_delete_connect_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, userdata);
return;
}
ret_cb(ins, packet->gattc_r.status, userdata);
}
static void gattc_write_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_gattc_write_cb_t ret_cb = (bt_gattc_write_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, userdata);
return;
}
ret_cb(ins, packet->gattc_r.status, userdata);
}
bt_status_t bt_gattc_create_connect_async(bt_instance_t* ins, gattc_handle_t* phandle, gattc_callbacks_t* callbacks,
bt_gattc_create_connect_cb_t cb, void* userdata)
{
bt_gattc_create_connect_data_t* data = NULL;
bt_socket_async_client_t* priv;
bt_message_packet_t packet = { 0 };
bt_status_t status;
bt_gattc_remote_t* gattc_remote;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
BT_SOCKET_PTR_VALID(cb, BT_STATUS_PARM_INVALID);
priv = ins->priv;
if (!priv)
return BT_STATUS_IPC_ERROR;
if (priv->gattc_remote_list == NULL) {
priv->gattc_remote_list = bt_list_new(free);
if (priv->gattc_remote_list == NULL) {
return BT_STATUS_NOMEM;
}
}
gattc_remote = (bt_gattc_remote_t*)malloc(sizeof(bt_gattc_remote_t));
if (!gattc_remote) {
status = BT_STATUS_NOMEM;
goto fail;
}
gattc_remote->ins = ins;
gattc_remote->callbacks = callbacks;
packet.gattc_pl._bt_gattc_create.cookie = PTR2INT(uint64_t) gattc_remote;
data = calloc(1, sizeof(bt_gattc_create_connect_data_t));
data->userdata = userdata;
data->gattc_remote = (void*)gattc_remote;
data->user_phandle = phandle;
status = bt_socket_client_send_with_reply(ins, &packet, BT_GATT_CLIENT_CREATE_CONNECT, gattc_create_connect_reply, (void*)cb, data);
if (status != BT_STATUS_SUCCESS)
goto fail;
return BT_STATUS_SUCCESS;
fail:
if (gattc_remote) {
free(gattc_remote);
}
if (!bt_list_length(priv->gattc_remote_list)) {
bt_list_free(priv->gattc_remote_list);
priv->gattc_remote_list = NULL;
}
if (data)
free(data);
return status;
}
bt_status_t bt_gattc_delete_connect_async(gattc_handle_t conn_handle, bt_gattc_delete_connect_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_socket_async_client_t* priv;
bt_status_t status;
bt_instance_t* ins;
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)conn_handle;
void** user_phandle;
CHECK_NULL_PTR(gattc_remote);
priv = gattc_remote->ins->priv;
if (!priv || !priv->gattc_remote_list)
return BT_STATUS_IPC_ERROR;
ins = gattc_remote->ins;
packet.gattc_pl._bt_gattc_delete.handle = PTR2INT(uint64_t) gattc_remote->cookie;
status = bt_socket_client_send_with_reply(ins, &packet, BT_GATT_CLIENT_DELETE_CONNECT, gattc_delete_connect_reply, (void*)cb, userdata);
user_phandle = gattc_remote->user_phandle;
bt_list_remove(priv->gattc_remote_list, gattc_remote);
*user_phandle = NULL;
if (!bt_list_length(priv->gattc_remote_list)) {
bt_list_free(priv->gattc_remote_list);
priv->gattc_remote_list = NULL;
}
return status;
}
bt_status_t bt_gattc_connect_async(gattc_handle_t conn_handle, bt_address_t* addr, ble_addr_type_t addr_type, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)conn_handle;
CHECK_NULL_PTR(gattc_remote);
packet.gattc_pl._bt_gattc_connect.handle = PTR2INT(uint64_t) gattc_remote->cookie;
packet.gattc_pl._bt_gattc_connect.addr_type = addr_type;
memcpy(&packet.gattc_pl._bt_gattc_connect.addr, addr, sizeof(bt_address_t));
return bt_socket_client_send_with_reply(gattc_remote->ins, &packet, BT_GATT_CLIENT_CONNECT, gattc_status_reply, (void*)cb, userdata);
}
bt_status_t bt_gattc_disconnect_async(gattc_handle_t conn_handle, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)conn_handle;
CHECK_NULL_PTR(gattc_remote);
packet.gattc_pl._bt_gattc_disconnect.handle = PTR2INT(uint64_t) gattc_remote->cookie;
return bt_socket_client_send_with_reply(gattc_remote->ins, &packet, BT_GATT_CLIENT_DISCONNECT, gattc_status_reply, (void*)cb, userdata);
}
bt_status_t bt_gattc_discover_service_async(gattc_handle_t conn_handle, bt_uuid_t* filter_uuid, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)conn_handle;
CHECK_NULL_PTR(gattc_remote);
packet.gattc_pl._bt_gattc_discover_service.handle = PTR2INT(uint64_t) gattc_remote->cookie;
if (filter_uuid == NULL)
packet.gattc_pl._bt_gattc_discover_service.filter_uuid.type = 0;
else
memcpy(&packet.gattc_pl._bt_gattc_discover_service.filter_uuid, filter_uuid, sizeof(bt_uuid_t));
return bt_socket_client_send_with_reply(gattc_remote->ins, &packet, BT_GATT_CLIENT_DISCOVER_SERVICE, gattc_status_reply, (void*)cb, userdata);
}
bt_status_t bt_gattc_get_attribute_by_handle_async(gattc_handle_t conn_handle, uint16_t attr_handle, bt_gattc_get_attribute_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)conn_handle;
CHECK_NULL_PTR(gattc_remote);
packet.gattc_pl._bt_gattc_get_attr_by_handle.handle = PTR2INT(uint64_t) gattc_remote->cookie;
packet.gattc_pl._bt_gattc_get_attr_by_handle.attr_handle = attr_handle;
return bt_socket_client_send_with_reply(gattc_remote->ins, &packet, BT_GATT_CLIENT_GET_ATTRIBUTE_BY_HANDLE, gattc_get_attribute_reply, (void*)cb, userdata);
}
bt_status_t bt_gattc_get_attribute_by_uuid_async(gattc_handle_t conn_handle, uint16_t start_handle, uint16_t end_handle, bt_uuid_t* attr_uuid,
bt_gattc_get_attribute_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)conn_handle;
CHECK_NULL_PTR(gattc_remote);
packet.gattc_pl._bt_gattc_get_attr_by_uuid.handle = PTR2INT(uint64_t) gattc_remote->cookie;
packet.gattc_pl._bt_gattc_get_attr_by_uuid.start_handle = start_handle;
packet.gattc_pl._bt_gattc_get_attr_by_uuid.end_handle = end_handle;
memcpy(&packet.gattc_pl._bt_gattc_get_attr_by_uuid.attr_uuid, attr_uuid, sizeof(bt_uuid_t));
return bt_socket_client_send_with_reply(gattc_remote->ins, &packet, BT_GATT_CLIENT_GET_ATTRIBUTE_BY_UUID, gattc_get_attribute_reply, (void*)cb, userdata);
}
bt_status_t bt_gattc_read_async(gattc_handle_t conn_handle, uint16_t attr_handle, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)conn_handle;
CHECK_NULL_PTR(gattc_remote);
packet.gattc_pl._bt_gattc_read.handle = PTR2INT(uint64_t) gattc_remote->cookie;
packet.gattc_pl._bt_gattc_read.attr_handle = attr_handle;
return bt_socket_client_send_with_reply(gattc_remote->ins, &packet, BT_GATT_CLIENT_READ, gattc_status_reply, (void*)cb, userdata);
}
bt_status_t bt_gattc_write_async(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)conn_handle;
CHECK_NULL_PTR(gattc_remote);
if (length > sizeof(packet.gattc_pl._bt_gattc_write.value))
return BT_STATUS_PARM_INVALID;
packet.gattc_pl._bt_gattc_write.handle = PTR2INT(uint64_t) gattc_remote->cookie;
packet.gattc_pl._bt_gattc_write.attr_handle = attr_handle;
packet.gattc_pl._bt_gattc_write.length = length;
memcpy(packet.gattc_pl._bt_gattc_write.value, value, length);
return bt_socket_client_send_with_reply(gattc_remote->ins, &packet, BT_GATT_CLIENT_WRITE, gattc_status_reply, (void*)cb, userdata);
}
bt_status_t bt_gattc_write_without_response_async(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length,
bt_gattc_write_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)conn_handle;
CHECK_NULL_PTR(gattc_remote);
if (length > sizeof(packet.gattc_pl._bt_gattc_write.value))
return BT_STATUS_PARM_INVALID;
packet.gattc_pl._bt_gattc_write.handle = PTR2INT(uint64_t) gattc_remote->cookie;
packet.gattc_pl._bt_gattc_write.attr_handle = attr_handle;
packet.gattc_pl._bt_gattc_write.length = length;
memcpy(packet.gattc_pl._bt_gattc_write.value, value, length);
return bt_socket_client_send_with_reply(gattc_remote->ins, &packet, BT_GATT_CLIENT_WRITE_NR, gattc_write_reply, (void*)cb, userdata);
}
bt_status_t bt_gattc_subscribe_async(gattc_handle_t conn_handle, uint16_t attr_handle, uint16_t ccc_value, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)conn_handle;
CHECK_NULL_PTR(gattc_remote);
packet.gattc_pl._bt_gattc_subscribe.handle = PTR2INT(uint64_t) gattc_remote->cookie;
packet.gattc_pl._bt_gattc_subscribe.attr_handle = attr_handle;
packet.gattc_pl._bt_gattc_subscribe.ccc_value = ccc_value;
return bt_socket_client_send_with_reply(gattc_remote->ins, &packet, BT_GATT_CLIENT_SUBSCRIBE, gattc_status_reply, (void*)cb, userdata);
}
bt_status_t bt_gattc_unsubscribe_async(gattc_handle_t conn_handle, uint16_t attr_handle, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)conn_handle;
CHECK_NULL_PTR(gattc_remote);
packet.gattc_pl._bt_gattc_subscribe.handle = PTR2INT(uint64_t) gattc_remote->cookie;
packet.gattc_pl._bt_gattc_subscribe.attr_handle = attr_handle;
return bt_socket_client_send_with_reply(gattc_remote->ins, &packet, BT_GATT_CLIENT_UNSUBSCRIBE, gattc_status_reply, (void*)cb, userdata);
}
bt_status_t bt_gattc_exchange_mtu_async(gattc_handle_t conn_handle, uint32_t mtu, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)conn_handle;
CHECK_NULL_PTR(gattc_remote);
packet.gattc_pl._bt_gattc_exchange_mtu.handle = PTR2INT(uint64_t) gattc_remote->cookie;
packet.gattc_pl._bt_gattc_exchange_mtu.mtu = mtu;
return bt_socket_client_send_with_reply(gattc_remote->ins, &packet, BT_GATT_CLIENT_EXCHANGE_MTU, gattc_status_reply, (void*)cb, userdata);
}
bt_status_t bt_gattc_update_connection_parameter_async(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, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)conn_handle;
CHECK_NULL_PTR(gattc_remote);
packet.gattc_pl._bt_gattc_update_connection_param.handle = PTR2INT(uint64_t) gattc_remote->cookie;
packet.gattc_pl._bt_gattc_update_connection_param.min_interval = min_interval;
packet.gattc_pl._bt_gattc_update_connection_param.max_interval = max_interval;
packet.gattc_pl._bt_gattc_update_connection_param.latency = latency;
packet.gattc_pl._bt_gattc_update_connection_param.timeout = timeout;
packet.gattc_pl._bt_gattc_update_connection_param.min_connection_event_length = min_connection_event_length;
packet.gattc_pl._bt_gattc_update_connection_param.max_connection_event_length = max_connection_event_length;
return bt_socket_client_send_with_reply(gattc_remote->ins, &packet, BT_GATT_CLIENT_UPDATE_CONNECTION_PARAM, gattc_status_reply, (void*)cb, userdata);
}
bt_status_t bt_gattc_read_phy_async(gattc_handle_t conn_handle, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)conn_handle;
CHECK_NULL_PTR(gattc_remote);
packet.gattc_pl._bt_gattc_phy.handle = PTR2INT(uint64_t) gattc_remote->cookie;
return bt_socket_client_send_with_reply(gattc_remote->ins, &packet, BT_GATT_CLIENT_READ_PHY, gattc_status_reply, (void*)cb, userdata);
}
bt_status_t bt_gattc_update_phy_async(gattc_handle_t conn_handle, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)conn_handle;
CHECK_NULL_PTR(gattc_remote);
packet.gattc_pl._bt_gattc_phy.handle = PTR2INT(uint64_t) gattc_remote->cookie;
packet.gattc_pl._bt_gattc_phy.tx_phy = tx_phy;
packet.gattc_pl._bt_gattc_phy.rx_phy = rx_phy;
return bt_socket_client_send_with_reply(gattc_remote->ins, &packet, BT_GATT_CLIENT_UPDATE_PHY, gattc_status_reply, (void*)cb, userdata);
}
bt_status_t bt_gattc_read_rssi_async(gattc_handle_t conn_handle, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)conn_handle;
CHECK_NULL_PTR(gattc_remote);
packet.gattc_pl._bt_gattc_rssi.handle = PTR2INT(uint64_t) gattc_remote->cookie;
return bt_socket_client_send_with_reply(gattc_remote->ins, &packet, BT_GATT_CLIENT_READ_RSSI, gattc_status_reply, (void*)cb, userdata);
}

View File

@ -1,174 +0,0 @@
/****************************************************************************
* 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.
***************************************************************************/
#define LOG_TAG "adv"
#include <stdlib.h>
#include "advertising.h"
#include "bluetooth.h"
#include "bt_async.h"
#include "bt_le_advertiser.h"
#include "bt_list.h"
#include "bt_socket.h"
#include "utils/log.h"
typedef struct {
void* userdata;
void* adv;
} bt_le_start_advertising_data_t;
static void le_advertiser_status_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* context)
{
bt_status_cb_t ret_cb = (bt_status_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, context);
return;
}
ret_cb(ins, packet->adv_r.status, context);
}
static void le_advertiser_bool_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_bool_cb_t ret_cb = (bt_bool_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, 0, userdata);
return;
}
ret_cb(ins, packet->adv_r.status, packet->adv_r.vbool, userdata);
}
static void le_start_advertising_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_advertiser_remote_t* adv;
bt_status_t status;
bt_le_start_advertising_data_t* data = userdata;
bt_le_start_adv_callback_cb_t ret_cb = (bt_le_start_adv_callback_cb_t)cb;
adv = (bt_advertiser_remote_t*)data->adv;
if (!packet) {
status = BT_STATUS_UNHANDLED;
goto error;
}
if (!packet->adv_r.remote) {
status = packet->adv_r.status;
goto error;
} else {
adv->remote = packet->adv_r.remote;
}
ret_cb(ins, packet->adv_r.status, data->adv, data->userdata);
free(data);
return;
error:
data->adv = NULL;
free(adv);
ret_cb(ins, status, data->adv, data->userdata);
free(data);
}
bt_status_t bt_le_start_advertising_async(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* adv_cbs, bt_le_start_adv_callback_cb_t cb, void* userdata)
{
bt_le_start_advertising_data_t* context;
bt_message_packet_t packet = { 0 };
bt_status_t status;
bt_advertiser_remote_t* adv;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
BT_SOCKET_PTR_VALID(cb, BT_STATUS_PARM_INVALID);
adv = malloc(sizeof(*adv));
if (adv == NULL)
return BT_STATUS_NOMEM;
adv->ins = ins;
adv->callbacks = adv_cbs;
packet.adv_pl._bt_le_start_advertising.adver = PTR2INT(uint64_t) adv;
memcpy(&packet.adv_pl._bt_le_start_advertising.params, params, sizeof(*params));
if ((adv_len && (adv_len > sizeof(packet.adv_pl._bt_le_start_advertising.adv_data)))
|| (scan_rsp_len && (scan_rsp_len > sizeof(packet.adv_pl._bt_le_start_advertising.scan_rsp_data)))) {
free(adv);
return BT_STATUS_FAIL;
}
if (adv_len)
memcpy(packet.adv_pl._bt_le_start_advertising.adv_data, adv_data, adv_len);
packet.adv_pl._bt_le_start_advertising.adv_len = adv_len;
if (scan_rsp_len)
memcpy(packet.adv_pl._bt_le_start_advertising.scan_rsp_data, scan_rsp_data, scan_rsp_len);
packet.adv_pl._bt_le_start_advertising.scan_rsp_len = scan_rsp_len;
context = calloc(1, sizeof(bt_le_start_advertising_data_t));
context->userdata = userdata;
context->adv = (void*)adv;
status = bt_socket_client_send_with_reply(ins, &packet, BT_LE_START_ADVERTISING, le_start_advertising_reply, cb, context);
if (status != BT_STATUS_SUCCESS) {
free(adv);
free(context);
return BT_STATUS_FAIL;
}
return status;
}
bt_status_t bt_le_stop_advertising_async(bt_instance_t* ins, bt_advertiser_t* adver, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
BT_SOCKET_PTR_VALID(adver, BT_STATUS_FAIL);
packet.adv_pl._bt_le_stop_advertising.adver = (uint32_t)((bt_advertiser_remote_t*)adver)->remote;
return bt_socket_client_send_with_reply(ins, &packet, BT_LE_STOP_ADVERTISING, le_advertiser_status_reply, (void*)cb, userdata);
}
bt_status_t bt_le_stop_advertising_id_async(bt_instance_t* ins, uint8_t adv_id, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.adv_pl._bt_le_stop_advertising_id.id = adv_id;
return bt_socket_client_send_with_reply(ins, &packet, BT_LE_STOP_ADVERTISING_ID, le_advertiser_status_reply, (void*)cb, userdata);
}
bt_status_t bt_le_advertising_is_supported_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_LE_ADVERTISING_IS_SUPPORT, le_advertiser_bool_reply, (void*)cb, userdata);
}

View File

@ -1,217 +0,0 @@
/****************************************************************************
* 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.
***************************************************************************/
#define LOG_TAG "scan"
#include <stdlib.h>
#include "bluetooth.h"
#include "bt_async.h"
#include "bt_debug.h"
#include "bt_le_scan.h"
#include "bt_list.h"
#include "bt_socket.h"
#include "scan_manager.h"
#include "utils/log.h"
typedef struct {
void* userdata;
void* scan;
} bt_le_start_scan_data_t;
static void le_scan_bool_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_bool_cb_t ret_cb = (bt_bool_cb_t)cb;
if (!ret_cb)
return;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, 0, userdata);
return;
}
ret_cb(ins, packet->scan_r.status, packet->scan_r.vbool, userdata);
}
static void le_start_scan_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_scan_remote_t* scan;
bt_le_start_scan_data_t* data = userdata;
bt_le_start_scan_cb_t ret_cb = (bt_le_start_scan_cb_t)cb;
bt_status_t status;
if (!packet) {
status = BT_STATUS_UNHANDLED;
goto error;
}
scan = (bt_scan_remote_t*)data->scan;
if (!packet->scan_r.remote) {
status = BT_STATUS_FAIL;
goto error;
}
scan->remote = packet->scan_r.remote;
ret_cb(ins, packet->scan_r.status, data->scan, data->userdata);
free(data);
return;
error:
ret_cb(ins, status, NULL, data->userdata);
free(data->scan);
free(data);
}
static void le_stop_scan_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_le_stop_scan_cb_t ret_cb = (bt_le_stop_scan_cb_t)cb;
if (!ret_cb)
return;
ret_cb(ins, userdata);
}
bt_status_t bt_le_start_scan_async(bt_instance_t* ins, const scanner_callbacks_t* scan_cbs,
bt_le_start_scan_cb_t cb, void* userdata)
{
bt_le_start_scan_data_t* data;
bt_message_packet_t packet = { 0 };
bt_status_t status;
bt_scan_remote_t* scan;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
BT_SOCKET_PTR_VALID(cb, BT_STATUS_PARM_INVALID);
scan = malloc(sizeof(*scan));
if (scan == NULL)
return BT_STATUS_FAIL;
scan->ins = ins;
scan->callbacks = (scanner_callbacks_t*)scan_cbs;
packet.scan_pl._bt_le_start_scan.remote = PTR2INT(uint64_t) scan;
data = calloc(1, sizeof(bt_le_start_scan_data_t));
data->userdata = userdata;
data->scan = (void*)scan;
status = bt_socket_client_send_with_reply(ins, &packet, BT_LE_SCAN_START, le_start_scan_reply, cb, data);
if (status != BT_STATUS_SUCCESS) {
free(scan);
free(data);
return BT_STATUS_FAIL;
}
return status;
}
bt_status_t bt_le_start_scan_settings_async(bt_instance_t* ins, ble_scan_settings_t* settings,
const scanner_callbacks_t* scan_cbs, bt_le_start_scan_cb_t cb, void* userdata)
{
bt_le_start_scan_data_t* data;
bt_message_packet_t packet = { 0 };
bt_status_t status;
bt_scan_remote_t* scan;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
BT_SOCKET_PTR_VALID(cb, BT_STATUS_PARM_INVALID);
scan = malloc(sizeof(*scan));
if (scan == NULL)
return BT_STATUS_FAIL;
scan->ins = ins;
scan->callbacks = (scanner_callbacks_t*)scan_cbs;
packet.scan_pl._bt_le_start_scan_settings.remote = PTR2INT(uint64_t) scan;
if (settings)
memcpy(&packet.scan_pl._bt_le_start_scan_settings.settings, settings, sizeof(*settings));
data = calloc(1, sizeof(bt_le_start_scan_data_t));
data->userdata = userdata;
data->scan = (void*)scan;
status = bt_socket_client_send_with_reply(ins, &packet, BT_LE_SCAN_START_SETTINGS, le_start_scan_reply, cb, data);
if (status != BT_STATUS_SUCCESS) {
free(scan);
free(data);
return BT_STATUS_FAIL;
}
return status;
}
bt_status_t bt_le_start_scan_with_filters_async(bt_instance_t* ins, ble_scan_settings_t* settings,
ble_scan_filter_t* filter, const scanner_callbacks_t* scan_cbs, bt_le_start_scan_cb_t cb, void* userdata)
{
bt_le_start_scan_data_t* data;
bt_message_packet_t packet = { 0 };
bt_status_t status;
bt_scan_remote_t* scan;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
BT_SOCKET_PTR_VALID(cb, BT_STATUS_PARM_INVALID);
scan = zalloc(sizeof(*scan));
if (scan == NULL)
return BT_STATUS_FAIL;
scan->ins = ins;
scan->callbacks = (scanner_callbacks_t*)scan_cbs;
packet.scan_pl._bt_le_start_scan_with_filters.remote = PTR2INT(uint64_t) scan;
if (settings)
memcpy(&packet.scan_pl._bt_le_start_scan_with_filters.settings, settings, sizeof(*settings));
if (filter) {
memcpy(&packet.scan_pl._bt_le_start_scan_with_filters.filter, filter, sizeof(*filter));
}
data = calloc(1, sizeof(bt_le_start_scan_data_t));
data->userdata = userdata;
data->scan = (void*)scan;
status = bt_socket_client_send_with_reply(ins, &packet, BT_LE_SCAN_START_WITH_FILTERS, le_start_scan_reply, cb, data);
if (status != BT_STATUS_SUCCESS) {
free(scan);
free(data);
return BT_STATUS_FAIL;
}
return status;
}
bt_status_t bt_le_stop_scan_async(bt_instance_t* ins, bt_scanner_t* scanner, bt_le_stop_scan_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
if (!scanner)
return BT_STATUS_FAIL;
packet.scan_pl._bt_le_stop_scan.remote = ((bt_scan_remote_t*)scanner)->remote;
return bt_socket_client_send_with_reply(ins, &packet, BT_LE_SCAN_STOP, le_stop_scan_reply, (void*)cb, userdata);
}
bt_status_t bt_le_scan_is_supported_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_LE_SCAN_IS_SUPPORT, le_scan_bool_reply, (void*)cb, userdata);
}

View File

@ -1,63 +0,0 @@
/****************************************************************************
* 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_async.h"
#include "bt_message.h"
#include "bt_socket.h"
#include "bt_trace.h"
#include "utils/btsnoop_log.h"
bt_status_t bluetooth_enable_btsnoop_log_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_LOG_ENABLE, NULL, (void*)cb, userdata);
}
bt_status_t bluetooth_disable_btsnoop_log_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
return bt_socket_client_send_with_reply(ins, &packet, BT_LOG_DISABLE, NULL, (void*)cb, 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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.log_pl._bt_log_set_flag.filter_flag = filter_flag;
return bt_socket_client_send_with_reply(ins, &packet, BT_LOG_SET_FILTER, NULL, (void*)cb, 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)
{
bt_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.log_pl._bt_log_remove_flag.filter_flag = filter_flag;
return bt_socket_client_send_with_reply(ins, &packet, BT_LOG_REMOVE_FILTER, NULL, (void*)cb, userdata);
}

View File

@ -78,45 +78,6 @@ bt_instance_t* bluetooth_create_instance(void)
return ins;
}
bt_instance_t* bluetooth_create_async_instance(uv_loop_t* loop, bt_ipc_connected_cb_t connected, bt_ipc_disconnected_cb_t disconnected, void* user_data)
{
bt_status_t status;
bt_instance_t* ins;
ins = zalloc(sizeof(bt_instance_t));
if (ins == NULL) {
return NULL;
}
#if defined(CONFIG_BLUETOOTH_SERVER)
status = bt_socket_async_client_init(ins, loop, PF_LOCAL,
"bluetooth", NULL, CONFIG_BLUETOOTH_SOCKET_PORT, connected, disconnected, user_data);
#elif defined(CONFIG_NET_RPMSG)
status = bt_socket_async_client_init(ins, loop, AF_RPMSG,
"bluetooth", CONFIG_BLUETOOTH_RPMSG_CPUNAME, CONFIG_BLUETOOTH_SOCKET_PORT, connected, disconnected, user_data);
#elif defined(CONFIG_NET_IPv4)
status = bt_socket_async_client_init(ins, loop, AF_INET,
"bluetooth", NULL, CONFIG_BLUETOOTH_SOCKET_PORT, connected, disconnected, user_data);
#else
status = bt_socket_async_client_init(ins, loop, PF_LOCAL,
"bluetooth", NULL, CONFIG_BLUETOOTH_SOCKET_PORT, connected, disconnected, user_data);
#endif
if (status != BT_STATUS_SUCCESS) {
free(ins);
return NULL;
}
status = manager_create_instance(PTR2INT(uint64_t) ins, BLUETOOTH_SYSTEM,
"local", getpid(), 0, &ins->app_id);
if (status != BT_STATUS_SUCCESS) {
bt_socket_client_deinit(ins);
free(ins);
ins = NULL;
}
return ins;
}
bt_instance_t* bluetooth_find_instance(pid_t pid)
{
bt_status_t status;
@ -153,15 +114,6 @@ void bluetooth_delete_instance(bt_instance_t* ins)
free(ins);
}
void bluetooth_delete_async_instance(bt_instance_t* ins)
{
BT_SOCKET_INS_VALID(ins, );
manager_delete_instance(ins->app_id);
bt_socket_async_client_deinit(ins);
free(ins);
}
bt_status_t bluetooth_start_service(bt_instance_t* ins, enum profile_id id)
{
bt_status_t status;

View File

@ -460,23 +460,6 @@ bt_status_t bt_adapter_set_page_scan_parameters(bt_instance_t* ins, bt_scan_type
return packet.adpt_r.status;
}
bt_status_t bt_adapter_set_debug_mode(bt_instance_t* ins, bt_debug_mode_t mode, uint8_t operation)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.adpt_pl._bt_adapter_set_debug_mode.mode = mode;
packet.adpt_pl._bt_adapter_set_debug_mode.operation = operation;
status = bt_socket_client_sendrecv(ins, &packet, BT_ADAPTER_SET_DEBUG_MODE);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.adpt_r.status;
}
bt_status_t bt_adapter_set_le_io_capability(bt_instance_t* ins, uint32_t le_io_cap)
{
bt_message_packet_t packet;
@ -771,24 +754,3 @@ bool bt_adapter_is_support_leaudio(bt_instance_t* ins)
return packet.adpt_r.bbool;
}
bt_status_t bt_adapter_start_limited_discovery(bt_instance_t* ins, uint32_t timeout)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.adpt_pl._bt_adapter_start_limited_discovery.v32 = timeout;
status = bt_socket_client_sendrecv(ins, &packet, BT_ADAPTER_START_LIMITED_DISCOVERY);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.adpt_r.status;
}
bt_status_t bt_adapter_disable_safe(bt_instance_t* ins)
{
return bt_adapter_disable(ins);
}

View File

@ -1,120 +0,0 @@
/****************************************************************************
* 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 "avrcp_control_api"
#include <stdint.h>
#include "bt_avrcp_control.h"
#include "bt_socket.h"
void* bt_avrcp_control_register_callbacks(bt_instance_t* ins, const avrcp_control_callbacks_t* callbacks)
{
bt_message_packet_t packet;
bt_status_t status;
void* handle;
BT_SOCKET_INS_VALID(ins, NULL);
if (ins->avrcp_control_callbacks != NULL) {
handle = bt_remote_callbacks_register(ins->avrcp_control_callbacks, NULL, (void*)callbacks);
return handle;
}
ins->avrcp_control_callbacks = bt_callbacks_list_new(CONFIG_BLUETOOTH_MAX_REGISTER_NUM);
#ifdef CONFIG_BLUETOOTH_FEATURE
handle = bt_remote_callbacks_register(ins->avrcp_control_callbacks, ins, (void*)callbacks);
#else
handle = bt_remote_callbacks_register(ins->avrcp_control_callbacks, NULL, (void*)callbacks);
#endif
if (handle == NULL) {
bt_callbacks_list_free(ins->avrcp_control_callbacks);
ins->avrcp_control_callbacks = NULL;
return handle;
}
status = bt_socket_client_sendrecv(ins, &packet, BT_AVRCP_CONTROL_REGISTER_CALLBACKS);
if (status != BT_STATUS_SUCCESS || packet.avrcp_control_r.status != BT_STATUS_SUCCESS) {
bt_callbacks_list_free(ins->avrcp_control_callbacks);
ins->avrcp_control_callbacks = NULL;
return NULL;
}
return handle;
}
bool bt_avrcp_control_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
bt_message_packet_t packet;
bt_status_t status;
callbacks_list_t* cbsl;
BT_SOCKET_INS_VALID(ins, false);
if (!ins->avrcp_control_callbacks)
return false;
bt_remote_callbacks_unregister(ins->avrcp_control_callbacks, NULL, cookie);
if (bt_callbacks_list_count(ins->avrcp_control_callbacks) > 0) {
return true;
}
cbsl = ins->avrcp_control_callbacks;
ins->avrcp_control_callbacks = NULL;
bt_socket_client_free_callbacks(ins, cbsl);
status = bt_socket_client_sendrecv(ins, &packet, BT_AVRCP_CONTROL_UNREGISTER_CALLBACKS);
if (status != BT_STATUS_SUCCESS || packet.avrcp_control_r.status != BT_STATUS_SUCCESS) {
return false;
}
return true;
}
bt_status_t bt_avrcp_control_get_element_attributes(bt_instance_t* ins, bt_address_t* addr)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.avrcp_control_pl._bt_avrcp_control_get_element_attribute.addr, addr, sizeof(packet.avrcp_control_pl._bt_avrcp_control_get_element_attribute.addr));
status = bt_socket_client_sendrecv(ins, &packet, BT_AVRCP_CONTROL_GET_ELEMENT_ATTRIBUTES);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.avrcp_control_r.status;
}
bt_status_t bt_avrcp_control_send_passthrough_cmd(bt_instance_t* ins, bt_address_t* addr, uint8_t cmd, uint8_t state)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.avrcp_control_pl._bt_avrcp_control_send_passthrough_cmd.addr, addr, sizeof(packet.avrcp_control_pl._bt_avrcp_control_send_passthrough_cmd.addr));
packet.avrcp_control_pl._bt_avrcp_control_send_passthrough_cmd.cmd = cmd;
packet.avrcp_control_pl._bt_avrcp_control_send_passthrough_cmd.state = state;
status = bt_socket_client_sendrecv(ins, &packet, BT_AVRCP_CT_SEND_PASSTHROUGH_CMD);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.avrcp_control_r.status;
}

View File

@ -1,146 +0,0 @@
/****************************************************************************
* 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_cs.h"
#include "bt_message.h"
#include "bt_socket.h"
#include <stdint.h>
void* bt_cs_register_callbacks(bt_instance_t* ins, const cs_callbacks_t* callbacks)
{
bt_message_packet_t packet;
bt_status_t status;
void* cookie;
BT_SOCKET_INS_VALID(ins, NULL);
if (ins->cs_callbacks != NULL) {
cookie = bt_remote_callbacks_register(ins->cs_callbacks, NULL, (void*)callbacks);
return cookie;
}
ins->cs_callbacks = bt_callbacks_list_new(CONFIG_BLUETOOTH_MAX_REGISTER_NUM);
cookie = bt_remote_callbacks_register(ins->cs_callbacks, NULL, (void*)callbacks);
if (cookie == NULL) {
bt_callbacks_list_free(ins->cs_callbacks);
ins->cs_callbacks = NULL;
return cookie;
}
status = bt_socket_client_sendrecv(ins, &packet, BT_CS_REGISTER_CALLBACKS);
if (status != BT_STATUS_SUCCESS || packet.cs_r.status != BT_STATUS_SUCCESS) {
bt_callbacks_list_free(ins->cs_callbacks);
ins->cs_callbacks = NULL;
return NULL;
}
return cookie;
}
bool bt_cs_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, false);
if (!ins->cs_callbacks)
return false;
bt_remote_callbacks_unregister(ins->cs_callbacks, NULL, cookie);
if (bt_callbacks_list_count(ins->cs_callbacks) > 0) {
return true;
}
bt_callbacks_list_free(ins->cs_callbacks);
ins->cs_callbacks = NULL;
status = bt_socket_client_sendrecv(ins, &packet, BT_CS_UNREGISTER_CALLBACKS);
if (status != BT_STATUS_SUCCESS || packet.cs_r.status != BT_STATUS_SUCCESS) {
return false;
}
return true;
}
bt_status_t bt_cs_start_distance_measurement(bt_instance_t* ins, const bt_distance_measurement_params_t* params)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.cs_pl._bt_cs_start_distance_measurement.params, params, sizeof(bt_distance_measurement_params_t));
status = bt_socket_client_sendrecv(ins, &packet, BT_CS_START_DISTANCE_MEASUREMENT);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.cs_r.status;
}
bt_status_t bt_cs_stop_distance_measurement(bt_instance_t* ins, bt_address_t* addr, uint8_t method, bool timeout)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.cs_pl._bt_cs_stop_distance_measurement.addr, addr, sizeof(packet.cs_pl._bt_cs_stop_distance_measurement.addr));
packet.cs_pl._bt_cs_stop_distance_measurement.method = method;
packet.cs_pl._bt_cs_stop_distance_measurement.timeout_bool = timeout;
status = bt_socket_client_sendrecv(ins, &packet, BT_CS_STOP_DISTANCE_MEASUREMENT);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.cs_r.status;
}
bt_status_t bt_cs_set_config(bt_instance_t* ins, bt_address_t* addr, const bt_cs_set_params_t* params)
{
bt_message_packet_t packet = { 0 };
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
if (addr)
memcpy(&packet.cs_pl._bt_cs_set_config.addr, addr, sizeof(bt_address_t));
memcpy(&packet.cs_pl._bt_cs_set_config.params, params, sizeof(bt_cs_set_params_t));
status = bt_socket_client_sendrecv(ins, &packet, BT_CS_SET_CONFIG);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.cs_r.status;
}
#ifdef CONFIG_BT_CS_RAS_TEST
bt_status_t bt_cs_test(bt_instance_t* ins, const void* data, uint16_t len)
{
bt_message_packet_t packet = { 0 };
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
if (data) {
memcpy(&packet.cs_pl._bt_cs_test.data, data, len);
}
packet.cs_pl._bt_cs_test.len = len;
status = bt_socket_client_sendrecv(ins, &packet, BT_CS_TEST);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.cs_r.status;
}
#endif /* CONFIG_BT_CS_RAS_TEST */

View File

@ -26,7 +26,7 @@
#include "device.h"
static int bt_device_send(bt_instance_t* ins, bt_address_t* addr,
bt_message_packet_t* packet, uint32_t code)
bt_message_packet_t* packet, bt_message_type_t code)
{
memcpy(&packet->devs_pl._bt_device_addr.addr, addr, sizeof(*addr));
@ -388,39 +388,6 @@ bt_status_t bt_device_set_le_phy(bt_instance_t* ins,
return packet.devs_r.status;
}
bt_status_t bt_device_set_bondable_le(bt_instance_t* ins, bool bondable)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.devs_pl._bt_device_set_bondable_le.accept = bondable;
status = bt_socket_client_sendrecv(ins, &packet, BT_DEVICE_SET_BONDABLE_LE);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.devs_r.status;
}
bt_status_t bt_device_set_security_level(bt_instance_t* ins, uint8_t level, bt_transport_t transport)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.devs_pl._bt_device_set_security_level.level = level;
packet.devs_pl._bt_device_set_security_level.transport = transport;
status = bt_socket_client_sendrecv(ins, &packet, BT_DEVICE_SET_SECURITY_LEVEL);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.devs_r.status;
}
bt_status_t bt_device_create_bond(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
bt_message_packet_t packet;
@ -540,7 +507,7 @@ bt_status_t bt_device_set_pass_key(bt_instance_t* ins, bt_address_t* addr, uint8
return packet.devs_r.status;
}
bt_status_t bt_device_set_le_legacy_tk(bt_instance_t* ins, bt_address_t* addr, bt_128key_t tk_val)
bt_status_t BTSYMBOLS(bt_device_set_le_legacy_tk)(bt_instance_t* ins, bt_address_t* addr, bt_128key_t tk_val)
{
bt_message_packet_t packet;
bt_status_t status;
@ -587,14 +554,4 @@ bt_status_t bt_device_get_le_sc_local_oob_data(bt_instance_t* ins, bt_address_t*
}
return packet.devs_r.status;
}
bt_status_t bt_device_enable_enhanced_mode(bt_instance_t* ins, bt_address_t* addr, bt_enhanced_mode_t mode)
{
return BT_STATUS_NOT_SUPPORTED;
}
bt_status_t bt_device_disable_enhanced_mode(bt_instance_t* ins, bt_address_t* addr, bt_enhanced_mode_t mode)
{
return BT_STATUS_NOT_SUPPORTED;
}

View File

@ -159,25 +159,6 @@ bt_status_t bt_gatts_connect(gatts_handle_t srv_handle, bt_address_t* addr, ble_
return packet.gatts_r.status;
}
bt_status_t bt_gatts_connect_bear(gatts_handle_t srv_handle, bt_address_t* addr, ble_addr_type_t addr_type, uint8_t bear_type)
{
bt_message_packet_t packet;
bt_status_t status;
bt_gatts_remote_t* gatts_remote = (bt_gatts_remote_t*)srv_handle;
CHECK_NULL_PTR(gatts_remote);
packet.gatts_pl._bt_gatts_connect_bear.handle = PTR2INT(uint64_t) gatts_remote->cookie;
packet.gatts_pl._bt_gatts_connect_bear.addr_type = addr_type;
packet.gatts_pl._bt_gatts_connect_bear.bear_type = bear_type;
memcpy(&packet.gatts_pl._bt_gatts_connect_bear.addr, addr, sizeof(bt_address_t));
status = bt_socket_client_sendrecv(gatts_remote->ins, &packet, BT_GATT_SERVER_CONNECT_BEAR);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.gatts_r.status;
}
bt_status_t bt_gatts_disconnect(gatts_handle_t srv_handle, bt_address_t* addr)
{
bt_message_packet_t packet;

View File

@ -326,73 +326,3 @@ bt_status_t bt_hfp_ag_send_at_command(bt_instance_t* ins, bt_address_t* addr, co
return packet.hfp_ag_r.status;
}
bt_status_t bt_hfp_ag_send_vendor_specific_at_command(bt_instance_t* ins, bt_address_t* addr, const char* command, const char* value)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.hfp_ag_pl._bt_hfp_ag_send_vendor_specific_at_cmd.addr, addr, sizeof(bt_address_t));
strlcpy(packet.hfp_ag_pl._bt_hfp_ag_send_vendor_specific_at_cmd.cmd, command, sizeof(packet.hfp_ag_pl._bt_hfp_ag_send_vendor_specific_at_cmd.cmd));
strlcpy(packet.hfp_ag_pl._bt_hfp_ag_send_vendor_specific_at_cmd.value, value, sizeof(packet.hfp_ag_pl._bt_hfp_ag_send_vendor_specific_at_cmd.value));
status = bt_socket_client_sendrecv(ins, &packet, BT_HFP_AG_SEND_VENDOR_SPECIFIC_AT_COMMAND);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.hfp_ag_r.status;
}
bt_status_t 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 state, hfp_call_mode_t mode,
hfp_call_mpty_type_t mpty, hfp_call_addrtype_t type, const char* number)
{
bt_message_packet_t packet = { 0 };
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.hfp_ag_pl._bt_hfp_ag_send_clcc_response.addr, addr, sizeof(bt_address_t));
packet.hfp_ag_pl._bt_hfp_ag_send_clcc_response.index = index;
packet.hfp_ag_pl._bt_hfp_ag_send_clcc_response.dir = dir;
packet.hfp_ag_pl._bt_hfp_ag_send_clcc_response.state = state;
packet.hfp_ag_pl._bt_hfp_ag_send_clcc_response.mode = mode;
packet.hfp_ag_pl._bt_hfp_ag_send_clcc_response.mpty = mpty;
packet.hfp_ag_pl._bt_hfp_ag_send_clcc_response.type = type;
if (number) {
strlcpy(packet.hfp_ag_pl._bt_hfp_ag_send_clcc_response.number, number, sizeof(packet.hfp_ag_pl._bt_hfp_ag_send_clcc_response.number));
}
status = bt_socket_client_sendrecv(ins, &packet, BT_HFP_AG_SEND_CLCC_RESPONSE);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.hfp_ag_r.status;
}
bt_status_t 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)
{
bt_message_packet_t packet = { 0 };
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.hfp_ag_pl._bt_hfp_ag_send_cind_response.addr, addr, sizeof(bt_address_t));
packet.hfp_ag_pl._bt_hfp_ag_send_cind_response.network = network;
packet.hfp_ag_pl._bt_hfp_ag_send_cind_response.call = call;
packet.hfp_ag_pl._bt_hfp_ag_send_cind_response.call_held = call_held;
packet.hfp_ag_pl._bt_hfp_ag_send_cind_response.call_setup = call_setup;
packet.hfp_ag_pl._bt_hfp_ag_send_cind_response.signal = signal;
packet.hfp_ag_pl._bt_hfp_ag_send_cind_response.roam = roam;
packet.hfp_ag_pl._bt_hfp_ag_send_cind_response.battery = battery;
status = bt_socket_client_sendrecv(ins, &packet, BT_HFP_AG_SEND_CIND_RESPONSE);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.hfp_ag_r.status;
}

View File

@ -42,7 +42,7 @@ bt_advertiser_t* bt_le_start_advertising(bt_instance_t* ins,
if (adv == NULL)
return NULL;
adv->callbacks = cbs;
adv->callback = cbs;
packet.adv_pl._bt_le_start_advertising.adver = PTR2INT(uint64_t) adv;
memcpy(&packet.adv_pl._bt_le_start_advertising.params, params, sizeof(*params));
if ((adv_len && (adv_len > sizeof(packet.adv_pl._bt_le_start_advertising.adv_data)))

View File

@ -36,7 +36,7 @@ bt_scanner_t* bt_le_start_scan(bt_instance_t* ins, const scanner_callbacks_t* cb
if (scan == NULL)
return NULL;
scan->callbacks = (scanner_callbacks_t*)cbs;
scan->callback = (scanner_callbacks_t*)cbs;
packet.scan_pl._bt_le_start_scan.remote = PTR2INT(uint64_t) scan;
status = bt_socket_client_sendrecv(ins, &packet, BT_LE_SCAN_START);
@ -62,7 +62,7 @@ bt_scanner_t* bt_le_start_scan_settings(bt_instance_t* ins,
if (scan == NULL)
return NULL;
scan->callbacks = (scanner_callbacks_t*)cbs;
scan->callback = (scanner_callbacks_t*)cbs;
packet.scan_pl._bt_le_start_scan_settings.remote = PTR2INT(uint64_t) scan;
if (settings)
memcpy(&packet.scan_pl._bt_le_start_scan_settings.settings, settings, sizeof(*settings));
@ -91,7 +91,7 @@ bt_scanner_t* bt_le_start_scan_with_filters(bt_instance_t* ins,
if (scan == NULL)
return NULL;
scan->callbacks = (scanner_callbacks_t*)cbs;
scan->callback = (scanner_callbacks_t*)cbs;
packet.scan_pl._bt_le_start_scan_with_filters.remote = PTR2INT(uint64_t) scan;
if (settings)
memcpy(&packet.scan_pl._bt_le_start_scan_with_filters.settings, settings, sizeof(*settings));

View File

@ -24,7 +24,7 @@
#include "spp_service.h"
#include "utils/log.h"
void* bt_spp_register_app_with_name(bt_instance_t* ins, const char* name, const spp_callbacks_t* callbacks)
void* bt_spp_register_app_ext(bt_instance_t* ins, const char* name, int port_type, const spp_callbacks_t* callbacks)
{
bt_message_packet_t packet = { 0 };
bt_status_t status;
@ -51,6 +51,7 @@ void* bt_spp_register_app_with_name(bt_instance_t* ins, const char* name, const
} else
packet.spp_pl._bt_spp_register_app.name_len = 0;
packet.spp_pl._bt_spp_register_app.port_type = port_type;
status = bt_socket_client_sendrecv(ins, &packet, BT_SPP_REGISTER_APP);
if (status != BT_STATUS_SUCCESS || !packet.spp_r.handle) {
bt_callbacks_list_free(ins->spp_callbacks);
@ -63,12 +64,7 @@ void* bt_spp_register_app_with_name(bt_instance_t* ins, const char* name, const
void* bt_spp_register_app(bt_instance_t* ins, const spp_callbacks_t* callbacks)
{
return bt_spp_register_app_with_name(ins, NULL, callbacks);
}
void* bt_spp_register_app_ext(bt_instance_t* ins, const char* name, int port_type, const spp_callbacks_t* callbacks)
{
return bt_spp_register_app_with_name(ins, NULL, callbacks);
return bt_spp_register_app_ext(ins, NULL, SPP_PORT_TYPE_TTY, callbacks);
}
bt_status_t bt_spp_unregister_app(bt_instance_t* ins, void* handle)
@ -138,29 +134,6 @@ bt_status_t bt_spp_connect(bt_instance_t* ins, void* handle, bt_address_t* addr,
memcpy(&packet.spp_pl._bt_spp_connect.addr, addr, sizeof(*addr));
packet.spp_pl._bt_spp_connect.scn = scn;
packet.spp_pl._bt_spp_connect.insecure = 0;
memcpy(&packet.spp_pl._bt_spp_connect.uuid, uuid, sizeof(*uuid));
status = bt_socket_client_sendrecv(ins, &packet, BT_SPP_CONNECT);
if (status != BT_STATUS_SUCCESS || packet.spp_r.status != BT_STATUS_SUCCESS) {
return packet.spp_r.status;
}
*port = packet.spp_pl._bt_spp_connect.port;
return BT_STATUS_SUCCESS;
}
bt_status_t bt_spp_insecure_connect(bt_instance_t* ins, void* handle, bt_address_t* addr, int16_t scn, bt_uuid_t* uuid, uint16_t* port)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.spp_pl._bt_spp_connect.addr, addr, sizeof(*addr));
packet.spp_pl._bt_spp_connect.scn = scn;
packet.spp_pl._bt_spp_connect.insecure = 1;
memcpy(&packet.spp_pl._bt_spp_connect.uuid, uuid, sizeof(*uuid));
status = bt_socket_client_sendrecv(ins, &packet, BT_SPP_CONNECT);

View File

@ -1,58 +0,0 @@
/****************************************************************************
* 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 "bt_message.h"
#include "bt_socket.h"
#include "utils/btsnoop_log.h"
void bluetooth_enable_btsnoop_log(bt_instance_t* ins)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, );
(void)bt_socket_client_sendrecv(ins, &packet, BT_LOG_ENABLE);
}
void bluetooth_disable_btsnoop_log(bt_instance_t* ins)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, );
(void)bt_socket_client_sendrecv(ins, &packet, BT_LOG_DISABLE);
}
void bluetooth_set_btsnoop_filter(bt_instance_t* ins, btsnoop_filter_flag_t filter_flag)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, );
packet.log_pl._bt_log_set_flag.filter_flag = filter_flag;
(void)bt_socket_client_sendrecv(ins, &packet, BT_LOG_SET_FILTER);
}
void bluetooth_remove_btsnoop_filter(bt_instance_t* ins, btsnoop_filter_flag_t filter_flag)
{
bt_message_packet_t packet;
BT_SOCKET_INS_VALID(ins, );
packet.log_pl._bt_log_remove_flag.filter_flag = filter_flag;
(void)bt_socket_client_sendrecv(ins, &packet, BT_LOG_REMOVE_FILTER);
}

View File

@ -1,41 +0,0 @@
package frameworkBluetooth
import (
"android/soong/android"
"android/soong/cc"
)
func init() {
android.RegisterModuleType("frameworkBluetooth_cc_binary", frameworkBluetoothBinDefaultsFactory)
}
func frameworkBluetoothBinDefaultsFactory() (android.Module) {
module := cc.BinaryFactory()
android.AddLoadHook(module, frameworkBluetoothBinHook)
return module
}
func frameworkBluetoothBinHook(ctx android.LoadHookContext) {
//AConfig() function is at build/soong/android/config.go
Version := ctx.AConfig().PlatformVersionName()
type props struct {
Srcs []string
Static_libs []string
Shared_libs []string
Cflags []string
}
p := &props{}
if (Version == "12") {
p.Cflags = append(p.Cflags, "-DANDROID_12")
} else if (Version == "14") {
p.Cflags = append(p.Cflags, "-DANDROID_14")
} else if (Version == "15") {
p.Cflags = append(p.Cflags, "-DANDROID_15")
}
ctx.AppendProperties(p)
}

View File

@ -1,353 +0,0 @@
/****************************************************************************
* 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 <stdlib.h>
#include "acceptbond.h"
static bt_instance_t* g_bt_ins = NULL;
static void* adapter_callback = NULL;
static app_demo_t app_demo;
/**
* @brief Block the current thread and wait to be woken up.
*/
static void wait_awakened(void)
{
sem_wait(&app_demo.sem);
}
/**
* @brief Wake up the main thread of the app.
*/
static void wakeup_thread(void)
{
sem_post(&app_demo.sem);
}
/**
* @brief Add a node to the message queue.
*/
static void app_list_add_tail(struct list_node* node)
{
pthread_mutex_lock(&app_demo.mutex);
list_add_tail(&app_demo.message_queue, node);
pthread_mutex_unlock(&app_demo.mutex);
wakeup_thread();
}
/**
* @brief Remove the head node of the message queue.
*/
static node_t* app_list_remove_head(void)
{
node_t* node_data;
wait_awakened();
pthread_mutex_lock(&app_demo.mutex);
struct list_node* node = list_remove_head(&app_demo.message_queue);
pthread_mutex_unlock(&app_demo.mutex);
if (node == NULL) {
return NULL;
}
node_data = list_entry(node, node_t, node);
return node_data;
}
/**
* @brief Set the scanning mode to make the device locally connectable and discoverable.
*/
static void app_bt_set_scan_mode(bt_scan_mode_t mode, bool bondable)
{
node_t* node = (node_t*)malloc(sizeof(node_t));
if (node == NULL) {
LOGE("malloc failed.");
return;
}
node->data.msg_type = APP_BT_GAP_SET_SCANMODE;
node->data.gap_req._bt_adapter_set_scan_mode.mode = mode;
node->data.gap_req._bt_adapter_set_scan_mode.bondable = bondable;
app_list_add_tail(&node->node);
}
/**
* @brief Set io capability to NOINPUTNOOUTPUT.
*/
static void app_bt_set_io_capability(bt_io_capability_t capability)
{
node_t* node = (node_t*)malloc(sizeof(node_t));
if (node == NULL) {
LOGE("malloc failed.");
return;
}
node->data.msg_type = APP_BT_GAP_SET_IO_CAPABILITY;
node->data.gap_req._bt_adapter_set_io_capability.cap = capability;
app_list_add_tail(&node->node);
}
static void app_bt_get_local_name()
{
node_t* node = (node_t*)malloc(sizeof(node_t));
if (node == NULL) {
LOGE("malloc failed.");
return;
}
node->data.msg_type = APP_BT_GAP_GET_NAME;
app_list_add_tail(&node->node);
}
static void app_bt_gap_init(void)
{
app_bt_set_io_capability(BT_IO_CAPABILITY_NOINPUTNOOUTPUT);
app_bt_get_local_name();
app_bt_set_scan_mode(BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE, true);
}
/**
* @brief Adapter state change callback.
*
* This function is executed in the bt_client thread, the app needs to handle the callback
* in another thread.
*/
static void gap_adapter_state_changed_callback(void* cookie, bt_adapter_state_t state)
{
node_t* node = (node_t*)malloc(sizeof(node_t));
if (node == NULL) {
LOGE("malloc failed.");
return;
}
node->data.msg_type = APP_BT_GAP_ON_GAP_STATE_CHANGED;
node->data.gap_cb._on_adapter_state_changed.state = state;
app_list_add_tail(&node->node);
if (state == BT_ADAPTER_STATE_ON) {
app_bt_gap_init();
} else if (state == BT_ADAPTER_STATE_OFF) {
app_demo.running = 0;
}
}
/**
* @brief Connection request callback.
*
* This function is executed in the bt_client thread, the app needs to handle the callback
* in another thread.
*/
static void gap_connection_request_callback(void* cookie, bt_address_t* addr)
{
node_t* node = (node_t*)malloc(sizeof(node_t));
if (node == NULL) {
LOGE("malloc failed.");
return;
}
node->data.msg_type = APP_BT_GAP_CONNECT_REQUEST_REPLY;
memcpy(&node->data.gap_req._bt_device_connect_request_reply.addr, addr, sizeof(bt_address_t));
node->data.gap_req._bt_device_connect_request_reply.accept = true;
app_list_add_tail(&node->node);
}
/**
* @brief Connection state change callback.
*
* This function is executed in the bt_client thread, the app needs to handle the callback
* in another thread.
*/
static void gap_connection_state_changed_callback(void* cookie, bt_address_t* addr, bt_transport_t transport, connection_state_t state)
{
node_t* node = (node_t*)malloc(sizeof(node_t));
if (node == NULL) {
LOGE("malloc failed.");
return;
}
node->data.msg_type = APP_BT_GAP_ON_CONNECTION_STATE_CHANGED;
node->data.gap_cb._on_connection_state_changed.state = state;
node->data.gap_cb._on_connection_state_changed.transport = transport;
memcpy(&node->data.gap_cb._on_connection_state_changed.addr, addr, sizeof(bt_address_t));
app_list_add_tail(&node->node);
}
/**
* @brief Bond state change callback.
*
* This function is executed in the bt_client thread, the app needs to handle the callback
* in another thread.
*/
static void gap_bond_state_changed_callback(void* cookie, bt_address_t* addr, bt_transport_t transport, bond_state_t state, bool is_ctkd)
{
node_t* node = (node_t*)malloc(sizeof(node_t));
if (node == NULL) {
LOGE("malloc failed.");
return;
}
node->data.msg_type = APP_BT_GAP_ON_BOND_STATE_CHANGED;
node->data.gap_cb._on_bond_state_changed.state = state;
node->data.gap_cb._on_bond_state_changed.transport = transport;
node->data.gap_cb._on_bond_state_changed.is_ctkd = is_ctkd;
memcpy(&node->data.gap_cb._on_bond_state_changed.addr, addr, sizeof(bt_address_t));
app_list_add_tail(&node->node);
}
// gap callback
const static adapter_callbacks_t app_gap_cbs = {
.on_adapter_state_changed = gap_adapter_state_changed_callback,
.on_connection_state_changed = gap_connection_state_changed_callback,
.on_connect_request = gap_connection_request_callback,
.on_bond_state_changed = gap_bond_state_changed_callback,
};
/**
* @brief Initialize semaphore, mutex, message queue.
*
* @note Semaphores are used to control the number of concurrently executing threads.
* A semaphore has a counter, and threads need to acquire the semaphore before
* accessing a resource. When the semaphore counter is greater than 0, the thread
* can continue executing. When the semaphore counter is equal to 0, the thread
* needs to wait for other threads to release resources so that the semaphore
* counter can increase before it can continue executing.
*
* @note Mutex locks are used to protect shared resources, ensuring that only one thread
* can access the shared resource at a time, while other threads must wait until
* the lock is released by that thread before they can access it.
*
* @note Message queues is used to store events to be processed. When calling the Bluetooth
* synchronization interface, receiving and sending Bluetooth messages from the Bluetooth
* module should be done in different threads.
*/
static void app_demo_init(void)
{
app_demo.running = 1;
sem_init(&app_demo.sem, 0, 1);
pthread_mutex_init(&app_demo.mutex, NULL);
list_initialize(&app_demo.message_queue);
}
/**
* @brief Destroy semaphore, mutex, clear up message queue.
*/
static void app_demo_deinit(void)
{
sem_destroy(&app_demo.sem);
pthread_mutex_destroy(&app_demo.mutex);
node_t* entry = NULL;
node_t* temp_entry = NULL;
list_for_every_entry_safe(&app_demo.message_queue, entry, temp_entry, node_t, node)
{
list_delete(&entry->node);
free(entry);
}
}
/**
* @brief The main thread processes events.
*/
static void app_handle_message(node_t* node)
{
if (node == NULL) {
return;
}
if (node->data.msg_type > APP_BT_GAP_MESSAGE_START && node->data.msg_type < APP_BT_GAP_MESSAGE_END)
demo_acceptbond_handle_gap_message(g_bt_ins, node);
}
/**
* @brief Check the exit condition of the while loop in the main function.
*
* The condition for exiting the while loop can be multiple, but in this demo,
* only one scenario is provided: Bluetooth is turned off.
*/
static bool app_if_running(void)
{
// Developers can add additional exit condition checks.
return app_demo.running;
}
int main(int argc, char* argv[])
{
node_t* node = NULL;
// 1. Initialize semaphore;
// 2. Initialize mutex;
// 3. Initialize message queue.
app_demo_init();
// Create bluetooth client instance.
g_bt_ins = bluetooth_create_instance();
if (g_bt_ins == NULL) {
LOGE("create instance error");
goto error;
}
// Register gap callback.
adapter_callback = bt_adapter_register_callback(g_bt_ins, &app_gap_cbs);
if (adapter_callback == NULL) {
LOGE("register callback error.");
goto error;
}
// Enable bluetooth.
if (bt_adapter_enable(g_bt_ins) != BT_STATUS_SUCCESS) {
LOGE("enable adapter error.");
goto error;
}
// The app main threadis used to handle bluetooth events.
while (app_if_running()) {
// Obtain the msg to be processed.
node = app_list_remove_head();
// The main thread processes events.
app_handle_message(node);
}
error:
// Unregister gap callback;
if (adapter_callback) {
bt_adapter_unregister_callback(g_bt_ins, adapter_callback);
adapter_callback = NULL;
}
if (g_bt_ins) {
// Delete bluetooth client instance;
bluetooth_delete_instance(g_bt_ins);
g_bt_ins = NULL;
}
// 1. Destroy semaphore;
// 2. Destroy mutex;
// 3. clean up message queue.
app_demo_deinit();
LOGI("Bluetooth closed.");
return 0;
}

View File

@ -1,75 +0,0 @@
/****************************************************************************
* 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 <nuttx/list.h>
#include <semaphore.h>
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include "app_bt_message_gap.h"
#include "bluetooth.h"
#include "bt_adapter.h"
typedef enum {
#define __APP_BT_MESSAGE_CODE__
#include "app_bt_message_gap.h"
#undef __APP_BT_MESSAGE_CODE__
} app_bt_message_type_t;
#define APP_LOG_TAG "app_demo"
#define LOG_EMERG 0 /* system is unusable */
#define LOG_ALERT 1 /* action must be taken immediately */
#define LOG_CRIT 2 /* critical conditions */
#define LOG_ERR 3 /* error conditions */
#define LOG_WARNING 4 /* warning conditions */
#define LOG_NOTICE 5 /* normal but significant condition */
#define LOG_INFO 6 /* informational */
#define LOG_DEBUG 7 /* debug-level messages */
#define LOGE(fmt, ...) syslog(LOG_ERR, "[" APP_LOG_TAG "]" \
": " fmt "\n", \
##__VA_ARGS__);
#define LOGW(fmt, ...) syslog(LOG_WARNING, "[" APP_LOG_TAG "]" \
": " fmt "\n", \
##__VA_ARGS__);
#define LOGI(fmt, ...) syslog(LOG_INFO, "[" APP_LOG_TAG "]" \
": " fmt "\n", \
##__VA_ARGS__);
typedef struct {
uint32_t msg_type;
union {
app_bt_message_gap_t gap_req;
};
union {
app_bt_message_gap_callbacks_t gap_cb;
};
} app_demo_message_t;
typedef struct {
struct list_node node;
app_demo_message_t data;
} node_t;
typedef struct {
uint8_t running;
sem_t sem;
pthread_mutex_t mutex;
struct list_node message_queue;
} app_demo_t;
void demo_acceptbond_handle_gap_message(bt_instance_t* g_bt_ins, node_t* node);

Some files were not shown because too many files have changed in this diff Show More