Compare commits

...

13 Commits

Author SHA1 Message Date
openvela-robot 65fe56749b Update the ci trigger from pull_request to pull_request_target 2025-01-09 23:57:24 +08:00
openvela-robot 95835120ec update CODEOWNERS, delete xiaoxiang781216 GUIDINGLI 2025-01-02 10:02:58 +08:00
openvela-robot e965a8484f update workflows ci.yml, delete pull_request_review trigger 2024-12-28 00:06:22 +08:00
openvela-robot 096afad711 add .github/CODEOWNERS PULL_REQUEST_TEMPLATE.md 2024-12-27 19:50:46 +08:00
openvela-robot a56ade4782 update ci pull_request types to [opened, reopened, synchronize] 2024-12-24 01:17:36 +08:00
liujinye f6ff415e55 workflows add ci.yaml 2024-12-17 10:25:50 +08:00
openvela-robot c3c60105fa workflows add checkpatch.yaml 2024-12-12 16:14:45 +08:00
openvela-robot 339de05938 update issue template 2024-12-10 22:13:51 +08:00
openvela-robot cc84ed0b6f update workflows ci 2024-12-10 15:55:25 +08:00
openvela-robot a3d9b24322 add issue template 2024-12-09 21:39:46 +08:00
Haishen Zhang 675dc80db6 Doc: Remove QuickAPP API details
Remove QuickAPP API details, for they've not been published yet.

Change-Id: Ie25d6c5088b118fadf681ba076ea984de7c15297
Signed-off-by: Haishen Zhang <zhanghaishen@xiaomi.com>
2024-12-09 18:08:02 +08:00
openvela-robot 5805376c2b add ci.yml
Change-Id: Ica3c29801931a43fa5fb0bc327ece0f609e56cd3
2024-11-25 19:44:17 +08:00
openvela-robot cf07bea530 Merge commit
Change-Id: If26995eebd18a82ac4cd827e6801458e57a6ead3
2024-11-25 17:34:53 +08:00
473 changed files with 103406 additions and 0 deletions

3
.clang-format Normal file
View File

@ -0,0 +1,3 @@
---
Language: Cpp
BasedOnStyle: WebKit

View File

@ -0,0 +1,40 @@
name: 缺陷反馈 | Bug
description: 当您发现了一个缺陷,需要向社区反馈时,请使用此模板。
title: "[BUG] <标题>"
labels: [👀 needs triage, "Type: Bug"]
body:
- type: markdown
attributes:
value: |
感谢您对 openvela 社区的支持与关注,欢迎反馈缺陷。
- type: textarea
attributes:
label: "重现问题的步骤"
description: "简洁地描述错误是什么,为什么您认为它是一个错误,以及如何重现它的步骤"
placeholder: |
重现问题的步骤,可能包括日志和截图。
1. 步骤 1
2. 步骤 2
validations:
required: true
- type: dropdown
id: architecture
attributes:
label: Issue Architecture
multiple: true
options:
- "Arch: arm"
- "Arch: arm64"
- "Arch: x86_64"
validations:
required: true
- type: markdown
attributes:
value: |
提交前请确认您已遵循以下步骤:
- 确认问题在 [**dev**](../) 上可重现。
- 遇到构建问题时运行 `make distclean`。
- 搜索 [现有问题](./)

View File

@ -0,0 +1,34 @@
name: 新需求 | Feature
description: 当您需要反馈或实现一个新需求时,使用此模板。
title: "[FEATURE] <标题>"
body:
- type: markdown
attributes:
value: |
感谢您对 openvela 社区的支持与关注。
- type: textarea
id: question-description
attributes:
label: 您的需求是否和问题相关?
description: 请简单描述问题并提供issue链接。
validations:
required: true
- type: textarea
id: solution
attributes:
label: 请描述您想要的解决方案
validations:
required: true
- type: textarea
id: 替代方案
attributes:
label: 请描述您考虑过的替代解决方案
- type: markdown
attributes:
value: |
提交前请搜索 [现有功能需求](./)

View File

@ -0,0 +1,22 @@
name: 问题咨询
title: "[问题咨询]"
body:
- type: markdown
attributes:
value: |
感谢您对 openvela 社区的支持与关注。
- type: textarea
id: question-description
attributes:
label: 描述
description: 请解释您的问题的背景或上下文,这有助于其他人更好地理解您的问题或疑问。
validations:
required: true
- type: markdown
attributes:
value: |
提交前请确认您已遵循以下步骤:
- 我已搜索 [openvela 文档](../),但未找到问题的答案。
- 已搜索 [现有问题](./)

View File

@ -0,0 +1 @@
blank_issues_enabled: false

View File

@ -0,0 +1,11 @@
## 概要
*在此部分更新信息,说明更改的必要性、具体做了什么以及如何实现的,如果有新功能出现,请提供参考资料(依赖关系、类似问题和解决方案等)。*
## 影响
*在此部分更新信息(如适用),说明更改如何影响用户、构建过程、硬件、文档、安全性、兼容性等。*
## 测试
*在此部分更新信息详细说明如何验证更改使用什么主机进行构建操作系统、CPU、编译器等使用什么目标进行验证架构、板子配置等。提供更改前后的构建和运行日志将非常有帮助。*

1
.github/CODEOWNERS vendored Normal file
View File

@ -0,0 +1 @@
* @hyson710

View File

@ -0,0 +1,60 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: Bug report
description: Report a bug to improve openvela stability
title: "[BUG] <title>"
labels: [👀 needs triage, "Type: Bug"]
body:
- type: markdown
attributes:
value: |
Hello openvela Community member! Please keep things tidy by putting your post in the proper place:
Reporting a bug: use this form.
Asking a question or getting help: use the [General Help](./new?assignees=&labels=Community%3A+Question&projects=&template=003_help.yml&title=%5BHELP%5D+%3Ctitle%3E) form.
Requesting a new feature: use the [Feature request](./new?assignees=&labels=Type%3A+Enhancement&projects=&template=002_feature_request.yml&title=%5BFEATURE%5D+%3Ctitle%3E) form.
- type: textarea
attributes:
label: "Description / Steps to reproduce the issue"
description: "A clear and concise description of what the bug is, and why you consider it to be a bug, and steps for how to reproduce it"
placeholder: |
A description with steps to reproduce the issue.
May include logs, images, or videos.
1. Step 1
2. Step 2
validations:
required: true
- type: dropdown
id: architecture
attributes:
label: Issue Architecture
description: What architecture(s) are you seeing the problem on?
multiple: true
options:
- "[Arch: arm]"
- "[Arch: arm64]"
- "[Arch: x86_64]"
validations:
required: true
- type: markdown
attributes:
value: |
### Before You Submit
Please verify that you've followed these steps:
- Confirm the problem is reproducible on [**dev**](../).
- Run `make distclean` when encountering build issues.
- Search [existing issues](./) (including [closed](./?q=is%3Aissue+is%3Aclosed))

View File

@ -0,0 +1,55 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: Feature request
description: Request an enhancement for openvela
title: "[FEATURE] <title>"
labels: ["Type: Enhancement"]
body:
- type: markdown
attributes:
value: |
Hello openvela Community member! Please keep things tidy by putting your post in the proper place:
Requesting a new feature: use this form.
Asking a question or getting help: use the [General Help](./new?assignees=&labels=Community%3A+Question&projects=&template=003_help.yml&title=%5BHELP%5D+%3Ctitle%3E) form.
Reporting a bug: use the [Bug report](./new?assignees=&labels=%F0%9F%91%80+needs+triage%2CType%3A+Bug&projects=&template=001_bug_report.yml&title=%5BBUG%5D+%3Ctitle%3E) form.
- type: textarea
id: question-description
attributes:
label: Is your feature request related to a problem? Please describe.
description: Please provide a clear and concise description of what the problem is. Add relevant issue link.
validations:
required: true
- type: textarea
id: solution
attributes:
label: Describe the solution you'd like
description: Please provide a clear and concise description of what you want to happen.
validations:
required: true
- type: textarea
id: alternatives
attributes:
label: Describe alternatives you've considered
description: Please provide a clear and concise description of any alternative solutions or features you've considered.
- type: markdown
attributes:
value: |
### Before You Submit
Please verify that you've followed these steps:
- Search [existing feature requests](./) (including [closed](./?q=is%3Aissue+is%3Aclosed))

47
.github/ISSUE_TEMPLATE/003_help.yml vendored Normal file
View File

@ -0,0 +1,47 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name: General Help
description: Get general support regarding openvela
title: "[HELP] <title>"
labels: ["Community: Question"]
body:
- type: markdown
attributes:
value: |
Hello openvela Community member! Please keep things tidy by putting your post in the proper place:
Asking a question or getting help: use this form.
Reporting a bug: use the [Bug report](./new?assignees=&labels=%F0%9F%91%80+needs+triage%2CType%3A+Bug&projects=&template=001_bug_report.yml&title=%5BBUG%5D+%3Ctitle%3E) form.
Requesting a new feature: use the [Feature request](./new?assignees=&labels=Type%3A+Enhancement&projects=&template=002_feature_request.yml&title=%5BFEATURE%5D+%3Ctitle%3E) form
- type: markdown
attributes:
value: |
### Whether you're a beginner or an experienced developer, openvela Help is here to assist you with all your openvela questions and concerns.
- type: textarea
id: question-description
attributes:
label: Description
description: Explain the background or context of your question. This helps others understand your problem or inquiry better.
validations:
required: true
- type: markdown
attributes:
value: |
### Before You Submit
Please verify that you've followed these steps:
- I have searched [openvela Documentation](../) and didn't find an answer to my question.
- Search [existing issues](./) (including [closed](./?q=is%3Aissue+is%3Aclosed))

1
.github/ISSUE_TEMPLATE/config.yml vendored Normal file
View File

@ -0,0 +1 @@
blank_issues_enabled: false

20
.github/PULL_REQUEST_TEMPLATE.md vendored Normal file
View File

@ -0,0 +1,20 @@
*Note: Please adhere to [Contributing Guidelines](https://github.com/open-vela/docs/blob/dev/CONTRIBUTING.md).*
## Summary
*Update this section with information on why change is necessary,
what it exactly does and how, if new feature shows up, provide
references (dependencies, similar problems and solutions), etc.*
## Impact
*Update this section, where applicable, on how change affects users,
build process, hardware, documentation, security, compatibility, etc.*
## Testing
*Update this section with details on how did you verify the change,
what Host was used for build (OS, CPU, compiler, ..), what Target was
used for verification (arch, board:config, ..), etc. Providing build
and runtime logs from before and after change is highly appreciated.*

14
.github/workflows/checkpatch.yml vendored Normal file
View File

@ -0,0 +1,14 @@
# This is a basic workflow to help you get started with Actions
name: checkpatch
# Controls when the workflow will run
on:
pull_request:
types: [opened, reopened, synchronize]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
checkpatch:
uses: open-vela/public-actions/.github/workflows/checkpatch.yml@trunk
secrets: inherit

14
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,14 @@
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the workflow will run
on:
pull_request_target:
types: [opened, reopened, synchronize]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
ci:
uses: open-vela/public-actions/.github/workflows/ci.yml@trunk
secrets: inherit

13
.github/workflows/clang-format.yml vendored Normal file
View File

@ -0,0 +1,13 @@
# This is a basic workflow to help you get started with Actions
name: clang-format
# Controls when the workflow will run
on:
pull_request:
types: [opened, reopened, synchronize]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
clang-format:
uses: open-vela/public-actions/.github/workflows/clang-format.yml@trunk

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*.o
*.built
*.depend
*.dep

123
Android.bp Normal file
View File

@ -0,0 +1,123 @@
bootstrap_go_package {
name: "soong-frameworkBluetooth",
pkgPath: "android/soong/frameworkBluetooth",
deps: [
"soong-android",
"soong-cc",
],
srcs: [
"frameworkBluetooth.go",
],
pluginFor: ["soong_build"],
}
frameworkBluetooth_cc_library {
name : "libbt-framework-client",
min_sdk_version: "33",
srcs : [
"framework/common/*.c",
"framework/socket/*.c",
"service/common/index_allocator.c",
"service/ipc/socket/src/bt_socket_client.c",
"service/ipc/socket/src/bt_socket_adapter.c",
"service/ipc/socket/src/bt_socket_advertiser.c",
"service/ipc/socket/src/bt_socket_scan.c",
"service/ipc/socket/src/bt_socket_gattc.c",
"service/ipc/socket/src/bt_socket_gatts.c",
"service/ipc/socket/src/bt_socket_a2dp_sink.c",
"service/ipc/socket/src/bt_socket_a2dp_source.c",
"service/ipc/socket/src/bt_socket_avrcp_target.c",
"service/ipc/socket/src/bt_socket_hfp_ag.c",
"service/ipc/socket/src/bt_socket_hfp_hf.c",
"service/ipc/socket/src/bt_socket_hid_device.c",
"service/ipc/socket/src/bt_socket_spp.c",
"service/src/manager_service.c",
],
include_dirs : [
"vendor/vela/apps/system/libuv/libuv/include",
"vendor/vela/apps/system/libuv/libuv/src",
],
local_include_dirs : [
"framework/include",
"service",
"service/common",
"service/ipc",
"service/ipc/socket/include",
"service/profiles",
"service/profiles/include",
"service/src",
],
static_libs : [
"libuv",
],
shared_libs : [
"liblog",
],
cflags : [
//"-DANDROID",
"-Werror",
"-Wno-unused-parameter",
"-Wno-unused-function",
"-Wno-unused-variable",
"-Wno-typedef-redefinition",
],
apex_available : [
"//apex_available:platform",
"com.android.btservices",
],
}
cc_binary {
name : "bttool",
srcs : [
"tools/bt_tools.c",
"tools/adv.c",
"tools/scan.c",
"tools/gatt_client.c",
"tools/gatt_server.c",
"tools/a2dp_sink.c",
"tools/a2dp_source.c",
"tools/hfp_ag.c",
"tools/hfp_hf.c",
"tools/hid_device.c",
"tools/spp.c",
"tools/log.c",
"tools/utils.c",
],
include_dirs : [
"vendor/vela/apps/system/libuv/libuv/include",
"vendor/vela/apps/system/libuv/libuv/src",
],
local_include_dirs : [
"framework/include",
"service",
"service/utils",
],
static_libs : [
"libuv",
],
shared_libs : [
"liblog",
"libbt-framework-client",
],
cflags : [
//"-DANDROID",
"-Werror",
"-Wno-unused-parameter",
"-Wno-unused-function",
"-Wno-unused-variable",
],
}

546
CMakeLists.txt Normal file
View File

@ -0,0 +1,546 @@
#
# Copyright (C) 2024 Xiaomi Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
#
if(CONFIG_BLUETOOTH)
# Source Directories
set(BLUETOOTH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
# Flags
set(CFLAGS)
set(CSRCS)
set(INCDIR)
# Sources
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/framework/common/*.c)
list(APPEND CSRCS ${APPEND_FILES})
if(CONFIG_BLUETOOTH_FRAMEWORK)
if(CONFIG_BLUETOOTH_FRAMEWORK_LOCAL)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/framework/api/*.c)
list(APPEND CSRCS ${APPEND_FILES})
if(NOT CONFIG_BLUETOOTH_BLE_AUDIO)
file(GLOB EXLUDE_FILES ${BLUETOOTH_DIR}/framework/api/bt_lea*)
list(REMOVE_ITEM CSRCS ${EXLUDE_FILES})
endif()
elseif(CONFIG_BLUETOOTH_FRAMEWORK_SOCKET_IPC)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/framework/api/*.c)
list(APPEND CSRCS ${APPEND_FILES})
if(NOT CONFIG_BLUETOOTH_BLE_AUDIO)
file(GLOB EXLUDE_FILES ${BLUETOOTH_DIR}/framework/api/bt_lea*)
list(REMOVE_ITEM EXCLUDE CSRCS ${EXLUDE_FILES})
endif()
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/ipc/*.c)
list(APPEND CSRCS ${APPEND_FILES})
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/ipc/socket/src/*.c)
list(APPEND CSRCS ${APPEND_FILES})
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/framework/socket/*.c)
list(APPEND CSRCS ${APPEND_FILES})
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/ipc/socket/include)
else()
# Other IPC source files
endif()
endif()
list(
APPEND
CSRCS
${BLUETOOTH_DIR}/service/src/manager_service.c
${BLUETOOTH_DIR}/service/src/power_manager.c
${BLUETOOTH_DIR}/service/vendor/bt_vendor.c
${BLUETOOTH_DIR}/service/common/bt_time.c
${BLUETOOTH_DIR}/service/common/index_allocator.c
${BLUETOOTH_DIR}/service/common/service_loop.c)
if(CONFIG_BLUETOOTH_STORAGE_PROPERTY_SUPPORT)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/common/storage_property.c)
else()
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/common/storage.c)
endif()
if(CONFIG_BLUETOOTH_SERVICE)
list(
APPEND
CSRCS
${BLUETOOTH_DIR}/service/src/adapter_service.c
${BLUETOOTH_DIR}/service/src/adapter_state.c
${BLUETOOTH_DIR}/service/src/btservice.c
${BLUETOOTH_DIR}/service/src/device.c
${BLUETOOTH_DIR}/service/src/hci_parser.c)
if(CONFIG_BLUETOOTH_BLE_ADV)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/src/advertising.c)
endif()
if(CONFIG_BLUETOOTH_BLE_SCAN)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/src/scan_manager.c
${BLUETOOTH_DIR}/service/src/scan_record.c
${BLUETOOTH_DIR}/service/src/scan_filter.c)
endif()
if(CONFIG_BLUETOOTH_L2CAP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/service/src/l2cap_service.c)
endif()
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/stacks/*.c)
list(APPEND CSRCS ${APPEND_FILES})
if(CONFIG_BLUETOOTH_STACK_BREDR_BLUELET
OR CONFIG_BLUETOOTH_STACK_LE_BLUELET)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/stacks/bluelet/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_STACK_BREDR_ZBLUE OR CONFIG_BLUETOOTH_STACK_LE_ZBLUE)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/stacks/zephyr/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(NOT CONFIG_BLUETOOTH_BLE_AUDIO)
file(GLOB EXLUDE_FILES ${BLUETOOTH_DIR}/service/stacks/bluelet/sal_lea_*)
list(REMOVE_ITEM CSRCS ${EXLUDE_FILES})
endif()
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/*.c)
list(APPEND CSRCS ${APPEND_FILES})
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/system/*.c)
list(APPEND CSRCS ${APPEND_FILES})
if(NOT CONFIG_BLUETOOTH_A2DP)
list(REMOVE_ITEM CSRCS
${BLUETOOTH_DIR}/service/profiles/system/bt_player.c)
endif()
if(NOT
(CONFIG_BLUETOOTH_A2DP
OR CONFIG_BLUETOOTH_HFP_AG
OR CONFIG_BLUETOOTH_HFP_HF
OR CONFIG_BLUETOOTH_BLE_AUDIO))
list(REMOVE_ITEM CSRCS
${BLUETOOTH_DIR}/service/profiles/system/media_system.c)
endif()
file(GLOB APPEND_FILES
${BLUETOOTH_DIR}/service/profiles/audio_interface/*.c)
list(APPEND CSRCS ${APPEND_FILES})
if(CONFIG_BLUETOOTH_GATT)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/gatt/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_A2DP)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/a2dp/*.c)
list(APPEND CSRCS ${APPEND_FILES})
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/a2dp/codec/*.c)
list(APPEND CSRCS ${APPEND_FILES})
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/profiles/a2dp)
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/profiles/a2dp/codec)
endif()
if(CONFIG_BLUETOOTH_A2DP_SOURCE)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/a2dp/source/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_A2DP_SINK)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/a2dp/sink/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_AVRCP_TARGET OR CONFIG_BLUETOOTH_AVRCP_CONTROL)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/avrcp/*.c)
list(APPEND CSRCS ${APPEND_FILES})
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/profiles/avrcp)
endif()
if(CONFIG_BLUETOOTH_AVRCP_TARGET)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/avrcp/target/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_AVRCP_CONTROL)
file(GLOB APPEND_FILES
${BLUETOOTH_DIR}/service/profiles/avrcp/control/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_HFP_HF)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/hfp_hf/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_HFP_AG)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/hfp_ag/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_SPP)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/spp/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_HID_DEVICE)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/hid/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_PAN)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/pan/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_LEAUDIO_CLIENT OR CONFIG_BLUETOOTH_LEAUDIO_SERVER)
file(GLOB APPEND_FILES
${BLUETOOTH_DIR}/service/profiles/leaudio/audio_ipc/*.c)
list(APPEND CSRCS ${APPEND_FILES})
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/leaudio/*.c)
list(APPEND CSRCS ${APPEND_FILES})
file(GLOB APPEND_FILES
${BLUETOOTH_DIR}/service/profiles/leaudio/codec/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_LEAUDIO_SERVER)
file(GLOB APPEND_FILES
${BLUETOOTH_DIR}/service/profiles/leaudio/server/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_LEAUDIO_CCP)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/leaudio/ccp/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_LEAUDIO_MCP)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/leaudio/mcp/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_LEAUDIO_VMICS)
file(GLOB APPEND_FILES
${BLUETOOTH_DIR}/service/profiles/leaudio/vmics/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_LEAUDIO_CLIENT)
file(GLOB APPEND_FILES
${BLUETOOTH_DIR}/service/profiles/leaudio/client/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_LEAUDIO_MCS)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/leaudio/mcs/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_LEAUDIO_TBS)
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/profiles/leaudio/tbs/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
if(CONFIG_BLUETOOTH_LEAUDIO_VMICP)
file(GLOB APPEND_FILES
${BLUETOOTH_DIR}/service/profiles/leaudio/vmicp/*.c)
list(APPEND CSRCS ${APPEND_FILES})
endif()
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/utils/*.c)
list(APPEND CSRCS ${APPEND_FILES})
file(GLOB APPEND_FILES ${BLUETOOTH_DIR}/service/vhal/*.c)
list(APPEND CSRCS ${APPEND_FILES})
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/vhal)
endif()
if(CONFIG_BLUETOOTH_TOOLS)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/utils.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/log.c)
if(CONFIG_BLUETOOTH_BLE_ADV)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/adv.c)
endif()
if(CONFIG_BLUETOOTH_BLE_SCAN)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/scan.c)
endif()
if(CONFIG_BLUETOOTH_A2DP_SINK)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/a2dp_sink.c)
endif()
if(CONFIG_BLUETOOTH_A2DP_SOURCE)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/a2dp_source.c)
endif()
if(CONFIG_BLUETOOTH_GATT)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/gatt_client.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/gatt_server.c)
endif()
if(CONFIG_BLUETOOTH_HFP_HF)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/hfp_hf.c)
endif()
if(CONFIG_BLUETOOTH_HFP_AG)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/hfp_ag.c)
endif()
if(CONFIG_BLUETOOTH_SPP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/spp.c)
endif()
if(CONFIG_BLUETOOTH_HID_DEVICE)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/hid_device.c)
endif()
if(CONFIG_BLUETOOTH_PAN)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/panu.c)
endif()
if(CONFIG_BLUETOOTH_LEAUDIO_SERVER)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/lea_server.c)
endif()
if(CONFIG_BLUETOOTH_LEAUDIO_MCP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/lea_mcp.c)
endif()
if(CONFIG_BLUETOOTH_LEAUDIO_CCP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/lea_ccp.c)
endif()
if(CONFIG_BLUETOOTH_LEAUDIO_VMICS)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/lea_vmics.c)
endif()
if(CONFIG_BLUETOOTH_LEAUDIO_CLIENT)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/lea_client.c)
endif()
if(CONFIG_BLUETOOTH_LEAUDIO_VMICP)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/lea_vmicp.c)
endif()
if(CONFIG_BLUETOOTH_LEAUDIO_MCS)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/lea_mcs.c)
endif()
if(CONFIG_BLUETOOTH_LEAUDIO_TBS)
list(APPEND CSRCS ${BLUETOOTH_DIR}/tools/lea_tbs.c)
endif()
endif()
list(APPEND INCDIR ${BLUETOOTH_DIR}/framework/include)
if(CONFIG_LIB_DBUS_RPMSG_SERVER_CPUNAME OR CONFIG_OFONO)
list(APPEND INCDIR ${NUTTX_APPS_DIR}/external/dbus/dbus)
list(APPEND INCDIR ${NUTTX_APPS_DIR}/external/glib/glib/glib)
list(APPEND INCDIR ${NUTTX_APPS_DIR}/external/glib/glib)
list(APPEND INCDIR ${NUTTX_APPS_DIR}/external/glib)
list(APPEND INCDIR ${NUTTX_APPS_DIR}/frameworks/system/utils/gdbus)
endif()
list(APPEND INCDIR ${BLUETOOTH_DIR}/service)
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/src)
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/common)
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/profiles)
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/profiles/include)
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/profiles/system)
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/stacks)
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/stacks/include)
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/vendor)
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/stacks/include)
if(CONFIG_BLUETOOTH_SERVICE)
if(CONFIG_BLUETOOTH_STACK_BREDR_BLUELET
OR CONFIG_BLUETOOTH_STACK_LE_BLUELET)
list(
APPEND INCDIR
${NUTTX_APPS_DIR}/external/bluelet/bluelet/src/samples/stack_adapter/inc
)
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/stacks/bluelet/include)
list(APPEND INCDIR ${NUTTX_APPS_DIR}/vendor/xiaomi/vela/bluelet/inc)
endif()
if(CONFIG_BLUETOOTH_STACK_BREDR_ZBLUE OR CONFIG_BLUETOOTH_STACK_LE_ZBLUE)
list(APPEND INCDIR ${NUTTX_APPS_DIR}/external/zblue/zblue/include/zephyr)
list(APPEND INCDIR ${NUTTX_APPS_DIR}/external/zblue/zblue/port/include/)
list(APPEND INCDIR
${NUTTX_APPS_DIR}/external/zblue/zblue/port/include/kernel/include)
endif()
list(APPEND INCDIR ${BLUETOOTH_DIR}/service/ipc)
endif()
if(CONFIG_BLUETOOTH_TOOLS)
list(APPEND INCDIR ${BLUETOOTH_DIR}/tools)
endif()
if(CONFIG_ARCH_SIM)
list(APPEND CFLAGS -O0)
endif()
list(APPEND CFLAGS -Wno-strict-prototypes)
if(CONFIG_BLUETOOTH_FEATURE)
set(FEATURE_TOP ${NUTTX_APPS_DIR}/frameworks/runtimes/feature)
list(APPEND INCDIR ${FEATURE_TOP}/include)
list(APPEND INCDIR
${NUTTX_APPS_DIR}/frameworks/connectivity/bluetooth/feature/include)
list(APPEND CSRCS ${BLUETOOTH_DIR}/feature/src/system_bluetooth.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/feature/src/system_bluetooth_impl.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/feature/src/feature_bluetooth_util.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/feature/src/system_bluetooth_bt.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/feature/src/system_bluetooth_bt_impl.c)
list(APPEND CSRCS ${BLUETOOTH_DIR}/feature/src/feature_bluetooth_callback.c)
if(CONFIG_BLUETOOTH_A2DP_SINK)
list(APPEND CSRCS
${BLUETOOTH_DIR}/feature/src/system_bluetooth_bt_a2dpsink.c)
list(APPEND CSRCS
${BLUETOOTH_DIR}/feature/src/system_bluetooth_bt_a2dpsink_impl.c)
endif()
endif()
nuttx_add_library(libbluetooth STATIC)
# Add Applications
if(CONFIG_BLUETOOTH_SERVER)
nuttx_add_application(
NAME
${CONFIG_BLUETOOTH_SERVER_NAME}
SRCS
${BLUETOOTH_DIR}/service/src/main.c
INCLUDE_DIRECTORIES
${INCDIR}
STACKSIZE
8192
PRIORITY
SCHED_PRIORITY_DEFAULT
COMPILE_FLAGS
${CFLAGS}
DEPENDS
libbluetooth)
endif()
if(CONFIG_BLUETOOTH_TOOLS)
nuttx_add_application(
NAME
bttool
SRCS
${BLUETOOTH_DIR}/tools/bt_tools.c
INCLUDE_DIRECTORIES
${INCDIR}
STACKSIZE
8192
PRIORITY
${SCHED_PRIORITY_DEFAULT}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
libbluetooth)
nuttx_add_application(
NAME
adapter_test
SRCS
${BLUETOOTH_DIR}/tests/adapter_test.c
INCLUDE_DIRECTORIES
${INCDIR}
STACKSIZE
8192
PRIORITY
${SCHED_PRIORITY_DEFAULT}
COMPILE_FLAGS
${CFLAGS}
DEPENDS
libbluetooth)
endif()
if(CONFIG_BLUETOOTH_FEATURE)
include(nuttx_add_jidl)
set(PY_SCRIPT ${FEATURE_TOP}/tools/jidl/jsongensource.py)
set(BINARY_EXT_MODULES_DIR ${CMAKE_BINARY_DIR}/feature/modules/)
set(JIDL_PATHS ${BLUETOOTH_DIR}/feature/jdil/bluetooth.jidl
${BLUETOOTH_DIR}/feature/jdil/bluetooth_bt.jidl)
if(CONFIG_BLUETOOTH_A2DP_SINK)
list(APPEND JIDL_PATHS
${BLUETOOTH_DIR}/feature/jdil/bluetooth_a2dpsink.jidl)
endif()
nuttx_add_jidl(
TARGET
libbluetooth
JIDL_SCRIPT
${PY_SCRIPT}
JIDL_OUT_DIR
${BINARY_EXT_MODULES_DIR}
JIDLS
${JIDL_PATHS}
OUT_SRC_EXT
c)
endif()
# Add Dependson
nuttx_add_dependencies(TARGET libbluetooth DEPENDS libuv)
# Export Headers
set_property(
TARGET nuttx
APPEND
PROPERTY NUTTX_INCLUDE_DIRECTORIES ${BLUETOOTH_DIR}/include
${BLUETOOTH_DIR}/framework/include)
# Library Configuration
target_compile_options(libbluetooth PRIVATE ${CFLAGS})
target_sources(libbluetooth PRIVATE ${CSRCS})
target_include_directories(libbluetooth PRIVATE ${INCDIR})
endif()

630
Kconfig Normal file
View File

@ -0,0 +1,630 @@
#
# Copyright (C) 2020 Xiaomi Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
config BLUETOOTH
bool "Enable Framework Bluetooth"
default n
depends on LIBUV
depends on LIBUV_EXTENSION
if BLUETOOTH
config BLUETOOTH_STORAGE_PROPERTY_SUPPORT
bool "Bluetooth Storage KVDB Property support"
default n
config BLUETOOTH_BREDR_SUPPORT
bool "BREDR support"
default y
config BLUETOOTH_BLE_SUPPORT
bool "LE support"
default n
config BLUETOOTH_BLE_ADV
bool "LE advertising support"
default n
config BLUETOOTH_BLE_SCAN
bool "LE scan support"
default n
config BLUETOOTH_BLE_AUDIO
bool "LE audio support"
default n
config BLUETOOTH_HCI_BRIDGE_MODE
bool "HCI bridge mode"
default n
config BLUETOOTH_GATT
bool "Generic ATT profile support"
default y
config BLUETOOTH_SERVICE_LOOP_THREAD_STACK_SIZE
int "bluetooth service loop thread stack size"
default 8192
config BLUETOOTH_SERVICE_LOOP_THREAD_PRIORITY
int "bluetooth service loop thread priority"
default 103
config BLUETOOTH_DUMPBUFFER
bool "Bluetooth dumpbuffer"
default n
config BLUETOOTH_AUDIO_TRANS_RPSMG_SERVER
bool "Rpmsg audio transport server"
default n
config BLUETOOTH_AUDIO_TRANS_ID_SOURCE_CTRL
int "Bluetooth Audio Transport Source Ctrl Channel ID"
default 0
config BLUETOOTH_AUDIO_TRANS_ID_SOURCE_AUDIO
int "Bluetooth Audio Transport Source Audio Channel ID"
default 1
config BLUETOOTH_AUDIO_TRANS_ID_SINK_CTRL
int "Bluetooth Audio Transport Sink Ctrl Channel ID"
default 2
config BLUETOOTH_AUDIO_TRANS_ID_SINK_AUDIO
int "Bluetooth Audio Transport Sink Audio Channel ID"
default 3
config BLUETOOTH_AUDIO_TRANS_ID_HFP_CTRL
int "Bluetooth Audio Transport SCO Ctrl Channel ID"
default 4
config BLUETOOTH_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"
config BLUETOOTH_LEA_SINK_CTRL_PATH
string "Bluetooth LE Audio Transport Sink Ctrl Path"
default "lea_sink_ctrl"
config BLUETOOTH_LEA_SINK_DATA_PATH
string "Bluetooth LE Audio Transport Sink Data Path"
default "lea_sink_data"
config BLUETOOTH_LEA_SOURCE_CTRL_PATH
string "Bluetooth LE Audio Transport Source Ctrl Path"
default "lea_source_ctrl"
config BLUETOOTH_LEA_SOURCE_DATA_PATH
string "Bluetooth LE Audio Transport Source Data Path"
default "lea_source_data"
config BLUETOOTH_SCO_CTRL_PATH
string "Bluetooth SCO Transport Ctrl Path"
default "sco_ctrl"
config BLUETOOTH_PM_MAX_TIMER_NUMBER
int "Bluetooth PM maximum number of timers"
default 16
if BLUETOOTH_GATT
config BLUETOOTH_GATTC_MAX_CONNECTIONS
int "GATT client max connections"
default 8
config BLUETOOTH_GATTS_MAX_ATTRIBUTE_NUM
int "GATT server max number of attributes contained in a table"
default 10
endif
config BLUETOOTH_AVRCP_TARGET
bool "Audio/Video Remote Control Profile (Target) support"
default n
config BLUETOOTH_AVRCP_CONTROL
bool "Audio/Video Remote Control Profile (Control) support"
default n
config BLUETOOTH_AVRCP_ABSOLUTE_VOLUME
bool "Audio/Video Remote Control Profile support absolute volume"
default n
depends on (BLUETOOTH_AVRCP_CONTROL || BLUETOOTH_AVRCP_TARGET) && BLUELET_AVRCP_TG_ABSVOL_SUPPORT
config BLUETOOTH_A2DP
bool "Advanced Audio Distribution Profile"
default n
depends on MEDIA
config BLUETOOTH_A2DP_SOURCE
bool "A2DP source profile support"
default n
select BLUETOOTH_AVRCP_TARGET
depends on BLUETOOTH_A2DP
config BLUETOOTH_A2DP_SINK
bool "A2DP sink profile support"
default n
select BLUETOOTH_AVRCP_CONTROL
depends on BLUETOOTH_A2DP
if BLUETOOTH_A2DP
config BLUETOOTH_A2DP_AAC_CODEC
bool "Bluetooth A2dp AAC codec support"
default n
select AAC_ENABLED
config BLUETOOTH_A2DP_MAX_CONNECTIONS
int "Maximum A2dp connections"
default 1
help
Maximum A2dp connections
config BLUETOOTH_A2DP_PEER_PARTIAL_RECONN
bool "Bluetooth A2dp peer partial reconnect support"
default y
help
Bluetooth A2dp peer partial reconnect support
endif #BLUETOOTH_A2DP
config BLUETOOTH_HFP_HF
bool "HFP hands-free profile support"
default n
if BLUETOOTH_HFP_HF
config HFP_HF_MAX_CONNECTIONS
int "HFP hands-free max connections"
default 1
config HFP_HF_WEBCHAT_BLOCKER
bool "Block webchat automatically"
default y
endif #BLUETOOTH_HFP_HF
config BLUETOOTH_HFP_AG
bool "HFP audio-gateway profile support"
default n
if BLUETOOTH_HFP_AG
config HFP_AG_MAX_CONNECTIONS
int "HFP audio-gateway max connections"
default 1
config BLUETOOTH_HFP_AG_PRIMARY_SLOT
int "HFP select primary modem slot"
default 0
endif # BLUETOOTH_HFP_AG
config BLUETOOTH_SPP
bool "Serial port profile support"
default n
depends on SERIAL_TERMIOS
depends on PSEUDOTERM
if BLUETOOTH_SPP
config BLUETOOTH_SPP_MAX_CONNECTIONS
int "SPP max connections"
default 1
config BLUETOOTH_SPP_SERVER_MAX_CONNECTIONS
int "SPP server max connections"
default 8
endif
config BLUETOOTH_HID_DEVICE
bool "HID device profile support"
default n
config BLUETOOTH_PAN
bool "Personal area network profile support"
default n
depends on ALLOW_BSD_COMPONENTS
help
config NET_TUN_PKTSIZE should set 1518
config BLUETOOTH_L2CAP
bool "L2CAP dynamic channel support"
default n
if BLUETOOTH_L2CAP
config BLUETOOTH_L2CAP_OUTGOING_MTU
int "Outgoing MTU"
default 2048
help
config L2CAP Outgoing MTU
endif #BLUETOOTH_L2CAP
config BLUETOOTH_MAX_REGISTER_NUM
int "Max register callback nums"
default 4
config BLUETOOTH_FRAMEWORK
bool "Enable bluetooth framework api"
default n
help
Enable bluetooth framework api
if BLUETOOTH_FRAMEWORK
choice
prompt "select bluetooth framework type"
default BLUETOOTH_FRAMEWORK_LOCAL
config BLUETOOTH_FRAMEWORK_LOCAL
bool "use local api without ipc"
config BLUETOOTH_FRAMEWORK_SOCKET_IPC
bool "use socket ipc api"
endchoice
endif #BLUETOOTH_FRAMEWORK
if BLUETOOTH_FRAMEWORK_SOCKET_IPC
config BLUETOOTH_RPMSG_CPUNAME
string "Blutooth rpmsg cpu name"
default "cp"
help
Bluetooth default server name
config BLUETOOTH_SOCKET_BUF_SIZE
int "Bluetooth socket buffer size"
default 1024
help
Bluetooth socket buffer size
config BLUETOOTH_SOCKET_PORT
int "Bluetooth socket port num"
default 140704
help
Socket port of inet
endif #BLUETOOTH_FRAMEWORK_SOCKET_IPC
config BLUETOOTH_SERVICE
bool "Enable bluetooth service"
default n
help
Enable bluetooth service
if BLUETOOTH_SERVICE
config BLUETOOTH_SERVER
bool "Bluetooth server enable"
default n
help
Enable bluetooth server
config CONFIG_BLUETOOTH_DEFAULT_COD
hex "default class of device"
default 0x00280704
help
Set default class of device
if BLUETOOTH_SERVER
config BLUETOOTH_SERVER_NAME
string "Blutooth server name"
default "bluetoothd"
help
Bluetooth default server name
config BLUETOOTH_IPC_JOIN_LOOP
bool "Let ipc join service loop"
default n
help
Bluetooth ipc join service loop
config BLUETOOTH_NET_IPv4
bool "Let Bluetooth server listen message from network"
default n
depends on NET_IPv4
help
Bluetooth server listen message
endif #BLUETOOTH_SERVER
config BLUETOOTH_SERVICE_LOG_LEVEL
int "Bluetooth service log level"
default 7
help
Set bt service log level <0~7>
config BLUETOOTH_SERVICE_HCI_UART_NAME
string "HCI uart driver name"
default "/dev/ttyBT0"
if BLUETOOTH_BREDR_SUPPORT
choice
prompt "select br stack"
default BLUETOOTH_STACK_BREDR_BLUELET
config BLUETOOTH_STACK_BREDR_BLUELET
bool "classic bt stack use bluelet"
select LIB_BLUELET
config BLUETOOTH_STACK_BREDR_ZBLUE
bool "classic bt stack use zblue"
config BLUETOOTH_STACK_NOT_SUPPORT_CLASSIC_BT
bool "not support classic bt stack"
endchoice
endif #BLUETOOTH_BREDR_SUPPORT
if BLUETOOTH_BLE_SUPPORT
choice
prompt "select le stack"
default BLUETOOTH_STACK_LE_BLUELET
config BLUETOOTH_STACK_LE_BLUELET
bool "ble stack use bluelet"
select LIB_BLUELET
config BLUETOOTH_STACK_LE_ZBLUE
bool "ble stack use zblue"
config BLUETOOTH_STACK_NOT_SUPPORT_LE
bool "not support ble stack"
endchoice
config BLUETOOTH_LE_SCANNER_MAX_NUM
int "LE scanner max register number"
default 2
help
le scanner max register number
config BLUETOOTH_LE_ADVERTISER_MAX_NUM
int "LE advertiser max register number"
default 2
help
Le scanner max register number
config BLUETOOTH_LE_AUDIO_SUPPORT
bool "LE audio support"
default n
endif #BLUETOOTH_BLE_SUPPORT
endif #BLUETOOTH_SERVICE
config BLUETOOTH_TOOLS
bool "Enable bluetooth profile test tools"
default n
select BLUETOOTH_FRAMEWORK
choice
prompt "select bt vendor"
default BLUETOOTH_VENDOR_BES
config BLUETOOTH_VENDOR_BES
bool "bluetooth vendor BES"
config BLUETOOTH_VENDOR_ACTIONS
bool "bluetooth vendor ACTIONS"
endchoice
config BLUETOOTH_FEATURE
bool "bluetooth feature api support"
default n
depends on FEATURE_FRAMEWORK
config BLUETOOTH_LEAUDIO_CLIENT
bool "enable bluetooth leaudio client feature"
default n
config BLUETOOTH_LEAUDIO_SERVER
bool "enable bluetooth leaudio server feature"
default n
config BLUETOOTH_LEAUDIO_TBS
bool "enable bluetooth leaudio tbs feature"
default n
depends on BLUETOOTH_LEAUDIO_CLIENT
config BLUETOOTH_LEAUDIO_CCP
bool "enable bluetooth leaudio ccp feature"
default n
depends on BLUETOOTH_LEAUDIO_SERVER
if BLUETOOTH_LEAUDIO_TBS
config BLUETOOTH_LEAUDIO_TBS_PRIMARY_SLOT
int "LE Audio TBS select primary modem slot"
default 0
config BLUETOOTH_LEAUDIO_TBS_CALL_NAME
string "LE Audio call name"
default "/ril_0/voicecall0"
endif # BLUETOOTH_LEAUDIO_TBS
if BLUETOOTH_LEAUDIO_CCP
config BLUETOOTH_LEAUDIO_SERVER_CALL_CONTROL_NUMBER
int "leaudio tbs server number"
default 1
help
leaudio tbs server number
endif # BLUETOOTH_LEAUDIO_CCP
config BLUETOOTH_LEAUDIO_MCS
bool "enable bluetooth leaudio mcs feature"
default n
depends on BLUETOOTH_LEAUDIO_CLIENT
config BLUETOOTH_LEAUDIO_MCP
bool "enable bluetooth leaudio mcp feature"
default n
depends on BLUETOOTH_LEAUDIO_SERVER
if BLUETOOTH_LEAUDIO_MCP
config BLUETOOTH_LEAUDIO_SERVER_MEDIA_CONTROL_NUMBER
int "leaudio mcs server number"
default 1
help
leaudio mcs server number
endif # BLUETOOTH_LEAUDIO_MCP
config BLUETOOTH_LEAUDIO_VMICP
bool "enable bluetooth leaudio vmicp feature"
default n
depends on BLUETOOTH_LEAUDIO_CLIENT
config BLUETOOTH_LEAUDIO_VMICS
bool "enable bluetooth leaudio vmics feature"
default n
depends on BLUETOOTH_LEAUDIO_SERVER
if BLUETOOTH_LEAUDIO_VMICS
config BLUETOOTH_LEAUDIO_VCS_VOLUME_STEP
int "leaudio server vcs volume step size"
default 2
help
leaudio server vcs volume step size
config BLUETOOTH_LEAUDIO_VOCS_NUMBER
int "leaudio server vocs numnber"
default 0
help
leaudio server vocs number
config BLUETOOTH_LEAUDIO_AICS_NUMBER
int "leaudio server aics numnber"
default 0
help
leaudio server aics number
config BLUETOOTH_LEAUDIO_VCS_VOLUME_INITIAL
int "leaudio server vcs initial volume value"
default 125
help
leaudio server vcs volume initial value
config BLUETOOTH_LEAUDIO_VCS_UNMUTED
int "leaudio server vcs unmute"
default 0
help
leaudio server vcs unmute
config BLUETOOTH_LEAUDIO_VCS_VOLUME_DEFAULT_SETTING
int "leaudio server vcs vol settings"
default 0
help
leaudio server vcs vol settings
config BLUETOOTH_LEAUDIO_MICS_NUMBER
int "leaudio server mics numnber"
default 0
help
leaudio server mics number
endif # BLUETOOTH_LEAUDIO_VMICS
if BLUETOOTH_LEAUDIO_SERVER
config BLUETOOTH_LEAUDIO_SERVER_SINK_ASE_NUMBER
int "leaudio server sink number"
default 1
help
leaudio server sink ase number
config BLUETOOTH_LEAUDIO_SERVER_SOURCE_ASE_NUMBER
int "leaudio server source number"
default 1
help
leaudio server source ase number
config BLUETOOTH_LEAUDIO_SERVER_BASS_STATE_NUMBER
int "leaudio server bass state number"
default 1
help
leaudio server bass state number
config BLUETOOTH_LEAUDIO_SERVER_SOURCE
bool "enable leaudio server source"
default y
config BLUETOOTH_LEAUDIO_SERVER_SOURCE_LOCATION
int "leaudio server source location"
default 1
help
leaudio server source location
config BLUETOOTH_LEAUDIO_SERVER_SINK_LOCATION
int "leaudio server sink location"
default 1
help
leaudio server sink location
config BLUETOOTH_LEAUDIO_SERVER_CSIS_SIZE
int "leaudio server csis set size"
default 1
help
leaudio server csis set size
config BLUETOOTH_LEAUDIO_SERVER_CSIS_RANK
int "leaudio server csis rank"
default 1
help
leaudio server csis rank
endif # BLUETOOTH_LEAUDIO_SERVER
if BLUETOOTH_LEAUDIO_CLIENT
config BLUETOOTH_LEAUDIO_CLIENT_MAX_CONNECTIONS
int "leaudio client max connections"
default 4
help
leaudio client max connections
config BLUETOOTH_LEAUDIO_CLIENT_MAX_GROUP
int "leaudio client max group"
default 4
help
leaudio client max connections
config BLUETOOTH_LEAUDIO_CLIENT_MAX_DEVICES
int "leaudio client max devices"
default 8
help
leaudio client max devices
config BLUETOOTH_LEAUDIO_CLIENT_MAX_ALLOC_NUMBER
int "leaudio client max alloc number"
default 64
help
leaudio client max group
config BLUETOOTH_LEAUDIO_CLIENT_ASE_MAX_NUMBER
int "leaudio client max ase number"
default 2
help
leaudio client max ase number
config BLUETOOTH_LEAUDIO_CLIENT_PAC_MAX_NUMBER
int "leaudio client max pac number"
default 3
help
leaudio client max pac number
config BLUETOOTH_LEAUDIO_CLIENT_CIS_MAX_NUMBER
int "leaudio client max cis number"
default 2
help
leaudio client max cis number
config BLUETOOTH_LEAUDIO_CLIENT_METADATA_MAX_NUMBER
int "leaudio client max metadata number"
default 4
help
leaudio client max metadata number
endif # BLUETOOTH_LEAUDIO_CLIENT
endif #BLUETOOTH

10
LICENSE Normal file
View File

@ -0,0 +1,10 @@
Copyright (C) 2024 Xiaomi Corporation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

23
Make.defs Normal file
View File

@ -0,0 +1,23 @@
#
# Copyright (C) 2020 Xiaomi Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
ifeq ($(CONFIG_BLUETOOTH), y)
CONFIGURED_APPS += $(APPDIR)/frameworks/connectivity/bluetooth
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/include
CXXFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/include
endif

363
Makefile Normal file
View File

@ -0,0 +1,363 @@
#
# Copyright (C) 2020 Xiaomi Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
include $(APPDIR)/Make.defs
ifeq ($(CONFIG_BLUETOOTH), y)
CSRCS += framework/common/*.c
ifeq ($(CONFIG_BLUETOOTH_FRAMEWORK), y)
ifeq ($(CONFIG_BLUETOOTH_FRAMEWORK_LOCAL), y)
CSRCS += framework/api/*.c
ifeq ($(CONFIG_BLUETOOTH_BLE_AUDIO),)
CSRCS := $(filter-out $(wildcard framework/api/bt_lea*),$(wildcard $(CSRCS)))
endif
else ifeq ($(CONFIG_BLUETOOTH_FRAMEWORK_SOCKET_IPC), y)
CSRCS += framework/api/*.c
ifeq ($(CONFIG_BLUETOOTH_BLE_AUDIO),)
CSRCS := $(filter-out $(wildcard framework/api/bt_lea*),$(wildcard $(CSRCS)))
endif
CSRCS += service/ipc/*.c
CSRCS += service/ipc/socket/src/*.c
CSRCS += framework/socket/*.c
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/ipc/socket/include
else
endif
endif
CSRCS += service/src/manager_service.c
CSRCS += service/common/index_allocator.c
ifeq ($(CONFIG_BLUETOOTH_STORAGE_PROPERTY_SUPPORT), y)
CSRCS += service/common/storage_property.c
else
CSRCS += service/common/storage.c
endif
ifeq ($(CONFIG_BLUETOOTH_SERVICE), y)
CSRCS += service/common/bt_time.c
CSRCS += service/common/service_loop.c
CSRCS += service/src/adapter_service.c
CSRCS += service/src/adapter_state.c
CSRCS += service/src/btservice.c
CSRCS += service/src/device.c
CSRCS += service/src/power_manager.c
CSRCS += service/vendor/bt_vendor.c
CSRCS += service/src/hci_parser.c
ifeq ($(CONFIG_BLUETOOTH_BLE_ADV), y)
CSRCS += service/src/advertising.c
endif #CONFIG_BLUETOOTH_BLE_ADV
ifeq ($(CONFIG_BLUETOOTH_BLE_SCAN), y)
CSRCS += service/src/scan_manager.c
CSRCS += service/src/scan_record.c
CSRCS += service/src/scan_filter.c
endif #CONFIG_BLUETOOTH_BLE_SCAN
ifeq ($(CONFIG_BLUETOOTH_L2CAP), y)
CSRCS += service/src/l2cap_service.c
endif #CONFIG_BLUETOOTH_L2CAP
CSRCS += service/stacks/*.c
ifneq ($(CONFIG_BLUETOOTH_STACK_BREDR_BLUELET)$(CONFIG_BLUETOOTH_STACK_LE_BLUELET),)
CSRCS += service/stacks/bluelet/*.c
endif
ifneq ($(CONFIG_BLUETOOTH_STACK_BREDR_ZBLUE)$(CONFIG_BLUETOOTH_STACK_LE_ZBLUE),)
CSRCS += service/stacks/zephyr/*.c
endif
ifeq ($(CONFIG_BLUETOOTH_BLE_AUDIO),)
CSRCS := $(filter-out $(wildcard service/stacks/bluelet/sal_lea_*),$(wildcard $(CSRCS)))
endif #CONFIG_BLUETOOTH_BLE_AUDIO
CSRCS += service/profiles/*.c
CSRCS += service/profiles/system/*.c
ifeq ($(CONFIG_BLUETOOTH_A2DP),)
CSRCS := $(filter-out $(wildcard service/profiles/system/bt_player.c),$(wildcard $(CSRCS)))
endif #CONFIG_BLUETOOTH_A2DP
ifeq ($(findstring y, $(CONFIG_BLUETOOTH_A2DP)_$(CONFIG_BLUETOOTH_HFP_AG)_$(CONFIG_BLUETOOTH_HFP_HF)_$(CONFIG_BLUETOOTH_BLE_AUDIO)), )
CSRCS := $(filter-out $(wildcard service/profiles/system/media_system.c),$(wildcard $(CSRCS)))
endif #CONFIG_BLUETOOTH_A2DP/CONFIG_BLUETOOTH_HFP_AG/CONFIG_BLUETOOTH_HFP_HF
ifeq ($(CONFIG_MICO_MEDIA_MAIN_PLAYER),y)
CFLAGS += ${INCDIR_PREFIX}${TOPDIR}/../vendor/xiaomi/miai/mediaplayer/include
endif #CONFIG_MICO_MEDIA_MAIN_PLAYER
CSRCS += service/profiles/audio_interface/*.c
ifeq ($(CONFIG_BLUETOOTH_GATT), y)
CSRCS += service/profiles/gatt/*.c
endif #CONFIG_BLUETOOTH_GATT
ifeq ($(CONFIG_BLUETOOTH_A2DP), y)
CSRCS += service/profiles/a2dp/*.c
CSRCS += service/profiles/a2dp/codec/*.c
CSRCS += service/profiles/avrcp/*.c
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/profiles/a2dp
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/profiles/a2dp/codec
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/profiles/avrcp
endif #CONFIG_BLUETOOTH_A2DP
ifeq ($(CONFIG_BLUETOOTH_A2DP_SOURCE), y)
CSRCS += service/profiles/a2dp/source/*.c
endif #CONFIG_BLUETOOTH_A2DP_SOURCE
ifeq ($(CONFIG_BLUETOOTH_A2DP_SINK), y)
CSRCS += service/profiles/a2dp/sink/*.c
endif #CONFIG_BLUETOOTH_A2DP_SINK
ifeq ($(CONFIG_BLUETOOTH_AVRCP_TARGET), y)
CSRCS += service/profiles/avrcp/target/*.c
endif #CONFIG_BLUETOOTH_A2DP_SOURCE
ifeq ($(CONFIG_BLUETOOTH_AVRCP_CONTROL), y)
CSRCS += service/profiles/avrcp/control/*.c
endif #CONFIG_BLUETOOTH_A2DP_SINK
ifeq ($(CONFIG_BLUETOOTH_HFP_HF), y)
CSRCS += service/profiles/hfp_hf/*.c
endif #CONFIG_BLUETOOTH_HFP_HF
ifeq ($(CONFIG_BLUETOOTH_HFP_AG), y)
CSRCS += service/profiles/hfp_ag/*.c
endif #CONFIG_BLUETOOTH_HFP_AG
ifeq ($(CONFIG_BLUETOOTH_SPP), y)
CSRCS += service/profiles/spp/*.c
endif #CONFIG_BLUETOOTH_SPP
ifeq ($(CONFIG_BLUETOOTH_HID_DEVICE), y)
CSRCS += service/profiles/hid/*.c
endif #CONFIG_BLUETOOTH_HID_DEVICE
ifeq ($(CONFIG_BLUETOOTH_PAN), y)
CSRCS += service/profiles/pan/*.c
endif #CONFIG_BLUETOOTH_PAN
ifneq ($(findstring y, $(CONFIG_BLUETOOTH_LEAUDIO_CLIENT)_$(CONFIG_BLUETOOTH_LEAUDIO_SERVER)), )
CSRCS += service/profiles/leaudio/audio_ipc/*.c
CSRCS += service/profiles/leaudio/*.c
CSRCS += service/profiles/leaudio/codec/*.c
endif #CONFIG_BLUETOOTH_LEAUDIO_CLIENT/CONFIG_BLUETOOTH_LEAUDIO_SERVER
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_SERVER), y)
CSRCS += service/profiles/leaudio/server/*.c
endif #CONFIG_BLUETOOTH_LEAUDIO_SERVER
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_CCP), y)
CSRCS += service/profiles/leaudio/ccp/*.c
endif #CONFIG_BLUETOOTH_LEAUDIO_CCP
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_MCP), y)
CSRCS += service/profiles/leaudio/mcp/*.c
endif #CONFIG_BLUETOOTH_LEAUDIO_MCP
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_VMICS), y)
CSRCS += service/profiles/leaudio/vmics/*.c
endif #CONFIG_BLUETOOTH_LEAUDIO_VMICS
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_CLIENT), y)
CSRCS += service/profiles/leaudio/client/*.c
endif #CONFIG_BLUETOOTH_LEAUDIO_CLIENT
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_MCS), y)
CSRCS += service/profiles/leaudio/mcs/*.c
endif #CONFIG_BLUETOOTH_LEAUDIO_MCS
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_TBS), y)
CSRCS += service/profiles/leaudio/tbs/*.c
endif #CONFIG_BLUETOOTH_LEAUDIO_TBS
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_VMICP), y)
CSRCS += service/profiles/leaudio/vmicp/*.c
endif #CONFIG_BLUETOOTH_LEAUDIO_VMICP
CSRCS += service/utils/*.c
CSRCS += service/vhal/*.c
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/vhal
endif #CONFIG_BLUETOOTH_SERVICE
ifeq ($(CONFIG_BLUETOOTH_TOOLS), y)
CSRCS += tools/utils.c
CSRCS += tools/log.c
CSRCS += tools/uv_thread_loop.c
ifeq ($(CONFIG_BLUETOOTH_BLE_ADV), y)
CSRCS += tools/adv.c
endif
ifeq ($(CONFIG_BLUETOOTH_BLE_SCAN), y)
CSRCS += tools/scan.c
endif
ifeq ($(CONFIG_BLUETOOTH_A2DP_SINK), y)
CSRCS += tools/a2dp_sink.c
endif #CONFIG_BLUETOOTH_A2DP_SINK
ifeq ($(CONFIG_BLUETOOTH_A2DP_SOURCE), y)
CSRCS += tools/a2dp_source.c
endif #CONFIG_BLUETOOTH_A2DP_SOURCE
ifeq ($(CONFIG_BLUETOOTH_GATT), y)
CSRCS += tools/gatt_client.c
CSRCS += tools/gatt_server.c
endif #CONFIG_BLUETOOTH_GATT
ifeq ($(CONFIG_BLUETOOTH_HFP_HF), y)
CSRCS += tools/hfp_hf.c
endif #CONFIG_BLUETOOTH_HFP_HF
ifeq ($(CONFIG_BLUETOOTH_HFP_AG), y)
CSRCS += tools/hfp_ag.c
endif #CONFIG_BLUETOOTH_HFP_AG
ifeq ($(CONFIG_BLUETOOTH_SPP), y)
CSRCS += tools/spp.c
endif
ifeq ($(CONFIG_BLUETOOTH_HID_DEVICE), y)
CSRCS += tools/hid_device.c
endif
ifeq ($(CONFIG_BLUETOOTH_PAN), y)
CSRCS += tools/panu.c
endif
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_SERVER), y)
CSRCS += tools/lea_server.c
endif
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_MCP), y)
CSRCS += tools/lea_mcp.c
endif
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_CCP), y)
CSRCS += tools/lea_ccp.c
endif
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_VMICS), y)
CSRCS += tools/lea_vmics.c
endif
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_CLIENT), y)
CSRCS += tools/lea_client.c
endif
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_VMICP), y)
CSRCS += tools/lea_vmicp.c
endif
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_MCS), y)
CSRCS += tools/lea_mcs.c
endif
ifeq ($(CONFIG_BLUETOOTH_LEAUDIO_TBS), y)
CSRCS += tools/lea_tbs.c
endif
endif
# framework/service/stack/tools dependence
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/framework/include
ifneq ($(CONFIG_LIB_DBUS_RPMSG_SERVER_CPUNAME)$(CONFIG_OFONO),)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/dbus/dbus
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/glib/glib/glib
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/glib/glib
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/glib
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/system/utils/gdbus
endif
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/src
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/common
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/profiles
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/profiles/include
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/profiles/system
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/stacks
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/stacks/include
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/vendor
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/stacks/include
ifeq ($(CONFIG_BLUETOOTH_SERVICE), y)
ifneq ($(CONFIG_BLUETOOTH_STACK_BREDR_BLUELET)$(CONFIG_BLUETOOTH_STACK_LE_BLUELET),)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/stacks/bluelet/include
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/bluelet/bluelet/src/samples/stack_adapter/inc
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/vendor/xiaomi/vela/bluelet/inc
endif
ifneq ($(CONFIG_BLUETOOTH_STACK_BREDR_ZBLUE)$(CONFIG_BLUETOOTH_STACK_LE_ZBLUE),)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/zblue/zblue/include/zephyr
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/zblue/zblue/port/include/
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/external/zblue/zblue/port/include/kernel/include
endif
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/service/ipc
endif
ifeq ($(CONFIG_BLUETOOTH_TOOLS), y)
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/tools
endif
ifeq ($(CONFIG_ARCH_SIM),y)
CFLAGS += -O0
endif
CFLAGS += -Wno-strict-prototypes #-fno-short-enums -Wl,-no-enum-size-warning #-Werror
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 8192
MODULE = $(CONFIG_BLUETOOTH)
# if enabled bluetoothd
ifeq ($(CONFIG_BLUETOOTH_SERVER), y)
PROGNAME += $(CONFIG_BLUETOOTH_SERVER_NAME)
MAINSRC += service/src/main.c
endif
# if enabled bttool
ifeq ($(CONFIG_BLUETOOTH_TOOLS), y)
PROGNAME += bttool
MAINSRC += tools/bt_tools.c
PROGNAME += adapter_test
MAINSRC += tests/adapter_test.c
endif
endif
ASRCS := $(wildcard $(ASRCS))
CSRCS := $(wildcard $(CSRCS))
CXXSRCS := $(wildcard $(CXXSRCS))
MAINSRC := $(wildcard $(MAINSRC))
NOEXPORTSRCS = $(ASRCS)$(CSRCS)$(CXXSRCS)$(MAINSRC)
ifeq ($(CONFIG_BLUETOOTH_FEATURE),y)
include $(APPDIR)/frameworks/runtimes/feature/Make.defs
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/frameworks/connectivity/bluetooth/feature/include
CSRCS += feature/src/system_bluetooth.c
CSRCS += feature/src/system_bluetooth_impl.c
CSRCS += feature/src/feature_bluetooth_util.c
CSRCS += feature/src/system_bluetooth_bt.c
CSRCS += feature/src/system_bluetooth_bt_impl.c
CSRCS += feature/src/feature_bluetooth_callback.c
ifeq ($(CONFIG_BLUETOOTH_A2DP_SINK), y)
CSRCS += feature/src/system_bluetooth_bt_a2dpsink.c
CSRCS += feature/src/system_bluetooth_bt_a2dpsink_impl.c
endif
depend::
@python3 $(APPDIR)/frameworks/runtimes/feature/tools/jidl/jsongensource.py \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/jidl/bluetooth.jidl -out-dir \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/src -header system_bluetooth.h -source system_bluetooth.c
@python3 $(APPDIR)/frameworks/runtimes/feature/tools/jidl/jsongensource.py \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/jidl/bluetooth_bt.jidl -out-dir \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/src -header system_bluetooth_bt.h -source system_bluetooth_bt.c
ifeq ($(CONFIG_BLUETOOTH_A2DP_SINK), y)
@python3 $(APPDIR)/frameworks/runtimes/feature/tools/jidl/jsongensource.py \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/jidl/bluetooth_bt_a2dpsink.jidl -out-dir \
$(APPDIR)/frameworks/connectivity/bluetooth/feature/src -header system_bluetooth_bt_a2dpsink.h -source system_bluetooth_bt_a2dpsink.c
endif
endif
ifneq ($(NOEXPORTSRCS),)
BIN := $(APPDIR)/staging/libbluetooth.a
endif
include $(APPDIR)/Application.mk

92
Makefile.host Normal file
View File

@ -0,0 +1,92 @@
############################################################################
# apps/system/lzf/Makefile.host
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
############################################################################
# USAGE:
#
# 1. TOPDIR and APPDIR must be defined on the make command line: TOPDIR
# is the full path to the nuttx/ directory; APPDIR is the full path to
# the apps/ directory. For example:
#
# make -f Makefile.host TOPDIR=/home/me/projects/nuttx
# APPDIR=/home/me/projects/apps
#
# 2. Add CONFIG_DEBUG_FEATURES=y to the make command line to enable debug output
# 3. Make sure to clean old target .o files before making new host .o
# files.
#
############################################################################
include $(APPDIR)/Make.defs
BIN = bttool$(HOSTEXEEXT)
CFLAGS := -I.
CFLAGS += -I service/src
CFLAGS += -I framework/include
CFLAGS += -I tools
CFLAGS += -I service
CFLAGS += -I service/common
CFLAGS += -I service/ipc/socket/include
CFLAGS += -I service/stacks
CFLAGS += -I service/stacks/include
CFLAGS += -I service/profiles
CFLAGS += -I service/profiles/include
CFLAGS += -DFAR= -DOK=0 -m32
LDLIBS += -lpthread -lreadline -luv
BTDIR = $(APPDIR)/frameworks/bluetooth
CSRCS := $(wildcard framework/common/*.c)
CSRCS += $(wildcard framework/socket/*.c)
CSRCS += $(wildcard tools/*.c)
CSRCS := $(filter-out $(wildcard tools/lea*) tools/log.c,$(wildcard $(CSRCS)))
CSRCS += service/ipc/socket/src/bt_socket_client.c
CSRCS += service/ipc/socket/src/bt_socket_adapter.c
CSRCS += service/common/service_loop.c
CSRCS += service/src/manager_service.c
CSRCS += service/common/callbacks_list.c
CSRCS += service/common/index_allocator.c
CSRCS += service/utils/log.c
CINC := nuttx/config.h
CINC += nuttx/list.h
CINC += nuttx/nuttx.h
all: $(BIN)
.PHONY: clean
nuttx/config.h:
$(Q) mkdir -p nuttx
$(Q) ln -sf $(TOPDIR)/include/nuttx/config.h nuttx/
nuttx/list.h:
$(Q) mkdir -p nuttx
$(Q) ln -sf $(TOPDIR)/include/nuttx/list.h nuttx/
nuttx/nuttx.h:
$(Q) mkdir -p nuttx
$(Q) ln -sf $(TOPDIR)/include/nuttx/nuttx.h nuttx/
$(BIN): $(CINC) $(CSRCS)
$(Q) $(HOSTCC) $(CFLAGS) -o $@ $(filter-out $(CINC), $^) $(LDLIBS)
clean:
rm -rf $(BIN) nuttx

65
README.md Normal file
View File

@ -0,0 +1,65 @@
# Overview of openvela Bluetooth
\[ English | [简体中文](README_zh-cn.md) \]
## 1. Introduction to openvela Bluetooth
openvela Bluetooth has been certified for Bluetooth 5.4. It currently supports Bluetooth profiles listed as below:
- Core
- BR/EDR/BLE
- GAP
- L2CAP
- GATT Client/Server
- A2DP SRC/SNK
- AVRCP CT/TG
- HFP AG/HF
- PAN
- SPP
- HID
- HOGP
- LEA
- TMAP
- CAP
- BAP/ASCS/PACS/BASS
- CSIP/CSIS
- MCP/MCS
- CCP/TBS
- VCP/VCS
- Mesh
openvela Bluetooth currently also supports a variety of open source and proprietary stacks such as Zephyr, Bluez, Bluedroid, Barrot, etc.
## 2. openvela Bluetooth Application Development
Third-party application developers may utilize the openvela QuickApp Feature to acquire system access capabilities.
Additionally, NDK interfaces are also provided to utilize all Bluetooth system-level capabilities. Please refer to header files in folder framework/include for more details.
## 3. openvela Bluetooth Driver Development
openvela Bluetooth supports multiple driver architectures. Taking the widely used BTH4 driver architecture as an example, chip manufacturers can implement a variable of the **struct bt_driver_s** structure type, and initialize the following member functions for it.
- CODE int (*open)(FAR struct bt_driver_s *btdev);
- CODE int (*send)(FAR struct bt_driver_s *btdev, enum bt_buf_type_e type, FAR void *data, size_t len);
- CODE int (*ioctl)(FAR struct bt_driver_s *btdev, int cmd, unsigned long arg);
- CODE void (*close)(FAR struct bt_driver_s *btdev);
The implementation of the above member functions depends on the specific type of HCI utilized, which refers to the physical bus linking the Host and the Controller.
Then, register the driver instance by passing the variable of the above structure type via the API bt_driver_register().
- int **bt_driver_register**(FAR struct bt_driver_s *drv);
Please refer to the type definition in header file nuttx/include/nuttx/wireless/bluetooth/bt_driver.h. The figure below helps to provide a comprehensive understanding of its functioning within the openvela OS.
![](img/bt_driver.png)
Note: chip manufacturers are not required to implement the receive() member function, for it will be initialized by the BTH4 driver.
- CODE int (*receive)(FAR struct bt_driver_s *btdev, enum bt_buf_type_e type, FAR void *data, size_t len);
Upon receipt of HCI data from the chip, the vendor drivers should invoke the **bt_netdev_receive**() function, which in turn will trigger the receive() function to store the received HCI data.

65
README_zh-cn.md Normal file
View File

@ -0,0 +1,65 @@
# 蓝牙概述
\[ [English](README.md) | 简体中文 \]
## 一、 openvela 蓝牙能力介绍
openvela 蓝牙已经通过 Bluetooth 5.4 认证。目前支持的蓝牙能力包括:
- Core
- BR/EDR/BLE
- GAP
- L2CAP
- GATT Client/Server
- A2DP SRC/SNK
- AVRCP CT/TG
- HFP AG/HF
- PAN
- SPP
- HID
- HOGP
- LEA
- TMAP
- CAP
- BAP/ASCS/PACS/BASS
- CSIP/CSIS
- MCP/MCS
- CCP/TBS
- VCP/VCS
- Mesh
openvela 蓝牙目前还能够支持多种开源、闭源协议栈如Zephyr、Bluez、Bluedroid、Barrot等。
## 二、 openvela 蓝牙应用开发
对于第三方应用开发者,可以使用 openvela 快应用 QuickApp Feature ,它是基于 QuickJS 引擎使用 C++ 实现的一系列 API 接口,为三方应用提供系统访问能力。
另外,还提供了 NDK 接口来使用蓝牙系统的所有能力。可以参阅目录 framework/include 中的头文件获取更多信息。
## 三、 openvela 蓝牙驱动开发
openvela 蓝牙支持多种驱动架构。以目前常用的 BTH4 驱动架构为例,芯片厂商可以实现一个 **struct bt_driver_s** 结构体类型的变量,并为其初始化以下成员函数:
- CODE int (*open)(FAR struct bt_driver_s *btdev);
- CODE int (*send)(FAR struct bt_driver_s *btdev, enum bt_buf_type_e type, FAR void *data, size_t len);
- CODE int (*ioctl)(FAR struct bt_driver_s *btdev, int cmd, unsigned long arg);
- CODE void (*close)(FAR struct bt_driver_s *btdev);
上面成员函数的实现依赖于 HCI 的实际工作方式,也就是 Host 和 Controller 之间的物理总线。
然后,将上述结构体类型的变量通过 API **bt_driver_register**()注册该驱动实例。
- int **bt_driver_register**(FAR struct bt_driver_s *drv);
类型定义可参考头文件 nuttx/include/nuttx/wireless/bluetooth/bt_driver.h。调用关系如下图所示
![](img/bt_driver.png)
备注:对于 receive() 成员函数芯片厂商无需定义BTH4 驱动会为其初始化。
- CODE int (*receive)(FAR struct bt_driver_s *btdev, enum bt_buf_type_e type, FAR void *data, size_t len);
当收到来自芯片的 HCI 数据时,只要调用 **bt_netdev_receive**()即可,它会调用这个 receive()函数来保存收到 HCI 数据。

View File

@ -0,0 +1,95 @@
/*
* This file is auto-generated by jsongensource.py, Do not modify it directly!
*/
/*
* Copyright (C) 2023 Xiaomi Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef FEATURE_BLUETOOTH_CONSTANT_H_
#define FEATURE_BLUETOOTH_CONSTANT_H_
#include "bluetooth.h"
#include "bt_list.h"
#include "feature_exports.h"
typedef enum {
A2DP_SINK,
A2DP_SOURCE,
HFP_AG,
HFP_HF,
HID_DEVICE,
PAN_USE,
MAX_FEATURE_ID,
} feature_bluetooth_profile_t;
typedef enum {
ON_ADAPTER_STATE_CHANGE,
ON_DISCOVERY_RESULT,
ON_BOND_STATE_CHANGE,
A2DPSINK_ON_CONNECT_STATE_CHANGE,
} feature_bluetooth_callback_t;
typedef enum {
FEATURE_BLUETOOTH,
FEATURE_BLUETOOTH_BT,
FEATURE_BLUETOOTH_A2DPSINK,
} feature_bluetooth_feature_type_t;
typedef struct {
FeatureInstanceHandle* feature_ins;
FtCallbackId on_adapter_state_changed_cb_id;
} feature_bluetooth_bluetooth_callbacks_t;
typedef struct {
FeatureInstanceHandle* feature_ins;
FtCallbackId on_discovery_result_cb_id;
FtCallbackId on_bond_state_changed_cb_id;
} feature_bluetooth_bluetooth_bt_callbacks_t;
typedef struct {
FeatureInstanceHandle* feature_ins;
FtCallbackId a2dp_sink_connection_state_cb_id;
} feature_bluetooth_a2dp_sink_callbacks_t;
typedef struct {
FtCallbackId feature_callback_id;
void* feature;
void* data;
} callback_info_t;
typedef struct {
uv_mutex_t mutex;
bt_list_t* feature_bluetooth_callbacks;
bt_list_t* feature_bluetooth_bt_callbacks;
bt_list_t* feature_a2dp_sink_callbacks;
uint32_t created_features;
} feature_bluetooth_features_info_t;
void feature_bluetooth_deal_callback(int status, void* data);
void feature_bluetooth_remove_callback(int status, void* data);
void feature_bluetooth_post_task(FeatureInstanceHandle handle, FtCallbackId callback_id, void* data);
char* StringToFtString(const char* str);
void feature_bluetooth_init_bt_ins(feature_bluetooth_feature_type_t feature, FeatureProtoHandle handle);
void feature_bluetooth_uninit_bt_ins(feature_bluetooth_feature_type_t feature, FeatureProtoHandle handle);
bt_instance_t* feature_bluetooth_get_bt_ins(FeatureInstanceHandle feature);
void feature_bluetooth_add_feature_callback(FeatureInstanceHandle handle, feature_bluetooth_feature_type_t feature_type);
void feature_bluetooth_free_feature_callback(FeatureInstanceHandle handle, feature_bluetooth_feature_type_t feature_type);
void feature_bluetooth_set_feature_callback(FeatureInstanceHandle handle, FtCallbackId callback_id, feature_bluetooth_callback_t callback_type);
FtCallbackId feature_bluetooth_get_feature_callback(FeatureInstanceHandle handle, feature_bluetooth_callback_t callback_type);
void feature_bluetooth_callback_init(bt_instance_t* bt_ins);
void feature_bluetooth_callback_uninit(bt_instance_t* bt_ins);
#endif // FEATURE_BLUETOOTH_CONSTANT_H_

View File

@ -0,0 +1,45 @@
module system.bluetooth@1.0
callback openAdapterSuccess()
callback openAdapterFail(string data, int code)
callback openAdapterComplete()
struct OpenAdapterParams {
boolean operateAdapter = false
callback openAdapterSuccess success
callback openAdapterFail fail
callback openAdapterComplete complete
}
void openAdapter(OpenAdapterParams params)
callback closeAdapterSuccess()
callback closeAdapterFail(string data, int code)
callback closeAdapterComplete()
struct CloseAdapterParams {
boolean operateAdapter = false
callback closeAdapterSuccess success
callback closeAdapterFail fail
callback closeAdapterComplete complete
}
void closeAdapter(CloseAdapterParams params)
struct GetAdapterSuccessResult {
boolean available
boolean discovering
}
callback getAdapterStateSuccess(GetAdapterSuccessResult data)
callback getAdapterStateFail(string data, int code)
callback getAdapterStateComplete()
struct GetAdapterStateParams {
callback getAdapterStateSuccess success
callback getAdapterStateFail fail
callback getAdapterStateComplete complete
}
void getAdapterState(GetAdapterStateParams params)
struct adapterStateCallbackData {
boolean available
boolean discovering
}
callback adapterStateChange(adapterStateCallbackData data)
property adapterStateChange onadapterstatechange

View File

@ -0,0 +1,105 @@
module system.bluetooth.bt@1.0
callback startDiscoverySuccess()
callback startDiscoveryFail(string data, int code)
callback startDiscoveryComplete()
struct StartDiscoveryParams {
callback startDiscoverySuccess success
callback startDiscoveryFail fail
callback startDiscoveryComplete complete
}
void startDiscovery(StartDiscoveryParams params)
callback stopDiscoverySuccess()
callback stopDiscoveryFail(string data, int code)
callback stopDiscoveryComplete()
struct StopDiscoveryParams {
callback stopDiscoverySuccess success
callback stopDiscoveryFail fail
callback stopDiscoveryComplete complete
}
void stopDiscovery(StopDiscoveryParams params)
struct DiscoveryResultCallbackData {
string deviceId
string name
uint cod
uint rssi
}
callback discoveryResultChange(DiscoveryResultCallbackData data)
property discoveryResultChange ondiscoveryresult
callback connectProfilesSuccess()
callback connectProfilesFail(string data, int code)
callback connectProfilesComplete()
struct ConnectProfilesParams {
string deviceId
int[] profiles
callback connectProfilesSuccess success
callback connectProfilesFail fail
callback connectProfilesComplete complete
}
void connectProfiles(ConnectProfilesParams params)
callback disconnectProfilesSuccess()
callback disconnectProfilesFail(string data, int code)
callback disconnectProfilesComplete()
struct DisconnectProfilesParams{
string deviceId
int[] profiles
callback disconnectProfilesSuccess success
callback disconnectProfilesFail fail
callback disconnectProfilesComplete complete
}
void disconnectProfiles(DisconnectProfilesParams params)
callback disconnectSuccess()
callback disconnectFail(string data, int code)
callback disconnectComplete()
struct DisconnectParams{
string deviceId
callback disconnectSuccess success
callback disconnectFail fail
callback disconnectComplete complete
}
void disconnect(DisconnectParams params)
boolean getConnectState(string deviceId)
struct connectedDevice {
string deviceId
string name
int cod
}
string[] getConnectedDevices()
string[] getBondedDevices()
struct onBondStateChangeData {
string deviceId
int bondState
}
callback onBondStateChangeCallback(onBondStateChangeData data)
property onBondStateChangeCallback onbondstatechange
callback removeBondedSuccess()
callback removeBondedFail(string data, int code)
callback removeBondedComplete()
struct RemoveBondedParams{
string deviceId
callback removeBondedSuccess success
callback removeBondedFail fail
callback removeBondedComplete complete
}
void removeBondedDevice(RemoveBondedParams params)
boolean setScanMode(int scanMode)
int getScanMode()
string getDeviceName(string deviceId)
uint getDeviceClass(string deviceId)

View File

@ -0,0 +1,9 @@
module system.bluetooth.bt.a2dpsink@1.0
struct OnConnectStateChangeData {
string deviceId
int connectState
}
callback onConnectStateChangeCallback(OnConnectStateChangeData data)
property onConnectStateChangeCallback onconnectstatechange

View File

@ -0,0 +1,642 @@
/*
* Copyright (C) 2024 Xiaomi Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "bt_a2dp_sink.h"
#include "bt_adapter.h"
#include "bt_list.h"
#include "feature_bluetooth.h"
#include "feature_exports.h"
#include "feature_log.h"
#include "system_bluetooth.h"
#include "system_bluetooth_bt.h"
#include "system_bluetooth_bt_a2dpsink.h"
#include "uv.h"
#define REMOVE_CALLBACK(feature_callback, callback_type) \
do { \
if (feature_callback->callback_type != -1) { \
feature_bluetooth_post_task(feature_callback->feature_ins, feature_callback->callback_type, NULL); \
} \
feature_callback->callback_type = -1; \
} while (0);
#define add_feature_callback(feature_callbacks, new_callbacks_type, handle) \
{ \
new_callbacks_type* new_callback = (new_callbacks_type*)malloc(sizeof(new_callbacks_type)); \
/* The hexadecimal representation of -1 is 0xFF */ \
memset(new_callback, -1, sizeof(new_callbacks_type)); \
new_callback->feature_ins = handle; \
bt_list_add_tail(feature_callbacks, new_callback); \
}
#define set_feature_callback(feature_callbacks, callbacks_type, find_func, handle, callback_id, callback_type) \
{ \
callbacks_type* callbacks = (callbacks_type*)bt_list_find(feature_callbacks, find_func, handle); \
REMOVE_CALLBACK(callbacks, callback_type) \
callbacks->callback_type = callback_id; \
};
#define get_feature_callback(feature_callbacks, callbacks_type, find_func, handle, callback_id, callback_type) \
{ \
callbacks_type* callbacks = (callbacks_type*)bt_list_find(feature_callbacks, find_func, handle); \
callback_id = callbacks->callback_type; \
};
static bool get_callback_bluetooth(void* data, void* feature_ins)
{
feature_bluetooth_bluetooth_callbacks_t* callbacks = (feature_bluetooth_bluetooth_callbacks_t*)data;
if (!callbacks) {
return false;
}
return callbacks->feature_ins == feature_ins;
}
static bool get_callback_bluetooth_bt(void* data, void* feature_ins)
{
feature_bluetooth_bluetooth_bt_callbacks_t* callbacks = (feature_bluetooth_bluetooth_bt_callbacks_t*)data;
if (!callbacks) {
return false;
}
return callbacks->feature_ins == feature_ins;
}
static bool get_callback_a2dp_sink(void* data, void* feature_ins)
{
feature_bluetooth_a2dp_sink_callbacks_t* callbacks = (feature_bluetooth_a2dp_sink_callbacks_t*)data;
if (!callbacks) {
return false;
}
return callbacks->feature_ins == feature_ins;
}
static void free_feature_callback(bt_list_t* callbacks, FeatureInstanceHandle handle, bt_list_find_cb find_func)
{
void* data;
if (!callbacks) {
return;
}
data = bt_list_find(callbacks, find_func, handle);
if (data) {
bt_list_remove(callbacks, data);
}
}
static void free_feature_bluetooth_node(void* node)
{
feature_bluetooth_bluetooth_callbacks_t* feature_callback = (feature_bluetooth_bluetooth_callbacks_t*)node;
if (!feature_callback) {
return;
}
REMOVE_CALLBACK(feature_callback, on_adapter_state_changed_cb_id);
free(feature_callback);
}
static void free_feature_bluetooth_bt_node(void* node)
{
feature_bluetooth_bluetooth_bt_callbacks_t* feature_callback = (feature_bluetooth_bluetooth_bt_callbacks_t*)node;
if (!feature_callback) {
return;
}
REMOVE_CALLBACK(feature_callback, on_bond_state_changed_cb_id);
REMOVE_CALLBACK(feature_callback, on_discovery_result_cb_id);
free(feature_callback);
}
static void free_feature_bluetooth_a2dp_sink_node(void* node)
{
feature_bluetooth_a2dp_sink_callbacks_t* feature_callback = (feature_bluetooth_a2dp_sink_callbacks_t*)node;
if (!feature_callback) {
return;
}
REMOVE_CALLBACK(feature_callback, a2dp_sink_connection_state_cb_id);
free(feature_callback);
}
static void on_adapter_state_changed_cb(void* cookie, bt_adapter_state_t state)
{
bt_instance_t* bt_ins = (bt_instance_t*)cookie;
feature_bluetooth_features_info_t* features_callbacks;
bt_list_t* callbacks;
bt_list_node_t* node;
FEATURE_LOG_DEBUG("adapter state change callback, state: %d", state);
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return;
}
uv_mutex_lock(&features_callbacks->mutex);
callbacks = features_callbacks->feature_bluetooth_callbacks;
if (!callbacks) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
node = bt_list_head(callbacks);
if (!node) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
while (node) {
feature_bluetooth_bluetooth_callbacks_t* feature_callback;
system_bluetooth_adapterStateCallbackData* data;
feature_callback = (feature_bluetooth_bluetooth_callbacks_t*)bt_list_node(node);
if (!feature_callback) {
break;
}
FEATURE_LOG_DEBUG("feature:%p, callbackId:%d", feature_callback->feature_ins, feature_callback->on_adapter_state_changed_cb_id);
if (state != BT_ADAPTER_STATE_ON && state != BT_ADAPTER_STATE_OFF) {
break;
}
data = system_bluetoothMallocadapterStateCallbackData();
if (!data) {
continue;
}
data->available = state == BT_ADAPTER_STATE_ON;
data->discovering = bt_adapter_is_discovering(bt_ins);
feature_bluetooth_post_task(feature_callback->feature_ins, feature_callback->on_adapter_state_changed_cb_id, data);
node = bt_list_next(callbacks, node);
}
uv_mutex_unlock(&features_callbacks->mutex);
}
static void on_discovery_state_changed_cb(void* cookie, bt_discovery_state_t state)
{
bt_instance_t* bt_ins = (bt_instance_t*)cookie;
feature_bluetooth_features_info_t* features_callbacks;
bt_list_t* callbacks;
bt_list_node_t* node;
FEATURE_LOG_DEBUG("discovery state change callback, state: %d", state);
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return;
}
uv_mutex_lock(&features_callbacks->mutex);
callbacks = features_callbacks->feature_bluetooth_callbacks;
if (!callbacks) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
node = bt_list_head(callbacks);
if (!node) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
while (node) {
feature_bluetooth_bluetooth_callbacks_t* feature_callback;
system_bluetooth_adapterStateCallbackData* data;
feature_callback = (feature_bluetooth_bluetooth_callbacks_t*)bt_list_node(node);
if (!feature_callback) {
break;
}
FEATURE_LOG_DEBUG("feature:%p, callbackId:%d", feature_callback->feature_ins, feature_callback->on_adapter_state_changed_cb_id);
data = system_bluetoothMallocadapterStateCallbackData();
if (!data) {
continue;
}
data->available = bt_adapter_get_state(bt_ins) == BT_ADAPTER_STATE_ON;
data->discovering = state == BT_DISCOVERY_STATE_STARTED;
feature_bluetooth_post_task(feature_callback->feature_ins, feature_callback->on_adapter_state_changed_cb_id, data);
node = bt_list_next(callbacks, node);
}
uv_mutex_unlock(&features_callbacks->mutex);
}
static void on_discovery_result_cb(void* cookie, bt_discovery_result_t* result)
{
bt_instance_t* bt_ins = (bt_instance_t*)cookie;
feature_bluetooth_features_info_t* features_callbacks;
bt_list_t* callbacks;
bt_list_node_t* node;
FEATURE_LOG_DEBUG("discovery result callback");
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return;
}
uv_mutex_lock(&features_callbacks->mutex);
callbacks = features_callbacks->feature_bluetooth_bt_callbacks;
if (!callbacks) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
node = bt_list_head(callbacks);
if (!node) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
while (node) {
feature_bluetooth_bluetooth_bt_callbacks_t* feature_callback;
system_bluetooth_bt_DiscoveryResultCallbackData* data;
char addr_str[BT_ADDR_STR_LENGTH] = { 0 };
feature_callback = (feature_bluetooth_bluetooth_bt_callbacks_t*)bt_list_node(node);
if (!feature_callback) {
break;
}
FEATURE_LOG_DEBUG("feature:%p, callbackId:%d", feature_callback->feature_ins, feature_callback->on_discovery_result_cb_id);
data = system_bluetooth_btMallocDiscoveryResultCallbackData();
if (!data) {
continue;
}
data->name = StringToFtString(result->name);
bt_addr_ba2str(&result->addr, addr_str);
data->deviceId = StringToFtString(addr_str);
data->cod = result->cod;
data->rssi = -result->rssi;
feature_bluetooth_post_task(feature_callback->feature_ins, feature_callback->on_discovery_result_cb_id, data);
node = bt_list_next(callbacks, node);
}
uv_mutex_unlock(&features_callbacks->mutex);
}
static void on_bond_state_changed_cb(void* cookie, bt_address_t* addr, bt_transport_t transport, bond_state_t state, bool is_ctkd)
{
bt_instance_t* bt_ins = (bt_instance_t*)cookie;
feature_bluetooth_features_info_t* features_callbacks;
bt_list_t* callbacks;
bt_list_node_t* node;
FEATURE_LOG_DEBUG("bond state callback");
if (transport != BT_TRANSPORT_BREDR) {
return;
}
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return;
}
uv_mutex_lock(&features_callbacks->mutex);
callbacks = features_callbacks->feature_bluetooth_bt_callbacks;
if (!callbacks) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
node = bt_list_head(callbacks);
if (!node) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
while (node) {
feature_bluetooth_bluetooth_bt_callbacks_t* feature_callback;
system_bluetooth_bt_onBondStateChangeData* data;
char addr_str[BT_ADDR_STR_LENGTH] = { 0 };
feature_callback = (feature_bluetooth_bluetooth_bt_callbacks_t*)bt_list_node(node);
if (!feature_callback) {
break;
}
FEATURE_LOG_DEBUG("feature:%p, callbackId:%d", feature_callback->feature_ins, feature_callback->on_bond_state_changed_cb_id);
data = system_bluetooth_btMalloconBondStateChangeData();
if (!data) {
continue;
}
bt_addr_ba2str(addr, addr_str);
data->deviceId = StringToFtString(addr_str);
data->bondState = state;
feature_bluetooth_post_task(feature_callback->feature_ins, feature_callback->on_bond_state_changed_cb_id, data);
node = bt_list_next(callbacks, node);
}
uv_mutex_unlock(&features_callbacks->mutex);
}
const static adapter_callbacks_t g_adapter_cbs = {
.on_adapter_state_changed = on_adapter_state_changed_cb,
.on_discovery_state_changed = on_discovery_state_changed_cb,
.on_discovery_result = on_discovery_result_cb,
.on_bond_state_changed = on_bond_state_changed_cb,
};
static void a2dp_sink_connection_state_cb(void* cookie, bt_address_t* addr, profile_connection_state_t state)
{
bt_instance_t* bt_ins = (bt_instance_t*)cookie;
feature_bluetooth_features_info_t* features_callbacks;
bt_list_t* callbacks;
bt_list_node_t* node;
FEATURE_LOG_DEBUG("a2dp sink connection state cb");
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return;
}
uv_mutex_lock(&features_callbacks->mutex);
callbacks = features_callbacks->feature_a2dp_sink_callbacks;
if (!callbacks) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
node = bt_list_head(callbacks);
if (!node) {
uv_mutex_unlock(&features_callbacks->mutex);
return;
}
while (node) {
feature_bluetooth_a2dp_sink_callbacks_t* feature_callback;
system_bluetooth_bt_a2dpsink_OnConnectStateChangeData* data;
char addr_str[BT_ADDR_STR_LENGTH] = { 0 };
feature_callback = (feature_bluetooth_a2dp_sink_callbacks_t*)bt_list_node(node);
if (!feature_callback) {
break;
}
FEATURE_LOG_DEBUG("feature:%p, callbackId:%d", feature_callback->feature_ins, feature_callback->a2dp_sink_connection_state_cb_id);
bt_addr_ba2str(addr, addr_str);
data = system_bluetooth_bt_a2dpsinkMallocOnConnectStateChangeData();
if (!data) {
continue;
}
data->deviceId = StringToFtString(addr_str);
data->connectState = state;
feature_bluetooth_post_task(feature_callback->feature_ins, feature_callback->a2dp_sink_connection_state_cb_id, data);
node = bt_list_next(callbacks, node);
}
uv_mutex_unlock(&features_callbacks->mutex);
}
static const a2dp_sink_callbacks_t a2dp_sink_cbs = {
sizeof(a2dp_sink_cbs),
a2dp_sink_connection_state_cb,
};
void feature_bluetooth_add_feature_callback(FeatureInstanceHandle handle, feature_bluetooth_feature_type_t feature_type)
{
bt_instance_t* bt_ins;
feature_bluetooth_features_info_t* features_callbacks;
bt_ins = feature_bluetooth_get_bt_ins(handle);
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return;
}
uv_mutex_lock(&features_callbacks->mutex);
switch (feature_type) {
case FEATURE_BLUETOOTH:
add_feature_callback(features_callbacks->feature_bluetooth_callbacks, feature_bluetooth_bluetooth_callbacks_t, handle);
break;
case FEATURE_BLUETOOTH_BT:
add_feature_callback(features_callbacks->feature_bluetooth_bt_callbacks, feature_bluetooth_bluetooth_bt_callbacks_t, handle);
break;
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
case FEATURE_BLUETOOTH_A2DPSINK:
add_feature_callback(features_callbacks->feature_a2dp_sink_callbacks, feature_bluetooth_a2dp_sink_callbacks_t, handle);
break;
#endif
default:
break;
}
uv_mutex_unlock(&features_callbacks->mutex);
}
void feature_bluetooth_free_feature_callback(FeatureInstanceHandle handle, feature_bluetooth_feature_type_t feature_type)
{
bt_instance_t* bt_ins;
feature_bluetooth_features_info_t* features_callbacks;
bt_ins = feature_bluetooth_get_bt_ins(handle);
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return;
}
uv_mutex_lock(&features_callbacks->mutex);
switch (feature_type) {
case FEATURE_BLUETOOTH:
free_feature_callback(features_callbacks->feature_bluetooth_callbacks, handle, get_callback_bluetooth);
break;
case FEATURE_BLUETOOTH_BT:
free_feature_callback(features_callbacks->feature_bluetooth_bt_callbacks, handle, get_callback_bluetooth_bt);
break;
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
case FEATURE_BLUETOOTH_A2DPSINK:
free_feature_callback(features_callbacks->feature_a2dp_sink_callbacks, handle, get_callback_a2dp_sink);
break;
#endif
default:
break;
}
uv_mutex_unlock(&features_callbacks->mutex);
}
void feature_bluetooth_set_feature_callback(FeatureInstanceHandle handle, FtCallbackId callback_id, feature_bluetooth_callback_t callback_type)
{
bt_instance_t* bt_ins;
feature_bluetooth_features_info_t* features_callbacks;
bt_ins = feature_bluetooth_get_bt_ins(handle);
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return;
}
uv_mutex_lock(&features_callbacks->mutex);
switch (callback_type) {
case ON_ADAPTER_STATE_CHANGE:
set_feature_callback(features_callbacks->feature_bluetooth_callbacks, feature_bluetooth_bluetooth_callbacks_t, get_callback_bluetooth, handle, callback_id, on_adapter_state_changed_cb_id);
break;
case ON_DISCOVERY_RESULT:
set_feature_callback(features_callbacks->feature_bluetooth_bt_callbacks, feature_bluetooth_bluetooth_bt_callbacks_t, get_callback_bluetooth_bt, handle, callback_id, on_discovery_result_cb_id);
break;
case ON_BOND_STATE_CHANGE:
set_feature_callback(features_callbacks->feature_bluetooth_bt_callbacks, feature_bluetooth_bluetooth_bt_callbacks_t, get_callback_bluetooth_bt, handle, callback_id, on_bond_state_changed_cb_id);
break;
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
case A2DPSINK_ON_CONNECT_STATE_CHANGE:
set_feature_callback(features_callbacks->feature_a2dp_sink_callbacks, feature_bluetooth_a2dp_sink_callbacks_t, get_callback_a2dp_sink, handle, callback_id, a2dp_sink_connection_state_cb_id);
break;
#endif
default:
break;
}
uv_mutex_unlock(&features_callbacks->mutex);
}
FtCallbackId feature_bluetooth_get_feature_callback(FeatureInstanceHandle handle, feature_bluetooth_callback_t callback_type)
{
bt_instance_t* bt_ins;
feature_bluetooth_features_info_t* features_callbacks;
FtCallbackId callback_id = -1;
bt_ins = feature_bluetooth_get_bt_ins(handle);
if (!bt_ins) {
return callback_id;
}
features_callbacks = (feature_bluetooth_features_info_t*)bt_ins->context;
if (!features_callbacks) {
return callback_id;
}
uv_mutex_lock(&features_callbacks->mutex);
switch (callback_type) {
case ON_ADAPTER_STATE_CHANGE:
set_feature_callback(features_callbacks->feature_bluetooth_callbacks, feature_bluetooth_bluetooth_callbacks_t, get_callback_bluetooth, handle, callback_id, on_adapter_state_changed_cb_id);
break;
case ON_DISCOVERY_RESULT:
set_feature_callback(features_callbacks->feature_bluetooth_bt_callbacks, feature_bluetooth_bluetooth_bt_callbacks_t, get_callback_bluetooth_bt, handle, callback_id, on_discovery_result_cb_id);
break;
case ON_BOND_STATE_CHANGE:
set_feature_callback(features_callbacks->feature_bluetooth_bt_callbacks, feature_bluetooth_bluetooth_bt_callbacks_t, get_callback_bluetooth_bt, handle, callback_id, on_bond_state_changed_cb_id);
break;
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
case A2DPSINK_ON_CONNECT_STATE_CHANGE:
get_feature_callback(features_callbacks->feature_a2dp_sink_callbacks, feature_bluetooth_a2dp_sink_callbacks_t, get_callback_a2dp_sink, handle, callback_id, a2dp_sink_connection_state_cb_id);
break;
#endif
default:
break;
}
uv_mutex_unlock(&features_callbacks->mutex);
return callback_id;
}
void feature_bluetooth_callback_init(bt_instance_t* bt_ins)
{
feature_bluetooth_features_info_t* features_callbacks;
if (!bt_ins) {
return;
}
features_callbacks = (feature_bluetooth_features_info_t*)calloc(1, sizeof(feature_bluetooth_features_info_t));
assert(features_callbacks);
uv_mutex_init(&features_callbacks->mutex);
features_callbacks->feature_bluetooth_callbacks = bt_list_new(free_feature_bluetooth_node);
features_callbacks->feature_bluetooth_bt_callbacks = bt_list_new(free_feature_bluetooth_bt_node);
bt_ins->adapter_cookie = bt_adapter_register_callback(bt_ins, &g_adapter_cbs);
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
features_callbacks->feature_a2dp_sink_callbacks = bt_list_new(free_feature_bluetooth_a2dp_sink_node);
bt_ins->a2dp_sink_cookie = bt_a2dp_sink_register_callbacks(bt_ins, &a2dp_sink_cbs);
#endif
bt_ins->context = features_callbacks;
}
void feature_bluetooth_callback_uninit(bt_instance_t* bt_ins)
{
feature_bluetooth_features_info_t* features_callbacks;
if (!bt_ins) {
return;
}
features_callbacks = bt_ins->context;
bt_ins->context = NULL;
if (!features_callbacks) {
return;
}
bt_adapter_unregister_callback(bt_ins, bt_ins->adapter_cookie);
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
bt_a2dp_sink_unregister_callbacks(bt_ins, bt_ins->a2dp_sink_cookie);
#endif
uv_mutex_lock(&features_callbacks->mutex);
bt_list_free(features_callbacks->feature_bluetooth_callbacks);
bt_list_free(features_callbacks->feature_bluetooth_bt_callbacks);
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
bt_list_free(features_callbacks->feature_a2dp_sink_callbacks);
#endif
uv_mutex_unlock(&features_callbacks->mutex);
uv_mutex_destroy(&features_callbacks->mutex);
free(features_callbacks);
}

View File

@ -0,0 +1,167 @@
/*
* Copyright (C) 2024 Xiaomi Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "feature_bluetooth.h"
#include "feature_log.h"
#include <kvdb.h>
#define KVDB_USE_FEATURE "persist.using_bluetooth_feature"
static void free_callback_info(callback_info_t* info)
{
if (info->data)
FeatureFreeValue(info->data);
free(info);
}
void feature_bluetooth_deal_callback(int status, void* data)
{
callback_info_t* info = (callback_info_t*)data;
FEATURE_LOG_DEBUG("callback type:%d, feature:%p, callback id: %d", info->callback_id, info->feature, info->feature_callback_id);
if (!FeatureCheckCallbackId(info->feature, info->feature_callback_id)) {
goto freeData;
}
if (!FeatureInvokeCallback(info->feature, info->feature_callback_id, info->data)) {
FEATURE_LOG_ERROR("feature:%p, callback id: %d, invoke discoveryresult callback failed!",
info->feature, info->feature_callback_id);
}
freeData:
free_callback_info(info);
}
void feature_bluetooth_remove_callback(int status, void* data)
{
callback_info_t* info = (callback_info_t*)data;
FEATURE_LOG_DEBUG("remove callback, feature:%p, callback id: %d", info->feature, info->feature_callback_id);
FeatureRemoveCallback(info->feature, info->feature_callback_id);
free_callback_info(info);
}
void feature_bluetooth_post_task(FeatureInstanceHandle handle, FtCallbackId callback_id, void* data)
{
callback_info_t* callback_info;
callback_info = (callback_info_t*)calloc(1, sizeof(callback_info_t));
if (!callback_info) {
if (data)
FeatureFreeValue(data);
return;
}
callback_info->feature_callback_id = callback_id;
callback_info->feature = handle;
callback_info->data = data;
if (!FeaturePost(handle, feature_bluetooth_deal_callback, callback_info)) {
FEATURE_LOG_WARN("feature:%p, callback id: %d, post callback failed!", handle, callback_id);
free_callback_info(callback_info);
}
}
char* StringToFtString(const char* str)
{
int len = strlen(str);
char* ftStr = (char*)FeatureMalloc(len + 1, FT_CHAR);
strcpy(ftStr, str);
return ftStr;
}
static bool feature_bluetooth_using_feature()
{
static int using_bluetoothd_feature = -1;
if (using_bluetoothd_feature == -1) {
using_bluetoothd_feature = property_get_bool(KVDB_USE_FEATURE, 1);
}
return using_bluetoothd_feature;
}
void feature_bluetooth_init_bt_ins(feature_bluetooth_feature_type_t feature, FeatureProtoHandle handle)
{
bt_instance_t* bluetooth_ins;
if (!feature_bluetooth_using_feature()) {
FeatureSetProtoData(handle, NULL);
return;
}
bluetooth_ins = bluetooth_get_instance();
if (bluetooth_ins == NULL) {
FEATURE_LOG_ERROR("Failed to get Bluetooth instance.");
return;
}
if (bluetooth_ins->context == NULL) {
feature_bluetooth_callback_init(bluetooth_ins);
}
((feature_bluetooth_features_info_t*)bluetooth_ins->context)->created_features |= (1UL << feature);
FeatureSetProtoData(handle, bluetooth_ins);
}
void feature_bluetooth_uninit_bt_ins(feature_bluetooth_feature_type_t feature, FeatureProtoHandle handle)
{
bt_instance_t* bluetooth_ins;
feature_bluetooth_features_info_t* features_info;
if (!feature_bluetooth_using_feature()) {
return;
}
FeatureSetProtoData(handle, NULL);
bluetooth_ins = bluetooth_find_instance(getpid());
if (bluetooth_ins == NULL) {
FEATURE_LOG_ERROR("Bluetooth instance not found.");
return;
}
features_info = (feature_bluetooth_features_info_t*)bluetooth_ins->context;
if (!features_info) {
FEATURE_LOG_ERROR("Feature context not found.");
return;
}
features_info->created_features &= ~(1UL << feature);
if (features_info->created_features) {
return;
}
feature_bluetooth_callback_uninit(bluetooth_ins);
bluetooth_delete_instance(bluetooth_ins);
}
void feature_bluetooth_set_bt_ins(FeatureProtoHandle protoHandle)
{
bt_instance_t* bluetooth_ins = bluetooth_get_instance();
FeatureSetProtoData(protoHandle, bluetooth_ins);
}
bt_instance_t* feature_bluetooth_get_bt_ins(FeatureInstanceHandle feature)
{
FeatureProtoHandle protoHandle = FeatureGetProtoHandle(feature);
return FeatureGetProtoData(protoHandle);
}

View File

@ -0,0 +1,70 @@
/*
* This file is auto-generated by jsongensource.py, Do not modify it directly!
*/
/*
* Copyright (C) 2023 Xiaomi Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "bt_a2dp_sink.h"
#include "feature_bluetooth.h"
#include "system_bluetooth_bt_a2dpsink.h"
#define file_tag "system_bluetooth_bt_a2dpsnk"
void system_bluetooth_bt_a2dpsink_onRegister(const char* feature_name)
{
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_a2dpsink_onCreate(FeatureRuntimeContext ctx, FeatureProtoHandle handle)
{
feature_bluetooth_init_bt_ins(FEATURE_BLUETOOTH_A2DPSINK, handle);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_a2dpsink_onRequired(FeatureRuntimeContext ctx, FeatureInstanceHandle handle)
{
feature_bluetooth_add_feature_callback(handle, FEATURE_BLUETOOTH_A2DPSINK);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_a2dpsink_onDetached(FeatureRuntimeContext ctx, FeatureInstanceHandle handle)
{
feature_bluetooth_free_feature_callback(handle, FEATURE_BLUETOOTH_A2DPSINK);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_a2dpsink_onDestroy(FeatureRuntimeContext ctx, FeatureProtoHandle handle)
{
feature_bluetooth_uninit_bt_ins(FEATURE_BLUETOOTH_A2DPSINK, handle);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_a2dpsink_onUnregister(const char* feature_name)
{
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
FtCallbackId system_bluetooth_bt_a2dpsink_get_onconnectstatechange(void* feature, AppendData append_data)
{
return feature_bluetooth_get_feature_callback(feature, A2DPSINK_ON_CONNECT_STATE_CHANGE);
}
void system_bluetooth_bt_a2dpsink_set_onconnectstatechange(void* feature, AppendData append_data, FtCallbackId onconnectstatechange)
{
FEATURE_LOG_DEBUG("set on a2dpsink set on connect state change callback: %p, callbackId: %d", feature, onconnectstatechange);
feature_bluetooth_set_feature_callback(feature, onconnectstatechange, A2DPSINK_ON_CONNECT_STATE_CHANGE);
}

View File

@ -0,0 +1,457 @@
/*
* This file is auto-generated by jsongensource.py, Do not modify it directly!
*/
/*
* Copyright (C) 2023 Xiaomi Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "bluetooth.h"
#include "bt_a2dp_sink.h"
#include "bt_a2dp_source.h"
#include "bt_adapter.h"
#include "bt_hfp_ag.h"
#include "bt_hfp_hf.h"
#include "bt_hid_device.h"
#include "bt_pan.h"
#include "feature_bluetooth.h"
#include "system_bluetooth_bt.h"
#define file_tag "system_bluetooth_bt"
static bool bt_feature_allocator(void** data, uint32_t size)
{
*data = malloc(size);
if (!(*data))
return false;
return true;
}
static bt_status_t bluetooth_connect_profiles(FeatureInstanceHandle feature, bt_address_t* addr, feature_bluetooth_profile_t profile_id)
{
bt_status_t status = BT_STATUS_SUCCESS;
bt_instance_t* bt_ins = feature_bluetooth_get_bt_ins(feature);
if (!bt_ins) {
return BT_STATUS_FAIL;
}
switch (profile_id) {
case A2DP_SINK:
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
status = bt_a2dp_sink_connect(bt_ins, addr);
#endif
break;
case A2DP_SOURCE:
#ifdef CONFIG_BLUETOOTH_A2DP_SOURCE
status = bt_a2dp_source_connect(bt_ins, addr);
#endif
break;
case HFP_AG:
#ifdef CONFIG_BLUETOOTH_HFP_AG
status = bt_hfp_ag_connect(bt_ins, addr);
#endif
break;
case HFP_HF:
#ifdef CONFIG_BLUETOOTH_HFP_HF
status = bt_hfp_hf_connect(bt_ins, addr);
#endif
break;
case HID_DEVICE:
#ifdef CONFIG_BLUETOOTH_HID_DEVICE
status = bt_hid_device_connect(bt_ins, addr);
#endif
break;
case PAN_USE:
#ifdef CONFIG_BLUETOOTH_PAN
status = bt_pan_connect(bt_ins, addr);
#endif
break;
default:
status = BT_STATUS_NOT_SUPPORTED;
break;
}
return status;
}
static bt_status_t bluetooth_disconnect_profiles(FeatureInstanceHandle feature, bt_address_t* addr, feature_bluetooth_profile_t profile_id)
{
bt_status_t status = BT_STATUS_SUCCESS;
bt_instance_t* bt_ins = feature_bluetooth_get_bt_ins(feature);
if (!bt_ins) {
return BT_STATUS_FAIL;
}
switch (profile_id) {
case A2DP_SINK:
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
status = bt_a2dp_sink_disconnect(bt_ins, addr);
#endif
break;
case A2DP_SOURCE:
#ifdef CONFIG_BLUETOOTH_A2DP_SOURCE
status = bt_a2dp_source_disconnect(bt_ins, addr);
#endif
break;
case HFP_AG:
#ifdef CONFIG_BLUETOOTH_HFP_AG
status = bt_hfp_ag_disconnect(bt_ins, addr);
#endif
break;
case HFP_HF:
#ifdef CONFIG_BLUETOOTH_HFP_HF
status = bt_hfp_hf_disconnect(bt_ins, addr);
#endif
break;
case HID_DEVICE:
#ifdef CONFIG_BLUETOOTH_HID_DEVICE
status = bt_hid_device_disconnect(bt_ins, addr);
#endif
break;
case PAN_USE:
#ifdef CONFIG_BLUETOOTH_PAN
status = bt_pan_disconnect(bt_ins, addr);
#endif
break;
default:
status = BT_STATUS_NOT_SUPPORTED;
break;
}
return status;
}
void system_bluetooth_bt_onRegister(const char* feature_name)
{
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_onCreate(FeatureRuntimeContext ctx, FeatureProtoHandle handle)
{
feature_bluetooth_init_bt_ins(FEATURE_BLUETOOTH_BT, handle);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_onRequired(FeatureRuntimeContext ctx, FeatureInstanceHandle handle)
{
feature_bluetooth_add_feature_callback(handle, FEATURE_BLUETOOTH_BT);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_onDetached(FeatureRuntimeContext ctx, FeatureInstanceHandle handle)
{
feature_bluetooth_free_feature_callback(handle, FEATURE_BLUETOOTH_BT);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_onDestroy(FeatureRuntimeContext ctx, FeatureProtoHandle handle)
{
feature_bluetooth_uninit_bt_ins(FEATURE_BLUETOOTH_BT, handle);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_onUnregister(const char* feature_name)
{
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_bt_wrap_startDiscovery(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_bt_StartDiscoveryParams* params)
{
int timeout = 8;
bt_status_t status = bt_adapter_start_discovery(feature_bluetooth_get_bt_ins(feature), timeout);
if (status == BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke start discovery success failed!");
}
} else {
if (!FeatureInvokeCallback(feature, params->fail, "start discovery failed!", status)) {
FEATURE_LOG_ERROR("invoke start discovery fail callback failed!");
}
}
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke start discovery complete callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}
void system_bluetooth_bt_wrap_stopDiscovery(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_bt_StopDiscoveryParams* params)
{
bt_status_t status = bt_adapter_cancel_discovery(feature_bluetooth_get_bt_ins(feature));
if (status == BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke stop discovery success callback failed!");
}
} else {
if (!FeatureInvokeCallback(feature, params->fail, "stop discovery failed!", status)) {
FEATURE_LOG_ERROR("invoke stop discovery fail callback failed!");
}
}
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke stop discovery complete callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}
void system_bluetooth_bt_wrap_connectProfiles(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_bt_ConnectProfilesParams* params)
{
int profiles_num = params->profiles->_size;
int* profiles = (int*)(params->profiles->_element);
bt_address_t addr;
int status = BT_STATUS_SUCCESS;
if (bt_addr_str2ba(params->deviceId, &addr) < 0) {
if (!FeatureInvokeCallback(feature, params->fail, "invalid addr!", BT_STATUS_PARM_INVALID)) {
FEATURE_LOG_ERROR("invoke connect profiles fail callback failed!");
}
goto COMPLETE_CALLBACK;
}
for (int i = 0; i < profiles_num; ++i) {
status |= bluetooth_connect_profiles(feature, &addr, (feature_bluetooth_profile_t)(profiles[i]));
}
if (status != BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->fail, "connect all passing profiles failed!", status)) {
FEATURE_LOG_ERROR("invoke connect profiles fail callback failed!");
}
} else {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke connect profiles success callback failed!");
}
}
COMPLETE_CALLBACK:
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke connect profiles complete callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}
void system_bluetooth_bt_wrap_disconnectProfiles(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_bt_DisconnectProfilesParams* params)
{
int profiles_num = params->profiles->_size;
int* profiles = (int*)params->profiles->_element;
bt_address_t addr;
int status = BT_STATUS_SUCCESS;
if (bt_addr_str2ba(params->deviceId, &addr) < 0) {
if (!FeatureInvokeCallback(feature, params->fail, "invalid addr!", BT_STATUS_PARM_INVALID)) {
FEATURE_LOG_ERROR("invoke disconnect profiles fail callback failed!");
}
goto COMPLETE_CALLBACK;
}
for (int i = 0; i < profiles_num; ++i) {
status |= bluetooth_disconnect_profiles(feature, &addr, (feature_bluetooth_profile_t)profiles[i]);
}
if (status != BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->fail, "disconnect all passing profiles failed!", status)) {
FEATURE_LOG_ERROR("invoke disconnect profiles fail callback failed!");
}
} else {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke disconnect profiles success callback failed!");
}
}
COMPLETE_CALLBACK:
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke disconnect profiles complete callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}
void system_bluetooth_bt_wrap_disconnect(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_bt_DisconnectParams* params)
{
bt_address_t addr;
bt_status_t status = BT_STATUS_SUCCESS;
if (bt_addr_str2ba(params->deviceId, &addr) < 0) {
if (!FeatureInvokeCallback(feature, params->fail, "invalid addr!", BT_STATUS_PARM_INVALID)) {
FEATURE_LOG_ERROR("invoke disconnect fail callback failed!");
}
goto COMPLETE_CALLBACK;
}
status = bt_device_disconnect(feature_bluetooth_get_bt_ins(feature), &addr);
if (status != BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->fail, "disconnect failed!", status)) {
FEATURE_LOG_ERROR("invoke disconnect fail callback failed!");
}
} else {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke disconnect success callback failed!");
}
}
COMPLETE_CALLBACK:
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke disconnect complete callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}
FtBool system_bluetooth_bt_wrap_getConnectState(FeatureInstanceHandle feature, AppendData append_data, FtString deviceId)
{
FtBool connected = false;
bt_address_t addr;
if (bt_addr_str2ba(deviceId, &addr) < 0) {
return false;
}
#ifdef CONFIG_BLUETOOTH_A2DP_SINK
connected |= bt_a2dp_sink_get_connection_state(feature_bluetooth_get_bt_ins(feature), &addr);
#endif
return connected;
}
FtArray* system_bluetooth_bt_wrap_getConnectedDevices(FeatureInstanceHandle feature, AppendData append_data)
{
bt_address_t* addrs = NULL;
int num = 0;
bt_adapter_get_connected_devices(feature_bluetooth_get_bt_ins(feature), BT_TRANSPORT_BREDR, &addrs, &num, bt_feature_allocator);
FtArray* devices = system_bluetooth_bt_malloc_string_array();
devices->_size = num;
devices->_element = malloc(devices->_size * sizeof(char*));
for (int i = 0; i < devices->_size; ++i) {
char addr_str[BT_ADDR_STR_LENGTH] = { 0 };
bt_addr_ba2str(addrs + i, addr_str);
((char**)devices->_element)[i] = StringToFtString(addr_str);
}
free(addrs);
return devices;
}
FtArray* system_bluetooth_bt_wrap_getBondedDevices(FeatureInstanceHandle feature, AppendData append_data)
{
bt_address_t* addrs = NULL;
int num = 0;
bt_adapter_get_bonded_devices(feature_bluetooth_get_bt_ins(feature), BT_TRANSPORT_BREDR, &addrs, &num, bt_feature_allocator);
FtArray* devices = system_bluetooth_bt_malloc_string_array();
devices->_size = num;
devices->_element = malloc(devices->_size * sizeof(char*));
for (int i = 0; i < devices->_size; ++i) {
char addr_str[BT_ADDR_STR_LENGTH] = { 0 };
bt_addr_ba2str(addrs + i, addr_str);
((char**)devices->_element)[i] = StringToFtString(addr_str);
}
free(addrs);
return devices;
}
void system_bluetooth_bt_wrap_removeBondedDevice(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_bt_RemoveBondedParams* params)
{
bt_address_t addr;
bt_status_t status;
if (bt_addr_str2ba(params->deviceId, &addr) < 0) {
if (!FeatureInvokeCallback(feature, params->fail, "invalid addr!", BT_STATUS_PARM_INVALID)) {
FEATURE_LOG_ERROR("invoke remove bonded fail callback failed!");
}
goto COMPLETE_CALLBACK;
}
if (!bt_device_is_bonded(feature_bluetooth_get_bt_ins(feature), &addr, BT_TRANSPORT_BREDR)) {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke remove bonded success callback failed!");
}
goto COMPLETE_CALLBACK;
}
status = bt_device_remove_bond(feature_bluetooth_get_bt_ins(feature), &addr, BT_TRANSPORT_BREDR);
if (status != BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->fail, "remove bonded failed!", status)) {
FEATURE_LOG_ERROR("invoke remove bonded fail callback failed!");
}
} else {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke remove bonded success callback failed!");
}
}
COMPLETE_CALLBACK:
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke remove bonded complete callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}
FtBool system_bluetooth_bt_wrap_setScanMode(FeatureInstanceHandle feature, AppendData append_data, FtInt scanMode)
{
FEATURE_LOG_DEBUG("set scanmode: %d!", scanMode);
if (scanMode < 0 || scanMode > 2) {
return false;
}
if (bt_adapter_set_scan_mode(feature_bluetooth_get_bt_ins(feature), (bt_scan_mode_t)scanMode, 1) == BT_STATUS_SUCCESS) {
return true;
} else {
return false;
}
}
FtInt system_bluetooth_bt_wrap_getScanMode(FeatureInstanceHandle feature, AppendData append_data)
{
return bt_adapter_get_scan_mode(feature_bluetooth_get_bt_ins(feature));
}
FtString system_bluetooth_bt_wrap_getDeviceName(FeatureInstanceHandle feature, AppendData append_data, FtString deviceId)
{
bt_address_t addr;
char name[64] = { 0 };
if (bt_addr_str2ba(deviceId, &addr) < 0) {
return StringToFtString("");
}
bt_device_get_name(feature_bluetooth_get_bt_ins(feature), &addr, name, 64);
return StringToFtString(name);
}
unsigned int system_bluetooth_bt_wrap_getDeviceClass(FeatureInstanceHandle feature, AppendData append_data, FtString deviceId)
{
bt_address_t addr;
if (bt_addr_str2ba(deviceId, &addr) < 0) {
return 0;
}
return bt_device_get_device_class(feature_bluetooth_get_bt_ins(feature), &addr);
}
FtCallbackId system_bluetooth_bt_get_ondiscoveryresult(void* feature, AppendData append_data)
{
return feature_bluetooth_get_feature_callback(feature, ON_DISCOVERY_RESULT);
}
void system_bluetooth_bt_set_ondiscoveryresult(void* feature, AppendData append_data, FtCallbackId ondiscoveryresult)
{
FEATURE_LOG_DEBUG("set ondiscoveryresult feature: %p, callbackId: %d", feature, ondiscoveryresult);
feature_bluetooth_set_feature_callback(feature, ondiscoveryresult, ON_DISCOVERY_RESULT);
}
FtCallbackId system_bluetooth_bt_get_onbondstatechange(void* feature, AppendData append_data)
{
return feature_bluetooth_get_feature_callback(feature, ON_BOND_STATE_CHANGE);
}
void system_bluetooth_bt_set_onbondstatechange(void* feature, AppendData append_data, FtCallbackId onbondstatechange)
{
FEATURE_LOG_DEBUG("set onbondstatechange feature: %p, callbackId: %d", feature, onbondstatechange);
feature_bluetooth_set_feature_callback(feature, onbondstatechange, ON_BOND_STATE_CHANGE);
}

View File

@ -0,0 +1,140 @@
/*
* This file is auto-generated by jsongensource.py, Do not modify it directly!
*/
/*
* Copyright (C) 2023 Xiaomi Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include "bluetooth.h"
#include "bt_adapter.h"
#include "feature_bluetooth.h"
#include "feature_exports.h"
#include "feature_log.h"
#include "system_bluetooth.h"
#include "system_bluetooth_bt.h"
#define file_tag "system_bluetooth"
void system_bluetooth_onRegister(const char* feature_name)
{
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_onCreate(FeatureRuntimeContext ctx, FeatureProtoHandle handle)
{
feature_bluetooth_init_bt_ins(FEATURE_BLUETOOTH, handle);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_onRequired(FeatureRuntimeContext ctx, FeatureInstanceHandle handle)
{
feature_bluetooth_add_feature_callback(handle, FEATURE_BLUETOOTH);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_onDetached(FeatureRuntimeContext ctx, FeatureInstanceHandle handle)
{
feature_bluetooth_free_feature_callback(handle, FEATURE_BLUETOOTH);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_onDestroy(FeatureRuntimeContext ctx, FeatureProtoHandle handle)
{
feature_bluetooth_uninit_bt_ins(FEATURE_BLUETOOTH, handle);
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_onUnregister(const char* feature_name)
{
FEATURE_LOG_DEBUG("%s::%s()", file_tag, __FUNCTION__);
}
void system_bluetooth_wrap_openAdapter(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_OpenAdapterParams* params)
{
bt_status_t status = bt_adapter_enable(feature_bluetooth_get_bt_ins(feature));
if (status == BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke success openAdapter callback failed, feature is %p, params->success is %d!", feature, params->success);
}
} else {
if (!FeatureInvokeCallback(feature, params->fail, "enable fail!", status)) {
FEATURE_LOG_ERROR("invoke fail openAdapter callback failed!");
}
}
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke complete openAdapter callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}
void system_bluetooth_wrap_closeAdapter(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_CloseAdapterParams* params)
{
bt_status_t status = bt_adapter_disable(feature_bluetooth_get_bt_ins(feature));
if (status == BT_STATUS_SUCCESS) {
if (!FeatureInvokeCallback(feature, params->success)) {
FEATURE_LOG_ERROR("invoke success closeAdapter callback failed!");
}
} else {
if (!FeatureInvokeCallback(feature, params->fail, "enable fail!", status)) {
FEATURE_LOG_ERROR("invoke fail closeAdapter callback failed!");
}
}
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke complete closeAdapter callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}
void system_bluetooth_wrap_getAdapterState(FeatureInstanceHandle feature, AppendData append_data, system_bluetooth_GetAdapterStateParams* params)
{
bt_instance_t* ins = feature_bluetooth_get_bt_ins(feature);
bt_adapter_state_t state = bt_adapter_get_state(ins);
bool is_discovering = bt_adapter_is_discovering(ins);
system_bluetooth_GetAdapterSuccessResult* success_result = system_bluetoothMallocGetAdapterSuccessResult();
success_result->available = state == BT_ADAPTER_STATE_ON;
success_result->discovering = is_discovering;
if (!FeatureInvokeCallback(feature, params->success, success_result)) {
FEATURE_LOG_ERROR("invoke success getAdapterState callback failed!");
}
FeatureFreeValue(success_result);
if (!FeatureInvokeCallback(feature, params->complete)) {
FEATURE_LOG_ERROR("invoke complete getAdapterState callback failed!");
}
FeatureRemoveCallback(feature, params->success);
FeatureRemoveCallback(feature, params->fail);
FeatureRemoveCallback(feature, params->complete);
}
FtCallbackId system_bluetooth_get_onadapterstatechange(void* feature, AppendData append_data)
{
return feature_bluetooth_get_feature_callback(feature, ON_ADAPTER_STATE_CHANGE);
}
void system_bluetooth_set_onadapterstatechange(void* feature, AppendData append_data, FtCallbackId onadapterstatechange)
{
FEATURE_LOG_DEBUG("set onadapterstatechange feature: %p, callbackId: %d", feature, onadapterstatechange);
feature_bluetooth_set_feature_callback(feature, onadapterstatechange, ON_ADAPTER_STATE_CHANGE);
}

109
framework/api/bluetooth.c Normal file
View File

@ -0,0 +1,109 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdlib.h>
#include <unistd.h>
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_LOCAL
#include "btservice.h"
#include "manager_service.h"
#include "service_loop.h"
#endif
#include "bluetooth.h"
#include "bt_internal.h"
#include "manager_service.h"
/*
*/
bt_instance_t* BTSYMBOLS(bluetooth_create_instance)(void)
{
uint32_t app_id;
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_LOCAL
service_loop_init();
bt_service_init();
service_loop_run(true, "bt_service");
#endif
bt_instance_t* ins = zalloc(sizeof(bt_instance_t));
if (!ins) {
return NULL;
}
bt_status_t status = manager_create_instance(PTR2INT(uint64_t) ins, BLUETOOTH_SYSTEM, "local", getpid(), 0, &app_id);
if (status != BT_STATUS_SUCCESS) {
free(ins);
return NULL;
}
ins->app_id = app_id;
return ins;
}
bt_instance_t* BTSYMBOLS(bluetooth_get_instance)(void)
{
bt_status_t status;
uint64_t handle;
status = manager_get_instance("local", getpid(), &handle);
if (status == BT_STATUS_SUCCESS && handle)
return INT2PTR(bt_instance_t*) handle;
else
return BTSYMBOLS(bluetooth_create_instance)();
}
void* BTSYMBOLS(bluetooth_get_proxy)(bt_instance_t* ins, enum profile_id id)
{
switch (id) {
case PROFILE_HFP_HF:
/* for binder ipc*/
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_BINDER_IPC
if (!ins->hfp_hf_proxy) {
ins->hfp_hf_proxy = NULL;
}
return ins->hfp_hf_proxy;
#endif
default:
break;
}
return NULL;
}
void BTSYMBOLS(bluetooth_delete_instance)(bt_instance_t* ins)
{
manager_delete_instance(ins->app_id);
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_LOCAL
bt_service_cleanup();
service_loop_exit();
#endif
free(ins);
}
bt_status_t BTSYMBOLS(bluetooth_start_service)(bt_instance_t* ins, enum profile_id id)
{
return manager_start_service(ins->app_id, id);
}
bt_status_t BTSYMBOLS(bluetooth_stop_service)(bt_instance_t* ins, enum profile_id id)
{
return manager_stop_service(ins->app_id, id);
}
#include "uv.h"
bool BTSYMBOLS(bluetooth_set_external_uv)(bt_instance_t* ins, uv_loop_t* ext_loop)
{
return false;
}

View File

@ -0,0 +1,86 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "a2dp_sink_api"
#include <stdint.h>
#include "a2dp_sink_service.h"
#include "bt_a2dp_sink.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "service_manager.h"
#include "utils/log.h"
static a2dp_sink_interface_t* get_profile_service(void)
{
return (a2dp_sink_interface_t*)service_manager_get_profile(PROFILE_A2DP_SINK);
}
void* BTSYMBOLS(bt_a2dp_sink_register_callbacks)(bt_instance_t* ins, const a2dp_sink_callbacks_t* callbacks)
{
a2dp_sink_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool BTSYMBOLS(bt_a2dp_sink_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
a2dp_sink_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bool BTSYMBOLS(bt_a2dp_sink_is_connected)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_sink_interface_t* profile = get_profile_service();
return profile->is_connected(addr);
}
bool BTSYMBOLS(bt_a2dp_sink_is_playing)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_sink_interface_t* profile = get_profile_service();
return profile->is_playing(addr);
}
profile_connection_state_t BTSYMBOLS(bt_a2dp_sink_get_connection_state)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_sink_interface_t* profile = get_profile_service();
return profile->get_connection_state(addr);
}
bt_status_t BTSYMBOLS(bt_a2dp_sink_connect)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_sink_interface_t* profile = get_profile_service();
return profile->connect(addr);
}
bt_status_t BTSYMBOLS(bt_a2dp_sink_disconnect)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_sink_interface_t* profile = get_profile_service();
return profile->disconnect(addr);
}
bt_status_t BTSYMBOLS(bt_a2dp_sink_set_active_device)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_sink_interface_t* profile = get_profile_service();
return profile->set_active_device(addr);
}

View File

@ -0,0 +1,93 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "a2dp_source_api"
#include <stdint.h>
#include "a2dp_source_service.h"
#include "bt_a2dp_source.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "service_manager.h"
#include "utils/log.h"
static a2dp_source_interface_t* get_profile_service(void)
{
return (a2dp_source_interface_t*)service_manager_get_profile(PROFILE_A2DP);
}
void* BTSYMBOLS(bt_a2dp_source_register_callbacks)(bt_instance_t* ins, const a2dp_source_callbacks_t* callbacks)
{
a2dp_source_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool BTSYMBOLS(bt_a2dp_source_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
a2dp_source_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bool BTSYMBOLS(bt_a2dp_source_is_connected)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_source_interface_t* profile = get_profile_service();
return profile->is_connected(addr);
}
bool BTSYMBOLS(bt_a2dp_source_is_playing)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_source_interface_t* profile = get_profile_service();
return profile->is_playing(addr);
}
profile_connection_state_t BTSYMBOLS(bt_a2dp_source_get_connection_state)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_source_interface_t* profile = get_profile_service();
return profile->get_connection_state(addr);
}
bt_status_t BTSYMBOLS(bt_a2dp_source_connect)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_source_interface_t* profile = get_profile_service();
return profile->connect(addr);
}
bt_status_t BTSYMBOLS(bt_a2dp_source_disconnect)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_source_interface_t* profile = get_profile_service();
return profile->disconnect(addr);
}
bt_status_t BTSYMBOLS(bt_a2dp_source_set_silence_device)(bt_instance_t* ins, bt_address_t* addr, bool silence)
{
a2dp_source_interface_t* profile = get_profile_service();
return profile->set_silence_device(addr, silence);
}
bt_status_t BTSYMBOLS(bt_a2dp_source_set_active_device)(bt_instance_t* ins, bt_address_t* addr)
{
a2dp_source_interface_t* profile = get_profile_service();
return profile->set_active_device(addr);
}

237
framework/api/bt_adapter.c Normal file
View File

@ -0,0 +1,237 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "adapter_internel.h"
#include "bt_adapter.h"
#include "bt_internal.h"
void* BTSYMBOLS(bt_adapter_register_callback)(bt_instance_t* ins, const adapter_callbacks_t* adapter_cbs)
{
return adapter_register_callback(NULL, adapter_cbs);
}
bool BTSYMBOLS(bt_adapter_unregister_callback)(bt_instance_t* ins, void* cookie)
{
return adapter_unregister_callback(NULL, cookie);
}
bt_status_t BTSYMBOLS(bt_adapter_enable)(bt_instance_t* ins)
{
return adapter_enable(SYS_SET_BT_ALL);
}
bt_status_t BTSYMBOLS(bt_adapter_disable)(bt_instance_t* ins)
{
return adapter_disable(SYS_SET_BT_ALL);
}
bt_status_t BTSYMBOLS(bt_adapter_enable_le)(bt_instance_t* ins)
{
return adapter_enable(APP_SET_LE_ONLY);
}
bt_status_t BTSYMBOLS(bt_adapter_disable_le)(bt_instance_t* ins)
{
return adapter_disable(APP_SET_LE_ONLY);
}
bt_adapter_state_t BTSYMBOLS(bt_adapter_get_state)(bt_instance_t* ins)
{
return adapter_get_state();
}
bool BTSYMBOLS(bt_adapter_is_le_enabled)(bt_instance_t* ins)
{
return adapter_is_le_enabled();
}
bt_device_type_t BTSYMBOLS(bt_adapter_get_type)(bt_instance_t* ins)
{
return adapter_get_type();
}
bt_status_t BTSYMBOLS(bt_adapter_set_discovery_filter)(bt_instance_t* ins)
{
return 0;
}
bt_status_t BTSYMBOLS(bt_adapter_start_discovery)(bt_instance_t* ins, uint32_t timeout)
{
return adapter_start_discovery(timeout);
}
bt_status_t BTSYMBOLS(bt_adapter_cancel_discovery)(bt_instance_t* ins)
{
return adapter_cancel_discovery();
}
bool BTSYMBOLS(bt_adapter_is_discovering)(bt_instance_t* ins)
{
return adapter_is_discovering();
}
void BTSYMBOLS(bt_adapter_get_address)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_get_address(addr);
}
bt_status_t BTSYMBOLS(bt_adapter_set_name)(bt_instance_t* ins, const char* name)
{
return adapter_set_name(name);
}
void BTSYMBOLS(bt_adapter_get_name)(bt_instance_t* ins, char* name, int length)
{
return adapter_get_name(name, length);
}
bt_status_t BTSYMBOLS(bt_adapter_get_uuids)(bt_instance_t* ins, bt_uuid_t* uuids, uint16_t* size)
{
return adapter_get_uuids(uuids, size);
}
bt_status_t BTSYMBOLS(bt_adapter_set_scan_mode)(bt_instance_t* ins, bt_scan_mode_t mode, bool bondable)
{
return adapter_set_scan_mode(mode, bondable);
}
bt_scan_mode_t BTSYMBOLS(bt_adapter_get_scan_mode)(bt_instance_t* ins)
{
return adapter_get_scan_mode();
}
bt_status_t BTSYMBOLS(bt_adapter_set_device_class)(bt_instance_t* ins, uint32_t cod)
{
return adapter_set_device_class(cod);
}
uint32_t BTSYMBOLS(bt_adapter_get_device_class)(bt_instance_t* ins)
{
return adapter_get_device_class();
}
bt_status_t BTSYMBOLS(bt_adapter_set_io_capability)(bt_instance_t* ins, bt_io_capability_t cap)
{
return adapter_set_io_capability(cap);
}
bt_io_capability_t BTSYMBOLS(bt_adapter_get_io_capability)(bt_instance_t* ins)
{
return adapter_get_io_capability();
}
bt_status_t BTSYMBOLS(bt_adapter_set_inquiry_scan_parameters)(bt_instance_t* ins, bt_scan_type_t type,
uint16_t interval, uint16_t window)
{
return adapter_set_inquiry_scan_parameters(type, interval, window);
}
bt_status_t BTSYMBOLS(bt_adapter_set_page_scan_parameters)(bt_instance_t* ins, bt_scan_type_t type,
uint16_t interval, uint16_t window)
{
return adapter_set_page_scan_parameters(type, interval, window);
}
bt_status_t BTSYMBOLS(bt_adapter_set_le_io_capability)(bt_instance_t* ins, uint32_t le_io_cap)
{
return adapter_set_le_io_capability(le_io_cap);
}
uint32_t BTSYMBOLS(bt_adapter_get_le_io_capability)(bt_instance_t* ins)
{
return adapter_get_le_io_capability();
}
bt_status_t BTSYMBOLS(bt_adapter_get_le_address)(bt_instance_t* ins, bt_address_t* addr, ble_addr_type_t* type)
{
return adapter_get_le_address(addr, type);
}
bt_status_t BTSYMBOLS(bt_adapter_set_le_address)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_set_le_address(addr);
}
bt_status_t BTSYMBOLS(bt_adapter_set_le_identity_address)(bt_instance_t* ins, bt_address_t* addr, bool public)
{
return adapter_set_le_identity_address(addr, public);
}
bt_status_t BTSYMBOLS(bt_adapter_set_le_appearance)(bt_instance_t* ins, uint16_t appearance)
{
return adapter_set_le_appearance(appearance);
}
uint16_t BTSYMBOLS(bt_adapter_get_le_appearance)(bt_instance_t* ins)
{
return adapter_get_le_appearance();
}
bt_status_t BTSYMBOLS(bt_adapter_le_enable_key_derivation)(bt_instance_t* ins,
bool brkey_to_lekey,
bool lekey_to_brkey)
{
return adapter_le_enable_key_derivation(brkey_to_lekey, lekey_to_brkey);
}
bt_status_t BTSYMBOLS(bt_adapter_le_add_whitelist)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_le_add_whitelist(addr);
}
bt_status_t BTSYMBOLS(bt_adapter_le_remove_whitelist)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_le_remove_whitelist(addr);
}
bt_status_t BTSYMBOLS(bt_adapter_get_bonded_devices)(bt_instance_t* ins, bt_transport_t transport, bt_address_t** addr, int* num, bt_allocator_t allocator)
{
return adapter_get_bonded_devices(transport, addr, num, allocator);
}
bt_status_t BTSYMBOLS(bt_adapter_get_connected_devices)(bt_instance_t* ins, bt_transport_t transport, bt_address_t** addr, int* num, bt_allocator_t allocator)
{
return adapter_get_connected_devices(transport, addr, num, allocator);
}
bt_status_t BTSYMBOLS(bt_adapter_set_afh_channel_classification)(bt_instance_t* ins, uint16_t central_frequency,
uint16_t band_width, uint16_t number)
{
return adapter_set_afh_channel_classification(central_frequency, band_width, number);
}
void BTSYMBOLS(bt_adapter_disconnect_all_devices)(bt_instance_t* ins)
{
}
bool BTSYMBOLS(bt_adapter_is_support_bredr)(bt_instance_t* ins)
{
return adapter_is_support_bredr();
}
bool BTSYMBOLS(bt_adapter_is_support_le)(bt_instance_t* ins)
{
return adapter_is_support_le();
}
bool BTSYMBOLS(bt_adapter_is_support_leaudio)(bt_instance_t* ins)
{
return adapter_is_support_leaudio();
}

View File

@ -0,0 +1,43 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "avrcp_control_api"
#include <stdint.h>
#include "avrcp_control_service.h"
#include "bt_avrcp_control.h"
#include "bt_profile.h"
#include "service_manager.h"
#include "utils/log.h"
static avrcp_control_interface_t* get_profile_service(void)
{
return (avrcp_control_interface_t*)service_manager_get_profile(PROFILE_AVRCP_CT);
}
void* bt_avrcp_control_register_callbacks(bt_instance_t* ins, const avrcp_control_callbacks_t* callbacks)
{
avrcp_control_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool bt_avrcp_control_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
avrcp_control_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}

View File

@ -0,0 +1,59 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "avrcp_target_api"
#include <stdint.h>
#include "avrcp_target_service.h"
#include "bt_avrcp_target.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "service_manager.h"
#include "utils/log.h"
static avrcp_target_interface_t* get_profile_service(void)
{
return (avrcp_target_interface_t*)service_manager_get_profile(PROFILE_AVRCP_TG);
}
void* BTSYMBOLS(bt_avrcp_target_register_callbacks)(bt_instance_t* ins, const avrcp_target_callbacks_t* callbacks)
{
avrcp_target_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool BTSYMBOLS(bt_avrcp_target_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
avrcp_target_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t BTSYMBOLS(bt_avrcp_target_get_play_status_response)(bt_instance_t* ins, bt_address_t* addr, avrcp_play_status_t play_status,
uint32_t song_len, uint32_t song_pos)
{
avrcp_target_interface_t* profile = get_profile_service();
return profile->get_play_status_rsp(addr, play_status, song_len, song_pos);
}
bt_status_t BTSYMBOLS(bt_avrcp_target_play_status_notify)(bt_instance_t* ins, bt_address_t* addr, avrcp_play_status_t play_status)
{
avrcp_target_interface_t* profile = get_profile_service();
return profile->play_status_notify(addr, play_status);
}

193
framework/api/bt_device.c Normal file
View File

@ -0,0 +1,193 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include <stdlib.h>
#include "adapter_internel.h"
#include "bluetooth.h"
#include "bt_addr.h"
#include "bt_device.h"
#include "bt_internal.h"
#include "device.h"
bt_status_t BTSYMBOLS(bt_device_get_identity_address)(bt_instance_t* ins, bt_address_t* bd_addr, bt_address_t* id_addr)
{
return adapter_get_remote_identity_address(bd_addr, id_addr);
}
ble_addr_type_t BTSYMBOLS(bt_device_get_address_type)(bt_instance_t* ins, bt_address_t* addr)
{
return 0;
}
bt_device_type_t BTSYMBOLS(bt_device_get_device_type)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_get_remote_device_type(addr);
}
bool BTSYMBOLS(bt_device_get_name)(bt_instance_t* ins, bt_address_t* addr, char* name, uint32_t length)
{
return adapter_get_remote_name(addr, name);
}
uint32_t BTSYMBOLS(bt_device_get_device_class)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_get_remote_device_class(addr);
}
bt_status_t BTSYMBOLS(bt_device_get_uuids)(bt_instance_t* ins, bt_address_t* addr, bt_uuid_t** uuids, uint16_t* size, bt_allocator_t allocator)
{
return adapter_get_remote_uuids(addr, uuids, size, allocator);
}
uint16_t BTSYMBOLS(bt_device_get_appearance)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_get_remote_appearance(addr);
}
int8_t BTSYMBOLS(bt_device_get_rssi)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_get_remote_rssi(addr);
}
bool BTSYMBOLS(bt_device_get_alias)(bt_instance_t* ins, bt_address_t* addr, char* alias, uint32_t length)
{
return adapter_get_remote_alias(addr, alias);
}
bt_status_t BTSYMBOLS(bt_device_set_alias)(bt_instance_t* ins, bt_address_t* addr, const char* alias)
{
return adapter_set_remote_alias(addr, alias);
}
bool BTSYMBOLS(bt_device_is_connected)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
return adapter_is_remote_connected(addr, transport);
}
bool BTSYMBOLS(bt_device_is_encrypted)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
return adapter_is_remote_encrypted(addr, transport);
}
bool BTSYMBOLS(bt_device_is_bond_initiate_local)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
return adapter_is_bond_initiate_local(addr, transport);
}
bond_state_t BTSYMBOLS(bt_device_get_bond_state)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
return adapter_get_remote_bond_state(addr, transport);
}
bool BTSYMBOLS(bt_device_is_bonded)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
return adapter_is_remote_bonded(addr, transport);
}
bt_status_t BTSYMBOLS(bt_device_connect)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_connect(addr);
}
bt_status_t BTSYMBOLS(bt_device_disconnect)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_disconnect(addr);
}
bt_status_t BTSYMBOLS(bt_device_connect_le)(bt_instance_t* ins,
bt_address_t* addr,
ble_addr_type_t type,
ble_connect_params_t* param)
{
return adapter_le_connect(addr, type, param);
}
bt_status_t BTSYMBOLS(bt_device_disconnect_le)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_le_disconnect(addr);
}
bt_status_t BTSYMBOLS(bt_device_connect_request_reply)(bt_instance_t* ins, bt_address_t* addr, bool accept)
{
return adapter_connect_request_reply(addr, accept);
}
void BTSYMBOLS(bt_device_connect_all_profile)(bt_instance_t* ins, bt_address_t* addr)
{
}
void BTSYMBOLS(bt_device_disconnect_all_profile)(bt_instance_t* ins, bt_address_t* addr)
{
}
bt_status_t BTSYMBOLS(bt_device_set_le_phy)(bt_instance_t* ins, bt_address_t* addr,
ble_phy_type_t tx_phy,
ble_phy_type_t rx_phy)
{
return adapter_le_set_phy(addr, tx_phy, rx_phy);
}
bt_status_t BTSYMBOLS(bt_device_create_bond)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
return adapter_create_bond(addr, transport);
}
bt_status_t BTSYMBOLS(bt_device_remove_bond)(bt_instance_t* ins, bt_address_t* addr, uint8_t transport)
{
return adapter_remove_bond(addr, transport);
}
bt_status_t BTSYMBOLS(bt_device_cancel_bond)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_cancel_bond(addr);
}
bt_status_t BTSYMBOLS(bt_device_pair_request_reply)(bt_instance_t* ins, bt_address_t* addr, bool accept)
{
return adapter_pair_request_reply(addr, accept);
}
bt_status_t BTSYMBOLS(bt_device_set_pairing_confirmation)(bt_instance_t* ins, bt_address_t* addr, uint8_t transport, bool accept)
{
return adapter_set_pairing_confirmation(addr, transport, accept);
}
bt_status_t BTSYMBOLS(bt_device_set_pin_code)(bt_instance_t* ins, bt_address_t* addr, bool accept,
char* pincode, int len)
{
return adapter_set_pin_code(addr, accept, pincode, len);
}
bt_status_t BTSYMBOLS(bt_device_set_pass_key)(bt_instance_t* ins, bt_address_t* addr, uint8_t transport, bool accept, uint32_t passkey)
{
return adapter_set_pass_key(addr, transport, accept, passkey);
}
bt_status_t BTSYMBOLS(bt_device_set_le_legacy_tk)(bt_instance_t* ins, bt_address_t* addr, bt_128key_t tk_val)
{
return adapter_le_set_legacy_tk(addr, tk_val);
}
bt_status_t BTSYMBOLS(bt_device_set_le_sc_remote_oob_data)(bt_instance_t* ins, bt_address_t* addr, bt_128key_t c_val, bt_128key_t r_val)
{
return adapter_le_set_remote_oob_data(addr, c_val, r_val);
}
bt_status_t BTSYMBOLS(bt_device_get_le_sc_local_oob_data)(bt_instance_t* ins, bt_address_t* addr)
{
return adapter_le_get_local_oob_data(addr);
}

150
framework/api/bt_gattc.c Normal file
View File

@ -0,0 +1,150 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "gattc"
#include "bt_gattc.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "gattc_service.h"
#include "service_manager.h"
#include "utils/log.h"
#include <stdint.h>
static gattc_interface_t* get_profile_service(void)
{
return (gattc_interface_t*)service_manager_get_profile(PROFILE_GATTC);
}
bt_status_t BTSYMBOLS(bt_gattc_create_connect)(bt_instance_t* ins, gattc_handle_t* phandle, gattc_callbacks_t* callbacks)
{
gattc_interface_t* profile = get_profile_service();
return profile->create_connect(NULL, phandle, callbacks);
}
bt_status_t BTSYMBOLS(bt_gattc_delete_connect)(gattc_handle_t conn_handle)
{
gattc_interface_t* profile = get_profile_service();
return profile->delete_connect(conn_handle);
}
bt_status_t BTSYMBOLS(bt_gattc_connect)(gattc_handle_t conn_handle, bt_address_t* addr, ble_addr_type_t addr_type)
{
gattc_interface_t* profile = get_profile_service();
return profile->connect(conn_handle, addr, addr_type);
}
bt_status_t BTSYMBOLS(bt_gattc_disconnect)(gattc_handle_t conn_handle)
{
gattc_interface_t* profile = get_profile_service();
return profile->disconnect(conn_handle);
}
bt_status_t BTSYMBOLS(bt_gattc_discover_service)(gattc_handle_t conn_handle, bt_uuid_t* filter_uuid)
{
gattc_interface_t* profile = get_profile_service();
return profile->discover_service(conn_handle, filter_uuid);
}
bt_status_t BTSYMBOLS(bt_gattc_get_attribute_by_handle)(gattc_handle_t conn_handle, uint16_t attr_handle, gatt_attr_desc_t* attr_desc)
{
gattc_interface_t* profile = get_profile_service();
return profile->get_attribute_by_handle(conn_handle, attr_handle, attr_desc);
}
bt_status_t BTSYMBOLS(bt_gattc_get_attribute_by_uuid)(gattc_handle_t conn_handle, uint16_t start_handle, uint16_t end_handle, bt_uuid_t* attr_uuid, gatt_attr_desc_t* attr_desc)
{
gattc_interface_t* profile = get_profile_service();
return profile->get_attribute_by_uuid(conn_handle, start_handle, end_handle, attr_uuid, attr_desc);
}
bt_status_t BTSYMBOLS(bt_gattc_read)(gattc_handle_t conn_handle, uint16_t attr_handle)
{
gattc_interface_t* profile = get_profile_service();
return profile->read(conn_handle, attr_handle);
}
bt_status_t BTSYMBOLS(bt_gattc_write)(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
gattc_interface_t* profile = get_profile_service();
return profile->write(conn_handle, attr_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gattc_write_without_response)(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
gattc_interface_t* profile = get_profile_service();
return profile->write_without_response(conn_handle, attr_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gattc_subscribe)(gattc_handle_t conn_handle, uint16_t attr_handle, uint16_t ccc_value)
{
gattc_interface_t* profile = get_profile_service();
return profile->subscribe(conn_handle, attr_handle, ccc_value);
}
bt_status_t BTSYMBOLS(bt_gattc_unsubscribe)(gattc_handle_t conn_handle, uint16_t attr_handle)
{
gattc_interface_t* profile = get_profile_service();
return profile->unsubscribe(conn_handle, attr_handle);
}
bt_status_t BTSYMBOLS(bt_gattc_exchange_mtu)(gattc_handle_t conn_handle, uint32_t mtu)
{
gattc_interface_t* profile = get_profile_service();
return profile->exchange_mtu(conn_handle, mtu);
}
bt_status_t BTSYMBOLS(bt_gattc_update_connection_parameter)(gattc_handle_t conn_handle, uint32_t min_interval, uint32_t max_interval, uint32_t latency,
uint32_t timeout, uint32_t min_connection_event_length, uint32_t max_connection_event_length)
{
gattc_interface_t* profile = get_profile_service();
return profile->update_connection_parameter(conn_handle, min_interval, max_interval, latency,
timeout, min_connection_event_length, max_connection_event_length);
}
bt_status_t BTSYMBOLS(bt_gattc_read_phy)(gattc_handle_t conn_handle)
{
gattc_interface_t* profile = get_profile_service();
return profile->read_phy(conn_handle);
}
bt_status_t BTSYMBOLS(bt_gattc_update_phy)(gattc_handle_t conn_handle, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy)
{
gattc_interface_t* profile = get_profile_service();
return profile->update_phy(conn_handle, tx_phy, rx_phy);
}
bt_status_t BTSYMBOLS(bt_gattc_read_rssi)(gattc_handle_t conn_handle)
{
gattc_interface_t* profile = get_profile_service();
return profile->read_rssi(conn_handle);
}

120
framework/api/bt_gatts.c Normal file
View File

@ -0,0 +1,120 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "gatts"
#include "bt_gatts.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "gatts_service.h"
#include "service_manager.h"
#include "utils/log.h"
#include <stdint.h>
static gatts_interface_t* get_profile_service(void)
{
return (gatts_interface_t*)service_manager_get_profile(PROFILE_GATTS);
}
bt_status_t BTSYMBOLS(bt_gatts_register_service)(bt_instance_t* ins, gatts_handle_t* phandle, gatts_callbacks_t* callbacks)
{
gatts_interface_t* profile = get_profile_service();
return profile->register_service(NULL, phandle, callbacks);
}
bt_status_t BTSYMBOLS(bt_gatts_unregister_service)(gatts_handle_t srv_handle)
{
gatts_interface_t* profile = get_profile_service();
return profile->unregister_service(srv_handle);
}
bt_status_t BTSYMBOLS(bt_gatts_connect)(gatts_handle_t srv_handle, bt_address_t* addr, ble_addr_type_t addr_type)
{
gatts_interface_t* profile = get_profile_service();
return profile->connect(srv_handle, addr, addr_type);
}
bt_status_t BTSYMBOLS(bt_gatts_disconnect)(gatts_handle_t srv_handle, bt_address_t* addr)
{
gatts_interface_t* profile = get_profile_service();
return profile->disconnect(srv_handle, addr);
}
bt_status_t BTSYMBOLS(bt_gatts_add_attr_table)(gatts_handle_t srv_handle, gatt_srv_db_t* srv_db)
{
gatts_interface_t* profile = get_profile_service();
return profile->add_attr_table(srv_handle, srv_db);
}
bt_status_t BTSYMBOLS(bt_gatts_remove_attr_table)(gatts_handle_t srv_handle, uint16_t attr_handle)
{
gatts_interface_t* profile = get_profile_service();
return profile->remove_attr_table(srv_handle, attr_handle);
}
bt_status_t BTSYMBOLS(bt_gatts_set_attr_value)(gatts_handle_t srv_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
gatts_interface_t* profile = get_profile_service();
return profile->set_attr_value(srv_handle, attr_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gatts_get_attr_value)(gatts_handle_t srv_handle, uint16_t attr_handle, uint8_t* value, uint16_t* length)
{
gatts_interface_t* profile = get_profile_service();
return profile->get_attr_value(srv_handle, attr_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gatts_response)(gatts_handle_t srv_handle, bt_address_t* addr, uint32_t req_handle, uint8_t* value, uint16_t length)
{
gatts_interface_t* profile = get_profile_service();
return profile->response(srv_handle, addr, req_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gatts_notify)(gatts_handle_t srv_handle, bt_address_t* addr, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
gatts_interface_t* profile = get_profile_service();
return profile->notify(srv_handle, addr, attr_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gatts_indicate)(gatts_handle_t srv_handle, bt_address_t* addr, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
gatts_interface_t* profile = get_profile_service();
return profile->indicate(srv_handle, addr, attr_handle, value, length);
}
bt_status_t BTSYMBOLS(bt_gatts_read_phy)(gatts_handle_t srv_handle, bt_address_t* addr)
{
gatts_interface_t* profile = get_profile_service();
return profile->read_phy(srv_handle, addr);
}
bt_status_t BTSYMBOLS(bt_gatts_update_phy)(gatts_handle_t srv_handle, bt_address_t* addr, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy)
{
gatts_interface_t* profile = get_profile_service();
return profile->update_phy(srv_handle, addr, tx_phy, rx_phy);
}

153
framework/api/bt_hfp_ag.c Normal file
View File

@ -0,0 +1,153 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "hfp_ag_api"
#include "bt_hfp_ag.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "hfp_ag_service.h"
#include "service_manager.h"
#include "utils/log.h"
#include <stdint.h>
static hfp_ag_interface_t* get_profile_service(void)
{
return (hfp_ag_interface_t*)service_manager_get_profile(PROFILE_HFP_AG);
}
void* BTSYMBOLS(bt_hfp_ag_register_callbacks)(bt_instance_t* ins, const hfp_ag_callbacks_t* callbacks)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool BTSYMBOLS(bt_hfp_ag_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bool BTSYMBOLS(bt_hfp_ag_is_connected)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->is_connected(addr);
}
bool BTSYMBOLS(bt_hfp_ag_is_audio_connected)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->is_audio_connected(addr);
}
profile_connection_state_t BTSYMBOLS(bt_hfp_ag_get_connection_state)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->get_connection_state(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_connect)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->connect(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_disconnect)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->disconnect(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_connect_audio)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->connect_audio(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_disconnect_audio)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->disconnect_audio(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_start_virtual_call)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->start_virtual_call(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_stop_virtual_call)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->stop_virtual_call(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_start_voice_recognition)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->start_voice_recognition(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_stop_voice_recognition)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->stop_voice_recognition(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_phone_state_change)(bt_instance_t* ins, bt_address_t* addr,
uint8_t num_active, uint8_t num_held,
hfp_ag_call_state_t call_state, hfp_call_addrtype_t type,
const char* number, const char* name)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->phone_state_change(addr, num_active, num_held, call_state, type, number, name);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_notify_device_status)(bt_instance_t* ins, bt_address_t* addr,
hfp_network_state_t network, hfp_roaming_state_t roam,
uint8_t signal, uint8_t battery)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->device_status_changed(addr, network, roam, signal, battery);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_volume_control)(bt_instance_t* ins, bt_address_t* addr, hfp_volume_type_t type, uint8_t volume)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->volume_control(addr, type, volume);
}
bt_status_t BTSYMBOLS(bt_hfp_ag_send_at_command)(bt_instance_t* ins, bt_address_t* addr, const char* at_command)
{
hfp_ag_interface_t* profile = get_profile_service();
return profile->send_at_command(addr, at_command);
}

200
framework/api/bt_hfp_hf.c Normal file
View File

@ -0,0 +1,200 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "hfp_hf_api"
#include "bt_hfp_hf.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "hfp_hf_service.h"
#include "service_manager.h"
#include "utils/log.h"
#include <stdint.h>
static hfp_hf_interface_t* get_profile_service(void)
{
return (hfp_hf_interface_t*)service_manager_get_profile(PROFILE_HFP_HF);
}
void* BTSYMBOLS(bt_hfp_hf_register_callbacks)(bt_instance_t* ins, const hfp_hf_callbacks_t* callbacks)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, (hfp_hf_callbacks_t*)callbacks);
}
bool BTSYMBOLS(bt_hfp_hf_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bool BTSYMBOLS(bt_hfp_hf_is_connected)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->is_connected(addr);
}
bool BTSYMBOLS(bt_hfp_hf_is_audio_connected)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->is_audio_connected(addr);
}
profile_connection_state_t BTSYMBOLS(bt_hfp_hf_get_connection_state)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->get_connection_state(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_connect)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->connect(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_disconnect)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->disconnect(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_set_connection_policy)(bt_instance_t* ins, bt_address_t* addr, connection_policy_t policy)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->set_connection_policy(addr, policy);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_connect_audio)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->connect_audio(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_disconnect_audio)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->disconnect_audio(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_start_voice_recognition)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->start_voice_recognition(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_stop_voice_recognition)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->stop_voice_recognition(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_dial)(bt_instance_t* ins, bt_address_t* addr, const char* number)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->dial(addr, number);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_dial_memory)(bt_instance_t* ins, bt_address_t* addr, uint32_t memory)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->dial_memory(addr, memory);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_redial)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->redial(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_accept_call)(bt_instance_t* ins, bt_address_t* addr, hfp_call_accept_t flag)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->accept_call(addr, flag);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_reject_call)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->reject_call(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_hold_call)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->hold_call(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_terminate_call)(bt_instance_t* ins, bt_address_t* addr)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->terminate_call(addr);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_control_call)(bt_instance_t* ins, bt_address_t* addr, hfp_call_control_t chld, uint8_t index)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->control_call(addr, chld, index);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_query_current_calls)(bt_instance_t* ins, bt_address_t* addr, hfp_current_call_t** calls, int* num, bt_allocator_t allocator)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->query_current_calls(addr, calls, num, allocator);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_send_at_cmd)(bt_instance_t* ins, bt_address_t* addr, const char* cmd)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->send_at_cmd(addr, cmd);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_update_battery_level)(bt_instance_t* ins, bt_address_t* addr, uint8_t level)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->update_battery_level(addr, level);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_volume_control)(bt_instance_t* ins, bt_address_t* addr, hfp_volume_type_t type, uint8_t volume)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->volume_control(addr, type, volume);
}
bt_status_t BTSYMBOLS(bt_hfp_hf_send_dtmf)(bt_instance_t* ins, bt_address_t* addr, char dtmf)
{
hfp_hf_interface_t* profile = get_profile_service();
return profile->send_dtmf(addr, dtmf);
}

View File

@ -0,0 +1,100 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "hid_device_api"
#include <stdint.h>
#include "bt_hid_device.h"
#include "bt_internal.h"
#include "bt_profile.h"
#include "hid_device_service.h"
#include "service_manager.h"
#include "utils/log.h"
static hid_device_interface_t* get_profile_service(void)
{
return (hid_device_interface_t*)service_manager_get_profile(PROFILE_HID_DEV);
}
void* BTSYMBOLS(bt_hid_device_register_callbacks)(bt_instance_t* ins, const hid_device_callbacks_t* callbacks)
{
hid_device_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool BTSYMBOLS(bt_hid_device_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
hid_device_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t BTSYMBOLS(bt_hid_device_register_app)(bt_instance_t* ins, hid_device_sdp_settings_t* sdp, bool le_hid)
{
hid_device_interface_t* profile = get_profile_service();
return profile->register_app(sdp, le_hid);
}
bt_status_t BTSYMBOLS(bt_hid_device_unregister_app)(bt_instance_t* ins)
{
hid_device_interface_t* profile = get_profile_service();
return profile->unregister_app();
}
bt_status_t BTSYMBOLS(bt_hid_device_connect)(bt_instance_t* ins, bt_address_t* addr)
{
hid_device_interface_t* profile = get_profile_service();
return profile->connect(addr);
}
bt_status_t BTSYMBOLS(bt_hid_device_disconnect)(bt_instance_t* ins, bt_address_t* addr)
{
hid_device_interface_t* profile = get_profile_service();
return profile->disconnect(addr);
}
bt_status_t BTSYMBOLS(bt_hid_device_send_report)(bt_instance_t* ins, bt_address_t* addr, uint8_t rpt_id, uint8_t* rpt_data, int rpt_size)
{
hid_device_interface_t* profile = get_profile_service();
return profile->send_report(addr, rpt_id, rpt_data, rpt_size);
}
bt_status_t BTSYMBOLS(bt_hid_device_response_report)(bt_instance_t* ins, bt_address_t* addr, uint8_t rpt_type, uint8_t* rpt_data, int rpt_size)
{
hid_device_interface_t* profile = get_profile_service();
return profile->response_report(addr, rpt_type, rpt_data, rpt_size);
}
bt_status_t BTSYMBOLS(bt_hid_device_report_error)(bt_instance_t* ins, bt_address_t* addr, hid_status_error_t error)
{
hid_device_interface_t* profile = get_profile_service();
return profile->report_error(addr, error);
}
bt_status_t BTSYMBOLS(bt_hid_device_virtual_unplug)(bt_instance_t* ins, bt_address_t* addr)
{
hid_device_interface_t* profile = get_profile_service();
return profile->virtual_unplug(addr);
}

48
framework/api/bt_l2cap.c Normal file
View File

@ -0,0 +1,48 @@
/****************************************************************************
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "L2CAP_api"
#include <stdint.h>
#include "bt_internal.h"
#include "bt_l2cap.h"
#include "l2cap_service.h"
#include "utils/log.h"
void* BTSYMBOLS(bt_l2cap_register_callbacks)(bt_instance_t* ins, const l2cap_callbacks_t* callbacks)
{
return l2cap_register_callbacks(NULL, callbacks);
}
bool BTSYMBOLS(bt_l2cap_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
return l2cap_unregister_callbacks(NULL, cookie);
}
bt_status_t BTSYMBOLS(bt_l2cap_listen)(bt_instance_t* ins, l2cap_config_option_t* option)
{
return l2cap_listen_channel(option);
}
bt_status_t BTSYMBOLS(bt_l2cap_connect)(bt_instance_t* ins, bt_address_t* addr, l2cap_config_option_t* option)
{
return l2cap_connect_channel(addr, option);
}
bt_status_t BTSYMBOLS(bt_l2cap_disconnect)(bt_instance_t* ins, uint16_t cid)
{
return l2cap_disconnect_channel(cid);
}

View File

@ -0,0 +1,52 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "adv"
#include <stdlib.h>
#include "advertising.h"
#include "bluetooth.h"
#include "bt_internal.h"
#include "bt_le_advertiser.h"
#include "bt_list.h"
#include "utils/log.h"
bt_advertiser_t* BTSYMBOLS(bt_le_start_advertising)(bt_instance_t* ins,
ble_adv_params_t* params,
uint8_t* adv_data,
uint16_t adv_len,
uint8_t* scan_rsp_data,
uint16_t scan_rsp_len,
advertiser_callback_t* cbs)
{
return start_advertising(NULL, params, adv_data, adv_len,
scan_rsp_data, scan_rsp_len, cbs);
}
void BTSYMBOLS(bt_le_stop_advertising)(bt_instance_t* ins, bt_advertiser_t* adver)
{
stop_advertising(adver);
}
void BTSYMBOLS(bt_le_stop_advertising_id)(bt_instance_t* ins, uint8_t adv_id)
{
stop_advertising_id(adv_id);
}
bool BTSYMBOLS(bt_le_advertising_is_supported)(bt_instance_t* ins)
{
return advertising_is_supported();
}

View File

@ -0,0 +1,55 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "adv"
#include <stdlib.h>
#include "bluetooth.h"
#include "bt_internal.h"
#include "bt_le_scan.h"
#include "bt_list.h"
#include "scan_manager.h"
#include "utils/log.h"
bt_scanner_t* BTSYMBOLS(bt_le_start_scan)(bt_instance_t* ins, const scanner_callbacks_t* cbs)
{
return scanner_start_scan(NULL, cbs);
}
bt_scanner_t* BTSYMBOLS(bt_le_start_scan_settings)(bt_instance_t* ins,
ble_scan_settings_t* settings,
const scanner_callbacks_t* cbs)
{
return scanner_start_scan_settings(NULL, settings, cbs);
}
bt_scanner_t* BTSYMBOLS(bt_le_start_scan_with_filters)(bt_instance_t* ins,
ble_scan_settings_t* settings,
ble_scan_filter_t* filter,
const scanner_callbacks_t* cbs)
{
return scanner_start_scan_with_filters(NULL, settings, filter, cbs);
}
void BTSYMBOLS(bt_le_stop_scan)(bt_instance_t* ins, bt_scanner_t* scanner)
{
scanner_stop_scan(scanner);
}
bool BTSYMBOLS(bt_le_scan_is_supported)(bt_instance_t* ins)
{
return scan_is_supported();
}

160
framework/api/bt_lea_ccp.c Normal file
View File

@ -0,0 +1,160 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include "bt_lea_ccp.h"
#include "bt_profile.h"
#include "lea_ccp_service.h"
#include "service_manager.h"
#include "utils/log.h"
#include <stdint.h>
static lea_ccp_interface_t* get_profile_service(void)
{
return (lea_ccp_interface_t*)service_manager_get_profile(PROFILE_LEAUDIO_CCP);
}
void* bt_lea_ccp_register_callbacks(bt_instance_t* ins, const lea_ccp_callbacks_t* callbacks)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, (lea_ccp_callbacks_t*)callbacks);
}
bool bt_lea_ccp_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t bt_lea_ccp_read_bearer_provider_name(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_bearer_provider_name(addr);
}
bt_status_t bt_lea_ccp_read_bearer_uci(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_bearer_uci(addr);
}
bt_status_t bt_lea_ccp_read_bearer_technology(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_bearer_technology(addr);
}
bt_status_t bt_lea_ccp_read_bearer_uri_schemes_supported_list(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_bearer_uri_schemes_supported_list(addr);
}
bt_status_t bt_lea_ccp_read_bearer_signal_strength(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_bearer_signal_strength(addr);
}
bt_status_t bt_lea_ccp_read_bearer_signal_strength_report_interval(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_bearer_signal_strength_report_interval(addr);
}
bt_status_t bt_lea_ccp_read_content_control_id(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_content_control_id(addr);
}
bt_status_t bt_lea_ccp_read_status_flags(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_status_flags(addr);
}
bt_status_t bt_lea_ccp_read_call_control_optional_opcodes(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_call_control_optional_opcodes(addr);
}
bt_status_t bt_lea_ccp_read_incoming_call(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_incoming_call(addr);
}
bt_status_t bt_lea_ccp_read_incoming_call_target_bearer_uri(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_incoming_call_target_bearer_uri(addr);
}
bt_status_t bt_lea_ccp_read_call_state(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_call_state(addr);
}
bt_status_t bt_lea_ccp_read_bearer_list_current_calls(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_bearer_list_current_calls(addr);
}
bt_status_t bt_lea_ccp_read_call_friendly_name(bt_instance_t* ins, bt_address_t* addr)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->read_call_friendly_name(addr);
}
bt_status_t bt_lea_ccp_call_control_by_index(bt_instance_t* ins, bt_address_t* addr, uint8_t opcode)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->call_control_by_index(addr, opcode);
}
bt_status_t bt_lea_ccp_originate_call(bt_instance_t* ins, bt_address_t* addr, uint8_t* uri)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->originate_call(addr, uri);
}
bt_status_t bt_lea_ccp_join_calls(bt_instance_t* ins, bt_address_t* addr, uint8_t number,
uint8_t* call_indexes)
{
lea_ccp_interface_t* profile = get_profile_service();
return profile->join_calls(addr, number, call_indexes);
}

View File

@ -0,0 +1,141 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include "bt_lea_server.h"
#include "bt_profile.h"
#include "lea_client_service.h"
#include "service_manager.h"
static lea_client_interface_t* get_profile_service(void)
{
return (lea_client_interface_t*)service_manager_get_profile(
PROFILE_LEAUDIO_CLIENT);
}
void* bt_lea_client_register_callbacks(bt_instance_t* ins,
const lea_client_callbacks_t* callbacks)
{
lea_client_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool bt_lea_client_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
lea_client_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t bt_lea_client_connect(bt_instance_t* ins, bt_address_t* addr)
{
lea_client_interface_t* profile = get_profile_service();
return profile->connect(addr);
}
bt_status_t bt_lea_client_connect_audio(bt_instance_t* ins, bt_address_t* addr, uint8_t context)
{
lea_client_interface_t* profile = get_profile_service();
return profile->connect_audio(addr, context);
}
bt_status_t bt_lea_client_disconnect(bt_instance_t* ins, bt_address_t* addr)
{
lea_client_interface_t* profile = get_profile_service();
return profile->disconnect(addr);
}
bt_status_t bt_lea_client_disconnect_audio(bt_instance_t* ins, bt_address_t* addr)
{
lea_client_interface_t* profile = get_profile_service();
return profile->disconnect_audio(addr);
}
profile_connection_state_t bt_lea_client_get_connection_state(bt_instance_t* ins, bt_address_t* addr)
{
lea_client_interface_t* profile = get_profile_service();
return profile->get_connection_state(addr);
}
bt_status_t bt_lea_client_get_group_id(bt_instance_t* ins, bt_address_t* addr, uint32_t* group_id)
{
lea_client_interface_t* profile = get_profile_service();
return profile->get_group_id(addr, group_id);
}
bt_status_t bt_lea_client_discovery_member_start(bt_instance_t* ins, uint32_t group_id)
{
lea_client_interface_t* profile = get_profile_service();
return profile->discovery_member_start(group_id);
}
bt_status_t bt_lea_client_discovery_member_stop(bt_instance_t* ins, uint32_t group_id)
{
lea_client_interface_t* profile = get_profile_service();
return profile->discovery_member_stop(group_id);
}
bt_status_t bt_lea_client_group_add_member(bt_instance_t* ins, uint32_t group_id, bt_address_t* addr)
{
lea_client_interface_t* profile = get_profile_service();
return profile->group_add_member(group_id, addr);
}
bt_status_t bt_lea_client_group_remove_member(bt_instance_t* ins, uint32_t group_id, bt_address_t* addr)
{
lea_client_interface_t* profile = get_profile_service();
return profile->group_remove_member(group_id, addr);
}
bt_status_t bt_lea_client_group_connect_audio(bt_instance_t* ins, uint32_t group_id, uint8_t context)
{
lea_client_interface_t* profile = get_profile_service();
return profile->group_connect_audio(group_id, context);
}
bt_status_t bt_lea_client_group_disconnect_audio(bt_instance_t* ins, uint32_t group_id)
{
lea_client_interface_t* profile = get_profile_service();
return profile->group_disconnect_audio(group_id);
}
bt_status_t bt_lea_client_group_lock(bt_instance_t* ins, uint32_t group_id)
{
lea_client_interface_t* profile = get_profile_service();
return profile->group_lock(group_id);
}
bt_status_t bt_lea_client_group_unlock(bt_instance_t* ins, uint32_t group_id)
{
lea_client_interface_t* profile = get_profile_service();
return profile->group_unlock(group_id);
}

View File

@ -0,0 +1,61 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include "bt_lea_mcp.h"
#include "bt_profile.h"
#include "lea_mcp_service.h"
#include "service_manager.h"
#include "utils/log.h"
#include <stdint.h>
static lea_mcp_interface_t* get_profile_service(void)
{
return (lea_mcp_interface_t*)service_manager_get_profile(PROFILE_LEAUDIO_MCP);
}
void* bt_lea_mcp_register_callbacks(bt_instance_t* ins, const lea_mcp_callbacks_t* callbacks)
{
lea_mcp_interface_t* profile = get_profile_service();
return profile->set_callbacks(NULL, (lea_mcp_callbacks_t*)callbacks);
}
bool bt_lea_mcp_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
lea_mcp_interface_t* profile = get_profile_service();
return profile->reset_callbacks(NULL, cookie);
}
bt_status_t bt_lea_mcp_read_info(bt_instance_t* ins, bt_address_t* addr, uint8_t opcode)
{
lea_mcp_interface_t* profile = get_profile_service();
return profile->read_remote_mcs_info(addr, opcode);
}
bt_status_t bt_lea_mcp_media_control_request(bt_instance_t* ins, bt_address_t* addr, uint32_t opcode, int32_t n)
{
lea_mcp_interface_t* profile = get_profile_service();
return profile->media_control_request(addr, opcode, n);
}
bt_status_t bt_lea_mcp_search_control_request(bt_instance_t* ins, bt_address_t* addr, uint8_t number, uint32_t type, uint8_t* parameter)
{
lea_mcp_interface_t* profile = get_profile_service();
return profile->search_control_request(addr, number, type, parameter);
}

145
framework/api/bt_lea_mcs.c Normal file
View File

@ -0,0 +1,145 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include "bt_lea_mcs.h"
#include "bt_profile.h"
#include "lea_mcs_service.h"
#include "service_manager.h"
#include "utils/log.h"
#include <stdint.h>
static lea_mcs_interface_t* get_profile_service(void)
{
return (lea_mcs_interface_t*)service_manager_get_profile(PROFILE_LEAUDIO_MCS);
}
void* bt_lea_mcs_register_callbacks(bt_instance_t* ins, const lea_mcs_callbacks_t* callbacks)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->set_callbacks(NULL, (lea_mcs_callbacks_t*)callbacks);
}
bool bt_lea_mcs_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->reset_callbacks(NULL, cookie);
}
bt_status_t bt_lea_mcs_service_add(bt_instance_t* ins)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->mcs_add();
}
bt_status_t bt_lea_mcs_service_remove(bt_instance_t* ins)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->mcs_remove();
}
bt_status_t bt_lea_mcs_playing_order_changed(bt_instance_t* ins, uint8_t order)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->playing_order_changed(order);
}
bt_status_t bt_lea_mcs_media_state_changed(bt_instance_t* ins, uint8_t state)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->media_state_changed(state);
}
bt_status_t bt_lea_mcs_playback_speed_changed(bt_instance_t* ins, int8_t speed)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->playback_speed_changed(speed);
}
bt_status_t bt_lea_mcs_seeking_speed_changed(bt_instance_t* ins, int8_t speed)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->seeking_speed_changed(speed);
}
bt_status_t bt_lea_mcs_track_title_changed(void* handl, uint8_t* title)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->track_title_changed(title);
}
bt_status_t bt_lea_mcs_track_duration_changed(bt_instance_t* ins, int32_t duration)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->track_duration_changed(duration);
}
bt_status_t bt_lea_mcs_track_position_changed(bt_instance_t* ins, int32_t position)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->track_position_changed(position);
}
bt_status_t bt_lea_mcs_current_track_change(bt_instance_t* ins, lea_object_id track_id)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->current_track_changed(track_id);
}
bt_status_t bt_lea_mcs_next_track_changed(bt_instance_t* ins, lea_object_id track_id)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->next_track_changed(track_id);
}
bt_status_t bt_lea_mcs_current_group_changed(bt_instance_t* ins, lea_object_id group_id)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->current_group_changed(group_id);
}
bt_status_t bt_lea_mcs_parent_group_changed(bt_instance_t* ins, lea_object_id group_id)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->parent_group_changed(group_id);
}
bt_status_t bt_lea_mcs_set_media_player_info(bt_instance_t* ins)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->set_media_player_info();
}
bt_status_t bt_lea_mcs_media_control_point_response(bt_instance_t* ins, lea_adpt_mcs_media_control_result_t result)
{
lea_mcs_interface_t* profile = get_profile_service();
return profile->media_control_response(result);
}

View File

@ -0,0 +1,81 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include "bt_lea_server.h"
#include "bt_profile.h"
#include "lea_server_service.h"
#include "service_manager.h"
static lea_server_interface_t* get_profile_service(void)
{
return (lea_server_interface_t*)service_manager_get_profile(
PROFILE_LEAUDIO_SERVER);
}
void* bt_lea_server_register_callbacks(bt_instance_t* ins,
const lea_server_callbacks_t* callbacks)
{
lea_server_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool bt_lea_server_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
lea_server_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t bt_lea_server_start_announce(bt_instance_t* ins, uint8_t adv_id,
uint8_t announce_type, uint8_t* adv_data, uint16_t adv_size,
uint8_t* md_data, uint16_t md_size)
{
lea_server_interface_t* profile = get_profile_service();
return profile->start_announce(adv_id, announce_type, adv_data,
adv_size, md_data, md_size);
}
bt_status_t bt_lea_server_stop_announce(bt_instance_t* ins, uint8_t adv_id)
{
lea_server_interface_t* profile = get_profile_service();
return profile->stop_announce(adv_id);
}
bt_status_t bt_lea_server_disconnect(bt_instance_t* ins, bt_address_t* addr)
{
lea_server_interface_t* profile = get_profile_service();
return profile->disconnect(addr);
}
bt_status_t bt_lea_server_disconnect_audio(bt_instance_t* ins, bt_address_t* addr)
{
lea_server_interface_t* profile = get_profile_service();
return profile->disconnect_audio(addr);
}
profile_connection_state_t bt_lea_server_get_connection_state(bt_instance_t* ins, bt_address_t* addr)
{
lea_server_interface_t* profile = get_profile_service();
return profile->get_connection_state(addr);
}

145
framework/api/bt_lea_tbs.c Normal file
View File

@ -0,0 +1,145 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include "bt_lea_tbs.h"
#include "bt_profile.h"
#include "lea_tbs_service.h"
#include "service_manager.h"
#include "utils/log.h"
#include <stdint.h>
static lea_tbs_interface_t* get_profile_service(void)
{
return (lea_tbs_interface_t*)service_manager_get_profile(PROFILE_LEAUDIO_TBS);
}
void* bt_lea_tbs_register_callbacks(bt_instance_t* ins, const lea_tbs_callbacks_t* callbacks)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, (lea_tbs_callbacks_t*)callbacks);
}
bool bt_lea_tbs_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t bt_lea_tbs_service_add(bt_instance_t* ins)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->tbs_add();
}
bt_status_t bt_lea_tbs_service_remove(bt_instance_t* ins)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->tbs_remove();
}
bt_status_t bt_lea_tbs_set_telephone_bearer_info(bt_instance_t* ins,
lea_tbs_telephone_bearer_t* bearer)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->set_telephone_bearer(bearer);
}
bt_status_t bt_lea_tbs_add_call(bt_instance_t* ins, lea_tbs_calls_t* call_s)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->add_call(call_s);
}
bt_status_t bt_lea_tbs_remove_call(bt_instance_t* ins, uint8_t call_index)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->remove_call(call_index);
}
bt_status_t bt_lea_tbs_provider_name_changed(bt_instance_t* ins, uint8_t* name)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->provider_name_changed(name);
}
bt_status_t bt_lea_tbs_bearer_technology_changed(bt_instance_t* ins,
lea_adpt_bearer_technology_t technology)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->bearer_technology_changed(technology);
}
bt_status_t bt_lea_tbs_uri_schemes_supported_list_changed(bt_instance_t* ins,
uint8_t* uri_schemes)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->uri_schemes_supported_list_changed(uri_schemes);
}
bt_status_t bt_lea_tbs_rssi_value_changed(bt_instance_t* ins, uint8_t strength)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->rssi_value_changed(strength);
}
bt_status_t bt_lea_tbs_rssi_interval_changed(bt_instance_t* ins,
uint8_t interval)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->rssi_interval_changed(interval);
}
bt_status_t bt_lea_tbs_status_flags_changed(bt_instance_t* ins, uint16_t status_flags)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->status_flags_changed(status_flags);
}
bt_status_t bt_lea_tbs_call_state_changed(bt_instance_t* ins, uint8_t number,
lea_tbs_call_state_t* state_s)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->call_state_changed(number, state_s);
}
bt_status_t bt_lea_tbs_notify_termination_reason(bt_instance_t* ins, uint8_t call_index,
lea_adpt_termination_reason_t reason)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->notify_termination_reason(call_index, reason);
}
bt_status_t bt_lea_tbs_call_control_response(bt_instance_t* ins, uint8_t call_index,
lea_adpt_call_control_result_t result)
{
lea_tbs_interface_t* profile = get_profile_service();
return profile->call_control_response(call_index, result);
}

View File

@ -0,0 +1,89 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include "bt_lea_vmicp.h"
#include "bt_profile.h"
#include "lea_vmicp_service.h"
#include "service_manager.h"
#include "utils/log.h"
#include <stdint.h>
static lea_vmicp_interface_t* get_profile_service(void)
{
return (lea_vmicp_interface_t*)service_manager_get_profile(PROFILE_LEAUDIO_VMICP);
}
void* bt_lea_vmicp_register_callbacks(bt_instance_t* ins, const lea_vmicp_callbacks_t* callbacks)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, (lea_vmicp_callbacks_t*)callbacks);
}
bool bt_lea_vmicp_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t bt_lea_vmicp_get_volume_state(bt_instance_t* ins, bt_address_t* addr)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->vol_get(addr);
}
bt_status_t bt_lea_vmicp_get_volume_flags(bt_instance_t* ins, bt_address_t* addr)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->flags_get(addr);
}
bt_status_t bt_lea_vmicp_change_volume(bt_instance_t* ins, bt_address_t* addr, int dir)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->vol_change(addr, dir);
}
bt_status_t bt_lea_vmicp_change_unmute_volume(bt_instance_t* ins, bt_address_t* addr, int dir)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->vol_unmute_change(addr, dir);
}
bt_status_t bt_lea_vmicp_set_volume(bt_instance_t* ins, bt_address_t* addr, int vol)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->vol_set(addr, vol);
}
bt_status_t bt_lea_vmicp_set_volume_mute(bt_instance_t* ins, bt_address_t* addr, int mute)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->mute_state_set(addr, mute);
}
bt_status_t bt_lea_vmicp_get_mic_state(bt_instance_t* ins, bt_address_t* addr)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->mic_mute_get(addr);
}
bt_status_t bt_lea_vmicp_set_mic_mute(bt_instance_t* ins, bt_address_t* addr, int mute)
{
lea_vmicp_interface_t* profile = get_profile_service();
return profile->mic_mute_set(addr, mute);
}

View File

@ -0,0 +1,65 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include "bt_lea_vmics.h"
#include "bt_profile.h"
#include "lea_vmics_service.h"
#include "service_manager.h"
static lea_vmics_interface_t* get_profile_service(void)
{
return (lea_vmics_interface_t*)service_manager_get_profile(PROFILE_LEAUDIO_VMICS);
}
void* bt_lea_vmics_register_callbacks(bt_instance_t* ins, const lea_vmics_callbacks_t* callbacks)
{
lea_vmics_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, (lea_vmics_callbacks_t*)callbacks);
}
bool bt_lea_vmics_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
lea_vmics_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t bt_lea_vcs_volume_set(bt_instance_t* ins, int vol)
{
lea_vmics_interface_t* profile = get_profile_service();
return profile->vcs_volume_notify(ins, vol);
}
bt_status_t bt_lea_vcs_mute_set(bt_instance_t* ins, int mute)
{
lea_vmics_interface_t* profile = get_profile_service();
return profile->vcs_mute_notify(ins, mute);
}
bt_status_t bt_lea_vcs_volume_flags_set(bt_instance_t* ins, int flags)
{
lea_vmics_interface_t* profile = get_profile_service();
return profile->vcs_volume_flags_notify(ins, flags);
}
bt_status_t bt_lea_mics_mute_set(bt_instance_t* ins, int mute)
{
lea_vmics_interface_t* profile = get_profile_service();
return profile->mics_mute_notify(ins, mute);
}

58
framework/api/bt_pan.c Normal file
View File

@ -0,0 +1,58 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "pan_api"
#include <stdint.h>
#include "bt_internal.h"
#include "bt_pan.h"
#include "bt_profile.h"
#include "pan_service.h"
#include "service_manager.h"
#include "utils/log.h"
static pan_interface_t* get_profile_service(void)
{
return (pan_interface_t*)service_manager_get_profile(PROFILE_PANU);
}
void* BTSYMBOLS(bt_pan_register_callbacks)(bt_instance_t* ins, const pan_callbacks_t* callbacks)
{
pan_interface_t* profile = get_profile_service();
return profile->register_callbacks(NULL, callbacks);
}
bool BTSYMBOLS(bt_pan_unregister_callbacks)(bt_instance_t* ins, void* cookie)
{
pan_interface_t* profile = get_profile_service();
return profile->unregister_callbacks(NULL, cookie);
}
bt_status_t BTSYMBOLS(bt_pan_connect)(bt_instance_t* ins, bt_address_t* addr, uint8_t dst_role, uint8_t src_role)
{
pan_interface_t* profile = get_profile_service();
return profile->connect(addr, dst_role, src_role);
}
bt_status_t BTSYMBOLS(bt_pan_disconnect)(bt_instance_t* ins, bt_address_t* addr)
{
pan_interface_t* profile = get_profile_service();
return profile->disconnect(addr);
}

79
framework/api/bt_spp.c Normal file
View File

@ -0,0 +1,79 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "spp_api"
#include <stdint.h>
#include "bt_internal.h"
#include "bt_profile.h"
#include "bt_spp.h"
#include "service_manager.h"
#include "spp_service.h"
#include "utils/log.h"
static spp_interface_t* get_profile_service(void)
{
return (spp_interface_t*)service_manager_get_profile(PROFILE_SPP);
}
void* BTSYMBOLS(bt_spp_register_app)(bt_instance_t* ins, const spp_callbacks_t* callbacks)
{
spp_interface_t* profile = get_profile_service();
return profile->register_app(NULL, NULL, SPP_PORT_TYPE_TTY, callbacks);
}
void* BTSYMBOLS(bt_spp_register_app_ext)(bt_instance_t* ins, const char* name, int port_type, const spp_callbacks_t* callbacks)
{
spp_interface_t* profile = get_profile_service();
return profile->register_app(NULL, name, port_type, callbacks);
}
bt_status_t BTSYMBOLS(bt_spp_unregister_app)(bt_instance_t* ins, void* handle)
{
spp_interface_t* profile = get_profile_service();
return profile->unregister_app(NULL, handle);
}
bt_status_t BTSYMBOLS(bt_spp_server_start)(bt_instance_t* ins, void* handle, uint16_t scn, bt_uuid_t* uuid, uint8_t max_connection)
{
spp_interface_t* profile = get_profile_service();
return profile->server_start(handle, scn, uuid, max_connection);
}
bt_status_t BTSYMBOLS(bt_spp_server_stop)(bt_instance_t* ins, void* handle, uint16_t scn)
{
spp_interface_t* profile = get_profile_service();
return profile->server_stop(handle, scn);
}
bt_status_t BTSYMBOLS(bt_spp_connect)(bt_instance_t* ins, void* handle, bt_address_t* addr, int16_t scn, bt_uuid_t* uuid, uint16_t* port)
{
spp_interface_t* profile = get_profile_service();
return profile->connect(handle, addr, scn, uuid, port);
}
bt_status_t BTSYMBOLS(bt_spp_disconnect)(bt_instance_t* ins, void* handle, bt_address_t* addr, uint16_t port)
{
spp_interface_t* profile = get_profile_service();
return profile->disconnect(handle, addr, port);
}

View File

@ -0,0 +1,177 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdlib.h>
#include <unistd.h>
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_BINDER_IPC
#include "adapter_proxy.h"
#include "adapter_stub.h"
#include "bluetooth_proxy.h"
#include "gattc_proxy.h"
#include "gatts_proxy.h"
#include "hfp_ag_proxy.h"
#include "hfp_hf_proxy.h"
#include "hid_device_proxy.h"
#include "pan_proxy.h"
#include "spp_proxy.h"
#endif
#include "bluetooth.h"
bt_instance_t* bluetooth_create_instance(void)
{
AIBinder* binder;
char name[64] = { 0 };
bt_instance_t* ins = zalloc(sizeof(bt_instance_t));
if (!ins) {
return NULL;
}
binder = BtManager_getService((BpBtManager**)&ins->manager_proxy, MANAGER_BINDER_INSTANCE);
if (!binder)
goto bail;
gethostname(name, 64);
bt_status_t status = BpBtManager_createInstance(binder, (uint32_t)ins, BLUETOOTH_SYSTEM, name, &ins->app_id);
if (status != BT_STATUS_SUCCESS)
goto bail;
BtAdapter_getService((BpBtAdapter**)&ins->adapter_proxy, ADAPTER_BINDER_INSTANCE);
Bluetooth_startThreadPool();
return ins;
bail:
free(ins);
return NULL;
}
bt_instance_t* bluetooth_get_instance(void)
{
uint32_t handle;
char name[64] = { 0 };
AIBinder* binder;
BpBtManager* proxy = NULL;
/* find instance from bluetooth manager by hostname,
if not found, create new instance for this hostname
*/
binder = BtManager_getService(&proxy, MANAGER_BINDER_INSTANCE);
if (!binder)
return NULL;
gethostname(name, 64);
bt_status_t status = BpBtManager_getInstance(binder, name, &handle);
BpBtManager_delete(proxy);
if (status == BT_STATUS_SUCCESS && handle)
return (bt_instance_t*)handle;
else
return bluetooth_create_instance();
}
void* bluetooth_get_proxy(bt_instance_t* ins, enum profile_id id)
{
switch (id) {
case PROFILE_HFP_HF:
/* for binder ipc*/
if (!ins->hfp_hf_proxy) {
ins->hfp_hf_proxy = BpBtHfpHf_new(HFP_HF_BINDER_INSTANCE);
}
return ins->hfp_hf_proxy;
case PROFILE_HFP_AG: {
if (!ins->hfp_ag_proxy) {
ins->hfp_ag_proxy = BpBtHfpAg_new(HFP_AG_BINDER_INSTANCE);
}
return ins->hfp_ag_proxy;
}
case PROFILE_SPP: {
if (!ins->spp_proxy) {
ins->spp_proxy = BpBtSpp_new(SPP_BINDER_INSTANCE);
}
return ins->spp_proxy;
}
case PROFILE_HID_DEV: {
if (!ins->hidd_proxy) {
ins->hidd_proxy = BpBtHidd_new(HID_DEVICE_BINDER_INSTANCE);
}
return ins->hidd_proxy;
}
case PROFILE_PANU: {
if (!ins->pan_proxy) {
ins->pan_proxy = BpBtPan_new(PAN_BINDER_INSTANCE);
}
return ins->pan_proxy;
}
case PROFILE_GATTC: {
if (!ins->gattc_proxy) {
ins->gattc_proxy = BpBtGattClient_new(GATT_CLIENT_BINDER_INSTANCE);
}
return ins->gattc_proxy;
}
case PROFILE_GATTS: {
if (!ins->gatts_proxy) {
ins->gatts_proxy = BpBtGattServer_new(GATT_SERVER_BINDER_INSTANCE);
}
return ins->gatts_proxy;
}
default:
break;
}
return NULL;
}
void bluetooth_delete_instance(bt_instance_t* ins)
{
if (ins->hfp_hf_proxy)
BpBtHfpHf_delete(ins->hfp_hf_proxy);
if (ins->hfp_ag_proxy)
BpBtHfpAg_delete(ins->hfp_ag_proxy);
if (ins->spp_proxy)
BpBtSpp_delete(ins->spp_proxy);
if (ins->pan_proxy)
BpBtPan_delete(ins->pan_proxy);
if (ins->gattc_proxy)
BpBtGattClient_delete(ins->gattc_proxy);
if (ins->gatts_proxy)
BpBtGattServer_delete(ins->gatts_proxy);
BpBtAdapter_delete(ins->adapter_proxy);
BpBtManager_deleteInstance(ins->manager_proxy, ins->app_id);
BpBtManager_delete(ins->manager_proxy);
free(ins);
}
bt_status_t bluetooth_start_service(bt_instance_t* ins, enum profile_id id)
{
return BpBtManager_startService(ins->manager_proxy, ins->app_id, id);
}
bt_status_t bluetooth_stop_service(bt_instance_t* ins, enum profile_id id)
{
return BpBtManager_stopService(ins->manager_proxy, ins->app_id, id);
}
#include "uv.h"
bool bluetooth_set_external_uv(bt_instance_t* ins, uv_loop_t* ext_loop)
{
return false;
}

View File

@ -0,0 +1,231 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "adapter_callbacks_stub.h"
#include "adapter_proxy.h"
#include "adapter_stub.h"
#include "bt_adapter.h"
void* bt_adapter_register_callback(bt_instance_t* ins, const adapter_callbacks_t* adapter_cbs)
{
BpBtAdapter* bpAdapter = ins->adapter_proxy;
if (!BtAdapter_getService(&bpAdapter, ADAPTER_BINDER_INSTANCE))
return NULL;
IBtAdapterCallbacks* cbks = BtAdapterCallbacks_new(adapter_cbs);
AIBinder* binder = BtAdapterCallbacks_getBinder(cbks);
if (!binder) {
BtAdapterCallbacks_delete(cbks);
return NULL;
}
void* rmt_cookie = BpBtAdapter_registerCallback(bpAdapter, binder);
AIBinder_decStrong(binder);
if (!rmt_cookie) {
BtAdapterCallbacks_delete(cbks);
return NULL;
}
cbks->cookie = rmt_cookie;
return (void*)cbks;
}
bool bt_adapter_unregister_callback(bt_instance_t* ins, void* cookie)
{
IBtAdapterCallbacks* cbks = cookie;
bool ret = BpBtAdapter_unRegisterCallback((BpBtAdapter*)ins->adapter_proxy, cbks->cookie);
if (ret)
BtAdapterCallbacks_delete(cbks);
return ret;
}
bt_status_t bt_adapter_enable(bt_instance_t* ins)
{
return BpBtAdapter_enable((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_disable(bt_instance_t* ins)
{
return BpBtAdapter_disable((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_enable_le(bt_instance_t* ins)
{
return BpBtAdapter_enableLe((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_disable_le(bt_instance_t* ins)
{
return BpBtAdapter_disableLe((BpBtAdapter*)ins->adapter_proxy);
}
bt_adapter_state_t bt_adapter_get_state(bt_instance_t* ins)
{
return BpBtAdapter_getState((BpBtAdapter*)ins->adapter_proxy);
}
bool bt_adapter_is_le_enabled(bt_instance_t* ins)
{
return BpBtAdapter_isLeEnabled((BpBtAdapter*)ins->adapter_proxy);
}
bt_device_type_t bt_adapter_get_type(bt_instance_t* ins)
{
return BpBtAdapter_getType((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_set_discovery_filter(bt_instance_t* ins)
{
return BpBtAdapter_setDiscoveryFilter((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_start_discovery(bt_instance_t* ins, uint32_t timeout)
{
return BpBtAdapter_startDiscovery((BpBtAdapter*)ins->adapter_proxy, timeout);
}
bt_status_t bt_adapter_cancel_discovery(bt_instance_t* ins)
{
return BpBtAdapter_cancelDiscovery((BpBtAdapter*)ins->adapter_proxy);
}
bool bt_adapter_is_discovering(bt_instance_t* ins)
{
return BpBtAdapter_isDiscovering((BpBtAdapter*)ins->adapter_proxy);
}
void bt_adapter_get_address(bt_instance_t* ins, bt_address_t* addr)
{
BpBtAdapter_getAddress((BpBtAdapter*)ins->adapter_proxy, addr);
}
bt_status_t bt_adapter_set_name(bt_instance_t* ins, const char* name)
{
assert(strlen(name) <= 64);
return BpBtAdapter_setName((BpBtAdapter*)ins->adapter_proxy, name);
}
void bt_adapter_get_name(bt_instance_t* ins, char* name, int length)
{
BpBtAdapter_getName((BpBtAdapter*)ins->adapter_proxy, name, length);
}
bt_status_t bt_adapter_get_uuids(bt_instance_t* ins, bt_uuid_t* uuids, uint16_t* size)
{
return BpBtAdapter_getUuids((BpBtAdapter*)ins->adapter_proxy, uuids, size);
}
bt_status_t bt_adapter_set_scan_mode(bt_instance_t* ins, bt_scan_mode_t mode, bool bondable)
{
return BpBtAdapter_setScanMode((BpBtAdapter*)ins->adapter_proxy, mode, bondable);
}
bt_scan_mode_t bt_adapter_get_scan_mode(bt_instance_t* ins)
{
return BpBtAdapter_getScanMode((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_set_device_class(bt_instance_t* ins, uint32_t cod)
{
return BpBtAdapter_setDeviceClass((BpBtAdapter*)ins->adapter_proxy, cod);
}
uint32_t bt_adapter_get_device_class(bt_instance_t* ins)
{
return BpBtAdapter_getDeviceClass((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_set_io_capability(bt_instance_t* ins, bt_io_capability_t cap)
{
return BpBtAdapter_setIOCapability((BpBtAdapter*)ins->adapter_proxy, cap);
}
bt_io_capability_t bt_adapter_get_io_capability(bt_instance_t* ins)
{
return BpBtAdapter_getIOCapability((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_set_le_io_capability(bt_instance_t* ins, uint32_t le_io_cap)
{
return BpBtAdapter_SetLeIOCapability((BpBtAdapter*)ins->adapter_proxy, le_io_cap);
}
uint32_t bt_adapter_get_le_io_capability(bt_instance_t* ins)
{
return BpBtAdapter_getLeIOCapability((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_get_le_address(bt_instance_t* ins, bt_address_t* addr, ble_addr_type_t* type)
{
return BpBtAdapter_getLeAddress((BpBtAdapter*)ins->adapter_proxy, addr, type);
}
bt_status_t bt_adapter_set_le_address(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_setLeAddress((BpBtAdapter*)ins->adapter_proxy, addr);
}
bt_status_t bt_adapter_set_le_identity_address(bt_instance_t* ins, bt_address_t* addr, bool public)
{
return BpBtAdapter_setLeIdentityAddress((BpBtAdapter*)ins->adapter_proxy, addr, public);
}
bt_status_t bt_adapter_set_le_appearance(bt_instance_t* ins, uint16_t appearance)
{
return BpBtAdapter_setLeAppearance((BpBtAdapter*)ins->adapter_proxy, appearance);
}
uint16_t bt_adapter_get_le_appearance(bt_instance_t* ins)
{
return BpBtAdapter_getLeAppearance((BpBtAdapter*)ins->adapter_proxy);
}
bt_status_t bt_adapter_get_bonded_devices(bt_instance_t* ins, bt_transport_t transport, bt_address_t** addr, int* num, bt_allocator_t allocator)
{
return BpBtAdapter_getBondedDevices((BpBtAdapter*)ins->adapter_proxy, addr, num, allocator);
}
bt_status_t bt_adapter_get_connected_devices(bt_instance_t* ins, bt_transport_t transport, bt_address_t** addr, int* num, bt_allocator_t allocator)
{
return BpBtAdapter_getConnectedDevices((BpBtAdapter*)ins->adapter_proxy, addr, num, allocator);
}
void bt_adapter_disconnect_all_devices(bt_instance_t* ins)
{
}
bool bt_adapter_is_support_bredr(bt_instance_t* ins)
{
return false;
}
bool bt_adapter_is_support_le(bt_instance_t* ins)
{
return false;
}
bool bt_adapter_is_support_leaudio(bt_instance_t* ins)
{
return false;
}

View File

@ -0,0 +1,176 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include <stdlib.h>
#include "adapter_internel.h"
#include "bluetooth.h"
#include "bt_addr.h"
#include "bt_device.h"
#include "device.h"
#include "adapter_proxy.h"
#include "adapter_stub.h"
bt_address_t* bt_device_get_identity_address(bt_instance_t* ins, bt_address_t* addr)
{
return NULL;
}
ble_addr_type_t bt_device_get_address_type(bt_instance_t* ins, bt_address_t* addr)
{
return 0;
}
bt_device_type_t bt_device_get_device_type(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_getRemoteDeviceType((BpBtAdapter*)ins->adapter_proxy, addr);
}
bool bt_device_get_name(bt_instance_t* ins, bt_address_t* addr, char* name, uint32_t length)
{
return BpBtAdapter_getRemoteName((BpBtAdapter*)ins->adapter_proxy, addr, name, length);
}
uint32_t bt_device_get_device_class(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_getRemoteDeviceClass((BpBtAdapter*)ins->adapter_proxy, addr);
}
bt_status_t bt_device_get_uuids(bt_instance_t* ins, bt_address_t* addr, bt_uuid_t** uuids, uint16_t* size, bt_allocator_t allocator)
{
return BpBtAdapter_getRemoteUuids((BpBtAdapter*)ins->adapter_proxy, addr, uuids, size, allocator);
}
uint16_t bt_device_get_appearance(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_getRemoteAppearance((BpBtAdapter*)ins->adapter_proxy, addr);
}
int8_t bt_device_get_rssi(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_getRemoteRssi((BpBtAdapter*)ins->adapter_proxy, addr);
}
bool bt_device_get_alias(bt_instance_t* ins, bt_address_t* addr, char* alias, uint32_t length)
{
return BpBtAdapter_getRemoteAlias((BpBtAdapter*)ins->adapter_proxy, addr, alias, length);
}
bt_status_t bt_device_set_alias(bt_instance_t* ins, bt_address_t* addr, const char* alias)
{
return BpBtAdapter_setRemoteAlias((BpBtAdapter*)ins->adapter_proxy, addr, alias);
}
bool bt_device_is_connected(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_isRemoteConnected((BpBtAdapter*)ins->adapter_proxy, addr);
}
bool bt_device_is_encrypted(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_isRemoteEncrypted((BpBtAdapter*)ins->adapter_proxy, addr);
}
bool bt_device_is_bond_initiate_local(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_isBondInitiateLocal((BpBtAdapter*)ins->adapter_proxy, addr);
}
bond_state_t bt_device_get_bond_state(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_getRemoteBondState((BpBtAdapter*)ins->adapter_proxy, addr);
}
bool bt_device_is_bonded(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_isRemoteBonded((BpBtAdapter*)ins->adapter_proxy, addr);
}
bt_status_t bt_device_connect(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_connect((BpBtAdapter*)ins->adapter_proxy, addr);
}
bt_status_t bt_device_disconnect(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_disconnect((BpBtAdapter*)ins->adapter_proxy, addr);
}
bt_status_t bt_device_connect_le(bt_instance_t* ins,
bt_address_t* addr,
ble_addr_type_t type,
ble_connect_params_t* param)
{
return BpBtAdapter_leConnect((BpBtAdapter*)ins->adapter_proxy, addr, type, param);
}
bt_status_t bt_device_disconnect_le(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_leDisconnect((BpBtAdapter*)ins->adapter_proxy, addr);
}
void bt_device_connect_all_profile(bt_instance_t* ins, bt_address_t* addr)
{
}
void bt_device_disconnect_all_profile(bt_instance_t* ins, bt_address_t* addr)
{
}
bt_status_t bt_device_set_le_phy(bt_instance_t* ins,
bt_address_t* addr,
ble_phy_type_t tx_phy,
ble_phy_type_t rx_phy)
{
return BpBtAdapter_leSetPhy((BpBtAdapter*)ins->adapter_proxy, addr, tx_phy, rx_phy);
}
bt_status_t bt_device_create_bond(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport)
{
return BpBtAdapter_createBond((BpBtAdapter*)ins->adapter_proxy, addr, transport);
}
bt_status_t bt_device_remove_bond(bt_instance_t* ins, bt_address_t* addr, uint8_t transport)
{
return BpBtAdapter_removeBond((BpBtAdapter*)ins->adapter_proxy, addr, transport);
}
bt_status_t bt_device_cancel_bond(bt_instance_t* ins, bt_address_t* addr)
{
return BpBtAdapter_cancelBond((BpBtAdapter*)ins->adapter_proxy, addr);
}
bt_status_t bt_device_pair_request_reply(bt_instance_t* ins, bt_address_t* addr, bool accept)
{
return BpBtAdapter_pairRequestReply((BpBtAdapter*)ins->adapter_proxy, addr, accept);
}
bt_status_t bt_device_set_pairing_confirmation(bt_instance_t* ins, bt_address_t* addr, uint8_t transport, bool accept)
{
return BpBtAdapter_setPairingConfirmation((BpBtAdapter*)ins->adapter_proxy, addr, transport, accept);
}
bt_status_t bt_device_set_pin_code(bt_instance_t* ins, bt_address_t* addr, bool accept,
char* pincode, int len)
{
return BpBtAdapter_setPinCode((BpBtAdapter*)ins->adapter_proxy, addr, accept, pincode, len);
}
bt_status_t bt_device_set_pass_key(bt_instance_t* ins, bt_address_t* addr, uint8_t transport, bool accept, uint32_t passkey)
{
return BpBtAdapter_setPassKey((BpBtAdapter*)ins->adapter_proxy, addr, transport, accept, passkey);
}

132
framework/binder/bt_gattc.c Normal file
View File

@ -0,0 +1,132 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "gattc"
#include "bt_gattc.h"
#include "bt_profile.h"
#include "gattc_callbacks_stub.h"
#include "gattc_proxy.h"
#include "gattc_stub.h"
#include "utils/log.h"
#include <stdint.h>
bt_status_t bt_gattc_create_connect(bt_instance_t* ins, gattc_handle_t* phandle, gattc_callbacks_t* callbacks)
{
BpBtGattClient* gattc = (BpBtGattClient*)bluetooth_get_proxy(ins, PROFILE_GATTC);
IBtGattClientCallbacks* cbks = BtGattClientCallbacks_new(callbacks);
AIBinder* binder = BtGattClientCallbacks_getBinder(cbks);
if (!binder) {
BtGattClientCallbacks_delete(cbks);
return BT_STATUS_FAIL;
}
void* handle = BpBtGattClient_createConnect(gattc, binder);
if (!handle) {
BtGattClientCallbacks_delete(cbks);
return BT_STATUS_FAIL;
}
cbks->proxy = gattc;
cbks->cookie = handle;
*phandle = cbks;
return BT_STATUS_SUCCESS;
}
bt_status_t bt_gattc_delete_connect(gattc_handle_t conn_handle)
{
IBtGattClientCallbacks* cbks = conn_handle;
bt_status_t status = BpBtGattClient_deleteConnect(cbks->proxy, cbks->cookie);
if (status == BT_STATUS_SUCCESS)
BtGattClientCallbacks_delete(cbks);
return status;
}
bt_status_t bt_gattc_connect(gattc_handle_t conn_handle, bt_address_t* addr, ble_addr_type_t addr_type)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_connect(cbks->proxy, cbks->cookie, addr, addr_type);
}
bt_status_t bt_gattc_disconnect(gattc_handle_t conn_handle)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_disconnect(cbks->proxy, cbks->cookie);
}
bt_status_t bt_gattc_discover_service(gattc_handle_t conn_handle, bt_uuid_t* filter_uuid)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_discoverService(cbks->proxy, cbks->cookie, filter_uuid);
}
bt_status_t bt_gattc_get_attribute_by_handle(gattc_handle_t conn_handle, uint16_t attr_handle, gatt_attr_desc_t* attr_desc)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_getAttributeByHandle(cbks->proxy, cbks->cookie, attr_handle, attr_desc);
}
bt_status_t bt_gattc_get_attribute_by_uuid(gattc_handle_t conn_handle, bt_uuid_t* attr_uuid, gatt_attr_desc_t* attr_desc)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_getAttributeByUUID(cbks->proxy, cbks->cookie, attr_uuid, attr_desc);
}
bt_status_t bt_gattc_read(gattc_handle_t conn_handle, uint16_t attr_handle)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_read(cbks->proxy, cbks->cookie, attr_handle);
}
bt_status_t bt_gattc_write(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_write(cbks->proxy, cbks->cookie, attr_handle, value, length);
}
bt_status_t bt_gattc_write_without_response(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_writeWithoutResponse(cbks->proxy, cbks->cookie, attr_handle, value, length);
}
bt_status_t bt_gattc_subscribe(gattc_handle_t conn_handle, uint16_t value_handle, uint16_t cccd_handle)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_subscribe(cbks->proxy, cbks->cookie, value_handle, cccd_handle);
}
bt_status_t bt_gattc_unsubscribe(gattc_handle_t conn_handle, uint16_t value_handle, uint16_t cccd_handle)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_unsubscribe(cbks->proxy, cbks->cookie, value_handle, cccd_handle);
}
bt_status_t bt_gattc_exchange_mtu(gattc_handle_t conn_handle, uint32_t mtu)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_exchangeMtu(cbks->proxy, cbks->cookie, mtu);
}
bt_status_t bt_gattc_update_connection_parameter(gattc_handle_t conn_handle, uint32_t min_interval, uint32_t max_interval, uint32_t latency,
uint32_t timeout, uint32_t min_connection_event_length, uint32_t max_connection_event_length)
{
IBtGattClientCallbacks* cbks = conn_handle;
return BpBtGattClient_updateConnectionParameter(cbks->proxy, cbks->cookie, min_interval, max_interval, latency,
timeout, min_connection_event_length, max_connection_event_length);
}

109
framework/binder/bt_gatts.c Normal file
View File

@ -0,0 +1,109 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "gatts"
#include "bt_gatts.h"
#include "bt_profile.h"
#include "gatts_callbacks_stub.h"
#include "gatts_proxy.h"
#include "gatts_stub.h"
#include "utils/log.h"
#include <stdint.h>
bt_status_t bt_gatts_register_service(bt_instance_t* ins, gatts_handle_t* phandle, gatts_callbacks_t* callbacks)
{
BpBtGattServer* gatts = (BpBtGattServer*)bluetooth_get_proxy(ins, PROFILE_GATTS);
IBtGattServerCallbacks* cbks = BtGattServerCallbacks_new(callbacks);
AIBinder* binder = BtGattServerCallbacks_getBinder(cbks);
if (!binder) {
BtGattServerCallbacks_delete(cbks);
return BT_STATUS_FAIL;
}
void* handle = BpBtGattServer_registerService(gatts, binder);
if (!handle) {
BtGattServerCallbacks_delete(cbks);
return BT_STATUS_FAIL;
}
cbks->proxy = gatts;
cbks->cookie = handle;
*phandle = cbks;
return BT_STATUS_SUCCESS;
}
bt_status_t bt_gatts_unregister_service(gatts_handle_t srv_handle)
{
IBtGattServerCallbacks* cbks = srv_handle;
bt_status_t status = BpBtGattServer_unregisterService(cbks->proxy, cbks->cookie);
if (status == BT_STATUS_SUCCESS)
BtGattServerCallbacks_delete(cbks);
return status;
}
bt_status_t bt_gatts_connect(gatts_handle_t srv_handle, bt_address_t* addr, ble_addr_type_t addr_type)
{
IBtGattServerCallbacks* cbks = srv_handle;
return BpBtGattServer_connect(cbks->proxy, cbks->cookie, addr, addr_type);
}
bt_status_t bt_gatts_disconnect(gatts_handle_t srv_handle)
{
IBtGattServerCallbacks* cbks = srv_handle;
return BpBtGattServer_disconnect(cbks->proxy, cbks->cookie);
}
bt_status_t bt_gatts_create_service_table(gatts_handle_t srv_handle, gatt_srv_db_t* srv_db)
{
IBtGattServerCallbacks* cbks = srv_handle;
bt_status_t status = BpBtGattServer_createServiceTable(cbks->proxy, cbks->cookie, srv_db);
if (status == BT_STATUS_SUCCESS)
cbks->srv_db = srv_db;
return status;
}
bt_status_t bt_gatts_start(gatts_handle_t srv_handle)
{
IBtGattServerCallbacks* cbks = srv_handle;
return BpBtGattServer_start(cbks->proxy, cbks->cookie);
}
bt_status_t bt_gatts_stop(gatts_handle_t srv_handle)
{
IBtGattServerCallbacks* cbks = srv_handle;
return BpBtGattServer_stop(cbks->proxy, cbks->cookie);
}
bt_status_t bt_gatts_response(gatts_handle_t srv_handle, uint32_t req_handle, uint8_t* value, uint16_t length)
{
IBtGattServerCallbacks* cbks = srv_handle;
return BpBtGattServer_response(cbks->proxy, cbks->cookie, req_handle, value, length);
}
bt_status_t bt_gatts_notify(gatts_handle_t srv_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
IBtGattServerCallbacks* cbks = srv_handle;
return BpBtGattServer_notify(cbks->proxy, cbks->cookie, attr_handle, value, length);
}
bt_status_t bt_gatts_indicate(gatts_handle_t srv_handle, uint16_t attr_handle, uint8_t* value, uint16_t length)
{
IBtGattServerCallbacks* cbks = srv_handle;
return BpBtGattServer_indicate(cbks->proxy, cbks->cookie, attr_handle, value, length);
}

View File

@ -0,0 +1,122 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "hfp_ag_api"
#include "bt_hfp_ag.h"
#include "bt_profile.h"
#include "hfp_ag_callbacks_stub.h"
#include "hfp_ag_proxy.h"
#include "hfp_ag_stub.h"
#include "utils/log.h"
#include <stdint.h>
void* bt_hfp_ag_register_callbacks(bt_instance_t* ins, const hfp_ag_callbacks_t* callbacks)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
IBtHfpAgCallbacks* cbks = BtHfpAgCallbacks_new(callbacks);
AIBinder* binder = BtHfpAgCallbacks_getBinder(cbks);
if (!binder) {
BtHfpAgCallbacks_delete(cbks);
return NULL;
}
void* remote_cbks = BpBtHfpAg_registerCallback(ag, binder);
if (!remote_cbks) {
BtHfpAgCallbacks_delete(cbks);
return NULL;
}
cbks->cookie = remote_cbks;
return cbks;
}
bool bt_hfp_ag_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
IBtHfpAgCallbacks* cbks = cookie;
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
bool ret = BpBtHfpAg_unRegisterCallback(ag, cbks->cookie);
if (ret)
BtHfpAgCallbacks_delete(cbks);
return ret;
}
bool bt_hfp_ag_is_connected(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
return BpBtHfpAg_isConnected(ag, addr);
}
bool bt_hfp_ag_is_audio_connected(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
return BpBtHfpAg_isAudioConnected(ag, addr);
}
profile_connection_state_t bt_hfp_ag_get_connection_state(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
return BpBtHfpAg_getConnectionState(ag, addr);
}
bt_status_t bt_hfp_ag_connect(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
return BpBtHfpAg_connect(ag, addr);
}
bt_status_t bt_hfp_ag_disconnect(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
return BpBtHfpAg_disconnect(ag, addr);
}
bt_status_t bt_hfp_ag_connect_audio(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
return BpBtHfpAg_connectAudio(ag, addr);
}
bt_status_t bt_hfp_ag_disconnect_audio(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
return BpBtHfpAg_disconnectAudio(ag, addr);
}
bt_status_t bt_hfp_ag_start_voice_recognition(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
return BpBtHfpAg_startVoiceRecognition(ag, addr);
}
bt_status_t bt_hfp_ag_stop_voice_recognition(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpAg* ag = (BpBtHfpAg*)bluetooth_get_proxy(ins, PROFILE_HFP_AG);
return BpBtHfpAg_stopVoiceRecognition(ag, addr);
}

View File

@ -0,0 +1,192 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_THF "hfp_hf_api"
#include "bt_hfp_hf.h"
#include "bt_profile.h"
#include "hfp_hf_callbacks_stub.h"
#include "hfp_hf_proxy.h"
#include "hfp_hf_stub.h"
#include "utils/log.h"
#include <stdint.h>
void* bt_hfp_hf_register_callbacks(bt_instance_t* ins, const hfp_hf_callbacks_t* callbacks)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
IBtHfpHfCallbacks* cbks = BtHfpHfCallbacks_new(callbacks);
AIBinder* binder = BtHfpHfCallbacks_getBinder(cbks);
if (!binder) {
BtHfpHfCallbacks_delete(cbks);
return NULL;
}
void* remote_cbks = BpBtHfpHf_registerCallback(hf, binder);
if (!remote_cbks) {
BtHfpHfCallbacks_delete(cbks);
return NULL;
}
cbks->cookie = remote_cbks;
return cbks;
}
bool bt_hfp_hf_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
IBtHfpHfCallbacks* cbks = cookie;
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
bool ret = BpBtHfpHf_unRegisterCallback(hf, cbks->cookie);
if (ret)
BtHfpHfCallbacks_delete(cbks);
return ret;
}
bool bt_hfp_hf_is_connected(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_isConnected(hf, addr);
}
bool bt_hfp_hf_is_audio_connected(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_isAudioConnected(hf, addr);
}
profile_connection_state_t bt_hfp_hf_get_connection_state(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_getConnectionState(hf, addr);
}
bt_status_t bt_hfp_hf_connect(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_connect(hf, addr);
}
bt_status_t bt_hfp_hf_disconnect(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_disconnect(hf, addr);
}
bt_status_t bt_hfp_hf_connect_audio(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_connectAudio(hf, addr);
}
bt_status_t bt_hfp_hf_disconnect_audio(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_disconnectAudio(hf, addr);
}
bt_status_t bt_hfp_hf_start_voice_recognition(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_startVoiceRecognition(hf, addr);
}
bt_status_t bt_hfp_hf_stop_voice_recognition(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_stopVoiceRecognition(hf, addr);
}
bt_status_t bt_hfp_hf_dial(bt_instance_t* ins, bt_address_t* addr, const char* number)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_dial(hf, addr, number);
}
bt_status_t bt_hfp_hf_dial_memory(bt_instance_t* ins, bt_address_t* addr, uint32_t memory)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_dialMemory(hf, addr, memory);
}
bt_status_t bt_hfp_hf_redial(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_redial(hf, addr);
}
bt_status_t bt_hfp_hf_accept_call(bt_instance_t* ins, bt_address_t* addr, hfp_call_accept_t flag)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_acceptCall(hf, addr, flag);
}
bt_status_t bt_hfp_hf_reject_call(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_rejectCall(hf, addr);
}
bt_status_t bt_hfp_hf_hold_call(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_holdCall(hf, addr);
}
bt_status_t bt_hfp_hf_terminate_call(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_terminateCall(hf, addr);
}
bt_status_t bt_hfp_hf_control_call(bt_instance_t* ins, bt_address_t* addr, hfp_call_control_t chld, uint8_t index)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_controlCall(hf, addr, chld, index);
}
bt_status_t bt_hfp_hf_query_current_calls(bt_instance_t* ins, bt_address_t* addr, hfp_current_call_t** calls, int* num, bt_allocator_t allocator)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_queryCurrentCalls(hf, addr, calls, num, allocator);
}
bt_status_t bt_hfp_hf_send_at_cmd(bt_instance_t* ins, bt_address_t* addr, const char* cmd)
{
BpBtHfpHf* hf = (BpBtHfpHf*)bluetooth_get_proxy(ins, PROFILE_HFP_HF);
return BpBtHfpHf_sendAtCmd(hf, addr, cmd);
}

View File

@ -0,0 +1,117 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "hid_device_api"
#include <stdint.h>
#include "bluetooth.h"
#include "bt_hid_device.h"
#include "bt_profile.h"
#include "hid_device_callbacks_stub.h"
#include "hid_device_proxy.h"
#include "hid_device_stub.h"
#include "utils/log.h"
void* bt_hid_device_register_callbacks(bt_instance_t* ins, const hid_device_callbacks_t* callbacks)
{
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
IBtHiddCallbacks* cbks = BtHiddCallbacks_new(callbacks);
AIBinder* binder = BtHiddCallbacks_getBinder(cbks);
if (!binder) {
BtHiddCallbacks_delete(cbks);
return NULL;
}
void* remote_cbks = BpBtHidd_registerCallback(hidd, binder);
if (!remote_cbks) {
BtHiddCallbacks_delete(cbks);
return NULL;
}
cbks->cookie = remote_cbks;
return cbks;
}
bool bt_hid_device_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
IBtHiddCallbacks* cbks = cookie;
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
bool ret = BpBtHidd_unRegisterCallback(hidd, cbks->cookie);
if (ret)
BtHiddCallbacks_delete(cbks);
return ret;
}
bt_status_t bt_hid_device_register_app(bt_instance_t* ins, hid_device_sdp_settings_t* sdp, bool le_hid)
{
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
return BpBtHidd_registerApp(hidd, sdp, le_hid);
}
bt_status_t bt_hid_device_unregister_app(bt_instance_t* ins)
{
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
return BpBtHidd_unregisterApp(hidd);
}
bt_status_t bt_hid_device_connect(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
return BpBtHidd_connect(hidd, addr);
}
bt_status_t bt_hid_device_disconnect(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
return BpBtHidd_disconnect(hidd, addr);
}
bt_status_t bt_hid_device_send_report(bt_instance_t* ins, bt_address_t* addr, uint8_t rpt_id, uint8_t* rpt_data, int rpt_size)
{
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
return BpBtHidd_sendReport(hidd, addr, rpt_id, rpt_data, rpt_size);
}
bt_status_t bt_hid_device_response_report(bt_instance_t* ins, bt_address_t* addr, uint8_t rpt_type, uint8_t* rpt_data, int rpt_size)
{
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
return BpBtHidd_responseReport(hidd, addr, rpt_type, rpt_data, rpt_size);
}
bt_status_t bt_hid_device_report_error(bt_instance_t* ins, bt_address_t* addr, hid_status_error_t error)
{
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
return BpBtHidd_reportError(hidd, addr, error);
}
bt_status_t bt_hid_device_virtual_unplug(bt_instance_t* ins, bt_address_t* addr)
{
BpBtHidd* hidd = (BpBtHidd*)bluetooth_get_proxy(ins, PROFILE_HID_DEV);
return BpBtHidd_virtualUnplug(hidd, addr);
}

View File

@ -0,0 +1,77 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "adv"
#include <stdlib.h>
#include "adapter_proxy.h"
#include "adapter_stub.h"
#include "advertiser_callbacks_stub.h"
#include "bluetooth.h"
#include "bt_le_advertiser.h"
#include "bt_list.h"
#include "utils/log.h"
bt_advertiser_t* bt_le_start_advertising(bt_instance_t* ins,
ble_adv_params_t* params,
uint8_t* adv_data,
uint16_t adv_len,
uint8_t* scan_rsp_data,
uint16_t scan_rsp_len,
advertiser_callback_t* cbs)
{
BpBtAdapter* bpAdapter = ins->adapter_proxy;
IBtAdvertiserCallbacks* cbks = BtAdvertiserCallbacks_new(cbs);
AIBinder* binder = BtAdvertiserCallbacks_getBinder(cbks);
if (!binder) {
BtAdvertiserCallbacks_delete(cbks);
return NULL;
}
void* rmt_adver = BpBtAdapter_startAdvertising(bpAdapter, params,
adv_data, adv_len,
scan_rsp_data,
scan_rsp_len, binder);
AIBinder_decStrong(binder);
if (!rmt_adver) {
BtAdvertiserCallbacks_delete(cbks);
return NULL;
}
cbks->cookie = rmt_adver;
return (bt_advertiser_t*)cbks;
}
void bt_le_stop_advertising(bt_instance_t* ins, bt_advertiser_t* adver)
{
BpBtAdapter* bpAdapter = ins->adapter_proxy;
IBtAdvertiserCallbacks* cbks = adver;
BpBtAdapter_stopAdvertising(bpAdapter, cbks->cookie);
}
void bt_le_stop_advertising_id(bt_instance_t* ins, uint8_t adv_id)
{
BpBtAdapter* bpAdapter = ins->adapter_proxy;
BpBtAdapter_stopAdvertisingId(bpAdapter, adv_id);
}
bool bt_le_advertising_is_supported(bt_instance_t* ins)
{
return false;
}

View File

@ -0,0 +1,73 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "adv"
#include <stdlib.h>
#include "adapter_proxy.h"
#include "adapter_stub.h"
#include "bluetooth.h"
#include "bt_le_scan.h"
#include "bt_list.h"
#include "scanner_callbacks_stub.h"
#include "utils/log.h"
bt_scanner_t* bt_le_start_scan(bt_instance_t* ins, const scanner_callbacks_t* cbs)
{
return bt_le_start_scan_settings(ins, NULL, cbs);
}
bt_scanner_t* bt_le_start_scan_settings(bt_instance_t* ins,
ble_scan_settings_t* settings,
const scanner_callbacks_t* cbs)
{
BpBtAdapter* bpAdapter = ins->adapter_proxy;
void* rmt_scanner = NULL;
IBtScannerCallbacks* cbks = BtScannerCallbacks_new(cbs);
AIBinder* binder = BtScannerCallbacks_getBinder(cbks);
if (!binder) {
BtScannerCallbacks_delete(cbks);
return NULL;
}
if (settings)
rmt_scanner = BpBtAdapter_startScanSettings(bpAdapter, settings, binder);
else
rmt_scanner = BpBtAdapter_startScan(bpAdapter, binder);
AIBinder_decStrong(binder);
if (!rmt_scanner) {
BtScannerCallbacks_delete(cbks);
return NULL;
}
cbks->cookie = rmt_scanner;
return (bt_scanner_t*)cbks;
}
void bt_le_stop_scan(bt_instance_t* ins, bt_scanner_t* scanner)
{
BpBtAdapter* bpAdapter = ins->adapter_proxy;
IBtScannerCallbacks* cbks = scanner;
BpBtAdapter_stopScan(bpAdapter, cbks->cookie);
}
bool bt_le_scan_is_supported(bt_instance_t* ins)
{
return false;
}

75
framework/binder/bt_pan.c Normal file
View File

@ -0,0 +1,75 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "pan_api"
#include <stdint.h>
#include "bluetooth.h"
#include "bt_pan.h"
#include "bt_profile.h"
#include "pan_callbacks_stub.h"
#include "pan_proxy.h"
#include "pan_stub.h"
#include "utils/log.h"
void* bt_pan_register_callbacks(bt_instance_t* ins, const pan_callbacks_t* callbacks)
{
BpBtPan* pan = (BpBtPan*)bluetooth_get_proxy(ins, PROFILE_PANU);
IBtPanCallbacks* cbks = BtPanCallbacks_new(callbacks);
AIBinder* binder = BtPanCallbacks_getBinder(cbks);
if (!binder) {
BtPanCallbacks_delete(cbks);
return NULL;
}
void* remote_cbks = BpBtPan_registerCallback(pan, binder);
if (!remote_cbks) {
BtPanCallbacks_delete(cbks);
return NULL;
}
cbks->cookie = remote_cbks;
return cbks;
}
bool bt_pan_unregister_callbacks(bt_instance_t* ins, void* cookie)
{
IBtPanCallbacks* cbks = cookie;
BpBtPan* pan = (BpBtPan*)bluetooth_get_proxy(ins, PROFILE_PANU);
bool ret = BpBtPan_unRegisterCallback(pan, cbks->cookie);
if (ret)
BtPanCallbacks_delete(cbks);
return ret;
}
bt_status_t bt_pan_connect(bt_instance_t* ins, bt_address_t* addr, uint8_t dst_role, uint8_t src_role)
{
BpBtPan* pan = (BpBtPan*)bluetooth_get_proxy(ins, PROFILE_PANU);
return BpBtPan_connect(pan, addr, dst_role, src_role);
}
bt_status_t bt_pan_disconnect(bt_instance_t* ins, bt_address_t* addr)
{
BpBtPan* pan = (BpBtPan*)bluetooth_get_proxy(ins, PROFILE_PANU);
return BpBtPan_disconnect(pan, addr);
}

93
framework/binder/bt_spp.c Normal file
View File

@ -0,0 +1,93 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#define LOG_TAG "spp_api"
#include <stdint.h>
#include "bluetooth.h"
#include "bt_profile.h"
#include "bt_spp.h"
#include "spp_callbacks_stub.h"
#include "spp_proxy.h"
#include "spp_stub.h"
#include "utils/log.h"
void* bt_spp_register_app(bt_instance_t* ins, const spp_callbacks_t* callbacks)
{
BpBtSpp* spp = (BpBtSpp*)bluetooth_get_proxy(ins, PROFILE_SPP);
IBtSppCallbacks* cbks = BtSppCallbacks_new(callbacks);
AIBinder* binder = BtSppCallbacks_getBinder(cbks);
if (!binder) {
BtSppCallbacks_delete(cbks);
return NULL;
}
void* handle = BpBtSpp_registerApp(spp, binder);
if (!handle) {
BtSppCallbacks_delete(cbks);
return NULL;
}
cbks->cookie = handle;
return cbks;
}
bt_status_t bt_spp_unregister_app(bt_instance_t* ins, void* handle)
{
IBtSppCallbacks* cbks = handle;
BpBtSpp* spp = (BpBtSpp*)bluetooth_get_proxy(ins, PROFILE_SPP);
bt_status_t status = BpBtSpp_unRegisterApp(spp, cbks->cookie);
if (status == BT_STATUS_SUCCESS)
BtSppCallbacks_delete(cbks);
return status;
}
bt_status_t bt_spp_server_start(bt_instance_t* ins, void* handle, uint16_t scn, bt_uuid_t* uuid, uint8_t max_connection)
{
IBtSppCallbacks* cbks = handle;
BpBtSpp* spp = (BpBtSpp*)bluetooth_get_proxy(ins, PROFILE_SPP);
return BpBtSpp_serverStart(spp, cbks->cookie, scn, uuid, max_connection);
}
bt_status_t bt_spp_server_stop(bt_instance_t* ins, void* handle, uint16_t scn)
{
IBtSppCallbacks* cbks = handle;
BpBtSpp* spp = (BpBtSpp*)bluetooth_get_proxy(ins, PROFILE_SPP);
return BpBtSpp_serverStop(spp, cbks->cookie, scn);
}
bt_status_t bt_spp_connect(bt_instance_t* ins, void* handle, bt_address_t* addr, int16_t scn, bt_uuid_t* uuid, uint16_t* port)
{
IBtSppCallbacks* cbks = handle;
BpBtSpp* spp = (BpBtSpp*)bluetooth_get_proxy(ins, PROFILE_SPP);
return BpBtSpp_connect(spp, cbks->cookie, addr, scn, uuid, port);
}
bt_status_t bt_spp_disconnect(bt_instance_t* ins, void* handle, bt_address_t* addr, uint16_t port)
{
IBtSppCallbacks* cbks = handle;
BpBtSpp* spp = (BpBtSpp*)bluetooth_get_proxy(ins, PROFILE_SPP);
return BpBtSpp_disconnect(spp, cbks->cookie, addr, port);
}

View File

@ -0,0 +1,229 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "bt_addr.h"
#include "bt_debug.h"
#include "bt_list.h"
#include "bt_utils.h"
#include "advertiser_data.h"
typedef struct advertiser_data_ {
bt_list_t* data;
uint8_t* buffer;
} advertiser_data_t;
static void advertiser_data_calc_len(void* data, void* context)
{
adv_data_t* adata = data;
*(uint16_t*)context += adata->len + 1;
}
advertiser_data_t* advertiser_data_new(void)
{
advertiser_data_t* ad = malloc(sizeof(advertiser_data_t));
if (!ad)
return NULL;
ad->data = bt_list_new((bt_list_free_cb_t)free);
ad->buffer = NULL;
return ad;
}
void advertiser_data_free(advertiser_data_t* ad)
{
if (ad->buffer)
free(ad->buffer);
bt_list_free(ad->data);
free(ad);
}
uint8_t* advertiser_data_build(advertiser_data_t* ad, uint16_t* len)
{
uint16_t total_len = 0;
bt_list_node_t* node;
uint8_t* p;
if (ad->buffer)
free(ad->buffer);
if (!bt_list_length(ad->data))
return NULL;
bt_list_foreach(ad->data, advertiser_data_calc_len, &total_len);
*len = total_len;
ad->buffer = malloc(total_len);
p = ad->buffer;
for (node = bt_list_head(ad->data); node != NULL;
node = bt_list_next(ad->data, node)) {
adv_data_t* adata = bt_list_node(node);
memcpy(p, adata, adata->len + 1);
p += adata->len + 1;
}
return ad->buffer;
}
void advertiser_data_set_name(advertiser_data_t* ad, const char* name)
{
uint8_t name_len = strlen(name);
adv_data_t* data = zalloc(sizeof(adv_data_t) + name_len + 1);
if (name_len > BT_LE_AD_NAME_LEN) {
name_len = BT_LE_AD_NAME_LEN;
data->type = BT_AD_NAME_SHORT;
} else
data->type = BT_AD_NAME_COMPLETE;
data->len = name_len + 1;
memcpy(data->data, name, name_len);
bt_list_add_tail(ad->data, data);
}
void advertiser_data_set_flags(advertiser_data_t* ad, uint8_t flags)
{
adv_data_t* data = malloc(sizeof(adv_data_t) + 1);
data->len = 2;
data->type = BT_AD_FLAGS;
data->data[0] = flags;
bt_list_add_tail(ad->data, data);
}
void advertiser_data_set_appearance(advertiser_data_t* ad, uint16_t appearance)
{
adv_data_t* data = malloc(sizeof(adv_data_t) + 2);
uint8_t* p = data->data;
data->len = 3;
data->type = BT_AD_GAP_APPEARANCE;
UINT16_TO_STREAM(p, appearance);
bt_list_add_tail(ad->data, data);
}
void advertiser_data_add_data(advertiser_data_t* ad, uint8_t type, uint8_t* data, uint8_t len)
{
adv_data_t* adata = malloc(sizeof(adv_data_t) + len);
adata->type = type;
adata->len = len;
memcpy(adata->data, data, len);
bt_list_add_tail(ad->data, adata);
}
void advertiser_data_remove_data(advertiser_data_t* ad, uint8_t type, uint8_t* data, uint8_t len)
{
}
void advertiser_data_add_manufacture_data(advertiser_data_t* ad,
uint16_t manufacture_id,
uint8_t* data, uint8_t length)
{
adv_data_t* mdata = malloc(sizeof(adv_data_t) + 2 + length);
uint8_t* p = mdata->data;
mdata->len = length + 2 + 1;
mdata->type = BT_AD_MANUFACTURER_DATA;
UINT16_TO_STREAM(p, manufacture_id);
memcpy(p, data, length);
bt_list_add_tail(ad->data, mdata);
}
bool advertiser_data_add_service_uuid(advertiser_data_t* ad, const bt_uuid_t* uuid)
{
adv_data_t* data;
uint8_t* p;
switch (uuid->type) {
case BT_UUID16_TYPE:
data = malloc(sizeof(adv_data_t) + 2);
data->len = 2 + 1;
data->type = BT_AD_UUID16_ALL;
p = data->data;
UINT16_TO_STREAM(p, uuid->val.u16);
break;
case BT_UUID32_TYPE:
data = malloc(sizeof(adv_data_t) + 4);
data->len = 4 + 1;
data->type = BT_AD_UUID32_ALL;
p = data->data;
UINT32_TO_STREAM(p, uuid->val.u32);
case BT_UUID128_TYPE:
data = malloc(sizeof(adv_data_t) + 16);
data->len = 16 + 1;
data->type = BT_AD_UUID128_ALL;
memcpy(data->data, uuid->val.u128, 16);
break;
default:
return false;
}
bt_list_add_tail(ad->data, data);
return true;
}
bool advertiser_data_add_service_data(advertiser_data_t* ad,
const bt_uuid_t* uuid,
uint8_t* data, uint8_t len)
{
adv_data_t* sdata;
uint8_t* p;
switch (uuid->type) {
case BT_UUID16_TYPE:
sdata = malloc(sizeof(adv_data_t) + len + 2);
sdata->len = 2 + 1;
sdata->type = BT_AD_SERVICE_DATA16;
p = sdata->data;
UINT16_TO_STREAM(p, uuid->val.u16);
break;
case BT_UUID32_TYPE:
sdata = malloc(sizeof(adv_data_t) + len + 4);
sdata->len = 4 + 1;
sdata->type = BT_AD_SERVICE_DATA32;
p = sdata->data;
UINT32_TO_STREAM(p, uuid->val.u32);
case BT_UUID128_TYPE:
sdata = malloc(sizeof(adv_data_t) + len + 16);
sdata->len = 16 + 1;
sdata->type = BT_AD_SERVICE_DATA128;
memcpy(sdata->data, uuid->val.u128, 16);
p = sdata->data + 16;
break;
default:
return false;
}
memcpy(p, data, len);
bt_list_add_tail(ad->data, sdata);
return true;
}

View File

@ -0,0 +1,215 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <stdbool.h>
#include <stdint.h>
#include "advertiser_data.h"
#include "bt_debug.h"
typedef struct {
uint8_t ad_type;
const char* desc;
} ad_type_desc_t;
static const ad_type_desc_t ad_type_map[] = {
{ BT_AD_FLAGS, "Flags" },
{ BT_AD_UUID16_SOME, "Incomplete List of 16­bit Service Class UUIDs" },
{ BT_AD_UUID16_ALL, "Complete List of 16­bit Service Class UUIDs" },
{ BT_AD_UUID32_SOME, "Incomplete List of 32­bit Service Class UUIDs" },
{ BT_AD_UUID32_ALL, "Complete List of 32­bit Service Class UUIDs" },
{ BT_AD_UUID128_SOME, "Incomplete List of 128­bit Service Class UUIDs" },
{ BT_AD_UUID128_ALL, "Complete List of 128­bit Service Class UUIDs" },
{ BT_AD_NAME_SHORT, "Shortened Local Name" },
{ BT_AD_NAME_COMPLETE, "Complete Local Name" },
{ BT_AD_TX_POWER, "Tx Power Level" },
{ BT_AD_CLASS_OF_DEV, "Class of Device" },
{ BT_AD_SSP_HASH, "Simple Pairing Hash C­192" },
{ BT_AD_SSP_RANDOMIZER, "Simple Pairing Randomizer R­192" },
{ BT_AD_SMP_TK, "Security Manager TK Value" },
{ BT_AD_SMP_OOB_FLAGS, "Security Manager Out of Band Flags" },
{ BT_AD_PERIPHERAL_CONN_INTERVAL, "Peripheral Connection Interval Range" },
{ BT_AD_SOLICIT16, "List of 16­bit Service Solicitation UUIDs" },
{ BT_AD_SOLICIT128, "List of 128­bit Service Solicitation UUIDs" },
{ BT_AD_SERVICE_DATA16, "Service Data ­ 16­bit UUID" },
{ BT_AD_PUBLIC_ADDRESS, "Public Target Address" },
{ BT_AD_RANDOM_ADDRESS, "Random Target Address" },
{ BT_AD_GAP_APPEARANCE, "Appearance" },
{ BT_AD_ADVERTISING_INTERVAL, "Advertising Interval" },
{ BT_AD_LE_DEVICE_ADDRESS, "LE Bluetooth Device Address" },
{ BT_AD_LE_ROLE, "LE Role" },
{ BT_AD_SSP_HASH_P256, "Simple Pairing Hash C­256" },
{ BT_AD_SSP_RANDOMIZER_P256, "Simple Pairing Randomizer R­256" },
{ BT_AD_SOLICIT32, "List of 32­bit Service Solicitation UUIDs" },
{ BT_AD_SERVICE_DATA32, "Service Data ­ 32­bit UUID" },
{ BT_AD_SERVICE_DATA128, "Service Data ­ 128­bit UUID" },
{ BT_AD_LE_SC_CONFIRM_VALUE, "LE Secure Connections Confirmation Value" },
{ BT_AD_LE_SC_RANDOM_VALUE, "LE Secure Connections Random Value" },
{ BT_AD_URI, "URI" },
{ BT_AD_INDOOR_POSITIONING, "Indoor Positioning" },
{ BT_AD_TRANSPORT_DISCOVERY, "Transport Discovery Data" },
{ BT_AD_LE_SUPPORTED_FEATURES, "LE Supported Features" },
{ BT_AD_CHANNEL_MAP_UPDATE_IND, "Channel Map Update Indication" },
{ BT_AD_MESH_PROV, "PB­ADV" },
{ BT_AD_MESH_DATA, "Mesh Message" },
{ BT_AD_MESH_BEACON, "Mesh Beacon" },
{ BT_AD_BIG_INFO, "BIGInfo" },
{ BT_AD_BROADCAST_CODE, "Broadcast_Code" },
{ BT_AD_RESOLVABLE_SET_IDENTIFIER, "Resolvable Set Identifier" },
{ BT_AD_ADV_INTERVAL_LONG, "Advertising Interval ­ long" },
{ BT_AD_BROADCAST_NAME, "Broadcast_Name" },
{ BT_AD_ENCRYPTED_ADV_DATA, "Encrypted Advertising Data" },
{ BT_AD_PERIODIC_ADV_RSP_TIMING, "Periodic Advertising Response Timing Information" },
{ BT_AD_3D_INFO_DATA, "3D Information Data" },
{ BT_AD_MANUFACTURER_DATA, "Manufacturer Specific Data" },
};
static const char* show_ad_type_desc(uint8_t type)
{
for (int i = 0; i < sizeof(ad_type_map) / sizeof(ad_type_map[0]); i++) {
if (ad_type_map[i].ad_type == type)
return ad_type_map[i].desc;
}
return "Unknown";
}
static void advertiser_data_info(adv_data_t* ad)
{
if (ad->len < 1) {
return;
}
syslog(4, "AdvType:(%s)\n", show_ad_type_desc(ad->type));
lib_dumpbuffer("AdvData:", ad->data, ad->len - 1);
switch (ad->type) {
case BT_AD_FLAGS:
break;
case BT_AD_UUID16_SOME:
break;
case BT_AD_UUID16_ALL:
break;
case BT_AD_UUID32_SOME:
break;
case BT_AD_UUID32_ALL:
break;
case BT_AD_UUID128_SOME:
break;
case BT_AD_UUID128_ALL:
break;
case BT_AD_NAME_SHORT:
break;
case BT_AD_NAME_COMPLETE:
break;
case BT_AD_TX_POWER:
break;
case BT_AD_CLASS_OF_DEV:
break;
case BT_AD_SSP_HASH:
break;
case BT_AD_SSP_RANDOMIZER:
break;
case BT_AD_SMP_TK:
/* if ad->len == 8, ad type is SMP_TK */
break;
case BT_AD_SMP_OOB_FLAGS:
break;
case BT_AD_PERIPHERAL_CONN_INTERVAL:
break;
case BT_AD_SOLICIT16:
break;
case BT_AD_SOLICIT128:
break;
case BT_AD_SERVICE_DATA16:
break;
case BT_AD_PUBLIC_ADDRESS:
break;
case BT_AD_RANDOM_ADDRESS:
break;
case BT_AD_GAP_APPEARANCE:
break;
case BT_AD_ADVERTISING_INTERVAL:
break;
case BT_AD_LE_DEVICE_ADDRESS:
break;
case BT_AD_LE_ROLE:
break;
case BT_AD_SSP_HASH_P256:
break;
case BT_AD_SSP_RANDOMIZER_P256:
break;
case BT_AD_SOLICIT32:
break;
case BT_AD_SERVICE_DATA32:
break;
case BT_AD_SERVICE_DATA128:
break;
case BT_AD_LE_SC_CONFIRM_VALUE:
break;
case BT_AD_LE_SC_RANDOM_VALUE:
break;
case BT_AD_URI:
break;
case BT_AD_INDOOR_POSITIONING:
break;
case BT_AD_TRANSPORT_DISCOVERY:
break;
case BT_AD_LE_SUPPORTED_FEATURES:
break;
case BT_AD_CHANNEL_MAP_UPDATE_IND:
break;
case BT_AD_MESH_PROV:
break;
case BT_AD_MESH_DATA:
break;
case BT_AD_MESH_BEACON:
break;
case BT_AD_BIG_INFO:
break;
case BT_AD_BROADCAST_CODE:
break;
case BT_AD_RESOLVABLE_SET_IDENTIFIER:
break;
case BT_AD_ADV_INTERVAL_LONG:
break;
case BT_AD_BROADCAST_NAME:
break;
case BT_AD_ENCRYPTED_ADV_DATA:
break;
case BT_AD_PERIODIC_ADV_RSP_TIMING:
break;
case BT_AD_3D_INFO_DATA:
break;
case BT_AD_MANUFACTURER_DATA:
break;
default:
break;
}
}
bool advertiser_data_dump(uint8_t* data, uint16_t len, ad_dump_cb_t dump)
{
uint16_t offset = 0;
while (offset < len) {
adv_data_t* ad = (adv_data_t*)&data[offset];
advertiser_data_info(ad);
offset += ad->len + 1;
};
return true;
}

118
framework/common/bt_addr.c Normal file
View File

@ -0,0 +1,118 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bt_addr.h"
const bt_address_t bt_addr_empty = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
};
const bt_address_t bt_addr_any = {
{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
};
static char g_bdaddr_str[18];
static int bachk(const char* str)
{
if (!str)
return -1;
if (strlen(str) != 17)
return -1;
while (*str) {
if (!isxdigit(*str++))
return -1;
if (!isxdigit(*str++))
return -1;
if (*str == 0)
break;
if (*str++ != ':')
return -1;
}
return 0;
}
bool bt_addr_is_empty(const bt_address_t* addr)
{
return memcmp(addr->addr, bt_addr_empty.addr, BT_ADDR_LENGTH) == 0;
}
void bt_addr_set_empty(bt_address_t* addr)
{
assert(addr != NULL);
memcpy(addr, &bt_addr_empty, sizeof(bt_address_t));
}
int bt_addr_compare(const bt_address_t* a, const bt_address_t* b)
{
return memcmp(a, b, sizeof(bt_address_t));
}
int bt_addr_ba2str(const bt_address_t* addr, char* str)
{
return sprintf(str, "%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X",
addr->addr[5], addr->addr[4], addr->addr[3],
addr->addr[2], addr->addr[1], addr->addr[0]);
}
char* bt_addr_str(const bt_address_t* addr)
{
if (!addr) {
return NULL;
}
bt_addr_ba2str(addr, g_bdaddr_str);
g_bdaddr_str[17] = '\0';
return g_bdaddr_str;
}
int bt_addr_str2ba(const char* str, bt_address_t* addr)
{
int i;
if (bachk(str) < 0) {
memset(addr, 0, sizeof(bt_address_t));
return -1;
}
for (i = 5; i >= 0; i--, str += 3)
addr->addr[i] = strtol(str, NULL, 16);
return 0;
}
void bt_addr_set(bt_address_t* addr, const uint8_t* bd)
{
memcpy(addr->addr, bd, 6);
}
void bt_addr_swap(const bt_address_t* src, bt_address_t* dest)
{
for (int i = 0; i < 6; i++)
dest->addr[5 - i] = src->addr[i];
}

View File

@ -0,0 +1,51 @@
/****************************************************************************
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include "bt_hash.h"
#define HASH4 h = ((h << 5) + h + *key++);
uint32_t bt_hash4(const void* keyarg, size_t len)
{
const uint8_t* key = keyarg;
uint32_t h = 0;
size_t loop;
if (len > 0) {
loop = (len + 8 - 1) >> 3;
switch (len & (8 - 1)) {
case 0:
do {
HASH4;
case 7:
HASH4;
case 6:
HASH4;
case 5:
HASH4;
case 4:
HASH4;
case 3:
HASH4;
case 2:
HASH4;
case 1:
HASH4;
} while (--loop);
}
}
return h;
}

224
framework/common/bt_list.c Normal file
View File

@ -0,0 +1,224 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include "bt_list.h"
typedef struct _bt_list {
struct list_node list;
size_t length;
bt_list_free_cb_t free_cb;
} bt_list_t;
typedef struct _bt_list_node {
struct list_node node;
void* data;
} bt_list_node_t;
bt_list_t* bt_list_new(bt_list_free_cb_t cb)
{
bt_list_t* list = malloc(sizeof(bt_list_t));
if (!list)
return NULL;
list->length = 0;
list->free_cb = cb;
list_initialize(&list->list);
return list;
}
void bt_list_free(bt_list_t* list)
{
if (!list)
return;
bt_list_clear(list);
list_delete(&list->list);
free(list);
}
void bt_list_clear(bt_list_t* list)
{
assert(list);
struct list_node* node;
struct list_node* tmp;
list_for_every_safe(&list->list, node, tmp)
{
bt_list_node_t* bt_node = (bt_list_node_t*)node;
list_delete(&bt_node->node);
if (list->free_cb)
list->free_cb(bt_node->data);
free(bt_node);
list->length--;
}
}
bool bt_list_is_empty(bt_list_t* list)
{
assert(list);
return list->length == 0;
}
size_t bt_list_length(bt_list_t* list)
{
assert(list);
return list->length;
}
bt_list_node_t* bt_list_head(bt_list_t* list)
{
assert(list);
return (bt_list_node_t*)list_peek_head(&list->list);
}
bt_list_node_t* bt_list_tail(bt_list_t* list)
{
assert(list);
return (bt_list_node_t*)list_peek_tail(&list->list);
}
bt_list_node_t* bt_list_next(bt_list_t* list, bt_list_node_t* bt_node)
{
assert(list);
if (!bt_node)
return NULL;
return (bt_list_node_t*)list_next(&list->list, &bt_node->node);
}
void* bt_list_node(bt_list_node_t* bt_node)
{
assert(bt_node);
if (!bt_node)
return NULL;
return bt_node->data;
}
void bt_list_add_head(bt_list_t* list, void* data)
{
assert(list);
bt_list_node_t* node = malloc(sizeof(bt_list_node_t));
assert(node);
node->data = data;
list_add_head(&list->list, &node->node);
list->length++;
}
void bt_list_add_tail(bt_list_t* list, void* data)
{
assert(list);
bt_list_node_t* node = malloc(sizeof(bt_list_node_t));
assert(node);
node->data = data;
list_add_tail(&list->list, &node->node);
list->length++;
}
void bt_list_remove_node(bt_list_t* list, bt_list_node_t* node)
{
list_delete(&node->node);
list->length--;
if (list->free_cb)
list->free_cb(node->data);
free(node);
}
void bt_list_remove(bt_list_t* list, void* data)
{
assert(list);
struct list_node* node;
struct list_node* tmp;
list_for_every_safe(&list->list, node, tmp)
{
bt_list_node_t* bt_node = (bt_list_node_t*)node;
if (bt_node->data == data) {
list_delete(&bt_node->node);
if (list->free_cb)
list->free_cb(bt_node->data);
free(bt_node);
list->length--;
break;
}
}
}
void bt_list_move(bt_list_t* src, bt_list_t* dst, void* data, bool move_to_head)
{
assert(src);
assert(dst);
struct list_node* node;
struct list_node* tmp;
list_for_every_safe(&src->list, node, tmp)
{
bt_list_node_t* bt_node = (bt_list_node_t*)node;
if (bt_node->data != data)
continue;
list_delete(&bt_node->node);
src->length--;
if (move_to_head) {
list_add_head(&dst->list, &bt_node->node);
} else {
list_add_tail(&dst->list, &bt_node->node);
}
dst->length++;
break;
}
}
void bt_list_foreach(bt_list_t* list, bt_list_iter_cb cb, void* context)
{
assert(list);
struct list_node* node;
struct list_node* tmp;
list_for_every_safe(&list->list, node, tmp)
{
bt_list_node_t* bt_node = (bt_list_node_t*)node;
cb(bt_node->data, context);
}
}
void* bt_list_find(bt_list_t* list, bt_list_find_cb cb, void* context)
{
assert(list);
struct list_node* node;
struct list_node* tmp;
list_for_every_safe(&list->list, node, tmp)
{
bt_list_node_t* bt_node = (bt_list_node_t*)node;
if (cb(bt_node->data, context))
return bt_node->data;
}
return NULL;
}

160
framework/common/bt_uuid.c Normal file
View File

@ -0,0 +1,160 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bt_utils.h"
#include "bt_uuid.h"
static const bt_uuid_t bt_uuid128_base = {
.type = BT_UUID128_TYPE,
.val.u128 = { 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
};
#define BASE_UUID16_OFFSET 12
#define BASE_UUID32_OFFSET 12
static void bt_uuid16_to_uuid128(const bt_uuid_t* uuid16, bt_uuid_t* uuid128)
{
uint8_t uuid[2];
uint8_t* p = uuid;
*uuid128 = bt_uuid128_base;
UINT16_TO_STREAM(p, uuid16->val.u16);
memcpy(&uuid128->val.u128[BASE_UUID16_OFFSET], uuid, sizeof(uuid));
}
static void bt_uuid32_to_uuid128(const bt_uuid_t* uuid32, bt_uuid_t* uuid128)
{
uint8_t uuid[4];
uint8_t* p = uuid;
*uuid128 = bt_uuid128_base;
UINT32_TO_STREAM(p, uuid32->val.u32);
memcpy(&uuid128->val.u128[BASE_UUID32_OFFSET], uuid, sizeof(uuid));
}
void bt_uuid_to_uuid128(const bt_uuid_t* src, bt_uuid_t* uuid128)
{
switch (src->type) {
case BT_UUID128_TYPE:
*uuid128 = *src;
break;
case BT_UUID32_TYPE:
bt_uuid32_to_uuid128(src, uuid128);
break;
case BT_UUID16_TYPE:
bt_uuid16_to_uuid128(src, uuid128);
break;
default:
break;
}
}
static int bt_uuid128_cmp(const bt_uuid_t* u1, const bt_uuid_t* u2)
{
return memcmp(&u1->val.u128, &u2->val.u128, 16);
}
int bt_uuid16_create(bt_uuid_t* uuid16, uint16_t value)
{
memset(uuid16, 0, sizeof(bt_uuid_t));
uuid16->type = BT_UUID16_TYPE;
uuid16->val.u16 = value;
return 0;
}
int bt_uuid32_create(bt_uuid_t* uuid32, uint32_t value)
{
memset(uuid32, 0, sizeof(bt_uuid_t));
uuid32->type = BT_UUID32_TYPE;
uuid32->val.u32 = value;
return 0;
}
int bt_uuid128_create(bt_uuid_t* uuid128, const uint8_t* value)
{
memset(uuid128, 0, sizeof(bt_uuid_t));
uuid128->type = BT_UUID128_TYPE;
memcpy(uuid128->val.u128, value, 16);
return 0;
}
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;
case BT_UUID32_TYPE: {
uint32_t val32;
STREAM_TO_UINT32(val32, data);
bt_uuid32_create(uuid, val32);
break;
}
case BT_UUID16_TYPE: {
uint16_t val16;
STREAM_TO_UINT32(val16, data);
bt_uuid16_create(uuid, val16);
break;
}
default:
return false;
}
return true;
}
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);
}
int bt_uuid_to_string(const bt_uuid_t* uuid, char* str, uint32_t len)
{
bt_uuid_t uuid128 = { 0 };
uint32_t tmp1, tmp5;
uint16_t tmp0, tmp2, tmp3, tmp4;
const uint8_t* p;
bt_uuid_to_uuid128(uuid, &uuid128);
p = (uint8_t*)&uuid128.val.u128;
STREAM_TO_UINT16(tmp0, p);
STREAM_TO_UINT32(tmp1, p);
STREAM_TO_UINT16(tmp2, p);
STREAM_TO_UINT16(tmp3, p);
STREAM_TO_UINT16(tmp4, p);
STREAM_TO_UINT32(tmp5, p);
snprintf(str, len, "%08" PRIx32 "-%04x-%04x-%04x-%08" PRIx32 "%04x", tmp5, tmp4, tmp3, tmp2, tmp1, tmp0);
return 0;
}

View File

@ -0,0 +1,165 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <assert.h>
#include <stdlib.h>
#include "callbacks_list.h"
static bool callback_is_found(void* data, void* context)
{
remote_callback_t* rcbk = data;
return rcbk->callbacks == context;
}
static bool remote_is_found(void* data, void* context)
{
remote_callback_t* rcbk = data;
return rcbk->remote == context;
}
callbacks_list_t* bt_callbacks_list_new(uint8_t max)
{
pthread_mutexattr_t attr;
callbacks_list_t* cbsl = malloc(sizeof(callbacks_list_t));
if (!cbsl)
return NULL;
cbsl->list = bt_list_new(free);
if (!cbsl->list) {
free(cbsl);
return NULL;
}
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
if (pthread_mutex_init(&cbsl->lock, &attr) < 0) {
bt_list_free(cbsl->list);
free(cbsl);
return NULL;
}
cbsl->max_reg = max;
cbsl->registed = 0;
return cbsl;
}
remote_callback_t* bt_callbacks_register(callbacks_list_t* cbsl, void* callbacks)
{
return bt_remote_callbacks_register(cbsl, NULL, callbacks);
}
bool bt_callbacks_unregister(callbacks_list_t* cbsl, remote_callback_t* rcbks)
{
return bt_remote_callbacks_unregister(cbsl, NULL, rcbks);
}
remote_callback_t* bt_remote_callbacks_register(callbacks_list_t* cbsl, void* remote, void* callbacks)
{
void* cbs;
remote_callback_t* remote_cbk;
assert(cbsl);
pthread_mutex_lock(&cbsl->lock);
if (cbsl->registed == cbsl->max_reg) {
pthread_mutex_unlock(&cbsl->lock);
return NULL;
}
if (remote)
cbs = bt_list_find(cbsl->list, remote_is_found, remote);
else
cbs = bt_list_find(cbsl->list, callback_is_found, callbacks);
if (cbs) {
pthread_mutex_unlock(&cbsl->lock);
return NULL;
}
remote_cbk = malloc(sizeof(*remote_cbk));
remote_cbk->remote = remote;
remote_cbk->callbacks = callbacks;
bt_list_add_tail(cbsl->list, remote_cbk);
cbsl->registed++;
pthread_mutex_unlock(&cbsl->lock);
return remote_cbk;
}
bool bt_remote_callbacks_unregister(callbacks_list_t* cbsl, void** remote, remote_callback_t* rcbks)
{
bt_list_node_t* node;
bt_list_t* list;
assert(cbsl);
list = cbsl->list;
pthread_mutex_lock(&cbsl->lock);
for (node = bt_list_head(list); node != NULL;
node = bt_list_next(list, node)) {
remote_callback_t* cbs = (remote_callback_t*)bt_list_node(node);
if (rcbks == cbs) {
cbsl->registed--;
if (remote)
*remote = cbs->remote;
bt_list_remove_node(list, node);
pthread_mutex_unlock(&cbsl->lock);
return true;
}
}
pthread_mutex_unlock(&cbsl->lock);
return false;
}
void bt_callbacks_foreach(callbacks_list_t* cbsl, void* context)
{
}
void bt_callbacks_list_free(void* data)
{
callbacks_list_t* cbsl = data;
if (!cbsl)
return;
pthread_mutex_lock(&cbsl->lock);
bt_list_free(cbsl->list);
pthread_mutex_unlock(&cbsl->lock);
pthread_mutex_destroy(&cbsl->lock);
free(cbsl);
}
uint8_t bt_callbacks_list_count(callbacks_list_t* cbsl)
{
uint8_t registed;
assert(cbsl);
pthread_mutex_lock(&cbsl->lock);
registed = cbsl->registed;
pthread_mutex_unlock(&cbsl->lock);
return registed;
}

198
framework/common/euv_pty.c Normal file
View File

@ -0,0 +1,198 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include "uv.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "euv_pty.h"
typedef struct _euv_pty {
uv_tty_t uv_tty;
} euv_pty_t;
typedef struct {
uv_write_t req;
uint8_t* buffer;
euv_write_cb write_cb;
} euv_wreq_t;
typedef struct {
euv_read_cb read_cb;
euv_alloc_cb alloc_cb;
uint16_t read_size;
} euv_read_t;
static void uv_close_callback(uv_handle_t* handle)
{
if (handle->data)
free(handle->data);
free(handle);
}
static void uv_alloc_callback(uv_handle_t* handle, size_t size, uv_buf_t* buf)
{
if (!handle->data)
return;
euv_read_t* reader = (euv_read_t*)handle->data;
if (reader->alloc_cb)
reader->alloc_cb((euv_pty_t*)handle, (uint8_t**)&buf->base, &buf->len);
else {
buf->base = malloc(reader->read_size);
buf->len = reader->read_size;
}
}
static void uv_read_callback(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf)
{
if (!stream->data)
return;
euv_read_t* reader = (euv_read_t*)stream->data;
/*if read stopped in read callback, will free reader struct*/
bool release = !reader->alloc_cb;
if (reader->read_cb)
reader->read_cb((euv_pty_t*)stream, (const uint8_t*)buf->base, nread);
if (release)
free(buf->base);
}
static void uv_write_callback(uv_write_t* req, int status)
{
euv_wreq_t* wreq = (euv_wreq_t*)req;
if (wreq->write_cb)
wreq->write_cb((euv_pty_t*)wreq->req.data, wreq->buffer, status);
free(wreq);
}
static int euv_pty_read_start_(euv_pty_t* handle, uint16_t read_size, euv_read_cb read_cb, euv_alloc_cb alloc_cb)
{
euv_read_t* reader;
int ret;
if (uv_is_active((uv_handle_t*)&handle->uv_tty))
return 0;
reader = malloc(sizeof(euv_read_t));
if (reader == NULL)
return -ENOMEM;
reader->read_cb = read_cb;
reader->alloc_cb = alloc_cb;
reader->read_size = read_size;
handle->uv_tty.data = reader;
ret = uv_read_start((uv_stream_t*)&handle->uv_tty, uv_alloc_callback, uv_read_callback);
if (ret != 0) {
handle->uv_tty.data = NULL;
free(reader);
}
return ret;
}
int euv_pty_read_start(euv_pty_t* handle, uint16_t read_size, euv_read_cb cb)
{
return euv_pty_read_start_(handle, read_size, cb, NULL);
}
int euv_pty_read_start2(euv_pty_t* handle, uint16_t read_size, euv_read_cb read_cb, euv_alloc_cb alloc_cb)
{
return euv_pty_read_start_(handle, read_size, read_cb, alloc_cb);
}
int euv_pty_read_stop(euv_pty_t* handle)
{
if (handle == NULL)
return -EINVAL;
free(handle->uv_tty.data);
handle->uv_tty.data = NULL;
if (uv_is_active((uv_handle_t*)&handle->uv_tty))
return uv_read_stop((uv_stream_t*)&handle->uv_tty);
return 0;
}
int euv_pty_write(euv_pty_t* handle, uint8_t* buffer, int length, euv_write_cb cb)
{
uv_buf_t buf;
euv_wreq_t* wreq;
int ret;
if (handle == NULL)
return -EINVAL;
wreq = (euv_wreq_t*)malloc(sizeof(euv_wreq_t));
if (!wreq)
return -ENOMEM;
wreq->req.data = (void*)handle;
wreq->buffer = buffer;
wreq->write_cb = cb;
buf = uv_buf_init((char*)buffer, length);
ret = uv_write(&wreq->req, (uv_stream_t*)&handle->uv_tty, &buf, 1, uv_write_callback);
if (ret != 0)
free(wreq);
return ret;
}
euv_pty_t* euv_pty_init(uv_loop_t* loop, int fd, uv_tty_mode_t mode)
{
euv_pty_t* handle;
int ret;
if (loop == NULL || fd < 0)
return NULL;
handle = (euv_pty_t*)malloc(sizeof(euv_pty_t));
if (!handle)
return NULL;
memset(handle, 0, sizeof(euv_pty_t));
ret = uv_tty_init(loop, &handle->uv_tty, fd, 1);
if (ret != 0) {
free(handle);
return NULL;
}
// set mode
ret = uv_tty_set_mode(&handle->uv_tty, mode);
return handle;
}
void euv_pty_close(euv_pty_t* hdl)
{
if (hdl == NULL)
return;
uv_close((uv_handle_t*)&hdl->uv_tty, uv_close_callback);
}

View File

@ -0,0 +1,99 @@
/****************************************************************************
* 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 "state_machine.h"
void hsm_ctor(state_machine_t* sm, const state_t* initial_state)
{
if (sm == NULL)
return;
sm->initial_state = initial_state;
sm->current_state = NULL;
sm->previous_state = NULL;
hsm_transition_to(sm, sm->initial_state);
}
void hsm_dtor(state_machine_t* sm)
{
(void)sm;
}
void hsm_transition_to(state_machine_t* sm, const state_t* state)
{
if (sm->current_state != NULL) {
sm->current_state->exit(sm);
sm->previous_state = sm->current_state;
}
sm->current_state = (state_t*)state;
sm->current_state->enter(sm);
}
const state_t* hsm_get_current_state(state_machine_t* sm)
{
if (!sm) {
return NULL;
}
return sm->current_state;
}
const state_t* hsm_get_previous_state(state_machine_t* sm)
{
if (!sm) {
return NULL;
}
return sm->previous_state;
}
const char* hsm_get_current_state_name(state_machine_t* sm)
{
if (!sm) {
return NULL;
}
return sm->current_state->state_name;
}
const char* hsm_get_state_name(const state_t* state)
{
if (!state) {
return NULL;
}
return state->state_name;
}
uint16_t hsm_get_state_value(const state_t* state)
{
return state->state_value;
}
uint16_t hsm_get_current_state_value(state_machine_t* sm)
{
return sm->current_state->state_value;
}
bool hsm_dispatch_event(state_machine_t* sm, uint32_t event, void* p_data)
{
if (sm->current_state == NULL) {
return false;
}
return sm->current_state->process_event(sm, event, p_data);
}

View File

@ -0,0 +1,337 @@
/****************************************************************************
* 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 __NuttX__
#define _GNU_SOURCE
#endif
#define LOG_TAG "thread_loop"
#include <assert.h>
#include <pthread.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#include "bt_config.h"
#include "bt_list.h"
#include "uv_thread_loop.h"
typedef struct thread_loop {
char name[64];
uv_async_t async;
uv_thread_t thread;
uv_mutex_t msg_lock;
uv_sem_t ready;
uv_sem_t exited;
uint8_t is_running;
struct list_node msg_queue;
} loop_priv_t;
typedef struct {
struct list_node node;
union {
thread_func_t func;
};
void* msg;
} internel_msg_t;
typedef struct {
thread_func_t func;
void* data;
uv_sem_t signal;
} signal_msg_t;
#if defined(ANDROID)
#define LOOP_THREAD_STACK_SIZE 40960
#else
#define LOOP_THREAD_STACK_SIZE 4096
#endif
static void set_ready(void* data)
{
loop_priv_t* priv = data;
priv->is_running = 1;
uv_sem_init(&priv->exited, 0);
uv_sem_post(&priv->ready);
syslog(LOG_DEBUG, "set_ready");
}
static void set_stop(void* data)
{
uv_loop_t* loop = data;
loop_priv_t* priv = loop->data;
priv->is_running = 0;
uv_close((uv_handle_t*)&priv->async, NULL);
uv_stop(loop);
syslog(LOG_DEBUG, "set_stopped");
}
static void thread_sync_callback(void* data)
{
signal_msg_t* msg = (signal_msg_t*)data;
msg->func(msg->data);
uv_sem_post(&msg->signal);
}
static void thread_message_callback(uv_async_t* handle)
{
internel_msg_t* imsg;
loop_priv_t* priv = handle->data;
for (;;) {
uv_mutex_lock(&priv->msg_lock);
imsg = (internel_msg_t*)list_remove_head(&priv->msg_queue);
uv_mutex_unlock(&priv->msg_lock);
if (!imsg)
return;
imsg->func(imsg->msg);
free(imsg);
}
}
static void thread_schedule_loop(void* data)
{
uv_loop_t* loop = data;
loop_priv_t* priv = loop->data;
int ret = uv_async_init(loop, &priv->async, thread_message_callback);
if (ret != 0) {
syslog(LOG_ERR, "%s async error: %d", __func__, ret);
return;
}
priv->async.data = priv;
syslog(LOG_DEBUG, "%s:%p, async:%p", __func__, loop, &priv->async);
do_in_thread_loop(loop, set_ready, priv);
uv_run(loop, UV_RUN_DEFAULT);
priv->is_running = 0;
(void)uv_loop_close(loop);
syslog(LOG_DEBUG, "%s %s quit", priv->name, __func__);
uv_sem_post(&priv->exited);
}
static void handle_close_cb(uv_handle_t* handle)
{
free(handle);
}
int thread_loop_init(uv_loop_t* loop)
{
int ret;
loop_priv_t* priv = malloc(sizeof(loop_priv_t));
if (!priv)
return -ENOMEM;
priv->is_running = 0;
ret = uv_mutex_init(&priv->msg_lock);
if (ret != 0) {
free(priv);
syslog(LOG_ERR, "%s mutex error: %d", __func__, ret);
return ret;
}
list_initialize(&priv->msg_queue);
ret = uv_loop_init(loop);
if (ret != 0) {
list_delete(&priv->msg_queue);
uv_mutex_destroy(&priv->msg_lock);
free(priv);
return ret;
}
loop->data = priv;
return 0;
}
int thread_loop_run(uv_loop_t* loop, bool start_thread, const char* name)
{
loop_priv_t* priv = loop->data;
if (start_thread) {
int ret = uv_sem_init(&priv->ready, 0);
if (ret != 0) {
syslog(LOG_ERR, "%s sem init error: %d", __func__, ret);
return ret;
}
uv_thread_options_t options = {
UV_THREAD_HAS_STACK_SIZE | UV_THREAD_HAS_PRIORITY,
LOOP_THREAD_STACK_SIZE,
CONFIG_BLUETOOTH_SERVICE_LOOP_THREAD_PRIORITY
};
ret = uv_thread_create_ex(&priv->thread, &options, thread_schedule_loop, (void*)loop);
if (ret != 0) {
syslog(LOG_ERR, "loop thread create :%d", ret);
return ret;
}
if (name != NULL && strlen(name) > 0)
snprintf(priv->name, sizeof(priv->name), "%s_%d", name, getpid());
else
snprintf(priv->name, sizeof(priv->name), "loop_%d", getpid());
pthread_setname_np(priv->thread, priv->name);
uv_sem_wait(&priv->ready);
uv_sem_destroy(&priv->ready);
syslog(LOG_DEBUG, "%s loop running now !!!", priv->name);
} else {
syslog(LOG_DEBUG, "%s loop running now !!!", name);
thread_schedule_loop(NULL);
}
return 0;
}
void thread_loop_exit(uv_loop_t* loop)
{
struct list_node* node;
struct list_node* tmp;
if (!loop || !loop->data)
return;
loop_priv_t* priv = loop->data;
if (priv->is_running) {
do_in_thread_loop(loop, set_stop, (void*)loop);
uv_sem_wait(&priv->exited);
uv_sem_destroy(&priv->exited);
} else {
uv_run(loop, UV_RUN_ONCE);
(void)uv_loop_close(loop);
}
uv_mutex_lock(&priv->msg_lock);
list_for_every_safe(&priv->msg_queue, node, tmp)
{
list_delete(node);
free(node);
}
list_delete(&priv->msg_queue);
uv_mutex_unlock(&priv->msg_lock);
uv_mutex_destroy(&priv->msg_lock);
free(priv);
}
uv_poll_t* thread_loop_poll_fd(uv_loop_t* loop, int fd, int pevents, uv_poll_cb cb, void* userdata)
{
assert(fd);
assert(cb);
uv_poll_t* handle = (uv_poll_t*)malloc(sizeof(uv_poll_t));
if (!handle)
return NULL;
handle->data = userdata;
int ret = uv_poll_init(loop, handle, fd);
if (ret != 0)
goto error;
ret = uv_poll_start(handle, pevents, cb);
if (ret != 0)
goto error;
return handle;
error:
syslog(LOG_ERR, "%s failed: %d", __func__, ret);
free(handle);
return NULL;
}
int thread_loop_reset_poll(uv_poll_t* poll, int pevents, uv_poll_cb cb)
{
assert(poll);
uv_poll_stop(poll);
return uv_poll_start(poll, pevents, cb);
}
void thread_loop_remove_poll(uv_poll_t* poll)
{
if (!poll)
return;
uv_poll_stop(poll);
uv_close((uv_handle_t*)poll, handle_close_cb);
}
uv_timer_t* thread_loop_timer(uv_loop_t* loop, uint64_t timeout, uint64_t repeat, uv_timer_cb cb, void* userdata)
{
if (!cb)
return NULL;
uv_timer_t* handle = malloc(sizeof(uv_timer_t));
if (!handle)
return NULL;
uv_timer_init(loop, handle);
handle->data = userdata;
uv_timer_start(handle, cb, timeout, repeat);
return handle;
}
uv_timer_t* thread_loop_timer_no_repeating(uv_loop_t* loop, uint64_t timeout, uv_timer_cb cb, void* userdata)
{
return thread_loop_timer(loop, timeout, 0, cb, userdata);
}
void thread_loop_cancel_timer(uv_timer_t* timer)
{
if (!timer)
return;
uv_timer_stop(timer);
uv_close((uv_handle_t*)timer, handle_close_cb);
}
void do_in_thread_loop(uv_loop_t* loop, thread_func_t func, void* data)
{
loop_priv_t* priv = loop->data;
internel_msg_t* msg = (internel_msg_t*)malloc(sizeof(internel_msg_t));
assert(msg);
msg->func = func;
msg->msg = data;
uv_mutex_lock(&priv->msg_lock);
list_add_tail(&priv->msg_queue, &msg->node);
uv_mutex_unlock(&priv->msg_lock);
uv_async_send(&priv->async);
}
void do_in_thread_loop_sync(uv_loop_t* loop, thread_func_t func, void* data)
{
signal_msg_t msg;
msg.func = func;
msg.data = data;
uv_sem_init(&msg.signal, 0);
do_in_thread_loop(loop, thread_sync_callback, &msg);
uv_sem_wait(&msg.signal);
uv_sem_destroy(&msg.signal);
}

0
framework/dbus/dbus.h Normal file
View File

View File

@ -0,0 +1,115 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#ifndef __ADVERTISER_DATA_H__
#define __ADVERTISER_DATA_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
#include "bt_uuid.h"
#define BT_AD_FLAGS 0x01 /* Flags */
#define BT_AD_UUID16_SOME 0x02 /* Incomplete List of 16­bit Service Class UUIDs */
#define BT_AD_UUID16_ALL 0x03 /* Complete List of 16­bit Service Class UUIDs */
#define BT_AD_UUID32_SOME 0x04 /* Incomplete List of 32­bit Service Class UUIDs */
#define BT_AD_UUID32_ALL 0x05 /* Complete List of 32­bit Service Class UUIDs */
#define BT_AD_UUID128_SOME 0x06 /* Incomplete List of 128­bit Service Class UUIDs */
#define BT_AD_UUID128_ALL 0x07 /* Complete List of 128­bit Service Class UUIDs */
#define BT_AD_NAME_SHORT 0x08 /* Shortened Local Name */
#define BT_AD_NAME_COMPLETE 0x09 /* Complete Local Name */
#define BT_AD_TX_POWER 0x0a /* Tx Power Level */
#define BT_AD_CLASS_OF_DEV 0x0d /* Class of Device */
#define BT_AD_SSP_HASH 0x0e /* Simple Pairing Hash C­192 */
#define BT_AD_SSP_RANDOMIZER 0x0f /* Simple Pairing Randomizer R­192 */
#define BT_AD_DEVICE_ID 0x10 /* Device ID */
#define BT_AD_SMP_TK 0x10 /* Security Manager TK Value */
#define BT_AD_SMP_OOB_FLAGS 0x11 /* Security Manager Out of Band Flags */
#define BT_AD_PERIPHERAL_CONN_INTERVAL 0x12 /* Peripheral Connection Interval Range */
#define BT_AD_SOLICIT16 0x14 /* List of 16­bit Service Solicitation UUIDs */
#define BT_AD_SOLICIT128 0x15 /* List of 128­bit Service Solicitation UUIDs */
#define BT_AD_SERVICE_DATA16 0x16 /* Service Data ­ 16­bit UUID */
#define BT_AD_PUBLIC_ADDRESS 0x17 /* Public Target Address */
#define BT_AD_RANDOM_ADDRESS 0x18 /* Random Target Address */
#define BT_AD_GAP_APPEARANCE 0x19 /* Appearance */
#define BT_AD_ADVERTISING_INTERVAL 0x1a /* Advertising Interval */
#define BT_AD_LE_DEVICE_ADDRESS 0x1b /* LE Bluetooth Device Address */
#define BT_AD_LE_ROLE 0x1c /* LE Role */
#define BT_AD_SSP_HASH_P256 0x1d /* Simple Pairing Hash C­256 */
#define BT_AD_SSP_RANDOMIZER_P256 0x1e /* Simple Pairing Randomizer R­256 */
#define BT_AD_SOLICIT32 0x1f /* List of 32­bit Service Solicitation UUIDs */
#define BT_AD_SERVICE_DATA32 0x20 /* Service Data ­ 32­bit UUID */
#define BT_AD_SERVICE_DATA128 0x21 /* Service Data ­ 128­bit UUID */
#define BT_AD_LE_SC_CONFIRM_VALUE 0x22 /* LE Secure Connections Confirmation Value */
#define BT_AD_LE_SC_RANDOM_VALUE 0x23 /* LE Secure Connections Random Value */
#define BT_AD_URI 0x24 /* URI */
#define BT_AD_INDOOR_POSITIONING 0x25 /* Indoor Positioning */
#define BT_AD_TRANSPORT_DISCOVERY 0x26 /* Transport Discovery Data */
#define BT_AD_LE_SUPPORTED_FEATURES 0x27 /* LE Supported Features */
#define BT_AD_CHANNEL_MAP_UPDATE_IND 0x28 /* Channel Map Update Indication */
#define BT_AD_MESH_PROV 0x29 /* PB­ADV */
#define BT_AD_MESH_DATA 0x2a /* Mesh Message */
#define BT_AD_MESH_BEACON 0x2b /* Mesh Beacon */
#define BT_AD_BIG_INFO 0x2C /* BIGInfo */
#define BT_AD_BROADCAST_CODE 0x2D /* Broadcast_Code */
#define BT_AD_RESOLVABLE_SET_IDENTIFIER 0x2E /* Resolvable Set Identifier */
#define BT_AD_ADV_INTERVAL_LONG 0x2F /* Advertising Interval ­ long */
#define BT_AD_BROADCAST_NAME 0x30 /* Broadcast_Name */
#define BT_AD_ENCRYPTED_ADV_DATA 0x31 /* Encrypted Advertising Data */
#define BT_AD_PERIODIC_ADV_RSP_TIMING 0x32 /* Periodic Advertising Response Timing Information */
#define BT_AD_3D_INFO_DATA 0x3d /* 3D Information Data */
#define BT_AD_MANUFACTURER_DATA 0xff /* Manufacturer Specific Data */
#define BT_LE_AD_NAME_LEN 29
#define BT_AD_FLAG_LIMITED_DISCOVERABLE 1
#define BT_AD_FLAG_GENERAL_DISCOVERABLE 2
#define BT_AD_FLAG_BREDR_NOT_SUPPORT 4
#define BT_AD_FLAG_DUAL_MODE 8
typedef struct adv_data {
uint8_t len;
uint8_t type;
uint8_t data[0];
} adv_data_t;
typedef struct advertiser_data_ advertiser_data_t;
typedef void (*ad_dump_cb_t)(const char* str);
bool advertiser_data_dump(uint8_t* data, uint16_t len, ad_dump_cb_t dump);
advertiser_data_t* advertiser_data_new(void);
void advertiser_data_free(advertiser_data_t* ad);
uint8_t* advertiser_data_build(advertiser_data_t* ad, uint16_t* len);
void advertiser_data_set_name(advertiser_data_t* ad, const char* name);
void advertiser_data_set_flags(advertiser_data_t* ad, uint8_t flags);
void advertiser_data_set_appearance(advertiser_data_t* ad, uint16_t appearance);
void advertiser_data_add_data(advertiser_data_t* ad, uint8_t type, uint8_t* data, uint8_t len);
void advertiser_data_remove_data(advertiser_data_t* ad, uint8_t type, uint8_t* data, uint8_t len);
void advertiser_data_add_manufacture_data(advertiser_data_t* ad,
uint16_t manufacture_id,
uint8_t* data, uint8_t length);
bool advertiser_data_add_service_uuid(advertiser_data_t* ad, const bt_uuid_t* uuid);
bool advertiser_data_add_service_data(advertiser_data_t* ad,
const bt_uuid_t* uuid,
uint8_t* data, uint8_t len);
#ifdef __cplusplus
}
#endif
#endif /* __ADVERTISER_DATA_H__ */

View File

@ -0,0 +1,516 @@
/****************************************************************************
* 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_BLUETOOTH_H__
#define _BT_BLUETOOTH_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <uv.h>
#include "bt_addr.h"
#include "bt_config.h"
#include "bt_list.h"
#include "bt_profile.h"
#include "bt_status.h"
#include "bt_uuid.h"
#include "callbacks_list.h"
#include "uv_thread_loop.h"
#ifndef BTSYMBOLS
#define BTSYMBOLS(s) s
#endif
#if defined(CONFIG_CPU_BIT64) // CONFIG_CPU_BIT64
#define PTR uint64_t
#define PRTx PRIx64
#if !defined(INT2PTR)
#define INT2PTR(pt) (pt)(uint64_t) // For example, INT2PTR(pt)(int): (int)=>uint64_t=>(pt)/pointer type
#endif
#if !defined(PTR2INT)
#define PTR2INT(it) (it)(uint64_t) // For example, PTR2INT(it)(pointer): (pointer)=>uint64_t=>(it)/int type
#endif
#else // CONFIG_CPU_BIT32 and others
#define PTR uint32_t
#define PRTx PRIx32
#if !defined(INT2PTR)
#define INT2PTR(pt) (pt)(uint32_t) // For example, INT2PTR(pt)(int): (int)=>uint32_t=>(pt)/pointer type
#endif
#if !defined(PTR2INT)
#define PTR2INT(it) (it)(uint32_t) // For example, PTR2INT(it)(pointer): (pointer)=>uint32_t=>(it)/int type
#endif
#endif // End of else
typedef enum {
BT_IO_CAPABILITY_DISPLAYONLY = 0,
BT_IO_CAPABILITY_DISPLAYYESNO,
BT_IO_CAPABILITY_KEYBOARDONLY,
BT_IO_CAPABILITY_NOINPUTNOOUTPUT,
BT_IO_CAPABILITY_KEYBOARDDISPLAY,
BT_IO_CAPABILITY_UNKNOW = 0xFF
} bt_io_capability_t;
#ifndef ANDROID_LIBBLUETOOTH
/*
* hardware/libhardware/include/hardware/bluetooth.h
* This definition was copied from Android 13.
* DON NOT MODIFY IT !!!
*/
typedef enum {
BT_SCAN_MODE_NONE,
BT_SCAN_MODE_CONNECTABLE,
BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE
} bt_scan_mode_t;
#endif
// Rename the definition
#define BT_BR_SCAN_MODE_NONE BT_SCAN_MODE_NONE
#define BT_BR_SCAN_MODE_CONNECTABLE BT_SCAN_MODE_CONNECTABLE
#define BT_BR_SCAN_MODE_CONNECTABLE_DISCOVERABLE BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE
typedef enum {
BT_BR_SCAN_TYPE_STANDARD,
BT_BR_SCAN_TYPE_INTERLACED,
BT_BR_SCAN_TYPE_UNKNOWN = 0xFF
} bt_scan_type_t;
#ifndef ANDROID_LIBBLUETOOTH
/*
* hardware/libhardware/include/hardware/bluetooth.h
* This definition was copied from Android 13.
* DON NOT MODIFY IT !!!
*/
typedef enum {
BT_DISCOVERY_STOPPED,
BT_DISCOVERY_STARTED
} bt_discovery_state_t;
#endif
// Rename the definition
#define BT_DISCOVERY_STATE_STOPPED BT_DISCOVERY_STOPPED
#define BT_DISCOVERY_STATE_STARTED BT_DISCOVERY_STARTED
typedef enum {
BT_BR_FILTER_CLEAR_ALL,
BT_BR_FILTER_INQUIRY_RESULT,
BT_BR_FILTER_CONNECTION_SETUP
} bt_filter_type_t;
/* * HCI Event Filter - Filter Condition Type */
typedef enum {
BT_BR_FILTER_CONDITION_ALL_DEVICES,
BT_BR_FILTER_CONDITION_DEVICE_CLASS,
BT_BR_FILTER_CONDITION_BDADDR,
BT_BR_FILTER_CONDITION_RSSI,
BT_BR_FILTER_CONDITION_UUIDS
} bt_filter_condition_type_t;
typedef enum {
BT_LINK_ROLE_MASTER,
BT_LINK_ROLE_SLAVE,
BT_LINK_ROLE_UNKNOWN
} bt_link_role_t;
typedef enum {
BT_LINK_MODE_ACTIVE,
BT_LINK_MODE_SNIFF,
BT_LINK_MODE_UNKNOWN,
} bt_link_mode_t;
typedef enum {
BT_BR_LINK_POLICY_DISABLE_ALL,
BT_BR_LINK_POLICY_ENABLE_ROLE_SWITCH,
BT_BR_LINK_POLICY_ENABLE_SNIFF,
BT_BR_LINK_POLICY_ENABLE_ROLE_SWITCH_AND_SNIFF
} bt_link_policy_t;
typedef enum {
PAIR_TYPE_PASSKEY_CONFIRMATION = 0,
PAIR_TYPE_PASSKEY_ENTRY,
PAIR_TYPE_CONSENT,
PAIR_TYPE_PASSKEY_NOTIFICATION,
PAIR_TYPE_PIN_CODE,
} bt_pair_type_t;
typedef enum {
BT_TRANSPORT_BLE,
BT_TRANSPORT_BREDR
} bt_transport_t;
#ifndef ANDROID_LIBBLUETOOTH
/*
* hardware/libhardware/include/hardware/bluetooth.h
* This definition was copied from Android 13.
* DON NOT MODIFY IT !!!
*/
typedef enum {
BT_DEVICE_DEVTYPE_BREDR = 0x1,
BT_DEVICE_DEVTYPE_BLE,
BT_DEVICE_DEVTYPE_DUAL
} bt_device_type_t;
#endif
// Rename the definition
#define BT_DEVICE_TYPE_BREDR BT_DEVICE_DEVTYPE_BREDR
#define BT_DEVICE_TYPE_BLE BT_DEVICE_DEVTYPE_BLE
#define BT_DEVICE_TYPE_DUAL BT_DEVICE_DEVTYPE_DUAL
// Add new definition
#define BT_DEVICE_TYPE_UNKNOW 0xFF
typedef enum {
BT_LE_ADDR_TYPE_PUBLIC,
BT_LE_ADDR_TYPE_RANDOM,
BT_LE_ADDR_TYPE_PUBLIC_ID,
BT_LE_ADDR_TYPE_RANDOM_ID,
BT_LE_ADDR_TYPE_ANONYMOUS,
BT_LE_ADDR_TYPE_UNKNOWN = 0xFF
} ble_addr_type_t;
/* * BLE PHY type */
typedef enum {
BT_LE_1M_PHY,
BT_LE_2M_PHY,
BT_LE_CODED_PHY
} ble_phy_type_t;
typedef enum {
BT_LE_CONNECT_FILTER_POLICY_ADDR,
BT_LE_CONNECT_FILTER_POLICY_WHITE_LIST
} ble_connect_filter_policy_t;
typedef uint8_t bt_128key_t[16];
#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 */
#define COD_SERVICE_LDM 0x002000 /* Limited Discoverable Mode */
#define COD_SERVICE_POSITION 0x010000 /* Positioning (Location identification) */
#define COD_SERVICE_NETWORK 0x020000 /* Networking (LAN, Ad hoc, ...) */
#define COD_SERVICE_RENDERING 0x040000 /* Rending (Printing, Speaker, ...) */
#define COD_SERVICE_CAPTURING 0x080000 /* Capturing (Scanner, Microphone, ...) */
#define COD_SERVICE_OBJECT 0x100000 /* Object Transfer (v-Inbox, v-Folder, ...) */
#define COD_SERVICE_AUDIO 0x200000 /* Audio (Speaker, Microphone, Headset service, ...) */
#define COD_SERVICE_TELEPHONY 0x400000 /* Telephony (Cordless telephony, Modem, Headset service, ...) */
#define COD_SERVICE_INFORMATION 0x800000 /* Information (WEB-server, WAP-server, ...) */
/* * Major Device Classes bit mask */
#define COD_DEVICE_MISCELLANEOUS 0x000000 /* Major Device Class - Miscellaneous */
#define COD_DEVICE_COMPUTER 0x000100 /* Major Device Class - Computer (desktop, notebook, PDA, organizers, ...) */
#define COD_DEVICE_PHONE 0x000200 /* Major Device Class - Phone (cellular, cordless, payphone, modem, ...) */
#define COD_DEVICE_LAP 0x000300 /* Major Device Class - LAN/Network Access Point */
#define COD_DEVICE_AV 0x000400 /* Major Device Class - Audio/Video (headset, speaker, stereo, video display, vcr...) */
#define COD_DEVICE_PERIPHERAL 0x000500 /* Major Device Class - Peripheral (mouse, joystick, keyboards, ...) */
#define COD_DEVICE_IMAGING 0x000600 /* Major Device Class - Imaging (printing, scanner, camera, display, ...) */
#define COD_DEVICE_WEARABLE 0x000700 /* Major Device Class - Wearable */
#define COD_DEVICE_TOY 0x000800 /* Major Device Class - Toy */
#define COD_DEVICE_HEALTH 0x000900 /* Major Device Class - Health */
#define COD_DEVICE_UNCLASSIFIED 0x001F00 /* Major Device Class - Uncategorized, specific device code not specified */
/* * Minor Device Class - Computer major class */
#define COD_COMPUTER_UNCLASSIFIED (COD_DEVICE_COMPUTER | 0x000000)
#define COD_COMPUTER_DESKTOP (COD_DEVICE_COMPUTER | 0x000004)
#define COD_COMPUTER_SERVER (COD_DEVICE_COMPUTER | 0x000008)
#define COD_COMPUTER_LAPTOP (COD_DEVICE_COMPUTER | 0x00000C)
#define COD_COMPUTER_HANDHELD (COD_DEVICE_COMPUTER | 0x000010)
#define COD_COMPUTER_PALMSIZED (COD_DEVICE_COMPUTER | 0x000014)
#define COD_COMPUTER_WEARABLE (COD_DEVICE_COMPUTER | 0x000018)
/* * Minor Device Class - Phone major class */
#define COD_PHONE_UNCLASSIFIED (COD_DEVICE_PHONE | 0x000000)
#define COD_PHONE_CELLULAR (COD_DEVICE_PHONE | 0x000004)
#define COD_PHONE_CORDLESS (COD_DEVICE_PHONE | 0x000008)
#define COD_PHONE_SMARTPHONE (COD_DEVICE_PHONE | 0x00000C)
#define COD_PHONE_WIREDMODEM (COD_DEVICE_PHONE | 0x000010)
#define COD_PHONE_COMMONISDNACCESS (COD_DEVICE_PHONE | 0x000014)
#define COD_PHONE_SIMCARDREADER (COD_DEVICE_PHONE | 0x000018)
/* * Minor Device Class - LAN/Network access point major class */
#define COD_LAP_FULLY_AVAILABLE (COD_DEVICE_LAP | 0x000000)
#define COD_LAP_17_UTILIZED (COD_DEVICE_LAP | 0x000020)
#define COD_LAP_33_UTILIZED (COD_DEVICE_LAP | 0x000040)
#define COD_LAP_50_UTILIZED (COD_DEVICE_LAP | 0x000060)
#define COD_LAP_67_UTILIZED (COD_DEVICE_LAP | 0x000080)
#define COD_LAP_83_UTILIZED (COD_DEVICE_LAP | 0x0000A0)
#define COD_LAP_99_UTILIZED (COD_DEVICE_LAP | 0x0000C0)
#define COD_LAP_UNAVAILABLE (COD_DEVICE_LAP | 0x0000E0)
/* * Minor Device Class - Audio/Video major class */
#define COD_AV_UNCLASSIFIED (COD_DEVICE_AV | 0x000000)
#define COD_AV_HEADSET (COD_DEVICE_AV | 0x000004)
#define COD_AV_HANDSFREE (COD_DEVICE_AV | 0x000008)
#define COD_AV_HEADANDHAND (COD_DEVICE_AV | 0x00000C)
#define COD_AV_MICROPHONE (COD_DEVICE_AV | 0x000010)
#define COD_AV_LOUD_SPEAKER (COD_DEVICE_AV | 0x000014)
#define COD_AV_HEADPHONES (COD_DEVICE_AV | 0x000018)
#define COD_AV_PORTABLE_AUDIO (COD_DEVICE_AV | 0x00001C)
#define COD_AV_CAR_AUDIO (COD_DEVICE_AV | 0x000020)
#define COD_AV_SETTOPBOX (COD_DEVICE_AV | 0x000024)
#define COD_AV_HIFI_AUDIO (COD_DEVICE_AV | 0x000028)
#define COD_AV_VCR (COD_DEVICE_AV | 0x00002C)
#define COD_AV_VIDEO_CAMERA (COD_DEVICE_AV | 0x000030)
#define COD_AV_CAMCORDER (COD_DEVICE_AV | 0x000034)
#define COD_AV_VIDEO_MONITOR (COD_DEVICE_AV | 0x000038)
#define COD_AV_DISPLAY_AND_SPEAKER (COD_DEVICE_AV | 0x00003C)
#define COD_AV_VIDEO_CONFERENCING (COD_DEVICE_AV | 0x000040)
#define COD_AV_GAME_OR_TOY (COD_DEVICE_AV | 0x000048)
/* * Minor Device Class - Peripheral major class */
#define COD_PERIPHERAL_UNCLASSIFIED (COD_DEVICE_PERIPHERAL | 0x000000)
#define COD_PERIPHERAL_JOYSTICK (COD_DEVICE_PERIPHERAL | 0x000004)
#define COD_PERIPHERAL_GAMEPAD (COD_DEVICE_PERIPHERAL | 0x000008)
#define COD_PERIPHERAL_REMCONTROL (COD_DEVICE_PERIPHERAL | 0x00000C)
#define COD_PERIPHERAL_SENSE (COD_DEVICE_PERIPHERAL | 0x000010)
#define COD_PERIPHERAL_TABLET (COD_DEVICE_PERIPHERAL | 0x000014)
#define COD_PERIPHERAL_SIMCARDREADER (COD_DEVICE_PERIPHERAL | 0x000018)
#define COD_PERIPHERAL_KEYBOARD (COD_DEVICE_PERIPHERAL | 0x000040)
#define COD_PERIPHERAL_POINT (COD_DEVICE_PERIPHERAL | 0x000080)
#define COD_PERIPHERAL_KEYORPOINT (COD_DEVICE_PERIPHERAL | 0x0000C0)
/* * Minor Device Class - Imaging major class */
#define COD_IMAGING_DISPLAY (COD_DEVICE_IMAGING | 0x000010)
#define COD_IMAGING_CAMERA (COD_DEVICE_IMAGING | 0x000020)
#define COD_IMAGING_SCANNER (COD_DEVICE_IMAGING | 0x000040)
#define COD_IMAGING_PRINTER (COD_DEVICE_IMAGING | 0x000080)
/* * Minor Device Class - Wearable major class */
#define COD_WERABLE_WATCH (COD_DEVICE_WEARABLE | 0x000004)
#define COD_WERABLE_PAGER (COD_DEVICE_WEARABLE | 0x000008)
#define COD_WERABLE_JACKET (COD_DEVICE_WEARABLE | 0x00000C)
#define COD_WERABLE_HELMET (COD_DEVICE_WEARABLE | 0x000010)
#define COD_WERABLE_GLASSES (COD_DEVICE_WEARABLE | 0x000014)
/* * Minor Device Class - Toy major class */
#define COD_TOY_ROBOT (COD_DEVICE_TOY | 0x000004)
#define COD_TOY_VEHICLE (COD_DEVICE_TOY | 0x000008)
#define COD_TOY_DOLL (COD_DEVICE_TOY | 0x00000C)
#define COD_TOY_CONROLLER (COD_DEVICE_TOY | 0x000010)
#define COD_TOY_GAME (COD_DEVICE_TOY | 0x000014)
/* * Minor Device Class - Health major class */
#define COD_HEALTH_BLOOD_PRESURE (COD_DEVICE_HEALTH | 0x000004)
#define COD_HEALTH_THERMOMETER (COD_DEVICE_HEALTH | 0x000008)
#define COD_HEALTH_WEIGHING_SCALE (COD_DEVICE_HEALTH | 0x00000C)
#define COD_HEALTH_GLUCOSE_METER (COD_DEVICE_HEALTH | 0x000010)
#define COD_HEALTH_PULSE_OXIMETER (COD_DEVICE_HEALTH | 0x000014)
#define COD_HEALTH_RATE_MONITOR (COD_DEVICE_HEALTH | 0x000018)
#define COD_HEALTH_DATA_DISPLAY (COD_DEVICE_HEALTH | 0x00001C)
/* * Headset Device Class */
#define IS_HEADSET(cod) ((COD_SERVICE_BITS(cod) & COD_SERVICE_AUDIO) && COD_DEVICE_MAJOR_BITS(cod) == COD_DEVICE_AV)
#ifdef CONFIG_DEV_NAME_MAX_LEN
#define BT_DEV_NAME_MAX_LEN (CONFIG_DEV_NAME_MAX_LEN)
#else
#define BT_DEV_NAME_MAX_LEN (64)
#endif
#define BT_LOC_NAME_MAX_LEN BT_DEV_NAME_MAX_LEN
#define BT_REM_NAME_MAX_LEN BT_DEV_NAME_MAX_LEN
#define BT_UUID_MAX_NUM (32)
#define BT_UUID_128_LEN (16)
typedef struct {
bt_address_t addr;
int8_t rssi;
int8_t pad[1];
uint32_t cod;
char name[BT_REM_NAME_MAX_LEN + 1];
} bt_discovery_result_t;
/* * HCI Set Event Filter Command param */
typedef struct {
bt_filter_condition_type_t condition_type;
uint32_t condition_cod;
bt_address_t condition_bdaddr;
} bt_discovery_filter_t;
// BLE connect parameter
typedef struct {
uint8_t filter_policy; /* ble_connect_filter_policy_t */
uint8_t use_default_params; /* boolean, If TRUE, the following parameters are ignored. */
uint8_t init_phy; /* ble_phy_type_t */
uint8_t pad[1];
uint16_t scan_interval;
uint16_t scan_window;
uint16_t connection_interval_min;
uint16_t connection_interval_max;
uint16_t connection_latency;
uint16_t supervision_timeout;
uint16_t min_ce_length;
uint16_t max_ce_length;
} ble_connect_params_t;
typedef struct {
uint8_t enable; /* enable sniff mode, boolean */
uint8_t idle_time; /* Idle time in seconds before entering sniff mode */
uint16_t sniff_max_interval; /* sniff maximum interval */
uint16_t sniff_min_interval; /* sniff minimum interval */
uint16_t sniff_attempt; /* sniff attempt */
uint16_t sniff_timeout; /* sniff timeout */
} bt_auto_sniff_params_t;
typedef struct {
uint8_t evt_code; /* HCI event code */
uint8_t length; /* length of the params */
char params[0]; /* parameters */
} bt_hci_event_t;
/* Possible 2.4G channel band width (MHz) */
#define AFH_WIFI_BANDWIDTH_20 20
#define AFH_WIFI_BANDWIDTH_22 22
#define AFH_WIFI_BANDWIDTH_40 40
/* Possible 2.4G none Bluetooth radio channel central frequency (MHz) */
#define AFH_WIFI_CENTRAL_FREQUENCY_CH1 2412
#define AFH_WIFI_CENTRAL_FREQUENCY_STEP 5
#define AFH_WIFI_CHANNEL_TO_FREQ(ch) \
(AFH_WIFI_CENTRAL_FREQUENCY_CH1 + ((ch - 1) * AFH_WIFI_CENTRAL_FREQUENCY_STEP))
enum {
BLUETOOTH_SYSTEM,
BLUETOOTH_USER,
};
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 struct bt_instance {
uint32_t app_id;
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_BINDER_IPC
void* manager_proxy;
void* adapter_proxy;
void* a2dp_proxy;
void* a2dp_sink_proxy;
void* hfp_hf_proxy;
void* hfp_ag_proxy;
void* gatt_proxy;
void* spp_proxy;
void* pan_proxy;
void* hidd_proxy;
void* gattc_proxy;
void* gatts_proxy;
void* lea_server_proxy;
#endif
#ifdef CONFIG_BLUETOOTH_FRAMEWORK_SOCKET_IPC
void* poll;
uv_mutex_t mutex;
uv_sem_t message_processed;
int peer_fd;
uv_loop_t* client_loop;
uv_loop_t* external_loop;
uv_async_t* external_async;
int offset;
void* packet;
void* cpacket;
struct list_node msg_queue;
void* context;
uv_mutex_t lock;
callbacks_list_t* adapter_callbacks;
callbacks_list_t* a2dp_sink_callbacks;
callbacks_list_t* a2dp_source_callbacks;
callbacks_list_t* avrcp_target_callbacks;
void* adapter_cookie;
void* a2dp_sink_cookie;
void* a2dp_source_cookie;
void* avrcp_target_cookie;
callbacks_list_t* hfp_ag_callbacks;
callbacks_list_t* hfp_hf_callbacks;
callbacks_list_t* panu_callbacks;
callbacks_list_t* spp_callbacks;
callbacks_list_t* hidd_callbacks;
callbacks_list_t* l2cap_callbacks;
void* hfp_ag_cookie;
void* hfp_hf_cookie;
void* panu_cookie;
void* spp_cookie;
void* hidd_cookie;
void* l2cap_cookie;
bt_list_t* gattc_remote_list;
bt_list_t* gatts_remote_list;
#endif
} bt_instance_t;
/**
* @brief Create bluetooth client instance
*
* @return bt_instance_t* - ins on success, NULL on failure.
*/
bt_instance_t* BTSYMBOLS(bluetooth_create_instance)(void);
/**
* @brief Get bluetooth client instance, If it does not exist, an instance is created
*
* @return bt_instance_t* - ins if exist or create success, NULL, if create fail.
*/
bt_instance_t* BTSYMBOLS(bluetooth_get_instance)(void);
/**
* @brief Find bluetooth client instance
*
* @return bt_instance_t* - ins if exist, NULL otherwise.
*/
bt_instance_t* BTSYMBOLS(bluetooth_find_instance)(pid_t pid);
/**
* @brief Get profile proxy
*
* @param ins - bluetooth client instance.
* @param id - profile ID.
* @return void* - profile proxy.
*/
void* BTSYMBOLS(bluetooth_get_proxy)(bt_instance_t* ins, enum profile_id id);
/**
* @brief Delete client instance
*
* @param ins - bluetooth client instance.
*/
void BTSYMBOLS(bluetooth_delete_instance)(bt_instance_t* ins);
/**
* @brief Start profile service
*
* @param ins - bluetooth client instance.
* @param id - profile ID.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
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.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bluetooth_stop_service)(bt_instance_t* ins, enum profile_id id);
bool BTSYMBOLS(bluetooth_set_external_uv)(bt_instance_t* ins, uv_loop_t* ext_loop);
#ifdef __cplusplus
}
#endif
#endif /* _BT_BLUETOOTH_H__ */

View File

@ -0,0 +1,53 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#ifndef __BT_A2DP_H__
#define __BT_A2DP_H__
#include <stddef.h>
#include "bt_addr.h"
#include "bt_device.h"
/**
* @brief A2DP audio state
*/
typedef enum {
A2DP_AUDIO_STATE_REMOTE_SUSPEND = 0,
A2DP_AUDIO_STATE_STOPPED,
A2DP_AUDIO_STATE_STARTED,
} a2dp_audio_state_t;
/**
* @brief A2DP connection state changed callback
*
* @param cookie - callback cookie.
* @param addr - address of peer A2DP device.
* @param state - connection state.
*/
typedef void (*a2dp_connection_state_callback)(void* cookie, bt_address_t* addr,
profile_connection_state_t state);
/**
* @brief A2DP audio connection state changed callback
*
* @param cookie - callback cookie.
* @param addr - address of peer A2DP device.
* @param state - audio connection state.
*/
typedef void (*a2dp_audio_state_callback)(void* cookie, bt_address_t* addr,
a2dp_audio_state_t state);
#endif /* __BT_A2DP_H__ */

View File

@ -0,0 +1,125 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#ifndef __BT_A2DP_SINK_H__
#define __BT_A2DP_SINK_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "bt_a2dp.h"
#ifndef BTSYMBOLS
#define BTSYMBOLS(s) s
#endif
/**
* @brief A2DP audio sink config changed callback
*
* @param cookie - callback cookie.
* @param addr - address of peer A2DP source device.
*/
typedef void (*a2dp_audio_sink_config_callback)(void* cookie, bt_address_t* addr);
/**
* @brief A2DP sink callback structure
*
*/
typedef struct {
/** set to sizeof(a2dp_sink_callbacks_t) */
size_t size;
a2dp_connection_state_callback connection_state_cb;
a2dp_audio_state_callback audio_state_cb;
a2dp_audio_sink_config_callback audio_sink_config_cb;
} a2dp_sink_callbacks_t;
/**
* @brief Register callback functions to A2DP sink service
*
* @param ins - bluetooth client instance.
* @param id - A2DP sink callback functions.
* @return void* - callbacks cookie.
*/
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
*
* @param ins - bluetooth client instance.
* @param id - callbacks cookie.
* @return true - on callback unregister success
* @return false - on callback cookie not found
*/
bool BTSYMBOLS(bt_a2dp_sink_unregister_callbacks)(bt_instance_t* ins, void* cookie);
/**
* @brief Check A2DP sink is connected
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP source device.
* @return true - connected.
* @return false - not connected.
*/
bool BTSYMBOLS(bt_a2dp_sink_is_connected)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Check A2DP sink is playing
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP source device.
* @return true - playing.
* @return false - not playing.
*/
bool BTSYMBOLS(bt_a2dp_sink_is_playing)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief get A2DP sink connection state
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP source device.
* @return profile_connection_state_t - connection state.
*/
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
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP source device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_a2dp_sink_connect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Disconnect from peer A2DP device
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP source device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
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
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP source device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_a2dp_sink_set_active_device)(bt_instance_t* ins, bt_address_t* addr);
#ifdef __cplusplus
}
#endif
#endif /* __BT_A2DP_SINK_H__ */

View File

@ -0,0 +1,134 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#ifndef __BT_A2DP_SOURCE_H__
#define __BT_A2DP_SOURCE_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "bt_a2dp.h"
#ifndef BTSYMBOLS
#define BTSYMBOLS(s) s
#endif
/**
* @brief A2DP audio source config changed callback
*
* @param cookie - callback cookie.
* @param addr - address of peer A2DP sink device.
*/
typedef void (*a2dp_audio_source_config_callback)(void* cookie, bt_address_t* addr);
/**
* @brief A2DP source callback structure
*
*/
typedef struct {
/** set to sizeof(a2dp_source_callbacks_t) */
size_t size;
a2dp_connection_state_callback connection_state_cb;
a2dp_audio_state_callback audio_state_cb;
a2dp_audio_source_config_callback audio_source_config_cb;
} a2dp_source_callbacks_t;
/**
* @brief Register callback functions to A2DP source service
*
* @param ins - bluetooth client instance.
* @param id - A2DP source callback functions.
* @return void* - callbacks cookie.
*/
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
*
* @param ins - bluetooth client instance.
* @param id - callbacks cookie.
* @return true - on callback unregister success.
* @return false - on callback cookie not found.
*/
bool BTSYMBOLS(bt_a2dp_source_unregister_callbacks)(bt_instance_t* ins, void* cookie);
/**
* @brief Check A2DP source is connected
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @return true - connected.
* @return false - not connected.
*/
bool BTSYMBOLS(bt_a2dp_source_is_connected)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Check A2DP source is playing
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @return true - playing.
* @return false - not playing.
*/
bool BTSYMBOLS(bt_a2dp_source_is_playing)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief get A2DP source connection state
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @return profile_connection_state_t - connection state.
*/
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
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_a2dp_source_connect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Disconnect from peer A2DP device
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
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
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
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
*
* @param ins - bluetooth client instance.
* @param addr - address of peer A2DP sink device.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_a2dp_source_set_active_device)(bt_instance_t* ins, bt_address_t* addr);
#ifdef __cplusplus
}
#endif
#endif /* __BT_A2DP_SOURCE_H__ */

View File

@ -0,0 +1,569 @@
/****************************************************************************
* 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_ADAPTER_H__
#define __BT_ADAPTER_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "bluetooth.h"
#include "bt_device.h"
#ifndef BTSYMBOLS
#define BTSYMBOLS(s) s
#endif
/**
* @brief adapter state define
*
*/
typedef enum {
BT_ADAPTER_STATE_OFF = 0,
BT_ADAPTER_STATE_BLE_TURNING_ON,
BT_ADAPTER_STATE_BLE_ON,
BT_ADAPTER_STATE_TURNING_ON,
BT_ADAPTER_STATE_ON,
BT_ADAPTER_STATE_TURNING_OFF,
BT_ADAPTER_STATE_BLE_TURNING_OFF,
} bt_adapter_state_t;
/**
* @brief Adapter state changed callback
*
* @param cookie - callback cookie.
* @param state - new adapter state.
*/
typedef void (*on_adapter_state_changed_callback)(void* cookie, bt_adapter_state_t state);
/**
* @brief Adapter discovery state changed callback
*
* @param cookie - callback cookie.
* @param state - discovery state (0:stopped, 1:started).
*/
typedef void (*on_discovery_state_changed_callback)(void* cookie, bt_discovery_state_t state);
/**
* @brief Discovery result callback
*
* @param cookie - callback cookie.
* @param remote - romote device info.
*/
typedef void (*on_discovery_result_callback)(void* cookie, bt_discovery_result_t* remote);
/**
* @brief Scan mode changed callback
*
* @param cookie - callback cookie.
* @param mode - new scan mode.
*/
typedef void (*on_scan_mode_changed_callback)(void* cookie, bt_scan_mode_t mode);
/**
* @brief Local device name changed callback
*
* @param cookie - callback cookie.
* @param device_name - new local name.
*/
typedef void (*on_device_name_changed_callback)(void* cookie, const char* device_name);
/**
* @brief Pair request callback (io cap request)
*
* @param cookie - callback cookie.
* @param addr - remote addr.
*/
typedef void (*on_pair_request_callback)(void* cookie, bt_address_t* addr);
/**
* @brief Pair information display callback
*
* @param cookie - callback cookie.
* @param addr - remote addr.
* @param transport - transport type (0:BLE, 1:BREDR).
* @param type - pair type.
* @param passkey - passkey value, invalid on pair type equal PAIR_TYPE_PASSKEY_CONFIRMATION
* or PAIR_TYPE_PASSKEY_NOTIFICATION.
*/
typedef void (*on_pair_display_callback)(void* cookie, bt_address_t* addr, bt_transport_t transport, bt_pair_type_t type, uint32_t passkey);
/**
* @brief Connect request callback
*
* @param cookie - callback cookie
* @param addr - remote addr.
*/
typedef void (*on_connect_request_callback)(void* cookie, bt_address_t* addr);
/**
* @brief Connection state changed callback
*
* @param cookie - callback cookie
* @param addr - remote addr.
* @param transport - transport type (0:BLE, 1:BREDR).
* @param state - ACL connection state.
*/
typedef void (*on_connection_state_changed_callback)(void* cookie, bt_address_t* addr, bt_transport_t transport, connection_state_t state);
/**
* @brief Bond state changed callback
*
* @param cookie - callback cookie.
* @param addr - remote addr.
* @param transport - transport type (0:BLE, 1:BREDR).
* @param state - bond state.
*/
typedef void (*on_bond_state_changed_callback)(void* cookie, bt_address_t* addr, bt_transport_t transport, bond_state_t state, bool is_ctkd);
/**
* @brief Got local OOB data for LE secure connection pairing callback
*
* @param cookie - callback cookie.
* @param addr - remote addr.
* @param c_val - LE secure connection confirmation value.
* @param r_val - LE secure connection random value.
*/
typedef void (*on_le_sc_local_oob_data_got_callback)(void* cookie, bt_address_t* addr, bt_128key_t c_val, bt_128key_t r_val);
/**
* @brief Remote device name changed callback
*
* @param cookie - callback cookie.
* @param addr - remote addr.
* @param name - remote device name.
*/
typedef void (*on_remote_name_changed_callback)(void* cookie, bt_address_t* addr, const char* name);
/**
* @brief Remote device alias changed callback
*
* @param cookie - callback cookie.
* @param addr - remote addr.
* @param alias - alias, set by user.
*/
typedef void (*on_remote_alias_changed_callback)(void* cookie, bt_address_t* addr, const char* alias);
/**
* @brief Remote device class changed callback
*
* @param cookie - callback cookie.
* @param addr - remote addr.
* @param cod - remote device class.
*/
typedef void (*on_remote_cod_changed_callback)(void* cookie, bt_address_t* addr, uint32_t cod);
/**
* @brief Remote device uuid changed callback
*
* @param cookie - callback cookie.
* @param addr - remote addr.
* @param uuids - remote device support uuids.
* @param size - uuid size.
*/
typedef void (*on_remote_uuids_changed_callback)(void* cookie, bt_address_t* addr, bt_uuid_t* uuids, uint16_t size);
/**
* @brief Remote device link mode changed callback
*
* @param cookie - callback cookie.
* @param addr - remote addr.
* @param mode - link mode.
* @param sniff_interval - sniff interval.
*/
typedef void (*on_remote_link_mode_changed_callback)(void* cookie, bt_address_t* addr, bt_link_mode_t mode, uint16_t sniff_interval);
/**
* @brief Adapter callback structure
*
*/
typedef struct {
on_adapter_state_changed_callback on_adapter_state_changed;
on_discovery_state_changed_callback on_discovery_state_changed;
on_discovery_result_callback on_discovery_result;
on_scan_mode_changed_callback on_scan_mode_changed;
on_device_name_changed_callback on_device_name_changed;
on_pair_request_callback on_pair_request;
on_pair_display_callback on_pair_display;
on_connect_request_callback on_connect_request;
on_connection_state_changed_callback on_connection_state_changed;
on_bond_state_changed_callback on_bond_state_changed;
on_le_sc_local_oob_data_got_callback on_le_sc_local_oob_data_got;
on_remote_name_changed_callback on_remote_name_changed;
on_remote_alias_changed_callback on_remote_alias_changed;
on_remote_cod_changed_callback on_remote_cod_changed;
on_remote_uuids_changed_callback on_remote_uuids_changed;
on_remote_link_mode_changed_callback on_remote_link_mode_changed;
} adapter_callbacks_t;
/**
* @note Not support
*
*/
typedef struct {
on_bond_state_changed_callback on_bond_state_changed;
on_remote_name_changed_callback on_remote_name_changed;
on_remote_alias_changed_callback on_remote_alias_changed;
on_remote_cod_changed_callback on_remote_cod_changed;
on_remote_uuids_changed_callback on_remote_uuids_changed;
} remote_device_callbacks_t;
/**
* @brief Enable bluetooth adapter
*
* @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_enable)(bt_instance_t* ins);
/**
* @brief Disable bluetooth adapter
*
* @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)(bt_instance_t* ins);
/**
* @brief Enable ble
*
* @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_enable_le)(bt_instance_t* ins);
/**
* @brief Disable ble
*
* @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_le)(bt_instance_t* ins);
/**
* @brief Get adapter state
*
* @param ins - bluetooth client instance.
* @return bt_adapter_state_t - adapter state.
*/
bt_adapter_state_t BTSYMBOLS(bt_adapter_get_state)(bt_instance_t* ins);
/**
* @brief Get adapter device type
*
* @param ins - bluetooth client instance.
* @return bt_device_type_t - device type(0:EDR, 1:LE, 2:DUAL, 0xFF:unknow).
*/
bt_device_type_t BTSYMBOLS(bt_adapter_get_type)(bt_instance_t* ins);
/**
* @brief Set discovery filter
* @note Not support now.
* @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_set_discovery_filter)(bt_instance_t* ins);
/**
* @brief Start discovery
*
* @param ins - bluetooth client instance.
* @param timeout - maximum amount of time specified(Time = N * 1.28s, Range: 1.28 to 61.44 s).
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_start_discovery)(bt_instance_t* ins, uint32_t timeout);
/**
* @brief Cancel discovery
*
* @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_cancel_discovery)(bt_instance_t* ins);
/**
* @brief Check adapter is discvering
*
* @param ins - bluetooth client instance.
* @return true - adapter is discovering.
* @return false - adapter is not discovering.
*/
bool BTSYMBOLS(bt_adapter_is_discovering)(bt_instance_t* ins);
/**
* @brief Read the bluetooth controller address(BD_ADDR)
*
* @param ins - bluetooth client instance.
* @param[out] addr - BDADDR, empty value on adapter not enabled.
*/
void BTSYMBOLS(bt_adapter_get_address)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Set adapter local name
*
* @param ins - bluetooth client instance.
* @param name - adapter local name.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_set_name)(bt_instance_t* ins, const char* name);
/**
* @brief Get adapter local name
*
* @param ins - bluetooth client instance.
* @param[out] name - adapter local name from adapter service.
* @param[in] length - maximum length of name buffer.
*/
void BTSYMBOLS(bt_adapter_get_name)(bt_instance_t* ins, char* name, int length);
/**
* @brief Get adapter supported uuids
* @note - not support now.
* @param ins - bluetooth client instance.
* @param[out] uuids - uuids .
* @param[out] size - uuid size.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_get_uuids)(bt_instance_t* ins, bt_uuid_t* uuids, uint16_t* size);
/**
* @brief Set adapter scan mode
*
* @param ins - bluetooth client instance.
* @param mode - scan mode (0:none, 1:connectable, 2:connectable_discoverable).
* @param bondable - bondable.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_set_scan_mode)(bt_instance_t* ins, bt_scan_mode_t mode, bool bondable);
/**
* @brief Get adapter scan mode
*
* @param ins - bluetooth client instance.
* @return bt_scan_mode_t - scan mode (0:none, 1:connectable, 2:connectable_discoverable).
*/
bt_scan_mode_t BTSYMBOLS(bt_adapter_get_scan_mode)(bt_instance_t* ins);
/**
* @brief Set adapter device class
*
* @param ins - bluetooth client instance.
* @param cod - class of device, zero is invalid.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_set_device_class)(bt_instance_t* ins, uint32_t cod);
/**
* @brief Get adapter device class
*
* @param ins - bluetooth client instance.
* @return uint32_t - class of device, zero on adapter not enabled.
*/
uint32_t BTSYMBOLS(bt_adapter_get_device_class)(bt_instance_t* ins);
/**
* @brief Set BREDR adapter io capability
*
* @param ins - bluetooth client instance.
* @param cap - BREDR io capability.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_set_io_capability)(bt_instance_t* ins, bt_io_capability_t cap);
/**
* @brief Get BREDR adapter io capability
*
* @param ins - bluetooth client instance.
* @return bt_io_capability_t - BREDR io capability.
*/
bt_io_capability_t BTSYMBOLS(bt_adapter_get_io_capability)(bt_instance_t* ins);
bt_status_t BTSYMBOLS(bt_adapter_set_inquiry_scan_parameters)(bt_instance_t* ins, bt_scan_type_t type,
uint16_t interval, uint16_t window);
bt_status_t BTSYMBOLS(bt_adapter_set_page_scan_parameters)(bt_instance_t* ins, bt_scan_type_t type,
uint16_t interval, uint16_t window);
/**
* @brief Get adapter bonded devices list
*
* @param ins - bluetooth client instance.
* @param[out] addr - out bonded devices address array.
* @param[out] num - out bonded devices num.
* @param allocator - address array allocator.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_get_bonded_devices)(bt_instance_t* ins, bt_transport_t transport, bt_address_t** addr, int* num, bt_allocator_t allocator);
/**
* @brief Get adapter connected devices list
*
* @param ins - bluetooth client instance.
* @param[out] addr - out connected devices address array.
* @param[out] num - out connected devices num.
* @param allocator - address array allocator.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_get_connected_devices)(bt_instance_t* ins, bt_transport_t transport, bt_address_t** addr, int* num, bt_allocator_t allocator);
/**
* @brief Disconnect all connected device.
* @note not support.
* @param ins - bluetooth client instance.
*/
void BTSYMBOLS(bt_adapter_disconnect_all_devices)(bt_instance_t* ins);
/**
* @brief Check BREDR adapter is supported
*
* @param ins - bluetooth client instance.
* @return true - support.
* @return false - not support.
*/
bool BTSYMBOLS(bt_adapter_is_support_bredr)(bt_instance_t* ins);
/**
* @brief Register callback functions to adapter service
*
* @param ins - bluetooth client instance.
* @param callbacks - adapter callback functions.
* @return void* - callback cookie, NULL on failure.
*/
void* BTSYMBOLS(bt_adapter_register_callback)(bt_instance_t* ins, const adapter_callbacks_t* adapter_cbs);
/**
* @brief Unregister adapter callback function
*
* @param ins - bluetooth client instance.
* @param cookie - callbacks cookie.
* @return true - on callback unregister success.
* @return false - on callback cookie not found.
*/
bool BTSYMBOLS(bt_adapter_unregister_callback)(bt_instance_t* ins, void* cookie);
/**
* @brief Check LE adapter is enabled
*
* @param ins - bluetooth client instance.
* @return true - enabled.
* @return false - disabled.
*/
bool BTSYMBOLS(bt_adapter_is_le_enabled)(bt_instance_t* ins);
/**
* @brief Check LE adapter is supported
*
* @param ins - bluetooth client instance.
* @return true - support.
* @return false - not support.
*/
bool BTSYMBOLS(bt_adapter_is_support_le)(bt_instance_t* ins);
/**
* @brief Check LE audio adapter is supported
*
* @param ins - bluetooth client instance.
* @return true - support.
* @return false - not support.
*/
bool BTSYMBOLS(bt_adapter_is_support_leaudio)(bt_instance_t* ins);
/**
* @brief Get LE adapter address
*
* @param ins - bluetooth client instance.
* @param[out] addr - LE address.
* @param[out] type - LE address type.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_get_le_address)(bt_instance_t* ins, bt_address_t* addr, ble_addr_type_t* type);
/**
* @brief Set LE adapter private address
*
* @param ins - bluetooth client instance.
* @param addr - LE address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_set_le_address)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Set Le identity address
*
* @param ins - bluetooth client instance.
* @param addr Le identity address
* @param is_public - true:public, false:static
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_set_le_identity_address)(bt_instance_t* ins, bt_address_t* addr, bool is_public);
/**
* @brief Set LE adapter io capability
*
* @param ins - bluetooth client instance.
* @param le_io_cap - LE adapter io capability
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_set_le_io_capability)(bt_instance_t* ins, uint32_t le_io_cap);
/**
* @brief Get LE adapter io capability
*
* @param ins - bluetooth client instance.
* @return uint32_t - LE adapter io capability
*/
uint32_t BTSYMBOLS(bt_adapter_get_le_io_capability)(bt_instance_t* ins);
/**
* @brief Set Le adapter appearance
*
* @param ins - bluetooth client instance.
* @param appearance - le appearance, zero is invalid.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_set_le_appearance)(bt_instance_t* ins, uint16_t appearance);
/**
* @brief Get Le adapter appearance
*
* @param ins - bluetooth client instance.
* @return uint16_t - le appearance, zero on adapter not enabled.
*/
uint16_t BTSYMBOLS(bt_adapter_get_le_appearance)(bt_instance_t* ins);
/**
* @brief Enable/Disable cross transport key derivation.
*
* @param ins - bluetooth client instance.
* @param brkey_to_lekey - Enable or disable generating LE LTK from BR link key.
* @param lekey_to_brkey - Enable or disable generating BR link key from LE LTK.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_adapter_le_enable_key_derivation)(bt_instance_t* ins,
bool brkey_to_lekey,
bool lekey_to_brkey);
bt_status_t BTSYMBOLS(bt_adapter_le_add_whitelist)(bt_instance_t* ins, bt_address_t* addr);
bt_status_t BTSYMBOLS(bt_adapter_le_remove_whitelist)(bt_instance_t* ins, bt_address_t* addr);
bt_status_t BTSYMBOLS(bt_adapter_set_afh_channel_classification)(bt_instance_t* ins, uint16_t central_frequency,
uint16_t band_width, uint16_t number);
bt_status_t BTSYMBOLS(bt_adapter_set_auto_sniff)(bt_instance_t* ins, bt_auto_sniff_params_t* params);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,51 @@
/****************************************************************************
* 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_ADDR_H__
#define __BT_ADDR_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
#define BT_ADDR_LENGTH 6 /*define the address length*/
#define BT_ADDR_STR_LENGTH 18
typedef struct bt_addr {
uint8_t addr[BT_ADDR_LENGTH];
} bt_address_t;
typedef struct bt_le_addr {
uint8_t addr[BT_ADDR_LENGTH];
uint8_t addr_type;
} bt_le_address_t;
bool bt_addr_is_empty(const bt_address_t* addr);
void bt_addr_set_empty(bt_address_t* addr);
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);
int bt_addr_str2ba(const char* str, bt_address_t* addr);
char* bt_addr_str(const bt_address_t* addr);
void bt_addr_set(bt_address_t* addr, const uint8_t* bd);
void bt_addr_swap(const bt_address_t* src, bt_address_t* dest);
#ifdef __cplusplus
}
#endif
#endif /* __BT_ADDR_H_ */

View File

@ -0,0 +1,138 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#ifndef __BT_AVRCP_H__
#define __BT_AVRCP_H__
#include <stddef.h>
#include "bt_addr.h"
#include "bt_device.h"
typedef enum {
PASSTHROUGH_CMD_ID_SELECT,
PASSTHROUGH_CMD_ID_UP,
PASSTHROUGH_CMD_ID_DOWN,
PASSTHROUGH_CMD_ID_LEFT,
PASSTHROUGH_CMD_ID_RIGHT,
PASSTHROUGH_CMD_ID_RIGHT_UP,
PASSTHROUGH_CMD_ID_RIGHT_DOWN,
PASSTHROUGH_CMD_ID_LEFT_UP,
PASSTHROUGH_CMD_ID_LEFT_DOWN,
PASSTHROUGH_CMD_ID_ROOT_MENU,
PASSTHROUGH_CMD_ID_SETUP_MENU,
PASSTHROUGH_CMD_ID_CONTENTS_MENU,
PASSTHROUGH_CMD_ID_FAVORITE_MENU,
PASSTHROUGH_CMD_ID_EXIT,
PASSTHROUGH_CMD_ID_0,
PASSTHROUGH_CMD_ID_1,
PASSTHROUGH_CMD_ID_2,
PASSTHROUGH_CMD_ID_3,
PASSTHROUGH_CMD_ID_4,
PASSTHROUGH_CMD_ID_5,
PASSTHROUGH_CMD_ID_6,
PASSTHROUGH_CMD_ID_7,
PASSTHROUGH_CMD_ID_8,
PASSTHROUGH_CMD_ID_9,
PASSTHROUGH_CMD_ID_DOT,
PASSTHROUGH_CMD_ID_ENTER,
PASSTHROUGH_CMD_ID_CLEAR,
PASSTHROUGH_CMD_ID_CHANNEL_UP,
PASSTHROUGH_CMD_ID_CHANNEL_DOWN,
PASSTHROUGH_CMD_ID_PREVIOUS_CHANNEL,
PASSTHROUGH_CMD_ID_SOUND_SELECT,
PASSTHROUGH_CMD_ID_INPUT_SELECT,
PASSTHROUGH_CMD_ID_DISPLAY_INFO,
PASSTHROUGH_CMD_ID_HELP,
PASSTHROUGH_CMD_ID_PAGE_UP,
PASSTHROUGH_CMD_ID_PAGE_DOWN,
PASSTHROUGH_CMD_ID_POWER,
PASSTHROUGH_CMD_ID_VOLUME_UP,
PASSTHROUGH_CMD_ID_VOLUME_DOWN,
PASSTHROUGH_CMD_ID_MUTE,
PASSTHROUGH_CMD_ID_PLAY,
PASSTHROUGH_CMD_ID_STOP,
PASSTHROUGH_CMD_ID_PAUSE,
PASSTHROUGH_CMD_ID_RECORD,
PASSTHROUGH_CMD_ID_REWIND,
PASSTHROUGH_CMD_ID_FAST_FORWARD,
PASSTHROUGH_CMD_ID_EJECT,
PASSTHROUGH_CMD_ID_FORWARD,
PASSTHROUGH_CMD_ID_BACKWARD,
PASSTHROUGH_CMD_ID_ANGLE,
PASSTHROUGH_CMD_ID_SUBPICTURE,
PASSTHROUGH_CMD_ID_F1,
PASSTHROUGH_CMD_ID_F2,
PASSTHROUGH_CMD_ID_F3,
PASSTHROUGH_CMD_ID_F4,
PASSTHROUGH_CMD_ID_F5,
PASSTHROUGH_CMD_ID_VENDOR_UNIQUE,
PASSTHROUGH_CMD_ID_NEXT_GROUP,
PASSTHROUGH_CMD_ID_PREV_GROUP,
PASSTHROUGH_CMD_ID_RESERVED
} avrcp_passthr_cmd_t;
typedef enum {
AVRCP_KEY_PRESSED,
AVRCP_KEY_RELEASED
} avrcp_key_state_t;
typedef enum {
PLAY_STATUS_STOPPED = 0,
PLAY_STATUS_PLAYING,
PLAY_STATUS_PAUSED,
PLAY_STATUS_FWD_SEEK,
PLAY_STATUS_REV_SEEK,
PLAY_STATUS_ERROR,
} avrcp_play_status_t;
enum {
AVRCP_CAPABILITY_ID_COMPANY_ID = 2,
AVRCP_CAPABILITY_ID_EVENTS_SUPPORTED,
};
typedef enum {
NOTIFICATION_EVT_PALY_STATUS_CHANGED = 0x01,
NOTIFICATION_EVT_TRACK_CHANGED,
NOTIFICATION_EVT_TRACK_END,
NOTIFICATION_EVT_TRACK_START,
NOTIFICATION_EVT_PLAY_POS_CHANGED,
NOTIFICATION_EVT_BATTERY_STATUS_CHANGED,
NOTIFICATION_EVT_SYSTEM_STATUS_CHANGED,
NOTIFICATION_EVT_APP_SETTING_CHANGED,
NOTIFICATION_EVT_NOW_PLAYING_CONTENT_CHANGED,
NOTIFICATION_EVT_AVAILABLE_PLAYERS_CHANGED,
NOTIFICATION_EVT_ADDRESSED_PLAYER_CHANGED,
NOTIFICATION_EVT_UIDS_CHANGED,
NOTIFICATION_EVT_VOLUME_CHANGED,
NOTIFICATION_EVT_FLAG_INTERIM
} avrcp_notification_event_t;
typedef enum {
AVRCP_RESPONSE_NOT_IMPLEMENTED,
AVRCP_RESPONSE_ACCEPTED,
AVRCP_RESPONSE_REJECTED,
AVRCP_RESPONSE_IN_TRANSITION,
AVRCP_RESPONSE_IMPLEMENTED_STABLE,
AVRCP_RESPONSE_CHANGED,
AVRCP_RESPONSE_INTERIM,
AVRCP_RESPONSE_BROWSING,
AVRCP_RESPONSE_SKIPPED,
AVRCP_RESPONSE_TIMEOUT
} avrcp_response_t;
typedef void (*avrcp_connection_state_callback)(void* cookie, bt_address_t* addr, profile_connection_state_t state);
#endif /* __BT_AVRCP_H__ */

View File

@ -0,0 +1,29 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#ifndef __BT_AVRCP_CONTROL_H__
#define __BT_AVRCP_CONTROL_H__
#include "bt_avrcp.h"
typedef struct {
size_t size;
avrcp_connection_state_callback connection_state_cb;
} avrcp_control_callbacks_t;
void* bt_avrcp_control_register_callbacks(bt_instance_t* ins, const avrcp_control_callbacks_t* callbacks);
bool bt_avrcp_control_unregister_callbacks(bt_instance_t* ins, void* cookie);
#endif /* __BT_AVRCP_CONTROL_H__ */

View File

@ -0,0 +1,116 @@
/****************************************************************************
* Copyright (C) 2023 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#ifndef __BT_AVRCP_TARGET_H__
#define __BT_AVRCP_TARGET_H__
#include "bt_avrcp.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef BTSYMBOLS
#define BTSYMBOLS(s) s
#endif
/**
* @brief Received Get Play Status request from CT.
*
* @param cookie - Callback cookie.
* @param addr - Remote BT address.
* @return void.
*/
typedef void (*avrcp_received_get_play_status_request_callback)(void* cookie, bt_address_t* addr);
/**
* @brief Received register notification request callback.
*
* @param cookie - Callback cookie.
* @param addr - Remote BT address.
* @param event - The event for which the CT requires notifications.
* @param interval - Only works in PLAY_POS_CHANGED event.
*/
typedef void (*avrcp_received_register_notification_request_callback)(void* cookie, bt_address_t* addr, avrcp_notification_event_t event, uint32_t interval);
/**
* @brief Received panel operation from CT.
*
* @param cookie - Callback cookie.
* @param addr - Remote BT address.
* @param op - Panel operation.
* @param state - Key state
*/
typedef void (*avrcp_received_panel_operation_callback)(void* cookie, bt_address_t* addr, uint8_t op, uint8_t state);
/**
* @cond
*/
typedef struct {
size_t size;
avrcp_connection_state_callback connection_state_cb;
avrcp_received_get_play_status_request_callback received_get_play_status_request_cb;
avrcp_received_register_notification_request_callback received_register_notification_request_cb;
avrcp_received_panel_operation_callback received_panel_operation_cb;
} avrcp_target_callbacks_t;
/**
* @endcond
*/
/**
* @brief Register callback functions to AVRCP Target
*
* @param ins - Bluetooth client instance.
* @param callbacks - AVRCP Target callback functions.
* @return void* - Callbacks cookie.
*/
void* BTSYMBOLS(bt_avrcp_target_register_callbacks)(bt_instance_t* ins, const avrcp_target_callbacks_t* callbacks);
/**
* @brief Unregister callback functions to AVRCP Target
*
* @param ins - Bluetooth client instance.
* @param cookie - Callbacks cookie.
* @return bool - True, if unregister success, false otherwise.
*/
bool BTSYMBOLS(bt_avrcp_target_unregister_callbacks)(bt_instance_t* ins, void* cookie);
/**
* @brief Send response of Get Play Status request to CT.
*
* @param ins - Bluetooth client instance.
* @param addr - Remote BT address.
* @param status - Current play status.
* @param song_len - Song length in ms.
* @param song_pos - Current position in ms.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_avrcp_target_get_play_status_response)(bt_instance_t* ins, bt_address_t* addr, avrcp_play_status_t status,
uint32_t song_len, uint32_t song_pos);
/**
* @brief Notify playback status if peer device had register playback notification
*
* @param ins - Bluetooth client instance.
* @param addr - Remote BT address.
* @param status - current play status.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_avrcp_target_play_status_notify)(bt_instance_t* ins, bt_address_t* addr, avrcp_play_status_t status);
#ifdef __cplusplus
}
#endif
#endif /* __BT_AVRCP_TARGET_H__ */

View File

@ -0,0 +1,127 @@
#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__)
#include <nuttx/config.h>
#elif defined(ANDROID)
#define CONFIG_NET_RPMSG 1
#define CONFIG_LIB_BLUELET 1
#define CONFIG_QBUF_COUNT 20
#define CONFIG_BREDR 1
#define CONFIG_RFCOMM 1
#define CONFIG_LE 1
#define CONFIG_A2DP 1
#define CONFIG_BLUELET_A2DP_SBC_MAX_BIT_POOL 32
#define CONFIG_BLUELET_AVRCP_TG_ABSVOL_SUPPORT 1
#define CONFIG_BLUELET_AVRCP_MAX_CONNECTIONS 1
#define CONFIG_HFP 1
#define CONFIG_HFP_HF 1
#define CONFIG_HFP_AG 1
#define CONFIG_HID 1
#define CONFIG_BLUELET_HCI_H4 1
#define CONFIG_BLUELET_HCI_UART_NAME "/dev/ttyBT0"
#define CONFIG_BLUELET_HCI_RX_STACKSIZE 4096
#define CONFIG_BLUELET_DEBUG 1
#define CONFIG_BLUELET_DBG_HCI 1
#define CONFIG_BLUELET_DBG_HCIRAW 1
#define CONFIG_BLUELET_HCI_SNOOP_LOG_EN 1
#define CONFIG_BLUELET_HCI_SNOOP_CREATE_NEW 1
#define CONFIG_BLUELET_HCI_SNOOP_LOG_PATH "/data/misc/bt/snoop/"
#define CONFIG_BLUETOOTH 1
#define CONFIG_BLUETOOTH_BREDR_SUPPORT 1
#define CONFIG_BLUETOOTH_BLE_SUPPORT 1
#define CONFIG_BLUETOOTH_BLE_ADV 1
#define CONFIG_BLUETOOTH_BLE_SCAN 1
#define CONFIG_BLUETOOTH_GATT 1
#define CONFIG_BLUETOOTH_SERVICE_LOOP_THREAD_STACK_SIZE 8192
#define CONFIG_BLUETOOTH_SERVICE_LOOP_THREAD_PRIORITY 103
#define CONFIG_BLUETOOTH_AUDIO_TRANS_RPSMG_SERVER 1
#define CONFIG_BLUETOOTH_AUDIO_TRANS_ID_SOURCE_CTRL 0
#define CONFIG_BLUETOOTH_AUDIO_TRANS_ID_SOURCE_AUDIO 1
#define CONFIG_BLUETOOTH_AUDIO_TRANS_ID_SINK_CTRL 2
#define CONFIG_BLUETOOTH_AUDIO_TRANS_ID_SINK_AUDIO 3
#define CONFIG_BLUETOOTH_AUDIO_TRANS_ID_HFP_CTRL 4
#define CONFIG_BLUETOOTH_A2DP_SINK_CTRL_PATH "a2dp_sink_ctrl"
#define CONFIG_BLUETOOTH_A2DP_SINK_DATA_PATH "a2dp_sink_data"
#define CONFIG_BLUETOOTH_A2DP_SOURCE_CTRL_PATH "a2dp_source_ctrl"
#define CONFIG_BLUETOOTH_A2DP_SOURCE_DATA_PATH "a2dp_source_data"
#define CONFIG_BLUETOOTH_LEA_SINK_CTRL_PATH "lea_sink_ctrl"
#define CONFIG_BLUETOOTH_LEA_SINK_DATA_PATH "lea_sink_data"
#define CONFIG_BLUETOOTH_LEA_SOURCE_CTRL_PATH "lea_source_ctrl"
#define CONFIG_BLUETOOTH_LEA_SOURCE_DATA_PATH "lea_source_data"
#define CONFIG_BLUETOOTH_SCO_CTRL_PATH "sco_ctrl"
//#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
#define CONFIG_BLUETOOTH_AVRCP_TARGET 1
#define CONFIG_BLUETOOTH_AVRCP_CONTROL 1
#define CONFIG_BLUETOOTH_A2DP_MAX_CONNECTIONS 1
#define CONFIG_HFP_HF_MAX_CONNECTIONS 1
#define CONFIG_HFP_HF_WEBCHAT_BLOCKER 1
#define CONFIG_BLUETOOTH_HFP_HF 1
#define CONFIG_HFP_AG_MAX_CONNECTIONS 1
#define CONFIG_BLUETOOTH_HFP_AG_PRIMARY_SLOT 0
#define CONFIG_BLUETOOTH_SPP 1
#define CONFIG_BLUETOOTH_SPP_MAX_CONNECTIONS 1
#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_SOCKET_IPC 1
#define CONFIG_BLUETOOTH_SOCKET_PORT 6001
#define CONFIG_BLUETOOTH_SERVICE 1
//#define CONFIG_BLUETOOTH_SERVER 1
#define CONFIG_BLUETOOTH_SERVER_NAME "bluetoothd"
#define CONFIG_BLUETOOTH_IPC_JOIN_LOOP 1
//#define CONFIG_BLUETOOTH_SERVICE_LOG_LEVEL 7
#define CONFIG_BLUETOOTH_SERVICE_HCI_UART_NAME "/dev/ttyBT0"
#define CONFIG_BLUETOOTH_STACK_BREDR_BLUELET 1
#define CONFIG_BLUETOOTH_STACK_LE_BLUELET 1
#define CONFIG_BLUETOOTH_LE_SCANNER_MAX_NUM 2
#define CONFIG_BLUETOOTH_LE_ADVERTISER_MAX_NUM 2
#define CONFIG_BLUETOOTH_TOOLS 1
#define CONFIG_BLUETOOTH_VENDOR_BES 1
// Socket: via IPv4
//#define CONFIG_NET_IPv4 1
#define CONFIG_INADDR_LOOPBACK 0x0A000202
/********************* O95 Project Only *********************/
#if defined(ANDROID_12)
// Socket: RPMsg
#define CONFIG_BLUETOOTH_RPMSG_CPUNAME "ap"
// SPP
#define CONFIG_RPMSG_UART 1
/********************* O61 Project Only *********************/
#elif defined(ANDROID_14)
// Socket: RPMsg
#define CONFIG_BLUETOOTH_RPMSG_CPUNAME "cp"
// A2DP
#define CONFIG_BLUETOOTH_A2DP 1
#define CONFIG_BLUETOOTH_A2DP_SOURCE 1
// HFP
#define CONFIG_BLUETOOTH_HFP_AG 1
// HID
#define CONFIG_BLUETOOTH_HID_DEVICE 1
#endif
#endif
//############################################################################
#define CONFIG_y 1
#define CONFIG_m 2
#endif //__INCLUDE_BT_CONFIG_H

View File

@ -0,0 +1,47 @@
#ifndef __BT_DEBUG_H__
#define __BT_DEBUG_H__
#ifdef __cplusplus
extern "C" {
#endif
#if defined(__NuttX__) // Vela
#include <debug.h>
#include <syslog.h>
#include "utils/log.h"
#elif defined(ANDROID) // Android
#include <android/log.h>
#include <assert.h>
#include "utils/log.h"
#ifndef LOG_TAG
#define LOG_TAG "VELA-BT"
#endif
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#define syslog(x, ...) \
do { \
} while (0)
#define lib_dumpbuffer(x, y, z) \
do { \
} while (0)
#define zalloc(x) calloc(x, 1)
#define OK 0
#define UNUSED(x) ((void)(x))
#endif // End of Android
#ifdef __cplusplus
}
#endif
#endif /* __BT_DEBUG_H__ */

View File

@ -0,0 +1,424 @@
/****************************************************************************
* 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_DEVICE_H__
#define _BT_DEVICE_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "bluetooth.h"
#include "bt_addr.h"
#include "bt_status.h"
#include <stdint.h>
#ifndef BTSYMBOLS
#define BTSYMBOLS(s) s
#endif
/**
* @brief Profile connection state
*
*/
typedef enum {
PROFILE_STATE_DISCONNECTED,
PROFILE_STATE_CONNECTING,
PROFILE_STATE_CONNECTED,
PROFILE_STATE_DISCONNECTING,
} profile_connection_state_t;
/**
* @brief Profile connection reason
*
*/
typedef enum {
PROFILE_REASON_SUCCESS = 0x0000,
PROFILE_REASON_COLLISION = 0x0001,
PROFILE_REASON_UNSPECIFIED = 0xFFFF,
} profile_connection_reason_t;
/**
* @brief ACL connection state
*
*/
typedef enum {
CONNECTION_STATE_DISCONNECTED,
CONNECTION_STATE_CONNECTING,
CONNECTION_STATE_DISCONNECTING,
CONNECTION_STATE_CONNECTED,
CONNECTION_STATE_ENCRYPTED_BREDR,
CONNECTION_STATE_ENCRYPTED_LE
} connection_state_t;
/**
* @brief Bond state
*
*/
typedef enum {
BOND_STATE_NONE,
BOND_STATE_BONDING,
BOND_STATE_BONDED,
BOND_STATE_CANCELING
} bond_state_t;
/**
* @brief bluetooth connection policy
*
*/
typedef enum {
CONNECTION_POLICY_ALLOWED,
CONNECTION_POLICY_FORBIDDEN,
CONNECTION_POLICY_UNKNOWN,
} connection_policy_t;
/**
* @brief Get identity address of remote device
*
* @param ins - bluetooth client instance.
* @param bd_addr - remote device address.
* @param[out] id_addr - identity address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_get_identity_address)(bt_instance_t* ins, bt_address_t* bd_addr, bt_address_t* id_addr);
/**
* @brief Get identity address of remote device
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return ble_addr_type_t - address type, UNKNOWN on device not found.
*/
ble_addr_type_t BTSYMBOLS(bt_device_get_address_type)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Get remote device type
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return bt_device_type_t - device type, zero on device not found.
*/
bt_device_type_t BTSYMBOLS(bt_device_get_device_type)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Get remote device name
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param[out] name - remote device name.
* @param length - maximum length of name buffer.
* @return true - on success.
* @return false - on device not found.
*/
bool BTSYMBOLS(bt_device_get_name)(bt_instance_t* ins, bt_address_t* addr, char* name, uint32_t length);
/**
* @brief Get remote device class
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return uint32_t - cod, zero on device not found.
*/
uint32_t BTSYMBOLS(bt_device_get_device_class)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Get remote device support uuids
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param[out] uuids - out remote device uuids array.
* @param[out] size - out remote device uuid array size.
* @param allocator - array allocator.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_get_uuids)(bt_instance_t* ins, bt_address_t* addr, bt_uuid_t** uuids, uint16_t* size, bt_allocator_t allocator);
/**
* @brief Get remote device LE apperance
* @note Not support
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return uint16_t - apperance, zero on device not found.
*/
uint16_t BTSYMBOLS(bt_device_get_appearance)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Get remote device RSSI
* @note Not support
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return int8_t - rssi.
*/
int8_t BTSYMBOLS(bt_device_get_rssi)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Get remote device alias, default use remote name if not set
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param[out] alias - out alias buffer.
* @param length - maximum length of alias buffer.
* @return true on success.
* @return false on device not found.
*/
bool BTSYMBOLS(bt_device_get_alias)(bt_instance_t* ins, bt_address_t* addr, char* alias, uint32_t length);
/**
* @brief Set remote device alias
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param alias - alias.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_set_alias)(bt_instance_t* ins, bt_address_t* addr, const char* alias);
/**
* @brief Check remote deivce is connected
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return true - connected.
* @return false - not connected.
*/
bool BTSYMBOLS(bt_device_is_connected)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport);
/**
* @brief Check remote deivce is encrypted
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return true - encrypted
* @return false - not encrypted
*/
bool BTSYMBOLS(bt_device_is_encrypted)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport);
/**
* @brief Check is bond initiate from local
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return true - initiate from local.
* @return false - initiate from remote.
*/
bool BTSYMBOLS(bt_device_is_bond_initiate_local)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport);
/**
* @brief Get remote device bond state
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return bond_state_t - bond state.
*/
bond_state_t BTSYMBOLS(bt_device_get_bond_state)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport);
/**
* @brief Check remote device is bonded
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return true - bonded
* @return false - not bonded
*/
bool BTSYMBOLS(bt_device_is_bonded)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport);
/**
* @brief Initiate bond to remote device
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param transport - transport type (0:BLE, 1:BREDR).
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_create_bond)(bt_instance_t* ins, bt_address_t* addr, bt_transport_t transport);
/**
* @brief Remove bonded device
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param transport - transport type (0:BLE, 1:BREDR).
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_remove_bond)(bt_instance_t* ins, bt_address_t* addr, uint8_t transport);
/**
* @brief Cancel bonding
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_cancel_bond)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Reply pairing request
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param accept - true:accept, false:reject.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_pair_request_reply)(bt_instance_t* ins, bt_address_t* addr, bool accept);
/**
* @brief Set pairing confirmation
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param transport - transport type (0:BLE, 1:BREDR).
* @param accept - true:accept, false:reject.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_set_pairing_confirmation)(bt_instance_t* ins, bt_address_t* addr, uint8_t transport, bool accept);
/**
* @brief Set pairing PIN code
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param accept - true:accept, false:reject.
* @param pincode - pin code string.
* @param len - length of pin code string
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_set_pin_code)(bt_instance_t* ins, bt_address_t* addr, bool accept,
char* pincode, int len);
/**
* @brief Set simple securty pair passkey or LE smp key
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param transport - transport type (0:BLE, 1:BREDR).
* @param accept - true:accept, false:reject.
* @param passkey - on transport is BREDR, mean ssp passkey; on transport is LE, mean smp key.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_set_pass_key)(bt_instance_t* ins, bt_address_t* addr, uint8_t transport, bool accept, uint32_t passkey);
/**
* @brief Set OOB temporary key for LE legacy pairing
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param tk_val - Legacy pairing OOB TK value.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_set_le_legacy_tk)(bt_instance_t* ins, bt_address_t* addr, bt_128key_t tk_val);
/**
* @brief Set remote OOB data for LE secure connection pairing
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param c_val - LE secure connection confirmation value.
* @param r_val - LE secure connection random value.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_set_le_sc_remote_oob_data)(bt_instance_t* ins, bt_address_t* addr, bt_128key_t c_val, bt_128key_t r_val);
/**
* @brief Get local OOB data for LE secure connection pairing
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_get_le_sc_local_oob_data)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Connect to peer device
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_connect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Disconnect from ACL connection.
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_disconnect)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Connect to LE device
*
* @param ins - bluetooth client instance.
* @param addr - remote LE device address.
* @param type - LE address type.
* @param param - connect params.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_connect_le)(bt_instance_t* ins, bt_address_t* addr,
ble_addr_type_t type,
ble_connect_params_t* param);
/**
* @brief Disconnect from LE connection
*
* @param ins - bluetooth client instance.
* @param addr - remote LE device address.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_disconnect_le)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Reply connect request
*
* @param ins - bluetooth client instance.
* @param addr - remote device address.
* @param accept - true:accept, false:reject.
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_connect_request_reply)(bt_instance_t* ins, bt_address_t* addr, bool accept);
/**
* @brief Set LE phy
*
* @param ins - bluetooth client instance.
* @param addr - remote LE device address.
* @param tx_phy - tx phy (0:1M, 1:2M, 2:CODED).
* @param rx_phy - rx phy (0:1M, 1:2M, 2:CODED).
* @return bt_status_t - BT_STATUS_SUCCESS on success, a negated errno value on failure.
*/
bt_status_t BTSYMBOLS(bt_device_set_le_phy)(bt_instance_t* ins, bt_address_t* addr,
ble_phy_type_t tx_phy,
ble_phy_type_t rx_phy);
/**
* @brief Connect to all profile.
* @note not support.
* @param ins - bluetooth client instance.
*/
void BTSYMBOLS(bt_device_connect_all_profile)(bt_instance_t* ins, bt_address_t* addr);
/**
* @brief Disconnect from all profile.
* @note not support.
* @param ins - bluetooth client instance.
*/
void BTSYMBOLS(bt_device_disconnect_all_profile)(bt_instance_t* ins, bt_address_t* addr);
#ifdef __cplusplus
}
#endif
#endif /* _BT_DEVICE_H__ */

View File

@ -0,0 +1,152 @@
/****************************************************************************
* 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_GATT_DEFS_H__
#define __BT_GATT_DEFS_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
typedef enum {
GATT_STATUS_SUCCESS,
GATT_STATUS_FAILURE,
GATT_STATUS_REQUEST_NOT_SUPPORTED,
GATT_STATUS_INSUFFICIENT_AUTHENTICATION,
GATT_STATUS_INSUFFICIENT_ENCRYPTION,
GATT_STATUS_READ_NOT_PERMITTED,
GATT_STATUS_WRITE_NOT_PERMITTED,
GATT_STATUS_INVALID_ATTRIBUTE_LENGTH
} gatt_status_t;
typedef enum {
GATT_PRIMARY_SERVICE,
GATT_SECONDARY_SERVICE,
GATT_INCLUDED_SERVICE,
GATT_CHARACTERISTIC,
GATT_DESCRIPTOR
} gatt_attr_type_t;
typedef enum {
ATTR_AUTO_RSP,
ATTR_RSP_BY_APP,
} gatt_attr_rsp_t;
#ifdef CONFIG_BLUETOOTH_GATTS_MAX_ATTRIBUTE_NUM
#define GATTS_MAX_ATTRIBUTE_NUM CONFIG_BLUETOOTH_GATTS_MAX_ATTRIBUTE_NUM
#else
#define GATTS_MAX_ATTRIBUTE_NUM 16
#endif
/* MAX GATT MTU size */
#define GATT_MAX_MTU_SIZE 517
/* Attribute permissions */
#define GATT_PERM_READ 0x01
#define GATT_PERM_WRITE 0x02
#define GATT_PERM_ENCRYPT_REQUIRED 0x04
#define GATT_PERM_AUTHEN_REQUIRED 0x08
#define GATT_PERM_MITM_REQUIRED 0x10
/* Characteristic Properties */
#define GATT_PROP_BROADCAST 0x01
#define GATT_PROP_READ 0x02
#define GATT_PROP_WRITE_NR 0x04
#define GATT_PROP_WRITE 0x08
#define GATT_PROP_NOTIFY 0x10
#define GATT_PROP_INDICATE 0x20
#define GATT_PROP_SIGNED_WRITE 0x40
#define GATT_PROP_EXTENDED_PROPS 0x80
#define GATT_PROP_EXPOSED_OVER_BREDR 0x1000 /* Applies to Primary/Secondary Service type only */
/* Client Characteristic Configuration Values */
#define GATT_CCC_NOTIFY 0x0001
#define GATT_CCC_INDICATE 0x0002
/* GATT Attribute Helper Macros */
#define GATT_H_ATTRIBUTE(_uuid, _type, _prop, _perm, _rsp, _read, _write, _value, _length, _handle) \
{ \
.handle = _handle, \
.uuid = _uuid, \
.type = _type, \
.properties = _prop, \
.permissions = _perm, \
.rsp_type = _rsp, \
.read_cb = _read, \
.write_cb = _write, \
.attr_length = _length, \
.attr_value = _value \
}
/* GATT_H_PRIMARY_SERVICE */
#define GATT_H_PRIMARY_SERVICE(_service, _handle) \
GATT_H_ATTRIBUTE(_service, GATT_PRIMARY_SERVICE, 0, GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, NULL, 0, _handle)
/* GATT_H_SECONDARY_SERVICE */
#define GATT_H_SECONDARY_SERVICE(_service, _handle) \
GATT_H_ATTRIBUTE(_service, GATT_SECONDARY_SERVICE, 0, GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, NULL, 0, _handle)
/* GATT_H_INCLUDE_SERVICE */
#define GATT_H_INCLUDE_SERVICE(_service, _handle) \
GATT_H_ATTRIBUTE(_service, GATT_INCLUDED_SERVICE, 0, GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, NULL, 0, _handle)
/* GATT_H_PRIMARY_SERVICE_OVER_BREDR */
#define GATT_H_PRIMARY_SERVICE_OVER_BREDR(_service, _handle) \
GATT_H_ATTRIBUTE(_service, GATT_PRIMARY_SERVICE, GATT_PROP_EXPOSED_OVER_BREDR, GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, NULL, 0, _handle)
/* GATT_H_SECONDARY_SERVICE_OVER_BREDR */
#define GATT_H_SECONDARY_SERVICE_OVER_BREDR(_service, _handle) \
GATT_H_ATTRIBUTE(_service, GATT_SECONDARY_SERVICE, GATT_PROP_EXPOSED_OVER_BREDR, GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, NULL, 0, _handle)
/* GATT_H_CHARACTERISTIC */
#define GATT_H_CHARACTERISTIC(_uuid, _prop, _perm, _rsp, _read, _write, _value, _length, _handle) \
GATT_H_ATTRIBUTE(_uuid, GATT_CHARACTERISTIC, _prop, _perm, _rsp, _read, _write, _value, _length, _handle)
/* GATT_H_CHARACTERISTIC */
#define GATT_H_CHARACTERISTIC_AUTO_RSP(_uuid, _prop, _perm, _value, _length, _handle) \
GATT_H_ATTRIBUTE(_uuid, GATT_CHARACTERISTIC, _prop, _perm, ATTR_AUTO_RSP, NULL, NULL, _value, _length, _handle)
/* GATT_H_CHARACTERISTIC */
#define GATT_H_CHARACTERISTIC_USER_RSP(_uuid, _prop, _perm, _read, _write, _handle) \
GATT_H_ATTRIBUTE(_uuid, GATT_CHARACTERISTIC, _prop, _perm, ATTR_RSP_BY_APP, _read, _write, NULL, 0, _handle)
/* GATT_H_DESCRIPTOR */
#define GATT_H_DESCRIPTOR(_uuid, _perm, _rsp, _read, _write, _value, _length, _handle) \
GATT_H_ATTRIBUTE(_uuid, GATT_DESCRIPTOR, 0, _perm, _rsp, _read, _write, _value, _length, _handle)
/* GATT_H_DESCRIPTOR */
#define GATT_H_CEPD(_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(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(0x2902), _perm, ATTR_RSP_BY_APP, NULL, _change, NULL, 0, _handle)
/* GATT_H_DESCRIPTOR */
#define GATT_H_CPFD(_value, _length, _handle) \
GATT_H_DESCRIPTOR(BT_UUID_DECLARE_16(0x2904), GATT_PERM_READ, ATTR_AUTO_RSP, NULL, NULL, _value, _length, _handle)
#ifdef __cplusplus
}
#endif
#endif /* __BT_GATT_DEFS_H_ */

View File

@ -0,0 +1,100 @@
/****************************************************************************
* 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_GATTC_H__
#define __BT_GATTC_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "bluetooth.h"
#include "bt_addr.h"
#include "bt_gatt_defs.h"
#include "bt_status.h"
#include "bt_uuid.h"
#include <stddef.h>
#ifndef BTSYMBOLS
#define BTSYMBOLS(s) s
#endif
typedef void* gattc_handle_t;
typedef struct {
uint8_t type; /* gatt_attr_type_t */
uint8_t pad[1];
uint16_t handle;
bt_uuid_t uuid;
uint32_t properties;
} gatt_attr_desc_t;
typedef void (*gattc_connected_cb_t)(gattc_handle_t conn_handle, bt_address_t* addr);
typedef void (*gattc_disconnected_cb_t)(gattc_handle_t conn_handle, bt_address_t* addr);
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);
typedef void (*gattc_mtu_updated_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, uint32_t mtu);
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);
typedef void (*gattc_write_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, uint16_t attr_handle);
typedef void (*gattc_subscribe_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, uint16_t attr_handle, bool enable);
typedef void (*gattc_notify_cb_t)(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length);
typedef void (*gattc_phy_read_cb_t)(gattc_handle_t conn_handle, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy);
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);
typedef void (*gattc_rssi_read_cb_t)(gattc_handle_t conn_handle, gatt_status_t status, int32_t rssi);
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);
typedef struct {
uint32_t size;
gattc_connected_cb_t on_connected;
gattc_disconnected_cb_t on_disconnected;
gattc_discover_cb_t on_discovered;
gattc_read_cb_t on_read;
gattc_write_cb_t on_written;
gattc_subscribe_cb_t on_subscribed;
gattc_notify_cb_t on_notified;
gattc_mtu_updated_cb_t on_mtu_updated;
gattc_phy_read_cb_t on_phy_read;
gattc_phy_updated_cb_t on_phy_updated;
gattc_rssi_read_cb_t on_rssi_read;
gattc_connection_parameter_updated_cb_t on_conn_param_updated;
} gattc_callbacks_t;
bt_status_t BTSYMBOLS(bt_gattc_create_connect)(bt_instance_t* ins, gattc_handle_t* phandle, gattc_callbacks_t* callbacks);
bt_status_t BTSYMBOLS(bt_gattc_delete_connect)(gattc_handle_t conn_handle);
bt_status_t BTSYMBOLS(bt_gattc_connect)(gattc_handle_t conn_handle, bt_address_t* addr, ble_addr_type_t addr_type);
bt_status_t BTSYMBOLS(bt_gattc_disconnect)(gattc_handle_t conn_handle);
bt_status_t BTSYMBOLS(bt_gattc_discover_service)(gattc_handle_t conn_handle, bt_uuid_t* filter_uuid);
bt_status_t BTSYMBOLS(bt_gattc_get_attribute_by_handle)(gattc_handle_t conn_handle, uint16_t attr_handle, gatt_attr_desc_t* attr_desc);
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);
bt_status_t BTSYMBOLS(bt_gattc_read)(gattc_handle_t conn_handle, uint16_t attr_handle);
bt_status_t BTSYMBOLS(bt_gattc_write)(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length);
bt_status_t BTSYMBOLS(bt_gattc_write_without_response)(gattc_handle_t conn_handle, uint16_t attr_handle, uint8_t* value, uint16_t length);
bt_status_t BTSYMBOLS(bt_gattc_subscribe)(gattc_handle_t conn_handle, uint16_t attr_handle, uint16_t ccc_value);
bt_status_t BTSYMBOLS(bt_gattc_unsubscribe)(gattc_handle_t conn_handle, uint16_t attr_handle);
bt_status_t BTSYMBOLS(bt_gattc_exchange_mtu)(gattc_handle_t conn_handle, uint32_t mtu);
bt_status_t BTSYMBOLS(bt_gattc_update_connection_parameter)(gattc_handle_t conn_handle, uint32_t min_interval, uint32_t max_interval,
uint32_t latency, uint32_t timeout, uint32_t min_connection_event_length,
uint32_t max_connection_event_length);
bt_status_t BTSYMBOLS(bt_gattc_read_phy)(gattc_handle_t conn_handle);
bt_status_t BTSYMBOLS(bt_gattc_update_phy)(gattc_handle_t conn_handle, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy);
bt_status_t BTSYMBOLS(bt_gattc_read_rssi)(gattc_handle_t conn_handle);
#ifdef __cplusplus
}
#endif
#endif /* __BT_GATTC_H__ */

View File

@ -0,0 +1,104 @@
/****************************************************************************
* 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_GATTS_H__
#define __BT_GATTS_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "bluetooth.h"
#include "bt_addr.h"
#include "bt_gatt_defs.h"
#include "bt_status.h"
#include "bt_uuid.h"
#include <stddef.h>
#ifndef BTSYMBOLS
#define BTSYMBOLS(s) s
#endif
typedef void* gatts_handle_t;
typedef uint16_t (*attribute_read_cb_t)(gatts_handle_t srv_handle, bt_address_t* addr, uint16_t attr_handle, uint32_t req_handle);
typedef uint16_t (*attribute_written_cb_t)(gatts_handle_t srv_handle, bt_address_t* addr, uint16_t attr_handle,
const uint8_t* value, uint16_t length, uint16_t offset);
typedef struct {
uint16_t handle;
bt_uuid_t uuid;
gatt_attr_type_t type;
uint32_t properties;
uint32_t permissions;
gatt_attr_rsp_t rsp_type;
attribute_read_cb_t read_cb;
attribute_written_cb_t write_cb;
uint32_t attr_length;
uint8_t* attr_value;
} gatt_attr_db_t;
typedef struct {
int32_t attr_num;
gatt_attr_db_t* attr_db;
} gatt_srv_db_t;
typedef void (*gatts_connected_cb_t)(gatts_handle_t srv_handle, bt_address_t* addr);
typedef void (*gatts_disconnected_cb_t)(gatts_handle_t srv_handle, bt_address_t* addr);
typedef void (*gatts_attr_table_added_cb_t)(gatts_handle_t srv_handle, gatt_status_t status, uint16_t attr_handle);
typedef void (*gatts_attr_table_removed_cb_t)(gatts_handle_t srv_handle, gatt_status_t status, uint16_t attr_handle);
typedef void (*gatts_mtu_changed_cb_t)(gatts_handle_t srv_handle, bt_address_t* addr, uint32_t mtu);
typedef void (*gatts_nofity_complete_cb_t)(gatts_handle_t srv_handle, bt_address_t* addr, gatt_status_t status, uint16_t attr_handle);
typedef void (*gatts_phy_read_cb_t)(gatts_handle_t srv_handle, bt_address_t* addr, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy);
typedef void (*gatts_phy_updated_cb_t)(gatts_handle_t srv_handle, bt_address_t* addr, gatt_status_t status, ble_phy_type_t tx_phy,
ble_phy_type_t rx_phy);
typedef void (*gatts_connection_parameter_changed_cb_t)(gatts_handle_t srv_handle, bt_address_t* addr, uint16_t connection_interval,
uint16_t peripheral_latency, uint16_t supervision_timeout);
typedef struct {
uint32_t size;
gatts_connected_cb_t on_connected;
gatts_disconnected_cb_t on_disconnected;
gatts_attr_table_added_cb_t on_attr_table_added;
gatts_attr_table_removed_cb_t on_attr_table_removed;
gatts_nofity_complete_cb_t on_notify_complete;
gatts_mtu_changed_cb_t on_mtu_changed;
gatts_phy_read_cb_t on_phy_read;
gatts_phy_updated_cb_t on_phy_updated;
gatts_connection_parameter_changed_cb_t on_conn_param_changed;
} gatts_callbacks_t;
bt_status_t BTSYMBOLS(bt_gatts_register_service)(bt_instance_t* ins, gatts_handle_t* phandle, gatts_callbacks_t* callbacks);
bt_status_t BTSYMBOLS(bt_gatts_unregister_service)(gatts_handle_t srv_handle);
bt_status_t BTSYMBOLS(bt_gatts_connect)(gatts_handle_t srv_handle, bt_address_t* addr, ble_addr_type_t addr_type);
bt_status_t BTSYMBOLS(bt_gatts_disconnect)(gatts_handle_t srv_handle, bt_address_t* addr);
bt_status_t BTSYMBOLS(bt_gatts_add_attr_table)(gatts_handle_t srv_handle, gatt_srv_db_t* srv_db);
bt_status_t BTSYMBOLS(bt_gatts_remove_attr_table)(gatts_handle_t srv_handle, uint16_t attr_handle);
bt_status_t BTSYMBOLS(bt_gatts_set_attr_value)(gatts_handle_t srv_handle, uint16_t attr_handle, uint8_t* value, uint16_t length);
bt_status_t BTSYMBOLS(bt_gatts_get_attr_value)(gatts_handle_t srv_handle, uint16_t attr_handle, uint8_t* value, uint16_t* length);
bt_status_t BTSYMBOLS(bt_gatts_response)(gatts_handle_t srv_handle, bt_address_t* addr, uint32_t req_handle, uint8_t* value, uint16_t length);
bt_status_t BTSYMBOLS(bt_gatts_notify)(gatts_handle_t srv_handle, bt_address_t* addr, uint16_t attr_handle, uint8_t* value, uint16_t length);
bt_status_t BTSYMBOLS(bt_gatts_indicate)(gatts_handle_t srv_handle, bt_address_t* addr, uint16_t attr_handle, uint8_t* value, uint16_t length);
bt_status_t BTSYMBOLS(bt_gatts_read_phy)(gatts_handle_t srv_handle, bt_address_t* addr);
bt_status_t BTSYMBOLS(bt_gatts_update_phy)(gatts_handle_t srv_handle, bt_address_t* addr, ble_phy_type_t tx_phy, ble_phy_type_t rx_phy);
#ifdef __cplusplus
}
#endif
#endif /* __BT_GATTS_H__ */

View File

@ -0,0 +1,32 @@
/****************************************************************************
* Copyright (C) 2024 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#ifndef __BT_HASH_H__
#define __BT_HASH_H__
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdio.h>
uint32_t bt_hash4(const void* keyarg, size_t len);
#ifdef __cplusplus
}
#endif
#endif /* __BT_HASH_H__ */

122
framework/include/bt_hfp.h Normal file
View File

@ -0,0 +1,122 @@
/****************************************************************************
* Copyright (C) 2022 Xiaomi Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#ifndef __BT_HFP_H__
#define __BT_HFP_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "bt_addr.h"
#include "bt_device.h"
#include <stddef.h>
/* According to HFP 1.9: Phone number string (max. 32 digits) */
#define HFP_PHONENUM_DIGITS_MAX 32
#define HFP_NAME_DIGITS_MAX 64
/* Although not explicitly stated in HFP, it is limited to 512
for better compatibility.
Also defined as BTA_HF_CLIENT_AT_MAX_LEN (512) at Android */
#define HFP_AT_LEN_MAX 512
#define HFP_CALL_LIST_MAX 4
typedef enum {
HFP_AUDIO_STATE_DISCONNECTED,
HFP_AUDIO_STATE_CONNECTING,
HFP_AUDIO_STATE_CONNECTED,
HFP_AUDIO_STATE_DISCONNECTING,
} hfp_audio_state_t;
typedef enum {
HFP_CALL_NO_CALLS_IN_PROGRESS = 0,
HFP_CALL_CALLS_IN_PROGRESS
} hfp_call_t;
typedef enum {
HFP_CALLSETUP_NONE = 0,
HFP_CALLSETUP_INCOMING,
HFP_CALLSETUP_OUTGOING,
HFP_CALLSETUP_ALERTING
} hfp_callsetup_t;
typedef enum {
HFP_CALLHELD_NONE = 0,
HFP_CALLHELD_HELD,
} hfp_callheld_t;
typedef enum {
HFP_HF_VR_STATE_STOPPED = 0,
HFP_HF_VR_STATE_STARTED
} hfp_hf_vr_state_t;
typedef enum {
HFP_VOLUME_TYPE_SPK = 0,
HFP_VOLUME_TYPE_MIC
} hfp_volume_type_t;
typedef enum {
HFP_HF_CALL_CONTROL_CHLD_0, /* Releases all held calls or sets User Determined User Busy (UDUB) for a waiting call */
HFP_HF_CALL_CONTROL_CHLD_1, /* Releases all active calls (if any exist) and accepts the other (held or waiting) call */
HFP_HF_CALL_CONTROL_CHLD_2, /* Places all active calls (if any exist) on hold and accepts the other (held or waiting) call */
HFP_HF_CALL_CONTROL_CHLD_3, /* Adds a held call to the conversation */
HFP_HF_CALL_CONTROL_CHLD_4 /* Connects the two calls and disconnects the subscriber from both calls (Explicit Call Transfer).
Support for this value and its associated functionality is optional for the HF */
} hfp_call_control_t;
typedef enum {
HFP_HF_CALL_ACCEPT_NONE,
HFP_HF_CALL_ACCEPT_RELEASE,
HFP_HF_CALL_ACCEPT_HOLD,
} hfp_call_accept_t;
typedef enum {
HFP_CALL_DIRECTION_OUTGOING = 0,
HFP_CALL_DIRECTION_INCOMING
} hfp_call_direction_t;
typedef enum {
HFP_CALL_MPTY_TYPE_SINGLE = 0,
HFP_CALL_MPTY_TYPE_MULTI
} hfp_call_mpty_type_t;
typedef enum {
HFP_CALL_MODE_VOICE = 0,
HFP_CALL_MODE_DATA,
HFP_CALL_MODE_FAX
} hfp_call_mode_t;
typedef enum {
HFP_CALL_ADDRTYPE_UNKNOWN = 0x81,
HFP_CALL_ADDRTYPE_INTERNATIONAL = 0x91,
HFP_CALL_ADDRTYPE_NATIONAL = 0xA1,
} hfp_call_addrtype_t;
typedef enum {
HFP_NETWORK_NOT_AVAILABLE = 0,
HFP_NETWORK_AVAILABLE,
} hfp_network_state_t;
typedef enum {
HFP_ROAM_STATE_NO_ROAMING = 0,
HFP_ROAM_STATE_ROAMING,
} hfp_roaming_state_t;
#ifdef __cplusplus
}
#endif
#endif /* __BT_HFP_H__ */

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