Merge branch 'feature/btdm_bluedroid' into feature/btdm_a2dp

# Conflicts:
#	components/bt/bluedroid/bta/sys/bta_sys_main.c
#	components/bt/bluedroid/btc/profile/std/avrc/avrc_api.c
#	components/bt/bluedroid/btc/profile/std/avrc/avrc_bld_ct.c
#	components/bt/bluedroid/btc/profile/std/avrc/avrc_bld_tg.c
#	components/bt/bluedroid/btc/profile/std/avrc/avrc_opt.c
#	components/bt/bluedroid/btc/profile/std/avrc/avrc_pars_ct.c
#	components/bt/bluedroid/btc/profile/std/avrc/avrc_pars_tg.c
#	components/bt/bluedroid/btc/profile/std/avrc/avrc_sdp.c
#	components/bt/bluedroid/btc/profile/std/avrc/avrc_utils.c
#	components/bt/bluedroid/btc/profile/std/avrc/include/avrc_int.h
#	components/bt/bluedroid/btc/profile/std/include/avct_api.h
#	components/bt/bluedroid/btc/profile/std/include/avdt_api.h
#	components/bt/bluedroid/btc/profile/std/include/avdt_defs.h
#	components/bt/bluedroid/btc/profile/std/include/avdtc_api.h
#	components/bt/bluedroid/btc/profile/std/include/avrc_api.h
#	components/bt/bluedroid/btc/profile/std/include/avrc_defs.h
#	components/bt/bluedroid/gki/gki_buffer.c
#	components/bt/bluedroid/hci/hci_hal_h4.c
#	components/bt/bluedroid/hci/hci_layer.c
#	components/bt/bluedroid/hci/packet_fragmenter.c
#	components/bt/bluedroid/include/bt_trace.h
#	components/bt/bluedroid/osi/alarm.c
#	components/bt/bluedroid/profiles/std/avrc/avrc_api.c
#	components/bt/bluedroid/profiles/std/avrc/avrc_bld_ct.c
#	components/bt/bluedroid/profiles/std/avrc/avrc_bld_tg.c
#	components/bt/bluedroid/profiles/std/avrc/avrc_opt.c
#	components/bt/bluedroid/profiles/std/avrc/avrc_pars_ct.c
#	components/bt/bluedroid/profiles/std/avrc/avrc_pars_tg.c
#	components/bt/bluedroid/profiles/std/avrc/avrc_sdp.c
#	components/bt/bluedroid/profiles/std/avrc/avrc_utils.c
#	components/bt/bluedroid/profiles/std/avrc/include/avrc_int.h
#	components/bt/bluedroid/profiles/std/include/avct_api.h
#	components/bt/bluedroid/profiles/std/include/avdt_api.h
#	components/bt/bluedroid/profiles/std/include/avdt_defs.h
#	components/bt/bluedroid/profiles/std/include/avdtc_api.h
#	components/bt/bluedroid/profiles/std/include/avrc_api.h
#	components/bt/bluedroid/profiles/std/include/avrc_defs.h
#	components/bt/bluedroid/stack/avdt/include/avdt_defs.h
#	components/bt/bluedroid/stack/avrc/avrc_api.c
#	components/bt/bluedroid/stack/avrc/avrc_bld_ct.c
#	components/bt/bluedroid/stack/avrc/avrc_bld_tg.c
#	components/bt/bluedroid/stack/avrc/avrc_opt.c
#	components/bt/bluedroid/stack/avrc/avrc_pars_ct.c
#	components/bt/bluedroid/stack/avrc/avrc_pars_tg.c
#	components/bt/bluedroid/stack/avrc/avrc_sdp.c
#	components/bt/bluedroid/stack/avrc/avrc_utils.c
#	components/bt/bluedroid/stack/avrc/include/avrc_int.h
#	components/bt/bluedroid/stack/btu/btu_task.c
#	components/bt/bluedroid/stack/include/avct_api.h
#	components/bt/bluedroid/stack/include/avdt_api.h
#	components/bt/bluedroid/stack/include/avdtc_api.h
#	components/bt/bluedroid/stack/include/avrc_api.h
#	components/bt/bluedroid/stack/include/avrc_defs.h
#	components/bt/bluedroid/stack/include/gatt_api.h
#	components/bt/bluedroid/stack/l2cap/l2c_main.c
#	components/bt/component.mk
#	examples/06_bluedroid_demos/components/bluedroid_demos/app_core/bt_app_core.c
This commit is contained in:
wangmengyang 2016-11-25 19:45:29 +08:00
commit 73f00732cf
790 changed files with 83839 additions and 46386 deletions

10
.gitignore vendored
View file

@ -19,3 +19,13 @@ GPATH
examples/*/sdkconfig
examples/*/sdkconfig.old
examples/*/build
#Doc build artifacts
docs/_build/
docs/doxygen-warning-log.txt
docs/xml/
# Unit test app files
tools/unit-test-app/sdkconfig
tools/unit-test-app/sdkconfig.old
tools/unit-test-app/build

View file

@ -1,6 +1,8 @@
stages:
- build
- unit_test
- test
- test_report
- deploy
before_script:
@ -61,10 +63,7 @@ build_ssc:
<<: *build_template
artifacts:
paths:
- ./SSC/build/*.bin
- ./SSC/build/*.elf
- ./SSC/build/*.map
- ./SSC/build/bootloader/*.bin
- ./SSC/ssc_bin
expire_in: 6 mos
script:
@ -75,6 +74,22 @@ build_ssc:
- chmod +x gen_misc_ng.sh
- ./gen_misc_ng.sh
build_esp_idf_tests:
<<: *build_template
artifacts:
paths:
- ./tools/unit-test-app/build/*.bin
- ./tools/unit-test-app/build/*.elf
- ./tools/unit-test-app/build/*.map
- ./tools/unit-test-app/build/bootloader/*.bin
expire_in: 6 mos
script:
- cd tools/unit-test-app
- git checkout ${CI_BUILD_REF_NAME} || echo "Using default branch..."
- make defconfig
- make
build_examples:
<<: *build_template
artifacts:
@ -92,13 +107,30 @@ build_examples:
- cd build_examples
- ${IDF_PATH}/make/build_examples.sh
build_docs:
stage: build
image: espressif/esp32-ci-env
tags:
- build_docs
script:
- cd docs
- doxygen
# If not building master branch, and there are Doxygen warnings, print them and bail out
- test "${CI_BUILD_REF_NAME}" = "master" || test $(cat doxygen-warning-log.txt | wc -l) -eq 0 || ( echo "Doxygen pass had some warnings:" && cat doxygen-warning-log.txt && false )
- make html
artifacts:
paths:
- docs/_build/html
expire_in: 1 mos
test_nvs_on_host:
stage: test
image: espressif/esp32-ci-env
tags:
- nvs_host_test
script:
- cd components/nvs_flash/test
- cd components/nvs_flash/test_nvs_host
- make test
test_build_system:
@ -112,13 +144,12 @@ test_build_system:
- ./make/test_build_system.sh
test_report:
stage: deploy
stage: test_report
only:
- master
- triggers
tags:
- test_report
allow_failure: true
variables:
LOG_PATH: "$CI_PROJECT_DIR/$CI_BUILD_REF"
TEST_CASE_FILE_PATH: "$CI_PROJECT_DIR/components/idf_test"
@ -127,7 +158,8 @@ test_report:
when: always
paths:
- $REPORT_PATH
expire_in: 6 mos
- $LOG_PATH
expire_in: 12 mos
script:
# clone test bench
- git clone $GITLAB_SSH_SERVER/yinling/auto_test_script.git
@ -159,6 +191,31 @@ push_master_to_github:
- git push --follow-tags github HEAD:master
deploy_docs:
before_script:
- echo "Not setting up GitLab key, not fetching submodules"
stage: deploy
only:
- master
- triggers
tags:
- deploy
image: espressif/esp32-ci-env
script:
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo -n $DOCS_DEPLOY_KEY > ~/.ssh/id_rsa_base64
- base64 --decode --ignore-garbage ~/.ssh/id_rsa_base64 > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- echo -e "Host $DOCS_SERVER\n\tStrictHostKeyChecking no\n\tUser $DOCS_SERVER_USER\n" >> ~/.ssh/config
- export GIT_VER=$(git describe --always)
- cd docs/_build/
- mv html $GIT_VER
- tar czvf $GIT_VER.tar.gz $GIT_VER
- scp $GIT_VER.tar.gz $DOCS_SERVER:$DOCS_PATH
- ssh $DOCS_SERVER -x "cd $DOCS_PATH && tar xzvf $GIT_VER.tar.gz && rm -f latest && ln -s $GIT_VER latest"
# AUTO GENERATED PART START, DO NOT MODIFY CONTENT BELOW
# template for test jobs
.test_template: &test_template
@ -172,11 +229,11 @@ push_master_to_github:
variables:
# LOCAL_ENV_CONFIG_PATH: define in template and jobs can overwrite if required
LOCAL_ENV_CONFIG_PATH: /home/gitlab-runner/LocalConfig/ESP32_IDF
BIN_PATH: "$CI_PROJECT_DIR/SSC/build/"
BIN_PATH: "$CI_PROJECT_DIR/SSC/ssc_bin/SSC"
APP_NAME: "ssc"
LOG_PATH: "$CI_PROJECT_DIR/$CI_BUILD_REF"
# append test level folder to TEST_CASE_FILE_PATH in before_script of test job
TEST_CASE_FILE_PATH: "$CI_PROJECT_DIR/components/idf_test"
TEST_CASE_FILE_PATH: "$CI_PROJECT_DIR/components/idf_test/integration_test"
# jobs MUST set CONFIG_FILE in before_script, and overwrite the variables above if necessary
artifacts:
@ -222,13 +279,34 @@ push_master_to_github:
# run test
- python CIRunner.py -l $LOG_PATH -c $CONFIG_FILE -e $LOCAL_ENV_CONFIG_PATH -t $TEST_CASE_FILE_PATH bin_path $APP_NAME $BIN_PATH
# template for unit test jobs
.unit_test_template: &unit_test_template
<<: *test_template
allow_failure: false
stage: unit_test
variables:
# jobs MUST set CONFIG_FILE in before_script, and overwrite the variables above if necessary
LOCAL_ENV_CONFIG_PATH: /home/gitlab-runner/LocalConfig/ESP32_IDF
BIN_PATH: "$CI_PROJECT_DIR/esp-idf-tests/build/"
LOG_PATH: "$CI_PROJECT_DIR/$CI_BUILD_REF"
APP_NAME: "ut"
TEST_CASE_FILE_PATH: "$CI_PROJECT_DIR/components/idf_test/unit_test"
UT_Function_SYS_01:
<<: *unit_test_template
tags:
- ESP32_IDF
- UT_T1_1
before_script:
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/UT_Function_SYS_01.yml
IT_Function_SYS_01:
<<: *test_template
tags:
- ESP32_IDF
- SSC_T1_1
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_SYS_01.yml
IT_Function_WIFI_01:
@ -238,7 +316,6 @@ IT_Function_WIFI_01:
- SSC_T1_1
- SSC_T2_1
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_WIFI_01.yml
IT_Function_WIFI_02:
@ -248,7 +325,6 @@ IT_Function_WIFI_02:
- SSC_T1_1
- SSC_T2_1
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_WIFI_02.yml
IT_Function_TCPIP_01:
@ -258,7 +334,6 @@ IT_Function_TCPIP_01:
- SSC_T1_1
- SSC_T2_1
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_01.yml
IT_Function_TCPIP_02:
@ -268,7 +343,6 @@ IT_Function_TCPIP_02:
- SSC_T1_1
- SSC_T2_1
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_02.yml
IT_Function_TCPIP_03:
@ -278,7 +352,6 @@ IT_Function_TCPIP_03:
- SSC_T1_1
- SSC_T2_1
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_03.yml
IT_Function_TCPIP_04:
@ -288,7 +361,6 @@ IT_Function_TCPIP_04:
- SSC_T1_1
- SSC_T2_1
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_04.yml
IT_Function_TCPIP_05:
@ -298,7 +370,6 @@ IT_Function_TCPIP_05:
- SSC_T1_1
- SSC_T2_1
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_05.yml
IT_Function_TCPIP_06:
@ -307,7 +378,6 @@ IT_Function_TCPIP_06:
- ESP32_IDF
- SSC_T1_1
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_06.yml
IT_Function_WIFI_03:
@ -316,7 +386,6 @@ IT_Function_WIFI_03:
- ESP32_IDF
- SSC_T3_PhyMode
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_WIFI_03.yml
IT_Function_WIFI_04:
@ -325,7 +394,6 @@ IT_Function_WIFI_04:
- ESP32_IDF
- SSC_T1_APC
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_WIFI_04.yml
IT_Function_WIFI_05:
@ -334,7 +402,6 @@ IT_Function_WIFI_05:
- ESP32_IDF
- SSC_T1_WEP
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_WIFI_05.yml
IT_Function_WIFI_06:
@ -343,7 +410,6 @@ IT_Function_WIFI_06:
- ESP32_IDF
- SSC_T2_PhyMode
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_WIFI_06.yml
IT_Function_TCPIP_07:
@ -354,7 +420,6 @@ IT_Function_TCPIP_07:
- SSC_T1_2
- SSC_T2_1
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_07.yml
IT_Function_TCPIP_08:
@ -363,7 +428,6 @@ IT_Function_TCPIP_08:
- ESP32_IDF
- SSC_T1_1
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_08.yml
IT_Function_TCPIP_09:
@ -372,7 +436,6 @@ IT_Function_TCPIP_09:
- ESP32_IDF
- SSC_T1_1
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_09.yml
IT_Function_TCPIP_10:
@ -383,7 +446,6 @@ IT_Function_TCPIP_10:
- SSC_T1_2
- SSC_T2_1
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_10.yml
IT_Function_TCPIP_11:
@ -391,8 +453,8 @@ IT_Function_TCPIP_11:
tags:
- ESP32_IDF
- SSC_T1_1
- SSC_T1_2
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_11.yml
IT_Function_TCPIP_12:
@ -400,7 +462,5 @@ IT_Function_TCPIP_12:
tags:
- ESP32_IDF
- SSC_T1_1
- SSC_T1_2
before_script:
- TEST_CASE_FILE_PATH=$TEST_CASE_FILE_PATH/integration_test
- CONFIG_FILE=$TEST_CASE_FILE_PATH/CIConfigs/IT_Function_TCPIP_12.yml

3
.gitmodules vendored
View file

@ -7,3 +7,6 @@
[submodule "components/bt/lib"]
path = components/bt/lib
url = https://github.com/espressif/esp32-bt-lib.git
[submodule "components/micro-ecc/micro-ecc"]
path = components/micro-ecc/micro-ecc
url = https://github.com/kmackay/micro-ecc.git

View file

@ -1,30 +1,36 @@
# Contributions Guide
Contributions Guide
===================
We welcome contributions to the esp-idf project!
## How to Contribute
How to Contribute
-----------------
Contributions to esp-idf - fixing bugs, adding features, adding documentation - are welcome. We accept contributions via [Github Pull Requests](https://help.github.com/articles/about-pull-requests/).
Contributions to esp-idf - fixing bugs, adding features, adding documentation - are welcome. We accept contributions via `Github Pull Requests <https://help.github.com/articles/about-pull-requests/>`_.
## Before Contributing
Before Contributing
-------------------
Before sending us a Pull Request, please consider this list of points:
* Is the contribution entirely your own work, or already licensed under an Apache License 2.0 compatible Open Source License? If not then we unfortunately cannot accept it.
* Does any new code conform to the esp-idf Style Guide? (Style Guide currently pending).
* Does any new code conform to the esp-idf :doc:`Style Guide <style-guide>`?
* Does the code documentation follow requirements in :doc:`documenting-code`?
* Is the code adequately commented for people to understand how it is structured?
* Is there documentation or examples that go with code contributions? [There are additional suggestions for writing good examples in the examples README](examples/README.md).
* Is there documentation or examples that go with code contributions? `There are additional suggestions for writing good examples in the examples README <https://github.com/espressif/esp-idf/tree/master/examples>`_.
* Are comments and documentation written in clear English, with no spelling or grammar errors?
* If the contribution contains multiple commits, are they grouped together into logical changes (one major change per pull request)? Are any commits with names like "fixed typo" [squashed into previous commits](http://eli.thegreenplace.net/2014/02/19/squashing-github-pull-requests-into-a-single-commit/)?
* If the contribution contains multiple commits, are they grouped together into logical changes (one major change per pull request)? Are any commits with names like "fixed typo" `squashed into previous commits <http://eli.thegreenplace.net/2014/02/19/squashing-github-pull-requests-into-a-single-commit/>`_?
* If you're unsure about any of these points, please open the Pull Request anyhow and then ask us for feedback.
## Pull Request Process
Pull Request Process
--------------------
After you open the Pull Request, there will probably be some discussion in the comments field of the request itself.
@ -32,6 +38,10 @@ Once the Pull Request is ready to merge, it will first be merged into our intern
If this process passes, it will be merged onto the public github repository.
## Legal Part
Legal Part
----------
Before a contribution can be accepted, you will need to sign our :doc:`contributor-agreement`. You will be prompted for this automatically as part of the Pull Request process.
Before a contribution can be accepted, you will need to sign our [Contributor Agreement](docs/contributor-agreement.rst). You will be prompted for this automatically as part of the Pull Request process.

View file

@ -1,5 +1,7 @@
# Using Espressif IoT Development Framework with the ESP32
[![alt text](https://readthedocs.org/projects/docs/badge/?version=latest "Documentation Status")](http://esp-idf.readthedocs.io/en/latest/?badge=latest)
# Setting Up ESP-IDF
In the [docs](docs) directory you will find per-platform setup guides:
@ -60,14 +62,15 @@ The simplest way to use the partition table is to `make menuconfig` and choose o
In both cases the factory app is flashed at offset 0x10000. If you `make partition_table` then it will print a summary of the partition table.
For more details about partition tables and how to create custom variations, view the `docs/partition_tables.rst` file.
For more details about partition tables and how to create custom variations, view the `docs/partition-tables.rst` file.
# Resources
* The [docs directory of the esp-idf repository](docs) contains esp-idf documentation.
* The [docs directory of the esp-idf repository](docs) contains source of [esp-idf](http://esp-idf.readthedocs.io/) documentation.
* The [esp32.com forum](http://esp32.com/) is a place to ask questions and find community resources.
* [Check the Issues section on github](https://github.com/espressif/esp-idf/issues) if you find a bug or have a feature request. Please check existing Issues before opening a new one.
* If you're interested in contributing to esp-idf, please check the [CONTRIBUTING.md](CONTRIBUTING.md) file.
* If you're interested in contributing to esp-idf, please check the [Contributions Guide](http://esp-idf.readthedocs.io/en/latest/contributing.html>).

View file

@ -29,3 +29,90 @@ config LOG_BOOTLOADER_LEVEL
default 5 if LOG_BOOTLOADER_LEVEL_VERBOSE
endmenu
menu "Secure boot configuration"
choice SECURE_BOOTLOADER
bool "Secure bootloader"
default SECURE_BOOTLOADER_DISABLED
help
Build a bootloader with the secure boot flag enabled.
Secure bootloader can be one-time-flash (chip will only ever
boot that particular bootloader), or a digest key can be used
to allow the secure bootloader to be re-flashed with
modifications. Secure boot also permanently disables JTAG.
See docs/security/secure-boot.rst for details.
config SECURE_BOOTLOADER_DISABLED
bool "Disabled"
config SECURE_BOOTLOADER_ONE_TIME_FLASH
bool "One-time flash"
help
On first boot, the bootloader will generate a key which is not readable externally or by software. A digest is generated from the bootloader image itself. This digest will be verified on each subsequent boot.
Enabling this option means that the bootloader cannot be changed after the first time it is booted.
config SECURE_BOOTLOADER_REFLASHABLE
bool "Reflashable"
help
Generate a reusable secure bootloader key, derived (via SHA-256) from the secure boot signing key.
This allows the secure bootloader to be re-flashed by anyone with access to the secure boot signing key.
This option is less secure than one-time flash, because a leak of the digest key from one device allows reflashing of any device that uses it.
endchoice
config SECURE_BOOT_SIGNING_KEY
string "Secure boot signing key"
depends on SECURE_BOOTLOADER_ENABLED
default secure_boot_signing_key.pem
help
Path to the key file used to sign partition tables and app images for secure boot.
Key file is an ECDSA private key (NIST256p curve) in PEM format.
Path is evaluated relative to the project directory.
You can generate a new signing key by running the following command:
espsecure.py generate_signing_key secure_boot_signing_key.pem
See docs/security/secure-boot.rst for details.
config SECURE_BOOT_DISABLE_JTAG
bool "First boot: Permanently disable JTAG"
depends on SECURE_BOOTLOADER_ENABLED
default Y
help
Bootloader permanently disable JTAG (across entire chip) when enabling secure boot. This happens on first boot of the bootloader.
It is recommended this option remains set for production environments.
config SECURE_BOOT_DISABLE_ROM_BASIC
bool "First boot: Permanently disable ROM BASIC fallback"
depends on SECURE_BOOTLOADER_ENABLED
default Y
help
Bootloader permanently disables ROM BASIC (on UART console) as a fallback if the bootloader image becomes invalid. This happens on first boot.
It is recommended this option remains set in production environments.
config SECURE_BOOT_TEST_MODE
bool "Test mode: don't actually enable secure boot"
depends on SECURE_BOOTLOADER_ENABLED
default N
help
If this option is set, all permanent secure boot changes (via Efuse) are disabled.
This option is for testing purposes only - it effectively completely disables secure boot protection.
config SECURE_BOOTLOADER_ENABLED
bool
default SECURE_BOOTLOADER_ONE_TIME_FLASH || SECURE_BOOTLOADER_REFLASHABLE
endmenu

View file

@ -13,43 +13,108 @@ ifndef IS_BOOTLOADER_BUILD
BOOTLOADER_COMPONENT_PATH := $(COMPONENT_PATH)
BOOTLOADER_BUILD_DIR=$(abspath $(BUILD_DIR_BASE)/bootloader)
BOOTLOADER_BIN=$(BOOTLOADER_BUILD_DIR)/bootloader.bin
BOOTLOADER_SDKCONFIG=$(BOOTLOADER_BUILD_DIR)/sdkconfig
# signing key path is resolved relative to the project directory
SECURE_BOOT_SIGNING_KEY=$(abspath $(call dequote,$(CONFIG_SECURE_BOOT_SIGNING_KEY)))
export SECURE_BOOT_SIGNING_KEY # used by bootloader_support component
# Custom recursive make for bootloader sub-project
BOOTLOADER_MAKE=+$(MAKE) -C $(BOOTLOADER_COMPONENT_PATH)/src \
V=$(V) SDKCONFIG=$(BOOTLOADER_SDKCONFIG) \
BUILD_DIR_BASE=$(BOOTLOADER_BUILD_DIR) \
V=$(V) BUILD_DIR_BASE=$(BOOTLOADER_BUILD_DIR) TEST_COMPONENTS=
.PHONY: bootloader-clean bootloader-flash bootloader $(BOOTLOADER_BIN)
$(BOOTLOADER_BIN): | $(BOOTLOADER_BUILD_DIR)/sdkconfig
$(Q) $(BOOTLOADER_MAKE) $@
bootloader-clean:
$(Q) $(BOOTLOADER_MAKE) app-clean config-clean
$(Q) rm -f $(BOOTLOADER_SDKCONFIG) $(BOOTLOADER_SDKCONFIG).old
$(BOOTLOADER_BIN): $(SDKCONFIG_MAKEFILE)
$(BOOTLOADER_MAKE) $@
clean: bootloader-clean
bootloader: $(BOOTLOADER_BIN)
@echo "Bootloader built. Default flash command is:"
@echo "$(ESPTOOLPY_WRITE_FLASH) 0x1000 $(BOOTLOADER_BIN)"
ifdef CONFIG_SECURE_BOOTLOADER_DISABLED
# If secure boot disabled, bootloader flashing is integrated
# with 'make flash' and no warnings are printed.
all_binaries: $(BOOTLOADER_BIN)
bootloader: $(BOOTLOADER_BIN)
@echo $(SEPARATOR)
@echo "Bootloader built. Default flash command is:"
@echo "$(ESPTOOLPY_WRITE_FLASH) 0x1000 $^"
ESPTOOL_ALL_FLASH_ARGS += 0x1000 $(BOOTLOADER_BIN)
# bootloader-flash calls flash in the bootloader dummy project
bootloader-flash: $(BOOTLOADER_BIN)
$(BOOTLOADER_MAKE) flash
$(ESPTOOLPY_WRITE_FLASH) 0x1000 $^
# synchronise the project level config to the bootloader's
# config
$(BOOTLOADER_SDKCONFIG): $(PROJECT_PATH)/sdkconfig | $(BOOTLOADER_BUILD_DIR)
$(Q) cp $< $@
else ifdef CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH
#### TEMPORARILY DISABLE THIS OPTION
ifneq ("$(IDF_INSECURE_SECURE_BOOT)","1")
bootloader:
@echo "Secure boot features are not yet mature, so the current secure bootloader will not properly secure the device"
@echo "If you flash this bootloader, you will be left with an non-updateable bootloader that is missing features."
@echo "If you really want to do this, set the environment variable IDF_INSECURE_SECURE_BOOT=1 and rerun make."
exit 1
else
# One time flashing requires user to run esptool.py command themselves,
# and warning is printed about inability to reflash.
bootloader: $(BOOTLOADER_BIN)
@echo $(SEPARATOR)
@echo "Bootloader built. One-time flash command is:"
@echo "$(ESPTOOLPY_WRITE_FLASH) 0x1000 $(BOOTLOADER_BIN)"
@echo $(SEPARATOR)
@echo "* IMPORTANT: After first boot, BOOTLOADER CANNOT BE RE-FLASHED on same device"
endif # IDF_INSECURE_SECURE_BOOT
else ifdef CONFIG_SECURE_BOOTLOADER_REFLASHABLE
# Reflashable secure bootloader
# generates a digest binary (bootloader + digest)
#### TEMPORARILY DISABLE THIS OPTION
ifneq ("$(IDF_INSECURE_SECURE_BOOT)","1")
bootloader:
@echo "Secure boot features are not yet mature, so the current secure bootloader will not properly secure the device."
@echo "If using this feature, expect to reflash the bootloader at least one more time."
@echo "If you really want to do this, set the environment variable IDF_INSECURE_SECURE_BOOT=1 and rerun make."
exit 1
else
BOOTLOADER_DIGEST_BIN := $(BOOTLOADER_BUILD_DIR)/bootloader-reflash-digest.bin
SECURE_BOOTLOADER_KEY := $(BOOTLOADER_BUILD_DIR)/secure-bootloader-key.bin
$(SECURE_BOOTLOADER_KEY): $(SECURE_BOOT_SIGNING_KEY)
$(Q) $(ESPSECUREPY) digest_private_key -k $< $@
bootloader: $(BOOTLOADER_DIGEST_BIN)
@echo $(SEPARATOR)
@echo "Bootloader built and secure digest generated. First time flash command is:"
@echo "$(ESPEFUSEPY) burn_key secure_boot $(SECURE_BOOTLOADER_KEY)"
@echo "$(ESPTOOLPY_WRITE_FLASH) 0x1000 $(BOOTLOADER_BIN)"
@echo $(SEPARATOR)
@echo "To reflash the bootloader after initial flash:"
@echo "$(ESPTOOLPY_WRITE_FLASH) 0x0 $(BOOTLOADER_DIGEST_BIN)"
@echo $(SEPARATOR)
@echo "* After first boot, only re-flashes of this kind (with same key) will be accepted."
@echo "* Not recommended to re-use the same secure boot keyfile on multiple production devices."
$(BOOTLOADER_DIGEST_BIN): $(BOOTLOADER_BIN) $(SECURE_BOOTLOADER_KEY)
@echo "DIGEST $(notdir $@)"
$(Q) $(ESPSECUREPY) digest_secure_bootloader -k $(SECURE_BOOTLOADER_KEY) -o $@ $<
endif # IDF_INSECURE_SECURE_BOOT
else
bootloader:
@echo "Invalid bootloader target: bad sdkconfig?"
@exit 1
endif
all_binaries: $(BOOTLOADER_BIN)
bootloader-clean:
$(BOOTLOADER_MAKE) app-clean
rm -f $(SECURE_BOOTLOADER_KEY) $(BOOTLOADER_DIGEST_BIN)
$(BOOTLOADER_BUILD_DIR):
$(Q) mkdir -p $@
mkdir -p $@
else
CFLAGS += -D BOOTLOADER_BUILD=1 -I $(IDF_PATH)/components/esp32/include

View file

@ -4,7 +4,10 @@
#
PROJECT_NAME := bootloader
COMPONENTS := esptool_py bootloader log spi_flash
#We cannot include the esp32 component directly but we need its includes.
#This is fixed by adding CFLAGS from Makefile.projbuild
COMPONENTS := esptool_py bootloader bootloader_support log spi_flash micro-ecc
# The bootloader pseudo-component is also included in this build, for its Kconfig.projbuild to be included.
#
@ -12,7 +15,7 @@ COMPONENTS := esptool_py bootloader log spi_flash
IS_BOOTLOADER_BUILD := 1
export IS_BOOTLOADER_BUILD
#We cannot include the esp32 component directly but we need its includes.
#This is fixed by adding CFLAGS from Makefile.projbuild
# include the top-level "project" include directory, for sdkconfig.h
CFLAGS += -I$(BUILD_DIR_BASE)/../include
include $(IDF_PATH)/make/project.mk

View file

@ -25,8 +25,6 @@ extern "C"
#define BOOT_VERSION "V0.1"
#define SPI_SEC_SIZE 0x1000
#define MEM_CACHE(offset) (uint8_t *)(0x3f400000 + (offset))
#define CACHE_READ_32(offset) ((uint32_t *)(0x3f400000 + (offset)))
#define IROM_LOW 0x400D0000
#define IROM_HIGH 0x40400000
#define DROM_LOW 0x3F400000
@ -36,7 +34,6 @@ extern "C"
#define RTC_DATA_LOW 0x50000000
#define RTC_DATA_HIGH 0x50002000
#define PART_TYPE_APP 0x00
#define PART_SUBTYPE_FACTORY 0x00
#define PART_SUBTYPE_OTA_FLAG 0x10
@ -62,12 +59,7 @@ typedef struct {
uint32_t selected_subtype;
} bootloader_state_t;
void boot_cache_redirect( uint32_t pos, size_t size );
uint32_t get_bin_len(uint32_t pos);
bool flash_encrypt(bootloader_state_t *bs);
bool secure_boot(void);
#ifdef __cplusplus
}

View file

@ -33,6 +33,9 @@
#include "soc/timer_group_reg.h"
#include "sdkconfig.h"
#include "esp_image_format.h"
#include "esp_secure_boot.h"
#include "bootloader_flash.h"
#include "bootloader_config.h"
@ -49,9 +52,9 @@ flash cache is down and the app CPU is in reset. We do have a stack, so we can d
extern void Cache_Flush(int);
void bootloader_main();
void unpack_load_app(const esp_partition_pos_t *app_node);
static void unpack_load_app(const esp_partition_pos_t *app_node);
void print_flash_info(const esp_image_header_t* pfhdr);
void IRAM_ATTR set_cache_and_start_app(uint32_t drom_addr,
void set_cache_and_start_app(uint32_t drom_addr,
uint32_t drom_load_addr,
uint32_t drom_size,
uint32_t irom_addr,
@ -94,53 +97,6 @@ void IRAM_ATTR call_start_cpu0()
bootloader_main();
}
/**
* @function : get_bin_len
* @description: get bin's length
*
* @inputs: pos bin locate address in flash
* @return: uint32 length of bin,if bin MAGIC error return 0
*/
uint32_t get_bin_len(uint32_t pos)
{
uint32_t len = 8 + 16;
uint8_t i;
ESP_LOGD(TAG, "pos %d %x",pos,*(uint8_t *)pos);
if(0xE9 != *(uint8_t *)pos) {
return 0;
}
for (i = 0; i < *(uint8_t *)(pos + 1); i++) {
len += *(uint32_t *)(pos + len + 4) + 8;
}
if (len % 16 != 0) {
len = (len / 16 + 1) * 16;
} else {
len += 16;
}
ESP_LOGD(TAG, "bin length = %d", len);
return len;
}
/**
* @function : boot_cache_redirect
* @description: Configure several pages in flash map so that `size` bytes
* starting at `pos` are mapped to 0x3f400000.
* This sets up mapping only for PRO CPU.
*
* @inputs: pos address in flash
* size size of the area to map, in bytes
*/
void boot_cache_redirect( uint32_t pos, size_t size )
{
uint32_t pos_aligned = pos & 0xffff0000;
uint32_t count = (size + 0xffff) / 0x10000;
Cache_Read_Disable( 0 );
Cache_Flush( 0 );
ESP_LOGD(TAG, "mmu set paddr=%08x count=%d", pos_aligned, count );
cache_flash_mmu_set( 0, 0, 0x3f400000, pos_aligned, 64, count );
Cache_Read_Enable( 0 );
}
/**
* @function : load_partition_table
@ -148,42 +104,65 @@ void boot_cache_redirect( uint32_t pos, size_t size )
* OTA info sector, factory app sector, and test app sector.
*
* @inputs: bs bootloader state structure used to save the data
* addr address of partition table in flash
* @return: return true, if the partition table is loaded (and MD5 checksum is valid)
*
*/
bool load_partition_table(bootloader_state_t* bs, uint32_t addr)
bool load_partition_table(bootloader_state_t* bs)
{
esp_partition_info_t partition;
uint32_t end = addr + 0x1000;
int index = 0;
const esp_partition_info_t *partitions;
const int ESP_PARTITION_TABLE_DATA_LEN = 0xC00; /* length of actual data (signature is appended to this) */
const int MAX_PARTITIONS = ESP_PARTITION_TABLE_DATA_LEN / sizeof(esp_partition_info_t);
char *partition_usage;
ESP_LOGI(TAG, "Partition Table:");
ESP_LOGI(TAG, "## Label Usage Type ST Offset Length");
while (addr < end) {
ESP_LOGD(TAG, "load partition table entry from %x(%08x)", addr, MEM_CACHE(addr));
memcpy(&partition, MEM_CACHE(addr), sizeof(partition));
ESP_LOGD(TAG, "type=%x subtype=%x", partition.type, partition.subtype);
#ifdef CONFIG_SECURE_BOOTLOADER_ENABLED
if(esp_secure_boot_enabled()) {
ESP_LOGI(TAG, "Verifying partition table signature...");
esp_err_t err = esp_secure_boot_verify_signature(ESP_PARTITION_TABLE_ADDR, ESP_PARTITION_TABLE_DATA_LEN);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to verify partition table signature.");
return false;
}
ESP_LOGD(TAG, "Partition table signature verified");
}
#endif
partitions = bootloader_mmap(ESP_PARTITION_TABLE_ADDR, ESP_PARTITION_TABLE_DATA_LEN);
if (!partitions) {
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", ESP_PARTITION_TABLE_ADDR, ESP_PARTITION_TABLE_DATA_LEN);
return false;
}
ESP_LOGD(TAG, "mapped partition table 0x%x at 0x%x", ESP_PARTITION_TABLE_ADDR, (intptr_t)partitions);
for(int i = 0; i < MAX_PARTITIONS; i++) {
const esp_partition_info_t *partition = &partitions[i];
ESP_LOGD(TAG, "load partition table entry 0x%x", (intptr_t)partition);
ESP_LOGD(TAG, "type=%x subtype=%x", partition->type, partition->subtype);
partition_usage = "unknown";
if (partition.magic == ESP_PARTITION_MAGIC) { /* valid partition definition */
switch(partition.type) {
if (partition->magic != ESP_PARTITION_MAGIC) {
/* invalid partition definition indicates end-of-table */
break;
}
/* valid partition table */
switch(partition->type) {
case PART_TYPE_APP: /* app partition */
switch(partition.subtype) {
switch(partition->subtype) {
case PART_SUBTYPE_FACTORY: /* factory binary */
bs->factory = partition.pos;
bs->factory = partition->pos;
partition_usage = "factory app";
break;
case PART_SUBTYPE_TEST: /* test binary */
bs->test = partition.pos;
bs->test = partition->pos;
partition_usage = "test app";
break;
default:
/* OTA binary */
if ((partition.subtype & ~PART_SUBTYPE_OTA_MASK) == PART_SUBTYPE_OTA_FLAG) {
bs->ota[partition.subtype & PART_SUBTYPE_OTA_MASK] = partition.pos;
if ((partition->subtype & ~PART_SUBTYPE_OTA_MASK) == PART_SUBTYPE_OTA_FLAG) {
bs->ota[partition->subtype & PART_SUBTYPE_OTA_MASK] = partition->pos;
++bs->app_count;
partition_usage = "OTA app";
}
@ -194,9 +173,9 @@ bool load_partition_table(bootloader_state_t* bs, uint32_t addr)
}
break; /* PART_TYPE_APP */
case PART_TYPE_DATA: /* data partition */
switch(partition.subtype) {
switch(partition->subtype) {
case PART_SUBTYPE_DATA_OTA: /* ota data */
bs->ota_info = partition.pos;
bs->ota_info = partition->pos;
partition_usage = "OTA data";
break;
case PART_SUBTYPE_DATA_RF:
@ -213,20 +192,15 @@ bool load_partition_table(bootloader_state_t* bs, uint32_t addr)
default: /* other partition type */
break;
}
}
/* invalid partition magic number */
else {
break; /* todo: validate md5 */
}
/* print partition type info */
ESP_LOGI(TAG, "%2d %-16s %-16s %02x %02x %08x %08x", index, partition.label, partition_usage,
partition.type, partition.subtype,
partition.pos.offset, partition.pos.size);
index++;
addr += sizeof(partition);
ESP_LOGI(TAG, "%2d %-16s %-16s %02x %02x %08x %08x", i, partition->label, partition_usage,
partition->type, partition->subtype,
partition->pos.offset, partition->pos.size);
}
bootloader_munmap(partitions);
ESP_LOGI(TAG,"End of partition table");
return true;
}
@ -256,6 +230,8 @@ void bootloader_main()
bootloader_state_t bs;
SpiFlashOpResult spiRet1,spiRet2;
esp_ota_select_entry_t sa,sb;
const esp_ota_select_entry_t *ota_select_map;
memset(&bs, 0, sizeof(bs));
ESP_LOGI(TAG, "compile time " __TIME__ );
@ -263,16 +239,17 @@ void bootloader_main()
REG_CLR_BIT( RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_FLASHBOOT_MOD_EN );
REG_CLR_BIT( TIMG_WDTCONFIG0_REG(0), TIMG_WDT_FLASHBOOT_MOD_EN );
SPIUnlock();
/*register first sector in drom0 page 0 */
boot_cache_redirect( 0, 0x5000 );
memcpy((unsigned int *) &fhdr, MEM_CACHE(0x1000), sizeof(esp_image_header_t) );
if(esp_image_load_header(0x1000, &fhdr) != ESP_OK) {
ESP_LOGE(TAG, "failed to load bootloader header!");
return;
}
print_flash_info(&fhdr);
update_flash_config(&fhdr);
if (!load_partition_table(&bs, ESP_PARTITION_TABLE_ADDR)) {
if (!load_partition_table(&bs)) {
ESP_LOGE(TAG, "load partition table error!");
return;
}
@ -281,9 +258,19 @@ void bootloader_main()
if (bs.ota_info.offset != 0) { // check if partition table has OTA info partition
//ESP_LOGE("OTA info sector handling is not implemented");
boot_cache_redirect(bs.ota_info.offset, bs.ota_info.size );
memcpy(&sa,MEM_CACHE(bs.ota_info.offset & 0x0000ffff),sizeof(sa));
memcpy(&sb,MEM_CACHE((bs.ota_info.offset + 0x1000)&0x0000ffff) ,sizeof(sb));
if (bs.ota_info.size < 2 * sizeof(esp_ota_select_entry_t)) {
ESP_LOGE(TAG, "ERROR: ota_info partition size %d is too small (minimum %d bytes)", bs.ota_info.size, sizeof(esp_ota_select_entry_t));
return;
}
ota_select_map = bootloader_mmap(bs.ota_info.offset, bs.ota_info.size);
if (!ota_select_map) {
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", bs.ota_info.offset, bs.ota_info.size);
return;
}
sa = ota_select_map[0];
sb = ota_select_map[1];
bootloader_munmap(ota_select_map);
if(sa.ota_seq == 0xFFFFFFFF && sb.ota_seq == 0xFFFFFFFF) {
// init status flash
load_part_pos = bs.ota[0];
@ -329,13 +316,18 @@ void bootloader_main()
}
ESP_LOGI(TAG, "Loading app partition at offset %08x", load_part_pos);
if(fhdr.secure_boot_flag == 0x01) {
/* protect the 2nd_boot */
if(false == secure_boot()){
ESP_LOGE(TAG, "secure boot failed");
return;
}
#ifdef CONFIG_SECURE_BOOTLOADER_ENABLED
/* Generate secure digest from this bootloader to protect future
modifications */
esp_err_t err = esp_secure_boot_permanently_enable();
if (err != ESP_OK) {
ESP_LOGE(TAG, "Bootloader digest generation failed (%d). SECURE BOOT IS NOT ENABLED.", err);
/* Allow booting to continue, as the failure is probably
due to user-configured EFUSEs for testing...
*/
}
#endif
if(fhdr.encrypt_flag == 0x01) {
/* encrypt flash */
@ -345,19 +337,40 @@ void bootloader_main()
}
}
// copy sections to RAM, set up caches, and start application
// copy loaded segments to RAM, set up caches for mapped segments, and start application
unpack_load_app(&load_part_pos);
}
void unpack_load_app(const esp_partition_pos_t* partition)
static void unpack_load_app(const esp_partition_pos_t* partition)
{
boot_cache_redirect(partition->offset, partition->size);
uint32_t pos = 0;
esp_err_t err;
esp_image_header_t image_header;
memcpy(&image_header, MEM_CACHE(pos), sizeof(image_header));
pos += sizeof(image_header);
uint32_t image_length;
/* TODO: verify the app image as part of OTA boot decision, so can have fallbacks */
err = esp_image_basic_verify(partition->offset, &image_length);
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to verify app image @ 0x%x (%d)", partition->offset, err);
return;
}
#ifdef CONFIG_SECURE_BOOTLOADER_ENABLED
if (esp_secure_boot_enabled()) {
ESP_LOGI(TAG, "Verifying app signature @ 0x%x (length 0x%x)", partition->offset, image_length);
err = esp_secure_boot_verify_signature(partition->offset, image_length);
if (err != ESP_OK) {
ESP_LOGE(TAG, "App image @ 0x%x failed signature verification (%d)", partition->offset, err);
return;
}
ESP_LOGD(TAG, "App signature is valid");
}
#endif
if (esp_image_load_header(partition->offset, &image_header) != ESP_OK) {
ESP_LOGE(TAG, "Failed to load app image header @ 0x%x", partition->offset);
return;
}
uint32_t drom_addr = 0;
uint32_t drom_load_addr = 0;
@ -366,24 +379,27 @@ void unpack_load_app(const esp_partition_pos_t* partition)
uint32_t irom_load_addr = 0;
uint32_t irom_size = 0;
/* Reload the RTC memory sections whenever a non-deepsleep reset
/* Reload the RTC memory segments whenever a non-deepsleep reset
is occurring */
bool load_rtc_memory = rtc_get_reset_reason(0) != DEEPSLEEP_RESET;
ESP_LOGD(TAG, "bin_header: %u %u %u %u %08x", image_header.magic,
image_header.blocks,
image_header.segment_count,
image_header.spi_mode,
image_header.spi_size,
(unsigned)image_header.entry_addr);
for (uint32_t section_index = 0;
section_index < image_header.blocks;
++section_index) {
esp_image_section_header_t section_header = {0};
memcpy(&section_header, MEM_CACHE(pos), sizeof(section_header));
pos += sizeof(section_header);
for (int segment = 0; segment < image_header.segment_count; segment++) {
esp_image_segment_header_t segment_header;
uint32_t data_offs;
if(esp_image_load_segment_header(segment, partition->offset,
&image_header, &segment_header,
&data_offs) != ESP_OK) {
ESP_LOGE(TAG, "failed to load segment header #%d", segment);
return;
}
const uint32_t address = section_header.load_addr;
const uint32_t address = segment_header.load_addr;
bool load = true;
bool map = false;
if (address == 0x00000000) { // padding, ignore block
@ -395,45 +411,48 @@ void unpack_load_app(const esp_partition_pos_t* partition)
}
if (address >= DROM_LOW && address < DROM_HIGH) {
ESP_LOGD(TAG, "found drom section, map from %08x to %08x", pos,
section_header.load_addr);
drom_addr = partition->offset + pos - sizeof(section_header);
drom_load_addr = section_header.load_addr;
drom_size = section_header.data_len + sizeof(section_header);
ESP_LOGD(TAG, "found drom segment, map from %08x to %08x", data_offs,
segment_header.load_addr);
drom_addr = data_offs;
drom_load_addr = segment_header.load_addr;
drom_size = segment_header.data_len + sizeof(segment_header);
load = false;
map = true;
}
if (address >= IROM_LOW && address < IROM_HIGH) {
ESP_LOGD(TAG, "found irom section, map from %08x to %08x", pos,
section_header.load_addr);
irom_addr = partition->offset + pos - sizeof(section_header);
irom_load_addr = section_header.load_addr;
irom_size = section_header.data_len + sizeof(section_header);
ESP_LOGD(TAG, "found irom segment, map from %08x to %08x", data_offs,
segment_header.load_addr);
irom_addr = data_offs;
irom_load_addr = segment_header.load_addr;
irom_size = segment_header.data_len + sizeof(segment_header);
load = false;
map = true;
}
if (!load_rtc_memory && address >= RTC_IRAM_LOW && address < RTC_IRAM_HIGH) {
ESP_LOGD(TAG, "Skipping RTC code section at %08x\n", pos);
ESP_LOGD(TAG, "Skipping RTC code segment at %08x\n", data_offs);
load = false;
}
if (!load_rtc_memory && address >= RTC_DATA_LOW && address < RTC_DATA_HIGH) {
ESP_LOGD(TAG, "Skipping RTC data section at %08x\n", pos);
ESP_LOGD(TAG, "Skipping RTC data segment at %08x\n", data_offs);
load = false;
}
ESP_LOGI(TAG, "section %d: paddr=0x%08x vaddr=0x%08x size=0x%05x (%6d) %s", section_index, pos,
section_header.load_addr, section_header.data_len, section_header.data_len, (load)?"load":(map)?"map":"");
ESP_LOGI(TAG, "segment %d: paddr=0x%08x vaddr=0x%08x size=0x%05x (%6d) %s", segment, data_offs - sizeof(esp_image_segment_header_t),
segment_header.load_addr, segment_header.data_len, segment_header.data_len, (load)?"load":(map)?"map":"");
if (!load) {
pos += section_header.data_len;
continue;
if (load) {
const void *data = bootloader_mmap(data_offs, segment_header.data_len);
if(!data) {
ESP_LOGE(TAG, "bootloader_mmap(0x%xc, 0x%x) failed",
data_offs, segment_header.data_len);
return;
}
memcpy((void *)segment_header.load_addr, data, segment_header.data_len);
bootloader_munmap(data);
}
memcpy((void*) section_header.load_addr, MEM_CACHE(pos), section_header.data_len);
pos += section_header.data_len;
}
set_cache_and_start_app(drom_addr,
@ -445,7 +464,7 @@ void unpack_load_app(const esp_partition_pos_t* partition)
image_header.entry_addr);
}
void IRAM_ATTR set_cache_and_start_app(
void set_cache_and_start_app(
uint32_t drom_addr,
uint32_t drom_load_addr,
uint32_t drom_size,
@ -456,9 +475,7 @@ void IRAM_ATTR set_cache_and_start_app(
{
ESP_LOGD(TAG, "configure drom and irom and start");
Cache_Read_Disable( 0 );
Cache_Read_Disable( 1 );
Cache_Flush( 0 );
Cache_Flush( 1 );
uint32_t drom_page_count = (drom_size + 64*1024 - 1) / (64*1024); // round up to 64k
ESP_LOGV(TAG, "d mmu set paddr=%08x vaddr=%08x size=%d n=%d", drom_addr & 0xffff0000, drom_load_addr & 0xffff0000, drom_size, drom_page_count );
int rc = cache_flash_mmu_set( 0, 0, drom_load_addr & 0xffff0000, drom_addr & 0xffff0000, 64, drom_page_count );
@ -474,7 +491,8 @@ void IRAM_ATTR set_cache_and_start_app(
REG_CLR_BIT( DPORT_PRO_CACHE_CTRL1_REG, (DPORT_PRO_CACHE_MASK_IRAM0) | (DPORT_PRO_CACHE_MASK_IRAM1 & 0) | (DPORT_PRO_CACHE_MASK_IROM0 & 0) | DPORT_PRO_CACHE_MASK_DROM0 | DPORT_PRO_CACHE_MASK_DRAM1 );
REG_CLR_BIT( DPORT_APP_CACHE_CTRL1_REG, (DPORT_APP_CACHE_MASK_IRAM0) | (DPORT_APP_CACHE_MASK_IRAM1 & 0) | (DPORT_APP_CACHE_MASK_IROM0 & 0) | DPORT_APP_CACHE_MASK_DROM0 | DPORT_APP_CACHE_MASK_DRAM1 );
Cache_Read_Enable( 0 );
Cache_Read_Enable( 1 );
// Application will need to do Cache_Flush(1) and Cache_Read_Enable(1)
ESP_LOGD(TAG, "start: 0x%08x", entry_addr);
typedef void (*entry_t)(void);
@ -521,7 +539,7 @@ void print_flash_info(const esp_image_header_t* phdr)
#if (BOOT_LOG_LEVEL >= BOOT_LOG_LEVEL_NOTICE)
ESP_LOGD(TAG, "magic %02x", phdr->magic );
ESP_LOGD(TAG, "blocks %02x", phdr->blocks );
ESP_LOGD(TAG, "segments %02x", phdr->segment_count );
ESP_LOGD(TAG, "spi_mode %02x", phdr->spi_mode );
ESP_LOGD(TAG, "spi_speed %02x", phdr->spi_speed );
ESP_LOGD(TAG, "spi_size %02x", phdr->spi_size );

View file

@ -1,12 +1,9 @@
#
# Main Makefile. This is basically the same as a component makefile.
# Main bootloader Makefile.
#
# This Makefile should, at the very least, just include $(IDF_PATH)/make/component_common.mk. By default,
# this will take the sources in the src/ directory, compile them and link them into
# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
# please read the esp-idf build system document if you need to do this.
# This is basically the same as a component makefile, but in the case of the bootloader
# we pull in bootloader-specific linker arguments.
#
COMPONENT_ADD_LDFLAGS := -L $(abspath .) -lmain -T esp32.bootloader.ld -T $(IDF_PATH)/components/esp32/ld/esp32.rom.ld
COMPONENT_ADD_LDFLAGS := -L $(COMPONENT_PATH) -lmain -T esp32.bootloader.ld -T $(IDF_PATH)/components/esp32/ld/esp32.rom.ld
include $(IDF_PATH)/make/component_common.mk

View file

@ -15,7 +15,7 @@ MEMORY
of the various regions. The 'data access port' dram/drom regions map to the same iram/irom regions but
are connected to the data port of the CPU and eg allow bytewise access. */
dport0_seg (RW) : org = 0x3FF00000, len = 0x10 /* IO */
iram_seg (RWX) : org = 0x4009A000, len = 0x1000
iram_seg (RWX) : org = 0x40080000, len = 0x400 /* 1k of IRAM used by bootloader functions which need to flush/enable APP CPU cache */
iram_pool_1_seg (RWX) : org = 0x40078000, len = 0x8000 /* IRAM POOL1, used for APP CPU cache. We can abuse it in bootloader because APP CPU is still held in reset, until we enable APP CPU cache */
dram_seg (RW) : org = 0x3FFC0000, len = 0x20000 /* Shared RAM, minus rom bss/data/stack.*/
}

View file

@ -17,6 +17,7 @@
#include "esp_types.h"
#include "esp_attr.h"
#include "esp_log.h"
#include "esp_err.h"
#include "rom/cache.h"
#include "rom/ets_sys.h"
@ -30,6 +31,7 @@
#include "sdkconfig.h"
#include "bootloader_config.h"
#include "esp_image_format.h"
static const char* TAG = "flash_encrypt";
@ -90,6 +92,8 @@ bool flash_encrypt_write(uint32_t pos, uint32_t len)
Cache_Read_Enable(0);
return true;
}
/**
* @function : flash_encrypt
* @description: encrypt 2nd boot ,partition table ,factory bin <EFBFBD><EFBFBD>test bin (if use)<EFBFBD><EFBFBD>ota bin
@ -102,24 +106,23 @@ bool flash_encrypt_write(uint32_t pos, uint32_t len)
*/
bool flash_encrypt(bootloader_state_t *bs)
{
uint32_t bin_len = 0;
esp_err_t err;
uint32_t image_len = 0;
uint32_t flash_crypt_cnt = REG_GET_FIELD(EFUSE_BLK0_RDATA0_REG, EFUSE_FLASH_CRYPT_CNT);
uint8_t count = bitcount(flash_crypt_cnt);
int i = 0;
ESP_LOGD(TAG, "flash encrypt cnt %x, bitcount %d", flash_crypt_cnt, count);
if ((count % 2) == 0) {
boot_cache_redirect( 0, 64*1024);
/* encrypt iv and abstruct */
/* encrypt iv and abstract */
if (false == flash_encrypt_write(0, SPI_SEC_SIZE)) {
ESP_LOGE(TAG, "encrypt iv and abstract error");
return false;
}
/* encrypt write boot bin*/
bin_len = get_bin_len((uint32_t)MEM_CACHE(0x1000));
if(bin_len != 0) {
if (false == flash_encrypt_write(0x1000, bin_len)) {
/* encrypt bootloader image */
err = esp_image_basic_verify(0x1000, &image_len);
if(err == ESP_OK && image_len != 0) {
if (false == flash_encrypt_write(0x1000, image_len)) {
ESP_LOGE(TAG, "encrypt 2nd boot error");
return false;
}
@ -127,6 +130,7 @@ bool flash_encrypt(bootloader_state_t *bs)
ESP_LOGE(TAG, "2nd boot len error");
return false;
}
/* encrypt partition table */
if (false == flash_encrypt_write(ESP_PARTITION_TABLE_ADDR, SPI_SEC_SIZE)) {
ESP_LOGE(TAG, "encrypt partition table error");
@ -134,48 +138,40 @@ bool flash_encrypt(bootloader_state_t *bs)
}
/* encrypt write factory bin */
if(bs->factory.offset != 0x00) {
if(bs->factory.offset != 0 && bs->factory.size != 0) {
ESP_LOGD(TAG, "have factory bin");
boot_cache_redirect(bs->factory.offset, bs->factory.size);
bin_len = get_bin_len((uint32_t)MEM_CACHE(bs->factory.offset&0xffff));
if(bin_len != 0) {
if (false == flash_encrypt_write(bs->factory.offset, bin_len)) {
if (false == flash_encrypt_write(bs->factory.offset, bs->factory.size)) {
ESP_LOGE(TAG, "encrypt factory bin error");
return false;
}
}
}
/* encrypt write test bin */
if(bs->test.offset != 0x00) {
if(bs->test.offset != 0 && bs->test.size != 0) {
ESP_LOGD(TAG, "have test bin");
boot_cache_redirect(bs->test.offset, bs->test.size);
bin_len = get_bin_len((uint32_t)MEM_CACHE(bs->test.offset&0xffff));
if(bin_len != 0) {
if (false == flash_encrypt_write(bs->test.offset, bin_len)) {
if (false == flash_encrypt_write(bs->test.offset, bs->test.size)) {
ESP_LOGE(TAG, "encrypt test bin error");
return false;
}
}
}
/* encrypt write ota bin */
for (i = 0;i<16;i++) {
if(bs->ota[i].offset != 0x00) {
for (int i = 0; i < 16; i++) {
if(bs->ota[i].offset != 0 && bs->ota[i].size != 0) {
ESP_LOGD(TAG, "have ota[%d] bin",i);
boot_cache_redirect(bs->ota[i].offset, bs->ota[i].size);
bin_len = get_bin_len((uint32_t)MEM_CACHE(bs->ota[i].offset&0xffff));
if(bin_len != 0) {
if (false == flash_encrypt_write(bs->ota[i].offset, bin_len)) {
if (false == flash_encrypt_write(bs->ota[i].offset, bs->ota[i].size)) {
ESP_LOGE(TAG, "encrypt ota bin error");
return false;
}
}
}
}
/* encrypt write ota info bin */
if (false == flash_encrypt_write(bs->ota_info.offset, 2*SPI_SEC_SIZE)) {
ESP_LOGE(TAG, "encrypt ota info error");
return false;
}
REG_SET_FIELD(EFUSE_BLK0_WDATA0_REG, EFUSE_FLASH_CRYPT_CNT, 0x04);
REG_WRITE(EFUSE_CONF_REG, 0x5A5A); /* efuse_pgm_op_ena, force no rd/wr disable */
REG_WRITE(EFUSE_CMD_REG, 0x02); /* efuse_pgm_cmd */

View file

@ -1,127 +0,0 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 <string.h>
#include "esp_attr.h"
#include "esp_types.h"
#include "esp_log.h"
#include "rom/cache.h"
#include "rom/ets_sys.h"
#include "rom/spi_flash.h"
#include "rom/secure_boot.h"
#include "soc/dport_reg.h"
#include "soc/io_mux_reg.h"
#include "soc/efuse_reg.h"
#include "soc/rtc_cntl_reg.h"
#include "sdkconfig.h"
#include "bootloader_config.h"
static const char* TAG = "secure_boot";
/**
* @function : secure_boot_generate
* @description: generate boot abstract & iv
*
* @inputs: bool
*/
bool secure_boot_generate(uint32_t bin_len){
SpiFlashOpResult spiRet;
uint16_t i;
uint32_t buf[32];
if (bin_len % 128 != 0) {
bin_len = (bin_len / 128 + 1) * 128;
}
ets_secure_boot_start();
ets_secure_boot_rd_iv(buf);
ets_secure_boot_hash(NULL);
Cache_Read_Disable(0);
/* iv stored in sec 0 */
spiRet = SPIEraseSector(0);
if (spiRet != SPI_FLASH_RESULT_OK)
{
ESP_LOGE(TAG, SPI_ERROR_LOG);
return false;
}
/* write iv to flash, 0x0000, 128 bytes (1024 bits) */
spiRet = SPIWrite(0, buf, 128);
if (spiRet != SPI_FLASH_RESULT_OK)
{
ESP_LOGE(TAG, SPI_ERROR_LOG);
return false;
}
ESP_LOGD(TAG, "write iv to flash.");
Cache_Read_Enable(0);
/* read 4K code image from flash, for test */
for (i = 0; i < bin_len; i+=128) {
ets_secure_boot_hash((uint32_t *)(0x3f400000 + 0x1000 + i));
}
ets_secure_boot_obtain();
ets_secure_boot_rd_abstract(buf);
ets_secure_boot_finish();
Cache_Read_Disable(0);
/* write abstract to flash, 0x0080, 64 bytes (512 bits) */
spiRet = SPIWrite(0x80, buf, 64);
if (spiRet != SPI_FLASH_RESULT_OK) {
ESP_LOGE(TAG, SPI_ERROR_LOG);
return false;
}
ESP_LOGD(TAG, "write abstract to flash.");
Cache_Read_Enable(0);
return true;
}
/**
* @function : secure_boot
* @description: protect boot code in flash
*
* @inputs: bool
*/
bool secure_boot(void){
uint32_t bin_len = 0;
if (REG_READ(EFUSE_BLK0_RDATA6_REG) & EFUSE_RD_ABS_DONE_0)
{
ESP_LOGD(TAG, "already secure boot !");
return true;
} else {
boot_cache_redirect( 0, 64*1024);
bin_len = get_bin_len((uint32_t)MEM_CACHE(0x1000));
if (bin_len == 0) {
ESP_LOGE(TAG, "boot len is error");
return false;
}
if (false == secure_boot_generate(bin_len)){
ESP_LOGE(TAG, "secure boot generate failed");
return false;
}
}
REG_SET_BIT(EFUSE_BLK0_WDATA6_REG, EFUSE_RD_ABS_DONE_0);
REG_WRITE(EFUSE_CONF_REG, 0x5A5A); /* efuse_pgm_op_ena, force no rd/wr disable */
REG_WRITE(EFUSE_CMD_REG, 0x02); /* efuse_pgm_cmd */
while (REG_READ(EFUSE_CMD_REG)); /* wait for efuse_pagm_cmd=0 */
ESP_LOGW(TAG, "burn abstract_done_0");
REG_WRITE(EFUSE_CONF_REG, 0x5AA5); /* efuse_read_op_ena, release force */
REG_WRITE(EFUSE_CMD_REG, 0x01); /* efuse_read_cmd */
while (REG_READ(EFUSE_CMD_REG)); /* wait for efuse_read_cmd=0 */
ESP_LOGI(TAG, "read EFUSE_BLK0_RDATA6 %x", REG_READ(EFUSE_BLK0_RDATA6_REG));
return true;
}

View file

@ -0,0 +1,9 @@
Bootloader Support Component
============================
Overview
--------
"Bootloader support" contains APIs which are used by the bootloader but are also needed for the main app.
Code in this component needs to be aware of being executed in a bootloader environment (no RTOS available, BOOTLOADER_BUILD macro set) or in an esp-idf app environment (RTOS running, need locking support.)

View file

@ -0,0 +1,35 @@
COMPONENT_ADD_INCLUDEDIRS := include
COMPONENT_PRIV_INCLUDEDIRS := include_priv
ifdef IS_BOOTLOADER_BUILD
# share "private" headers with the bootloader component
# eventual goal: all functionality that needs this lives in bootloader_support
COMPONENT_ADD_INCLUDEDIRS += include_priv
endif
COMPONENT_SRCDIRS := src
#
# Secure boot signing key support
#
ifdef CONFIG_SECURE_BOOTLOADER_ENABLED
# this path is created relative to the component build directory
SECURE_BOOT_VERIFICATION_KEY := $(abspath signature_verification_key.bin)
$(SECURE_BOOT_SIGNING_KEY):
@echo "Need to generate secure boot signing key."
@echo "One way is to run this command:"
@echo "$(ESPSECUREPY) generate_signing_key $@"
@echo "Keep key file safe after generating."
@echo "(See secure boot documentation for risks & alternatives.)"
@exit 1
$(SECURE_BOOT_VERIFICATION_KEY): $(SECURE_BOOT_SIGNING_KEY)
$(ESPSECUREPY) extract_public_key --keyfile $< $@
COMPONENT_EXTRA_CLEAN += $(SECURE_BOOT_VERIFICATION_KEY)
COMPONENT_EMBED_FILES := $(SECURE_BOOT_VERIFICATION_KEY)
endif

View file

@ -0,0 +1,132 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 __ESP32_IMAGE_FORMAT_H
#define __ESP32_IMAGE_FORMAT_H
#include <stdbool.h>
#include <esp_err.h>
#define ESP_ERR_IMAGE_BASE 0x2000
#define ESP_ERR_IMAGE_FLASH_FAIL (ESP_ERR_IMAGE_BASE + 1)
#define ESP_ERR_IMAGE_INVALID (ESP_ERR_IMAGE_BASE + 2)
/* Support for app/bootloader image parsing
Can be compiled as part of app or bootloader code.
*/
/* SPI flash mode, used in esp_image_header_t */
typedef enum {
ESP_IMAGE_SPI_MODE_QIO,
ESP_IMAGE_SPI_MODE_QOUT,
ESP_IMAGE_SPI_MODE_DIO,
ESP_IMAGE_SPI_MODE_DOUT,
ESP_IMAGE_SPI_MODE_FAST_READ,
ESP_IMAGE_SPI_MODE_SLOW_READ
} esp_image_spi_mode_t;
/* SPI flash clock frequency */
enum {
ESP_IMAGE_SPI_SPEED_40M,
ESP_IMAGE_SPI_SPEED_26M,
ESP_IMAGE_SPI_SPEED_20M,
ESP_IMAGE_SPI_SPEED_80M = 0xF
} esp_image_spi_freq_t;
/* Supported SPI flash sizes */
typedef enum {
ESP_IMAGE_FLASH_SIZE_1MB = 0,
ESP_IMAGE_FLASH_SIZE_2MB,
ESP_IMAGE_FLASH_SIZE_4MB,
ESP_IMAGE_FLASH_SIZE_8MB,
ESP_IMAGE_FLASH_SIZE_16MB,
ESP_IMAGE_FLASH_SIZE_MAX
} esp_image_flash_size_t;
#define ESP_IMAGE_HEADER_MAGIC 0xE9
/* Main header of binary image */
typedef struct {
uint8_t magic;
uint8_t segment_count;
uint8_t spi_mode; /* flash read mode (esp_image_spi_mode_t as uint8_t) */
uint8_t spi_speed: 4; /* flash frequency (esp_image_spi_freq_t as uint8_t) */
uint8_t spi_size: 4; /* flash chip size (esp_image_flash_size_t as uint8_t) */
uint32_t entry_addr;
uint8_t encrypt_flag; /* encrypt flag */
uint8_t extra_header[15]; /* ESP32 additional header, unused by second bootloader */
} esp_image_header_t;
/* Header of binary image segment */
typedef struct {
uint32_t load_addr;
uint32_t data_len;
} esp_image_segment_header_t;
/**
* @brief Read an ESP image header from flash.
*
* @param src_addr Address in flash to load image header. Must be 4 byte aligned.
* @param[out] image_header Pointer to an esp_image_header_t struture to be filled with data. If the function fails, contents are undefined.
*
* @return ESP_OK if image header was loaded, ESP_ERR_IMAGE_FLASH_FAIL
* if a SPI flash error occurs, ESP_ERR_IMAGE_INVALID if the image header
* appears invalid.
*/
esp_err_t esp_image_load_header(uint32_t src_addr, esp_image_header_t *image_header);
/**
* @brief Read the segment header and data offset of a segment in the image.
*
* @param index Index of the segment to load information for.
* @param src_addr Base address in flash of the image.
* @param[in] image_header Pointer to the flash image header, already loaded by @ref esp_image_load_header().
* @param[out] segment_header Pointer to a segment header structure to be filled with data. If the function fails, contents are undefined.
* @param[out] segment_data_offset Pointer to the data offset of the segment.
*
* @return ESP_OK if segment_header & segment_data_offset were loaded successfully, ESP_ERR_IMAGE_FLASH_FAIL if a SPI flash error occurs, ESP_ERR_IMAGE_INVALID if the image header appears invalid, ESP_ERR_INVALID_ARG if the index is invalid.
*/
esp_err_t esp_image_load_segment_header(uint8_t index, uint32_t src_addr, const esp_image_header_t *image_header, esp_image_segment_header_t *segment_header, uint32_t *segment_data_offset);
/**
* @brief Return length of an image in flash. Non-cryptographically validates image integrity in the process.
*
* If the image has a secure boot signature appended, the signature is not checked and this length is not included in the result.
*
* Image validation checks:
* - Magic byte
* - No single segment longer than 16MB
* - Total image no longer than 16MB
* - 8 bit image checksum is valid
*
* @param src_addr Offset of the start of the image in flash. Must be 4 byte aligned.
* @param[out] length Length of the image, set to a value if the image is valid. Can be null.
*
* @return ESP_OK if image is valid, ESP_FAIL or ESP_ERR_IMAGE_INVALID on errors.
*
*/
esp_err_t esp_image_basic_verify(uint32_t src_addr, uint32_t *length);
typedef struct {
uint32_t drom_addr;
uint32_t drom_load_addr;
uint32_t drom_size;
uint32_t irom_addr;
uint32_t irom_load_addr;
uint32_t irom_size;
} esp_image_flash_mapping_t;
#endif

View file

@ -0,0 +1,75 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 __ESP32_SECUREBOOT_H
#define __ESP32_SECUREBOOT_H
#include <stdbool.h>
#include <esp_err.h>
#include "soc/efuse_reg.h"
/* Support functions for secure boot features.
Can be compiled as part of app or bootloader code.
*/
/** @brief Is secure boot currently enabled in hardware?
*
* Secure boot is enabled if the ABS_DONE_0 efuse is blown. This means
* that the ROM bootloader code will only boot a verified secure
* bootloader digest from now on.
*
* @return true if secure boot is enabled.
*/
static inline bool esp_secure_boot_enabled(void) {
return REG_READ(EFUSE_BLK0_RDATA6_REG) & EFUSE_RD_ABS_DONE_0;
}
/** @brief Enable secure boot if it is not already enabled.
*
* @important If this function succeeds, secure boot is permanently
* enabled on the chip via efuse.
*
* @important This function is intended to be called from bootloader code only.
*
* If secure boot is not yet enabled for bootloader, this will
* generate the secure boot digest and enable secure boot by blowing
* the EFUSE_RD_ABS_DONE_0 efuse.
*
* This function does not verify secure boot of the bootloader (the
* ROM bootloader does this.)
*
* Will fail if efuses have been part-burned in a way that indicates
* secure boot should not or could not be correctly enabled.
*
*
* @return ESP_ERR_INVALID_STATE if efuse state doesn't allow
* secure boot to be enabled cleanly. ESP_OK if secure boot
* is enabled on this chip from now on.
*/
esp_err_t esp_secure_boot_permanently_enable(void);
/** @brief Verify the secure boot signature (determinstic ECDSA w/ SHA256) appended to some binary data in flash.
*
* Public key is compiled into the calling program. See docs/security/secure-boot.rst for details.
*
* @param src_addr Starting offset of the data in flash.
* @param length Length of data in bytes. Signature is appended -after- length bytes.
*
* @return ESP_OK if signature is valid, ESP_ERR_INVALID_STATE if
* signature fails, ESP_FAIL for other failures (ie can't read flash).
*/
esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length);
#endif

View file

@ -0,0 +1,69 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 __BOOTLOADER_FLASH_H
#define __BOOTLOADER_FLASH_H
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include <esp_err.h>
/* Provide a Flash API for bootloader_support code,
that can be used from bootloader or app code.
This header is available to source code in the bootloader &
bootloader_support components only.
*/
/**
* @brief Map a region of flash to data memory
*
* @important In bootloader code, only one region can be bootloader_mmaped at once. The previous region must be bootloader_munmapped before another region is mapped.
*
* @important In app code, these functions are not thread safe.
*
* Call bootloader_munmap once for each successful call to bootloader_mmap.
*
* In esp-idf app, this function maps directly to spi_flash_mmap.
*
* @param offset - Starting flash offset to map to memory.
* @param length - Length of data to map.
*
* @return Pointer to mapped data memory (at src_addr), or NULL
* if an allocation error occured.
*/
const void *bootloader_mmap(uint32_t src_addr, uint32_t size);
/**
* @brief Unmap a previously mapped region of flash
*
* Call bootloader_munmap once for each successful call to bootloader_mmap.
*/
void bootloader_munmap(const void *mapping);
/**
* @brief Read data from Flash.
*
* @note Both src and dest have to be 4-byte aligned.
*
* @param src source address of the data in Flash.
* @param dest pointer to the destination buffer
* @param size length of data
*
* @return esp_err_t
*/
esp_err_t bootloader_flash_read(size_t src_addr, void *dest, size_t size);
#endif

View file

@ -0,0 +1,122 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 <stddef.h>
#include <bootloader_flash.h>
#include <esp_log.h>
#include <esp_spi_flash.h> /* including in bootloader for error values */
#ifndef BOOTLOADER_BUILD
/* Normal app version maps to esp_spi_flash.h operations...
*/
static const char *TAG = "bootloader_mmap";
static spi_flash_mmap_memory_t map;
const void *bootloader_mmap(uint32_t src_addr, uint32_t size)
{
if (map) {
ESP_LOGE(TAG, "tried to bootloader_mmap twice");
return NULL; /* existing mapping in use... */
}
const void *result = NULL;
esp_err_t err = spi_flash_mmap(src_addr, size, SPI_FLASH_MMAP_DATA, &result, &map);
if (err != ESP_OK) {
result = NULL;
}
return result;
}
void bootloader_munmap(const void *mapping)
{
if(mapping && map) {
spi_flash_munmap(map);
}
map = 0;
}
esp_err_t bootloader_flash_read(size_t src, void *dest, size_t size)
{
return spi_flash_read(src, dest, size);
}
#else
/* Bootloader version, uses ROM functions only */
#include <rom/spi_flash.h>
#include <rom/cache.h>
static const char *TAG = "bootloader_flash";
static bool mapped;
const void *bootloader_mmap(uint32_t src_addr, uint32_t size)
{
if (mapped) {
ESP_LOGE(TAG, "tried to bootloader_mmap twice");
return NULL; /* can't map twice */
}
uint32_t src_addr_aligned = src_addr & 0xffff0000;
uint32_t count = (size + (src_addr - src_addr_aligned) + 0xffff) / 0x10000;
Cache_Read_Disable(0);
Cache_Flush(0);
ESP_LOGD(TAG, "mmu set paddr=%08x count=%d", src_addr_aligned, count );
cache_flash_mmu_set( 0, 0, 0x3f400000, src_addr_aligned, 64, count );
Cache_Read_Enable( 0 );
mapped = true;
return (void *)(0x3f400000 + (src_addr - src_addr_aligned));
}
void bootloader_munmap(const void *mapping)
{
if (mapped) {
/* Full MMU reset */
Cache_Read_Disable(0);
Cache_Flush(0);
mmu_init(0);
mapped = false;
}
}
esp_err_t bootloader_flash_read(size_t src_addr, void *dest, size_t size)
{
if(src_addr & 3) {
ESP_LOGE(TAG, "bootloader_flash_read src_addr 0x%x not 4-byte aligned", src_addr);
return ESP_FAIL;
}
if((intptr_t)dest & 3) {
ESP_LOGE(TAG, "bootloader_flash_read dest 0x%x not 4-byte aligned", (intptr_t)dest);
return ESP_FAIL;
}
Cache_Read_Disable(0);
Cache_Flush(0);
SpiFlashOpResult r = SPIRead(src_addr, dest, size);
Cache_Read_Enable(0);
switch(r) {
case SPI_FLASH_RESULT_OK:
return ESP_OK;
case SPI_FLASH_RESULT_ERR:
return ESP_ERR_FLASH_OP_FAIL;
case SPI_FLASH_RESULT_TIMEOUT:
return ESP_ERR_FLASH_OP_TIMEOUT;
default:
return ESP_FAIL;
}
}
#endif

View file

@ -0,0 +1,161 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 <string.h>
#include <esp_image_format.h>
#include <esp_log.h>
#include <bootloader_flash.h>
static const char *TAG = "esp_image";
#define SIXTEEN_MB 0x1000000
#define ESP_ROM_CHECKSUM_INITIAL 0xEF
esp_err_t esp_image_load_header(uint32_t src_addr, esp_image_header_t *image_header)
{
esp_err_t err;
ESP_LOGD(TAG, "reading image header @ 0x%x", src_addr);
err = bootloader_flash_read(src_addr, image_header, sizeof(esp_image_header_t));
if (err == ESP_OK) {
if (image_header->magic != ESP_IMAGE_HEADER_MAGIC) {
ESP_LOGE(TAG, "image at 0x%x has invalid magic byte", src_addr);
err = ESP_ERR_IMAGE_INVALID;
}
if (image_header->spi_mode > ESP_IMAGE_SPI_MODE_SLOW_READ) {
ESP_LOGW(TAG, "image at 0x%x has invalid SPI mode %d", src_addr, image_header->spi_mode);
}
if (image_header->spi_speed > ESP_IMAGE_SPI_SPEED_80M) {
ESP_LOGW(TAG, "image at 0x%x has invalid SPI speed %d", src_addr, image_header->spi_speed);
}
if (image_header->spi_size > ESP_IMAGE_FLASH_SIZE_MAX) {
ESP_LOGW(TAG, "image at 0x%x has invalid SPI size %d", src_addr, image_header->spi_size);
}
}
if (err != ESP_OK) {
bzero(image_header, sizeof(esp_image_header_t));
}
return err;
}
esp_err_t esp_image_load_segment_header(uint8_t index, uint32_t src_addr, const esp_image_header_t *image_header, esp_image_segment_header_t *segment_header, uint32_t *segment_data_offset)
{
esp_err_t err = ESP_OK;
uint32_t next_addr = src_addr + sizeof(esp_image_header_t);
if(index >= image_header->segment_count) {
ESP_LOGE(TAG, "index %d higher than segment count %d", index, image_header->segment_count);
return ESP_ERR_INVALID_ARG;
}
for(int i = 0; i <= index && err == ESP_OK; i++) {
ESP_LOGV(TAG, "loading segment header %d at offset 0x%x", i, next_addr);
err = bootloader_flash_read(next_addr, segment_header, sizeof(esp_image_segment_header_t));
if (err == ESP_OK) {
if ((segment_header->data_len & 3) != 0
|| segment_header->data_len >= SIXTEEN_MB) {
ESP_LOGE(TAG, "invalid segment length 0x%x", segment_header->data_len);
err = ESP_ERR_IMAGE_INVALID;
}
next_addr += sizeof(esp_image_segment_header_t);
ESP_LOGV(TAG, "segment data length 0x%x data starts 0x%x", segment_header->data_len, next_addr);
*segment_data_offset = next_addr;
next_addr += segment_header->data_len;
}
}
if (err != ESP_OK) {
*segment_data_offset = 0;
bzero(segment_header, sizeof(esp_image_segment_header_t));
}
return err;
}
esp_err_t esp_image_basic_verify(uint32_t src_addr, uint32_t *p_length)
{
esp_err_t err;
uint8_t buf[16];
uint8_t checksum = ESP_ROM_CHECKSUM_INITIAL;
esp_image_header_t image_header;
esp_image_segment_header_t segment_header = { 0 };
uint32_t segment_data_offs = 0;
const uint8_t *segment_data;
uint32_t end_addr;
uint32_t length;
if (p_length != NULL) {
*p_length = 0;
}
err = esp_image_load_header(src_addr, &image_header);
if (err != ESP_OK) {
return err;
}
ESP_LOGD(TAG, "reading %d image segments", image_header.segment_count);
/* Checksum each segment's data */
for (int i = 0; i < image_header.segment_count; i++) {
err = esp_image_load_segment_header(i, src_addr, &image_header,
&segment_header, &segment_data_offs);
if (err != ESP_OK) {
return err;
}
segment_data = bootloader_mmap(segment_data_offs, segment_header.data_len);
if (segment_data == NULL) {
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", segment_data_offs, segment_header.data_len);
return ESP_FAIL;
}
for(int i = 0; i < segment_header.data_len; i++) {
checksum ^= segment_data[i];
}
bootloader_munmap(segment_data);
}
/* End of image, verify checksum */
end_addr = segment_data_offs + segment_header.data_len;
if (end_addr < src_addr) {
ESP_LOGE(TAG, "image offset has wrapped");
return ESP_ERR_IMAGE_INVALID;
}
length = end_addr - src_addr;
if (length >= SIXTEEN_MB) {
ESP_LOGE(TAG, "invalid total length 0x%x", length);
return ESP_ERR_IMAGE_INVALID;
}
/* image padded to next full 16 byte block, with checksum byte at very end */
ESP_LOGV(TAG, "unpadded image length 0x%x", length);
length += 16; /* always pad by at least 1 byte */
length = length - (length % 16);
ESP_LOGV(TAG, "padded image length 0x%x", length);
ESP_LOGD(TAG, "reading checksum block at 0x%x", src_addr + length - 16);
bootloader_flash_read(src_addr + length - 16, buf, 16);
if (checksum != buf[15]) {
ESP_LOGE(TAG, "checksum failed. Calculated 0x%x read 0x%x",
checksum, buf[15]);
return ESP_ERR_IMAGE_INVALID;
}
if (p_length != NULL) {
*p_length = length;
}
return ESP_OK;
}

View file

@ -0,0 +1,222 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 <string.h>
#include "esp_attr.h"
#include "esp_types.h"
#include "esp_log.h"
#include "rom/cache.h"
#include "rom/ets_sys.h"
#include "rom/spi_flash.h"
#include "rom/secure_boot.h"
#include "soc/dport_reg.h"
#include "soc/io_mux_reg.h"
#include "soc/efuse_reg.h"
#include "soc/rtc_cntl_reg.h"
#include "sdkconfig.h"
#include "bootloader_flash.h"
#include "esp_image_format.h"
#include "esp_secure_boot.h"
static const char* TAG = "secure_boot";
#define HASH_BLOCK_SIZE 128
#define IV_LEN HASH_BLOCK_SIZE
#define DIGEST_LEN 64
/**
* @function : secure_boot_generate
* @description: generate boot digest (aka "abstract") & iv
*
* @inputs: image_len - length of image to calculate digest for
*/
static bool secure_boot_generate(uint32_t image_len){
SpiFlashOpResult spiRet;
/* buffer is uint32_t not uint8_t to meet ROM SPI API signature */
uint32_t buf[IV_LEN / sizeof(uint32_t)];
const void *image;
/* hardware secure boot engine only takes full blocks, so round up the
image length. The additional data should all be 0xFF.
*/
if (image_len % HASH_BLOCK_SIZE != 0) {
image_len = (image_len / HASH_BLOCK_SIZE + 1) * HASH_BLOCK_SIZE;
}
ets_secure_boot_start();
ets_secure_boot_rd_iv(buf);
ets_secure_boot_hash(NULL);
Cache_Read_Disable(0);
/* iv stored in sec 0 */
spiRet = SPIEraseSector(0);
if (spiRet != SPI_FLASH_RESULT_OK)
{
ESP_LOGE(TAG, "SPI erase failed %d", spiRet);
return false;
}
Cache_Read_Enable(0);
/* write iv to flash, 0x0000, 128 bytes (1024 bits) */
ESP_LOGD(TAG, "write iv to flash.");
spiRet = SPIWrite(0, buf, IV_LEN);
if (spiRet != SPI_FLASH_RESULT_OK)
{
ESP_LOGE(TAG, "SPI write failed %d", spiRet);
return false;
}
bzero(buf, sizeof(buf));
/* generate digest from image contents */
image = bootloader_mmap(0x1000, image_len);
if (!image) {
ESP_LOGE(TAG, "bootloader_mmap(0x1000, 0x%x) failed", image_len);
return false;
}
for (int i = 0; i < image_len; i+= HASH_BLOCK_SIZE) {
ets_secure_boot_hash(image + i/sizeof(void *));
}
bootloader_munmap(image);
ets_secure_boot_obtain();
ets_secure_boot_rd_abstract(buf);
ets_secure_boot_finish();
ESP_LOGD(TAG, "write digest to flash.");
spiRet = SPIWrite(0x80, buf, DIGEST_LEN);
if (spiRet != SPI_FLASH_RESULT_OK) {
ESP_LOGE(TAG, "SPI write failed %d", spiRet);
return false;
}
ESP_LOGD(TAG, "write digest to flash.");
Cache_Read_Enable(0);
return true;
}
/* Burn values written to the efuse write registers */
static inline void burn_efuses()
{
#ifdef CONFIG_SECURE_BOOT_TEST_MODE
ESP_LOGE(TAG, "SECURE BOOT TEST MODE. Not really burning any efuses!");
#else
REG_WRITE(EFUSE_CONF_REG, 0x5A5A); /* efuse_pgm_op_ena, force no rd/wr disable */
REG_WRITE(EFUSE_CMD_REG, 0x02); /* efuse_pgm_cmd */
while (REG_READ(EFUSE_CMD_REG)); /* wait for efuse_pagm_cmd=0 */
REG_WRITE(EFUSE_CONF_REG, 0x5AA5); /* efuse_read_op_ena, release force */
REG_WRITE(EFUSE_CMD_REG, 0x01); /* efuse_read_cmd */
while (REG_READ(EFUSE_CMD_REG)); /* wait for efuse_read_cmd=0 */
#endif
}
esp_err_t esp_secure_boot_permanently_enable(void) {
esp_err_t err;
uint32_t image_len = 0;
if (esp_secure_boot_enabled())
{
ESP_LOGI(TAG, "bootloader secure boot is already enabled, continuing..");
return ESP_OK;
}
err = esp_image_basic_verify(0x1000, &image_len);
if (err != ESP_OK) {
ESP_LOGE(TAG, "bootloader image appears invalid! error %d", err);
return err;
}
uint32_t dis_reg = REG_READ(EFUSE_BLK0_RDATA0_REG);
bool efuse_key_read_protected = dis_reg & EFUSE_RD_DIS_BLK2;
bool efuse_key_write_protected = dis_reg & EFUSE_WR_DIS_BLK2;
if (efuse_key_read_protected == false
&& efuse_key_write_protected == false
&& REG_READ(EFUSE_BLK2_RDATA0_REG) == 0
&& REG_READ(EFUSE_BLK2_RDATA1_REG) == 0
&& REG_READ(EFUSE_BLK2_RDATA2_REG) == 0
&& REG_READ(EFUSE_BLK2_RDATA3_REG) == 0
&& REG_READ(EFUSE_BLK2_RDATA4_REG) == 0
&& REG_READ(EFUSE_BLK2_RDATA5_REG) == 0
&& REG_READ(EFUSE_BLK2_RDATA6_REG) == 0
&& REG_READ(EFUSE_BLK2_RDATA7_REG) == 0) {
ESP_LOGI(TAG, "Generating new secure boot key...");
/* reuse the secure boot IV generation function to generate
the key, as this generator uses the hardware RNG. */
uint32_t buf[32];
ets_secure_boot_start();
ets_secure_boot_rd_iv(buf);
ets_secure_boot_finish();
for (int i = 0; i < 8; i++) {
ESP_LOGV(TAG, "EFUSE_BLK2_WDATA%d_REG = 0x%08x", i, buf[i]);
REG_WRITE(EFUSE_BLK2_WDATA0_REG + 4*i, buf[i]);
}
bzero(buf, sizeof(buf));
burn_efuses();
ESP_LOGI(TAG, "Read & write protecting new key...");
REG_WRITE(EFUSE_BLK0_WDATA0_REG, EFUSE_WR_DIS_BLK2 | EFUSE_RD_DIS_BLK2);
burn_efuses();
efuse_key_read_protected = true;
efuse_key_write_protected = true;
} else {
ESP_LOGW(TAG, "Using pre-loaded secure boot key in EFUSE block 2");
}
ESP_LOGI(TAG, "Generating secure boot digest...");
if (false == secure_boot_generate(image_len)){
ESP_LOGE(TAG, "secure boot generation failed");
return ESP_FAIL;
}
ESP_LOGI(TAG, "Digest generation complete.");
if (!efuse_key_read_protected) {
ESP_LOGE(TAG, "Pre-loaded key is not read protected. Refusing to blow secure boot efuse.");
return ESP_ERR_INVALID_STATE;
}
if (!efuse_key_write_protected) {
ESP_LOGE(TAG, "Pre-loaded key is not write protected. Refusing to blow secure boot efuse.");
return ESP_ERR_INVALID_STATE;
}
ESP_LOGI(TAG, "blowing secure boot efuse...");
ESP_LOGD(TAG, "before updating, EFUSE_BLK0_RDATA6 %x", REG_READ(EFUSE_BLK0_RDATA6_REG));
uint32_t new_wdata6 = EFUSE_RD_ABS_DONE_0;
#ifdef CONFIG_SECURE_BOOT_DISABLE_JTAG
ESP_LOGI(TAG, "disabling JTAG...");
new_wdata6 |= EFUSE_RD_DISABLE_JTAG;
#endif
#ifdef CONFIG_SECURE_BOOT_DISABLE_UART_BOOTLOADER
ESP_LOGI(TAG, "disabling UART bootloader...");
new_wdata6 |= EFUSE_RD_CONSOLE_DEBUG_DISABLE_S;
#endif
REG_WRITE(EFUSE_BLK0_WDATA6_REG, new_wdata6);
burn_efuses();
uint32_t after = REG_READ(EFUSE_BLK0_RDATA6_REG);
ESP_LOGD(TAG, "after updating, EFUSE_BLK0_RDATA6 %x", after);
if (after & EFUSE_RD_ABS_DONE_0) {
ESP_LOGI(TAG, "secure boot is now enabled for bootloader image");
return ESP_OK;
} else {
#ifdef CONFIG_SECURE_BOOT_TEST_MODE
ESP_LOGE(TAG, "secure boot not enabled due to test mode");
#else
ESP_LOGE(TAG, "secure boot not enabled for bootloader image, EFUSE_RD_ABS_DONE_0 is probably write protected!");
#endif
return ESP_ERR_INVALID_STATE;
}
}

View file

@ -0,0 +1,110 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 "sdkconfig.h"
#include "bootloader_flash.h"
#include "esp_log.h"
#include "esp_image_format.h"
#include "esp_secure_boot.h"
#include "uECC.h"
#ifdef BOOTLOADER_BUILD
#include "rom/sha.h"
typedef SHA_CTX sha_context;
#else
#include "hwcrypto/sha.h"
typedef esp_sha_context sha_context;
#endif
typedef struct {
uint32_t version;
uint8_t signature[64];
} signature_block_t;
static const char* TAG = "secure_boot";
extern const uint8_t signature_verification_key_start[] asm("_binary_signature_verification_key_bin_start");
extern const uint8_t signature_verification_key_end[] asm("_binary_signature_verification_key_bin_end");
#define SIGNATURE_VERIFICATION_KEYLEN 64
esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length)
{
sha_context sha;
uint8_t digest[32];
ptrdiff_t keylen;
const uint8_t *data;
const signature_block_t *sigblock;
bool is_valid;
#ifdef BOOTLOADER_BUILD
const uint8_t *digest_data;
uint32_t digest_len;
#endif
ESP_LOGD(TAG, "verifying signature src_addr 0x%x length 0x%x", src_addr, length);
data = bootloader_mmap(src_addr, length + sizeof(signature_block_t));
if(data == NULL) {
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", src_addr, length+sizeof(signature_block_t));
return ESP_FAIL;
}
sigblock = (const signature_block_t *)(data + length);
if (sigblock->version != 0) {
ESP_LOGE(TAG, "src 0x%x has invalid signature version field 0x%08x", src_addr, sigblock->version);
goto unmap_and_fail;
}
#ifdef BOOTLOADER_BUILD
/* Use ROM SHA functions directly */
ets_sha_enable();
ets_sha_init(&sha);
digest_len = length * 8;
digest_data = data;
while (digest_len > 0) {
uint32_t chunk_len = (digest_len > 64) ? 64 : digest_len;
ets_sha_update(&sha, SHA2_256, digest_data, chunk_len);
digest_len -= chunk_len;
digest_data += chunk_len / 8;
}
ets_sha_finish(&sha, SHA2_256, digest);
ets_sha_disable();
#else
/* Use thread-safe esp-idf SHA layer */
esp_sha256_init(&sha);
esp_sha256_start(&sha, false);
esp_sha256_update(&sha, data, length);
esp_sha256_finish(&sha, digest);
esp_sha256_free(&sha);
#endif
keylen = signature_verification_key_end - signature_verification_key_start;
if(keylen != SIGNATURE_VERIFICATION_KEYLEN) {
ESP_LOGE(TAG, "Embedded public verification key has wrong length %d", keylen);
goto unmap_and_fail;
}
is_valid = uECC_verify(signature_verification_key_start,
digest, sizeof(digest), sigblock->signature,
uECC_secp256r1());
bootloader_munmap(data);
return is_valid ? ESP_OK : ESP_ERR_IMAGE_INVALID;
unmap_and_fail:
bootloader_munmap(data);
return ESP_FAIL;
}

View file

@ -8,6 +8,18 @@ config BT_ENABLED
help
This compiles in the low-level BT stack.
menu "BT_UTIL"
visible if BT_ENABLED
config BT_USE_ETS_PRINT
bool "BT USE ETS_PRINT"
default y
depends on BT_ENABLED
help
This select use print or ets_print
endmenu #menu
#config BT_BTLE
# bool "Enable BTLE"
# depends on BT_ENABLED

View file

@ -1,345 +0,0 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 "esp_bt_defs.h"
/*******************************************************************************
**
** Function esp_ble_config_adv_data
**
** Description This function is called to override the BTA default ADV parameters.
**
** adv_data: Pointer to User defined ADV data structure. This
** memory space can not be freed until p_adv_data_cback
** is received.
** p_adv_data_cback: set adv data complete callback.
**
** Returns None
**
*******************************************************************************/
void esp_ble_config_adv_data(esp_ble_adv_data_cfg_t *adv_data,
esp_ble_set_adv_data_cmpl_cb_t *p_adv_data_cback)
{
tBTA_BLE_AD_MASK data_mask = 0;
if(adv_data->adv_name != NULL)
{
data_mask |= BTM_BLE_AD_BIT_DEV_NAME;
BTA_DmSetDeviceName(adv_data->adv_name);
}
if(adv_data->ble_adv_data.int_range.low != 0 ||
adv_data->ble_adv_data.int_range.hi != 0)
data_mask |= BTM_BLE_AD_BIT_INT_RANGE;
if(adv_data->ble_adv_data.p_manu != NULL)
{
data_mask |= BTM_BLE_AD_BIT_MANU;
}
if(adv_data->ble_adv_data.p_services != NULL)
{
data_mask |= BTM_BLE_AD_BIT_SERVICE;
}
if(adv_data->ble_adv_data.p_service_32b != NULL)
{
data_mask |= BTM_BLE_AD_BIT_SERVICE_32;
}
if(adv_data->ble_adv_data.p_services_128b != NULL)
{
data_mask |= BTM_BLE_AD_BIT_SERVICE_128;
}
if(adv_data->ble_adv_data.p_sol_services != NULL)
{
data_mask |= BTM_BLE_AD_BIT_SERVICE_SOL;
}
if(adv_data->ble_adv_data.p_sol_service_32b != NULL)
{
data_mask |= BTM_BLE_AD_BIT_SERVICE_32SOL;
}
if(adv_data->ble_adv_data.p_sol_service_128b != NULL)
{
data_mask |= BTM_BLE_AD_BIT_SERVICE_128SOL;
}
if(adv_data->ble_adv_data.p_service_data != NULL)
{
data_mask |= BTM_BLE_AD_BIT_SERVICE_DATA;
}
if(adv_data->ble_adv_data.appearance != 0)
{
data_mask |= BTM_BLE_AD_BIT_APPEARANCE;
}
if(adv_data->ble_adv_data.p_proprietary != NULL)
{
data_mask |= BTM_BLE_AD_BIT_PROPRIETARY;
}
if(adv_data->ble_adv_data.tx_power != 0)
{
data_mask |= BTM_BLE_AD_BIT_TX_PWR;
}
BTA_DmBleSetAdvConfig(data_mask, &(adv_data->ble_adv_data), p_adv_data_cback);
}
/*******************************************************************************
**
** Function esp_ble_set_scan_rsp
**
** Description This function is called to override the app scan response.
**
** Parameters Pointer to User defined ADV data structure
**
** Returns None
**
*******************************************************************************/
void esp_ble_set_scan_rsp(esp_ble_adv_data_cfg_t *scan_rsp_data,
esp_ble_set_adv_data_cmpl_cb_t *p_scan_rsp_data_cback)
{
tBTA_BLE_AD_MASK data_mask = 0;
if(scan_rsp_data->adv_name != NULL)
{
data_mask |= BTM_BLE_AD_BIT_DEV_NAME;
BTA_DmSetDeviceName(scan_rsp_data->adv_name);
}
if(scan_rsp_data->ble_adv_data.int_range.low != 0 ||
scan_rsp_data->ble_adv_data.int_range.hi != 0)
data_mask |= BTM_BLE_AD_BIT_INT_RANGE;
if(scan_rsp_data->ble_adv_data.p_manu != NULL)
{
data_mask |= BTM_BLE_AD_BIT_MANU;
}
if(scan_rsp_data->ble_adv_data.p_services != NULL)
{
data_mask |= BTM_BLE_AD_BIT_SERVICE;
}
if(scan_rsp_data->ble_adv_data.p_service_32b != NULL)
{
data_mask |= BTM_BLE_AD_BIT_SERVICE_32;
}
if(scan_rsp_data->ble_adv_data.p_services_128b != NULL)
{
data_mask |= BTM_BLE_AD_BIT_SERVICE_128;
}
if(scan_rsp_data->ble_adv_data.p_sol_services != NULL)
{
data_mask |= BTM_BLE_AD_BIT_SERVICE_SOL;
}
if(scan_rsp_data->ble_adv_data.p_sol_service_32b != NULL)
{
data_mask |= BTM_BLE_AD_BIT_SERVICE_32SOL;
}
if(scan_rsp_data->ble_adv_data.p_sol_service_128b != NULL)
{
data_mask |= BTM_BLE_AD_BIT_SERVICE_128SOL;
}
if(scan_rsp_data->ble_adv_data.p_service_data != NULL)
{
data_mask |= BTM_BLE_AD_BIT_SERVICE_DATA;
}
if(scan_rsp_data->ble_adv_data.appearance != 0)
{
data_mask |= BTM_BLE_AD_BIT_APPEARANCE;
}
if(scan_rsp_data->ble_adv_data.p_proprietary != NULL)
{
data_mask |= BTM_BLE_AD_BIT_PROPRIETARY;
}
if(scan_rsp_data->ble_adv_data.tx_power != 0)
{
data_mask |= BTM_BLE_AD_BIT_TX_PWR;
}
BTA_DmBleSetScanRsp(data_mask, &(scan_rsp_data->ble_adv_data), p_scan_rsp_data_cback);
}
#if 0
/*******************************************************************************
**
** @function esp_ble_config_adv_data
**
** @brief This function is called to override the BTA default ADV parameters.
**
** @param[in] adv_data: Pointer to User defined ADV data structure. This
** memory space can not be freed until p_adv_data_cback
** is received.
** @param[in|out] adv_data_cback: set adv data complete callback.
**
** @return None
**
*******************************************************************************/
void esp_ble_config_adv_data (esp_ble_adv_data_cfg_t *adv_data,
esp_ble_set_adv_data_cmpl_cb_t *adv_data_cback)
{
if(adv_data != NULL)
{
ble_config_adv_data(adv_data, adv_data_cback);
}else{
LOG_ERROR("The adv_data is NULL\n");
}
if(++adv_data != NULL)
{
ble_set_scan_rsp(adv_data, NULL);
}
}
#endif
/*******************************************************************************
**
** @function esp_ble_start_advertising
**
** @brief This function is called to start advertising.
**
** @param[in] esp_ble_adv_params_all_t: ointer to User defined adv_params data structure.
**
** @return None
**
*******************************************************************************/
void esp_ble_start_advertising (esp_ble_adv_params_all_t *ble_adv_params)
{
if (!API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) ||
!API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX))
{
LOG_ERROR("Invalid advertisting interval parameters.\n");
return ;
}
if ((ble_adv_params->adv_type < API_NON_DISCOVERABLE) &&
(ble_adv_params->adv_type > API_BROADCASTER_MODE) )
{
LOG_ERROR("Invalid advertisting type parameters.\n");
return;
}
if ((ble_adv_params->adv_filter_policy < ADV_ALLOW_SCAN_ANY_CON_ANY) &&
(ble_adv_params->adv_filter_policy > ADV_ALLOW_SCAN_WLST_CON_WLST) )
{
LOG_ERROR("Invalid advertisting type parameters.\n");
return;
}
LOG_ERROR("API_Ble_AppStartAdvertising\n");
///
BTA_DmSetBleAdvParamsAll(ble_adv_params->adv_int_min,
ble_adv_params->adv_int_max,
ble_adv_params->adv_type,
ble_adv_params->addr_type_own,
ble_adv_params->channel_map,
ble_adv_params->adv_filter_policy,
ble_adv_params->p_dir_bda);
}
/*******************************************************************************
**
** @function esp_ble_set_scan_params
**
** @brief This function is called to set scan parameters
**
** @param[in] esp_ble_scan_params: Pointer to User defined scan_params data structure. This
** memory space can not be freed until scan_param_setup_cback
** @param[in] client_if: Client interface ID
** @param[in|out] scan_param_setup_status_cback - Set scan param status callback
**
** @return None
**
*******************************************************************************/
void esp_ble_set_scan_params (esp_ble_scan_params *scan_params, esp_gattc_if_t client_if,
esp_scan_param_setup_cb_t scan_param_setup_cback)
{
if (API_BLE_ISVALID_PARAM(scan_params->scan_intv, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) &&
API_BLE_ISVALID_PARAM(scan_params->scan_win, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX) &&
(scan_params->scan_type == BTM_BLE_SCAN_MODE_ACTI || scan_params->scan_type == BTM_BLE_SCAN_MODE_PASS))
{
BTA_DmSetBleScanFilterParams(client_if,
scan_params->scan_intv,
scan_params->scan_win,
scan_params->scan_type,
scan_params->scan_fil_policy,
scan_params->addr_type_own,
scan_param_setup_cback);
}
}
/*******************************************************************************
**
** @function esp_ble_start_scanning
**
** @brief This procedure keep the device scanning the peer device whith advertising on the air
**
** @param[in] duration: Keeping the scaning time, the unit is second.
** @param[in|out] results_cb: The scanning function callback when the peer device has been scan
** which advertising on the air
**
** @return None
**
*******************************************************************************/
void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb)
{
if((duration != 0) && (results_cb != NULL))
{
///Start scan the device
BTA_DmBleObserve(true, duration, results_cb);
}else{
LOG_ERROR("The scan duration or p_results_cb invalid\n");
}
}
/*******************************************************************************
**
** @function esp_ble_stop_advertising
**
** @brief This function is called to stop advertising.
**
** @param None
**
** @return None
**
*******************************************************************************/
void esp_ble_stop_advertising (void)
{
bool stop_adv = false;
BTA_DmBleBroadcast(stop_adv);
}

View file

@ -37,7 +37,7 @@ tAPP_SEC_ENV app_sec_env;
UINT32 app_ble_sec_gen_tk(void)
{
// Generate a PIN Code (Between 100000 and 999999)
return (100000 + (random()%900000));
return (100000 + (random() % 900000));
}
/*******************************************************************************
@ -56,19 +56,17 @@ void app_ble_sec_gen_ltk(UINT8 key_size)
app_sec_env.key_size = key_size;
// Randomly generate the LTK and the Random Number
for (i = 0; i < RAND_NB_LEN; i++)
{
app_sec_env.rand_nb.nb[i] = random()%256;
for (i = 0; i < RAND_NB_LEN; i++) {
app_sec_env.rand_nb.nb[i] = random() % 256;
}
// Randomly generate the end of the LTK
for (i = 0; i < SEC_KEY_LEN; i++)
{
app_sec_env.ltk.key[i] = (((key_size) < (16 - i)) ? 0 : random()%256);
for (i = 0; i < SEC_KEY_LEN; i++) {
app_sec_env.ltk.key[i] = (((key_size) < (16 - i)) ? 0 : random() % 256);
}
// Randomly generate the EDIV
app_sec_env.ediv = random()%65536;
app_sec_env.ediv = random() % 65536;
}

View file

@ -0,0 +1,66 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 "esp_blufi_api.h"
#include "esp_bt_defs.h"
#include "esp_bt_main.h"
#include "btc_task.h"
#include "btc_blufi_prf.h"
#include "btc_manage.h"
#include "btc_main.h"
#include "future.h"
esp_err_t esp_blufi_register_callback(esp_profile_cb_t callback)
{
return (btc_profile_cb_set(BTC_PID_BLUFI, callback) == 0 ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_blufi_send_config_state(esp_blufi_config_state_t state)
{
btc_msg_t msg;
btc_blufi_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_BLUFI;
msg.act = BTC_BLUFI_ACT_SEND_CFG_STATE;
arg.cfg_state.state = state;
return (btc_transfer_context(&msg, &arg, sizeof(btc_blufi_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_blufi_profile_init(void)
{
btc_msg_t msg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_BLUFI;
msg.act = BTC_BLUFI_ACT_INIT;
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_blufi_profile_deinit(void)
{
btc_msg_t msg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_BLUFI;
msg.act = BTC_BLUFI_ACT_DEINIT;
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

View file

@ -1,30 +0,0 @@
#include "esp_bt_defs.h"
#include "esp_bt_common.h"
#include "esp_err.h"
extern int bte_main_boot_entry(void *cb);
extern int bte_main_shutdown(void);
// tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback)
esp_err_t esp_enable_bluetooth(esp_bt_sec_cb_t *p_cback)
{
return BTA_EnableBluetooth(p_cback) == BTA_SUCCESS ? ESP_OK : ESP_FAIL;
}
esp_err_t esp_disable_bluetooth(void)
{
return BTA_DisableBluetooth() == BTA_SUCCESS ? ESP_OK : ESP_FAIL;
}
esp_err_t esp_init_bluetooth(bluetooth_init_cb_t cb)
{
return bte_main_boot_entry(cb) == 0 ? ESP_OK : ESP_FAIL;
}
void esp_deinit_bluetooth(void)
{
bte_main_shutdown();
}

View file

@ -0,0 +1,157 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 "esp_bt_main.h"
#include "btc_task.h"
#include "btc_main.h"
#include "future.h"
static bool esp_already_enable = false;
static bool esp_already_init = false;
esp_err_t esp_enable_bluetooth(void)
{
btc_msg_t msg;
future_t **future_p;
if (esp_already_enable) {
LOG_ERROR("%s already enable\n", __func__);
return ESP_ERR_INVALID_STATE;
}
future_p = btc_main_get_future_p(BTC_MAIN_ENABLE_FUTURE);
*future_p = future_new();
if (*future_p == NULL) {
LOG_ERROR("%s failed\n", __func__);
return ESP_ERR_NO_MEM;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_MAIN_INIT;
msg.act = BTC_MAIN_ACT_ENABLE;
btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n", __func__);
return ESP_FAIL;
}
esp_already_enable = true;
return ESP_OK;
}
esp_err_t esp_disable_bluetooth(void)
{
btc_msg_t msg;
future_t **future_p;
if (!esp_already_enable) {
LOG_ERROR("%s already disable\n", __func__);
return ESP_ERR_INVALID_STATE;
}
future_p = btc_main_get_future_p(BTC_MAIN_DISABLE_FUTURE);
*future_p = future_new();
if (*future_p == NULL) {
LOG_ERROR("%s failed\n", __func__);
return ESP_ERR_NO_MEM;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_MAIN_INIT;
msg.act = BTC_MAIN_ACT_DISABLE;
btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n", __func__);
return ESP_FAIL;
}
esp_already_enable = false;
return ESP_OK;
}
esp_err_t esp_init_bluetooth(void)
{
btc_msg_t msg;
future_t **future_p;
if (esp_already_init) {
LOG_ERROR("%s already init\n", __func__);
return ESP_ERR_INVALID_STATE;
}
future_p = btc_main_get_future_p(BTC_MAIN_INIT_FUTURE);
*future_p = future_new();
if (*future_p == NULL) {
LOG_ERROR("%s failed\n", __func__);
return ESP_ERR_NO_MEM;
}
btc_init();
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_MAIN_INIT;
msg.act = BTC_MAIN_ACT_INIT;
btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n", __func__);
return ESP_FAIL;
}
esp_already_init = true;;
return ESP_OK;
}
esp_err_t esp_deinit_bluetooth(void)
{
btc_msg_t msg;
future_t **future_p;
if (!esp_already_init) {
LOG_ERROR("%s already deinit\n", __func__);
return ESP_ERR_INVALID_STATE;
}
future_p = btc_main_get_future_p(BTC_MAIN_DEINIT_FUTURE);
*future_p = future_new();
if (*future_p == NULL) {
LOG_ERROR("%s failed\n", __func__);
return ESP_ERR_NO_MEM;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_MAIN_INIT;
msg.act = BTC_MAIN_ACT_DEINIT;
btc_transfer_context(&msg, NULL, 0, NULL);
if (future_await(*future_p) == FUTURE_FAIL) {
LOG_ERROR("%s failed\n", __func__);
return ESP_FAIL;
}
btc_deinit();
esp_already_init = false;
return ESP_OK;
}

View file

@ -0,0 +1,221 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 <string.h>
#include "esp_gap_ble_api.h"
#include "bta_api.h"
#include "bt_trace.h"
#include "btc_manage.h"
#include "btc_gap_ble.h"
esp_err_t esp_ble_gap_register_callback(esp_profile_cb_t callback)
{
return (btc_profile_cb_set(BTC_PID_GAP_BLE, callback) == 0 ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gap_config_adv_data(esp_ble_adv_data_t *adv_data)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (adv_data == NULL) {
return ESP_ERR_INVALID_ARG;
}
if (adv_data->service_uuid_len & 0xf) { //not 16*n
return ESP_ERR_INVALID_ARG;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_CFG_ADV_DATA;
memcpy(&arg.cfg_adv_data.adv_data, adv_data, sizeof(esp_ble_adv_data_t));
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), btc_gap_ble_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (scan_params == NULL) {
return ESP_ERR_INVALID_ARG;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_SET_SCAN_PARAM;
memcpy(&arg.set_scan_param.scan_params, scan_params, sizeof(esp_ble_scan_params_t));
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gap_start_scanning(uint32_t duration)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_START_SCAN;
arg.start_scan.duration = duration;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gap_stop_scanning(void)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_STOP_SCAN;
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gap_start_advertising(esp_ble_adv_params_t *adv_params)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_START_ADV;
memcpy(&arg.start_adv.adv_params, adv_params, sizeof(esp_ble_adv_params_t));
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gap_stop_advertising(void)
{
btc_msg_t msg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_STOP_ADV;
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_UPDATE_CONN_PARAM;
memcpy(&arg.conn_update_params.conn_params, params, sizeof(esp_ble_conn_update_params_t));
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_data_length)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN;
arg.set_pkt_data_len.tx_data_length = tx_data_length;
memcpy(arg.set_pkt_data_len.remote_device, remote_device, ESP_BD_ADDR_LEN);
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_SET_RAND_ADDRESS;
memcpy(arg.set_rand_addr.rand_addr, rand_addr, ESP_BD_ADDR_LEN);
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY;
arg.cfg_local_privacy.privacy_enable = privacy_enable;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gap_set_device_name(char *name)
{
btc_msg_t msg;
btc_ble_gap_args_t arg;
if (strlen(name) > ESP_GAP_DEVICE_NAME_MAX) {
return ESP_ERR_INVALID_ARG;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GAP_BLE;
msg.act = BTC_GAP_BLE_ACT_SET_DEV_NAME;
strcpy(arg.set_dev_name.device_name, name);
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
**
** Function esp_ble_resolve_adv_data
**
** Description This function is called to get ADV data for a specific type.
**
** Parameters p_adv - pointer of ADV data
** type - finding ADV data type
** p_length - return the length of ADV data not including type
**
** Returns pointer of ADV data
**
*******************************************************************************/
uint8_t *esp_ble_resolve_adv_data( uint8_t *p_adv, uint8_t type, uint8_t *p_length)
{
if (((type < ESP_BLE_AD_TYPE_FLAG) || (type > ESP_BLE_AD_TYPE_128SERVICE_DATA)) &&
(type != ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE)) {
LOG_ERROR("the eir type not define, type = %x\n", type);
return NULL;
}
if (p_adv == NULL) {
LOG_ERROR("Invalid p_eir data.\n");
return NULL;
}
return (BTM_CheckAdvData( p_adv, type, p_length));
}

View file

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "esp_gap_bt_api.h"
#include "bta_api.h"
#include "bt_trace.h"

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,623 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 <string.h>
#include "esp_gattc_api.h"
#include "btc_manage.h"
#include "btc_gattc.h"
/*******************************************************************************
**
** @function esp_ble_gattc_app_register_callback
**
** @brief This function is called to register application callbacks
** with GATTC module.
**
** @param[in] callback - pointer to the application callback function.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_register_callback(esp_profile_cb_t callback)
{
if (callback == NULL) {
return ESP_FAIL;
}
btc_profile_cb_set(BTC_PID_GATTC, callback);
return ESP_OK;
}
/*******************************************************************************
**
** @function esp_ble_gattc_app_register
**
** @brief This function is called to register application
** with GATTC module.
**
** @param[in] app_id : Application Identitfy (UUID), for different application
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_app_register(uint16_t app_id)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_APP_REGISTER;
arg.app_reg.app_id = app_id;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
**
** @function esp_ble_gattc_app_unregister
**
** @brief This function is called to unregister an application
** from GATTC module.
**
** @param[in] client_if - client interface identifier.
**
** @return None
**
*******************************************************************************/
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gatt_if)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_APP_UNREGISTER;
arg.app_unreg.gatt_if = gatt_if;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
**
** @function esp_ble_gattc_conn
**
** @brief Open a direct connection or add a background auto connection
** bd address
**
** @param[in] gatt_if: application identity.
** @param[in] remote_bda: remote device BD address.
** @param[in] is_direct: direct connection or background auto connection
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_OPEN;
arg.open.gatt_if = gatt_if;
memcpy(arg.open.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
arg.open.is_direct = is_direct;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
**
** @function esp_ble_gattc_close
**
** @brief Close a connection to a GATT server.
**
** @param[in] conn_id: connectino ID to be closed.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_close (uint16_t conn_id)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_CLOSE;
arg.close.conn_id = conn_id;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
**
** @function esp_ble_gattc_config_mtu
**
** @brief Configure the MTU size in the GATT channel. This can be done
** only once per connection.
**
** @param[in] conn_id: connection ID.
** mtu: desired MTU size to use.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
if ((mtu < ESP_GATT_DEF_BLE_MTU_SIZE) || (mtu > ESP_GATT_MAX_MTU_SIZE)) {
return ESP_GATT_ILLEGAL_PARAMETER;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_CFG_MTU;
arg.cfg_mtu.conn_id = conn_id;
arg.cfg_mtu.mtu = mtu;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
**
** @function esp_ble_gattc_search_service
**
** @brief This function is called to request a GATT service discovery
** on a GATT server. This function report service search result
** by a callback event, and followed by a service search complete
** event.
**
** @param[in] conn_id: connection ID.
** @param[in] filter_uuid: a UUID of the service application is interested in.
** If Null, discover for all services.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_uuid)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_SEARCH_SERVICE;
arg.search_srvc.conn_id = conn_id;
if (filter_uuid) {
arg.search_srvc.filter_uuid_enable = true;
memcpy(&arg.search_srvc.filter_uuid, filter_uuid, sizeof(esp_bt_uuid_t));
} else {
arg.search_srvc.filter_uuid_enable = false;
}
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/****************************************************************************************************
**
** @function esp_ble_gattc_get_characteristic
**
** @brief This function is called to find the first characteristic of the
** service on the given server.
**
** @param[in] conn_id: connection ID which identify the server.
**
** @param[in] srvc_id: serivce ID
**
** @param[in] start_char_id: the start characteristic ID
**
** @return ESP_OK - success, other - failed
**
*****************************************************************************************************/
esp_err_t esp_ble_gattc_get_characteristic(uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *start_char_id)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
if (start_char_id) {
arg.get_next_char.conn_id = conn_id;
memcpy(&arg.get_next_char.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.get_next_char.char_id, start_char_id, sizeof(esp_gatt_id_t));
msg.act = BTC_GATTC_ACT_GET_NEXT_CHAR;
} else {
arg.get_first_char.conn_id = conn_id;
memcpy(&arg.get_first_char.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
msg.act = BTC_GATTC_ACT_GET_FIRST_CHAR;
}
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/****************************************************************************************************
**
** @function esp_ble_gattc_get_descriptor
**
** @brief This function is called to find the descriptor of the
** service on the given server.
**
** @param[in] conn_id: connection ID which identify the server.
** @param[in] srvc_id: the service ID of which the characteristic is belonged to.
** @param[in] char_id: Characteristic ID, if NULL find the first available
** characteristic.
** @param[in] start_descr_id: the sctart descriptor id
**
** @return ESP_OK - success, other - failed
**
*****************************************************************************************************/
esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
esp_gatt_id_t *start_descr_id)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
if (start_descr_id) {
arg.get_next_descr.conn_id = conn_id;
memcpy(&arg.get_next_descr.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.get_next_descr.char_id, char_id, sizeof(esp_gatt_id_t));
memcpy(&arg.get_next_descr.descr_id, start_descr_id, sizeof(esp_gatt_id_t));
msg.act = BTC_GATTC_ACT_GET_NEXT_DESCR;
} else {
arg.get_first_descr.conn_id = conn_id;
memcpy(&arg.get_first_descr.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.get_first_descr.char_id, char_id, sizeof(esp_gatt_id_t));
msg.act = BTC_GATTC_ACT_GET_FIRST_DESCR;
}
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/****************************************************************************************************
**
** @function esp_ble_gattc_get_include_service
**
** @brief This function is called to find the first characteristic of the
** service on the given server.
**
** @param[in] conn_id: connection ID which identify the server.
** @param[in] srvc_id: the service ID of which the characteristic is belonged to.
** @param[in] start_incl_srvc_id: the start include service id
**
** @return ESP_OK - success, other - failed
**
*****************************************************************************************************/
esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_srvc_id_t *start_incl_srvc_id)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
if (start_incl_srvc_id) {
arg.get_next_incl_srvc.conn_id = conn_id;
memcpy(&arg.get_next_incl_srvc.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.get_next_incl_srvc.start_service_id, start_incl_srvc_id, sizeof(esp_gatt_srvc_id_t));
msg.act = BTC_GATTC_ACT_GET_NEXT_INCL_SERVICE;
} else {
arg.get_first_incl_srvc.conn_id = conn_id;
memcpy(&arg.get_first_incl_srvc.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
msg.act = BTC_GATTC_ACT_GET_FIRST_INCL_SERVICE;
}
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
**
** @function esp_ble_gattc_read_char
**
** @brief This function is called to read a service's characteristics of
** the given characteritisc ID.UTH_REQ_NO_SCATTERNET
**
** @param[in] conn_id - connectino ID.
** @param[in] srvc_id - serivcie ID.
** @param[in] char_id - characteritic ID to read.
** @param[in] auth_req - authenticate request type
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_read_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id, esp_gatt_auth_req_t auth_req)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_READ_CHAR;
arg.read_char.conn_id = conn_id;
memcpy(&arg.read_char.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.read_char.char_id, char_id, sizeof(esp_gatt_id_t));
arg.read_char.auth_req = auth_req;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
**
** @function esp_ble_gattc_read_char_descr
**
** @brief This function is called to read a characteristics descriptor.
**
** @param[in] conn_id - connection ID.
** @param[in] srvc_id - serivcie ID.
** @param[in] descr_id - characteritic descriptor ID to read.
** @param[in] auth_req - authenticate request type
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_read_char_descr (uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
esp_gatt_id_t *descr_id,
esp_gatt_auth_req_t auth_req)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_READ_CHAR_DESCR;
arg.read_descr.conn_id = conn_id;
memcpy(&arg.read_descr.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.read_descr.char_id, char_id, sizeof(esp_gatt_id_t));
memcpy(&arg.read_descr.descr_id, descr_id, sizeof(esp_gatt_id_t));
arg.read_descr.auth_req = auth_req;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
**
** @function esp_ble_gattc_write_char
**
** @brief This function is called to write characteristic value.
**
** @param[in] conn_id - connection ID.
** @param[in] srvc_id - serivcie ID.
** @param[in] char_id - characteristic ID to write.
** @param[in] value_len: length of the value to be written.
** @param[in] value - the value to be written.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
uint16_t value_len,
uint8_t *value,
esp_gatt_auth_req_t auth_req)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_WRITE_CHAR;
arg.write_char.conn_id = (uint16_t) conn_id;
memcpy(&arg.write_char.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.write_char.char_id, char_id, sizeof(esp_gatt_id_t));
arg.write_char.value_len = value_len > ESP_GATT_MAX_ATTR_LEN ? ESP_GATT_MAX_ATTR_LEN : value_len;
arg.write_char.value = value;
arg.write_char.auth_req = auth_req;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), btc_gattc_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
**
** @function esp_ble_gattc_write_char_descr
**
** @brief This function is called to write characteristic descriptor value.
**
** @param[in] conn_id - connection ID
** @param[in] srvc_id - serivcie ID.
** @param[in] char_id - characteristic ID.
** @param[in] descr_id - characteristic descriptor ID to write.
** @param[in] value_len: length of the value to be written.
** @param[in] value - the value to be written.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_write_char_descr (uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
esp_gatt_id_t *descr_id,
uint16_t value_len,
uint8_t *value,
esp_gatt_auth_req_t auth_req)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_WRITE_CHAR_DESCR;
arg.write_descr.conn_id = (uint16_t) conn_id;
memcpy(&arg.write_descr.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.write_descr.char_id, char_id, sizeof(esp_gatt_id_t));
memcpy(&arg.write_descr.descr_id, descr_id, sizeof(esp_gatt_id_t));
arg.write_descr.value_len = value_len > ESP_GATT_MAX_ATTR_LEN ? ESP_GATT_MAX_ATTR_LEN : value_len;
arg.write_descr.value = value;
arg.write_descr.auth_req = auth_req;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), btc_gattc_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
**
** @function esp_ble_gattc_prepare_write
**
** @brief This function is called to prepare write a characteristic value.
**
** @param[in] conn_id - connection ID.
** @param[in] char_id - GATT characteritic ID of the service.
** @param[in] offset - offset of the write value.
** @param[in] value_len: length of the value to be written.
** @param[in] value - the value to be written.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
uint16_t offset,
uint16_t value_len,
uint8_t *value,
esp_gatt_auth_req_t auth_req)
{
//TODO: Review this function
btc_msg_t msg;
btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_PREPARE_WRITE;
arg.prep_write.conn_id = conn_id;
memcpy(&arg.prep_write.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.prep_write.char_id, char_id, sizeof(esp_gatt_id_t));
arg.prep_write.offset = offset;
arg.prep_write.value_len = value_len > ESP_GATT_MAX_ATTR_LEN ? ESP_GATT_MAX_ATTR_LEN : value_len; // length check ?
arg.prep_write.value = value;
arg.prep_write.auth_req = auth_req;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), btc_gattc_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
**
** @function esp_ble_gattc_execu_write
**
** @brief This function is called to execute write a prepare write sequence.
**
** @param[in] conn_id - connection ID.
** @param[in] is_execute - execute or cancel.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_execute_write (uint16_t conn_id, bool is_execute)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_EXECUTE_WRITE;
arg.exec_write.conn_id = conn_id;
arg.exec_write.is_execute = is_execute;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
**
** @function esp_ble_gattc_register_for_notify
**
** @brief This function is called to register for notification of a service.
**
** @param[in] gatt_if - gatt interface id.
** @param[in] bda - target GATT server.
** @param[in] srvc_id - pointer to GATT service ID.
** @param[in] char_id - pointer to GATT characteristic ID.
**
** @return OK if registration succeed, otherwise failed.
**
*******************************************************************************/
esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
esp_bd_addr_t server_bda,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_REG_FOR_NOTIFY;
arg.reg_for_notify.gatt_if = gatt_if;
memcpy(&arg.reg_for_notify.remote_bda, &server_bda, sizeof(esp_bd_addr_t));
memcpy(&arg.reg_for_notify.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.reg_for_notify.char_id, char_id, sizeof(esp_gatt_id_t));
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
/*******************************************************************************
**
** @function esp_ble_gattc_unregister_ntf
**
** @brief This function is called to de-register for notification of a service.
**
** @param[in] gatt_if - gatt interface id.
** @param[in] bda - target GATT server.
** @param[in] srvc_id - pointer to GATT service ID.
** @param[in] char_id - pointer to GATT characteristic ID.
**
** @return OK if deregistration succeed, otherwise failed.
**
*******************************************************************************/
esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gatt_if,
esp_bd_addr_t server_bda,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id)
{
btc_msg_t msg;
btc_ble_gattc_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTC;
msg.act = BTC_GATTC_ACT_UNREG_FOR_NOTIFY;
arg.unreg_for_notify.gatt_if = gatt_if;
memcpy(&arg.unreg_for_notify.remote_bda, &server_bda, sizeof(esp_bd_addr_t));
memcpy(&arg.unreg_for_notify.service_id, srvc_id, sizeof(esp_gatt_srvc_id_t));
memcpy(&arg.unreg_for_notify.char_id, char_id, sizeof(esp_gatt_id_t));
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

View file

@ -0,0 +1,227 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 "string.h"
#include "esp_gatt_defs.h"
#include "esp_gatts_api.h"
#include "btc_manage.h"
#include "btc_gatts.h"
#define COPY_TO_GATTS_ARGS(_gatt_args, _arg, _arg_type) memcpy(_gatt_args, _arg, sizeof(_arg_type))
esp_err_t esp_ble_gatts_register_callback(esp_profile_cb_t callback)
{
return (btc_profile_cb_set(BTC_PID_GATTS, callback) == 0 ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_app_register(uint16_t app_id)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
if (app_id < APP_ID_MIN || app_id > APP_ID_MAX) {
return ESP_ERR_INVALID_ARG;
}
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_APP_REGISTER;
arg.app_reg.app_id = app_id;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatt_if)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_APP_UNREGISTER;
arg.app_unreg.gatt_if = gatt_if;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatt_if,
esp_gatt_srvc_id_t *service_id, uint16_t num_handle)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_CREATE_SERVICE;
arg.create_srvc.gatt_if = gatt_if;
arg.create_srvc.num_handle = num_handle;
memcpy(&arg.create_srvc.service_id, service_id, sizeof(esp_gatt_srvc_id_t));
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_add_include_service(uint16_t service_handle, uint16_t included_service_handle)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_ADD_INCLUDE_SERVICE;
arg.add_incl_srvc.service_handle = service_handle;
arg.add_incl_srvc.included_service_handle = included_service_handle;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_add_char(uint16_t service_handle, esp_bt_uuid_t *char_uuid,
esp_gatt_perm_t perm, esp_gatt_char_prop_t property)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_ADD_CHAR;
arg.add_char.service_handle = service_handle;
arg.add_char.perm = perm;
arg.add_char.property = property;
memcpy(&arg.add_char.char_uuid, char_uuid, sizeof(esp_bt_uuid_t));
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_add_char_descr (uint16_t service_handle,
esp_bt_uuid_t *descr_uuid,
esp_gatt_perm_t perm)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_ADD_CHAR_DESCR;
arg.add_descr.service_handle = service_handle;
arg.add_descr.perm = perm;
memcpy(&arg.add_descr.descr_uuid, descr_uuid, sizeof(esp_bt_uuid_t));
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_delete_service(uint16_t service_handle)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_DELETE_SERVICE;
arg.delete_srvc.service_handle = service_handle;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_start_service(uint16_t service_handle)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_START_SERVICE;
arg.start_srvc.service_handle = service_handle;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_stop_service(uint16_t service_handle)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_STOP_SERVICE;
arg.stop_srvc.service_handle = service_handle;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_send_indicate(uint16_t conn_id, uint16_t attr_handle,
uint16_t value_len, uint8_t *value, bool need_confirm)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_SEND_INDICATE;
arg.send_ind.conn_id = conn_id;
arg.send_ind.attr_handle = attr_handle;
arg.send_ind.need_confirm = need_confirm;
arg.send_ind.value_len = value_len;
arg.send_ind.value = value;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_send_response(uint16_t conn_id, uint32_t trans_id,
esp_gatt_status_t status, esp_gatt_rsp_t *rsp)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_SEND_RESPONSE;
arg.send_rsp.conn_id = conn_id;
arg.send_rsp.trans_id = trans_id;
arg.send_rsp.status = status;
arg.send_rsp.rsp = rsp;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), btc_gatts_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_OPEN;
arg.open.gatt_if = gatt_if;
arg.open.is_direct = is_direct;
memcpy(&arg.open.remote_bda, remote_bda, sizeof(esp_bd_addr_t));
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_gatts_close(uint16_t conn_id)
{
btc_msg_t msg;
btc_ble_gatts_args_t arg;
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_GATTS;
msg.act = BTC_GATTS_ACT_CLOSE;
arg.close.conn_id = conn_id;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gatts_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}

View file

@ -22,7 +22,7 @@ esp_err_t esp_bt_sdp_enable(bt_sdp_cb_t *cback)
return (status == BTA_SDP_SUCCESS) ? ESP_OK : ESP_FAIL;
}
esp_err_t esp_bt_sdp_search(esp_bd_addr_t bd_addr, esp_bt_uuid_t* uuid)
esp_err_t esp_bt_sdp_search(esp_bd_addr_t bd_addr, esp_bt_uuid_t *uuid)
{
tBTA_SDP_STATUS status = BTA_SdpSearch(bd_addr, (tSDP_UUID *)uuid);
return (status == BTA_SDP_SUCCESS) ? ESP_OK : ESP_FAIL;

View file

@ -1,106 +0,0 @@
#ifndef __ESP_ADV_API_H__
#define __ESP_ADV_API_H__
#include "bt_types.h"
#include "esp_bt_defs.h"
#include "bta_gatt_api.h"
#include "bt_prf_sys.h"
/*******************************************************************************
**
** @function esp_ble_config_adv_data
**
** @brief This function is called to override the BTA default ADV parameters.
**
** @param[in] adv_data: Pointer to User defined ADV data structure. This
** memory space can not be freed until p_adv_data_cback
** is received.
** @param[in|out] adv_data_cback: set adv data complete callback.
**
** @return None
**
*******************************************************************************/
void esp_ble_config_adv_data (esp_ble_adv_data_cfg_t *adv_data,
esp_ble_set_adv_data_cmpl_cb_t *adv_data_cback);
/*******************************************************************************
**
** Function esp_ble_set_scan_rsp
**
** Description This function is called to override the app scan response.
**
** Parameters Pointer to User defined ADV data structure
**
** Returns None
**
*******************************************************************************/
void esp_ble_set_scan_rsp(esp_ble_adv_data_cfg_t *scan_rsp_data,
esp_ble_set_adv_data_cmpl_cb_t *p_scan_rsp_data_cback);
/*******************************************************************************
**
** @function esp_ble_set_scan_params
**
** @brief This function is called to set scan parameters
**
** @param[in] esp_ble_scan_params: Pointer to User defined scan_params data structure. This
** memory space can not be freed until scan_param_setup_cback
** @param[in] client_if: Client interface ID
** @param[in|out] scan_param_setup_status_cback - Set scan param status callback
**
** @return None
**
*******************************************************************************/
void esp_ble_set_scan_params (esp_ble_scan_params *scan_params, esp_gattc_if_t client_if,
esp_scan_param_setup_cb_t scan_param_setup_cback);
/*******************************************************************************
**
** @function esp_ble_start_scanning
**
** @brief This procedure keep the device scanning the peer device whith advertising on the air
**
** @param[in] duration: Keeping the scaning time, the unit is second.
** @param[in|out] results_cb: The scanning function callback when the peer device has been scan
** which advertising on the air
**
** @return None
**
*******************************************************************************/
void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb);
/*******************************************************************************
**
** @function esp_ble_start_advertising
**
** @brief This function is called to start advertising.
**
** @param[in] esp_ble_adv_params_all_t: ointer to User defined adv_params data structure.
**
** @return None
**
*******************************************************************************/
void esp_ble_start_advertising (esp_ble_adv_params_all_t *ble_adv_params);
/*******************************************************************************
**
** @function esp_ble_stop_advertising
**
** @brief This function is called to stop advertising.
**
** @param None
**
** @return None
**
*******************************************************************************/
void esp_ble_stop_advertising (void);
#endif /* __ESP_ADV_API_H__ */

View file

@ -0,0 +1,111 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 __ESP_BLUFI_API_H__
#define __ESP_BLUFI_API_H__
#include "bt_types.h"
#include "esp_bt_defs.h"
#include "esp_gatt_defs.h"
#include "bta_gatt_api.h"
#include "esp_err.h"
#define ESP_BLUFI_RECV_DATA_LEN_MAX 128
#define ESP_BLUFI_EVENT_INIT_FINISH 0
#define ESP_BLUFI_EVENT_DEINIT_FINISH 1
#define ESP_BLUFI_EVENT_RECV_DATA 2
typedef enum {
ESP_BLUFI_CONFIG_OK = 0,
ESP_BLUFI_CONFIG_FAILED,
} esp_blufi_config_state_t;
typedef enum {
ESP_BLUFI_INIT_OK = 0,
ESP_BLUFI_INIT_FAILED = 0,
} esp_blufi_init_state_t;
typedef enum {
ESP_BLUFI_DEINIT_OK = 0,
ESP_BLUFI_DEINIT_FAILED = 0,
} esp_blufi_deinit_state_t;
typedef union {
//ESP_BLUFI_EVENT_INIT_FINISH
struct blufi_init_finish_evt_param {
esp_blufi_init_state_t state;
} init_finish;
//ESP_BLUFI_EVENT_DEINIT_FINISH
struct blufi_deinit_finish_evt_param {
esp_blufi_deinit_state_t state;
} deinit_finish;
//ESP_BLUFI_EVENT_RECV_DATA
struct blufi_recv_evt_param {
uint8_t data[ESP_BLUFI_RECV_DATA_LEN_MAX];
uint8_t data_len;
} recv_data;
} esp_blufi_cb_param_t;
/*******************************************************************************
**
** @function esp_blufi_register_callback
**
** @brief This function is called to receive blufi callback event
**
** @param[in] callback: callback function
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_blufi_register_callback(esp_profile_cb_t callback);
/*******************************************************************************
**
** @function esp_blufi_send_config_state
**
** @brief This function is called to send config state to phone
**
** @param[in] state: blufi config ok or not
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_blufi_send_config_state(esp_blufi_config_state_t state);
/*******************************************************************************
**
** @function esp_blufi_profile_init
**
** @brief This function is called to init blufi_profile
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_blufi_profile_init(void);
/*******************************************************************************
**
** @function esp_blufi_profile_deinit
**
** @brief This function is called to init blufi_profile
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_blufi_profile_deinit(void);
#endif /* _ESP_BLUFI_API_ */

View file

@ -1,84 +0,0 @@
#ifndef __ESP_BT_COMMON_H__
#define __ESP_BT_COMMON_H__
#include <stdint.h>
#include "bt_types.h"
#include "bta_api.h"
#include "esp_err.h"
typedef tBT_UUID esp_bt_uuid_t; /* tBT_UUID in "bt_types.h" */
typedef BD_ADDR esp_bd_addr_t; /* BD_ADDR in bt_types.h */
typedef tBTA_DM_SEC_CBACK esp_bt_sec_cb_t;
typedef void (*bluetooth_init_cb_t)(void);
/*******************************************************************************
**
** @function esp_enable_bluetooth
**
** @brief This function is called to enable bluetooth host. This
** function must be called before any other functions in the
** API (except esp_bluetooth_init) are called.
**
** @param[in] p_cback:
** security call back function
** @param[out] None
**
** @return ESP_OK - Success; Other - Failed
**
*******************************************************************************/
esp_err_t esp_enable_bluetooth(esp_bt_sec_cb_t p_cback);
/*******************************************************************************
**
** @function esp_disable_bluetooth
**
** @brief This function is called to disable bluetooth host
**
** @param[in] None
**
** @param[out] None
**
** @return ESP_OK - Success; Other - Failed
**
*******************************************************************************/
esp_err_t esp_disable_bluetooth(void);
/*******************************************************************************
**
** @function esp_init_bluetooth
**
** @brief This function is called to init bluetooth host and alloc the
** resource. This function must be called before all othor API
** are called.
**
** @param[in] cb: When this function called success, the callback will be called
**
** @param[out] None
**
** @return ESP_OK - Success; Other - Failed
**
*******************************************************************************/
esp_err_t esp_init_bluetooth(bluetooth_init_cb_t cb);
/*******************************************************************************
**
** @function esp_deinit_bluetooth
**
** @brief This function is called to deinit bluetooth host and free the
** resource.
**
** @param[in] None
**
** @param[out] None
**
** @return ESP_OK - Success; Other - Failed
**
*******************************************************************************/
void esp_deinit_bluetooth(void);
#endif /* __ESP_BT_COMMON_H__ */

View file

@ -1,331 +1,88 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 __ESP_BT_DEFS_H__
#define __ESP_BT_DEFS_H__
#include <stdint.h>
#include <stdbool.h>
#include "bta_api.h"
#include "btm_ble_api.h"
#include "bta_gatt_api.h"
/* Status Return Value */
typedef enum {
ESP_BT_STATUS_SUCCESS = 0, /* Successful operation. */
ESP_BT_STATUS_FAILURE = 1, /* Generic failure. */
ESP_BT_STATUS_PENDING = 2, /* API cannot be completed right now */
ESP_BT_STATUS_BUSY = 3,
ESP_BT_STATUS_NO_RESOURCES = 4,
ESP_BT_STATUS_WRONG_MODE = 5,
} esp_bt_status_t;
#define ESP_DEFAULT_GATT_IF 0xff
#define ESP_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */
#define ESP_BLE_ADV_CHNL_MAP (ESP_BLE_ADV_CHNL_37|ESP_BLE_ADV_CHNL_38|ESP_BLE_ADV_CHNL_39)
#define ESP_BLE_IS_VALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF))
/* advertising channel map */
#define ESP_BLE_ADV_CHNL_37 (0x01 << 0)
#define ESP_BLE_ADV_CHNL_38 (0x01 << 1)
#define ESP_BLE_ADV_CHNL_39 (0x01 << 2)
typedef struct {
#define ESP_UUID_LEN_16 2
#define ESP_UUID_LEN_32 4
#define ESP_UUID_LEN_128 16
uint16_t len;
union {
uint16_t uuid16;
uint32_t uuid32;
uint8_t uuid128[ESP_UUID_LEN_128];
} uuid;
} __attribute__((packed)) esp_bt_uuid_t; /* tBT_UUID in "bt_types.h" */
typedef tBTA_GATT_STATUS esp_gatt_status_t;
typedef enum {
ESP_BT_DEVICE_TYPE_BREDR = 0x01,
ESP_BT_DEVICE_TYPE_BLE = 0x02,
ESP_BT_DEVICE_TYPE_DUMO = 0x03,
} esp_bt_dev_type_t;
#define ESP_BD_ADDR_LEN 6
typedef uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN]; /* BD_ADDR in bt_types.h */
/// Own BD address source of the device
typedef enum {
/// Public Address
BD_ADDR_PUBLIC,
/// Provided random address
BD_ADDR_PROVIDED_RND,
/// Provided static random address
BD_ADDR_GEN_STATIC_RND,
/// Generated resolvable private random address
BD_ADDR_GEN_RSLV,
/// Generated non-resolvable private random address
BD_ADDR_GEN_NON_RSLV,
/// Provided Reconnection address
BD_ADDR_PROVIDED_RECON,
} esp_bd_addr_type_t;
typedef enum {
BLE_ADDR_TYPE_PUBLIC = 0x00,
BLE_ADDR_TYPE_RANDOM = 0x01,
BLE_ADDR_TYPE_RPA_PUBLIC = 0x02,
BLE_ADDR_TYPE_RPA_RANDOM = 0x03,
} esp_ble_addr_type_t;
#define APP_ID_MIN 0x0000
#define APP_ID_MAX 0x7fff
typedef UINT16 gatt_size_t;
typedef tBT_UUID esp_bt_uuid_t;
typedef tBTA_GATT_ID esp_gatt_id_t;
typedef tBTA_BLE_AD_MASK esp_ble_ad_mask_t;
typedef tGATT_IF esp_gatt_if_t;
typedef tBTA_GATT_SRVC_ID esp_gatt_srvc_id_t;
typedef tBTA_GATTC_CHAR_ID esp_gattc_char_id_t;
typedef tBTA_GATTC_CHAR_DESCR_ID esp_gattc_char_descr_id_t;
typedef tBTA_GATTC_INCL_SVC_ID esp_gattc_incl_srvc_id_t;
typedef tBTA_GATT_AUTH_REQ esp_gatt_auth_req_t;
typedef tBTA_GATTC_MULTI esp_gattc_multi_t;
typedef tBTA_GATTC_WRITE_TYPE esp_gattc_write_type_t;
typedef tBTA_GATT_UNFMT esp_gatt_unfmt_t;
typedef tBTA_GATT_PERM esp_gatt_perm_t;
typedef tBTA_GATT_CHAR_PROP esp_gatt_char_prop_t;
typedef tBTA_GATTC esp_gattc_t;
typedef tBTA_GATTC_EVT esp_gattc_evt_t;
typedef tBTA_GATTC_IF esp_gattc_if_t;
/* Client callback function events */
#define ESP_GATTC_REG_EVT 0 /* GATT client is registered. */
#define ESP_GATTC_DEREG_EVT 1 /* GATT client deregistered event */
#define ESP_GATTC_OPEN_EVT 2 /* GATTC open request status event */
#define ESP_GATTC_READ_CHAR_EVT 3 /* GATT read characteristic event */
#define ESP_GATTC_WRITE_CHAR_EVT 4 /* GATT write characteristic or char descriptor event */
#define ESP_GATTC_CLOSE_EVT 5 /* GATTC close request status event */
#define ESP_GATTC_SEARCH_CMPL_EVT 6 /* GATT discovery complete event */
#define ESP_GATTC_SEARCH_RES_EVT 7 /* GATT discovery result event */
#define ESP_GATTC_READ_DESCR_EVT 8 /* GATT read characterisitc descriptor event */
#define ESP_GATTC_WRITE_DESCR_EVT 9 /* GATT write characteristic descriptor event */
#define ESP_GATTC_NOTIF_EVT 10 /* GATT attribute notification event */
#define ESP_GATTC_PREP_WRITE_EVT 11 /* GATT prepare write event */
#define ESP_GATTC_EXEC_EVT 12 /* execute write complete event */
#define ESP_GATTC_ACL_EVT 13 /* ACL up event */
#define ESP_GATTC_CANCEL_OPEN_EVT 14 /* cancel open event */
#define ESP_GATTC_SRVC_CHG_EVT 15 /* service change event */
#define ESP_GATTC_ENC_CMPL_CB_EVT 17 /* encryption complete callback event */
#define ESP_GATTC_CFG_MTU_EVT 18 /* configure MTU complete event */
#define ESP_GATTC_ADV_DATA_EVT 19 /* ADV data event */
#define ESP_GATTC_MULT_ADV_ENB_EVT 20 /* Enable Multi ADV event */
#define ESP_GATTC_MULT_ADV_UPD_EVT 21 /* Update parameter event */
#define ESP_GATTC_MULT_ADV_DATA_EVT 22 /* Multi ADV data event */
#define ESP_GATTC_MULT_ADV_DIS_EVT 23 /* Disable Multi ADV event */
#define ESP_GATTC_CONGEST_EVT 24 /* Congestion event */
#define ESP_GATTC_BTH_SCAN_ENB_EVT 25 /* Enable batch scan event */
#define ESP_GATTC_BTH_SCAN_CFG_EVT 26 /* Config storage event */
#define ESP_GATTC_BTH_SCAN_RD_EVT 27 /* Batch scan reports read event */
#define ESP_GATTC_BTH_SCAN_THR_EVT 28 /* Batch scan threshold event */
#define ESP_GATTC_BTH_SCAN_PARAM_EVT 29 /* Batch scan param event */
#define ESP_GATTC_BTH_SCAN_DIS_EVT 30 /* Disable batch scan event */
#define ESP_GATTC_SCAN_FLT_CFG_EVT 31 /* Scan filter config event */
#define ESP_GATTC_SCAN_FLT_PARAM_EVT 32 /* Param filter event */
#define ESP_GATTC_SCAN_FLT_STATUS_EVT 33 /* Filter status event */
#define ESP_GATTC_ADV_VSC_EVT 34 /* ADV VSC event */
/* GATT Server Data Structure */
/* Server callback function events */
#define ESP_GATTS_REG_EVT 0
#define ESP_GATTS_READ_EVT GATTS_REQ_TYPE_READ /* 1 */
#define ESP_GATTS_WRITE_EVT GATTS_REQ_TYPE_WRITE /* 2 */
#define ESP_GATTS_EXEC_WRITE_EVT GATTS_REQ_TYPE_WRITE_EXEC /* 3 */
#define ESP_GATTS_MTU_EVT GATTS_REQ_TYPE_MTU /* 4 */
#define ESP_GATTS_CFM_EVT GATTS_REQ_TYPE_CONF /* 5 */
#define ESP_GATTS_DEREG_EVT 6
#define ESP_GATTS_CREATE_EVT 7
#define ESP_GATTS_ADD_INCL_SRVC_EVT 8
#define ESP_GATTS_ADD_CHAR_EVT 9
#define ESP_GATTS_ADD_CHAR_DESCR_EVT 10
#define ESP_GATTS_DELELTE_EVT 11
#define ESP_GATTS_START_EVT 12
#define ESP_GATTS_STOP_EVT 13
#define ESP_GATTS_CONNECT_EVT 14
#define ESP_GATTS_DISCONNECT_EVT 15
#define ESP_GATTS_OPEN_EVT 16
#define ESP_GATTS_CANCEL_OPEN_EVT 17
#define ESP_GATTS_CLOSE_EVT 18
#define ESP_GATTS_CONGEST_EVT 20
/* Attribute permissions
*/
#define ESP_GATT_PERM_READ BTA_GATT_PERM_READ /* bit 0 - 0x0001 */
#define ESP_GATT_PERM_READ_ENCRYPTED BTA_GATT_PERM_READ_ENCRYPTED /* bit 1 - 0x0002 */
#define ESP_GATT_PERM_READ_ENC_MITM BTA_GATT_PERM_READ_ENC_MITM /* bit 2 - 0x0004 */
#define ESP_GATT_PERM_WRITE BTA_GATT_PERM_WRITE /* bit 4 - 0x0010 */
#define ESP_GATT_PERM_WRITE_ENCRYPTED BTA_GATT_PERM_WRITE_ENCRYPTED /* bit 5 - 0x0020 */
#define ESP_GATT_PERM_WRITE_ENC_MITM BTA_GATT_PERM_WRITE_ENC_MITM /* bit 6 - 0x0040 */
#define ESP_GATT_PERM_WRITE_SIGNED BTA_GATT_PERM_WRITE_SIGNED /* bit 7 - 0x0080 */
#define ESP_GATT_PERM_WRITE_SIGNED_MITM BTA_GATT_PERM_WRITE_SIGNED_MITM /* bit 8 - 0x0100 */
#define ESP_GATTS_INVALID_APP 0xff
#define ESP_GATTS_INVALID_IF 0
/* definition of characteristic properties */
#define ESP_GATT_CHAR_PROP_BIT_BROADCAST BTA_GATT_CHAR_PROP_BIT_BROADCAST /* 0x01 */
#define ESP_GATT_CHAR_PROP_BIT_READ BTA_GATT_CHAR_PROP_BIT_READ /* 0x02 */
#define ESP_GATT_CHAR_PROP_BIT_WRITE_NR BTA_GATT_CHAR_PROP_BIT_WRITE_NR /* 0x04 */
#define ESP_GATT_CHAR_PROP_BIT_WRITE BTA_GATT_CHAR_PROP_BIT_WRITE /* 0x08 */
#define ESP_GATT_CHAR_PROP_BIT_NOTIFY BTA_GATT_CHAR_PROP_BIT_NOTIFY /* 0x10 */
#define ESP_GATT_CHAR_PROP_BIT_INDICATE BTA_GATT_CHAR_PROP_BIT_INDICATE /* 0x20 */
#define ESP_GATT_CHAR_PROP_BIT_AUTH BTA_GATT_CHAR_PROP_BIT_AUTH /* 0x40 */
#define ESP_GATT_CHAR_PROP_BIT_EXT_PROP BTA_GATT_CHAR_PROP_BIT_EXT_PROP /* 0x80 */
typedef tBTA_GATTS_EVT esp_gatts_evt_t;
typedef tBTA_GATTS_IF esp_gatts_if_t;
/* attribute value */
typedef tBTA_GATT_VALUE esp_gatt_value_t;
/* attribute response data */
typedef tBTA_GATTS_RSP esp_gatts_rsp_t;
typedef tBTA_GATTS esp_gatts_t;
/* attribute request data from the client */
#define ESP_GATT_PREP_WRITE_CANCEL 0x00
#define ESP_GATT_PREP_WRITE_EXEC 0x01
typedef tBTA_GATT_EXEC_FLAG esp_gatt_exec_flag_t;
/* read request always based on UUID */
typedef tBTA_GATT_READ_REQ esp_gatt_read_req_t;
/* write request data */
typedef tBTA_GATT_WRITE_REQ esp_gatt_write_req_t;
/* callback data for server access request from client */
typedef tBTA_GATTS_REQ_DATA esp_gatts_req_data_t;
/* Search callback */
typedef tBTA_DM_SEARCH_CBACK esp_dm_search_cb_t;
typedef tBLE_SCAN_PARAM_SETUP_CBACK esp_scan_param_setup_cb_t;
typedef tBTA_SET_ADV_DATA_CMPL_CBACK esp_ble_set_adv_data_cmpl_cb_t;
/* GATTC enable callback function */
typedef void (esp_gattc_enb_cb_t)(esp_gatt_status_t status);
/* Client callback function */
typedef void (esp_gattc_cb_t)(esp_gattc_evt_t event, esp_gattc_t *cb_data);
/* GATTS enable callback function */
typedef void (esp_gatts_enb_cb_t)(esp_gatt_status_t status);
/* Server callback function */
typedef void (esp_gatts_cb_t)(esp_gatts_evt_t event, esp_gatts_t *cb_data);
/* Success code and error codes */
#define ESP_GATT_OK BTA_GATT_OK
#define ESP_GATT_INVALID_HANDLE BTA_GATT_INVALID_HANDLE /* 0x0001 */
#define ESP_GATT_READ_NOT_PERMIT BTA_GATT_READ_NOT_PERMIT /* 0x0002 */
#define ESP_GATT_WRITE_NOT_PERMIT BTA_GATT_WRITE_NOT_PERMIT /* 0x0003 */
#define ESP_GATT_INVALID_PDU BTA_GATT_INVALID_PDU /* 0x0004 */
#define ESP_GATT_INSUF_AUTHENTICATION BTA_GATT_INSUF_AUTHENTICATION /* 0x0005 */
#define ESP_GATT_REQ_NOT_SUPPORTED BTA_GATT_REQ_NOT_SUPPORTED /* 0x0006 */
#define ESP_GATT_INVALID_OFFSET BTA_GATT_INVALID_OFFSET /* 0x0007 */
#define ESP_GATT_INSUF_AUTHORIZATION BTA_GATT_INSUF_AUTHORIZATION /* 0x0008 */
#define ESP_GATT_PREPARE_Q_FULL BTA_GATT_PREPARE_Q_FULL /* 0x0009 */
#define ESP_GATT_NOT_FOUND BTA_GATT_NOT_FOUND /* 0x000a */
#define ESP_GATT_NOT_LONG BTA_GATT_NOT_LONG /* 0x000b */
#define ESP_GATT_INSUF_KEY_SIZE BTA_GATT_INSUF_KEY_SIZE /* 0x000c */
#define ESP_GATT_INVALID_ATTR_LEN BTA_GATT_INVALID_ATTR_LEN /* 0x000d */
#define ESP_GATT_ERR_UNLIKELY BTA_GATT_ERR_UNLIKELY /* 0x000e */
#define ESP_GATT_INSUF_ENCRYPTION BTA_GATT_INSUF_ENCRYPTION /* 0x000f */
#define ESP_GATT_UNSUPPORT_GRP_TYPE BTA_GATT_UNSUPPORT_GRP_TYPE /* 0x0010 */
#define ESP_GATT_INSUF_RESOURCE BTA_GATT_INSUF_RESOURCE /* 0x0011 */
#define ESP_GATT_NO_RESOURCES BTA_GATT_NO_RESOURCES /* 0x80 */
#define ESP_GATT_INTERNAL_ERROR BTA_GATT_INTERNAL_ERROR /* 0x81 */
#define ESP_GATT_WRONG_STATE BTA_GATT_WRONG_STATE /* 0x82 */
#define ESP_GATT_DB_FULL BTA_GATT_DB_FULL /* 0x83 */
#define ESP_GATT_BUSY BTA_GATT_BUSY /* 0x84 */
#define ESP_GATT_ERROR BTA_GATT_ERROR /* 0x85 */
#define ESP_GATT_CMD_STARTED BTA_GATT_CMD_STARTED /* 0x86 */
#define ESP_GATT_ILLEGAL_PARAMETER BTA_GATT_ILLEGAL_PARAMETER /* 0x87 */
#define ESP_GATT_PENDING BTA_GATT_PENDING /* 0x88 */
#define ESP_GATT_AUTH_FAIL BTA_GATT_AUTH_FAIL /* 0x89 */
#define ESP_GATT_MORE BTA_GATT_MORE /* 0x8a */
#define ESP_GATT_INVALID_CFG BTA_GATT_INVALID_CFG /* 0x8b */
#define ESP_GATT_SERVICE_STARTED BTA_GATT_SERVICE_STARTED /* 0x8c */
#define ESP_GATT_ENCRYPED_MITM BTA_GATT_ENCRYPED_MITM /* GATT_SUCCESS */
#define ESP_GATT_ENCRYPED_NO_MITM BTA_GATT_ENCRYPED_NO_MITM /* 0x8d */
#define ESP_GATT_NOT_ENCRYPTED BTA_GATT_NOT_ENCRYPTED /* 0x8e */
#define ESP_GATT_CONGESTED BTA_GATT_CONGESTED /* 0x8f */
#define ESP_GATT_DUP_REG BTA_GATT_DUP_REG /* 0x90 */
#define ESP_GATT_ALREADY_OPEN BTA_GATT_ALREADY_OPEN /* 0x91 */
#define ESP_GATT_CANCEL BTA_GATT_CANCEL /* 0x92 */
/* 0xE0 ~ 0xFC reserved for future use */
#define ESP_GATT_CCC_CFG_ERR BTA_GATT_CCC_CFG_ERR /* 0xFD Client Characteristic Configuration Descriptor Improperly Configured */
#define ESP_GATT_PRC_IN_PROGRESS BTA_GATT_PRC_IN_PROGRESS /* 0xFE Procedure Already in progress */
#define ESP_GATT_OUT_OF_RANGE BTA_GATT_OUT_OF_RANGE /* 0xFFAttribute value out of range */
typedef void (* esp_profile_cb_t)(uint32_t event, void *param);
#define API_BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF))
enum
{
BLE_ADV_DATA_IDX,
BLE_SCAN_RSP_DATA_IDX,
ADV_SCAN_IDX_MAX
};
/// Advertising mode
enum api_adv_type
{
/// Mode in non-discoverable
API_NON_DISCOVERABLE,
/// Mode in general discoverable
API_GEN_DISCOVERABLE,
/// Mode in limited discoverable
API_LIM_DISCOVERABLE,
/// Broadcaster mode which is a non discoverable and non connectable mode.
API_BROADCASTER_MODE,
};
enum api_adv_filter
{
///Allow both scan and connection requests from anyone
ADV_ALLOW_SCAN_ANY_CON_ANY = 0x00,
///Allow both scan req from White List devices only and connection req from anyone
ADV_ALLOW_SCAN_WLST_CON_ANY,
///Allow both scan req from anyone and connection req from White List devices only
ADV_ALLOW_SCAN_ANY_CON_WLST,
///Allow scan and connection requests from White List devices only
ADV_ALLOW_SCAN_WLST_CON_WLST,
///Enumeration end value for advertising filter policy value check
ADV_ALLOW_SCAN_END
};
/// Own BD address source of the device
enum api_own_addr_src
{
/// Public Address
API_PUBLIC_ADDR,
/// Provided random address
API_PROVIDED_RND_ADDR,
/// Provided static random address
API_GEN_STATIC_RND_ADDR,
/// Generated resolvable private random address
API_GEN_RSLV_ADDR,
/// Generated non-resolvable private random address
API_GEN_NON_RSLV_ADDR,
/// Provided Reconnection address
API_PROVIDED_RECON_ADDR,
};
typedef struct
{
char *adv_name; //set the device name to be sent on the advertising
tBTA_BLE_ADV_DATA ble_adv_data;
}esp_ble_adv_data_cfg_t;
typedef struct
{
UINT16 adv_int_min;
UINT16 adv_int_max;
tBLE_BD_ADDR *p_dir_bda;
}esp_ble_adv_params_t;
typedef struct
{
UINT16 adv_int_min;
UINT16 adv_int_max;
UINT8 adv_type;
tBLE_ADDR_TYPE addr_type_own;
tBTM_BLE_ADV_CHNL_MAP channel_map;
tBTM_BLE_AFP adv_filter_policy;
tBLE_BD_ADDR *p_dir_bda;
}esp_ble_adv_params_all_t;
typedef struct
{
UINT8 scan_type;
UINT16 scan_intv;
UINT16 scan_win;
UINT8 addr_type_own;
UINT8 scan_fil_policy;
}esp_ble_scan_params;
extern void ble_config_adv_data(esp_ble_adv_data_cfg_t *adv_data,
tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback);
extern void ble_set_scan_rsp(esp_ble_adv_data_cfg_t *scan_rsp_data,
tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback);
#endif ///__ESP_BT_DEFS_H__

View file

@ -0,0 +1,30 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 __ESP_BT_MAIN_H__
#define __ESP_BT_MAIN_H__
#include "btc_main.h"
#include "esp_err.h"
esp_err_t esp_enable_bluetooth(void);
esp_err_t esp_disable_bluetooth(void);
esp_err_t esp_init_bluetooth(void);
esp_err_t esp_deinit_bluetooth(void);
#endif /* __ESP_BT_MAIN_H__ */

View file

@ -1,18 +0,0 @@
#ifndef __ESP_GAP_API_H__
#define __ESP_GAP_API_H__
#include <stdint.h>
#include "esp_err.h"
#include "esp_bt_common.h"
enum {
BT_SCAN_MODE_NONE,
BT_SCAN_MODE_CONNECTABLE,
BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE
};
typedef uint16_t bt_scan_mode_t;
esp_err_t esp_bt_gap_set_scan_mode(bt_scan_mode_t mode);
#endif /* __ESP_GAP_API_H__ */

View file

@ -0,0 +1,390 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 __ESP_GAP_BLE_API_H__
#define __ESP_GAP_BLE_API_H__
#include <stdint.h>
#include <stdbool.h>
#include "esp_err.h"
#include "esp_bt_defs.h"
#define ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT 0
#define ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT 1
#define ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT 2
#define ESP_GAP_BLE_SCAN_RESULT_EVT 3
#define ESP_BLE_ADV_DATA_LEN_MAX 31
/****************** define the adv type macro***************************************/
#define ESP_BLE_AD_TYPE_FLAG 0x01
#define ESP_BLE_AD_TYPE_16SRV_PART 0x02
#define ESP_BLE_AD_TYPE_16SRV_CMPL 0x03
#define ESP_BLE_AD_TYPE_32SRV_PART 0x04
#define ESP_BLE_AD_TYPE_32SRV_CMPL 0x05
#define ESP_BLE_AD_TYPE_128SRV_PART 0x06
#define ESP_BLE_AD_TYPE_128SRV_CMPL 0x07
#define ESP_BLE_AD_TYPE_NAME_SHORT 0x08
#define ESP_BLE_AD_TYPE_NAME_CMPL 0x09
#define ESP_BLE_AD_TYPE_TX_PWR 0x0A
#define ESP_BLE_AD_TYPE_DEV_CLASS 0x0D
#define ESP_BLE_AD_TYPE_SM_TK 0x10
#define ESP_BLE_AD_TYPE_SM_OOB_FLAG 0x11
#define ESP_BLE_AD_TYPE_INT_RANGE 0x12
#define ESP_BLE_AD_TYPE_SOL_SRV_UUID 0x14
#define ESP_BLE_AD_TYPE_128SOL_SRV_UUID 0x15
#define ESP_BLE_AD_TYPE_SERVICE_DATA 0x16
#define ESP_BLE_AD_TYPE_PUBLIC_TARGET 0x17
#define ESP_BLE_AD_TYPE_RANDOM_TARGET 0x18
#define ESP_BLE_AD_TYPE_APPEARANCE 0x19
#define ESP_BLE_AD_TYPE_ADV_INT 0x1A
#define ESP_BLE_AD_TYPE_32SOL_SRV_UUID 0x1B
#define ESP_BLE_AD_TYPE_32SERVICE_DATA 0x1C
#define ESP_BLE_AD_TYPE_128SERVICE_DATA 0x1D
#define ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE 0xFF
typedef uint32_t esp_gap_ble_event_t;
/// Advertising mode
typedef enum {
ADV_TYPE_IND = 0x00,
ADV_TYPE_DIRECT_IND_HIGH = 0x01,
ADV_TYPE_SCAN_IND = 0x02,
ADV_TYPE_NONCONN_IND = 0x03,
ADV_TYPE_DIRECT_IND_LOW = 0x04,
} esp_ble_adv_type_t;
typedef enum {
ADV_CHNL_37 = 0x01,
ADV_CHNL_38 = 0x02,
ADV_CHNL_39 = 0x03,
ADV_CHNL_ALL = 0x07,
} esp_ble_adv_channel_t;
typedef enum {
///Allow both scan and connection requests from anyone
ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY = 0x00,
///Allow both scan req from White List devices only and connection req from anyone
ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY,
///Allow both scan req from anyone and connection req from White List devices only
ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST,
///Allow scan and connection requests from White List devices only
ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST,
///Enumeration end value for advertising filter policy value check
} esp_ble_adv_filter_t;
typedef struct {
uint16_t adv_int_min;
uint16_t adv_int_max;
esp_ble_adv_type_t adv_type;
esp_ble_addr_type_t own_addr_type;
esp_bd_addr_t peer_addr;
esp_ble_addr_type_t peer_addr_type;
esp_ble_adv_channel_t channel_map;
esp_ble_adv_filter_t adv_filter_policy;
} esp_ble_adv_params_t;
typedef struct {
bool set_scan_rsp;
bool include_name;
bool include_txpower;
int min_interval;
int max_interval;
int appearance;
uint16_t manufacturer_len;
uint8_t *p_manufacturer_data;
uint16_t service_data_len;
uint8_t *p_service_data;
uint16_t service_uuid_len;
uint8_t *p_service_uuid;
uint8_t flag;
} esp_ble_adv_data_t;
/// Own BD address source of the device
typedef enum {
/// Public Address
ESP_PUBLIC_ADDR,
/// Provided random address
ESP_PROVIDED_RND_ADDR,
/// Provided static random address
ESP_GEN_STATIC_RND_ADDR,
/// Generated resolvable private random address
ESP_GEN_RSLV_ADDR,
/// Generated non-resolvable private random address
ESP_GEN_NON_RSLV_ADDR,
/// Provided Reconnection address
ESP_PROVIDED_RECON_ADDR,
} esp_ble_own_addr_src_t;
typedef enum {
BLE_SCAN_TYPE_PASSIVE = 0x0,
BLE_SCAN_TYPE_ACTIVE = 0x1,
} esp_ble_scan_type_t;
typedef enum {
BLE_SCAN_FILTER_ALLOW_ALL = 0x0,
BLE_SCAN_FILTER_ALLOW_ONLY_WLST = 0x1,
BLE_SCAN_FILTER_ALLOW_UND_RPA_DIR = 0x2,
BLE_SCAN_FILTER_ALLOW_WLIST_PRA_DIR = 0x3,
} esp_ble_scan_filter_t;
typedef struct {
esp_ble_scan_type_t scan_type;
esp_ble_addr_type_t own_addr_type;
esp_ble_scan_filter_t scan_filter_policy;
uint16_t scan_interval;
uint16_t scan_window;
} esp_ble_scan_params_t;
typedef struct {
esp_bd_addr_t bda;
uint16_t min_int;
uint16_t max_int;
uint16_t latency;
uint16_t timeout;
} esp_ble_conn_update_params_t;
typedef void (*esp_gap_ble_cb_t)(esp_gap_ble_event_t event, void *param);
typedef enum {
/* Search callback events */
ESP_GAP_SEARCH_INQ_RES_EVT = 0, /* Inquiry result for a peer device. */
ESP_GAP_SEARCH_INQ_CMPL_EVT = 1, /* Inquiry complete. */
ESP_GAP_SEARCH_DISC_RES_EVT = 2, /* Discovery result for a peer device. */
ESP_GAP_SEARCH_DISC_BLE_RES_EVT = 3, /* Discovery result for BLE GATT based servoce on a peer device. */
ESP_GAP_SEARCH_DISC_CMPL_EVT = 4, /* Discovery complete. */
ESP_GAP_SEARCH_DI_DISC_CMPL_EVT = 5, /* Discovery complete. */
ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT = 6, /* Search cancelled */
} esp_gap_search_evt_t;
typedef union {
//ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT 0
struct ble_adv_data_cmpl_evt_param {
esp_bt_status_t status;
} adv_data_cmpl;
//ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT 1
struct ble_scan_rsp_data_cmpl_evt_param {
esp_bt_status_t status;
} scan_rsp_data_cmpl;
//ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT 2
struct ble_scan_param_cmpl_evt_param {
esp_bt_status_t status;
} scan_param_cmpl;
//ESP_GAP_BLE_SCAN_RESULT_EVT 3
struct ble_scan_result_evt_param {
esp_gap_search_evt_t search_evt;
esp_bd_addr_t bda;
esp_bt_dev_type_t dev_type;
esp_ble_addr_type_t ble_addr_type;
int rssi;
uint8_t ble_adv[ESP_BLE_ADV_DATA_LEN_MAX]; /* received EIR */
int flag;
int num_resps;
} scan_rst;
} esp_ble_gap_cb_param_t;
/*******************************************************************************
**
** @function esp_ble_gap_register_callback
**
** @brief This function is called to occur gap event, such as scan result
**
** @param[in] callback: callback function
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gap_register_callback(esp_profile_cb_t callback);
/*******************************************************************************
**
** @function esp_ble_gap_config_adv_data
**
** @brief This function is called to override the BTA default ADV parameters.
**
** @param[in] adv_data: Pointer to User defined ADV data structure. This
** memory space can not be freed until p_adv_data_cback
** is received.
** @param[in|out] adv_data_cback: set adv data complete callback.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gap_config_adv_data (esp_ble_adv_data_t *adv_data);
/*******************************************************************************
**
** @function esp_ble_gap_set_scan_params
**
** @brief This function is called to set scan parameters
**
** @param[in] esp_ble_scan_params: Pointer to User defined scan_params data structure. This
** memory space can not be freed until scan_param_setup_cback
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params);
/*******************************************************************************
**
** @function esp_ble_gap_start_scanning
**
** @brief This procedure keep the device scanning the peer device whith advertising on the air
**
** @param[in] duration: Keeping the scaning time, the unit is second.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gap_start_scanning(uint32_t duration);
/*******************************************************************************
**
** @function esp_ble_gap_stop_scanning
**
** @brief This function call to stop the device scanning the peer device whith advertising on the air
** @param void
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gap_stop_scanning(void);
/*******************************************************************************
**
** @function esp_ble_gap_start_advertising
**
** @brief This function is called to start advertising.
**
** @param[in] esp_ble_adv_params_all_t: ointer to User defined adv_params data structure.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gap_start_advertising (esp_ble_adv_params_t *adv_params);
/*******************************************************************************
**
** @function esp_gap_ble_stop_advertising
**
** @brief This function is called to stop advertising.
**
** @param None
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gap_stop_advertising(void);
/*******************************************************************************
**
** @function esp_ble_update_conn_params
**
** @brief Update connection parameters, can only be used when connection is up.
**
** @param[in] param - connection update params
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params);
/*******************************************************************************
**
** @function esp_ble_gap_set_pkt_data_len
**
** @brief This function is to set maximum LE data packet size
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_data_length);
/*******************************************************************************
**
** @function esp_ble_gap_set_rand_addr
**
** @brief This function set the random address for the appliction
**
** @param[in] rand_addr: the random address whith should be setting
**
** @return ESP_OK - success, other - failed
**
**
*******************************************************************************/
esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr);
/*******************************************************************************
**
** @function esp_ble_gap_config_local_privacy
**
** @brief Enable/disable privacy on the local device
**
** @param[in] privacy_enable - enable/disabe privacy on remote device.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable);
/*******************************************************************************
**
** @function esp_ble_gap_set_device_name
**
** @brief Set device name to the local device
**
** @param[in] name - device name.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gap_set_device_name(char *name);
/*******************************************************************************
**
** @function esp_ble_resolve_adv_data
**
** @brief This function is called to get ADV data for a specific type.
**
** @param[in] p_adv - pointer of ADV data whitch to be resolved
** @param[in] type - finding ADV data type
** @param[out] p_length - return the length of ADV data not including type
**
** @return pointer of ADV data
**
*******************************************************************************/
uint8_t *esp_ble_resolve_adv_data( uint8_t *p_adv, uint8_t type, uint8_t *p_length );
#endif /* __ESP_GAP_BLE_API_H__ */

View file

@ -0,0 +1,31 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 __ESP_GAP_BT_API_H__
#define __ESP_GAP_BT_API_H__
#include <stdint.h>
#include "esp_err.h"
#include "esp_bt_defs.h"
typedef enum {
BT_SCAN_MODE_NONE = 0,
BT_SCAN_MODE_CONNECTABLE,
BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE
} bt_scan_mode_t;
esp_err_t esp_bt_gap_set_scan_mode(bt_scan_mode_t mode);
#endif /* __ESP_GAP_BT_API_H__ */

View file

@ -1,829 +0,0 @@
#ifndef __ESP_GATT_API_H__
#define __ESP_GATT_API_H__
#include "bt_types.h"
#include "esp_bt_defs.h"
#include "bta_gatt_api.h"
#include "bt_prf_sys.h"
/*******************************************************************************
**
** @function esp_ble_update_conn_params
**
** @brief Update connection parameters, can only be used when connection is up.
**
** @param[in] bd_addr - BD address of the peer
** @param[in] min_int - minimum connection interval, [0x0004~ 0x4000]
** @param[in] max_int - maximum connection interval, [0x0004~ 0x4000]
** @param[in] latency - slave latency [0 ~ 500]
** @param[in] timeout - supervision timeout [0x000a ~ 0xc80]
**
** @return None
**
*******************************************************************************/
void esp_ble_update_conn_params (BD_ADDR bd_addr, uint16_t min_int,
uint16_t max_int, uint16_t latency, uint16_t timeout);
/*******************************************************************************
**
** @function esp_ble_set_pkt_data_len
**
** @brief This function is to set maximum LE data packet size
**
** @return None
**
**
*******************************************************************************/
void esp_ble_set_pkt_data_len (BD_ADDR remote_device, uint16_t tx_data_length);
/*******************************************************************************
**
** @function esp_ble_set_rand_addr
**
** @brief This function set the random address for the appliction
**
** @param[in] rand_addr: the random address whith should be setting
**
** @return None
**
**
*******************************************************************************/
void esp_ble_set_rand_addr (BD_ADDR rand_addr);
/*******************************************************************************
**
** @function esp_ble_config_local_privacy
**
** @brief Enable/disable privacy on the local device
**
** @param[in] privacy_enable - enable/disabe privacy on remote device.
**
** @return None
**
*******************************************************************************/
void esp_ble_config_local_privacy (BOOLEAN privacy_enable);
/*******************************************************************************
** @function esp_gattc_disable
** @brief This function is called by application to disable GATTC module
**
** @param NULL
**
** @return None.
**
*******************************************************************************/
void esp_gattc_disable(void);
/*******************************************************************************
**
** @function esp_ble_gattc_app_register
**
** @brief This function is called to register application callbacks
** with GATTC module.
**
** @param[in] app_uuid - applicaiton UUID
** @param[in] client_cb - pointer to the application callback function.
**
** @return None
**
*******************************************************************************/
void esp_ble_gattc_app_register(esp_bt_uuid_t *app_uuid, esp_gattc_cb_t *client_cb);
/*******************************************************************************
**
** @function esp_ble_gattc_app_unregister
**
** @brief This function is called to unregister an application
** from GATTC module.
**
** @param[in] client_if - client interface identifier.
**
** @return None
**
*******************************************************************************/
void esp_ble_gattc_app_unregister(esp_gattc_if_t client_if);
/*******************************************************************************
**
** @function esp_ble_gattc_conn
**
** @brief Open a direct connection or add a background auto connection
** bd address
**
** @param[in] client_if: server interface.
** @param[in] remote_bda: remote device BD address.
** @param[in] is_direct: direct connection or background auto connection
**
** @return None
**
*******************************************************************************/
void esp_ble_gattc_conn(esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is_direct);
/*******************************************************************************
**
** @function esp_ble_gattc_cancel_conn
**
** @brief Cancel a direct open connection or remove a background auto connection
** bd address
**
** @param[in] client_if: server interface.
** @param[in] remote_bda: remote device BD address.
** @param[in] is_direct: direct connection or background auto connection
**
** @return None
**
*******************************************************************************/
void esp_ble_gattc_cancel_conn (esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is_direct);
/*******************************************************************************
**
** @function esp_ble_gattc_close
**
** @brief Close a connection to a GATT server.
**
** @param[in] conn_id: connectino ID to be closed.
**
** @return None
**
*******************************************************************************/
void esp_ble_gattc_close (uint16_t conn_id);
/*******************************************************************************
**
** @function esp_ble_gattc_config_mtu
**
** @brief Configure the MTU size in the GATT channel. This can be done
** only once per connection.
**
** @param[in] conn_id: connection ID.
** mtu: desired MTU size to use.
**
** @return Command status code:
** - @ref ESP_GATT_OK: If request succeeds
** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the mtu value invalid
**
*******************************************************************************/
esp_gatt_status_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu);
/*******************************************************************************
**
** @function esp_ble_gattc_svc_search_req
**
** @brief This function is called to request a GATT service discovery
** on a GATT server. This function report service search result
** by a callback event, and followed by a service search complete
** event.
**
** @param[in] conn_id: connection ID.
** @param[in] srvc_uuid: a UUID of the service application is interested in.
** If Null, discover for all services.
**
** @return None
**
*******************************************************************************/
void esp_ble_gattc_svc_search_req (uint16_t conn_id, esp_bt_uuid_t *srvc_uuid);
/****************************************************************************************************
**
** @function esp_ble_gattc_get_first_char
**
** @brief This function is called to find the first characteristic of the
** service on the given server.
**
** @param[in] conn_id: connection ID which identify the server.
** @param[in] srvc_id: the service ID of which the characteristic is belonged to.
** @param[in] char_uuid_cond: Characteristic UUID, if NULL find the first available
** characteristic.
** @param[in] char_result: output parameter which will store the GATT
** characteristic ID.
** @param[in] property: output parameter to carry the characteristic property.
**
** @return Command status code:
** - @ref ESP_GATT_OK: If request succeeds
** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or char_result parameter is NULL.
**
*****************************************************************************************************/
esp_gatt_status_t esp_ble_gattc_get_first_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id,
esp_bt_uuid_t *char_uuid_cond,
esp_gattc_char_id_t *char_result,
esp_gatt_char_prop_t *property);
/*******************************************************************************
**
** @function esp_ble_gattc_get_first_char_descr
**
** @brief This function is called to find the first characteristic descriptor of the
** characteristic on the given server.
**
** @param[in] conn_id: connection ID which identify the server.
** @param[in] char_id: the characteristic ID of which the descriptor is belonged to.
** @param[in] descr_uuid_cond: Characteristic Descr UUID, if NULL find the first available
** characteristic.
** @param[in] descr_result: output parameter which will store the GATT
** characteristic descriptor ID.
**
** @return Command status code:
** - @ref ESP_GATT_OK: If request succeeds
** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the char_id or descr_result parameter is NULL.
**
*******************************************************************************/
esp_gatt_status_t esp_ble_gattc_get_first_char_descr (uint16_t conn_id, esp_gattc_char_id_t *char_id,
esp_bt_uuid_t *descr_uuid_cond,
esp_gattc_char_descr_id_t *descr_result);
/*******************************************************************************
**
** @function esp_ble_gattc_get_next_inclu_srvc
**
** @brief This function is called to find the next included service of the
** service on the given server.
**
** @param[in] conn_id: connection ID which identify the server.
** @param[in] start_id: start the search from the next record
** after the one identified by p_start_id.
** @param[in] uuid_cond: Included service UUID, if NULL find the first available
** included service.
** @param[in] result: output parameter which will store the GATT ID
** of the included service found.
**
** @return Command status code:
** - @ref ESP_GATT_OK: If request succeeds
** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the p_char_id or p_descr_result parameter is NULL.
*******************************************************************************/
esp_gatt_status_t esp_ble_gattc_get_next_inclu_srvc (uint16_t conn_id,
esp_gattc_incl_srvc_id_t *start_id,
esp_bt_uuid_t *uuid_cond,
esp_gattc_incl_srvc_id_t *result);
/*******************************************************************************
**
** @function esp_ble_gattc_get_next_char
**
** @brief This function is called to find the next characteristic of the
** service on the given server.
**
** @param[in] conn_id: connection ID which identify the server.
** @param[in] start_char_id: start the characteristic search from the next record
** after the one identified by char_id.
** @param[in] char_uuid_cond: Characteristic UUID, if NULL find the first available
** characteristic.
** @param[in] char_result: output parameter which will store the GATT
** characteristic ID.
** @param[in] property: output parameter to carry the characteristic property.
**
** @return Command status code:
** - @ref ESP_GATT_OK: If request succeeds
** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the start_char_id or char_result parameter is NULL.
**
*******************************************************************************/
esp_gatt_status_t esp_ble_gattc_get_next_char (uint16_t conn_id,
esp_gattc_char_id_t *start_char_id,
esp_bt_uuid_t *char_uuid_cond,
esp_gattc_char_id_t *char_result,
esp_gatt_char_prop_t *property);
/*******************************************************************************
**
** @function esp_ble_gattc_get_next_char_descr
**
** @brief This function is called to find the next characteristic descriptor
** of the characterisctic.
**
** @param[in] conn_id: connection ID which identify the server.
** @param[in] start_descr_id: start the descriptor search from the next record
** after the one identified by p_start_descr_id.
** @param[in] descr_uuid_cond: Characteristic descriptor UUID, if NULL find
** the first available characteristic descriptor.
** @param[in] descr_result: output parameter which will store the GATT
** characteristic descriptor ID.
**
** @return Command status code:
** - @ref ESP_GATT_OK: If request succeeds
** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the start_descr_id or descr_result parameter is NULL.
**
*******************************************************************************/
esp_gatt_status_t esp_ble_gattc_get_next_char_descr (uint16_t conn_id,
esp_gattc_char_descr_id_t *start_descr_id,
esp_bt_uuid_t *descr_uuid_cond,
esp_gattc_char_descr_id_t *descr_result);
/*******************************************************************************
**
** @function esp_ble_gattc_get_first_inclu_srvc
**
** @brief This function is called to find the first included service of the
** service on the given server.
**
** @param[in] conn_id: connection ID which identify the server.
** @param[in] srvc_id: the service ID of which the characteristic is belonged to.
** @param[in] uuid_cond: Characteristic UUID, if NULL find the first available
** characteristic.
** @param[in] result: output parameter which will store the GATT ID
** of the included service found.
**
** @return Command status code:
** - @ref ESP_GATT_OK: If request succeeds
** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or result parameter is NULL.
**
*******************************************************************************/
esp_gatt_status_t esp_ble_gattc_get_first_inclu_srvc (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id,
esp_bt_uuid_t *uuid_cond, esp_gattc_incl_srvc_id_t *result);
/*******************************************************************************
**
** @function esp_ble_gattc_read_char
**
** @brief This function is called to read a service's characteristics of
** the given characteritisc ID.
**
** @param[in] conn_id - connectino ID.
** @param[in] char_id - characteritic ID to read.
**
** @return None
**
*******************************************************************************/
void esp_ble_gattc_read_char (uint16_t conn_id, esp_gattc_char_id_t *char_id,
esp_gatt_auth_req_t auth_req);
/*******************************************************************************
**
** @function esp_ble_gattc_read_char_descr
**
** @brief This function is called to read a characteristics descriptor.
**
** @param[in] conn_id - connection ID.
** @param[in] descr_id - characteritic descriptor ID to read.
**
** @return None
**
*******************************************************************************/
void esp_ble_gattc_read_char_descr (uint16_t conn_id,
esp_gattc_char_descr_id_t *descr_id,
esp_gatt_auth_req_t auth_req);
/*******************************************************************************
**
** @function esp_ble_gattc_read_multi
**
** @brief This function is called to read multiple characteristic or
** characteristic descriptors.
**
** @param[in] conn_id - connectino ID.
** @param[in] read_multi - pointer to the read multiple parameter.
**
** @return None
**
*******************************************************************************/
void esp_ble_gattc_read_multi (uint16_t conn_id, esp_gattc_multi_t *read_multi,
esp_gatt_auth_req_t auth_req);
/*******************************************************************************
**
** @function esp_ble_gattc_write_char_val
**
** @brief This function is called to write characteristic value.
**
** @param[in] conn_id - connection ID.
** @param[in] char_id - characteristic ID to write.
** @param[in] write_type - type of write.
** @param[in] len: length of the data to be written.
** @param[in] value - the value to be written.
**
** @return None
**
*******************************************************************************/
void esp_ble_gattc_write_char_val ( uint16_t conn_id,
esp_gattc_char_id_t *char_id,
esp_gattc_write_type_t write_type,
uint16_t len,
uint8_t *value,
esp_gatt_auth_req_t auth_req);
/*******************************************************************************
**
** @function esp_ble_gattc_write_char_descr
**
** @brief This function is called to write characteristic descriptor value.
**
** @param[in] conn_id - connection ID
** @param[in] char_descr_id - characteristic descriptor ID to write.
** @param[in] write_type - write type.
** @param[in] data - the value to be written.
**
** @return None
**
*******************************************************************************/
void esp_ble_gattc_write_char_descr (uint16_t conn_id,
esp_gattc_char_descr_id_t *char_descr_id,
esp_gattc_write_type_t write_type,
esp_gatt_unfmt_t *data,
esp_gatt_auth_req_t auth_req);
/*******************************************************************************
**
** @function esp_ble_gattc_prepa_write
**
** @brief This function is called to prepare write a characteristic value.
**
** @param[in] conn_id - connection ID.
** @param[in] char_id - GATT characteritic ID of the service.
** @param[in] offset - offset of the write value.
** @param[in] len: length of the data to be written.
** @param[in] value - the value to be written.
**
** @return None
**
*******************************************************************************/
void esp_ble_gattc_prepa_write (uint16_t conn_id, esp_gattc_char_id_t *char_id,
uint16_t offset, uint16_t len, uint8_t *value,
esp_gatt_auth_req_t auth_req);
/*******************************************************************************
**
** @function esp_ble_gattc_execu_write
**
** @brief This function is called to execute write a prepare write sequence.
**
** @param[in] conn_id - connection ID.
** @param[in] is_execute - execute or cancel.
**
** @return None
**
*******************************************************************************/
void esp_ble_gattc_execu_write (uint16_t conn_id, BOOLEAN is_execute);
/*******************************************************************************
**
** @function esp_ble_gattc_send_ind_cfm
**
** @brief This function is called to send handle value confirmation.
**
** @param[in] conn_id - connection ID.
** @param[in] char_id - characteristic ID to confirm.
**
** @return None
**
*******************************************************************************/
void esp_ble_gattc_send_ind_cfm (uint16_t conn_id, esp_gattc_char_id_t *char_id);
/*******************************************************************************
**
** @function esp_ble_gattc_register_ntf
**
** @brief This function is called to register for notification of a service.
**
** @param[in] client_if - client interface.
** @param[in] bda - target GATT server.
** @param[in] char_id - pointer to GATT characteristic ID.
**
** @return OK if registration succeed, otherwise failed.
**
*******************************************************************************/
esp_gatt_status_t esp_ble_gattc_register_ntf (esp_gattc_if_t client_if,
BD_ADDR bda,
esp_gattc_char_id_t *char_id);
/*******************************************************************************
**
** @function esp_ble_gattc_unregister_ntf
**
** @brief This function is called to de-register for notification of a service.
**
** @param[in] client_if - client interface.
** @param[in] bda - target GATT server.
** @param[in] char_id - pointer to GATT characteristic ID.
**
** @return OK if deregistration succeed, otherwise failed.
**
*******************************************************************************/
tBTA_GATT_STATUS esp_ble_gattc_unregister_ntf (esp_gattc_if_t client_if,
BD_ADDR bda,
esp_gattc_char_id_t *char_id);
/*******************************************************************************
**
** @function esp_ble_gatts_disale
**
** @brief This function is called to disable GATTS module
**
** @param[in] None.
**
** @return None
**
*******************************************************************************/
void esp_ble_gatts_disale(void);
/*******************************************************************************
**
** @function esp_ble_gatts_app_register
**
** @brief This function is called to register application callbacks
** with BTA GATTS module.
**
** @param[in] app_uuid - applicaiton UUID
** @param[in] cback - pointer to the application callback function.
**
** @return None
**
*******************************************************************************/
void esp_ble_gatts_app_register(esp_bt_uuid_t *app_uuid, esp_gatts_cb_t *cback);
/*******************************************************************************
**
** @function esp_ble_gatts_app_unregister
**
** @brief un-register with GATT Server.
**
** @param[in] server_if: service interface id.
**
** @return None
**
*******************************************************************************/
void esp_ble_gatts_app_unregister(esp_gatts_if_t server_if);
/*******************************************************************************
**
** @function esp_ble_gatts_create_srvc
**
** @brief Create a service. When service creation is done, a callback
** event BTA_GATTS_CREATE_SRVC_EVT is called to report status
** and service ID to the profile. The service ID obtained in
** the callback function needs to be used when adding included
** service and characteristics/descriptors into the service.
**
** @param[in] server_if: Profile ID this service is belonged to.
** @param[in] service_uuid: service UUID.
** @param[in] inst: instance ID number of this service.
** @param[in] num_handle: numble of handle requessted for this service.
** @param[in] is_primary: is this service a primary one or not.
**
** @return None
**
*******************************************************************************/
void esp_ble_gatts_create_srvc(esp_gatts_if_t server_if, esp_bt_uuid_t *service_uuid, uint8_t inst,
uint16_t num_handle, BOOLEAN is_primary);
/*******************************************************************************
**
** @function esp_ble_gatts_add_inclu_srvc
**
** @brief This function is called to add an included service. After included
** service is included, a callback event BTA_GATTS_ADD_INCL_SRVC_EVT
** is reported the included service ID.
**
** @param[in] service_id: service ID to which this included service is to
** be added.
** @param[in] included_service_id: the service ID to be included.
**
** @return None
**
*******************************************************************************/
void esp_ble_gatts_add_inclu_srvc (uint16_t service_id, uint16_t included_service_id);
/*******************************************************************************
**
** @function esp_ble_gatts_add_char
**
** @brief This function is called to add a characteristic into a service.
**
** @param[in] service_id: service ID to which this included service is to
** be added.
** @param[in] char_uuid : Characteristic UUID.
** @param[in] perm : Characteristic value declaration attribute permission.
** @param[in] property : Characteristic Properties
**
** @return None
**
*******************************************************************************/
void esp_ble_gatts_add_char (uint16_t service_id, esp_bt_uuid_t *char_uuid,
esp_gatt_perm_t perm, esp_gatt_char_prop_t property);
/*******************************************************************************
**
** @function esp_ble_gatts_add_char_descr
**
** @brief This function is called to add characteristic descriptor. When
** it's done, a callback event BTA_GATTS_ADD_DESCR_EVT is called
** to report the status and an ID number for this descriptor.
**
** @param[in] service_id: service ID to which this charatceristic descriptor is to
** be added.
** @param[in] perm: descriptor access permission.
** @param[in] descr_uuid: descriptor UUID.
**
** @return None
**
*******************************************************************************/
void esp_ble_gatts_add_char_descr (uint16_t service_id,
esp_gatt_perm_t perm,
esp_bt_uuid_t * descr_uuid);
/*******************************************************************************
**
** @function esp_ble_gatts_dele_srvc
**
** @brief This function is called to delete a service. When this is done,
** a callback event BTA_GATTS_DELETE_EVT is report with the status.
**
** @param[in] service_id: service_id to be deleted.
**
** @return None
**
*******************************************************************************/
void esp_ble_gatts_dele_srvc (uint16_t service_id);
/*******************************************************************************
**
** @function esp_ble_gatts_start_srvc
**
** @brief This function is called to start a service.
**
** @param[in] service_id: the service ID to be started.
** @param[in] sup_transport: supported trasnport.
**
** @return None
**
*******************************************************************************/
void esp_ble_gatts_start_srvc(uint16_t service_id);
/*******************************************************************************
**
** @function esp_ble_gatts_stop_srvc
**
** @brief This function is called to stop a service.
**
** @param[in] service_id - service to be topped.
**
** @return None
**
*******************************************************************************/
void esp_ble_gatts_stop_srvc(uint16_t service_id);
/*******************************************************************************
**
** @function esp_ble_gatts_hdl_val_indica
**
** @brief This function is called to read a characteristics descriptor.
**
** @param[in] bda - remote device bd address to indicate.
** @param[in] attr_id - attribute ID to indicate.
** @param[in] data_len - indicate data length.
** @param[in] data: data to indicate.
** @param[in] need_confirm - if this indication expects a confirmation or not.
**
** @return None
**
*******************************************************************************/
void esp_ble_gatts_hdl_val_indica (uint16_t conn_id, uint16_t attr_id, uint16_t data_len,
uint8_t *data, BOOLEAN need_confirm);
/*******************************************************************************
**
** @function esp_ble_gatts_send_rsp
**
** @brief This function is called to send a response to a request.
**
** @param[in] conn_id - connection identifier.
** @param[in] trans_id - transaction ID.
** @param[in] status - response status
** @param[in] msg - response data.
**
** @return None
**
*******************************************************************************/
void esp_ble_gatts_send_rsp (uint16_t conn_id, uint32_t trans_id,
esp_gatt_status_t status, esp_gatts_rsp_t *msg);
/*******************************************************************************
**
** @function esp_ble_gatts_conn
**
** @brief Open a direct open connection or add a background auto connection
** bd address
**
** @param[in] server_if: server interface.
** @param[in] remote_bda: remote device BD address.
** @param[in] is_direct: direct connection or background auto connection
**
** @return None
**
*******************************************************************************/
void esp_ble_gatts_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BOOLEAN is_direct);
/*******************************************************************************
**
** @function esp_ble_gatts_cancel_conn
**
** @brief Cancel a direct open connection or remove a background auto connection
** bd address
**
** @param[in] server_if: server interface.
** @param[in] remote_bda: remote device BD address.
** @param[in] is_direct: direct connection or background auto connection
**
** @return None
**
*******************************************************************************/
void esp_ble_gatts_cancel_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BOOLEAN is_direct);
/*******************************************************************************
**
** @function esp_ble_gatts_close
**
** @brief Close a connection a remote device.
**
** @param[in] conn_id: connectino ID to be closed.
**
** @return None
**
*******************************************************************************/
void esp_ble_gatts_close(uint16_t conn_id);
/*******************************************************************************
**
** @function esp_prf_app_register
**
** @brief This function is called to register application callbacks
** with BTA GATTS module.
**
** @param[in] prf_id - the profile identification
** @param[in] p_cback - pointer to the application callback function.
**
** @return None
**
*******************************************************************************/
void esp_prf_app_register(uint8_t prf_id, void *p_cback);
#endif /* __ESP_GATT_API_H__ */

View file

@ -0,0 +1,149 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 __ESP_GATT_DEFS_H__
#define __ESP_GATT_DEFS_H__
#include "esp_bt_defs.h"
/* attribute request data from the client */
#define ESP_GATT_PREP_WRITE_CANCEL 0x00
#define ESP_GATT_PREP_WRITE_EXEC 0x01
/* Success code and error codes */
typedef enum {
ESP_GATT_OK = 0x0,
ESP_GATT_INVALID_HANDLE = 0x01, /* 0x0001 */
ESP_GATT_READ_NOT_PERMIT = 0x02, /* 0x0002 */
ESP_GATT_WRITE_NOT_PERMIT = 0x03, /* 0x0003 */
ESP_GATT_INVALID_PDU = 0x04, /* 0x0004 */
ESP_GATT_INSUF_AUTHENTICATION = 0x05, /* 0x0005 */
ESP_GATT_REQ_NOT_SUPPORTED = 0x06, /* 0x0006 */
ESP_GATT_INVALID_OFFSET = 0x07, /* 0x0007 */
ESP_GATT_INSUF_AUTHORIZATION = 0x08, /* 0x0008 */
ESP_GATT_PREPARE_Q_FULL = 0x09, /* 0x0009 */
ESP_GATT_NOT_FOUND = 0x0a, /* 0x000a */
ESP_GATT_NOT_LONG = 0x0b, /* 0x000b */
ESP_GATT_INSUF_KEY_SIZE = 0x0c, /* 0x000c */
ESP_GATT_INVALID_ATTR_LEN = 0x0d, /* 0x000d */
ESP_GATT_ERR_UNLIKELY = 0x0e, /* 0x000e */
ESP_GATT_INSUF_ENCRYPTION = 0x0f, /* 0x000f */
ESP_GATT_UNSUPPORT_GRP_TYPE = 0x10, /* 0x0010 */
ESP_GATT_INSUF_RESOURCE = 0x11, /* 0x0011 */
ESP_GATT_NO_RESOURCES = 0x80, /* 0x80 */
ESP_GATT_INTERNAL_ERROR = 0x81, /* 0x81 */
ESP_GATT_WRONG_STATE = 0x82, /* 0x82 */
ESP_GATT_DB_FULL = 0x83, /* 0x83 */
ESP_GATT_BUSY = 0x84, /* 0x84 */
ESP_GATT_ERROR = 0x85, /* 0x85 */
ESP_GATT_CMD_STARTED = 0x86, /* 0x86 */
ESP_GATT_ILLEGAL_PARAMETER = 0x87, /* 0x87 */
ESP_GATT_PENDING = 0x88, /* 0x88 */
ESP_GATT_AUTH_FAIL = 0x89, /* 0x89 */
ESP_GATT_MORE = 0x8a, /* 0x8a */
ESP_GATT_INVALID_CFG = 0x8b, /* 0x8b */
ESP_GATT_SERVICE_STARTED = 0x8c, /* 0x8c */
ESP_GATT_ENCRYPED_MITM = ESP_GATT_OK,
ESP_GATT_ENCRYPED_NO_MITM = 0x8d, /* 0x8d */
ESP_GATT_NOT_ENCRYPTED = 0x8e, /* 0x8e */
ESP_GATT_CONGESTED = 0x8f, /* 0x8f */
ESP_GATT_DUP_REG = 0x90, /* 0x90 */
ESP_GATT_ALREADY_OPEN = 0x91, /* 0x91 */
ESP_GATT_CANCEL = 0x92, /* 0x92 */
/* 0xE0 ~ 0xFC reserved for future use */
ESP_GATT_CCC_CFG_ERR = 0xfd, /* 0xFD Client Characteristic Configuration Descriptor Improperly Configured */
ESP_GATT_PRC_IN_PROGRESS = 0xfe, /* 0xFE Procedure Already in progress */
ESP_GATT_OUT_OF_RANGE = 0xff, /* 0xFFAttribute value out of range */
} esp_gatt_status_t;
typedef enum {
ESP_GATT_CONN_UNKNOWN = 0,
ESP_GATT_CONN_L2C_FAILURE = 1, /* general L2cap failure */
ESP_GATT_CONN_TIMEOUT = 0x08, /* 0x08 connection timeout */
ESP_GATT_CONN_TERMINATE_PEER_USER = 0x13, /* 0x13 connection terminate by peer user */
ESP_GATT_CONN_TERMINATE_LOCAL_HOST = 0x16, /* 0x16 connectionterminated by local host */
ESP_GATT_CONN_FAIL_ESTABLISH = 0x3e, /* 0x03E connection fail to establish */
// ESP_GATT_CONN_LMP_TIMEOUT = 0x22, /* 0x22 connection fail for LMP response tout */
ESP_GATT_CONN_CONN_CANCEL = 0x0100, /* 0x0100 L2CAP connection cancelled */
ESP_GATT_CONN_NONE = 0x0101 /* 0x0101 no connection to cancel */
} esp_gatt_reason_t;
typedef struct {
esp_bt_uuid_t uuid;
uint8_t inst_id;
} __attribute__((packed)) esp_gatt_id_t;
typedef struct {
esp_gatt_id_t id;
bool is_primary;
} __attribute__((packed)) esp_gatt_srvc_id_t;
typedef enum {
AUTH_REQ_NO_SCATTERNET, /* Device doesn't support scatternet, it might
support "role switch during connection" for
an incoming connection, when it already has
another connection in master role */
AUTH_REQ_PARTIAL_SCATTERNET, /* Device supports partial scatternet. It can have
simulateous connection in Master and Slave roles
for short period of time */
AUTH_REQ_FULL_SCATTERNET /* Device can have simultaneous connection in master
and slave roles */
} esp_gatt_auth_req_t;
/* Attribute permissions
*/
typedef enum {
ESP_GATT_PERM_READ = (1 << 0), /* bit 0 - 0x0001 */
ESP_GATT_PERM_READ_ENCRYPTED = (1 << 1), /* bit 1 - 0x0002 */
ESP_GATT_PERM_READ_ENC_MITM = (1 << 2), /* bit 2 - 0x0004 */
ESP_GATT_PERM_WRITE = (1 << 4), /* bit 4 - 0x0010 */
ESP_GATT_PERM_WRITE_ENCRYPTED = (1 << 5), /* bit 5 - 0x0020 */
ESP_GATT_PERM_WRITE_ENC_MITM = (1 << 6), /* bit 6 - 0x0040 */
ESP_GATT_PERM_WRITE_SIGNED = (1 << 7), /* bit 7 - 0x0080 */
ESP_GATT_PERM_WRITE_SIGNED_MITM = (1 << 8), /* bit 8 - 0x0100 */
} esp_gatt_perm_t;
/* definition of characteristic properties */
typedef enum {
ESP_GATT_CHAR_PROP_BIT_BROADCAST = (1 << 0), /* 0x01 */
ESP_GATT_CHAR_PROP_BIT_READ = (1 << 1), /* 0x02 */
ESP_GATT_CHAR_PROP_BIT_WRITE_NR = (1 << 2), /* 0x04 */
ESP_GATT_CHAR_PROP_BIT_WRITE = (1 << 3), /* 0x08 */
ESP_GATT_CHAR_PROP_BIT_NOTIFY = (1 << 4), /* 0x10 */
ESP_GATT_CHAR_PROP_BIT_INDICATE = (1 << 5), /* 0x20 */
ESP_GATT_CHAR_PROP_BIT_AUTH = (1 << 6), /* 0x40 */
ESP_GATT_CHAR_PROP_BIT_EXT_PROP = (1 << 7), /* 0x80 */
} esp_gatt_char_prop_t;
#define ESP_GATT_MAX_ATTR_LEN 600 //as same as GATT_MAX_ATTR_LEN
typedef struct {
uint8_t value[ESP_GATT_MAX_ATTR_LEN];
uint16_t handle;
uint16_t offset;
uint16_t len;
uint8_t auth_req;
} esp_gatt_value_t;
/** GATT remote read request response type */
typedef union {
esp_gatt_value_t attr_value;
uint16_t handle;
} esp_gatt_rsp_t;
typedef uint32_t esp_gatt_if_t;
#endif /* __ESP_GATT_DEFS_H__ */

View file

@ -0,0 +1,554 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 __ESP_GATTC_API_H__
#define __ESP_GATTC_API_H__
#include "bt_types.h"
#include "esp_bt_defs.h"
#include "esp_gatt_defs.h"
#include "esp_err.h"
/* Client callback function events */
#define ESP_GATTC_REG_EVT 0 /* GATT client is registered. */
#define ESP_GATTC_UNREG_EVT 1 /* GATT client unregistered event */
#define ESP_GATTC_OPEN_EVT 2 /* GATTC open request status event */
#define ESP_GATTC_READ_CHAR_EVT 3 /* GATT read characteristic event */
#define ESP_GATTC_WRITE_CHAR_EVT 4 /* GATT write characteristic or char descriptor event */
#define ESP_GATTC_CLOSE_EVT 5 /* GATTC close request status event */
#define ESP_GATTC_SEARCH_CMPL_EVT 6 /* GATT discovery complete event */
#define ESP_GATTC_SEARCH_RES_EVT 7 /* GATT discovery result event */
#define ESP_GATTC_READ_DESCR_EVT 8 /* GATT read characterisitc descriptor event */
#define ESP_GATTC_WRITE_DESCR_EVT 9 /* GATT write characteristic descriptor event */
#define ESP_GATTC_NOTIFY_EVT 10 /* GATT attribute notification event */
#define ESP_GATTC_PREP_WRITE_EVT 11 /* GATT prepare write event */
#define ESP_GATTC_EXEC_EVT 12 /* execute write complete event */
#define ESP_GATTC_ACL_EVT 13 /* ACL up event */
#define ESP_GATTC_CANCEL_OPEN_EVT 14 /* cancel open event */
#define ESP_GATTC_SRVC_CHG_EVT 15 /* service change event */
#define ESP_GATTC_ENC_CMPL_CB_EVT 17 /* encryption complete callback event */
#define ESP_GATTC_CFG_MTU_EVT 18 /* configure MTU complete event */
#define ESP_GATTC_ADV_DATA_EVT 19 /* ADV data event */
#define ESP_GATTC_MULT_ADV_ENB_EVT 20 /* Enable Multi ADV event */
#define ESP_GATTC_MULT_ADV_UPD_EVT 21 /* Update parameter event */
#define ESP_GATTC_MULT_ADV_DATA_EVT 22 /* Multi ADV data event */
#define ESP_GATTC_MULT_ADV_DIS_EVT 23 /* Disable Multi ADV event */
#define ESP_GATTC_CONGEST_EVT 24 /* Congestion event */
#define ESP_GATTC_BTH_SCAN_ENB_EVT 25 /* Enable batch scan event */
#define ESP_GATTC_BTH_SCAN_CFG_EVT 26 /* Config storage event */
#define ESP_GATTC_BTH_SCAN_RD_EVT 27 /* Batch scan reports read event */
#define ESP_GATTC_BTH_SCAN_THR_EVT 28 /* Batch scan threshold event */
#define ESP_GATTC_BTH_SCAN_PARAM_EVT 29 /* Batch scan param event */
#define ESP_GATTC_BTH_SCAN_DIS_EVT 30 /* Disable batch scan event */
#define ESP_GATTC_SCAN_FLT_CFG_EVT 31 /* Scan filter config event */
#define ESP_GATTC_SCAN_FLT_PARAM_EVT 32 /* Param filter event */
#define ESP_GATTC_SCAN_FLT_STATUS_EVT 33 /* Filter status event */
#define ESP_GATTC_ADV_VSC_EVT 34 /* ADV VSC event */
#define ESP_GATTC_GET_CHAR_EVT 35 /* get characteristic event */
#define ESP_GATTC_GET_DESCR_EVT 36 /* get characteristic descriptor event */
#define ESP_GATTC_GET_INCL_SRVC_EVT 37 /* get included service event */
#define ESP_GATTC_REG_FOR_NOTIFY_EVT 38 /* register for notification event */
#define ESP_GATTC_UNREG_FOR_NOTIFY_EVT 39 /* unregister for notification event */
#define ESP_GATT_DEF_BLE_MTU_SIZE 23
#define ESP_GATT_MAX_MTU_SIZE 517
/* esp_ble_gattc_cb_param_t */
typedef union {
/*registration data for ESP_GATTC_REG_EVT */
struct gattc_reg_evt_param {
esp_gatt_status_t status;
esp_gatt_if_t gatt_if;
esp_bt_uuid_t uuid; /* btla-specific ++ */
} reg;
/* ESP_GATTC_OPEN_EVT */
struct gattc_open_evt_param {
esp_gatt_status_t status;
uint16_t conn_id;
esp_gatt_if_t gatt_if;
esp_bd_addr_t remote_bda;
// tBTA_TRANSPORT transport;
uint16_t mtu;
} open;
/* ESP_GATTC_CLOSE_EVT */
struct gattc_close_evt_param {
esp_gatt_status_t status;
uint16_t conn_id;
esp_gatt_if_t gatt_if;
esp_bd_addr_t remote_bda;
esp_gatt_reason_t reason;
} close;
/* ESP_GATTC_CFG_MTU_EVT */
struct gattc_cfg_mtu_evt_param {
uint16_t conn_id;
esp_gatt_status_t status;
uint16_t mtu;
} cfg_mtu;
/* ESP_GATTC_SEARCH_CMPL_EVT */
struct gattc_search_cmpl_evt_param {
uint16_t conn_id;
esp_gatt_status_t status;
} search_cmpl;
/* ESP_GATTC_SEARCH_RES_EVT */
struct gattc_search_res_evt_param {
uint16_t conn_id;
esp_gatt_srvc_id_t service_id;
} search_res;
/* ESP_GATTC_READ_CHAR_EVT, ESP_GATTC_READ_DESCR_EVT */
struct gattc_read_char_evt_param {
uint16_t conn_id;
esp_gatt_status_t status;
esp_gatt_srvc_id_t srvc_id;
esp_gatt_id_t char_id;
esp_gatt_id_t descr_id;
uint8_t *value;
uint16_t value_type;
uint16_t value_len;
} read; /* ESP_GATTC_READ_CHAR_EVT */
/* ESP_GATTC_WRITE_CHAR_EVT, ESP_GATTC_PREP_WRITE_EVT, ESP_GATTC_WRITE_DESCR_EVT */
struct gattc_write_evt_param {
uint16_t conn_id;
esp_gatt_status_t status;
esp_gatt_srvc_id_t srvc_id;
esp_gatt_id_t char_id;
esp_gatt_id_t descr_id;
} write;
/* ESP_GATTC_EXEC_EVT */
struct gattc_exec_cmpl_evt_param {
uint16_t conn_id;
esp_gatt_status_t status;
} exec_cmpl;
/* ESP_GATTC_NOTIF_EVT */
struct gattc_notify_evt_param {
uint16_t conn_id;
esp_bd_addr_t bda;
esp_gatt_srvc_id_t srvc_id;
esp_gatt_id_t char_id;
esp_gatt_id_t descr_id;
uint16_t value_len;
uint8_t *value;
bool is_notify;
} notify;
/* ESP_GATTC_SRVC_CHG_EVT*/
struct gattc_srvc_chg_evt_param {
esp_bd_addr_t remote_bda;
} srvc_chg;
/* ESP_GATTC_CONGEST_EVT */
struct gattc_congest_evt_param {
uint16_t conn_id;
bool congested;
} congest;
/* ESP_GATTC_GET_CHAR_EVT */
struct gattc_get_char_evt_param {
uint16_t conn_id;
esp_gatt_status_t status;
esp_gatt_srvc_id_t srvc_id;
esp_gatt_id_t char_id;
esp_gatt_char_prop_t char_prop;
} get_char;
/* ESP_GATTC_GET_DESCR_EVT */
struct gattc_get_descr_evt_param {
uint16_t conn_id;
esp_gatt_status_t status;
esp_gatt_srvc_id_t srvc_id;
esp_gatt_id_t char_id;
esp_gatt_id_t descr_id;
} get_descr;
/* ESP_GATTC_GET_INCL_SRVC_EVT */
struct gattc_get_incl_srvc_evt_param {
uint16_t conn_id;
esp_gatt_status_t status;
esp_gatt_srvc_id_t srvc_id;
esp_gatt_srvc_id_t incl_srvc_id;
} get_incl_srvc;
/* ESP_GATTC_REG_FOR_NOTIF_EVT, ESP_GATTC_UNREG_FOR_NOTIF_EVT */
struct gattc_reg_for_notify_evt_param {
esp_gatt_status_t status;
esp_gatt_srvc_id_t srvc_id;
esp_gatt_id_t char_id;
} reg_for_notify;
struct gattc_unreg_for_notify_evt_param {
esp_gatt_status_t status;
esp_gatt_srvc_id_t srvc_id;
esp_gatt_id_t char_id;
} unreg_for_notify;
} esp_ble_gattc_cb_param_t;
/*******************************************************************************
**
** @function esp_ble_gattc_app_register_callback
**
** @brief This function is called to register application callbacks
** with GATTC module.
**
** @param[in] callback - pointer to the application callback function.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_register_callback(esp_profile_cb_t callback);
/*******************************************************************************
**
** @function esp_ble_gattc_app_register
**
** @brief This function is called to register application callbacks
** with GATTC module.
**
** @param[in] app_id : Application Identitfy (UUID), for different application
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_app_register(uint16_t app_id);
/*******************************************************************************
**
** @function esp_ble_gattc_app_unregister
**
** @brief This function is called to unregister an application
** from GATTC module.
**
** @param[in] gatt_if - app identifier.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gatt_if);
/*******************************************************************************
**
** @function esp_ble_gattc_conn
**
** @brief Open a direct connection or add a background auto connection
** bd address
**
** @param[in] gatt_if: application identity.
** @param[in] remote_bda: remote device BD address.
** @param[in] is_direct: direct connection or background auto connection
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct);
/*******************************************************************************
**
** @function esp_ble_gattc_close
**
** @brief Close a connection to a GATT server.
**
** @param[in] conn_id: connectino ID to be closed.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_close (uint16_t conn_id);
/*******************************************************************************
**
** @function esp_ble_gattc_config_mtu
**
** @brief Configure the MTU size in the GATT channel. This can be done
** only once per connection.
**
** @param[in] conn_id: connection ID.
** mtu: desired MTU size to use.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu);
/*******************************************************************************
**
** @function esp_ble_gattc_search_service
**
** @brief This function is called to request a GATT service discovery
** on a GATT server. This function report service search result
** by a callback event, and followed by a service search complete
** event.
**
** @param[in] conn_id: connection ID.
** @param[in] filter_uuid: a UUID of the service application is interested in.
** If Null, discover for all services.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_uuid);
/****************************************************************************************************
**
** @function esp_ble_gattc_get_characteristic
**
** @brief This function is called to find the first characteristic of the
** service on the given server.
**
** @param[in] conn_id: connection ID which identify the server.
**
** @param[in] srvc_id: serivce ID
**
** @param[in] start_char_id: the start characteristic ID
**
** @return ESP_OK - success, other - failed
**
*****************************************************************************************************/
esp_err_t esp_ble_gattc_get_characteristic(uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id, esp_gatt_id_t *start_char_id);
/****************************************************************************************************
**
** @function esp_ble_gattc_get_descriptor
**
** @brief This function is called to find the descriptor of the
** service on the given server.
**
** @param[in] conn_id: connection ID which identify the server.
** @param[in] srvc_id: the service ID of which the characteristic is belonged to.
** @param[in] char_id: Characteristic ID, if NULL find the first available
** characteristic.
** @param[in] start_descr_id: the sctart descriptor id
**
** @return ESP_OK - success, other - failed
**
*****************************************************************************************************/
esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id, esp_gatt_id_t *char_id,
esp_gatt_id_t *start_descr_id);
/****************************************************************************************************
**
** @function esp_ble_gattc_get_include_service
**
** @brief This function is called to find the first characteristic of the
** service on the given server.
**
** @param[in] conn_id: connection ID which identify the server.
** @param[in] srvc_id: the service ID of which the characteristic is belonged to.
** @param[in] start_incl_srvc_id: the start include service id
**
** @return ESP_OK - success, other - failed
**
*****************************************************************************************************/
esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id, esp_gatt_srvc_id_t *start_incl_srvc_id);
/*******************************************************************************
**
** @function esp_ble_gattc_read_char
**
** @brief This function is called to read a service's characteristics of
** the given characteritisc ID.UTH_REQ_NO_SCATTERNET
**
** @param[in] conn_id - connectino ID.
** @param[in] srvc_id - serivcie ID.
** @param[in] char_id - characteritic ID to read.
** @param[in] auth_req - authenticate request type
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_read_char (uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
esp_gatt_auth_req_t auth_req);
/*******************************************************************************
**
** @function esp_ble_gattc_read_char_descr
**
** @brief This function is called to read a characteristics descriptor.
**
** @param[in] conn_id - connection ID.
** @param[in] srvc_id - serivcie ID.
** @param[in] descr_id - characteritic descriptor ID to read.
** @param[in] auth_req - authenticate request type
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_read_char_descr (uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
esp_gatt_id_t *descr_id,
esp_gatt_auth_req_t auth_req);
/*******************************************************************************
**
** @function esp_ble_gattc_write_char
**
** @brief This function is called to write characteristic value.
**
** @param[in] conn_id - connection ID.
** @param[in] srvc_id - serivcie ID.
** @param[in] char_id - characteristic ID to write.
** @param[in] value_len: length of the value to be written.
** @param[in] value - the value to be written.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
uint16_t value_len,
uint8_t *value,
esp_gatt_auth_req_t auth_req);
/*******************************************************************************
**
** @function esp_ble_gattc_write_char_descr
**
** @brief This function is called to write characteristic descriptor value.
**
** @param[in] conn_id - connection ID
** @param[in] srvc_id - serivcie ID.
** @param[in] char_id - characteristic ID.
** @param[in] descr_id - characteristic descriptor ID to write.
** @param[in] value_len: length of the value to be written.
** @param[in] value - the value to be written.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_write_char_descr (uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
esp_gatt_id_t *descr_id,
uint16_t value_len,
uint8_t *value,
esp_gatt_auth_req_t auth_req);
/*******************************************************************************
**
** @function esp_ble_gattc_prepare_write
**
** @brief This function is called to prepare write a characteristic value.
**
** @param[in] conn_id - connection ID.
** @param[in] char_id - GATT characteritic ID of the service.
** @param[in] offset - offset of the write value.
** @param[in] value_len: length of the value to be written.
** @param[in] value - the value to be written.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id,
uint16_t offset,
uint16_t value_len,
uint8_t *value,
esp_gatt_auth_req_t auth_req);
/*******************************************************************************
**
** @function esp_ble_gattc_execu_write
**
** @brief This function is called to execute write a prepare write sequence.
**
** @param[in] conn_id - connection ID.
** @param[in] is_execute - execute or cancel.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gattc_execute_write (uint16_t conn_id, bool is_execute);
/*******************************************************************************
**
** @function esp_ble_gattc_register_for_notify
**
** @brief This function is called to register for notification of a service.
**
** @param[in] gatt_if - gatt interface id.
** @param[in] bda - target GATT server.
** @param[in] srvc_id - pointer to GATT service ID.
** @param[in] char_id - pointer to GATT characteristic ID.
**
** @return OK if registration succeed, otherwise failed.
**
*******************************************************************************/
esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
esp_bd_addr_t server_bda,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id);
/*******************************************************************************
**
** @function esp_ble_gattc_unregister_ntf
**
** @brief This function is called to de-register for notification of a service.
**
** @param[in] gatt_if - gatt interface id.
** @param[in] bda - target GATT server.
** @param[in] srvc_id - pointer to GATT service ID.
** @param[in] char_id - pointer to GATT characteristic ID.
**
** @return OK if deregistration succeed, otherwise failed.
**
*******************************************************************************/
esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gatt_if,
esp_bd_addr_t server_bda,
esp_gatt_srvc_id_t *srvc_id,
esp_gatt_id_t *char_id);
#endif /* __ESP_GATTC_API_H__ */

View file

@ -0,0 +1,418 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 __ESP_GATTS_API_H__
#define __ESP_GATTS_API_H__
#include "bt_types.h"
#include "esp_bt_defs.h"
#include "esp_gatt_defs.h"
#include "bta_gatt_api.h"
#include "esp_err.h"
/* GATT Server Data Structure */
/* Server callback function events */
#define ESP_GATTS_REG_EVT 0
#define ESP_GATTS_READ_EVT 1
#define ESP_GATTS_WRITE_EVT 2
#define ESP_GATTS_EXEC_WRITE_EVT 3
#define ESP_GATTS_MTU_EVT 4
#define ESP_GATTS_CONF_EVT 5
#define ESP_GATTS_UNREG_EVT 6
#define ESP_GATTS_CREATE_EVT 7
#define ESP_GATTS_ADD_INCL_SRVC_EVT 8
#define ESP_GATTS_ADD_CHAR_EVT 9
#define ESP_GATTS_ADD_CHAR_DESCR_EVT 10
#define ESP_GATTS_DELELTE_EVT 11
#define ESP_GATTS_START_EVT 12
#define ESP_GATTS_STOP_EVT 13
#define ESP_GATTS_CONNECT_EVT 14
#define ESP_GATTS_DISCONNECT_EVT 15
#define ESP_GATTS_OPEN_EVT 16
#define ESP_GATTS_CANCEL_OPEN_EVT 17
#define ESP_GATTS_CLOSE_EVT 18
#define ESP_GATTS_LISTEN_EVT 19
#define ESP_GATTS_CONGEST_EVT 20
/* following is extra event */
#define ESP_GATTS_RESPONSE_EVT 21
/* esp_ble_gatts_cb_param_t */
typedef union {
//ESP_GATTS_REG_EVT
struct gatts_reg_evt_param {
int status;
uint16_t gatt_if;
uint16_t app_id;
} reg;
// param for ESP_GATTS_READ_EVT
struct gatts_read_evt_param {
uint16_t conn_id;
uint32_t trans_id;
esp_bd_addr_t bda;
uint16_t handle;
uint16_t offset;
bool is_long;
} read;
// param for ESP_GATTS_WRITE_EVT
struct gatts_write_evt_param {
uint16_t conn_id;
uint32_t trans_id;
esp_bd_addr_t bda;
uint16_t handle;
uint16_t offset;
bool need_rsp;
bool is_prep;
uint16_t len;
uint8_t *value;
} write;
// param for ESP_GATTS_EXEC_WRITE_EVT
struct gatts_exec_write_evt_param {
uint16_t conn_id;
uint32_t trans_id;
esp_bd_addr_t bda;
#define ESP_GATT_PREP_WRITE_CANCEL 0x00
#define ESP_GATT_PREP_WRITE_EXEC 0x01
uint8_t exec_write_flag;
} exec_write;
// param for ESP_GATTS_MTU_EVT
struct gatts_mtu_evt_param {
uint16_t conn_id;
uint16_t mtu;
} mtu;
// param for ESP_GATTS_CONF_EVT
struct gatts_conf_evt_param {
uint16_t conn_id;
int status;
} conf;
// param for ESP_GATTS_DEREG_EVT, NONE
// param for ESP_GATTS_CREATE_EVT
struct gatts_create_evt_param {
int status;
uint16_t gatt_if;
uint16_t service_handle; //handle
esp_gatt_srvc_id_t service_id; //id
} create;
// param for ESP_GATTS_ADD_INCL_SRVC_EVT
struct gatts_add_incl_srvc_evt_param {
int status;
uint16_t gatt_if;
uint16_t attr_handle; //handle
uint16_t service_handle; //handle
} add_incl_srvc;
// param for ESP_GATTS_ADD_CHAR_EVT
struct gatts_add_char_evt_param {
int status;
uint16_t gatt_if;
uint16_t attr_handle; //handle
uint16_t service_handle; //handle
esp_bt_uuid_t char_uuid;
} add_char;
// param for ESP_GATTS_ADD_CHAR_DESCR_EVT
struct gatts_add_char_descr_evt_param {
int status;
uint16_t gatt_if;
uint16_t attr_handle; //handle
uint16_t service_handle; //handle
esp_bt_uuid_t char_uuid;
} add_char_descr;
// param for ESP_GATTS_DELELTE_EVT
struct gatts_delete_evt_param {
int status;
uint16_t gatt_if;
uint16_t service_handle; //handle
} del;
// param for ESP_GATTS_START_EVT
struct gatts_start_evt_param {
int status;
uint16_t gatt_if;
uint16_t service_handle; //handle
} start;
// param for ESP_GATTS_STOP_EVT
struct gatts_stop_evt_param {
int status;
uint16_t gatt_if;
uint16_t service_handle; //handle
} stop;
// param for ESP_GATTS_CONNECT_EVT
struct gatts_connect_evt_param {
uint16_t conn_id;
uint16_t gatt_if;
esp_bd_addr_t remote_bda;
bool is_connected;
} connect;
// param for ESP_GATTS_DISCONNECT_EVT
struct gatts_disconnect_evt_param {
uint16_t conn_id;
uint16_t gatt_if;
esp_bd_addr_t remote_bda;
bool is_connected;
} disconnect;
// param for ESP_GATTS_OPEN_EVT none
// param for ESP_GATTS_CANCEL_OPEN_EVT none
// param for ESP_GATTS_CLOSE_EVT none
// param for ESP_GATTS_LISTEN_EVT none
// param for ESP_GATTS_CONGEST_EVT
struct gatts_congest_evt_param {
uint16_t conn_id;
bool congested;
} congest;
// param for ESP_GATTS_RESPONSE_EVT
struct gatts_rsp_evt_param {
int status; //response status, 0 is success
uint16_t handle; //attribute handle which send response
} rsp;
} esp_ble_gatts_cb_param_t;
/*******************************************************************************
**
** @function esp_ble_gatts_register_callback
**
** @brief This function is called to register application callbacks
** with BTA GATTS module.
**
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gatts_register_callback(esp_profile_cb_t callback);
/*******************************************************************************
**
** @function esp_ble_gatts_app_register
**
** @brief This function is called to register application identity
**
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gatts_app_register(uint16_t app_id);
/*******************************************************************************
**
** @function esp_ble_gatts_app_unregister
**
** @brief un-register with GATT Server.
**
** @param[in] gatt_if: gatt interface id.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatt_if);
/*******************************************************************************
**
** @function esp_ble_gatts_create_service
**
** @brief Create a service. When service creation is done, a callback
** event BTA_GATTS_CREATE_SRVC_EVT is called to report status
** and service ID to the profile. The service ID obtained in
** the callback function needs to be used when adding included
** service and characteristics/descriptors into the service.
**
** @param[in] gatt_if: gatt interface ID
** @param[in] service_id: service ID.
** @param[in] num_handle: numble of handle requessted for this service.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatt_if,
esp_gatt_srvc_id_t *service_id, uint16_t num_handle);
/*******************************************************************************
**
** @function esp_ble_gatts_add_include_service
**
** @brief This function is called to add an included service. After included
** service is included, a callback event BTA_GATTS_ADD_INCL_SRVC_EVT
** is reported the included service ID.
**
** @param[in] service_handle: service handle to which this included service is to
** be added.
** @param[in] included_service_handle: the service ID to be included.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gatts_add_include_service(uint16_t service_handle, uint16_t included_service_handle);
/*******************************************************************************
**
** @function esp_ble_gatts_add_char
**
** @brief This function is called to add a characteristic into a service.
**
** @param[in] service_handle: service handle to which this included service is to
** be added.
** @param[in] char_uuid : Characteristic UUID.
** @param[in] perm : Characteristic value declaration attribute permission.
** @param[in] property : Characteristic Properties
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gatts_add_char(uint16_t service_handle, esp_bt_uuid_t *char_uuid,
esp_gatt_perm_t perm, esp_gatt_char_prop_t property);
/*******************************************************************************
**
** @function esp_ble_gatts_add_char_descr
**
** @brief This function is called to add characteristic descriptor. When
** it's done, a callback event BTA_GATTS_ADD_DESCR_EVT is called
** to report the status and an ID number for this descriptor.
**
** @param[in] service_handle: service handle to which this charatceristic descriptor is to
** be added.
** @param[in] perm: descriptor access permission.
** @param[in] descr_uuid: descriptor UUID.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gatts_add_char_descr (uint16_t service_handle,
esp_bt_uuid_t *descr_uuid,
esp_gatt_perm_t perm);
/*******************************************************************************
**
** @function esp_ble_gatts_delete_service
**
** @brief This function is called to delete a service. When this is done,
** a callback event BTA_GATTS_DELETE_EVT is report with the status.
**
** @param[in] service_handled: service_handle to be deleted.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gatts_delete_service(uint16_t service_handle);
/*******************************************************************************
**
** @function esp_ble_gatts_start_service
**
** @brief This function is called to start a service.
**
** @param[in] service_handle: the service handle to be started.
** @param[in] sup_transport: supported trasnport.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gatts_start_service(uint16_t service_handle);
/*******************************************************************************
**
** @function esp_ble_gatts_stop_service
**
** @brief This function is called to stop a service.
**
** @param[in] service_handle - service to be topped.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gatts_stop_service(uint16_t service_handle);
/*******************************************************************************
**
** @function esp_ble_gatts_send_indicate
**
** @brief This function is called to read a characteristics descriptor.
**
** @param[in] conn_id - connection id to indicate.
** @param[in] attribute_handle - attribute handle to indicate.
** @param[in] value_len - indicate value length.
** @param[in] value: value to indicate.
** @param[in] need_confirm - if this indication expects a confirmation or not.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gatts_send_indicate(uint16_t conn_id, uint16_t attr_handle,
uint16_t value_len, uint8_t *value, bool need_confirm);
/*******************************************************************************
**
** @function esp_ble_gatts_send_rsp
**
** @brief This function is called to send a response to a request.
**
** @param[in] conn_id - connection identifier.
** @param[in] trans_id - transfe id
** @param[in] status - response status
** @param[in] rsp - response data.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gatts_send_response(uint16_t conn_id, uint32_t trans_id,
esp_gatt_status_t status, esp_gatt_rsp_t *rsp);
/*******************************************************************************
**
** @function esp_ble_gatts_open
**
** @brief Open a direct open connection or add a background auto connection
** bd address
**
** @param[in] gatt_if: application ID.
** @param[in] remote_bda: remote device BD address.
** @param[in] is_direct: direct connection or background auto connection
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct);
/*******************************************************************************
**
** @function esp_ble_gatts_close
**
** @brief Close a connection a remote device.
**
** @param[in] conn_id: connectino ID to be closed.
**
** @return ESP_OK - success, other - failed
**
*******************************************************************************/
esp_err_t esp_ble_gatts_close(uint16_t conn_id);
#endif /* __ESP_GATTS_API_H__ */

View file

@ -1,9 +1,23 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 __ESP_SDP_API_H__
#define __ESP_SDP_API_H__
#include <stdint.h>
#include "esp_err.h"
#include "esp_bt_common.h"
#include "esp_bt_defs.h"
#include "bta_sdp_api.h"
#include "bt_sdp.h"
@ -36,17 +50,16 @@ typedef struct {
} bt_sdp_search_comp_t;
/* tBTA_SDP, bta_sdp_api.h */
typedef union
{
typedef union {
bt_sdp_status_t status;
bt_sdp_search_comp_t sdp_search_comp;
} bt_sdp_t;
typedef void (bt_sdp_cb_t)(bt_sdp_evt_t event, bt_sdp_t *p_data, void * user_data);
typedef void (bt_sdp_cb_t)(bt_sdp_evt_t event, bt_sdp_t *p_data, void *user_data);
esp_err_t esp_bt_sdp_enable(bt_sdp_cb_t *cback);
esp_err_t esp_bt_sdp_search(esp_bd_addr_t bd_addr, esp_bt_uuid_t* uuid);
esp_err_t esp_bt_sdp_search(esp_bd_addr_t bd_addr, esp_bt_uuid_t *uuid);
esp_err_t esp_bt_sdp_create_record_by_user(void *user_data);
@ -69,8 +82,7 @@ typedef struct {
} sdp_proto_elem_t; // tSDP_PROTOCOL_ELEM, sdp_api.h
#define ESP_BT_SDP_MAX_LIST_ELEMS SDP_MAX_LIST_ELEMS // sdp_api.h
typedef struct
{
typedef struct {
uint16_t num_elems;
sdp_proto_elem_t list_elem[ESP_BT_SDP_MAX_LIST_ELEMS];
} sdp_proto_list_elem_t; // tSDP_PROTO_LIST_ELEM, sdp_api.h

View file

@ -1,3 +1,17 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 __ESP_SEC_API_H__
#define __ESP_SEC_API_H__
@ -7,28 +21,25 @@
#define RAND_NB_LEN 0x08
#define SEC_KEY_LEN 0x10
/*
/*
* STRUCTURES DEFINITIONS
****************************************************************************************
*/
/// Generic Security key structure
typedef struct
{
/// Generic Security key structure
typedef struct {
/// Key value MSB -> LSB
UINT8 key[SEC_KEY_LEN];
}smp_sec_key;
} smp_sec_key;
///Random number structure
typedef struct
{
///Random number structure
typedef struct {
///8-byte array for random number
UINT8 nb[RAND_NB_LEN];
}rand_nb;
} rand_nb;
typedef struct
{
typedef struct {
// LTK
smp_sec_key ltk;
// Random Number
@ -46,14 +57,14 @@ typedef struct
// authentication level
UINT8 auth;
}tAPP_SEC_ENV;
} tAPP_SEC_ENV;
extern tAPP_SEC_ENV app_sec_env;
extern tAPP_SEC_ENV app_sec_env;
/*
* GLOBAL FUNCTIONS DECLARATIONS
****************************************************************************************
*/
/*
* GLOBAL FUNCTIONS DECLARATIONS
****************************************************************************************
*/
void app_ble_sec_init(void);

1804
components/bt/bluedroid/bta/dm/bta_dm_act.c Executable file → Normal file

File diff suppressed because it is too large Load diff

345
components/bt/bluedroid/bta/dm/bta_dm_api.c Executable file → Normal file
View file

@ -36,14 +36,12 @@
** Constants
*****************************************************************************/
static const tBTA_SYS_REG bta_dm_reg =
{
static const tBTA_SYS_REG bta_dm_reg = {
bta_dm_sm_execute,
bta_dm_sm_disable
};
static const tBTA_SYS_REG bta_dm_search_reg =
{
static const tBTA_SYS_REG bta_dm_search_reg = {
bta_dm_search_sm_execute,
bta_dm_search_sm_disable
};
@ -65,8 +63,9 @@ tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback)
tBTA_DM_API_ENABLE *p_msg;
/* Bluetooth disabling is in progress */
if (bta_dm_cb.disabling)
if (bta_dm_cb.disabling) {
return BTA_FAILURE;
}
memset(&bta_dm_cb, 0, sizeof(bta_dm_cb));
@ -76,8 +75,7 @@ tBTA_STATUS BTA_EnableBluetooth(tBTA_DM_SEC_CBACK *p_cback)
/* if UUID list is not provided as static data */
bta_sys_eir_register(bta_dm_eir_update_uuid);
if ((p_msg = (tBTA_DM_API_ENABLE *) GKI_getbuf(sizeof(tBTA_DM_API_ENABLE))) != NULL)
{
if ((p_msg = (tBTA_DM_API_ENABLE *) GKI_getbuf(sizeof(tBTA_DM_API_ENABLE))) != NULL) {
p_msg->hdr.event = BTA_DM_API_ENABLE_EVT;
p_msg->p_sec_cback = p_cback;
bta_sys_sendmsg(p_msg);
@ -102,13 +100,10 @@ tBTA_STATUS BTA_DisableBluetooth(void)
BT_HDR *p_msg;
if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
{
if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
p_msg->event = BTA_DM_API_DISABLE_EVT;
bta_sys_sendmsg(p_msg);
}
else
{
} else {
return BTA_FAILURE;
}
@ -131,8 +126,7 @@ tBTA_STATUS BTA_EnableTestMode(void)
APPL_TRACE_API("BTA_EnableTestMode");
if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
{
if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
p_msg->event = BTA_DM_API_ENABLE_TEST_MODE_EVT;
bta_sys_sendmsg(p_msg);
return BTA_SUCCESS;
@ -156,8 +150,7 @@ void BTA_DisableTestMode(void)
APPL_TRACE_API("BTA_DisableTestMode");
if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
{
if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
p_msg->event = BTA_DM_API_DISABLE_TEST_MODE_EVT;
bta_sys_sendmsg(p_msg);
}
@ -178,12 +171,11 @@ void BTA_DmSetDeviceName(char *p_name)
tBTA_DM_API_SET_NAME *p_msg;
if ((p_msg = (tBTA_DM_API_SET_NAME *) GKI_getbuf(sizeof(tBTA_DM_API_SET_NAME))) != NULL)
{
if ((p_msg = (tBTA_DM_API_SET_NAME *) GKI_getbuf(sizeof(tBTA_DM_API_SET_NAME))) != NULL) {
p_msg->hdr.event = BTA_DM_API_SET_NAME_EVT;
/* truncate the name if needed */
BCM_STRNCPY_S((char*)p_msg->name, sizeof(p_msg->name), p_name, BD_NAME_LEN-1);
p_msg->name[BD_NAME_LEN-1]=0;
BCM_STRNCPY_S((char *)p_msg->name, sizeof(p_msg->name), p_name, BD_NAME_LEN - 1);
p_msg->name[BD_NAME_LEN - 1] = 0;
bta_sys_sendmsg(p_msg);
}
@ -207,8 +199,7 @@ void BTA_DmSetVisibility(tBTA_DM_DISC disc_mode, tBTA_DM_CONN conn_mode, UINT8 p
tBTA_DM_API_SET_VISIBILITY *p_msg;
if ((p_msg = (tBTA_DM_API_SET_VISIBILITY *) GKI_getbuf(sizeof(tBTA_DM_API_SET_VISIBILITY))) != NULL)
{
if ((p_msg = (tBTA_DM_API_SET_VISIBILITY *) GKI_getbuf(sizeof(tBTA_DM_API_SET_VISIBILITY))) != NULL) {
p_msg->hdr.event = BTA_DM_API_SET_VISIBILITY_EVT;
p_msg->disc_mode = disc_mode;
p_msg->conn_mode = conn_mode;
@ -239,8 +230,7 @@ void BTA_DmSearch(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK services, tBTA_DM_SEA
tBTA_DM_API_SEARCH *p_msg;
if ((p_msg = (tBTA_DM_API_SEARCH *) GKI_getbuf(sizeof(tBTA_DM_API_SEARCH))) != NULL)
{
if ((p_msg = (tBTA_DM_API_SEARCH *) GKI_getbuf(sizeof(tBTA_DM_API_SEARCH))) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_SEARCH));
p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
@ -268,8 +258,7 @@ void BTA_DmSearchCancel(void)
{
BT_HDR *p_msg;
if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
{
if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
p_msg->event = BTA_DM_API_SEARCH_CANCEL_EVT;
bta_sys_sendmsg(p_msg);
}
@ -292,8 +281,7 @@ void BTA_DmDiscover(BD_ADDR bd_addr, tBTA_SERVICE_MASK services,
{
tBTA_DM_API_DISCOVER *p_msg;
if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(sizeof(tBTA_DM_API_DISCOVER))) != NULL)
{
if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(sizeof(tBTA_DM_API_DISCOVER))) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_DISCOVER));
p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
@ -322,8 +310,7 @@ void BTA_DmDiscoverUUID(BD_ADDR bd_addr, tSDP_UUID *uuid,
{
tBTA_DM_API_DISCOVER *p_msg;
if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(sizeof(tBTA_DM_API_DISCOVER))) != NULL)
{
if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(sizeof(tBTA_DM_API_DISCOVER))) != NULL) {
p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
bdcpy(p_msg->bd_addr, bd_addr);
p_msg->services = BTA_USER_SERVICE_MASK; //Not exposed at API level
@ -356,8 +343,7 @@ void BTA_DmBond(BD_ADDR bd_addr)
tBTA_DM_API_BOND *p_msg;
p_msg = (tBTA_DM_API_BOND *) GKI_getbuf(sizeof(tBTA_DM_API_BOND));
if (p_msg != NULL)
{
if (p_msg != NULL) {
p_msg->hdr.event = BTA_DM_API_BOND_EVT;
bdcpy(p_msg->bd_addr, bd_addr);
p_msg->transport = BTA_TRANSPORT_UNKNOWN;
@ -380,8 +366,7 @@ void BTA_DmBondByTransport(BD_ADDR bd_addr, tBTA_TRANSPORT transport)
{
tBTA_DM_API_BOND *p_msg;
if ((p_msg = (tBTA_DM_API_BOND *) GKI_getbuf(sizeof(tBTA_DM_API_BOND))) != NULL)
{
if ((p_msg = (tBTA_DM_API_BOND *) GKI_getbuf(sizeof(tBTA_DM_API_BOND))) != NULL) {
p_msg->hdr.event = BTA_DM_API_BOND_EVT;
bdcpy(p_msg->bd_addr, bd_addr);
p_msg->transport = transport;
@ -406,8 +391,7 @@ void BTA_DmBondCancel(BD_ADDR bd_addr)
{
tBTA_DM_API_BOND_CANCEL *p_msg;
if ((p_msg = (tBTA_DM_API_BOND_CANCEL *) GKI_getbuf(sizeof(tBTA_DM_API_BOND_CANCEL))) != NULL)
{
if ((p_msg = (tBTA_DM_API_BOND_CANCEL *) GKI_getbuf(sizeof(tBTA_DM_API_BOND_CANCEL))) != NULL) {
p_msg->hdr.event = BTA_DM_API_BOND_CANCEL_EVT;
bdcpy(p_msg->bd_addr, bd_addr);
bta_sys_sendmsg(p_msg);
@ -432,13 +416,11 @@ void BTA_DmPinReply(BD_ADDR bd_addr, BOOLEAN accept, UINT8 pin_len, UINT8 *p_pin
{
tBTA_DM_API_PIN_REPLY *p_msg;
if ((p_msg = (tBTA_DM_API_PIN_REPLY *) GKI_getbuf(sizeof(tBTA_DM_API_PIN_REPLY))) != NULL)
{
if ((p_msg = (tBTA_DM_API_PIN_REPLY *) GKI_getbuf(sizeof(tBTA_DM_API_PIN_REPLY))) != NULL) {
p_msg->hdr.event = BTA_DM_API_PIN_REPLY_EVT;
bdcpy(p_msg->bd_addr, bd_addr);
p_msg->accept = accept;
if(accept)
{
if (accept) {
p_msg->pin_len = pin_len;
memcpy(p_msg->p_pin, p_pin, pin_len);
}
@ -465,8 +447,7 @@ void BTA_DmLocalOob(void)
{
tBTA_DM_API_LOC_OOB *p_msg;
if ((p_msg = (tBTA_DM_API_LOC_OOB *) GKI_getbuf(sizeof(tBTA_DM_API_LOC_OOB))) != NULL)
{
if ((p_msg = (tBTA_DM_API_LOC_OOB *) GKI_getbuf(sizeof(tBTA_DM_API_LOC_OOB))) != NULL) {
p_msg->hdr.event = BTA_DM_API_LOC_OOB_EVT;
bta_sys_sendmsg(p_msg);
}
@ -486,8 +467,7 @@ void BTA_DmConfirm(BD_ADDR bd_addr, BOOLEAN accept)
{
tBTA_DM_API_CONFIRM *p_msg;
if ((p_msg = (tBTA_DM_API_CONFIRM *) GKI_getbuf(sizeof(tBTA_DM_API_CONFIRM))) != NULL)
{
if ((p_msg = (tBTA_DM_API_CONFIRM *) GKI_getbuf(sizeof(tBTA_DM_API_CONFIRM))) != NULL) {
p_msg->hdr.event = BTA_DM_API_CONFIRM_EVT;
bdcpy(p_msg->bd_addr, bd_addr);
p_msg->accept = accept;
@ -513,8 +493,7 @@ void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key,
tBTA_DM_API_ADD_DEVICE *p_msg;
if ((p_msg = (tBTA_DM_API_ADD_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_DEVICE))) != NULL)
{
if ((p_msg = (tBTA_DM_API_ADD_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_DEVICE))) != NULL) {
memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_DEVICE));
p_msg->hdr.event = BTA_DM_API_ADD_DEVICE_EVT;
@ -523,16 +502,14 @@ void BTA_DmAddDevice(BD_ADDR bd_addr, DEV_CLASS dev_class, LINK_KEY link_key,
p_msg->is_trusted = is_trusted;
p_msg->io_cap = io_cap;
if (link_key)
{
if (link_key) {
p_msg->link_key_known = TRUE;
p_msg->key_type = key_type;
memcpy(p_msg->link_key, link_key, LINK_KEY_LEN);
}
/* Load device class if specified */
if (dev_class)
{
if (dev_class) {
p_msg->dc_known = TRUE;
memcpy (p_msg->dc, dev_class, DEV_CLASS_LEN);
}
@ -561,16 +538,13 @@ tBTA_STATUS BTA_DmRemoveDevice(BD_ADDR bd_addr)
{
tBTA_DM_API_REMOVE_DEVICE *p_msg;
if ((p_msg = (tBTA_DM_API_REMOVE_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_REMOVE_DEVICE))) != NULL)
{
if ((p_msg = (tBTA_DM_API_REMOVE_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_REMOVE_DEVICE))) != NULL) {
memset (p_msg, 0, sizeof(tBTA_DM_API_REMOVE_DEVICE));
p_msg->hdr.event = BTA_DM_API_REMOVE_DEVICE_EVT;
bdcpy(p_msg->bd_addr, bd_addr);
bta_sys_sendmsg(p_msg);
}
else
{
} else {
return BTA_FAILURE;
}
@ -594,18 +568,15 @@ void BTA_GetEirService( UINT8 *p_eir, tBTA_SERVICE_MASK *p_services )
{
UINT8 xx, yy;
UINT8 num_uuid, max_num_uuid = 32;
UINT8 uuid_list[32*LEN_UUID_16];
UINT8 uuid_list[32 * LEN_UUID_16];
UINT16 *p_uuid16 = (UINT16 *)uuid_list;
tBTA_SERVICE_MASK mask;
BTM_GetEirUuidList( p_eir, LEN_UUID_16, &num_uuid, uuid_list, max_num_uuid);
for( xx = 0; xx < num_uuid; xx++ )
{
for ( xx = 0; xx < num_uuid; xx++ ) {
mask = 1;
for( yy = 0; yy < BTA_MAX_SERVICE_ID; yy++ )
{
if( *(p_uuid16 + xx) == bta_service_id_to_uuid_lkup_tbl[yy] )
{
for ( yy = 0; yy < BTA_MAX_SERVICE_ID; yy++ ) {
if ( *(p_uuid16 + xx) == bta_service_id_to_uuid_lkup_tbl[yy] ) {
*p_services |= mask;
break;
}
@ -613,15 +584,18 @@ void BTA_GetEirService( UINT8 *p_eir, tBTA_SERVICE_MASK *p_services )
}
/* for HSP v1.2 only device */
if (*(p_uuid16 + xx) == UUID_SERVCLASS_HEADSET_HS)
if (*(p_uuid16 + xx) == UUID_SERVCLASS_HEADSET_HS) {
*p_services |= BTA_HSP_SERVICE_MASK;
}
if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SOURCE)
if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SOURCE) {
*p_services |= BTA_HL_SERVICE_MASK;
}
if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SINK)
if (*(p_uuid16 + xx) == UUID_SERVCLASS_HDP_SINK) {
*p_services |= BTA_HL_SERVICE_MASK;
}
}
}
/*******************************************************************************
@ -635,7 +609,7 @@ void BTA_GetEirService( UINT8 *p_eir, tBTA_SERVICE_MASK *p_services )
*******************************************************************************/
UINT16 BTA_DmGetConnectionState( BD_ADDR bd_addr )
{
tBTA_DM_PEER_DEVICE * p_dev = bta_dm_find_peer_device(bd_addr);
tBTA_DM_PEER_DEVICE *p_dev = bta_dm_find_peer_device(bd_addr);
return (p_dev && p_dev->conn_state == BTA_DM_CONNECTED);
}
@ -657,12 +631,9 @@ tBTA_STATUS BTA_DmSetLocalDiRecord( tBTA_DI_RECORD *p_device_info,
{
tBTA_STATUS status = BTA_FAILURE;
if(bta_dm_di_cb.di_num < BTA_DI_NUM_MAX)
{
if(SDP_SetLocalDiRecord((tSDP_DI_RECORD *)p_device_info, p_handle) == SDP_SUCCESS)
{
if(!p_device_info->primary_record)
{
if (bta_dm_di_cb.di_num < BTA_DI_NUM_MAX) {
if (SDP_SetLocalDiRecord((tSDP_DI_RECORD *)p_device_info, p_handle) == SDP_SUCCESS) {
if (!p_device_info->primary_record) {
bta_dm_di_cb.di_handle[bta_dm_di_cb.di_num] = *p_handle;
bta_dm_di_cb.di_num ++;
}
@ -686,15 +657,14 @@ tBTA_STATUS BTA_DmSetLocalDiRecord( tBTA_DI_RECORD *p_device_info,
** Returns void
**
*******************************************************************************/
void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK* p_callback, void * p_param)
void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK *p_callback, void *p_param)
{
tBTA_DM_API_EXECUTE_CBACK *p_msg;
if ((p_msg = (tBTA_DM_API_EXECUTE_CBACK *) GKI_getbuf(sizeof(tBTA_DM_API_EXECUTE_CBACK))) != NULL)
{
if ((p_msg = (tBTA_DM_API_EXECUTE_CBACK *) GKI_getbuf(sizeof(tBTA_DM_API_EXECUTE_CBACK))) != NULL) {
p_msg->hdr.event = BTA_DM_API_EXECUTE_CBACK_EVT;
p_msg->p_param= p_param;
p_msg->p_exec_cback= p_callback;
p_msg->p_param = p_param;
p_msg->p_exec_cback = p_callback;
bta_sys_sendmsg(p_msg);
}
}
@ -721,8 +691,7 @@ void BTA_DmAddBleKey (BD_ADDR bd_addr, tBTA_LE_KEY_VALUE *p_le_key, tBTA_LE_KEY_
tBTA_DM_API_ADD_BLEKEY *p_msg;
if ((p_msg = (tBTA_DM_API_ADD_BLEKEY *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_BLEKEY))) != NULL)
{
if ((p_msg = (tBTA_DM_API_ADD_BLEKEY *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_BLEKEY))) != NULL) {
memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_BLEKEY));
p_msg->hdr.event = BTA_DM_API_ADD_BLEKEY_EVT;
@ -756,8 +725,7 @@ void BTA_DmAddBleDevice(BD_ADDR bd_addr, tBLE_ADDR_TYPE addr_type, tBT_DEVICE_TY
#if BLE_INCLUDED == TRUE
tBTA_DM_API_ADD_BLE_DEVICE *p_msg;
if ((p_msg = (tBTA_DM_API_ADD_BLE_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_BLE_DEVICE))) != NULL)
{
if ((p_msg = (tBTA_DM_API_ADD_BLE_DEVICE *) GKI_getbuf(sizeof(tBTA_DM_API_ADD_BLE_DEVICE))) != NULL) {
memset (p_msg, 0, sizeof(tBTA_DM_API_ADD_BLE_DEVICE));
p_msg->hdr.event = BTA_DM_API_ADD_BLEDEVICE_EVT;
@ -788,16 +756,14 @@ void BTA_DmBlePasskeyReply(BD_ADDR bd_addr, BOOLEAN accept, UINT32 passkey)
#if BLE_INCLUDED == TRUE
tBTA_DM_API_PASSKEY_REPLY *p_msg;
if ((p_msg = (tBTA_DM_API_PASSKEY_REPLY *) GKI_getbuf(sizeof(tBTA_DM_API_PASSKEY_REPLY))) != NULL)
{
if ((p_msg = (tBTA_DM_API_PASSKEY_REPLY *) GKI_getbuf(sizeof(tBTA_DM_API_PASSKEY_REPLY))) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_PASSKEY_REPLY));
p_msg->hdr.event = BTA_DM_API_BLE_PASSKEY_REPLY_EVT;
bdcpy(p_msg->bd_addr, bd_addr);
p_msg->accept = accept;
if(accept)
{
if (accept) {
p_msg->passkey = passkey;
}
bta_sys_sendmsg(p_msg);
@ -820,8 +786,7 @@ void BTA_DmBleConfirmReply(BD_ADDR bd_addr, BOOLEAN accept)
{
#if BLE_INCLUDED == TRUE
tBTA_DM_API_CONFIRM *p_msg = (tBTA_DM_API_CONFIRM *)GKI_getbuf(sizeof(tBTA_DM_API_CONFIRM));
if (p_msg != NULL)
{
if (p_msg != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_CONFIRM));
p_msg->hdr.event = BTA_DM_API_BLE_CONFIRM_REPLY_EVT;
bdcpy(p_msg->bd_addr, bd_addr);
@ -848,8 +813,7 @@ void BTA_DmBleSecurityGrant(BD_ADDR bd_addr, tBTA_DM_BLE_SEC_GRANT res)
#if BLE_INCLUDED == TRUE
tBTA_DM_API_BLE_SEC_GRANT *p_msg;
if ((p_msg = (tBTA_DM_API_BLE_SEC_GRANT *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_SEC_GRANT))) != NULL)
{
if ((p_msg = (tBTA_DM_API_BLE_SEC_GRANT *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_SEC_GRANT))) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SEC_GRANT));
p_msg->hdr.event = BTA_DM_API_BLE_SEC_GRANT_EVT;
@ -888,8 +852,7 @@ void BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr,
#if BLE_INCLUDED == TRUE
tBTA_DM_API_BLE_CONN_PARAMS *p_msg;
if ((p_msg = (tBTA_DM_API_BLE_CONN_PARAMS *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_CONN_PARAMS))) != NULL)
{
if ((p_msg = (tBTA_DM_API_BLE_CONN_PARAMS *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_CONN_PARAMS))) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_CONN_PARAMS));
p_msg->hdr.event = BTA_DM_API_BLE_CONN_PARAM_EVT;
@ -922,8 +885,7 @@ void BTA_DmSetBlePrefConnParams(BD_ADDR bd_addr,
void BTA_DmSetBleConnScanParams(UINT32 scan_interval, UINT32 scan_window)
{
tBTA_DM_API_BLE_SCAN_PARAMS *p_msg;
if ((p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS *)GKI_getbuf(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS))) != NULL)
{
if ((p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS *)GKI_getbuf(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS))) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
p_msg->hdr.event = BTA_DM_API_BLE_CONN_SCAN_PARAM_EVT;
p_msg->scan_int = scan_interval;
@ -953,8 +915,7 @@ void BTA_DmSetBleScanParams(tGATT_IF client_if, UINT32 scan_interval,
{
tBTA_DM_API_BLE_SCAN_PARAMS *p_msg;
if ((p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS *)GKI_getbuf(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS))) != NULL)
{
if ((p_msg = (tBTA_DM_API_BLE_SCAN_PARAMS *)GKI_getbuf(sizeof(tBTA_DM_API_BLE_SCAN_PARAMS))) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_PARAMS));
p_msg->hdr.event = BTA_DM_API_BLE_SCAN_PARAM_EVT;
p_msg->client_if = client_if;
@ -989,8 +950,7 @@ void BTA_DmSetBleScanFilterParams(tGATT_IF client_if, UINT32 scan_interval,
{
tBTA_DM_API_BLE_SCAN_FILTER_PARAMS *p_msg;
if ((p_msg = (tBTA_DM_API_BLE_SCAN_FILTER_PARAMS *)GKI_getbuf(sizeof(tBTA_DM_API_BLE_SCAN_FILTER_PARAMS))) != NULL)
{
if ((p_msg = (tBTA_DM_API_BLE_SCAN_FILTER_PARAMS *)GKI_getbuf(sizeof(tBTA_DM_API_BLE_SCAN_FILTER_PARAMS))) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SCAN_FILTER_PARAMS));
p_msg->hdr.event = BTA_DM_API_BLE_SCAN_FIL_PARAM_EVT;
p_msg->client_if = client_if;
@ -1000,6 +960,8 @@ void BTA_DmSetBleScanFilterParams(tGATT_IF client_if, UINT32 scan_interval,
p_msg->addr_type_own = addr_type_own;
p_msg->scan_filter_policy = scan_fil_poilcy;
p_msg->scan_param_setup_cback = scan_param_setup_cback;
bta_sys_sendmsg(p_msg);
}
@ -1026,17 +988,15 @@ void BTA_DmSetBleAdvParams (UINT16 adv_int_min, UINT16 adv_int_max,
APPL_TRACE_API ("BTA_DmSetBleAdvParam: %d, %d\n", adv_int_min, adv_int_max);
if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_ADV_PARAMS)
+ sizeof(tBLE_BD_ADDR))) != NULL)
{
memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS)+sizeof(tBLE_BD_ADDR));
+ sizeof(tBLE_BD_ADDR))) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS) + sizeof(tBLE_BD_ADDR));
p_msg->hdr.event = BTA_DM_API_BLE_ADV_PARAM_EVT;
p_msg->adv_int_min = adv_int_min;
p_msg->adv_int_max = adv_int_max;
if (p_dir_bda != NULL)
{
if (p_dir_bda != NULL) {
p_msg->p_dir_bda = (tBLE_BD_ADDR *)(p_msg + 1);
memcpy(p_msg->p_dir_bda, p_dir_bda, sizeof(tBLE_BD_ADDR));
}
@ -1056,10 +1016,9 @@ void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max,
APPL_TRACE_ERROR ("BTA_DmSetBleAdvParamsAll: %d, %d\n", adv_int_min, adv_int_max);
APPL_TRACE_ERROR ("adv_type = %d, addr_type_own = %d, chnl_map = %d, adv_fil_pol = %d\n",
adv_type,addr_type_own,chnl_map,adv_fil_pol);
adv_type, addr_type_own, chnl_map, adv_fil_pol);
if ((p_msg = (tBTA_DM_API_BLE_ADV_PARAMS_ALL *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL)
+ sizeof(tBLE_BD_ADDR))) != NULL)
{
+ sizeof(tBLE_BD_ADDR))) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_ADV_PARAMS_ALL));
p_msg->hdr.event = BTA_DM_API_BLE_ADV_PARAM_All_EVT;
@ -1070,8 +1029,7 @@ void BTA_DmSetBleAdvParamsAll (UINT16 adv_int_min, UINT16 adv_int_max,
p_msg->addr_type_own = addr_type_own;
p_msg->channel_map = chnl_map;
p_msg->adv_filter_policy = adv_fil_pol;
if (p_dir_bda != NULL)
{
if (p_dir_bda != NULL) {
p_msg->p_dir_bda = (tBLE_BD_ADDR *)(p_msg + 1);
memcpy(p_msg->p_dir_bda, p_dir_bda, sizeof(tBLE_BD_ADDR));
}
@ -1109,8 +1067,7 @@ void BTA_DmBleSetAdvConfig (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *p_adv
tBTA_DM_API_SET_ADV_CONFIG *p_msg;
if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG *)
GKI_getbuf(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL)
{
GKI_getbuf(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL) {
p_msg->hdr.event = BTA_DM_API_BLE_SET_ADV_CONFIG_EVT;
p_msg->data_mask = data_mask;
p_msg->p_adv_data_cback = p_adv_data_cback;
@ -1137,8 +1094,7 @@ extern void BTA_DmBleSetScanRsp (tBTA_BLE_AD_MASK data_mask, tBTA_BLE_ADV_DATA *
tBTA_DM_API_SET_ADV_CONFIG *p_msg;
if ((p_msg = (tBTA_DM_API_SET_ADV_CONFIG *)
GKI_getbuf(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL)
{
GKI_getbuf(sizeof(tBTA_DM_API_SET_ADV_CONFIG))) != NULL) {
p_msg->hdr.event = BTA_DM_API_BLE_SET_SCAN_RSP_EVT;
p_msg->data_mask = data_mask;
p_msg->p_adv_data_cback = p_adv_data_cback;
@ -1170,18 +1126,17 @@ extern void BTA_DmBleSetStorageParams(UINT8 batch_scan_full_max,
UINT8 batch_scan_notify_threshold,
tBTA_BLE_SCAN_SETUP_CBACK *p_setup_cback,
tBTA_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback,
tBTA_BLE_SCAN_REP_CBACK* p_rep_cback,
tBTA_BLE_SCAN_REP_CBACK *p_rep_cback,
tBTA_DM_BLE_REF_VALUE ref_value)
{
tBTA_DM_API_SET_STORAGE_CONFIG *p_msg;
bta_dm_cb.p_setup_cback = p_setup_cback;
if ((p_msg = (tBTA_DM_API_SET_STORAGE_CONFIG *)
GKI_getbuf(sizeof(tBTA_DM_API_SET_STORAGE_CONFIG))) != NULL)
{
GKI_getbuf(sizeof(tBTA_DM_API_SET_STORAGE_CONFIG))) != NULL) {
p_msg->hdr.event = BTA_DM_API_BLE_SETUP_STORAGE_EVT;
p_msg->p_setup_cback=bta_ble_scan_setup_cb;
p_msg->p_thres_cback=p_thres_cback;
p_msg->p_read_rep_cback=p_rep_cback;
p_msg->p_setup_cback = bta_ble_scan_setup_cb;
p_msg->p_thres_cback = p_thres_cback;
p_msg->p_read_rep_cback = p_rep_cback;
p_msg->ref_value = ref_value;
p_msg->batch_scan_full_max = batch_scan_full_max;
p_msg->batch_scan_trunc_max = batch_scan_trunc_max;
@ -1214,8 +1169,7 @@ extern void BTA_DmBleEnableBatchScan(tBTA_BLE_BATCH_SCAN_MODE scan_mode,
{
tBTA_DM_API_ENABLE_SCAN *p_msg;
if ((p_msg = (tBTA_DM_API_ENABLE_SCAN *) GKI_getbuf(sizeof(tBTA_DM_API_ENABLE_SCAN))) != NULL)
{
if ((p_msg = (tBTA_DM_API_ENABLE_SCAN *) GKI_getbuf(sizeof(tBTA_DM_API_ENABLE_SCAN))) != NULL) {
p_msg->hdr.event = BTA_DM_API_BLE_ENABLE_BATCH_SCAN_EVT;
p_msg->scan_mode = scan_mode;
p_msg->scan_int = scan_interval;
@ -1243,8 +1197,7 @@ extern void BTA_DmBleDisableBatchScan(tBTA_DM_BLE_REF_VALUE ref_value)
tBTA_DM_API_DISABLE_SCAN *p_msg;
if ((p_msg = (tBTA_DM_API_DISABLE_SCAN *)
GKI_getbuf(sizeof(tBTA_DM_API_DISABLE_SCAN))) != NULL)
{
GKI_getbuf(sizeof(tBTA_DM_API_DISABLE_SCAN))) != NULL) {
p_msg->hdr.event = BTA_DM_API_BLE_DISABLE_BATCH_SCAN_EVT;
p_msg->ref_value = ref_value;
bta_sys_sendmsg(p_msg);
@ -1269,8 +1222,7 @@ extern void BTA_DmBleReadScanReports(tBTA_BLE_BATCH_SCAN_MODE scan_type,
tBTA_DM_API_READ_SCAN_REPORTS *p_msg;
if ((p_msg = (tBTA_DM_API_READ_SCAN_REPORTS *)
GKI_getbuf(sizeof(tBTA_DM_API_READ_SCAN_REPORTS))) != NULL)
{
GKI_getbuf(sizeof(tBTA_DM_API_READ_SCAN_REPORTS))) != NULL) {
p_msg->hdr.event = BTA_DM_API_BLE_READ_SCAN_REPORTS_EVT;
p_msg->scan_type = scan_type;
p_msg->ref_value = ref_value;
@ -1296,8 +1248,7 @@ extern void BTA_DmBleTrackAdvertiser(tBTA_DM_BLE_REF_VALUE ref_value,
tBTA_DM_API_TRACK_ADVERTISER *p_msg;
if ((p_msg = (tBTA_DM_API_TRACK_ADVERTISER *)
GKI_getbuf(sizeof(tBTA_DM_API_TRACK_ADVERTISER))) != NULL)
{
GKI_getbuf(sizeof(tBTA_DM_API_TRACK_ADVERTISER))) != NULL) {
p_msg->hdr.event = BTA_DM_API_BLE_TRACK_ADVERTISER_EVT;
p_msg->p_track_adv_cback = p_track_adv_cback;
p_msg->ref_value = ref_value;
@ -1329,8 +1280,7 @@ extern void BTA_DmBleBroadcast (BOOLEAN start)
APPL_TRACE_API("BTA_DmBleBroadcast: start = %d \n", start);
if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL)
{
if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_OBSERVE));
p_msg->hdr.event = BTA_DM_API_BLE_BROADCAST_EVT;
@ -1360,8 +1310,7 @@ void BTA_DmBleSetBgConnType(tBTA_DM_BLE_CONN_TYPE bg_conn_type, tBTA_DM_BLE_SEL_
#if BLE_INCLUDED == TRUE
tBTA_DM_API_BLE_SET_BG_CONN_TYPE *p_msg;
if ((p_msg = (tBTA_DM_API_BLE_SET_BG_CONN_TYPE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE))) != NULL)
{
if ((p_msg = (tBTA_DM_API_BLE_SET_BG_CONN_TYPE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE))) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_SET_BG_CONN_TYPE));
p_msg->hdr.event = BTA_DM_API_BLE_SET_BG_CONN_TYPE;
@ -1392,8 +1341,7 @@ static void bta_dm_discover_send_msg(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_s
sizeof(tBT_UUID) * p_services->num_uuid) :
sizeof(tBTA_DM_API_DISCOVER);
if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(len)) != NULL)
{
if ((p_msg = (tBTA_DM_API_DISCOVER *) GKI_getbuf(len)) != NULL) {
memset(p_msg, 0, len);
p_msg->hdr.event = BTA_DM_API_DISCOVER_EVT;
@ -1402,13 +1350,11 @@ static void bta_dm_discover_send_msg(BD_ADDR bd_addr, tBTA_SERVICE_MASK_EXT *p_s
p_msg->sdp_search = sdp_search;
p_msg->transport = transport;
if (p_services != NULL)
{
if (p_services != NULL) {
#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
p_msg->services = p_services->srvc_mask;
p_msg->num_uuid = p_services->num_uuid;
if (p_services->num_uuid != 0)
{
if (p_services->num_uuid != 0) {
p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
memcpy(p_msg->p_uuid, p_services->p_uuid, sizeof(tBT_UUID) * p_services->num_uuid);
}
@ -1495,8 +1441,7 @@ void BTA_DmSearchExt(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK_EXT *p_services, t
UINT16 len = p_services ? (sizeof(tBTA_DM_API_SEARCH) + sizeof(tBT_UUID) * p_services->num_uuid) :
sizeof(tBTA_DM_API_SEARCH);
if ((p_msg = (tBTA_DM_API_SEARCH *) GKI_getbuf(len)) != NULL)
{
if ((p_msg = (tBTA_DM_API_SEARCH *) GKI_getbuf(len)) != NULL) {
memset(p_msg, 0, len);
p_msg->hdr.event = BTA_DM_API_SEARCH_EVT;
@ -1505,19 +1450,17 @@ void BTA_DmSearchExt(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK_EXT *p_services, t
p_msg->rs_res = BTA_DM_RS_NONE;
if (p_services != NULL)
{
if (p_services != NULL) {
p_msg->services = p_services->srvc_mask;
p_msg->num_uuid = p_services->num_uuid;
if (p_services->num_uuid != 0)
{
if (p_services->num_uuid != 0) {
p_msg->p_uuid = (tBT_UUID *)(p_msg + 1);
memcpy(p_msg->p_uuid, p_services->p_uuid, sizeof(tBT_UUID) * p_services->num_uuid);
}
else
} else {
p_msg->p_uuid = NULL;
}
}
bta_sys_sendmsg(p_msg);
}
@ -1550,8 +1493,7 @@ void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, UINT16 min_int,
tBTA_DM_API_UPDATE_CONN_PARAM *p_msg;
p_msg = (tBTA_DM_API_UPDATE_CONN_PARAM *) GKI_getbuf(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
if (p_msg != NULL)
{
if (p_msg != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
@ -1577,12 +1519,12 @@ void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, UINT16 min_int,
**
*******************************************************************************/
void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable)
{ ///This function used the irk to generate the resolve address
{
///This function used the irk to generate the resolve address
#if BLE_INCLUDED == TRUE && BLE_PRIVACY_SPT == TRUE
tBTA_DM_API_LOCAL_PRIVACY *p_msg;
if ((p_msg = (tBTA_DM_API_LOCAL_PRIVACY *) GKI_getbuf(sizeof(tBTA_DM_API_ENABLE_PRIVACY))) != NULL)
{
if ((p_msg = (tBTA_DM_API_LOCAL_PRIVACY *) GKI_getbuf(sizeof(tBTA_DM_API_ENABLE_PRIVACY))) != NULL) {
memset (p_msg, 0, sizeof(tBTA_DM_API_LOCAL_PRIVACY));
p_msg->hdr.event = BTA_DM_API_LOCAL_PRIVACY_EVT;
@ -1613,20 +1555,19 @@ void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable)
void BTA_BleEnableAdvInstance (tBTA_BLE_ADV_PARAMS *p_params,
tBTA_BLE_MULTI_ADV_CBACK *p_cback,
void *p_ref)
{ ///This function just used for vendor debug
{
///This function just used for vendor debug
tBTA_DM_API_BLE_MULTI_ADV_ENB *p_msg;
UINT16 len = sizeof(tBTA_BLE_ADV_PARAMS) + sizeof(tBTA_DM_API_BLE_MULTI_ADV_ENB);
APPL_TRACE_API ("BTA_BleEnableAdvInstance");
if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_ENB *) GKI_getbuf(len)) != NULL)
{
if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_ENB *) GKI_getbuf(len)) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_MULTI_ADV_ENB));
p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_ENB_EVT;
p_msg->p_cback = (void *)p_cback;
if (p_params != NULL)
{
if (p_params != NULL) {
p_msg->p_params = (void *)(p_msg + 1);
memcpy(p_msg->p_params, p_params, sizeof(tBTA_BLE_ADV_PARAMS));
}
@ -1656,8 +1597,7 @@ void BTA_BleUpdateAdvInstParam (UINT8 inst_id, tBTA_BLE_ADV_PARAMS *p_params)
UINT16 len = sizeof(tBTA_BLE_ADV_PARAMS) + sizeof(tBTA_DM_API_BLE_MULTI_ADV_PARAM);
APPL_TRACE_API ("BTA_BleUpdateAdvInstParam");
if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_PARAM *) GKI_getbuf(len)) != NULL)
{
if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_PARAM *) GKI_getbuf(len)) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_MULTI_ADV_PARAM));
p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_PARAM_UPD_EVT;
p_msg->inst_id = inst_id;
@ -1688,14 +1628,14 @@ void BTA_BleUpdateAdvInstParam (UINT8 inst_id, tBTA_BLE_ADV_PARAMS *p_params)
void BTA_BleCfgAdvInstData (UINT8 inst_id, BOOLEAN is_scan_rsp,
tBTA_BLE_AD_MASK data_mask,
tBTA_BLE_ADV_DATA *p_data)
{ ///This function just used for vendor debug
{
///This function just used for vendor debug
tBTA_DM_API_BLE_MULTI_ADV_DATA *p_msg;
UINT16 len = sizeof(tBTA_DM_API_BLE_MULTI_ADV_DATA) ;
APPL_TRACE_API ("BTA_BleCfgAdvInstData");
if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_DATA *) GKI_getbuf(len)) != NULL)
{
if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_DATA *) GKI_getbuf(len)) != NULL) {
memset(p_msg, 0, len);
p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_DATA_EVT;
p_msg->inst_id = inst_id;
@ -1724,8 +1664,7 @@ void BTA_BleDisableAdvInstance (UINT8 inst_id) //this function just used for v
APPL_TRACE_API ("BTA_BleDisableAdvInstance: %d", inst_id);
if ((p_msg = (tBTA_DM_API_BLE_MULTI_ADV_DISABLE *)
GKI_getbuf(sizeof(tBTA_DM_API_BLE_MULTI_ADV_DISABLE))) != NULL)
{
GKI_getbuf(sizeof(tBTA_DM_API_BLE_MULTI_ADV_DISABLE))) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_MULTI_ADV_DISABLE));
p_msg->hdr.event = BTA_DM_API_BLE_MULTI_ADV_DISABLE_EVT;
p_msg->inst_id = inst_id;
@ -1765,10 +1704,8 @@ void BTA_DmBleCfgFilterCondition(tBTA_DM_BLE_SCAN_COND_OP action,
sizeof(tBTA_DM_BLE_PF_COND_PARAM);
UINT8 *p;
if (NULL != p_cond)
{
switch(cond_type)
{
if (NULL != p_cond) {
switch (cond_type) {
case BTA_DM_BLE_PF_SRVC_DATA_PATTERN:
case BTA_DM_BLE_PF_MANU_DATA:
/* Length of pattern and pattern mask and other elements in */
@ -1791,8 +1728,7 @@ void BTA_DmBleCfgFilterCondition(tBTA_DM_BLE_SCAN_COND_OP action,
}
}
if ((p_msg = (tBTA_DM_API_CFG_FILTER_COND *) GKI_getbuf(len)) != NULL)
{
if ((p_msg = (tBTA_DM_API_CFG_FILTER_COND *) GKI_getbuf(len)) != NULL) {
memset (p_msg, 0, len);
p_msg->hdr.event = BTA_DM_API_CFG_FILTER_COND_EVT;
@ -1801,56 +1737,46 @@ void BTA_DmBleCfgFilterCondition(tBTA_DM_BLE_SCAN_COND_OP action,
p_msg->filt_index = filt_index;
p_msg->p_filt_cfg_cback = p_cmpl_cback;
p_msg->ref_value = ref_value;
if (p_cond)
{
if (p_cond) {
p_msg->p_cond_param = (tBTA_DM_BLE_PF_COND_PARAM *)(p_msg + 1);
memcpy(p_msg->p_cond_param, p_cond, sizeof(tBTA_DM_BLE_PF_COND_PARAM));
p = (UINT8 *)(p_msg->p_cond_param + 1);
if (cond_type == BTA_DM_BLE_PF_SRVC_DATA_PATTERN ||
cond_type == BTA_DM_BLE_PF_MANU_DATA)
{
cond_type == BTA_DM_BLE_PF_MANU_DATA) {
p_msg->p_cond_param->manu_data.p_pattern = p;
p_msg->p_cond_param->manu_data.data_len = p_cond->manu_data.data_len;
memcpy(p_msg->p_cond_param->manu_data.p_pattern, p_cond->manu_data.p_pattern,
p_cond->manu_data.data_len);
p += p_cond->manu_data.data_len;
if (cond_type == BTA_DM_BLE_PF_MANU_DATA)
{
if (cond_type == BTA_DM_BLE_PF_MANU_DATA) {
p_msg->p_cond_param->manu_data.company_id_mask =
p_cond->manu_data.company_id_mask;
if ( p_cond->manu_data.p_pattern_mask != NULL)
{
if ( p_cond->manu_data.p_pattern_mask != NULL) {
p_msg->p_cond_param->manu_data.p_pattern_mask = p;
memcpy(p_msg->p_cond_param->manu_data.p_pattern_mask,
p_cond->manu_data.p_pattern_mask, p_cond->manu_data.data_len);
}
}
}
else if (cond_type == BTA_DM_BLE_PF_LOCAL_NAME)
{
} else if (cond_type == BTA_DM_BLE_PF_LOCAL_NAME) {
p_msg->p_cond_param->local_name.p_data = p;
p_msg->p_cond_param->local_name.data_len =
p_cond->local_name.data_len;
memcpy(p_msg->p_cond_param->local_name.p_data,
p_cond->local_name.p_data, p_cond->local_name.data_len);
}
else if ((cond_type == BTM_BLE_PF_SRVC_UUID
|| cond_type == BTM_BLE_PF_SRVC_SOL_UUID))
{
if (p_cond->srvc_uuid.p_target_addr != NULL)
{
} else if ((cond_type == BTM_BLE_PF_SRVC_UUID
|| cond_type == BTM_BLE_PF_SRVC_SOL_UUID)) {
if (p_cond->srvc_uuid.p_target_addr != NULL) {
p_msg->p_cond_param->srvc_uuid.p_target_addr = (tBLE_BD_ADDR *)(p);
p_msg->p_cond_param->srvc_uuid.p_target_addr->type =
p_cond->srvc_uuid.p_target_addr->type;
memcpy(p_msg->p_cond_param->srvc_uuid.p_target_addr->bda,
p_cond->srvc_uuid.p_target_addr->bda, BD_ADDR_LEN);
p = (UINT8*)( p_msg->p_cond_param->srvc_uuid.p_target_addr + 1);
p = (UINT8 *)( p_msg->p_cond_param->srvc_uuid.p_target_addr + 1);
}
if (p_cond->srvc_uuid.p_uuid_mask)
{
if (p_cond->srvc_uuid.p_uuid_mask) {
p_msg->p_cond_param->srvc_uuid.p_uuid_mask = (tBTA_DM_BLE_PF_COND_MASK *)p;
memcpy(p_msg->p_cond_param->srvc_uuid.p_uuid_mask,
p_cond->srvc_uuid.p_uuid_mask, sizeof(tBTA_DM_BLE_PF_COND_MASK));
@ -1898,20 +1824,19 @@ void BTA_DmBleScanFilterSetup(UINT8 action, tBTA_DM_BLE_PF_FILT_INDEX filt_index
UINT16 len = sizeof(tBTA_DM_API_SCAN_FILTER_PARAM_SETUP) + sizeof(tBLE_BD_ADDR);
if ((p_msg = (tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *) GKI_getbuf(len)) != NULL)
{
if ((p_msg = (tBTA_DM_API_SCAN_FILTER_PARAM_SETUP *) GKI_getbuf(len)) != NULL) {
memset (p_msg, 0, len);
p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_SETUP_EVT;
p_msg->action = action;
p_msg->filt_index = filt_index;
if (p_filt_params)
if (p_filt_params) {
memcpy(&p_msg->filt_params, p_filt_params, sizeof(tBTA_DM_BLE_PF_FILT_PARAMS));
}
p_msg->p_filt_param_cback = p_cmpl_cback;
p_msg->ref_value = ref_value;
if (p_target)
{
if (p_target) {
p_msg->p_target = (tBLE_BD_ADDR *)(p_msg + 1);
memcpy(p_msg->p_target, p_target, sizeof(tBLE_BD_ADDR));
}
@ -1946,8 +1871,7 @@ void BTA_DmBleGetEnergyInfo(tBTA_BLE_ENERGY_INFO_CBACK *p_cmpl_cback)
UINT16 len = sizeof(tBTA_DM_API_ENERGY_INFO) + sizeof(tBLE_BD_ADDR);
if ((p_msg = (tBTA_DM_API_ENERGY_INFO *) GKI_getbuf(len)) != NULL)
{
if ((p_msg = (tBTA_DM_API_ENERGY_INFO *) GKI_getbuf(len)) != NULL) {
memset (p_msg, 0, len);
p_msg->hdr.event = BTA_DM_API_BLE_ENERGY_INFO_EVT;
p_msg->p_energy_info_cback = p_cmpl_cback;
@ -1977,8 +1901,7 @@ void BTA_DmEnableScanFilter(UINT8 action, tBTA_DM_BLE_PF_STATUS_CBACK *p_cmpl_cb
UINT16 len = sizeof(tBTA_DM_API_ENABLE_SCAN_FILTER) + sizeof(tBLE_BD_ADDR);
if ((p_msg = (tBTA_DM_API_ENABLE_SCAN_FILTER *) GKI_getbuf(len)) != NULL)
{
if ((p_msg = (tBTA_DM_API_ENABLE_SCAN_FILTER *) GKI_getbuf(len)) != NULL) {
memset (p_msg, 0, len);
p_msg->hdr.event = BTA_DM_API_SCAN_FILTER_ENABLE_EVT;
@ -2015,8 +1938,7 @@ void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, UINT16 max
{
tBTA_DM_API_UPDATE_CONN_PARAM *p_msg;
if ((p_msg = (tBTA_DM_API_UPDATE_CONN_PARAM *) GKI_getbuf(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM))) != NULL)
{
if ((p_msg = (tBTA_DM_API_UPDATE_CONN_PARAM *) GKI_getbuf(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM))) != NULL) {
memset (p_msg, 0, sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
@ -2045,8 +1967,7 @@ void BTA_DmBleSetDataLength(BD_ADDR remote_device, UINT16 tx_data_length)
tBTA_DM_API_BLE_SET_DATA_LENGTH *p_msg;
if ((p_msg = (tBTA_DM_API_BLE_SET_DATA_LENGTH *)GKI_getbuf(sizeof(tBTA_DM_API_BLE_SET_DATA_LENGTH)))
!= NULL)
{
!= NULL) {
bdcpy(p_msg->remote_bda, remote_device);
p_msg->hdr.event = BTA_DM_API_SET_DATA_LENGTH_EVT;
p_msg->tx_data_length = tx_data_length;
@ -2085,8 +2006,7 @@ void BTA_DmSetEncryption(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_DM_ENCR
tBTA_DM_API_SET_ENCRYPTION *p_msg;
APPL_TRACE_API("BTA_DmSetEncryption"); //todo
if ((p_msg = (tBTA_DM_API_SET_ENCRYPTION *) GKI_getbuf(sizeof(tBTA_DM_API_SET_ENCRYPTION))) != NULL)
{
if ((p_msg = (tBTA_DM_API_SET_ENCRYPTION *) GKI_getbuf(sizeof(tBTA_DM_API_SET_ENCRYPTION))) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_SET_ENCRYPTION));
p_msg->hdr.event = BTA_DM_API_SET_ENCRYPTION_EVT;
@ -2119,8 +2039,7 @@ void BTA_DmCloseACL(BD_ADDR bd_addr, BOOLEAN remove_dev, tBTA_TRANSPORT transpor
APPL_TRACE_API("BTA_DmCloseACL");
if ((p_msg = (tBTA_DM_API_REMOVE_ACL *) GKI_getbuf(sizeof(tBTA_DM_API_REMOVE_ACL))) != NULL)
{
if ((p_msg = (tBTA_DM_API_REMOVE_ACL *) GKI_getbuf(sizeof(tBTA_DM_API_REMOVE_ACL))) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_REMOVE_ACL));
p_msg->hdr.event = BTA_DM_API_REMOVE_ACL_EVT;
@ -2156,8 +2075,7 @@ extern void BTA_DmBleObserve(BOOLEAN start, UINT8 duration,
APPL_TRACE_API("BTA_DmBleObserve:start = %d ", start);
if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL)
{
if ((p_msg = (tBTA_DM_API_BLE_OBSERVE *) GKI_getbuf(sizeof(tBTA_DM_API_BLE_OBSERVE))) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_API_BLE_OBSERVE));
p_msg->hdr.event = BTA_DM_API_BLE_OBSERVE_EVT;
@ -2187,8 +2105,7 @@ extern void BTA_DmBleStopAdvertising(void)
APPL_TRACE_API("BTA_DmBleStopAdvertising\n");
if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
{
if ((p_msg = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
memset(p_msg, 0, sizeof(BT_HDR));
p_msg->event = BTA_DM_API_BLE_STOP_ADV_EVT;
bta_sys_sendmsg(p_msg);
@ -2212,10 +2129,9 @@ extern void BTA_DmSetRandAddress(BD_ADDR rand_addr)
{
tBTA_DM_APT_SET_DEV_ADDR *p_msg;
APPL_TRACE_API("set the random address ");
if ((p_msg = (tBTA_DM_APT_SET_DEV_ADDR *) GKI_getbuf(sizeof(tBTA_DM_APT_SET_DEV_ADDR))) != NULL)
{
if ((p_msg = (tBTA_DM_APT_SET_DEV_ADDR *) GKI_getbuf(sizeof(tBTA_DM_APT_SET_DEV_ADDR))) != NULL) {
memset(p_msg, 0, sizeof(tBTA_DM_APT_SET_DEV_ADDR));
memcpy(p_msg->address,rand_addr,BD_ADDR_LEN);
memcpy(p_msg->address, rand_addr, BD_ADDR_LEN);
p_msg->hdr.event = BTA_DM_API_SET_RAND_ADDR_EVT;
p_msg->addr_type = BLE_ADDR_RANDOM;
//start sent the msg to the bta system control moudle
@ -2252,20 +2168,21 @@ void BTA_VendorCleanup (void)
BTM_BleGetVendorCapabilities(&cmn_ble_vsc_cb);
#if (BLE_INCLUDED == TRUE && BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE)
if (cmn_ble_vsc_cb.max_filter > 0)
{
if (cmn_ble_vsc_cb.max_filter > 0) {
btm_ble_adv_filter_cleanup();
#if BLE_PRIVACY_SPT == TRUE
btm_ble_resolving_list_cleanup ();
#endif
}
if (cmn_ble_vsc_cb.tot_scan_results_strg > 0)
if (cmn_ble_vsc_cb.tot_scan_results_strg > 0) {
btm_ble_batchscan_cleanup();
}
#endif
if(cmn_ble_vsc_cb.adv_inst_max > 0)
if (cmn_ble_vsc_cb.adv_inst_max > 0) {
btm_ble_multi_adv_cleanup();
}
}
#endif

53
components/bt/bluedroid/bta/dm/bta_dm_cfg.c Executable file → Normal file
View file

@ -57,8 +57,7 @@
#endif
const tBTA_DM_CFG bta_dm_cfg =
{
const tBTA_DM_CFG bta_dm_cfg = {
/* mobile phone COD */
BTA_DM_COD,
/* link policy settings */
@ -101,8 +100,7 @@ const tBTA_DM_CFG bta_dm_cfg =
/* First element is always for SYS:
app_id = # of entries table, cfg is
device scatternet support */
const tBTA_DM_RM bta_dm_rm_cfg[] =
{
const tBTA_DM_RM bta_dm_rm_cfg[] = {
{BTA_ID_SYS, BTA_DM_NUM_RM_ENTRY, BTA_DM_SCATTERNET},
{BTA_ID_PAN, BTUI_PAN_ID_NAP, BTA_ANY_ROLE},
{BTA_ID_PAN, BTUI_PAN_ID_GN, BTA_ANY_ROLE},
@ -113,9 +111,9 @@ const tBTA_DM_RM bta_dm_rm_cfg[] =
};
tBTA_DM_CFG *p_bta_dm_cfg = (tBTA_DM_CFG *)&bta_dm_cfg;
tBTA_DM_CFG *p_bta_dm_cfg = (tBTA_DM_CFG *) &bta_dm_cfg;
tBTA_DM_RM *p_bta_dm_rm_cfg = (tBTA_DM_RM *)&bta_dm_rm_cfg;
tBTA_DM_RM *p_bta_dm_rm_cfg = (tBTA_DM_RM *) &bta_dm_rm_cfg;
#if BLE_INCLUDED == TRUE
# define BTA_DM_NUM_PM_ENTRY 21 /* number of entries in bta_dm_pm_cfg except the first */
@ -125,8 +123,7 @@ tBTA_DM_RM *p_bta_dm_rm_cfg = (tBTA_DM_RM *)&bta_dm_rm_cfg;
# define BTA_DM_NUM_PM_SPEC 13 /* number of entries in bta_dm_pm_spec */
#endif
tBTA_DM_PM_TYPE_QUALIFIER tBTA_DM_PM_CFG bta_dm_pm_cfg[BTA_DM_NUM_PM_ENTRY + 1] =
{
tBTA_DM_PM_TYPE_QUALIFIER tBTA_DM_PM_CFG bta_dm_pm_cfg[BTA_DM_NUM_PM_ENTRY + 1] = {
{BTA_ID_SYS, BTA_DM_NUM_PM_ENTRY, 0}, /* reserved: specifies length of this table. */
{BTA_ID_AG, BTA_ALL_APP_ID, 0}, /* ag uses first spec table for app id 0 */
{BTA_ID_CT, 1, 1}, /* ct (BTA_ID_CT,APP ID=1) spec table */
@ -150,13 +147,12 @@ tBTA_DM_PM_TYPE_QUALIFIER tBTA_DM_PM_CFG bta_dm_pm_cfg[BTA_DM_NUM_PM_ENTRY + 1]
{BTA_ID_PAN, BTUI_PAN_ID_NAP, 10}, /* NAP spec table */
{BTA_ID_HS, BTA_ALL_APP_ID, 11} /* HS spec table */
#if BLE_INCLUDED == TRUE
,{BTA_ID_GATTC, BTA_ALL_APP_ID, 13} /* gattc spec table */
,{BTA_ID_GATTS, BTA_ALL_APP_ID, 14} /* gatts spec table */
, {BTA_ID_GATTC, BTA_ALL_APP_ID, 13} /* gattc spec table */
, {BTA_ID_GATTS, BTA_ALL_APP_ID, 14} /* gatts spec table */
#endif
};
tBTA_DM_PM_TYPE_QUALIFIER tBTA_DM_PM_SPEC bta_dm_pm_spec[BTA_DM_NUM_PM_SPEC] =
{
tBTA_DM_PM_TYPE_QUALIFIER tBTA_DM_PM_SPEC bta_dm_pm_spec[BTA_DM_NUM_PM_SPEC] = {
/* AG : 0 */
{
(BTA_DM_PM_SNIFF | BTA_DM_PM_PARK), /* allow park & sniff */
@ -259,7 +255,7 @@ tBTA_DM_PM_TYPE_QUALIFIER tBTA_DM_PM_SPEC bta_dm_pm_spec[BTA_DM_NUM_PM_SPEC] =
(BTA_DM_PM_SSR1), /* the SSR entry */
#endif
{
{{BTA_DM_PM_SNIFF_HH_OPEN_IDX, BTA_DM_PM_HH_OPEN_DELAY},{BTA_DM_PM_NO_ACTION, 0}}, /* conn open sniff */
{{BTA_DM_PM_SNIFF_HH_OPEN_IDX, BTA_DM_PM_HH_OPEN_DELAY}, {BTA_DM_PM_NO_ACTION, 0}}, /* conn open sniff */
{{BTA_DM_PM_NO_PREF, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* conn close */
{{BTA_DM_PM_NO_ACTION, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* app open */
{{BTA_DM_PM_NO_ACTION, 0}, {BTA_DM_PM_NO_ACTION, 0}}, /* app close */
@ -407,7 +403,7 @@ tBTA_DM_PM_TYPE_QUALIFIER tBTA_DM_PM_SPEC bta_dm_pm_spec[BTA_DM_NUM_PM_SPEC] =
#if BLE_INCLUDED == TRUE
/* GATTC : 13 */
,{
, {
(BTA_DM_PM_SNIFF | BTA_DM_PM_PARK), /* allow park & sniff */
#if (BTM_SSR_INCLUDED == TRUE)
(BTA_DM_PM_SSR2), /* the SSR entry */
@ -428,7 +424,7 @@ tBTA_DM_PM_TYPE_QUALIFIER tBTA_DM_PM_SPEC bta_dm_pm_spec[BTA_DM_NUM_PM_SPEC] =
}
}
/* GATTS : 14 */
,{
, {
(BTA_DM_PM_SNIFF | BTA_DM_PM_PARK), /* allow park & sniff */
#if (BTM_SSR_INCLUDED == TRUE)
(BTA_DM_PM_SSR2), /* the SSR entry */
@ -476,9 +472,8 @@ tBTA_DM_PM_TYPE_QUALIFIER tBTA_DM_PM_SPEC bta_dm_pm_spec[BTA_DM_NUM_PM_SPEC] =
* If there is a conflict among the connected services the setting with the lowest latency will
* be selected.
*/
tBTA_DM_PM_TYPE_QUALIFIER tBTM_PM_PWR_MD bta_dm_pm_md[] =
{
/*
tBTA_DM_PM_TYPE_QUALIFIER tBTM_PM_PWR_MD bta_dm_pm_md[] = {
/*
* More sniff parameter entries can be added for
* BTA_DM_PM_SNIFF3 - BTA_DM_PM_SNIFF7, if needed. When entries are added or
* removed, BTA_DM_PM_PARK_IDX needs to be updated to reflect the actual index
@ -488,7 +483,7 @@ tBTA_DM_PM_TYPE_QUALIFIER tBTM_PM_PWR_MD bta_dm_pm_md[] =
* interval) to lowest latency. If there's a conflict among the connected
* services, the setting with lowest latency wins.
*/
/* sniff modes: max interval, min interval, attempt, timeout */
/* sniff modes: max interval, min interval, attempt, timeout */
{BTA_DM_PM_SNIFF_MAX, BTA_DM_PM_SNIFF_MIN, BTA_DM_PM_SNIFF_ATTEMPT, BTA_DM_PM_SNIFF_TIMEOUT, BTM_PM_MD_SNIFF}, /* for BTA_DM_PM_SNIFF - A2DP */
{BTA_DM_PM_SNIFF1_MAX, BTA_DM_PM_SNIFF1_MIN, BTA_DM_PM_SNIFF1_ATTEMPT, BTA_DM_PM_SNIFF1_TIMEOUT, BTM_PM_MD_SNIFF}, /* for BTA_DM_PM_SNIFF1 */
{BTA_DM_PM_SNIFF2_MAX, BTA_DM_PM_SNIFF2_MIN, BTA_DM_PM_SNIFF2_ATTEMPT, BTA_DM_PM_SNIFF2_TIMEOUT, BTM_PM_MD_SNIFF}, /* for BTA_DM_PM_SNIFF2- HD idle */
@ -515,8 +510,7 @@ tBTA_DM_PM_TYPE_QUALIFIER tBTM_PM_PWR_MD bta_dm_pm_md[] =
/* the smaller of the SSR max latency wins.
* the entries in this table must be from highest latency (biggest interval) to lowest latency */
#if (BTM_SSR_INCLUDED == TRUE)
tBTA_DM_SSR_SPEC bta_dm_ssr_spec[] =
{
tBTA_DM_SSR_SPEC bta_dm_ssr_spec[] = {
/*max_lat, min_rmt_to, min_loc_to*/
{0, 0, 0}, /* BTA_DM_PM_SSR0 - do not use SSR */
{0, 0, 2}, /* BTA_DM_PM_SSR1 - HH, can NOT share entry with any other profile,
@ -526,12 +520,12 @@ tBTA_DM_SSR_SPEC bta_dm_ssr_spec[] =
{360, 160, 2} /* BTA_DM_PM_SSR3 - HD */
};
tBTA_DM_SSR_SPEC *p_bta_dm_ssr_spec = (tBTA_DM_SSR_SPEC *)&bta_dm_ssr_spec;
tBTA_DM_SSR_SPEC *p_bta_dm_ssr_spec = (tBTA_DM_SSR_SPEC *) &bta_dm_ssr_spec;
#endif
tBTA_DM_PM_CFG *p_bta_dm_pm_cfg = (tBTA_DM_PM_CFG *)&bta_dm_pm_cfg;
tBTA_DM_PM_SPEC *p_bta_dm_pm_spec = (tBTA_DM_PM_SPEC *)&bta_dm_pm_spec;
tBTM_PM_PWR_MD *p_bta_dm_pm_md = (tBTM_PM_PWR_MD *)&bta_dm_pm_md;
tBTA_DM_PM_CFG *p_bta_dm_pm_cfg = (tBTA_DM_PM_CFG *) &bta_dm_pm_cfg;
tBTA_DM_PM_SPEC *p_bta_dm_pm_spec = (tBTA_DM_PM_SPEC *) &bta_dm_pm_spec;
tBTM_PM_PWR_MD *p_bta_dm_pm_md = (tBTM_PM_PWR_MD *) &bta_dm_pm_md;
/* The performance impact of EIR packet size
**
@ -552,17 +546,16 @@ tBTM_PM_PWR_MD *p_bta_dm_pm_md = (tBTM_PM_PWR_MD *)&bta_dm_pm_md;
*/
#if (BTA_EIR_CANNED_UUID_LIST == TRUE)
/* for example */
/* for example */
const UINT8 bta_dm_eir_uuid16_list[] = { 0x08, 0x11, /* Headset */
0x1E, 0x11, /* Handsfree */
0x0E, 0x11, /* AV Remote Control */
0x0B, 0x11, /* Audio Sink */
};
};
#endif // BTA_EIR_CANNED_UUID_LIST
/* Extended Inquiry Response */
const tBTA_DM_EIR_CONF bta_dm_eir_cfg =
{
const tBTA_DM_EIR_CONF bta_dm_eir_cfg = {
50, /* minimum length of local name when it is shortened */
/* if length of local name is longer than this and EIR has not enough */
/* room for all UUID list then local name is shortened to this length */
@ -584,4 +577,4 @@ const tBTA_DM_EIR_CONF bta_dm_eir_cfg =
0, /* length of additional data in bytes */
NULL /* additional data */
};
tBTA_DM_EIR_CONF *p_bta_dm_eir_cfg = (tBTA_DM_EIR_CONF*)&bta_dm_eir_cfg;
tBTA_DM_EIR_CONF *p_bta_dm_eir_cfg = (tBTA_DM_EIR_CONF *) &bta_dm_eir_cfg;

9
components/bt/bluedroid/bta/dm/bta_dm_ci.c Executable file → Normal file
View file

@ -48,8 +48,7 @@ void bta_dm_ci_io_req(BD_ADDR bd_addr, tBTA_IO_CAP io_cap, tBTA_OOB_DATA oob_dat
{
tBTA_DM_CI_IO_REQ *p_msg;
if ((p_msg = (tBTA_DM_CI_IO_REQ *) GKI_getbuf(sizeof(tBTA_DM_CI_IO_REQ))) != NULL)
{
if ((p_msg = (tBTA_DM_CI_IO_REQ *) GKI_getbuf(sizeof(tBTA_DM_CI_IO_REQ))) != NULL) {
p_msg->hdr.event = BTA_DM_CI_IO_REQ_EVT;
bdcpy(p_msg->bd_addr, bd_addr);
p_msg->io_cap = io_cap;
@ -74,8 +73,7 @@ void bta_dm_ci_rmt_oob(BOOLEAN accept, BD_ADDR bd_addr, BT_OCTET16 c, BT_OCTET16
{
tBTA_DM_CI_RMT_OOB *p_msg;
if ((p_msg = (tBTA_DM_CI_RMT_OOB *) GKI_getbuf(sizeof(tBTA_DM_CI_RMT_OOB))) != NULL)
{
if ((p_msg = (tBTA_DM_CI_RMT_OOB *) GKI_getbuf(sizeof(tBTA_DM_CI_RMT_OOB))) != NULL) {
p_msg->hdr.event = BTA_DM_CI_RMT_OOB_EVT;
bdcpy(p_msg->bd_addr, bd_addr);
p_msg->accept = accept;
@ -106,8 +104,7 @@ void bta_dm_sco_ci_data_ready(UINT16 event, UINT16 sco_handle)
{
BT_HDR *p_buf;
if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
{
if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
p_buf->event = event;
p_buf->layer_specific = sco_handle;

328
components/bt/bluedroid/bta/dm/bta_dm_int.h Executable file → Normal file
View file

@ -27,7 +27,7 @@
#include "bt_target.h"
#if (BLE_INCLUDED == TRUE && (defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE))
#include "bta_gatt_api.h"
#include "bta_gatt_api.h"
#endif
@ -47,8 +47,7 @@
#define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id))
/* DM events */
enum
{
enum {
/* device manager local device API events */
BTA_DM_API_ENABLE_EVT = BTA_SYS_EVT_START(BTA_ID_DM),
BTA_DM_API_DISABLE_EVT,
@ -142,8 +141,7 @@ enum
/* DM search events */
enum
{
enum {
/* DM search API events */
BTA_DM_API_SEARCH_EVT = BTA_SYS_EVT_START(BTA_ID_DM_SEARCH),
BTA_DM_API_SEARCH_CANCEL_EVT,
@ -159,22 +157,19 @@ enum
};
/* data type for BTA_DM_API_ENABLE_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_DM_SEC_CBACK *p_sec_cback;
} tBTA_DM_API_ENABLE;
/* data type for BTA_DM_API_SET_NAME_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_NAME name; /* max 248 bytes name, plus must be Null terminated */
} tBTA_DM_API_SET_NAME;
/* data type for BTA_DM_API_SET_VISIBILITY_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_DM_DISC disc_mode;
tBTA_DM_CONN conn_mode;
@ -182,8 +177,7 @@ typedef struct
UINT8 conn_paired_only;
} tBTA_DM_API_SET_VISIBILITY;
enum
{
enum {
BTA_DM_RS_NONE, /* straight API call */
BTA_DM_RS_OK, /* the role switch result - successful */
BTA_DM_RS_FAIL /* the role switch result - failed */
@ -191,12 +185,11 @@ enum
typedef UINT8 tBTA_DM_RS_RES;
/* data type for BTA_DM_API_SEARCH_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_DM_INQ inq_params;
tBTA_SERVICE_MASK services;
tBTA_DM_SEARCH_CBACK * p_cback;
tBTA_DM_SEARCH_CBACK *p_cback;
tBTA_DM_RS_RES rs_res;
#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
UINT8 num_uuid;
@ -205,12 +198,11 @@ typedef struct
} tBTA_DM_API_SEARCH;
/* data type for BTA_DM_API_DISCOVER_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
tBTA_SERVICE_MASK services;
tBTA_DM_SEARCH_CBACK * p_cback;
tBTA_DM_SEARCH_CBACK *p_cback;
BOOLEAN sdp_search;
tBTA_TRANSPORT transport;
#if BLE_INCLUDED == TRUE && BTA_GATT_INCLUDED == TRUE
@ -221,34 +213,30 @@ typedef struct
} tBTA_DM_API_DISCOVER;
/* data type for BTA_DM_API_DI_DISC_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
tBTA_DISCOVERY_DB *p_sdp_db;
UINT32 len;
tBTA_DM_SEARCH_CBACK * p_cback;
}tBTA_DM_API_DI_DISC;
tBTA_DM_SEARCH_CBACK *p_cback;
} tBTA_DM_API_DI_DISC;
/* data type for BTA_DM_API_BOND_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
tBTA_TRANSPORT transport;
} tBTA_DM_API_BOND;
/* data type for BTA_DM_API_BOND_CANCEL_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
tBTA_TRANSPORT transport;
} tBTA_DM_API_BOND_CANCEL;
/* data type for BTA_DM_API_PIN_REPLY_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
BOOLEAN accept;
@ -257,22 +245,19 @@ typedef struct
} tBTA_DM_API_PIN_REPLY;
/* data type for BTA_DM_API_LOC_OOB_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
} tBTA_DM_API_LOC_OOB;
/* data type for BTA_DM_API_CONFIRM_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
BOOLEAN accept;
} tBTA_DM_API_CONFIRM;
/* data type for BTA_DM_CI_IO_REQ_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
tBTA_IO_CAP io_cap;
@ -281,8 +266,7 @@ typedef struct
} tBTA_DM_CI_IO_REQ;
/* data type for BTA_DM_CI_RMT_OOB_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
BT_OCTET16 c;
@ -291,37 +275,32 @@ typedef struct
} tBTA_DM_CI_RMT_OOB;
/* data type for BTA_DM_REMT_NAME_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_DM_SEARCH result;
} tBTA_DM_REM_NAME;
/* data type for tBTA_DM_DISC_RESULT */
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_DM_SEARCH result;
} tBTA_DM_DISC_RESULT;
/* data type for BTA_DM_INQUIRY_CMPL_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT8 num;
} tBTA_DM_INQUIRY_CMPL;
/* data type for BTA_DM_SDP_RESULT_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT16 sdp_result;
} tBTA_DM_SDP_RESULT;
/* data type for BTA_DM_ACL_CHANGE_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTM_BL_EVENT event;
UINT8 busy_level;
@ -337,8 +316,7 @@ typedef struct
} tBTA_DM_ACL_CHANGE;
/* data type for BTA_DM_PM_BTM_STATUS_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
@ -349,8 +327,7 @@ typedef struct
} tBTA_DM_PM_BTM_STATUS;
/* data type for BTA_DM_PM_TIMER_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
tBTA_DM_PM_ACTION pm_request;
@ -358,8 +335,7 @@ typedef struct
/* data type for BTA_DM_API_ADD_DEVICE_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
DEV_CLASS dc;
@ -376,23 +352,20 @@ typedef struct
} tBTA_DM_API_ADD_DEVICE;
/* data type for BTA_DM_API_REMOVE_ACL_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
} tBTA_DM_API_REMOVE_DEVICE;
/* data type for BTA_DM_API_EXECUTE_CBACK_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
void * p_param;
void *p_param;
tBTA_DM_EXEC_CBACK *p_exec_cback;
} tBTA_DM_API_EXECUTE_CBACK;
/* data type for tBTA_DM_API_SET_ENCRYPTION */
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_TRANSPORT transport;
tBTA_DM_ENCRYPT_CBACK *p_callback;
@ -401,50 +374,44 @@ typedef struct
} tBTA_DM_API_SET_ENCRYPTION;
#if BLE_INCLUDED == TRUE
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
tBTA_LE_KEY_VALUE blekey;
tBTA_LE_KEY_TYPE key_type;
}tBTA_DM_API_ADD_BLEKEY;
} tBTA_DM_API_ADD_BLEKEY;
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
tBT_DEVICE_TYPE dev_type ;
tBLE_ADDR_TYPE addr_type;
}tBTA_DM_API_ADD_BLE_DEVICE;
} tBTA_DM_API_ADD_BLE_DEVICE;
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
BOOLEAN accept;
UINT32 passkey;
}tBTA_DM_API_PASSKEY_REPLY;
} tBTA_DM_API_PASSKEY_REPLY;
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
tBTA_DM_BLE_SEC_GRANT res;
}tBTA_DM_API_BLE_SEC_GRANT;
} tBTA_DM_API_BLE_SEC_GRANT;
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_DM_BLE_CONN_TYPE bg_conn_type;
tBTA_DM_BLE_SEL_CBACK *p_select_cback;
}tBTA_DM_API_BLE_SET_BG_CONN_TYPE;
} tBTA_DM_API_BLE_SET_BG_CONN_TYPE;
/* set prefered BLE connection parameters for a device */
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR peer_bda;
UINT16 conn_int_min;
@ -452,35 +419,31 @@ typedef struct
UINT16 supervision_tout;
UINT16 slave_latency;
}tBTA_DM_API_BLE_CONN_PARAMS;
} tBTA_DM_API_BLE_CONN_PARAMS;
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR peer_bda;
BOOLEAN privacy_enable;
}tBTA_DM_API_ENABLE_PRIVACY;
} tBTA_DM_API_ENABLE_PRIVACY;
typedef struct
{
typedef struct {
BT_HDR hdr;
BOOLEAN privacy_enable;
}tBTA_DM_API_LOCAL_PRIVACY;
} tBTA_DM_API_LOCAL_PRIVACY;
/* set scan parameter for BLE connections */
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_GATTC_IF client_if;
UINT32 scan_int;
UINT32 scan_window;
tBLE_SCAN_MODE scan_mode;
tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback;
}tBTA_DM_API_BLE_SCAN_PARAMS;
} tBTA_DM_API_BLE_SCAN_PARAMS;
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_GATTC_IF client_if;
UINT32 scan_int;
@ -489,54 +452,48 @@ typedef struct
UINT8 addr_type_own;
UINT8 scan_filter_policy;
tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback;
}tBTA_DM_API_BLE_SCAN_FILTER_PARAMS;
} tBTA_DM_API_BLE_SCAN_FILTER_PARAMS;
/* set scan parameter for BLE connections */
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT16 scan_int;
UINT16 scan_window;
} tBTA_DM_API_BLE_CONN_SCAN_PARAMS;
/* Data type for start/stop observe */
typedef struct
{
typedef struct {
BT_HDR hdr;
BOOLEAN start;
UINT16 duration;
tBTA_DM_SEARCH_CBACK * p_cback;
}tBTA_DM_API_BLE_OBSERVE;
tBTA_DM_SEARCH_CBACK *p_cback;
} tBTA_DM_API_BLE_OBSERVE;
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR remote_bda;
UINT16 tx_data_length;
}tBTA_DM_API_BLE_SET_DATA_LENGTH;
} tBTA_DM_API_BLE_SET_DATA_LENGTH;
/* set the address for BLE device
this type added by Yulong at 2016/9/9*/
typedef struct
{
typedef struct {
BT_HDR hdr;
tBLE_ADDR_TYPE addr_type;
BD_ADDR address;
}tBTA_DM_APT_SET_DEV_ADDR;
} tBTA_DM_APT_SET_DEV_ADDR;
/* set adv parameter for BLE advertising */
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT16 adv_int_min;
UINT16 adv_int_max;
tBLE_BD_ADDR *p_dir_bda;
}tBTA_DM_API_BLE_ADV_PARAMS;
} tBTA_DM_API_BLE_ADV_PARAMS;
/* set adv parameter for BLE advertising */
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT16 adv_int_min;
UINT16 adv_int_max;
@ -545,57 +502,50 @@ typedef struct
tBTM_BLE_ADV_CHNL_MAP channel_map;
tBTM_BLE_AFP adv_filter_policy;
tBLE_BD_ADDR *p_dir_bda;
}tBTA_DM_API_BLE_ADV_PARAMS_ALL;
} tBTA_DM_API_BLE_ADV_PARAMS_ALL;
typedef struct
{
typedef struct {
BT_HDR hdr;
BOOLEAN enable;
}tBTA_DM_API_BLE_FEATURE;
} tBTA_DM_API_BLE_FEATURE;
/* multi adv data structure */
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_BLE_MULTI_ADV_CBACK *p_cback;
void *p_ref;
tBTA_BLE_ADV_PARAMS *p_params;
}tBTA_DM_API_BLE_MULTI_ADV_ENB;
} tBTA_DM_API_BLE_MULTI_ADV_ENB;
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT8 inst_id;
tBTA_BLE_ADV_PARAMS *p_params;
}tBTA_DM_API_BLE_MULTI_ADV_PARAM;
} tBTA_DM_API_BLE_MULTI_ADV_PARAM;
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT8 inst_id;
BOOLEAN is_scan_rsp;
tBTA_BLE_AD_MASK data_mask;
tBTA_BLE_ADV_DATA *p_data;
}tBTA_DM_API_BLE_MULTI_ADV_DATA;
} tBTA_DM_API_BLE_MULTI_ADV_DATA;
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT8 inst_id;
}tBTA_DM_API_BLE_MULTI_ADV_DISABLE;
} tBTA_DM_API_BLE_MULTI_ADV_DISABLE;
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT32 data_mask;
tBTA_BLE_ADV_DATA *p_adv_cfg;
tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback;
}tBTA_DM_API_SET_ADV_CONFIG;
} tBTA_DM_API_SET_ADV_CONFIG;
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT8 batch_scan_full_max;
UINT8 batch_scan_trunc_max;
@ -606,8 +556,7 @@ typedef struct
tBTA_DM_BLE_REF_VALUE ref_value;
} tBTA_DM_API_SET_STORAGE_CONFIG;
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_BLE_BATCH_SCAN_MODE scan_mode;
UINT32 scan_int;
@ -617,28 +566,24 @@ typedef struct
tBTA_DM_BLE_REF_VALUE ref_value;
} tBTA_DM_API_ENABLE_SCAN;
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_DM_BLE_REF_VALUE ref_value;
} tBTA_DM_API_DISABLE_SCAN;
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_BLE_BATCH_SCAN_MODE scan_type;
tBTA_DM_BLE_REF_VALUE ref_value;
} tBTA_DM_API_READ_SCAN_REPORTS;
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_DM_BLE_REF_VALUE ref_value;
tBTA_BLE_TRACK_ADV_CBACK *p_track_adv_cback;
} tBTA_DM_API_TRACK_ADVERTISER;
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_BLE_ENERGY_INFO_CBACK *p_energy_info_cback;
} tBTA_DM_API_ENERGY_INFO;
@ -646,35 +591,31 @@ typedef struct
#endif /* BLE_INCLUDED */
/* data type for BTA_DM_API_REMOVE_ACL_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
BOOLEAN remove_dev;
tBTA_TRANSPORT transport;
}tBTA_DM_API_REMOVE_ACL;
} tBTA_DM_API_REMOVE_ACL;
/* data type for BTA_DM_API_REMOVE_ALL_ACL_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_DM_LINK_TYPE link_type;
} tBTA_DM_API_REMOVE_ALL_ACL;
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
UINT16 min_int;
UINT16 max_int;
UINT16 latency;
UINT16 timeout;
}tBTA_DM_API_UPDATE_CONN_PARAM;
} tBTA_DM_API_UPDATE_CONN_PARAM;
#if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_DM_BLE_SCAN_COND_OP action;
tBTA_DM_BLE_PF_COND_TYPE cond_type;
@ -682,18 +623,16 @@ typedef struct
tBTA_DM_BLE_PF_COND_PARAM *p_cond_param;
tBTA_DM_BLE_PF_CFG_CBACK *p_filt_cfg_cback;
tBTA_DM_BLE_REF_VALUE ref_value;
}tBTA_DM_API_CFG_FILTER_COND;
} tBTA_DM_API_CFG_FILTER_COND;
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT8 action;
tBTA_DM_BLE_PF_STATUS_CBACK *p_filt_status_cback;
tBTA_DM_BLE_REF_VALUE ref_value;
}tBTA_DM_API_ENABLE_SCAN_FILTER;
} tBTA_DM_API_ENABLE_SCAN_FILTER;
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT8 action;
tBTA_DM_BLE_PF_FILT_INDEX filt_index;
@ -701,12 +640,11 @@ typedef struct
tBLE_BD_ADDR *p_target;
tBTA_DM_BLE_PF_PARAM_CBACK *p_filt_param_cback;
tBTA_DM_BLE_REF_VALUE ref_value;
}tBTA_DM_API_SCAN_FILTER_PARAM_SETUP;
} tBTA_DM_API_SCAN_FILTER_PARAM_SETUP;
#endif
/* union of all data types */
typedef union
{
typedef union {
/* GKI event buffer header */
BT_HDR hdr;
tBTA_DM_API_ENABLE enable;
@ -819,8 +757,7 @@ typedef UINT8 tBTA_DM_DEV_INFO;
#define BTA_DM_PM_EXECUTE 3
typedef UINT8 tBTA_DM_PM_REQ;
typedef struct
{
typedef struct {
BD_ADDR peer_bdaddr;
UINT16 link_policy;
tBTA_DM_CONN_STATE conn_state;
@ -844,8 +781,7 @@ typedef struct
/* structure to store list of
active connections */
typedef struct
{
typedef struct {
tBTA_DM_PEER_DEVICE peer_device[BTA_DM_NUM_PEER_DEVICE];
UINT8 count;
#if BLE_INCLUDED == TRUE
@ -854,8 +790,7 @@ typedef struct
} tBTA_DM_ACTIVE_LINK;
typedef struct
{
typedef struct {
BD_ADDR peer_bdaddr;
tBTA_SYS_ID id;
UINT8 app_id;
@ -868,16 +803,14 @@ typedef struct
#define BTA_DM_NUM_CONN_SRVS 10
#endif
typedef struct
{
typedef struct {
UINT8 count;
tBTA_DM_SRVCS conn_srvc[BTA_DM_NUM_CONN_SRVS];
} tBTA_DM_CONNECTED_SRVCS;
typedef struct
{
typedef struct {
#define BTA_DM_PM_SNIFF_TIMER_IDX 0
#define BTA_DM_PM_PARK_TIMER_IDX 1
#define BTA_DM_PM_SUSPEND_TIMER_IDX 2
@ -901,8 +834,7 @@ extern tBTA_DM_CONNECTED_SRVCS bta_dm_conn_srvcs;
#define BTA_DM_NUM_PM_TIMER 7
/* DM control block */
typedef struct
{
typedef struct {
BOOLEAN is_bta_dm_active;
tBTA_DM_ACTIVE_LINK device_list;
tBTA_DM_SEC_CBACK *p_sec_cback;
@ -961,22 +893,21 @@ typedef struct
#endif
/* DM search control block */
typedef struct
{
typedef struct {
tBTA_DM_SEARCH_CBACK * p_search_cback;
tBTM_INQ_INFO * p_btm_inq_info;
tBTA_DM_SEARCH_CBACK *p_search_cback;
tBTM_INQ_INFO *p_btm_inq_info;
tBTA_SERVICE_MASK services;
tBTA_SERVICE_MASK services_to_search;
tBTA_SERVICE_MASK services_found;
tSDP_DISCOVERY_DB * p_sdp_db;
tSDP_DISCOVERY_DB *p_sdp_db;
UINT16 state;
BD_ADDR peer_bdaddr;
BOOLEAN name_discover_done;
BD_NAME peer_name;
TIMER_LIST_ENT search_timer;
UINT8 service_index;
tBTA_DM_MSG * p_search_queue; /* search or discover commands during search cancel stored here */
tBTA_DM_MSG *p_search_queue; /* search or discover commands during search cancel stored here */
BOOLEAN wait_disc;
BOOLEAN sdp_results;
tSDP_UUID uuid;
@ -985,7 +916,7 @@ typedef struct
BOOLEAN cancel_pending; /* inquiry cancel is pending */
tBTA_TRANSPORT transport;
#if ((defined BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
tBTA_DM_SEARCH_CBACK * p_scan_cback;
tBTA_DM_SEARCH_CBACK *p_scan_cback;
#if ((defined BTA_GATT_INCLUDED) && (BTA_GATT_INCLUDED == TRUE))
tBTA_GATTC_IF client_if;
UINT8 num_uuid;
@ -993,7 +924,7 @@ typedef struct
UINT8 uuid_to_search;
BOOLEAN gatt_disc_active;
UINT16 conn_id;
UINT8 * p_ble_rawdata;
UINT8 *p_ble_rawdata;
UINT32 ble_raw_size;
UINT32 ble_raw_used;
TIMER_LIST_ENT gatt_close_timer; /* GATT channel close delay timer */
@ -1005,16 +936,14 @@ typedef struct
} tBTA_DM_SEARCH_CB;
/* DI control block */
typedef struct
{
tSDP_DISCOVERY_DB * p_di_db; /* pointer to the DI discovery database */
typedef struct {
tSDP_DISCOVERY_DB *p_di_db; /* pointer to the DI discovery database */
UINT8 di_num; /* total local DI record number */
UINT32 di_handle[BTA_DI_NUM_MAX]; /* local DI record handle, the first one is primary record */
}tBTA_DM_DI_CB;
} tBTA_DM_DI_CB;
/* DM search state */
enum
{
enum {
BTA_DM_SEARCH_IDLE,
BTA_DM_SEARCH_ACTIVE,
@ -1025,8 +954,7 @@ enum
typedef struct
{
typedef struct {
DEV_CLASS dev_class; /* local device class */
UINT16 policy_settings; /* link policy setting hold, sniff, park, MS switch */
UINT16 page_timeout; /* timeout for page in slots */
@ -1038,8 +966,7 @@ typedef struct
extern const UINT32 bta_service_id_to_btm_srv_id_lkup_tbl[];
typedef struct
{
typedef struct {
UINT8 id;
UINT8 app_id;
UINT8 cfg;
@ -1049,8 +976,7 @@ typedef struct
extern tBTA_DM_CFG *p_bta_dm_cfg;
extern tBTA_DM_RM *p_bta_dm_rm_cfg;
typedef struct
{
typedef struct {
UINT8 id;
UINT8 app_id;
@ -1059,16 +985,14 @@ typedef struct
} tBTA_DM_PM_CFG;
typedef struct
{
typedef struct {
tBTA_DM_PM_ACTION power_mode;
UINT16 timeout;
} tBTA_DM_PM_ACTN;
typedef struct
{
typedef struct {
UINT8 allow_mask; /* mask of sniff/hold/park modes to allow */
#if (BTM_SSR_INCLUDED == TRUE)
@ -1078,19 +1002,17 @@ typedef struct
} tBTA_DM_PM_SPEC;
typedef struct
{
typedef struct {
UINT16 max_lat;
UINT16 min_rmt_to;
UINT16 min_loc_to;
} tBTA_DM_SSR_SPEC;
typedef struct
{
typedef struct {
UINT16 manufacturer;
UINT16 lmp_sub_version;
UINT8 lmp_version;
}tBTA_DM_LMP_VER_INFO;
} tBTA_DM_LMP_VER_INFO;
extern tBTA_DM_PM_CFG *p_bta_dm_pm_cfg;
extern tBTA_DM_PM_SPEC *p_bta_dm_pm_spec;
@ -1188,10 +1110,10 @@ extern void bta_dm_ble_multi_adv_upd_param(tBTA_DM_MSG *p_data);
extern void bta_dm_ble_multi_adv_enb(tBTA_DM_MSG *p_data);
extern void bta_dm_ble_setup_storage(tBTA_DM_MSG *p_data);
extern void bta_dm_ble_enable_batch_scan(tBTA_DM_MSG * p_data);
extern void bta_dm_ble_disable_batch_scan(tBTA_DM_MSG * p_data);
extern void bta_dm_ble_read_scan_reports(tBTA_DM_MSG * p_data);
extern void bta_dm_ble_track_advertiser(tBTA_DM_MSG * p_data);
extern void bta_dm_ble_enable_batch_scan(tBTA_DM_MSG *p_data);
extern void bta_dm_ble_disable_batch_scan(tBTA_DM_MSG *p_data);
extern void bta_dm_ble_read_scan_reports(tBTA_DM_MSG *p_data);
extern void bta_dm_ble_track_advertiser(tBTA_DM_MSG *p_data);
extern void bta_dm_ble_get_energy_info(tBTA_DM_MSG *p_data);
#endif
@ -1226,7 +1148,7 @@ extern void bta_dm_search_cancel_cmpl (tBTA_DM_MSG *p_data);
extern void bta_dm_search_cancel_notify (tBTA_DM_MSG *p_data);
extern void bta_dm_search_cancel_transac_cmpl(tBTA_DM_MSG *p_data);
extern void bta_dm_disc_rmt_name (tBTA_DM_MSG *p_data);
extern tBTA_DM_PEER_DEVICE * bta_dm_find_peer_device(BD_ADDR peer_addr);
extern tBTA_DM_PEER_DEVICE *bta_dm_find_peer_device(BD_ADDR peer_addr);
extern void bta_dm_pm_active(BD_ADDR peer_addr);

128
components/bt/bluedroid/bta/dm/bta_dm_main.c Executable file → Normal file
View file

@ -44,8 +44,7 @@ tBTA_DM_DI_CB bta_dm_di_cb;
typedef void (*tBTA_DM_ACTION)(tBTA_DM_MSG *p_data);
/* action function list */
const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] =
{
const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = {
/* device manager local device API events */
bta_dm_enable, /* 0 BTA_DM_API_ENABLE_EVT */
@ -133,8 +132,7 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] =
/* state machine action enumeration list */
enum
{
enum {
BTA_DM_API_SEARCH, /* 0 bta_dm_search_start */
BTA_DM_API_SEARCH_CANCEL, /* 1 bta_dm_search_cancel */
BTA_DM_API_DISCOVER, /* 2 bta_dm_discover */
@ -161,8 +159,7 @@ enum
/* action function list */
const tBTA_DM_ACTION bta_dm_search_action[] =
{
const tBTA_DM_ACTION bta_dm_search_action[] = {
bta_dm_search_start, /* 0 BTA_DM_API_SEARCH */
bta_dm_search_cancel, /* 1 BTA_DM_API_SEARCH_CANCEL */
@ -183,7 +180,7 @@ const tBTA_DM_ACTION bta_dm_search_action[] =
bta_dm_disc_rmt_name, /* 16 BTA_DM_DISC_RMT_NAME */
bta_dm_di_disc /* 17 BTA_DM_API_DI_DISCOVER */
#if BLE_INCLUDED == TRUE
,bta_dm_close_gatt_conn
, bta_dm_close_gatt_conn
#endif
};
@ -196,77 +193,73 @@ const tBTA_DM_ACTION bta_dm_search_action[] =
/* state table for listen state */
const UINT8 bta_dm_search_idle_st_table[][BTA_DM_SEARCH_NUM_COLS] =
{
const UINT8 bta_dm_search_idle_st_table[][BTA_DM_SEARCH_NUM_COLS] = {
/* Event Action 1 Action 2 Next State */
/* API_SEARCH */ {BTA_DM_API_SEARCH, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE},
/* API_SEARCH_CANCEL */ {BTA_DM_SEARCH_CANCEL_NOTIFY, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE},
/* API_SEARCH_DISC */ {BTA_DM_API_DISCOVER, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE},
/* INQUIRY_CMPL */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE},
/* REMT_NAME_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE},
/* SDP_RESULT_EVT */ {BTA_DM_FREE_SDP_DB, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE},
/* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE},
/* DISCV_RES_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE},
/* API_DI_DISCOVER_EVT */ {BTA_DM_API_DI_DISCOVER, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE}
/* Event Action 1 Action 2 Next State */
/* API_SEARCH */ {BTA_DM_API_SEARCH, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE},
/* API_SEARCH_CANCEL */ {BTA_DM_SEARCH_CANCEL_NOTIFY, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE},
/* API_SEARCH_DISC */ {BTA_DM_API_DISCOVER, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE},
/* INQUIRY_CMPL */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE},
/* REMT_NAME_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE},
/* SDP_RESULT_EVT */ {BTA_DM_FREE_SDP_DB, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE},
/* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE},
/* DISCV_RES_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE},
/* API_DI_DISCOVER_EVT */ {BTA_DM_API_DI_DISCOVER, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE}
#if BLE_INCLUDED == TRUE
/* DISC_CLOSE_TOUT_EVT */ ,{BTA_DM_CLOSE_GATT_CONN, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE}
/* DISC_CLOSE_TOUT_EVT */ , {BTA_DM_CLOSE_GATT_CONN, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE}
#endif
};
const UINT8 bta_dm_search_search_active_st_table[][BTA_DM_SEARCH_NUM_COLS] =
{
const UINT8 bta_dm_search_search_active_st_table[][BTA_DM_SEARCH_NUM_COLS] = {
/* Event Action 1 Action 2 Next State */
/* API_SEARCH */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE},
/* API_SEARCH_CANCEL */ {BTA_DM_API_SEARCH_CANCEL, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_CANCELLING},
/* API_SEARCH_DISC */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE},
/* INQUIRY_CMPL */ {BTA_DM_INQUIRY_CMPL, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE},
/* REMT_NAME_EVT */ {BTA_DM_REMT_NAME, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE},
/* SDP_RESULT_EVT */ {BTA_DM_SDP_RESULT, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE},
/* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_CMPL, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE},
/* DISCV_RES_EVT */ {BTA_DM_SEARCH_RESULT, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE},
/* API_DI_DISCOVER_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE}
/* Event Action 1 Action 2 Next State */
/* API_SEARCH */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE},
/* API_SEARCH_CANCEL */ {BTA_DM_API_SEARCH_CANCEL, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_CANCELLING},
/* API_SEARCH_DISC */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE},
/* INQUIRY_CMPL */ {BTA_DM_INQUIRY_CMPL, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE},
/* REMT_NAME_EVT */ {BTA_DM_REMT_NAME, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE},
/* SDP_RESULT_EVT */ {BTA_DM_SDP_RESULT, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE},
/* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_CMPL, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE},
/* DISCV_RES_EVT */ {BTA_DM_SEARCH_RESULT, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE},
/* API_DI_DISCOVER_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE}
#if BLE_INCLUDED == TRUE
/* DISC_CLOSE_TOUT_EVT */ ,{BTA_DM_CLOSE_GATT_CONN, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE}
/* DISC_CLOSE_TOUT_EVT */ , {BTA_DM_CLOSE_GATT_CONN, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_ACTIVE}
#endif
};
const UINT8 bta_dm_search_search_cancelling_st_table[][BTA_DM_SEARCH_NUM_COLS] =
{
const UINT8 bta_dm_search_search_cancelling_st_table[][BTA_DM_SEARCH_NUM_COLS] = {
/* Event Action 1 Action 2 Next State */
/* API_SEARCH */ {BTA_DM_QUEUE_SEARCH, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_CANCELLING},
/* API_SEARCH_CANCEL */ {BTA_DM_SEARCH_CLEAR_QUEUE, BTA_DM_SEARCH_CANCEL_NOTIFY, BTA_DM_SEARCH_CANCELLING},
/* API_SEARCH_DISC */ {BTA_DM_QUEUE_DISC, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_CANCELLING},
/* INQUIRY_CMPL */ {BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE},
/* REMT_NAME_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL, BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
/* SDP_RESULT_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL, BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
/* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL, BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
/* DISCV_RES_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL, BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
/* API_DI_DISCOVER_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_CANCELLING}
/* Event Action 1 Action 2 Next State */
/* API_SEARCH */ {BTA_DM_QUEUE_SEARCH, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_CANCELLING},
/* API_SEARCH_CANCEL */ {BTA_DM_SEARCH_CLEAR_QUEUE, BTA_DM_SEARCH_CANCEL_NOTIFY, BTA_DM_SEARCH_CANCELLING},
/* API_SEARCH_DISC */ {BTA_DM_QUEUE_DISC, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_CANCELLING},
/* INQUIRY_CMPL */ {BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE},
/* REMT_NAME_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL, BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
/* SDP_RESULT_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL, BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
/* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL, BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
/* DISCV_RES_EVT */ {BTA_DM_SEARCH_CANCEL_TRANSAC_CMPL, BTA_DM_SEARCH_CANCEL_CMPL, BTA_DM_SEARCH_IDLE},
/* API_DI_DISCOVER_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_CANCELLING}
#if BLE_INCLUDED == TRUE
/* DISC_CLOSE_TOUT_EVT */ ,{BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_CANCELLING}
/* DISC_CLOSE_TOUT_EVT */ , {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_CANCELLING}
#endif
};
const UINT8 bta_dm_search_disc_active_st_table[][BTA_DM_SEARCH_NUM_COLS] =
{
const UINT8 bta_dm_search_disc_active_st_table[][BTA_DM_SEARCH_NUM_COLS] = {
/* Event Action 1 Action 2 Next State */
/* API_SEARCH */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE},
/* API_SEARCH_CANCEL */ {BTA_DM_SEARCH_CANCEL_NOTIFY, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_CANCELLING},
/* API_SEARCH_DISC */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE},
/* INQUIRY_CMPL */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE},
/* REMT_NAME_EVT */ {BTA_DM_DISC_RMT_NAME, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE},
/* SDP_RESULT_EVT */ {BTA_DM_SDP_RESULT, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE},
/* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_CMPL, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE},
/* DISCV_RES_EVT */ {BTA_DM_DISC_RESULT, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE},
/* API_DI_DISCOVER_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE}
/* Event Action 1 Action 2 Next State */
/* API_SEARCH */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE},
/* API_SEARCH_CANCEL */ {BTA_DM_SEARCH_CANCEL_NOTIFY, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_CANCELLING},
/* API_SEARCH_DISC */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE},
/* INQUIRY_CMPL */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE},
/* REMT_NAME_EVT */ {BTA_DM_DISC_RMT_NAME, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE},
/* SDP_RESULT_EVT */ {BTA_DM_SDP_RESULT, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE},
/* SEARCH_CMPL_EVT */ {BTA_DM_SEARCH_CMPL, BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IDLE},
/* DISCV_RES_EVT */ {BTA_DM_DISC_RESULT, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE},
/* API_DI_DISCOVER_EVT */ {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE}
#if BLE_INCLUDED == TRUE
/* DISC_CLOSE_TOUT_EVT */ ,{BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE}
/* DISC_CLOSE_TOUT_EVT */ , {BTA_DM_SEARCH_IGNORE, BTA_DM_SEARCH_IGNORE, BTA_DM_DISCOVER_ACTIVE}
#endif
};
@ -314,9 +307,8 @@ BOOLEAN bta_dm_sm_execute(BT_HDR *p_msg)
APPL_TRACE_EVENT("bta_dm_sm_execute event:0x%x", event);
/* execute action functions */
if(event < BTA_DM_NUM_ACTIONS)
{
(*bta_dm_action[event])( (tBTA_DM_MSG*) p_msg);
if (event < BTA_DM_NUM_ACTIONS) {
(*bta_dm_action[event])( (tBTA_DM_MSG *) p_msg);
}
return TRUE;
@ -365,14 +357,10 @@ BOOLEAN bta_dm_search_sm_execute(BT_HDR *p_msg)
/* execute action functions */
for (i = 0; i < BTA_DM_SEARCH_ACTIONS; i++)
{
if ((action = state_table[p_msg->event & 0x00ff][i]) != BTA_DM_SEARCH_IGNORE)
{
(*bta_dm_search_action[action])( (tBTA_DM_MSG*) p_msg);
}
else
{
for (i = 0; i < BTA_DM_SEARCH_ACTIONS; i++) {
if ((action = state_table[p_msg->event & 0x00ff][i]) != BTA_DM_SEARCH_IGNORE) {
(*bta_dm_search_action[action])( (tBTA_DM_MSG *) p_msg);
} else {
break;
}
}

431
components/bt/bluedroid/bta/dm/bta_dm_pm.c Executable file → Normal file
View file

@ -73,20 +73,19 @@ void bta_dm_init_pm(void)
memset(&bta_dm_conn_srvcs, 0x00, sizeof(bta_dm_conn_srvcs));
/* if there are no power manger entries, so not register */
if(p_bta_dm_pm_cfg[0].app_id != 0)
{
bta_sys_pm_register((tBTA_SYS_CONN_CBACK*)bta_dm_pm_cback);
if (p_bta_dm_pm_cfg[0].app_id != 0) {
bta_sys_pm_register((tBTA_SYS_CONN_CBACK *)bta_dm_pm_cback);
BTM_PmRegister((BTM_PM_REG_SET | BTM_PM_REG_NOTIF), &bta_dm_cb.pm_id,
bta_dm_pm_btm_cback);
}
/* Need to initialize all PM timer service IDs */
for (int i = 0; i < BTA_DM_NUM_PM_TIMER; i++)
{
for (int j = 0; j < BTA_DM_PM_MODE_TIMER_MAX; j++)
for (int i = 0; i < BTA_DM_NUM_PM_TIMER; i++) {
for (int j = 0; j < BTA_DM_PM_MODE_TIMER_MAX; j++) {
bta_dm_cb.pm_timer[i].srvc_id[j] = BTA_ID_MAX;
}
}
}
@ -108,13 +107,11 @@ void bta_dm_disable_pm(void)
* Deregister the PM callback from the system handling to prevent
* re-enabling the PM timers after this call if the callback is invoked.
*/
bta_sys_pm_register((tBTA_SYS_CONN_CBACK*)NULL);
bta_sys_pm_register((tBTA_SYS_CONN_CBACK *)NULL);
/* Need to stop all active timers. */
for (int i = 0; i < BTA_DM_NUM_PM_TIMER; i++)
{
for (int j = 0; j < BTA_DM_PM_MODE_TIMER_MAX; j++)
{
for (int i = 0; i < BTA_DM_NUM_PM_TIMER; i++) {
for (int j = 0; j < BTA_DM_PM_MODE_TIMER_MAX; j++) {
bta_dm_pm_stop_timer_by_index(&bta_dm_cb.pm_timer[i], j);
bta_dm_cb.pm_timer[i].pm_action[j] = BTA_DM_PM_NO_ACTION;
}
@ -134,11 +131,11 @@ void bta_dm_disable_pm(void)
UINT8 bta_dm_get_av_count(void)
{
UINT8 count = 0;
for (int i = 0; i < bta_dm_conn_srvcs.count; i++)
{
if (bta_dm_conn_srvcs.conn_srvc[i].id == BTA_ID_AV)
for (int i = 0; i < bta_dm_conn_srvcs.count; i++) {
if (bta_dm_conn_srvcs.conn_srvc[i].id == BTA_ID_AV) {
++count;
}
}
return count;
}
@ -156,12 +153,9 @@ static void bta_dm_pm_stop_timer(BD_ADDR peer_addr)
{
APPL_TRACE_DEBUG("%s: ", __func__);
for(int i=0; i<BTA_DM_NUM_PM_TIMER; i++)
{
if (bta_dm_cb.pm_timer[i].in_use && !bdcmp(bta_dm_cb.pm_timer[i].peer_bdaddr, peer_addr))
{
for (int j = 0; j < BTA_DM_PM_MODE_TIMER_MAX; j++)
{
for (int i = 0; i < BTA_DM_NUM_PM_TIMER; i++) {
if (bta_dm_cb.pm_timer[i].in_use && !bdcmp(bta_dm_cb.pm_timer[i].peer_bdaddr, peer_addr)) {
for (int j = 0; j < BTA_DM_PM_MODE_TIMER_MAX; j++) {
bta_dm_pm_stop_timer_by_index(&bta_dm_cb.pm_timer[i], j);
/*
* TODO: For now, stopping the timer does not reset
@ -191,12 +185,13 @@ static void bta_dm_pm_stop_timer(BD_ADDR peer_addr)
*******************************************************************************/
static UINT8 bta_pm_action_to_timer_idx(UINT8 pm_action)
{
if (pm_action == BTA_DM_PM_SUSPEND)
if (pm_action == BTA_DM_PM_SUSPEND) {
return BTA_DM_PM_SUSPEND_TIMER_IDX;
else if (pm_action == BTA_DM_PM_PARK)
} else if (pm_action == BTA_DM_PM_PARK) {
return BTA_DM_PM_PARK_TIMER_IDX;
else if ((pm_action & BTA_DM_PM_SNIFF) == BTA_DM_PM_SNIFF)
} else if ((pm_action & BTA_DM_PM_SNIFF) == BTA_DM_PM_SNIFF) {
return BTA_DM_PM_SNIFF_TIMER_IDX;
}
/* Active, no preference, no action and retry */
return BTA_DM_PM_MODE_TIMER_MAX;
@ -215,15 +210,13 @@ static UINT8 bta_pm_action_to_timer_idx(UINT8 pm_action)
static void bta_dm_pm_stop_timer_by_mode(BD_ADDR peer_addr, UINT8 power_mode)
{
const UINT8 timer_idx = bta_pm_action_to_timer_idx(power_mode);
if (timer_idx == BTA_DM_PM_MODE_TIMER_MAX)
if (timer_idx == BTA_DM_PM_MODE_TIMER_MAX) {
return;
}
for (int i = 0; i < BTA_DM_NUM_PM_TIMER; i++)
{
if (bta_dm_cb.pm_timer[i].in_use && !bdcmp(bta_dm_cb.pm_timer[i].peer_bdaddr, peer_addr))
{
if (bta_dm_cb.pm_timer[i].srvc_id[timer_idx] != BTA_ID_MAX)
{
for (int i = 0; i < BTA_DM_NUM_PM_TIMER; i++) {
if (bta_dm_cb.pm_timer[i].in_use && !bdcmp(bta_dm_cb.pm_timer[i].peer_bdaddr, peer_addr)) {
if (bta_dm_cb.pm_timer[i].srvc_id[timer_idx] != BTA_ID_MAX) {
bta_dm_pm_stop_timer_by_index(&bta_dm_cb.pm_timer[i], timer_idx);
/*
* TODO: Intentionally setting pm_action[timer_idx].
@ -250,14 +243,10 @@ static void bta_dm_pm_stop_timer_by_mode(BD_ADDR peer_addr, UINT8 power_mode)
*******************************************************************************/
static void bta_dm_pm_stop_timer_by_srvc_id(BD_ADDR peer_addr, UINT8 srvc_id)
{
for (int i = 0; i < BTA_DM_NUM_PM_TIMER; i++)
{
if (bta_dm_cb.pm_timer[i].in_use && !bdcmp(bta_dm_cb.pm_timer[i].peer_bdaddr, peer_addr))
{
for (int j = 0; j < BTA_DM_PM_MODE_TIMER_MAX; j++)
{
if (bta_dm_cb.pm_timer[i].srvc_id[j] == srvc_id)
{
for (int i = 0; i < BTA_DM_NUM_PM_TIMER; i++) {
if (bta_dm_cb.pm_timer[i].in_use && !bdcmp(bta_dm_cb.pm_timer[i].peer_bdaddr, peer_addr)) {
for (int j = 0; j < BTA_DM_PM_MODE_TIMER_MAX; j++) {
if (bta_dm_cb.pm_timer[i].srvc_id[j] == srvc_id) {
bta_dm_pm_stop_timer_by_index(&bta_dm_cb.pm_timer[i], j);
bta_dm_cb.pm_timer[i].pm_action[j] = BTA_DM_PM_NO_ACTION;
break;
@ -283,11 +272,13 @@ static void bta_dm_pm_start_timer(tBTA_PM_TIMER *p_timer, UINT8 timer_idx,
p_timer->in_use = TRUE;
p_timer->timer[timer_idx].p_cback = bta_dm_pm_timer_cback;
if (p_timer->srvc_id[timer_idx] == BTA_ID_MAX)
if (p_timer->srvc_id[timer_idx] == BTA_ID_MAX) {
p_timer->active++;
}
if (p_timer->pm_action[timer_idx] < pm_action)
if (p_timer->pm_action[timer_idx] < pm_action) {
p_timer->pm_action[timer_idx] = pm_action;
}
p_timer->srvc_id[timer_idx] = srvc_id;
@ -307,11 +298,13 @@ static void bta_dm_pm_start_timer(tBTA_PM_TIMER *p_timer, UINT8 timer_idx,
static void bta_dm_pm_stop_timer_by_index(tBTA_PM_TIMER *p_timer,
UINT8 timer_idx)
{
if ((p_timer == NULL) || (timer_idx >= BTA_DM_PM_MODE_TIMER_MAX))
if ((p_timer == NULL) || (timer_idx >= BTA_DM_PM_MODE_TIMER_MAX)) {
return;
}
if (p_timer->srvc_id[timer_idx] == BTA_ID_MAX)
if (p_timer->srvc_id[timer_idx] == BTA_ID_MAX) {
return; /* The timer was not scheduled */
}
assert(p_timer->in_use && (p_timer->active > 0));
@ -320,8 +313,9 @@ static void bta_dm_pm_stop_timer_by_index(tBTA_PM_TIMER *p_timer,
/* NOTE: pm_action[timer_idx] intentionally not reset */
p_timer->active--;
if (p_timer->active == 0)
if (p_timer->active == 0) {
p_timer->in_use = FALSE;
}
}
UINT32 bta_dm_pm_get_remaining_ticks (TIMER_LIST_ENT *p_target_tle)
@ -342,7 +336,7 @@ UINT32 bta_dm_pm_get_remaining_ticks (TIMER_LIST_ENT *p_target_tle)
static void bta_dm_pm_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
{
UINT8 i,j;
UINT8 i, j;
UINT16 policy_setting;
UINT8 *p = NULL;
tBTA_DM_PEER_DEVICE *p_dev;
@ -356,46 +350,43 @@ static void bta_dm_pm_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id,
p_dev = bta_dm_find_peer_device(peer_addr);
/* find if there is an power mode entry for the service */
for(i=1; i<=p_bta_dm_pm_cfg[0].app_id; i++)
{
for (i = 1; i <= p_bta_dm_pm_cfg[0].app_id; i++) {
if((p_bta_dm_pm_cfg[i].id == id)
&& ((p_bta_dm_pm_cfg[i].app_id == BTA_ALL_APP_ID ) || (p_bta_dm_pm_cfg[i].app_id == app_id )))
if ((p_bta_dm_pm_cfg[i].id == id)
&& ((p_bta_dm_pm_cfg[i].app_id == BTA_ALL_APP_ID ) || (p_bta_dm_pm_cfg[i].app_id == app_id ))) {
break;
}
}
/* if no entries are there for the app_id and subsystem in p_bta_dm_pm_spec*/
if(i> p_bta_dm_pm_cfg[0].app_id)
if (i > p_bta_dm_pm_cfg[0].app_id) {
return;
}
bta_dm_pm_stop_timer_by_srvc_id(peer_addr, id);
/*p_dev = bta_dm_find_peer_device(peer_addr);*/
#if (BTM_SSR_INCLUDED == TRUE)
/* set SSR parameters on SYS CONN OPEN */
if((BTA_SYS_CONN_OPEN == status) && p_dev && (p_dev->info & BTA_DM_DI_USE_SSR))
{
if ((BTA_SYS_CONN_OPEN == status) && p_dev && (p_dev->info & BTA_DM_DI_USE_SSR)) {
index = p_bta_dm_pm_spec[p_bta_dm_pm_cfg[i].spec_idx].ssr;
}
#endif
/* if no action for the event */
if(p_bta_dm_pm_spec[p_bta_dm_pm_cfg[i].spec_idx].actn_tbl[status][0].power_mode == BTA_DM_PM_NO_ACTION)
{
if (p_bta_dm_pm_spec[p_bta_dm_pm_cfg[i].spec_idx].actn_tbl[status][0].power_mode == BTA_DM_PM_NO_ACTION) {
#if (BTM_SSR_INCLUDED == TRUE)
if(BTA_DM_PM_SSR0 == index) /* and do not need to set SSR, return. */
if (BTA_DM_PM_SSR0 == index) /* and do not need to set SSR, return. */
#endif
return;
}
for(j=0; j<bta_dm_conn_srvcs.count ; j++)
{
for (j = 0; j < bta_dm_conn_srvcs.count ; j++) {
/* check if an entry already present */
if((bta_dm_conn_srvcs.conn_srvc[j].id == id)
if ((bta_dm_conn_srvcs.conn_srvc[j].id == id)
&& (bta_dm_conn_srvcs.conn_srvc[j].app_id == app_id )
&& !bdcmp(bta_dm_conn_srvcs.conn_srvc[j].peer_bdaddr, peer_addr))
{
&& !bdcmp(bta_dm_conn_srvcs.conn_srvc[j].peer_bdaddr, peer_addr)) {
bta_dm_conn_srvcs.conn_srvc[j].new_request = TRUE;
break;
}
@ -404,30 +395,22 @@ static void bta_dm_pm_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id,
/* if subsystem has no more preference on the power mode remove
the cb */
if(p_bta_dm_pm_spec[p_bta_dm_pm_cfg[i].spec_idx].actn_tbl[status][0].power_mode == BTA_DM_PM_NO_PREF)
{
if(j != bta_dm_conn_srvcs.count)
{
if (p_bta_dm_pm_spec[p_bta_dm_pm_cfg[i].spec_idx].actn_tbl[status][0].power_mode == BTA_DM_PM_NO_PREF) {
if (j != bta_dm_conn_srvcs.count) {
bta_dm_conn_srvcs.count--;
for(; j<bta_dm_conn_srvcs.count ; j++)
{
for (; j < bta_dm_conn_srvcs.count ; j++) {
memcpy(&bta_dm_conn_srvcs.conn_srvc[j], &bta_dm_conn_srvcs.conn_srvc[j+1], sizeof(bta_dm_conn_srvcs.conn_srvc[j]));
memcpy(&bta_dm_conn_srvcs.conn_srvc[j], &bta_dm_conn_srvcs.conn_srvc[j + 1], sizeof(bta_dm_conn_srvcs.conn_srvc[j]));
}
}
else
{
} else {
APPL_TRACE_WARNING("bta_dm_act no entry for connected service cbs");
return;
}
}
else if(j == bta_dm_conn_srvcs.count )
{
} else if (j == bta_dm_conn_srvcs.count ) {
/* check if we have more connected service that cbs */
if(bta_dm_conn_srvcs.count == BTA_DM_NUM_CONN_SRVS)
{
if (bta_dm_conn_srvcs.count == BTA_DM_NUM_CONN_SRVS) {
APPL_TRACE_WARNING("bta_dm_act no more connected service cbs");
return;
}
@ -442,9 +425,7 @@ static void bta_dm_pm_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id,
bta_dm_conn_srvcs.count++;
bta_dm_conn_srvcs.conn_srvc[j].state = status;
}
else
{
} else {
/* no service is added or removed. only updating status. */
bta_dm_conn_srvcs.conn_srvc[j].state = status;
}
@ -452,34 +433,26 @@ static void bta_dm_pm_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id,
/* stop timer */
bta_dm_pm_stop_timer(peer_addr);
if(p_dev)
{
if (p_dev) {
p_dev->pm_mode_attempted = 0;
p_dev->pm_mode_failed = 0;
}
#if (BTM_SSR_INCLUDED == TRUE)
if(p_bta_dm_ssr_spec[index].max_lat
if (p_bta_dm_ssr_spec[index].max_lat
#if (defined BTA_HH_INCLUDED && BTA_HH_INCLUDED == TRUE)
|| index == BTA_DM_PM_SSR_HH
#endif
)
{
) {
bta_dm_pm_ssr(peer_addr);
}
else
{
if( ((NULL != (p = BTM_ReadLocalFeatures ())) && HCI_SNIFF_SUB_RATE_SUPPORTED(p)) &&
} else {
if ( ((NULL != (p = BTM_ReadLocalFeatures ())) && HCI_SNIFF_SUB_RATE_SUPPORTED(p)) &&
((NULL != (p = BTM_ReadRemoteFeatures (peer_addr))) && HCI_SNIFF_SUB_RATE_SUPPORTED(p)) &&
(index == BTA_DM_PM_SSR0))
{
if (status == BTA_SYS_SCO_OPEN)
{
(index == BTA_DM_PM_SSR0)) {
if (status == BTA_SYS_SCO_OPEN) {
APPL_TRACE_DEBUG("%s: SCO inactive, reset SSR to zero", __func__);
BTM_SetSsrParams (peer_addr, 0,0,0 );
}
else if (status == BTA_SYS_SCO_CLOSE)
{
BTM_SetSsrParams (peer_addr, 0, 0, 0 );
} else if (status == BTA_SYS_SCO_CLOSE) {
APPL_TRACE_DEBUG("%s: SCO active, back to old SSR", __func__);
bta_dm_pm_ssr(peer_addr);
}
@ -496,13 +469,13 @@ static void bta_dm_pm_cback(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id,
*/
if ( BTM_IsDeviceUp() &&
( ((status == BTA_SYS_SCO_OPEN) || (status == BTA_SYS_SCO_CLOSE)) ||
((status == BTA_SYS_CONN_OPEN) && (id == BTA_ID_HH) && bta_dm_pm_is_sco_active()) ) )
{
((status == BTA_SYS_CONN_OPEN) && (id == BTA_ID_HH) && bta_dm_pm_is_sco_active()) ) ) {
BOOLEAN bScoActive;
if (status == BTA_SYS_CONN_OPEN)
if (status == BTA_SYS_CONN_OPEN) {
bScoActive = TRUE;
else
} else {
bScoActive = (status == BTA_SYS_SCO_OPEN);
}
bta_dm_pm_hid_check(bScoActive);
}
@ -527,7 +500,7 @@ static void bta_dm_pm_set_mode(BD_ADDR peer_addr, tBTA_DM_PM_ACTION pm_request,
tBTA_DM_PM_ACTION pm_action = BTA_DM_PM_NO_ACTION;
UINT16 timeout = 0;
UINT8 i,j;
UINT8 i, j;
tBTA_DM_PM_ACTION failed_pm = 0;
tBTA_DM_PEER_DEVICE *p_peer_device = NULL;
tBTA_DM_PM_ACTION allowed_modes = 0;
@ -540,32 +513,32 @@ static void bta_dm_pm_set_mode(BD_ADDR peer_addr, tBTA_DM_PM_ACTION pm_request,
UINT8 timer_idx, available_timer = BTA_DM_PM_MODE_TIMER_MAX;
UINT32 remaining_ticks = 0;
if(!bta_dm_cb.device_list.count)
if (!bta_dm_cb.device_list.count) {
return;
}
/* see if any attempt to put device in low power mode failed */
p_peer_device = bta_dm_find_peer_device(peer_addr);
/* if no peer device found return */
if (p_peer_device == NULL)
if (p_peer_device == NULL) {
return;
}
failed_pm = p_peer_device->pm_mode_failed;
for(i=0; i<bta_dm_conn_srvcs.count ; i++)
{
for (i = 0; i < bta_dm_conn_srvcs.count ; i++) {
p_srvcs = &bta_dm_conn_srvcs.conn_srvc[i];
if(!bdcmp(p_srvcs->peer_bdaddr, peer_addr))
{
if (!bdcmp(p_srvcs->peer_bdaddr, peer_addr)) {
/* p_bta_dm_pm_cfg[0].app_id is the number of entries */
for(j=1; j<=p_bta_dm_pm_cfg[0].app_id; j++)
{
if((p_bta_dm_pm_cfg[j].id == p_srvcs->id)
for (j = 1; j <= p_bta_dm_pm_cfg[0].app_id; j++) {
if ((p_bta_dm_pm_cfg[j].id == p_srvcs->id)
&& ((p_bta_dm_pm_cfg[j].app_id == BTA_ALL_APP_ID ) ||
(p_bta_dm_pm_cfg[j].app_id == p_srvcs->app_id)))
(p_bta_dm_pm_cfg[j].app_id == p_srvcs->app_id))) {
break;
}
}
p_pm_cfg = &p_bta_dm_pm_cfg[j];
p_pm_spec = &p_bta_dm_pm_spec[p_pm_cfg->spec_idx];
@ -578,28 +551,23 @@ static void bta_dm_pm_set_mode(BD_ADDR peer_addr, tBTA_DM_PM_ACTION pm_request,
/* PM actions are in the order of strictness */
/* first check if the first preference is ok */
if(!(failed_pm & p_act0->power_mode))
{
if (!(failed_pm & p_act0->power_mode)) {
pref_modes |= p_act0->power_mode;
if(p_act0->power_mode >= pm_action)
{
if (p_act0->power_mode >= pm_action) {
pm_action = p_act0->power_mode;
if (pm_req != BTA_DM_PM_NEW_REQ || p_srvcs->new_request)
{
if (pm_req != BTA_DM_PM_NEW_REQ || p_srvcs->new_request) {
p_srvcs->new_request = FALSE;
timeout = p_act0->timeout;
}
}
}
/* if first preference has already failed, try second preference */
else if(!(failed_pm & p_act1->power_mode))
{
else if (!(failed_pm & p_act1->power_mode)) {
pref_modes |= p_act1->power_mode;
if(p_act1->power_mode > pm_action)
{
if (p_act1->power_mode > pm_action) {
pm_action = p_act1->power_mode;
timeout = p_act1->timeout;
}
@ -607,35 +575,27 @@ static void bta_dm_pm_set_mode(BD_ADDR peer_addr, tBTA_DM_PM_ACTION pm_request,
}
}
if(pm_action & (BTA_DM_PM_PARK | BTA_DM_PM_SNIFF))
{
if (pm_action & (BTA_DM_PM_PARK | BTA_DM_PM_SNIFF)) {
/* some service don't like the mode */
if(!(allowed_modes & pm_action))
{
if (!(allowed_modes & pm_action)) {
/* select the other mode if its allowed and preferred, otherwise 0 which is BTA_DM_PM_NO_ACTION */
pm_action = (allowed_modes & (BTA_DM_PM_PARK | BTA_DM_PM_SNIFF) & pref_modes);
/* no timeout needed if no action is required */
if(pm_action == BTA_DM_PM_NO_ACTION)
{
if (pm_action == BTA_DM_PM_NO_ACTION) {
timeout = 0;
}
}
}
/* if need to start a timer */
if((pm_req != BTA_DM_PM_EXECUTE) && timeout)
{
for(i=0; i<BTA_DM_NUM_PM_TIMER; i++)
{
if(bta_dm_cb.pm_timer[i].in_use && bdcmp(bta_dm_cb.pm_timer[i].peer_bdaddr, peer_addr) == 0)
{
if ((timer_idx = bta_pm_action_to_timer_idx(pm_action)) != BTA_DM_PM_MODE_TIMER_MAX)
{
if ((pm_req != BTA_DM_PM_EXECUTE) && timeout) {
for (i = 0; i < BTA_DM_NUM_PM_TIMER; i++) {
if (bta_dm_cb.pm_timer[i].in_use && bdcmp(bta_dm_cb.pm_timer[i].peer_bdaddr, peer_addr) == 0) {
if ((timer_idx = bta_pm_action_to_timer_idx(pm_action)) != BTA_DM_PM_MODE_TIMER_MAX) {
remaining_ticks = bta_dm_pm_get_remaining_ticks(&bta_dm_cb.pm_timer[i].timer[timer_idx]);
if (remaining_ticks < timeout)
{
if (remaining_ticks < timeout) {
LOG_DEBUG("%s remain 0\n", __func__);
/* Cancel and restart the timer */
/*
@ -652,29 +612,24 @@ static void bta_dm_pm_set_mode(BD_ADDR peer_addr, tBTA_DM_PM_ACTION pm_request,
timer_started = TRUE;
}
break;
}
else if (!bta_dm_cb.pm_timer[i].in_use)
{
} else if (!bta_dm_cb.pm_timer[i].in_use) {
APPL_TRACE_DEBUG("%s dm_pm_timer:%d, %d", __func__, i, timeout);
if (available_timer == BTA_DM_PM_MODE_TIMER_MAX)
if (available_timer == BTA_DM_PM_MODE_TIMER_MAX) {
available_timer = i;
}
}
}
/* new power mode for a new active connection */
if (!timer_started)
{
if( available_timer != BTA_DM_PM_MODE_TIMER_MAX)
{
if (!timer_started) {
if ( available_timer != BTA_DM_PM_MODE_TIMER_MAX) {
bdcpy(bta_dm_cb.pm_timer[available_timer].peer_bdaddr, peer_addr);
if ((timer_idx = bta_pm_action_to_timer_idx(pm_action)) != BTA_DM_PM_MODE_TIMER_MAX)
{
if ((timer_idx = bta_pm_action_to_timer_idx(pm_action)) != BTA_DM_PM_MODE_TIMER_MAX) {
bta_dm_pm_start_timer(&bta_dm_cb.pm_timer[available_timer], timer_idx, timeout, p_srvcs->id, pm_action);
timer_started = TRUE;
}
}
/* no more timers */
else
{
else {
APPL_TRACE_WARNING("bta_dm_act dm_pm_timer no more");
}
}
@ -682,31 +637,22 @@ static void bta_dm_pm_set_mode(BD_ADDR peer_addr, tBTA_DM_PM_ACTION pm_request,
}
/* if pending power mode timer expires, and currecnt link is in a
lower power mode than current profile requirement, igonre it */
if (pm_req == BTA_DM_PM_EXECUTE && pm_request < pm_action)
{
if (pm_req == BTA_DM_PM_EXECUTE && pm_request < pm_action) {
APPL_TRACE_ERROR("Ignore the power mode request: %d", pm_request)
return;
}
if(pm_action == BTA_DM_PM_PARK)
{
if (pm_action == BTA_DM_PM_PARK) {
p_peer_device->pm_mode_attempted = BTA_DM_PM_PARK;
bta_dm_pm_park(peer_addr);
}
else if(pm_action & BTA_DM_PM_SNIFF)
{
} else if (pm_action & BTA_DM_PM_SNIFF) {
/* dont initiate SNIFF, if link_policy has it disabled */
if (p_peer_device->link_policy & HCI_ENABLE_SNIFF_MODE)
{
if (p_peer_device->link_policy & HCI_ENABLE_SNIFF_MODE) {
p_peer_device->pm_mode_attempted = BTA_DM_PM_SNIFF;
bta_dm_pm_sniff(p_peer_device, (UINT8)(pm_action & 0x0F) );
}
else
{
} else {
APPL_TRACE_DEBUG("bta_dm_pm_set_mode: Link policy disallows SNIFF, ignore request");
}
}
else if(pm_action == BTA_DM_PM_ACTIVE)
{
} else if (pm_action == BTA_DM_PM_ACTIVE) {
bta_dm_pm_active(peer_addr);
}
}
@ -728,8 +674,7 @@ static BOOLEAN bta_dm_pm_park(BD_ADDR peer_addr)
/* if not in park mode, switch to park */
BTM_ReadPowerMode(peer_addr, &mode);
if(mode != BTM_PM_MD_PARK)
{
if (mode != BTM_PM_MD_PARK) {
BTM_SetPowerMode (bta_dm_cb.pm_id, peer_addr, &p_bta_dm_pm_md[BTA_DM_PM_PARK_IDX]);
}
return TRUE;
@ -765,7 +710,7 @@ static BOOLEAN bta_dm_pm_sniff(tBTA_DM_PEER_DEVICE *p_peer_dev, UINT8 index)
!(p_peer_dev->info & BTA_DM_DI_USE_SSR)))
#else
APPL_TRACE_DEBUG("bta_dm_pm_sniff cur:%d, idx:%d", mode, index);
if(mode != BTM_PM_MD_SNIFF)
if (mode != BTM_PM_MD_SNIFF)
#endif
{
#if (BTM_SSR_INCLUDED == TRUE)
@ -773,8 +718,7 @@ static BOOLEAN bta_dm_pm_sniff(tBTA_DM_PEER_DEVICE *p_peer_dev, UINT8 index)
* remote sniff params. This avoid sniff loop issue with
* some agrresive headsets who use sniff latencies more than
* DUT supported range of Sniff intervals.*/
if ((mode == BTM_PM_MD_SNIFF) && (p_peer_dev->info & BTA_DM_DI_ACP_SNIFF))
{
if ((mode == BTM_PM_MD_SNIFF) && (p_peer_dev->info & BTA_DM_DI_ACP_SNIFF)) {
APPL_TRACE_DEBUG("%s: already in remote initiate sniff", __func__);
return TRUE;
}
@ -782,25 +726,19 @@ static BOOLEAN bta_dm_pm_sniff(tBTA_DM_PEER_DEVICE *p_peer_dev, UINT8 index)
/* if the current mode is not sniff, issue the sniff command.
* If sniff, but SSR is not used in this link, still issue the command */
memcpy(&pwr_md, &p_bta_dm_pm_md[index], sizeof (tBTM_PM_PWR_MD));
if (p_peer_dev->info & BTA_DM_DI_INT_SNIFF)
{
if (p_peer_dev->info & BTA_DM_DI_INT_SNIFF) {
pwr_md.mode |= BTM_PM_MD_FORCE;
}
status = BTM_SetPowerMode (bta_dm_cb.pm_id, p_peer_dev->peer_bdaddr, &pwr_md);
if (status == BTM_CMD_STORED|| status == BTM_CMD_STARTED)
{
p_peer_dev->info &= ~(BTA_DM_DI_INT_SNIFF|BTA_DM_DI_ACP_SNIFF);
if (status == BTM_CMD_STORED || status == BTM_CMD_STARTED) {
p_peer_dev->info &= ~(BTA_DM_DI_INT_SNIFF | BTA_DM_DI_ACP_SNIFF);
p_peer_dev->info |= BTA_DM_DI_SET_SNIFF;
}
else if (status == BTM_SUCCESS)
{
} else if (status == BTM_SUCCESS) {
APPL_TRACE_DEBUG("bta_dm_pm_sniff BTM_SetPowerMode() returns BTM_SUCCESS");
p_peer_dev->info &= ~(BTA_DM_DI_INT_SNIFF|BTA_DM_DI_ACP_SNIFF|BTA_DM_DI_SET_SNIFF);
}
else /* error */
{
p_peer_dev->info &= ~(BTA_DM_DI_INT_SNIFF | BTA_DM_DI_ACP_SNIFF | BTA_DM_DI_SET_SNIFF);
} else { /* error */
APPL_TRACE_ERROR("bta_dm_pm_sniff BTM_SetPowerMode() returns ERROR status=%d", status);
p_peer_dev->info &= ~(BTA_DM_DI_INT_SNIFF|BTA_DM_DI_ACP_SNIFF|BTA_DM_DI_SET_SNIFF);
p_peer_dev->info &= ~(BTA_DM_DI_INT_SNIFF | BTA_DM_DI_ACP_SNIFF | BTA_DM_DI_SET_SNIFF);
}
}
return TRUE;
@ -819,22 +757,18 @@ static BOOLEAN bta_dm_pm_sniff(tBTA_DM_PEER_DEVICE *p_peer_dev, UINT8 index)
static void bta_dm_pm_ssr(BD_ADDR peer_addr)
{
tBTA_DM_SSR_SPEC *p_spec, *p_spec_cur;
UINT8 i,j;
UINT8 i, j;
int ssr = BTA_DM_PM_SSR0;
/* go through the connected services */
for(i=0; i<bta_dm_conn_srvcs.count ; i++)
{
if(!bdcmp(bta_dm_conn_srvcs.conn_srvc[i].peer_bdaddr, peer_addr))
{
for (i = 0; i < bta_dm_conn_srvcs.count ; i++) {
if (!bdcmp(bta_dm_conn_srvcs.conn_srvc[i].peer_bdaddr, peer_addr)) {
/* p_bta_dm_pm_cfg[0].app_id is the number of entries */
for(j=1; j<=p_bta_dm_pm_cfg[0].app_id; j++)
{
for (j = 1; j <= p_bta_dm_pm_cfg[0].app_id; j++) {
/* find the associated p_bta_dm_pm_cfg */
if((p_bta_dm_pm_cfg[j].id == bta_dm_conn_srvcs.conn_srvc[i].id)
if ((p_bta_dm_pm_cfg[j].id == bta_dm_conn_srvcs.conn_srvc[i].id)
&& ((p_bta_dm_pm_cfg[j].app_id == BTA_ALL_APP_ID )
|| (p_bta_dm_pm_cfg[j].app_id == bta_dm_conn_srvcs.conn_srvc[i].app_id)))
{
|| (p_bta_dm_pm_cfg[j].app_id == bta_dm_conn_srvcs.conn_srvc[i].app_id))) {
APPL_TRACE_WARNING("bta_dm_pm_ssr conn_srvc id:%d, app_id:%d",
bta_dm_conn_srvcs.conn_srvc[i].id, bta_dm_conn_srvcs.conn_srvc[i].app_id);
break;
@ -847,15 +781,14 @@ static void bta_dm_pm_ssr(BD_ADDR peer_addr)
#if (defined BTA_HH_INCLUDED && BTA_HH_INCLUDED == TRUE)
/* HH has the per connection SSR preference, already read the SSR params from BTA HH */
if (p_bta_dm_pm_spec[p_bta_dm_pm_cfg[j].spec_idx].ssr == BTA_DM_PM_SSR_HH)
{
if (bta_hh_read_ssr_param(peer_addr, &p_spec_cur->max_lat, &p_spec_cur->min_rmt_to) == BTA_HH_ERR)
if (p_bta_dm_pm_spec[p_bta_dm_pm_cfg[j].spec_idx].ssr == BTA_DM_PM_SSR_HH) {
if (bta_hh_read_ssr_param(peer_addr, &p_spec_cur->max_lat, &p_spec_cur->min_rmt_to) == BTA_HH_ERR) {
continue;
}
}
#endif
if (p_spec_cur->max_lat < p_spec->max_lat ||
(ssr == BTA_DM_PM_SSR0 && p_bta_dm_pm_spec[p_bta_dm_pm_cfg[j].spec_idx].ssr != BTA_DM_PM_SSR0))
{
(ssr == BTA_DM_PM_SSR0 && p_bta_dm_pm_spec[p_bta_dm_pm_cfg[j].spec_idx].ssr != BTA_DM_PM_SSR0)) {
ssr = p_bta_dm_pm_spec[p_bta_dm_pm_cfg[j].spec_idx].ssr;
}
@ -864,8 +797,7 @@ static void bta_dm_pm_ssr(BD_ADDR peer_addr)
p_spec = &p_bta_dm_ssr_spec[ssr];
APPL_TRACE_WARNING("bta_dm_pm_ssr:%d, lat:%d", ssr, p_spec->max_lat);
if(p_spec->max_lat)
{
if (p_spec->max_lat) {
/* set the SSR parameters. */
BTM_SetSsrParams (peer_addr, p_spec->max_lat,
p_spec->min_rmt_to, p_spec->min_loc_to);
@ -886,7 +818,7 @@ void bta_dm_pm_active(BD_ADDR peer_addr)
{
tBTM_PM_PWR_MD pm;
memset( (void*)&pm, 0, sizeof(pm));
memset( (void *)&pm, 0, sizeof(pm));
/* switch to active mode */
pm.mode = BTM_PM_MD_ACTIVE;
@ -910,8 +842,7 @@ static void bta_dm_pm_btm_cback(BD_ADDR bd_addr, tBTM_PM_STATUS status, UINT16 v
{
tBTA_DM_PM_BTM_STATUS *p_buf;
if ((p_buf = (tBTA_DM_PM_BTM_STATUS *) GKI_getbuf(sizeof(tBTA_DM_PM_BTM_STATUS))) != NULL)
{
if ((p_buf = (tBTA_DM_PM_BTM_STATUS *) GKI_getbuf(sizeof(tBTA_DM_PM_BTM_STATUS))) != NULL) {
p_buf->hdr.event = BTA_DM_PM_BTM_STATUS_EVT;
p_buf->status = status;
p_buf->value = value;
@ -935,35 +866,33 @@ static void bta_dm_pm_timer_cback(void *p_tle)
{
UINT8 i, j;
for (i=0; i<BTA_DM_NUM_PM_TIMER; i++)
{
for (i = 0; i < BTA_DM_NUM_PM_TIMER; i++) {
APPL_TRACE_DEBUG("dm_pm_timer[%d] in use? %d", i, bta_dm_cb.pm_timer[i].in_use);
if (bta_dm_cb.pm_timer[i].in_use)
{
for (j = 0; j < BTA_DM_PM_MODE_TIMER_MAX; j++)
{
if(&bta_dm_cb.pm_timer[i].timer[j] == (TIMER_LIST_ENT*) p_tle)
{
if (bta_dm_cb.pm_timer[i].in_use) {
for (j = 0; j < BTA_DM_PM_MODE_TIMER_MAX; j++) {
if (&bta_dm_cb.pm_timer[i].timer[j] == (TIMER_LIST_ENT *) p_tle) {
bta_dm_cb.pm_timer[i].active --;
bta_dm_cb.pm_timer[i].srvc_id[j] = BTA_ID_MAX;
APPL_TRACE_DEBUG("dm_pm_timer[%d] expires, timer_idx=%d", i, j);
break;
}
}
if (bta_dm_cb.pm_timer[i].active == 0)
if (bta_dm_cb.pm_timer[i].active == 0) {
bta_dm_cb.pm_timer[i].in_use = FALSE;
if (j < BTA_DM_PM_MODE_TIMER_MAX)
}
if (j < BTA_DM_PM_MODE_TIMER_MAX) {
break;
}
}
}
/* no more timers */
if (i==BTA_DM_NUM_PM_TIMER)
if (i == BTA_DM_NUM_PM_TIMER) {
return;
}
tBTA_DM_PM_TIMER *p_buf = (tBTA_DM_PM_TIMER *) GKI_getbuf(sizeof(tBTA_DM_PM_TIMER));
if (p_buf != NULL)
{
if (p_buf != NULL) {
p_buf->hdr.event = BTA_DM_PM_TIMER_EVT;
p_buf->pm_request = bta_dm_cb.pm_timer[i].pm_action[j];
bdcpy(p_buf->bd_addr, bta_dm_cb.pm_timer[i].peer_bdaddr);
@ -986,34 +915,29 @@ void bta_dm_pm_btm_status(tBTA_DM_MSG *p_data)
APPL_TRACE_DEBUG("%s status: %d", __func__, p_data->pm_status.status);
tBTA_DM_PEER_DEVICE *p_dev = bta_dm_find_peer_device(p_data->pm_status.bd_addr);
if (NULL == p_dev)
if (NULL == p_dev) {
return;
}
tBTA_DM_DEV_INFO info = p_dev->info;
/* check new mode */
switch (p_data->pm_status.status)
{
switch (p_data->pm_status.status) {
case BTM_PM_STS_ACTIVE:
/* if our sniff or park attempt failed
we should not try it again*/
if (p_data->pm_status.hci_status != 0)
{
if (p_data->pm_status.hci_status != 0) {
APPL_TRACE_ERROR("%s hci_status=%d", __func__, p_data->pm_status.hci_status);
p_dev->info &= ~(BTA_DM_DI_INT_SNIFF|BTA_DM_DI_ACP_SNIFF|BTA_DM_DI_SET_SNIFF);
p_dev->info &= ~(BTA_DM_DI_INT_SNIFF | BTA_DM_DI_ACP_SNIFF | BTA_DM_DI_SET_SNIFF);
if(p_dev->pm_mode_attempted &(BTA_DM_PM_PARK | BTA_DM_PM_SNIFF))
{
if (p_dev->pm_mode_attempted & (BTA_DM_PM_PARK | BTA_DM_PM_SNIFF)) {
p_dev->pm_mode_failed
|= ((BTA_DM_PM_PARK | BTA_DM_PM_SNIFF) & p_dev->pm_mode_attempted);
bta_dm_pm_stop_timer_by_mode(p_data->pm_status.bd_addr, p_dev->pm_mode_attempted);
bta_dm_pm_set_mode(p_data->pm_status.bd_addr, BTA_DM_PM_NO_ACTION, BTA_DM_PM_RESTART);
}
}
else
{
} else {
#if (BTM_SSR_INCLUDED == TRUE)
if(p_dev->prev_low)
{
if (p_dev->prev_low) {
/* need to send the SSR paramaters to controller again */
bta_dm_pm_ssr(p_dev->peer_bdaddr);
}
@ -1031,20 +955,21 @@ void bta_dm_pm_btm_status(tBTA_DM_MSG *p_data)
/* save the previous low power mode - for SSR.
* SSR parameters are sent to controller on "conn open".
* the numbers stay good until park/hold/detach */
if(p_dev->info & BTA_DM_DI_USE_SSR)
if (p_dev->info & BTA_DM_DI_USE_SSR) {
p_dev->prev_low = p_data->pm_status.status;
}
break;
case BTM_PM_STS_SSR:
if(p_data->pm_status.value)
if (p_data->pm_status.value) {
p_dev->info |= BTA_DM_DI_USE_SSR;
else
} else {
p_dev->info &= ~BTA_DM_DI_USE_SSR;
}
break;
#endif
case BTM_PM_STS_SNIFF:
if (p_data->pm_status.hci_status == 0)
{
if (p_data->pm_status.hci_status == 0) {
/* Stop PM timer now if already active for
* particular device since link is already
* put in sniff mode by remote device, and
@ -1052,15 +977,14 @@ void bta_dm_pm_btm_status(tBTA_DM_MSG *p_data)
* in sniff mode from host side.
*/
bta_dm_pm_stop_timer(p_data->pm_status.bd_addr);
}
else
{
} else {
p_dev->info &= ~(BTA_DM_DI_SET_SNIFF | BTA_DM_DI_INT_SNIFF | BTA_DM_DI_ACP_SNIFF);
if (info & BTA_DM_DI_SET_SNIFF)
if (info & BTA_DM_DI_SET_SNIFF) {
p_dev->info |= BTA_DM_DI_INT_SNIFF;
else
} else {
p_dev->info |= BTA_DM_DI_ACP_SNIFF;
}
}
break;
case BTM_PM_STS_ERROR:
@ -1100,14 +1024,12 @@ void bta_dm_pm_timer(tBTA_DM_MSG *p_data)
** Returns tBTA_DM_PEER_DEVICE
**
*******************************************************************************/
tBTA_DM_PEER_DEVICE * bta_dm_find_peer_device(BD_ADDR peer_addr)
tBTA_DM_PEER_DEVICE *bta_dm_find_peer_device(BD_ADDR peer_addr)
{
tBTA_DM_PEER_DEVICE *p_dev = NULL;
for (int i=0; i<bta_dm_cb.device_list.count; i++)
{
if(!bdcmp( bta_dm_cb.device_list.peer_device[i].peer_bdaddr, peer_addr))
{
for (int i = 0; i < bta_dm_cb.device_list.count; i++) {
if (!bdcmp( bta_dm_cb.device_list.peer_device[i].peer_bdaddr, peer_addr)) {
p_dev = &bta_dm_cb.device_list.peer_device[i];
break;
}
@ -1130,11 +1052,9 @@ static BOOLEAN bta_dm_pm_is_sco_active ()
int j;
BOOLEAN bScoActive = FALSE;
for(j=0; j<bta_dm_conn_srvcs.count ; j++)
{
for (j = 0; j < bta_dm_conn_srvcs.count ; j++) {
/* check if an entry already present */
if ( (bta_dm_conn_srvcs.conn_srvc[j].id == BTA_ID_AG ) && (bta_dm_conn_srvcs.conn_srvc[j].state == BTA_SYS_SCO_OPEN) )
{
if ( (bta_dm_conn_srvcs.conn_srvc[j].id == BTA_ID_AG ) && (bta_dm_conn_srvcs.conn_srvc[j].state == BTA_SYS_SCO_OPEN) ) {
bScoActive = TRUE;
break;
}
@ -1160,11 +1080,9 @@ static void bta_dm_pm_hid_check(BOOLEAN bScoActive)
int j;
/* if HID is active, disable the link policy */
for(j=0; j<bta_dm_conn_srvcs.count ; j++)
{
for (j = 0; j < bta_dm_conn_srvcs.count ; j++) {
/* check if an entry already present */
if(bta_dm_conn_srvcs.conn_srvc[j].id == BTA_ID_HH )
{
if (bta_dm_conn_srvcs.conn_srvc[j].id == BTA_ID_HH ) {
APPL_TRACE_DEBUG ("SCO status change(Active: %d), modify HID link policy. state: %d",
bScoActive, bta_dm_conn_srvcs.conn_srvc[j].state);
bta_dm_pm_set_sniff_policy( bta_dm_find_peer_device(bta_dm_conn_srvcs.conn_srvc[j].peer_bdaddr), bScoActive);
@ -1191,26 +1109,25 @@ static void bta_dm_pm_set_sniff_policy(tBTA_DM_PEER_DEVICE *p_dev, BOOLEAN bDisa
{
UINT16 policy_setting;
if (!p_dev)
if (!p_dev) {
return;
}
if (bDisable)
{
if (bDisable) {
policy_setting = bta_dm_cb.cur_policy &
(HCI_ENABLE_MASTER_SLAVE_SWITCH |
HCI_ENABLE_HOLD_MODE |
HCI_ENABLE_PARK_MODE);
}
else
{
} else {
/* allow sniff after sco is closed */
policy_setting= bta_dm_cb.cur_policy;
policy_setting = bta_dm_cb.cur_policy;
}
/* if disabling SNIFF, make sure link is Active */
if (bDisable)
if (bDisable) {
bta_dm_pm_active(p_dev->peer_bdaddr);
}
/* update device record and set link policy */
p_dev->link_policy = policy_setting;

114
components/bt/bluedroid/bta/dm/bta_dm_sco.c Executable file → Normal file
View file

@ -49,11 +49,10 @@
*****************************************************************************/
typedef INT32 (*PCONVERT_TO_BT_FILTERED) (UINT8 *pSrc, void *pDst, UINT32 dwSrcSamples,
UINT32 dwSrcSps,INT32 *pLastCurPos, UINT8 *pOverlapArea);
UINT32 dwSrcSps, INT32 *pLastCurPos, UINT8 *pOverlapArea);
typedef INT32 (*PCONVERT_TO_BT_NOFILTER) (void *pSrc, void *pDst, UINT32 dwSrcSamples,
UINT32 dwSrcSps);
typedef struct
{
typedef struct {
UINT8 overlap_area[BTA_DM_PCM_OVERLAP_SIZE * 4];
UINT32 cur_pos; /* current position */
UINT32 src_sps; /* samples per second (source audio data) */
@ -258,18 +257,13 @@ INT32 Convert_8M_ToBT_Filtered (UINT8 *pSrc, void *pDst, UINT32 dwSrcSamples,
pInEnd = (SRC_TYPE *)(pSrc + (dwSrcSamples * SRC_CHANNELS * sizeof (SRC_TYPE)) - \
BTA_DM_PCM_OVERLAP_SIZE);
if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_44100)
{
if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_44100) {
CONVERT_44100_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_44100_TO_BLUETOOTH(pIn, pInEnd);
}
else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_22050)
{
} else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_22050) {
CONVERT_22050_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_22050_TO_BLUETOOTH(pIn, pInEnd);
}
else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_11025)
{
} else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_11025) {
CONVERT_11025_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_11025_TO_BLUETOOTH(pIn, pInEnd);
}
@ -293,14 +287,12 @@ INT32 Convert_8M_ToBT_NoFilter (void *pSrc, void *pDst, UINT32 dwSrcSamples, UIN
//
CurrentPos = (dwSrcSps >> 1);
while (dwSrcSamples--)
{
while (dwSrcSamples--) {
CurrentPos -= 8000;
if (CurrentPos >= 0)
if (CurrentPos >= 0) {
pbSrc++;
else
{
} else {
sWorker = *pbSrc++;
sWorker -= 0x80;
sWorker <<= 8;
@ -341,18 +333,13 @@ INT32 Convert_16M_ToBT_Filtered (UINT8 *pSrc, void *pDst, UINT32 dwSrcSamples,
pIn = (SRC_TYPE *)(pSrc + BTA_DM_PCM_OVERLAP_SIZE);
pInEnd = (SRC_TYPE *)(pSrc + (dwSrcSamples * SRC_CHANNELS * sizeof (SRC_TYPE)) - BTA_DM_PCM_OVERLAP_SIZE);
if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_44100)
{
if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_44100) {
CONVERT_44100_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_44100_TO_BLUETOOTH(pIn, pInEnd);
}
else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_22050)
{
} else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_22050) {
CONVERT_22050_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_22050_TO_BLUETOOTH(pIn, pInEnd);
}
else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_11025)
{
} else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_11025) {
CONVERT_11025_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_11025_TO_BLUETOOTH(pIn, pInEnd);
}
@ -375,14 +362,12 @@ INT32 Convert_16M_ToBT_NoFilter (void *pSrc, void *pDst, UINT32 dwSrcSamples, UI
//
CurrentPos = (dwSrcSps >> 1);
while (dwSrcSamples--)
{
while (dwSrcSamples--) {
CurrentPos -= 8000;
if (CurrentPos >= 0)
if (CurrentPos >= 0) {
psSrc++;
else
{
} else {
*psDst++ = *psSrc++;
CurrentPos += dwSrcSps;
@ -423,18 +408,13 @@ INT32 Convert_8S_ToBT_Filtered (UINT8 *pSrc, void *pDst, UINT32 dwSrcSamples,
pIn = (SRC_TYPE *)(pSrc + BTA_DM_PCM_OVERLAP_SIZE);
pInEnd = (SRC_TYPE *)(pSrc + (dwSrcSamples * SRC_CHANNELS * sizeof (SRC_TYPE)) - BTA_DM_PCM_OVERLAP_SIZE);
if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_44100)
{
if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_44100) {
CONVERT_44100_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_44100_TO_BLUETOOTH(pIn, pInEnd);
}
else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_22050)
{
} else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_22050) {
CONVERT_22050_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_22050_TO_BLUETOOTH(pIn, pInEnd);
}
else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_11025)
{
} else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_11025) {
CONVERT_11025_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_11025_TO_BLUETOOTH(pIn, pInEnd);
}
@ -458,14 +438,12 @@ INT32 Convert_8S_ToBT_NoFilter (void *pSrc, void *pDst, UINT32 dwSrcSamples, UIN
//
CurrentPos = (dwSrcSps >> 1);
while (dwSrcSamples--)
{
while (dwSrcSamples--) {
CurrentPos -= 8000;
if (CurrentPos >= 0)
if (CurrentPos >= 0) {
pbSrc += 2;
else
{
} else {
sWorker = *(unsigned char *)pbSrc;
sWorker -= 0x80;
sWorker <<= 8;
@ -515,18 +493,13 @@ INT32 Convert_16S_ToBT_Filtered (UINT8 *pSrc, void *pDst, UINT32 dwSrcSamples,
pIn = (SRC_TYPE *)(pSrc + BTA_DM_PCM_OVERLAP_SIZE);
pInEnd = (SRC_TYPE *)(pSrc + (dwSrcSamples * SRC_CHANNELS * sizeof (SRC_TYPE)) - BTA_DM_PCM_OVERLAP_SIZE);
if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_44100)
{
if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_44100) {
CONVERT_44100_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_44100_TO_BLUETOOTH(pIn, pInEnd);
}
else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_22050)
{
} else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_22050) {
CONVERT_22050_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_22050_TO_BLUETOOTH(pIn, pInEnd);
}
else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_11025)
{
} else if (dwSrcSps == BTA_DM_PCM_SMPL_RATE_11025) {
CONVERT_11025_TO_BLUETOOTH(pOv, pOvEnd);
CONVERT_11025_TO_BLUETOOTH(pIn, pInEnd);
}
@ -550,14 +523,12 @@ INT32 Convert_16S_ToBT_NoFilter (void *pSrc, void *pDst, UINT32 dwSrcSamples, UI
//
CurrentPos = (dwSrcSps >> 1);
while (dwSrcSamples--)
{
while (dwSrcSamples--) {
CurrentPos -= 8000;
if (CurrentPos >= 0)
if (CurrentPos >= 0) {
psSrc += 2;
else
{
} else {
/* CR 82894, to avoid overflow, divide before add */
sWorker = ((*psSrc) >> 1 );
psSrc++;
@ -602,39 +573,31 @@ void BTA_DmPcmInitSamples (UINT32 src_sps, UINT32 bits, UINT32 n_channels)
if ((src_sps == BTA_DM_PCM_SMPL_RATE_44100) ||
(src_sps == BTA_DM_PCM_SMPL_RATE_22050) ||
(src_sps == BTA_DM_PCM_SMPL_RATE_11025))
(src_sps == BTA_DM_PCM_SMPL_RATE_11025)) {
p_cb->can_be_filtered = 1;
else
} else {
p_cb->can_be_filtered = 0;
}
#if BTA_DM_SCO_DEBUG
APPL_TRACE_DEBUG("bta_dm_pcm_init_samples: n_channels = %d bits = %d", n_channels, bits);
#endif
if(n_channels == 1)
{
if (n_channels == 1) {
/* mono */
if(bits == 8)
{
if (bits == 8) {
p_cb->filter = (PCONVERT_TO_BT_FILTERED) Convert_8M_ToBT_Filtered;
p_cb->nofilter = (PCONVERT_TO_BT_NOFILTER) Convert_8M_ToBT_NoFilter;
p_cb->divisor = 1;
}
else
{
} else {
p_cb->filter = (PCONVERT_TO_BT_FILTERED) Convert_16M_ToBT_Filtered;
p_cb->nofilter = (PCONVERT_TO_BT_NOFILTER) Convert_16M_ToBT_NoFilter;
}
}
else
{
} else {
/* stereo */
if(bits == 8)
{
if (bits == 8) {
p_cb->filter = (PCONVERT_TO_BT_FILTERED) Convert_8S_ToBT_Filtered;
p_cb->nofilter = (PCONVERT_TO_BT_NOFILTER) Convert_8S_ToBT_NoFilter;
}
else
{
} else {
p_cb->filter = (PCONVERT_TO_BT_FILTERED) Convert_16S_ToBT_Filtered;
p_cb->nofilter = (PCONVERT_TO_BT_NOFILTER) Convert_16S_ToBT_NoFilter;
p_cb->divisor = 4;
@ -675,13 +638,10 @@ INT32 BTA_DmPcmResample (void *p_src, UINT32 in_bytes, void *p_dst)
#if BTA_DM_SCO_DEBUG
APPL_TRACE_DEBUG("bta_pcm_resample : insamples %d", (in_bytes / bta_dm_pcm_cb.divisor));
#endif
if(bta_dm_pcm_cb.can_be_filtered)
{
if (bta_dm_pcm_cb.can_be_filtered) {
out_sample = (*bta_dm_pcm_cb.filter) (p_src, p_dst, (in_bytes / bta_dm_pcm_cb.divisor),
bta_dm_pcm_cb.src_sps, (INT32 *) &bta_dm_pcm_cb.cur_pos, bta_dm_pcm_cb.overlap_area);
}
else
{
} else {
out_sample = (*bta_dm_pcm_cb.nofilter) (p_src, p_dst,
(in_bytes / bta_dm_pcm_cb.divisor), bta_dm_pcm_cb.src_sps);
}

746
components/bt/bluedroid/bta/gatt/bta_gattc_act.c Executable file → Normal file

File diff suppressed because it is too large Load diff

186
components/bt/bluedroid/bta/gatt/bta_gattc_api.c Executable file → Normal file
View file

@ -36,8 +36,7 @@
** Constants
*****************************************************************************/
static const tBTA_SYS_REG bta_gattc_reg =
{
static const tBTA_SYS_REG bta_gattc_reg = {
bta_gattc_hdl_event,
BTA_GATTC_Disable
};
@ -58,13 +57,11 @@ void BTA_GATTC_Disable(void)
{
BT_HDR *p_buf;
if (bta_sys_is_register(BTA_ID_GATTC) == FALSE)
{
if (bta_sys_is_register(BTA_ID_GATTC) == FALSE) {
APPL_TRACE_WARNING("GATTC Module not enabled/already disabled\n");
return;
}
if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
{
if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
p_buf->event = BTA_GATTC_API_DISABLE_EVT;
bta_sys_sendmsg(p_buf);
}
@ -89,16 +86,15 @@ void BTA_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_client_cb)
{
tBTA_GATTC_API_REG *p_buf;
if (bta_sys_is_register(BTA_ID_GATTC) == FALSE)
{
if (bta_sys_is_register(BTA_ID_GATTC) == FALSE) {
bta_sys_register(BTA_ID_GATTC, &bta_gattc_reg);
}
if ((p_buf = (tBTA_GATTC_API_REG *) GKI_getbuf(sizeof(tBTA_GATTC_API_REG))) != NULL)
{
if ((p_buf = (tBTA_GATTC_API_REG *) GKI_getbuf(sizeof(tBTA_GATTC_API_REG))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_REG_EVT;
if (p_app_uuid != NULL)
if (p_app_uuid != NULL) {
memcpy(&p_buf->app_uuid, p_app_uuid, sizeof(tBT_UUID));
}
p_buf->p_cback = p_client_cb;
bta_sys_sendmsg(p_buf);
@ -122,8 +118,7 @@ void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if)
{
tBTA_GATTC_API_DEREG *p_buf;
if ((p_buf = (tBTA_GATTC_API_DEREG *) GKI_getbuf(sizeof(tBTA_GATTC_API_DEREG))) != NULL)
{
if ((p_buf = (tBTA_GATTC_API_DEREG *) GKI_getbuf(sizeof(tBTA_GATTC_API_DEREG))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_DEREG_EVT;
p_buf->client_if = client_if;
bta_sys_sendmsg(p_buf);
@ -151,8 +146,7 @@ void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda,
{
tBTA_GATTC_API_OPEN *p_buf;
if ((p_buf = (tBTA_GATTC_API_OPEN *) GKI_getbuf(sizeof(tBTA_GATTC_API_OPEN))) != NULL)
{
if ((p_buf = (tBTA_GATTC_API_OPEN *) GKI_getbuf(sizeof(tBTA_GATTC_API_OPEN))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_OPEN_EVT;
p_buf->client_if = client_if;
@ -184,8 +178,7 @@ void BTA_GATTC_CancelOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN i
{
tBTA_GATTC_API_CANCEL_OPEN *p_buf;
if ((p_buf = (tBTA_GATTC_API_CANCEL_OPEN *) GKI_getbuf(sizeof(tBTA_GATTC_API_CANCEL_OPEN))) != NULL)
{
if ((p_buf = (tBTA_GATTC_API_CANCEL_OPEN *) GKI_getbuf(sizeof(tBTA_GATTC_API_CANCEL_OPEN))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_CANCEL_OPEN_EVT;
p_buf->client_if = client_if;
@ -212,8 +205,7 @@ void BTA_GATTC_Close(UINT16 conn_id)
{
BT_HDR *p_buf;
if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
{
if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
p_buf->event = BTA_GATTC_API_CLOSE_EVT;
p_buf->layer_specific = conn_id;
@ -240,8 +232,7 @@ void BTA_GATTC_ConfigureMTU (UINT16 conn_id, UINT16 mtu)
{
tBTA_GATTC_API_CFG_MTU *p_buf;
if ((p_buf = (tBTA_GATTC_API_CFG_MTU *) GKI_getbuf(sizeof(tBTA_GATTC_API_CFG_MTU))) != NULL)
{
if ((p_buf = (tBTA_GATTC_API_CFG_MTU *) GKI_getbuf(sizeof(tBTA_GATTC_API_CFG_MTU))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_CFG_MTU_EVT;
p_buf->hdr.layer_specific = conn_id;
@ -272,20 +263,18 @@ void BTA_GATTC_ServiceSearchRequest (UINT16 conn_id, tBT_UUID *p_srvc_uuid)
tBTA_GATTC_API_SEARCH *p_buf;
UINT16 len = sizeof(tBTA_GATTC_API_SEARCH) + sizeof(tBT_UUID);
if ((p_buf = (tBTA_GATTC_API_SEARCH *) GKI_getbuf(len)) != NULL)
{
if ((p_buf = (tBTA_GATTC_API_SEARCH *) GKI_getbuf(len)) != NULL) {
memset(p_buf, 0, len);
p_buf->hdr.event = BTA_GATTC_API_SEARCH_EVT;
p_buf->hdr.layer_specific = conn_id;
if (p_srvc_uuid)
{
if (p_srvc_uuid) {
p_buf->p_srvc_uuid = (tBT_UUID *)(p_buf + 1);
memcpy(p_buf->p_srvc_uuid, p_srvc_uuid, sizeof(tBT_UUID));
}
else
} else {
p_buf->p_srvc_uuid = NULL;
}
bta_sys_sendmsg(p_buf);
}
@ -318,13 +307,13 @@ tBTA_GATT_STATUS BTA_GATTC_GetFirstChar (UINT16 conn_id, tBTA_GATT_SRVC_ID *p_s
{
tBTA_GATT_STATUS status;
if (!p_srvc_id || !p_char_result)
if (!p_srvc_id || !p_char_result) {
return BTA_GATT_ILLEGAL_PARAMETER;
}
if ((status = bta_gattc_query_cache(conn_id, BTA_GATTC_ATTR_TYPE_CHAR, p_srvc_id, NULL,
p_char_uuid_cond, &p_char_result->char_id, (void *)p_property))
== BTA_GATT_OK)
{
== BTA_GATT_OK) {
memcpy(&p_char_result->srvc_id, p_srvc_id, sizeof(tBTA_GATT_SRVC_ID));
}
@ -358,8 +347,9 @@ tBTA_GATT_STATUS BTA_GATTC_GetNextChar (UINT16 conn_id,
{
tBTA_GATT_STATUS status;
if (!p_start_char_id || !p_char_result)
if (!p_start_char_id || !p_char_result) {
return BTA_GATT_ILLEGAL_PARAMETER;
}
if ((status = bta_gattc_query_cache(conn_id, BTA_GATTC_ATTR_TYPE_CHAR,
&p_start_char_id->srvc_id,
@ -367,8 +357,7 @@ tBTA_GATT_STATUS BTA_GATTC_GetNextChar (UINT16 conn_id,
p_char_uuid_cond,
&p_char_result->char_id,
(void *) p_property))
== BTA_GATT_OK)
{
== BTA_GATT_OK) {
memcpy(&p_char_result->srvc_id, &p_start_char_id->srvc_id, sizeof(tBTA_GATT_SRVC_ID));
}
@ -398,8 +387,9 @@ tBTA_GATT_STATUS BTA_GATTC_GetFirstCharDescr (UINT16 conn_id, tBTA_GATTC_CHAR_I
{
tBTA_GATT_STATUS status;
if (!p_char_id || !p_descr_result)
if (!p_char_id || !p_descr_result) {
return BTA_GATT_ILLEGAL_PARAMETER;
}
memset(p_descr_result, 0, sizeof(tBTA_GATTC_CHAR_DESCR_ID));
@ -410,8 +400,7 @@ tBTA_GATT_STATUS BTA_GATTC_GetFirstCharDescr (UINT16 conn_id, tBTA_GATTC_CHAR_I
p_descr_uuid_cond,
&p_descr_result->char_id.char_id,
NULL))
== BTA_GATT_OK)
{
== BTA_GATT_OK) {
memcpy(&p_descr_result->descr_id, &p_descr_result->char_id.char_id, sizeof(tBTA_GATT_ID));
memcpy(&p_descr_result->char_id, p_char_id, sizeof(tBTA_GATTC_CHAR_ID));
}
@ -443,8 +432,9 @@ tBTA_GATT_STATUS BTA_GATTC_GetNextCharDescr (UINT16 conn_id,
{
tBTA_GATT_STATUS status;
if (!p_start_descr_id || !p_descr_result)
if (!p_start_descr_id || !p_descr_result) {
return BTA_GATT_ILLEGAL_PARAMETER;
}
memset(p_descr_result, 0, sizeof(tBTA_GATTC_CHAR_DESCR_ID));
@ -454,8 +444,7 @@ tBTA_GATT_STATUS BTA_GATTC_GetNextCharDescr (UINT16 conn_id,
p_descr_uuid_cond,
&p_descr_result->char_id.char_id,
(void *)&p_start_descr_id->descr_id))
== BTA_GATT_OK)
{
== BTA_GATT_OK) {
memcpy(&p_descr_result->descr_id, &p_descr_result->char_id.char_id, sizeof(tBTA_GATT_ID));
memcpy(&p_descr_result->char_id, p_start_descr_id, sizeof(tBTA_GATTC_CHAR_ID));
}
@ -486,8 +475,9 @@ tBTA_GATT_STATUS BTA_GATTC_GetFirstIncludedService(UINT16 conn_id, tBTA_GATT_SR
{
tBTA_GATT_STATUS status;
if (!p_srvc_id || !p_result)
if (!p_srvc_id || !p_result) {
return BTA_GATT_ILLEGAL_PARAMETER;
}
if ((status = bta_gattc_query_cache(conn_id,
BTA_GATTC_ATTR_TYPE_INCL_SRVC,
@ -496,8 +486,7 @@ tBTA_GATT_STATUS BTA_GATTC_GetFirstIncludedService(UINT16 conn_id, tBTA_GATT_SR
p_uuid_cond,
&p_result->incl_svc_id.id,
(void *)&p_result->incl_svc_id.is_primary))
== BTA_GATT_OK)
{
== BTA_GATT_OK) {
memcpy(&p_result->srvc_id, p_srvc_id, sizeof(tBTA_GATT_SRVC_ID));
}
@ -528,8 +517,9 @@ tBTA_GATT_STATUS BTA_GATTC_GetNextIncludedService(UINT16 conn_id,
{
tBTA_GATT_STATUS status;
if (!p_start_id || !p_result)
if (!p_start_id || !p_result) {
return BTA_GATT_ILLEGAL_PARAMETER;
}
if ((status = bta_gattc_query_cache(conn_id,
BTA_GATTC_ATTR_TYPE_INCL_SRVC,
@ -538,8 +528,7 @@ tBTA_GATT_STATUS BTA_GATTC_GetNextIncludedService(UINT16 conn_id,
p_uuid_cond,
&p_result->incl_svc_id.id,
(void *)&p_result->incl_svc_id.is_primary))
== BTA_GATT_OK)
{
== BTA_GATT_OK) {
memcpy(&p_result->srvc_id, &p_start_id->srvc_id, sizeof(tBTA_GATT_SRVC_ID));
}
@ -564,8 +553,7 @@ void BTA_GATTC_ReadCharacteristic(UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id,
{
tBTA_GATTC_API_READ *p_buf;
if ((p_buf = (tBTA_GATTC_API_READ *) GKI_getbuf(sizeof(tBTA_GATTC_API_READ))) != NULL)
{
if ((p_buf = (tBTA_GATTC_API_READ *) GKI_getbuf(sizeof(tBTA_GATTC_API_READ))) != NULL) {
memset(p_buf, 0, sizeof(tBTA_GATTC_API_READ));
p_buf->hdr.event = BTA_GATTC_API_READ_EVT;
@ -600,8 +588,7 @@ void BTA_GATTC_ReadCharDescr (UINT16 conn_id,
tBTA_GATTC_API_READ *p_buf;
UINT16 len = (UINT16)(sizeof(tBTA_GATT_ID) + sizeof(tBTA_GATTC_API_READ));
if ((p_buf = (tBTA_GATTC_API_READ *) GKI_getbuf(len)) != NULL)
{
if ((p_buf = (tBTA_GATTC_API_READ *) GKI_getbuf(len)) != NULL) {
memset(p_buf, 0, sizeof(tBTA_GATTC_API_READ));
p_buf->hdr.event = BTA_GATTC_API_READ_EVT;
@ -641,8 +628,7 @@ void BTA_GATTC_ReadMultiple(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi,
p_read_multi->num_attr * sizeof(tBTA_GATTC_ATTR_ID));
UINT8 i;
if ((p_buf = (tBTA_GATTC_API_READ_MULTI *) GKI_getbuf(len)) != NULL)
{
if ((p_buf = (tBTA_GATTC_API_READ_MULTI *) GKI_getbuf(len)) != NULL) {
memset(p_buf, 0, len);
p_buf->hdr.event = BTA_GATTC_API_READ_MULTI_EVT;
@ -651,12 +637,10 @@ void BTA_GATTC_ReadMultiple(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_multi,
p_buf->num_attr = p_read_multi->num_attr;
if (p_buf->num_attr > 0)
{
if (p_buf->num_attr > 0) {
p_buf->p_id_list = p_value = (tBTA_GATTC_ATTR_ID *)(p_buf + 1);
for (i = 0; i < p_buf->num_attr; i ++, p_value ++)
{
for (i = 0; i < p_buf->num_attr; i ++, p_value ++) {
memcpy(p_value, &p_read_multi->id_list[i], sizeof(tBTA_GATTC_ATTR_ID));
}
}
@ -690,8 +674,7 @@ void BTA_GATTC_WriteCharValue ( UINT16 conn_id,
{
tBTA_GATTC_API_WRITE *p_buf;
if ((p_buf = (tBTA_GATTC_API_WRITE *) GKI_getbuf((UINT16)(sizeof(tBTA_GATTC_API_WRITE) + len))) != NULL)
{
if ((p_buf = (tBTA_GATTC_API_WRITE *) GKI_getbuf((UINT16)(sizeof(tBTA_GATTC_API_WRITE) + len))) != NULL) {
memset(p_buf, 0, sizeof(tBTA_GATTC_API_WRITE) + len);
p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT;
@ -704,8 +687,7 @@ void BTA_GATTC_WriteCharValue ( UINT16 conn_id,
p_buf->write_type = write_type;
p_buf->len = len;
if (p_value && len > 0)
{
if (p_value && len > 0) {
p_buf->p_value = (UINT8 *)(p_buf + 1);
memcpy(p_buf->p_value, p_value, len);
}
@ -737,11 +719,11 @@ void BTA_GATTC_WriteCharDescr (UINT16 conn_id,
tBTA_GATTC_API_WRITE *p_buf;
UINT16 len = sizeof(tBTA_GATTC_API_WRITE) + sizeof(tBTA_GATT_ID);
if (p_data != NULL)
if (p_data != NULL) {
len += p_data->len;
}
if ((p_buf = (tBTA_GATTC_API_WRITE *) GKI_getbuf(len)) != NULL)
{
if ((p_buf = (tBTA_GATTC_API_WRITE *) GKI_getbuf(len)) != NULL) {
memset(p_buf, 0, len);
p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT;
@ -754,8 +736,7 @@ void BTA_GATTC_WriteCharDescr (UINT16 conn_id,
memcpy(p_buf->p_descr_type, &p_char_descr_id->descr_id, sizeof(tBTA_GATT_ID));
p_buf->write_type = write_type;
if (p_data && p_data->len != 0)
{
if (p_data && p_data->len != 0) {
p_buf->p_value = (UINT8 *)(p_buf->p_descr_type + 1);
p_buf->len = p_data->len;
/* pack the descr data */
@ -788,8 +769,7 @@ void BTA_GATTC_PrepareWrite (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id,
{
tBTA_GATTC_API_WRITE *p_buf;
if ((p_buf = (tBTA_GATTC_API_WRITE *) GKI_getbuf((UINT16)(sizeof(tBTA_GATTC_API_WRITE) + len))) != NULL)
{
if ((p_buf = (tBTA_GATTC_API_WRITE *) GKI_getbuf((UINT16)(sizeof(tBTA_GATTC_API_WRITE) + len))) != NULL) {
memset(p_buf, 0, sizeof(tBTA_GATTC_API_WRITE) + len);
p_buf->hdr.event = BTA_GATTC_API_WRITE_EVT;
@ -803,8 +783,7 @@ void BTA_GATTC_PrepareWrite (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id,
p_buf->offset = offset;
p_buf->len = len;
if (p_value && len > 0)
{
if (p_value && len > 0) {
p_buf->p_value = (UINT8 *)(p_buf + 1);
memcpy(p_buf->p_value, p_value, len);
}
@ -830,8 +809,7 @@ void BTA_GATTC_ExecuteWrite (UINT16 conn_id, BOOLEAN is_execute)
{
tBTA_GATTC_API_EXEC *p_buf;
if ((p_buf = (tBTA_GATTC_API_EXEC *) GKI_getbuf((UINT16)sizeof(tBTA_GATTC_API_EXEC))) != NULL)
{
if ((p_buf = (tBTA_GATTC_API_EXEC *) GKI_getbuf((UINT16)sizeof(tBTA_GATTC_API_EXEC))) != NULL) {
memset(p_buf, 0, sizeof(tBTA_GATTC_API_EXEC));
p_buf->hdr.event = BTA_GATTC_API_EXEC_EVT;
@ -863,8 +841,7 @@ void BTA_GATTC_SendIndConfirm (UINT16 conn_id, tBTA_GATTC_CHAR_ID *p_char_id)
APPL_TRACE_API("BTA_GATTC_SendIndConfirm conn_id=%d service uuid1=0x%x char uuid=0x%x",
conn_id, p_char_id->srvc_id.id.uuid.uu.uuid16, p_char_id->char_id.uuid.uu.uuid16);
if ((p_buf = (tBTA_GATTC_API_CONFIRM *) GKI_getbuf(sizeof(tBTA_GATTC_API_CONFIRM))) != NULL)
{
if ((p_buf = (tBTA_GATTC_API_CONFIRM *) GKI_getbuf(sizeof(tBTA_GATTC_API_CONFIRM))) != NULL) {
memset(p_buf, 0, sizeof(tBTA_GATTC_API_CONFIRM));
p_buf->hdr.event = BTA_GATTC_API_CONFIRM_EVT;
@ -900,31 +877,24 @@ tBTA_GATT_STATUS BTA_GATTC_RegisterForNotifications (tBTA_GATTC_IF client_if,
tBTA_GATT_STATUS status = BTA_GATT_ILLEGAL_PARAMETER;
UINT8 i;
if (!p_char_id)
{
if (!p_char_id) {
APPL_TRACE_ERROR("deregistration failed, unknow char id");
return status;
}
if ((p_clreg = bta_gattc_cl_get_regcb(client_if)) != NULL)
{
for (i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++)
{
if ((p_clreg = bta_gattc_cl_get_regcb(client_if)) != NULL) {
for (i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++) {
if ( p_clreg->notif_reg[i].in_use &&
!memcmp(p_clreg->notif_reg[i].remote_bda, bda, BD_ADDR_LEN) &&
bta_gattc_charid_compare(&p_clreg->notif_reg[i].char_id, p_char_id))
{
bta_gattc_charid_compare(&p_clreg->notif_reg[i].char_id, p_char_id)) {
APPL_TRACE_WARNING("notification already registered");
status = BTA_GATT_OK;
break;
}
}
if (status != BTA_GATT_OK)
{
for (i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++)
{
if (!p_clreg->notif_reg[i].in_use)
{
if (status != BTA_GATT_OK) {
for (i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++) {
if (!p_clreg->notif_reg[i].in_use) {
memset((void *)&p_clreg->notif_reg[i], 0, sizeof(tBTA_GATTC_NOTIF_REG));
p_clreg->notif_reg[i].in_use = TRUE;
@ -938,15 +908,12 @@ tBTA_GATT_STATUS BTA_GATTC_RegisterForNotifications (tBTA_GATTC_IF client_if,
break;
}
}
if (i == BTA_GATTC_NOTIF_REG_MAX)
{
if (i == BTA_GATTC_NOTIF_REG_MAX) {
status = BTA_GATT_NO_RESOURCES;
APPL_TRACE_ERROR("Max Notification Reached, registration failed.");
}
}
}
else
{
} else {
APPL_TRACE_ERROR("Client_if: %d Not Registered", client_if);
}
@ -974,20 +941,16 @@ tBTA_GATT_STATUS BTA_GATTC_DeregisterForNotifications (tBTA_GATTC_IF client_if,
tBTA_GATT_STATUS status = BTA_GATT_ILLEGAL_PARAMETER;
UINT8 i;
if (!p_char_id)
{
if (!p_char_id) {
APPL_TRACE_ERROR("%s deregistration failed, unknown char id", __func__);
return status;
}
if ((p_clreg = bta_gattc_cl_get_regcb(client_if)) != NULL)
{
for (i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++)
{
if ((p_clreg = bta_gattc_cl_get_regcb(client_if)) != NULL) {
for (i = 0; i < BTA_GATTC_NOTIF_REG_MAX; i ++) {
if (p_clreg->notif_reg[i].in_use &&
!memcmp(p_clreg->notif_reg[i].remote_bda, bda, BD_ADDR_LEN) &&
bta_gattc_charid_compare(&p_clreg->notif_reg[i].char_id, p_char_id))
{
bta_gattc_charid_compare(&p_clreg->notif_reg[i].char_id, p_char_id)) {
APPL_TRACE_DEBUG("%s deregistered bd_addr:%02x:%02x:%02x:%02x:%02x:%02x",
__func__, bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
memset(&p_clreg->notif_reg[i], 0, sizeof(tBTA_GATTC_NOTIF_REG));
@ -995,15 +958,12 @@ tBTA_GATT_STATUS BTA_GATTC_DeregisterForNotifications (tBTA_GATTC_IF client_if,
break;
}
}
if (i == BTA_GATTC_NOTIF_REG_MAX)
{
if (i == BTA_GATTC_NOTIF_REG_MAX) {
status = BTA_GATT_ERROR;
APPL_TRACE_ERROR("%s registration not found bd_addr:%02x:%02x:%02x:%02x:%02x:%02x",
__func__, bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
}
}
else
{
} else {
APPL_TRACE_ERROR("%s client_if: %d not registered bd_addr:%02x:%02x:%02x:%02x:%02x:%02x",
__func__, client_if, bda[0], bda[1], bda[2], bda[3], bda[4], bda[5]);
}
@ -1026,8 +986,7 @@ void BTA_GATTC_Refresh(BD_ADDR remote_bda)
{
tBTA_GATTC_API_OPEN *p_buf;
if ((p_buf = (tBTA_GATTC_API_OPEN *) GKI_getbuf(sizeof(tBTA_GATTC_API_OPEN))) != NULL)
{
if ((p_buf = (tBTA_GATTC_API_OPEN *) GKI_getbuf(sizeof(tBTA_GATTC_API_OPEN))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_REFRESH_EVT;
memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);
@ -1057,19 +1016,17 @@ void BTA_GATTC_Listen(tBTA_GATTC_IF client_if, BOOLEAN start, BD_ADDR_PTR target
{
tBTA_GATTC_API_LISTEN *p_buf;
if ((p_buf = (tBTA_GATTC_API_LISTEN *) GKI_getbuf((UINT16)(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN))) != NULL)
{
if ((p_buf = (tBTA_GATTC_API_LISTEN *) GKI_getbuf((UINT16)(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_LISTEN_EVT;
p_buf->client_if = client_if;
p_buf->start = start;
if (target_bda)
{
p_buf->remote_bda = (UINT8*)(p_buf + 1);
if (target_bda) {
p_buf->remote_bda = (UINT8 *)(p_buf + 1);
memcpy(p_buf->remote_bda, target_bda, BD_ADDR_LEN);
}
else
} else {
p_buf->remote_bda = NULL;
}
bta_sys_sendmsg(p_buf);
}
@ -1092,8 +1049,7 @@ void BTA_GATTC_Broadcast(tBTA_GATTC_IF client_if, BOOLEAN start)
{
tBTA_GATTC_API_LISTEN *p_buf;
if ((p_buf = (tBTA_GATTC_API_LISTEN *) GKI_getbuf((UINT16)(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN))) != NULL)
{
if ((p_buf = (tBTA_GATTC_API_LISTEN *) GKI_getbuf((UINT16)(sizeof(tBTA_GATTC_API_LISTEN) + BD_ADDR_LEN))) != NULL) {
p_buf->hdr.event = BTA_GATTC_API_BROADCAST_EVT;
p_buf->client_if = client_if;
p_buf->start = start;

459
components/bt/bluedroid/bta/gatt/bta_gattc_cache.c Executable file → Normal file
View file

@ -50,8 +50,7 @@ static tBTA_GATT_STATUS bta_gattc_sdp_service_disc(UINT16 conn_id, tBTA_GATTC_SE
*****************************************************************************/
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
static char *bta_gattc_attr_type[] =
{
static char *bta_gattc_attr_type[] = {
"I", /* Included Service */
"C", /* Characteristic */
"D" /* Characteristic Descriptor */
@ -75,8 +74,7 @@ static void bta_gattc_display_cache_server(tBTA_GATTC_CACHE *p_cache)
APPL_TRACE_ERROR("<================Start Server Cache =============>");
while (p_cur_srvc)
{
while (p_cur_srvc) {
APPL_TRACE_ERROR("Service[%d]: handle[%d ~ %d] %s[0x%04x] inst[%d]",
i, p_cur_srvc->s_handle, p_cur_srvc->e_handle,
((p_cur_srvc->service_uuid.id.uuid.len == 2) ? "uuid16" : "uuid128"),
@ -86,8 +84,7 @@ static void bta_gattc_display_cache_server(tBTA_GATTC_CACHE *p_cache)
p_attr = p_cur_srvc->p_attr;
for (j = 0; p_attr; j ++ )
{
for (j = 0; p_attr; j ++ ) {
APPL_TRACE_ERROR("\t Attr[0x%04x] handle[%d] uuid[0x%04x] inst[%d] type[%s] prop[0x%1x]",
j + 1, p_attr->attr_handle, p_attr->p_uuid->uuid16, p_attr->inst_id,
bta_gattc_attr_type[p_attr->attr_type], p_attr->property);
@ -116,8 +113,7 @@ static void bta_gattc_display_explore_record(tBTA_GATTC_ATTR_REC *p_rec, UINT8 n
tBTA_GATTC_ATTR_REC *pp = p_rec;
APPL_TRACE_ERROR("<================Start Explore Queue =============>");
for (i = 0; i < num_rec; i ++, pp ++)
{
for (i = 0; i < num_rec; i ++, pp ++) {
APPL_TRACE_ERROR("\t rec[%d] uuid[0x%04x] s_handle[%d] e_handle[%d] is_primary[%d]",
i + 1, pp->uuid.uu.uuid16, pp->s_handle, pp->e_handle, pp->is_primary);
}
@ -141,14 +137,11 @@ BT_HDR *bta_gattc_alloc_cache_buf(tBTA_GATTC_SERV *p_srvc_cb)
{
BT_HDR *p_buf;
if ((p_buf = (BT_HDR *)GKI_getpoolbuf(GATT_DB_POOL_ID)) == NULL)
{
if ((p_buf = (BT_HDR *)GKI_getpoolbuf(GATT_DB_POOL_ID)) == NULL) {
APPL_TRACE_DEBUG("No resources: GKI buffer allocation failed.");
utl_freebuf((void **)&p_srvc_cb->p_srvc_list);
p_srvc_cb->free_byte = 0;
}
else
{
} else {
memset(p_buf, 0, GKI_get_buf_size(p_buf));
p_srvc_cb->p_free = (UINT8 *) p_buf;
p_srvc_cb->free_byte = GKI_get_buf_size(p_buf);
@ -174,29 +167,24 @@ tBTA_GATT_STATUS bta_gattc_init_cache(tBTA_GATTC_SERV *p_srvc_cb)
{
tBTA_GATT_STATUS status = BTA_GATT_OK;
while (!GKI_queue_is_empty(&p_srvc_cb->cache_buffer))
while (!GKI_queue_is_empty(&p_srvc_cb->cache_buffer)) {
GKI_freebuf (GKI_dequeue (&p_srvc_cb->cache_buffer));
}
utl_freebuf((void **)&p_srvc_cb->p_srvc_list);
if ((p_srvc_cb->p_srvc_list = (tBTA_GATTC_ATTR_REC*)GKI_getbuf(BTA_GATTC_ATTR_LIST_SIZE)) == NULL)
{
if ((p_srvc_cb->p_srvc_list = (tBTA_GATTC_ATTR_REC *)GKI_getbuf(BTA_GATTC_ATTR_LIST_SIZE)) == NULL) {
APPL_TRACE_DEBUG("No resources: GKI buffer allocation failed.");
status = GATT_NO_RESOURCES;
}
else
{
} else {
p_srvc_cb->total_srvc = 0;
p_srvc_cb->cur_srvc_idx =
p_srvc_cb->cur_char_idx =
p_srvc_cb->next_avail_idx = 0;
if (bta_gattc_alloc_cache_buf(p_srvc_cb) == NULL)
{
if (bta_gattc_alloc_cache_buf(p_srvc_cb) == NULL) {
status = GATT_NO_RESOURCES;
}
else
{
} else {
p_srvc_cb->p_cur_srvc = p_srvc_cb->p_srvc_cache = NULL;
}
}
@ -223,9 +211,10 @@ static UINT8 bta_gattc_get_srvc_inst_id(tBTA_GATTC_SERV *p_srvc_cb, tBT_UUID uui
{
p_srvc_rec = p_srvc_cb->p_srvc_list + i;
if (bta_gattc_uuid_compare(&p_srvc_rec->uuid, &uuid, TRUE))
if (bta_gattc_uuid_compare(&p_srvc_rec->uuid, &uuid, TRUE)) {
inst ++;
}
}
return inst ;
}
/*******************************************************************************
@ -245,12 +234,12 @@ static UINT8 bta_gattc_get_char_inst_id(tBTA_GATTC_CACHE *p_service_cache, tBT_U
p_attr = p_service_cache->p_attr;
while (p_attr)
{
while (p_attr) {
bta_gattc_pack_attr_uuid(p_attr, &attr_uuid);
if (bta_gattc_uuid_compare(&attr_uuid, p_uuid, TRUE))
if (bta_gattc_uuid_compare(&attr_uuid, p_uuid, TRUE)) {
inst ++;
}
p_attr = p_attr->p_next;
}
@ -271,15 +260,16 @@ static UINT8 bta_gattc_get_char_descr_inst_id(tBTA_GATTC_CACHE_ATTR *p_char_attr
UINT8 inst = 0;
tBT_UUID attr_uuid;
if (p_char_attr != NULL)
if (p_char_attr != NULL) {
p_char_attr = p_char_attr->p_next;
}
while (p_char_attr)
{
while (p_char_attr) {
bta_gattc_pack_attr_uuid(p_char_attr, &attr_uuid);
if (bta_gattc_uuid_compare(&attr_uuid, p_uuid, TRUE))
if (bta_gattc_uuid_compare(&attr_uuid, p_uuid, TRUE)) {
inst ++;
}
p_char_attr = p_char_attr->p_next;
}
@ -308,11 +298,11 @@ static tBTA_GATT_STATUS bta_gattc_add_srvc_to_cache(tBTA_GATTC_SERV *p_srvc_cb,
APPL_TRACE_DEBUG("free byte = %d, req %d bytes.", p_srvc_cb->free_byte, sizeof(tBTA_GATTC_CACHE))
#endif
if (p_srvc_cb->free_byte < sizeof(tBTA_GATTC_CACHE))
{
if (bta_gattc_alloc_cache_buf(p_srvc_cb) == NULL)
if (p_srvc_cb->free_byte < sizeof(tBTA_GATTC_CACHE)) {
if (bta_gattc_alloc_cache_buf(p_srvc_cb) == NULL) {
return GATT_NO_RESOURCES;
}
}
p_new_srvc = (tBTA_GATTC_CACHE *)p_srvc_cb->p_free;
/* update service information */
@ -323,14 +313,16 @@ static tBTA_GATT_STATUS bta_gattc_add_srvc_to_cache(tBTA_GATTC_SERV *p_srvc_cb,
p_new_srvc->service_uuid.id.inst_id = srvc_inst;
p_new_srvc->p_next = NULL;
if (p_srvc_cb->p_cur_srvc != NULL)
if (p_srvc_cb->p_cur_srvc != NULL) {
p_srvc_cb->p_cur_srvc->p_next = p_new_srvc;
}
p_srvc_cb->p_cur_srvc = p_new_srvc;
p_srvc_cb->p_cur_srvc->p_cur_char = NULL;
/* first service */
if (p_srvc_cb->p_srvc_cache == NULL)
if (p_srvc_cb->p_srvc_cache == NULL) {
p_srvc_cb->p_srvc_cache = p_new_srvc;
}
/* update buffer managament info */
p_srvc_cb->p_free += sizeof(tBTA_GATTC_CACHE);
@ -365,17 +357,16 @@ static tBTA_GATT_STATUS bta_gattc_add_attr_to_cache(tBTA_GATTC_SERV *p_srvc_cb,
APPL_TRACE_DEBUG("free byte = %d, req %d bytes.", p_srvc_cb->free_byte, len);
#endif
if (p_srvc_cb->p_cur_srvc == NULL)
{
if (p_srvc_cb->p_cur_srvc == NULL) {
APPL_TRACE_ERROR("Illegal action to add char/descr/incl srvc before adding a service!");
return GATT_WRONG_STATE;
}
if (p_srvc_cb->free_byte < len)
{
if (bta_gattc_alloc_cache_buf(p_srvc_cb) == NULL)
if (p_srvc_cb->free_byte < len) {
if (bta_gattc_alloc_cache_buf(p_srvc_cb) == NULL) {
return GATT_NO_RESOURCES;
}
}
p_attr = (tBTA_GATTC_CACHE_ATTR *)p_srvc_cb->p_free;
@ -388,36 +379,32 @@ static tBTA_GATT_STATUS bta_gattc_add_attr_to_cache(tBTA_GATTC_SERV *p_srvc_cb,
pp = (UINT8 *)p_attr->p_uuid;
if (p_uuid->len == LEN_UUID_16)
{
if (p_uuid->len == LEN_UUID_16) {
UINT16_TO_STREAM(pp, p_uuid->uu.uuid16);
}
else if (p_uuid->len == LEN_UUID_128)
{
} else if (p_uuid->len == LEN_UUID_128) {
memcpy(pp, p_uuid->uu.uuid128, LEN_UUID_128);
}
if (type == BTA_GATTC_ATTR_TYPE_CHAR)
{
if (type == BTA_GATTC_ATTR_TYPE_CHAR) {
p_attr->inst_id = bta_gattc_get_char_inst_id(p_srvc_cb->p_cur_srvc, p_uuid);
p_srvc_cb->p_cur_srvc->p_cur_char = p_attr;
}
else if (type == BTA_GATTC_ATTR_TYPE_CHAR_DESCR)
} else if (type == BTA_GATTC_ATTR_TYPE_CHAR_DESCR) {
p_attr->inst_id = bta_gattc_get_char_descr_inst_id(p_srvc_cb->p_cur_srvc->p_cur_char, p_uuid);
else /* TODO: --->> temp treat included service as single instance */
} else { /* TODO: --->> temp treat included service as single instance */
p_attr->inst_id = 0;
}
/* update service information */
p_srvc_cb->p_free += len;
p_srvc_cb->free_byte -= len;
/* first attribute within the service, update the attribute pointer */
if (p_srvc_cb->p_cur_srvc->p_attr == NULL)
{
if (p_srvc_cb->p_cur_srvc->p_attr == NULL) {
p_srvc_cb->p_cur_srvc->p_attr = p_attr;
}
if (p_srvc_cb->p_cur_srvc->p_last_attr != NULL)
if (p_srvc_cb->p_cur_srvc->p_last_attr != NULL) {
p_srvc_cb->p_cur_srvc->p_last_attr->p_next = p_attr;
}
p_srvc_cb->p_cur_srvc->p_last_attr = p_attr;
@ -437,20 +424,17 @@ void bta_gattc_get_disc_range(tBTA_GATTC_SERV *p_srvc_cb, UINT16 *p_s_hdl, UINT1
{
tBTA_GATTC_ATTR_REC *p_rec = NULL;
if (is_srvc)
{
if (is_srvc) {
p_rec = p_srvc_cb->p_srvc_list + p_srvc_cb->cur_srvc_idx;
*p_s_hdl = p_rec->s_handle;
}
else
{
} else {
p_rec = p_srvc_cb->p_srvc_list + p_srvc_cb->cur_char_idx;
*p_s_hdl = p_rec->s_handle + 1;
}
*p_e_hdl = p_rec->e_handle;
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
APPL_TRACE_DEBUG("discover range [%d ~ %d]",p_rec->s_handle, p_rec->e_handle);
APPL_TRACE_DEBUG("discover range [%d ~ %d]", p_rec->s_handle, p_rec->e_handle);
#endif
return;
}
@ -469,13 +453,13 @@ tBTA_GATT_STATUS bta_gattc_discover_pri_service(UINT16 conn_id, tBTA_GATTC_SERV
tBTA_GATTC_CLCB *p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id);
tBTA_GATT_STATUS status = BTA_GATT_ERROR;
if (p_clcb)
{
if (p_clcb->transport == BTA_TRANSPORT_LE)
if (p_clcb) {
if (p_clcb->transport == BTA_TRANSPORT_LE) {
status = bta_gattc_discover_procedure(conn_id, p_server_cb, disc_type);
else
} else {
status = bta_gattc_sdp_service_disc(conn_id, p_server_cb);
}
}
return status;
}
@ -496,20 +480,17 @@ tBTA_GATT_STATUS bta_gattc_discover_procedure(UINT16 conn_id, tBTA_GATTC_SERV *p
memset(&param, 0, sizeof(tGATT_DISC_PARAM));
if (disc_type == GATT_DISC_SRVC_ALL || disc_type == GATT_DISC_SRVC_BY_UUID)
{
if (disc_type == GATT_DISC_SRVC_ALL || disc_type == GATT_DISC_SRVC_BY_UUID) {
param.s_handle = 1;
param.e_handle = 0xFFFF;
}
else
{
if (disc_type == GATT_DISC_CHAR_DSCPT)
} else {
if (disc_type == GATT_DISC_CHAR_DSCPT) {
is_service = FALSE;
}
bta_gattc_get_disc_range(p_server_cb, &param.s_handle, &param.e_handle, is_service);
if (param.s_handle > param.e_handle)
{
if (param.s_handle > param.e_handle) {
return GATT_ERROR;
}
}
@ -557,8 +538,9 @@ void bta_gattc_start_disc_char_dscp(UINT16 conn_id, tBTA_GATTC_SERV *p_srvc_cb)
{
APPL_TRACE_DEBUG("starting discover characteristics descriptor");
if (bta_gattc_discover_procedure(conn_id, p_srvc_cb, GATT_DISC_CHAR_DSCPT) != 0)
if (bta_gattc_discover_procedure(conn_id, p_srvc_cb, GATT_DISC_CHAR_DSCPT) != 0) {
bta_gattc_char_dscpt_disc_cmpl(conn_id, p_srvc_cb);
}
}
/*******************************************************************************
@ -579,29 +561,26 @@ static void bta_gattc_explore_srvc(UINT16 conn_id, tBTA_GATTC_SERV *p_srvc_cb)
p_srvc_cb->cur_char_idx = p_srvc_cb->next_avail_idx = p_srvc_cb->total_srvc;
if (p_clcb == NULL)
{
if (p_clcb == NULL) {
APPL_TRACE_ERROR("unknown connection ID");
return;
}
/* start expore a service if there is service not been explored */
if (p_srvc_cb->cur_srvc_idx < p_srvc_cb->total_srvc)
{
if (p_srvc_cb->cur_srvc_idx < p_srvc_cb->total_srvc) {
/* add the first service into cache */
if (bta_gattc_add_srvc_to_cache (p_srvc_cb,
p_rec->s_handle,
p_rec->e_handle,
&p_rec->uuid,
p_rec->is_primary,
p_rec->srvc_inst_id) == 0)
{
p_rec->srvc_inst_id) == 0) {
/* start discovering included services */
bta_gattc_start_disc_include_srvc(conn_id, p_srvc_cb);
return;
}
}
/* no service found at all, the end of server discovery*/
LOG_WARN("%s no more services found", __func__);
LOG_DEBUG("%s no more services found", __func__);
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
bta_gattc_display_cache_server(p_srvc_cb->p_srvc_cache);
@ -641,8 +620,7 @@ static void bta_gattc_char_disc_cmpl(UINT16 conn_id, tBTA_GATTC_SERV *p_srvc_cb)
tBTA_GATTC_ATTR_REC *p_rec = p_srvc_cb->p_srvc_list + p_srvc_cb->cur_char_idx;
/* if there are characteristic needs to be explored */
if (p_srvc_cb->total_char > 0)
{
if (p_srvc_cb->total_char > 0) {
/* add the first characteristic into cache */
bta_gattc_add_attr_to_cache (p_srvc_cb,
p_rec->s_handle,
@ -652,9 +630,7 @@ static void bta_gattc_char_disc_cmpl(UINT16 conn_id, tBTA_GATTC_SERV *p_srvc_cb)
/* start discoverying characteristic descriptor , if failed, disc for next char*/
bta_gattc_start_disc_char_dscp(conn_id, p_srvc_cb);
}
else /* otherwise start with next service */
{
} else { /* otherwise start with next service */
p_srvc_cb->cur_srvc_idx ++;
bta_gattc_explore_srvc (conn_id, p_srvc_cb);
@ -673,8 +649,7 @@ static void bta_gattc_char_dscpt_disc_cmpl(UINT16 conn_id, tBTA_GATTC_SERV *p_sr
{
tBTA_GATTC_ATTR_REC *p_rec = NULL;
if (-- p_srvc_cb->total_char > 0)
{
if (-- p_srvc_cb->total_char > 0) {
p_rec = p_srvc_cb->p_srvc_list + (++ p_srvc_cb->cur_char_idx);
/* add the next characteristic into cache */
bta_gattc_add_attr_to_cache (p_srvc_cb,
@ -685,8 +660,7 @@ static void bta_gattc_char_dscpt_disc_cmpl(UINT16 conn_id, tBTA_GATTC_SERV *p_sr
/* start discoverying next characteristic for char descriptor */
bta_gattc_start_disc_char_dscp(conn_id, p_srvc_cb);
}
else
} else
/* all characteristic has been explored, start with next service if any */
{
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
@ -705,20 +679,15 @@ static BOOLEAN bta_gattc_srvc_in_list(tBTA_GATTC_SERV *p_srvc_cb, UINT16 s_handl
BOOLEAN exist_srvc = FALSE;
UNUSED(uuid);
if (!GATT_HANDLE_IS_VALID(s_handle) || !GATT_HANDLE_IS_VALID(e_handle))
{
if (!GATT_HANDLE_IS_VALID(s_handle) || !GATT_HANDLE_IS_VALID(e_handle)) {
APPL_TRACE_ERROR("invalid included service handle: [0x%04x ~ 0x%04x]", s_handle, e_handle);
exist_srvc = TRUE;
}
else
{
for (i = 0; i < p_srvc_cb->next_avail_idx; i ++)
{
} else {
for (i = 0; i < p_srvc_cb->next_avail_idx; i ++) {
p_rec = p_srvc_cb->p_srvc_list + i;
/* a new service should not have any overlap with other service handle range */
if (p_rec->s_handle == s_handle || p_rec->e_handle == e_handle)
{
if (p_rec->s_handle == s_handle || p_rec->e_handle == e_handle) {
exist_srvc = TRUE;
break;
}
@ -742,8 +711,7 @@ static tBTA_GATT_STATUS bta_gattc_add_srvc_to_list(tBTA_GATTC_SERV *p_srvc_cb,
tBTA_GATTC_ATTR_REC *p_rec = NULL;
tBTA_GATT_STATUS status = BTA_GATT_OK;
if (p_srvc_cb->p_srvc_list && p_srvc_cb->next_avail_idx < BTA_GATTC_MAX_CACHE_CHAR)
{
if (p_srvc_cb->p_srvc_list && p_srvc_cb->next_avail_idx < BTA_GATTC_MAX_CACHE_CHAR) {
p_rec = p_srvc_cb->p_srvc_list + p_srvc_cb->next_avail_idx;
APPL_TRACE_DEBUG("%s handle=%d, service type=0x%04x",
@ -757,9 +725,8 @@ static tBTA_GATT_STATUS bta_gattc_add_srvc_to_list(tBTA_GATTC_SERV *p_srvc_cb,
p_srvc_cb->total_srvc ++;
p_srvc_cb->next_avail_idx ++;
}
else
{ /* allocate bigger buffer ?? */
} else {
/* allocate bigger buffer ?? */
status = GATT_DB_FULL;
APPL_TRACE_ERROR("service not added, no resources or wrong state");
@ -782,13 +749,10 @@ static tBTA_GATT_STATUS bta_gattc_add_char_to_list(tBTA_GATTC_SERV *p_srvc_cb,
tBTA_GATTC_ATTR_REC *p_rec = NULL;
tBTA_GATT_STATUS status = BTA_GATT_OK;
if (p_srvc_cb->p_srvc_list == NULL)
{
if (p_srvc_cb->p_srvc_list == NULL) {
APPL_TRACE_ERROR("No service available, unexpected char discovery result");
status = BTA_GATT_INTERNAL_ERROR;
}
else if (p_srvc_cb->next_avail_idx < BTA_GATTC_MAX_CACHE_CHAR)
{
} else if (p_srvc_cb->next_avail_idx < BTA_GATTC_MAX_CACHE_CHAR) {
p_rec = p_srvc_cb->p_srvc_list + p_srvc_cb->next_avail_idx;
@ -800,15 +764,12 @@ static tBTA_GATT_STATUS bta_gattc_add_char_to_list(tBTA_GATTC_SERV *p_srvc_cb,
memcpy(&p_rec->uuid, &uuid, sizeof(tBT_UUID));
/* update the endind handle of pervious characteristic if available */
if (p_srvc_cb->total_char > 1)
{
if (p_srvc_cb->total_char > 1) {
p_rec -= 1;
p_rec->e_handle = decl_handle - 1;
}
p_srvc_cb->next_avail_idx ++;
}
else
{
} else {
APPL_TRACE_ERROR("char not added, no resources");
/* allocate bigger buffer ?? */
status = BTA_GATT_DB_FULL;
@ -833,20 +794,15 @@ void bta_gattc_sdp_callback (UINT16 sdp_status)
UINT16 start_handle = 0, end_handle = 0;
tBTA_GATTC_SERV *p_srvc_cb = bta_gattc_find_scb_by_cid(bta_gattc_cb.sdp_conn_id);
if(((sdp_status == SDP_SUCCESS) || (sdp_status == SDP_DB_FULL)) && p_srvc_cb != NULL)
{
do
{
if (((sdp_status == SDP_SUCCESS) || (sdp_status == SDP_DB_FULL)) && p_srvc_cb != NULL) {
do {
/* find a service record, report it */
p_sdp_rec = SDP_FindServiceInDb(bta_gattc_cb.p_sdp_db,
0, p_sdp_rec);
if (p_sdp_rec)
{
if (SDP_FindServiceUUIDInRec(p_sdp_rec, &service_uuid))
{
if (p_sdp_rec) {
if (SDP_FindServiceUUIDInRec(p_sdp_rec, &service_uuid)) {
if (SDP_FindProtocolListElemInRec(p_sdp_rec, UUID_PROTOCOL_ATT, &pe))
{
if (SDP_FindProtocolListElemInRec(p_sdp_rec, UUID_PROTOCOL_ATT, &pe)) {
start_handle = (UINT16) pe.params[0];
end_handle = (UINT16) pe.params[1];
@ -855,18 +811,15 @@ void bta_gattc_sdp_callback (UINT16 sdp_status)
service_uuid.uu.uuid16, start_handle, end_handle);
#endif
if (GATT_HANDLE_IS_VALID(start_handle) && GATT_HANDLE_IS_VALID(end_handle)&&
p_srvc_cb != NULL)
{
if (GATT_HANDLE_IS_VALID(start_handle) && GATT_HANDLE_IS_VALID(end_handle) &&
p_srvc_cb != NULL) {
/* discover services result, add services into a service list */
bta_gattc_add_srvc_to_list(p_srvc_cb,
start_handle,
end_handle,
service_uuid,
TRUE);
}
else
{
} else {
APPL_TRACE_ERROR("invalid start_handle = %d end_handle = %d",
start_handle, end_handle);
}
@ -880,9 +833,9 @@ void bta_gattc_sdp_callback (UINT16 sdp_status)
if ( p_srvc_cb != NULL)
/* start discover primary service */
bta_gattc_explore_srvc(bta_gattc_cb.sdp_conn_id, p_srvc_cb);
else
{
bta_gattc_explore_srvc(bta_gattc_cb.sdp_conn_id, p_srvc_cb);
} else {
APPL_TRACE_ERROR("GATT service discovery is done on unknown connection");
}
@ -911,22 +864,18 @@ static tBTA_GATT_STATUS bta_gattc_sdp_service_disc(UINT16 conn_id, tBTA_GATTC_SE
uuid.len = LEN_UUID_16;
uuid.uu.uuid16 = UUID_PROTOCOL_ATT;
if((bta_gattc_cb.p_sdp_db = (tSDP_DISCOVERY_DB *)GKI_getbuf(BTA_GATT_SDP_DB_SIZE)) != NULL)
{
if ((bta_gattc_cb.p_sdp_db = (tSDP_DISCOVERY_DB *)GKI_getbuf(BTA_GATT_SDP_DB_SIZE)) != NULL) {
attr_list[0] = ATTR_ID_SERVICE_CLASS_ID_LIST;
attr_list[1] = ATTR_ID_PROTOCOL_DESC_LIST;
SDP_InitDiscoveryDb (bta_gattc_cb.p_sdp_db, BTA_GATT_SDP_DB_SIZE, 1,
&uuid, num_attrs, attr_list);
if(!SDP_ServiceSearchAttributeRequest (p_server_cb->server_bda,
bta_gattc_cb.p_sdp_db, &bta_gattc_sdp_callback))
{
if (!SDP_ServiceSearchAttributeRequest (p_server_cb->server_bda,
bta_gattc_cb.p_sdp_db, &bta_gattc_sdp_callback)) {
GKI_freebuf(bta_gattc_cb.p_sdp_db);
bta_gattc_cb.p_sdp_db = NULL;
}
else
{
} else {
bta_gattc_cb.sdp_conn_id = conn_id;
status = BTA_GATT_OK;
}
@ -945,16 +894,14 @@ static tBTA_GATT_STATUS bta_gattc_sdp_service_disc(UINT16 conn_id, tBTA_GATTC_SE
*******************************************************************************/
void bta_gattc_disc_res_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_DISC_RES *p_data)
{
tBTA_GATTC_SERV * p_srvc_cb = NULL;
tBTA_GATTC_SERV *p_srvc_cb = NULL;
BOOLEAN pri_srvc;
tBTA_GATTC_CLCB *p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id);
p_srvc_cb = bta_gattc_find_scb_by_cid(conn_id);
if (p_srvc_cb != NULL && p_clcb != NULL && p_clcb->state == BTA_GATTC_DISCOVER_ST)
{
switch (disc_type)
{
if (p_srvc_cb != NULL && p_clcb != NULL && p_clcb->state == BTA_GATTC_DISCOVER_ST) {
switch (disc_type) {
case GATT_DISC_SRVC_ALL:
/* discover services result, add services into a service list */
bta_gattc_add_srvc_to_list(p_srvc_cb,
@ -1012,22 +959,20 @@ void bta_gattc_disc_res_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_
}
void bta_gattc_disc_cmpl_cback (UINT16 conn_id, tGATT_DISC_TYPE disc_type, tGATT_STATUS status)
{
tBTA_GATTC_SERV * p_srvc_cb;
tBTA_GATTC_SERV *p_srvc_cb;
tBTA_GATTC_CLCB *p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id);
if ( p_clcb && (status != GATT_SUCCESS || p_clcb->status != GATT_SUCCESS) )
{
if (p_clcb->status == GATT_SUCCESS)
if ( p_clcb && (status != GATT_SUCCESS || p_clcb->status != GATT_SUCCESS) ) {
if (p_clcb->status == GATT_SUCCESS) {
p_clcb->status = status;
}
bta_gattc_sm_execute(p_clcb, BTA_GATTC_DISCOVER_CMPL_EVT, NULL);
return;
}
p_srvc_cb = bta_gattc_find_scb_by_cid(conn_id);
if (p_srvc_cb != NULL)
{
switch (disc_type)
{
if (p_srvc_cb != NULL) {
switch (disc_type) {
case GATT_DISC_SRVC_ALL:
case GATT_DISC_SRVC_BY_UUID:
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
@ -1073,8 +1018,7 @@ UINT16 bta_gattc_id2handle(tBTA_GATTC_SERV *p_srcb, tBTA_GATT_SRVC_ID *p_service
tBT_UUID attr_uuid;
BOOLEAN char_map = FALSE, done = FALSE;
while (p_service_id && p_cache && !done)
{
while (p_service_id && p_cache && !done) {
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
APPL_TRACE_DEBUG("Service: handle[%d] uuid[0x%04x] inst[%d]",
p_cache->s_handle, p_cache->service_uuid.id.uuid.uu.uuid16,
@ -1082,10 +1026,8 @@ UINT16 bta_gattc_id2handle(tBTA_GATTC_SERV *p_srcb, tBTA_GATT_SRVC_ID *p_service
#endif
p_attr = p_cache->p_attr;
if (bta_gattc_srvcid_compare(p_service_id, &p_cache->service_uuid))
{
for (j = 0; p_attr; j ++)
{
if (bta_gattc_srvcid_compare(p_service_id, &p_cache->service_uuid)) {
for (j = 0; p_attr; j ++) {
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
APPL_TRACE_DEBUG("\t Attr[0x%04x] handle[0x%04x] uuid[0x%04x] inst[%d] type[%d]",
j + 1, p_attr->attr_handle, p_attr->p_uuid->uuid16,
@ -1094,47 +1036,35 @@ UINT16 bta_gattc_id2handle(tBTA_GATTC_SERV *p_srcb, tBTA_GATT_SRVC_ID *p_service
bta_gattc_pack_attr_uuid(p_attr, &attr_uuid);
if (bta_gattc_uuid_compare(&p_char_id->uuid, &attr_uuid, TRUE) &&
p_char_id->inst_id == p_attr->inst_id)
{
if (p_descr_uuid == NULL)
{
p_char_id->inst_id == p_attr->inst_id) {
if (p_descr_uuid == NULL) {
handle = p_attr->attr_handle;
done = TRUE;
break;
}
else
{
} else {
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
APPL_TRACE_DEBUG("found matching characteristic for the descriptor");
#endif
char_map = TRUE;
}
}
else if (char_map == TRUE)
{
if (p_attr->attr_type == BTA_GATTC_ATTR_TYPE_CHAR_DESCR)
{
} else if (char_map == TRUE) {
if (p_attr->attr_type == BTA_GATTC_ATTR_TYPE_CHAR_DESCR) {
if (p_descr_uuid != NULL &&
bta_gattc_uuid_compare(&p_descr_uuid->uuid, &attr_uuid, TRUE) &&
p_descr_uuid->inst_id == p_attr->inst_id)
{
p_descr_uuid->inst_id == p_attr->inst_id) {
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
APPL_TRACE_DEBUG("found descriptor!!");
#endif
handle = p_attr->attr_handle;
done = TRUE;
break;
}
else
{
} else {
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
APPL_TRACE_DEBUG("descriptor UUID not matching");
#endif
}
}
else /* another char */
{
} else { /* another char */
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
APPL_TRACE_DEBUG("no matching descptr found!!start of next characteristic");
#endif
@ -1172,58 +1102,48 @@ BOOLEAN bta_gattc_handle2id(tBTA_GATTC_SERV *p_srcb, UINT16 handle, tBTA_GATT_SR
memset(p_char_id, 0, sizeof(tBTA_GATT_ID));
memset(p_descr_type, 0, sizeof(tBTA_GATT_ID));
while (p_cache)
{
while (p_cache) {
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
APPL_TRACE_DEBUG("Service: handle[%d] uuid[0x%04x] inst[%d]",
p_cache->s_handle, p_cache->service_uuid.id.uuid.uu.uuid16,
p_cache->service_uuid.id.inst_id);
#endif
/* a service found */
if (p_cache->s_handle == handle)
{
if (p_cache->s_handle == handle) {
memcpy(p_service_id, &p_cache->service_uuid, sizeof(tBTA_GATT_SRVC_ID));
return TRUE;
}
else /* start looking for attributes within the service */
{
} else { /* start looking for attributes within the service */
p_attr = p_cache->p_attr;
for (j = 0; p_attr; j ++)
{
for (j = 0; p_attr; j ++) {
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
APPL_TRACE_DEBUG("\t Attr[0x%04x] handle[0x%04x] uuid[0x%04x] inst[%d] type[%d]",
j + 1, p_attr->attr_handle, p_attr->p_uuid->uuid16,
p_attr->inst_id, p_attr->attr_type);
#endif
if (p_attr->attr_type == BTA_GATTC_ATTR_TYPE_CHAR)
if (p_attr->attr_type == BTA_GATTC_ATTR_TYPE_CHAR) {
p_char = p_attr;
}
if (handle == p_attr->attr_handle)
{
if (handle == p_attr->attr_handle) {
memcpy(p_service_id, &p_cache->service_uuid, sizeof(tBTA_GATT_SRVC_ID));
if (p_attr->attr_type == BTA_GATTC_ATTR_TYPE_CHAR_DESCR)
{
if (p_attr->attr_type == BTA_GATTC_ATTR_TYPE_CHAR_DESCR) {
bta_gattc_pack_attr_uuid(p_attr, &p_descr_type->uuid);
p_descr_type->inst_id = p_attr->inst_id;
if (p_char != NULL)
{
if (p_char != NULL) {
bta_gattc_pack_attr_uuid(p_char, &p_char_id->uuid);
p_char_id->inst_id = p_char->inst_id;
}
else
{
} else {
APPL_TRACE_ERROR("descptr does not belong to any chracteristic");
}
}
else
} else
/* is a characterisitc value or included service */
{
bta_gattc_pack_attr_uuid(p_attr, &p_char_id->uuid);
p_char_id->inst_id =p_attr->inst_id;
p_char_id->inst_id = p_attr->inst_id;
}
return TRUE;
}
@ -1251,18 +1171,15 @@ void bta_gattc_search_service(tBTA_GATTC_CLCB *p_clcb, tBT_UUID *p_uuid)
tBTA_GATTC_CACHE *p_cache = p_srcb->p_srvc_cache;
tBTA_GATTC cb_data;
while (p_cache)
{
if (bta_gattc_uuid_compare(p_uuid, &p_cache->service_uuid.id.uuid, FALSE))
{
while (p_cache) {
if (bta_gattc_uuid_compare(p_uuid, &p_cache->service_uuid.id.uuid, FALSE)) {
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
APPL_TRACE_DEBUG("found service [0x%04x], inst[%d] handle [%d]",
p_cache->service_uuid.id.uuid.uu.uuid16,
p_cache->service_uuid.id.inst_id,
p_cache->s_handle);
#endif
if (p_clcb->p_rcb->p_cback)
{
if (p_clcb->p_rcb->p_cback) {
memset(&cb_data, 0, sizeof(tBTA_GATTC));
cb_data.srvc_res.conn_id = p_clcb->bta_conn_id;
@ -1291,7 +1208,7 @@ static tBTA_GATT_STATUS bta_gattc_find_record(tBTA_GATTC_SERV *p_srcb,
tBTA_GATTC_ATTR_TYPE attr_type,
tBTA_GATT_SRVC_ID *p_service_id,
tBTA_GATT_ID *p_start_rec,
tBT_UUID * p_uuid_cond,
tBT_UUID *p_uuid_cond,
tBTA_GATT_ID *p_result,
void *p_param)
{
@ -1302,10 +1219,8 @@ static tBTA_GATT_STATUS bta_gattc_find_record(tBTA_GATTC_SERV *p_srcb,
BOOLEAN char_found = FALSE, descr_found = FALSE;
tBTA_GATT_ID *p_descr_id = (tBTA_GATT_ID *)p_param;;
for (i = 0; p_cache && status != BTA_GATT_OK; i ++)
{
if (bta_gattc_srvcid_compare(p_service_id, &p_cache->service_uuid))
{
for (i = 0; p_cache && status != BTA_GATT_OK; i ++) {
if (bta_gattc_srvcid_compare(p_service_id, &p_cache->service_uuid)) {
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
APPL_TRACE_DEBUG("found matching service [0x%04x], inst[%d]",
p_cache->service_uuid.id.uuid.uu.uuid16,
@ -1313,8 +1228,7 @@ static tBTA_GATT_STATUS bta_gattc_find_record(tBTA_GATTC_SERV *p_srcb,
#endif
p_attr = p_cache->p_attr;
for (j = 0; p_attr; j ++)
{
for (j = 0; p_attr; j ++) {
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
APPL_TRACE_DEBUG("\t Attr[%d] handle[0x%04x] uuid[0x%04x] inst[%d] type[%d]",
j + 1, p_attr->attr_handle,
@ -1324,68 +1238,50 @@ static tBTA_GATT_STATUS bta_gattc_find_record(tBTA_GATTC_SERV *p_srcb,
#endif
bta_gattc_pack_attr_uuid(p_attr, &p_result->uuid);
if (p_start_rec != NULL && char_found == FALSE)
{
if (p_start_rec != NULL && char_found == FALSE) {
/* find the starting record first */
if (bta_gattc_uuid_compare(&p_start_rec->uuid, &p_result->uuid, FALSE) &&
p_start_rec->inst_id == p_attr->inst_id &&
(attr_type == p_attr->attr_type ||
/* find descriptor would look for characteristic first */
(attr_type == BTA_GATTC_ATTR_TYPE_CHAR_DESCR &&
p_attr->attr_type == BTA_GATTC_ATTR_TYPE_CHAR)))
{
p_attr->attr_type == BTA_GATTC_ATTR_TYPE_CHAR))) {
char_found = TRUE;
}
}
else
{
} else {
/* if looking for descriptor, here is the where the descrptor to be found */
if (attr_type == BTA_GATTC_ATTR_TYPE_CHAR_DESCR)
{
if (attr_type == BTA_GATTC_ATTR_TYPE_CHAR_DESCR) {
/* next characeteristic already, return error */
if (p_attr->attr_type != BTA_GATTC_ATTR_TYPE_CHAR_DESCR)
{
if (p_attr->attr_type != BTA_GATTC_ATTR_TYPE_CHAR_DESCR) {
break;
}
else
{
} else {
/* find starting descriptor */
if (p_descr_id != NULL && !descr_found)
{
if (p_descr_id != NULL && !descr_found) {
if (bta_gattc_uuid_compare(&p_descr_id->uuid, &p_result->uuid, TRUE)
&& p_descr_id->inst_id == p_attr->inst_id)
{
&& p_descr_id->inst_id == p_attr->inst_id) {
descr_found = TRUE;
}
}
else
{
} else {
/* with matching descriptor */
if (bta_gattc_uuid_compare(p_uuid_cond, &p_result->uuid, FALSE))
{
if (bta_gattc_uuid_compare(p_uuid_cond, &p_result->uuid, FALSE)) {
p_result->inst_id = p_attr->inst_id;
status = BTA_GATT_OK;
break;
}
}
}
}
else
{
} else {
if (bta_gattc_uuid_compare(p_uuid_cond, &p_result->uuid, FALSE) &&
attr_type == p_attr->attr_type)
{
attr_type == p_attr->attr_type) {
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
APPL_TRACE_DEBUG("found char handle mapping characteristic");
#endif
p_result->inst_id = p_attr->inst_id;
if (p_param != NULL)
{
if (p_param != NULL) {
if (attr_type == BTA_GATTC_ATTR_TYPE_CHAR ||
attr_type == BTA_GATTC_ATTR_TYPE_INCL_SRVC)
{
attr_type == BTA_GATTC_ATTR_TYPE_INCL_SRVC) {
*(tBTA_GATT_CHAR_PROP *)p_param = p_attr->property;
}
}
@ -1398,8 +1294,7 @@ static tBTA_GATT_STATUS bta_gattc_find_record(tBTA_GATTC_SERV *p_srcb,
p_attr = p_attr->p_next;
}
#if (defined BTA_GATT_DEBUG && BTA_GATT_DEBUG == TRUE)
if (status)
{
if (status) {
APPL_TRACE_ERROR("In the given service, can not find matching record");
}
#endif
@ -1441,14 +1336,11 @@ tBTA_GATT_STATUS bta_gattc_query_cache(UINT16 conn_id,
tBTA_GATTC_CLCB *p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id);
tBTA_GATT_STATUS status = BTA_GATT_ILLEGAL_PARAMETER;
if (p_clcb != NULL )
{
if (p_clcb->state == BTA_GATTC_CONN_ST)
{
if (p_clcb != NULL ) {
if (p_clcb->state == BTA_GATTC_CONN_ST) {
if (p_clcb->p_srcb &&
!p_clcb->p_srcb->p_srvc_list && /* no active discovery */
p_clcb->p_srcb->p_srvc_cache)
{
p_clcb->p_srcb->p_srvc_cache) {
status = bta_gattc_find_record(p_clcb->p_srcb,
query_type,
p_srvc_id,
@ -1456,22 +1348,16 @@ tBTA_GATT_STATUS bta_gattc_query_cache(UINT16 conn_id,
p_uuid_cond,
p_output,
p_param);
}
else
{
} else {
status = BTA_GATT_ERROR;
APPL_TRACE_ERROR("No server cache available");
}
}
else
{
} else {
APPL_TRACE_ERROR("server cache not available, CLCB state = %d", p_clcb->state);
status = (p_clcb->state == BTA_GATTC_DISCOVER_ST) ? BTA_GATT_BUSY : BTA_GATT_ERROR;
}
}
else
{
} else {
APPL_TRACE_ERROR("Unknown conn ID: %d", conn_id);
}
@ -1494,25 +1380,20 @@ void bta_gattc_rebuild_cache(tBTA_GATTC_SERV *p_srvc_cb, UINT16 num_attr,
{
/* first attribute loading, initialize buffer */
APPL_TRACE_ERROR("bta_gattc_rebuild_cache");
if (attr_index == 0)
{
while (!GKI_queue_is_empty(&p_srvc_cb->cache_buffer))
if (attr_index == 0) {
while (!GKI_queue_is_empty(&p_srvc_cb->cache_buffer)) {
GKI_freebuf (GKI_dequeue (&p_srvc_cb->cache_buffer));
if (bta_gattc_alloc_cache_buf(p_srvc_cb) == NULL)
{
APPL_TRACE_ERROR("allocate cache buffer failed, no resources");
}
else
{
if (bta_gattc_alloc_cache_buf(p_srvc_cb) == NULL) {
APPL_TRACE_ERROR("allocate cache buffer failed, no resources");
} else {
p_srvc_cb->p_cur_srvc = p_srvc_cb->p_srvc_cache = NULL;
}
}
while (num_attr > 0 && p_attr != NULL)
{
switch (p_attr->attr_type)
{
while (num_attr > 0 && p_attr != NULL) {
switch (p_attr->attr_type) {
case BTA_GATTC_ATTR_TYPE_SRVC:
bta_gattc_add_srvc_to_cache(p_srvc_cb,
p_attr->s_handle,
@ -1577,10 +1458,8 @@ BOOLEAN bta_gattc_cache_save(tBTA_GATTC_SERV *p_srvc_cb, UINT16 conn_id)
tBTA_GATTC_CACHE_ATTR *p_attr;
tBT_UUID uuid;
while (p_cur_srvc && i < BTA_GATTC_NV_LOAD_MAX)
{
if (offset ++ >= p_srvc_cb->attr_index)
{
while (p_cur_srvc && i < BTA_GATTC_NV_LOAD_MAX) {
if (offset ++ >= p_srvc_cb->attr_index) {
bta_gattc_fill_nv_attr(&nv_attr[i++],
BTA_GATTC_ATTR_TYPE_SRVC,
p_cur_srvc->s_handle,
@ -1593,16 +1472,11 @@ BOOLEAN bta_gattc_cache_save(tBTA_GATTC_SERV *p_srvc_cb, UINT16 conn_id)
p_attr = p_cur_srvc->p_attr;
for (; p_attr && i < BTA_GATTC_NV_LOAD_MAX ; offset ++, p_attr = p_attr->p_next)
{
if (offset >= p_srvc_cb->attr_index)
{
if ((uuid.len = p_attr->uuid_len) == LEN_UUID_16)
{
for (; p_attr && i < BTA_GATTC_NV_LOAD_MAX ; offset ++, p_attr = p_attr->p_next) {
if (offset >= p_srvc_cb->attr_index) {
if ((uuid.len = p_attr->uuid_len) == LEN_UUID_16) {
uuid.uu.uuid16 = p_attr->p_uuid->uuid16;
}
else
{
} else {
memcpy(uuid.uu.uuid128, p_attr->p_uuid->uuid128, LEN_UUID_128);
}
@ -1619,17 +1493,14 @@ BOOLEAN bta_gattc_cache_save(tBTA_GATTC_SERV *p_srvc_cb, UINT16 conn_id)
p_cur_srvc = p_cur_srvc->p_next;
}
if (i > 0)
{
if (i > 0) {
bta_gattc_co_cache_save(p_srvc_cb->server_bda, BTA_GATTC_CI_CACHE_SAVE_EVT, i,
nv_attr, p_srvc_cb->attr_index, conn_id);
p_srvc_cb->attr_index += i;
return TRUE;
}
else
{
} else {
return FALSE;
}
}

12
components/bt/bluedroid/bta/gatt/bta_gattc_ci.c Executable file → Normal file
View file

@ -54,8 +54,7 @@ void bta_gattc_ci_cache_open(BD_ADDR server_bda, UINT16 evt, tBTA_GATT_STATUS st
tBTA_GATTC_CI_EVT *p_evt;
UNUSED(server_bda);
if ((p_evt = (tBTA_GATTC_CI_EVT *) GKI_getbuf(sizeof(tBTA_GATTC_CI_EVT))) != NULL)
{
if ((p_evt = (tBTA_GATTC_CI_EVT *) GKI_getbuf(sizeof(tBTA_GATTC_CI_EVT))) != NULL) {
p_evt->hdr.event = evt;
p_evt->hdr.layer_specific = conn_id;
@ -87,8 +86,7 @@ void bta_gattc_ci_cache_load(BD_ADDR server_bda, UINT16 evt, UINT16 num_attr,
tBTA_GATTC_CI_LOAD *p_evt;
UNUSED(server_bda);
if ((p_evt = (tBTA_GATTC_CI_LOAD *) GKI_getbuf(sizeof(tBTA_GATTC_CI_LOAD))) != NULL)
{
if ((p_evt = (tBTA_GATTC_CI_LOAD *) GKI_getbuf(sizeof(tBTA_GATTC_CI_LOAD))) != NULL) {
memset(p_evt, 0, sizeof(tBTA_GATTC_CI_LOAD));
p_evt->hdr.event = evt;
@ -97,8 +95,7 @@ void bta_gattc_ci_cache_load(BD_ADDR server_bda, UINT16 evt, UINT16 num_attr,
p_evt->status = status;
p_evt->num_attr = (num_attr > BTA_GATTC_NV_LOAD_MAX) ? BTA_GATTC_NV_LOAD_MAX : num_attr;
if (p_evt->num_attr > 0 && p_attr != NULL)
{
if (p_evt->num_attr > 0 && p_attr != NULL) {
memcpy(p_evt->attr, p_attr, p_evt->num_attr * sizeof(tBTA_GATTC_NV_ATTR));
}
@ -128,8 +125,7 @@ void bta_gattc_ci_cache_save(BD_ADDR server_bda, UINT16 evt, tBTA_GATT_STATUS st
tBTA_GATTC_CI_EVT *p_evt;
UNUSED(server_bda);
if ((p_evt = (tBTA_GATTC_CI_EVT *) GKI_getbuf(sizeof(tBTA_GATTC_CI_EVT))) != NULL)
{
if ((p_evt = (tBTA_GATTC_CI_EVT *) GKI_getbuf(sizeof(tBTA_GATTC_CI_EVT))) != NULL) {
p_evt->hdr.event = evt;
p_evt->hdr.layer_specific = conn_id;

251
components/bt/bluedroid/bta/gatt/bta_gattc_main.c Executable file → Normal file
View file

@ -38,8 +38,7 @@
/* state machine action enumeration list */
enum
{
enum {
BTA_GATTC_OPEN,
BTA_GATTC_OPEN_FAIL,
BTA_GATTC_OPEN_ERROR,
@ -77,8 +76,7 @@ enum
typedef void (*tBTA_GATTC_ACTION)(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
/* action function list */
const tBTA_GATTC_ACTION bta_gattc_action[] =
{
const tBTA_GATTC_ACTION bta_gattc_action[] = {
bta_gattc_open,
bta_gattc_open_fail,
bta_gattc_open_error,
@ -118,149 +116,144 @@ const tBTA_GATTC_ACTION bta_gattc_action[] =
#define BTA_GATTC_NUM_COLS 2 /* number of columns in state tables */
/* state table for idle state */
static const UINT8 bta_gattc_st_idle[][BTA_GATTC_NUM_COLS] =
{
/* Event Action 1 Next state */
/* BTA_GATTC_API_OPEN_EVT */ {BTA_GATTC_OPEN, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_INT_OPEN_FAIL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_CANCEL_OPEN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
static const UINT8 bta_gattc_st_idle[][BTA_GATTC_NUM_COLS] = {
/* Event Action 1 Next state */
/* BTA_GATTC_API_OPEN_EVT */ {BTA_GATTC_OPEN, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_INT_OPEN_FAIL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_CANCEL_OPEN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_READ_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_WRITE_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_EXEC_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_CFG_MTU_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_READ_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_WRITE_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_EXEC_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_CFG_MTU_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_CLOSE_EVT */ {BTA_GATTC_CLOSE_FAIL, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_CLOSE_EVT */ {BTA_GATTC_CLOSE_FAIL, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_SEARCH_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_CONFIRM_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_SEARCH_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_CONFIRM_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_CONN, BTA_GATTC_CONN_ST},
/* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_INT_DISCONN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_CONN, BTA_GATTC_CONN_ST},
/* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_INT_DISCONN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* ===> for cache loading, saving */
/* BTA_GATTC_START_CACHE_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_CI_CACHE_OPEN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_CI_CACHE_LOAD_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_CI_CACHE_SAVE_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST}
/* ===> for cache loading, saving */
/* BTA_GATTC_START_CACHE_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_CI_CACHE_OPEN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_CI_CACHE_LOAD_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_CI_CACHE_SAVE_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_IDLE_ST}
};
/* state table for wait for open state */
static const UINT8 bta_gattc_st_w4_conn[][BTA_GATTC_NUM_COLS] =
{
/* Event Action 1 Next state */
/* BTA_GATTC_API_OPEN_EVT */ {BTA_GATTC_OPEN, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_INT_OPEN_FAIL_EVT */ {BTA_GATTC_OPEN_FAIL, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_CANCEL_OPEN_EVT */ {BTA_GATTC_CANCEL_OPEN, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */ {BTA_GATTC_CANCEL_OPEN_OK, BTA_GATTC_IDLE_ST},
static const UINT8 bta_gattc_st_w4_conn[][BTA_GATTC_NUM_COLS] = {
/* Event Action 1 Next state */
/* BTA_GATTC_API_OPEN_EVT */ {BTA_GATTC_OPEN, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_INT_OPEN_FAIL_EVT */ {BTA_GATTC_OPEN_FAIL, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_CANCEL_OPEN_EVT */ {BTA_GATTC_CANCEL_OPEN, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */ {BTA_GATTC_CANCEL_OPEN_OK, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_READ_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_WRITE_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_EXEC_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_CFG_MTU_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_READ_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_WRITE_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_EXEC_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_CFG_MTU_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_CLOSE_EVT */ {BTA_GATTC_CANCEL_OPEN, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_CLOSE_EVT */ {BTA_GATTC_CANCEL_OPEN, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_SEARCH_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_CONFIRM_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_SEARCH_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_CONFIRM_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_CONN, BTA_GATTC_CONN_ST},
/* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_INT_DISCONN_EVT */ {BTA_GATTC_OPEN_FAIL, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_CONN, BTA_GATTC_CONN_ST},
/* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_INT_DISCONN_EVT */ {BTA_GATTC_OPEN_FAIL, BTA_GATTC_IDLE_ST},
/* ===> for cache loading, saving */
/* BTA_GATTC_START_CACHE_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_CI_CACHE_OPEN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_CI_CACHE_LOAD_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_CI_CACHE_SAVE_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST}
/* ===> for cache loading, saving */
/* BTA_GATTC_START_CACHE_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_CI_CACHE_OPEN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_CI_CACHE_LOAD_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST},
/* BTA_GATTC_CI_CACHE_SAVE_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_W4_CONN_ST}
};
/* state table for open state */
static const UINT8 bta_gattc_st_connected[][BTA_GATTC_NUM_COLS] =
{
/* Event Action 1 Next state */
/* BTA_GATTC_API_OPEN_EVT */ {BTA_GATTC_OPEN, BTA_GATTC_CONN_ST},
/* BTA_GATTC_INT_OPEN_FAIL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_CANCEL_OPEN_EVT */ {BTA_GATTC_CANCEL_OPEN_ERROR, BTA_GATTC_CONN_ST},
/* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
static const UINT8 bta_gattc_st_connected[][BTA_GATTC_NUM_COLS] = {
/* Event Action 1 Next state */
/* BTA_GATTC_API_OPEN_EVT */ {BTA_GATTC_OPEN, BTA_GATTC_CONN_ST},
/* BTA_GATTC_INT_OPEN_FAIL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_CANCEL_OPEN_EVT */ {BTA_GATTC_CANCEL_OPEN_ERROR, BTA_GATTC_CONN_ST},
/* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_READ_EVT */ {BTA_GATTC_READ, BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_WRITE_EVT */ {BTA_GATTC_WRITE, BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_EXEC_EVT */ {BTA_GATTC_EXEC, BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_CFG_MTU_EVT */ {BTA_GATTC_CFG_MTU, BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_READ_EVT */ {BTA_GATTC_READ, BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_WRITE_EVT */ {BTA_GATTC_WRITE, BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_EXEC_EVT */ {BTA_GATTC_EXEC, BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_CFG_MTU_EVT */ {BTA_GATTC_CFG_MTU, BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_CLOSE_EVT */ {BTA_GATTC_CLOSE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_CLOSE_EVT */ {BTA_GATTC_CLOSE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_API_SEARCH_EVT */ {BTA_GATTC_SEARCH, BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_CONFIRM_EVT */ {BTA_GATTC_CONFIRM, BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_READ_MULTI, BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_SEARCH_EVT */ {BTA_GATTC_SEARCH, BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_CONFIRM_EVT */ {BTA_GATTC_CONFIRM, BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_READ_MULTI, BTA_GATTC_CONN_ST},
/* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
/* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
/* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_START_DISCOVER, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
/* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_OP_CMPL, BTA_GATTC_CONN_ST},
/* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
/* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_START_DISCOVER, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
/* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_OP_CMPL, BTA_GATTC_CONN_ST},
/* BTA_GATTC_INT_DISCONN_EVT */ {BTA_GATTC_CLOSE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_INT_DISCONN_EVT */ {BTA_GATTC_CLOSE, BTA_GATTC_IDLE_ST},
/* ===> for cache loading, saving */
/* BTA_GATTC_START_CACHE_EVT */ {BTA_GATTC_CACHE_OPEN, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_CI_CACHE_OPEN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
/* BTA_GATTC_CI_CACHE_LOAD_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
/* BTA_GATTC_CI_CACHE_SAVE_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST}
/* ===> for cache loading, saving */
/* BTA_GATTC_START_CACHE_EVT */ {BTA_GATTC_CACHE_OPEN, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_CI_CACHE_OPEN_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
/* BTA_GATTC_CI_CACHE_LOAD_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST},
/* BTA_GATTC_CI_CACHE_SAVE_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_CONN_ST}
};
/* state table for discover state */
static const UINT8 bta_gattc_st_discover[][BTA_GATTC_NUM_COLS] =
{
/* Event Action 1 Next state */
/* BTA_GATTC_API_OPEN_EVT */ {BTA_GATTC_OPEN, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_INT_OPEN_FAIL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_CANCEL_OPEN_EVT */ {BTA_GATTC_CANCEL_OPEN_ERROR, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_DISCOVER_ST},
static const UINT8 bta_gattc_st_discover[][BTA_GATTC_NUM_COLS] = {
/* Event Action 1 Next state */
/* BTA_GATTC_API_OPEN_EVT */ {BTA_GATTC_OPEN, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_INT_OPEN_FAIL_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_CANCEL_OPEN_EVT */ {BTA_GATTC_CANCEL_OPEN_ERROR, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_INT_CANCEL_OPEN_OK_EVT */ {BTA_GATTC_FAIL, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_READ_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_WRITE_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_EXEC_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_CFG_MTU_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_READ_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_WRITE_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_EXEC_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_CFG_MTU_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_CLOSE_EVT */ {BTA_GATTC_DISC_CLOSE, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_CLOSE_EVT */ {BTA_GATTC_DISC_CLOSE, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_SEARCH_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_CONFIRM_EVT */ {BTA_GATTC_CONFIRM, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_SEARCH_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_CONFIRM_EVT */ {BTA_GATTC_CONFIRM, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_READ_MULTI_EVT */ {BTA_GATTC_Q_CMD, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_API_REFRESH_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_CONN, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_RESTART_DISCOVER, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_DISC_CMPL, BTA_GATTC_CONN_ST},
/* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_IGNORE_OP_CMPL, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_INT_DISCONN_EVT */ {BTA_GATTC_CLOSE, BTA_GATTC_IDLE_ST},
/* BTA_GATTC_INT_CONN_EVT */ {BTA_GATTC_CONN, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_INT_DISCOVER_EVT */ {BTA_GATTC_RESTART_DISCOVER, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_DISCOVER_CMPL_EVT */ {BTA_GATTC_DISC_CMPL, BTA_GATTC_CONN_ST},
/* BTA_GATTC_OP_CMPL_EVT */ {BTA_GATTC_IGNORE_OP_CMPL, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_INT_DISCONN_EVT */ {BTA_GATTC_CLOSE, BTA_GATTC_IDLE_ST},
/* ===> for cache loading, saving */
/* BTA_GATTC_START_CACHE_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_CI_CACHE_OPEN_EVT */ {BTA_GATTC_CI_OPEN, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_CI_CACHE_LOAD_EVT */ {BTA_GATTC_CI_LOAD, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_CI_CACHE_SAVE_EVT */ {BTA_GATTC_CI_SAVE, BTA_GATTC_DISCOVER_ST}
/* ===> for cache loading, saving */
/* BTA_GATTC_START_CACHE_EVT */ {BTA_GATTC_IGNORE, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_CI_CACHE_OPEN_EVT */ {BTA_GATTC_CI_OPEN, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_CI_CACHE_LOAD_EVT */ {BTA_GATTC_CI_LOAD, BTA_GATTC_DISCOVER_ST},
/* BTA_GATTC_CI_CACHE_SAVE_EVT */ {BTA_GATTC_CI_SAVE, BTA_GATTC_DISCOVER_ST}
};
/* type for state table */
typedef const UINT8 (*tBTA_GATTC_ST_TBL)[BTA_GATTC_NUM_COLS];
/* state table */
const tBTA_GATTC_ST_TBL bta_gattc_st_tbl[] =
{
const tBTA_GATTC_ST_TBL bta_gattc_st_tbl[] = {
bta_gattc_st_idle,
bta_gattc_st_w4_conn,
bta_gattc_st_connected,
@ -317,10 +310,8 @@ BOOLEAN bta_gattc_sm_execute(tBTA_GATTC_CLCB *p_clcb, UINT16 event, tBTA_GATTC_D
p_clcb->state = state_table[event][BTA_GATTC_NEXT_STATE];
/* execute action functions */
for (i = 0; i < BTA_GATTC_ACTIONS; i++)
{
if ((action = state_table[event][i]) != BTA_GATTC_IGNORE)
{
for (i = 0; i < BTA_GATTC_ACTIONS; i++) {
if ((action = state_table[event][i]) != BTA_GATTC_IGNORE) {
(*bta_gattc_action[action])(p_clcb, p_data);
if (p_clcb->p_q_cmd == p_data) {
/* buffer is queued, don't free in the bta dispatcher.
@ -328,16 +319,13 @@ BOOLEAN bta_gattc_sm_execute(tBTA_GATTC_CLCB *p_clcb, UINT16 event, tBTA_GATTC_D
*/
rt = FALSE;
}
}
else
{
} else {
break;
}
}
#if BTA_GATT_DEBUG == TRUE
if (in_state != p_clcb->state)
{
if (in_state != p_clcb->state) {
APPL_TRACE_DEBUG("GATTC State Change: [%s] -> [%s] after Event [%s]",
gattc_state_code(in_state),
gattc_state_code(p_clcb->state),
@ -366,8 +354,7 @@ BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg)
#if BTA_GATT_DEBUG == TRUE
APPL_TRACE_DEBUG("bta_gattc_hdl_event: Event [%s]\n", gattc_evt_code(p_msg->event));
#endif
switch (p_msg->event)
{
switch (p_msg->event) {
case BTA_GATTC_API_DISABLE_EVT:
bta_gattc_disable(p_cb);
break;
@ -411,19 +398,17 @@ BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg)
break;
default:
if (p_msg->event == BTA_GATTC_INT_CONN_EVT)
if (p_msg->event == BTA_GATTC_INT_CONN_EVT) {
p_clcb = bta_gattc_find_int_conn_clcb((tBTA_GATTC_DATA *) p_msg);
else if (p_msg->event == BTA_GATTC_INT_DISCONN_EVT)
} else if (p_msg->event == BTA_GATTC_INT_DISCONN_EVT) {
p_clcb = bta_gattc_find_int_disconn_clcb((tBTA_GATTC_DATA *) p_msg);
else
} else {
p_clcb = bta_gattc_find_clcb_by_conn_id(p_msg->layer_specific);
if (p_clcb != NULL)
{
rt = bta_gattc_sm_execute(p_clcb, p_msg->event, (tBTA_GATTC_DATA *) p_msg);
}
else
{
if (p_clcb != NULL) {
rt = bta_gattc_sm_execute(p_clcb, p_msg->event, (tBTA_GATTC_DATA *) p_msg);
} else {
APPL_TRACE_DEBUG("Ignore unknown conn ID: %d\n", p_msg->layer_specific);
}
@ -451,8 +436,7 @@ BOOLEAN bta_gattc_hdl_event(BT_HDR *p_msg)
*******************************************************************************/
static char *gattc_evt_code(tBTA_GATTC_INT_EVT evt_code)
{
switch (evt_code)
{
switch (evt_code) {
case BTA_GATTC_API_OPEN_EVT:
return "BTA_GATTC_API_OPEN_EVT";
case BTA_GATTC_INT_OPEN_FAIL_EVT:
@ -523,8 +507,7 @@ static char *gattc_evt_code(tBTA_GATTC_INT_EVT evt_code)
*******************************************************************************/
static char *gattc_state_code(tBTA_GATTC_STATE state_code)
{
switch (state_code)
{
switch (state_code) {
case BTA_GATTC_IDLE_ST:
return "GATTC_IDLE_ST";
case BTA_GATTC_W4_CONN_ST:

325
components/bt/bluedroid/bta/gatt/bta_gattc_utils.c Executable file → Normal file
View file

@ -43,9 +43,10 @@
static const UINT8 base_uuid[LEN_UUID_128] = {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static const BD_ADDR dummy_bda = {0,0,0,0,0,0};
static const BD_ADDR dummy_bda = {0, 0, 0, 0, 0, 0};
/*******************************************************************************
**
@ -79,40 +80,37 @@ BOOLEAN bta_gattc_uuid_compare (tBT_UUID *p_src, tBT_UUID *p_tar, BOOLEAN is_pre
UINT8 *ps, *pt;
/* any of the UUID is unspecified */
if (p_src == 0 || p_tar == 0)
{
if (is_precise)
if (p_src == 0 || p_tar == 0) {
if (is_precise) {
return FALSE;
else
} else {
return TRUE;
}
}
/* If both are 16-bit, we can do a simple compare */
if (p_src->len == 2 && p_tar->len == 2)
{
if (p_src->len == 2 && p_tar->len == 2) {
return p_src->uu.uuid16 == p_tar->uu.uuid16;
}
/* One or both of the UUIDs is 128-bit */
if (p_src->len == LEN_UUID_16)
{
if (p_src->len == LEN_UUID_16) {
/* convert a 16 bits UUID to 128 bits value */
bta_gatt_convert_uuid16_to_uuid128(su, p_src->uu.uuid16);
ps = su;
}
else
} else {
ps = p_src->uu.uuid128;
}
if (p_tar->len == LEN_UUID_16)
{
if (p_tar->len == LEN_UUID_16) {
/* convert a 16 bits UUID to 128 bits value */
bta_gatt_convert_uuid16_to_uuid128(tu, p_tar->uu.uuid16);
pt = tu;
}
else
} else {
pt = p_tar->uu.uuid128;
}
return(memcmp(ps, pt, LEN_UUID_128) == 0);
return (memcmp(ps, pt, LEN_UUID_128) == 0);
}
/*******************************************************************************
@ -124,17 +122,17 @@ BOOLEAN bta_gattc_uuid_compare (tBT_UUID *p_src, tBT_UUID *p_tar, BOOLEAN is_pre
** Returns pointer to the regcb
**
*******************************************************************************/
tBTA_GATTC_RCB * bta_gattc_cl_get_regcb(UINT8 client_if)
tBTA_GATTC_RCB *bta_gattc_cl_get_regcb(UINT8 client_if)
{
UINT8 i = 0;
tBTA_GATTC_RCB *p_clrcb = &bta_gattc_cb.cl_rcb[0];
for (i = 0; i < BTA_GATTC_CL_MAX; i ++, p_clrcb ++)
{
for (i = 0; i < BTA_GATTC_CL_MAX; i ++, p_clrcb ++) {
if (p_clrcb->in_use &&
p_clrcb->client_if == client_if)
p_clrcb->client_if == client_if) {
return p_clrcb;
}
}
return NULL;
}
/*******************************************************************************
@ -150,11 +148,11 @@ UINT8 bta_gattc_num_reg_app(void)
{
UINT8 i = 0, j = 0;
for (i = 0; i < BTA_GATTC_CL_MAX; i ++)
{
if (bta_gattc_cb.cl_rcb[i].in_use)
for (i = 0; i < BTA_GATTC_CL_MAX; i ++) {
if (bta_gattc_cb.cl_rcb[i].in_use) {
j ++;
}
}
return j;
}
/*******************************************************************************
@ -166,20 +164,20 @@ UINT8 bta_gattc_num_reg_app(void)
** Returns pointer to the clcb
**
*******************************************************************************/
tBTA_GATTC_CLCB * bta_gattc_find_clcb_by_cif (UINT8 client_if, BD_ADDR remote_bda,
tBTA_GATTC_CLCB *bta_gattc_find_clcb_by_cif (UINT8 client_if, BD_ADDR remote_bda,
tBTA_TRANSPORT transport)
{
tBTA_GATTC_CLCB *p_clcb = &bta_gattc_cb.clcb[0];
UINT8 i;
for (i = 0; i < BTA_GATTC_CLCB_MAX; i ++, p_clcb ++)
{
for (i = 0; i < BTA_GATTC_CLCB_MAX; i ++, p_clcb ++) {
if (p_clcb->in_use &&
p_clcb->p_rcb->client_if == client_if &&
p_clcb->transport == transport &&
bdcmp(p_clcb->bda, remote_bda) == 0)
bdcmp(p_clcb->bda, remote_bda) == 0) {
return p_clcb;
}
}
return NULL;
}
/*******************************************************************************
@ -191,17 +189,17 @@ tBTA_GATTC_CLCB * bta_gattc_find_clcb_by_cif (UINT8 client_if, BD_ADDR remote_bd
** Returns pointer to the clcb
**
*******************************************************************************/
tBTA_GATTC_CLCB * bta_gattc_find_clcb_by_conn_id (UINT16 conn_id)
tBTA_GATTC_CLCB *bta_gattc_find_clcb_by_conn_id (UINT16 conn_id)
{
tBTA_GATTC_CLCB *p_clcb = &bta_gattc_cb.clcb[0];
UINT8 i;
for (i = 0; i < BTA_GATTC_CLCB_MAX; i ++, p_clcb ++)
{
for (i = 0; i < BTA_GATTC_CLCB_MAX; i ++, p_clcb ++) {
if (p_clcb->in_use &&
p_clcb->bta_conn_id == conn_id)
p_clcb->bta_conn_id == conn_id) {
return p_clcb;
}
}
return NULL;
}
@ -214,18 +212,16 @@ tBTA_GATTC_CLCB * bta_gattc_find_clcb_by_conn_id (UINT16 conn_id)
** Returns pointer to the clcb
**
*******************************************************************************/
tBTA_GATTC_CLCB * bta_gattc_clcb_alloc(tBTA_GATTC_IF client_if, BD_ADDR remote_bda,
tBTA_GATTC_CLCB *bta_gattc_clcb_alloc(tBTA_GATTC_IF client_if, BD_ADDR remote_bda,
tBTA_TRANSPORT transport)
{
UINT8 i_clcb = 0;
tBTA_GATTC_CLCB *p_clcb = NULL;
for (i_clcb = 0; i_clcb < BTA_GATTC_CLCB_MAX; i_clcb++)
{
if (!bta_gattc_cb.clcb[i_clcb].in_use)
{
for (i_clcb = 0; i_clcb < BTA_GATTC_CLCB_MAX; i_clcb++) {
if (!bta_gattc_cb.clcb[i_clcb].in_use) {
#if BTA_GATT_DEBUG == TRUE
APPL_TRACE_DEBUG("bta_gattc_clcb_alloc: found clcb[%d] available",i_clcb);
APPL_TRACE_DEBUG("bta_gattc_clcb_alloc: found clcb[%d] available", i_clcb);
#endif
p_clcb = &bta_gattc_cb.clcb[i_clcb];
p_clcb->in_use = TRUE;
@ -235,16 +231,14 @@ tBTA_GATTC_CLCB * bta_gattc_clcb_alloc(tBTA_GATTC_IF client_if, BD_ADDR remote_b
p_clcb->p_rcb = bta_gattc_cl_get_regcb(client_if);
if ((p_clcb->p_srcb = bta_gattc_find_srcb(remote_bda)) == NULL)
if ((p_clcb->p_srcb = bta_gattc_find_srcb(remote_bda)) == NULL) {
p_clcb->p_srcb = bta_gattc_srcb_alloc(remote_bda);
}
if (p_clcb->p_rcb != NULL && p_clcb->p_srcb != NULL)
{
if (p_clcb->p_rcb != NULL && p_clcb->p_srcb != NULL) {
p_clcb->p_srcb->num_clcb ++;
p_clcb->p_rcb->num_clcb ++;
}
else
{
} else {
/* release this clcb if clcb or srcb allocation failed */
p_clcb->in_use = FALSE;
p_clcb = NULL;
@ -268,8 +262,7 @@ tBTA_GATTC_CLCB *bta_gattc_find_alloc_clcb(tBTA_GATTC_IF client_if, BD_ADDR remo
{
tBTA_GATTC_CLCB *p_clcb ;
if ((p_clcb = bta_gattc_find_clcb_by_cif(client_if, remote_bda, transport)) == NULL)
{
if ((p_clcb = bta_gattc_find_clcb_by_cif(client_if, remote_bda, transport)) == NULL) {
p_clcb = bta_gattc_clcb_alloc(client_if, remote_bda, transport);
}
return p_clcb;
@ -288,18 +281,18 @@ void bta_gattc_clcb_dealloc(tBTA_GATTC_CLCB *p_clcb)
{
tBTA_GATTC_SERV *p_srcb = NULL;
if (p_clcb)
{
if (p_clcb) {
p_srcb = p_clcb->p_srcb;
if (p_srcb->num_clcb)
if (p_srcb->num_clcb) {
p_srcb->num_clcb --;
}
if (p_clcb->p_rcb->num_clcb)
if (p_clcb->p_rcb->num_clcb) {
p_clcb->p_rcb->num_clcb --;
}
/* if the srcb is no longer needed, reset the state */
if ( p_srcb->num_clcb == 0)
{
if ( p_srcb->num_clcb == 0) {
p_srcb->connected = FALSE;
p_srcb->state = BTA_GATTC_SERV_IDLE;
p_srcb->mtu = 0;
@ -308,9 +301,7 @@ void bta_gattc_clcb_dealloc(tBTA_GATTC_CLCB *p_clcb)
utl_freebuf((void **)&p_clcb->p_q_cmd);
memset(p_clcb, 0, sizeof(tBTA_GATTC_CLCB));
}
else
{
} else {
APPL_TRACE_ERROR("bta_gattc_clcb_dealloc p_clcb=NULL");
}
}
@ -324,16 +315,16 @@ void bta_gattc_clcb_dealloc(tBTA_GATTC_CLCB *p_clcb)
** Returns pointer to the server cache.
**
*******************************************************************************/
tBTA_GATTC_SERV * bta_gattc_find_srcb(BD_ADDR bda)
tBTA_GATTC_SERV *bta_gattc_find_srcb(BD_ADDR bda)
{
tBTA_GATTC_SERV *p_srcb = &bta_gattc_cb.known_server[0];
UINT8 i;
for (i = 0; i < BTA_GATTC_KNOWN_SR_MAX; i ++, p_srcb ++)
{
if (p_srcb->in_use && bdcmp(p_srcb->server_bda, bda) == 0)
for (i = 0; i < BTA_GATTC_KNOWN_SR_MAX; i ++, p_srcb ++) {
if (p_srcb->in_use && bdcmp(p_srcb->server_bda, bda) == 0) {
return p_srcb;
}
}
return NULL;
}
@ -346,16 +337,16 @@ tBTA_GATTC_SERV * bta_gattc_find_srcb(BD_ADDR bda)
** Returns pointer to the server cache.
**
*******************************************************************************/
tBTA_GATTC_SERV * bta_gattc_find_srvr_cache(BD_ADDR bda)
tBTA_GATTC_SERV *bta_gattc_find_srvr_cache(BD_ADDR bda)
{
tBTA_GATTC_SERV *p_srcb = &bta_gattc_cb.known_server[0];
UINT8 i;
for (i = 0; i < BTA_GATTC_KNOWN_SR_MAX; i ++, p_srcb ++)
{
if (bdcmp(p_srcb->server_bda, bda) == 0)
for (i = 0; i < BTA_GATTC_KNOWN_SR_MAX; i ++, p_srcb ++) {
if (bdcmp(p_srcb->server_bda, bda) == 0) {
return p_srcb;
}
}
return NULL;
}
/*******************************************************************************
@ -367,14 +358,15 @@ tBTA_GATTC_SERV * bta_gattc_find_srvr_cache(BD_ADDR bda)
** Returns pointer to the server cache.
**
*******************************************************************************/
tBTA_GATTC_SERV * bta_gattc_find_scb_by_cid (UINT16 conn_id)
tBTA_GATTC_SERV *bta_gattc_find_scb_by_cid (UINT16 conn_id)
{
tBTA_GATTC_CLCB *p_clcb = bta_gattc_find_clcb_by_conn_id(conn_id);
if (p_clcb)
if (p_clcb) {
return p_clcb->p_srcb;
else
} else {
return NULL;
}
}
/*******************************************************************************
**
@ -385,36 +377,33 @@ tBTA_GATTC_SERV * bta_gattc_find_scb_by_cid (UINT16 conn_id)
** Returns pointer to the server cache.
**
*******************************************************************************/
tBTA_GATTC_SERV * bta_gattc_srcb_alloc(BD_ADDR bda)
tBTA_GATTC_SERV *bta_gattc_srcb_alloc(BD_ADDR bda)
{
tBTA_GATTC_SERV *p_tcb = &bta_gattc_cb.known_server[0],
*p_recycle = NULL;
BOOLEAN found = FALSE;
UINT8 i;
for (i = 0; i < BTA_GATTC_KNOWN_SR_MAX; i ++, p_tcb ++)
{
if (!p_tcb->in_use)
{
for (i = 0; i < BTA_GATTC_KNOWN_SR_MAX; i ++, p_tcb ++) {
if (!p_tcb->in_use) {
found = TRUE;
break;
}
else if (!p_tcb->connected)
{
} else if (!p_tcb->connected) {
p_recycle = p_tcb;
}
}
/* if not found, try to recycle one known device */
if (!found && !p_recycle)
if (!found && !p_recycle) {
p_tcb = NULL;
else if (!found && p_recycle)
} else if (!found && p_recycle) {
p_tcb = p_recycle;
}
if (p_tcb != NULL)
{
while (!GKI_queue_is_empty(&p_tcb->cache_buffer))
if (p_tcb != NULL) {
while (!GKI_queue_is_empty(&p_tcb->cache_buffer)) {
GKI_freebuf (GKI_dequeue (&p_tcb->cache_buffer));
}
utl_freebuf((void **)&p_tcb->p_srvc_list);
memset(p_tcb, 0 , sizeof(tBTA_GATTC_SERV));
@ -436,12 +425,9 @@ tBTA_GATTC_SERV * bta_gattc_srcb_alloc(BD_ADDR bda)
BOOLEAN bta_gattc_enqueue(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
{
if (p_clcb->p_q_cmd == NULL)
{
if (p_clcb->p_q_cmd == NULL) {
p_clcb->p_q_cmd = p_data;
}
else
{
} else {
APPL_TRACE_ERROR("already has a pending command!!");
/* skip the callback now. ----- need to send callback ? */
}
@ -466,12 +452,9 @@ void bta_gattc_pack_attr_uuid(tBTA_GATTC_CACHE_ATTR *p_attr, tBT_UUID *p_uuid)
p_uuid->len = p_attr->uuid_len;
if (p_attr->uuid_len == LEN_UUID_16)
{
if (p_attr->uuid_len == LEN_UUID_16) {
STREAM_TO_UINT16(p_uuid->uu.uuid16, pp);
}
else
{
} else {
memcpy(p_uuid->uu.uuid128, pp, LEN_UUID_128);
}
@ -494,12 +477,9 @@ void bta_gattc_cpygattid(tBTA_GATT_ID *p_des, tBTA_GATT_ID *p_src)
p_des->uuid.len = p_src->uuid.len;
if (p_des->uuid.len == LEN_UUID_16)
{
if (p_des->uuid.len == LEN_UUID_16) {
p_des->uuid.uu.uuid16 = p_src->uuid.uu.uuid16;
}
else if (p_des->uuid.len == LEN_UUID_128)
{
} else if (p_des->uuid.len == LEN_UUID_128) {
memcpy(p_des->uuid.uu.uuid128, p_src->uuid.uu.uuid128, LEN_UUID_128);
}
}
@ -515,10 +495,11 @@ void bta_gattc_cpygattid(tBTA_GATT_ID *p_des, tBTA_GATT_ID *p_src)
BOOLEAN bta_gattc_gattid_compare(tBTA_GATT_ID *p_src, tBTA_GATT_ID *p_tar)
{
if (p_src->inst_id == p_tar->inst_id &&
bta_gattc_uuid_compare (&p_src->uuid, &p_tar->uuid, TRUE ))
bta_gattc_uuid_compare (&p_src->uuid, &p_tar->uuid, TRUE )) {
return TRUE;
else
} else {
return FALSE;
}
}
/*******************************************************************************
@ -533,10 +514,11 @@ BOOLEAN bta_gattc_gattid_compare(tBTA_GATT_ID *p_src, tBTA_GATT_ID *p_tar)
BOOLEAN bta_gattc_srvcid_compare(tBTA_GATT_SRVC_ID *p_src, tBTA_GATT_SRVC_ID *p_tar)
{
if (p_src->is_primary == p_tar->is_primary &&
bta_gattc_gattid_compare (&p_src->id, &p_tar->id))
bta_gattc_gattid_compare (&p_src->id, &p_tar->id)) {
return TRUE;
else
} else {
return FALSE;
}
}
/*******************************************************************************
**
@ -550,10 +532,11 @@ BOOLEAN bta_gattc_srvcid_compare(tBTA_GATT_SRVC_ID *p_src, tBTA_GATT_SRVC_ID *p_
BOOLEAN bta_gattc_charid_compare(tBTA_GATTC_CHAR_ID *p_src, tBTA_GATTC_CHAR_ID *p_tar)
{
if (bta_gattc_gattid_compare (&p_src->char_id, &p_tar->char_id) &&
bta_gattc_srvcid_compare (&p_src->srvc_id, &p_tar->srvc_id))
bta_gattc_srvcid_compare (&p_src->srvc_id, &p_tar->srvc_id)) {
return TRUE;
else
} else {
return FALSE;
}
}
/*******************************************************************************
@ -570,12 +553,10 @@ BOOLEAN bta_gattc_check_notif_registry(tBTA_GATTC_RCB *p_clreg, tBTA_GATTC_SERV
{
UINT8 i;
for (i = 0 ; i < BTA_GATTC_NOTIF_REG_MAX; i ++)
{
for (i = 0 ; i < BTA_GATTC_NOTIF_REG_MAX; i ++) {
if (p_clreg->notif_reg[i].in_use &&
bdcmp(p_clreg->notif_reg[i].remote_bda, p_srcb->server_bda) == 0 &&
bta_gattc_charid_compare (&p_clreg->notif_reg[i].char_id, &p_notify->char_id))
{
bta_gattc_charid_compare (&p_clreg->notif_reg[i].char_id, &p_notify->char_id)) {
APPL_TRACE_DEBUG("Notification registered!");
return TRUE;
}
@ -600,20 +581,16 @@ void bta_gattc_clear_notif_registration(UINT16 conn_id)
UINT8 i;
tGATT_TRANSPORT transport;
if (GATT_GetConnectionInfor(conn_id, &gatt_if, remote_bda, &transport))
{
if ((p_clrcb = bta_gattc_cl_get_regcb(gatt_if)) != NULL)
{
for (i = 0 ; i < BTA_GATTC_NOTIF_REG_MAX; i ++)
{
if (GATT_GetConnectionInfor(conn_id, &gatt_if, remote_bda, &transport)) {
if ((p_clrcb = bta_gattc_cl_get_regcb(gatt_if)) != NULL) {
for (i = 0 ; i < BTA_GATTC_NOTIF_REG_MAX; i ++) {
if (p_clrcb->notif_reg[i].in_use &&
!bdcmp(p_clrcb->notif_reg[i].remote_bda, remote_bda))
!bdcmp(p_clrcb->notif_reg[i].remote_bda, remote_bda)) {
memset(&p_clrcb->notif_reg[i], 0, sizeof(tBTA_GATTC_NOTIF_REG));
}
}
}
else
{
} else {
APPL_TRACE_ERROR("can not clear indication/notif registration for unknown app");
}
return;
@ -639,18 +616,15 @@ tBTA_GATT_STATUS bta_gattc_pack_read_cb_data(tBTA_GATTC_SERV *p_srcb,
tBTA_GATT_STATUS status = BTA_GATT_OK;
/* GATT_UUID_CHAR_AGG_FORMAT */
if (bta_gattc_uuid_compare (&uuid, p_descr_uuid, TRUE))
{
while (p_attr->len >= 2 && i < BTA_GATTC_MULTI_MAX)
{
if (bta_gattc_uuid_compare (&uuid, p_descr_uuid, TRUE)) {
while (p_attr->len >= 2 && i < BTA_GATTC_MULTI_MAX) {
STREAM_TO_UINT16(handle, pp);
if (bta_gattc_handle2id(p_srcb,
handle,
&p_value->aggre_value.pre_format[i].char_id.srvc_id,
&p_value->aggre_value.pre_format[i].char_id.char_id,
&p_value->aggre_value.pre_format[i].descr_id) == FALSE)
{
&p_value->aggre_value.pre_format[i].descr_id) == FALSE) {
status = BTA_GATT_INTERNAL_ERROR;
APPL_TRACE_ERROR("can not map to GATT ID. handle = 0x%04x", handle);
break;
@ -659,9 +633,7 @@ tBTA_GATT_STATUS bta_gattc_pack_read_cb_data(tBTA_GATTC_SERV *p_srcb,
p_attr->len -= 2;
}
p_value->aggre_value.num_pres_fmt = i;
}
else
{
} else {
/* all others, take as raw format */
p_value->unformat.len = p_attr->len;
p_value->unformat.p_value = p_attr->value;
@ -685,59 +657,52 @@ BOOLEAN bta_gattc_mark_bg_conn (tBTA_GATTC_IF client_if, BD_ADDR_PTR remote_bda
UINT8 i = 0;
tBTA_GATTC_CIF_MASK *p_cif_mask;
for (i = 0; i < BTA_GATTC_KNOWN_SR_MAX; i ++, p_bg_tck ++)
{
for (i = 0; i < BTA_GATTC_KNOWN_SR_MAX; i ++, p_bg_tck ++) {
if (p_bg_tck->in_use &&
((remote_bda_ptr != NULL && bdcmp(p_bg_tck->remote_bda, remote_bda_ptr) == 0) ||
(remote_bda_ptr == NULL && bdcmp(p_bg_tck->remote_bda, dummy_bda) == 0)))
{
(remote_bda_ptr == NULL && bdcmp(p_bg_tck->remote_bda, dummy_bda) == 0))) {
p_cif_mask = is_listen ? &p_bg_tck->cif_adv_mask : &p_bg_tck->cif_mask;
if (add)
/* mask on the cif bit */
*p_cif_mask |= (1 <<(client_if - 1));
else
{
if (client_if != 0)
*p_cif_mask &= (~(1 <<(client_if - 1)));
else
*p_cif_mask |= (1 << (client_if - 1));
} else {
if (client_if != 0) {
*p_cif_mask &= (~(1 << (client_if - 1)));
} else {
*p_cif_mask = 0;
}
}
/* no BG connection for this device, make it available */
if (p_bg_tck->cif_mask == 0 && p_bg_tck->cif_adv_mask == 0)
{
if (p_bg_tck->cif_mask == 0 && p_bg_tck->cif_adv_mask == 0) {
memset(p_bg_tck, 0, sizeof(tBTA_GATTC_BG_TCK));
}
return TRUE;
}
}
if (!add)
{
if (remote_bda_ptr)
{
if (!add) {
if (remote_bda_ptr) {
// bdstr_t bdstr = {0};
char bdstr[18] = {0};
APPL_TRACE_ERROR("%s unable to find the bg connection mask for: %s", __func__,
bdaddr_to_string((bt_bdaddr_t *)remote_bda_ptr, bdstr, sizeof(bdstr)));
}
return FALSE;
}
else /* adding a new device mask */
{
} else { /* adding a new device mask */
for (i = 0, p_bg_tck = &bta_gattc_cb.bg_track[0];
i < BTA_GATTC_KNOWN_SR_MAX; i ++, p_bg_tck ++)
{
if (!p_bg_tck->in_use)
{
i < BTA_GATTC_KNOWN_SR_MAX; i ++, p_bg_tck ++) {
if (!p_bg_tck->in_use) {
p_bg_tck->in_use = TRUE;
if (remote_bda_ptr)
if (remote_bda_ptr) {
bdcpy(p_bg_tck->remote_bda, remote_bda_ptr);
else
} else {
bdcpy(p_bg_tck->remote_bda, dummy_bda);
}
p_cif_mask = is_listen ? &p_bg_tck->cif_adv_mask : &p_bg_tck->cif_mask;
*p_cif_mask = (1 <<(client_if - 1));
*p_cif_mask = (1 << (client_if - 1));
return TRUE;
}
}
@ -760,21 +725,21 @@ BOOLEAN bta_gattc_check_bg_conn (tBTA_GATTC_IF client_if, BD_ADDR remote_bda, U
UINT8 i = 0;
BOOLEAN is_bg_conn = FALSE;
for (i = 0; i < BTA_GATTC_KNOWN_SR_MAX && !is_bg_conn; i ++, p_bg_tck ++)
{
for (i = 0; i < BTA_GATTC_KNOWN_SR_MAX && !is_bg_conn; i ++, p_bg_tck ++) {
if (p_bg_tck->in_use &&
(bdcmp(p_bg_tck->remote_bda, remote_bda) == 0 ||
bdcmp(p_bg_tck->remote_bda, dummy_bda) == 0))
{
if (((p_bg_tck->cif_mask &(1 <<(client_if - 1))) != 0) &&
role == HCI_ROLE_MASTER)
bdcmp(p_bg_tck->remote_bda, dummy_bda) == 0)) {
if (((p_bg_tck->cif_mask & (1 << (client_if - 1))) != 0) &&
role == HCI_ROLE_MASTER) {
is_bg_conn = TRUE;
}
if (((p_bg_tck->cif_adv_mask &(1 <<(client_if - 1))) != 0) &&
role == HCI_ROLE_SLAVE)
if (((p_bg_tck->cif_adv_mask & (1 << (client_if - 1))) != 0) &&
role == HCI_ROLE_SLAVE) {
is_bg_conn = TRUE;
}
}
}
return is_bg_conn;
}
/*******************************************************************************
@ -792,8 +757,7 @@ void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status
{
tBTA_GATTC cb_data;
if (p_clreg->p_cback)
{
if (p_clreg->p_cback) {
memset(&cb_data, 0, sizeof(tBTA_GATTC));
cb_data.open.status = status;
@ -815,17 +779,15 @@ void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status
** Returns pointer to the clcb
**
*******************************************************************************/
tBTA_GATTC_CONN * bta_gattc_conn_alloc(BD_ADDR remote_bda)
tBTA_GATTC_CONN *bta_gattc_conn_alloc(BD_ADDR remote_bda)
{
UINT8 i_conn = 0;
tBTA_GATTC_CONN *p_conn = &bta_gattc_cb.conn_track[0];
for (i_conn = 0; i_conn < BTA_GATTC_CONN_MAX; i_conn++, p_conn ++)
{
if (!p_conn->in_use)
{
for (i_conn = 0; i_conn < BTA_GATTC_CONN_MAX; i_conn++, p_conn ++) {
if (!p_conn->in_use) {
#if BTA_GATT_DEBUG == TRUE
APPL_TRACE_DEBUG("bta_gattc_conn_alloc: found conn_track[%d] available",i_conn);
APPL_TRACE_DEBUG("bta_gattc_conn_alloc: found conn_track[%d] available", i_conn);
#endif
p_conn->in_use = TRUE;
bdcpy(p_conn->remote_bda, remote_bda);
@ -844,17 +806,15 @@ tBTA_GATTC_CONN * bta_gattc_conn_alloc(BD_ADDR remote_bda)
** Returns pointer to the clcb
**
*******************************************************************************/
tBTA_GATTC_CONN * bta_gattc_conn_find(BD_ADDR remote_bda)
tBTA_GATTC_CONN *bta_gattc_conn_find(BD_ADDR remote_bda)
{
UINT8 i_conn = 0;
tBTA_GATTC_CONN *p_conn = &bta_gattc_cb.conn_track[0];
for (i_conn = 0; i_conn < BTA_GATTC_CONN_MAX; i_conn++, p_conn ++)
{
if (p_conn->in_use && bdcmp(remote_bda, p_conn->remote_bda) == 0)
{
for (i_conn = 0; i_conn < BTA_GATTC_CONN_MAX; i_conn++, p_conn ++) {
if (p_conn->in_use && bdcmp(remote_bda, p_conn->remote_bda) == 0) {
#if BTA_GATT_DEBUG == TRUE
APPL_TRACE_DEBUG("bta_gattc_conn_find: found conn_track[%d] matched",i_conn);
APPL_TRACE_DEBUG("bta_gattc_conn_find: found conn_track[%d] matched", i_conn);
#endif
return p_conn;
}
@ -872,12 +832,11 @@ tBTA_GATTC_CONN * bta_gattc_conn_find(BD_ADDR remote_bda)
** Returns pointer to the clcb
**
*******************************************************************************/
tBTA_GATTC_CONN * bta_gattc_conn_find_alloc(BD_ADDR remote_bda)
tBTA_GATTC_CONN *bta_gattc_conn_find_alloc(BD_ADDR remote_bda)
{
tBTA_GATTC_CONN *p_conn = bta_gattc_conn_find (remote_bda);
if (p_conn == NULL)
{
if (p_conn == NULL) {
p_conn = bta_gattc_conn_alloc(remote_bda);
}
return p_conn;
@ -896,8 +855,7 @@ BOOLEAN bta_gattc_conn_dealloc(BD_ADDR remote_bda)
{
tBTA_GATTC_CONN *p_conn = bta_gattc_conn_find (remote_bda);
if (p_conn != NULL)
{
if (p_conn != NULL) {
p_conn->in_use = FALSE;
memset(p_conn->remote_bda, 0, BD_ADDR_LEN);
return TRUE;
@ -914,24 +872,23 @@ BOOLEAN bta_gattc_conn_dealloc(BD_ADDR remote_bda)
** Returns pointer to the clcb
**
*******************************************************************************/
tBTA_GATTC_CLCB * bta_gattc_find_int_conn_clcb(tBTA_GATTC_DATA *p_msg)
tBTA_GATTC_CLCB *bta_gattc_find_int_conn_clcb(tBTA_GATTC_DATA *p_msg)
{
tBTA_GATTC_CLCB *p_clcb = NULL;
if (p_msg->int_conn.role == HCI_ROLE_SLAVE)
if (p_msg->int_conn.role == HCI_ROLE_SLAVE) {
bta_gattc_conn_find_alloc(p_msg->int_conn.remote_bda);
}
/* try to locate a logic channel */
if ((p_clcb = bta_gattc_find_clcb_by_cif(p_msg->int_conn.client_if,
p_msg->int_conn.remote_bda,
p_msg->int_conn.transport)) == NULL)
{
p_msg->int_conn.transport)) == NULL) {
/* for a background connection or listening connection */
if (/*p_msg->int_conn.role == HCI_ROLE_SLAVE || */
bta_gattc_check_bg_conn(p_msg->int_conn.client_if,
p_msg->int_conn.remote_bda,
p_msg->int_conn.role))
{
p_msg->int_conn.role)) {
/* allocate a new channel */
p_clcb = bta_gattc_clcb_alloc(p_msg->int_conn.client_if,
p_msg->int_conn.remote_bda,
@ -950,20 +907,18 @@ tBTA_GATTC_CLCB * bta_gattc_find_int_conn_clcb(tBTA_GATTC_DATA *p_msg)
** Returns pointer to the clcb
**
*******************************************************************************/
tBTA_GATTC_CLCB * bta_gattc_find_int_disconn_clcb(tBTA_GATTC_DATA *p_msg)
tBTA_GATTC_CLCB *bta_gattc_find_int_disconn_clcb(tBTA_GATTC_DATA *p_msg)
{
tBTA_GATTC_CLCB *p_clcb = NULL;
bta_gattc_conn_dealloc(p_msg->int_conn.remote_bda);
if ((p_clcb = bta_gattc_find_clcb_by_conn_id(p_msg->int_conn.hdr.layer_specific)) == NULL)
{
if ((p_clcb = bta_gattc_find_clcb_by_conn_id(p_msg->int_conn.hdr.layer_specific)) == NULL) {
/* connection attempt failed, send connection callback event */
p_clcb = bta_gattc_find_clcb_by_cif(p_msg->int_conn.client_if,
p_msg->int_conn.remote_bda,
p_msg->int_conn.transport);
}
if (p_clcb == NULL)
{
if (p_clcb == NULL) {
APPL_TRACE_DEBUG(" disconnection ID: [%d] not used by BTA",
p_msg->int_conn.hdr.layer_specific);
}

347
components/bt/bluedroid/bta/gatt/bta_gatts_act.c Executable file → Normal file
View file

@ -49,8 +49,7 @@ static void bta_gatts_send_request_cback (UINT16 conn_id,
tGATTS_REQ_TYPE req_type, tGATTS_DATA *p_data);
static void bta_gatts_cong_cback (UINT16 conn_id, BOOLEAN congested);
static tGATT_CBACK bta_gatts_cback =
{
static tGATT_CBACK bta_gatts_cback = {
bta_gatts_conn_cback,
NULL,
NULL,
@ -60,8 +59,7 @@ static tGATT_CBACK bta_gatts_cback =
bta_gatts_cong_cback
};
tGATT_APPL_INFO bta_gatts_nv_cback =
{
tGATT_APPL_INFO bta_gatts_nv_cback = {
bta_gatts_nv_save_cback,
bta_gatts_nv_srv_chg_cback
};
@ -112,21 +110,17 @@ static BOOLEAN bta_gatts_nv_srv_chg_cback(tGATTS_SRV_CHG_CMD cmd,
*******************************************************************************/
void bta_gatts_enable(tBTA_GATTS_CB *p_cb)
{
UINT8 index=0;
UINT8 index = 0;
tBTA_GATTS_HNDL_RANGE handle_range;
if (p_cb->enabled)
{
if (p_cb->enabled) {
APPL_TRACE_DEBUG("GATTS already enabled.");
}
else
{
} else {
memset(p_cb, 0, sizeof(tBTA_GATTS_CB));
p_cb->enabled = TRUE;
while ( bta_gatts_co_load_handle_range(index, &handle_range))
{
while ( bta_gatts_co_load_handle_range(index, &handle_range)) {
GATTS_AddHandleRange((tGATTS_HNDL_RANGE *)&handle_range);
memset(&handle_range, 0, sizeof(tGATTS_HNDL_RANGE));
index++;
@ -134,8 +128,7 @@ void bta_gatts_enable(tBTA_GATTS_CB *p_cb)
APPL_TRACE_DEBUG("bta_gatts_enable: num of handle range added=%d", index);
if (!GATTS_NVRegister(&bta_gatts_nv_cback))
{
if (!GATTS_NVRegister(&bta_gatts_nv_cback)) {
APPL_TRACE_ERROR("BTA GATTS NV register failed.");
}
}
@ -154,19 +147,14 @@ void bta_gatts_api_disable(tBTA_GATTS_CB *p_cb)
{
UINT8 i;
if (p_cb->enabled)
{
for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++)
{
if (p_cb->rcb[i].in_use)
{
if (p_cb->enabled) {
for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++) {
if (p_cb->rcb[i].in_use) {
GATT_Deregister(p_cb->rcb[i].gatt_if);
}
}
memset(p_cb, 0, sizeof(tBTA_GATTS_CB));
}
else
{
} else {
APPL_TRACE_ERROR("GATTS not enabled");
}
}
@ -187,17 +175,13 @@ void bta_gatts_register(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
tBTA_GATT_STATUS status = BTA_GATT_OK;
UINT8 i, first_unuse = 0xff;
if (p_cb->enabled == FALSE)
{
if (p_cb->enabled == FALSE) {
bta_gatts_enable(p_cb);
}
for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++)
{
if (p_cb->rcb[i].in_use)
{
if (bta_gatts_uuid_compare(p_cb->rcb[i].app_uuid, p_msg->api_reg.app_uuid))
{
for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++) {
if (p_cb->rcb[i].in_use) {
if (bta_gatts_uuid_compare(p_cb->rcb[i].app_uuid, p_msg->api_reg.app_uuid)) {
APPL_TRACE_ERROR("application already registered.\n");
status = BTA_GATT_DUP_REG;
break;
@ -205,12 +189,9 @@ void bta_gatts_register(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
}
}
if (status == BTA_GATT_OK)
{
for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++)
{
if (first_unuse == 0xff && !p_cb->rcb[i].in_use)
{
if (status == BTA_GATT_OK) {
for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++) {
if (first_unuse == 0xff && !p_cb->rcb[i].in_use) {
first_unuse = i;
break;
}
@ -220,9 +201,8 @@ void bta_gatts_register(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
// btla-specific ++
memcpy(&cb_data.reg_oper.uuid, &p_msg->api_reg.app_uuid, sizeof(tBT_UUID));
// btla-specific --
if (first_unuse != 0xff)
{
APPL_TRACE_ERROR("register application first_unuse rcb_idx = %d", first_unuse);
if (first_unuse != 0xff) {
APPL_TRACE_VERBOSE("register application first_unuse rcb_idx = %d", first_unuse);
p_cb->rcb[first_unuse].in_use = TRUE;
p_cb->rcb[first_unuse].p_cback = p_msg->api_reg.p_cback;
@ -230,38 +210,31 @@ void bta_gatts_register(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
cb_data.reg_oper.server_if =
p_cb->rcb[first_unuse].gatt_if =
GATT_Register(&p_msg->api_reg.app_uuid, &bta_gatts_cback);
if ( !p_cb->rcb[first_unuse].gatt_if)
{
if ( !p_cb->rcb[first_unuse].gatt_if) {
status = BTA_GATT_NO_RESOURCES;
}
else
{
} else {
if ((p_buf =
(tBTA_GATTS_INT_START_IF *) GKI_getbuf(sizeof(tBTA_GATTS_INT_START_IF))) != NULL)
{
(tBTA_GATTS_INT_START_IF *) GKI_getbuf(sizeof(tBTA_GATTS_INT_START_IF))) != NULL) {
p_buf->hdr.event = BTA_GATTS_INT_START_IF_EVT;
p_buf->server_if = p_cb->rcb[first_unuse].gatt_if;
bta_sys_sendmsg(p_buf);
}
else
{
} else {
status = BTA_GATT_NO_RESOURCES;
memset( &p_cb->rcb[first_unuse], 0 , sizeof(tBTA_GATTS_RCB));
}
}
}
else
{
} else {
status = BTA_GATT_NO_RESOURCES;
}
}
cb_data.reg_oper.status = status;
if (p_msg->api_reg.p_cback)
if (p_msg->api_reg.p_cback) {
(*p_msg->api_reg.p_cback)(BTA_GATTS_REG_EVT, &cb_data);
}
LOG_ERROR("status=%x\n",status);
LOG_ERROR("status=%x\n", status);
}
@ -278,12 +251,9 @@ void bta_gatts_start_if(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
{
UNUSED(p_cb);
if (bta_gatts_find_app_rcb_by_app_if(p_msg->int_start_if.server_if))
{
if (bta_gatts_find_app_rcb_by_app_if(p_msg->int_start_if.server_if)) {
GATT_StartIf(p_msg->int_start_if.server_if);
}
else
{
} else {
APPL_TRACE_ERROR("Unable to start app.: Unknown interface =%d",
p_msg->int_start_if.server_if );
}
@ -307,10 +277,8 @@ void bta_gatts_deregister(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
cb_data.reg_oper.server_if = p_msg->api_dereg.server_if;
cb_data.reg_oper.status = status;
for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++)
{
if (p_cb->rcb[i].in_use && p_cb->rcb[i].gatt_if == p_msg->api_dereg.server_if)
{
for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++) {
if (p_cb->rcb[i].in_use && p_cb->rcb[i].gatt_if == p_msg->api_dereg.server_if) {
p_cback = p_cb->rcb[i].p_cback;
status = BTA_GATT_OK;
@ -324,12 +292,9 @@ void bta_gatts_deregister(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
}
}
if (p_cback)
{
if (p_cback) {
(*p_cback)(BTA_GATTS_DEREG_EVT, &cb_data);
}
else
{
} else {
APPL_TRACE_ERROR("application not registered.");
}
}
@ -342,7 +307,7 @@ void bta_gatts_deregister(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
** Returns none.
**
*******************************************************************************/
void bta_gatts_create_srvc(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
void bta_gatts_create_srvc(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
{
UINT8 rcb_idx;
tBTA_GATTS cb_data;
@ -353,12 +318,10 @@ void bta_gatts_create_srvc(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
rcb_idx = bta_gatts_find_app_rcb_idx_by_app_if(p_cb, p_msg->api_create_svc.server_if);
APPL_TRACE_ERROR("create service rcb_idx = %d", rcb_idx);
APPL_TRACE_DEBUG("create service rcb_idx = %d", rcb_idx);
if (rcb_idx != BTA_GATTS_INVALID_APP)
{
if ((srvc_idx = bta_gatts_alloc_srvc_cb(p_cb, rcb_idx)) != BTA_GATTS_INVALID_APP)
{
if (rcb_idx != BTA_GATTS_INVALID_APP) {
if ((srvc_idx = bta_gatts_alloc_srvc_cb(p_cb, rcb_idx)) != BTA_GATTS_INVALID_APP) {
/* create the service now */
service_id = GATTS_CreateService (p_cb->rcb[rcb_idx].gatt_if,
&p_msg->api_create_svc.service_uuid,
@ -366,8 +329,7 @@ void bta_gatts_create_srvc(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
p_msg->api_create_svc.num_handle,
p_msg->api_create_svc.is_pri);
if (service_id != 0)
{
if (service_id != 0) {
memcpy(&p_cb->srvc_cb[srvc_idx].service_uuid,
&p_msg->api_create_svc.service_uuid, sizeof(tBT_UUID));
p_cb->srvc_cb[srvc_idx].service_id = service_id;
@ -380,23 +342,20 @@ void bta_gatts_create_srvc(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
cb_data.create.is_primary = p_msg->api_create_svc.is_pri;
// btla-specific --
cb_data.create.server_if = p_cb->rcb[rcb_idx].gatt_if;
}
else
{
} else {
cb_data.status = BTA_GATT_ERROR;
memset(&p_cb->srvc_cb[srvc_idx], 0, sizeof(tBTA_GATTS_SRVC_CB));
APPL_TRACE_ERROR("service creation failed.");
}
// btla-specific ++
memcpy(&cb_data.create.uuid, &p_msg->api_create_svc.service_uuid, sizeof(tBT_UUID));
cb_data.create.svc_instance= p_msg->api_create_svc.inst;
cb_data.create.svc_instance = p_msg->api_create_svc.inst;
// btla-specific --
}
if (p_cb->rcb[rcb_idx].p_cback)
if (p_cb->rcb[rcb_idx].p_cback) {
(* p_cb->rcb[rcb_idx].p_cback)(BTA_GATTS_CREATE_EVT, &cb_data);
}
else /* application not registered */
{
} else { /* application not registered */
APPL_TRACE_ERROR("Application not registered");
}
}
@ -409,7 +368,7 @@ void bta_gatts_create_srvc(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
** Returns none.
**
*******************************************************************************/
void bta_gatts_add_include_srvc(tBTA_GATTS_SRVC_CB *p_srvc_cb,tBTA_GATTS_DATA * p_msg)
void bta_gatts_add_include_srvc(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg)
{
tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx];
UINT16 attr_id = 0;
@ -422,17 +381,15 @@ void bta_gatts_add_include_srvc(tBTA_GATTS_SRVC_CB *p_srvc_cb,tBTA_GATTS_DATA *
cb_data.add_result.service_id = p_msg->api_add_incl_srvc.hdr.layer_specific;
cb_data.add_result.attr_id = attr_id;
if (attr_id)
{
if (attr_id) {
cb_data.add_result.status = BTA_GATT_OK;
}
else
{
} else {
cb_data.add_result.status = BTA_GATT_ERROR;
}
if (p_rcb->p_cback)
if (p_rcb->p_cback) {
(*p_rcb->p_cback)(BTA_GATTS_ADD_INCL_SRVC_EVT, &cb_data);
}
}
/*******************************************************************************
**
@ -443,7 +400,7 @@ void bta_gatts_add_include_srvc(tBTA_GATTS_SRVC_CB *p_srvc_cb,tBTA_GATTS_DATA *
** Returns none.
**
*******************************************************************************/
void bta_gatts_add_char(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg)
void bta_gatts_add_char(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg)
{
tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx];
UINT16 attr_id = 0;
@ -460,17 +417,15 @@ void bta_gatts_add_char(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg)
memcpy(&cb_data.add_result.char_uuid, &p_msg->api_add_char.char_uuid, sizeof(tBT_UUID));
// btla-specific --
if (attr_id)
{
if (attr_id) {
cb_data.add_result.status = BTA_GATT_OK;
}
else
{
} else {
cb_data.add_result.status = BTA_GATT_ERROR;
}
if (p_rcb->p_cback)
if (p_rcb->p_cback) {
(*p_rcb->p_cback)(BTA_GATTS_ADD_CHAR_EVT, &cb_data);
}
}
/*******************************************************************************
**
@ -481,7 +436,7 @@ void bta_gatts_add_char(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg)
** Returns none.
**
*******************************************************************************/
void bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg)
void bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg)
{
tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx];
UINT16 attr_id = 0;
@ -498,17 +453,15 @@ void bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p
memcpy(&cb_data.add_result.char_uuid, &p_msg->api_add_char_descr.descr_uuid, sizeof(tBT_UUID));
// btla-specific --
if (attr_id)
{
if (attr_id) {
cb_data.add_result.status = BTA_GATT_OK;
}
else
{
} else {
cb_data.add_result.status = BTA_GATT_ERROR;
}
if (p_rcb->p_cback)
if (p_rcb->p_cback) {
(*p_rcb->p_cback)(BTA_GATTS_ADD_CHAR_DESCR_EVT, &cb_data);
}
}
/*******************************************************************************
@ -520,7 +473,7 @@ void bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p
** Returns none.
**
*******************************************************************************/
void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg)
void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg)
{
tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx];
tBTA_GATTS cb_data;
@ -530,18 +483,16 @@ void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p
if (GATTS_DeleteService(p_rcb->gatt_if,
&p_srvc_cb->service_uuid,
p_srvc_cb->inst_num))
{
p_srvc_cb->inst_num)) {
cb_data.srvc_oper.status = BTA_GATT_OK;
memset(p_srvc_cb, 0, sizeof(tBTA_GATTS_SRVC_CB));
}
else
{
} else {
cb_data.srvc_oper.status = BTA_GATT_ERROR;
}
if (p_rcb->p_cback)
if (p_rcb->p_cback) {
(*p_rcb->p_cback)(BTA_GATTS_DELELTE_EVT, &cb_data);
}
}
/*******************************************************************************
@ -553,7 +504,7 @@ void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p
** Returns none.
**
*******************************************************************************/
void bta_gatts_start_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg)
void bta_gatts_start_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg)
{
tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx];
tBTA_GATTS cb_data;
@ -563,18 +514,16 @@ void bta_gatts_start_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_
if (GATTS_StartService(p_rcb->gatt_if,
p_srvc_cb->service_id,
p_msg->api_start.transport) == GATT_SUCCESS)
{
p_msg->api_start.transport) == GATT_SUCCESS) {
APPL_TRACE_DEBUG("bta_gatts_start_service service_id= %d", p_srvc_cb->service_id);
cb_data.srvc_oper.status = BTA_GATT_OK;
}
else
{
} else {
cb_data.srvc_oper.status = BTA_GATT_ERROR;
}
if (p_rcb->p_cback)
if (p_rcb->p_cback) {
(*p_rcb->p_cback)(BTA_GATTS_START_EVT, &cb_data);
}
}
/*******************************************************************************
@ -586,7 +535,7 @@ void bta_gatts_start_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_
** Returns none.
**
*******************************************************************************/
void bta_gatts_stop_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg)
void bta_gatts_stop_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg)
{
tBTA_GATTS_RCB *p_rcb = &bta_gatts_cb.rcb[p_srvc_cb->rcb_idx];
tBTA_GATTS cb_data;
@ -598,8 +547,9 @@ void bta_gatts_stop_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_m
cb_data.srvc_oper.status = BTA_GATT_OK;
APPL_TRACE_ERROR("bta_gatts_stop_service service_id= %d", p_srvc_cb->service_id);
if (p_rcb->p_cback)
if (p_rcb->p_cback) {
(*p_rcb->p_cback)(BTA_GATTS_STOP_EVT, &cb_data);
}
}
/*******************************************************************************
@ -611,15 +561,14 @@ void bta_gatts_stop_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_m
** Returns none.
**
*******************************************************************************/
void bta_gatts_send_rsp (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
void bta_gatts_send_rsp (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
{
UNUSED(p_cb);
if (GATTS_SendRsp (p_msg->api_rsp.hdr.layer_specific,
p_msg->api_rsp.trans_id,
p_msg->api_rsp.status,
(tGATTS_RSP *)p_msg->api_rsp.p_rsp) != GATT_SUCCESS)
{
(tGATTS_RSP *)p_msg->api_rsp.p_rsp) != GATT_SUCCESS) {
APPL_TRACE_ERROR("Sending response failed\n");
}
@ -633,7 +582,7 @@ void bta_gatts_send_rsp (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
** Returns none.
**
*******************************************************************************/
void bta_gatts_indicate_handle (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
void bta_gatts_indicate_handle (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
{
tBTA_GATTS_SRVC_CB *p_srvc_cb;
tBTA_GATTS_RCB *p_rcb = NULL;
@ -645,11 +594,9 @@ void bta_gatts_indicate_handle (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
p_srvc_cb = bta_gatts_find_srvc_cb_by_attr_id (p_cb, p_msg->api_indicate.attr_id);
if (p_srvc_cb )
{
if (p_srvc_cb ) {
if (GATT_GetConnectionInfor(p_msg->api_indicate.hdr.layer_specific,
&gatt_if, remote_bda, &transport))
{
&gatt_if, remote_bda, &transport)) {
p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if);
if (p_msg->api_indicate.need_confirm)
@ -665,29 +612,23 @@ void bta_gatts_indicate_handle (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
p_msg->api_indicate.value);
/* if over BR_EDR, inform PM for mode change */
if (transport == BTA_TRANSPORT_BR_EDR)
{
if (transport == BTA_TRANSPORT_BR_EDR) {
bta_sys_busy(BTA_ID_GATTS, BTA_ALL_APP_ID, remote_bda);
bta_sys_idle(BTA_ID_GATTS, BTA_ALL_APP_ID, remote_bda);
}
}
else
{
} else {
APPL_TRACE_ERROR("Unknown connection ID: %d fail sending notification",
p_msg->api_indicate.hdr.layer_specific);
}
if ((status != GATT_SUCCESS || !p_msg->api_indicate.need_confirm) &&
p_rcb && p_cb->rcb[p_srvc_cb->rcb_idx].p_cback)
{
p_rcb && p_cb->rcb[p_srvc_cb->rcb_idx].p_cback) {
cb_data.req_data.status = status;
cb_data.req_data.conn_id = p_msg->api_indicate.hdr.layer_specific;
(*p_rcb->p_cback)(BTA_GATTS_CONF_EVT, &cb_data);
}
}
else
{
} else {
APPL_TRACE_ERROR("Not an registered servce attribute ID: 0x%04x",
p_msg->api_indicate.attr_id);
}
@ -703,35 +644,31 @@ void bta_gatts_indicate_handle (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
** Returns none.
**
*******************************************************************************/
void bta_gatts_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
void bta_gatts_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
{
tBTA_GATTS_RCB *p_rcb=NULL;
tBTA_GATT_STATUS status= BTA_GATT_ERROR;
tBTA_GATTS_RCB *p_rcb = NULL;
tBTA_GATT_STATUS status = BTA_GATT_ERROR;
UINT16 conn_id;
UNUSED(p_cb);
if ((p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_open.server_if)) != NULL)
{
if ((p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_open.server_if)) != NULL) {
/* should always get the connection ID */
if (GATT_Connect(p_rcb->gatt_if, p_msg->api_open.remote_bda,
p_msg->api_open.is_direct, p_msg->api_open.transport))
{
p_msg->api_open.is_direct, p_msg->api_open.transport)) {
status = BTA_GATT_OK;
if (GATT_GetConnIdIfConnected(p_rcb->gatt_if, p_msg->api_open.remote_bda,
&conn_id, p_msg->api_open.transport))
{
&conn_id, p_msg->api_open.transport)) {
status = BTA_GATT_ALREADY_OPEN;
}
}
}
else
{
} else {
APPL_TRACE_ERROR("Inavlide server_if=%d", p_msg->api_open.server_if);
}
if (p_rcb && p_rcb->p_cback)
if (p_rcb && p_rcb->p_cback) {
(*p_rcb->p_cback)(BTA_GATTS_OPEN_EVT, (tBTA_GATTS *)&status);
}
}
/*******************************************************************************
@ -743,31 +680,26 @@ void bta_gatts_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
** Returns none.
**
*******************************************************************************/
void bta_gatts_cancel_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
void bta_gatts_cancel_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
{
tBTA_GATTS_RCB *p_rcb;
tBTA_GATT_STATUS status= BTA_GATT_ERROR;
tBTA_GATT_STATUS status = BTA_GATT_ERROR;
UNUSED(p_cb);
if ((p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_cancel_open.server_if)) != NULL)
{
if ((p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_cancel_open.server_if)) != NULL) {
if (!GATT_CancelConnect(p_rcb->gatt_if, p_msg->api_cancel_open.remote_bda,
p_msg->api_cancel_open.is_direct))
{
p_msg->api_cancel_open.is_direct)) {
APPL_TRACE_ERROR("bta_gatts_cancel_open failed for open request");
} else {
status = BTA_GATT_OK;
}
else
{
status= BTA_GATT_OK;
}
}
else
{
} else {
APPL_TRACE_ERROR("Inavlide server_if=%d", p_msg->api_cancel_open.server_if);
}
if (p_rcb && p_rcb->p_cback)
if (p_rcb && p_rcb->p_cback) {
(*p_rcb->p_cback)(BTA_GATTS_CANCEL_OPEN_EVT, (tBTA_GATTS *)&status);
}
}
/*******************************************************************************
**
@ -778,39 +710,33 @@ void bta_gatts_cancel_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
** Returns none.
**
*******************************************************************************/
void bta_gatts_close (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
void bta_gatts_close (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
{
tBTA_GATTS_RCB *p_rcb;
tBTA_GATT_STATUS status= BTA_GATT_ERROR;
tBTA_GATT_STATUS status = BTA_GATT_ERROR;
tGATT_IF gatt_if;
BD_ADDR remote_bda;
tBTA_GATT_TRANSPORT transport;
UNUSED(p_cb);
if (GATT_GetConnectionInfor(p_msg->hdr.layer_specific, &gatt_if, remote_bda, &transport))
{
if (GATT_Disconnect(p_msg->hdr.layer_specific) != GATT_SUCCESS)
{
if (GATT_GetConnectionInfor(p_msg->hdr.layer_specific, &gatt_if, remote_bda, &transport)) {
if (GATT_Disconnect(p_msg->hdr.layer_specific) != GATT_SUCCESS) {
APPL_TRACE_ERROR("bta_gatts_close fail conn_id=%d", p_msg->hdr.layer_specific);
}
else
{
status= BTA_GATT_OK;
} else {
status = BTA_GATT_OK;
}
p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if);
if (p_rcb && p_rcb->p_cback)
{
if (transport == BTA_TRANSPORT_BR_EDR)
bta_sys_conn_close( BTA_ID_GATTS ,BTA_ALL_APP_ID, remote_bda);
if (p_rcb && p_rcb->p_cback) {
if (transport == BTA_TRANSPORT_BR_EDR) {
bta_sys_conn_close( BTA_ID_GATTS , BTA_ALL_APP_ID, remote_bda);
}
(*p_rcb->p_cback)(BTA_GATTS_CLOSE_EVT, (tBTA_GATTS *)&status);
}
}
else
{
} else {
APPL_TRACE_ERROR("Unknown connection ID: %d", p_msg->hdr.layer_specific);
}
@ -824,7 +750,7 @@ void bta_gatts_close (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
** Returns none.
**
*******************************************************************************/
void bta_gatts_listen(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
void bta_gatts_listen(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg)
{
tBTA_GATTS_RCB *p_rcb = bta_gatts_find_app_rcb_by_app_if(p_msg->api_listen.server_if);
tBTA_GATTS cb_data;
@ -833,22 +759,21 @@ void bta_gatts_listen(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg)
cb_data.reg_oper.status = BTA_GATT_OK;
cb_data.reg_oper.server_if = p_msg->api_listen.server_if;
if (p_rcb == NULL)
{
if (p_rcb == NULL) {
APPL_TRACE_ERROR("Unknown GATTS application");
return;
}
if (!GATT_Listen(p_msg->api_listen.server_if,
p_msg->api_listen.start,
p_msg->api_listen.remote_bda))
{
p_msg->api_listen.remote_bda)) {
cb_data.status = BTA_GATT_ERROR;
APPL_TRACE_ERROR("bta_gatts_listen Listen failed");
}
if (p_rcb->p_cback)
if (p_rcb->p_cback) {
(*p_rcb->p_cback)(BTA_GATTS_LISTEN_EVT, &cb_data);
}
}
/*******************************************************************************
@ -871,18 +796,15 @@ static void bta_gatts_send_request_cback (UINT16 conn_id,
memset(&cb_data, 0 , sizeof(tBTA_GATTS));
if (GATT_GetConnectionInfor(conn_id, &gatt_if, cb_data.req_data.remote_bda, &transport))
{
if (GATT_GetConnectionInfor(conn_id, &gatt_if, cb_data.req_data.remote_bda, &transport)) {
p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if);
APPL_TRACE_DEBUG ("bta_gatts_send_request_cback conn_id=%d trans_id=%d req_type=%d",
conn_id, trans_id, req_type);
if (p_rcb && p_rcb->p_cback)
{
if (p_rcb && p_rcb->p_cback) {
/* if over BR_EDR, inform PM for mode change */
if (transport == BTA_TRANSPORT_BR_EDR)
{
if (transport == BTA_TRANSPORT_BR_EDR) {
bta_sys_busy(BTA_ID_GATTS, BTA_ALL_APP_ID, cb_data.req_data.remote_bda);
bta_sys_idle(BTA_ID_GATTS, BTA_ALL_APP_ID, cb_data.req_data.remote_bda);
}
@ -892,14 +814,10 @@ static void bta_gatts_send_request_cback (UINT16 conn_id,
cb_data.req_data.p_data = (tBTA_GATTS_REQ_DATA *)p_data;
(*p_rcb->p_cback)(req_type, &cb_data);
}
else
{
} else {
APPL_TRACE_ERROR("connection request on gatt_if[%d] is not interested", gatt_if);
}
}
else
{
} else {
APPL_TRACE_ERROR("request received on unknown connectino ID: %d", conn_id);
}
}
@ -918,7 +836,7 @@ static void bta_gatts_conn_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id,
tGATT_TRANSPORT transport)
{
tBTA_GATTS cb_data;
UINT8 evt = connected ? BTA_GATTS_CONNECT_EVT: BTA_GATTS_DISCONNECT_EVT;
UINT8 evt = connected ? BTA_GATTS_CONNECT_EVT : BTA_GATTS_DISCONNECT_EVT;
tBTA_GATTS_RCB *p_reg;
APPL_TRACE_DEBUG ("bta_gatts_conn_cback gatt_if=%d conn_id=%d connected=%d reason = 0x%04d",
@ -936,15 +854,14 @@ static void bta_gatts_conn_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id,
*/
p_reg = bta_gatts_find_app_rcb_by_app_if(gatt_if);
if (p_reg && p_reg->p_cback)
{
if (p_reg && p_reg->p_cback) {
/* there is no RM for GATT */
if (transport == BTA_TRANSPORT_BR_EDR)
{
if (connected)
if (transport == BTA_TRANSPORT_BR_EDR) {
if (connected) {
bta_sys_conn_open(BTA_ID_GATTS, BTA_ALL_APP_ID, bda);
else
bta_sys_conn_close( BTA_ID_GATTS ,BTA_ALL_APP_ID, bda);
} else {
bta_sys_conn_close( BTA_ID_GATTS , BTA_ALL_APP_ID, bda);
}
}
cb_data.conn.conn_id = conn_id;
@ -953,10 +870,8 @@ static void bta_gatts_conn_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id,
cb_data.conn.transport = transport;
memcpy(cb_data.conn.remote_bda, bda, BD_ADDR_LEN);
(*p_reg->p_cback)(evt, &cb_data);
}
else
{
APPL_TRACE_ERROR("bta_gatts_conn_cback server_if=%d not found",gatt_if);
} else {
APPL_TRACE_ERROR("bta_gatts_conn_cback server_if=%d not found", gatt_if);
}
}
@ -976,12 +891,10 @@ static void bta_gatts_cong_cback (UINT16 conn_id, BOOLEAN congested)
tBTA_GATT_TRANSPORT transport;
tBTA_GATTS cb_data;
if (GATT_GetConnectionInfor(conn_id, &gatt_if, cb_data.req_data.remote_bda, &transport))
{
if (GATT_GetConnectionInfor(conn_id, &gatt_if, cb_data.req_data.remote_bda, &transport)) {
p_rcb = bta_gatts_find_app_rcb_by_app_if(gatt_if);
if (p_rcb && p_rcb->p_cback)
{
if (p_rcb && p_rcb->p_cback) {
cb_data.congest.conn_id = conn_id;
cb_data.congest.congested = congested;

83
components/bt/bluedroid/bta/gatt/bta_gatts_api.c Executable file → Normal file
View file

@ -36,8 +36,7 @@
** Constants
*****************************************************************************/
static const tBTA_SYS_REG bta_gatts_reg =
{
static const tBTA_SYS_REG bta_gatts_reg = {
bta_gatts_hdl_event,
BTA_GATTS_Disable
};
@ -57,14 +56,12 @@ void BTA_GATTS_Disable(void)
{
BT_HDR *p_buf;
if (bta_sys_is_register(BTA_ID_GATTS) == FALSE)
{
if (bta_sys_is_register(BTA_ID_GATTS) == FALSE) {
APPL_TRACE_WARNING("GATTS Module not enabled/already disabled");
return;
}
if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
{
if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
p_buf->event = BTA_GATTS_API_DISABLE_EVT;
bta_sys_sendmsg(p_buf);
}
@ -90,17 +87,16 @@ void BTA_GATTS_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTS_CBACK *p_cback)
tBTA_GATTS_API_REG *p_buf;
/* register with BTA system manager */
if (bta_sys_is_register(BTA_ID_GATTS) == FALSE)
{
if (bta_sys_is_register(BTA_ID_GATTS) == FALSE) {
bta_sys_register(BTA_ID_GATTS, &bta_gatts_reg);
}
if ((p_buf = (tBTA_GATTS_API_REG *) GKI_getbuf(sizeof(tBTA_GATTS_API_REG))) != NULL)
{
if ((p_buf = (tBTA_GATTS_API_REG *) GKI_getbuf(sizeof(tBTA_GATTS_API_REG))) != NULL) {
p_buf->hdr.event = BTA_GATTS_API_REG_EVT;
if (p_app_uuid != NULL)
if (p_app_uuid != NULL) {
memcpy(&p_buf->app_uuid, p_app_uuid, sizeof(tBT_UUID));
}
p_buf->p_cback = p_cback;
bta_sys_sendmsg(p_buf);
@ -125,8 +121,7 @@ void BTA_GATTS_AppDeregister(tBTA_GATTS_IF server_if)
{
tBTA_GATTS_API_DEREG *p_buf;
if ((p_buf = (tBTA_GATTS_API_DEREG *) GKI_getbuf(sizeof(tBTA_GATTS_API_DEREG))) != NULL)
{
if ((p_buf = (tBTA_GATTS_API_DEREG *) GKI_getbuf(sizeof(tBTA_GATTS_API_DEREG))) != NULL) {
p_buf->hdr.event = BTA_GATTS_API_DEREG_EVT;
p_buf->server_if = server_if;
@ -159,8 +154,7 @@ void BTA_GATTS_CreateService(tBTA_GATTS_IF server_if, tBT_UUID *p_service_uuid,
{
tBTA_GATTS_API_CREATE_SRVC *p_buf;
if ((p_buf = (tBTA_GATTS_API_CREATE_SRVC *) GKI_getbuf(sizeof(tBTA_GATTS_API_CREATE_SRVC))) != NULL)
{
if ((p_buf = (tBTA_GATTS_API_CREATE_SRVC *) GKI_getbuf(sizeof(tBTA_GATTS_API_CREATE_SRVC))) != NULL) {
p_buf->hdr.event = BTA_GATTS_API_CREATE_SRVC_EVT;
p_buf->server_if = server_if;
@ -194,8 +188,7 @@ void BTA_GATTS_AddIncludeService(UINT16 service_id, UINT16 included_service_id)
if ((p_buf =
(tBTA_GATTS_API_ADD_INCL_SRVC *) GKI_getbuf(sizeof(tBTA_GATTS_API_ADD_INCL_SRVC)))
!= NULL)
{
!= NULL) {
p_buf->hdr.event = BTA_GATTS_API_ADD_INCL_SRVC_EVT;
p_buf->hdr.layer_specific = service_id;
@ -226,8 +219,7 @@ void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid,
{
tBTA_GATTS_API_ADD_CHAR *p_buf;
if ((p_buf = (tBTA_GATTS_API_ADD_CHAR *) GKI_getbuf(sizeof(tBTA_GATTS_API_ADD_CHAR))) != NULL)
{
if ((p_buf = (tBTA_GATTS_API_ADD_CHAR *) GKI_getbuf(sizeof(tBTA_GATTS_API_ADD_CHAR))) != NULL) {
memset(p_buf, 0, sizeof(tBTA_GATTS_API_ADD_CHAR));
p_buf->hdr.event = BTA_GATTS_API_ADD_CHAR_EVT;
@ -235,8 +227,7 @@ void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid,
p_buf->perm = perm;
p_buf->property = property;
if (p_char_uuid)
{
if (p_char_uuid) {
memcpy(&p_buf->char_uuid, p_char_uuid, sizeof(tBT_UUID));
}
bta_sys_sendmsg(p_buf);
@ -262,22 +253,20 @@ void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_uuid,
*******************************************************************************/
void BTA_GATTS_AddCharDescriptor (UINT16 service_id,
tBTA_GATT_PERM perm,
tBT_UUID * p_descr_uuid)
tBT_UUID *p_descr_uuid)
{
tBTA_GATTS_API_ADD_DESCR *p_buf;
UINT16 len = sizeof(tBTA_GATTS_API_ADD_DESCR);
if ((p_buf = (tBTA_GATTS_API_ADD_DESCR *) GKI_getbuf(len)) != NULL)
{
if ((p_buf = (tBTA_GATTS_API_ADD_DESCR *) GKI_getbuf(len)) != NULL) {
memset(p_buf, 0, len);
p_buf->hdr.event = BTA_GATTS_API_ADD_DESCR_EVT;
p_buf->hdr.layer_specific = service_id;
p_buf->perm = perm;
if (p_descr_uuid)
{
if (p_descr_uuid) {
memcpy(&p_buf->descr_uuid, p_descr_uuid, sizeof(tBT_UUID));
}
bta_sys_sendmsg(p_buf);
@ -302,8 +291,7 @@ void BTA_GATTS_DeleteService(UINT16 service_id)
{
BT_HDR *p_buf;
if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
{
if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
p_buf->event = BTA_GATTS_API_DEL_SRVC_EVT;
p_buf->layer_specific = service_id;
@ -330,8 +318,7 @@ void BTA_GATTS_StartService(UINT16 service_id, tBTA_GATT_TRANSPORT sup_transpor
{
tBTA_GATTS_API_START *p_buf;
if ((p_buf = (tBTA_GATTS_API_START *) GKI_getbuf(sizeof(tBTA_GATTS_API_START))) != NULL)
{
if ((p_buf = (tBTA_GATTS_API_START *) GKI_getbuf(sizeof(tBTA_GATTS_API_START))) != NULL) {
p_buf->hdr.event = BTA_GATTS_API_START_SRVC_EVT;
p_buf->hdr.layer_specific = service_id;
@ -357,8 +344,7 @@ void BTA_GATTS_StopService(UINT16 service_id)
{
BT_HDR *p_buf;
if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
{
if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
p_buf->event = BTA_GATTS_API_STOP_SRVC_EVT;
p_buf->layer_specific = service_id;
@ -389,8 +375,7 @@ void BTA_GATTS_HandleValueIndication (UINT16 conn_id, UINT16 attr_id, UINT16 dat
tBTA_GATTS_API_INDICATION *p_buf;
UINT16 len = sizeof(tBTA_GATTS_API_INDICATION);
if ((p_buf = (tBTA_GATTS_API_INDICATION *) GKI_getbuf(len)) != NULL)
{
if ((p_buf = (tBTA_GATTS_API_INDICATION *) GKI_getbuf(len)) != NULL) {
memset(p_buf, 0, len);
p_buf->hdr.event = BTA_GATTS_API_INDICATION_EVT;
@ -398,8 +383,7 @@ void BTA_GATTS_HandleValueIndication (UINT16 conn_id, UINT16 attr_id, UINT16 dat
p_buf->attr_id = attr_id;
p_buf->need_confirm = need_confirm;
if (data_len > 0 && p_data != NULL)
{
if (data_len > 0 && p_data != NULL) {
p_buf->len = data_len;
memcpy(p_buf->value, p_data, data_len);
@ -429,8 +413,7 @@ void BTA_GATTS_SendRsp (UINT16 conn_id, UINT32 trans_id,
tBTA_GATTS_API_RSP *p_buf;
UINT16 len = sizeof(tBTA_GATTS_API_RSP) + sizeof(tBTA_GATTS_RSP);
if ((p_buf = (tBTA_GATTS_API_RSP *) GKI_getbuf(len)) != NULL)
{
if ((p_buf = (tBTA_GATTS_API_RSP *) GKI_getbuf(len)) != NULL) {
memset(p_buf, 0, len);
p_buf->hdr.event = BTA_GATTS_API_RSP_EVT;
@ -438,8 +421,7 @@ void BTA_GATTS_SendRsp (UINT16 conn_id, UINT32 trans_id,
p_buf->trans_id = trans_id;
p_buf->status = status;
if (p_msg != NULL)
{
if (p_msg != NULL) {
p_buf->p_rsp = (tBTA_GATTS_RSP *)(p_buf + 1);
memcpy(p_buf->p_rsp, p_msg, sizeof(tBTA_GATTS_RSP));
}
@ -472,8 +454,7 @@ void BTA_GATTS_Open(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN is_dire
{
tBTA_GATTS_API_OPEN *p_buf;
if ((p_buf = (tBTA_GATTS_API_OPEN *) GKI_getbuf(sizeof(tBTA_GATTS_API_OPEN))) != NULL)
{
if ((p_buf = (tBTA_GATTS_API_OPEN *) GKI_getbuf(sizeof(tBTA_GATTS_API_OPEN))) != NULL) {
p_buf->hdr.event = BTA_GATTS_API_OPEN_EVT;
p_buf->server_if = server_if;
p_buf->is_direct = is_direct;
@ -504,8 +485,7 @@ void BTA_GATTS_CancelOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN i
{
tBTA_GATTS_API_CANCEL_OPEN *p_buf;
if ((p_buf = (tBTA_GATTS_API_CANCEL_OPEN *) GKI_getbuf(sizeof(tBTA_GATTS_API_CANCEL_OPEN))) != NULL)
{
if ((p_buf = (tBTA_GATTS_API_CANCEL_OPEN *) GKI_getbuf(sizeof(tBTA_GATTS_API_CANCEL_OPEN))) != NULL) {
p_buf->hdr.event = BTA_GATTS_API_CANCEL_OPEN_EVT;
p_buf->server_if = server_if;
p_buf->is_direct = is_direct;
@ -530,8 +510,7 @@ void BTA_GATTS_Close(UINT16 conn_id)
{
BT_HDR *p_buf;
if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
{
if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) {
p_buf->event = BTA_GATTS_API_CLOSE_EVT;
p_buf->layer_specific = conn_id;
bta_sys_sendmsg(p_buf);
@ -558,20 +537,18 @@ void BTA_GATTS_Listen(tBTA_GATTS_IF server_if, BOOLEAN start, BD_ADDR_PTR target
{
tBTA_GATTS_API_LISTEN *p_buf;
if ((p_buf = (tBTA_GATTS_API_LISTEN *) GKI_getbuf((UINT16)(sizeof(tBTA_GATTS_API_LISTEN) + BD_ADDR_LEN))) != NULL)
{
if ((p_buf = (tBTA_GATTS_API_LISTEN *) GKI_getbuf((UINT16)(sizeof(tBTA_GATTS_API_LISTEN) + BD_ADDR_LEN))) != NULL) {
p_buf->hdr.event = BTA_GATTS_API_LISTEN_EVT;
p_buf->server_if = server_if;
p_buf->start = start;
if (target_bda)
{
p_buf->remote_bda = (UINT8*)(p_buf + 1);
if (target_bda) {
p_buf->remote_bda = (UINT8 *)(p_buf + 1);
memcpy(p_buf->remote_bda, target_bda, BD_ADDR_LEN);
}
else
} else {
p_buf->remote_bda = NULL;
}
bta_sys_sendmsg(p_buf);
}

26
components/bt/bluedroid/bta/gatt/bta_gatts_main.c Executable file → Normal file
View file

@ -35,8 +35,7 @@
typedef void (*tBTA_GATTS_SRVC_ACT)(tBTA_GATTS_SRVC_CB *p_rcb, tBTA_GATTS_DATA *p_data);
/* service building action function list */
const tBTA_GATTS_SRVC_ACT bta_gatts_srvc_build_act[] =
{
const tBTA_GATTS_SRVC_ACT bta_gatts_srvc_build_act[] = {
bta_gatts_add_include_srvc,
bta_gatts_add_char,
bta_gatts_add_char_descr,
@ -65,14 +64,12 @@ BOOLEAN bta_gatts_hdl_event(BT_HDR *p_msg)
tBTA_GATTS_CB *p_cb = &bta_gatts_cb;
tBTA_GATTS_SRVC_CB *p_srvc_cb = NULL;
switch (p_msg->event)
{
switch (p_msg->event) {
case BTA_GATTS_API_DISABLE_EVT:
bta_gatts_api_disable(p_cb);
break;
case BTA_GATTS_API_REG_EVT:
LOG_ERROR("bta_gatts_register\n");
bta_gatts_register(p_cb, (tBTA_GATTS_DATA *) p_msg);
break;
@ -89,27 +86,27 @@ BOOLEAN bta_gatts_hdl_event(BT_HDR *p_msg)
break;
case BTA_GATTS_API_INDICATION_EVT:
bta_gatts_indicate_handle(p_cb,(tBTA_GATTS_DATA *) p_msg);
bta_gatts_indicate_handle(p_cb, (tBTA_GATTS_DATA *) p_msg);
break;
case BTA_GATTS_API_OPEN_EVT:
bta_gatts_open(p_cb,(tBTA_GATTS_DATA *) p_msg);
bta_gatts_open(p_cb, (tBTA_GATTS_DATA *) p_msg);
break;
case BTA_GATTS_API_CANCEL_OPEN_EVT:
bta_gatts_cancel_open(p_cb,(tBTA_GATTS_DATA *) p_msg);
bta_gatts_cancel_open(p_cb, (tBTA_GATTS_DATA *) p_msg);
break;
case BTA_GATTS_API_CLOSE_EVT:
bta_gatts_close(p_cb,(tBTA_GATTS_DATA *) p_msg);
bta_gatts_close(p_cb, (tBTA_GATTS_DATA *) p_msg);
break;
case BTA_GATTS_API_RSP_EVT:
bta_gatts_send_rsp(p_cb,(tBTA_GATTS_DATA *) p_msg);
bta_gatts_send_rsp(p_cb, (tBTA_GATTS_DATA *) p_msg);
break;
case BTA_GATTS_API_LISTEN_EVT:
bta_gatts_listen(p_cb,(tBTA_GATTS_DATA *) p_msg);
bta_gatts_listen(p_cb, (tBTA_GATTS_DATA *) p_msg);
break;
@ -123,12 +120,9 @@ BOOLEAN bta_gatts_hdl_event(BT_HDR *p_msg)
p_srvc_cb = bta_gatts_find_srvc_cb_by_srvc_id(p_cb,
((tBTA_GATTS_DATA *)p_msg)->api_add_incl_srvc.hdr.layer_specific);
if (p_srvc_cb != NULL)
{
if (p_srvc_cb != NULL) {
bta_gatts_srvc_build_act[p_msg->event - BTA_GATTS_API_ADD_INCL_SRVC_EVT](p_srvc_cb, (tBTA_GATTS_DATA *) p_msg);
}
else
{
} else {
APPL_TRACE_ERROR("service not created");
}
break;

59
components/bt/bluedroid/bta/gatt/bta_gatts_utils.c Executable file → Normal file
View file

@ -33,7 +33,8 @@
#include "bta_gatts_int.h"
static const UINT8 base_uuid[LEN_UUID_128] = {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
/*******************************************************************************
**
@ -65,10 +66,8 @@ UINT8 bta_gatts_alloc_srvc_cb(tBTA_GATTS_CB *p_cb, UINT8 rcb_idx)
{
UINT8 i;
for (i = 0; i < BTA_GATTS_MAX_SRVC_NUM; i ++)
{
if (!p_cb->srvc_cb[i].in_use)
{
for (i = 0; i < BTA_GATTS_MAX_SRVC_NUM; i ++) {
if (!p_cb->srvc_cb[i].in_use) {
p_cb->srvc_cb[i].in_use = TRUE;
p_cb->srvc_cb[i].rcb_idx = rcb_idx;
return i;
@ -91,11 +90,11 @@ tBTA_GATTS_RCB *bta_gatts_find_app_rcb_by_app_if(tBTA_GATTS_IF server_if)
UINT8 i;
tBTA_GATTS_RCB *p_reg;
for (i = 0, p_reg = bta_gatts_cb.rcb; i < BTA_GATTS_MAX_APP_NUM; i ++, p_reg++)
{
if (p_reg->in_use && p_reg->gatt_if == server_if)
for (i = 0, p_reg = bta_gatts_cb.rcb; i < BTA_GATTS_MAX_APP_NUM; i ++, p_reg++) {
if (p_reg->in_use && p_reg->gatt_if == server_if) {
return p_reg;
}
}
return NULL;
}
@ -113,11 +112,11 @@ UINT8 bta_gatts_find_app_rcb_idx_by_app_if(tBTA_GATTS_CB *p_cb, tBTA_GATTS_IF se
{
UINT8 i;
for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++)
{
if (p_cb->rcb[i].in_use && p_cb->rcb[i].gatt_if == server_if)
for (i = 0; i < BTA_GATTS_MAX_APP_NUM; i ++) {
if (p_cb->rcb[i].in_use && p_cb->rcb[i].gatt_if == server_if) {
return i;
}
}
return BTA_GATTS_INVALID_APP;
}
/*******************************************************************************
@ -129,15 +128,13 @@ UINT8 bta_gatts_find_app_rcb_idx_by_app_if(tBTA_GATTS_CB *p_cb, tBTA_GATTS_IF se
** Returns pointer to the rcb.
**
*******************************************************************************/
tBTA_GATTS_SRVC_CB * bta_gatts_find_srvc_cb_by_srvc_id(tBTA_GATTS_CB *p_cb, UINT16 service_id)
tBTA_GATTS_SRVC_CB *bta_gatts_find_srvc_cb_by_srvc_id(tBTA_GATTS_CB *p_cb, UINT16 service_id)
{
UINT8 i;
APPL_TRACE_DEBUG("bta_gatts_find_srvc_cb_by_srvc_id service_id=%d", service_id);
for (i = 0; i < BTA_GATTS_MAX_SRVC_NUM; i ++)
{
for (i = 0; i < BTA_GATTS_MAX_SRVC_NUM; i ++) {
if (p_cb->srvc_cb[i].in_use &&
p_cb->srvc_cb[i].service_id == service_id)
{
p_cb->srvc_cb[i].service_id == service_id) {
APPL_TRACE_DEBUG("bta_gatts_find_srvc_cb_by_srvc_id found service cb index =%d", i);
return &p_cb->srvc_cb[i];
}
@ -153,12 +150,11 @@ tBTA_GATTS_SRVC_CB * bta_gatts_find_srvc_cb_by_srvc_id(tBTA_GATTS_CB *p_cb, UINT
** Returns pointer to the rcb.
**
*******************************************************************************/
tBTA_GATTS_SRVC_CB * bta_gatts_find_srvc_cb_by_attr_id(tBTA_GATTS_CB *p_cb, UINT16 attr_id)
tBTA_GATTS_SRVC_CB *bta_gatts_find_srvc_cb_by_attr_id(tBTA_GATTS_CB *p_cb, UINT16 attr_id)
{
UINT8 i;
for (i = 0; i < (BTA_GATTS_MAX_SRVC_NUM); i ++)
{
for (i = 0; i < (BTA_GATTS_MAX_SRVC_NUM); i ++) {
if (/* middle service */
(i < (BTA_GATTS_MAX_SRVC_NUM - 1) &&
p_cb->srvc_cb[i].in_use &&
@ -173,8 +169,7 @@ tBTA_GATTS_SRVC_CB * bta_gatts_find_srvc_cb_by_attr_id(tBTA_GATTS_CB *p_cb, UINT
/* last service incb */
(i == (BTA_GATTS_MAX_SRVC_NUM - 1) &&
attr_id >= p_cb->srvc_cb[i].service_id)
)
{
) {
return &p_cb->srvc_cb[i];
}
}
@ -195,37 +190,33 @@ BOOLEAN bta_gatts_uuid_compare(tBT_UUID tar, tBT_UUID src)
UINT8 *ps, *pt;
/* any of the UUID is unspecified */
if (src.len == 0 || tar.len == 0)
{
if (src.len == 0 || tar.len == 0) {
return TRUE;
}
/* If both are 16-bit, we can do a simple compare */
if (src.len == 2 && tar.len == 2)
{
if (src.len == 2 && tar.len == 2) {
return src.uu.uuid16 == tar.uu.uuid16;
}
/* One or both of the UUIDs is 128-bit */
if (src.len == LEN_UUID_16)
{
if (src.len == LEN_UUID_16) {
/* convert a 16 bits UUID to 128 bits value */
bta_gatt_convert_uuid16_to_uuid128(su, src.uu.uuid16);
ps = su;
}
else
} else {
ps = src.uu.uuid128;
}
if (tar.len == LEN_UUID_16)
{
if (tar.len == LEN_UUID_16) {
/* convert a 16 bits UUID to 128 bits value */
bta_gatt_convert_uuid16_to_uuid128(tu, tar.uu.uuid16);
pt = tu;
}
else
} else {
pt = tar.uu.uuid128;
}
return(memcmp(ps, pt, LEN_UUID_128) == 0);
return (memcmp(ps, pt, LEN_UUID_128) == 0);
}

View file

@ -48,8 +48,8 @@ static void bta_hh_cback (UINT8 dev_handle, BD_ADDR addr, UINT8 event,
static tBTA_HH_STATUS bta_hh_get_trans_status(UINT32 result);
#if BTA_HH_DEBUG
static char* bta_hh_get_w4_event(UINT16 event);
static char * bta_hh_hid_event_name(UINT16 event);
static char *bta_hh_get_w4_event(UINT16 event);
static char *bta_hh_hid_event_name(UINT16 event);
#endif
/*****************************************************************************
@ -78,31 +78,28 @@ void bta_hh_api_enable(tBTA_HH_DATA *p_data)
HID_HostSetSecurityLevel("", p_data->api_enable.sec_mask);
/* Register with L2CAP */
if ( HID_HostRegister (bta_hh_cback) == HID_SUCCESS)
{
if ( HID_HostRegister (bta_hh_cback) == HID_SUCCESS) {
/* store parameters */
bta_hh_cb.p_cback = p_data->api_enable.p_cback;
status = BTA_HH_OK;
/* initialize device CB */
for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx ++)
{
for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx ++) {
bta_hh_cb.kdev[xx].state = BTA_HH_IDLE_ST;
bta_hh_cb.kdev[xx].hid_handle = BTA_HH_INVALID_HANDLE;
bta_hh_cb.kdev[xx].index = xx;
}
/* initialize control block map */
for (xx = 0; xx < BTA_HH_MAX_KNOWN; xx ++)
for (xx = 0; xx < BTA_HH_MAX_KNOWN; xx ++) {
bta_hh_cb.cb_index[xx] = BTA_HH_IDX_INVALID;
}
}
#if (BTA_HH_LE_INCLUDED == TRUE)
if (status == BTA_HH_OK)
{
if (status == BTA_HH_OK) {
bta_hh_le_enable();
}
else
} else
#endif
/* signal BTA call back event */
(* bta_hh_cb.p_cback)(BTA_HH_ENABLE_EVT, (tBTA_HH *)&status);
@ -122,23 +119,19 @@ void bta_hh_api_disable(void)
UINT8 xx;
/* service is not enabled */
if (bta_hh_cb.p_cback == NULL)
if (bta_hh_cb.p_cback == NULL) {
return;
}
/* no live connection, signal DISC_CMPL_EVT directly */
if (!bta_hh_cb.cnt_num)
{
if (!bta_hh_cb.cnt_num) {
bta_hh_disc_cmpl();
}
else /* otherwise, disconnect all live connections */
{
} else { /* otherwise, disconnect all live connections */
bta_hh_cb.w4_disable = TRUE;
for(xx = 0; xx < BTA_HH_MAX_DEVICE; xx ++)
{
for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx ++) {
/* send API_CLOSE event to every connected device */
if ( bta_hh_cb.kdev[xx].state == BTA_HH_CONN_ST )
{
if ( bta_hh_cb.kdev[xx].state == BTA_HH_CONN_ST ) {
/* disconnect all connected devices */
bta_hh_sm_execute(&bta_hh_cb.kdev[xx],
BTA_HH_API_CLOSE_EVT,
@ -165,8 +158,9 @@ void bta_hh_disc_cmpl(void)
tBTA_HH_STATUS status = BTA_HH_OK;
/* Deregister with lower layer */
if (HID_HostDeregister() != HID_SUCCESS)
if (HID_HostDeregister() != HID_SUCCESS) {
status = BTA_HH_ERR;
}
#if (BTA_HH_LE_INCLUDED == TRUE)
bta_hh_le_deregister();
@ -193,44 +187,36 @@ static void bta_hh_sdp_cback(UINT16 result, UINT16 attr_mask,
tBTA_HH_STATUS status = BTA_HH_ERR_SDP;
/* make sure sdp succeeded and hh has not been disabled */
if ((result == SDP_SUCCESS) && (p_cb != NULL))
{
if ((result == SDP_SUCCESS) && (p_cb != NULL)) {
/* security is required for the connection, add attr_mask bit*/
if (p_cb->sec_mask)
if (p_cb->sec_mask) {
attr_mask |= HID_SEC_REQUIRED;
}
#if BTA_HH_DEBUG
APPL_TRACE_EVENT("bta_hh_sdp_cback: p_cb: %d result 0x%02x, \
attr_mask 0x%02x, handle %x", \
p_cb, result, attr_mask,p_cb->hid_handle);
p_cb, result, attr_mask, p_cb->hid_handle);
#endif
/* check to see type of device is supported , and should not been added before */
if (bta_hh_tod_spt(p_cb, sdp_rec->sub_class))
{
if (bta_hh_tod_spt(p_cb, sdp_rec->sub_class)) {
/* if not added before */
if (p_cb->hid_handle == BTA_HH_INVALID_HANDLE)
{
if (p_cb->hid_handle == BTA_HH_INVALID_HANDLE) {
/* add device/update attr_mask information */
if(HID_HostAddDev (p_cb->addr, attr_mask, &hdl) == HID_SUCCESS)
{
if (HID_HostAddDev (p_cb->addr, attr_mask, &hdl) == HID_SUCCESS) {
status = BTA_HH_OK;
/* update cb_index[] map */
bta_hh_cb.cb_index[hdl] = p_cb->index;
}
else
{
} else {
p_cb->app_id = 0;
}
}
else
{
} else {
hdl = p_cb->hid_handle;
}
/* else : incoming connection after SDP should update the SDP information as well */
if (p_cb->app_id != 0)
{
if (p_cb->app_id != 0) {
/* update cb information with attr_mask, dscp_info etc. */
bta_hh_add_device_to_list(p_cb, hdl, attr_mask,
&sdp_rec->dscp_info,
@ -244,10 +230,10 @@ static void bta_hh_sdp_cback(UINT16 result, UINT16 attr_mask,
status = BTA_HH_OK;
}
}
else /* type of device is not supported */
} else { /* type of device is not supported */
status = BTA_HH_ERR_TOD_UNSPT;
}
}
/* free disc_db when SDP is completed */
utl_freebuf((void **)&bta_hh_cb.p_disc_db);
@ -280,31 +266,23 @@ static void bta_hh_di_sdp_cback(UINT16 result)
* set to 0xffff and we will allow the connection to go through. Spec mandates that DI
* record be set, but many HID devices do not set this. So for IOP purposes, we allow the
* connection to go through and update the DI record to invalid DI entry.*/
if (((result == SDP_SUCCESS) || (result == SDP_NO_RECS_MATCH)) && (p_cb != NULL))
{
if(result == SDP_SUCCESS && SDP_GetNumDiRecords(bta_hh_cb.p_disc_db) != 0)
{
if (((result == SDP_SUCCESS) || (result == SDP_NO_RECS_MATCH)) && (p_cb != NULL)) {
if (result == SDP_SUCCESS && SDP_GetNumDiRecords(bta_hh_cb.p_disc_db) != 0) {
/* always update information with primary DI record */
if (SDP_GetDiRecord(1, &di_rec, bta_hh_cb.p_disc_db) == SDP_SUCCESS)
{
if (SDP_GetDiRecord(1, &di_rec, bta_hh_cb.p_disc_db) == SDP_SUCCESS) {
bta_hh_update_di_info(p_cb, di_rec.rec.vendor, di_rec.rec.product, di_rec.rec.version, 0);
}
}
else /* no DI recrod available */
{
} else { /* no DI recrod available */
bta_hh_update_di_info(p_cb, BTA_HH_VENDOR_ID_INVALID, 0, 0, 0);
}
if ((ret = HID_HostGetSDPRecord(p_cb->addr,
bta_hh_cb.p_disc_db,
p_bta_hh_cfg->sdp_db_size,
bta_hh_sdp_cback)) == HID_SUCCESS)
{
bta_hh_sdp_cback)) == HID_SUCCESS) {
status = BTA_HH_OK;
}
else
{
} else {
#if BTA_HH_DEBUG
APPL_TRACE_DEBUG ("bta_hh_di_sdp_cback: HID_HostGetSDPRecord failed: Status 0x%2x",
ret);
@ -313,8 +291,7 @@ static void bta_hh_di_sdp_cback(UINT16 result)
}
if (status != BTA_HH_OK)
{
if (status != BTA_HH_OK) {
utl_freebuf((void **)&bta_hh_cb.p_disc_db);
/* send SDP_CMPL_EVT into state machine */
bta_hh_sm_execute(p_cb, BTA_HH_SDP_CMPL_EVT, (tBTA_HH_DATA *)&status);
@ -346,25 +323,21 @@ void bta_hh_start_sdp(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
bta_hh_cb.p_cur = p_cb;
#if (BTA_HH_LE_INCLUDED == TRUE)
if (bta_hh_is_le_device(p_cb, p_data->api_conn.bd_addr))
{
if (bta_hh_is_le_device(p_cb, p_data->api_conn.bd_addr)) {
bta_hh_le_open_conn(p_cb, p_data->api_conn.bd_addr);
return;
}
#endif
/* if previously virtually cabled device, skip SDP */
if (p_cb->app_id)
{
if (p_cb->app_id) {
status = BTA_HH_OK;
#if BTA_HH_DEBUG
APPL_TRACE_DEBUG("bta_hh_start_sdp:: skip SDP for known devices");
#endif
if (p_cb->hid_handle == BTA_HH_INVALID_HANDLE)
{
if (p_cb->hid_handle == BTA_HH_INVALID_HANDLE) {
if (HID_HostAddDev (p_cb->addr, p_cb->attr_mask, &hdl) \
== HID_SUCCESS)
{
== HID_SUCCESS) {
/* update device CB with newly register device handle */
bta_hh_add_device_to_list(p_cb, hdl, p_cb->attr_mask, NULL,
p_cb->sub_class,
@ -373,46 +346,42 @@ void bta_hh_start_sdp(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
p_cb->app_id);
/* update cb_index[] map */
bta_hh_cb.cb_index[hdl] = p_cb->index;
}
else
} else {
status = BTA_HH_ERR_NO_RES;
}
}
bta_hh_sm_execute(p_cb, BTA_HH_SDP_CMPL_EVT, (tBTA_HH_DATA *)&status);
return;
}
/* GetSDPRecord. at one time only one SDP precedure can be active */
else if (!bta_hh_cb.p_disc_db)
{
else if (!bta_hh_cb.p_disc_db) {
bta_hh_cb.p_disc_db = (tSDP_DISCOVERY_DB *) GKI_getbuf(p_bta_hh_cfg->sdp_db_size);
if (bta_hh_cb.p_disc_db == NULL)
{
if (bta_hh_cb.p_disc_db == NULL) {
status = BTA_HH_ERR_NO_RES;
}
else
{
} else {
bta_hh_cb.p_cur = p_cb;
/* do DI discovery first */
if (SDP_DiDiscover(p_data->api_conn.bd_addr,
bta_hh_cb.p_disc_db,
p_bta_hh_cfg->sdp_db_size,
bta_hh_di_sdp_cback) != SDP_SUCCESS)
{
bta_hh_di_sdp_cback) != SDP_SUCCESS) {
#if BTA_HH_DEBUG
APPL_TRACE_DEBUG ("bta_hh_start_sdp: SDP_DiDiscover failed: \
Status 0x%2X",status);
Status 0x%2X", status);
#endif
status = BTA_HH_ERR_SDP;
utl_freebuf((void **)&bta_hh_cb.p_disc_db);
}
else
} else {
status = BTA_HH_OK;
}
}
}
if (status != BTA_HH_OK)
if (status != BTA_HH_OK) {
bta_hh_sm_execute(p_cb, BTA_HH_SDP_CMPL_EVT, (tBTA_HH_DATA *)&status);
}
return;
@ -434,7 +403,7 @@ void bta_hh_sdp_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
tBTA_HH_STATUS status = p_data->status;
#if BTA_HH_DEBUG
APPL_TRACE_DEBUG ("bta_hh_sdp_cmpl: status 0x%2X",p_data->status);
APPL_TRACE_DEBUG ("bta_hh_sdp_cmpl: status 0x%2X", p_data->status);
#endif
/* initialize call back data */
@ -443,46 +412,37 @@ void bta_hh_sdp_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
bdcpy(conn_dat.bda, p_cb->addr);
/* if SDP compl success */
if ( status == BTA_HH_OK)
{
if ( status == BTA_HH_OK) {
/* not incoming connection doing SDP, initiate a HID connection */
if (!p_cb->incoming_conn)
{
if (!p_cb->incoming_conn) {
tHID_STATUS ret;
/* set security level */
HID_HostSetSecurityLevel("", p_cb->sec_mask);
/* open HID connection */
if ((ret = HID_HostOpenDev (p_cb->hid_handle)) != HID_SUCCESS)
{
if ((ret = HID_HostOpenDev (p_cb->hid_handle)) != HID_SUCCESS) {
#if BTA_HH_DEBUG
APPL_TRACE_DEBUG ("bta_hh_sdp_cmpl: HID_HostOpenDev failed: \
Status 0x%2X",ret);
Status 0x%2X", ret);
#endif
/* open fail, remove device from management device list */
HID_HostRemoveDev( p_cb->hid_handle);
status = BTA_HH_ERR;
}
else
{
} else {
status = BTA_HH_OK;
}
}
else /* incoming connection SDP finish */
{
} else { /* incoming connection SDP finish */
bta_hh_sm_execute(p_cb, BTA_HH_OPEN_CMPL_EVT, NULL);
}
}
if (status != BTA_HH_OK)
{
if (status != BTA_HH_OK) {
/* Check if this was incoming connection request from an unknown device
**and connection failed due to missing HID Device SDP UUID
**In above condition, disconnect the link as well as remove the
**device from list of HID devices*/
if ((status == BTA_HH_ERR_SDP) &&
(p_cb->incoming_conn) &&(p_cb->app_id == 0))
{
(p_cb->incoming_conn) && (p_cb->app_id == 0)) {
APPL_TRACE_DEBUG ("bta_hh_sdp_cmpl:SDP failed for incoming conn :hndl %d",
p_cb->incoming_hid_handle);
HID_HostRemoveDev( p_cb->incoming_hid_handle);
@ -494,8 +454,7 @@ void bta_hh_sdp_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
bta_hh_sm_execute(p_cb, BTA_HH_API_CLOSE_EVT, NULL);
/* if this is an outgoing connection to an unknown device, clean up cb */
if (p_cb->app_id == 0 && !p_cb->incoming_conn)
{
if (p_cb->app_id == 0 && !p_cb->incoming_conn) {
/* clean up device control block */
bta_hh_clean_up_kdev(p_cb);
}
@ -522,20 +481,21 @@ void bta_hh_api_disc_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
tHID_STATUS status;
#if BTA_HH_LE_INCLUDED == TRUE
if (p_cb->is_le_device)
if (p_cb->is_le_device) {
bta_hh_le_api_disc_act(p_cb);
else
} else
#endif
{
/* found an active connection */
disc_dat.handle = p_data ?(UINT8)p_data->hdr.layer_specific :p_cb->hid_handle;
disc_dat.handle = p_data ? (UINT8)p_data->hdr.layer_specific : p_cb->hid_handle;
disc_dat.status = BTA_HH_ERR;
status = HID_HostCloseDev(disc_dat.handle);
if (status)
if (status) {
(* bta_hh_cb.p_cback)(BTA_HH_CLOSE_EVT, (tBTA_HH *)&disc_dat);
}
}
return;
@ -576,32 +536,28 @@ void bta_hh_open_cmpl_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
#endif
{
/* inform role manager */
bta_sys_conn_open( BTA_ID_HH ,p_cb->app_id, p_cb->addr);
bta_sys_conn_open( BTA_ID_HH , p_cb->app_id, p_cb->addr);
}
/* set protocol mode when not default report mode */
if ( p_cb->mode != BTA_HH_PROTO_RPT_MODE
#if (BTA_HH_LE_INCLUDED == TRUE)
&& !p_cb->is_le_device
#endif
)
{
) {
if ((HID_HostWriteDev(dev_handle,
HID_TRANS_SET_PROTOCOL, HID_PAR_PROTOCOL_BOOT_MODE,
0,
0, NULL)) != HID_SUCCESS)
{
0, NULL)) != HID_SUCCESS) {
/* HID connection is up, while SET_PROTO fail */
conn.status = BTA_HH_ERR_PROTO;
(* bta_hh_cb.p_cback)(BTA_HH_OPEN_EVT, (tBTA_HH *)&conn);
}
else
{
} else {
conn.status = BTA_HH_OK;
p_cb->w4_evt = BTA_HH_OPEN_EVT;
}
}
else
} else {
(* bta_hh_cb.p_cback)(BTA_HH_OPEN_EVT, (tBTA_HH *)&conn);
}
p_cb->incoming_conn = FALSE;
p_cb->incoming_hid_handle = BTA_HH_INVALID_HANDLE;
@ -629,11 +585,9 @@ void bta_hh_open_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
#endif
/* SDP has been done */
if (p_cb->app_id != 0)
{
if (p_cb->app_id != 0) {
bta_hh_sm_execute(p_cb, BTA_HH_OPEN_CMPL_EVT, p_data);
}
else
} else
/* app_id == 0 indicates an incoming conenction request arrives without SDP
performed, do it first */
{
@ -660,7 +614,7 @@ void bta_hh_open_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
** Returns void
**
*******************************************************************************/
void bta_hh_data_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * p_data)
void bta_hh_data_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
{
BT_HDR *pdata = p_data->hid_cback.p_data;
UINT8 *p_rpt = (UINT8 *)(pdata + 1) + pdata->offset;
@ -682,7 +636,7 @@ void bta_hh_data_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * p_data)
** Returns void
**
*******************************************************************************/
void bta_hh_handsk_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * p_data)
void bta_hh_handsk_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
{
tBTA_HH_CBDATA cback_data ;
tBTA_HH_HSDATA hs_data;
@ -696,8 +650,7 @@ void bta_hh_handsk_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * p_data)
memset(&hs_data, 0, sizeof(tBTA_HH_HSDATA));
memset(&cback_data, 0, sizeof(tBTA_HH_CBDATA));
switch (p_cb->w4_evt)
{
switch (p_cb->w4_evt) {
/* GET_ transsaction, handshake indicate unsupported request */
case BTA_HH_GET_PROTO_EVT:
hs_data.rsp_data.proto_mode = BTA_HH_PROTO_UNKNOWN;
@ -706,8 +659,9 @@ void bta_hh_handsk_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * p_data)
case BTA_HH_GET_IDLE_EVT :
hs_data.handle = p_cb->hid_handle;
/* if handshake gives an OK code for these transaction, fill in UNSUPT */
if ((hs_data.status = bta_hh_get_trans_status(p_data->hid_cback.data)) == BTA_HH_OK)
if ((hs_data.status = bta_hh_get_trans_status(p_data->hid_cback.data)) == BTA_HH_OK) {
hs_data.status = BTA_HH_HS_TRANS_NOT_SPT;
}
(* bta_hh_cb.p_cback)(p_cb->w4_evt, (tBTA_HH *)&hs_data);
p_cb->w4_evt = 0;
@ -725,7 +679,7 @@ void bta_hh_handsk_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * p_data)
/* SET_PROTOCOL when open connection */
case BTA_HH_OPEN_EVT:
conn.status =p_data->hid_cback.data ? BTA_HH_ERR_PROTO: BTA_HH_OK;
conn.status = p_data->hid_cback.data ? BTA_HH_ERR_PROTO : BTA_HH_OK;
conn.handle = p_cb->hid_handle;
bdcpy(conn.bda, p_cb->addr);
(* bta_hh_cb.p_cback)(p_cb->w4_evt, (tBTA_HH *)&conn);
@ -755,7 +709,7 @@ void bta_hh_handsk_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * p_data)
** Returns void
**
*******************************************************************************/
void bta_hh_ctrl_dat_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * p_data)
void bta_hh_ctrl_dat_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
{
BT_HDR *pdata = p_data->hid_cback.p_data;
UINT8 *data = (UINT8 *)(pdata + 1) + pdata->offset;
@ -768,8 +722,7 @@ void bta_hh_ctrl_dat_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * p_data)
hs_data.status = BTA_HH_OK;
hs_data.handle = p_cb->hid_handle;
switch (p_cb->w4_evt)
{
switch (p_cb->w4_evt) {
case BTA_HH_GET_IDLE_EVT:
hs_data.rsp_data.idle_rate = *data;
break;
@ -778,11 +731,11 @@ void bta_hh_ctrl_dat_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * p_data)
break;
case BTA_HH_GET_PROTO_EVT:
/* match up BTE/BTA report/boot mode def*/
hs_data.rsp_data.proto_mode = ((*data) == HID_PAR_PROTOCOL_REPORT)? \
hs_data.rsp_data.proto_mode = ((*data) == HID_PAR_PROTOCOL_REPORT) ? \
BTA_HH_PROTO_RPT_MODE : BTA_HH_PROTO_BOOT_MODE;
#if BTA_HH_DEBUG
APPL_TRACE_DEBUG("GET_PROTOCOL Mode = [%s]",
(hs_data.rsp_data.proto_mode == BTA_HH_PROTO_RPT_MODE)? "Report" : "Boot");
(hs_data.rsp_data.proto_mode == BTA_HH_PROTO_RPT_MODE) ? "Report" : "Boot");
#endif
break;
/* should not expect control DATA for SET_ transaction */
@ -845,8 +798,7 @@ void bta_hh_open_failure(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
p_cb->w4_evt = 0;
/* if no connection is active and HH disable is signaled, disable service */
if (bta_hh_cb.cnt_num == 0 && bta_hh_cb.w4_disable)
{
if (bta_hh_cb.cnt_num == 0 && bta_hh_cb.w4_disable) {
bta_hh_disc_cmpl();
}
@ -875,10 +827,9 @@ void bta_hh_close_act (tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
disc_dat.status = p_data->hid_cback.data;
/* Check reason for closing */
if ((reason & (HID_L2CAP_CONN_FAIL|HID_L2CAP_REQ_FAIL)) || /* Failure to initialize connection (page timeout or l2cap error) */
if ((reason & (HID_L2CAP_CONN_FAIL | HID_L2CAP_REQ_FAIL)) || /* Failure to initialize connection (page timeout or l2cap error) */
(reason == HID_ERR_AUTH_FAILED) || /* Authenication error (while initiating) */
(reason == HID_ERR_L2CAP_FAILED)) /* Failure creating l2cap connection */
{
(reason == HID_ERR_L2CAP_FAILED)) { /* Failure creating l2cap connection */
/* Failure in opening connection */
conn_dat.handle = p_cb->hid_handle;
conn_dat.status = (reason == HID_ERR_AUTH_FAILED) ? BTA_HH_ERR_AUTH_FAILED : BTA_HH_ERR;
@ -894,23 +845,22 @@ void bta_hh_close_act (tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
return;
}
/* otherwise report CLOSE/VC_UNPLUG event */
else
{
else {
/* finaliza device driver */
bta_hh_co_close(p_cb->hid_handle, p_cb->app_id);
/* inform role manager */
bta_sys_conn_close( BTA_ID_HH ,p_cb->app_id, p_cb->addr);
bta_sys_conn_close( BTA_ID_HH , p_cb->app_id, p_cb->addr);
/* update total conn number */
bta_hh_cb.cnt_num --;
if (disc_dat.status)
if (disc_dat.status) {
disc_dat.status = BTA_HH_ERR;
}
(*bta_hh_cb.p_cback)(event, (tBTA_HH *)&disc_dat);
/* if virtually unplug, remove device */
if (p_cb->vp )
{
if (p_cb->vp ) {
HID_HostRemoveDev( p_cb->hid_handle);
bta_hh_clean_up_kdev(p_cb);
}
@ -925,8 +875,7 @@ void bta_hh_close_act (tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
p_cb->w4_evt = 0;
/* if no connection is active and HH disable is signaled, disable service */
if (bta_hh_cb.cnt_num == 0 && bta_hh_cb.w4_disable)
{
if (bta_hh_cb.cnt_num == 0 && bta_hh_cb.w4_disable) {
bta_hh_disc_cmpl();
}
@ -948,11 +897,9 @@ void bta_hh_get_dscp_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
UNUSED(p_data);
#if (BTA_HH_LE_INCLUDED == TRUE)
if (p_cb->is_le_device)
{
if (p_cb->is_le_device) {
bta_hh_le_get_dscp_act(p_cb);
}
else
} else
#endif
(*bta_hh_cb.p_cback)(BTA_HH_GET_DSCP_EVT, (tBTA_HH *)&p_cb->dscp_info);
}
@ -976,25 +923,20 @@ void bta_hh_maint_dev_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
dev_info.status = BTA_HH_ERR;
dev_info.handle = BTA_HH_INVALID_HANDLE;
switch (p_dev_info->sub_event)
{
switch (p_dev_info->sub_event) {
case BTA_HH_ADD_DEV_EVT: /* add a device */
bdcpy(dev_info.bda, p_dev_info->bda);
/* initialize callback data */
if (p_cb->hid_handle == BTA_HH_INVALID_HANDLE)
{
if (p_cb->hid_handle == BTA_HH_INVALID_HANDLE) {
#if (BTA_HH_LE_INCLUDED == TRUE)
if (bta_hh_is_le_device(p_cb, p_data->api_conn.bd_addr))
{
if (bta_hh_is_le_device(p_cb, p_data->api_conn.bd_addr)) {
dev_info.handle = bta_hh_le_add_device(p_cb, p_dev_info);
dev_info.status = BTA_HH_OK;
}
else
} else
#endif
if (HID_HostAddDev(p_dev_info->bda, p_dev_info->attr_mask, &dev_handle)\
== HID_SUCCESS)
{
== HID_SUCCESS) {
dev_info.handle = dev_handle;
dev_info.status = BTA_HH_OK;
@ -1024,9 +966,7 @@ void bta_hh_maint_dev_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
/* update cb_index[] map */
bta_hh_cb.cb_index[dev_handle] = p_cb->index;
}
}
else /* device already been added */
{
} else { /* device already been added */
dev_info.handle = p_cb->hid_handle;
dev_info.status = BTA_HH_OK;
}
@ -1040,17 +980,14 @@ void bta_hh_maint_dev_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
bdcpy(dev_info.bda, p_cb->addr);
#if BTA_HH_LE_INCLUDED == TRUE
if (p_cb->is_le_device)
{
if (p_cb->is_le_device) {
bta_hh_le_remove_dev_bg_conn(p_cb);
bta_hh_sm_execute(p_cb, BTA_HH_API_CLOSE_EVT, NULL);
bta_hh_clean_up_kdev(p_cb);
}
else
} else
#endif
{
if(HID_HostRemoveDev( dev_info.handle ) == HID_SUCCESS)
{
if (HID_HostRemoveDev( dev_info.handle ) == HID_SUCCESS) {
dev_info.status = BTA_HH_OK;
/* remove from known device list in BTA */
@ -1082,19 +1019,18 @@ void bta_hh_write_dev_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
BTA_HH_FST_TRANS_CB_EVT;
#if BTA_HH_LE_INCLUDED == TRUE
if (p_cb->is_le_device)
if (p_cb->is_le_device) {
bta_hh_le_write_dev_act(p_cb, p_data);
else
} else
#endif
{
cbdata.handle = p_cb->hid_handle;
/* match up BTE/BTA report/boot mode def */
if (p_data->api_sndcmd.t_type == HID_TRANS_SET_PROTOCOL)
{
p_data->api_sndcmd.param = ( p_data->api_sndcmd.param == BTA_HH_PROTO_RPT_MODE) ?\
HID_PAR_PROTOCOL_REPORT :HID_PAR_PROTOCOL_BOOT_MODE;
if (p_data->api_sndcmd.t_type == HID_TRANS_SET_PROTOCOL) {
p_data->api_sndcmd.param = ( p_data->api_sndcmd.param == BTA_HH_PROTO_RPT_MODE) ? \
HID_PAR_PROTOCOL_REPORT : HID_PAR_PROTOCOL_BOOT_MODE;
}
if (HID_HostWriteDev (p_cb->hid_handle,
@ -1102,22 +1038,19 @@ void bta_hh_write_dev_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
p_data->api_sndcmd.param,
p_data->api_sndcmd.data,
p_data->api_sndcmd.rpt_id,
p_data->api_sndcmd.p_data) != HID_SUCCESS)
{
p_data->api_sndcmd.p_data) != HID_SUCCESS) {
APPL_TRACE_ERROR("HID_HostWriteDev Error ");
cbdata.status = BTA_HH_ERR;
if (p_data->api_sndcmd.t_type != HID_TRANS_CONTROL &&
p_data->api_sndcmd.t_type != HID_TRANS_DATA)
p_data->api_sndcmd.t_type != HID_TRANS_DATA) {
(* bta_hh_cb.p_cback)(event, (tBTA_HH *)&cbdata);
else if (p_data->api_sndcmd.param == BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG)
} else if (p_data->api_sndcmd.param == BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG) {
(* bta_hh_cb.p_cback)(BTA_HH_VC_UNPLUG_EVT, (tBTA_HH *)&cbdata);
}
else
{
} else {
switch(p_data->api_sndcmd.t_type)
{
switch (p_data->api_sndcmd.t_type) {
case HID_TRANS_SET_PROTOCOL:
/* fall through */
case HID_TRANS_GET_REPORT:
@ -1136,8 +1069,9 @@ void bta_hh_write_dev_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
case HID_TRANS_CONTROL:
/* no handshake event will be generated */
/* if VC_UNPLUG is issued, set flag */
if (p_data->api_sndcmd.param == BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG)
if (p_data->api_sndcmd.param == BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG) {
p_cb->vp = TRUE;
}
break;
/* currently not expected */
@ -1149,18 +1083,13 @@ void bta_hh_write_dev_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
}
/* if not control type transaction, notify PM for energy control */
if (p_data->api_sndcmd.t_type != HID_TRANS_CONTROL)
{
if (p_data->api_sndcmd.t_type != HID_TRANS_CONTROL) {
/* inform PM for mode change */
bta_sys_busy(BTA_ID_HH, p_cb->app_id, p_cb->addr);
bta_sys_idle(BTA_ID_HH, p_cb->app_id, p_cb->addr);
}
else if (p_data->api_sndcmd.param == BTA_HH_CTRL_SUSPEND)
{
} else if (p_data->api_sndcmd.param == BTA_HH_CTRL_SUSPEND) {
bta_sys_sco_close(BTA_ID_HH, p_cb->app_id, p_cb->addr);
}
else if (p_data->api_sndcmd.param == BTA_HH_CTRL_EXIT_SUSPEND)
{
} else if (p_data->api_sndcmd.param == BTA_HH_CTRL_EXIT_SUSPEND) {
bta_sys_busy(BTA_ID_HH, p_cb->app_id, p_cb->addr);
}
}
@ -1193,8 +1122,7 @@ static void bta_hh_cback (UINT8 dev_handle, BD_ADDR addr, UINT8 event,
APPL_TRACE_DEBUG("bta_hh_cback::HID_event [%s]", bta_hh_hid_event_name(event));
#endif
switch (event)
{
switch (event) {
case HID_HDEV_EVT_OPEN:
sm_event = BTA_HH_INT_OPEN_EVT;
break;
@ -1218,10 +1146,8 @@ static void bta_hh_cback (UINT8 dev_handle, BD_ADDR addr, UINT8 event,
utl_freebuf((void **)&pdata);
break;
case HID_HDEV_EVT_VC_UNPLUG:
for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx++)
{
if (bta_hh_cb.kdev[xx].hid_handle == dev_handle)
{
for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx++) {
if (bta_hh_cb.kdev[xx].hid_handle == dev_handle) {
bta_hh_cb.kdev[xx].vp = TRUE;
break;
}
@ -1231,8 +1157,7 @@ static void bta_hh_cback (UINT8 dev_handle, BD_ADDR addr, UINT8 event,
if (sm_event != BTA_HH_INVALID_EVT &&
(p_buf = (tBTA_HH_CBACK_DATA *)GKI_getbuf(sizeof(tBTA_HH_CBACK_DATA) +
sizeof(BT_HDR))) != NULL)
{
sizeof(BT_HDR))) != NULL) {
p_buf->hdr.event = sm_event;
p_buf->hdr.layer_specific = (UINT16)dev_handle;
p_buf->data = data;
@ -1253,8 +1178,7 @@ static void bta_hh_cback (UINT8 dev_handle, BD_ADDR addr, UINT8 event,
*******************************************************************************/
static tBTA_HH_STATUS bta_hh_get_trans_status(UINT32 result)
{
switch(result)
{
switch (result) {
case HID_PAR_HANDSHAKE_RSP_SUCCESS : /* (0) */
return BTA_HH_OK;
case HID_PAR_HANDSHAKE_RSP_NOT_READY : /* (1) */
@ -1274,10 +1198,9 @@ static tBTA_HH_STATUS bta_hh_get_trans_status(UINT32 result)
*****************************************************************************/
#if (defined BTA_HH_DEBUG && BTA_HH_DEBUG == TRUE)
static char* bta_hh_get_w4_event(UINT16 event)
static char *bta_hh_get_w4_event(UINT16 event)
{
switch (event)
{
switch (event) {
case BTA_HH_GET_RPT_EVT:
return "BTA_HH_GET_RPT_EVT";
case BTA_HH_SET_RPT_EVT:
@ -1298,10 +1221,9 @@ static char* bta_hh_get_w4_event(UINT16 event)
}
static char * bta_hh_hid_event_name(UINT16 event)
static char *bta_hh_hid_event_name(UINT16 event)
{
switch (event)
{
switch (event) {
case HID_HDEV_EVT_OPEN:
return "HID_HDEV_EVT_OPEN";
case HID_HDEV_EVT_CLOSE:

View file

@ -42,8 +42,7 @@
** Constants
*****************************************************************************/
static const tBTA_SYS_REG bta_hh_reg =
{
static const tBTA_SYS_REG bta_hh_reg = {
bta_hh_hdl_event,
BTA_HhDisable
};
@ -71,8 +70,7 @@ void BTA_HhEnable(tBTA_SEC sec_mask, tBTA_HH_CBACK *p_cback)
LOG_INFO("%s sec_mask:0x%x p_cback:%p", __func__, sec_mask, p_cback);
p_buf = (tBTA_HH_API_ENABLE *)GKI_getbuf((UINT16)sizeof(tBTA_HH_API_ENABLE));
if (p_buf != NULL)
{
if (p_buf != NULL) {
memset(p_buf, 0, sizeof(tBTA_HH_API_ENABLE));
p_buf->hdr.event = BTA_HH_API_ENABLE_EVT;
@ -98,8 +96,7 @@ void BTA_HhDisable(void)
BT_HDR *p_buf;
bta_sys_deregister(BTA_ID_HH);
if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR))) != NULL)
{
if ((p_buf = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR))) != NULL) {
p_buf->event = BTA_HH_API_DISABLE_EVT;
bta_sys_sendmsg(p_buf);
}
@ -118,8 +115,7 @@ void BTA_HhClose(UINT8 dev_handle)
{
BT_HDR *p_buf;
if ((p_buf = (BT_HDR *)GKI_getbuf((UINT16)sizeof(BT_HDR))) != NULL)
{
if ((p_buf = (BT_HDR *)GKI_getbuf((UINT16)sizeof(BT_HDR))) != NULL) {
memset(p_buf, 0, sizeof(BT_HDR));
p_buf->event = BTA_HH_API_CLOSE_EVT;
p_buf->layer_specific = (UINT16) dev_handle;
@ -144,8 +140,7 @@ void BTA_HhOpen(BD_ADDR dev_bda, tBTA_HH_PROTO_MODE mode, tBTA_SEC sec_mask)
p_buf = (tBTA_HH_API_CONN *)GKI_getbuf((UINT16)sizeof(tBTA_HH_API_CONN));
if (p_buf!= NULL)
{
if (p_buf != NULL) {
memset((void *)p_buf, 0, sizeof(tBTA_HH_API_CONN));
p_buf->hdr.event = BTA_HH_API_OPEN_EVT;
@ -155,9 +150,7 @@ void BTA_HhOpen(BD_ADDR dev_bda, tBTA_HH_PROTO_MODE mode, tBTA_SEC sec_mask)
bdcpy(p_buf->bd_addr, dev_bda);
bta_sys_sendmsg((void *)p_buf);
}
else
{
} else {
APPL_TRACE_ERROR("No resource to send HID host Connect request.");
}
}
@ -173,8 +166,7 @@ static void bta_hh_snd_write_dev(UINT8 dev_handle, UINT8 t_type, UINT8 param,
tBTA_HH_CMD_DATA *p_buf;
UINT16 len = (UINT16) (sizeof(tBTA_HH_CMD_DATA) );
if ((p_buf = (tBTA_HH_CMD_DATA *)GKI_getbuf(len))!= NULL)
{
if ((p_buf = (tBTA_HH_CMD_DATA *)GKI_getbuf(len)) != NULL) {
memset(p_buf, 0, sizeof(tBTA_HH_CMD_DATA));
p_buf->hdr.event = BTA_HH_API_WRITE_DEV_EVT;
@ -309,8 +301,7 @@ void BTA_HhSendData(UINT8 dev_handle, BD_ADDR dev_bda, BT_HDR *p_data)
{
UNUSED(dev_bda);
#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
if (p_data->layer_specific != BTA_HH_RPTT_OUTPUT)
{
if (p_data->layer_specific != BTA_HH_RPTT_OUTPUT) {
APPL_TRACE_ERROR("ERROR! Wrong report type! Write Command only valid for output report!");
return;
}
@ -331,8 +322,7 @@ void BTA_HhGetDscpInfo(UINT8 dev_handle)
{
BT_HDR *p_buf;
if ((p_buf = (BT_HDR *)GKI_getbuf((UINT16)sizeof(BT_HDR))) != NULL)
{
if ((p_buf = (BT_HDR *)GKI_getbuf((UINT16)sizeof(BT_HDR))) != NULL) {
memset(p_buf, 0, sizeof(BT_HDR));
p_buf->event = BTA_HH_API_GET_DSCP_EVT;
p_buf->layer_specific = (UINT16) dev_handle;
@ -361,8 +351,7 @@ void BTA_HhAddDev(BD_ADDR bda, tBTA_HH_ATTR_MASK attr_mask, UINT8 sub_class,
p_buf = (tBTA_HH_MAINT_DEV *)GKI_getbuf(len);
if (p_buf != NULL)
{
if (p_buf != NULL) {
memset(p_buf, 0, sizeof(tBTA_HH_MAINT_DEV));
p_buf->hdr.event = BTA_HH_API_MAINT_DEV_EVT;
@ -375,14 +364,11 @@ void BTA_HhAddDev(BD_ADDR bda, tBTA_HH_ATTR_MASK attr_mask, UINT8 sub_class,
bdcpy(p_buf->bda, bda);
memcpy(&p_buf->dscp_info, &dscp_info, sizeof(tBTA_HH_DEV_DSCP_INFO));
if ( dscp_info.descriptor.dl_len != 0 && dscp_info.descriptor.dsc_list)
{
if ( dscp_info.descriptor.dl_len != 0 && dscp_info.descriptor.dsc_list) {
p_buf->dscp_info.descriptor.dl_len = dscp_info.descriptor.dl_len;
p_buf->dscp_info.descriptor.dsc_list = (UINT8 *)(p_buf + 1);
memcpy(p_buf->dscp_info.descriptor.dsc_list, dscp_info.descriptor.dsc_list, dscp_info.descriptor.dl_len);
}
else
{
} else {
p_buf->dscp_info.descriptor.dsc_list = NULL;
p_buf->dscp_info.descriptor.dl_len = 0;
}
@ -405,8 +391,7 @@ void BTA_HhRemoveDev(UINT8 dev_handle )
p_buf = (tBTA_HH_MAINT_DEV *)GKI_getbuf((UINT16)sizeof(tBTA_HH_MAINT_DEV));
if (p_buf != NULL)
{
if (p_buf != NULL) {
memset(p_buf, 0, sizeof(tBTA_HH_MAINT_DEV));
p_buf->hdr.event = BTA_HH_API_MAINT_DEV_EVT;
@ -434,8 +419,7 @@ void BTA_HhUpdateLeScanParam(UINT8 dev_handle, UINT16 scan_int, UINT16 scan_win)
p_buf = (tBTA_HH_SCPP_UPDATE *)GKI_getbuf((UINT16)sizeof(tBTA_HH_SCPP_UPDATE));
if (p_buf != NULL)
{
if (p_buf != NULL) {
memset(p_buf, 0, sizeof(tBTA_HH_SCPP_UPDATE));
p_buf->hdr.event = BTA_HH_API_SCPP_UPDATE_EVT;
@ -469,14 +453,12 @@ void BTA_HhParseBootRpt(tBTA_HH_BOOT_RPT *p_data, UINT8 *p_report,
{
p_data->dev_type = BTA_HH_DEVT_UNKNOWN;
if (p_report)
{
if (p_report) {
/* first byte is report ID */
switch (p_report[0])
{
switch (p_report[0]) {
case BTA_HH_KEYBD_RPT_ID: /* key board report ID */
p_data->dev_type = p_report[0];
bta_hh_parse_keybd_rpt(p_data, p_report + 1, (UINT16)(report_len -1));
bta_hh_parse_keybd_rpt(p_data, p_report + 1, (UINT16)(report_len - 1));
break;
case BTA_HH_MOUSE_RPT_ID: /* mouse report ID */

View file

@ -37,11 +37,10 @@
/* The type of devices supported by BTA HH and corresponding application ID */
tBTA_HH_SPT_TOD p_devt_list[BTA_HH_MAX_DEVT_SPT] =
{
tBTA_HH_SPT_TOD p_devt_list[BTA_HH_MAX_DEVT_SPT] = {
{BTA_HH_DEVT_MIC, BTA_HH_APP_ID_MI},
{BTA_HH_DEVT_KBD, BTA_HH_APP_ID_KB},
{BTA_HH_DEVT_KBD|BTA_HH_DEVT_MIC, BTA_HH_APP_ID_KB},
{BTA_HH_DEVT_KBD | BTA_HH_DEVT_MIC, BTA_HH_APP_ID_KB},
{BTA_HH_DEVT_RMC, BTA_HH_APP_ID_RMC},
{BTA_HH_DEVT_RMC | BTA_HH_DEVT_KBD, BTA_HH_APP_ID_RMC},
{BTA_HH_DEVT_MIC | BTA_HH_DEVT_DGT, BTA_HH_APP_ID_MI},
@ -51,12 +50,11 @@ tBTA_HH_SPT_TOD p_devt_list[BTA_HH_MAX_DEVT_SPT] =
};
const tBTA_HH_CFG bta_hh_cfg =
{
const tBTA_HH_CFG bta_hh_cfg = {
BTA_HH_MAX_DEVT_SPT, /* number of supported type of devices */
p_devt_list, /* ToD & AppID list */
BTA_HH_DISC_BUF_SIZE /* HH SDP discovery database size */
};
tBTA_HH_CFG *p_bta_hh_cfg = (tBTA_HH_CFG *)&bta_hh_cfg;
tBTA_HH_CFG *p_bta_hh_cfg = (tBTA_HH_CFG *) &bta_hh_cfg;

View file

@ -42,8 +42,7 @@
#endif
/* state machine events, these events are handled by the state machine */
enum
{
enum {
BTA_HH_API_OPEN_EVT = BTA_SYS_EVT_START(BTA_ID_HH),
BTA_HH_API_CLOSE_EVT,
BTA_HH_INT_OPEN_EVT,
@ -87,23 +86,21 @@ typedef UINT16 tBTA_HH_INT_EVT; /* HID host internal events */
#define BTA_HH_REMOVE_DEV 1
/* state machine states */
enum
{
enum {
BTA_HH_NULL_ST,
BTA_HH_IDLE_ST,
BTA_HH_W4_CONN_ST,
BTA_HH_CONN_ST
#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
,BTA_HH_W4_SEC
, BTA_HH_W4_SEC
#endif
,BTA_HH_INVALID_ST /* Used to check invalid states before executing SM function */
, BTA_HH_INVALID_ST /* Used to check invalid states before executing SM function */
};
typedef UINT8 tBTA_HH_STATE;
/* data structure used to send a command/data to HID device */
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT8 t_type;
UINT8 param;
@ -113,36 +110,32 @@ typedef struct
#endif
UINT16 data;
BT_HDR *p_data;
}tBTA_HH_CMD_DATA;
} tBTA_HH_CMD_DATA;
/* data type for BTA_HH_API_ENABLE_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT8 sec_mask;
UINT8 service_name[BTA_SERVICE_NAME_LEN+1];
UINT8 service_name[BTA_SERVICE_NAME_LEN + 1];
tBTA_HH_CBACK *p_cback;
} tBTA_HH_API_ENABLE;
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
UINT8 sec_mask;
tBTA_HH_PROTO_MODE mode;
}tBTA_HH_API_CONN;
} tBTA_HH_API_CONN;
/* internal event data from BTE HID callback */
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR addr;
UINT32 data;
BT_HDR *p_data;
}tBTA_HH_CBACK_DATA;
} tBTA_HH_CBACK_DATA;
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bda;
UINT16 attr_mask;
@ -150,27 +143,24 @@ typedef struct
UINT8 sub_class;
UINT8 app_id;
tBTA_HH_DEV_DSCP_INFO dscp_info;
}tBTA_HH_MAINT_DEV;
} tBTA_HH_MAINT_DEV;
#if BTA_HH_LE_INCLUDED == TRUE
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT16 conn_id;
tBTA_GATT_REASON reason; /* disconnect reason code, not useful when connect event is reported */
}tBTA_HH_LE_CLOSE;
} tBTA_HH_LE_CLOSE;
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT16 scan_int;
UINT16 scan_win;
}tBTA_HH_SCPP_UPDATE;
} tBTA_HH_SCPP_UPDATE;
#endif
/* union of all event data types */
typedef union
{
typedef union {
BT_HDR hdr;
tBTA_HH_API_ENABLE api_enable;
tBTA_HH_API_CONN api_conn;
@ -187,8 +177,7 @@ typedef union
} tBTA_HH_DATA;
#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
typedef struct
{
typedef struct {
UINT8 index;
BOOLEAN in_use;
UINT8 inst_id; /* share service instance ID and report instance ID, as
@ -199,14 +188,13 @@ typedef struct
UINT8 rpt_id;
BOOLEAN client_cfg_exist;
UINT16 client_cfg_value;
}tBTA_HH_LE_RPT;
} tBTA_HH_LE_RPT;
#ifndef BTA_HH_LE_RPT_MAX
#define BTA_HH_LE_RPT_MAX 20
#endif
typedef struct
{
typedef struct {
BOOLEAN in_use;
tBTA_HH_LE_RPT report[BTA_HH_LE_RPT_MAX];
@ -221,7 +209,7 @@ typedef struct
UINT16 ext_rpt_ref;
tBTA_HH_DEV_DESCR descriptor;
}tBTA_HH_LE_HID_SRVC;
} tBTA_HH_LE_HID_SRVC;
#ifndef BTA_HH_LE_HID_SRVC_MAX
#define BTA_HH_LE_HID_SRVC_MAX 1
@ -237,8 +225,7 @@ typedef struct
#endif
/* device control block */
typedef struct
{
typedef struct {
tBTA_HH_DEV_DSCP_INFO dscp_info; /* report descriptor and DI information */
BD_ADDR addr; /* BD-Addr of the HID device */
UINT16 attr_mask; /* attribute mask */
@ -285,8 +272,7 @@ typedef struct
} tBTA_HH_DEV_CB;
/* key board parsing control block */
typedef struct
{
typedef struct {
BOOLEAN mod_key[4]; /* ctrl, shift(upper), Alt, GUI */
BOOLEAN num_lock;
BOOLEAN caps_lock;
@ -296,14 +282,13 @@ typedef struct
/******************************************************************************
** Main Control Block
*******************************************************************************/
typedef struct
{
typedef struct {
tBTA_HH_KB_CB kb_cb; /* key board control block,
suppose BTA will connect
to only one keyboard at
the same time */
tBTA_HH_DEV_CB kdev[BTA_HH_MAX_DEVICE]; /* device control block */
tBTA_HH_DEV_CB* p_cur; /* current device control
tBTA_HH_DEV_CB *p_cur; /* current device control
block idx, used in sdp */
UINT8 cb_index[BTA_HH_MAX_KNOWN]; /* maintain a CB index
map to dev handle */
@ -312,7 +297,7 @@ typedef struct
tBTA_GATTC_IF gatt_if;
#endif
tBTA_HH_CBACK *p_cback; /* Application callbacks */
tSDP_DISCOVERY_DB* p_disc_db;
tSDP_DISCOVERY_DB *p_disc_db;
UINT8 trace_level; /* tracing level */
UINT8 cnt_num; /* connected device number */
BOOLEAN w4_disable; /* w4 disable flag */
@ -340,8 +325,8 @@ extern void bta_hh_sm_execute(tBTA_HH_DEV_CB *p_cb, UINT16 event,
extern void bta_hh_api_disc_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
extern void bta_hh_open_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
extern void bta_hh_close_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
extern void bta_hh_data_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * p_data);
extern void bta_hh_ctrl_dat_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA * p_data);
extern void bta_hh_data_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
extern void bta_hh_ctrl_dat_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
extern void bta_hh_start_sdp(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
extern void bta_hh_sdp_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
extern void bta_hh_write_dev_act(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
@ -357,7 +342,7 @@ extern void bta_hh_parse_keybd_rpt(tBTA_HH_BOOT_RPT *p_kb_data,
UINT8 *p_report, UINT16 report_len);
extern void bta_hh_parse_mice_rpt(tBTA_HH_BOOT_RPT *p_kb_data,
UINT8 *p_report, UINT16 report_len);
extern BOOLEAN bta_hh_tod_spt(tBTA_HH_DEV_CB *p_cb,UINT8 sub_class);
extern BOOLEAN bta_hh_tod_spt(tBTA_HH_DEV_CB *p_cb, UINT8 sub_class);
extern void bta_hh_clean_up_kdev(tBTA_HH_DEV_CB *p_cb);
extern void bta_hh_add_device_to_list(tBTA_HH_DEV_CB *p_cb, UINT8 handle,

File diff suppressed because it is too large Load diff

View file

@ -37,8 +37,7 @@
*****************************************************************************/
/* state machine action enumeration list */
enum
{
enum {
BTA_HH_API_DISC_ACT, /* HID host process API close action */
BTA_HH_OPEN_ACT, /* HID host process BTA_HH_EVT_OPEN */
BTA_HH_CLOSE_ACT, /* HID host process BTA_HH_EVT_CLOSE */
@ -77,8 +76,7 @@ enum
typedef void (*tBTA_HH_ACTION)(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data);
/* action functions */
const tBTA_HH_ACTION bta_hh_action[] =
{
const tBTA_HH_ACTION bta_hh_action[] = {
bta_hh_api_disc_act,
bta_hh_open_act,
bta_hh_close_act,
@ -93,20 +91,20 @@ const tBTA_HH_ACTION bta_hh_action[] =
bta_hh_open_cmpl_act,
bta_hh_open_failure
#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
,bta_hh_gatt_close
,bta_hh_le_open_fail
,bta_hh_gatt_open
,bta_hh_w4_le_read_char_cmpl
,bta_hh_le_read_char_cmpl
,bta_hh_w4_le_read_descr_cmpl
,bta_hh_le_read_descr_cmpl
,bta_hh_w4_le_write_cmpl
,bta_hh_le_write_cmpl
,bta_hh_le_write_char_descr_cmpl
,bta_hh_start_security
,bta_hh_security_cmpl
,bta_hh_le_update_scpp
,bta_hh_le_notify_enc_cmpl
, bta_hh_gatt_close
, bta_hh_le_open_fail
, bta_hh_gatt_open
, bta_hh_w4_le_read_char_cmpl
, bta_hh_le_read_char_cmpl
, bta_hh_w4_le_read_descr_cmpl
, bta_hh_le_read_descr_cmpl
, bta_hh_w4_le_write_cmpl
, bta_hh_le_write_cmpl
, bta_hh_le_write_char_descr_cmpl
, bta_hh_start_security
, bta_hh_security_cmpl
, bta_hh_le_update_scpp
, bta_hh_le_notify_enc_cmpl
#endif
};
@ -116,121 +114,117 @@ const tBTA_HH_ACTION bta_hh_action[] =
#define BTA_HH_NUM_COLS 2 /* number of columns */
/* state table for idle state */
const UINT8 bta_hh_st_idle[][BTA_HH_NUM_COLS] =
{
/* Event Action Next state */
/* BTA_HH_API_OPEN_EVT */ {BTA_HH_START_SDP, BTA_HH_W4_CONN_ST },
/* BTA_HH_API_CLOSE_EVT */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST },
/* BTA_HH_INT_OPEN_EVT */ {BTA_HH_OPEN_ACT, BTA_HH_W4_CONN_ST },
/* BTA_HH_INT_CLOSE_EVT */ {BTA_HH_CLOSE_ACT, BTA_HH_IDLE_ST },
/* BTA_HH_INT_DATA_EVT */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST },
/* BTA_HH_INT_CTRL_DATA */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST },
/* BTA_HH_INT_HANDSK_EVT */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST },
/* BTA_HH_SDP_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST },
/* BTA_HH_API_WRITE_DEV_EVT */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST },
/* BTA_HH_API_GET_DSCP_EVT */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST },
/* BTA_HH_API_MAINT_DEV_EVT */ {BTA_HH_MAINT_DEV_ACT, BTA_HH_IDLE_ST },
/* BTA_HH_OPEN_CMPL_EVT */ {BTA_HH_OPEN_CMPL_ACT, BTA_HH_CONN_ST }
const UINT8 bta_hh_st_idle[][BTA_HH_NUM_COLS] = {
/* Event Action Next state */
/* BTA_HH_API_OPEN_EVT */ {BTA_HH_START_SDP, BTA_HH_W4_CONN_ST },
/* BTA_HH_API_CLOSE_EVT */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST },
/* BTA_HH_INT_OPEN_EVT */ {BTA_HH_OPEN_ACT, BTA_HH_W4_CONN_ST },
/* BTA_HH_INT_CLOSE_EVT */ {BTA_HH_CLOSE_ACT, BTA_HH_IDLE_ST },
/* BTA_HH_INT_DATA_EVT */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST },
/* BTA_HH_INT_CTRL_DATA */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST },
/* BTA_HH_INT_HANDSK_EVT */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST },
/* BTA_HH_SDP_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST },
/* BTA_HH_API_WRITE_DEV_EVT */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST },
/* BTA_HH_API_GET_DSCP_EVT */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST },
/* BTA_HH_API_MAINT_DEV_EVT */ {BTA_HH_MAINT_DEV_ACT, BTA_HH_IDLE_ST },
/* BTA_HH_OPEN_CMPL_EVT */ {BTA_HH_OPEN_CMPL_ACT, BTA_HH_CONN_ST }
#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
/* BTA_HH_GATT_CLOSE_EVT */ ,{BTA_HH_IGNORE, BTA_HH_IDLE_ST }
/* BTA_HH_GATT_OPEN_EVT */ ,{BTA_HH_GATT_OPEN, BTA_HH_W4_CONN_ST }
/* BTA_HH_START_ENC_EVT */ ,{BTA_HH_IGNORE, BTA_HH_IDLE_ST }
/* BTA_HH_ENC_CMPL_EVT */ ,{BTA_HH_IGNORE, BTA_HH_IDLE_ST }
/* READ_CHAR_CMPL_EVT */ ,{BTA_HH_IGNORE, BTA_HH_IDLE_ST }
/* BTA_HH_GATT_WRITE_CMPL_EVT*/ ,{BTA_HH_IGNORE, BTA_HH_IDLE_ST }
/* READ_DESCR_CMPL_EVT */ ,{BTA_HH_IGNORE, BTA_HH_IDLE_ST }
/* WRITE_DESCR_CMPL_EVT */ ,{BTA_HH_IGNORE, BTA_HH_IDLE_ST }
/* SCPP_UPDATE_EVT */ ,{BTA_HH_IGNORE, BTA_HH_IDLE_ST }
/* BTA_HH_GATT_ENC_CMPL_EVT */ ,{BTA_HH_IGNORE, BTA_HH_IDLE_ST }
/* BTA_HH_GATT_CLOSE_EVT */ , {BTA_HH_IGNORE, BTA_HH_IDLE_ST }
/* BTA_HH_GATT_OPEN_EVT */ , {BTA_HH_GATT_OPEN, BTA_HH_W4_CONN_ST }
/* BTA_HH_START_ENC_EVT */ , {BTA_HH_IGNORE, BTA_HH_IDLE_ST }
/* BTA_HH_ENC_CMPL_EVT */ , {BTA_HH_IGNORE, BTA_HH_IDLE_ST }
/* READ_CHAR_CMPL_EVT */ , {BTA_HH_IGNORE, BTA_HH_IDLE_ST }
/* BTA_HH_GATT_WRITE_CMPL_EVT*/ , {BTA_HH_IGNORE, BTA_HH_IDLE_ST }
/* READ_DESCR_CMPL_EVT */ , {BTA_HH_IGNORE, BTA_HH_IDLE_ST }
/* WRITE_DESCR_CMPL_EVT */ , {BTA_HH_IGNORE, BTA_HH_IDLE_ST }
/* SCPP_UPDATE_EVT */ , {BTA_HH_IGNORE, BTA_HH_IDLE_ST }
/* BTA_HH_GATT_ENC_CMPL_EVT */ , {BTA_HH_IGNORE, BTA_HH_IDLE_ST }
#endif
};
const UINT8 bta_hh_st_w4_conn[][BTA_HH_NUM_COLS] =
{
/* Event Action Next state */
/* BTA_HH_API_OPEN_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST },
/* BTA_HH_API_CLOSE_EVT */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST },
/* BTA_HH_INT_OPEN_EVT */ {BTA_HH_OPEN_ACT, BTA_HH_W4_CONN_ST },
/* BTA_HH_INT_CLOSE_EVT */ {BTA_HH_OPEN_FAILURE, BTA_HH_IDLE_ST },
/* BTA_HH_INT_DATA_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST },
/* BTA_HH_INT_CTRL_DATA */ {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST },
/* BTA_HH_INT_HANDSK_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST },
/* BTA_HH_SDP_CMPL_EVT */ {BTA_HH_SDP_CMPL, BTA_HH_W4_CONN_ST },
/* BTA_HH_API_WRITE_DEV_EVT */ {BTA_HH_WRITE_DEV_ACT, BTA_HH_W4_CONN_ST },
/* BTA_HH_API_GET_DSCP_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST },
/* BTA_HH_API_MAINT_DEV_EVT */ {BTA_HH_MAINT_DEV_ACT, BTA_HH_IDLE_ST },
/* BTA_HH_OPEN_CMPL_EVT */ {BTA_HH_OPEN_CMPL_ACT, BTA_HH_CONN_ST }
const UINT8 bta_hh_st_w4_conn[][BTA_HH_NUM_COLS] = {
/* Event Action Next state */
/* BTA_HH_API_OPEN_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST },
/* BTA_HH_API_CLOSE_EVT */ {BTA_HH_IGNORE, BTA_HH_IDLE_ST },
/* BTA_HH_INT_OPEN_EVT */ {BTA_HH_OPEN_ACT, BTA_HH_W4_CONN_ST },
/* BTA_HH_INT_CLOSE_EVT */ {BTA_HH_OPEN_FAILURE, BTA_HH_IDLE_ST },
/* BTA_HH_INT_DATA_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST },
/* BTA_HH_INT_CTRL_DATA */ {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST },
/* BTA_HH_INT_HANDSK_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST },
/* BTA_HH_SDP_CMPL_EVT */ {BTA_HH_SDP_CMPL, BTA_HH_W4_CONN_ST },
/* BTA_HH_API_WRITE_DEV_EVT */ {BTA_HH_WRITE_DEV_ACT, BTA_HH_W4_CONN_ST },
/* BTA_HH_API_GET_DSCP_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST },
/* BTA_HH_API_MAINT_DEV_EVT */ {BTA_HH_MAINT_DEV_ACT, BTA_HH_IDLE_ST },
/* BTA_HH_OPEN_CMPL_EVT */ {BTA_HH_OPEN_CMPL_ACT, BTA_HH_CONN_ST }
#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
/* BTA_HH_GATT_CLOSE_EVT */ ,{BTA_HH_LE_OPEN_FAIL, BTA_HH_IDLE_ST }
/* BTA_HH_GATT_OPEN_EVT */ ,{BTA_HH_GATT_OPEN, BTA_HH_W4_CONN_ST }
/* BTA_HH_START_ENC_EVT */ ,{BTA_HH_START_SEC, BTA_HH_W4_SEC }
/* BTA_HH_ENC_CMPL_EVT */ ,{BTA_HH_IGNORE, BTA_HH_W4_CONN_ST }
/* READ_CHAR_CMPL_EVT */ ,{BTA_HH_W4_LE_READ_CHAR, BTA_HH_W4_CONN_ST }
/* BTA_HH_GATT_WRITE_CMPL_EVT*/ ,{BTA_HH_W4_LE_WRITE, BTA_HH_W4_CONN_ST }
/* READ_DESCR_CMPL_EVT */ ,{BTA_HH_W4_LE_READ_DESCR, BTA_HH_W4_CONN_ST }
/* WRITE_DESCR_CMPL_EVT */ ,{BTA_HH_WRITE_DESCR, BTA_HH_W4_CONN_ST }
/* SCPP_UPDATE_EVT */ ,{BTA_HH_IGNORE, BTA_HH_W4_CONN_ST }
/* BTA_HH_GATT_ENC_CMPL_EVT */ ,{BTA_HH_IGNORE, BTA_HH_W4_CONN_ST }
/* BTA_HH_GATT_CLOSE_EVT */ , {BTA_HH_LE_OPEN_FAIL, BTA_HH_IDLE_ST }
/* BTA_HH_GATT_OPEN_EVT */ , {BTA_HH_GATT_OPEN, BTA_HH_W4_CONN_ST }
/* BTA_HH_START_ENC_EVT */ , {BTA_HH_START_SEC, BTA_HH_W4_SEC }
/* BTA_HH_ENC_CMPL_EVT */ , {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST }
/* READ_CHAR_CMPL_EVT */ , {BTA_HH_W4_LE_READ_CHAR, BTA_HH_W4_CONN_ST }
/* BTA_HH_GATT_WRITE_CMPL_EVT*/ , {BTA_HH_W4_LE_WRITE, BTA_HH_W4_CONN_ST }
/* READ_DESCR_CMPL_EVT */ , {BTA_HH_W4_LE_READ_DESCR, BTA_HH_W4_CONN_ST }
/* WRITE_DESCR_CMPL_EVT */ , {BTA_HH_WRITE_DESCR, BTA_HH_W4_CONN_ST }
/* SCPP_UPDATE_EVT */ , {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST }
/* BTA_HH_GATT_ENC_CMPL_EVT */ , {BTA_HH_IGNORE, BTA_HH_W4_CONN_ST }
#endif
};
const UINT8 bta_hh_st_connected[][BTA_HH_NUM_COLS] =
{
/* Event Action Next state */
/* BTA_HH_API_OPEN_EVT */ {BTA_HH_IGNORE, BTA_HH_CONN_ST },
/* BTA_HH_API_CLOSE_EVT */ {BTA_HH_API_DISC_ACT, BTA_HH_CONN_ST },
/* BTA_HH_INT_OPEN_EVT */ {BTA_HH_OPEN_ACT, BTA_HH_CONN_ST },
/* BTA_HH_INT_CLOSE_EVT */ {BTA_HH_CLOSE_ACT, BTA_HH_IDLE_ST },
/* BTA_HH_INT_DATA_EVT */ {BTA_HH_DATA_ACT, BTA_HH_CONN_ST },
/* BTA_HH_INT_CTRL_DATA */ {BTA_HH_CTRL_DAT_ACT, BTA_HH_CONN_ST },
/* BTA_HH_INT_HANDSK_EVT */ {BTA_HH_HANDSK_ACT, BTA_HH_CONN_ST },
/* BTA_HH_SDP_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_CONN_ST },
/* BTA_HH_API_WRITE_DEV_EVT */ {BTA_HH_WRITE_DEV_ACT, BTA_HH_CONN_ST },
/* BTA_HH_API_GET_DSCP_EVT */ {BTA_HH_GET_DSCP_ACT, BTA_HH_CONN_ST },
/* BTA_HH_API_MAINT_DEV_EVT */ {BTA_HH_MAINT_DEV_ACT, BTA_HH_CONN_ST },
/* BTA_HH_OPEN_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_CONN_ST }
const UINT8 bta_hh_st_connected[][BTA_HH_NUM_COLS] = {
/* Event Action Next state */
/* BTA_HH_API_OPEN_EVT */ {BTA_HH_IGNORE, BTA_HH_CONN_ST },
/* BTA_HH_API_CLOSE_EVT */ {BTA_HH_API_DISC_ACT, BTA_HH_CONN_ST },
/* BTA_HH_INT_OPEN_EVT */ {BTA_HH_OPEN_ACT, BTA_HH_CONN_ST },
/* BTA_HH_INT_CLOSE_EVT */ {BTA_HH_CLOSE_ACT, BTA_HH_IDLE_ST },
/* BTA_HH_INT_DATA_EVT */ {BTA_HH_DATA_ACT, BTA_HH_CONN_ST },
/* BTA_HH_INT_CTRL_DATA */ {BTA_HH_CTRL_DAT_ACT, BTA_HH_CONN_ST },
/* BTA_HH_INT_HANDSK_EVT */ {BTA_HH_HANDSK_ACT, BTA_HH_CONN_ST },
/* BTA_HH_SDP_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_CONN_ST },
/* BTA_HH_API_WRITE_DEV_EVT */ {BTA_HH_WRITE_DEV_ACT, BTA_HH_CONN_ST },
/* BTA_HH_API_GET_DSCP_EVT */ {BTA_HH_GET_DSCP_ACT, BTA_HH_CONN_ST },
/* BTA_HH_API_MAINT_DEV_EVT */ {BTA_HH_MAINT_DEV_ACT, BTA_HH_CONN_ST },
/* BTA_HH_OPEN_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_CONN_ST }
#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
/* BTA_HH_GATT_CLOSE_EVT */ ,{BTA_HH_GATT_CLOSE, BTA_HH_IDLE_ST }
/* BTA_HH_GATT_OPEN_EVT */ ,{BTA_HH_IGNORE, BTA_HH_CONN_ST }
/* BTA_HH_START_ENC_EVT */ ,{BTA_HH_IGNORE, BTA_HH_CONN_ST }
/* BTA_HH_ENC_CMPL_EVT */ ,{BTA_HH_IGNORE, BTA_HH_CONN_ST }
/* READ_CHAR_CMPL_EVT */ ,{BTA_HH_LE_READ_CHAR, BTA_HH_CONN_ST }
/* WRITE_CHAR_CMPL_EVT*/ ,{BTA_HH_LE_WRITE, BTA_HH_CONN_ST }
/* READ_DESCR_CMPL_EVT */ ,{BTA_HH_LE_READ_DESCR, BTA_HH_CONN_ST } /* do not currently read any descr when connection up */
/* WRITE_DESCR_CMPL_EVT */ ,{BTA_HH_WRITE_DESCR, BTA_HH_CONN_ST } /* do not currently write any descr when connection up */
/* SCPP_UPDATE_EVT */ ,{BTA_HH_LE_UPDATE_SCPP, BTA_HH_CONN_ST }
/* BTA_HH_GATT_ENC_CMPL_EVT */ ,{BTA_HH_IGNORE, BTA_HH_CONN_ST }
/* BTA_HH_GATT_CLOSE_EVT */ , {BTA_HH_GATT_CLOSE, BTA_HH_IDLE_ST }
/* BTA_HH_GATT_OPEN_EVT */ , {BTA_HH_IGNORE, BTA_HH_CONN_ST }
/* BTA_HH_START_ENC_EVT */ , {BTA_HH_IGNORE, BTA_HH_CONN_ST }
/* BTA_HH_ENC_CMPL_EVT */ , {BTA_HH_IGNORE, BTA_HH_CONN_ST }
/* READ_CHAR_CMPL_EVT */ , {BTA_HH_LE_READ_CHAR, BTA_HH_CONN_ST }
/* WRITE_CHAR_CMPL_EVT*/ , {BTA_HH_LE_WRITE, BTA_HH_CONN_ST }
/* READ_DESCR_CMPL_EVT */ , {BTA_HH_LE_READ_DESCR, BTA_HH_CONN_ST } /* do not currently read any descr when connection up */
/* WRITE_DESCR_CMPL_EVT */ , {BTA_HH_WRITE_DESCR, BTA_HH_CONN_ST } /* do not currently write any descr when connection up */
/* SCPP_UPDATE_EVT */ , {BTA_HH_LE_UPDATE_SCPP, BTA_HH_CONN_ST }
/* BTA_HH_GATT_ENC_CMPL_EVT */ , {BTA_HH_IGNORE, BTA_HH_CONN_ST }
#endif
};
#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
const UINT8 bta_hh_st_w4_sec[][BTA_HH_NUM_COLS] =
{
/* Event Action Next state */
/* BTA_HH_API_OPEN_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_API_CLOSE_EVT */ {BTA_HH_API_DISC_ACT, BTA_HH_W4_SEC },
/* BTA_HH_INT_OPEN_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_INT_CLOSE_EVT */ {BTA_HH_OPEN_FAILURE, BTA_HH_IDLE_ST },
/* BTA_HH_INT_DATA_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_INT_CTRL_DATA */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_INT_HANDSK_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_SDP_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_API_WRITE_DEV_EVT */ {BTA_HH_IGNORE , BTA_HH_W4_SEC },
/* BTA_HH_API_GET_DSCP_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_API_MAINT_DEV_EVT */ {BTA_HH_MAINT_DEV_ACT, BTA_HH_W4_SEC },
/* BTA_HH_OPEN_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_GATT_CLOSE_EVT */ {BTA_HH_LE_OPEN_FAIL, BTA_HH_IDLE_ST },
/* BTA_HH_GATT_OPEN_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_START_ENC_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_ENC_CMPL_EVT */ {BTA_HH_SEC_CMPL, BTA_HH_W4_CONN_ST },
/* READ_CHAR_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_GATT_WRITE_CMPL_EVT*/ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* READ_DESCR_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* WRITE_DESCR_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC }
/* SCPP_UPDATE_EVT */ ,{BTA_HH_IGNORE, BTA_HH_W4_SEC }
/* BTA_HH_GATT_ENC_CMPL_EVT */ ,{BTA_HH_GATT_ENC_CMPL, BTA_HH_W4_SEC }
const UINT8 bta_hh_st_w4_sec[][BTA_HH_NUM_COLS] = {
/* Event Action Next state */
/* BTA_HH_API_OPEN_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_API_CLOSE_EVT */ {BTA_HH_API_DISC_ACT, BTA_HH_W4_SEC },
/* BTA_HH_INT_OPEN_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_INT_CLOSE_EVT */ {BTA_HH_OPEN_FAILURE, BTA_HH_IDLE_ST },
/* BTA_HH_INT_DATA_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_INT_CTRL_DATA */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_INT_HANDSK_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_SDP_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_API_WRITE_DEV_EVT */ {BTA_HH_IGNORE , BTA_HH_W4_SEC },
/* BTA_HH_API_GET_DSCP_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_API_MAINT_DEV_EVT */ {BTA_HH_MAINT_DEV_ACT, BTA_HH_W4_SEC },
/* BTA_HH_OPEN_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_GATT_CLOSE_EVT */ {BTA_HH_LE_OPEN_FAIL, BTA_HH_IDLE_ST },
/* BTA_HH_GATT_OPEN_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_START_ENC_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_ENC_CMPL_EVT */ {BTA_HH_SEC_CMPL, BTA_HH_W4_CONN_ST },
/* READ_CHAR_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* BTA_HH_GATT_WRITE_CMPL_EVT*/ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* READ_DESCR_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC },
/* WRITE_DESCR_CMPL_EVT */ {BTA_HH_IGNORE, BTA_HH_W4_SEC }
/* SCPP_UPDATE_EVT */ , {BTA_HH_IGNORE, BTA_HH_W4_SEC }
/* BTA_HH_GATT_ENC_CMPL_EVT */ , {BTA_HH_GATT_ENC_CMPL, BTA_HH_W4_SEC }
};
#endif
@ -238,13 +232,12 @@ const UINT8 bta_hh_st_w4_sec[][BTA_HH_NUM_COLS] =
typedef const UINT8 (*tBTA_HH_ST_TBL)[BTA_HH_NUM_COLS];
/* state table */
const tBTA_HH_ST_TBL bta_hh_st_tbl[] =
{
const tBTA_HH_ST_TBL bta_hh_st_tbl[] = {
bta_hh_st_idle,
bta_hh_st_w4_conn,
bta_hh_st_connected
#if (defined BTA_HH_LE_INCLUDED && BTA_HH_LE_INCLUDED == TRUE)
,bta_hh_st_w4_sec
, bta_hh_st_w4_sec
#endif
};
@ -272,7 +265,7 @@ static char *bta_hh_state_code(tBTA_HH_STATE state_code);
** Returns void
**
*******************************************************************************/
void bta_hh_sm_execute(tBTA_HH_DEV_CB *p_cb, UINT16 event, tBTA_HH_DATA * p_data)
void bta_hh_sm_execute(tBTA_HH_DEV_CB *p_cb, UINT16 event, tBTA_HH_DATA *p_data)
{
tBTA_HH_ST_TBL state_table;
UINT8 action;
@ -286,13 +279,10 @@ void bta_hh_sm_execute(tBTA_HH_DEV_CB *p_cb, UINT16 event, tBTA_HH_DATA * p_data
memset(&cback_data, 0, sizeof(tBTA_HH));
/* handle exception, no valid control block was found */
if (!p_cb)
{
if (!p_cb) {
/* BTA HH enabled already? otherwise ignore the event although it's bad*/
if (bta_hh_cb.p_cback != NULL)
{
switch (event)
{
if (bta_hh_cb.p_cback != NULL) {
switch (event) {
/* no control block available for new connection */
case BTA_HH_API_OPEN_EVT:
cback_event = BTA_HH_OPEN_EVT;
@ -305,14 +295,11 @@ void bta_hh_sm_execute(tBTA_HH_DEV_CB *p_cb, UINT16 event, tBTA_HH_DATA * p_data
case BTA_HH_API_MAINT_DEV_EVT:
cback_event = p_data->api_maintdev.sub_event;
if (p_data->api_maintdev.sub_event == BTA_HH_ADD_DEV_EVT)
{
if (p_data->api_maintdev.sub_event == BTA_HH_ADD_DEV_EVT) {
bdcpy(cback_data.dev_info.bda, p_data->api_maintdev.bda);
cback_data.dev_info.status = BTA_HH_ERR_DB_FULL;
cback_data.dev_info.handle = BTA_HH_INVALID_HANDLE;
}
else
{
} else {
cback_data.dev_info.status = BTA_HH_ERR_HDL;
cback_data.dev_info.handle = (UINT8)p_data->api_maintdev.hdr.layer_specific;
}
@ -320,32 +307,26 @@ void bta_hh_sm_execute(tBTA_HH_DEV_CB *p_cb, UINT16 event, tBTA_HH_DATA * p_data
case BTA_HH_API_WRITE_DEV_EVT:
cback_event = (p_data->api_sndcmd.t_type - BTA_HH_FST_BTE_TRANS_EVT) +
BTA_HH_FST_TRANS_CB_EVT;
if (p_data->api_sndcmd.p_data != NULL)
{
if (p_data->api_sndcmd.p_data != NULL) {
GKI_freebuf(p_data->api_sndcmd.p_data);
}
if (p_data->api_sndcmd.t_type == HID_TRANS_SET_PROTOCOL ||
p_data->api_sndcmd.t_type == HID_TRANS_SET_REPORT ||
p_data->api_sndcmd.t_type == HID_TRANS_SET_IDLE)
{
p_data->api_sndcmd.t_type == HID_TRANS_SET_IDLE) {
cback_data.dev_status.status = BTA_HH_ERR_HDL;
cback_data.dev_status.handle = (UINT8)p_data->api_sndcmd.hdr.layer_specific;
}
else if (p_data->api_sndcmd.t_type != HID_TRANS_DATA &&
p_data->api_sndcmd.t_type != HID_TRANS_CONTROL)
{
} else if (p_data->api_sndcmd.t_type != HID_TRANS_DATA &&
p_data->api_sndcmd.t_type != HID_TRANS_CONTROL) {
cback_data.hs_data.handle = (UINT8)p_data->api_sndcmd.hdr.layer_specific;
cback_data.hs_data.status = BTA_HH_ERR_HDL;
/* hs_data.rsp_data will be all zero, which is not valid value */
}
else if (p_data->api_sndcmd.t_type == HID_TRANS_CONTROL &&
p_data->api_sndcmd.param == BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG)
{
} else if (p_data->api_sndcmd.t_type == HID_TRANS_CONTROL &&
p_data->api_sndcmd.param == BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG) {
cback_data.status = BTA_HH_ERR_HDL;
cback_event = BTA_HH_VC_UNPLUG_EVT;
}
else
} else {
cback_event = 0;
}
break;
case BTA_HH_API_CLOSE_EVT:
@ -359,20 +340,19 @@ void bta_hh_sm_execute(tBTA_HH_DEV_CB *p_cb, UINT16 event, tBTA_HH_DATA * p_data
/* invalid handle, call bad API event */
APPL_TRACE_ERROR("wrong device handle: [%d]", p_data->hdr.layer_specific);
/* Free the callback buffer now */
if (p_data != NULL && p_data->hid_cback.p_data != NULL)
{
if (p_data != NULL && p_data->hid_cback.p_data != NULL) {
GKI_freebuf(p_data->hid_cback.p_data);
p_data->hid_cback.p_data = NULL;
}
break;
}
if (cback_event)
if (cback_event) {
(* bta_hh_cb.p_cback)(cback_event, &cback_data);
}
}
}
/* corresponding CB is found, go to state machine */
else
{
else {
#if BTA_HH_DEBUG == TRUE
in_state = p_cb->state;
APPL_TRACE_EVENT("bta_hh_sm_execute: State 0x%02x [%s], Event [%s]",
@ -380,10 +360,9 @@ void bta_hh_sm_execute(tBTA_HH_DEV_CB *p_cb, UINT16 event, tBTA_HH_DATA * p_data
bta_hh_evt_code(debug_event));
#endif
if ((p_cb->state == BTA_HH_NULL_ST) || (p_cb->state >= BTA_HH_INVALID_ST))
{
if ((p_cb->state == BTA_HH_NULL_ST) || (p_cb->state >= BTA_HH_INVALID_ST)) {
APPL_TRACE_ERROR("bta_hh_sm_execute: Invalid state State = 0x%x, Event = %d",
p_cb->state,event);
p_cb->state, event);
return;
}
state_table = bta_hh_st_tbl[p_cb->state - 1];
@ -392,14 +371,12 @@ void bta_hh_sm_execute(tBTA_HH_DEV_CB *p_cb, UINT16 event, tBTA_HH_DATA * p_data
p_cb->state = state_table[event][BTA_HH_NEXT_STATE] ;
if ((action = state_table[event][BTA_HH_ACTION]) != BTA_HH_IGNORE)
{
if ((action = state_table[event][BTA_HH_ACTION]) != BTA_HH_IGNORE) {
(*bta_hh_action[action])(p_cb, p_data);
}
#if BTA_HH_DEBUG == TRUE
if (in_state != p_cb->state)
{
if (in_state != p_cb->state) {
APPL_TRACE_DEBUG("HH State Change: [%s] -> [%s] after Event [%s]",
bta_hh_state_code(in_state),
bta_hh_state_code(p_cb->state),
@ -425,8 +402,7 @@ BOOLEAN bta_hh_hdl_event(BT_HDR *p_msg)
UINT8 index = BTA_HH_IDX_INVALID;
tBTA_HH_DEV_CB *p_cb = NULL;
switch (p_msg->event)
{
switch (p_msg->event) {
case BTA_HH_API_ENABLE_EVT:
bta_hh_api_enable((tBTA_HH_DATA *) p_msg);
break;
@ -442,19 +418,13 @@ BOOLEAN bta_hh_hdl_event(BT_HDR *p_msg)
default:
/* all events processed in state machine need to find corresponding
CB before proceed */
if (p_msg->event == BTA_HH_API_OPEN_EVT)
{
if (p_msg->event == BTA_HH_API_OPEN_EVT) {
index = bta_hh_find_cb(((tBTA_HH_API_CONN *)p_msg)->bd_addr);
}
else if (p_msg->event == BTA_HH_API_MAINT_DEV_EVT)
{
} else if (p_msg->event == BTA_HH_API_MAINT_DEV_EVT) {
/* if add device */
if (((tBTA_HH_MAINT_DEV *)p_msg)->sub_event == BTA_HH_ADD_DEV_EVT)
{
if (((tBTA_HH_MAINT_DEV *)p_msg)->sub_event == BTA_HH_ADD_DEV_EVT) {
index = bta_hh_find_cb(((tBTA_HH_MAINT_DEV *)p_msg)->bda);
}
else /* else remove device by handle */
{
} else { /* else remove device by handle */
index = bta_hh_dev_handle_to_cb_idx((UINT8)p_msg->layer_specific);
// btla-specific ++
/* If BT disable is done while the HID device is connected and Link_Key uses unauthenticated combination
@ -469,16 +439,15 @@ BOOLEAN bta_hh_hdl_event(BT_HDR *p_msg)
}
// btla-specific --
}
}
else if (p_msg->event == BTA_HH_INT_OPEN_EVT)
{
} else if (p_msg->event == BTA_HH_INT_OPEN_EVT) {
index = bta_hh_find_cb(((tBTA_HH_CBACK_DATA *)p_msg)->addr);
}
else
} else {
index = bta_hh_dev_handle_to_cb_idx((UINT8)p_msg->layer_specific);
}
if (index != BTA_HH_IDX_INVALID)
if (index != BTA_HH_IDX_INVALID) {
p_cb = &bta_hh_cb.kdev[index];
}
#if BTA_HH_DEBUG
APPL_TRACE_DEBUG("bta_hh_hdl_event:: handle = %d dev_cb[%d] ", p_msg->layer_specific, index);
@ -503,8 +472,7 @@ BOOLEAN bta_hh_hdl_event(BT_HDR *p_msg)
*******************************************************************************/
static char *bta_hh_evt_code(tBTA_HH_INT_EVT evt_code)
{
switch(evt_code)
{
switch (evt_code) {
case BTA_HH_API_DISABLE_EVT:
return "BTA_HH_API_DISABLE_EVT";
case BTA_HH_API_ENABLE_EVT:
@ -569,8 +537,7 @@ static char *bta_hh_evt_code(tBTA_HH_INT_EVT evt_code)
*******************************************************************************/
static char *bta_hh_state_code(tBTA_HH_STATE state_code)
{
switch (state_code)
{
switch (state_code) {
case BTA_HH_NULL_ST:
return"BTA_HH_NULL_ST";
case BTA_HH_IDLE_ST:

View file

@ -41,8 +41,7 @@
#define BTA_HH_MAX_RPT_CHARS 8
static const UINT8 bta_hh_mod_key_mask[BTA_HH_MOD_MAX_KEY] =
{
static const UINT8 bta_hh_mod_key_mask[BTA_HH_MOD_MAX_KEY] = {
BTA_HH_KB_CTRL_MASK,
BTA_HH_KB_SHIFT_MASK,
BTA_HH_KB_ALT_MASK,
@ -65,12 +64,10 @@ UINT8 bta_hh_find_cb(BD_ADDR bda)
UINT8 xx;
/* See how many active devices there are. */
for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx++)
{
for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx++) {
/* check if any active/known devices is a match */
if ((!bdcmp (bda, bta_hh_cb.kdev[xx].addr) &&
bdcmp(bda, bd_addr_null) != 0) )
{
bdcmp(bda, bd_addr_null) != 0) ) {
#if BTA_HH_DEBUG
APPL_TRACE_DEBUG("found kdev_cb[%d] hid_handle = %d ", xx,
bta_hh_cb.kdev[xx].hid_handle)
@ -87,10 +84,8 @@ UINT8 bta_hh_find_cb(BD_ADDR bda)
}
/* if no active device match, find a spot for it */
for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx++)
{
if (!bta_hh_cb.kdev[xx].in_use)
{
for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx++) {
if (!bta_hh_cb.kdev[xx].in_use) {
bdcpy(bta_hh_cb.kdev[xx].addr, bda);
break;
}
@ -101,8 +96,9 @@ UINT8 bta_hh_find_cb(BD_ADDR bda)
xx, BTA_HH_MAX_DEVICE);
#endif
if (xx == BTA_HH_MAX_DEVICE)
if (xx == BTA_HH_MAX_DEVICE) {
xx = BTA_HH_IDX_INVALID;
}
return xx;
}
@ -121,12 +117,11 @@ void bta_hh_clean_up_kdev(tBTA_HH_DEV_CB *p_cb)
{
UINT8 index;
if (p_cb->hid_handle != BTA_HH_INVALID_HANDLE )
{
if (p_cb->hid_handle != BTA_HH_INVALID_HANDLE ) {
#if BTA_HH_LE_INCLUDED == TRUE
if (p_cb->is_le_device)
if (p_cb->is_le_device) {
bta_hh_cb.le_cb_index[BTA_HH_GET_LE_CB_IDX(p_cb->hid_handle)] = BTA_HH_IDX_INVALID;
else
} else
#endif
bta_hh_cb.cb_index[p_cb->hid_handle] = BTA_HH_IDX_INVALID;
}
@ -201,14 +196,12 @@ void bta_hh_add_device_to_list(tBTA_HH_DEV_CB *p_cb, UINT8 handle,
p_cb->dscp_info.ssr_min_tout = ssr_min_tout;
/* store report descriptor info */
if ( p_dscp_info)
{
if ( p_dscp_info) {
utl_freebuf((void **)&p_cb->dscp_info.descriptor.dsc_list);
if (p_dscp_info->dl_len &&
(p_cb->dscp_info.descriptor.dsc_list =
(UINT8 *)GKI_getbuf(p_dscp_info->dl_len)) != NULL)
{
(UINT8 *)GKI_getbuf(p_dscp_info->dl_len)) != NULL) {
p_cb->dscp_info.descriptor.dl_len = p_dscp_info->dl_len;
memcpy(p_cb->dscp_info.descriptor.dsc_list, p_dscp_info->dsc_list,
p_dscp_info->dl_len);
@ -226,15 +219,13 @@ void bta_hh_add_device_to_list(tBTA_HH_DEV_CB *p_cb, UINT8 handle,
** Returns
**
*******************************************************************************/
BOOLEAN bta_hh_tod_spt(tBTA_HH_DEV_CB *p_cb,UINT8 sub_class)
BOOLEAN bta_hh_tod_spt(tBTA_HH_DEV_CB *p_cb, UINT8 sub_class)
{
UINT8 xx;
UINT8 cod = (sub_class >> 2); /* lower two bits are reserved */
for (xx = 0 ; xx < p_bta_hh_cfg->max_devt_spt; xx ++)
{
if (cod == (UINT8) p_bta_hh_cfg->p_devt_list[xx].tod)
{
for (xx = 0 ; xx < p_bta_hh_cfg->max_devt_spt; xx ++) {
if (cod == (UINT8) p_bta_hh_cfg->p_devt_list[xx].tod) {
p_cb->app_id = p_bta_hh_cfg->p_devt_list[xx].app_id;
#if BTA_HH_DEBUG
APPL_TRACE_EVENT("bta_hh_tod_spt sub_class:0x%x supported", sub_class);
@ -273,29 +264,27 @@ void bta_hh_parse_keybd_rpt(tBTA_HH_BOOT_RPT *p_kb_data, UINT8 *p_report,
p_report, report_len);
#endif
if (report_len < 2)
if (report_len < 2) {
return;
}
ctl_shift = *p_report++;
report_len--;
if (report_len > BTA_HH_MAX_RPT_CHARS)
if (report_len > BTA_HH_MAX_RPT_CHARS) {
report_len = BTA_HH_MAX_RPT_CHARS;
}
memset (this_report, 0, BTA_HH_MAX_RPT_CHARS);
memset (p_data, 0, sizeof(tBTA_HH_KEYBD_RPT));
memcpy (this_report, p_report, report_len);
/* Take care of shift, control, GUI and alt, modifier keys */
for (xx = 0; xx < BTA_HH_MOD_MAX_KEY; xx ++ )
{
if (ctl_shift & bta_hh_mod_key_mask[xx])
{
for (xx = 0; xx < BTA_HH_MOD_MAX_KEY; xx ++ ) {
if (ctl_shift & bta_hh_mod_key_mask[xx]) {
APPL_TRACE_DEBUG("Mod Key[%02x] pressed", bta_hh_mod_key_mask[xx] );
p_kb->mod_key[xx] = TRUE;
}
else if (p_kb->mod_key[xx])
{
} else if (p_kb->mod_key[xx]) {
p_kb->mod_key[xx] = FALSE;
}
/* control key flag is set */
@ -305,12 +294,9 @@ void bta_hh_parse_keybd_rpt(tBTA_HH_BOOT_RPT *p_kb_data, UINT8 *p_report,
/***************************************************************************/
/* First step is to remove all characters we saw in the last report */
/***************************************************************************/
for (xx = 0; xx < report_len; xx++)
{
for (yy = 0; yy < BTA_HH_MAX_RPT_CHARS; yy++)
{
if (this_report[xx] == p_kb->last_report[yy])
{
for (xx = 0; xx < report_len; xx++) {
for (yy = 0; yy < BTA_HH_MAX_RPT_CHARS; yy++) {
if (this_report[xx] == p_kb->last_report[yy]) {
this_report[xx] = 0;
}
}
@ -318,20 +304,21 @@ void bta_hh_parse_keybd_rpt(tBTA_HH_BOOT_RPT *p_kb_data, UINT8 *p_report,
/***************************************************************************/
/* Now, process all the characters in the report, up to 6 keycodes */
/***************************************************************************/
for (xx = 0; xx < report_len; xx++)
{
for (xx = 0; xx < report_len; xx++) {
#if BTA_HH_DEBUG
APPL_TRACE_DEBUG("this_char = %02x", this_report[xx]);
#endif
if ((this_char = this_report[xx]) == 0)
if ((this_char = this_report[xx]) == 0) {
continue;
}
/* take the key code as the report data */
if (this_report[xx] == BTA_HH_KB_CAPS_LOCK)
if (this_report[xx] == BTA_HH_KB_CAPS_LOCK) {
p_kb->caps_lock = p_kb->caps_lock ? FALSE : TRUE;
else if (this_report[xx] == BTA_HH_KB_NUM_LOCK)
} else if (this_report[xx] == BTA_HH_KB_NUM_LOCK) {
p_kb->num_lock = p_kb->num_lock ? FALSE : TRUE;
else
} else {
p_data->this_char[key_idx ++] = this_char;
}
#if BTA_HH_DEBUG
APPL_TRACE_DEBUG("found keycode %02x ", this_report[xx]);
@ -366,15 +353,16 @@ void bta_hh_parse_mice_rpt(tBTA_HH_BOOT_RPT *p_mice_data, UINT8 *p_report,
report_len=%d) called", p_report, report_len);
#endif
if (report_len < 3)
if (report_len < 3) {
return;
}
if (report_len > BTA_HH_MAX_RPT_CHARS)
if (report_len > BTA_HH_MAX_RPT_CHARS) {
report_len = BTA_HH_MAX_RPT_CHARS;
}
#if BTA_HH_DEBUG
for (xx = 0; xx < report_len; xx++)
{
for (xx = 0; xx < report_len; xx++) {
APPL_TRACE_DEBUG("this_char = %02x", p_report[xx]);
}
#endif
@ -413,15 +401,12 @@ tBTA_HH_STATUS bta_hh_read_ssr_param(BD_ADDR bd_addr, UINT16 *p_max_ssr_lat, UIN
tBTA_HH_CB *p_cb = &bta_hh_cb;
UINT8 i;
UINT16 ssr_max_latency;
for (i = 0; i < BTA_HH_MAX_KNOWN; i ++)
{
if (memcmp(p_cb->kdev[i].addr, bd_addr, BD_ADDR_LEN) == 0)
{
for (i = 0; i < BTA_HH_MAX_KNOWN; i ++) {
if (memcmp(p_cb->kdev[i].addr, bd_addr, BD_ADDR_LEN) == 0) {
/* if remote device does not have HIDSSRHostMaxLatency attribute in SDP,
set SSR max latency default value here. */
if (p_cb->kdev[i].dscp_info.ssr_max_latency == HID_SSR_PARAM_INVALID)
{
if (p_cb->kdev[i].dscp_info.ssr_max_latency == HID_SSR_PARAM_INVALID) {
/* The default is calculated as half of link supervision timeout.*/
BTM_GetLinkSuperTout(p_cb->kdev[i].addr, &ssr_max_latency) ;
@ -429,18 +414,20 @@ tBTA_HH_STATUS bta_hh_read_ssr_param(BD_ADDR bd_addr, UINT16 *p_max_ssr_lat, UIN
/* per 1.1 spec, if the newly calculated max latency is greater than
BTA_HH_SSR_MAX_LATENCY_DEF which is 500ms, use BTA_HH_SSR_MAX_LATENCY_DEF */
if (ssr_max_latency > BTA_HH_SSR_MAX_LATENCY_DEF)
if (ssr_max_latency > BTA_HH_SSR_MAX_LATENCY_DEF) {
ssr_max_latency = BTA_HH_SSR_MAX_LATENCY_DEF;
}
* p_max_ssr_lat = ssr_max_latency;
}
else
} else {
* p_max_ssr_lat = p_cb->kdev[i].dscp_info.ssr_max_latency;
}
if (p_cb->kdev[i].dscp_info.ssr_min_tout == HID_SSR_PARAM_INVALID)
if (p_cb->kdev[i].dscp_info.ssr_min_tout == HID_SSR_PARAM_INVALID) {
* p_min_ssr_tout = BTA_HH_SSR_MIN_TOUT_DEF;
else
} else {
* p_min_ssr_tout = p_cb->kdev[i].dscp_info.ssr_min_tout;
}
status = BTA_HH_OK;
@ -465,8 +452,7 @@ void bta_hh_cleanup_disable(tBTA_HH_STATUS status)
{
UINT8 xx;
/* free buffer in CB holding report descriptors */
for(xx = 0; xx < BTA_HH_MAX_DEVICE; xx ++)
{
for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx ++) {
utl_freebuf((void **)&bta_hh_cb.kdev[xx].dscp_info.descriptor.dsc_list);
}
utl_freebuf((void **)&bta_hh_cb.p_disc_db);
@ -491,19 +477,19 @@ UINT8 bta_hh_dev_handle_to_cb_idx(UINT8 dev_handle)
UINT8 index = BTA_HH_IDX_INVALID;
#if BTA_HH_LE_INCLUDED == TRUE
if (BTA_HH_IS_LE_DEV_HDL(dev_handle))
{
if (BTA_HH_IS_LE_DEV_HDL_VALID(dev_handle))
if (BTA_HH_IS_LE_DEV_HDL(dev_handle)) {
if (BTA_HH_IS_LE_DEV_HDL_VALID(dev_handle)) {
index = bta_hh_cb.le_cb_index[BTA_HH_GET_LE_CB_IDX(dev_handle)];
}
#if BTA_HH_DEBUG == TRUE
APPL_TRACE_DEBUG("bta_hh_dev_handle_to_cb_idx dev_handle = %d index = %d", dev_handle, index);
#endif
}
else
} else
#endif
/* regular HID device checking */
if (dev_handle < BTA_HH_MAX_KNOWN )
if (dev_handle < BTA_HH_MAX_KNOWN ) {
index = bta_hh_cb.cb_index[dev_handle];
}
return index;
@ -524,9 +510,8 @@ void bta_hh_trace_dev_db(void)
APPL_TRACE_DEBUG("bta_hh_trace_dev_db:: Device DB list********************");
for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx++)
{
APPL_TRACE_DEBUG("kdev[%d] in_use[%d] handle[%d] ",xx,
for (xx = 0; xx < BTA_HH_MAX_DEVICE; xx++) {
APPL_TRACE_DEBUG("kdev[%d] in_use[%d] handle[%d] ", xx,
bta_hh_cb.kdev[xx].in_use, bta_hh_cb.kdev[xx].hid_handle);
APPL_TRACE_DEBUG("\t\t\t attr_mask[%04x] state [%d] sub_class[%02x] index = %d",

217
components/bt/bluedroid/bta/include/bta_api.h Executable file → Normal file
View file

@ -157,12 +157,11 @@ typedef UINT8 tBTA_SERVICE_ID;
typedef UINT32 tBTA_SERVICE_MASK;
/* extended service mask, including mask with one or more GATT UUID */
typedef struct
{
typedef struct {
tBTA_SERVICE_MASK srvc_mask;
UINT8 num_uuid;
tBT_UUID *p_uuid;
}tBTA_SERVICE_MASK_EXT;
} tBTA_SERVICE_MASK_EXT;
/* Security Setting Mask */
#define BTA_SEC_NONE BTM_SEC_NONE /* No security. */
@ -253,8 +252,7 @@ typedef UINT8 tBTA_AUTH_RESP;
typedef UINT8 tBTA_PREF_ROLES;
enum
{
enum {
BTA_DM_NO_SCATTERNET, /* Device doesn't support scatternet, it might
support "role switch during connection" for
@ -270,23 +268,20 @@ enum
/* Inquiry filter device class condition */
typedef struct
{
typedef struct {
DEV_CLASS dev_class; /* device class of interest */
DEV_CLASS dev_class_mask; /* mask to determine the bits of device class of interest */
} tBTA_DM_COD_COND;
/* Inquiry Filter Condition */
typedef union
{
typedef union {
BD_ADDR bd_addr; /* BD address of device to filter. */
tBTA_DM_COD_COND dev_class_cond; /* Device class filter condition */
} tBTA_DM_INQ_COND;
/* Inquiry Parameters */
typedef struct
{
typedef struct {
tBTA_DM_INQ_MODE mode; /* Inquiry mode, limited or general. */
UINT8 duration; /* Inquiry duration in 1.28 sec units. */
UINT8 max_resps; /* Maximum inquiry responses. Set to zero for unlimited responses. */
@ -298,8 +293,7 @@ typedef struct
#endif
} tBTA_DM_INQ;
typedef struct
{
typedef struct {
UINT8 bta_dm_eir_min_name_len; /* minimum length of local name when it is shortened */
#if (BTA_EIR_CANNED_UUID_LIST == TRUE)
UINT8 bta_dm_eir_uuid16_len; /* length of 16-bit UUIDs */
@ -347,54 +341,47 @@ typedef struct
typedef tBTM_BLE_AD_MASK tBTA_BLE_AD_MASK;
/* slave preferred connection interval range */
typedef struct
{
typedef struct {
UINT16 low;
UINT16 hi;
}tBTA_BLE_INT_RANGE;
} tBTA_BLE_INT_RANGE;
/* Service tag supported in the device */
typedef struct
{
typedef struct {
UINT8 num_service;
BOOLEAN list_cmpl;
UINT16 *p_uuid;
}tBTA_BLE_SERVICE;
} tBTA_BLE_SERVICE;
typedef struct
{
typedef struct {
UINT8 len;
UINT8 *p_val;
}tBTA_BLE_MANU;
} tBTA_BLE_MANU;
typedef struct
{
typedef struct {
UINT8 adv_type;
UINT8 len;
UINT8 *p_val; /* number of len byte */
}tBTA_BLE_PROP_ELEM;
} tBTA_BLE_PROP_ELEM;
/* vendor proprietary adv type */
typedef struct
{
typedef struct {
UINT8 num_elem;
tBTA_BLE_PROP_ELEM *p_elem;
}tBTA_BLE_PROPRIETARY;
} tBTA_BLE_PROPRIETARY;
typedef struct
{
typedef struct {
tBT_UUID service_uuid;
UINT8 len;
UINT8 *p_val;
}tBTA_BLE_SERVICE_DATA;
} tBTA_BLE_SERVICE_DATA;
typedef tBTM_BLE_128SERVICE tBTA_BLE_128SERVICE;
typedef tBTM_BLE_32SERVICE tBTA_BLE_32SERVICE;
typedef struct
{
typedef struct {
tBTA_BLE_INT_RANGE int_range; /* slave prefered conn interval range */
tBTA_BLE_MANU *p_manu; /* manufacturer data */
tBTA_BLE_SERVICE *p_services; /* 16 bits services */
@ -408,7 +395,7 @@ typedef struct
UINT16 appearance; /* appearance data */
UINT8 flag;
UINT8 tx_power;
}tBTA_BLE_ADV_DATA;
} tBTA_BLE_ADV_DATA;
typedef void (tBTA_SET_ADV_DATA_CMPL_CBACK) (tBTA_STATUS status);
@ -437,21 +424,19 @@ typedef UINT8 tBTA_BLE_ADV_EVT;
typedef UINT8 tBTA_BLE_ADV_TX_POWER;
/* advertising instance parameters */
typedef struct
{
typedef struct {
UINT16 adv_int_min; /* minimum adv interval */
UINT16 adv_int_max; /* maximum adv interval */
tBTA_BLE_ADV_EVT adv_type; /* adv event type */
tBTA_BLE_ADV_CHNL_MAP channel_map; /* adv channel map */
tBTA_BLE_AFP adv_filter_policy; /* advertising filter policy */
tBTA_BLE_ADV_TX_POWER tx_power; /* adv tx power */
}tBTA_BLE_ADV_PARAMS;
} tBTA_BLE_ADV_PARAMS;
/* These are the fields returned in each device adv packet. It
** is returned in the results callback if registered.
*/
typedef struct
{
typedef struct {
UINT8 conn_mode;
tBTA_BLE_AD_MASK ad_mask; /* mask of the valid adv data field */
UINT8 flag;
@ -461,30 +446,26 @@ typedef struct
tBTA_BLE_SERVICE service;
} tBTA_BLE_INQ_DATA;
enum
{
enum {
BTA_BLE_BATCH_SCAN_MODE_PASS = 1,
BTA_BLE_BATCH_SCAN_MODE_ACTI = 2,
BTA_BLE_BATCH_SCAN_MODE_PASS_ACTI = 3
};
typedef UINT8 tBTA_BLE_BATCH_SCAN_MODE;
enum
{
BTA_BLE_DISCARD_OLD_ITEMS=0,
BTA_BLE_DISCARD_LOWER_RSSI_ITEMS=1
enum {
BTA_BLE_DISCARD_OLD_ITEMS = 0,
BTA_BLE_DISCARD_LOWER_RSSI_ITEMS = 1
};
typedef UINT8 tBTA_BLE_DISCARD_RULE;
enum
{
BTA_BLE_ADV_SEEN_FIRST_TIME=0,
BTA_BLE_ADV_TRACKING_TIMEOUT=1
enum {
BTA_BLE_ADV_SEEN_FIRST_TIME = 0,
BTA_BLE_ADV_TRACKING_TIMEOUT = 1
};
typedef UINT8 tBTA_BLE_ADV_CHANGE_REASON;
enum
{
enum {
BTA_BLE_BATCH_SCAN_ENB_EVT = 1,
BTA_BLE_BATCH_SCAN_CFG_STRG_EVT = 2,
BTA_BLE_BATCH_SCAN_DATA_EVT = 3,
@ -523,8 +504,7 @@ typedef void (tBTA_DM_BLE_RSSI_CBACK) (BD_ADDR bd_addr, tBTA_DM_BLE_RSSI_ALERT_T
#define BTA_DM_BLE_PF_LOGIC_AND 1
typedef UINT8 tBTA_DM_BLE_PF_LOGIC_TYPE;
enum
{
enum {
BTA_DM_BLE_SCAN_COND_ADD,
BTA_DM_BLE_SCAN_COND_DELETE,
BTA_DM_BLE_SCAN_COND_CLEAR = 2
@ -532,8 +512,7 @@ enum
typedef UINT8 tBTA_DM_BLE_SCAN_COND_OP;
/* ADV payload filtering vendor specific call event */
enum
{
enum {
BTA_BLE_SCAN_PF_ENABLE_EVT = 7,
BTA_BLE_SCAN_PF_COND_EVT
};
@ -550,55 +529,49 @@ enum
#define BTA_DM_BLE_PF_TYPE_MAX BTM_BLE_PF_TYPE_MAX
typedef UINT8 tBTA_DM_BLE_PF_COND_TYPE;
typedef union
{
typedef union {
UINT16 uuid16_mask;
UINT32 uuid32_mask;
UINT8 uuid128_mask[LEN_UUID_128];
}tBTA_DM_BLE_PF_COND_MASK;
} tBTA_DM_BLE_PF_COND_MASK;
typedef struct
{
typedef struct {
tBLE_BD_ADDR *p_target_addr; /* target address, if NULL, generic UUID filter */
tBT_UUID uuid; /* UUID condition */
tBTA_DM_BLE_PF_LOGIC_TYPE cond_logic; /* AND/OR */
tBTA_DM_BLE_PF_COND_MASK *p_uuid_mask; /* UUID condition mask, if NULL, match exact as UUID condition */
}tBTA_DM_BLE_PF_UUID_COND;
} tBTA_DM_BLE_PF_UUID_COND;
typedef struct
{
typedef struct {
UINT8 data_len; /* <= 20 bytes */
UINT8 *p_data;
}tBTA_DM_BLE_PF_LOCAL_NAME_COND;
} tBTA_DM_BLE_PF_LOCAL_NAME_COND;
typedef struct
{
typedef struct {
UINT16 company_id; /* company ID */
UINT8 data_len; /* <= 20 bytes */
UINT8 *p_pattern;
UINT16 company_id_mask; /* UUID value mask */
UINT8 *p_pattern_mask; /* Manufacturer data matching mask, same length
as data pattern, set to all 0xff, match exact data */
}tBTA_DM_BLE_PF_MANU_COND;
} tBTA_DM_BLE_PF_MANU_COND;
typedef struct
{
typedef struct {
UINT16 uuid; /* service ID */
UINT8 data_len; /* <= 20 bytes */
UINT8 *p_pattern;
UINT8 *p_pattern_mask; /* Service data matching mask, same length
as data pattern, set to all 0xff, match exact data */
}tBTA_DM_BLE_PF_SRVC_PATTERN_COND;
} tBTA_DM_BLE_PF_SRVC_PATTERN_COND;
typedef union
{
typedef union {
tBLE_BD_ADDR target_addr;
tBTA_DM_BLE_PF_LOCAL_NAME_COND local_name; /* lcoal name filtering */
tBTA_DM_BLE_PF_MANU_COND manu_data; /* manufactuer data filtering */
tBTA_DM_BLE_PF_UUID_COND srvc_uuid; /* service UUID filtering */
tBTA_DM_BLE_PF_UUID_COND solicitate_uuid; /* solicitated service UUID filtering */
tBTA_DM_BLE_PF_SRVC_PATTERN_COND srvc_data; /* service data pattern */
}tBTA_DM_BLE_PF_COND_PARAM;
} tBTA_DM_BLE_PF_COND_PARAM;
typedef UINT8 tBTA_DM_BLE_PF_FILT_INDEX;
typedef UINT8 tBTA_DM_BLE_PF_AVBL_SPACE;
@ -645,14 +618,12 @@ typedef UINT8 tBTA_SIG_STRENGTH_MASK;
typedef UINT8 tBTA_DM_SEC_EVT;
/* Structure associated with BTA_DM_ENABLE_EVT */
typedef struct
{
typedef struct {
tBTA_STATUS status;
} tBTA_DM_ENABLE;
/* Structure associated with BTA_DM_PIN_REQ_EVT */
typedef struct
{
typedef struct {
/* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in order */
BD_ADDR bd_addr; /* BD address peer device. */
DEV_CLASS dev_class; /* Class of Device */
@ -710,26 +681,24 @@ typedef tBTM_LE_LENC_KEYS tBTA_LE_LENC_KEYS ;
typedef tBTM_LE_LCSRK_KEYS tBTA_LE_LCSRK_KEYS ;
typedef tBTM_LE_PID_KEYS tBTA_LE_PID_KEYS ;
typedef union
{
typedef union {
tBTA_LE_PENC_KEYS penc_key; /* received peer encryption key */
tBTA_LE_PCSRK_KEYS psrk_key; /* received peer device SRK */
tBTA_LE_PID_KEYS pid_key; /* peer device ID key */
tBTA_LE_LENC_KEYS lenc_key; /* local encryption reproduction keys LTK = = d1(ER,DIV,0)*/
tBTA_LE_LCSRK_KEYS lcsrk_key; /* local device CSRK = d1(ER,DIV,1)*/
tBTA_LE_PID_KEYS lid_key; /* local device ID key for the particular remote */
}tBTA_LE_KEY_VALUE;
} tBTA_LE_KEY_VALUE;
#define BTA_BLE_LOCAL_KEY_TYPE_ID 1
#define BTA_BLE_LOCAL_KEY_TYPE_ER 2
typedef UINT8 tBTA_DM_BLE_LOCAL_KEY_MASK;
typedef struct
{
typedef struct {
BT_OCTET16 ir;
BT_OCTET16 irk;
BT_OCTET16 dhk;
}tBTA_BLE_LOCAL_ID_KEYS;
} tBTA_BLE_LOCAL_ID_KEYS;
#define BTA_DM_SEC_GRANTED BTA_SUCCESS
#define BTA_DM_SEC_PAIR_NOT_SPT BTA_DM_AUTH_SMP_PAIR_NOT_SUPPORT
@ -745,22 +714,19 @@ typedef UINT8 tBTA_DM_BLE_CONN_TYPE;
typedef BOOLEAN (tBTA_DM_BLE_SEL_CBACK)(BD_ADDR random_bda, UINT8 *p_remote_name);
/* Structure associated with BTA_DM_BLE_SEC_REQ_EVT */
typedef struct
{
typedef struct {
BD_ADDR bd_addr; /* peer address */
BD_NAME bd_name; /* peer device name */
} tBTA_DM_BLE_SEC_REQ;
typedef struct
{
typedef struct {
BD_ADDR bd_addr; /* peer address */
tBTM_LE_KEY_TYPE key_type;
tBTM_LE_KEY_VALUE *p_key_value;
}tBTA_DM_BLE_KEY;
} tBTA_DM_BLE_KEY;
/* Structure associated with BTA_DM_AUTH_CMPL_EVT */
typedef struct
{
typedef struct {
BD_ADDR bd_addr; /* BD address peer device. */
BD_NAME bd_name; /* Name of peer device. */
BOOLEAN key_present; /* Valid link key value in key element */
@ -774,8 +740,7 @@ typedef struct
/* Structure associated with BTA_DM_AUTHORIZE_EVT */
typedef struct
{
typedef struct {
BD_ADDR bd_addr; /* BD address peer device. */
BD_NAME bd_name; /* Name of peer device. */
tBTA_SERVICE_ID service; /* Service ID to authorize. */
@ -785,8 +750,7 @@ typedef struct
} tBTA_DM_AUTHORIZE;
/* Structure associated with BTA_DM_LINK_UP_EVT */
typedef struct
{
typedef struct {
BD_ADDR bd_addr; /* BD address peer device. */
#if BLE_INCLUDED == TRUE
tBTA_TRANSPORT link_type;
@ -794,8 +758,7 @@ typedef struct
} tBTA_DM_LINK_UP;
/* Structure associated with BTA_DM_LINK_DOWN_EVT */
typedef struct
{
typedef struct {
BD_ADDR bd_addr; /* BD address peer device. */
UINT8 status; /* connection open/closed */
BOOLEAN is_removed; /* TRUE if device is removed when link is down */
@ -805,15 +768,13 @@ typedef struct
} tBTA_DM_LINK_DOWN;
/* Structure associated with BTA_DM_ROLE_CHG_EVT */
typedef struct
{
typedef struct {
BD_ADDR bd_addr; /* BD address peer device. */
UINT8 new_role; /* the new connection role */
} tBTA_DM_ROLE_CHG;
/* Structure associated with BTA_DM_BUSY_LEVEL_EVT */
typedef struct
{
typedef struct {
UINT8 level; /* when paging or inquiring, level is 10.
Otherwise, the number of ACL links */
UINT8 level_flags; /* indicates individual flags */
@ -864,8 +825,7 @@ typedef tBTM_LE_AUTH_REQ tBTA_LE_AUTH_REQ; /* combination of the abo
typedef tBTM_OOB_DATA tBTA_OOB_DATA;
/* Structure associated with BTA_DM_SP_CFM_REQ_EVT */
typedef struct
{
typedef struct {
/* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in order */
BD_ADDR bd_addr; /* peer address */
DEV_CLASS dev_class; /* peer CoD */
@ -878,8 +838,7 @@ typedef struct
tBTA_AUTH_REQ rmt_io_caps; /* IO Capabilities of remote device */
} tBTA_DM_SP_CFM_REQ;
enum
{
enum {
BTA_SP_KEY_STARTED, /* passkey entry started */
BTA_SP_KEY_ENTERED, /* passkey digit entered */
BTA_SP_KEY_ERASED, /* passkey digit erased */
@ -889,15 +848,13 @@ enum
typedef UINT8 tBTA_SP_KEY_TYPE;
/* Structure associated with BTA_DM_SP_KEYPRESS_EVT */
typedef struct
{
typedef struct {
BD_ADDR bd_addr; /* peer address */
tBTA_SP_KEY_TYPE notif_type;
}tBTA_DM_SP_KEY_PRESS;
} tBTA_DM_SP_KEY_PRESS;
/* Structure associated with BTA_DM_SP_KEY_NOTIF_EVT */
typedef struct
{
typedef struct {
/* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in order */
BD_ADDR bd_addr; /* peer address */
DEV_CLASS dev_class; /* peer CoD */
@ -906,8 +863,7 @@ typedef struct
} tBTA_DM_SP_KEY_NOTIF;
/* Structure associated with BTA_DM_SP_RMT_OOB_EVT */
typedef struct
{
typedef struct {
/* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in order */
BD_ADDR bd_addr; /* peer address */
DEV_CLASS dev_class; /* peer CoD */
@ -915,14 +871,12 @@ typedef struct
} tBTA_DM_SP_RMT_OOB;
/* Structure associated with BTA_DM_BOND_CANCEL_CMPL_EVT */
typedef struct
{
typedef struct {
tBTA_STATUS result; /* TRUE of bond cancel succeeded, FALSE if failed. */
} tBTA_DM_BOND_CANCEL_CMPL;
/* Union of all security callback structures */
typedef union
{
typedef union {
tBTA_DM_ENABLE enable; /* BTA enabled */
tBTA_DM_PIN_REQ pin_req; /* PIN request. */
tBTA_DM_AUTH_CMPL auth_cmpl; /* Authentication complete indication. */
@ -1005,8 +959,7 @@ typedef UINT16 tBTA_DM_BLE_PF_TIMEOUT;
typedef UINT8 tBTA_DM_BLE_PF_TIMEOUT_CNT;
typedef UINT16 tBTA_DM_BLE_PF_ADV_TRACK_ENTRIES;
typedef struct
{
typedef struct {
tBTA_DM_BLE_PF_FEAT_SEL feat_seln;
tBTA_DM_BLE_PF_LIST_LOGIC_TYPE list_logic_type;
tBTA_DM_BLE_PF_FILT_LOGIC_TYPE filt_logic_type;
@ -1033,8 +986,7 @@ typedef UINT8 tBTA_DM_SEARCH_EVT;
#define BTA_DM_INQ_RES_IGNORE_RSSI BTM_INQ_RES_IGNORE_RSSI /* 0x7f RSSI value not supplied (ignore it) */
/* Structure associated with BTA_DM_INQ_RES_EVT */
typedef struct
{
typedef struct {
BD_ADDR bd_addr; /* BD address peer device. */
DEV_CLASS dev_class; /* Device class of peer device. */
BOOLEAN remt_name_not_required; /* Application sets this flag if it already knows the name of the device */
@ -1053,27 +1005,24 @@ typedef struct
} tBTA_DM_INQ_RES;
/* Structure associated with BTA_DM_INQ_CMPL_EVT */
typedef struct
{
typedef struct {
UINT8 num_resps; /* Number of inquiry responses. */
} tBTA_DM_INQ_CMPL;
/* Structure associated with BTA_DM_DI_DISC_CMPL_EVT */
typedef struct
{
typedef struct {
BD_ADDR bd_addr; /* BD address peer device. */
UINT8 num_record; /* Number of DI record */
tBTA_STATUS result;
} tBTA_DM_DI_DISC_CMPL;
/* Structure associated with BTA_DM_DISC_RES_EVT */
typedef struct
{
typedef struct {
BD_ADDR bd_addr; /* BD address peer device. */
BD_NAME bd_name; /* Name of peer device. */
tBTA_SERVICE_MASK services; /* Services found on peer device. */
// btla-specific ++
UINT8 * p_raw_data; /* Raw data for discovery DB */
UINT8 *p_raw_data; /* Raw data for discovery DB */
UINT32 raw_data_size; /* size of raw data */
tBT_DEVICE_TYPE device_type; /* device type in case it is BLE device */
UINT32 num_uuids;
@ -1083,8 +1032,7 @@ typedef struct
} tBTA_DM_DISC_RES;
/* Structure associated with tBTA_DM_DISC_BLE_RES */
typedef struct
{
typedef struct {
BD_ADDR bd_addr; /* BD address peer device. */
BD_NAME bd_name; /* Name of peer device. */
tBT_UUID service; /* GATT based Services UUID found on peer device. */
@ -1092,8 +1040,7 @@ typedef struct
/* Union of all search callback structures */
typedef union
{
typedef union {
tBTA_DM_INQ_RES inq_res; /* Inquiry result for a peer device. */
tBTA_DM_INQ_CMPL inq_cmpl; /* Inquiry complete. */
tBTA_DM_DISC_RES disc_res; /* Discovery result for a peer device. */
@ -1106,7 +1053,7 @@ typedef union
typedef void (tBTA_DM_SEARCH_CBACK)(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data);
/* Execute call back */
typedef void (tBTA_DM_EXEC_CBACK) (void * p_param);
typedef void (tBTA_DM_EXEC_CBACK) (void *p_param);
/* Encryption callback*/
typedef void (tBTA_DM_ENCRYPT_CBACK) (BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_STATUS result);
@ -1141,7 +1088,7 @@ typedef void (tBTA_BLE_SCAN_THRESHOLD_CBACK)(tBTA_DM_BLE_REF_VALUE ref_value);
typedef void (tBTA_BLE_SCAN_REP_CBACK) (tBTA_DM_BLE_REF_VALUE ref_value, UINT8 report_format,
UINT8 num_records, UINT16 data_len,
UINT8* p_rep_data, tBTA_STATUS status);
UINT8 *p_rep_data, tBTA_STATUS status);
typedef void (tBTA_BLE_SCAN_SETUP_CBACK) (tBTA_BLE_BATCH_SCAN_EVT evt,
tBTA_DM_BLE_REF_VALUE ref_value,
@ -1705,7 +1652,7 @@ extern void BTA_DmCloseACL(BD_ADDR bd_addr, BOOLEAN remove_dev, tBTA_TRANSPORT t
** Returns void
**
*******************************************************************************/
extern void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK* p_callback, void * p_param);
extern void bta_dmexecutecallback (tBTA_DM_EXEC_CBACK *p_callback, void *p_param);
#if (BTM_SCO_HCI_INCLUDED == TRUE)
/*******************************************************************************
@ -2145,7 +2092,7 @@ extern void BTA_DmBleBroadcast (BOOLEAN start);
**
*******************************************************************************/
extern void BTA_BleEnableAdvInstance (tBTA_BLE_ADV_PARAMS *p_params,
tBTA_BLE_MULTI_ADV_CBACK *p_cback,void *p_ref);
tBTA_BLE_MULTI_ADV_CBACK *p_cback, void *p_ref);
/*******************************************************************************
**
@ -2242,7 +2189,7 @@ extern void BTA_DmBleSetStorageParams(UINT8 batch_scan_full_max,
UINT8 batch_scan_notify_threshold,
tBTA_BLE_SCAN_SETUP_CBACK *p_setup_cback,
tBTA_BLE_SCAN_THRESHOLD_CBACK *p_thres_cback,
tBTA_BLE_SCAN_REP_CBACK* p_rep_cback,
tBTA_BLE_SCAN_REP_CBACK *p_rep_cback,
tBTA_DM_BLE_REF_VALUE ref_value);
/*******************************************************************************

0
components/bt/bluedroid/bta/include/bta_dm_ci.h Executable file → Normal file
View file

7
components/bt/bluedroid/bta/include/bta_dm_co.h Executable file → Normal file
View file

@ -28,7 +28,7 @@
#ifndef BTA_SCO_OUT_PKT_SIZE
#define BTA_SCO_OUT_PKT_SIZE BTM_SCO_DATA_SIZE_MAX
#define BTA_SCO_OUT_PKT_SIZE BTM_SCO_DATA_SIZE_MAX
#endif
#define BTA_SCO_CODEC_PCM 0 /* used for regular SCO */
@ -39,10 +39,9 @@ typedef UINT8 tBTA_SCO_CODEC_TYPE;
#define BTA_DM_SCO_SAMP_RATE_16K 16000
/* SCO codec information */
typedef struct
{
typedef struct {
tBTA_SCO_CODEC_TYPE codec_type;
}tBTA_CODEC_INFO;
} tBTA_CODEC_INFO;
#define BTA_DM_SCO_ROUTE_PCM BTM_SCO_ROUTE_PCM
#define BTA_DM_SCO_ROUTE_HCI BTM_SCO_ROUTE_HCI

187
components/bt/bluedroid/bta/include/bta_gatt_api.h Executable file → Normal file
View file

@ -50,8 +50,7 @@
** Common Definitions
***************************/
/* GATT ID */
typedef struct
{
typedef struct {
tBT_UUID uuid; /* uuid of the attribute */
UINT8 inst_id; /* instance ID */
} __attribute__((packed)) tBTA_GATT_ID;
@ -99,7 +98,7 @@ typedef struct
#define BTA_GATT_ALREADY_OPEN 0x91 /* 0x91 */
#define BTA_GATT_CANCEL 0x92 /* 0x92 */
/* 0xE0 ~ 0xFC reserved for future use */
/* 0xE0 ~ 0xFC reserved for future use */
#define BTA_GATT_CCC_CFG_ERR GATT_CCC_CFG_ERR /* 0xFD Client Characteristic Configuration Descriptor Improperly Configured */
#define BTA_GATT_PRC_IN_PROGRESS GATT_PRC_IN_PROGRESS /* 0xFE Procedure Already in progress */
#define BTA_GATT_OUT_OF_RANGE GATT_OUT_OF_RANGE /* 0xFFAttribute value out of range */
@ -150,14 +149,13 @@ typedef UINT8 tBTA_GATTC_EVT;
typedef tGATT_IF tBTA_GATTC_IF;
typedef struct
{
typedef struct {
UINT16 unit; /* as UUIUD defined by SIG */
UINT16 descr; /* as UUID as defined by SIG */
tGATT_FORMAT format;
INT8 exp;
UINT8 name_spc; /* The name space of the description */
}tBTA_GATT_CHAR_PRES;
} tBTA_GATT_CHAR_PRES;
#define BTA_GATT_CLT_CONFIG_NONE GATT_CLT_CONFIG_NONE /* 0x0000 */
#define BTA_GATT_CLT_CONFIG_NOTIFICATION GATT_CLT_CONFIG_NOTIFICATION /* 0x0001 */
@ -173,18 +171,16 @@ typedef UINT16 tBTA_GATT_SVR_CHAR_CONFIG;
/* Characteristic Aggregate Format attribute value
*/
#define BTA_GATT_AGGR_HANDLE_NUM_MAX 10
typedef struct
{
typedef struct {
UINT8 num_handle;
UINT16 handle_list[BTA_GATT_AGGR_HANDLE_NUM_MAX];
} tBTA_GATT_CHAR_AGGRE;
typedef tGATT_VALID_RANGE tBTA_GATT_VALID_RANGE;
typedef struct
{
typedef struct {
UINT16 len;
UINT8 *p_value;
}tBTA_GATT_UNFMT;
} tBTA_GATT_UNFMT;
#define BTA_GATT_MAX_ATTR_LEN GATT_MAX_ATTR_LEN
@ -203,53 +199,46 @@ typedef UINT8 tBTA_GATTC_WRITE_TYPE;
#define BTA_GATT_CONN_NONE 0x0101 /* 0x0101 no connection to cancel */
typedef UINT16 tBTA_GATT_REASON;
typedef struct
{
typedef struct {
tBTA_GATT_ID id;
BOOLEAN is_primary;
}tBTA_GATT_SRVC_ID;
} tBTA_GATT_SRVC_ID;
typedef struct
{
typedef struct {
tBTA_GATT_SRVC_ID srvc_id;
tBTA_GATT_ID char_id;
}tBTA_GATTC_CHAR_ID;
} tBTA_GATTC_CHAR_ID;
typedef struct
{
typedef struct {
tBTA_GATTC_CHAR_ID char_id;
tBTA_GATT_ID descr_id;
}tBTA_GATTC_CHAR_DESCR_ID;
} tBTA_GATTC_CHAR_DESCR_ID;
typedef struct
{
typedef struct {
tBTA_GATT_SRVC_ID srvc_id;
tBTA_GATT_SRVC_ID incl_svc_id;
}tBTA_GATTC_INCL_SVC_ID;
} tBTA_GATTC_INCL_SVC_ID;
#define BTA_GATT_TYPE_CHAR 0
#define BTA_GATT_TYPE_CHAR_DESCR 1
typedef UINT8 tBTA_GATT_ID_TYPE;
typedef struct
{
typedef struct {
tBTA_GATT_ID_TYPE id_type;
union
{
union {
tBTA_GATTC_CHAR_ID char_id;
tBTA_GATTC_CHAR_DESCR_ID char_descr_id;
} id_value;
}tBTA_GATTC_ATTR_ID;
} tBTA_GATTC_ATTR_ID;
#define BTA_GATTC_MULTI_MAX GATT_MAX_READ_MULTI_HANDLES
typedef struct
{
typedef struct {
UINT8 num_attr;
tBTA_GATTC_ATTR_ID id_list[BTA_GATTC_MULTI_MAX];
}tBTA_GATTC_MULTI;
} tBTA_GATTC_MULTI;
#define BTA_GATT_AUTH_REQ_NONE GATT_AUTH_REQ_NONE
#define BTA_GATT_AUTH_REQ_NO_MITM GATT_AUTH_REQ_NO_MITM /* unauthenticated encryption */
@ -259,8 +248,7 @@ typedef struct
typedef tGATT_AUTH_REQ tBTA_GATT_AUTH_REQ;
enum
{
enum {
BTA_GATTC_ATTR_TYPE_INCL_SRVC,
BTA_GATTC_ATTR_TYPE_CHAR,
BTA_GATTC_ATTR_TYPE_CHAR_DESCR,
@ -269,8 +257,7 @@ enum
typedef UINT8 tBTA_GATTC_ATTR_TYPE;
typedef struct
{
typedef struct {
tBT_UUID uuid;
UINT16 s_handle;
UINT16 e_handle; /* used for service only */
@ -278,96 +265,84 @@ typedef struct
UINT8 id;
UINT8 prop; /* used when attribute type is characteristic */
BOOLEAN is_primary; /* used when attribute type is service */
}tBTA_GATTC_NV_ATTR;
} tBTA_GATTC_NV_ATTR;
/* callback data structure */
typedef struct
{
typedef struct {
tBTA_GATT_STATUS status;
tBTA_GATTC_IF client_if;
// btla-specific ++
tBT_UUID app_uuid;
// btla-specific --
}tBTA_GATTC_REG;
} tBTA_GATTC_REG;
typedef struct
{
typedef struct {
UINT8 num_pres_fmt; /* number of presentation format aggregated*/
tBTA_GATTC_CHAR_DESCR_ID pre_format[BTA_GATTC_MULTI_MAX];
}tBTA_GATT_CHAR_AGGRE_VALUE;
} tBTA_GATT_CHAR_AGGRE_VALUE;
typedef union
{
typedef union {
tBTA_GATT_CHAR_AGGRE_VALUE aggre_value;
tBTA_GATT_UNFMT unformat;
}tBTA_GATT_READ_VAL;
} tBTA_GATT_READ_VAL;
typedef struct
{
typedef struct {
UINT16 conn_id;
tBTA_GATT_STATUS status;
tBTA_GATT_SRVC_ID srvc_id;
tBTA_GATT_ID char_id;
tBTA_GATT_ID descr_type;
tBTA_GATT_READ_VAL *p_value;
}tBTA_GATTC_READ;
} tBTA_GATTC_READ;
typedef struct
{
typedef struct {
UINT16 conn_id;
tBTA_GATT_STATUS status;
tBTA_GATT_SRVC_ID srvc_id;
tBTA_GATT_ID char_id;
tBTA_GATT_ID descr_type;
}tBTA_GATTC_WRITE;
} tBTA_GATTC_WRITE;
typedef struct
{
typedef struct {
UINT16 conn_id;
tBTA_GATT_STATUS status;
}tBTA_GATTC_EXEC_CMPL;
} tBTA_GATTC_EXEC_CMPL;
typedef struct
{
typedef struct {
UINT16 conn_id;
tBTA_GATT_STATUS status;
}tBTA_GATTC_SEARCH_CMPL;
} tBTA_GATTC_SEARCH_CMPL;
typedef struct
{
typedef struct {
UINT16 conn_id;
tBTA_GATT_SRVC_ID service_uuid;
}tBTA_GATTC_SRVC_RES;
} tBTA_GATTC_SRVC_RES;
typedef struct
{
typedef struct {
UINT16 conn_id;
tBTA_GATT_STATUS status;
UINT16 mtu;
}tBTA_GATTC_CFG_MTU;
} tBTA_GATTC_CFG_MTU;
typedef struct
{
typedef struct {
tBTA_GATT_STATUS status;
UINT16 conn_id;
tBTA_GATTC_IF client_if;
BD_ADDR remote_bda;
tBTA_TRANSPORT transport;
UINT16 mtu;
}tBTA_GATTC_OPEN;
} tBTA_GATTC_OPEN;
typedef struct
{
typedef struct {
tBTA_GATT_STATUS status;
UINT16 conn_id;
tBTA_GATTC_IF client_if;
BD_ADDR remote_bda;
tBTA_GATT_REASON reason; /* disconnect reason code, not useful when connect event is reported */
}tBTA_GATTC_CLOSE;
} tBTA_GATTC_CLOSE;
typedef struct
{
typedef struct {
UINT16 conn_id;
BD_ADDR bda;
tBTA_GATTC_CHAR_ID char_id;
@ -375,32 +350,28 @@ typedef struct
UINT16 len;
UINT8 value[BTA_GATT_MAX_ATTR_LEN];
BOOLEAN is_notify;
}tBTA_GATTC_NOTIFY;
} tBTA_GATTC_NOTIFY;
typedef struct
{
typedef struct {
UINT16 conn_id;
BOOLEAN congested; /* congestion indicator */
}tBTA_GATTC_CONGEST;
} tBTA_GATTC_CONGEST;
// btla-specific ++
typedef struct
{
typedef struct {
tBTA_GATT_STATUS status;
tBTA_GATTC_IF client_if;
UINT16 conn_id;
BD_ADDR remote_bda;
}tBTA_GATTC_OPEN_CLOSE;
} tBTA_GATTC_OPEN_CLOSE;
// btla-specific --
typedef struct
{
typedef struct {
tBTA_GATTC_IF client_if;
BD_ADDR remote_bda;
}tBTA_GATTC_ENC_CMPL_CB;
} tBTA_GATTC_ENC_CMPL_CB;
typedef union
{
typedef union {
tBTA_GATT_STATUS status;
tBTA_GATTC_SEARCH_CMPL search_cmpl; /* discovery complete */
@ -485,8 +456,7 @@ typedef UINT8 tBTA_GATT_CHAR_PROP;
/*********************** NV callback Data Definitions **********************
*/
typedef struct
{
typedef struct {
tBT_UUID app_uuid128;
tBT_UUID svc_uuid;
UINT16 svc_inst;
@ -531,27 +501,24 @@ typedef tGATT_WRITE_REQ tBTA_GATT_WRITE_REQ;
/* callback data for server access request from client */
typedef tGATTS_DATA tBTA_GATTS_REQ_DATA;
typedef struct
{
typedef struct {
tBTA_GATT_STATUS status;
BD_ADDR remote_bda;
UINT32 trans_id;
UINT16 conn_id;
tBTA_GATTS_REQ_DATA *p_data;
}tBTA_GATTS_REQ;
} tBTA_GATTS_REQ;
typedef struct
{
typedef struct {
tBTA_GATTS_IF server_if;
tBTA_GATT_STATUS status;
// btla-specific ++
tBT_UUID uuid;
// btla-specific --
}tBTA_GATTS_REG_OPER;
} tBTA_GATTS_REG_OPER;
typedef struct
{
typedef struct {
tBTA_GATTS_IF server_if;
UINT16 service_id;
// btla-specific ++
@ -560,10 +527,9 @@ typedef struct
tBTA_GATT_STATUS status;
tBT_UUID uuid;
// btla-specific --
}tBTA_GATTS_CREATE;
} tBTA_GATTS_CREATE;
typedef struct
{
typedef struct {
tBTA_GATTS_IF server_if;
UINT16 service_id;
UINT16 attr_id;
@ -571,40 +537,35 @@ typedef struct
// btla-specific ++
tBT_UUID char_uuid;
// btla-specific --
}tBTA_GATTS_ADD_RESULT;
} tBTA_GATTS_ADD_RESULT;
typedef struct
{
typedef struct {
tBTA_GATTS_IF server_if;
UINT16 service_id;
tBTA_GATT_STATUS status;
}tBTA_GATTS_SRVC_OPER;
} tBTA_GATTS_SRVC_OPER;
typedef struct
{
typedef struct {
tBTA_GATTS_IF server_if;
BD_ADDR remote_bda;
UINT16 conn_id;
tBTA_GATT_REASON reason; /* report disconnect reason */
tBTA_GATT_TRANSPORT transport;
}tBTA_GATTS_CONN;
} tBTA_GATTS_CONN;
typedef struct
{
typedef struct {
UINT16 conn_id;
BOOLEAN congested; /* report channel congestion indicator */
}tBTA_GATTS_CONGEST;
} tBTA_GATTS_CONGEST;
typedef struct
{
typedef struct {
UINT16 conn_id; /* connection ID */
tBTA_GATT_STATUS status; /* notification/indication status */
}tBTA_GATTS_CONF;
} tBTA_GATTS_CONF;
/* GATTS callback data */
typedef union
{
typedef union {
tBTA_GATTS_REG_OPER reg_oper;
tBTA_GATTS_CREATE create;
tBTA_GATTS_SRVC_OPER srvc_oper;
@ -616,7 +577,7 @@ typedef union
tBTA_GATTS_CONN conn; /* BTA_GATTS_CONN_EVT */
tBTA_GATTS_CONGEST congest; /* BTA_GATTS_CONGEST_EVT callback data */
tBTA_GATTS_CONF confirm; /* BTA_GATTS_CONF_EVT callback data */
}tBTA_GATTS;
} tBTA_GATTS;
/* GATTS enable callback function */
typedef void (tBTA_GATTS_ENB_CBACK)(tBTA_GATT_STATUS status);
@ -1254,7 +1215,7 @@ extern void BTA_GATTS_AddCharacteristic (UINT16 service_id, tBT_UUID *p_char_
*******************************************************************************/
extern void BTA_GATTS_AddCharDescriptor (UINT16 service_id,
tBTA_GATT_PERM perm,
tBT_UUID * p_descr_uuid);
tBT_UUID *p_descr_uuid);
/*******************************************************************************
**

6
components/bt/bluedroid/bta/include/bta_gattc_ci.h Executable file → Normal file
View file

@ -31,8 +31,7 @@
*****************************************************************************/
/* Open Complete Event */
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_GATT_STATUS status;
} tBTA_GATTC_CI_EVT;
@ -40,8 +39,7 @@ typedef struct
#define BTA_GATTC_NV_LOAD_MAX 10
/* Read Ready Event */
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_GATT_STATUS status;
UINT16 num_attr;

0
components/bt/bluedroid/bta/include/bta_gattc_co.h Executable file → Normal file
View file

167
components/bt/bluedroid/bta/include/bta_gattc_int.h Executable file → Normal file
View file

@ -35,8 +35,7 @@
/*****************************************************************************
** Constants and data types
*****************************************************************************/
enum
{
enum {
BTA_GATTC_API_OPEN_EVT = BTA_SYS_EVT_START(BTA_ID_GATTC),
BTA_GATTC_INT_OPEN_FAIL_EVT,
BTA_GATTC_API_CANCEL_OPEN_EVT,
@ -89,31 +88,28 @@ typedef UINT16 tBTA_GATTC_INT_EVT;
#define BTA_GATTC_CONN_MAX GATT_MAX_PHY_CHANNEL
#ifndef BTA_GATTC_CLCB_MAX
#define BTA_GATTC_CLCB_MAX GATT_CL_MAX_LCB
#define BTA_GATTC_CLCB_MAX GATT_CL_MAX_LCB
#endif
#define BTA_GATTC_WRITE_PREPARE GATT_WRITE_PREPARE
/* internal strucutre for GATTC register API */
typedef struct
{
typedef struct {
BT_HDR hdr;
tBT_UUID app_uuid;
tBTA_GATTC_CBACK *p_cback;
}tBTA_GATTC_API_REG;
} tBTA_GATTC_API_REG;
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_GATTC_IF client_if;
}tBTA_GATTC_INT_START_IF;
} tBTA_GATTC_INT_START_IF;
typedef tBTA_GATTC_INT_START_IF tBTA_GATTC_API_DEREG;
typedef tBTA_GATTC_INT_START_IF tBTA_GATTC_INT_DEREG;
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR remote_bda;
tBTA_GATTC_IF client_if;
@ -123,8 +119,7 @@ typedef struct
typedef tBTA_GATTC_API_OPEN tBTA_GATTC_API_CANCEL_OPEN;
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_GATT_AUTH_REQ auth_req;
tBTA_GATT_SRVC_ID srvc_id;
@ -132,8 +127,7 @@ typedef struct
tBTA_GATT_ID *p_descr_type;
} tBTA_GATTC_API_READ;
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_GATT_AUTH_REQ auth_req;
tBTA_GATT_SRVC_ID srvc_id;
@ -143,16 +137,14 @@ typedef struct
UINT16 offset;
UINT16 len;
UINT8 *p_value;
}tBTA_GATTC_API_WRITE;
} tBTA_GATTC_API_WRITE;
typedef struct
{
typedef struct {
BT_HDR hdr;
BOOLEAN is_execute;
}tBTA_GATTC_API_EXEC;
} tBTA_GATTC_API_EXEC;
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_GATT_SRVC_ID srvc_id;
tBTA_GATT_ID char_id;
@ -160,30 +152,26 @@ typedef struct
typedef tGATT_CL_COMPLETE tBTA_GATTC_CMPL;
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT8 op_code;
tGATT_STATUS status;
tBTA_GATTC_CMPL *p_cmpl;
}tBTA_GATTC_OP_CMPL;
} tBTA_GATTC_OP_CMPL;
typedef struct
{
typedef struct {
BT_HDR hdr;
tBT_UUID *p_srvc_uuid;
}tBTA_GATTC_API_SEARCH;
} tBTA_GATTC_API_SEARCH;
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_GATT_AUTH_REQ auth_req;
UINT8 num_attr;
tBTA_GATTC_ATTR_ID *p_id_list;
}tBTA_GATTC_API_READ_MULTI;
} tBTA_GATTC_API_READ_MULTI;
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR_PTR remote_bda;
tBTA_GATTC_IF client_if;
@ -191,31 +179,27 @@ typedef struct
} tBTA_GATTC_API_LISTEN;
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT16 mtu;
}tBTA_GATTC_API_CFG_MTU;
} tBTA_GATTC_API_CFG_MTU;
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR remote_bda;
tBTA_GATTC_IF client_if;
UINT8 role;
tBT_TRANSPORT transport;
tGATT_DISCONN_REASON reason;
}tBTA_GATTC_INT_CONN;
} tBTA_GATTC_INT_CONN;
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR remote_bda;
tBTA_GATTC_IF client_if;
}tBTA_GATTC_ENC_CMPL;
} tBTA_GATTC_ENC_CMPL;
typedef union
{
typedef union {
BT_HDR hdr;
tBTA_GATTC_API_REG api_reg;
tBTA_GATTC_API_DEREG api_dereg;
@ -244,14 +228,12 @@ typedef union
/* GATT server cache on the client */
typedef union
{
typedef union {
UINT8 uuid128[LEN_UUID_128];
UINT16 uuid16;
}tBTA_GATTC_UUID;
} tBTA_GATTC_UUID;
typedef struct gattc_attr_cache
{
typedef struct gattc_attr_cache {
tBTA_GATTC_UUID *p_uuid;
struct gattc_attr_cache *p_next;
UINT16 uuid_len;
@ -265,8 +247,7 @@ typedef struct gattc_attr_cache
} __attribute__((packed)) tBTA_GATTC_CACHE_ATTR;
// btla-specific --
typedef struct gattc_svc_cache
{
typedef struct gattc_svc_cache {
tBTA_GATT_SRVC_ID service_uuid;
tBTA_GATTC_CACHE_ATTR *p_attr;
tBTA_GATTC_CACHE_ATTR *p_last_attr;
@ -278,26 +259,24 @@ typedef struct gattc_svc_cache
} __attribute__((packed)) tBTA_GATTC_CACHE;
// btla-specific --
typedef struct
{
typedef struct {
tBT_UUID uuid;
UINT16 s_handle;
UINT16 e_handle;
BOOLEAN is_primary;
UINT8 srvc_inst_id;
tBTA_GATT_CHAR_PROP property;
}tBTA_GATTC_ATTR_REC;
} tBTA_GATTC_ATTR_REC;
#define BTA_GATTC_MAX_CACHE_CHAR 40
#define BTA_GATTC_ATTR_LIST_SIZE (BTA_GATTC_MAX_CACHE_CHAR * sizeof(tBTA_GATTC_ATTR_REC))
#ifndef BTA_GATTC_CACHE_SRVR_SIZE
#define BTA_GATTC_CACHE_SRVR_SIZE 600
#define BTA_GATTC_CACHE_SRVR_SIZE 600
#endif
enum
{
enum {
BTA_GATTC_IDLE_ST = 0, /* Idle */
BTA_GATTC_W4_CONN_ST, /* Wait for connection - (optional) */
BTA_GATTC_CONN_ST, /* connected state */
@ -305,8 +284,7 @@ enum
};
typedef UINT8 tBTA_GATTC_STATE;
typedef struct
{
typedef struct {
BOOLEAN in_use;
BD_ADDR server_bda;
BOOLEAN connected;
@ -345,15 +323,13 @@ typedef struct
#define BTA_GATTC_NOTIF_REG_MAX 15
#endif
typedef struct
{
typedef struct {
BOOLEAN in_use;
BD_ADDR remote_bda;
tBTA_GATTC_CHAR_ID char_id;
}tBTA_GATTC_NOTIF_REG;
} tBTA_GATTC_NOTIF_REG;
typedef struct
{
typedef struct {
tBTA_GATTC_CBACK *p_cback;
BOOLEAN in_use;
tBTA_GATTC_IF client_if; /* client interface with BTE stack for this application */
@ -361,11 +337,10 @@ typedef struct
BOOLEAN dereg_pending;
tBT_UUID app_uuid;
tBTA_GATTC_NOTIF_REG notif_reg[BTA_GATTC_NOTIF_REG_MAX];
}tBTA_GATTC_RCB;
} tBTA_GATTC_RCB;
/* client channel is a mapping between a BTA client(cl_id) and a remote BD address */
typedef struct
{
typedef struct {
UINT16 bta_conn_id; /* client channel ID, unique for clcb */
BD_ADDR bda;
tBTA_TRANSPORT transport; /* channel transport */
@ -394,31 +369,27 @@ typedef UINT16 tBTA_GATTC_CIF_MASK;
typedef UINT32 tBTA_GATTC_CIF_MASK;
#endif
typedef struct
{
typedef struct {
BOOLEAN in_use;
BD_ADDR remote_bda;
tBTA_GATTC_CIF_MASK cif_mask;
tBTA_GATTC_CIF_MASK cif_adv_mask;
}tBTA_GATTC_BG_TCK;
} tBTA_GATTC_BG_TCK;
typedef struct
{
typedef struct {
BOOLEAN in_use;
BD_ADDR remote_bda;
}tBTA_GATTC_CONN;
} tBTA_GATTC_CONN;
enum
{
enum {
BTA_GATTC_STATE_DISABLED,
BTA_GATTC_STATE_ENABLING,
BTA_GATTC_STATE_ENABLED,
BTA_GATTC_STATE_DISABLING
};
typedef struct
{
typedef struct {
UINT8 state;
tBTA_GATTC_CONN conn_track[BTA_GATTC_CONN_MAX];
@ -430,7 +401,7 @@ typedef struct
tSDP_DISCOVERY_DB *p_sdp_db;
UINT16 sdp_conn_id;
}tBTA_GATTC_CB;
} tBTA_GATTC_CB;
/*****************************************************************************
** Global data
@ -454,8 +425,8 @@ extern BOOLEAN bta_gattc_sm_execute(tBTA_GATTC_CLCB *p_clcb, UINT16 event, tBTA_
extern void bta_gattc_disable(tBTA_GATTC_CB *p_cb);
extern void bta_gattc_register(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data);
extern void bta_gattc_start_if(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_data);
extern void bta_gattc_process_api_open (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg);
extern void bta_gattc_process_api_open_cancel (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg);
extern void bta_gattc_process_api_open (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
extern void bta_gattc_process_api_open_cancel (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
extern void bta_gattc_deregister(tBTA_GATTC_CB *p_cb, tBTA_GATTC_RCB *p_clreg);
extern void bta_gattc_process_enc_cmpl(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
@ -491,29 +462,29 @@ extern void bta_gattc_ci_close(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
extern void bta_gattc_ci_save(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
extern void bta_gattc_cache_open(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
extern void bta_gattc_ignore_op_cmpl(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
extern void bta_gattc_restart_discover(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA * p_msg);
extern void bta_gattc_restart_discover(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_msg);
extern void bta_gattc_init_bk_conn(tBTA_GATTC_API_OPEN *p_data, tBTA_GATTC_RCB *p_clreg);
extern void bta_gattc_cancel_bk_conn(tBTA_GATTC_API_CANCEL_OPEN *p_data);
extern void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS status,
BD_ADDR remote_bda, UINT16 conn_id, tBTA_TRANSPORT transport, UINT16 mtu);
extern void bta_gattc_process_api_refresh(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg);
extern void bta_gattc_process_api_refresh(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
extern void bta_gattc_cfg_mtu(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
#if BLE_INCLUDED == TRUE
extern void bta_gattc_listen(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg);
extern void bta_gattc_broadcast(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA * p_msg);
extern void bta_gattc_listen(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
extern void bta_gattc_broadcast(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
#endif
/* utility functions */
extern tBTA_GATTC_CLCB * bta_gattc_find_clcb_by_cif (UINT8 client_if, BD_ADDR remote_bda, tBTA_TRANSPORT transport);
extern tBTA_GATTC_CLCB * bta_gattc_find_clcb_by_conn_id (UINT16 conn_id);
extern tBTA_GATTC_CLCB * bta_gattc_clcb_alloc(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_TRANSPORT transport);
extern tBTA_GATTC_CLCB *bta_gattc_find_clcb_by_cif (UINT8 client_if, BD_ADDR remote_bda, tBTA_TRANSPORT transport);
extern tBTA_GATTC_CLCB *bta_gattc_find_clcb_by_conn_id (UINT16 conn_id);
extern tBTA_GATTC_CLCB *bta_gattc_clcb_alloc(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_TRANSPORT transport);
extern void bta_gattc_clcb_dealloc(tBTA_GATTC_CLCB *p_clcb);
extern tBTA_GATTC_CLCB * bta_gattc_find_alloc_clcb(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_TRANSPORT transport);
extern tBTA_GATTC_RCB * bta_gattc_cl_get_regcb(UINT8 client_if);
extern tBTA_GATTC_SERV * bta_gattc_find_srcb(BD_ADDR bda);
extern tBTA_GATTC_SERV * bta_gattc_srcb_alloc(BD_ADDR bda);
extern tBTA_GATTC_SERV * bta_gattc_find_scb_by_cid (UINT16 conn_id);
extern tBTA_GATTC_CLCB * bta_gattc_find_int_conn_clcb(tBTA_GATTC_DATA *p_msg);
extern tBTA_GATTC_CLCB * bta_gattc_find_int_disconn_clcb(tBTA_GATTC_DATA *p_msg);
extern tBTA_GATTC_CLCB *bta_gattc_find_alloc_clcb(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_TRANSPORT transport);
extern tBTA_GATTC_RCB *bta_gattc_cl_get_regcb(UINT8 client_if);
extern tBTA_GATTC_SERV *bta_gattc_find_srcb(BD_ADDR bda);
extern tBTA_GATTC_SERV *bta_gattc_srcb_alloc(BD_ADDR bda);
extern tBTA_GATTC_SERV *bta_gattc_find_scb_by_cid (UINT16 conn_id);
extern tBTA_GATTC_CLCB *bta_gattc_find_int_conn_clcb(tBTA_GATTC_DATA *p_msg);
extern tBTA_GATTC_CLCB *bta_gattc_find_int_disconn_clcb(tBTA_GATTC_DATA *p_msg);
extern BOOLEAN bta_gattc_enqueue(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data);
@ -527,7 +498,7 @@ extern BOOLEAN bta_gattc_mark_bg_conn (tBTA_GATTC_IF client_if, BD_ADDR_PTR rem
extern BOOLEAN bta_gattc_check_bg_conn (tBTA_GATTC_IF client_if, BD_ADDR remote_bda, UINT8 role);
extern UINT8 bta_gattc_num_reg_app(void);
extern void bta_gattc_clear_notif_registration(UINT16 conn_id);
extern tBTA_GATTC_SERV * bta_gattc_find_srvr_cache(BD_ADDR bda);
extern tBTA_GATTC_SERV *bta_gattc_find_srvr_cache(BD_ADDR bda);
extern BOOLEAN bta_gattc_charid_compare(tBTA_GATTC_CHAR_ID *p_src, tBTA_GATTC_CHAR_ID *p_tar);
extern BOOLEAN bta_gattc_srvcid_compare(tBTA_GATT_SRVC_ID *p_src, tBTA_GATT_SRVC_ID *p_tar);
extern void bta_gattc_cpygattid(tBTA_GATT_ID *p_des, tBTA_GATT_ID *p_src);
@ -539,16 +510,16 @@ extern tBTA_GATT_STATUS bta_gattc_discover_procedure(UINT16 conn_id, tBTA_GATTC_
extern tBTA_GATT_STATUS bta_gattc_discover_pri_service(UINT16 conn_id, tBTA_GATTC_SERV *p_server_cb, UINT8 disc_type);
extern void bta_gattc_search_service(tBTA_GATTC_CLCB *p_clcb, tBT_UUID *p_uuid);
extern tBTA_GATT_STATUS bta_gattc_query_cache(UINT16 conn_id, UINT8 query_type, tBTA_GATT_SRVC_ID *p_srvc_id,
tBTA_GATT_ID *p_start_rec,tBT_UUID *p_uuid_cond,
tBTA_GATT_ID *p_start_rec, tBT_UUID *p_uuid_cond,
tBTA_GATT_ID *p_output, void *p_param);
extern tBTA_GATT_STATUS bta_gattc_init_cache(tBTA_GATTC_SERV *p_srvc_cb);
extern void bta_gattc_rebuild_cache(tBTA_GATTC_SERV *p_srcv, UINT16 num_attr, tBTA_GATTC_NV_ATTR *p_attr, UINT16 attr_index);
extern BOOLEAN bta_gattc_cache_save(tBTA_GATTC_SERV *p_srvc_cb, UINT16 conn_id);
extern tBTA_GATTC_CONN * bta_gattc_conn_alloc(BD_ADDR remote_bda);
extern tBTA_GATTC_CONN * bta_gattc_conn_find(BD_ADDR remote_bda);
extern tBTA_GATTC_CONN * bta_gattc_conn_find_alloc(BD_ADDR remote_bda);
extern tBTA_GATTC_CONN *bta_gattc_conn_alloc(BD_ADDR remote_bda);
extern tBTA_GATTC_CONN *bta_gattc_conn_find(BD_ADDR remote_bda);
extern tBTA_GATTC_CONN *bta_gattc_conn_find_alloc(BD_ADDR remote_bda);
extern BOOLEAN bta_gattc_conn_dealloc(BD_ADDR remote_bda);
#endif /* BTA_GATTC_INT_H */

0
components/bt/bluedroid/bta/include/bta_gatts_co.h Executable file → Normal file
View file

104
components/bt/bluedroid/bta/include/bta_gatts_int.h Executable file → Normal file
View file

@ -34,8 +34,7 @@
/*****************************************************************************
** Constants and data types
*****************************************************************************/
enum
{
enum {
BTA_GATTS_API_REG_EVT = BTA_SYS_EVT_START(BTA_ID_GATTS),
BTA_GATTS_INT_START_IF_EVT,
BTA_GATTS_API_DEREG_EVT,
@ -64,23 +63,20 @@ typedef UINT16 tBTA_GATTS_INT_EVT;
#define BTA_GATTS_MAX_SRVC_NUM GATT_MAX_SR_PROFILES
/* internal strucutre for GATTC register API */
typedef struct
{
typedef struct {
BT_HDR hdr;
tBT_UUID app_uuid;
tBTA_GATTS_CBACK *p_cback;
}tBTA_GATTS_API_REG;
} tBTA_GATTS_API_REG;
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_GATTS_IF server_if;
}tBTA_GATTS_INT_START_IF;
} tBTA_GATTS_INT_START_IF;
typedef tBTA_GATTS_INT_START_IF tBTA_GATTS_API_DEREG;
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_GATTS_IF server_if;
tBT_UUID service_uuid;
@ -90,75 +86,66 @@ typedef struct
} tBTA_GATTS_API_CREATE_SRVC;
typedef struct
{
typedef struct {
BT_HDR hdr;
tBT_UUID char_uuid;
tBTA_GATT_PERM perm;
tBTA_GATT_CHAR_PROP property;
}tBTA_GATTS_API_ADD_CHAR;
} tBTA_GATTS_API_ADD_CHAR;
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT16 included_service_id;
}tBTA_GATTS_API_ADD_INCL_SRVC;
} tBTA_GATTS_API_ADD_INCL_SRVC;
typedef struct
{
typedef struct {
BT_HDR hdr;
tBT_UUID descr_uuid;
tBTA_GATT_PERM perm;
}tBTA_GATTS_API_ADD_DESCR;
} tBTA_GATTS_API_ADD_DESCR;
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT16 attr_id;
UINT16 len;
BOOLEAN need_confirm;
UINT8 value[BTA_GATT_MAX_ATTR_LEN];
}tBTA_GATTS_API_INDICATION;
} tBTA_GATTS_API_INDICATION;
typedef struct
{
typedef struct {
BT_HDR hdr;
UINT32 trans_id;
tBTA_GATT_STATUS status;
tBTA_GATTS_RSP *p_rsp;
}tBTA_GATTS_API_RSP;
} tBTA_GATTS_API_RSP;
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_GATT_TRANSPORT transport;
}tBTA_GATTS_API_START;
} tBTA_GATTS_API_START;
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR remote_bda;
tBTA_GATTS_IF server_if;
BOOLEAN is_direct;
tBTA_GATT_TRANSPORT transport;
}tBTA_GATTS_API_OPEN;
} tBTA_GATTS_API_OPEN;
typedef tBTA_GATTS_API_OPEN tBTA_GATTS_API_CANCEL_OPEN;
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR_PTR remote_bda;
tBTA_GATTS_IF server_if;
BOOLEAN start;
} tBTA_GATTS_API_LISTEN;
typedef union
{
typedef union {
BT_HDR hdr;
tBTA_GATTS_API_REG api_reg;
tBTA_GATTS_API_DEREG api_dereg;
@ -178,17 +165,15 @@ typedef union
} tBTA_GATTS_DATA;
/* application registration control block */
typedef struct
{
typedef struct {
BOOLEAN in_use;
tBT_UUID app_uuid;
tBTA_GATTS_CBACK *p_cback;
tBTA_GATTS_IF gatt_if;
}tBTA_GATTS_RCB;
} tBTA_GATTS_RCB;
/* service registration control block */
typedef struct
{
typedef struct {
tBT_UUID service_uuid; /* service UUID */
UINT16 service_id; /* service handle */
UINT8 inst_num; /* instance ID */
@ -196,16 +181,15 @@ typedef struct
UINT8 idx; /* self index of serviec CB */
BOOLEAN in_use;
}tBTA_GATTS_SRVC_CB;
} tBTA_GATTS_SRVC_CB;
/* GATT server control block */
typedef struct
{
typedef struct {
BOOLEAN enabled;
tBTA_GATTS_RCB rcb[BTA_GATTS_MAX_APP_NUM];
tBTA_GATTS_SRVC_CB srvc_cb[BTA_GATTS_MAX_SRVC_NUM];
}tBTA_GATTS_CB;
} tBTA_GATTS_CB;
@ -218,7 +202,7 @@ typedef struct
extern tBTA_GATTS_CB bta_gatts_cb;
#else
extern tBTA_GATTS_CB *bta_gatts_cb_ptr;
#define bta_gatts_cb (*bta_gatts_cb_ptr)
#define bta_gatts_cb (*bta_gatts_cb_ptr)
#endif
/*****************************************************************************
@ -231,29 +215,29 @@ extern void bta_gatts_api_enable(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_data);
extern void bta_gatts_register(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_start_if(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_deregister(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_create_srvc(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_add_include_srvc(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_add_char(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_start_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_stop_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_create_srvc(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_add_include_srvc(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_add_char(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_add_char_descr(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_delete_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_start_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_stop_service(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_send_rsp(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_indicate_handle (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_send_rsp(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_indicate_handle (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_cancel_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_close (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_listen(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA * p_msg);
extern void bta_gatts_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_cancel_open (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_close (tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern void bta_gatts_listen(tBTA_GATTS_CB *p_cb, tBTA_GATTS_DATA *p_msg);
extern BOOLEAN bta_gatts_uuid_compare(tBT_UUID tar, tBT_UUID src);
extern tBTA_GATTS_RCB *bta_gatts_find_app_rcb_by_app_if(tBTA_GATTS_IF server_if);
extern UINT8 bta_gatts_find_app_rcb_idx_by_app_if(tBTA_GATTS_CB *p_cb, tBTA_GATTS_IF server_if);
extern UINT8 bta_gatts_alloc_srvc_cb(tBTA_GATTS_CB *p_cb, UINT8 rcb_idx);
extern tBTA_GATTS_SRVC_CB * bta_gatts_find_srvc_cb_by_srvc_id(tBTA_GATTS_CB *p_cb, UINT16 service_id);
extern tBTA_GATTS_SRVC_CB * bta_gatts_find_srvc_cb_by_attr_id(tBTA_GATTS_CB *p_cb, UINT16 attr_id);
extern tBTA_GATTS_SRVC_CB *bta_gatts_find_srvc_cb_by_srvc_id(tBTA_GATTS_CB *p_cb, UINT16 service_id);
extern tBTA_GATTS_SRVC_CB *bta_gatts_find_srvc_cb_by_attr_id(tBTA_GATTS_CB *p_cb, UINT16 attr_id);
#endif /* BTA_GATTS_INT_H */

View file

@ -93,8 +93,7 @@ typedef UINT16 tBTA_HH_EVT;
#define BTA_HH_PROTO_UNKNOWN (0xff)
typedef UINT8 tBTA_HH_PROTO_MODE;
enum
{
enum {
BTA_HH_KEYBD_RPT_ID = 1,
BTA_HH_MOUSE_RPT_ID
};
@ -114,8 +113,7 @@ typedef UINT8 tBTA_HH_BOOT_RPT_ID;
#define BTA_HH_DEVT_OTHER 0x80
typedef UINT8 tBTA_HH_DEVT;
enum
{
enum {
BTA_HH_OK,
BTA_HH_HS_HID_NOT_READY, /* handshake error : device not ready */
BTA_HH_HS_INVALID_RPT_ID, /* handshake error : invalid report ID */
@ -149,22 +147,19 @@ typedef UINT8 tBTA_HH_STATUS;
typedef UINT16 tBTA_HH_ATTR_MASK;
/* supported type of device and corresponding application ID */
typedef struct
{
typedef struct {
tBTA_HH_DEVT tod; /* type of device */
UINT8 app_id; /* corresponding application ID */
}tBTA_HH_SPT_TOD;
} tBTA_HH_SPT_TOD;
/* configuration struct */
typedef struct
{
typedef struct {
UINT8 max_devt_spt; /* max number of types of devices spt */
tBTA_HH_SPT_TOD *p_devt_list; /* supported types of device list */
UINT16 sdp_db_size;
}tBTA_HH_CFG;
} tBTA_HH_CFG;
enum
{
enum {
BTA_HH_RPTT_RESRV, /* reserved */
BTA_HH_RPTT_INPUT, /* input report */
BTA_HH_RPTT_OUTPUT, /* output report */
@ -174,8 +169,7 @@ typedef UINT8 tBTA_HH_RPT_TYPE;
/* HID_CONTROL operation code used in BTA_HhSendCtrl()
*/
enum
{
enum {
BTA_HH_CTRL_NOP = 0 + HID_PAR_CONTROL_NOP ,/* mapping from BTE */
BTA_HH_CTRL_HARD_RESET, /* hard reset */
BTA_HH_CTRL_SOFT_RESET, /* soft reset */
@ -194,8 +188,7 @@ typedef tHID_DEV_DSCP_INFO tBTA_HH_DEV_DESCR;
/* report descriptor information */
typedef struct
{
typedef struct {
UINT16 vendor_id; /* vendor ID */
UINT16 product_id; /* product ID */
UINT16 version; /* version */
@ -209,11 +202,10 @@ typedef struct
UINT8 flag;
#endif
tBTA_HH_DEV_DESCR descriptor;
}tBTA_HH_DEV_DSCP_INFO;
} tBTA_HH_DEV_DSCP_INFO;
/* callback event data for BTA_HH_OPEN_EVT */
typedef struct
{
typedef struct {
BD_ADDR bda; /* HID device bd address */
tBTA_HH_STATUS status; /* operation status */
UINT8 handle; /* device handle */
@ -227,14 +219,12 @@ typedef struct
typedef tBTA_HH_CONN tBTA_HH_DEV_INFO;
/* callback event data */
typedef struct
{
typedef struct {
tBTA_HH_STATUS status; /* operation status */
UINT8 handle; /* device handle */
} tBTA_HH_CBDATA;
enum
{
enum {
BTA_HH_MOD_CTRL_KEY,
BTA_HH_MOD_SHFT_KEY,
BTA_HH_MOD_ALT_KEY,
@ -243,8 +233,7 @@ enum
};
/* parsed boot mode keyboard report */
typedef struct
{
typedef struct {
UINT8 this_char[6]; /* virtual key code */
BOOLEAN mod_key[BTA_HH_MOD_MAX_KEY];
/* ctrl, shift, Alt, GUI */
@ -257,41 +246,35 @@ typedef struct
} tBTA_HH_KEYBD_RPT;
/* parsed boot mode mouse report */
typedef struct
{
typedef struct {
UINT8 mouse_button; /* mouse button is clicked */
INT8 delta_x; /* displacement x */
INT8 delta_y; /* displacement y */
}tBTA_HH_MICE_RPT;
} tBTA_HH_MICE_RPT;
/* parsed Boot report */
typedef struct
{
typedef struct {
tBTA_HH_BOOT_RPT_ID dev_type; /* type of device report */
union
{
union {
tBTA_HH_KEYBD_RPT keybd_rpt; /* keyboard report */
tBTA_HH_MICE_RPT mice_rpt; /* mouse report */
} data_rpt;
} tBTA_HH_BOOT_RPT;
/* handshake data */
typedef struct
{
typedef struct {
tBTA_HH_STATUS status; /* handshake status */
UINT8 handle; /* device handle */
union
{
union {
tBTA_HH_PROTO_MODE proto_mode; /* GET_PROTO_EVT :protocol mode */
BT_HDR *p_rpt_data; /* GET_RPT_EVT : report data */
UINT8 idle_rate; /* GET_IDLE_EVT : idle rate */
} rsp_data;
}tBTA_HH_HSDATA;
} tBTA_HH_HSDATA;
/* union of data associated with HD callback */
typedef union
{
typedef union {
tBTA_HH_DEV_INFO dev_info; /* BTA_HH_ADD_DEV_EVT, BTA_HH_RMV_DEV_EVT */
tBTA_HH_CONN conn; /* BTA_HH_OPEN_EVT */
tBTA_HH_CBDATA dev_status; /* BTA_HH_CLOSE_EVT,

View file

@ -26,14 +26,13 @@
#include "bta_hh_api.h"
typedef struct
{
typedef struct {
UINT16 rpt_uuid;
UINT8 rpt_id;
tBTA_HH_RPT_TYPE rpt_type;
UINT8 inst_id;
UINT8 prop;
}tBTA_HH_RPT_CACHE_ENTRY;
} tBTA_HH_RPT_CACHE_ENTRY;
/*******************************************************************************
**

17
components/bt/bluedroid/bta/include/bta_sdp_api.h Executable file → Normal file
View file

@ -51,8 +51,7 @@ typedef UINT8 tBTA_SDP_STATUS;
typedef UINT16 tBTA_SDP_EVT;
/* data associated with BTA_SDP_DISCOVERY_COMP_EVT */
typedef struct
{
typedef struct {
tBTA_SDP_STATUS status;
BD_ADDR remote_addr;
tBT_UUID uuid;
@ -60,18 +59,16 @@ typedef struct
bluetooth_sdp_record records[BTA_SDP_MAX_RECORDS];
} tBTA_SDP_SEARCH_COMP;
typedef union
{
typedef union {
tBTA_SDP_STATUS status; /* BTA_SDP_SEARCH_EVT */
tBTA_SDP_SEARCH_COMP sdp_search_comp; /* BTA_SDP_SEARCH_COMP_EVT */
} tBTA_SDP;
/* SDP DM Interface callback */
typedef void (tBTA_SDP_DM_CBACK)(tBTA_SDP_EVT event, tBTA_SDP *p_data, void * user_data);
typedef void (tBTA_SDP_DM_CBACK)(tBTA_SDP_EVT event, tBTA_SDP *p_data, void *user_data);
/* MCE configuration structure */
typedef struct
{
typedef struct {
UINT16 sdp_db_size; /* The size of p_sdp_db */
tSDP_DISCOVERY_DB *p_sdp_db; /* The data buffer to keep SDP database */
} tBTA_SDP_CFG;
@ -108,7 +105,7 @@ extern tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK *p_cback);
** BTA_SDP_FAIL if internal failure.
**
*******************************************************************************/
extern tBTA_SDP_STATUS BTA_SdpSearch(BD_ADDR bd_addr,tSDP_UUID *uuid);
extern tBTA_SDP_STATUS BTA_SdpSearch(BD_ADDR bd_addr, tSDP_UUID *uuid);
/*******************************************************************************
**
@ -122,7 +119,7 @@ extern tBTA_SDP_STATUS BTA_SdpSearch(BD_ADDR bd_addr,tSDP_UUID *uuid);
** BTA_SDP_FAILURE, otherwise.
**
*******************************************************************************/
extern tBTA_SDP_STATUS BTA_SdpCreateRecordByUser(void* user_data);
extern tBTA_SDP_STATUS BTA_SdpCreateRecordByUser(void *user_data);
/*******************************************************************************
**
@ -136,7 +133,7 @@ extern tBTA_SDP_STATUS BTA_SdpCreateRecordByUser(void* user_data);
** BTA_SDP_FAILURE, otherwise.
**
*******************************************************************************/
extern tBTA_SDP_STATUS BTA_SdpRemoveRecordByUser(void* user_data);
extern tBTA_SDP_STATUS BTA_SdpRemoveRecordByUser(void *user_data);
#ifdef __cplusplus
}

View file

@ -42,8 +42,7 @@ typedef void (tBTA_SYS_DISABLE)(void);
/* HW modules */
enum
{
enum {
BTA_SYS_HW_BLUETOOTH,
BTA_SYS_HW_RT,
@ -137,7 +136,7 @@ typedef UINT8 tBTA_SYS_CONN_STATUS;
typedef UINT8 tBTA_SYS_PREF_ROLES;
/* conn callback for role / low power manager*/
typedef void (tBTA_SYS_CONN_CBACK)(tBTA_SYS_CONN_STATUS status,UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
typedef void (tBTA_SYS_CONN_CBACK)(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
/* conn callback for role / low power manager*/
typedef void (tBTA_SYS_SSR_CFG_CBACK)(UINT8 id, UINT8 app_id, UINT16 latency, UINT16 tout);
@ -148,15 +147,13 @@ typedef void (tBTA_SYS_EIR_CBACK)(UINT16 uuid16, BOOLEAN adding);
#endif
/* registration structure */
typedef struct
{
typedef struct {
tBTA_SYS_EVT_HDLR *evt_hdlr;
tBTA_SYS_DISABLE *disable;
} tBTA_SYS_REG;
/* data type to send events to BTA SYS HW manager */
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_SYS_HW_MODULE hw_module;
} tBTA_SYS_HW_MSG;
@ -180,8 +177,7 @@ extern UINT8 appl_trace_level;
*****************************************************************************/
/* events sent to SYS HW manager - must be kept synchronized with tables in bta_sys_main.c */
enum
{
enum {
/* device manager local device API events */
BTA_SYS_API_ENABLE_EVT = BTA_SYS_EVT_START(BTA_ID_SYS),
BTA_SYS_EVT_ENABLED_EVT,
@ -196,8 +192,7 @@ enum
/* SYS HW status events - returned by SYS HW manager to other modules. */
enum
{
enum {
BTA_SYS_HW_OFF_EVT,
BTA_SYS_HW_ON_EVT,
BTA_SYS_HW_STARTING_EVT,
@ -236,11 +231,11 @@ extern void bta_sys_hw_register( tBTA_SYS_HW_MODULE module, tBTA_SYS_HW_CBACK *c
extern void bta_sys_hw_unregister( tBTA_SYS_HW_MODULE module );
extern void bta_sys_rm_register(tBTA_SYS_CONN_CBACK * p_cback);
extern void bta_sys_pm_register(tBTA_SYS_CONN_CBACK * p_cback);
extern void bta_sys_rm_register(tBTA_SYS_CONN_CBACK *p_cback);
extern void bta_sys_pm_register(tBTA_SYS_CONN_CBACK *p_cback);
extern void bta_sys_policy_register(tBTA_SYS_CONN_CBACK * p_cback);
extern void bta_sys_sco_register(tBTA_SYS_CONN_CBACK * p_cback);
extern void bta_sys_policy_register(tBTA_SYS_CONN_CBACK *p_cback);
extern void bta_sys_sco_register(tBTA_SYS_CONN_CBACK *p_cback);
extern void bta_sys_conn_open(UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
@ -255,17 +250,17 @@ extern void bta_sys_idle(UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
extern void bta_sys_busy(UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
#if (BTM_SSR_INCLUDED == TRUE)
extern void bta_sys_ssr_cfg_register(tBTA_SYS_SSR_CFG_CBACK * p_cback);
extern void bta_sys_ssr_cfg_register(tBTA_SYS_SSR_CFG_CBACK *p_cback);
extern void bta_sys_chg_ssr_config (UINT8 id, UINT8 app_id, UINT16 max_latency, UINT16 min_tout);
#endif
extern void bta_sys_role_chg_register(tBTA_SYS_CONN_CBACK * p_cback);
extern void bta_sys_role_chg_register(tBTA_SYS_CONN_CBACK *p_cback);
extern void bta_sys_notify_role_chg(BD_ADDR_PTR p_bda, UINT8 new_role, UINT8 hci_status);
extern void bta_sys_collision_register(UINT8 bta_id, tBTA_SYS_CONN_CBACK *p_cback);
extern void bta_sys_notify_collision (BD_ADDR_PTR p_bda);
#if (BTA_EIR_CANNED_UUID_LIST != TRUE)
extern void bta_sys_eir_register(tBTA_SYS_EIR_CBACK * p_cback);
extern void bta_sys_eir_register(tBTA_SYS_EIR_CBACK *p_cback);
extern void bta_sys_add_uuid(UINT16 uuid16);
extern void bta_sys_remove_uuid(UINT16 uuid16);
#else

3
components/bt/bluedroid/bta/include/utl.h Executable file → Normal file
View file

@ -42,8 +42,7 @@
*****************************************************************************/
/** for utl_set_device_class() **/
typedef struct
{
typedef struct {
UINT8 minor;
UINT8 major;
UINT16 service;

14
components/bt/bluedroid/bta/sdp/bta_sdp.c Executable file → Normal file
View file

@ -44,8 +44,7 @@ tBTA_SDP_CB bta_sdp_cb;
typedef void (*tBTA_SDP_ACTION)(tBTA_SDP_MSG *p_data);
/* action function list */
const tBTA_SDP_ACTION bta_sdp_action[] =
{
const tBTA_SDP_ACTION bta_sdp_action[] = {
bta_sdp_enable, /* BTA_SDP_API_ENABLE_EVT */
bta_sdp_search, /* BTA_SDP_API_SEARCH_EVT */
bta_sdp_create_record, /* BTA_SDP_API_CREATE_RECORD_USER_EVT */
@ -61,17 +60,18 @@ const tBTA_SDP_ACTION bta_sdp_action[] =
*******************************************************************************/
BOOLEAN bta_sdp_sm_execute(BT_HDR *p_msg)
{
if(p_msg == NULL) return FALSE;
if (p_msg == NULL) {
return FALSE;
}
BOOLEAN ret = FALSE;
UINT16 action = (p_msg->event & 0x00ff);
/* execute action functions */
if(action < BTA_SDP_NUM_ACTIONS)
{
(*bta_sdp_action[action])((tBTA_SDP_MSG*)p_msg);
if (action < BTA_SDP_NUM_ACTIONS) {
(*bta_sdp_action[action])((tBTA_SDP_MSG *)p_msg);
ret = TRUE;
}
return(ret);
return (ret);
}

174
components/bt/bluedroid/bta/sdp/bta_sdp_act.c Executable file → Normal file
View file

@ -44,17 +44,23 @@
*****************************************************************************/
static const uint8_t UUID_OBEX_OBJECT_PUSH[] = {0x00, 0x00, 0x11, 0x05, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
};
static const uint8_t UUID_PBAP_PSE[] = {0x00, 0x00, 0x11, 0x2F, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
};
static const uint8_t UUID_MAP_MAS[] = {0x00, 0x00, 0x11, 0x32, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
};
static const uint8_t UUID_MAP_MNS[] = {0x00, 0x00, 0x11, 0x33, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
};
static const uint8_t UUID_SPP[] = {0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
};
static const uint8_t UUID_SAP[] = {0x00, 0x00, 0x11, 0x2D, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB};
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
};
// TODO:
// Both the fact that the UUIDs are declared in multiple places, plus the fact
// that there is a mess of UUID comparison and shortening methods will have to
@ -64,22 +70,24 @@ static const uint8_t UUID_SAP[] = {0x00, 0x00, 0x11, 0x2D, 0x00, 0x00, 0x10, 0x
#define UUID_MAX_LENGTH 16
#define IS_UUID(u1,u2) !memcmp(u1,u2,UUID_MAX_LENGTH)
static inline tBT_UUID shorten_sdp_uuid(const tBT_UUID* u)
static inline tBT_UUID shorten_sdp_uuid(const tBT_UUID *u)
{
static uint8_t bt_base_uuid[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB };
0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB
};
APPL_TRACE_DEBUG("%s() - uuid len:%d\n", __func__, u->len);
if(u->len != 16)
if (u->len != 16) {
return *u;
}
if(memcmp(&u->uu.uuid128[4], &bt_base_uuid[4], 12) != 0)
if (memcmp(&u->uu.uuid128[4], &bt_base_uuid[4], 12) != 0) {
return *u;
}
tBT_UUID su;
memset(&su, 0, sizeof(su));
if(u->uu.uuid128[0] == 0 && u->uu.uuid128[1] == 0)
{
if (u->uu.uuid128[0] == 0 && u->uu.uuid128[1] == 0) {
su.len = 2;
uint16_t u16;
memcpy(&u16, &u->uu.uuid128[2], sizeof(u16));
@ -106,29 +114,24 @@ static void bta_create_mns_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_RE
record->mns.hdr.profile_version = 0;
record->mns.supported_features = 0x0000001F; //default value if not found
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_MAP_SUPPORTED_FEATURES)) != NULL)
{
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_MAP_SUPPORTED_FEATURES)) != NULL) {
record->mns.supported_features = p_attr->attr_value.v.u32;
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL)
{
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL) {
record->mns.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
record->mns.hdr.service_name = (char *)p_attr->attr_value.v.array;
}
if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_MAP_PROFILE, &pversion))
{
if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_MAP_PROFILE, &pversion)) {
record->mns.hdr.profile_version = pversion;
}
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe))
{
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe)) {
record->mns.hdr.rfcomm_channel_number = pe.params[0];
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_GOEP_L2CAP_PSM)) != NULL)
{
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_GOEP_L2CAP_PSM)) != NULL) {
record->mns.hdr.l2cap_psm = p_attr->attr_value.v.u16;
}
}
@ -149,39 +152,32 @@ static void bta_create_mas_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_RE
record->mas.supported_features = 0x0000001F;
record->mas.supported_message_types = 0;
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_MAS_INSTANCE_ID)) != NULL)
{
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_MAS_INSTANCE_ID)) != NULL) {
record->mas.mas_instance_id = p_attr->attr_value.v.u8;
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SUPPORTED_MSG_TYPE)) != NULL)
{
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SUPPORTED_MSG_TYPE)) != NULL) {
record->mas.supported_message_types = p_attr->attr_value.v.u8;
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_MAP_SUPPORTED_FEATURES)) != NULL)
{
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_MAP_SUPPORTED_FEATURES)) != NULL) {
record->mas.supported_features = p_attr->attr_value.v.u32;
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL)
{
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL) {
record->mas.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
record->mas.hdr.service_name = (char *)p_attr->attr_value.v.array;
}
if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_MAP_PROFILE, &pversion))
{
if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_MAP_PROFILE, &pversion)) {
record->mas.hdr.profile_version = pversion;
}
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe))
{
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe)) {
record->mas.hdr.rfcomm_channel_number = pe.params[0];
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_GOEP_L2CAP_PSM)) != NULL)
{
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_GOEP_L2CAP_PSM)) != NULL) {
record->mas.hdr.l2cap_psm = p_attr->attr_value.v.u16;
}
}
@ -201,33 +197,27 @@ static void bta_create_pse_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_RE
record->pse.supported_features = 0x00000003;
record->pse.supported_repositories = 0;
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SUPPORTED_REPOSITORIES)) != NULL)
{
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SUPPORTED_REPOSITORIES)) != NULL) {
record->pse.supported_repositories = p_attr->attr_value.v.u8;
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_PBAP_SUPPORTED_FEATURES)) != NULL)
{
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_PBAP_SUPPORTED_FEATURES)) != NULL) {
record->pse.supported_features = p_attr->attr_value.v.u32;
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL)
{
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL) {
record->pse.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
record->pse.hdr.service_name = (char *)p_attr->attr_value.v.array;
}
if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_PHONE_ACCESS, &pversion))
{
if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_PHONE_ACCESS, &pversion)) {
record->pse.hdr.profile_version = pversion;
}
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe))
{
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe)) {
record->pse.hdr.rfcomm_channel_number = pe.params[0];
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_GOEP_L2CAP_PSM)) != NULL)
{
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_GOEP_L2CAP_PSM)) != NULL) {
record->pse.hdr.l2cap_psm = p_attr->attr_value.v.u16;
}
}
@ -246,28 +236,23 @@ static void bta_create_ops_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_RE
record->ops.hdr.profile_version = 0;
record->ops.supported_formats_list_len = 0;
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL)
{
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL) {
record->ops.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
record->ops.hdr.service_name = (char *)p_attr->attr_value.v.array;
}
if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_OBEX_OBJECT_PUSH, &pversion))
{
if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_OBEX_OBJECT_PUSH, &pversion)) {
record->ops.hdr.profile_version = pversion;
}
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe))
{
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe)) {
record->ops.hdr.rfcomm_channel_number = pe.params[0];
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_GOEP_L2CAP_PSM)) != NULL)
{
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_GOEP_L2CAP_PSM)) != NULL) {
record->ops.hdr.l2cap_psm = p_attr->attr_value.v.u16;
}
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SUPPORTED_FORMATS_LIST)) != NULL)
{
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SUPPORTED_FORMATS_LIST)) != NULL) {
/* Safety check - each entry should itself be a sequence */
if (SDP_DISC_ATTR_TYPE(p_attr->attr_len_type) != DATA_ELE_SEQ_DESC_TYPE) {
record->ops.supported_formats_list_len = 0;
@ -276,15 +261,13 @@ static void bta_create_ops_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_RE
} else {
int count = 0;
/* 1 byte for type/length 1 byte for value */
record->ops.supported_formats_list_len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type)/2;
record->ops.supported_formats_list_len = SDP_DISC_ATTR_LEN(p_attr->attr_len_type) / 2;
/* Extract each value into */
for (p_sattr = p_attr->attr_value.v.p_sub_attr;
p_sattr != NULL; p_sattr = p_sattr->p_next_attr)
{
p_sattr != NULL; p_sattr = p_sattr->p_next_attr) {
if ((SDP_DISC_ATTR_TYPE(p_sattr->attr_len_type) == UINT_DESC_TYPE)
&& (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 1))
{
&& (SDP_DISC_ATTR_LEN(p_sattr->attr_len_type) == 1)) {
if (count == sizeof(record->ops.supported_formats_list)) {
APPL_TRACE_ERROR("%s() - supported_formats_list - count overflow - "
"too many sub attributes!!\n", __func__);
@ -327,19 +310,16 @@ static void bta_create_sap_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_RE
record->sap.hdr.l2cap_psm = -1;
record->sap.hdr.profile_version = 0;
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL)
{
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL) {
record->sap.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
record->sap.hdr.service_name = (char *)p_attr->attr_value.v.array;
}
if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_SAP, &pversion))
{
if (SDP_FindProfileVersionInRec(p_rec, UUID_SERVCLASS_SAP, &pversion)) {
record->sap.hdr.profile_version = pversion;
}
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe))
{
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe)) {
record->sap.hdr.rfcomm_channel_number = pe.params[0];
}
}
@ -357,15 +337,13 @@ static void bta_create_raw_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_RE
record->hdr.profile_version = -1;
/* Try to extract a service name */
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL)
{
if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) != NULL) {
record->pse.hdr.service_name_length = SDP_DISC_ATTR_LEN(p_attr->attr_len_type);
record->pse.hdr.service_name = (char *)p_attr->attr_value.v.array;
}
/* Try to extract an RFCOMM channel */
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe))
{
if (SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe)) {
record->pse.hdr.rfcomm_channel_number = pe.params[0];
}
record->hdr.user1_ptr_len = p_bta_sdp_cfg->p_sdp_db->raw_size;
@ -382,7 +360,7 @@ static void bta_create_raw_sdp_record(bluetooth_sdp_record *record, tSDP_DISC_RE
** Returns void
**
*******************************************************************************/
static void bta_sdp_search_cback(UINT16 result, void * user_data)
static void bta_sdp_search_cback(UINT16 result, void *user_data)
{
tSDP_DISC_REC *p_rec = NULL;
tBTA_SDP_SEARCH_COMP evt_data = {0}; // We need to zero-initialize
@ -393,33 +371,34 @@ static void bta_sdp_search_cback(UINT16 result, void * user_data)
bta_sdp_cb.sdp_active = BTA_SDP_ACTIVE_NONE;
if (bta_sdp_cb.p_dm_cback == NULL) return;
if (bta_sdp_cb.p_dm_cback == NULL) {
return;
}
bdcpy(evt_data.remote_addr, bta_sdp_cb.remote_addr);
tBT_UUID *uuid = (tBT_UUID*)user_data;
tBT_UUID *uuid = (tBT_UUID *)user_data;
memcpy(&evt_data.uuid, uuid, sizeof(tBT_UUID));
su = shorten_sdp_uuid(uuid);
if (result == SDP_SUCCESS || result == SDP_DB_FULL)
{
if (result == SDP_SUCCESS || result == SDP_DB_FULL) {
do {
p_rec = SDP_FindServiceUUIDInDb(p_bta_sdp_cfg->p_sdp_db, &su, p_rec);
/* generate the matching record data pointer */
if(p_rec != NULL){
if (p_rec != NULL) {
status = BTA_SDP_SUCCESS;
if (IS_UUID(UUID_MAP_MAS,uuid->uu.uuid128)) {
if (IS_UUID(UUID_MAP_MAS, uuid->uu.uuid128)) {
APPL_TRACE_DEBUG("%s() - found MAP (MAS) uuid\n", __func__);
bta_create_mas_sdp_record(&evt_data.records[count], p_rec);
} else if (IS_UUID(UUID_MAP_MNS,uuid->uu.uuid128)) {
} else if (IS_UUID(UUID_MAP_MNS, uuid->uu.uuid128)) {
APPL_TRACE_DEBUG("%s() - found MAP (MNS) uuid\n", __func__);
bta_create_mns_sdp_record(&evt_data.records[count], p_rec);
} else if (IS_UUID(UUID_PBAP_PSE,uuid->uu.uuid128)){
} else if (IS_UUID(UUID_PBAP_PSE, uuid->uu.uuid128)) {
APPL_TRACE_DEBUG("%s() - found PBAP (PSE) uuid\n", __func__);
bta_create_pse_sdp_record(&evt_data.records[count], p_rec);
} else if (IS_UUID(UUID_OBEX_OBJECT_PUSH,uuid->uu.uuid128)){
} else if (IS_UUID(UUID_OBEX_OBJECT_PUSH, uuid->uu.uuid128)) {
APPL_TRACE_DEBUG("%s() - found Object Push Server (OPS) uuid\n", __func__);
bta_create_ops_sdp_record(&evt_data.records[count], p_rec);
} else if (IS_UUID(UUID_SAP,uuid->uu.uuid128)) {
} else if (IS_UUID(UUID_SAP, uuid->uu.uuid128)) {
APPL_TRACE_DEBUG("%s() - found SAP uuid\n", __func__);
bta_create_sap_sdp_record(&evt_data.records[count], p_rec);
} else {
@ -444,7 +423,7 @@ static void bta_sdp_search_cback(UINT16 result, void * user_data)
}
evt_data.status = status;
bta_sdp_cb.p_dm_cback(BTA_SDP_SEARCH_COMP_EVT, (tBTA_SDP*) &evt_data, (void*)&uuid->uu.uuid128);
bta_sdp_cb.p_dm_cback(BTA_SDP_SEARCH_COMP_EVT, (tBTA_SDP *) &evt_data, (void *)&uuid->uu.uuid128);
osi_free(user_data); // We no longer need the user data to track the search
}
@ -476,11 +455,10 @@ void bta_sdp_enable(tBTA_SDP_MSG *p_data)
*******************************************************************************/
void bta_sdp_search(tBTA_SDP_MSG *p_data)
{
int x=0;
int x = 0;
// TODO: Leaks!!! but needed as user-data pointer
tBT_UUID *bta_sdp_search_uuid = osi_malloc(sizeof(tBT_UUID));
if(p_data == NULL)
{
if (p_data == NULL) {
APPL_TRACE_DEBUG("SDP control block handle is null\n");
return;
}
@ -488,11 +466,10 @@ void bta_sdp_search(tBTA_SDP_MSG *p_data)
APPL_TRACE_DEBUG("%s in, sdp_active:%d\n", __func__, bta_sdp_cb.sdp_active);
if (bta_sdp_cb.sdp_active != BTA_SDP_ACTIVE_NONE)
{
if (bta_sdp_cb.sdp_active != BTA_SDP_ACTIVE_NONE) {
/* SDP is still in progress */
status = BTA_SDP_BUSY;
if(bta_sdp_cb.p_dm_cback) {
if (bta_sdp_cb.p_dm_cback) {
tBTA_SDP_SEARCH_COMP result = {0};
result.uuid = p_data->get_search.uuid;
bdcpy(result.remote_addr, p_data->get_search.bd_addr);
@ -505,20 +482,19 @@ void bta_sdp_search(tBTA_SDP_MSG *p_data)
bta_sdp_cb.sdp_active = BTA_SDP_ACTIVE_YES;
bdcpy(bta_sdp_cb.remote_addr, p_data->get_search.bd_addr);
/* set the uuid used in the search */
memcpy(bta_sdp_search_uuid, &(p_data->get_search.uuid),sizeof(tBT_UUID));
memcpy(bta_sdp_search_uuid, &(p_data->get_search.uuid), sizeof(tBT_UUID));
/* initialize the search for the uuid */
APPL_TRACE_DEBUG("%s init discovery with UUID(len: %d):\n",
__func__, bta_sdp_search_uuid->len);
for(x = 0; x<bta_sdp_search_uuid->len;x++){
APPL_TRACE_DEBUG("%X",bta_sdp_search_uuid->uu.uuid128[x]);
for (x = 0; x < bta_sdp_search_uuid->len; x++) {
APPL_TRACE_DEBUG("%X", bta_sdp_search_uuid->uu.uuid128[x]);
}
SDP_InitDiscoveryDb (p_bta_sdp_cfg->p_sdp_db, p_bta_sdp_cfg->sdp_db_size, 1,
bta_sdp_search_uuid, 0, NULL);
if (!SDP_ServiceSearchAttributeRequest2(p_data->get_search.bd_addr, p_bta_sdp_cfg->p_sdp_db,
bta_sdp_search_cback, (void*)bta_sdp_search_uuid))
{
bta_sdp_search_cback, (void *)bta_sdp_search_uuid)) {
bta_sdp_cb.sdp_active = BTA_SDP_ACTIVE_NONE;
/* failed to start SDP. report the failure right away */
@ -547,8 +523,9 @@ void bta_sdp_search(tBTA_SDP_MSG *p_data)
void bta_sdp_create_record(tBTA_SDP_MSG *p_data)
{
APPL_TRACE_DEBUG("%s() event: %d\n", __func__, p_data->record.hdr.event);
if (bta_sdp_cb.p_dm_cback)
if (bta_sdp_cb.p_dm_cback) {
bta_sdp_cb.p_dm_cback(BTA_SDP_CREATE_RECORD_USER_EVT, NULL, p_data->record.user_data);
}
}
/*******************************************************************************
@ -563,6 +540,7 @@ void bta_sdp_create_record(tBTA_SDP_MSG *p_data)
void bta_sdp_remove_record(tBTA_SDP_MSG *p_data)
{
APPL_TRACE_DEBUG("%s() event: %d\n", __func__, p_data->record.hdr.event);
if (bta_sdp_cb.p_dm_cback)
if (bta_sdp_cb.p_dm_cback) {
bta_sdp_cb.p_dm_cback(BTA_SDP_REMOVE_RECORD_USER_EVT, NULL, p_data->record.user_data);
}
}

30
components/bt/bluedroid/bta/sdp/bta_sdp_api.c Executable file → Normal file
View file

@ -35,8 +35,7 @@
** Constants
*****************************************************************************/
static const tBTA_SYS_REG bta_sdp_reg =
{
static const tBTA_SYS_REG bta_sdp_reg = {
bta_sdp_sm_execute,
NULL
};
@ -61,23 +60,21 @@ tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK *p_cback)
tBTA_SDP_API_ENABLE *p_buf;
APPL_TRACE_API(__FUNCTION__);
if(p_cback && FALSE == bta_sys_is_register(BTA_ID_SDP))
{
if (p_cback && FALSE == bta_sys_is_register(BTA_ID_SDP)) {
memset(&bta_sdp_cb, 0, sizeof(tBTA_SDP_CB));
/* register with BTA system manager */
bta_sys_register(BTA_ID_SDP, &bta_sdp_reg);
if (p_cback &&
(p_buf = (tBTA_SDP_API_ENABLE *) GKI_getbuf(sizeof(tBTA_SDP_API_ENABLE))) != NULL)
{
(p_buf = (tBTA_SDP_API_ENABLE *) GKI_getbuf(sizeof(tBTA_SDP_API_ENABLE))) != NULL) {
p_buf->hdr.event = BTA_SDP_API_ENABLE_EVT;
p_buf->p_cback = p_cback;
bta_sys_sendmsg(p_buf);
status = BTA_SDP_SUCCESS;
}
}
return(status);
return (status);
}
/*******************************************************************************
@ -99,8 +96,7 @@ tBTA_SDP_STATUS BTA_SdpSearch(BD_ADDR bd_addr, tSDP_UUID *uuid)
tBTA_SDP_API_SEARCH *p_msg;
APPL_TRACE_API(__FUNCTION__);
if ((p_msg = (tBTA_SDP_API_SEARCH *)GKI_getbuf(sizeof(tBTA_SDP_API_SEARCH))) != NULL)
{
if ((p_msg = (tBTA_SDP_API_SEARCH *)GKI_getbuf(sizeof(tBTA_SDP_API_SEARCH))) != NULL) {
p_msg->hdr.event = BTA_SDP_API_SEARCH_EVT;
bdcpy(p_msg->bd_addr, bd_addr);
//p_msg->uuid = uuid;
@ -109,7 +105,7 @@ tBTA_SDP_STATUS BTA_SdpSearch(BD_ADDR bd_addr, tSDP_UUID *uuid)
ret = BTA_SDP_SUCCESS;
}
return(ret);
return (ret);
}
/*******************************************************************************
@ -124,21 +120,20 @@ tBTA_SDP_STATUS BTA_SdpSearch(BD_ADDR bd_addr, tSDP_UUID *uuid)
** BTA_SDP_FAILURE, otherwise.
**
*******************************************************************************/
tBTA_SDP_STATUS BTA_SdpCreateRecordByUser(void* user_data)
tBTA_SDP_STATUS BTA_SdpCreateRecordByUser(void *user_data)
{
tBTA_SDP_STATUS ret = BTA_SDP_FAILURE;
tBTA_SDP_API_RECORD_USER *p_msg;
APPL_TRACE_API(__FUNCTION__);
if ((p_msg = (tBTA_SDP_API_RECORD_USER *)GKI_getbuf(sizeof(tBTA_SDP_API_RECORD_USER))) != NULL)
{
if ((p_msg = (tBTA_SDP_API_RECORD_USER *)GKI_getbuf(sizeof(tBTA_SDP_API_RECORD_USER))) != NULL) {
p_msg->hdr.event = BTA_SDP_API_CREATE_RECORD_USER_EVT;
p_msg->user_data = user_data;
bta_sys_sendmsg(p_msg);
ret = BTA_SDP_SUCCESS;
}
return(ret);
return (ret);
}
/*******************************************************************************
@ -153,21 +148,20 @@ tBTA_SDP_STATUS BTA_SdpCreateRecordByUser(void* user_data)
** BTA_SDP_FAILURE, otherwise.
**
*******************************************************************************/
tBTA_SDP_STATUS BTA_SdpRemoveRecordByUser(void* user_data)
tBTA_SDP_STATUS BTA_SdpRemoveRecordByUser(void *user_data)
{
tBTA_SDP_STATUS ret = BTA_SDP_FAILURE;
tBTA_SDP_API_RECORD_USER *p_msg;
APPL_TRACE_API(__FUNCTION__);
if ((p_msg = (tBTA_SDP_API_RECORD_USER *)GKI_getbuf(sizeof(tBTA_SDP_API_RECORD_USER))) != NULL)
{
if ((p_msg = (tBTA_SDP_API_RECORD_USER *)GKI_getbuf(sizeof(tBTA_SDP_API_RECORD_USER))) != NULL) {
p_msg->hdr.event = BTA_SDP_API_REMOVE_RECORD_USER_EVT;
p_msg->user_data = user_data;
bta_sys_sendmsg(p_msg);
ret = BTA_SDP_SUCCESS;
}
return(ret);
return (ret);
}

3
components/bt/bluedroid/bta/sdp/bta_sdp_cfg.c Executable file → Normal file
View file

@ -31,8 +31,7 @@
static UINT8 __attribute__ ((aligned(4))) bta_sdp_db_data[BTA_SDP_DB_SIZE];
/* SDP configuration structure */
const tBTA_SDP_CFG bta_sdp_cfg =
{
const tBTA_SDP_CFG bta_sdp_cfg = {
BTA_SDP_DB_SIZE,
(tSDP_DISCOVERY_DB *)bta_sdp_db_data /* The data buffer to keep SDP database */
};

23
components/bt/bluedroid/bta/sdp/bta_sdp_int.h Executable file → Normal file
View file

@ -35,8 +35,7 @@
** Constants
*****************************************************************************/
enum
{
enum {
/* these events are handled by the state machine */
BTA_SDP_API_ENABLE_EVT = BTA_SYS_EVT_START(BTA_ID_SDP),
BTA_SDP_API_SEARCH_EVT,
@ -45,8 +44,7 @@ enum
BTA_SDP_MAX_INT_EVT
};
enum
{
enum {
BTA_SDP_ACTIVE_NONE = 0,
BTA_SDP_ACTIVE_YES /* waiting for SDP result */
};
@ -54,30 +52,26 @@ enum
/* data type for BTA_SDP_API_ENABLE_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
tBTA_SDP_DM_CBACK *p_cback;
} tBTA_SDP_API_ENABLE;
/* data type for BTA_SDP_API_SEARCH_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
BD_ADDR bd_addr;
tSDP_UUID uuid;
} tBTA_SDP_API_SEARCH;
/* data type for BTA_SDP_API_SEARCH_EVT */
typedef struct
{
typedef struct {
BT_HDR hdr;
void* user_data;
void *user_data;
} tBTA_SDP_API_RECORD_USER;
/* union of all data types */
typedef union
{
typedef union {
/* GKI event buffer header */
BT_HDR hdr;
tBTA_SDP_API_ENABLE enable;
@ -86,8 +80,7 @@ typedef union
} tBTA_SDP_MSG;
/* SDP control block */
typedef struct
{
typedef struct {
UINT8 sdp_active; /* see BTA_SDP_SDP_ACT_* */
BD_ADDR remote_addr;
tBTA_SDP_DM_CBACK *p_dm_cback;

101
components/bt/bluedroid/bta/sys/bta_sys_conn.c Executable file → Normal file
View file

@ -39,7 +39,7 @@
** Returns void
**
*******************************************************************************/
void bta_sys_rm_register(tBTA_SYS_CONN_CBACK * p_cback)
void bta_sys_rm_register(tBTA_SYS_CONN_CBACK *p_cback)
{
bta_sys_cb.prm_cb = p_cback;
}
@ -55,7 +55,7 @@ void bta_sys_rm_register(tBTA_SYS_CONN_CBACK * p_cback)
** Returns void
**
*******************************************************************************/
void bta_sys_policy_register(tBTA_SYS_CONN_CBACK * p_cback)
void bta_sys_policy_register(tBTA_SYS_CONN_CBACK *p_cback)
{
bta_sys_cb.p_policy_cb = p_cback;
}
@ -70,7 +70,7 @@ void bta_sys_policy_register(tBTA_SYS_CONN_CBACK * p_cback)
** Returns void
**
*******************************************************************************/
void bta_sys_role_chg_register(tBTA_SYS_CONN_CBACK * p_cback)
void bta_sys_role_chg_register(tBTA_SYS_CONN_CBACK *p_cback)
{
bta_sys_cb.p_role_cb = p_cback;
}
@ -85,7 +85,7 @@ void bta_sys_role_chg_register(tBTA_SYS_CONN_CBACK * p_cback)
**
*******************************************************************************/
#if (BTM_SSR_INCLUDED == TRUE)
void bta_sys_ssr_cfg_register(tBTA_SYS_SSR_CFG_CBACK * p_cback)
void bta_sys_ssr_cfg_register(tBTA_SYS_SSR_CFG_CBACK *p_cback)
{
bta_sys_cb.p_ssr_cb = p_cback;
}
@ -102,8 +102,7 @@ void bta_sys_ssr_cfg_register(tBTA_SYS_SSR_CFG_CBACK * p_cback)
*******************************************************************************/
void bta_sys_notify_role_chg(BD_ADDR_PTR p_bda, UINT8 new_role, UINT8 hci_status)
{
if (bta_sys_cb.p_role_cb)
{
if (bta_sys_cb.p_role_cb) {
bta_sys_cb.p_role_cb(BTA_SYS_ROLE_CHANGE, new_role, hci_status, p_bda);
}
}
@ -122,11 +121,9 @@ void bta_sys_collision_register(UINT8 bta_id, tBTA_SYS_CONN_CBACK *p_cback)
{
UINT8 index;
for (index = 0; index < MAX_COLLISION_REG; index++)
{
for (index = 0; index < MAX_COLLISION_REG; index++) {
if ((bta_sys_cb.colli_reg.id[index] == bta_id) ||
(bta_sys_cb.colli_reg.id[index] == 0))
{
(bta_sys_cb.colli_reg.id[index] == 0)) {
bta_sys_cb.colli_reg.id[index] = bta_id;
bta_sys_cb.colli_reg.p_coll_cback[index] = p_cback;
return;
@ -148,11 +145,9 @@ void bta_sys_notify_collision (BD_ADDR_PTR p_bda)
{
UINT8 index;
for (index = 0; index < MAX_COLLISION_REG; index++)
{
for (index = 0; index < MAX_COLLISION_REG; index++) {
if ((bta_sys_cb.colli_reg.id[index] != 0) &&
(bta_sys_cb.colli_reg.p_coll_cback[index] != NULL))
{
(bta_sys_cb.colli_reg.p_coll_cback[index] != NULL)) {
bta_sys_cb.colli_reg.p_coll_cback[index] (0, BTA_ID_SYS, 0, p_bda);
}
}
@ -168,7 +163,7 @@ void bta_sys_notify_collision (BD_ADDR_PTR p_bda)
** Returns void
**
*******************************************************************************/
void bta_sys_sco_register(tBTA_SYS_CONN_CBACK * p_cback)
void bta_sys_sco_register(tBTA_SYS_CONN_CBACK *p_cback)
{
bta_sys_cb.p_sco_cb = p_cback;
}
@ -183,7 +178,7 @@ void bta_sys_sco_register(tBTA_SYS_CONN_CBACK * p_cback)
** Returns void
**
*******************************************************************************/
void bta_sys_pm_register(tBTA_SYS_CONN_CBACK * p_cback)
void bta_sys_pm_register(tBTA_SYS_CONN_CBACK *p_cback)
{
bta_sys_cb.ppm_cb = p_cback;
}
@ -201,15 +196,13 @@ void bta_sys_pm_register(tBTA_SYS_CONN_CBACK * p_cback)
*******************************************************************************/
void bta_sys_conn_open(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
{
if(bta_sys_cb.prm_cb)
{
if (bta_sys_cb.prm_cb) {
bta_sys_cb.prm_cb(BTA_SYS_CONN_OPEN, id, app_id, peer_addr);
}
if(bta_sys_cb.ppm_cb)
{
if (bta_sys_cb.ppm_cb) {
bta_sys_cb.ppm_cb(BTA_SYS_CONN_OPEN, id, app_id, peer_addr);
@ -231,15 +224,13 @@ void bta_sys_conn_open(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
*******************************************************************************/
void bta_sys_conn_close(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
{
if(bta_sys_cb.prm_cb)
{
if (bta_sys_cb.prm_cb) {
bta_sys_cb.prm_cb(BTA_SYS_CONN_CLOSE, id, app_id, peer_addr);
}
if(bta_sys_cb.ppm_cb)
{
if (bta_sys_cb.ppm_cb) {
bta_sys_cb.ppm_cb(BTA_SYS_CONN_CLOSE, id, app_id, peer_addr);
@ -260,8 +251,7 @@ void bta_sys_conn_close(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
*******************************************************************************/
void bta_sys_app_open(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
{
if(bta_sys_cb.ppm_cb)
{
if (bta_sys_cb.ppm_cb) {
bta_sys_cb.ppm_cb(BTA_SYS_APP_OPEN, id, app_id, peer_addr);
}
}
@ -280,8 +270,7 @@ void bta_sys_app_open(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
*******************************************************************************/
void bta_sys_app_close(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
{
if(bta_sys_cb.ppm_cb)
{
if (bta_sys_cb.ppm_cb) {
bta_sys_cb.ppm_cb(BTA_SYS_APP_CLOSE, id, app_id, peer_addr);
}
}
@ -300,14 +289,12 @@ void bta_sys_app_close(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
void bta_sys_sco_open(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
{
/* AG triggers p_sco_cb by bta_sys_sco_use. */
if((id != BTA_ID_AG) && (bta_sys_cb.p_sco_cb))
{
if ((id != BTA_ID_AG) && (bta_sys_cb.p_sco_cb)) {
/* without querying BTM_GetNumScoLinks() */
bta_sys_cb.p_sco_cb(BTA_SYS_SCO_OPEN, 1, app_id, peer_addr);
}
if(bta_sys_cb.ppm_cb)
{
if (bta_sys_cb.ppm_cb) {
bta_sys_cb.ppm_cb(BTA_SYS_SCO_OPEN, id, app_id, peer_addr);
}
}
@ -326,14 +313,12 @@ void bta_sys_sco_close(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
{
UINT8 num_sco_links;
if((id != BTA_ID_AG) && (bta_sys_cb.p_sco_cb))
{
if ((id != BTA_ID_AG) && (bta_sys_cb.p_sco_cb)) {
num_sco_links = BTM_GetNumScoLinks();
bta_sys_cb.p_sco_cb(BTA_SYS_SCO_CLOSE, num_sco_links, app_id, peer_addr);
}
if(bta_sys_cb.ppm_cb)
{
if (bta_sys_cb.ppm_cb) {
bta_sys_cb.ppm_cb(BTA_SYS_SCO_CLOSE, id, app_id, peer_addr);
}
}
@ -353,8 +338,7 @@ void bta_sys_sco_use(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
UNUSED(id);
/* AV streaming need to be suspended before SCO is connected. */
if(bta_sys_cb.p_sco_cb)
{
if (bta_sys_cb.p_sco_cb) {
/* without querying BTM_GetNumScoLinks() */
bta_sys_cb.p_sco_cb(BTA_SYS_SCO_OPEN, 1, app_id, peer_addr);
}
@ -375,8 +359,7 @@ void bta_sys_sco_unuse(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
UINT8 num_sco_links;
UNUSED(id);
if((bta_sys_cb.p_sco_cb))
{
if ((bta_sys_cb.p_sco_cb)) {
num_sco_links = BTM_GetNumScoLinks();
bta_sys_cb.p_sco_cb(BTA_SYS_SCO_CLOSE, num_sco_links, app_id, peer_addr);
}
@ -394,8 +377,7 @@ void bta_sys_sco_unuse(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
#if (BTM_SSR_INCLUDED == TRUE)
void bta_sys_chg_ssr_config (UINT8 id, UINT8 app_id, UINT16 max_latency, UINT16 min_tout)
{
if(bta_sys_cb.p_ssr_cb)
{
if (bta_sys_cb.p_ssr_cb) {
bta_sys_cb.p_ssr_cb(id, app_id, max_latency, min_tout);
}
}
@ -412,8 +394,7 @@ void bta_sys_chg_ssr_config (UINT8 id, UINT8 app_id, UINT16 max_latency, UINT16
*******************************************************************************/
void bta_sys_set_policy (UINT8 id, UINT8 policy, BD_ADDR peer_addr)
{
if(bta_sys_cb.p_policy_cb)
{
if (bta_sys_cb.p_policy_cb) {
bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_SET, id, policy, peer_addr);
}
}
@ -430,8 +411,7 @@ void bta_sys_set_policy (UINT8 id, UINT8 policy, BD_ADDR peer_addr)
*******************************************************************************/
void bta_sys_clear_policy (UINT8 id, UINT8 policy, BD_ADDR peer_addr)
{
if(bta_sys_cb.p_policy_cb)
{
if (bta_sys_cb.p_policy_cb) {
bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_CLR, id, policy, peer_addr);
}
}
@ -448,8 +428,7 @@ void bta_sys_clear_policy (UINT8 id, UINT8 policy, BD_ADDR peer_addr)
*******************************************************************************/
void bta_sys_set_default_policy (UINT8 id, UINT8 policy)
{
if(bta_sys_cb.p_policy_cb)
{
if (bta_sys_cb.p_policy_cb) {
bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_DEF_SET, id, policy, NULL);
}
}
@ -466,8 +445,7 @@ void bta_sys_set_default_policy (UINT8 id, UINT8 policy)
*******************************************************************************/
void bta_sys_clear_default_policy (UINT8 id, UINT8 policy)
{
if(bta_sys_cb.p_policy_cb)
{
if (bta_sys_cb.p_policy_cb) {
bta_sys_cb.p_policy_cb(BTA_SYS_PLCY_DEF_CLR, id, policy, NULL);
}
}
@ -485,15 +463,13 @@ void bta_sys_clear_default_policy (UINT8 id, UINT8 policy)
void bta_sys_idle(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
{
if(bta_sys_cb.prm_cb)
{
if (bta_sys_cb.prm_cb) {
bta_sys_cb.prm_cb(BTA_SYS_CONN_IDLE, id, app_id, peer_addr);
}
if(bta_sys_cb.ppm_cb)
{
if (bta_sys_cb.ppm_cb) {
bta_sys_cb.ppm_cb(BTA_SYS_CONN_IDLE, id, app_id, peer_addr);
}
@ -511,15 +487,13 @@ void bta_sys_idle(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
*******************************************************************************/
void bta_sys_busy(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
{
if(bta_sys_cb.prm_cb)
{
if (bta_sys_cb.prm_cb) {
bta_sys_cb.prm_cb(BTA_SYS_CONN_BUSY, id, app_id, peer_addr);
}
if(bta_sys_cb.ppm_cb)
{
if (bta_sys_cb.ppm_cb) {
bta_sys_cb.ppm_cb(BTA_SYS_CONN_BUSY, id, app_id, peer_addr);
@ -537,7 +511,7 @@ void bta_sys_busy(UINT8 id, UINT8 app_id, BD_ADDR peer_addr)
** Returns void
**
*******************************************************************************/
void bta_sys_eir_register(tBTA_SYS_EIR_CBACK * p_cback)
void bta_sys_eir_register(tBTA_SYS_EIR_CBACK *p_cback)
{
bta_sys_cb.eir_cb = p_cback;
}
@ -554,8 +528,7 @@ void bta_sys_eir_register(tBTA_SYS_EIR_CBACK * p_cback)
*******************************************************************************/
void bta_sys_add_uuid(UINT16 uuid16)
{
if(bta_sys_cb.eir_cb)
{
if (bta_sys_cb.eir_cb) {
bta_sys_cb.eir_cb(uuid16, TRUE );
}
}
@ -572,8 +545,7 @@ void bta_sys_add_uuid(UINT16 uuid16)
*******************************************************************************/
void bta_sys_remove_uuid(UINT16 uuid16)
{
if(bta_sys_cb.eir_cb)
{
if (bta_sys_cb.eir_cb) {
bta_sys_cb.eir_cb(uuid16, FALSE);
}
}
@ -590,8 +562,9 @@ void bta_sys_remove_uuid(UINT16 uuid16)
*******************************************************************************/
BOOLEAN bta_sys_vs_hdl(UINT16 evt, void *p)
{
if (bta_sys_cb.p_vs_evt_hdlr)
if (bta_sys_cb.p_vs_evt_hdlr) {
return (*bta_sys_cb.p_vs_evt_hdlr)(evt, p);
}
return FALSE;
}

197
components/bt/bluedroid/bta/sys/bta_sys_main.c Executable file → Normal file
View file

@ -66,8 +66,7 @@ UINT8 btif_trace_level = BT_TRACE_LEVEL_NONE;
extern fixed_queue_t *btu_bta_msg_queue;
void btu_bta_alarm_ready(fixed_queue_t *queue);
static const tBTA_SYS_REG bta_sys_hw_reg =
{
static const tBTA_SYS_REG bta_sys_hw_reg = {
bta_sys_sm_execute,
NULL
};
@ -77,8 +76,7 @@ static const tBTA_SYS_REG bta_sys_hw_reg =
typedef void (*tBTA_SYS_ACTION)(tBTA_SYS_HW_MSG *p_data);
/* action function list */
const tBTA_SYS_ACTION bta_sys_action[] =
{
const tBTA_SYS_ACTION bta_sys_action[] = {
/* device manager local device API events - cf bta_sys.h for events */
bta_sys_hw_api_enable, /* 0 BTA_SYS_HW_API_ENABLE_EVT */
bta_sys_hw_evt_enabled, /* 1 BTA_SYS_HW_EVT_ENABLED_EVT */
@ -89,8 +87,7 @@ const tBTA_SYS_ACTION bta_sys_action[] =
};
/* state machine action enumeration list */
enum
{
enum {
/* device manager local device API events */
BTA_SYS_HW_API_ENABLE,
BTA_SYS_HW_EVT_ENABLED,
@ -110,48 +107,44 @@ enum
/* state table for OFF state */
const UINT8 bta_sys_hw_off[][BTA_SYS_NUM_COLS] =
{
/* Event Action 1 Action 2 Next State */
/* API_ENABLE */ {BTA_SYS_HW_API_ENABLE, BTA_SYS_IGNORE, BTA_SYS_HW_STARTING},
/* EVT_ENABLED */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_STARTING},
/* STACK_ENABLED */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_ON},
/* API_DISABLE */ {BTA_SYS_HW_EVT_DISABLED, BTA_SYS_IGNORE, BTA_SYS_HW_OFF},
/* EVT_DISABLED */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_OFF},
/* EVT_ERROR */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_OFF}
const UINT8 bta_sys_hw_off[][BTA_SYS_NUM_COLS] = {
/* Event Action 1 Action 2 Next State */
/* API_ENABLE */ {BTA_SYS_HW_API_ENABLE, BTA_SYS_IGNORE, BTA_SYS_HW_STARTING},
/* EVT_ENABLED */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_STARTING},
/* STACK_ENABLED */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_ON},
/* API_DISABLE */ {BTA_SYS_HW_EVT_DISABLED, BTA_SYS_IGNORE, BTA_SYS_HW_OFF},
/* EVT_DISABLED */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_OFF},
/* EVT_ERROR */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_OFF}
};
const UINT8 bta_sys_hw_starting[][BTA_SYS_NUM_COLS] =
{
/* Event Action 1 Action 2 Next State */
/* API_ENABLE */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_STARTING}, /* wait for completion event */
/* EVT_ENABLED */ {BTA_SYS_HW_EVT_ENABLED, BTA_SYS_IGNORE, BTA_SYS_HW_STARTING},
/* STACK_ENABLED */ {BTA_SYS_HW_EVT_STACK_ENABLED, BTA_SYS_IGNORE, BTA_SYS_HW_ON},
/* API_DISABLE */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_STOPPING}, /* successive disable/enable: change state wait for completion to disable */
/* EVT_DISABLED */ {BTA_SYS_HW_EVT_DISABLED, BTA_SYS_HW_API_ENABLE, BTA_SYS_HW_STARTING}, /* successive enable/disable: notify, then restart HW */
/* EVT_ERROR */ {BTA_SYS_HW_ERROR, BTA_SYS_IGNORE, BTA_SYS_HW_ON}
const UINT8 bta_sys_hw_starting[][BTA_SYS_NUM_COLS] = {
/* Event Action 1 Action 2 Next State */
/* API_ENABLE */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_STARTING}, /* wait for completion event */
/* EVT_ENABLED */ {BTA_SYS_HW_EVT_ENABLED, BTA_SYS_IGNORE, BTA_SYS_HW_STARTING},
/* STACK_ENABLED */ {BTA_SYS_HW_EVT_STACK_ENABLED, BTA_SYS_IGNORE, BTA_SYS_HW_ON},
/* API_DISABLE */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_STOPPING}, /* successive disable/enable: change state wait for completion to disable */
/* EVT_DISABLED */ {BTA_SYS_HW_EVT_DISABLED, BTA_SYS_HW_API_ENABLE, BTA_SYS_HW_STARTING}, /* successive enable/disable: notify, then restart HW */
/* EVT_ERROR */ {BTA_SYS_HW_ERROR, BTA_SYS_IGNORE, BTA_SYS_HW_ON}
};
const UINT8 bta_sys_hw_on[][BTA_SYS_NUM_COLS] =
{
/* Event Action 1 Action 2 Next State */
/* API_ENABLE */ {BTA_SYS_HW_API_ENABLE, BTA_SYS_IGNORE, BTA_SYS_HW_ON},
/* EVT_ENABLED */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_ON},
/* STACK_ENABLED */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_ON},
/* API_DISABLE */ {BTA_SYS_HW_API_DISABLE, BTA_SYS_IGNORE, BTA_SYS_HW_ON}, /* don't change the state here, as some other modules might be active */
/* EVT_DISABLED */ {BTA_SYS_HW_ERROR, BTA_SYS_IGNORE, BTA_SYS_HW_ON},
/* EVT_ERROR */ {BTA_SYS_HW_ERROR, BTA_SYS_IGNORE, BTA_SYS_HW_ON}
const UINT8 bta_sys_hw_on[][BTA_SYS_NUM_COLS] = {
/* Event Action 1 Action 2 Next State */
/* API_ENABLE */ {BTA_SYS_HW_API_ENABLE, BTA_SYS_IGNORE, BTA_SYS_HW_ON},
/* EVT_ENABLED */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_ON},
/* STACK_ENABLED */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_ON},
/* API_DISABLE */ {BTA_SYS_HW_API_DISABLE, BTA_SYS_IGNORE, BTA_SYS_HW_ON}, /* don't change the state here, as some other modules might be active */
/* EVT_DISABLED */ {BTA_SYS_HW_ERROR, BTA_SYS_IGNORE, BTA_SYS_HW_ON},
/* EVT_ERROR */ {BTA_SYS_HW_ERROR, BTA_SYS_IGNORE, BTA_SYS_HW_ON}
};
const UINT8 bta_sys_hw_stopping[][BTA_SYS_NUM_COLS] =
{
/* Event Action 1 Action 2 Next State */
/* API_ENABLE */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_STARTING}, /* change state, and wait for completion event to enable */
/* EVT_ENABLED */ {BTA_SYS_HW_EVT_ENABLED, BTA_SYS_IGNORE, BTA_SYS_HW_STOPPING}, /* successive enable/disable: finish the enable before disabling */
/* STACK_ENABLED */ {BTA_SYS_HW_EVT_STACK_ENABLED, BTA_SYS_HW_API_DISABLE, BTA_SYS_HW_STOPPING}, /* successive enable/disable: notify, then stop */
/* API_DISABLE */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_STOPPING}, /* wait for completion event */
/* EVT_DISABLED */ {BTA_SYS_HW_EVT_DISABLED, BTA_SYS_IGNORE, BTA_SYS_HW_OFF},
/* EVT_ERROR */ {BTA_SYS_HW_API_DISABLE, BTA_SYS_IGNORE, BTA_SYS_HW_STOPPING}
const UINT8 bta_sys_hw_stopping[][BTA_SYS_NUM_COLS] = {
/* Event Action 1 Action 2 Next State */
/* API_ENABLE */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_STARTING}, /* change state, and wait for completion event to enable */
/* EVT_ENABLED */ {BTA_SYS_HW_EVT_ENABLED, BTA_SYS_IGNORE, BTA_SYS_HW_STOPPING}, /* successive enable/disable: finish the enable before disabling */
/* STACK_ENABLED */ {BTA_SYS_HW_EVT_STACK_ENABLED, BTA_SYS_HW_API_DISABLE, BTA_SYS_HW_STOPPING}, /* successive enable/disable: notify, then stop */
/* API_DISABLE */ {BTA_SYS_IGNORE, BTA_SYS_IGNORE, BTA_SYS_HW_STOPPING}, /* wait for completion event */
/* EVT_DISABLED */ {BTA_SYS_HW_EVT_DISABLED, BTA_SYS_IGNORE, BTA_SYS_HW_OFF},
/* EVT_ERROR */ {BTA_SYS_HW_API_DISABLE, BTA_SYS_IGNORE, BTA_SYS_HW_STOPPING}
};
typedef const UINT8 (*tBTA_SYS_ST_TBL)[BTA_SYS_NUM_COLS];
@ -193,7 +186,7 @@ void bta_sys_init(void)
bta_sys_register( BTA_ID_SYS, &bta_sys_hw_reg);
/* register for BTM notifications */
BTM_RegisterForDeviceStatusNotif ((tBTM_DEV_STATUS_CB*)&bta_sys_hw_btm_cback );
BTM_RegisterForDeviceStatusNotif ((tBTM_DEV_STATUS_CB *)&bta_sys_hw_btm_cback );
#if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
bta_ar_init();
@ -201,7 +194,8 @@ void bta_sys_init(void)
}
void bta_sys_free(void) {
void bta_sys_free(void)
{
fixed_queue_free(btu_bta_alarm_queue, NULL);
hash_map_free(bta_alarm_hash_map);
pthread_mutex_destroy(&bta_alarm_lock);
@ -232,14 +226,10 @@ BOOLEAN bta_sys_sm_execute(BT_HDR *p_msg)
bta_sys_cb.state = state_table[p_msg->event & 0x00ff][BTA_SYS_NEXT_STATE];
/* execute action functions */
for (i = 0; i < BTA_SYS_ACTIONS; i++)
{
if ((action = state_table[p_msg->event & 0x00ff][i]) != BTA_SYS_IGNORE)
{
(*bta_sys_action[action])( (tBTA_SYS_HW_MSG*) p_msg);
}
else
{
for (i = 0; i < BTA_SYS_ACTIONS; i++) {
if ((action = state_table[p_msg->event & 0x00ff][i]) != BTA_SYS_IGNORE) {
(*bta_sys_action[action])( (tBTA_SYS_HW_MSG *) p_msg);
} else {
break;
}
}
@ -250,13 +240,13 @@ BOOLEAN bta_sys_sm_execute(BT_HDR *p_msg)
void bta_sys_hw_register( tBTA_SYS_HW_MODULE module, tBTA_SYS_HW_CBACK *cback)
{
bta_sys_cb.sys_hw_cback[module]=cback;
bta_sys_cb.sys_hw_cback[module] = cback;
}
void bta_sys_hw_unregister( tBTA_SYS_HW_MODULE module )
{
bta_sys_cb.sys_hw_cback[module]=NULL;
bta_sys_cb.sys_hw_cback[module] = NULL;
}
/*******************************************************************************
@ -277,26 +267,21 @@ void bta_sys_hw_btm_cback( tBTM_DEV_STATUS status )
APPL_TRACE_DEBUG(" bta_sys_hw_btm_cback was called with parameter: %i" , status );
/* send a message to BTA SYS */
if ((sys_event = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL)
{
if (status == BTM_DEV_STATUS_UP)
if ((sys_event = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL) {
if (status == BTM_DEV_STATUS_UP) {
sys_event->hdr.event = BTA_SYS_EVT_STACK_ENABLED_EVT;
else if (status == BTM_DEV_STATUS_DOWN)
} else if (status == BTM_DEV_STATUS_DOWN) {
sys_event->hdr.event = BTA_SYS_ERROR_EVT;
else
{
} else {
/* BTM_DEV_STATUS_CMD_TOUT is ignored for now. */
GKI_freebuf (sys_event);
sys_event = NULL;
}
if (sys_event)
{
if (sys_event) {
bta_sys_sendmsg(sys_event);
}
}
else
{
} else {
APPL_TRACE_DEBUG("ERROR bta_sys_hw_btm_cback couldn't send msg" );
}
}
@ -320,15 +305,14 @@ void bta_sys_hw_error(tBTA_SYS_HW_MSG *p_sys_hw_msg)
APPL_TRACE_DEBUG("%s\n", __FUNCTION__);
for (module_index = 0; module_index < BTA_SYS_MAX_HW_MODULES; module_index++)
{
if( bta_sys_cb.sys_hw_module_active & ((UINT32)1 << module_index )) {
switch( module_index)
{
for (module_index = 0; module_index < BTA_SYS_MAX_HW_MODULES; module_index++) {
if ( bta_sys_cb.sys_hw_module_active & ((UINT32)1 << module_index )) {
switch ( module_index) {
case BTA_SYS_HW_BLUETOOTH:
/* Send BTA_SYS_HW_ERROR_EVT to DM */
if (bta_sys_cb.sys_hw_cback[module_index] != NULL)
if (bta_sys_cb.sys_hw_cback[module_index] != NULL) {
bta_sys_cb.sys_hw_cback[module_index] (BTA_SYS_HW_ERROR_EVT);
}
break;
default:
/* not yet supported */
@ -353,29 +337,26 @@ void bta_sys_hw_error(tBTA_SYS_HW_MSG *p_sys_hw_msg)
void bta_sys_hw_api_enable( tBTA_SYS_HW_MSG *p_sys_hw_msg )
{
if ((!bta_sys_cb.sys_hw_module_active) && (bta_sys_cb.state != BTA_SYS_HW_ON))
{
if ((!bta_sys_cb.sys_hw_module_active) && (bta_sys_cb.state != BTA_SYS_HW_ON)) {
/* register which HW module was turned on */
bta_sys_cb.sys_hw_module_active |= ((UINT32)1 << p_sys_hw_msg->hw_module );
tBTA_SYS_HW_MSG *p_msg;
if ((p_msg = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL)
{
if ((p_msg = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL) {
p_msg->hdr.event = BTA_SYS_EVT_ENABLED_EVT;
p_msg->hw_module = p_sys_hw_msg->hw_module;
bta_sys_sendmsg(p_msg);
}
}
else
{
} else {
/* register which HW module was turned on */
bta_sys_cb.sys_hw_module_active |= ((UINT32)1 << p_sys_hw_msg->hw_module );
/* HW already in use, so directly notify the caller */
if (bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module ]!= NULL )
if (bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module ] != NULL ) {
bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module ]( BTA_SYS_HW_ON_EVT );
}
}
APPL_TRACE_EVENT ("bta_sys_hw_api_enable for %d, active modules 0x%04X\n",
p_sys_hw_msg->hw_module, bta_sys_cb.sys_hw_module_active);
@ -406,20 +387,17 @@ void bta_sys_hw_api_disable(tBTA_SYS_HW_MSG *p_sys_hw_msg)
/* if there are still some SW modules using the HW, just provide an answer to the calling */
if( bta_sys_cb.sys_hw_module_active != 0 )
{
if ( bta_sys_cb.sys_hw_module_active != 0 ) {
/* if there are still some SW modules using the HW, directly notify the caller */
if( bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module ]!= NULL )
if ( bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module ] != NULL ) {
bta_sys_cb.sys_hw_cback[p_sys_hw_msg->hw_module ]( BTA_SYS_HW_OFF_EVT );
}
else
{
} else {
/* manually update the state of our system */
bta_sys_cb.state = BTA_SYS_HW_STOPPING;
tBTA_SYS_HW_MSG *p_msg;
if ((p_msg = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL)
{
if ((p_msg = (tBTA_SYS_HW_MSG *) GKI_getbuf(sizeof(tBTA_SYS_HW_MSG))) != NULL) {
p_msg->hdr.event = BTA_SYS_EVT_DISABLED_EVT;
p_msg->hw_module = p_sys_hw_msg->hw_module;
@ -463,11 +441,11 @@ void bta_sys_hw_evt_disabled(tBTA_SYS_HW_MSG *p_sys_hw_msg)
APPL_TRACE_DEBUG("bta_sys_hw_evt_disabled - module 0x%X\n", p_sys_hw_msg->hw_module);
for (hw_module_index = 0; hw_module_index < BTA_SYS_MAX_HW_MODULES; hw_module_index++)
{
if (bta_sys_cb.sys_hw_cback[hw_module_index] != NULL)
for (hw_module_index = 0; hw_module_index < BTA_SYS_MAX_HW_MODULES; hw_module_index++) {
if (bta_sys_cb.sys_hw_cback[hw_module_index] != NULL) {
bta_sys_cb.sys_hw_cback[hw_module_index] (BTA_SYS_HW_OFF_EVT);
}
}
}
/*******************************************************************************
@ -487,11 +465,11 @@ void bta_sys_hw_evt_stack_enabled(tBTA_SYS_HW_MSG *p_sys_hw_msg)
APPL_TRACE_DEBUG(" bta_sys_hw_evt_stack_enabled!notify the callers\n");
for (hw_module_index = 0; hw_module_index < BTA_SYS_MAX_HW_MODULES; hw_module_index++ )
{
if (bta_sys_cb.sys_hw_cback[hw_module_index] != NULL)
for (hw_module_index = 0; hw_module_index < BTA_SYS_MAX_HW_MODULES; hw_module_index++ ) {
if (bta_sys_cb.sys_hw_cback[hw_module_index] != NULL) {
bta_sys_cb.sys_hw_cback[hw_module_index] (BTA_SYS_HW_ON_EVT);
}
}
}
@ -518,17 +496,13 @@ void bta_sys_event(BT_HDR *p_msg)
id = (UINT8) (p_msg->event >> 8);
/* verify id and call subsystem event handler */
if ((id < BTA_ID_MAX) && (bta_sys_cb.reg[id] != NULL))
{
if ((id < BTA_ID_MAX) && (bta_sys_cb.reg[id] != NULL)) {
freebuf = (*bta_sys_cb.reg[id]->evt_hdlr)(p_msg);
}
else
{
} else {
APPL_TRACE_WARNING("BTA got unregistered event id %d\n", id);
}
if (freebuf)
{
if (freebuf) {
GKI_freebuf(p_msg);
}
@ -618,14 +592,16 @@ void bta_sys_sendmsg(void *p_msg)
** Returns void
**
*******************************************************************************/
void bta_alarm_cb(void *data) {
void bta_alarm_cb(void *data)
{
assert(data != NULL);
TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
fixed_queue_enqueue(btu_bta_alarm_queue, p_tle);
}
void bta_sys_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout_ms) {
void bta_sys_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout_ms)
{
assert(p_tle != NULL);
// Get the alarm for this p_tle.
@ -650,8 +626,8 @@ void bta_sys_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout_ms) {
bool hash_iter_ro_cb(hash_map_entry_t *hash_map_entry, void *context)
{
osi_alarm_t *alarm = (osi_alarm_t *)hash_map_entry->data;
period_ms_t *p_remaining_ms = (period_ms_t*)context;
*p_remaining_ms +=osi_alarm_get_remaining_ms(alarm);
period_ms_t *p_remaining_ms = (period_ms_t *)context;
*p_remaining_ms += osi_alarm_get_remaining_ms(alarm);
return true;
}
@ -675,7 +651,8 @@ UINT32 bta_sys_get_remaining_ticks(TIMER_LIST_ENT *p_target_tle)
** Returns void
**
*******************************************************************************/
void bta_sys_stop_timer(TIMER_LIST_ENT *p_tle) {
void bta_sys_stop_timer(TIMER_LIST_ENT *p_tle)
{
assert(p_tle != NULL);
osi_alarm_t *alarm = hash_map_get(bta_alarm_hash_map, p_tle);
@ -702,8 +679,7 @@ void bta_sys_disable(tBTA_SYS_HW_MODULE module)
APPL_TRACE_DEBUG("bta_sys_disable: module %i", module);
switch( module )
{
switch ( module ) {
case BTA_SYS_HW_BLUETOOTH:
bta_id = BTA_ID_DM;
bta_id_max = BTA_ID_BLUETOOTH_MAX;
@ -713,12 +689,9 @@ void bta_sys_disable(tBTA_SYS_HW_MODULE module)
return;
}
for ( ; bta_id <= bta_id_max; bta_id++)
{
if (bta_sys_cb.reg[bta_id] != NULL)
{
if (bta_sys_cb.is_reg[bta_id] == TRUE && bta_sys_cb.reg[bta_id]->disable != NULL)
{
for ( ; bta_id <= bta_id_max; bta_id++) {
if (bta_sys_cb.reg[bta_id] != NULL) {
if (bta_sys_cb.is_reg[bta_id] == TRUE && bta_sys_cb.reg[bta_id]->disable != NULL) {
(*bta_sys_cb.reg[bta_id]->disable)();
}
}

9
components/bt/bluedroid/bta/sys/include/bta_sys_int.h Executable file → Normal file
View file

@ -33,8 +33,7 @@
*****************************************************************************/
/* SYS HW state */
enum
{
enum {
BTA_SYS_HW_OFF,
BTA_SYS_HW_STARTING,
BTA_SYS_HW_ON,
@ -45,15 +44,13 @@ typedef UINT8 tBTA_SYS_HW_STATE;
/* Collision callback */
#define MAX_COLLISION_REG 5
typedef struct
{
typedef struct {
UINT8 id[MAX_COLLISION_REG];
tBTA_SYS_CONN_CBACK *p_coll_cback[MAX_COLLISION_REG];
} tBTA_SYS_COLLISION;
/* system manager control block */
typedef struct
{
typedef struct {
tBTA_SYS_REG *reg[BTA_ID_MAX]; /* registration structures */
BOOLEAN is_reg[BTA_ID_MAX]; /* registration structures */
tBTA_SYS_HW_STATE state;

77
components/bt/bluedroid/bta/sys/utl.c Executable file → Normal file
View file

@ -43,24 +43,26 @@ INT16 utl_str2int(const char *p_s)
{
INT32 val = 0;
for (;*p_s == ' ' && *p_s != 0; p_s++);
for (; *p_s == ' ' && *p_s != 0; p_s++);
if (*p_s == 0) return -1;
if (*p_s == 0) {
return -1;
}
for (;;)
{
if ((*p_s < '0') || (*p_s > '9')) return -1;
for (;;) {
if ((*p_s < '0') || (*p_s > '9')) {
return -1;
}
val += (INT32) (*p_s++ - '0');
if (val > 32767) return -1;
if (*p_s == 0)
{
return (INT16) val;
if (val > 32767) {
return -1;
}
else
{
if (*p_s == 0) {
return (INT16) val;
} else {
val *= 10;
}
}
@ -83,26 +85,21 @@ int utl_strucmp(const char *p_s, const char *p_t)
{
char c;
while (*p_s && *p_t)
{
while (*p_s && *p_t) {
c = *p_t++;
if (c >= 'a' && c <= 'z')
{
if (c >= 'a' && c <= 'z') {
c -= 0x20;
}
if (*p_s++ != c)
{
if (*p_s++ != c) {
return -1;
}
}
/* if p_t hit null first, no match */
if (*p_t == 0 && *p_s != 0)
{
if (*p_t == 0 && *p_s != 0) {
return 1;
}
/* else p_s hit null first, count as match */
else
{
else {
return 0;
}
}
@ -125,19 +122,14 @@ UINT8 utl_itoa(UINT16 i, char *p_s)
char *p = p_s;
BOOLEAN fill = FALSE;
if (i == 0)
{
if (i == 0) {
/* take care of zero case */
*p++ = '0';
}
else
{
for(j = 10000; j > 0; j /= 10)
{
} else {
for (j = 10000; j > 0; j /= 10) {
k = i / j;
i %= j;
if (k > 0 || fill)
{
if (k > 0 || fill) {
*p++ = k + '0';
fill = TRUE;
}
@ -161,8 +153,7 @@ UINT8 utl_itoa(UINT16 i, char *p_s)
*******************************************************************************/
void utl_freebuf(void **p)
{
if (*p != NULL)
{
if (*p != NULL) {
GKI_freebuf(*p);
*p = NULL;
}
@ -200,8 +191,7 @@ BOOLEAN utl_set_device_class(tBTA_UTL_COD *p_cod, UINT8 cmd)
BTM_COD_MINOR_CLASS(minor, dev );
BTM_COD_MAJOR_CLASS(major, dev );
switch(cmd)
{
switch (cmd) {
case BTA_UTL_SET_COD_MAJOR_MINOR:
minor = p_cod->minor & BTM_COD_MINOR_CLASS_MASK;
major = p_cod->major & BTM_COD_MAJOR_CLASS_MASK;
@ -238,8 +228,9 @@ BOOLEAN utl_set_device_class(tBTA_UTL_COD *p_cod, UINT8 cmd)
/* convert the fields into the device class type */
FIELDS_TO_COD(dev_class, minor, major, service);
if (BTM_SetDeviceClass(dev_class) == BTM_SUCCESS)
if (BTM_SetDeviceClass(dev_class) == BTM_SUCCESS) {
return TRUE;
}
return FALSE;
}
@ -259,11 +250,11 @@ BOOLEAN utl_isintstr(const char *p_s)
{
UINT16 i = 0;
for(i=0; p_s[i] != 0; i++)
{
if(((p_s[i] < '0') || (p_s[i] > '9')) && (p_s[i] != ';'))
for (i = 0; p_s[i] != 0; i++) {
if (((p_s[i] < '0') || (p_s[i] > '9')) && (p_s[i] != ';')) {
return FALSE;
}
}
return TRUE;
}
@ -283,15 +274,15 @@ BOOLEAN utl_isdialstr(const char *p_s)
{
UINT16 i = 0;
for(i=0; p_s[i] != 0; i++)
{
if(!(((p_s[i] >= '0') && (p_s[i] <= '9'))
for (i = 0; p_s[i] != 0; i++) {
if (!(((p_s[i] >= '0') && (p_s[i] <= '9'))
|| (p_s[i] == '*') || (p_s[i] == '+') || (p_s[i] == '#') || (p_s[i] == ';')
|| ((p_s[i] >= 'A') && (p_s[i] <= 'C'))
|| ((p_s[i] == 'p') || (p_s[i] == 'P')
|| (p_s[i] == 'w') || (p_s[i] == 'W'))))
|| (p_s[i] == 'w') || (p_s[i] == 'W')))) {
return FALSE;
}
}
return TRUE;
}

View file

@ -0,0 +1,91 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 "btc_task.h"
#include "btc_main.h"
#include "future.h"
#include "esp_err.h"
static future_t *main_future[BTC_MAIN_FUTURE_NUM];
extern int bte_main_boot_entry(void *cb);
extern int bte_main_shutdown(void);
future_t **btc_main_get_future_p(btc_main_future_type_t type)
{
return &main_future[type];
}
static void btc_sec_callback(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data)
{
switch (event) {
case BTA_DM_ENABLE_EVT:
future_ready(*btc_main_get_future_p(BTC_MAIN_ENABLE_FUTURE), FUTURE_SUCCESS);
break;
case BTA_DM_DISABLE_EVT:
future_ready(*btc_main_get_future_p(BTC_MAIN_DISABLE_FUTURE), FUTURE_SUCCESS);
break;
}
}
static bt_status_t btc_enable_bluetooth(void)
{
BTA_EnableBluetooth(btc_sec_callback);
}
static bt_status_t btc_disable_bluetooth(void)
{
BTA_DisableBluetooth();
}
void btc_init_callback(void)
{
future_ready(*btc_main_get_future_p(BTC_MAIN_INIT_FUTURE), FUTURE_SUCCESS);
}
static bt_status_t btc_init_bluetooth(void)
{
bte_main_boot_entry(btc_init_callback);
}
static void btc_deinit_bluetooth(void)
{
bte_main_shutdown();
future_ready(*btc_main_get_future_p(BTC_MAIN_DEINIT_FUTURE), FUTURE_SUCCESS);
}
void btc_main_call_handler(btc_msg_t *msg)
{
LOG_DEBUG("%s act %d\n", __func__, msg->act);
switch (msg->act) {
case BTC_MAIN_ACT_INIT:
btc_init_bluetooth();
break;
case BTC_MAIN_ACT_DEINIT:
btc_deinit_bluetooth();
break;
case BTC_MAIN_ACT_ENABLE:
btc_enable_bluetooth();
break;
case BTC_MAIN_ACT_DISABLE:
btc_disable_bluetooth();
break;
default:
LOG_ERROR("%s UNKNOWN ACT %d\n", __func__, msg->act);
break;
}
}

View file

@ -0,0 +1,54 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
//
// 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 "btc_task.h"
#include "bt_trace.h"
#include "thread.h"
#include "gki.h"
#include "esp_bt_defs.h"
#include "esp_gatt_defs.h"
static esp_profile_cb_t btc_profile_cb_tab[BTC_PID_NUM] = {};
void esp_profile_cb_reset(void)
{
int i;
for (i = 0; i < BTC_PID_NUM; i++) {
btc_profile_cb_tab[i] = NULL;
}
}
int btc_profile_cb_set(btc_pid_t profile_id, esp_profile_cb_t cb)
{
if (profile_id < 0 || profile_id >= BTC_PID_NUM) {
return -1;
}
btc_profile_cb_tab[profile_id] = cb;
return 0;
}
esp_profile_cb_t btc_profile_cb_get(btc_pid_t profile_id)
{
if (profile_id < 0 || profile_id >= BTC_PID_NUM) {
return NULL;
}
return btc_profile_cb_tab[profile_id];
}

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