Compare commits

..

1 Commits
dev ... trunk

Author SHA1 Message Date
liujinye 43945bc1d1 chore: sync .github, .gitee and LICENSE from dev branch
Change-Id: I96ba58db002827e8dd9d09d786be539aaa4ab162
2026-04-22 16:51:45 +08:00
371 changed files with 8510 additions and 27594 deletions

View File

@ -7,6 +7,7 @@ bootstrap_go_package {
],
srcs: [
"frameworkBluetooth.go",
"frameworkBluetoothBin.go",
],
pluginFor: ["soong_build"],
}
@ -22,6 +23,7 @@ frameworkBluetooth_cc_library {
"service/ipc/socket/src/bt_socket_client.c",
"service/ipc/socket/src/bt_socket_adapter.c",
"service/ipc/socket/src/bt_socket_advertiser.c",
"service/ipc/socket/src/bt_socket_avrcp_control.c",
"service/ipc/socket/src/bt_socket_scan.c",
"service/ipc/socket/src/bt_socket_gattc.c",
"service/ipc/socket/src/bt_socket_gatts.c",
@ -31,6 +33,7 @@ frameworkBluetooth_cc_library {
"service/ipc/socket/src/bt_socket_hfp_ag.c",
"service/ipc/socket/src/bt_socket_hfp_hf.c",
"service/ipc/socket/src/bt_socket_hid_device.c",
"service/ipc/socket/src/bt_socket_l2cap.c",
"service/ipc/socket/src/bt_socket_spp.c",
"service/src/manager_service.c",
],
@ -73,9 +76,13 @@ frameworkBluetooth_cc_library {
"//apex_available:platform",
"com.android.btservices",
],
header_libs: [
"kernel_modules_headers_apex",
],
}
cc_binary {
frameworkBluetooth_cc_binary {
name : "bttool",
srcs : [
@ -89,6 +96,7 @@ cc_binary {
"tools/hfp_ag.c",
"tools/hfp_hf.c",
"tools/hid_device.c",
"tools/l2cap.c",
"tools/spp.c",
"tools/log.c",
"tools/utils.c",
@ -102,6 +110,7 @@ cc_binary {
local_include_dirs : [
"framework/include",
"service",
"service/common",
"service/utils",
],

View File

@ -35,10 +35,6 @@ if(CONFIG_BLUETOOTH)
${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()
@ -194,11 +190,6 @@ if(CONFIG_BLUETOOTH)
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)
@ -220,7 +211,7 @@ if(CONFIG_BLUETOOTH)
if(CONFIG_BLUETOOTH_STORAGE_PROPERTY_SUPPORT)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/common/storage_property.c)
else()
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/common/storage.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/common/bt_storage.c)
endif()
if(CONFIG_BLUETOOTH_STORAGE_UPDATE)
@ -290,6 +281,10 @@ if(CONFIG_BLUETOOTH)
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_SPP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_spp_interface.c)
endif()
if(CONFIG_BLUETOOTH_A2DP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_a2dp_interface.c)
endif()
@ -298,6 +293,10 @@ if(CONFIG_BLUETOOTH)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_avrcp_interface.c)
endif()
if(CONFIG_BLUETOOTH_HID_DEVICE)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_hid_device_interface.c)
endif()
if(CONFIG_BLUETOOTH_HFP_HF)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/stacks/zephyr/sal_hfp_hf_interface.c)
endif()
@ -306,14 +305,6 @@ if(CONFIG_BLUETOOTH)
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)
@ -334,10 +325,6 @@ if(CONFIG_BLUETOOTH)
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()
endif()
if(NOT CONFIG_BLUETOOTH_BLE_AUDIO)
@ -364,17 +351,16 @@ if(CONFIG_BLUETOOTH)
list(REMOVE_ITEM CSRCS
${BLUETOOTH_DIR}/service/profiles/system/media_system.c)
else()
file(GLOB APPEND_FILES
${BLUETOOTH_DIR}/service/profiles/audio_interface/*.c)
list(APPEND CSRCS ${APPEND_FILES})
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/profiles/audio_interface/audio_control.c)
if(CONFIG_AUDIOUTILS_TINYCOMPRESS)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/profiles/audio_interface/audio_transport.c)
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/profiles/audio_interface/include)
endif()
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)
@ -429,6 +415,12 @@ if(CONFIG_BLUETOOTH)
if(CONFIG_BLUETOOTH_HFP_AG)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/hfp_ag/*.c)
if(CONFIG_PHONE_SERVICE)
list(REMOVE_ITEM APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/system/telephony_interface.c)
list(REMOVE_ITEM APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/hfp_ag/hfp_ag_tele_service.c)
else()
list(REMOVE_ITEM APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/hfp_ag/hfp_ag_tele_phone_service.c)
endif()
list(APPEND CSRCS ${APPEND_FILES})
endif()
@ -511,12 +503,6 @@ if(CONFIG_BLUETOOTH)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/utils/btsnoop_filter.c)
endif()
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()
@ -533,23 +519,23 @@ if(CONFIG_BLUETOOTH)
if(CONFIG_APP_BT_SAMPLE_CODE)
if(CONFIG_APP_BT_SAMPLE_CODE_BASIC)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/basic/*.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/basic/app_bt_gap.c)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_ENABLE)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/enable/*.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/enable/app_bt_gap.c)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_DISCOVERY)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/discovery/*.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/discovery/app_bt_gap.c)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_CREATEBOND)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/createbond/*.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/createbond/app_bt_gap.c)
endif()
if(CONFIG_APP_BT_SAMPLE_CODE_ACCEPTBOND)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/acceptbond/*.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/sample_code/acceptbond/app_bt_gap.c)
endif()
endif()
@ -581,6 +567,10 @@ if(CONFIG_BLUETOOTH)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/scan.c)
endif()
if(CONFIG_BLUETOOTH_L2CAP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/l2cap.c)
endif()
if(CONFIG_BLUETOOTH_A2DP_SINK)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/a2dp_sink.c)
endif()
@ -611,7 +601,10 @@ if(CONFIG_BLUETOOTH)
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_DEBUG_TRACE)
list(APPEND CSRCS ${BLUETOOTH_DIR}/debug/bt_trace.c)
endif()
if(CONFIG_BLUETOOTH_SPP)
@ -661,14 +654,9 @@ if(CONFIG_BLUETOOTH)
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)
@ -715,7 +703,10 @@ if(CONFIG_BLUETOOTH)
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/port/include/)
list(APPEND INCDIR ${NUTTX_APPS_DIR}/external/zblue/zblue/subsys/settings/include/settings)
list(APPEND INCDIR
${NUTTX_APPS_DIR}/external/zblue/zblue/port/include/kernel/include)
endif()
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/ipc)
@ -807,7 +798,7 @@ if(CONFIG_BLUETOOTH)
INCLUDE_DIRECTORIES
${INCDIR}
STACKSIZE
8192
4096
PRIORITY
${SCHED_PRIORITY_DEFAULT}
COMPILE_FLAGS
@ -905,24 +896,6 @@ 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
@ -949,21 +922,23 @@ if(CONFIG_BLUETOOTH)
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(JIDL_PATHS ${BLUETOOTH_DIR}/feature/jidl/bluetooth.jidl
${BLUETOOTH_DIR}/feature/jidl/bluetooth_bt.jidl)
set(JIDL_OUT_NAMES system_bluetooth system_bluetooth_bt)
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)
list(APPEND FEATURE_SRCS ${BLUETOOTH_DIR}/feature/src/system_bluetooth_bt_a2dpsink_impl.c)
list(APPEND JIDL_PATHS ${BLUETOOTH_DIR}/feature/jidl/bluetooth_bt_a2dpsink.jidl)
list(APPEND FEATURE_NAMES system_bluetooth_bt_a2dpsink)
list(APPEND JIDL_OUT_NAMES system_bluetooth_bt_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)
list(APPEND FEATURE_SRCS ${BLUETOOTH_DIR}/feature/src/system_bluetooth_bt_avrcpcontrol_impl.c)
list(APPEND JIDL_PATHS ${BLUETOOTH_DIR}/feature/jidl/bluetooth_bt_avrcpcontrol.jidl)
list(APPEND FEATURE_NAMES system_bluetooth_bt_avrcpcontrol)
list(APPEND JIDL_OUT_NAMES system_bluetooth_bt_avrcpcontrol)
endif()
nuttx_add_jidl(
@ -975,31 +950,51 @@ if(CONFIG_BLUETOOTH)
${JIDL_PATHS}
FEATURE_NAMES
${FEATURE_NAMES}
JIDL_OUT_NAMES
${JIDL_OUT_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(ASYNC_FEATURE_SRCS ${BLUETOOTH_DIR}/feature/feature_async/src/bluetooth_impl.c
${BLUETOOTH_DIR}/feature/feature_async/src/feature_bluetooth_util.c
${BLUETOOTH_DIR}/feature/feature_async/src/bluetooth_ble_impl.c)
target_include_directories(libbluetooth PRIVATE ${CMAKE_CURRENT_LIST_DIR}/feature/feature_async/include)
set(ASYNC_FEATURE_NAMES system_bluetooth system_bluetooth_ble)
set(JIDL_PATHS ${BLUETOOTH_DIR}/feature/feature_async/jidl/bluetooth.jidl)
list(APPEND JIDL_PATHS
${BLUETOOTH_DIR}/feature/feature_async/jidl/bluetooth_ble.jidl)
if(CONFIG_BLUETOOTH_GATT)
list(APPEND CSRCS ${BLUETOOTH_DIR}/framework/btwrap/async/bt_gatt_feature.c)
endif()
nuttx_add_jidl(
TARGET
libbluetooth
JIDL_SCRIPT
${PY_SCRIPT}
JIDL_OUT_DIR
${BINARY_EXT_MODULES_DIR}
FEATURE_SRCS
${ASYNC_FEATURE_SRCS}
JIDLS
${JIDL_PATHS}
FEATURE_NAMES
${ASYNC_FEATURE_NAMES}
OUT_SRC_EXT
c)
else()
endif()
if(CONFIG_BLUETOOTH_DFX)
set(XML_PATHS ${BLUETOOTH_DIR}/dfx/event_bt.xml)
nuttx_add_dfx_event(
TARGET
dfx_bt
XML_PATHS
${XML_PATHS})
endif()
# Add Dependson
nuttx_add_dependencies(TARGET libbluetooth DEPENDS libuv)
@ -1011,6 +1006,9 @@ if(CONFIG_BLUETOOTH)
${BLUETOOTH_DIR}/framework/include)
# Library Configuration
if(CONFIG_BLUETOOTH_STACK_BREDR_ZBLUE OR CONFIG_BLUETOOTH_STACK_LE_ZBLUE)
target_link_libraries(libbluetooth PRIVATE zblue_headers)
endif()
target_compile_options(libbluetooth PRIVATE ${CFLAGS})
target_sources(libbluetooth PRIVATE ${CSRCS})
target_include_directories(libbluetooth PRIVATE ${INCDIR})

107
Kconfig
View File

@ -66,15 +66,15 @@ config BLUETOOTH_FRAMEWORK_ASYNC
Enable Bluetooth Framework async API
choice
prompt "Select feature API"
prompt "select feature api"
default BLUETOOTH_FEATURE_NONE
config BLUETOOTH_FEATURE_NONE
bool "Not supporting Bluetooth feature API."
bool "not supporting Bluetooth feature API."
config BLUETOOTH_FEATURE
bool "Support Bluetooth synchronization API."
bool "support Bluetooth synchronization API."
depends on FEATURE_FRAMEWORK
config BLUETOOTH_FEATURE_ASYNC
bool "Support Bluetooth asynchronous API."
bool "support Bluetooth asynchronous API."
depends on FEATURE_FRAMEWORK
depends on BLUETOOTH_FRAMEWORK_ASYNC
endchoice
@ -103,6 +103,12 @@ config BLUETOOTH_BLE_SCAN_FILTER
default n
depends on BLUETOOTH_BLE_SCAN
config BLUETOOTH_HCI_FILTER
bool "Enable Bluetooth HCI filter"
default y
help
Enable Bluetooth HCI filter
config BLUETOOTH_L2CAP
bool "L2CAP dynamic channel support"
default n
@ -157,7 +163,7 @@ config BLUETOOTH_MAX_SAVED_REMOTE_UUIDS_LEN
config BLUETOOTH_MAX_REGISTER_NUM
int "Max register callback nums"
default 4
default 6
endmenu #Core
@ -227,11 +233,6 @@ choice
bool "Not support BLE Stack"
endchoice
config BLUETOOTH_LE_CS
bool "Bluetooth LE Channel Sounding supported"
depends on BLUETOOTH_STACK_LE_ZBLUE
default n
config BLUETOOTH_LE_SCANNER_MAX_NUM
int "LE Scanner max register number"
default 2
@ -244,15 +245,20 @@ config BLUETOOTH_LE_ADVERTISER_MAX_NUM
help
LE Advertiser max register number
config BLUETOOTH_CONNECTION_MANAGER
bool "Bluetooth connection manager support"
default y
config LE_DLF_SUPPORT
bool "Enable LE DLF support"
depends on BLUETOOTH_CONNECTION_MANAGER
default n
endmenu #Bluetooth LE Config
endif #BLUETOOTH_BLE_SUPPORT
choice
prompt "Select Bluetooth Storage Method(Unqlite, KVDB)"
prompt "select Bluetooth Storage Method(Unqlite, KVDB)"
default BLUETOOTH_STORAGE_PROPERTY_SUPPORT
config BLUETOOTH_STORAGE_PROPERTY_SUPPORT
bool "Bluetooth Storage KVDB Property support"
@ -295,6 +301,13 @@ config BLUETOOTH_A2DP_SOURCE
default n
select BLUETOOTH_AVRCP_TARGET
config ZBLUE_A2DP_SBC_MAX_BIT_POOL
int "A2DP sbc codec max bit pool"
default 32
depends on BLUETOOTH_STACK_BREDR_ZBLUE
help
A2DP sbc codec max bit pool 1~53
if BLUETOOTH_A2DP_SOURCE
config BLUETOOTH_A2DP_PEER_PARTIAL_RECONN
bool "Bluetooth A2DP peer partial reconnect support"
@ -302,6 +315,13 @@ config BLUETOOTH_A2DP_PEER_PARTIAL_RECONN
help
Bluetooth A2DP peer partial reconnect support
config ZBLUE_A2DP_SOURCE_BUF_SIZE
int "A2DP source buffer size"
default 660
depends on BLUETOOTH_STACK_BREDR_ZBLUE
help
Buffer size is related to L2CAP TX MTU
endif #BLUETOOTH_A2DP_SOURCE
config BLUETOOTH_A2DP_SINK
@ -365,6 +385,15 @@ config BLUETOOTH_HFP_AG_PRIMARY_SLOT
int "HFP select primary modem slot"
default 0
config BLUETOOTH_HFP_AG_LOCAL_TELEPHONY
bool "Handle telephony AT commands locally instead of notifying upper layer"
default y
help
If enabled, the HFP AG service handles telephony-related AT commands
(AT+CIND, AT+CLCC, AT+COPS, ATA, AT+CHUP, ATD, AT+CHLD) locally by
calling telephony service directly. If disabled, these requests are
forwarded to the upper layer (e.g. AP core) via callback.
endif # BLUETOOTH_HFP_AG
config BLUETOOTH_SCO_CTRL_PATH
@ -621,6 +650,16 @@ config BLUETOOTH_AUDIO_TRANS_ID_HFP_CTRL
int "Bluetooth Audio Transport SCO Ctrl Channel ID"
default 4
config BLUETOOTH_A2DP_SINK_DEVICE
string "Bluetooth A2DP Audio Transport Sink Device"
default "/dev/audio/a2dpsnkp" if MEDIA_SERVER
default "/dev/audio/a2dpsnk"
config BLUETOOTH_A2DP_SOURCE_DEVICE
string "Bluetooth A2DP Audio Transport Source Device"
default "/dev/audio/a2dpsrcc" if MEDIA_SERVER
default "/dev/audio/a2dpsrc"
config BLUETOOTH_LEA_SINK_CTRL_PATH
string "Bluetooth LE Audio Transport Sink Ctrl Path"
default "lea_sink_ctrl"
@ -637,25 +676,9 @@ config BLUETOOTH_LEA_SOURCE_DATA_PATH
string "Bluetooth LE Audio Transport Source Data Path"
default "lea_source_data"
config BLUETOOTH_A2DP_SINK_CTRL_PATH
string "Bluetooth A2DP Audio Transport Sink Ctrl Path"
default "a2dp_sink_ctrl"
config BLUETOOTH_A2DP_SINK_DATA_PATH
string "Bluetooth A2DP Audio Transport Sink Data Path"
default "a2dp_sink_data"
config BLUETOOTH_A2DP_SOURCE_CTRL_PATH
string "Bluetooth A2DP Audio Transport Source Ctrl Path"
default "a2dp_source_ctrl"
config BLUETOOTH_A2DP_SOURCE_DATA_PATH
string "Bluetooth A2DP Audio Transport Source Data Path"
default "a2dp_source_data"
endmenu #Bluetooth Audio Transport config
config BLUETOOTH_GATT
menuconfig BLUETOOTH_GATT
bool "Generic ATT Profile Support(deprecated)"
default y
@ -693,14 +716,6 @@ config GATT_CLIENT_CHAR_PER_SERVICE_MAX
help
The maximum number of characteristics that can be discovered and stored
under a single GATT service when using the ZBLUE stack.
config BLUETOOTH_GATT_CLIENT_DEBUG
bool "Enable GATT Client debug"
default y
help
Enable debug logging for GATT Client service discovery and dump.
Disabling this option reduces code size by removing log strings.
endif # BLUETOOTH_GATT_CLIENT
menuconfig BLUETOOTH_GATT_SERVER
@ -716,26 +731,32 @@ config BLUETOOTH_GATTS_MAX_CONNECTIONS
config BLUETOOTH_GATTS_MAX_ATTRIBUTE_NUM
int "GATT Server max number of attributes contained in a table"
default 10
config BLUETOOTH_GATTS_CACHE_SUPPORT
bool "Enable GATT Server Cache Support"
default y
depends on BLUETOOTH_BLE_SUPPORT
help
Enable internal GATT attribute table hash comparison.
On reconnect, trusted devices may receive Service Changed indications
if attribute changes are detected.
endif # BLUETOOTH_GATT_SERVER
menuconfig BLUETOOTH_SPP
bool "Serial Port Profile (SPP)"
default n
depends on SERIAL_TERMIOS
depends on PSEUDOTERM
if BLUETOOTH_SPP
config BLUETOOTH_SPP_MAX_CONNECTIONS
int "SPP max connections"
default 8
default 1
config BLUETOOTH_SPP_SERVER_MAX_CONNECTIONS
int "SPP Server max connections"
default 8
config BLUETOOTH_SPP_RPMSG_NET
bool "SPP RPMsg net support"
default n
depends on NET_RPMSG
endif #BLUETOOTH_SPP
config BLUETOOTH_HID_DEVICE
@ -800,7 +821,7 @@ config BLUETOOTH_DUMPBUFFER
config BLUETOOTH_DFX
bool "Enable Bluetooth DFX"
default y
depends on DFX_EVENT
depends on DFX
help
Enable Bluetooth DFX

View File

@ -17,7 +17,7 @@
ifeq ($(CONFIG_BLUETOOTH), y)
CONFIGURED_APPS += $(APPDIR)/frameworks/connectivity/bluetooth
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/include
CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/include
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/framework/include
CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/framework/include
endif

View File

@ -22,9 +22,7 @@ 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
@ -162,11 +160,6 @@ 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
@ -184,7 +177,7 @@ endif #CONFIG_BLUETOOTH_CONNECTION_MANAGER
ifeq ($(CONFIG_BLUETOOTH_STORAGE_PROPERTY_SUPPORT), y)
CSRCS += service/common/storage_property.c
else
CSRCS += service/common/storage.c
CSRCS += service/common/bt_storage.c
endif
ifeq ($(CONFIG_BLUETOOTH_STORAGE_UPDATE), y)
@ -196,7 +189,7 @@ ifeq ($(CONFIG_BLUETOOTH_DEBUG_MEMORY),y)
CSRCS += debug/bt_memory.c
endif
ifeq ($(CONFIG_BLUETOOTH_LOG), y)
ifeq ($(CONFIG_BLUETOOTH_DEBUG_TRACE), y)
CSRCS += service/debug/bt_trace.c
endif
@ -237,6 +230,9 @@ ifneq ($(CONFIG_BLUETOOTH_STACK_BREDR_ZBLUE)$(CONFIG_BLUETOOTH_STACK_LE_ZBLUE),)
ifeq ($(CONFIG_BLUETOOTH_CONNECTION_MANAGER), y)
CSRCS += service/stacks/zephyr/sal_connection_manager.c
endif
ifeq ($(CONFIG_BLUETOOTH_SPP), y)
CSRCS += service/stacks/zephyr/sal_spp_interface.c
endif #CONFIG_BLUETOOTH_SPP
ifeq ($(CONFIG_BLUETOOTH_A2DP), y)
CSRCS += service/stacks/zephyr/sal_a2dp_interface.c
endif #CONFIG_BLUETOOTH_A2DP
@ -244,6 +240,17 @@ ifneq ($(CONFIG_BLUETOOTH_AVRCP_CONTROL)$(CONFIG_BLUETOOTH_AVRCP_TARGET),)
CSRCS += service/stacks/zephyr/sal_avrcp_interface.c
endif #CONFIG_BLUETOOTH_AVRCP_CONTROL/CONFIG_BLUETOOTH_AVRCP_TARGET
ifeq ($(CONFIG_BLUETOOTH_HFP_HF), y)
CSRCS += service/stacks/zephyr/sal_hfp_hf_interface.c
endif #CONFIG_BLUETOOTH_HFP_HF
ifeq ($(CONFIG_BLUETOOTH_HFP_AG), y)
CSRCS += service/stacks/zephyr/sal_hfp_ag_interface.c
endif #CONFIG_BLUETOOTH_HFP_AG
ifeq ($(CONFIG_BLUETOOTH_HID_DEVICE), y)
CSRCS += service/stacks/zephyr/sal_hid_device_interface.c
endif #CONFIG_BLUETOOTH_HID_DEVICE
ifeq ($(CONFIG_BLUETOOTH_STACK_LE_ZBLUE), y)
CSRCS += service/stacks/zephyr/sal_adapter_le_interface.c
ifeq ($(CONFIG_BLUETOOTH_BLE_ADV), y)
@ -258,9 +265,6 @@ 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
endif
@ -275,7 +279,11 @@ 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
CSRCS += service/profiles/audio_interface/audio_control.c
ifeq ($(CONFIG_AUDIOUTILS_TINYCOMPRESS), y)
CSRCS += service/profiles/audio_interface/audio_transport.c
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/service/profiles/audio_interface/include
endif #CONFIG_AUDIOUTILS_TINYCOMPRESS
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
@ -283,9 +291,6 @@ 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
@ -323,6 +328,11 @@ endif #CONFIG_BLUETOOTH_HFP_HF
ifeq ($(CONFIG_BLUETOOTH_HFP_AG), y)
CSRCS += service/profiles/hfp_ag/*.c
ifeq ($(CONFIG_PHONE_SERVICE), y)
CSRCS := $(filter-out $(wildcard service/profiles/system/telephony_interface.c) $(wildcard service/profiles/hfp_ag/hfp_ag_tele_service.c), $(wildcard $(CSRCS)))
else
CSRCS := $(filter-out $(wildcard service/profiles/hfp_ag/hfp_ag_tele_phone_service.c),$(wildcard $(CSRCS)))
endif
endif #CONFIG_BLUETOOTH_HFP_AG
ifeq ($(CONFIG_BLUETOOTH_SPP), y)
@ -382,11 +392,6 @@ 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
@ -439,6 +444,9 @@ endif
ifeq ($(CONFIG_BLUETOOTH_BLE_SCAN), y)
CSRCS += tools/scan.c
endif
ifeq ($(CONFIG_BLUETOOTH_L2CAP), y)
CSRCS += tools/l2cap.c
endif #CONFIG_BLUETOOTH_L2CAP
ifeq ($(CONFIG_BLUETOOTH_A2DP_SINK), y)
CSRCS += tools/a2dp_sink.c
endif #CONFIG_BLUETOOTH_A2DP_SINK
@ -509,15 +517,10 @@ 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
@ -549,7 +552,6 @@ ifneq ($(CONFIG_BLUETOOTH_STACK_BREDR_ZBLUE)$(CONFIG_BLUETOOTH_STACK_LE_ZBLUE),)
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
@ -654,6 +656,7 @@ NOEXPORTSRCS = $(ASRCS)$(CSRCS)$(CXXSRCS)$(MAINSRC)
ifeq ($(CONFIG_BLUETOOTH_FEATURE),y)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/feature/include
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/runtimes/feature/include
CSRCS += feature/src/system_bluetooth.c
CSRCS += feature/src/system_bluetooth_impl.c
@ -671,6 +674,13 @@ CSRCS += feature/src/system_bluetooth_bt_avrcpcontrol.c
CSRCS += feature/src/system_bluetooth_bt_avrcpcontrol_impl.c
endif
ifneq ($(CONFIG_BLUETOOTH_DFX),)
DFX_XML=$(APPDIR)/frameworks/system/dfx/src/onetrack/xml
BLUETOOTH_XML=$(APPDIR)/frameworks/connectivity/bluetooth/dfx/event_bt.xml
context::
@cp $(BLUETOOTH_XML) $(DFX_XML)
endif
depend::
$(APPDIR)/../prebuilts/tools/rust/bin/jidl/jidl_gen_cpp \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/jidl/bluetooth.jidl --out-dir \
@ -684,9 +694,9 @@ ifeq ($(CONFIG_BLUETOOTH_A2DP_SINK), y)
$(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
$(APPDIR)/../prebuilts/tools/rust/bin/jidl/jidl_gen_cpp \
$(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

View File

@ -15,7 +15,6 @@
***************************************************************************/
#include "bt_sched_trace.h"
#include <inttypes.h>
#include <stdatomic.h>
#include <stdio.h>
#include <string.h>
@ -24,9 +23,6 @@
#include "utils/log.h"
#ifndef CONFIG_BLUETOOTH_TRACE_BUFFER_SIZE
#define CONFIG_BLUETOOTH_TRACE_BUFFER_SIZE 64
#endif
#define DUMP_THRESHOLD 256
typedef struct {
@ -68,7 +64,7 @@ void bt_note_stop(void)
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",
"[TAG=%s][TS=%lu][LAT=%uus]\n",
p->tag, p->timestamp, p->latency_us);
trace_manager->tail = (trace_manager->tail + 1) % CONFIG_BLUETOOTH_TRACE_BUFFER_SIZE;
written = written % DUMP_THRESHOLD;

View File

@ -96,75 +96,181 @@
"%s:%s", "blePairError", reason); \
} while (0)
// spp
#if defined(CONFIG_BLUETOOTH_DFX) && defined(CONFIG_BLUETOOTH_SPP)
#define BT_DFX_SEND_SPP_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_SPP_EVENT(...)
#endif
#define BT_DFX_SPP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btSppConnectError: %s", reason); \
BT_DFX_SEND_SPP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_RFCOMM, BT_DFXC_SPP_CONN), \
"%s:%s", "btSppConnectError", reason); \
} while (0)
#define BT_DFX_SPP_DISCONN_ERROR(reason, scn, port, role) \
do { \
BT_LOGE("BT_DFX: btSppDisconnected: %s, scn: %d, port: %d, role: %d", \
reason, scn, port, role); \
BT_DFX_SEND_SPP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_RFCOMM, BT_DFXC_SPP_DISCONN), \
"%s:%s,%s:%d,%s:%d,%s:%s", "btSppDisconnected", reason, "scn", scn, \
"port", port, "role", role); \
} while (0)
// a2dp
#if defined(CONFIG_BLUETOOTH_DFX) && defined(CONFIG_BLUETOOTH_BREDR_SUPPORT)
#if defined(CONFIG_BLUETOOTH_DFX) && defined(CONFIG_BLUETOOTH_A2DP)
#define BT_DFX_SEND_A2DP_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_A2DP_EVENT(...)
#endif
#define BT_DFX_A2DP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: a2dpConnError: %s", reason); \
BT_DFX_SEND_A2DP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_A2DP, BT_DFXC_A2DP_CONN), \
"%s:%s", "a2dpConnError", reason); \
#define BT_DFX_A2DP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btA2dpConnectError: %s", reason); \
BT_DFX_SEND_A2DP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_A2DP, BT_DFXC_A2DP_CONN), \
"%s:%s", "btA2dpConnectError", reason); \
} while (0)
#define BT_DFX_A2DP_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); \
#define BT_DFX_A2DP_MEDIA_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btA2dpMediaError: %s", reason); \
BT_DFX_SEND_A2DP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_A2DP, BT_DFXC_A2DP_MEDIA), \
"%s:%s", "btA2dpMediaError", reason); \
} while (0)
#define BT_DFX_A2DP_OFFLOAD_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btA2dpOffloadError: %s", reason); \
BT_DFX_SEND_A2DP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_A2DP, BT_DFXC_A2DP_OFFLOAD), \
"%s:%s", "btA2dpOffloadError", reason); \
} while (0)
// avrcp
#if defined(CONFIG_BLUETOOTH_DFX) && (defined(CONFIG_BLUETOOTH_AVRCP_CONTROL) || defined(CONFIG_BLUETOOTH_AVRCP_TARGET))
#define BT_DFX_SEND_AVRCP_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_AVRCP_EVENT(...)
#endif
#define BT_DFX_AVRCP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btAvrcpConnectError: %s", reason); \
BT_DFX_SEND_AVRCP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_AVRCP, BT_DFXC_AVRCP_CONN), \
"%s:%s", "btAvrcpConnectError", reason); \
} while (0)
#define BT_DFX_AVRCP_CTRL_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btAvrcpCtrlError: %s", reason); \
BT_DFX_SEND_AVRCP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_AVRCP, BT_DFXC_AVRCP_CTRL), \
"%s:%s", "btAvrcpCtrlError", reason); \
} while (0)
#define BT_DFX_AVRCP_VOL_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btAvrcpVolError: %s", reason); \
BT_DFX_SEND_AVRCP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_AVRCP, BT_DFXC_AVRCP_VOL), \
"%s:%s", "btAvrcpVolError", reason); \
} while (0)
// hfp
#if defined(CONFIG_BLUETOOTH_DFX) && defined(CONFIG_BLUETOOTH_BREDR_SUPPORT)
#if defined(CONFIG_BLUETOOTH_DFX) && (defined(CONFIG_BLUETOOTH_HFP_HF) || defined(CONFIG_BLUETOOTH_HFP_AG))
#define BT_DFX_SEND_HFP_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_HFP_EVENT(...)
#endif
#define BT_DFX_HFP_CONN_ERROR(reason) \
#define BT_DFX_HFP_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btHfpConnectError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_CONN), \
"%s:%s", "btHfpConnectError", reason); \
} while (0)
#define BT_DFX_HFP_SCO_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: hfpConnError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_CONN), \
"%s:%s", "hfpConnError", reason); \
BT_LOGE("BT_DFX: btHfpScoConnectError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_SCO_CONN), \
"%s:%s", "btHfpScoConnectError", reason); \
} while (0)
#define BT_DFX_HFP_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); \
#define BT_DFX_HFP_VOL_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btHfpVolError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_VOL), \
"%s:%s", "btHfpVolError", reason); \
} while (0)
// open (enable)
#define BT_DFX_HFP_MEDIA_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btHfpMediaError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_MEDIA), \
"%s:%s", "btHfpMediaError", reason); \
} while (0)
#define BT_DFX_HFP_OFFLOAD_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btHfpOffloadError: %s", reason); \
BT_DFX_SEND_HFP_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HFP, BT_DFXC_HFP_OFFLOAD), \
"%s:%s", "btHfpOffloadError", reason); \
} while (0)
// hid
#if defined(CONFIG_BLUETOOTH_DFX) && defined(CONFIG_BLUETOOTH_HID_DEVICE)
#define BT_DFX_SEND_HID_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_HID_EVENT(...)
#endif
#define BT_DFX_HID_CONN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btHidConnectError: %s", reason); \
BT_DFX_SEND_HID_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_HID, BT_DFXC_HID_CONN), \
"%s:%s", "btHidConnectError", reason); \
} while (0)
// others
#if defined(CONFIG_BLUETOOTH_DFX)
#define BT_DFX_SEND_OTHERS_EVENT(...) sendEventMisightF(__VA_ARGS__)
#else
#define BT_DFX_SEND_OTHERS_EVENT(...)
#endif
#define BT_DFX_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); \
#define BT_DFX_SOCKET_ERROR(reason, port) \
do { \
BT_LOGE("BT_DFX: btSocketError: %s, port: %d", reason, port); \
BT_DFX_SEND_OTHERS_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_OTHERS, BT_DFXC_SOCKET), \
"%s:%s,%s:%d", "btSocketError", reason, "port", port); \
} while (0)
// 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); \
#define BT_DFX_IPC_CONN_ERROR(type, reason) \
do { \
BT_LOGE("BT_DFX: btIpcConnectError: %s, reason: %s", type, reason); \
BT_DFX_SEND_OTHERS_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_OTHERS, BT_DFXC_IPC_CONN), \
"%s:%s,%s:%s", "btIpcConnectError", type, "reason", reason); \
} while (0)
#define BT_DFX_IPC_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); \
#define BT_DFX_IPC_ALLOC_ERROR(reason, packet_code) \
do { \
BT_LOGE("BT_DFX: btIpcAllocError: %s, packetCode: %" PRIu32, reason, packet_code); \
BT_DFX_SEND_OTHERS_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_OTHERS, BT_DFXC_IPC_ALLOC), \
"%s:%s,%s:%" PRIu32 "", "btIpcAllocError", reason, "packetCode", packet_code); \
} while (0)
#endif /* _BT_DFX_H_ */
#define BT_DFX_DRIVER_ERROR(type, name, reason) \
do { \
BT_LOGE("BT_DFX: btDriverError: %s, name: %s, reason: %s", type, name, reason); \
BT_DFX_SEND_OTHERS_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_OTHERS, BT_DFXC_DRIVER), \
"%s:%s,%s:%s,%s:%s", "btDriverError", type, "name", name, "reason", reason); \
} while (0)
#define BT_DFX_OPEN_ERROR(reason) \
do { \
BT_LOGE("BT_DFX: btOpenError: %s", reason); \
BT_DFX_SEND_OTHERS_EVENT(BT_DFX_BUILD_CODE(BT_DFXG_OTHERS, BT_DFXC_OPEN), \
"%s:%s", "btOpenError", reason); \
} while (0)
#endif /* _BT_DFX_H_ */

View File

@ -17,7 +17,7 @@
#define _BT_DFX_EVENT_H_
// vela bluetooth event id
#define BT_DFX_BASE_VELA_BLUETOOTH (923020000)
#define BT_DFX_BASE_VELA_BLUETOOTH (961020000)
// event group
#define BT_DFXG_BR_GAP (0)
@ -47,16 +47,40 @@
#define BT_DFXC_LE_GAP_DISCONN (110)
#define BT_DFXC_LE_GAP_PAIR (200)
// group: BT_DFXG_RFCOMM
#define BT_DFXC_SPP_CONN (0)
#define BT_DFXC_SPP_DISCONN (10)
// group: BT_DFXG_A2DP
#define BT_DFXC_A2DP_CONN (0)
#define BT_DFXC_A2DP_OFFLOAD (100)
#define BT_DFXC_A2DP_MEDIA (10)
#define BT_DFXC_A2DP_OFFLOAD (20)
// group: BT_DFXG_AVRCP
#define BT_DFXC_AVRCP_CONN (0)
#define BT_DFXC_AVRCP_CTRL (10)
#define BT_DFXC_AVRCP_VOL (20)
// group: BT_DFXG_HFP
#define BT_DFXC_HFP_CONN (0)
#define BT_DFXC_HFP_OFFLOAD (100)
#define BT_DFXC_HFP_SCO_CONN (10)
#define BT_DFXC_HFP_VOL (20)
#define BT_DFXC_HFP_MEDIA (30)
#define BT_DFXC_HFP_OFFLOAD (40)
// group: BT_DFXG_HID
#define BT_DFXC_HID_CONN (0)
// group: BT_DFXG_MESH
// group: BT_DFXG_CHANNEL_SOUNDING
// group: BT_DFXG_OTHERS
#define BT_DFXC_OPEN (0)
#define BT_DFXC_SOCKET (0)
#define BT_DFXC_IPC_CONN (10)
#define BT_DFXC_IPC_ALLOC (20)
#define BT_DFXC_DRIVER (100)
#define BT_DFXC_OPEN (200)
#define BT_DFX_BUILD_CODE(group, subcode) ((BT_DFX_BASE_VELA_BLUETOOTH) + (group) + (subcode))

View File

@ -24,16 +24,53 @@
#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"
#define BT_DFXE_A2DP_CONN_TIMEOUT "btA2dpConnTimeout"
#define BT_DFXE_SET_A2DP_AVAILABLE_FAIL "btSetA2dpAvailableFail"
#define BT_DFXE_GET_A2DP_AVAILABLE_FAIL "btGetA2dpAvailableFail"
#define BT_DFXE_OFFLOAD_START_TIMEOUT "btOffloadStartTimeout"
#define BT_DFXE_OFFLOAD_HCI_UNSPECIFIED_ERROR "btOffloadHciUnspecifiedError"
#define BT_DFXE_GET_MEDIA_VOLUME_RANGE_FAIL "btGetMediaVolumeRangeFail"
#define BT_DFXE_SET_MEDIA_VOLUME_FAIL "btSetMediaVolumeFail"
#define BT_DFXE_SET_UI_VOLUME_FAIL "btSetUiVolumeFail"
#define BT_DFXE_MEDIA_PLAYER_CREATE_FAIL "btMediaPlayerCreateFail"
#define BT_DFXE_GET_STREAM_VOLUME_FAIL "btGetStreamVolumeFail"
#define BT_DFXE_MEDIA_SESSION_OPEN_FAIL "btMediaSessionOpenFail"
#define BT_DFXE_MEDIA_SESSION_SET_EVENT_CB_FAIL "btMediaSessionSetEventCbFail"
#define BT_DFXE_MEDIA_SESSION_START_FAIL "btMediaSessionStartFail"
#define BT_DFXE_MEDIA_SESSION_STOP_FAIL "btMediaSessionStopFail"
#define BT_DFXE_MEDIA_SESSION_PAUSE_FAIL "btMediaSessionPauseFail"
#define BT_DFXE_MEDIA_SESSION_NEXT_SONG_FAIL "btMediaSessionNextSongFail"
#define BT_DFXE_MEDIA_SESSION_PREV_SONG_FAIL "btMediaSessionPrevSongFail"
#define BT_DFXE_HFP_AG_CONN_TIMEOUT "btHfpAgConnTimeout"
#define BT_DFXE_HFP_AG_CONN_RETRY_FAIL "btHfpAgConnRetryFail"
#define BT_DFXE_HFP_HF_CONN_TIMEOUT "btHfpHfConnTimeout"
#define BT_DFXE_HFP_HF_CONN_RETRY_FAIL "btHfpHfConnRetryFail"
#define BT_DFXE_SET_VOICE_CALL_VOLUME_FAIL "btSetVoiceCallVolumeFail"
#define BT_DFXE_GET_VOICE_CALL_VOLUME_FAIL "btGetVoiceCallVolumeFail"
#define BT_DFXE_MEDIA_POLICY_SUBSCRIBE_FAIL "btMediaPolicySubscribeFail"
#define BT_DFXE_SET_HFP_SAMPLERATE_FAIL "btSetHfpSamplerateFail"
#define BT_DFXE_SET_SCO_AVAILABLE_FAIL "btSetScoAvailableFail"
#define BT_DFXE_SET_SCO_UNAVAILABLE_FAIL "btSetScoUnavailableFail"
#define BT_DFXE_SET_ANC_ENABLE_FAIL "btSetAncEnableFail"
#define BT_DFXE_HID_CONNECT_BUSY "btHidConnectBusy"
#define BT_DFXE_CLIENT_CONNECT_FAIL "btClientConnectFail"
#define BT_DFXE_ASYNC_CLIENT_CONN_FAIL "btAsyncClientConnectFail"
#define BT_DFXE_FILE_DESCRIPTOR_ERROR "btFileDescriptorError"
#define BT_DFXE_SPP_CONN_FAIL "btSppConnFail"
#define BT_DFXE_CLIENT_MSG_ALLOC_FAIL "btClientMsgAllocFail"
#define BT_DFXE_SERVER_CACHE_ALLOC_FAIL "btServerCacheAllocFail"
#define BT_DFXE_OPEN_HCI_UART_FAIL "btOpenHciUartFail"
#define BT_DFXE_LE_ENABLE_FAIL "btLeEnableFail"
#define BT_DFXE_BR_ENABLE_FAIL "btBrEnableFail"
#endif /* _BT_DFX_REASON_H_ */

View File

@ -191,8 +191,8 @@ bt_status_t get_valid_uuid128(uint8_t uuid128[16], const char* in)
char* bt_uuid_to_feature_string(const bt_uuid_t* bt_uuid)
{
char uuid[BT_UUID_STR_LENGTH] = { 0 };
bt_uuid_to_string(bt_uuid, uuid, BT_UUID_STR_LENGTH);
char uuid[40] = { 0 };
bt_uuid_to_string(bt_uuid, uuid, 40);
return StringToFtString(uuid);
}
#endif

View File

@ -424,7 +424,7 @@ FtString system_bluetooth_bt_wrap_getDeviceName(FeatureInstanceHandle feature, A
return StringToFtString(name);
}
unsigned int system_bluetooth_bt_wrap_getDeviceClass(FeatureInstanceHandle feature, AppendData append_data, FtString deviceId)
FtUint32 system_bluetooth_bt_wrap_getDeviceClass(FeatureInstanceHandle feature, AppendData append_data, FtString deviceId)
{
bt_address_t addr;
if (bt_addr_str2ba(deviceId, &addr) < 0) {

View File

@ -85,7 +85,7 @@ void system_bluetooth_wrap_openAdapter(FeatureInstanceHandle feature, AppendData
void system_bluetooth_wrap_closeAdapter(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_CloseAdapterParams* params)
{
bt_status_t status = bt_adapter_disable(feature_bluetooth_get_bt_ins(feature));
bt_status_t status = bt_adapter_disable_safe(feature_bluetooth_get_bt_ins(feature));
if (status == BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke success closeAdapter callback failed!");

View File

@ -44,7 +44,7 @@ bt_status_t BTSYMBOLS(bt_adapter_disable)(bt_instance_t* ins)
bt_status_t BTSYMBOLS(bt_adapter_disable_safe)(bt_instance_t* ins)
{
return adapter_disable(SYS_SET_BT_ALL);
return adapter_disable_safe(SYS_SET_BT_ALL);
}
bt_status_t BTSYMBOLS(bt_adapter_enable_le)(bt_instance_t* ins)
@ -82,7 +82,7 @@ bt_status_t BTSYMBOLS(bt_adapter_start_limited_discovery)(bt_instance_t* ins, ui
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)
bt_status_t BTSYMBOLS(bt_adapter_set_debug_mode)(bt_instance_t* ins, bt_debug_mode_t mode, uint8_t operation)
{
return adapter_set_debug_mode(mode, operation);
}
@ -208,7 +208,12 @@ bt_status_t BTSYMBOLS(bt_adapter_le_enable_key_derivation)(bt_instance_t* ins,
bt_status_t BTSYMBOLS(bt_adapter_le_add_whitelist)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_le_add_whitelist(addr);
return adapter_le_add_whitelist_with_type(addr, BT_LE_ADDR_TYPE_UNKNOWN);
}
bt_status_t BTSYMBOLS(bt_adapter_le_add_whitelist_with_type)(bt_instance_t* ins, bt_address_t* addr, ble_addr_type_t type)
{
return adapter_le_add_whitelist_with_type(addr, type);
}
bt_status_t BTSYMBOLS(bt_adapter_le_remove_whitelist)(bt_instance_t* ins, bt_address_t* addr)

View File

@ -75,12 +75,12 @@ bt_status_t BTSYMBOLS(bt_avrcp_control_get_playback_state)(bt_instance_t* ins, b
{
avrcp_control_interface_t* profile = get_profile_service();
return profile->get_playback_state(addr);
return profile->avrcp_control_get_playback_state(addr);
}
bt_status_t BTSYMBOLS(bt_avrcp_control_register_notification)(bt_instance_t* ins, bt_address_t* addr, avrcp_notification_event_t event, uint32_t interval)
bt_status_t BTSYMBOLS(bt_avrcp_control_register_notification)(bt_instance_t* ins, bt_address_t* addr, uint8_t event, uint32_t interval)
{
avrcp_control_interface_t* profile = get_profile_service();
return profile->avrcp_control_register_notification(addr, event, interval);
}
}

View File

@ -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

@ -21,6 +21,7 @@
#include "bt_addr.h"
#include "bt_device.h"
#include "bt_internal.h"
#include "connection_manager.h"
#include "device.h"
bt_status_t BTSYMBOLS(bt_device_get_identity_address)(bt_instance_t* ins, bt_address_t* bd_addr, bt_address_t* id_addr)
@ -30,11 +31,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)
@ -112,6 +109,24 @@ bt_status_t BTSYMBOLS(bt_device_disconnect)(bt_instance_t* ins, bt_address_t* ad
return adapter_disconnect(addr);
}
bt_status_t BTSYMBOLS(bt_device_background_connect)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
#ifdef CONFIG_BLUETOOTH_CONNECTION_MANAGER
return bt_cm_device_connect(addr, transport);
#else
return BT_STATUS_UNSUPPORTED;
#endif
}
bt_status_t BTSYMBOLS(bt_device_background_disconnect)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
#ifdef CONFIG_BLUETOOTH_CONNECTION_MANAGER
return bt_cm_device_disconnect(addr, transport);
#else
return BT_STATUS_UNSUPPORTED;
#endif
}
bt_status_t BTSYMBOLS(bt_device_connect_le)(bt_instance_t* ins,
bt_address_t* addr,
ble_addr_type_t type,
@ -204,4 +219,22 @@ bt_status_t BTSYMBOLS(bt_device_set_le_sc_remote_oob_data)(bt_instance_t* ins, b
bt_status_t BTSYMBOLS(bt_device_get_le_sc_local_oob_data)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_le_get_local_oob_data(addr);
}
bt_status_t BTSYMBOLS(bt_device_enable_enhanced_mode)(bt_instance_t* ins, bt_address_t* addr, bt_enhanced_mode_t mode)
{
#ifdef CONFIG_BLUETOOTH_CONNECTION_MANAGER
return bt_cm_enable_enhanced_mode(addr, mode);
#else
return BT_STATUS_UNSUPPORTED;
#endif
}
bt_status_t BTSYMBOLS(bt_device_disable_enhanced_mode)(bt_instance_t* ins, bt_address_t* addr, bt_enhanced_mode_t mode)
{
#ifdef CONFIG_BLUETOOTH_CONNECTION_MANAGER
return bt_cm_disable_enhanced_mode(addr, mode);
#else
return BT_STATUS_UNSUPPORTED;
#endif
}

View File

@ -98,6 +98,13 @@ bt_status_t BTSYMBOLS(bt_gattc_write_without_response)(gattc_handle_t conn_handl
return profile->write_without_response(conn_handle, attr_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gattc_write_with_signed)(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
gattc_interface_t* profile = get_profile_service();
return profile->write_signed(conn_handle, attr_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gattc_subscribe)(gattc_handle_t conn_handle, uint16_t attr_handle, uint16_t ccc_value)
{
gattc_interface_t* profile = get_profile_service();

View File

@ -152,13 +152,6 @@ bt_status_t BTSYMBOLS(bt_hfp_ag_send_at_command)(bt_instance_t* ins, bt_address_
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)
@ -168,6 +161,13 @@ bt_status_t BTSYMBOLS(bt_hfp_ag_send_clcc_response)(bt_instance_t* ins, bt_addre
return profile->send_clcc_response(addr, index, dir, call, mode, mpty, type, number);
}
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_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)
@ -175,4 +175,4 @@ bt_status_t BTSYMBOLS(bt_hfp_ag_send_cind_response)(bt_instance_t* ins, bt_addre
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

@ -24,25 +24,35 @@
void* BTSYMBOLS(bt_l2cap_register_callbacks)(bt_instance_t* ins, const l2cap_callbacks_t* callbacks)
{
return l2cap_register_callbacks(NULL, callbacks);
return l2cap_register_callbacks(ins, callbacks);
}
bool BTSYMBOLS(bt_l2cap_unregister_callbacks)(bt_instance_t* ins, void* cookie)
bool BTSYMBOLS(bt_l2cap_unregister_callbacks)(bt_instance_t* ins, void* handle)
{
return l2cap_unregister_callbacks(NULL, cookie);
return l2cap_unregister_callbacks(NULL, handle);
}
bt_status_t BTSYMBOLS(bt_l2cap_listen)(bt_instance_t* ins, l2cap_config_option_t* option)
bt_status_t BTSYMBOLS(bt_l2cap_listen)(bt_instance_t* ins, void* handle, l2cap_config_option_t* option)
{
return l2cap_listen_channel(option);
return l2cap_listen_channel(handle, option);
}
bt_status_t BTSYMBOLS(bt_l2cap_connect)(bt_instance_t* ins, bt_address_t* addr, l2cap_config_option_t* option)
bt_status_t BTSYMBOLS(bt_l2cap_connect)(bt_instance_t* ins, void* handel, bt_address_t* addr, l2cap_config_option_t* option)
{
return l2cap_connect_channel(addr, option);
return l2cap_connect_channel(handel, addr, option);
}
bt_status_t BTSYMBOLS(bt_l2cap_disconnect)(bt_instance_t* ins, uint16_t cid)
bt_status_t BTSYMBOLS(bt_l2cap_disconnect)(bt_instance_t* ins, void* handle, uint16_t id)
{
return l2cap_disconnect_channel(cid);
return l2cap_disconnect_channel(handle, id);
}
bt_status_t BTSYMBOLS(bt_l2cap_stop_listen)(bt_instance_t* ins, void* handle, uint16_t psm)
{
return l2cap_stop_listen_channel(handle, BT_TRANSPORT_BLE, psm);
}
bt_status_t BTSYMBOLS(bt_l2cap_stop_listen_with_transport)(bt_instance_t* ins, void* handle, bt_transport_t transport, uint16_t psm)
{
return l2cap_stop_listen_channel(handle, transport, psm);
}

View File

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "adv"
#define LOG_TAG "scan"
#include <stdlib.h>

View File

@ -186,9 +186,9 @@ bt_status_t bt_adapter_set_le_address(bt_instance_t* ins, bt_address_t* addr)
return BpBtAdapter_setLeAddress((BpBtAdapter*)ins->adapter_proxy, addr);
}
bt_status_t bt_adapter_set_le_identity_address(bt_instance_t* ins, bt_address_t* addr, bool public)
bt_status_t bt_adapter_set_le_identity_address(bt_instance_t* ins, bt_address_t* addr, bool is_public)
{
return BpBtAdapter_setLeIdentityAddress((BpBtAdapter*)ins->adapter_proxy, addr, public);
return BpBtAdapter_setLeIdentityAddress((BpBtAdapter*)ins->adapter_proxy, addr, is_public);
}
bt_status_t bt_adapter_set_le_appearance(bt_instance_t* ins, uint16_t appearance)

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
@ -53,7 +54,6 @@ typedef struct {
struct gatt_client {
gattc_handle_t conn;
bt_address_t addr;
bt_gattc_feature_callbacks_t callbacks;
bool connected;
bool services_discovering;
@ -158,25 +158,6 @@ void discovery_database_destroy(gatt_client_t* client)
}
}
static bool match_client_by_addr(void* element, void* context)
{
bt_address_t* target_addr;
gatt_client_t* client;
target_addr = (bt_address_t*)context;
client = (gatt_client_t*)element;
return memcmp(&client->addr, target_addr, sizeof(bt_address_t)) == 0;
}
static gatt_client_t* find_client_by_addr(bt_address_t* addr)
{
if (!g_gatt_client_list || !addr)
return NULL;
return (gatt_client_t*)bt_list_find(g_gatt_client_list, match_client_by_addr, (void*)addr);
}
static gatt_client_t* find_client_by_conn(gattc_handle_t conn)
{
bt_list_node_t* node;
@ -327,6 +308,18 @@ static gatt_descriptor_t* find_desc_by_attr_handle(gatt_client_t* client, uint16
return NULL;
}
static void gatt_service_list_to_array(bt_list_t* list,
const gatt_service_t* out_array[])
{
bt_list_node_t* node;
size_t i = 0;
for (node = bt_list_head(list); node != NULL;
node = bt_list_next(list, node)) {
out_array[i++] = (gatt_service_t*)bt_list_node(node);
}
}
static gatt_service_t* build_service_from_attr_list(bt_list_t* attr_list)
{
gatt_service_t* service;
@ -439,11 +432,10 @@ static void feature_on_connected(void* conn_handle, bt_address_t* addr)
return;
client->connected = true;
memcpy(&client->addr, addr, sizeof(bt_address_t));
BT_FEATURE_LOG("connected: conn=%p", conn_handle);
BT_GATTC_FEATURE_INVOKE_CB(client, on_connected, client->ins, BT_STATUS_SUCCESS, client->conn);
BT_GATTC_FEATURE_INVOKE_CB(client, on_connected, client->ins, GATT_STATUS_SUCCESS, client->conn);
}
static void feature_on_disconnected(void* conn_handle, bt_address_t* addr)
@ -463,7 +455,7 @@ static void feature_on_disconnected(void* conn_handle, bt_address_t* addr)
client->services_discovering = false;
discovery_database_clear(client);
BT_GATTC_FEATURE_INVOKE_CB(client, on_disconnected, client->ins, BT_STATUS_SUCCESS,
BT_GATTC_FEATURE_INVOKE_CB(client, on_disconnected, client->ins, GATT_STATUS_SUCCESS,
client->conn);
}
@ -474,6 +466,8 @@ static void feature_get_attribute_cb(bt_instance_t* ins, bt_status_t status,
gatt_client_t* client;
gatt_attr_desc_t* attr_node;
gatt_service_t* service;
size_t service_count;
const gatt_service_t** service_array;
(void)ins;
@ -504,10 +498,23 @@ static void feature_get_attribute_cb(bt_instance_t* ins, bt_status_t status,
free(user_data);
client->services_discovering = false;
service_count = bt_list_length(client->services_db);
service_array = calloc(service_count, sizeof(gatt_service_t*));
if (!service_array) {
BT_GATTC_FEATURE_INVOKE_CB(client, on_discovered,
client->ins, GATT_STATUS_FAILURE,
client->conn, NULL, 0);
return;
}
gatt_service_list_to_array(client->services_db, service_array);
BT_GATTC_FEATURE_INVOKE_CB(client, on_discovered,
client->ins, GATT_STATUS_SUCCESS,
client->conn, NULL);
client->conn, service_array, service_count);
free(service_array);
return;
}
@ -530,9 +537,6 @@ static void feature_get_attribute_cb(bt_instance_t* ins, bt_status_t status,
if (service) {
bt_list_add_tail(client->services_db, service);
}
BT_GATTC_FEATURE_INVOKE_CB(client, on_discovered, client->ins, BT_STATUS_SUCCESS,
client->conn, service);
}
free(user_data);
@ -553,7 +557,7 @@ static void feature_on_discovered(void* conn_handle, gatt_status_t status,
if (status != GATT_STATUS_SUCCESS) {
client->services_discovering = false;
BT_GATTC_FEATURE_INVOKE_CB(client, on_discovered, client->ins, status,
client->conn, NULL);
client->conn, NULL, 0);
return;
}
@ -584,7 +588,7 @@ static void feature_on_discovered(void* conn_handle, gatt_status_t status,
client->services_discovering = false;
BT_GATTC_FEATURE_INVOKE_CB(client, on_discovered,
client->ins, GATT_STATUS_FAILURE,
client->conn, NULL);
client->conn, NULL, 0);
return;
}
@ -787,7 +791,6 @@ bt_status_t bt_gattc_feature_create_client_async(bt_instance_t* ins, bt_address_
goto fail;
}
memcpy(&client->addr, addr, sizeof(bt_address_t));
client->ins = ins;
memcpy(&client->callbacks, callbacks, callbacks->size);
@ -838,7 +841,7 @@ static void delete_client_cb(bt_instance_t* ins, bt_status_t status, void* userd
user_ud = client->delete_client_ctx.delete_userdata;
conn_handle = client->conn;
if (status == BT_STATUS_SUCCESS && g_gatt_client_list) {
if (g_gatt_client_list) {
bt_list_remove(g_gatt_client_list, client);
if (!bt_list_length(g_gatt_client_list)) {
@ -851,15 +854,15 @@ static void delete_client_cb(bt_instance_t* ins, bt_status_t status, void* userd
user_cb(ins, status, conn_handle, user_ud);
}
bt_status_t bt_gattc_feature_delete_client_async(bt_instance_t* ins, bt_address_t* addr,
bt_status_t bt_gattc_feature_delete_client_async(bt_instance_t* ins, gattc_handle_t conn_handle,
bt_gattc_feature_delete_client_cb_t cb, void* userdata)
{
gatt_client_t* client;
if (!ins || !addr || !cb)
if (!ins || !conn_handle)
return BT_STATUS_PARM_INVALID;
client = find_client_by_addr(addr);
client = find_client_by_conn(conn_handle);
if (!client)
return BT_STATUS_PARM_INVALID;

View File

@ -223,6 +223,7 @@ bool advertiser_data_add_service_data(advertiser_data_t* ad,
}
memcpy(p, data, len);
sdata->len += len;
bt_list_add_tail(ad->data, sdata);
return true;

View File

@ -88,12 +88,13 @@ static const char* show_ad_type_desc(uint8_t type)
static void advertiser_data_info(adv_data_t* ad)
{
if (ad->len < 1) {
if (!ad || ad->len < 1) {
syslog(LOG_ERR, "Invalid params, ad(%p)", ad);
return;
}
syslog(4, "AdvType:(%s)\n", show_ad_type_desc(ad->type));
lib_dumpbuffer("AdvData:", ad->data, ad->len - 1);
BT_DUMPBUFFER("AdvData:", ad->data, ad->len - 1);
switch (ad->type) {
case BT_AD_FLAGS:

View File

@ -138,10 +138,6 @@ static void euv_close_callback(uv_handle_t* hdl)
#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);
@ -203,16 +199,6 @@ int euv_pipe_read_start(euv_pipe_t* handle, uint16_t read_size, euv_read_cb read
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;
@ -246,12 +232,6 @@ int euv_pipe_read_stop(euv_pipe_t* handle)
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;
@ -262,6 +242,11 @@ int euv_pipe_read_stop(euv_pipe_t* handle)
return 0;
}
if (uv_is_closing((uv_handle_t*)&handle->cli_pipe)) {
BT_LOGE("%s, uv_is_closing", __func__);
return 0;
}
return uv_read_stop((uv_stream_t*)&handle->cli_pipe);
}
@ -495,14 +480,13 @@ errout_with_handle:
return NULL;
}
void euv_pipe_close_with_cb(euv_pipe_t* handle, euv_close_cb cb)
void euv_pipe_close(euv_pipe_t* handle)
{
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;
@ -525,11 +509,6 @@ void euv_pipe_close_with_cb(euv_pipe_t* handle, euv_close_cb cb)
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) {

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,6 +56,11 @@ typedef struct {
uv_sem_t signal;
} signal_msg_t;
typedef struct {
thread_loop_work_t work;
uv_sem_t signal;
} signal_work_t;
#if defined(ANDROID)
#define LOOP_THREAD_STACK_SIZE 40960
#else
@ -179,7 +184,7 @@ int thread_loop_run(uv_loop_t* loop, bool start_thread, const char* name)
uv_thread_options_t options = {
UV_THREAD_HAS_STACK_SIZE | UV_THREAD_HAS_PRIORITY,
LOOP_THREAD_STACK_SIZE,
CONFIG_BLUETOOTH_SERVICE_LOOP_THREAD_PRIORITY
CONFIG_BLUETOOTH_SERVICE_LOOP_THREAD_PRIORITY + 1
};
ret = uv_thread_create_ex(&priv->thread, &options, thread_schedule_loop, (void*)loop);
if (ret != 0) {
@ -218,8 +223,10 @@ void thread_loop_exit(uv_loop_t* loop)
uv_sem_wait(&priv->exited);
uv_sem_destroy(&priv->exited);
} else {
uv_run(loop, UV_RUN_ONCE);
(void)uv_loop_close(loop);
if (!uv_loop_is_close(loop)) {
uv_run(loop, UV_RUN_ONCE);
(void)uv_loop_close(loop);
}
}
uv_mutex_lock(&priv->msg_lock);
@ -335,3 +342,48 @@ void do_in_thread_loop_sync(uv_loop_t* loop, thread_func_t func, void* data)
uv_sem_wait(&msg.signal);
uv_sem_destroy(&msg.signal);
}
static void work_sync_cb(uv_work_t* req)
{
signal_work_t* work = req->data;
assert(work);
if (work->work.work_cb)
work->work.work_cb(&work->work, work->work.userdata);
}
static void after_work_sync_cb(uv_work_t* req, int status)
{
signal_work_t* work = req->data;
assert(status == 0);
assert(work);
if (work->work.after_work_cb)
work->work.after_work_cb(&work->work, work->work.userdata);
uv_sem_post(&work->signal);
}
void thread_loop_work_sync(uv_loop_t* loop, void* user_data, thread_work_cb_t work_cb,
thread_after_work_cb_t after_work_cb)
{
signal_work_t* work = (signal_work_t*)calloc(1, sizeof(signal_work_t));
if (work == NULL)
return;
work->work.userdata = user_data;
work->work.work_cb = work_cb;
work->work.after_work_cb = after_work_cb;
work->work.work.data = work;
uv_sem_init(&work->signal, 0);
if (uv_queue_work(loop, &work->work.work, work_sync_cb, after_work_sync_cb) != 0) {
syslog(LOG_DEBUG, "%s uv_queue_work failed", __func__);
goto exit;
}
uv_sem_wait(&work->signal);
exit:
uv_sem_destroy(&work->signal);
free(work);
}

View File

@ -82,29 +82,248 @@ extern "C" {
#define BT_AD_FLAG_BREDR_NOT_SUPPORT 4
#define BT_AD_FLAG_DUAL_MODE 8
/**
* @cond
*/
typedef struct adv_data {
uint8_t len;
uint8_t type;
uint8_t data[0];
} adv_data_t;
/**
* @endcond
*/
typedef struct advertiser_data_ advertiser_data_t;
/**
* @brief Advertising data dump callback function.
*
* Function prototype for dumping advertising data in string format.
*
* @param str - Null-terminated string to dump.
*/
typedef void (*ad_dump_cb_t)(const char* str);
/**
* @brief Dump advertising data.
*
* Parses the advertising data and outputs it using the provided dump callback.
*
* @param data - Pointer to the advertising data buffer.
* @param len - Length of the advertising data buffer.
* @param dump - Callback function to output the parsed data.
* @return true - Parsing and dumping was successful.
* @return false - Parsing failed.
*
* **Example:**
* @code
static void on_scan_result_cb(bt_scanner_t* scanner, ble_scan_result_t* result)
{
PRINT_ADDR("ScanResult ------[%s]------", &result->addr);
PRINT("AddrType:%d", result->addr_type);
PRINT("Rssi:%d", result->rssi);
PRINT("Type:%d", result->adv_type);
advertiser_data_dump((uint8_t*)result->adv_data, result->length, NULL);
PRINT("\n");
}
* @endcode
*/
bool advertiser_data_dump(uint8_t* data, uint16_t len, ad_dump_cb_t dump);
/**
* @brief Create a new advertiser data object.
*
* Allocates and initializes a new advertiser data object.
*
* @return advertiser_data_t* - Pointer to the new advertiser data object; NULL on failure.
*
* **Example:**
* @code
advertiser_data_t* ad = advertiser_data_new();
if (ad == NULL) {
// Handle allocation failure
}
* @endcode
*/
advertiser_data_t* advertiser_data_new(void);
/**
* @brief Free an advertiser data object.
*
* Frees the memory associated with an advertiser data object.
*
* @param ad - Pointer to the advertiser data object to free.
*
* **Example:**
* @code
advertiser_data_free(ad);
* @endcode
*/
void advertiser_data_free(advertiser_data_t* ad);
/**
* @brief Build the advertising data buffer.
*
* Constructs the advertising data buffer from the advertiser data object.
*
* @param ad - Pointer to the advertiser data object.
* @param[out] len - Pointer to store the length of the advertising data buffer.
* @return uint8_t* - Pointer to the advertising data buffer; NULL on failure.
*
* **Note:** The returned buffer should be freed by the caller when no longer needed.
*
* **Example:**
* @code
uint16_t len;
uint8_t* data = advertiser_data_build(ad, &len);
if (data != NULL) {
// Use the advertising data buffer
free(data);
}
* @endcode
*/
uint8_t* advertiser_data_build(advertiser_data_t* ad, uint16_t* len);
/**
* @brief Set the device name in advertising data.
*
* Sets the local device name to be included in the advertising data.
*
* @param ad - Pointer to the advertiser data object.
* @param name - Null-terminated string containing the device name.
*
* **Example:**
* @code
advertiser_data_set_name(ad, "My Device");
* @endcode
*/
void advertiser_data_set_name(advertiser_data_t* ad, const char* name);
/**
* @brief Set the advertising flags.
*
* Sets the advertising flags to be included in the advertising data.
*
* @param ad - Pointer to the advertiser data object.
* @param flags - Advertising flags, see BT_AD_FLAG_* definitions.
*
* **Example:**
* @code
advertiser_data_set_flags(ad, BT_AD_FLAG_GENERAL_DISCOVERABLE | BT_AD_FLAG_BREDR_NOT_SUPPORT);
* @endcode
*/
void advertiser_data_set_flags(advertiser_data_t* ad, uint8_t flags);
/**
* @brief Set the GAP appearance.
*
* Sets the GAP appearance value to be included in the advertising data.
*
* @param ad - Pointer to the advertiser data object.
* @param appearance - Appearance value, see GAP Appearance Values.
*
* **Example:**
* @code
advertiser_data_set_appearance(ad, 0x03C0); // HID Generic
* @endcode
*/
void advertiser_data_set_appearance(advertiser_data_t* ad, uint16_t appearance);
/**
* @brief Add custom data to advertising data.
*
* Adds a custom AD structure to the advertising data.
*
* @param ad - Pointer to the advertiser data object.
* @param type - AD type, see BT_AD_* definitions.
* @param data - Pointer to the data payload.
* @param len - Length of the data payload.
*
* **Example:**
* @code
uint8_t custom_data[] = {0x01, 0x02, 0x03};
advertiser_data_add_data(ad, BT_AD_MANUFACTURER_DATA, custom_data, sizeof(custom_data));
* @endcode
*/
void advertiser_data_add_data(advertiser_data_t* ad, uint8_t type, uint8_t* data, uint8_t len);
/**
* @brief Remove custom data from advertising data.
*
* Removes a custom AD structure from the advertising data.
*
* @param ad - Pointer to the advertiser data object.
* @param type - AD type, see BT_AD_* definitions.
* @param data - Pointer to the data payload.
* @param len - Length of the data payload.
*
* **Example:**
* @code
advertiser_data_remove_data(ad, BT_AD_MANUFACTURER_DATA, custom_data, sizeof(custom_data));
* @endcode
*/
void advertiser_data_remove_data(advertiser_data_t* ad, uint8_t type, uint8_t* data, uint8_t len);
/**
* @brief Add manufacturer-specific data to advertising data.
*
* Adds manufacturer-specific data to the advertising data.
*
* @param ad - Pointer to the advertiser data object.
* @param manufacture_id - Manufacturer ID assigned by the Bluetooth SIG.
* @param data - Pointer to the manufacturer-specific data.
* @param length - Length of the manufacturer-specific data.
*
* **Example:**
* @code
uint8_t manuf_data[] = {0x12, 0x34, 0x56};
advertiser_data_add_manufacture_data(ad, 0x038F, manuf_data, sizeof(manuf_data)); // 0x038F is Xiaomi Inc.
* @endcode
*/
void advertiser_data_add_manufacture_data(advertiser_data_t* ad,
uint16_t manufacture_id,
uint8_t* data, uint8_t length);
/**
* @brief Add a service UUID to advertising data.
*
* Adds a service UUID to the advertising data.
*
* @param ad - Pointer to the advertiser data object.
* @param uuid - Pointer to the UUID to add, see @ref bt_uuid_t.
* @return true - UUID added successfully.
* @return false - Failed to add UUID.
*
* **Example:**
* @code
bt_uuid_t service_uuid;
bt_uuid_from_string("0000180D-0000-1000-8000-00805F9B34FB", &service_uuid); // Heart Rate Service
advertiser_data_add_service_uuid(ad, &service_uuid);
* @endcode
*/
bool advertiser_data_add_service_uuid(advertiser_data_t* ad, const bt_uuid_t* uuid);
/**
* @brief Add service data to advertising data.
*
* Adds service-specific data associated with a service UUID to the advertising data.
*
* @param ad - Pointer to the advertiser data object.
* @param uuid - Pointer to the UUID of the service, see @ref bt_uuid_t.
* @param data - Pointer to the service data payload.
* @param len - Length of the service data payload.
* @return true - Service data added successfully.
* @return false - Failed to add service data.
*
* **Example:**
* @code
bt_uuid_t service_uuid;
bt_uuid_from_string("0000180F-0000-1000-8000-00805F9B34FB", &service_uuid); // Battery Service
uint8_t battery_level = 85; // 85%
advertiser_data_add_service_data(ad, &service_uuid, &battery_level, 1);
* @endcode
*/
bool advertiser_data_add_service_data(advertiser_data_t* ad,
const bt_uuid_t* uuid,
uint8_t* data, uint8_t len);

View File

@ -32,6 +32,10 @@ extern "C" {
#include "callbacks_list.h"
#include "uv_thread_loop.h"
/**
* @cond
*/
#ifndef BTSYMBOLS
#define BTSYMBOLS(s) s
#endif
@ -56,17 +60,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;
@ -233,16 +226,10 @@ typedef enum {
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 */
@ -441,10 +428,6 @@ enum {
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);
@ -487,13 +470,11 @@ typedef struct bt_instance {
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;
@ -515,60 +496,224 @@ typedef struct bt_instance {
} bt_instance_t;
/**
* @brief Create bluetooth client instance
* @endcond
*/
/**
* @brief Allocate memory
*
* This function pointer allocates a size of memory and is pointed to the allocated memory by *data
*
* @param data - pointer of the pointer to the allocated memory
* @param size - size of the memory to be allocated
* @return bool.
*
* **Example:**
* @code
static bool bt_socket_allocator(void** data, uint32_t size)
{
*data = zalloc(size);
if (!(*data))
return false;
return true;
}
* @endcode
*/
typedef bool (*bt_allocator_t)(void** data, uint32_t size);
/**
* @brief hci event callback.
*
* This function pointer is triggered when hci event is received.
*
* @param hci_event - pointer of hci event(specified by vendor).
* @param context - user context.
* @return void.
*
* **Example:**
* @code
static void bt_hci_event_callback(bt_hci_event_t* hci_event, void* context)
{
BT_LOGD("%s, evt_code:0x%x, len:%d", __func__, hci_event->evt_code,
hci_event->length);
// Handle Context.
}
* @endcode
*/
typedef void (*bt_hci_event_callback_t)(bt_hci_event_t* hci_event, void* context);
/**
* @brief Create bluetooth instance
*
* @return bt_instance_t* - ins on success, NULL on failure.
*
* **Example:**
* @code
bt_instance_t* bluetooth_get_instance(void)
{
bt_instance_t* bluetooth_ins = bluetooth_find_instance(getpid());
if (bluetooth_ins == NULL)
return bluetooth_create_instance();
else
return bluetooth_ins;
}
* @endcode
*/
bt_instance_t* BTSYMBOLS(bluetooth_create_instance)(void);
/**
* @brief Get bluetooth client instance, If it does not exist, an instance is created
* @brief Get bluetooth instance, If it does not exist, an instance is created
*
* @return bt_instance_t* - ins if exist or create success, NULL, if create fail.
*
* **Example:**
* @code
bt_instance_t* bluetooth_get_instance(void)
{
bt_instance_t* bluetooth_ins = bluetooth_find_instance(getpid());
if (bluetooth_ins == NULL)
return bluetooth_create_instance();
else
return bluetooth_ins;
}
* @endcode
*/
bt_instance_t* BTSYMBOLS(bluetooth_get_instance)(void);
/**
* @brief Find bluetooth client instance
* @brief Find bluetooth instance
*
* @return bt_instance_t* - ins if exist, NULL otherwise.
*
* **Example:**
* @code
bt_instance_t* bluetooth_get_instance(void)
{
bt_instance_t* bluetooth_ins = bluetooth_find_instance(getpid());
if (bluetooth_ins == NULL)
return bluetooth_create_instance();
else
return bluetooth_ins;
}
* @endcode
*/
bt_instance_t* BTSYMBOLS(bluetooth_find_instance)(pid_t pid);
/**
* @brief Get profile proxy
*
* @param ins - bluetooth client instance.
* @param ins - bluetooth instance.
* @param id - profile ID.
* @return void* - profile proxy.
*
* **Example:**
* @code
static bool bt_socket_allocator(void** data, uint32_t size)
{
*data = zalloc(size);
if (!(*data))
return false;
return true;
}
* @endcode
*/
void* BTSYMBOLS(bluetooth_get_proxy)(bt_instance_t* ins, enum profile_id id);
/**
* @brief Delete client instance
*
* @param ins - bluetooth client instance.
* @param ins - bluetooth instance.
*
* **Example:**
* @code
int main(int argc, char** argv) {
g_app_ins = bluetooth_create_instance();
while(1) {
// Handle events
}
bluetooth_delete_instance(g_app_ins);
}
* @endcode
*/
void BTSYMBOLS(bluetooth_delete_instance)(bt_instance_t* ins);
/**
* @brief Start profile service
*
* @param ins - bluetooth client instance.
* @param ins - bluetooth instance.
* @param id - profile ID.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
int leac_command_init(void* handle)
{
bt_status_t ret;
ret = bluetooth_start_service(handle, PROFILE_LEAUDIO_CLIENT);
if (ret != BT_STATUS_SUCCESS) {
PRINT("%s, failed ret:%d", __func__, ret);
return ret;
}
lea_client_callbacks = bt_lea_client_register_callbacks(handle, &lea_client_cbs);
return 0;
}
* @endcode
*/
bt_status_t BTSYMBOLS(bluetooth_start_service)(bt_instance_t* ins, enum profile_id id);
/**
* @brief Stop profile service
*
* @param ins - bluetooth client instance.
* @param id -profile ID.
* @param ins - bluetooth instance.
* @param id - profile ID.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
void leac_command_uninit(void* handle)
{
bt_status_t ret;
bt_lea_client_unregister_callbacks(handle, lea_client_callbacks);
ret = bluetooth_stop_service(handle, PROFILE_LEAUDIO_CLIENT);
if (ret != BT_STATUS_SUCCESS) {
PRINT("%s, failed ret:%d", __func__, ret);
}
}
* @endcode
*/
bt_status_t BTSYMBOLS(bluetooth_stop_service)(bt_instance_t* ins, enum profile_id id);
/**
* @brief Set external uv loop
*
* This function drops external UV_loop into bluetooth instance.
*
* @param ins - bluetooth instance.
* @param ext_loop - external uv loop.
* @return bool - true on success, false on failure.
*
* **Example:**
* @code
bool bluetooth_set_external_uv(bt_instance_t* ins, uv_loop_t* ext_loop)
{
BT_SOCKET_INS_VALID(ins, false);
ins->external_loop = ext_loop;
return true;
}
* @endcode
*/
bool BTSYMBOLS(bluetooth_set_external_uv)(bt_instance_t* ins, uv_loop_t* ext_loop);
/*
@ -592,6 +737,23 @@ bt_instance_t* bluetooth_create_async_instance(uv_loop_t* loop, bt_ipc_connected
*/
void bluetooth_delete_async_instance(bt_instance_t* ins);
/**
* @brief get 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_get_async_instance(uv_loop_t* loop, bt_ipc_connected_cb_t connected, bt_ipc_disconnected_cb_t disconnected, void* user_data);
/**
* @brief Find bluetooth instance
*
* @return bt_instance_t* - ins if exist, NULL otherwise.
*/
bt_instance_t* BTSYMBOLS(bluetooth_find_async_instance)(pid_t pid);
#ifdef __cplusplus
}
#endif

View File

@ -21,6 +21,9 @@
#include "bt_addr.h"
#include "bt_device.h"
/**
* @cond
*/
/**
* @brief A2DP audio state
*/
@ -29,23 +32,63 @@ typedef enum {
A2DP_AUDIO_STATE_STOPPED,
A2DP_AUDIO_STATE_STARTED,
} a2dp_audio_state_t;
/**
* @endcond
*/
/**
* @brief A2DP connection state changed callback
* @brief Callback for A2DP connection state changed.
*
* @param cookie - callback cookie.
* @param addr - address of peer A2DP device.
* @param state - connection state.
* There are four states for A2DP connection, namely DISCONNECTED, CONNECTING,
* CONNECTED, and DISCONNECTING. During the initialization phase of the A2DP,
* it is necessary to register callback functions. This callback is triggered
* when there is a change in the state of the A2DP connection.
*
* Stable States:
* DISCONNECTED: The initial state.
* CONNECTED: The A2DP connection is established.
* Transient states:
* CONNECTING: The A2DP connection is being established.
* DISCONNECTING: The A2DP connection is being terminated.
*
* @param cookie - Callback cookie.
* @param addr - The Bluetooth address of the peer device.
* @param state - A2DP profile connection state.
*
* **Example:**
* @code
static void on_connection_state_changed_cb(void* cookie, bt_address_t* addr, profile_connection_state_t state)
{
printf("A2DP connection state is: %d", state);
}
* @endcode
*/
typedef void (*a2dp_connection_state_callback)(void* cookie, bt_address_t* addr,
profile_connection_state_t state);
/**
* @brief A2DP audio connection state changed callback
* @brief Callback for A2DP audio state changed.
*
* @param cookie - callback cookie.
* @param addr - address of peer A2DP device.
* @param state - audio connection state.
* There are three states for A2DP audio, namely SUSPEND, STOPPED,
* and STARTED. It is important to note that a callback function
* is triggered whenever a change occurs in the audio state.
*
* Stable States:
* SUSPEND: The stream is suspended.
* STOPPED: The stream is stopped.
* STARTED: The stream is started.
*
* @param cookie - Callback cookie.
* @param addr - The Bluetooth address of the peer device.
* @param state - A2DP audio connection state.
*
* **Example:**
* @code
static void on_audio_state_changed_cb(void* cookie, bt_address_t* addr, a2dp_audio_state_t state)
{
printf("A2DP audio state is: %d", state);
}
* @endcode
*/
typedef void (*a2dp_audio_state_callback)(void* cookie, bt_address_t* addr,
a2dp_audio_state_t state);

View File

@ -25,15 +25,30 @@ extern "C" {
#endif
/**
* @brief A2DP audio sink config changed callback
* @brief Callback for A2DP audio configuration.
*
* @param cookie - callback cookie.
* @param addr - address of peer A2DP source device.
* During the initialization process of the A2DP, callback functions are registered.
* This callbacks is triggered whenever a change occurs in the audio configuration
* of an A2DP connection.
*
* @param cookie - Callbacks cookie.
* @param addr - The Bluetooth address of the peer device.
*
* **Example:**
* @code
static void on_audio_config_changed_cb(void* cookie, bt_address_t* addr)
{
printf("A2DP audio sink configuration is changed");
}
* @endcode
*/
typedef void (*a2dp_audio_sink_config_callback)(void* cookie, bt_address_t* addr);
/**
* @brief A2DP sink callback structure
* @cond
*/
/**
* @brief A2DP Sink callback structure
*
*/
typedef struct {
@ -43,79 +58,209 @@ typedef struct {
a2dp_audio_state_callback audio_state_cb;
a2dp_audio_sink_config_callback audio_sink_config_cb;
} a2dp_sink_callbacks_t;
/**
* @endcond
*/
/**
* @brief Register callback functions to A2DP sink service
* @brief Register callback functions to A2DP Sink service.
*
* @param ins - bluetooth client instance.
* @param id - A2DP sink callback functions.
* @return void* - callbacks cookie.
* When initializing the A2DP Sink, an application should register callback functions
* to the A2DP Sink service, which includes a connection state callback function, an
* audio state callback function, and an audio sink configuration callback function.
* Subsequently, the A2DP Sink service will notify the application of any state
* changes via the registered callback functions.
*
* @param ins - Buetooth client instance.
* @param callbacks - A2DP Sink 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 a2dp_sink_callbacks_t a2dp_sink_cbs = {
sizeof(a2dp_sink_cbs),
a2dp_sink_connection_state_cb,
a2dp_sink_audio_state_cb,
a2dp_sink_audio_config_cb,
};
void a2dp_sink_init(void* ins)
{
static void* sink_cbks_cookie;
sink_cbks_cookie = bt_a2dp_sink_register_callbacks(ins, &a2dp_sink_cbs);
}
* @endcode
*/
void* BTSYMBOLS(bt_a2dp_sink_register_callbacks)(bt_instance_t* ins, const a2dp_sink_callbacks_t* callbacks);
/**
* @brief Unregister callback functions to a2dp sink service
* @brief Unregister callback functions from A2DP Sink service.
*
* @param ins - bluetooth client instance.
* @param id - callbacks cookie.
* @return true - on callback unregister success
* @return false - on callback cookie not found
* An application may use this interface to stop listening on the A2DP Sink
* callbacks and to release the associated resources.
*
* @param ins - Buetooth client instance.
* @param cookie - Callbacks cookie.
* @return true - Callback unregistration successful.
* @return false - Callback cookie not found or callback unregistration failed.
*
* **Example:**
* @code
static void* sink_cbks_cookie = bt_a2dp_sink_register_callbacks(ins, &a2dp_sink_cbs);
void a2dp_sink_uninit(void* ins)
{
bt_a2dp_sink_unregister_callbacks(ins, sink_cbks_cookie);
}
* @endcode
*/
bool BTSYMBOLS(bt_a2dp_sink_unregister_callbacks)(bt_instance_t* ins, void* cookie);
/**
* @brief Check A2DP sink is connected
* @brief Check if A2DP is already connected.
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP source device.
* @return true - connected.
* @return false - not connected.
* This function serves the purpose of verifying the connection status of A2DP.
* It is important to note that the A2DP profile is deemed connected solely when
* the A2DP Sink is either in the Opened or Started state.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @return true - A2DP Sink connected.
* @return false - A2DP Sink not connected.
*
* **Example:**
* @code
void a2dp_sink_connected(void* ins, bt_address_t* addr)
{
bool ret = bt_a2dp_sink_is_connected(ins, addr);
printf("A2DP sink is %s", ret? "connected" : "not connected");
}
* @endcode
*/
bool BTSYMBOLS(bt_a2dp_sink_is_connected)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Check A2DP sink is playing
* @brief Check if the stream is being transmitted.
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP source device.
* @return true - playing.
* @return false - not playing.
* This function is used to verify the streaming status of the A2DP Sink.
* The A2DP Sink can only be deemed as playing when it is in the Started
* state and the audio is also in the Started state.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @return true - Stream is being transmitted .
* @return false - No stream transmission.
*
* **Example**
* @code
void a2dp_sink_playing(void* ins, bt_address_t* addr)
{
bool ret = bt_a2dp_sink_is_playing(ins, addr);
printf("A2DP sink is %s", ret? "playing" : "not playing");
}
* @endcode
*/
bool BTSYMBOLS(bt_a2dp_sink_is_playing)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief get A2DP sink connection state
* @brief Obtain A2DP Sink connection state.
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP source device.
* @return profile_connection_state_t - connection state.
* There are four states for A2DP connection, namely DISCONNECTED, CONNECTING,
* CONNECTED, and DIACONNECTED. This function is used by the application of
* the A2DP Sink to obtain the current state of the A2DP profile connection.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @return profile_connection_state_t - A2DP profile connection state.
*
* **Example**
* @code
int get_state_cmd(void* ins, bt_address_t* addr)
{
int state = bt_a2dp_sink_get_connection_state(ins, addr);
printf("A2DP sink connection state is: %d", state);
return state;
}
* @endcode
*/
profile_connection_state_t BTSYMBOLS(bt_a2dp_sink_get_connection_state)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Establish connection with peer A2DP device
* @brief Establish connection with peer A2DP device.
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP source device.
* This function is used to establish an A2DP profile connection with a designated
* peer device. Following the successful creation of the A2DP connection, the A2DP
* Sink transitions to an Opened state and subsequently notifies the application of
* its CONNECTED state. Upon reception of audio data from the A2DP Source device,
* the A2DP Sink then proceeds to forward the audio data to the Media.
*
* @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
int a2dp_sink_connect(void* ins, bt_address_t* addr)
{
int ret = bt_a2dp_sink_connect(ins, addr);
printf("A2DP sink connect %s", ret ? "failed" : "success");
return ret;
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_a2dp_sink_connect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Disconnect from peer A2DP device
* @brief Disconnect from peer A2DP device.
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP source device.
* This function is utilized for the purpose of disconnecting an A2DP profile connection
* with a designated peer device. Upon successful disconnection of the A2DP connection,
* the A2DP Sink transitions into an Idle state and subsequently notifies the application
* of the DISCONNECTED state.
*
* @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
int a2dp_sink_disconnect(void* ins, bt_address_t* addr)
{
int ret = bt_a2dp_sink_disconnect(ins, addr);
printf("A2DP sink disconnect %s", ret ? "failed" : "success");
return ret;
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_a2dp_sink_disconnect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief set a peer A2DP source device as active device
/*
* @brief Set a peer A2DP Source device as active device.
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP source device.
* @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
int enable_source_device(void* ins, bt_address_t* addr)
{
int ret = bt_a2dp_sink_set_active_device(ins, addr);
return ret;
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_a2dp_sink_set_active_device)(bt_instance_t* ins, bt_address_t* addr);

View File

@ -26,13 +26,28 @@ extern "C" {
#endif
/**
* @brief A2DP audio source config changed callback
* @brief Callback for A2DP audio configuration.
*
* @param cookie - callback cookie.
* @param addr - address of peer A2DP sink device.
* During the initialization process of the A2DP, callback functions are registered.
* This callbacks is triggered whenever a change occurs in the audio configuration
* of an A2DP connection.
*
* @param cookie - Callback cookie.
* @param addr - The Bluetooth address of the peer device.
*
* **Example:**
* @code
static void on_audio_config_changed_cb(void* cookie, bt_address_t* addr)
{
printf("A2DP audio source configuration is changed");
}
* @endcode
*/
typedef void (*a2dp_audio_source_config_callback)(void* cookie, bt_address_t* addr);
/**
* @cond
*/
/**
* @brief A2DP source callback structure
*
@ -44,87 +59,227 @@ typedef struct {
a2dp_audio_state_callback audio_state_cb;
a2dp_audio_source_config_callback audio_source_config_cb;
} a2dp_source_callbacks_t;
/**
* @endcond
*/
/**
* @brief Register callback functions to A2DP source service
* @brief Register callback functions to A2DP Source service.
*
* @param ins - bluetooth client instance.
* @param id - A2DP source callback functions.
* @return void* - callbacks cookie.
* When the A2DP Source is initialized, an application registers various callback
* functions to the A2DP Source service, such as the connection state callback function,
* audio state callback function, and audio source configuration callback function.
* The A2DP Source service will notify the application of any state changes via the
* registered callback functions.
*
* @param ins - Bluetooth client instance.
* @param callbacks - A2DP Source callback functions.
* @return void* - Callbacks cookie, if the callback is registered successfuly.
* NULL if the callback is already registered or registration fails.
*
* **Example:**
* @code
static const a2dp_source_callbacks_t a2dp_src_cbs = {
sizeof(a2dp_src_cbs),
a2dp_src_connection_state_cb,
a2dp_src_audio_state_cb,
a2dp_src_audio_source_config_cb,
};
void a2dp_source_uninit(void* ins)
{
static void* src_cbks_cookie;
src_cbks_cookie = bt_a2dp_source_register_callbacks(ins, &a2dp_src_cbs);
}
* @endcode
*/
void* BTSYMBOLS(bt_a2dp_source_register_callbacks)(bt_instance_t* ins, const a2dp_source_callbacks_t* callbacks);
/**
* @brief Unregister callback functions to A2DP source service
* @brief Unregister callback functions to A2DP Source service.
*
* @param ins - bluetooth client instance.
* @param id - callbacks cookie.
* @return true - on callback unregister success.
* @return false - on callback cookie not found.
* An application may use this interface to stop listening on the A2DP Source
* 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
static void* src_cbks_cookie = bt_a2dp_source_register_callbacks(ins, &a2dp_src_cbs);
void a2dp_source_uninit(void* ins)
{
bt_a2dp_source_unregister_callbacks(ins, src_cbks_cookie);
}
* @endcode
*/
bool BTSYMBOLS(bt_a2dp_source_unregister_callbacks)(bt_instance_t* ins, void* cookie);
/**
* @brief Check A2DP source is connected
* @brief Check if A2DP is already connected.
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @return true - connected.
* @return false - not connected.
* This function serves the purpose of verifying the connection status of A2DP.
* It is important to note that the A2DP profile is deemed connected solely when
* the A2DP Source is either in the Opened or Started state.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @return true - A2DP Source connected.
* @return false - A2DP Source not connected.
*
* **Example:**
* @code
void a2dp_source_connected(void* ins, bt_address_t* addr)
{
bool ret = bt_a2dp_source_is_connected(ins, addr);
printf("A2DP source is %s", ret? "connected" : "not connected");
}
* @endcode
*/
bool BTSYMBOLS(bt_a2dp_source_is_connected)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Check A2DP source is playing
* @brief Check if the stream is being transmitted.
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @return true - playing.
* @return false - not playing.
* This function is used to verify the streaming status of the A2DP Source.
* The A2DP Source can only be deemed as playing when it is in the Started
* state and the audio is also in the Started state.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @return true - Stream is being transmitted.
* @return false - No stream transmission.
*
* **Example**
* @code
void a2dp_source_playing(void* ins, bt_address_t* addr)
{
bool ret = bt_a2dp_source_is_playing(ins, addr);
printf("A2DP source is %s", ret? "playing" : "not playing");
}
* @endcode
*/
bool BTSYMBOLS(bt_a2dp_source_is_playing)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief get A2DP source connection state
* @brief Obtain A2DP Source connection state.
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @return profile_connection_state_t - connection state.
* There are four states for A2DP connection, namely DISCONNECTED, CONNECTING,
* CONNECTED, and DIACONNECTED. This function is used by the application of
* the A2DP Source to obtain the current state of the A2DP profile connection.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @return profile_connection_state_t - A2DP profile connection state.
*
* **Example**
* @code
int get_state_cmd(void* ins, bt_address_t* addr)
{
int state = bt_a2dp_source_get_connection_state(ins, addr);
printf("A2DP source connection state is: %d", state);
return state;
}
* @endcode
*/
profile_connection_state_t BTSYMBOLS(bt_a2dp_source_get_connection_state)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Establish connection with peer A2DP device
* @brief Establish connection with peer A2DP device.
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* This function is used to establish an A2DP profile connection with a designated
* peer device. Upon successful establishment of the A2DP connection, the A2DP Source
* transitions to an Opened state and notifies the application of its CONNECTED status.
* Upon receipt of audio data from the media, the A2DP Source subsequently relays the
* audio data to the A2DP Sink.
*
* @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
int a2dp_source_connect(void* ins, bt_address_t* addr)
{
int ret = bt_a2dp_source_connect(ins, &addr);
printf("A2DP source connect %s", ret ? "failed" : "success");
return ret;
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_a2dp_source_connect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Disconnect from peer A2DP device
* @brief Disconnect from peer A2DP device.
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* This function is used to remove an A2DP profile connection with a specific peer device. Once
* the A2DP connection is removed, the A2DP Source turns into the Idle state and reports the
* DISCONNECTED state to the application.
*
* @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
int a2dp_source_disconnect(void* ins, bt_address_t* addr)
{
int ret = bt_a2dp_source_disconnect(ins, addr);
printf("A2DP source disconnect %s", ret ? "failed" : "success");
return ret;
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_a2dp_source_disconnect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief set a peer A2DP sink device as silence device
* @brief Set a peer A2DP Sink device as silence device.
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @param silence - True, switch to silence mode to keep this device inactive.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example**
* @code
int disable_sink_device(void* ins, bt_address_t* addr, bool silence)
{
int ret = bt_a2dp_source_set_silence_device(ins, addr, silence);
return ret;
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_a2dp_source_set_silence_device)(bt_instance_t* ins, bt_address_t* addr, bool silence);
/**
* @brief set a peer A2DP sink device as active device
* @brief Set a peer A2DP Sink device as active device.
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @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
int enable_sink_device(void* ins, bt_address_t* addr)
{
int ret = bt_a2dp_source_set_active_device(ins, addr);
return ret;
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_a2dp_source_set_active_device)(bt_instance_t* ins, bt_address_t* addr);

View File

@ -598,6 +598,12 @@ if (bt_adapter_disable(ins) == BT_STATUS_SUCCESS) {
*/
bt_status_t BTSYMBOLS(bt_adapter_disable)(bt_instance_t* ins);
/**
* @brief Disable bluetooth adapter safely
*
* @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_adapter_disable_safe)(bt_instance_t* ins);
/**
@ -650,6 +656,17 @@ bt_device_type_t BTSYMBOLS(bt_adapter_get_type)(bt_instance_t* ins);
*/
bt_status_t BTSYMBOLS(bt_adapter_set_discovery_filter)(bt_instance_t* ins);
/**
* @brief Start device limited discovery.
*
* Initiates the device limited discovery process to find nearby Bluetooth devices.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param timeout - Maximum amount of time to perform discovery (Time = N * 1.28s, Range: 1.28s to 61.44s).
* @return bt_status_t - BT_STATUS_SUCCESS on success; a negative error code on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_start_limited_discovery)(bt_instance_t* ins, uint32_t timeout);
/**
* @brief Start device discovery.
*
@ -670,8 +687,6 @@ if (bt_adapter_start_discovery(ins, 10) == BT_STATUS_SUCCESS) {
*/
bt_status_t BTSYMBOLS(bt_adapter_start_discovery)(bt_instance_t* ins, uint32_t timeout);
bt_status_t BTSYMBOLS(bt_adapter_start_limited_discovery)(bt_instance_t* ins, uint32_t timeout);
/**
* @brief Cancel device discovery.
*
@ -1135,6 +1150,19 @@ bt_status_t BTSYMBOLS(bt_adapter_le_enable_key_derivation)(bt_instance_t* ins,
*/
bt_status_t BTSYMBOLS(bt_adapter_le_add_whitelist)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Add a device to the BLE whitelist with specified address type.
*
* Adds a device address to the BLE whitelist, allowing the caller to specify the address type
* (e.g., public or random address).
*
* @param ins Bluetooth client instance, see @ref bt_instance_t.
* @param addr Address of the device to add, see @ref bt_address_t.
* @param type Address type of the device, see @ref ble_addr_type_t.
* @return bt_status_t BT_STATUS_SUCCESS on success; a negative error code on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_le_add_whitelist_with_type)(bt_instance_t* ins, bt_address_t* addr, ble_addr_type_t type);
/**
* @brief Remove a device from the BLE whitelist.
*
@ -1171,8 +1199,71 @@ bt_status_t BTSYMBOLS(bt_adapter_set_afh_channel_classification)(bt_instance_t*
*/
bt_status_t BTSYMBOLS(bt_adapter_set_auto_sniff)(bt_instance_t* ins, bt_auto_sniff_params_t* params);
// async
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_ASYNC
#include "bt_async.h"
typedef void (*bt_register_callback_cb_t)(bt_instance_t* ins, bt_status_t status, void* cookie, void* userdata);
typedef void (*bt_adapter_get_state_cb_t)(bt_instance_t* ins, bt_status_t status, bt_adapter_state_t state, void* userdata);
typedef void (*bt_adapter_get_device_type_cb_t)(bt_instance_t* ins, bt_status_t status, bt_device_type_t type, void* userdata);
typedef void (*bt_adapter_get_address_cb_t)(bt_instance_t* ins, bt_status_t status, bt_address_t* addr, void* userdata);
typedef void (*bt_adapter_get_io_capability_cb_t)(bt_instance_t* ins, bt_status_t status, bt_io_capability_t cap, void* userdata);
typedef void (*bt_adapter_get_scan_mode_cb_t)(bt_instance_t* ins, bt_status_t status, bt_scan_mode_t mode, void* userdata);
typedef void (*bt_adapter_get_devices_cb_t)(bt_instance_t* ins, bt_status_t status, bt_address_t* addr, int num, void* userdata);
typedef void (*bt_adapter_get_uuids_cb_t)(bt_instance_t* ins, bt_status_t status, bt_uuid_t* uuids, uint16_t size, void* userdata);
typedef void (*bt_adapter_get_le_address_cb_t)(bt_instance_t* ins, bt_status_t status, bt_address_t* addr, ble_addr_type_t type, void* userdata);
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_status_t bt_adapter_unregister_callback_async(bt_instance_t* ins, void* cookie, bt_bool_cb_t cb, void* userdata);
bt_status_t bt_adapter_enable_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_disable_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_enable_le_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_disable_le_async(bt_instance_t* ins, bt_status_cb_t cb, void* 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_status_t bt_adapter_is_le_enabled_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
bt_status_t bt_adapter_get_type_async(bt_instance_t* ins, bt_device_type_cb_t get_dtype_cb, void* userdata);
bt_status_t bt_adapter_set_discovery_filter_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_start_discovery_async(bt_instance_t* ins, uint32_t timeout, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_cancel_discovery_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_is_discovering_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
bt_status_t bt_adapter_get_address_async(bt_instance_t* ins, bt_address_cb_t cb, void* userdata);
bt_status_t bt_adapter_set_name_async(bt_instance_t* ins, const char* name, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_get_name_async(bt_instance_t* ins, bt_string_cb_t get_name_cb, void* userdata);
bt_status_t bt_adapter_get_uuids_async(bt_instance_t* ins, bt_uuids_cb_t get_uuids_cb, void* 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_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_status_t bt_adapter_set_device_class_async(bt_instance_t* ins, uint32_t cod, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_get_device_class_async(bt_instance_t* ins, bt_u32_cb_t get_cod_cb, void* 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_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_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_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_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_status_t bt_adapter_get_le_io_capability_async(bt_instance_t* ins, bt_u32_cb_t get_le_ioc_cb, void* 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_status_t bt_adapter_set_le_address_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* 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_status_t bt_adapter_set_le_appearance_async(bt_instance_t* ins, uint16_t appearance, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_get_le_appearance_async(bt_instance_t* ins, bt_u16_cb_t cb, void* 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_status_t bt_adapter_le_add_whitelist_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* 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_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_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_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_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);
bt_status_t bt_adapter_disconnect_all_devices_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata);
bt_status_t bt_adapter_is_support_bredr_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
bt_status_t bt_adapter_is_support_le_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
bt_status_t bt_adapter_is_support_leaudio_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
#endif /* CONFIG_BLUETOOTH_FRAMEWORK_ASYNC */
#ifdef __cplusplus
}
#endif
#endif /* __BT_ADAPTER_H__ */

View File

@ -69,7 +69,6 @@ typedef struct bt_le_addr {
*/
bool bt_addr_is_empty(const bt_address_t* addr);
/**
* @brief Set a Bluetooth address to empty.
*
@ -85,7 +84,6 @@ bool bt_addr_is_empty(const bt_address_t* addr);
*/
void bt_addr_set_empty(bt_address_t* addr);
/**
* @brief Compare two Bluetooth addresses.
*
@ -106,7 +104,6 @@ void bt_addr_set_empty(bt_address_t* addr);
*/
int bt_addr_compare(const bt_address_t* a, const bt_address_t* b);
/**
* @brief Convert a Bluetooth address to a string.
*
@ -128,7 +125,6 @@ int bt_addr_compare(const bt_address_t* a, const bt_address_t* b);
*/
int bt_addr_ba2str(const bt_address_t* addr, char* str);
/**
* @brief Convert a string to a Bluetooth address.
*
@ -149,7 +145,6 @@ int bt_addr_ba2str(const bt_address_t* addr, char* str);
*/
int bt_addr_str2ba(const char* str, bt_address_t* addr);
/**
* @brief Get the string representation of a Bluetooth address.
*
@ -190,7 +185,6 @@ char* bt_addr_bastr(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.
*

View File

@ -21,9 +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
@ -34,6 +31,9 @@
#define AVRCP_ATTR_MAX_PLAYING_TIMES_LEN 0
#define AVRCP_ATTR_MAX_COVER_ART_HANDLE_LEN 0
/**
* @cond
*/
typedef enum {
PASSTHROUGH_CMD_ID_SELECT,
PASSTHROUGH_CMD_ID_UP,
@ -111,10 +111,10 @@ typedef enum {
PLAY_STATUS_ERROR,
} avrcp_play_status_t;
enum {
typedef enum {
AVRCP_CAPABILITY_ID_COMPANY_ID = 2,
AVRCP_CAPABILITY_ID_EVENTS_SUPPORTED,
};
} avrcp_capability_id_t;
typedef enum {
NOTIFICATION_EVT_PALY_STATUS_CHANGED = 0x01,
@ -156,6 +156,7 @@ typedef enum {
AVRCP_ATTR_PLAYING_TIME_MS,
AVRCP_ATTR_COVER_ART_HANDLE
} avrcp_media_attr_type_t;
/**
* @endcond
*/

View File

@ -21,6 +21,7 @@
/**
* @cond
*/
typedef struct {
uint32_t attr_id;
uint16_t chr_set;
@ -44,6 +45,7 @@ typedef struct {
avrcp_connection_state_callback connection_state_cb;
avrcp_get_element_attribute_cb get_element_attribute_cb;
} avrcp_control_callbacks_t;
/**
* @endcond
*/
@ -105,24 +107,15 @@ void avrcp_control_uninit(void* ins)
bool BTSYMBOLS(bt_avrcp_control_unregister_callbacks)(bt_instance_t* ins, void* cookie);
/**
* @brief Get element attributes from AVRCP Target.
* @brief Get element attribute from peer device.
*
* 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.
* @param addr - Remote BT address.
* @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);
@ -137,12 +130,41 @@ bt_status_t BTSYMBOLS(bt_avrcp_control_get_element_attributes)(bt_instance_t* in
*/
bt_status_t BTSYMBOLS(bt_avrcp_control_send_passthrough_cmd)(bt_instance_t* ins, bt_address_t* addr, uint8_t cmd, uint8_t state);
/**
* @brief Get unit info from peer device.
*
* @param ins - Bluetooth client instance.
* @param addr - Remote BT address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_avrcp_control_get_unit_info)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Get subunit info from peer device.
*
* @param ins - Bluetooth client instance.
* @param addr - Remote BT address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_avrcp_control_get_subunit_info)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Get playback state from peer device.
*
* @param ins - Bluetooth client instance.
* @param addr - Remote BT address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
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);
/**
* @brief Register notification to peer device, this interface is used for pts.
*
* @param ins - Bluetooth client instance.
* @param addr - Remote BT address.
* @param event - Notification event.
* @param interval - Notification interval.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_avrcp_control_register_notification)(bt_instance_t* ins, bt_address_t* addr, uint8_t event, uint32_t interval);
#endif /* __BT_AVRCP_CONTROL_H__ */

View File

@ -1,13 +1,6 @@
#ifndef __INCLUDE_BT_CONFIG_H
#define __INCLUDE_BT_CONFIG_H
// Platform: 32-bit or 64-bit
#if defined(CONFIG_ARCH_ARM64) || defined(ARCH_X86_64) || defined(ANDROID) || (!defined(CONFIG_SIM_M32) && defined(CONFIG_ARCH_SIM))
#define CONFIG_CPU_BIT64 1
#elif defined(ARCH_ARM) || defined(ARCH_X86) || defined(__NuttX__)
#define CONFIG_CPU_BIT32 1
#endif
// Configuration of Bluetooth Framework/Service/Stack
#if defined(__NuttX__)
@ -62,7 +55,7 @@
#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,14 +72,14 @@
#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_LOG_LEVEL 7
#define CONFIG_BLUETOOTH_SERVICE_HCI_UART_NAME "/dev/ttyHCI0"
#define CONFIG_BLUETOOTH_STACK_BREDR_BLUELET 1
#define CONFIG_BLUETOOTH_STACK_LE_BLUELET 1
@ -99,17 +92,14 @@
#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_BLUETOOTH_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
//#define CONFIG_RPMSG_UART 1
/********************* O95 Project Only *********************/
#if defined(ANDROID_12)
@ -117,7 +107,7 @@
#define CONFIG_BLUETOOTH_RPMSG_CPUNAME "ap"
/********************* O61 Project Only *********************/
#elif defined(ANDROID_14)
#elif defined(ANDROID_14) || defined(ANDROID_15)
// Socket: RPMsg
#define CONFIG_BLUETOOTH_RPMSG_CPUNAME "cp"
// A2DP
@ -131,7 +121,14 @@
#endif
// ############################################################################
// Platform: 32-bit or 64-bit
#if defined(CONFIG_ARCH_ARM64) || defined(ARCH_X86_64) || defined(ANDROID) || (!defined(CONFIG_SIM_M32) && defined(CONFIG_ARCH_SIM)) || defined(CONFIG_ARCH_X86_64)
#define CONFIG_CPU_BIT64 1
#elif defined(ARCH_ARM) || defined(ARCH_X86)
#define CONFIG_CPU_BIT32 1
#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

@ -755,6 +755,25 @@ if (bt_device_connect(ins, &addr) == BT_STATUS_SUCCESS) {
*/
bt_status_t BTSYMBOLS(bt_device_connect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Connect to peer device with specific Profiles. And open reconnect method.
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.if addr is NULL, connect last device in bonded list.
* @param transport - transport type (0:BLE, 1:BREDR).
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
if (bt_device_background_connect(ins, &addr, BT_TRANSPORT_BREDR) == BT_STATUS_SUCCESS) {
// connection initiated successfully
} else {
// Handle error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_device_background_connect)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport);
/**
* @brief Disconnect from a remote device.
*
@ -775,6 +794,25 @@ if (bt_device_disconnect(ins, &addr) == BT_STATUS_SUCCESS) {
*/
bt_status_t BTSYMBOLS(bt_device_disconnect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Disconnect specific prfoiles.
*
* @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.
*
* **Example:**
* @code
if (bt_device_background_disconnect(ins, &addr, BT_TRANSPORT_BREDR) == BT_STATUS_SUCCESS) {
// Disconnection initiated successfully
} else {
// Handle error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_device_background_disconnect)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport);
/**
* @brief Connect to a remote LE device.
*
@ -847,29 +885,65 @@ void BTSYMBOLS(bt_device_connect_all_profile)(bt_instance_t* ins, bt_address_t*
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.
* @brief Enable connection enhanced mode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param mode - enhanced mode.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value 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.
* @brief Disable connection enhanced mode
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param mode - enhanced mode.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_disable_enhanced_mode)(bt_instance_t* ins, bt_address_t* addr, bt_enhanced_mode_t mode);
// async
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_ASYNC
#include "bt_async.h"
typedef void (*bt_device_get_bond_state_cb_t)(bt_instance_t* ins, bt_status_t status, bond_state_t bstate, void* userdata);
typedef void (*bt_device_get_address_type_cb_t)(bt_instance_t* ins, bt_status_t status, ble_addr_type_t atype, void* 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_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_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_status_t bt_device_get_name_async(bt_instance_t* ins, bt_address_t* addr, bt_string_cb_t cb, void* 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_status_t bt_device_get_uuids_async(bt_instance_t* ins, bt_address_t* addr, bt_uuids_cb_t cb, void* 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_status_t bt_device_get_rssi_async(bt_instance_t* ins, bt_address_t* addr, bt_s8_cb_t cb, void* 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_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_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_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_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_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_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_status_t bt_device_connect_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* userdata);
bt_status_t bt_device_disconnect_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* 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_status_t bt_device_disconnect_le_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* 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_status_t bt_device_connect_all_profile_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* 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_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_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_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_status_t bt_device_cancel_bond_async(bt_instance_t* ins, bt_address_t* addr, bt_status_cb_t cb, void* 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_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_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_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_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_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_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);
#endif
#ifdef __cplusplus
}
#endif

View File

@ -23,8 +23,6 @@ extern "C" {
#include <stdbool.h>
#include <stdint.h>
#include "bt_uuid.h"
/**
* @cond
*/
@ -147,22 +145,23 @@ 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_AUTO_RSP_CCC_READ, 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(BT_UUID_DECLARE_16(0x2902), _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)
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(0x2904), GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, _value, _length, _handle)
/**
* @endcond

View File

@ -133,10 +133,11 @@ typedef void (*bt_gattc_feature_delete_client_cb_t)(bt_instance_t* ins, gatt_sta
* @param ins Bluetooth instance.
* @param status Operation status.
* @param conn_handle Connection handle.
* @param service Retrieved service (single entry).
* @param services Array of discovered services (pointer array).
* @param count Number of services in the array.
*/
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);
const gatt_service_t* services[], size_t count);
/**
* @brief Read characteristic callback.
@ -232,13 +233,13 @@ bt_status_t bt_gattc_feature_create_client_async(bt_instance_t* ins, bt_address_
/**
* @brief Delete GATT client.
* @param ins Bluetooth instance.
* @param addr Remote device address.
* @param cb Delete completion callback.
* @param userdata User context.
* @param ins Bluetooth instance.
* @param conn_handle Connection handle (from create).
* @param cb Async call status 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_status_t bt_gattc_feature_delete_client_async(bt_instance_t* ins, gattc_handle_t conn_handle,
bt_gattc_feature_delete_client_cb_t cb, void* userdata);
/**

View File

@ -28,6 +28,10 @@ extern "C" {
#include "bt_uuid.h"
#include <stddef.h>
/**
* @cond
*/
#ifndef BTSYMBOLS
#define BTSYMBOLS(s) s
#endif
@ -43,20 +47,300 @@ typedef struct {
} gatt_attr_desc_t;
/**
* @endcond
*/
/**
* @brief callback for connected as GATT client.
*
* This callback is triggered when gattc connected. BT Service use this callback to notify the application calling
* bt_gattc_connect that gattc connection has been established.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param addr - remote device address.
* @return void.
*
* **Example:**
* @code
static void connect_callback(void* conn_handle, bt_address_t* addr)
{
gattc_device_t* device = find_gattc_device(conn_handle);
assert(device);
memcpy(&device->remote_address, addr, sizeof(bt_address_t));
device->conn_state = CONNECTION_STATE_CONNECTED;
PRINT_ADDR("gattc_connect_callback, addr:%s", addr);
}
* @endcode
*/
typedef void (*gattc_connected_cb_t)(gattc_handle_t conn_handle, bt_address_t* addr);
/**
* @brief callback for disconnected as GATT client.
*
* This callback is triggered when gattc disconnected. BT Service use this callback to notify the application that
* the gattc connection is destroyed.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param addr - remote device address.
* @return void.
*
* **Example:**
* @code
static void disconnect_callback(void* conn_handle, bt_address_t* addr)
{
gattc_device_t* device = find_gattc_device(conn_handle);
assert(device);
device->conn_state = CONNECTION_STATE_DISCONNECTED;
PRINT_ADDR("gattc_disconnect_callback, addr:%s", addr);
}
* @endcode
*/
typedef void (*gattc_disconnected_cb_t)(gattc_handle_t conn_handle, bt_address_t* addr);
/**
* @brief callback for GATT client execute Services discover operation.
*
* This callback is triggered when application initiating service discovery procedure to peer GATT server.
* BT Service use this callback to report the result of attributes.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param status - bt_status_t - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @param uuid - uuid of the attribute. uuid == NULL or uuid->type == 0 means discovery procedure completed.
* @param start_handle - start handle of Primary services(Secondary services).
* @param end_handle - end handle of Primary services(Secondary services).
* @return void.
*
* **Example:**
* @code
static void discover_callback(void* conn_handle, gatt_status_t status, bt_uuid_t* uuid, uint16_t start_handle, uint16_t end_handle)
{
PRINT("gattc_discover_callback result, attr_handle: 0x%04x - 0x%04x", start_handle, end_handle);
}
* @endcode
*/
typedef void (*gattc_discover_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, bt_uuid_t* uuid, uint16_t start_handle, uint16_t end_handle);
/**
* @brief callback for GATT client excute Exchange MTU operation.
*
* This callback is triggered when application initiating Exchange MTU procedure to peer GATT server.
* BT Service use this callback to Report the results of MTU negotiation.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param status - bt_status_t - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @param mtu - negotiated MTU.
* @return void.
*
* **Example:**
* @code
static void mtu_updated_callback(void* conn_handle, gatt_status_t status, uint32_t mtu)
{
gattc_device_t* device = find_gattc_device(conn_handle);
assert(device);
if (status == GATT_STATUS_SUCCESS) {
device->gatt_mtu = mtu;
}
PRINT("gattc_mtu_updated_callback, status:%d, mtu:%" PRIu32, status, mtu);
}
* @endcode
*/
typedef void (*gattc_mtu_updated_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, uint32_t mtu);
/**
* @brief callback for GATT client excute attribute read operation.
*
* This callback is triggered when application initiating read procedure to peer GATT server.
* BT Service use this callback to Report the attribute value of corresponding attribute.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param status - bt_status_t - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @param attr_handle - attribute handle.
* @param value - attribute value.
* @param length - attribute value length.
* @return void.
*
* **Example:**
* @code
static void read_complete_callback(void* conn_handle, gatt_status_t status, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
PRINT("gattc connection read complete, handle 0x%" PRIx16 ", status:%d", attr_handle, status);
}
* @endcode
*/
typedef void (*gattc_read_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, uint16_t attr_handle, uint8_t* value, uint16_t length);
/**
* @brief callback for GATT client excute attribute read operation.
*
* This callback is triggered when application initiating write procedure to peer GATT server.
* BT Service use this callback to Report the status of write procedure to corresponding attribute.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param status - bt_status_t - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @param attr_handle - attribute handle.
* @return void.
*
* **Example:**
* @code
static void write_complete_callback(void* conn_handle, gatt_status_t status, uint16_t attr_handle)
{
if (status != GATT_STATUS_SUCCESS) {
PRINT("gattc connection write failed, handle 0x%" PRIx16 ", status:%d", attr_handle, status);
return;
}
if (throughtput_cursor) {
throughtput_cursor--;
} else {
PRINT("gattc connection write complete, handle 0x%" PRIx16 ", status:%d", attr_handle, status);
}
}
* @endcode
*/
typedef void (*gattc_write_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, uint16_t attr_handle);
/**
* @brief callback for GATT client excute enable/disable cccd operation.
*
* This callback is triggered when application initiating enable/disable to corresponding cccd.
* BT Service use this callback to Report the value of corresponding cccd.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param status - bt_status_t - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @param attr_handle - attribute handle.
* @param enable - enable/disable flag.
* @return void.
*
* **Example:**
* @code
static void subscribe_complete_callback(void* conn_handle, gatt_status_t status, uint16_t attr_handle, bool enable)
{
PRINT("gattc connection subscribe complete, handle 0x%" PRIx16 ", status:%d, enable:%d", attr_handle, status, enable);
}
* @endcode
*/
typedef void (*gattc_subscribe_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, uint16_t attr_handle, bool enable);
/**
* @brief callback for GATT client recv notification/indication from peer GATT server.
*
* This callback is triggered when Peer GATT Server initiating notify/indicate procedure. BT Service use this callback
* to Report the notify/indicate value received.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param attr_handle - attribute handle.
* @param value - notify/indicate value.
* @param length - notify/indicate value length.
* @return void.
*
* **Example:**
* @code
static void notify_received_callback(void* conn_handle, uint16_t attr_handle,
uint8_t* value, uint16_t length)
{
PRINT("gattc connection receive notify, handle 0x%" PRIx16, attr_handle);
}
* @endcode
*/
typedef void (*gattc_notify_cb_t)(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length);
/**
* @brief callback for GATT client 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 conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param tx_phy - current Tx PHY.
* @param rx_phy - current Rx PHY.
* @return void.
*
* **Example:**
* @code
static void phy_read_callback(void* conn_handle, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy)
{
PRINT("gattc read phy complete, tx:%d, rx:%d", tx_phy, rx_phy);
}
* @endcode
*/
typedef void (*gattc_phy_read_cb_t)(gattc_handle_t conn_handle, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy);
/**
* @brief callback for GATT client 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 conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param status - bt_status_t - 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* conn_handle, gatt_status_t status, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy)
{
PRINT("gattc_phy_updated_callback, status:%d, tx:%d, rx:%d", status, tx_phy, rx_phy);
}
* @endcode
*/
typedef void (*gattc_phy_updated_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy);
/**
* @brief callback for GATT client execute read RSSI of remote device.
*
* This callback is triggered when application initiating read remote RSSI procedure. BT Service use this callback to
* Report the RSSI of remote device.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param status - bt_status_t - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @param RSSI - value of remote RSSI.
* @return void.
*
* **Example:**
* @code
static void rssi_read_callback(void* conn_handle, gatt_status_t status, int32_t rssi)
{
PRINT("gattc read rssi complete, status:%d, rssi:%" PRIi32, status, rssi);
}
* @endcode
*/
typedef void (*gattc_rssi_read_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, int32_t rssi);
/**
* @brief callback for GATT client execute connnection parameter update operation.
*
* This callback is triggered when application initiating connnection parameter update procedure. BT Service use this
* callback to Report the connection parameter.
*
* @param conn_handle - gattc connection handle(void*). The Caller use gattc_connection_t as real parameter.
* @param status - bt_status_t - GATT_STATUS_SUCCESS on success, and other error codes on failure.
* @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_updated_callback(void* conn_handle, bt_status_t status, uint16_t connection_interval,
uint16_t peripheral_latency, uint16_t supervision_timeout)
{
PRINT("gattc connection paramter updated, status:%d, interval:%" PRIu16 ", latency:%" PRIu16 ", timeout:%" PRIu16,
status, connection_interval, peripheral_latency, supervision_timeout);
}
* @endcode
*/
typedef void (*gattc_connection_parameter_updated_cb_t)(gattc_handle_t conn_handle, bt_status_t status, uint16_t connection_interval,
uint16_t peripheral_latency, uint16_t supervision_timeout);
/**
* @cond
*/
typedef struct {
uint32_t size;
gattc_connected_cb_t on_connected;
@ -73,24 +357,368 @@ typedef struct {
gattc_connection_parameter_updated_cb_t on_conn_param_updated;
} gattc_callbacks_t;
/**
* @endcond
*/
/**
* @brief create a gatt client.
*
* This function is used to create a gatt client.
*
* @param ins - Bluetooth client instance.
* @param phandle - pointer of gattc connection handle(void*).
* @param callbacks - gattc callback table.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_create_connect(handle, &g_gattc_devies[conn_id].handle, &gattc_cbs) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_create_connect)(bt_instance_t* ins, gattc_handle_t* phandle, gattc_callbacks_t* callbacks);
/**
* @brief delete a gatt client.
*
* This function is used to delete a gatt client.
*
* @param conn_handle - gattc connection handle(void*).
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_delete_connect(g_gattc_devies[conn_id].handle) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_delete_connect)(gattc_handle_t conn_handle);
/**
* @brief create a ATT bearer with peer device.
*
* This function is used to establish a ATT bearer.
*
* @param conn_handle - gattc connection handle(void*).
* @param addr - peer bluetooth 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_gattc_connect(g_gattc_devies[conn_id].handle, &addr, BT_LE_ADDR_TYPE_UNKNOWN) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_connect)(gattc_handle_t conn_handle, bt_address_t* addr, ble_addr_type_t addr_type);
/**
* @brief dicconnect ATT bearer.
*
* This function is used to initiate a disconnection.
*
* @param conn_handle - gattc connection handle(void*).
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_disconnect(g_gattc_devies[conn_id].handle) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_disconnect)(gattc_handle_t conn_handle);
/**
* @brief discover all GATT services or service with specific UUIDs on peer GATT Server.
*
* This function is used to discover GATT services. If filter_uuid is NULL, all services will be discovered.
*
* @param conn_handle - gattc connection handle(void*).
* @param filter_uuid - UUID of service to be discovered. filter_uuid is NULL for discover all service of peer device
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_discover_service(g_gattc_devies[conn_id].handle, NULL) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_discover_service)(gattc_handle_t conn_handle, bt_uuid_t* filter_uuid);
/**
* @brief get attribute by specific Attribute handle.
*
* This function is used to get attribute by specific Attribute handle, which is stored after Discover Services procedure.
*
* @param conn_handle - gattc connection handle(void*).
* @param attr_handle - attribute handle being found.
* @param attr_desc - attribute structure(Type, handle, UUID, property). The desired result is stored in this pointer.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_get_attribute_by_handle(conn_handle, attr_handle, &attr_desc) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_get_attribute_by_handle)(gattc_handle_t conn_handle, uint16_t attr_handle, gatt_attr_desc_t* attr_desc);
/**
* @brief get attribute by specific UUID.
*
* This function is used to get attribute by specific handle, which is stored after Discover Services procedure.
*
* @param conn_handle - gattc connection handle(void*).
* @param start_handle - start of the Attribute handle range being found.
* @param end_handle - end of the Attribute handle range being found.
* @param attr_uuid - attribute UUID being found.
* @param attr_desc - attribute structure(Type, handle, UUID, property). The desired result is stored in this pointer.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_get_attribute_by_handle(conn_handle, start_handle, end_handle &attr_desc.uuid, &attr_desc) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_get_attribute_by_uuid)(gattc_handle_t conn_handle, uint16_t start_handle, uint16_t end_handle, bt_uuid_t* attr_uuid, gatt_attr_desc_t* attr_desc);
/**
* @brief read attribute value by specific handle.If This Attribute's permissions is readable
*
* This function is used to read a attribute value by specific handle. This function will initiate a ATT Read Request procedure.
*
* @param conn_handle - gattc connection handle(void*).
* @param attr_handle - attribute handle being read.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_read(g_gattc_devies[conn_id].handle, attr_handle) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_read)(gattc_handle_t conn_handle, uint16_t attr_handle);
/**
* @brief write data to a specific attribute. If This Attribute's permissions is Writable
*
* This function is used to write data to a specific attribute. This function will initiate a ATT write Request procedure.
*
* @param conn_handle - gattc connection handle(void*).
* @param attr_handle - attribute handle being written.
* @param value - data to be written.
* @param length - the length of value.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_write_without_response(g_gattc_devies[conn_id].handle, attr_handle, value, len) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_write)(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length);
/**
* @brief write data to a specific attribute. If Write Without Response flag of This Attribute's property is set to 1
*
* This function is used to write data to a specific attribute. This function will initiate a ATT write command procedure.
*
* @param conn_handle - gattc connection handle(void*).
* @param attr_handle - attribute handle being written.
* @param value - data to be written.
* @param length - the length of value.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_write_without_response(g_gattc_devies[conn_id].handle, attr_handle, value, len) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_write_without_response)(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length);
/**
* @brief Write data to a specific attribute (Signed Write Without Response).
*
* This function writes data to a specific attribute handle using the
* ATT "Signed Write Command" procedure. It should be used when the
* attribute's properties include the `GATT_PROPERTY_SIGNED_WRITE` flag.
*
* Unlike a normal Write Without Response, this procedure includes a
* signature to provide authentication of the write operation.
*
* @param conn_handle GATT client connection handle (void*).
* @param attr_handle Attribute handle being written.
* @param value Pointer to the buffer containing the data to write.
* @param length Length of the data buffer.
*
* @return bt_status_t
* - BT_STATUS_SUCCESS on success,
* - Other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_write_with_signed(g_gattc_devices[conn_id].handle,
attr_handle, value, len) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_write_with_signed)(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length);
/**
* @brief enable a centain CCCD(Client Characteristic Configuration Description).
*
* This function is used to enable CCCD. Once enabled, it can receive Indication and Notification
* from the Server successfully.
*
* @param conn_handle - gattc connection handle(void*).
* @param attr_handle - attribute handle of the characteristic you want to enable CCCD.
* @param ccc_value - bit 0 is used to enable Notification, bit 1 is used to enable Indication.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_subscribe(g_gattc_devies[conn_id].handle, attr_handle, ccc_value) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_subscribe)(gattc_handle_t conn_handle, uint16_t attr_handle, uint16_t ccc_value);
/**
* @brief disable a centain CCCD(Client Characteristic Configuration Description).
*
* This function is used to disable CCCD. Once disable, it cannot receive Indication and Notification
* from the Server.
*
* @param conn_handle - gattc connection handle(void*).
* @param attr_handle - attribute handle of the characteristic you want to disable CCCD.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_unsubscribe(g_gattc_devies[conn_id].handle, attr_handle) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_unsubscribe)(gattc_handle_t conn_handle, uint16_t attr_handle);
/**
* @brief exchange ATT_MTU.
*
* This function is used to initiate an ATT_MTU negotiation, which will initiate a Exchcange MTU procedure.
* In Bluetooth Core Spec, this procedure can be initiated once per connection. If it is initiated more than
* once, BT_STATUS_FAIL will be returned.
*
* @param conn_handle - gattc connection handle(void*).
* @param mtu - MTU size.
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_exchange_mtu(g_gattc_devies[conn_id].handle, mtu) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_exchange_mtu)(gattc_handle_t conn_handle, uint32_t mtu);
/**
* @brief Modify BLE connection parameters.
*
* This function is used to modify BLE connection parameters.
* Note: The following conditions must be met:
* min_interval <= max_interval.
* min_connection_event_length <= max_connection_event_length.
* timeout > (1 + latency) * max_interval * 2
*
* @param conn_handle - gattc connection handle(void*).
* @param min_interval - min connection interval(n * 1.25ms).
* @param max_interval - max connection interval(n * 1.25ms).
* @param latency - peripheral latency.
* @param timeout - supervision timeout(n * 10ms).
* @param min_connection_event_length - min connection event length(n * 0.625ms).
* @param max_connection_event_length - max connection event length(n * 0.625ms).
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_update_connection_parameter(g_gattc_devies[conn_id].handle, min_interval, max_interval, latency,
timeout, min_connection_event_length, max_connection_event_length)
!= BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_update_connection_parameter)(gattc_handle_t conn_handle, uint32_t min_interval, uint32_t max_interval,
uint32_t latency, uint32_t timeout, uint32_t min_connection_event_length,
uint32_t max_connection_event_length);
/**
* @brief read Tx & Rx PHY.
*
* This function is used to read PHY.(1M, 2M, Coded)
*
* @param conn_handle - gattc connection handle(void*).
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_read_phy(g_gattc_devies[conn_id].handle) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_read_phy)(gattc_handle_t conn_handle);
/**
* @brief update PHY.
*
* This function is used to update PHY type(1M, 2M, Coded).
*
* @param conn_handle - gattc connection handle(void*).
* @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_gattc_update_phy(g_gattc_devies[conn_id].handle, tx, rx) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
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);
/**
* @brief read RSSI.
*
* This function is used to read RSSI value.
*
* @param conn_handle - gattc connection handle(void*).
* @return bt_status_t - BT_STATUS_SUCCESS on success, and other error codes on failure.
*
* **Example:**
* @code
if (bt_gattc_read_rssi(g_gattc_devies[conn_id].handle) != BT_STATUS_SUCCESS) {
// Handle Error
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_gattc_read_rssi)(gattc_handle_t conn_handle);
// async

View File

@ -120,11 +120,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
*/

View File

@ -284,29 +284,6 @@ void hfp_ag_at_cmd_received_cb(void* cookie, bt_address_t* addr, const char* at_
*/
typedef void (*hfp_ag_at_cmd_received_callback)(void* cookie, bt_address_t* addr, const char* at_command);
/**
* @brief Callback for HFP AG received vendor specific AT command.
*
* This callback is used to notify the application of the vendor specific AT command. During
* HFP AG initialization, callback functions will be registered. This callback will be triggered
* when AG receives a vendor specific AT command.
*
* @param cookie - Callback cookie.
* @param addr - The Bluetooth address of the peer device.
* @param command - The prefix of the AT command.
* @param company_id - Bluetooth company ID.
* @param value - AT command value.
*
* **Example:**
* @code
void hfp_ag_vend_spec_at_cmd_received_cb(void* cookie, bt_address_t* addr, const char* command, uint16_t company_id, const char* value)
{
printf("hfp_ag_vend_spec_at_cmd_received_cb, command: %s, company_id: %d, value: %s\n", command, company_id, value);
}
* @endcode
*/
typedef void (*hfp_ag_vend_spec_at_cmd_received_callback)(void* cookie, bt_address_t* addr, const char* command, uint16_t company_id, const char* value);
/**
* @brief HFP CLCC command received callback
*
@ -343,6 +320,17 @@ typedef void (*hfp_ag_cind_cmd_received_callback)(void* cookie, bt_address_t* ad
* @cond
*/
/**
* @brief HFP vendor specific AT command received callback
*
* @param cookie - callback cookie.
* @param command - The prefix of the AT command.
* @param company_id - Bluetooth company ID.
* @param value - AT command value.
* @param addr - address of peer HF device.
*/
typedef void (*hfp_ag_vend_spec_at_cmd_received_callback)(void* cookie, bt_address_t* addr, const char* command, uint16_t company_id, const char* value);
/**
* @brief HFP AG callback structure
*
@ -407,7 +395,7 @@ void app_init_hfp_ag(bt_instance_t* ins)
else
printf("register callbacks success\n");
}
* @endcode
* @endcode
*/
void* BTSYMBOLS(bt_hfp_ag_register_callbacks)(bt_instance_t* ins, const hfp_ag_callbacks_t* callbacks);
@ -846,7 +834,7 @@ int app_send_specific_volume_control(bt_instance_t* ins, bt_address_t* addr);
bt_status_t BTSYMBOLS(bt_hfp_ag_volume_control)(bt_instance_t* ins, bt_address_t* addr, hfp_volume_type_t type, uint8_t volume);
/**
* @brief Send an AT Command to HF device.
* @brief Send an AT Command to HF device [Deprecated].
*
* This function is used to send specific AT commands to the specified HF device. The
* address parameter is used to specify the peer HF device.
@ -876,36 +864,6 @@ int app_send_specific_at_command(bt_instance_t* ins, bt_address_t* addr);
*/
bt_status_t BTSYMBOLS(bt_hfp_ag_send_at_command)(bt_instance_t* ins, bt_address_t* addr, const char* at_command);
/**
* @brief Send a vendor specific AT Command
*
* This function is used to send specific vendor AT commands to the specified HF device. The
* address parameter is used to specify the peer HF device.
*
* @param ins - The Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @param command - The prefix of the AT command to be send.
* @param value - The value of the AT command to be send.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
int app_send_specific_at_command(bt_instance_t* ins, bt_address_t* addr);
{
bt_status_t status;
char at_command[] = "+XIAOMI";
char value[] = "123456";
status = bt_hfp_ag_send_at_command(ins, addr, at_command, value);
if (status != BT_STATUS_SUCCESS)
printf("send AT command failed\n");
return status;
}
* @endcode
*/
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);
/**
* @brief Send CLCC Response
*
@ -950,6 +908,17 @@ bt_status_t BTSYMBOLS(bt_hfp_ag_send_clcc_response)(bt_instance_t* ins, bt_addre
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);
/**
* @brief Send vendor specific AT Command
*
* @param ins - bluetooth client instance.
* @param addr - address of peer HF device.
* @param command - the prefix of the AT command to be send.
* @param value - the value of the AT command to be send.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
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);
/**
* @brief Send CIND Response
*

View File

@ -69,6 +69,15 @@ typedef struct {
char name[HFP_NAME_DIGITS_MAX];
} hfp_current_call_t;
/**
* @brief HFP subscriber number service
*/
typedef enum {
HFP_HF_SERVICE_UNKNOWN = 0,
HFP_HF_SERVICE_VOICE,
HFP_HF_SERVICE_FAX,
} hfp_subscriber_number_service_t;
/**
* @endcond
*/
@ -387,8 +396,35 @@ void hfp_hf_callheld_cb(void* cookie, bt_address_t* addr, hfp_callheld_t callhel
* @endcode
*/
typedef void (*hfp_hf_callheld_callback)(void* cookie, bt_address_t* addr, hfp_callheld_t callheld);
typedef void (*hfp_hf_clip_callback)(void* cookie, bt_address_t* addr, const char* number, const char* name);
/**
* @brief HFP HF get subscriber number callback.
*
* @param cookie - callback cookie.
* @param addr - address of peer AG device.
* @param number - phone number.
* @param service - indicates which service this phone number relates to.
*/
typedef void (*hfp_hf_subscriber_number_callback)(void* cookie, bt_address_t* addr, const char* number, hfp_subscriber_number_service_t service);
/**
* @brief HFP HF +clip callback.
*
* @param cookie - callback cookie.
* @param addr - address of peer AG device.
* @param number - the number of call.
* @param name - the name of call.
*/
typedef void (*hfp_hf_clip_callback)(void* cookie, bt_address_t* addr, const char* number, const char* name);
/**
* @brief HFP HF query current calls callback.
*
* @param cookie - callback cookie.
* @param addr - address of peer AG device.
* @param num - number of current calls.
* @param calls - list of current calls.
*/
typedef void (*hfp_hf_query_current_calls_callback)(void* cookie, bt_address_t* addr, uint8_t num, hfp_current_call_t* calls);
/**
@ -1153,8 +1189,21 @@ int app_send_dtmf(bt_instance_t* ins, bt_address_t* addr, char dtmf);
*/
bt_status_t BTSYMBOLS(bt_hfp_hf_send_dtmf)(bt_instance_t* ins, bt_address_t* addr, char dtmf);
/**
* @brief Get Subscriber Number
*
* @param ins - bluetooth client instance.
* @param addr - address of peer AG device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_hfp_hf_get_subscriber_number)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Query Current Calls With Callback
*
* @param ins - bluetooth client instance.
* @param addr - address of peer AG device.
*/
bt_status_t BTSYMBOLS(bt_hfp_hf_query_current_calls_with_callback)(bt_instance_t* ins, bt_address_t* addr);
#ifdef __cplusplus

View File

@ -124,15 +124,14 @@ typedef enum {
* @endcond
*/
/**
* @brief HID device application 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
* is used to notify the HID device about the state transition in interaction
* with the remote HID host.
*
* @param cookie - `remote_callback_t*`.
* @param cookie - `remote_callback_t*`.
* See `bt_hid_device_register_callbacks`.
* @param state - New HID application state, see @ref hid_app_state_t.
*
@ -150,10 +149,10 @@ typedef void (*hidd_app_state_callback)(void* cookie, hid_app_state_t state);
* @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
* is used to notify the HID device about connection state changes with the remote
* HID host.
*
* @param cookie - `remote_callback_t*`.
* @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.
@ -175,7 +174,7 @@ typedef void (*hidd_connection_state_callback)(void* cookie, bt_address_t* addr,
*
* Callback function invoked when a GET_REPORT request is received from the remote HID host.
*
* @param cookie - `remote_callback_t*`.
* @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.
@ -199,7 +198,7 @@ typedef void (*hidd_get_report_callback)(void* cookie, bt_address_t* addr, uint8
*
* Callback function invoked when a SET_REPORT request is received from the remote HID host.
*
* @param cookie - `remote_callback_t*`.
* @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.
@ -223,7 +222,7 @@ typedef void (*hidd_set_report_callback)(void* cookie, bt_address_t* addr, uint8
*
* Callback function invoked when an INPUT report is received from the remote HID host.
*
* @param cookie - `remote_callback_t*`.
* @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.
@ -247,7 +246,7 @@ typedef void (*hidd_receive_report_callback)(void* cookie, bt_address_t* addr, u
*
* Callback function invoked when a virtual cable unplug request is received from the remote HID host.
*
* @param cookie - `remote_callback_t*`.
* @param cookie - `remote_callback_t*`.
* See `bt_hid_device_register_callbacks`.
* @param addr - Address of the peer device, see @ref bt_address_t.
*

View File

@ -26,6 +26,8 @@ extern "C" {
#define BTSYMBOLS(s) s
#endif
#define INVALID_L2CAP_LISTEN_ID 0xFFFF
enum {
LE_PSM_DYNAMIC_MIN = 0x0080,
LE_PSM_DYNAMIC_MAX = 0x00FF,
@ -50,16 +52,21 @@ typedef struct {
uint16_t mtu; /* Maximum Transmission Unit */
uint16_t le_mps; /* Maximum PDU payload Size for LE */
uint16_t init_credits; /* initial credits for LE */
uint16_t id; /* L2CAP Service socket id */
char proxy_name[16]; /* Proxy name */
} l2cap_config_option_t;
typedef struct {
bt_address_t addr;
bt_transport_t transport;
uint16_t cid; /* Channel id. */
uint16_t cid; /* Local channel id. */
uint16_t psm; /* Dynamic Service PSM */
uint16_t incoming_mtu; /* Incoming transmit MTU. */
uint16_t outgoing_mtu; /* outgoing transmit MTU */
const char* pty_name; /* pty device name, like "/dev/pts/0" */
uint16_t outgoing_mtu; /* Outgoing transmit MTU */
uint16_t id; /* Connected L2CAP Channel socket id */
// for L2CAP listen only.
uint16_t listen_id; /* New L2CAP Listen socket id, INVALID_L2CAP_LISTEN_ID indicates invalid */
char proxy_name[16]; /* Proxy name for server */
} l2cap_connect_params_t;
/**
@ -75,10 +82,10 @@ typedef void (*l2cap_connected_callback_t)(void* cookie, l2cap_connect_params_t*
*
* @param cookie - callbacks cookie, the return value of bt_l2cap_register_callbacks.
* @param addr - remote addr.
* @param cid - channel id.
* @param id - L2CAP service socket id, used to identify L2CAP service channel resource.
* @param reason - disconnect reason.
*/
typedef void (*l2cap_disconnected_callback_t)(void* cookie, bt_address_t* addr, uint16_t cid, uint32_t reason);
typedef void (*l2cap_disconnected_callback_t)(void* cookie, bt_address_t* addr, uint16_t id, uint32_t reason);
/**
* @brief L2CAP event callback structure
@ -95,7 +102,7 @@ typedef struct {
*
* @param ins - bluetooth client instance.
* @param callbacks - L2CAP callback functions.
* @return void* - callbacks cookie, NULL on failure.
* @return void* - L2CAP APP handle, NULL on failure.
*/
void* BTSYMBOLS(bt_l2cap_register_callbacks)(bt_instance_t* ins, const l2cap_callbacks_t* callbacks);
@ -103,36 +110,68 @@ void* BTSYMBOLS(bt_l2cap_register_callbacks)(bt_instance_t* ins, const l2cap_cal
* @brief Unregister L2CAP callback functions.
*
* @param ins - bluetooth client instance.
* @param cookie - callbacks cookie.
* @param handle - L2CAP APP handle.
* @return true - on callback unregister success
* @return false - on callback cookie not found
*/
bool BTSYMBOLS(bt_l2cap_unregister_callbacks)(bt_instance_t* ins, void* cookie);
bool BTSYMBOLS(bt_l2cap_unregister_callbacks)(bt_instance_t* ins, void* handle);
/**
* @brief Listen for a L2CAP connection request
* @param ins - bluetooth client instance.
* @param handle - L2CAP APP handle.
* @param option - L2CAP config option.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_l2cap_listen)(bt_instance_t* ins, l2cap_config_option_t* option);
bt_status_t BTSYMBOLS(bt_l2cap_listen)(bt_instance_t* ins, void* handle, l2cap_config_option_t* option);
/**
* @brief Request L2CAP connection to remote device
* @param ins - bluetooth client instance.
* @param handle - L2CAP APP handle.
* @param addr - remote addr.
* @param option - L2CAP config option.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_l2cap_connect)(bt_instance_t* ins, bt_address_t* addr, l2cap_config_option_t* option);
bt_status_t BTSYMBOLS(bt_l2cap_connect)(bt_instance_t* ins, void* handle, bt_address_t* addr, l2cap_config_option_t* option);
/**
* @brief Reqeust to disconnect a L2CAP channel
* @param ins - bluetooth client instance.
* @param cid - channel id.
* @param handle - L2CAP APP handle.
* @param id - Connected L2CAP Channel socket id.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_l2cap_disconnect)(bt_instance_t* ins, uint16_t cid);
bt_status_t BTSYMBOLS(bt_l2cap_disconnect)(bt_instance_t* ins, void* handle, uint16_t id);
/**
* @brief Stop L2CAP listen
*
* This function used to stop L2CAP listen rather than disconnect all conected
* L2CAP channels for a specific PSM.
*
* @param ins - bluetooth client instance.
* @param handle - L2CAP APP handle.
* @param psm - LE PSM used for listen.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* @note This function is only used for LE transport scenario.
*/
bt_status_t BTSYMBOLS(bt_l2cap_stop_listen)(bt_instance_t* ins, void* handle, uint16_t psm);
/**
* @brief Stop L2CAP listen with transport
*
* This function used to stop L2CAP listen rather than disconnect all conected
* L2CAP channels for a specific PSM.
*
* @param ins - bluetooth client instance.
* @param handle - L2CAP APP handle.
* @param transport - bt_transport_t, LE or BR/EDR.
* @param psm - PSM used for listen.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_l2cap_stop_listen_with_transport)(bt_instance_t* ins, void* handle, bt_transport_t transport, uint16_t psm);
#ifdef __cplusplus
}

View File

@ -25,6 +25,10 @@ extern "C" {
#define BTSYMBOLS(s) s
#endif
/**
* @cond
*/
/**
* @brief Advertising type
*
@ -88,23 +92,57 @@ enum {
typedef void bt_advertiser_t;
/**
* @brief Advertising start status callback, invoke on adverting start success or failure
* @endcond
*/
/**
* @brief Callback for advertising started notification.
*
* @param adv - advertiser handle.
* @param adv_id - advertiser ID.
* @param status - advertiser start status, BT_ADV_STATUS_SUCCESS on success.
* This callback is used to notify the application of the adverter handle, ID, and
* start status of the advertiser. It will be triggered in the following cases:
* 1. Advertiser ID allocates failed or the return value of the function "bt_sal_le_start_adv"
* is not "BT_STATUS_SUCCESS" within the advertiser starting event.
* 2. 1 second after the successful notification of the start of LE advertising to the
* Bluetooth protocol stack.
*
* @param adv - Notifies the allocated Advertiser handle.
* @param adv_id - Notifies the allocated Advertiser ID.
* @param status - Notifies the starting status of the advertiser. BT_ADV_STATUS_SUCCESS
* indicates that the advertiser has started successfully.
*
* **Example:**
* @code
void on_advertising_start(bt_advertiser_t* adv, uint8_t adv_id, uint8_t status)
{
printf("on_advertising_start, adv_id: %d, status: %d\n", adv_id, status);
}
* @endcode
*/
typedef void (*on_advertising_start_cb_t)(bt_advertiser_t* adv, uint8_t adv_id, uint8_t status);
/**
* @brief Advertising stopped notification
* @brief Callback for advertising stopped notification.
*
* @param adv - advertiser handle
* @param adv_id - advertiser ID.
* This callback is used to notify the application of the handle and ID corresponding to
* the stopped advertising.
*
* @param adv - Advertiser handle.
* @param adv_id - Advertiser ID.
*
* **Example:**
* @code
void on_advertising_stopped(bt_advertiser_t* adv, uint8_t adv_id)
{
printf("on_advertising_stopped, adv_id: %d\n", adv_id);
}
* @endcode
*/
typedef void (*on_advertising_stopped_cb_t)(bt_advertiser_t* adv, uint8_t adv_id);
/**
* @cond
*/
/**
* @brief Advertising callback functions structure
*
@ -130,16 +168,58 @@ typedef struct {
} ble_adv_params_t;
/**
* @brief Start LE advertising
* @endcond
*/
/**
* @brief Initate LE advertising.
*
* @param ins - bluetooth client instance.
* @param params - advertising parameter.
* @param adv_data - advertisement data.
* @param adv_len - length of advertisement data.
* @param scan_rsp_data - scan response data.
* @param scan_rsp_len - length of scan response data.
* @param cbs - advertiser callback functions.
* @return bt_advertiser_t* - advertiser handle.
* Before using this function to initiate LE advertising, the Bluetooth application
* should set appropriate LE advertising parameters, prepare advertising data and scan
* response data, and an advertising callback function. When using this function, the
* above content is passed as parameters, and an advertiser handle is returned to indicate
* the initiated advertising. With this handle, the Bluetooth application can disable the
* corresponding advertising at an appropriate time.
*
* @param ins - Bluetooth client instance.
* @param params - Advertising parameter.
* @param adv_data - Advertisement data.
* @param adv_len - Length of advertisement data.
* @param scan_rsp_data - Scan response data.
* @param scan_rsp_len - Length of scan response data.
* @param cbs - Advertiser callback functions.
* @return bt_advertiser_t* - Advertiser handle.
*
* **Example:**
* @code
bt_advertiser_t* adver;
void app_start_advertising(bt_instance_t* ins)
{
ble_adv_params_t params;
uint8_t adv_data[10];
uint8_t scan_rsp_data[10];
advertiser_callback_t cbs;
params.adv_type = BT_LE_ADV_IND;
params.own_addr_type = BT_LE_ADDR_TYPE_PUBLIC;
params.tx_power = -20;
params.interval = 100;
params.duration = 0;
params.channel_map = 7;
params.filter_policy = BT_LE_ADV_FILTER_WHITE_LIST_FOR_ALL;
memset(adv_data, 0, sizeof(adv_data));
memset(scan_rsp_data, 0, sizeof(scan_rsp_data));
cbs.size = sizeof(advertiser_callback_t);
cbs.on_advertising_start = on_advertising_start;
cbs.on_advertising_stopped = on_advertising_stopped;
adver = bt_le_start_advertising(ins, &params, adv_data, sizeof(adv_data), scan_rsp_data, sizeof(scan_rsp_data), &cbs);
}
* @endcode
*/
bt_advertiser_t* BTSYMBOLS(bt_le_start_advertising)(bt_instance_t* ins,
ble_adv_params_t* params,
@ -150,30 +230,87 @@ bt_advertiser_t* BTSYMBOLS(bt_le_start_advertising)(bt_instance_t* ins,
advertiser_callback_t* cbs);
/**
* @brief Stop LE advertising by advertiser handle
* @brief Stop LE advertising by advertiser handle.
*
* @param ins - bluetooth client instance.
* @param adver - advertiser handle.
* This function is used to stop the LE advertising indicated by the specified advertiser
* handle. Therefore, before using this function, the Bluetooth application should know
* the handle corresponding to the initiated advertising. When a Bluetooth application
* initiates an advertising, it will be informed of the advertiser handle.
*
* @param ins - Bluetooth client instance.
* @param adver - Advertiser handle.
*
* **Example:**
* @code
void app_stop_advertising(bt_instance_t* ins)
{
if(!adver)
return;
bt_le_stop_advertising(ins, adver);
}
* @endcode
*/
void BTSYMBOLS(bt_le_stop_advertising)(bt_instance_t* ins, bt_advertiser_t* adver);
/**
* @brief Stop LE advertising by adver id
* @brief Stop LE advertising by advertiser ID.
*
* @param ins - bluetooth client instance.
* @param adv_id - advertiser ID.
* This function is used to stop the LE advertising indicated by the specified advertiser ID.
* Therefore, before using this function, the Bluetooth application should know the ID
* corresponding to the initiated advertising. When a Bluetooth application successfully initiates
* an advertising, the advertiser ID will be informed through the "on_advertising_start_cb_t"
* callback function provided when the advertising is initiated by the application.
*
* @param ins - Bluetooth client instance.
* @param adv_id - Advertiser ID.
*
* **Example:**
* @code
void app_stop_advertising(bt_instance_t* ins, uint8_t adv_id)
{
bt_le_stop_advertising_id(ins, adv_id);
}
* @endcode
*/
void BTSYMBOLS(bt_le_stop_advertising_id)(bt_instance_t* ins, uint8_t adv_id);
/**
* @brief Check is advertising supported
* @brief Check if LE advertising is supported.
*
* @param ins - bluetooth client instance.
* @return true - support.
* @return false - not support.
* This function is used to check if the Bluetooth protocol stack supports LE advertising for
* Bluetooth applications.
*
* @param ins - Bluetooth client instance.
* @return bool - true represents support for LE advertising, while false represents non-support.
*
* **Example:**
* @code
void app_check_advertising_support(bt_instance_t* ins)
{
if(bt_le_advertising_is_supported(ins))
printf("advertising is supported\n");
else
printf("advertising is not supported\n");
}
* @endcode
*/
bool BTSYMBOLS(bt_le_advertising_is_supported)(bt_instance_t* ins);
// async
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_ASYNC
#include "bt_async.h"
typedef void (*bt_le_start_adv_callback_cb_t)(bt_instance_t* ins, bt_status_t status, void* adv, void* userdata);
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_status_t bt_le_stop_advertising_async(bt_instance_t* ins, bt_advertiser_t* adver, bt_status_cb_t cb, void* 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_status_t bt_le_advertising_is_supported_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
#endif // CONFIG_BLUETOOTH_FRAMEWORK_ASYNC
#ifdef __cplusplus
}
#endif

View File

@ -22,6 +22,10 @@ extern "C" {
#include <stdint.h>
#ifdef CONFIG_BLUETOOTH_STACK_LE_ZBLUE
#include <zephyr/bluetooth/bluetooth.h>
#endif
#include "bluetooth.h"
#include "bt_le_advertiser.h"
#ifndef BTSYMBOLS
@ -30,6 +34,10 @@ extern "C" {
#define BLE_SCAN_FILTER_UUID_MAX_NUM 2
/**
* @cond
*/
/**
* @brief Scan start status code
*
@ -41,7 +49,8 @@ enum {
BT_SCAN_STATUS_SCANNER_REG_NOMEM,
BT_SCAN_STATUS_SCANNER_EXISTED,
BT_SCAN_STATUS_SCANNER_NOT_FOUND,
BT_SCAN_STATUS_SCANNER_REMOVED
BT_SCAN_STATUS_SCANNER_REMOVED,
BT_SCAN_STATUS_INVALID_PARAMETER = 0xFF
};
/**
@ -54,19 +63,28 @@ enum {
BT_SCAN_MODE_LOW_LATENCY,
};
#define SCAN_MODE_LOW_POWER_INTERVAL 0x1000
#define SCAN_MODE_LOW_POWER_WINDOW 0x100
#define SCAN_MODE_BALANCED_INTERVAL 0x500
#define SCAN_MODE_BALANCED_WINDOW 0x140
#define SCAN_MODE_LOW_POWER_INTERVAL 0x3C0
#define SCAN_MODE_LOW_POWER_WINDOW 0x18
#define SCAN_MODE_BALANCED_INTERVAL 0x80
#define SCAN_MODE_BALANCED_WINDOW 0x20
#define SCAN_MODE_LOW_LATENCY_INTERVAL 0xA0
#define SCAN_MODE_LOW_LATENCY_WINDOW 0xA0
typedef void bt_scanner_t;
#ifdef CONFIG_BLUETOOTH_STACK_LE_ZBLUE
#define BT_LE_SCAN_TYPE_PASSIVE BT_LE_SCAN_TYPE_PASSIVE_MODE
#define BT_LE_SCAN_TYPE_ACTIVE BT_LE_SCAN_TYPE_ACTIVE_MODE
typedef enum {
BT_LE_SCAN_TYPE_PASSIVE_MODE = 0,
BT_LE_SCAN_TYPE_ACTIVE_MODE
} ble_scan_type_t;
#else
typedef enum {
BT_LE_SCAN_TYPE_PASSIVE = 0,
BT_LE_SCAN_TYPE_ACTIVE
} ble_scan_type_t;
#endif
/**
* @brief Scan filter policy
@ -133,30 +151,76 @@ typedef struct {
uint8_t active;
uint8_t duplicated;
} ble_scan_filter_t;
/**
* @endcond
*/
/**
* @brief scan result callback
* @brief Scan result callback function.
*
* @param scanner - scanner handle.
* @param result - scan result.
* Callback function called when a scan result is available.
*
* @param scanner - Scanner handle.
* @param result - Pointer to the scan result, see @ref ble_scan_result_t.
*
* **Example:**
* @code
void le_scan_result_callback(bt_scanner_t* scanner, ble_scan_result_t* result)
{
// Process scan result
}
static scanner_callbacks_t lescan_cbs = {
.size = sizeof(lescan_cbs),
.on_scan_result = le_scan_result_callback,
};
* @endcode
*/
typedef void (*on_scan_result_cb_t)(bt_scanner_t* scanner, ble_scan_result_t* result);
/**
* @brief Scan start status callback
* @brief Scan start status callback function.
*
* @param scanner - scanner handle.
* @param result - scan start status, BT_SCAN_STATUS_SUCCESS on success.
* Callback function called when the scan starts or fails to start.
*
* @param scanner - Scanner handle.
* @param status - Scan start status code, see scan status codes.
*
* **Example:**
* @code
void on_scan_status(bt_scanner_t* scanner, uint8_t status)
{
if (status == BT_SCAN_STATUS_SUCCESS) {
// Scan started successfully
} else {
// Handle scan start failure
}
}
* @endcode
*/
typedef void (*on_scan_status_cb_t)(bt_scanner_t* scanner, uint8_t status);
/**
* @brief Scan stopped callback
* @brief Scan stopped callback function.
*
* @param scanner - scanner handle.
* Callback function called when the scan is stopped.
*
* @param scanner - Scanner handle.
*
* **Example:**
* @code
void on_scan_stopped(bt_scanner_t* scanner)
{
// Handle scan stopped event
}
* @endcode
*/
typedef void (*on_scan_stopped_cb_t)(bt_scanner_t* scanner);
/**
* @cond
*/
/**
* @brief Scanner callback structure
*
@ -167,37 +231,79 @@ typedef struct {
on_scan_status_cb_t on_scan_start_status;
on_scan_stopped_cb_t on_scan_stopped;
} scanner_callbacks_t;
/**
* @endcond
*/
/**
* @brief Start LE scan
* @brief Start BLE scan.
*
* @param ins - bluetooth client instance.
* @param cbs - scan callback function.
* @return bt_scanner_t* - scanner handle generated by scan manager.
* Initiates a BLE scan with default settings.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param cbs - Pointer to scanner callbacks, see @ref scanner_callbacks_t.
* @return bt_scanner_t* - Scanner handle generated by the scan manager.
*
* **Example:**
* @code
bt_scanner_t* scanner = bt_le_start_scan(ins, &my_scanner_callbacks);
if (scanner == NULL) {
// Handle error
}
* @endcode
*/
bt_scanner_t* BTSYMBOLS(bt_le_start_scan)(bt_instance_t* ins, const scanner_callbacks_t* cbs);
/**
* @brief Start LE scan with scan settings
* @brief Start BLE scan with specific settings.
*
* @param ins - bluetooth client instance.
* @param settings - scan settings with scan mode and scan phy.
* @param cbs - scan callback function.
* @return bt_scanner_t* - scanner handle generated by scan manager.
* Initiates a BLE scan with provided scan settings.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param settings - Pointer to scan settings, see @ref ble_scan_settings_t.
* @param cbs - Pointer to scanner callbacks, see @ref scanner_callbacks_t.
* @return bt_scanner_t* - Scanner handle generated by the scan manager.
*
* **Example:**
* @code
ble_scan_settings_t settings = {
.scan_mode = BT_SCAN_MODE_LOW_LATENCY,
.scan_type = BT_LE_SCAN_TYPE_ACTIVE,
// Additional settings...
};
bt_scanner_t* scanner = bt_le_start_scan_settings(ins, &settings, &my_scanner_callbacks);
if (scanner == NULL) {
// Handle error
}
* @endcode
*/
bt_scanner_t* BTSYMBOLS(bt_le_start_scan_settings)(bt_instance_t* ins,
ble_scan_settings_t* settings,
const scanner_callbacks_t* cbs);
/**
* @brief Start LE scan with scan filters
* @brief Start BLE scan with filters.
*
* @param ins - bluetooth client instance.
* @param settings - scan settings with scan mode and scan phy.
* @param filter_data - filter data.
* @param filter_length - filter data length.
* @param cbs - scan callback function.
* @return bt_scanner_t* - scanner handle generated by scan manager.
* Initiates a BLE scan with specific settings and filters.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param settings - Pointer to scan settings, see @ref ble_scan_settings_t.
* @param filter_data - Pointer to filter data, see @ref ble_scan_filter_t.
* @param cbs - Pointer to scanner callbacks, see @ref scanner_callbacks_t.
* @return bt_scanner_t* - Scanner handle generated by the scan manager.
*
* **Example:**
* @code
ble_scan_filter_t filter = {
.uuids = {0x180D, 0x180F}, // Heart Rate and Battery Service UUIDs
.active = 1,
// Additional filter settings...
};
bt_scanner_t* scanner = bt_le_start_scan_with_filters(ins, &settings, &filter, &my_scanner_callbacks);
if (scanner == NULL) {
// Handle error
}
* @endcode
*/
bt_scanner_t* BTSYMBOLS(bt_le_start_scan_with_filters)(bt_instance_t* ins,
ble_scan_settings_t* settings,
@ -205,24 +311,136 @@ bt_scanner_t* BTSYMBOLS(bt_le_start_scan_with_filters)(bt_instance_t* ins,
const scanner_callbacks_t* cbs);
/**
* @brief Stop LE scan
* @brief Stop BLE scan.
*
* @param ins - bluetooth client instance.
* @param scanner - scanner handle generated by scan manager.
* Stops an ongoing BLE scan.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param scanner - Scanner handle generated by the scan manager.
*
* **Example:**
* @code
bt_le_stop_scan(ins, scanner);
* @endcode
*/
void BTSYMBOLS(bt_le_stop_scan)(bt_instance_t* ins, bt_scanner_t* scanner);
/**
* @brief Check LE scan is support
* @brief Check if BLE scanning is supported.
*
* @param ins - bluetooth client instance.
* @return true - support.
* @return false - not support.
* Determines whether BLE scanning is supported by the adapter.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @return true - Scanning is supported.
* @return false - Scanning is not supported.
*
* **Example:**
* @code
if (bt_le_scan_is_supported(ins)) {
// Scanning is supported
} else {
// Scanning is not supported
}
* @endcode
*/
bool BTSYMBOLS(bt_le_scan_is_supported)(bt_instance_t* ins);
// async
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_ASYNC
#include "bt_async.h"
/**
* @brief The asynchronous callback for start BLE scan registered by the caller.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param status - Status of the operation.
* @param scan - Scanner handle generated by the scan manager. The caller needs
* to save the handle to use when stopping the scan.
* @param userdata - User context.
*/
typedef void (*bt_le_start_scan_cb_t)(bt_instance_t* ins, bt_status_t status, void* scan, void* userdata);
/**
* @brief The asynchronous callback for stop BLE scan registered by the caller.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param userdata - User context.
*/
typedef void (*bt_le_stop_scan_cb_t)(bt_instance_t* ins, void* userdata);
/**
* @brief Start BLE scan.
*
* Initiates a BLE scan with default settings.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param scan_cbs - Pointer to scanner callbacks, see @ref scanner_callbacks_t.
* @param cb - Callback function for asynchronous call.
* @param userdata - User context.
* @return bt_status_t - Only return IPC status.
*/
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);
/**
* @brief Start BLE scan with specific settings.
*
* Initiates a BLE scan with provided scan settings.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param settings - Pointer to scan settings, see @ref ble_scan_settings_t.
* @param scan_cbs - Pointer to scanner callbacks, see @ref scanner_callbacks_t.
* @param cb - Callback function for asynchronous call.
* @param userdata - User context.
* @return bt_status_t - Only return IPC 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);
/**
* @brief Start BLE scan with filters.
*
* Initiates a BLE scan with specific settings and filters.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param settings - Pointer to scan settings, see @ref ble_scan_settings_t.
* @param filter_data - Pointer to filter data, see @ref ble_scan_filter_t.
* @param scan_cbs - Pointer to scanner callbacks, see @ref scanner_callbacks_t.
* @param cb - Callback function for asynchronous call.
* @param userdata - User context.
* @return bt_status_t - Only return IPC 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);
/**
* @brief Stop BLE scan.
*
* Stops an ongoing BLE scan.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param scanner - Scanner handle generated by the scan manager.
* @param cb - Callback function for asynchronous call.
* @param userdata - User context.
* @return bt_status_t - Only return IPC 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);
/**
* @brief Check if BLE scanning is supported.
*
* Determines whether BLE scanning is supported by the adapter.
*
* @param ins - Bluetooth client instance, see @ref bt_instance_t.
* @param cb - Callback function for asynchronous call.
* @param userdata - User context.
* @return bt_status_t - Only return IPC status.
*/
bt_status_t bt_le_scan_is_supported_async(bt_instance_t* ins, bt_bool_cb_t cb, void* userdata);
#endif // CONFIG_BLUETOOTH_FRAMEWORK_ASYNC
#ifdef __cplusplus
}
#endif
#endif /* __BT_LE_SCAN_H_ */
#endif /* __BT_LE_SCAN_H_ */

View File

@ -23,7 +23,7 @@ extern "C" {
#include "bt_addr.h"
#include "bt_device.h"
#include "lea_audio_common.h"
#include "bt_lea_common.h"
#include <stddef.h>
/**

View File

@ -23,7 +23,7 @@ extern "C" {
#include "bt_addr.h"
#include "bt_device.h"
#include "lea_audio_common.h"
#include "bt_lea_common.h"
#include <stddef.h>
#define OBJ_ID_SIZE 6

View File

@ -23,7 +23,7 @@ extern "C" {
#include "bt_addr.h"
#include "bt_device.h"
#include "lea_audio_common.h"
#include "bt_lea_common.h"
#include <stddef.h>
typedef void (*lea_tbs_test_callback)(void* cookie, uint8_t value, bool added);

View File

@ -23,7 +23,7 @@ extern "C" {
#include <stdbool.h>
#include <stddef.h>
#include "list.h"
#include "bt_list_internal.h"
typedef void (*bt_list_free_cb_t)(void* data);
typedef struct _bt_list bt_list_t;

View File

@ -139,15 +139,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); \

View File

@ -26,7 +26,11 @@
#endif
/**
* @brief Pan role type define.
* @cond
*/
/**
* @brief PAN role type define.
*
*/
typedef enum {
@ -50,29 +54,68 @@ typedef enum {
} pan_netif_state_t;
/**
* @brief Pan connection state change callback.
* @endcond
*/
/**
* @brief Callback for PAN connection state change.
*
* @param cookie - callbacks cookie, the return value of bt_pan_register_callbacks.
* @param state - pan connection state
* @param bd_addr - address of peer device.
* @param local_role - local device pan role, reference type pan_role_t.
* @param remote_role - remote device pan role, reference type pan_role_t.
* When the PAN connection state changes, this callback will be triggered to
* notify the cookie corresponding to the callback, the latest PAN connection
* state, the Bluetooth address of the peer device, and the roles of both
* devices in the PAN.
*
* @param cookie - Callbacks cookie, the return value of bt_pan_register_callbacks.
* @param state - PAN connection state
* @param bd_addr - The Bluetooth address of the peer device.
* @param local_role - Local device PAN role, reference type pan_role_t.
* @param remote_role - Remote device PAN role, reference type pan_role_t.
*
* **Example:**
* @code
void pan_connection_state_cb(void* cookie, profile_connection_state_t state,
bt_address_t* bd_addr, uint8_t local_role,
uint8_t remote_role)
{
printf("pan_connection_state_cb, state: %d, bd_addr: %s, local_role: %d, remote_role: %d\n",
state, bd_addr->address, local_role, remote_role);
}
* @endcode
*/
typedef void (*pan_connection_state_callback)(void* cookie, profile_connection_state_t state,
bt_address_t* bd_addr, uint8_t local_role,
uint8_t remote_role);
/**
* @brief Pan net interface (down/up)state change callback.
* @brief Callback for PAN net interface (down/up) state change.
*
* @param cookie - callbacks cookie, the return value of bt_pan_register_callbacks.
* @param state - net interface state.
* @param local_role - local device pan role
* @param ifname - net interface name, default "bt-pan".
* When the PAN interface becomes up or down, this callback will be triggered
* to notify the Cookie corresponding to the callback, the latest status of
* the interface, the role of the local device in the PAN, and the interface
* name.
*
* @param cookie - Callbacks cookie, the return value of bt_pan_register_callbacks.
* @param state - Net interface state.
* @param local_role - Local device PAN role.
* @param ifname - Net interface name, default "bt-pan".
*
* **Example:**
* @code
void pan_netif_state_cb(void* cookie, pan_netif_state_t state,
int local_role, const char* ifname)
{
printf("pan_netif_state_cb, state: %d, local_role: %d, ifname: %s\n",
state, local_role, ifname);
}
* @endcode
*/
typedef void (*pan_netif_state_callback)(void* cookie, pan_netif_state_t state,
int local_role, const char* ifname);
/**
* @cond
*/
/**
* @brief PAN event callbacks structure
*
@ -84,41 +127,133 @@ typedef struct {
} pan_callbacks_t;
/**
* @brief Register callback functions to pan service
* @endcond
*/
/**
* @brief Register callback functions to PAN service.
*
* @param ins - bluetooth client instance.
* @param callbacks - pan callback functions.
* @return void* - callback cookie, NULL on failure.
* This function is used to register the callback for notifying PAN connection
* states and the callback for notifying PAN interface states to the PAN service.
* When the PAN service detects the corresponding event, it will notify the
* application through the registered callback function. After this function is
* called, it returns the cookie corresponding to the callback.
*
* @param ins - Bluetooth client instance.
* @param callbacks - PAN callback functions.
* @return void* - Callback cookie, NULL represents fail.
*
* **Example:**
* @code
void* pan_cookie;
const static pan_callbacks_t callbacks = {
.size = sizeof(pan_callbacks_t),
.netif_state_cb = pan_netif_state_cb,
.connection_state_cb = pan_connection_state_cb,
};
void app_init_pan(bt_instance_t* ins)
{
pan_cookie = bt_pan_register_callbacks(ins, &callbacks);
if (!pan_cookie)
printf("register pan callbacks failed\n");
else
printf("register pan callbacks success\n");
}
* @endcode
*/
void* BTSYMBOLS(bt_pan_register_callbacks)(bt_instance_t* ins, const pan_callbacks_t* callbacks);
/**
* @brief Unregister pan callback function
* @brief Unregister PAN callback functions.
*
* @param ins - bluetooth client instance.
* @param cookie - callbacks cookie.
* This function is used to unregister callbacks from the PAN service. The caller
* needs to provide the cookie corresponding to callbacks.
*
* @param ins - Bluetooth client instance.
* @param cookie - Callbacks cookie.
* @return true - on callback unregister success
* @return false - on callback cookie not found
*
* **Example:**
* @code
void app_deinit_pan(bt_instance_t* ins)
{
bt_status_t status;
if (!pan_cookie)
return;
status = bt_pan_unregister_callbacks(ins, pan_cookie);
if (status != BT_STATUS_SUCCESS)
printf("unregister pan callbacks failed\n");
else
printf("unregister pan callbacks success\n");
}
* @endcode
*/
bool BTSYMBOLS(bt_pan_unregister_callbacks)(bt_instance_t* ins, void* cookie);
/**
* @brief Connect to pan device
* @brief Connect to PAN device.
*
* @param ins - bluetooth client instance.
* @param addr - address of peer device.
* @param dst_role - dest pan role, reference type pan_role_t.
* @param src_role - src pan role, reference type pan_role_t.
* This function is used to connect to a PAN device. The caller needs to provide
* the address of the peer device, the role of the local device, and the role of
* the peer device.
*
* @param ins - Bluetooth client instance.
* @param addr - The Bluetooth address of the peer device.
* @param dst_role - Destination PAN role, reference type pan_role_t.
* Only support PANU connect to NAP server, dst_role must be PAN_ROLE_NAP.
* @param src_role - Source PAN role, reference type pan_role_t.
* Only support PANU connect to NAP server, src_role must be PAN_ROLE_PANU.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*
* **Example:**
* @code
void app_connect_pan_device(bt_instance_t* ins)
{
bt_status_t status;
bt_address_t addr = {
.addr = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06},
};
status = bt_pan_connect(ins, &addr, PAN_ROLE_NAP, PAN_ROLE_PANU);
if(status != BT_STATUS_SUCCESS)
printf("connect pan device failed\n");
else
printf("connect pan device success\n");
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_pan_connect)(bt_instance_t* ins, bt_address_t* addr, uint8_t dst_role, uint8_t src_role);
/**
* @brief Disconnect from pan connection
* @brief Disconnect from PAN connection.
*
* @param ins - bluetooth client instance.
* @param addr - address of peer device.
* This function is used to disconnect from a PAN device. The caller needs to
* provide the address of the peer device.
*
* @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
void app_disconnect_pan_device(bt_instance_t* ins)
{
bt_status_t status;
bt_address_t addr = {
.addr = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06},
};
status = bt_pan_disconnect(ins, &addr);
if(status != BT_STATUS_SUCCESS)
printf("disconnect pan device failed\n");
else
printf("disconnect pan device success\n");
}
* @endcode
*/
bt_status_t BTSYMBOLS(bt_pan_disconnect)(bt_instance_t* ins, bt_address_t* addr);

View File

@ -20,11 +20,14 @@
extern "C" {
#endif
/**
* @cond
*/
#define PROFILE_A2DP_NAME "A2DP-Src"
#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,11 +64,14 @@ enum profile_id {
PROFILE_LEAUDIO_MCS,
PROFILE_LEAUDIO_TBS,
PROFILE_LEAUDIO_VMICP,
PROFILE_CS, // TODO: remove this profile
PROFILE_UNKOWN,
PROFILE_MAX
};
/**
* @endcond
*/
#ifdef __cplusplus
}
#endif

View File

@ -46,8 +46,6 @@ extern "C" {
*/
#define BT_UUID_SERVCLASS_SERIAL_PORT 0x1101
#define SPP_PORT_TYPE_TTY 1
/**
* @brief Spp proxy state
*
@ -59,6 +57,10 @@ typedef enum {
SPP_PROXY_STATE_CLOSING,
} spp_proxy_state_t;
/**
* @endcond
*/
/**
* @brief Callback used to notify SPP connection states.
*
@ -145,9 +147,12 @@ void spp_proxy_state_cb(void* handle, bt_address_t* addr, spp_proxy_state_t stat
*/
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);
/**
* @cond
*/
/**
* @brief SPP event callbacks structure
*
*/
typedef struct {
size_t size;
@ -326,8 +331,8 @@ bt_status_t BTSYMBOLS(bt_spp_unregister_app)(bt_instance_t* ins, void* handle);
* on other devices.
*
* @param ins - Bluetooth client instance.
* @param handle - SPP application handle.
* @param scn - Server channel number, range in 1-28.
* @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.
@ -364,8 +369,8 @@ bt_status_t BTSYMBOLS(bt_spp_server_start)(bt_instance_t* ins, void* handle, uin
* 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 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:**
@ -396,9 +401,9 @@ bt_status_t BTSYMBOLS(bt_spp_server_stop)(bt_instance_t* ins, void* handle, uint
* 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.
* @param[in] handle - SPP APP handle.
* @param[in] addr - address of 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.

View File

@ -23,30 +23,14 @@ 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
/**
* @cond
*/
typedef enum {
BT_UUID16_TYPE = 2,
@ -86,13 +70,172 @@ typedef struct {
((bt_uuid_t) { .type = BT_UUID128_TYPE, .val.u128 = { value } })
#endif
/**
* @endcond
*/
/**
* @brief Converting UUID to a 128-bits UUID.
*
* @param src - src UUID(16-bits, 32-bits, 128-bits).
* @param uuid128 - Converted 128-bits UUID.
* @return void.
*
* **Example:**
* @code
int bt_uuid_compare(const bt_uuid_t* uuid1, const bt_uuid_t* uuid2)
{
bt_uuid_t u1 = { 0 };
bt_uuid_t u2 = { 0 };
bt_uuid_to_uuid128(uuid1, &u1);
bt_uuid_to_uuid128(uuid2, &u2);
return bt_uuid128_cmp(&u1, &u2);
}
* @endcode
*/
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);
/**
* @brief compare two UUIDs.
*
* @param uuid1 - UUID1.
* @param uuid2 - UUID2.
* @return int. If uuid1 is equal to uuid2, return 0.
*
* **Example:**
* @code
if (!bt_uuid_compare(&element->uuid, attr_uuid)) {
BT_LOGE("uuid match");
// Handle continue
} else {
BT_LOGE("uuid not match");
// Handle error
}
* @endcode
*/
int bt_uuid_compare(const bt_uuid_t* uuid1, const bt_uuid_t* uuid2);
/**
* @brief create a 16-bits UUID.
*
* @param uuid16 - pointer of the generated UUID16.
* @param value - UUID value.
* @return int.
*
* **Example:**
* @code
bool bt_uuid_create_common(bt_uuid_t* uuid, const uint8_t* data, uint8_t type)
{
switch (type) {
case BT_UUID16_TYPE: {
uint16_t val16;
STREAM_TO_UINT32(val16, data);
bt_uuid16_create(uuid, val16);
break;
}
default:
return false;
}
return true;
}
* @endcode
*/
int bt_uuid16_create(bt_uuid_t* uuid16, uint16_t value);
/**
* @brief create a 32-bits UUID.
*
* @param uuid16 - pointer of the generated UUID32.
* @param value - UUID value.
* @return int.
*
* **Example:**
* @code
bool bt_uuid_create_common(bt_uuid_t* uuid, const uint8_t* data, uint8_t type)
{
switch (type) {
case BT_UUID32_TYPE: {
uint32_t val32;
STREAM_TO_UINT32(val32, data);
bt_uuid32_create(uuid, val32);
break;
}
default:
return false;
}
return true;
}
* @endcode
*/
int bt_uuid32_create(bt_uuid_t* uuid32, uint32_t value);
/**
* @brief create a 128-bits UUID.
*
* @param uuid16 - pointer of the generated UUID128.
* @param value - UUID value.
* @return int.
*
* **Example:**
* @code
bool bt_uuid_create_common(bt_uuid_t* uuid, const uint8_t* data, uint8_t type)
{
switch (type) {
case BT_UUID128_TYPE:
bt_uuid128_create(uuid, data);
break;
default:
return false;
}
return true;
}
* @endcode
*/
int bt_uuid128_create(bt_uuid_t* uuid128, const uint8_t* value);
/**
* @brief Wrapper of UUID create.
*
* @param uuid - pointer of the generated UUID(16-bits, 32-bits, 128-bits).
* @param data - UUID value.
* @param type - UUID type(16-bits, 32-bits, 128-bits).
* @return bool. If type belongs to UUID16, UUID32, UUID128return true, else return false.
*
* **Example:**
* @code
bt_uuid_create_common(&uuid, data, BT_UUID128_TYPE)
* @endcode
*/
bool bt_uuid_create_common(bt_uuid_t* uuid, const uint8_t* data, uint8_t type);
/**
* @brief Converting UUID to string.
*
* @param uuid - pointer of the generated UUID.
* @param str - UUID string.
* @param len - string length.
* @return int.
*
* **Example:**
* @code
bt_device_get_uuids(handle, addr, &uuids, &uuid_cnt, bttool_allocator);
if (uuid_cnt) {
PRINT("\tUUIDs:[%d]", uuid_cnt);
for (int i = 0; i < uuid_cnt; i++) {
bt_uuid_to_string(uuids + i, uuid_str, 40);
PRINT("\t\tuuid[%-2d]: %s", i, uuid_str);
}
}
free(uuids);
* @endcode
*/
int bt_uuid_to_string(const bt_uuid_t* uuid, char* str, uint32_t len);
#ifdef __cplusplus

View File

@ -33,25 +33,20 @@ typedef enum {
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 {
typedef 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;
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);
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

View File

@ -1,327 +0,0 @@
/****************************************************************************
* include/nuttx/list.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_NUTTX_LIST_H
#define __INCLUDE_NUTTX_LIST_H
/****************************************************************************
* Included Files
****************************************************************************/
#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
****************************************************************************/
#include <nuttx/list_type.h>
/****************************************************************************
* 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;
}
#endif /* __INCLUDE_NUTTX_LIST_H */

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

@ -22,6 +22,17 @@
typedef void (*thread_func_t)(void* data);
typedef struct thread_loop_work thread_loop_work_t;
typedef void (*thread_work_cb_t)(thread_loop_work_t* work, void* userdata);
typedef void (*thread_after_work_cb_t)(thread_loop_work_t* work, void* userdata);
typedef struct thread_loop_work {
uv_work_t work;
thread_work_cb_t work_cb;
thread_after_work_cb_t after_work_cb;
void* userdata;
} thread_loop_work_t;
int thread_loop_init(uv_loop_t* loop);
int thread_loop_run(uv_loop_t* loop, bool start_thread, const char* name);
void thread_loop_exit(uv_loop_t* loop);
@ -33,5 +44,7 @@ uv_timer_t* thread_loop_timer_no_repeating(uv_loop_t* loop, uint64_t timeout, uv
void thread_loop_cancel_timer(uv_timer_t* timer);
void do_in_thread_loop(uv_loop_t* loop, thread_func_t func, void* data);
void do_in_thread_loop_sync(uv_loop_t* loop, thread_func_t func, void* data);
void thread_loop_work_sync(uv_loop_t* loop, void* user_data, thread_work_cb_t work_cb,
thread_after_work_cb_t after_work_cb);
#endif /* _UV_THREAD_LOOP_H__ */

View File

@ -30,15 +30,7 @@ static void adapter_status_reply(bt_instance_t* ins, bt_message_packet_t* packet
{
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);
HANDLE_BT_ASTNC_CALLBACK(ret_cb, ins, packet, adpt_r, userdata);
}
static void adapter_bool_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
@ -257,7 +249,7 @@ bt_status_t bt_adapter_register_callback_async(bt_instance_t* ins,
{
bt_register_callback_data_t* data;
bt_socket_async_client_t* priv;
bt_message_packet_t packet;
bt_message_packet_t packet = { 0 };
bt_status_t status;
void* handle;
@ -310,7 +302,7 @@ send_message:
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_message_packet_t packet = { 0 };
bt_socket_async_client_t* priv;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -332,7 +324,7 @@ bt_status_t bt_adapter_unregister_callback_async(bt_instance_t* ins, void* cooki
bt_status_t bt_adapter_enable_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
bt_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -341,7 +333,7 @@ bt_status_t bt_adapter_enable_async(bt_instance_t* ins, bt_status_cb_t cb, void*
bt_status_t bt_adapter_disable_async(bt_instance_t* ins, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
bt_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -350,7 +342,7 @@ bt_status_t bt_adapter_disable_async(bt_instance_t* ins, bt_status_cb_t cb, void
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -359,7 +351,7 @@ bt_status_t bt_adapter_enable_le_async(bt_instance_t* ins, bt_status_cb_t cb, vo
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -368,7 +360,7 @@ bt_status_t bt_adapter_disable_le_async(bt_instance_t* ins, bt_status_cb_t cb, v
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -377,7 +369,7 @@ bt_status_t bt_adapter_get_state_async(bt_instance_t* ins, bt_adapter_get_state_
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -386,7 +378,7 @@ bt_status_t bt_adapter_is_le_enabled_async(bt_instance_t* ins, bt_bool_cb_t cb,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -400,7 +392,7 @@ bt_status_t bt_adapter_set_discovery_filter_async(bt_instance_t* ins, bt_status_
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -411,7 +403,7 @@ bt_status_t bt_adapter_start_discovery_async(bt_instance_t* ins, uint32_t timeou
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -420,7 +412,7 @@ bt_status_t bt_adapter_cancel_discovery_async(bt_instance_t* ins, bt_status_cb_t
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -429,7 +421,7 @@ bt_status_t bt_adapter_is_discovering_async(bt_instance_t* ins, bt_bool_cb_t cb,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -438,7 +430,7 @@ bt_status_t bt_adapter_get_address_async(bt_instance_t* ins, bt_address_cb_t cb,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -453,7 +445,7 @@ bt_status_t bt_adapter_set_name_async(bt_instance_t* ins, const char* name, bt_s
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -462,7 +454,7 @@ bt_status_t bt_adapter_get_name_async(bt_instance_t* ins, bt_string_cb_t get_nam
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -471,7 +463,7 @@ bt_status_t bt_adapter_get_uuids_async(bt_instance_t* ins, bt_uuids_cb_t get_uui
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -483,7 +475,7 @@ bt_status_t bt_adapter_set_scan_mode_async(bt_instance_t* ins, bt_scan_mode_t mo
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -492,7 +484,7 @@ bt_status_t bt_adapter_get_scan_mode_async(bt_instance_t* ins, bt_adapter_get_sc
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -503,7 +495,7 @@ bt_status_t bt_adapter_set_device_class_async(bt_instance_t* ins, uint32_t cod,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -512,7 +504,7 @@ bt_status_t bt_adapter_get_device_class_async(bt_instance_t* ins, bt_u32_cb_t ge
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -523,7 +515,7 @@ bt_status_t bt_adapter_set_io_capability_async(bt_instance_t* ins, bt_io_capabil
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -533,7 +525,7 @@ bt_status_t bt_adapter_get_io_capability_async(bt_instance_t* ins, bt_adapter_ge
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -547,7 +539,7 @@ bt_status_t bt_adapter_set_inquiry_scan_parameters_async(bt_instance_t* ins, bt_
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -560,7 +552,7 @@ bt_status_t bt_adapter_set_page_scan_parameters_async(bt_instance_t* ins, bt_sca
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -571,7 +563,7 @@ bt_status_t bt_adapter_set_le_io_capability_async(bt_instance_t* ins, uint32_t l
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -580,7 +572,7 @@ bt_status_t bt_adapter_get_le_io_capability_async(bt_instance_t* ins, bt_u32_cb_
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -589,7 +581,7 @@ bt_status_t bt_adapter_get_le_address_async(bt_instance_t* ins, bt_adapter_get_l
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -600,7 +592,7 @@ bt_status_t bt_adapter_set_le_address_async(bt_instance_t* ins, bt_address_t* ad
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -612,7 +604,7 @@ bt_status_t bt_adapter_set_le_identity_address_async(bt_instance_t* ins, bt_addr
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -623,7 +615,7 @@ bt_status_t bt_adapter_set_le_appearance_async(bt_instance_t* ins, uint16_t appe
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -633,7 +625,7 @@ bt_status_t bt_adapter_get_le_appearance_async(bt_instance_t* ins, bt_u16_cb_t c
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -645,7 +637,7 @@ bt_status_t bt_adapter_le_enable_key_derivation_async(bt_instance_t* ins,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -656,7 +648,7 @@ bt_status_t bt_adapter_le_add_whitelist_async(bt_instance_t* ins, bt_address_t*
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -667,7 +659,7 @@ bt_status_t bt_adapter_le_remove_whitelist_async(bt_instance_t* ins, bt_address_
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -678,7 +670,7 @@ bt_status_t bt_adapter_get_bonded_devices_async(bt_instance_t* ins, bt_transport
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -690,7 +682,7 @@ bt_status_t bt_adapter_get_connected_devices_async(bt_instance_t* ins, bt_transp
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -708,7 +700,7 @@ bt_status_t bt_adapter_set_auto_sniff_async(bt_instance_t* ins, bt_auto_sniff_pa
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -717,7 +709,7 @@ bt_status_t bt_adapter_disconnect_all_devices_async(bt_instance_t* ins, bt_statu
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -726,7 +718,7 @@ bt_status_t bt_adapter_is_support_bredr_async(bt_instance_t* ins, bt_bool_cb_t c
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -735,7 +727,7 @@ bt_status_t bt_adapter_is_support_le_async(bt_instance_t* ins, bt_bool_cb_t cb,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);

View File

@ -43,15 +43,7 @@ static void device_status_reply(bt_instance_t* ins, bt_message_packet_t* packet,
{
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);
HANDLE_BT_ASTNC_CALLBACK(ret_cb, ins, packet, devs_r, userdata);
}
static void device_bool_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
@ -214,7 +206,7 @@ static int bt_device_send_async(bt_instance_t* ins, bt_address_t* addr,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -223,7 +215,7 @@ bt_status_t bt_device_get_identity_address_async(bt_instance_t* ins, bt_address_
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -232,7 +224,7 @@ bt_status_t bt_device_get_address_type_async(bt_instance_t* ins, bt_address_t* a
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -252,7 +244,7 @@ bt_status_t bt_device_get_name_async(bt_instance_t* ins, bt_address_t* addr, bt_
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -272,7 +264,7 @@ bt_status_t bt_device_get_uuids_async(bt_instance_t* ins, bt_address_t* addr, bt
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -281,7 +273,7 @@ bt_status_t bt_device_get_appearance_async(bt_instance_t* ins, bt_address_t* add
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -316,7 +308,7 @@ bt_status_t bt_device_set_alias_async(bt_instance_t* ins, bt_address_t* addr,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -328,7 +320,7 @@ bt_status_t bt_device_is_connected_async(bt_instance_t* ins, bt_address_t* addr,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -340,7 +332,7 @@ bt_status_t bt_device_is_encrypted_async(bt_instance_t* ins, bt_address_t* addr,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -352,7 +344,7 @@ bt_status_t bt_device_is_bond_initiate_local_async(bt_instance_t* ins, bt_addres
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -364,7 +356,7 @@ bt_status_t bt_device_get_bond_state_async(bt_instance_t* ins, bt_address_t* add
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -375,7 +367,7 @@ bt_status_t bt_device_is_bonded_async(bt_instance_t* ins, bt_address_t* addr,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -384,7 +376,7 @@ bt_status_t bt_device_connect_async(bt_instance_t* ins, bt_address_t* addr, bt_s
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -396,7 +388,7 @@ bt_status_t bt_device_connect_le_async(bt_instance_t* ins,
ble_addr_type_t type,
ble_connect_params_t* param, bt_status_cb_t cb, void* userdata)
{
bt_message_packet_t packet;
bt_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -409,7 +401,7 @@ bt_status_t bt_device_connect_le_async(bt_instance_t* ins,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -419,7 +411,7 @@ bt_status_t bt_device_disconnect_le_async(bt_instance_t* ins, bt_address_t* addr
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -431,7 +423,7 @@ bt_status_t bt_device_connect_request_reply_async(bt_instance_t* ins, bt_address
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -440,7 +432,7 @@ bt_status_t bt_device_connect_all_profile_async(bt_instance_t* ins, bt_address_t
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -452,7 +444,7 @@ bt_status_t bt_device_set_le_phy_async(bt_instance_t* ins,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -466,7 +458,7 @@ bt_status_t bt_device_set_le_phy_async(bt_instance_t* ins,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -478,7 +470,7 @@ bt_status_t bt_device_create_bond_async(bt_instance_t* ins, bt_address_t* addr,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -490,7 +482,7 @@ bt_status_t bt_device_remove_bond_async(bt_instance_t* ins, bt_address_t* addr,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -501,7 +493,7 @@ bt_status_t bt_device_cancel_bond_async(bt_instance_t* ins, bt_address_t* addr,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -514,7 +506,7 @@ bt_status_t bt_device_pair_request_reply_async(bt_instance_t* ins, bt_address_t*
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -528,7 +520,7 @@ bt_status_t bt_device_set_pairing_confirmation_async(bt_instance_t* ins, bt_addr
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
if (len > sizeof(packet.devs_pl._bt_device_set_pin_code.pincode))
@ -545,7 +537,7 @@ bt_status_t bt_device_set_pin_code_async(bt_instance_t* ins, bt_address_t* addr,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -560,7 +552,7 @@ bt_status_t bt_device_set_pass_key_async(bt_instance_t* ins, bt_address_t* addr,
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -573,7 +565,7 @@ bt_status_t bt_device_set_le_legacy_tk_async(bt_instance_t* ins, bt_address_t* a
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
@ -586,7 +578,7 @@ bt_status_t bt_device_set_le_sc_remote_oob_data_async(bt_instance_t* ins, bt_add
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_message_packet_t packet = { 0 };
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);

View File

@ -38,19 +38,16 @@ typedef struct {
gattc_handle_t* user_phandle;
} bt_gattc_create_connect_data_t;
typedef struct {
void* userdata;
void* gattc_remote;
} bt_gattc_delete_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);
HANDLE_BT_ASTNC_CALLBACK(ret_cb, ins, packet, gattc_r, userdata);
}
static void gattc_get_attribute_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
@ -78,7 +75,7 @@ static void gattc_create_connect_reply(bt_instance_t* ins, bt_message_packet_t*
if (!packet || packet->gattc_r.status != BT_STATUS_SUCCESS)
goto error;
gattc_remote->cookie = INT2PTR(void*) packet->gattc_r.handle;
gattc_remote->cookie = PTR2INT(uint64_t) 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;
@ -109,32 +106,40 @@ error:
static void gattc_delete_connect_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
{
bt_gattc_delete_connect_data_t* data = userdata;
bt_socket_async_client_t* priv = ins->priv;
bt_gattc_delete_connect_cb_t ret_cb = (bt_gattc_delete_connect_cb_t)cb;
bt_gattc_remote_t* gattc_remote = (bt_gattc_remote_t*)data->gattc_remote;
void** user_phandle = gattc_remote->user_phandle;
if (!ret_cb)
return;
bt_list_remove(priv->gattc_remote_list, gattc_remote);
*user_phandle = NULL;
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, userdata);
if (!bt_list_length(priv->gattc_remote_list)) {
bt_list_free(priv->gattc_remote_list);
priv->gattc_remote_list = NULL;
}
if (!ret_cb) {
free(userdata);
return;
}
ret_cb(ins, packet->gattc_r.status, userdata);
if (!packet) {
ret_cb(ins, BT_STATUS_UNHANDLED, data->userdata);
free(userdata);
return;
}
ret_cb(ins, packet->gattc_r.status, data->userdata);
free(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);
HANDLE_BT_ASTNC_CALLBACK(ret_cb, ins, packet, gattc_r, userdata);
}
bt_status_t bt_gattc_create_connect_async(bt_instance_t* ins, gattc_handle_t* phandle, gattc_callbacks_t* callbacks,
@ -201,11 +206,10 @@ fail:
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_gattc_delete_connect_data_t* data;
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);
@ -216,18 +220,11 @@ bt_status_t bt_gattc_delete_connect_async(gattc_handle_t conn_handle, bt_gattc_d
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);
data = calloc(1, sizeof(bt_gattc_delete_connect_data_t));
data->userdata = userdata;
data->gattc_remote = (void*)gattc_remote;
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;
return bt_socket_client_send_with_reply(ins, &packet, BT_GATT_CLIENT_DELETE_CONNECT, gattc_delete_connect_reply, (void*)cb, data);
}
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)

View File

@ -34,15 +34,7 @@ static void le_advertiser_status_reply(bt_instance_t* ins, bt_message_packet_t*
{
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);
HANDLE_BT_ASTNC_CALLBACK(ret_cb, ins, packet, adv_r, context);
}
static void le_advertiser_bool_reply(bt_instance_t* ins, bt_message_packet_t* packet, void* cb, void* userdata)
@ -109,7 +101,7 @@ bt_status_t bt_le_start_advertising_async(bt_instance_t* ins, ble_adv_params_t*
return BT_STATUS_NOMEM;
adv->ins = ins;
adv->callbacks = adv_cbs;
adv->callback = 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)))

View File

@ -102,7 +102,7 @@ bt_status_t bt_le_start_scan_async(bt_instance_t* ins, const scanner_callbacks_t
return BT_STATUS_FAIL;
scan->ins = ins;
scan->callbacks = (scanner_callbacks_t*)scan_cbs;
scan->callback = (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));
@ -135,7 +135,7 @@ bt_status_t bt_le_start_scan_settings_async(bt_instance_t* ins, ble_scan_setting
return BT_STATUS_FAIL;
scan->ins = ins;
scan->callbacks = (scanner_callbacks_t*)scan_cbs;
scan->callback = (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));
@ -170,7 +170,7 @@ bt_status_t bt_le_start_scan_with_filters_async(bt_instance_t* ins, ble_scan_set
return BT_STATUS_FAIL;
scan->ins = ins;
scan->callbacks = (scanner_callbacks_t*)scan_cbs;
scan->callback = (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));

View File

@ -23,6 +23,10 @@
#include "manager_service.h"
#include "service_loop.h"
#ifdef CONFIG_NET_RPMSG
#include <netpacket/rpmsg.h>
#endif
bt_instance_t* bluetooth_create_instance(void)
{
bt_status_t status;
@ -107,8 +111,8 @@ bt_instance_t* bluetooth_create_async_instance(uv_loop_t* loop, bt_ipc_connected
return NULL;
}
status = manager_create_instance(PTR2INT(uint64_t) ins, BLUETOOTH_SYSTEM,
"local", getpid(), 0, &ins->app_id);
status = manager_create_async_instance(PTR2INT(uint64_t) ins, BLUETOOTH_SYSTEM,
"local", getpid(), (uid_t)pthread_self(), &ins->app_id);
if (status != BT_STATUS_SUCCESS) {
bt_socket_client_deinit(ins);
free(ins);
@ -129,6 +133,18 @@ bt_instance_t* bluetooth_find_instance(pid_t pid)
return INT2PTR(bt_instance_t*) handle;
}
bt_instance_t* bluetooth_find_async_instance(pid_t pid)
{
bt_status_t status;
uint64_t handle;
status = manager_get_async_instance("local", pid, &handle);
if (status != BT_STATUS_SUCCESS) {
return NULL;
}
return INT2PTR(bt_instance_t*) handle;
}
bt_instance_t* bluetooth_get_instance(void)
{
bt_instance_t* bluetooth_ins = bluetooth_find_instance(getpid());
@ -139,6 +155,16 @@ bt_instance_t* bluetooth_get_instance(void)
return bluetooth_ins;
}
bt_instance_t* bluetooth_get_async_instance(uv_loop_t* loop, bt_ipc_connected_cb_t connected, bt_ipc_disconnected_cb_t disconnected, void* user_data)
{
bt_instance_t* bluetooth_ins = bluetooth_find_async_instance(getpid());
if (bluetooth_ins == NULL)
return bluetooth_create_async_instance(loop, connected, disconnected, user_data);
else
return bluetooth_ins;
}
void* bluetooth_get_proxy(bt_instance_t* ins, enum profile_id id)
{
return NULL;

View File

@ -117,6 +117,21 @@ bt_status_t bt_adapter_disable(bt_instance_t* ins)
return packet.adpt_r.status;
}
bt_status_t bt_adapter_disable_safe(bt_instance_t* ins)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
status = bt_socket_client_sendrecv(ins, &packet, BT_ADAPTER_DISABLE_SAFE);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.adpt_r.status;
}
bt_status_t bt_adapter_enable_le(bt_instance_t* ins)
{
bt_message_packet_t packet;
@ -223,6 +238,22 @@ bt_status_t bt_adapter_start_discovery(bt_instance_t* ins, uint32_t timeout)
return packet.adpt_r.status;
}
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_cancel_discovery(bt_instance_t* ins)
{
bt_message_packet_t packet;
@ -544,7 +575,7 @@ bt_status_t bt_adapter_set_le_address(bt_instance_t* ins, bt_address_t* addr)
return packet.adpt_r.status;
}
bt_status_t bt_adapter_set_le_identity_address(bt_instance_t* ins, bt_address_t* addr, bool public)
bt_status_t bt_adapter_set_le_identity_address(bt_instance_t* ins, bt_address_t* addr, bool is_public)
{
bt_message_packet_t packet;
bt_status_t status;
@ -552,7 +583,7 @@ bt_status_t bt_adapter_set_le_identity_address(bt_instance_t* ins, bt_address_t*
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 = public;
packet.adpt_pl._bt_adapter_set_le_identity_address.pub = is_public;
status = bt_socket_client_sendrecv(ins, &packet, BT_ADAPTER_SET_LE_IDENTITY_ADDRESS);
if (status != BT_STATUS_SUCCESS) {
return status;
@ -612,6 +643,11 @@ bt_status_t bt_adapter_le_enable_key_derivation(bt_instance_t* ins,
}
bt_status_t bt_adapter_le_add_whitelist(bt_instance_t* ins, bt_address_t* addr)
{
return bt_adapter_le_add_whitelist_with_type(ins, addr, BT_LE_ADDR_TYPE_UNKNOWN);
}
bt_status_t bt_adapter_le_add_whitelist_with_type(bt_instance_t* ins, bt_address_t* addr, ble_addr_type_t type)
{
bt_message_packet_t packet;
bt_status_t status;
@ -619,6 +655,7 @@ bt_status_t bt_adapter_le_add_whitelist(bt_instance_t* ins, bt_address_t* addr)
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.adpt_pl._bt_adapter_le_add_whitelist.addr, addr, sizeof(*addr));
packet.adpt_pl._bt_adapter_le_add_whitelist.type = (uint8_t)type;
status = bt_socket_client_sendrecv(ins, &packet, BT_ADAPTER_LE_ADD_WHITELIST);
if (status != BT_STATUS_SUCCESS) {
return status;
@ -771,24 +808,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

@ -116,5 +116,71 @@ bt_status_t bt_avrcp_control_send_passthrough_cmd(bt_instance_t* ins, bt_address
return status;
}
return packet.avrcp_control_r.status;
}
bt_status_t bt_avrcp_control_get_unit_info(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_unit_info.addr, addr, sizeof(packet.avrcp_control_pl._bt_avrcp_control_get_unit_info.addr));
status = bt_socket_client_sendrecv(ins, &packet, BT_AVRCP_CT_GET_UNIT_INFO_CMD);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.avrcp_control_r.status;
}
bt_status_t bt_avrcp_control_get_subunit_info(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_subunit_info.addr, addr, sizeof(packet.avrcp_control_pl._bt_avrcp_control_get_subunit_info.addr));
status = bt_socket_client_sendrecv(ins, &packet, BT_AVRCP_CT_GET_SUBUNIT_INFO_CMD);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.avrcp_control_r.status;
}
bt_status_t bt_avrcp_control_get_playback_state(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_playback_state.addr, addr, sizeof(packet.avrcp_control_pl._bt_avrcp_control_get_playback_state.addr));
status = bt_socket_client_sendrecv(ins, &packet, BT_AVRCP_CT_GET_PLAYBACK_STATE_CMD);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.avrcp_control_r.status;
}
bt_status_t bt_avrcp_control_register_notification(bt_instance_t* ins, bt_address_t* addr, uint8_t event, uint32_t interval)
{
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_register_notification.addr, addr, sizeof(packet.avrcp_control_pl._bt_avrcp_control_register_notification.addr));
packet.avrcp_control_pl._bt_avrcp_control_register_notification.event = event;
packet.avrcp_control_pl._bt_avrcp_control_register_notification.interval = interval;
status = bt_socket_client_sendrecv(ins, &packet, BT_AVRCP_CT_REGISTER_NOTIFICATION_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

@ -177,7 +177,7 @@ bool bt_device_get_alias(bt_instance_t* ins, bt_address_t* addr, char* alias, ui
}
strlcpy(alias, packet.devs_pl._bt_device_get_alias.alias,
MIN(length, sizeof(packet.devs_pl._bt_device_get_alias.alias) - 1));
MIN(length, sizeof(packet.devs_pl._bt_device_get_alias.alias)));
return packet.devs_r.status;
}
@ -288,6 +288,40 @@ bt_status_t bt_device_connect(bt_instance_t* ins, bt_address_t* addr)
return packet.devs_r.status;
}
bt_status_t bt_device_background_connect(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
bt_message_packet_t packet;
bt_status_t status;
if (addr)
memcpy(&packet.devs_pl._bt_device_background_connect, addr, sizeof(*addr));
else
bt_addr_set_empty(&packet.devs_pl._bt_device_background_connect.addr);
packet.devs_pl._bt_device_background_connect.transport = transport;
status = bt_socket_client_sendrecv(ins, &packet, BT_DEVICE_BACKGROUND_CONNECT);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.devs_r.status;
}
bt_status_t bt_device_background_disconnect(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_background_disconnect, addr, sizeof(*addr));
packet.devs_pl._bt_device_background_disconnect.transport = transport;
status = bt_socket_client_sendrecv(ins, &packet, BT_DEVICE_BACKGROUND_DISCONNECT);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.devs_r.status;
}
bt_status_t bt_device_disconnect(bt_instance_t* ins, bt_address_t* addr)
{
bt_message_packet_t packet;
@ -514,6 +548,7 @@ bt_status_t bt_device_set_pin_code(bt_instance_t* ins, bt_address_t* addr, bool
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;
status = bt_socket_client_sendrecv(ins, &packet, BT_DEVICE_SET_PIN_CODE);
if (status != BT_STATUS_SUCCESS) {
return status;
@ -540,7 +575,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;
@ -591,10 +626,34 @@ bt_status_t bt_device_get_le_sc_local_oob_data(bt_instance_t* ins, bt_address_t*
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_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_enable_enhanced_mode.addr, addr, sizeof(packet.devs_pl._bt_device_enable_enhanced_mode.addr));
packet.devs_pl._bt_device_enable_enhanced_mode.mode = mode;
status = bt_socket_client_sendrecv(ins, &packet, BT_DEVICE_ENABLE_ENHANCED_MODE);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.devs_r.status;
}
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;
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
memcpy(&packet.devs_pl._bt_device_disable_enhanced_mode.addr, addr, sizeof(packet.devs_pl._bt_device_disable_enhanced_mode.addr));
packet.devs_pl._bt_device_disable_enhanced_mode.mode = mode;
status = bt_socket_client_sendrecv(ins, &packet, BT_DEVICE_DISABLE_ENHANCED_MODE);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.devs_r.status;
}

View File

@ -66,7 +66,7 @@ bt_status_t bt_gattc_create_connect(bt_instance_t* ins, gattc_handle_t* phandle,
goto fail;
}
gattc_remote->cookie = INT2PTR(void*) packet.gattc_r.handle;
gattc_remote->cookie = packet.gattc_r.handle;
gattc_remote->user_phandle = phandle;
bt_list_add_tail(ins->gattc_remote_list, gattc_remote);
@ -267,6 +267,27 @@ bt_status_t bt_gattc_write_without_response(gattc_handle_t conn_handle, uint16_t
return packet.gattc_r.status;
}
bt_status_t bt_gattc_write_with_signed(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
bt_message_packet_t packet;
bt_status_t status;
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 = 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);
status = bt_socket_client_sendrecv(gattc_remote->ins, &packet, BT_GATT_CLIENT_WRITE_WITH_SIGNED);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.gattc_r.status;
}
bt_status_t bt_gattc_subscribe(gattc_handle_t conn_handle, uint16_t attr_handle, uint16_t ccc_value)
{
bt_message_packet_t packet;

View File

@ -45,7 +45,7 @@ static bt_gatts_remote_t* gatts_remote_new(bt_instance_t* ins, gatts_callbacks_t
remote->ins = ins;
remote->callbacks = callbacks;
remote->cookie = NULL;
remote->cookie = 0;
return remote;
}
@ -91,7 +91,7 @@ bt_status_t bt_gatts_register_service(bt_instance_t* ins, gatts_handle_t* phandl
goto fail;
}
gatts_remote->cookie = INT2PTR(void*) packet.gatts_r.handle;
gatts_remote->cookie = packet.gatts_r.handle;
gatts_remote->user_phandle = phandle;
bt_list_add_tail(ins->gatts_remote_list, gatts_remote);
@ -199,41 +199,49 @@ bt_status_t bt_gatts_add_attr_table(gatts_handle_t srv_handle, gatt_srv_db_t* sr
{
bt_message_packet_t packet;
bt_status_t status;
int32_t attr_offset = 0;
int num_max;
bt_gatts_remote_t* gatts_remote = (bt_gatts_remote_t*)srv_handle;
uint8_t* raw_data = (uint8_t*)packet.gatts_pl._bt_gatts_add_attr_table.attr_db;
uint32_t data_length = sizeof(packet.gatts_pl._bt_gatts_add_attr_table.attr_db[0]) * srv_db->attr_num;
uint8_t* raw_data;
gatt_attr_db_t* attr_inst = srv_db->attr_db;
CHECK_NULL_PTR(gatts_remote);
if (data_length > sizeof(packet.gatts_pl._bt_gatts_add_attr_table.attr_db))
return BT_STATUS_PARM_INVALID;
raw_data += data_length;
for (int i = 0; i < srv_db->attr_num; i++, attr_inst++) {
memcpy(&packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].uuid, &attr_inst->uuid,
sizeof(packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].uuid));
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].handle = attr_inst->handle;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].type = attr_inst->type;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].rsp_type = attr_inst->rsp_type;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].properties = attr_inst->properties;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].permissions = attr_inst->permissions;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].attr_length = attr_inst->attr_length;
while (attr_offset < srv_db->attr_num) {
num_max = (srv_db->attr_num - attr_offset)
> GATTS_MAX_ATTRIBUTE_NUM
? GATTS_MAX_ATTRIBUTE_NUM
: (srv_db->attr_num - attr_offset);
if (attr_inst->rsp_type == ATTR_AUTO_RSP && attr_inst->attr_length) {
data_length += attr_inst->attr_length;
if (data_length > sizeof(packet.gatts_pl._bt_gatts_add_attr_table.attr_db))
return BT_STATUS_PARM_INVALID;
raw_data = (uint8_t*)packet.gatts_pl._bt_gatts_add_attr_table.attr_db
+ sizeof(packet.gatts_pl._bt_gatts_add_attr_table.attr_db[0]) * num_max;
attr_inst = srv_db->attr_db + attr_offset;
memcpy(raw_data, attr_inst->attr_value, attr_inst->attr_length);
raw_data += attr_inst->attr_length;
for (int i = 0; i < num_max; i++, attr_inst++) {
memcpy(&packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].uuid, &attr_inst->uuid,
sizeof(packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].uuid));
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].handle = attr_inst->handle;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].type = attr_inst->type;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].rsp_type = attr_inst->rsp_type;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].properties = attr_inst->properties;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].permissions = attr_inst->permissions;
packet.gatts_pl._bt_gatts_add_attr_table.attr_db[i].attr_length = attr_inst->attr_length;
if (attr_inst->rsp_type == ATTR_AUTO_RSP && attr_inst->attr_length) {
memcpy(raw_data, attr_inst->attr_value, attr_inst->attr_length);
raw_data += attr_inst->attr_length;
}
}
}
packet.gatts_pl._bt_gatts_add_attr_table.handle = PTR2INT(uint64_t) gatts_remote->cookie;
packet.gatts_pl._bt_gatts_add_attr_table.attr_num = srv_db->attr_num;
status = bt_socket_client_sendrecv(gatts_remote->ins, &packet, BT_GATT_SERVER_ADD_ATTR_TABLE);
if (status != BT_STATUS_SUCCESS)
return status;
packet.gatts_pl._bt_gatts_add_attr_table.handle = PTR2INT(uint64_t) gatts_remote->cookie;
packet.gatts_pl._bt_gatts_add_attr_table.attr_num = srv_db->attr_num;
packet.gatts_pl._bt_gatts_add_attr_table.attr_num_offset = attr_offset;
status = bt_socket_client_sendrecv(gatts_remote->ins, &packet, BT_GATT_SERVER_ADD_ATTR_TABLE);
if (status != BT_STATUS_SUCCESS)
return status;
attr_offset += num_max;
}
if (packet.gatts_r.status == BT_STATUS_SUCCESS) {
bt_list_add_tail(gatts_remote->db_list, srv_db);

View File

@ -327,23 +327,6 @@ 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)
@ -372,6 +355,24 @@ bt_status_t bt_hfp_ag_send_clcc_response(bt_instance_t* ins, bt_address_t* addr,
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_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)

View File

@ -454,3 +454,34 @@ bt_status_t bt_hfp_hf_send_dtmf(bt_instance_t* ins, bt_address_t* addr, char dtm
return packet.hfp_hf_r.status;
}
bt_status_t bt_hfp_hf_get_subscriber_number(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.hfp_hf_pl._bt_hfp_hf_get_subscriber_number.addr, addr, sizeof(bt_address_t));
status = bt_socket_client_sendrecv(ins, &packet, BT_HFP_HF_GET_SUBSCRIBER_NUMBER);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.hfp_hf_r.status;
}
bt_status_t bt_hfp_hf_query_current_calls_with_callback(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.hfp_hf_pl._bt_hfp_hf_query_current_calls_with_callback.addr, addr, sizeof(bt_address_t));
status = bt_socket_client_sendrecv(ins, &packet, BT_HFP_HF_QUERY_CURRENT_CALLS_WITH_CALLBACK);
if (status != BT_STATUS_SUCCESS) {
return status;
}
return packet.hfp_hf_r.status;
}

View File

@ -26,7 +26,7 @@ void* bt_l2cap_register_callbacks(bt_instance_t* ins, const l2cap_callbacks_t* c
{
bt_message_packet_t packet;
bt_status_t status;
void* cookie;
void* handle;
BT_SOCKET_INS_VALID(ins, NULL);
@ -39,8 +39,8 @@ void* bt_l2cap_register_callbacks(bt_instance_t* ins, const l2cap_callbacks_t* c
return NULL;
}
cookie = bt_remote_callbacks_register(ins->l2cap_callbacks, NULL, (void*)callbacks);
if (cookie == NULL) {
handle = bt_remote_callbacks_register(ins->l2cap_callbacks, NULL, (void*)callbacks);
if (handle == NULL) {
bt_callbacks_list_free(ins->l2cap_callbacks);
ins->l2cap_callbacks = NULL;
return NULL;
@ -53,10 +53,10 @@ void* bt_l2cap_register_callbacks(bt_instance_t* ins, const l2cap_callbacks_t* c
return NULL;
}
return cookie;
return handle;
}
bool bt_l2cap_unregister_callbacks(bt_instance_t* ins, void* cookie)
bool bt_l2cap_unregister_callbacks(bt_instance_t* ins, void* handle)
{
bt_message_packet_t packet;
bt_status_t status;
@ -68,7 +68,7 @@ bool bt_l2cap_unregister_callbacks(bt_instance_t* ins, void* cookie)
return false;
}
bt_remote_callbacks_unregister(ins->l2cap_callbacks, NULL, cookie);
bt_remote_callbacks_unregister(ins->l2cap_callbacks, NULL, handle);
cbsl = ins->l2cap_callbacks;
ins->l2cap_callbacks = NULL;
@ -82,7 +82,7 @@ bool bt_l2cap_unregister_callbacks(bt_instance_t* ins, void* cookie)
return true;
}
bt_status_t bt_l2cap_listen(bt_instance_t* ins, l2cap_config_option_t* option)
bt_status_t bt_l2cap_listen(bt_instance_t* ins, void* handle, l2cap_config_option_t* option)
{
bt_message_packet_t packet;
bt_status_t status;
@ -94,10 +94,14 @@ bt_status_t bt_l2cap_listen(bt_instance_t* ins, l2cap_config_option_t* option)
if (status != BT_STATUS_SUCCESS)
return status;
option->psm = packet.l2cap_pl._bt_l2cap_listen.option.psm;
option->id = packet.l2cap_pl._bt_l2cap_listen.option.id;
strlcpy(option->proxy_name, packet.l2cap_pl._bt_l2cap_listen.option.proxy_name, sizeof(option->proxy_name));
return packet.l2cap_r.status;
}
bt_status_t bt_l2cap_connect(bt_instance_t* ins, bt_address_t* addr, l2cap_config_option_t* option)
bt_status_t bt_l2cap_connect(bt_instance_t* ins, void* handle, bt_address_t* addr, l2cap_config_option_t* option)
{
bt_message_packet_t packet;
bt_status_t status;
@ -110,20 +114,55 @@ bt_status_t bt_l2cap_connect(bt_instance_t* ins, bt_address_t* addr, l2cap_confi
if (status != BT_STATUS_SUCCESS)
return status;
option->id = packet.l2cap_pl._bt_l2cap_connect.option.id;
strlcpy(option->proxy_name, packet.l2cap_pl._bt_l2cap_connect.option.proxy_name, sizeof(option->proxy_name));
return packet.l2cap_r.status;
}
bt_status_t bt_l2cap_disconnect(bt_instance_t* ins, uint16_t cid)
bt_status_t bt_l2cap_disconnect(bt_instance_t* ins, void* handle, uint16_t id)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.l2cap_pl._bt_l2cap_disconnect.cid = cid;
packet.l2cap_pl._bt_l2cap_disconnect.id = id;
status = bt_socket_client_sendrecv(ins, &packet, BT_L2CAP_DISCONNECT);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.l2cap_r.status;
}
bt_status_t bt_l2cap_stop_listen(bt_instance_t* ins, void* handle, uint16_t psm)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.l2cap_pl._bt_l2cap_stop_listen.transport = BT_TRANSPORT_BLE;
packet.l2cap_pl._bt_l2cap_stop_listen.psm = psm;
status = bt_socket_client_sendrecv(ins, &packet, BT_L2CAP_STOP_LISTEN);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.l2cap_r.status;
}
bt_status_t bt_l2cap_stop_listen_with_transport(bt_instance_t* ins, void* handle, bt_transport_t transport, uint16_t psm)
{
bt_message_packet_t packet;
bt_status_t status;
BT_SOCKET_INS_VALID(ins, BT_STATUS_PARM_INVALID);
packet.l2cap_pl._bt_l2cap_stop_listen.transport = transport;
packet.l2cap_pl._bt_l2cap_stop_listen.psm = psm;
status = bt_socket_client_sendrecv(ins, &packet, BT_L2CAP_STOP_LISTEN);
if (status != BT_STATUS_SUCCESS)
return status;
return packet.l2cap_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

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "adv"
#define LOG_TAG "scan"
#include <stdlib.h>
@ -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

@ -33,6 +33,8 @@ func frameworkBluetoothHook(ctx android.LoadHookContext) {
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,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 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 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,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 get_os_timestamp_us(void);
uint32_t get_os_timestamp_ms(void);
#endif /* _BT_STORAGE_H__ */

View File

@ -287,8 +287,10 @@ void service_loop_exit(void)
uv_sem_wait(&loop->exited);
uv_sem_destroy(&loop->exited);
} else {
uv_run(handle, UV_RUN_ONCE);
(void)uv_loop_close(handle);
if (!uv_loop_is_close(handle)) {
uv_run(handle, UV_RUN_ONCE);
(void)uv_loop_close(handle);
}
}
uv_mutex_lock(&loop->msg_lock);

View File

@ -1,221 +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.
***************************************************************************/
#define LOG_TAG "storage"
#include <nuttx/crc16.h>
#include <stdint.h>
#include <time.h>
#include <unistd.h>
#include "bluetooth_define.h"
#include "service_loop.h"
#include "storage.h"
#include "utils/log.h"
#include "uv_ext.h"
#define BT_DB_FOLDER_PATH "/data/misc/bt"
#define BT_DB_FILE_NAME "bt_storage.db"
#define BT_DB_FILE_PATH BT_DB_FOLDER_PATH "/" BT_DB_FILE_NAME
#define REMOTE_DEVICE_FILE_NAME "device.db"
#define BT_KEY_ADAPTER_INFO "AdapterInfo"
#define BT_KEY_BTBOND "BtBonded"
#define BT_KEY_BLEBOND "BleBonded"
#define BT_KEY_BLEWHITELIST "WhiteList"
#define BT_KEY_BLERESOLVINGLIST "ResolvingList"
#define BT_KEY_BLEGATTHASH "BleGattDBHash"
typedef struct {
uint16_t items;
uint16_t key_length;
uint8_t key_value[0];
} key_header_t;
static uv_db_t* storage_handle = NULL;
static void key_set_callback(int status, const char* key, uv_buf_t value, void* cookie)
{
free(value.base);
if (status == 0)
uv_db_commit(storage_handle);
}
static void key_get_callback(int status, const char* key, uv_buf_t value, void* cookie)
{
load_storage_callback_t callback = (load_storage_callback_t)cookie;
if (status == 0) {
key_header_t* header = (key_header_t*)value.base;
assert(value.len == (sizeof(key_header_t) + header->key_length));
callback(header->key_value, header->key_length, header->items);
} else
callback(NULL, 0, 0);
}
static int storage_set_key(const char* key, void* data, uint16_t length)
{
uv_buf_t buf = uv_buf_init((char*)data, length);
int ret = uv_db_set(storage_handle, key, &buf, key_set_callback, NULL);
if (ret != 0)
BT_LOGE("key %s set error:%d", key, ret);
return ret;
}
static int storage_get_key(const char* key, void** data, uint16_t* length, void* cookie)
{
uv_buf_t buf;
if (data)
buf = uv_buf_init(NULL, 0);
int ret = uv_db_get(storage_handle, key, data ? &buf : NULL,
data ? NULL : key_get_callback, cookie);
if (ret == 0 && data) {
*data = buf.base;
*length = buf.len;
}
return ret;
}
static void adapter_properties_default(adapter_storage_t* prop)
{
srand(time(NULL));
int r = rand() % 999;
snprintf(prop->name, BT_LOC_NAME_MAX_LEN, "%s-%03X", "XIAOMI VELA", r);
prop->class_of_device = DEFAULT_DEVICE_OF_CLASS;
prop->io_capability = DEFAULT_IO_CAPABILITY;
prop->scan_mode = DEFAULT_SCAN_MODE;
prop->bondable = DEFAULT_BONDABLE_MODE;
}
int bt_storage_save_adapter_info(adapter_storage_t* adapter)
{
key_header_t* key = malloc(sizeof(key_header_t) + sizeof(*adapter));
key->items = 1;
key->key_length = sizeof(*adapter);
memcpy(key->key_value, adapter, sizeof(*adapter));
int ret = storage_set_key(BT_KEY_ADAPTER_INFO, key, sizeof(key_header_t) + sizeof(*adapter));
if (ret != 0)
free(key);
return ret;
}
int bt_storage_load_adapter_info(adapter_storage_t* adapter)
{
uint16_t len = sizeof(key_header_t) + sizeof(*adapter);
key_header_t* key;
if (storage_get_key(BT_KEY_ADAPTER_INFO, (void**)&key, &len, NULL) == 0) {
memcpy(adapter, key->key_value, sizeof(*adapter));
free(key);
} else {
adapter_properties_default(adapter);
bt_storage_save_adapter_info(adapter);
}
return 0;
}
static int bt_storage_save_remote_device(const char* key, void* value, uint16_t value_size, uint16_t items)
{
uint16_t total_length = value_size * items;
key_header_t* header = malloc(sizeof(key_header_t) + total_length);
header->items = items;
header->key_length = total_length;
if (value && items)
memcpy(header->key_value, value, total_length);
int ret = storage_set_key(key, header, sizeof(key_header_t) + total_length);
if (ret != 0)
free(header);
return ret;
}
int bt_storage_save_gatt_cache_device(remote_device_gatt_properties_t* remote, uint16_t size)
{
return bt_storage_save_remote_device(BT_KEY_BLEGATTHASH, remote, sizeof(*remote), size);
}
int bt_storage_save_bonded_device(remote_device_properties_t* remote, uint16_t size)
{
return bt_storage_save_remote_device(BT_KEY_BTBOND, remote, sizeof(*remote), size);
}
int bt_storage_save_whitelist(remote_device_le_properties_t* remote, uint16_t size)
{
return bt_storage_save_remote_device(BT_KEY_BLEWHITELIST, remote, sizeof(*remote), size);
}
int bt_storage_save_le_bonded_device(remote_device_le_properties_t* remote, uint16_t size)
{
return bt_storage_save_remote_device(BT_KEY_BLEBOND, remote, sizeof(*remote), size);
}
int bt_storage_load_gatt_cache_device(load_storage_callback_t cb)
{
return storage_get_key(BT_KEY_BLEGATTHASH, NULL, NULL, (void*)cb);
}
int bt_storage_load_bonded_device(load_storage_callback_t cb)
{
return storage_get_key(BT_KEY_BTBOND, NULL, NULL, (void*)cb);
}
int bt_storage_load_whitelist_device(load_storage_callback_t cb)
{
return storage_get_key(BT_KEY_BLEWHITELIST, NULL, NULL, (void*)cb);
}
int bt_storage_load_le_bonded_device(load_storage_callback_t cb)
{
return storage_get_key(BT_KEY_BLEBOND, NULL, NULL, (void*)cb);
}
void bt_storage_load_le_device_info(void)
{
}
void bt_storage_load_irk_info(void)
{
}
int bt_storage_init(void)
{
int ret;
ret = uv_db_init(get_service_uv_loop(), &storage_handle, BT_DB_FILE_PATH);
if (ret != 0)
BT_LOGE("%s fail, ret:%d", __func__, ret);
BT_LOGD("%s successed", __func__);
return ret;
}
int bt_storage_cleanup(void)
{
BT_LOGD("%s", __func__);
if (storage_handle)
uv_db_close(storage_handle);
storage_handle = NULL;
return 0;
}

View File

@ -1,68 +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_STORAGE_H__
#define _BT_STORAGE_H__
#include "bluetooth_define.h"
typedef void (*load_storage_callback_t)(void* data, uint16_t length, uint16_t items);
int bt_storage_init(void);
int bt_storage_cleanup(void);
int bt_storage_save_adapter_info(adapter_storage_t* adapter);
int bt_storage_load_adapter_info(adapter_storage_t* adapter);
int bt_storage_save_bonded_device(remote_device_properties_t* remote, uint16_t size);
int bt_storage_save_whitelist(remote_device_le_properties_t* remote, uint16_t size);
int bt_storage_save_le_bonded_device(remote_device_le_properties_t* remote, uint16_t size);
int bt_storage_save_gatt_cache_device(remote_device_gatt_properties_t* remote, uint16_t size);
int bt_storage_load_bonded_device(load_storage_callback_t cb);
int bt_storage_load_whitelist_device(load_storage_callback_t cb);
int bt_storage_load_le_bonded_device(load_storage_callback_t cb);
int bt_storage_load_gatt_cache_device(load_storage_callback_t cb);
#ifdef CONFIG_BLUETOOTH_STORAGE_PROPERTY_SUPPORT
#define GEN_PROP_KEY(buf, key, address, len) snprintf((buf), (len), "%s%02X:%02X:%02X:%02X:%02X:%02X", \
(key), \
(address)->addr[5], (address)->addr[4], (address)->addr[3], \
(address)->addr[2], (address)->addr[1], (address)->addr[0])
#define PARSE_PROP_KEY(addr_str, name, name_prefix_len, addr_str_len, addr_ptr) \
do { \
strlcpy((addr_str), (name) + (name_prefix_len), (addr_str_len)); \
bt_addr_str2ba((addr_str), (addr_ptr)); \
} while (0)
#define ERROR_ADAPTERINFO_VALUE -1
#define BT_KVDB_ADAPTERINFO_NAME "persist.bluetooth.adapterInfo.name"
#define BT_KVDB_ADAPTERINFO_COD "persist.bluetooth.adapterInfo.class_of_device"
#define BT_KVDB_ADAPTERINFO_IOCAP "persist.bluetooth.adapterInfo.io_capability"
#define BT_KVDB_ADAPTERINFO_SCAN "persist.bluetooth.adapterInfo.scan_mode"
#define BT_KVDB_ADAPTERINFO_BOND "persist.bluetooth.adapterInfo.bondable"
#define BT_KVDB_ADAPTERINFO_IRK "persist.bluetooth.adapterInfo.irk"
#define BT_KVDB_ADAPTERINFO "persist.bluetooth.adapterInfo."
#define BT_KVDB_BTBOND "persist.bluetooth.btbonded."
#define BT_KVDB_BLEBOND "persist.bluetooth.blebonded."
#define BT_KVDB_BLEWHITELIST "persist.bluetooth.whitelist."
#define BT_KVDB_BLEGATTDBHASH "persist.bluetooth.blegattDBhash."
int bt_storage_properties_destory(void);
void bt_storage_delete(char* key, uint16_t items, char* prop_name);
#endif
#endif /* _BT_STORAGE_H__ */

View File

@ -25,8 +25,8 @@
#endif
#include "bluetooth_define.h"
#include "bt_storage.h"
#include "service_loop.h"
#include "storage.h"
#include "utils/log.h"
#include "uv_ext.h"
@ -672,6 +672,11 @@ int bt_storage_properties_destory(void)
property_list(callback_whitelist_count, &items);
bt_storage_delete(BT_KVDB_BLEWHITELIST, items, prop_name);
/* remove all GATT cache device property */
items = 0;
property_list(callback_gatthash_count, &items);
bt_storage_delete(BT_KVDB_BLEGATTDBHASH, items, prop_name);
/* remove all BREDR bond device property */
items = 0;
property_list(callback_bt_count, &items);
@ -685,6 +690,7 @@ int bt_storage_properties_destory(void)
ret |= property_delete(BT_KVDB_ADAPTERINFO_IOCAP);
ret |= property_delete(BT_KVDB_ADAPTERINFO_SCAN);
ret |= property_delete(BT_KVDB_ADAPTERINFO_BOND);
ret |= property_delete(BT_KVDB_ADAPTERINFO_IRK);
if (ret) {
BT_LOGE("property_delete failed!");
return ret;

View File

@ -60,7 +60,7 @@ bt_status_t BpBtAdapter_SetLeIOCapability(BpBtAdapter* bpBinder, uint32_t le_io_
uint32_t BpBtAdapter_getLeIOCapability(BpBtAdapter* bpBinder);
bt_status_t BpBtAdapter_getLeAddress(BpBtAdapter* bpBinder, bt_address_t* addr, ble_addr_type_t* type);
bt_status_t BpBtAdapter_setLeAddress(BpBtAdapter* bpBinder, bt_address_t* addr);
bt_status_t BpBtAdapter_setLeIdentityAddress(BpBtAdapter* bpBinder, bt_address_t* addr, bool public);
bt_status_t BpBtAdapter_setLeIdentityAddress(BpBtAdapter* bpBinder, bt_address_t* addr, bool is_public);
bt_status_t BpBtAdapter_setLeAppearance(BpBtAdapter* bpBinder, uint16_t appearance);
uint16_t BpBtAdapter_getLeAppearance(BpBtAdapter* bpBinder);
bt_status_t BpBtAdapter_getBondedDevices(BpBtAdapter* bpBinder, bt_address_t** addr, int* num, bt_allocator_t allocator);

View File

@ -658,7 +658,7 @@ bt_status_t BpBtAdapter_setLeAddress(BpBtAdapter* bpBinder, bt_address_t* addr)
return status;
}
bt_status_t BpBtAdapter_setLeIdentityAddress(BpBtAdapter* bpBinder, bt_address_t* addr, bool public)
bt_status_t BpBtAdapter_setLeIdentityAddress(BpBtAdapter* bpBinder, bt_address_t* addr, bool is_public)
{
binder_status_t stat = STATUS_OK;
AParcel *parcelIn, *parcelOut;
@ -673,7 +673,7 @@ bt_status_t BpBtAdapter_setLeIdentityAddress(BpBtAdapter* bpBinder, bt_address_t
if (stat != STATUS_OK)
return BT_STATUS_IPC_ERROR;
stat = AParcel_writeBool(parcelIn, public);
stat = AParcel_writeBool(parcelIn, is_public);
if (stat != STATUS_OK)
return BT_STATUS_IPC_ERROR;

View File

@ -43,7 +43,6 @@ extern "C" {
#define BT_IPC_CODE_GROUP_AVRCP_TG (BT_IPC_CODE_GROUP_PROFILES + PROFILE_AVRCP_TG)
#define BT_IPC_CODE_GROUP_HFP_HF (BT_IPC_CODE_GROUP_PROFILES + PROFILE_HFP_HF)
#define BT_IPC_CODE_GROUP_HFP_AG (BT_IPC_CODE_GROUP_PROFILES + PROFILE_HFP_AG)
#define BT_IPC_CODE_GROUP_CS (BT_IPC_CODE_GROUP_PROFILES + PROFILE_CS)
#define BT_IPC_CODE_GROUP_SPP (BT_IPC_CODE_GROUP_PROFILES + PROFILE_SPP)
#define BT_IPC_CODE_GROUP_HID_DEV (BT_IPC_CODE_GROUP_PROFILES + PROFILE_HID_DEV)
#define BT_IPC_CODE_GROUP_PANU (BT_IPC_CODE_GROUP_PROFILES + PROFILE_PANU)

View File

@ -43,7 +43,6 @@ extern "C" {
#include "bt_message_pan.h"
#include "bt_message_scan.h"
#include "bt_message_spp.h"
#include "bt_message_cs.h"
#include "service_loop.h"
@ -68,7 +67,6 @@ typedef enum {
#include "bt_message_pan.h"
#include "bt_message_scan.h"
#include "bt_message_spp.h"
#include "bt_message_cs.h"
BT_MESSAGE_END,
#undef __BT_MESSAGE_CODE__
#define __BT_CALLBACK_CODE__
@ -90,7 +88,6 @@ typedef enum {
#include "bt_message_pan.h"
#include "bt_message_scan.h"
#include "bt_message_spp.h"
#include "bt_message_cs.h"
BT_CALLBACK_END,
#undef __BT_MESSAGE_CODE__
} bt_message_type_t;
@ -108,7 +105,6 @@ typedef struct
bt_a2dp_source_result_t a2dp_source_r;
bt_avrcp_target_result_t avrcp_target_r;
bt_avrcp_control_result_t avrcp_control_r;
bt_cs_result_t cs_r;
bt_hfp_ag_result_t hfp_ag_r;
bt_hfp_hf_result_t hfp_hf_r;
bt_advertiser_result_t adv_r;
@ -135,7 +131,6 @@ typedef struct
bt_message_a2dp_source_callbacks_t a2dp_source_cb;
bt_message_avrcp_target_t avrcp_target_pl;
bt_message_cs_t cs_pl;
bt_message_avrcp_target_callbacks_t avrcp_target_cb;
bt_message_avrcp_control_t avrcp_control_pl;
bt_message_avrcp_control_callbacks_t avrcp_control_cb;

View File

@ -18,6 +18,7 @@
BT_ADAPTER_MESSAGE_START,
BT_ADAPTER_ENABLE,
BT_ADAPTER_DISABLE,
BT_ADAPTER_DISABLE_SAFE,
BT_ADAPTER_ENABLE_LE,
BT_ADAPTER_DISABLE_LE,
BT_ADAPTER_GET_STATE,
@ -121,6 +122,7 @@ BT_ADAPTER_MESSAGE_START,
typedef union {
struct {
bt_address_t addr;
uint8_t type;
} _bt_adapter_get_address,
_bt_adapter_set_le_address,
_bt_adapter_le_add_whitelist,

View File

@ -39,8 +39,8 @@ BT_ADVERTISER_MESSAGE_START,
#endif
#include "bluetooth.h"
#include "bt_ipc_code.h"
#include "bt_le_advertiser.h"
#include "bt_ipc_code.h"
#define BT_IPC_CODE_COMMAND_BLE_ADVERTISER_BEGIN BT_IPC_CODE(BT_IPC_CODE_TYPE_COMMAND, BT_IPC_CODE_GROUP_BLE_ADVERTISER, 0)
// TODO: Add new BT IPC Code sequentially
@ -60,7 +60,7 @@ BT_ADVERTISER_MESSAGE_START,
typedef struct
{
bt_instance_t* ins;
advertiser_callback_t* callbacks;
advertiser_callback_t* callback;
uint64_t remote;
} bt_advertiser_remote_t;

View File

@ -83,7 +83,6 @@ BT_AVRCP_CONTROL_MESSAGE_START,
struct {
bt_address_t addr;
uint8_t event;
uint8_t pad[1];
uint32_t interval;
} _bt_avrcp_control_register_notification;
} bt_message_avrcp_control_t;

View File

@ -1,85 +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_MESSAGE_CS_H__
#define _BT_MESSAGE_CS_H__
#include "bt_cs.h"
#include "bt_ipc_code.h"
#define BT_IPC_CODE_COMMAND_CS_BEGIN BT_IPC_CODE(BT_IPC_CODE_TYPE_COMMAND, BT_IPC_CODE_GROUP_CS, 0)
// TODO: Add new BT IPC Code sequentially
#define CS_SUBCODE_REGISTER_CALLBACKS 1
#define BT_CS_REGISTER_CALLBACKS BT_IPC_CODE(BT_IPC_CODE_TYPE_COMMAND, BT_IPC_CODE_GROUP_CS, CS_SUBCODE_REGISTER_CALLBACKS)
#define CS_SUBCODE_UNREGISTER_CALLBACKS 2
#define BT_CS_UNREGISTER_CALLBACKS BT_IPC_CODE(BT_IPC_CODE_TYPE_COMMAND, BT_IPC_CODE_GROUP_CS, CS_SUBCODE_UNREGISTER_CALLBACKS)
#define CS_SUBCODE_START_DISTANCE_MEASUREMENT 3
#define BT_CS_START_DISTANCE_MEASUREMENT BT_IPC_CODE(BT_IPC_CODE_TYPE_COMMAND, BT_IPC_CODE_GROUP_CS, CS_SUBCODE_START_DISTANCE_MEASUREMENT)
#define CS_SUBCODE_STOP_DISTANCE_MEASUREMENT 4
#define BT_CS_STOP_DISTANCE_MEASUREMENT BT_IPC_CODE(BT_IPC_CODE_TYPE_COMMAND, BT_IPC_CODE_GROUP_CS, CS_SUBCODE_STOP_DISTANCE_MEASUREMENT)
#define CS_SUBCODE_SET_CONFIG 5
#define BT_CS_SET_CONFIG BT_IPC_CODE(BT_IPC_CODE_TYPE_COMMAND, BT_IPC_CODE_GROUP_CS, CS_SUBCODE_SET_CONFIG)
#ifdef CONFIG_BT_CS_RAS_TEST
#define CS_SUBCODE_TEST 6
#define BT_CS_TEST BT_IPC_CODE(BT_IPC_CODE_TYPE_COMMAND, BT_IPC_CODE_GROUP_CS, CS_SUBCODE_TEST)
#endif /* CONFIG_BT_CS_RAS_TEST */
#define BT_IPC_CODE_COMMAND_CS_END BT_IPC_CODE(BT_IPC_CODE_TYPE_COMMAND, BT_IPC_CODE_GROUP_CS, BT_IPC_CODE_SUBCODE_MAX_NUM)
#define BT_IPC_CODE_CALLBACK_CS_BEGIN BT_IPC_CODE(BT_IPC_CODE_TYPE_CALLBACK, BT_IPC_CODE_GROUP_CS, 0)
// TODO: Add new BT IPC Code sequentially
#define BT_IPC_CODE_CALLBACK_CS_END BT_IPC_CODE(BT_IPC_CODE_TYPE_CALLBACK, BT_IPC_CODE_GROUP_CS, BT_IPC_CODE_SUBCODE_MAX_NUM)
typedef union {
uint8_t status; /* bt_status_t */
// uint8_t profile_conn_state; /* profile_connection_state_t */
// uint8_t value_bool; /* boolean */
} bt_cs_result_t;
typedef union {
struct {
bt_distance_measurement_params_t params;
} _bt_cs_start_distance_measurement;
struct {
bt_address_t addr;
uint8_t method;
uint8_t timeout_bool; /* boolean */
} _bt_cs_stop_distance_measurement;
struct {
bt_address_t addr;
bt_cs_set_params_t params;
} _bt_cs_set_config;
#ifdef CONFIG_BT_CS_RAS_TEST
struct {
uint16_t len;
uint8_t data[MAX_TEST_DATA];
} _bt_cs_test;
#endif /* CONFIG_BT_CS_RAS_TEST */
} bt_message_cs_t;
typedef union {
struct {
bt_address_t addr;
uint8_t state; /* profile_connection_state_t */
} _on_connection_state_changed;
} bt_message_cs_callbacks_t;
#endif /* _BT_MESSAGE_CS_H__ */

View File

@ -42,13 +42,17 @@ BT_DEVICE_MESSAGE_START,
BT_DEVICE_SET_LE_SC_REMOTE_OOB_DATA,
BT_DEVICE_GET_LE_SC_LOCAL_OOB_DATA,
BT_DEVICE_CONNECT,
BT_DEVICE_BACKGROUND_CONNECT,
BT_DEVICE_DISCONNECT,
BT_DEVICE_BACKGROUND_DISCONNECT,
BT_DEVICE_CONNECT_LE,
BT_DEVICE_DISCONNECT_LE,
BT_DEVICE_CONNECT_REQUEST_REPLY,
BT_DEVICE_SET_LE_PHY,
BT_DEVICE_CONNECT_ALL_PROFILE,
BT_DEVICE_DISCONNECT_ALL_PROFILE,
BT_DEVICE_ENABLE_ENHANCED_MODE,
BT_DEVICE_DISABLE_ENHANCED_MODE,
BT_DEVICE_MESSAGE_END,
#endif
@ -149,7 +153,9 @@ BT_DEVICE_MESSAGE_START,
_bt_device_is_encrypted,
_bt_device_is_bond_initiate_local,
_bt_device_get_bond_state,
_bt_device_is_bonded;
_bt_device_is_bonded,
_bt_device_background_connect,
_bt_device_background_disconnect;
struct {
bt_address_t addr;
@ -206,6 +212,12 @@ BT_DEVICE_MESSAGE_START,
uint8_t rx_phy; /* ble_phy_type_t */
} _bt_device_set_le_phy;
struct {
bt_address_t addr;
uint8_t mode; /* bt_enhanced_mode_t */
} _bt_device_enable_enhanced_mode,
_bt_device_disable_enhanced_mode;
} bt_message_device_t;
#ifdef __cplusplus

View File

@ -66,6 +66,9 @@ BT_GATT_CLIENT_MESSAGE_START,
#define BT_IPC_CODE_COMMAND_GATTC_BEGIN BT_IPC_CODE(BT_IPC_CODE_TYPE_COMMAND, BT_IPC_CODE_GROUP_GATTC, 0)
// TODO: Add new BT IPC Code sequentially
#define BT_GATT_CLIENT_SUBCODE_WRITE_WITH_SIGNED 1
#define BT_GATT_CLIENT_WRITE_WITH_SIGNED BT_IPC_CODE(BT_IPC_CODE_TYPE_COMMAND, BT_IPC_CODE_GROUP_GATTC, BT_GATT_CLIENT_SUBCODE_WRITE_WITH_SIGNED)
#define BT_IPC_CODE_COMMAND_GATTC_END BT_IPC_CODE(BT_IPC_CODE_TYPE_COMMAND, BT_IPC_CODE_GROUP_GATTC, BT_IPC_CODE_SUBCODE_MAX_NUM)
#define BT_IPC_CODE_CALLBACK_GATTC_BEGIN BT_IPC_CODE(BT_IPC_CODE_TYPE_CALLBACK, BT_IPC_CODE_GROUP_GATTC, 0)
@ -75,7 +78,7 @@ BT_GATT_CLIENT_MESSAGE_START,
typedef struct {
bt_instance_t* ins;
gattc_callbacks_t* callbacks;
void* cookie;
uint64_t cookie;
void** user_phandle;
} bt_gattc_remote_t;

View File

@ -71,7 +71,7 @@ BT_GATT_SERVER_MESSAGE_START,
typedef struct {
bt_instance_t* ins;
gatts_callbacks_t* callbacks;
void* cookie;
uint64_t cookie;
void** user_phandle;
bt_list_t* db_list;
} bt_gatts_remote_t;
@ -117,6 +117,7 @@ BT_GATT_SERVER_MESSAGE_START,
struct {
uint64_t handle; /* gatts_handle_t */
int32_t attr_num_offset;
int32_t attr_num;
struct {
bt_uuid_t uuid;

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