forked from espressif/esp-idf
Compare commits
409 Commits
release/v5
...
remove-use
| Author | SHA1 | Date | |
|---|---|---|---|
| 4bbff34ac2 | |||
|
|
f420609c33 | ||
|
|
5910fc8270 | ||
|
|
691a0ee1fd | ||
|
|
66596b7f59 | ||
|
|
9c91d08c78 | ||
|
|
f3c95b632e | ||
|
|
978896a09d | ||
|
|
b65f8a98bd | ||
|
|
0045550de5 | ||
|
|
393b7410a6 | ||
|
|
03b6436745 | ||
|
|
6d3a82eecf | ||
|
|
b9253b4e66 | ||
|
|
e8800ac785 | ||
|
|
88c4086db9 | ||
|
|
42cbc7aada | ||
|
|
9382c9a400 | ||
|
|
4c9154bad1 | ||
|
|
16469297b4 | ||
|
|
5009857d7d | ||
|
|
401fa7b0f3 | ||
|
|
53d2d67226 | ||
|
|
a3922cd1a7 | ||
|
|
29b017b785 | ||
|
|
5aaa47834a | ||
|
|
c5ada2e82f | ||
|
|
9f47024e78 | ||
|
|
6e05a9e65b | ||
|
|
7c384facd7 | ||
|
|
092bbdbc9c | ||
|
|
c014ced2f8 | ||
|
|
872a3a2d71 | ||
|
|
e84b59cf92 | ||
|
|
a1ec278291 | ||
|
|
9dc4a27d9c | ||
|
|
d74bf059c8 | ||
|
|
3c8a32ff0d | ||
|
|
8255ba29a6 | ||
|
|
4b79cb964f | ||
|
|
4d75d2d487 | ||
|
|
59d20e80d3 | ||
|
|
890106fb23 | ||
|
|
7e9782b67e | ||
|
|
1a028bdfdc | ||
|
|
167cd4762b | ||
|
|
74c847210d | ||
|
|
6002db2fb9 | ||
|
|
c86a301736 | ||
|
|
ce85e113a9 | ||
|
|
c445ec134b | ||
|
|
1e11d42aa1 | ||
|
|
38b737511c | ||
|
|
7fcbdb9c2e | ||
|
|
83c9cffd2b | ||
|
|
ab75a94877 | ||
|
|
ace6a490bc | ||
|
|
7ff774905a | ||
|
|
705e2695ee | ||
|
|
0b1170af8f | ||
|
|
78a690517f | ||
|
|
074b74c701 | ||
|
|
d5f244c5f7 | ||
|
|
1de992adef | ||
|
|
6a9e7f61e8 | ||
|
|
bbcfb35d67 | ||
|
|
fe93c990e6 | ||
|
|
4b4a9a2174 | ||
|
|
d7bc953d66 | ||
|
|
ea31e155e8 | ||
|
|
32f60da330 | ||
|
|
4e9362a1cb | ||
|
|
7a305c0284 | ||
|
|
9ec62baa94 | ||
|
|
862f3bd7bf | ||
|
|
e613fcde6e | ||
|
|
d37e1cccb6 | ||
|
|
582c99041c | ||
|
|
5532fa8e26 | ||
|
|
0d99214012 | ||
|
|
1e7098fe97 | ||
|
|
1a25f6887d | ||
|
|
cbbb85fecd | ||
|
|
97b65d7350 | ||
|
|
b6be76f53b | ||
|
|
df52e1aa71 | ||
|
|
b4bd3d98bd | ||
|
|
908e62f5e4 | ||
|
|
ed8ec9de0b | ||
|
|
bff20b5397 | ||
|
|
f8ddcee8cd | ||
|
|
5bff669f2f | ||
|
|
727825663b | ||
|
|
cb41623b2e | ||
|
|
9e3b7e4558 | ||
|
|
cf44fc6a1f | ||
|
|
30b13b132d | ||
|
|
d8949fe50f | ||
|
|
5bae0b92ec | ||
|
|
7f54410256 | ||
|
|
ce72392e2f | ||
|
|
542a5d280c | ||
|
|
05beacad73 | ||
|
|
33149921aa | ||
|
|
dca5d193fc | ||
|
|
b0ffe15514 | ||
|
|
b4f366f56f | ||
|
|
32040c7f98 | ||
|
|
e8f0299557 | ||
|
|
de077c77b4 | ||
|
|
ccc2411191 | ||
|
|
bb9a2658a9 | ||
|
|
3318e0accd | ||
|
|
52f14f344d | ||
|
|
a4acbd2758 | ||
|
|
e8fda6f776 | ||
|
|
e6ef4d1791 | ||
|
|
16eef27492 | ||
|
|
d0e6e825d9 | ||
|
|
64bbb53b8f | ||
|
|
c9bf5d9698 | ||
|
|
c41cead036 | ||
|
|
f5f46ab74c | ||
|
|
98f1dd969a | ||
|
|
2b29de78bb | ||
|
|
3107f0abe7 | ||
|
|
1689c7e14f | ||
|
|
e7ab36ebbf | ||
|
|
afb4a02fe4 | ||
|
|
cf087cb8e5 | ||
|
|
2899c1e39f | ||
|
|
ba2bf2f512 | ||
|
|
3f46b378bb | ||
|
|
ea902d6ed7 | ||
|
|
dccbd16750 | ||
|
|
06508329c8 | ||
|
|
7bc8b998a7 | ||
|
|
08ef00d82d | ||
|
|
87e4f63c77 | ||
|
|
56db9a2841 | ||
|
|
4df585e1a8 | ||
|
|
3ec05583b2 | ||
|
|
2414b285c0 | ||
|
|
611e163024 | ||
|
|
7962d54c4c | ||
|
|
4e3e73f353 | ||
|
|
d74e99c08a | ||
|
|
110bfc1f45 | ||
|
|
f817b85fc3 | ||
|
|
d03ead4cf8 | ||
|
|
b3bae69c5c | ||
|
|
798d35b2e1 | ||
|
|
99f1455199 | ||
|
|
816a0da0fd | ||
|
|
8f777699ff | ||
|
|
8b191dd7a1 | ||
|
|
c7e2a9ea0d | ||
|
|
f269835865 | ||
|
|
9a41a61dd5 | ||
|
|
197128b162 | ||
|
|
2a5743c0c5 | ||
|
|
83306b79ef | ||
|
|
3e2b56d114 | ||
|
|
5a3f53a2b5 | ||
|
|
92cd70acc9 | ||
|
|
f84f883ab4 | ||
|
|
d137deed2a | ||
|
|
dcb4bf4600 | ||
|
|
fc81b6878e | ||
|
|
63e74e6b68 | ||
|
|
941d0e0779 | ||
|
|
f15c1b4c4f | ||
|
|
8576f40ced | ||
|
|
efd04b7709 | ||
|
|
d2c74a6b1e | ||
|
|
0bda2f8990 | ||
|
|
3730567940 | ||
|
|
6b54dfc636 | ||
|
|
7f07c9de44 | ||
|
|
1a30fd0c39 | ||
|
|
a86bb375f7 | ||
|
|
cfdefd3e03 | ||
|
|
c79eb0d5bf | ||
|
|
01cd5cf4fe | ||
|
|
f0ab551348 | ||
|
|
a50c095df1 | ||
|
|
ad476afb5c | ||
|
|
bb329c4e53 | ||
|
|
457f65195e | ||
|
|
cce9a80aee | ||
|
|
94536cb512 | ||
|
|
4fa6e03879 | ||
|
|
d2fe62f682 | ||
|
|
19ab0213d9 | ||
|
|
f41b43dc43 | ||
|
|
68e9bcbf1e | ||
|
|
97d150d69a | ||
|
|
ac630e4417 | ||
|
|
0ed4c19c5e | ||
|
|
712e6ad927 | ||
|
|
5e056de1e7 | ||
|
|
db579962b6 | ||
|
|
8aa56d805a | ||
|
|
d2b1202d5a | ||
|
|
269322191a | ||
|
|
8e4ff8bcba | ||
|
|
d1e7939940 | ||
|
|
9c5dde5536 | ||
|
|
ef437b7b0d | ||
|
|
6fdd380812 | ||
|
|
4a444c80ae | ||
|
|
dbc6be3138 | ||
|
|
97e669214c | ||
|
|
8bd4071f92 | ||
|
|
280b3d9e62 | ||
|
|
0a098f49d4 | ||
|
|
87f2080705 | ||
|
|
0eeb544bd2 | ||
|
|
4c6cda734d | ||
|
|
670d34e363 | ||
|
|
b7aecdbbaf | ||
|
|
df120ac962 | ||
|
|
e8c5992a57 | ||
|
|
1f49c9a845 | ||
|
|
068790baa9 | ||
|
|
9d4a897d47 | ||
|
|
c8b67235e6 | ||
|
|
402fecee17 | ||
|
|
50ac90b489 | ||
|
|
b2e0bd9200 | ||
|
|
765fe330ea | ||
|
|
afa46c06a8 | ||
|
|
72308ca089 | ||
|
|
26002e13fc | ||
|
|
405327d22a | ||
|
|
67169f8efd | ||
|
|
0c07ee6baf | ||
|
|
d46b23d44b | ||
|
|
6f86f70f0a | ||
|
|
3e4955345a | ||
|
|
f0701b265d | ||
|
|
7aaab5a3ff | ||
|
|
9677a4929f | ||
|
|
682a66d164 | ||
|
|
7e90a41bc9 | ||
|
|
0546805fc5 | ||
|
|
34ba72a431 | ||
|
|
e1a3ff1529 | ||
|
|
7786cbe2c8 | ||
|
|
ae51dcc227 | ||
|
|
47c8ca5556 | ||
|
|
5c3cb06d18 | ||
|
|
75aea08703 | ||
|
|
6bf2d91c4d | ||
|
|
9386b58e17 | ||
|
|
cfe6c45122 | ||
|
|
08f1c3681a | ||
|
|
676f5194d5 | ||
|
|
5cc9931dc7 | ||
|
|
70b652052e | ||
|
|
2d8053aabf | ||
|
|
403d44ae68 | ||
|
|
e6a97d2c56 | ||
|
|
1f47975472 | ||
|
|
93e77a4df6 | ||
|
|
c0f3ac4295 | ||
|
|
e1abef5e9b | ||
|
|
94d1a4f1c0 | ||
|
|
3cc9d42695 | ||
|
|
3357fe8b95 | ||
|
|
5504a596e2 | ||
|
|
6b3ae2822d | ||
|
|
ed21c54a64 | ||
|
|
c4bde5dfae | ||
|
|
375156918e | ||
|
|
a41c2d498e | ||
|
|
2cb35a2955 | ||
|
|
92ed77933b | ||
|
|
5976e391ea | ||
|
|
45ea08b955 | ||
|
|
f46b9ed5a6 | ||
|
|
02f6738d22 | ||
|
|
ce6085349f | ||
|
|
c2acddda7b | ||
|
|
37b600124f | ||
|
|
7397c159cb | ||
|
|
5b1891c2fa | ||
|
|
a71eb45ca1 | ||
|
|
5e8443a2f6 | ||
|
|
d1e5fd08ff | ||
|
|
569222488e | ||
|
|
63fdde6cd4 | ||
|
|
48ebf7c715 | ||
|
|
8fb28dcedc | ||
|
|
e27889a146 | ||
|
|
90abcdebf2 | ||
|
|
d1991b5b46 | ||
|
|
1a419e594b | ||
|
|
7bc9393301 | ||
|
|
feafc84ece | ||
|
|
729c55b790 | ||
|
|
a49454e352 | ||
|
|
e33bcaa6d3 | ||
|
|
a1df6b8185 | ||
|
|
775c65a6b7 | ||
|
|
a2f3585030 | ||
|
|
90e71bfa48 | ||
|
|
566721629f | ||
|
|
f6d154e761 | ||
|
|
24056620ef | ||
|
|
0e8a933488 | ||
|
|
50aeec2f97 | ||
|
|
8ac260a9d7 | ||
|
|
2c1bec2c70 | ||
|
|
ed31c19933 | ||
|
|
df2d09e3e0 | ||
|
|
116c3d6ddb | ||
|
|
8318adb448 | ||
|
|
203e5432a9 | ||
|
|
a4ef854a2d | ||
|
|
8c4f576f99 | ||
|
|
f9d6c4df20 | ||
|
|
7e5741953d | ||
|
|
77656e2046 | ||
|
|
8cd4091114 | ||
|
|
92b4c62d06 | ||
|
|
7d179ccd3e | ||
|
|
bb5a53c66c | ||
|
|
66f6364bb1 | ||
|
|
7a044c0f81 | ||
|
|
35ef6f5140 | ||
|
|
00dcf1a0c0 | ||
|
|
7cea2a78cc | ||
|
|
f7da0175b0 | ||
|
|
dee6ad56c9 | ||
|
|
f54ec30f6a | ||
|
|
92e4b80a65 | ||
|
|
b64e2ebfc9 | ||
|
|
460233ee3b | ||
|
|
034a35a66f | ||
|
|
1acc70f476 | ||
|
|
8f1fa6164a | ||
|
|
61a7ecd145 | ||
|
|
358e140705 | ||
|
|
dbad6a0ca5 | ||
|
|
dabd66e16f | ||
|
|
57eddeb36a | ||
|
|
908e1e670a | ||
|
|
3b36050e5e | ||
|
|
a2be2ffe5a | ||
|
|
d622011a2b | ||
|
|
dd8c545423 | ||
|
|
ddf6fea6a2 | ||
|
|
4685405a3f | ||
|
|
1805efb0b2 | ||
|
|
5ee42e0239 | ||
|
|
059de88f23 | ||
|
|
9b270c4c7d | ||
|
|
65deae1404 | ||
|
|
e2e4a36577 | ||
|
|
1de0358249 | ||
|
|
ecefb3c7e5 | ||
|
|
06da32f9f2 | ||
|
|
cb4442d948 | ||
|
|
ae4c4464b3 | ||
|
|
4464673ab9 | ||
|
|
29513cfe09 | ||
|
|
af75da0eee | ||
|
|
d74b584427 | ||
|
|
a98ff3aea6 | ||
|
|
653ce935f9 | ||
|
|
81f43866cd | ||
|
|
4b767d03fe | ||
|
|
c007ec5f17 | ||
|
|
1ccb534dc7 | ||
|
|
6856aec19e | ||
|
|
1cd9dd5001 | ||
|
|
10e6101061 | ||
|
|
e4c92855ee | ||
|
|
cceadc4ce8 | ||
|
|
8f7672e117 | ||
|
|
949fc7f2c9 | ||
|
|
e8f01afef7 | ||
|
|
1fcf006ec6 | ||
|
|
c466082ea6 | ||
|
|
cd21bdeb15 | ||
|
|
31b665c628 | ||
|
|
c0e1ecd310 | ||
|
|
901812c589 | ||
|
|
fc5b392c30 | ||
|
|
1d89e14433 | ||
|
|
21b38e8b97 | ||
|
|
d092c1ba55 | ||
|
|
33d3c60b26 | ||
|
|
52496491f8 | ||
|
|
d998d76627 | ||
|
|
7df8467be5 | ||
|
|
7fdfa6c227 | ||
|
|
4a22f982f3 | ||
|
|
000270a4f6 | ||
|
|
d837cae2b0 | ||
|
|
3881d4031d | ||
|
|
675653af89 | ||
|
|
cd8eb11ee7 | ||
|
|
0abdd20240 | ||
|
|
7bfee98996 | ||
|
|
bdf0821f97 | ||
|
|
ff25e646fb | ||
|
|
f3087c8fb0 |
@@ -1,4 +1,4 @@
|
||||
[codespell]
|
||||
skip = build,*.yuv,components/fatfs/src/*,alice.txt,*.rgb,components/wpa_supplicant/*,components/esp_wifi/*,*.pem
|
||||
ignore-words-list = ser,dout,rsource,fram,inout,shs,ans,aci,unstall,unstalling,hart,wheight,wel,ot,fane,assertIn,registr,oen
|
||||
ignore-words-list = ser,dout,rsource,fram,inout,shs,ans,aci,unstall,unstalling,hart,wheight,wel,ot,fane,assertIn,registr,oen,parms
|
||||
write-changes = true
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
.build_template:
|
||||
stage: build
|
||||
extends:
|
||||
- .after_script:build:ccache:upload-when-fail
|
||||
- .after_script:build:ccache-show-stats:upload-failed-job-logs
|
||||
image: $ESP_ENV_IMAGE
|
||||
tags:
|
||||
- build
|
||||
@@ -12,11 +12,11 @@
|
||||
IDF_CCACHE_ENABLE: "1"
|
||||
dependencies: []
|
||||
|
||||
.build_cmake_template:
|
||||
.build_cmake_clang_template:
|
||||
extends:
|
||||
- .build_template
|
||||
- .before_script:build
|
||||
- .after_script:build:ccache
|
||||
- .after_script:build:ccache-show-stats
|
||||
dependencies: # set dependencies to null to avoid missing artifacts issue
|
||||
needs:
|
||||
- job: fast_template_app
|
||||
@@ -34,29 +34,11 @@
|
||||
- "**/build*/size.json"
|
||||
expire_in: 1 week
|
||||
when: always
|
||||
script:
|
||||
# CI specific options start from "--parallel-count xxx". could ignore when running locally
|
||||
- run_cmd python tools/ci/ci_build_apps.py $TEST_DIR -v
|
||||
-t $IDF_TARGET
|
||||
--copy-sdkconfig
|
||||
--parallel-count ${CI_NODE_TOTAL:-1}
|
||||
--parallel-index ${CI_NODE_INDEX:-1}
|
||||
--extra-preserve-dirs
|
||||
examples/bluetooth/esp_ble_mesh/ble_mesh_console
|
||||
examples/bluetooth/hci/controller_hci_uart_esp32
|
||||
examples/wifi/iperf
|
||||
--modified-components ${MR_MODIFIED_COMPONENTS}
|
||||
--modified-files ${MR_MODIFIED_FILES}
|
||||
# for detailed documents, please refer to .gitlab/ci/README.md#uploaddownload-artifacts-to-internal-minio-server
|
||||
- python tools/ci/artifacts_handler.py upload
|
||||
|
||||
.build_cmake_clang_template:
|
||||
extends:
|
||||
- .build_cmake_template
|
||||
variables:
|
||||
IDF_TOOLCHAIN: clang
|
||||
TEST_BUILD_OPTS_EXTRA: ""
|
||||
TEST_DIR: tools/test_apps/system/clang_build_test
|
||||
PYTEST_IGNORE_COLLECT_IMPORT_ERROR: "1"
|
||||
script:
|
||||
# CI specific options start from "--parallel-count xxx". could ignore when running locally
|
||||
- run_cmd python tools/ci/ci_build_apps.py $TEST_DIR -v
|
||||
@@ -126,7 +108,7 @@ gcc_static_analyzer:
|
||||
ANALYZING_APP: "examples/get-started/hello_world"
|
||||
script:
|
||||
- echo "CONFIG_COMPILER_STATIC_ANALYZER=y" >> ${ANALYZING_APP}/sdkconfig.defaults
|
||||
- python -m idf_build_apps build -vv -p ${ANALYZING_APP} -t all
|
||||
- python -m idf_build_apps build -v -p ${ANALYZING_APP} -t all
|
||||
|
||||
########################################
|
||||
# Clang Build Apps Without Tests Cases #
|
||||
@@ -246,15 +228,16 @@ pytest_build_system_macos:
|
||||
extends:
|
||||
- .test_build_system_template
|
||||
- .before_script:build:macos
|
||||
- .after_script:build:macos:upload-when-fail
|
||||
- .after_script:build:macos:upload-failed-job-logs:ccache-show-stats
|
||||
- .rules:build:macos
|
||||
tags:
|
||||
- macos_shell
|
||||
parallel: 3
|
||||
variables:
|
||||
PYENV_VERSION: "3.8"
|
||||
CI_CCACHE_DISABLE: "1" # ccache: error: Read-only file system
|
||||
|
||||
PYENV_VERSION: "3.9"
|
||||
# CCACHE_DIR: "/cache/idf_ccache". On macOS, you cannot write to this folder due to insufficient permissions.
|
||||
CCACHE_DIR: "" # ccache will use "$HOME/Library/Caches/ccache".
|
||||
CCACHE_MAXSIZE: "5G" # To preserve the limited Macbook storage. CCACHE automatically prunes old caches to fit the set limit.
|
||||
build_docker:
|
||||
extends:
|
||||
- .before_script:minimal
|
||||
|
||||
@@ -40,7 +40,7 @@ variables:
|
||||
GIT_FETCH_EXTRA_FLAGS: "--no-recurse-submodules --prune --prune-tags"
|
||||
# we're using .cache folder for caches
|
||||
GIT_CLEAN_FLAGS: -ffdx -e .cache/
|
||||
LATEST_GIT_TAG: v5.4-dev
|
||||
LATEST_GIT_TAG: v5.5-dev
|
||||
|
||||
SUBMODULE_FETCH_TOOL: "tools/ci/ci_fetch_submodule.py"
|
||||
# by default we will fetch all submodules
|
||||
@@ -55,9 +55,9 @@ variables:
|
||||
CHECKOUT_REF_SCRIPT: "$CI_PROJECT_DIR/tools/ci/checkout_project_ref.py"
|
||||
|
||||
# Docker images
|
||||
ESP_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/esp-env-v5.4:1"
|
||||
ESP_IDF_DOC_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/esp-idf-doc-env-v5.4:1-1"
|
||||
TARGET_TEST_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/target-test-env-v5.4:1"
|
||||
ESP_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/esp-env-v5.5:2"
|
||||
ESP_IDF_DOC_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/esp-idf-doc-env-v5.5:2-1"
|
||||
TARGET_TEST_ENV_IMAGE: "${CI_DOCKER_REGISTRY}/target-test-env-v5.5:2"
|
||||
SONARQUBE_SCANNER_IMAGE: "${CI_DOCKER_REGISTRY}/sonarqube-scanner:5"
|
||||
PRE_COMMIT_IMAGE: "${CI_DOCKER_REGISTRY}/esp-idf-pre-commit:1"
|
||||
|
||||
@@ -70,7 +70,7 @@ variables:
|
||||
CI_PYTHON_CONSTRAINT_BRANCH: ""
|
||||
|
||||
# Update the filename for a specific ESP-IDF release. It is used only with CI_PYTHON_CONSTRAINT_BRANCH.
|
||||
CI_PYTHON_CONSTRAINT_FILE: "espidf.constraints.v5.4.txt"
|
||||
CI_PYTHON_CONSTRAINT_FILE: "espidf.constraints.v5.5.txt"
|
||||
|
||||
# Set this variable to repository name of a Python tool you wish to install and test in the context of ESP-IDF CI.
|
||||
# Keep the variable empty when not used.
|
||||
@@ -141,40 +141,48 @@ variables:
|
||||
export IDF_MIRROR_PREFIX_MAP=
|
||||
fi
|
||||
|
||||
# install latest python packages
|
||||
# target test jobs
|
||||
if [[ "${CI_JOB_STAGE}" == "target_test" ]]; then
|
||||
run_cmd bash install.sh --enable-ci --enable-pytest --enable-test-specific
|
||||
elif [[ "${CI_JOB_STAGE}" == "build_doc" ]]; then
|
||||
run_cmd bash install.sh --enable-ci --enable-docs
|
||||
elif [[ "${CI_JOB_STAGE}" == "build" ]]; then
|
||||
run_cmd bash install.sh --enable-ci
|
||||
else
|
||||
if ! echo "${CI_JOB_NAME}" | egrep ".*pytest.*"; then
|
||||
if [[ "${CI_JOB_STAGE}" != "target_test" ]]; then
|
||||
section_start "running_install_sh" "Running install.sh"
|
||||
if [[ "${CI_JOB_STAGE}" == "build_doc" ]]; then
|
||||
run_cmd bash install.sh --enable-ci --enable-docs
|
||||
elif [[ "${CI_JOB_STAGE}" == "build" ]]; then
|
||||
run_cmd bash install.sh --enable-ci
|
||||
else
|
||||
run_cmd bash install.sh --enable-ci --enable-pytest --enable-test-specific
|
||||
if ! echo "${CI_JOB_NAME}" | egrep ".*pytest.*"; then
|
||||
run_cmd bash install.sh --enable-ci
|
||||
else
|
||||
run_cmd bash install.sh --enable-ci --enable-pytest --enable-test-specific
|
||||
fi
|
||||
fi
|
||||
section_end "running_install_sh"
|
||||
else
|
||||
section_start "install_python_env" "Install Python environment"
|
||||
run_cmd python tools/idf_tools.py install-python-env --features ci,pytest,test-specific
|
||||
section_end "install_python_env"
|
||||
fi
|
||||
|
||||
# Install esp-clang if necessary
|
||||
if [[ ! -z "$INSTALL_EXTRA_TOOLS" ]]; then
|
||||
section_start "installing_optional_tools" "Install optional tools ${INSTALL_EXTRA_TOOLS}"
|
||||
$IDF_PATH/tools/idf_tools.py --non-interactive install $INSTALL_EXTRA_TOOLS
|
||||
section_end "installing_optional_tools"
|
||||
fi
|
||||
|
||||
# Install esp-clang if necessary (esp-clang is separately installed)
|
||||
if [[ "$IDF_TOOLCHAIN" == "clang" && -z "$CI_CLANG_DISTRO_URL" ]]; then
|
||||
$IDF_PATH/tools/idf_tools.py --non-interactive install esp-clang
|
||||
fi
|
||||
|
||||
# Install QEMU if necessary
|
||||
if [[ ! -z "$INSTALL_QEMU" ]]; then
|
||||
$IDF_PATH/tools/idf_tools.py --non-interactive install qemu-xtensa qemu-riscv32
|
||||
if [[ "${CI_JOB_STAGE}" == "target_test" ]]; then
|
||||
section_start "IDF_SKIP_TOOLS_CHECK" "Skip required tools check"
|
||||
export IDF_SKIP_TOOLS_CHECK=1
|
||||
section_end "IDF_SKIP_TOOLS_CHECK"
|
||||
fi
|
||||
|
||||
# Since the version 3.21 CMake passes source files and include dirs to ninja using absolute paths.
|
||||
# Needed for pytest junit reports.
|
||||
$IDF_PATH/tools/idf_tools.py --non-interactive install cmake
|
||||
|
||||
section_start "source_export" "Source export.sh"
|
||||
source ./export.sh
|
||||
section_end "source_export"
|
||||
|
||||
# Custom clang toolchain
|
||||
if [[ ! -z "$CI_CLANG_DISTRO_URL" ]]; then
|
||||
if [[ "$IDF_TOOLCHAIN" == "clang" && ! -z "$CI_CLANG_DISTRO_URL" ]]; then
|
||||
echo "Using custom clang from ${CI_CLANG_DISTRO_URL}"
|
||||
wget $CI_CLANG_DISTRO_URL
|
||||
ARCH_NAME=$(basename $CI_CLANG_DISTRO_URL)
|
||||
@@ -198,6 +206,8 @@ variables:
|
||||
rm -rf ${CI_PYTHON_TOOL_REPO}
|
||||
fi
|
||||
|
||||
info "setup tools and python venv done"
|
||||
|
||||
.show_ccache_statistics: &show_ccache_statistics |
|
||||
# Show ccache statistics if enabled globally
|
||||
test "$CI_CCACHE_STATS" == 1 && test -n "$(which ccache)" && ccache --show-stats -vv || true
|
||||
@@ -222,18 +232,20 @@ variables:
|
||||
- export IDF_TOOLS_PATH="${HOME}/.espressif_runner_${CI_RUNNER_ID}_${CI_CONCURRENT_ID}"
|
||||
# remove idf-env.json, since it may contains enabled "features"
|
||||
- rm -f $IDF_TOOLS_PATH/idf-env.json
|
||||
- $IDF_PATH/tools/idf_tools.py --non-interactive install cmake ninja
|
||||
# This adds tools (compilers) and the version-specific Python environment to PATH
|
||||
- *setup_tools_and_idf_python_venv
|
||||
- fetch_submodules
|
||||
variables:
|
||||
INSTALL_EXTRA_TOOLS: cmake ninja
|
||||
|
||||
.after_script:build:macos:upload-when-fail:
|
||||
.after_script:build:macos:upload-failed-job-logs:ccache-show-stats:
|
||||
after_script:
|
||||
# macos is running shell executor, which means it would use
|
||||
# the system installed /usr/local/bin/python3 by default.
|
||||
# Ensure pyenv and PYENV_VERSION installed
|
||||
- eval "$(pyenv init -)"
|
||||
- *upload_failed_job_log_artifacts
|
||||
- *show_ccache_statistics
|
||||
|
||||
.before_script:build:
|
||||
before_script:
|
||||
@@ -244,11 +256,11 @@ variables:
|
||||
- export EXTRA_CFLAGS=${PEDANTIC_CFLAGS}
|
||||
- export EXTRA_CXXFLAGS=${PEDANTIC_CXXFLAGS}
|
||||
|
||||
.after_script:build:ccache:
|
||||
.after_script:build:ccache-show-stats:
|
||||
after_script:
|
||||
- *show_ccache_statistics
|
||||
|
||||
.after_script:build:ccache:upload-when-fail:
|
||||
.after_script:build:ccache-show-stats:upload-failed-job-logs:
|
||||
after_script:
|
||||
- *show_ccache_statistics
|
||||
- *upload_failed_job_log_artifacts
|
||||
@@ -307,26 +319,32 @@ variables:
|
||||
- *git_init
|
||||
- *git_fetch_from_mirror_url_if_exists
|
||||
- |
|
||||
# Store the diff output in a temporary file
|
||||
TEMP_FILE=$(mktemp)
|
||||
# merged results pipelines, by default
|
||||
if [[ -n $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA ]]; then
|
||||
git fetch origin $CI_MERGE_REQUEST_DIFF_BASE_SHA --depth=1 ${GIT_FETCH_EXTRA_FLAGS}
|
||||
git fetch origin $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA --depth=1 ${GIT_FETCH_EXTRA_FLAGS}
|
||||
export GIT_DIFF_OUTPUT=$(git diff --name-only $CI_MERGE_REQUEST_DIFF_BASE_SHA $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA)
|
||||
git diff --name-only $CI_MERGE_REQUEST_DIFF_BASE_SHA $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA > "$TEMP_FILE"
|
||||
GIT_DIFF_OUTPUT=$(cat "$TEMP_FILE")
|
||||
git fetch origin $CI_COMMIT_SHA --depth=1 ${GIT_FETCH_EXTRA_FLAGS}
|
||||
# merge request pipelines, when the mr got conflicts
|
||||
elif [[ -n $CI_MERGE_REQUEST_DIFF_BASE_SHA ]]; then
|
||||
git fetch origin $CI_MERGE_REQUEST_DIFF_BASE_SHA --depth=1 ${GIT_FETCH_EXTRA_FLAGS}
|
||||
git fetch origin $CI_COMMIT_SHA --depth=1 ${GIT_FETCH_EXTRA_FLAGS}
|
||||
export GIT_DIFF_OUTPUT=$(git diff --name-only $CI_MERGE_REQUEST_DIFF_BASE_SHA $CI_COMMIT_SHA)
|
||||
git diff --name-only $CI_MERGE_REQUEST_DIFF_BASE_SHA $CI_COMMIT_SHA > "$TEMP_FILE"
|
||||
GIT_DIFF_OUTPUT=$(cat "$TEMP_FILE")
|
||||
# other pipelines, like the protected branches pipelines
|
||||
elif [[ "$CI_COMMIT_BEFORE_SHA" != "0000000000000000000000000000000000000000" ]]; then
|
||||
git fetch origin $CI_COMMIT_BEFORE_SHA --depth=1 ${GIT_FETCH_EXTRA_FLAGS}
|
||||
git fetch origin $CI_COMMIT_SHA --depth=1 ${GIT_FETCH_EXTRA_FLAGS}
|
||||
export GIT_DIFF_OUTPUT=$(git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA)
|
||||
git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA > "$TEMP_FILE"
|
||||
GIT_DIFF_OUTPUT=$(cat "$TEMP_FILE")
|
||||
else
|
||||
# pipeline source could be web, scheduler, etc.
|
||||
git fetch origin $CI_COMMIT_SHA --depth=2 ${GIT_FETCH_EXTRA_FLAGS}
|
||||
export GIT_DIFF_OUTPUT=$(git diff --name-only $CI_COMMIT_SHA~1 $CI_COMMIT_SHA)
|
||||
git diff --name-only $CI_COMMIT_SHA~1 $CI_COMMIT_SHA > "$TEMP_FILE"
|
||||
GIT_DIFF_OUTPUT=$(cat "$TEMP_FILE")
|
||||
fi
|
||||
- *git_checkout_ci_commit_sha
|
||||
- *common-before_scripts
|
||||
|
||||
@@ -195,7 +195,7 @@ test_tools:
|
||||
junit: ${IDF_PATH}/XUNIT_*.xml
|
||||
variables:
|
||||
LC_ALL: C.UTF-8
|
||||
INSTALL_QEMU: 1 # for test_idf_qemu.py
|
||||
INSTALL_EXTRA_TOOLS: "qemu-xtensa qemu-riscv32" # for test_idf_qemu.py
|
||||
script:
|
||||
- stat=0
|
||||
- cd ${IDF_PATH}/tools/ci/test_autocomplete
|
||||
@@ -282,9 +282,10 @@ test_pytest_qemu:
|
||||
junit: XUNIT_RESULT.xml
|
||||
parallel:
|
||||
matrix:
|
||||
- IDF_TARGET: [esp32, esp32c3]
|
||||
variables:
|
||||
INSTALL_QEMU: 1
|
||||
- IDF_TARGET: "esp32"
|
||||
INSTALL_EXTRA_TOOLS: "qemu-xtensa"
|
||||
- IDF_TARGET: "esp32c3"
|
||||
INSTALL_EXTRA_TOOLS: "qemu-riscv32"
|
||||
script:
|
||||
- run_cmd python tools/ci/ci_build_apps.py . -v
|
||||
--target $IDF_TARGET
|
||||
@@ -346,9 +347,10 @@ test_pytest_macos:
|
||||
reports:
|
||||
junit: XUNIT_RESULT.xml
|
||||
variables:
|
||||
PYENV_VERSION: "3.9"
|
||||
PYTEST_IGNORE_COLLECT_IMPORT_ERROR: "1"
|
||||
script:
|
||||
- run_cmd python tools/ci/ci_build_apps.py components examples tools/test_apps -vv
|
||||
- run_cmd python tools/ci/ci_build_apps.py components examples tools/test_apps -v
|
||||
--target linux
|
||||
--pytest-apps
|
||||
-m \"host_test and macos_shell\"
|
||||
|
||||
@@ -183,12 +183,24 @@ baseline_manifest_sha:
|
||||
tags: [fast_run, shiny]
|
||||
script:
|
||||
- |
|
||||
if [ -n "$CI_MERGE_REQUEST_DIFF_BASE_SHA" ]; then
|
||||
# merged results pipelines, by default
|
||||
# diff between target-branch-head and merged-result-head
|
||||
if [ -n "$CI_MERGE_REQUEST_TARGET_BRANCH_SHA" ]; then
|
||||
git fetch origin $CI_MERGE_REQUEST_TARGET_BRANCH_SHA --depth=1
|
||||
git checkout FETCH_HEAD
|
||||
idf-build-apps dump-manifest-sha \
|
||||
--manifest-files $(find . -name ".build-test-rules.yml" | xargs) \
|
||||
--output .manifest_sha
|
||||
# merge request pipelines, when the mr got conflicts
|
||||
# diff between diff-base-sha and merge-request-head
|
||||
elif [ -n "$CI_MERGE_REQUEST_DIFF_BASE_SHA" ]; then
|
||||
git fetch origin $CI_MERGE_REQUEST_DIFF_BASE_SHA --depth=1
|
||||
git checkout FETCH_HEAD
|
||||
idf-build-apps dump-manifest-sha \
|
||||
--manifest-files $(find . -name ".build-test-rules.yml" | xargs) \
|
||||
--output .manifest_sha
|
||||
# other pipelines, like the protected branches pipelines
|
||||
# not triggered in this job
|
||||
fi
|
||||
artifacts:
|
||||
paths:
|
||||
|
||||
9
Kconfig
9
Kconfig
@@ -136,6 +136,14 @@ mainmenu "Espressif IoT Development Framework Configuration"
|
||||
select FREERTOS_UNICORE
|
||||
select IDF_TARGET_ARCH_RISCV
|
||||
|
||||
config IDF_TARGET_ESP32H21
|
||||
bool
|
||||
default "y" if IDF_TARGET="esp32h21"
|
||||
select FREERTOS_UNICORE
|
||||
select IDF_TARGET_ARCH_RISCV
|
||||
select IDF_ENV_FPGA
|
||||
select IDF_ENV_BRINGUP
|
||||
|
||||
config IDF_TARGET_LINUX
|
||||
bool
|
||||
default "y" if IDF_TARGET="linux"
|
||||
@@ -152,6 +160,7 @@ mainmenu "Espressif IoT Development Framework Configuration"
|
||||
default 0x0012 if IDF_TARGET_ESP32P4
|
||||
default 0x0017 if IDF_TARGET_ESP32C5
|
||||
default 0x0014 if IDF_TARGET_ESP32C61
|
||||
default 0x0019 if IDF_TARGET_ESP32H21
|
||||
default 0xFFFF
|
||||
|
||||
|
||||
|
||||
@@ -121,16 +121,3 @@ if(CONFIG_APPTRACE_GCOV_ENABLE)
|
||||
else()
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE $<TARGET_FILE:${app_trace}> c)
|
||||
endif()
|
||||
|
||||
# This function adds a dependency on the given component if the component is included into the build.
|
||||
function(maybe_add_component component_name)
|
||||
idf_build_get_property(components BUILD_COMPONENTS)
|
||||
if(${component_name} IN_LIST components)
|
||||
idf_component_get_property(lib_name ${component_name} COMPONENT_LIB)
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC ${lib_name})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
if(CONFIG_APPTRACE_DEST_UART0 OR CONFIG_APPTRACE_DEST_UART1 OR CONFIG_APPTRACE_DEST_UART2)
|
||||
maybe_add_component(driver)
|
||||
endif()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -218,6 +218,13 @@ static esp_err_t esp_apptrace_uart_init(esp_apptrace_uart_data_t *hw_data)
|
||||
hw_data->message_buff_overflow = false;
|
||||
hw_data->circular_buff_overflow = false;
|
||||
|
||||
assert((hw_data->port_num <= SOC_UART_NUM) && "Not possible to configure UART. Please check selected UART port");
|
||||
|
||||
int source_clk = UART_SCLK_DEFAULT;
|
||||
#if SOC_UART_LP_NUM > 0
|
||||
if (hw_data->port_num >= SOC_UART_HP_NUM)
|
||||
source_clk = LP_UART_SCLK_DEFAULT;
|
||||
#endif
|
||||
|
||||
const uart_config_t uart_config = {
|
||||
.baud_rate = CONFIG_APPTRACE_UART_BAUDRATE,
|
||||
@@ -225,7 +232,7 @@ static esp_err_t esp_apptrace_uart_init(esp_apptrace_uart_data_t *hw_data)
|
||||
.parity = UART_PARITY_DISABLE,
|
||||
.stop_bits = UART_STOP_BITS_1,
|
||||
.flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
|
||||
.source_clk = UART_SCLK_DEFAULT,
|
||||
.source_clk = source_clk,
|
||||
};
|
||||
ESP_LOGI(TAG, "UART baud rate: %i", CONFIG_APPTRACE_UART_BAUDRATE);
|
||||
// We won't use a buffer for sending data.
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-1-Clause
|
||||
*
|
||||
* SPDX-FileContributor: 2017-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileContributor: 2017-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*/
|
||||
/*********************************************************************
|
||||
* SEGGER Microcontroller GmbH *
|
||||
@@ -58,6 +58,7 @@ File : SEGGER_SYSVIEW_Config_FreeRTOS.c
|
||||
Purpose : Sample setup configuration of SystemView with FreeRTOS.
|
||||
Revision: $Rev: 7745 $
|
||||
*/
|
||||
#include <string.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "SEGGER_SYSVIEW.h"
|
||||
@@ -156,15 +157,16 @@ static esp_apptrace_lock_t s_sys_view_lock = {.mux = portMUX_INITIALIZER_UNLOCKE
|
||||
* Sends SystemView description strings.
|
||||
*/
|
||||
static void _cbSendSystemDesc(void) {
|
||||
char irq_str[32];
|
||||
char irq_str[32] = "I#";
|
||||
SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME",C="SYSVIEW_CORE_NAME",O=FreeRTOS");
|
||||
snprintf(irq_str, sizeof(irq_str), "I#%d=SysTick", SYSTICK_INTR_ID);
|
||||
strcat(itoa(SYSTICK_INTR_ID, irq_str + 2, 10), "=SysTick");
|
||||
SEGGER_SYSVIEW_SendSysDesc(irq_str);
|
||||
size_t isr_count = sizeof(esp_isr_names)/sizeof(esp_isr_names[0]);
|
||||
for (size_t i = 0; i < isr_count; ++i) {
|
||||
if (esp_isr_names[i] == NULL || (ETS_INTERNAL_INTR_SOURCE_OFF + i) == SYSTICK_INTR_ID)
|
||||
continue;
|
||||
snprintf(irq_str, sizeof(irq_str), "I#%d=%s", ETS_INTERNAL_INTR_SOURCE_OFF + i, esp_isr_names[i]);
|
||||
strcat(itoa(ETS_INTERNAL_INTR_SOURCE_OFF + i, irq_str + 2, 10), "=");
|
||||
strncat(irq_str, esp_isr_names[i], sizeof(irq_str) - strlen(irq_str) - 1);
|
||||
SEGGER_SYSVIEW_SendSysDesc(irq_str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,13 +31,19 @@
|
||||
#include "esp_attr.h"
|
||||
#include "esp_bootloader_desc.h"
|
||||
#include "esp_flash.h"
|
||||
#include "esp_flash_internal.h"
|
||||
|
||||
#define SUB_TYPE_ID(i) (i & 0x0F)
|
||||
#define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1))
|
||||
|
||||
/* Partial_data is word aligned so no reallocation is necessary for encrypted flash write */
|
||||
typedef struct ota_ops_entry_ {
|
||||
uint32_t handle;
|
||||
const esp_partition_t *part;
|
||||
struct {
|
||||
const esp_partition_t *staging; /*!< New image will be downloaded in this staging partition. */
|
||||
const esp_partition_t *final; /*!< Final destination partition which is intended to be updated. Its type/subtype shall be used for verification. */
|
||||
bool finalize_with_copy; /*!< Flag to copy the image from staging partition to the final partition at the end of OTA update */
|
||||
} partition;
|
||||
bool need_erase;
|
||||
uint32_t wrote_size;
|
||||
uint8_t partial_bytes;
|
||||
@@ -52,6 +58,8 @@ static uint32_t s_ota_ops_last_handle = 0;
|
||||
|
||||
const static char *TAG = "esp_ota_ops";
|
||||
|
||||
static ota_ops_entry_t *get_ota_ops_entry(esp_ota_handle_t handle);
|
||||
|
||||
/* Return true if this is an OTA app partition */
|
||||
static bool is_ota_partition(const esp_partition_t *p)
|
||||
{
|
||||
@@ -114,8 +122,6 @@ static esp_ota_img_states_t set_new_state_otadata(void)
|
||||
esp_err_t esp_ota_begin(const esp_partition_t *partition, size_t image_size, esp_ota_handle_t *out_handle)
|
||||
{
|
||||
ota_ops_entry_t *new_entry;
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
if ((partition == NULL) || (out_handle == NULL)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
@@ -125,36 +131,26 @@ esp_err_t esp_ota_begin(const esp_partition_t *partition, size_t image_size, esp
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
if (!is_ota_partition(partition)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (partition->type == ESP_PARTITION_TYPE_APP) {
|
||||
// The staging partition cannot be of type Factory, but the final partition can be.
|
||||
if (!is_ota_partition(partition)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
const esp_partition_t* running_partition = esp_ota_get_running_partition();
|
||||
if (partition == running_partition) {
|
||||
return ESP_ERR_OTA_PARTITION_CONFLICT;
|
||||
}
|
||||
const esp_partition_t* running_partition = esp_ota_get_running_partition();
|
||||
if (partition == running_partition) {
|
||||
return ESP_ERR_OTA_PARTITION_CONFLICT;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE
|
||||
esp_ota_img_states_t ota_state_running_part;
|
||||
if (esp_ota_get_state_partition(running_partition, &ota_state_running_part) == ESP_OK) {
|
||||
if (ota_state_running_part == ESP_OTA_IMG_PENDING_VERIFY) {
|
||||
ESP_LOGE(TAG, "Running app has not confirmed state (ESP_OTA_IMG_PENDING_VERIFY)");
|
||||
return ESP_ERR_OTA_ROLLBACK_INVALID_STATE;
|
||||
esp_ota_img_states_t ota_state_running_part;
|
||||
if (esp_ota_get_state_partition(running_partition, &ota_state_running_part) == ESP_OK) {
|
||||
if (ota_state_running_part == ESP_OTA_IMG_PENDING_VERIFY) {
|
||||
ESP_LOGE(TAG, "Running app has not confirmed state (ESP_OTA_IMG_PENDING_VERIFY)");
|
||||
return ESP_ERR_OTA_ROLLBACK_INVALID_STATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (image_size != OTA_WITH_SEQUENTIAL_WRITES) {
|
||||
// If input image size is 0 or OTA_SIZE_UNKNOWN, erase entire partition
|
||||
if ((image_size == 0) || (image_size == OTA_SIZE_UNKNOWN)) {
|
||||
ret = esp_partition_erase_range(partition, 0, partition->size);
|
||||
} else {
|
||||
const int aligned_erase_size = (image_size + partition->erase_size - 1) & ~(partition->erase_size - 1);
|
||||
ret = esp_partition_erase_range(partition, 0, aligned_erase_size);
|
||||
}
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
new_entry = (ota_ops_entry_t *) calloc(1, sizeof(ota_ops_entry_t));
|
||||
@@ -164,10 +160,60 @@ esp_err_t esp_ota_begin(const esp_partition_t *partition, size_t image_size, esp
|
||||
|
||||
LIST_INSERT_HEAD(&s_ota_ops_entries_head, new_entry, entries);
|
||||
|
||||
new_entry->part = partition;
|
||||
new_entry->partition.staging = partition;
|
||||
new_entry->partition.final = partition;
|
||||
new_entry->partition.finalize_with_copy = false;
|
||||
new_entry->handle = ++s_ota_ops_last_handle;
|
||||
new_entry->need_erase = (image_size == OTA_WITH_SEQUENTIAL_WRITES);
|
||||
*out_handle = new_entry->handle;
|
||||
|
||||
if (partition->type == ESP_PARTITION_TYPE_BOOTLOADER) {
|
||||
esp_image_bootloader_offset_set(partition->address);
|
||||
}
|
||||
if (partition->type == ESP_PARTITION_TYPE_BOOTLOADER || partition->type == ESP_PARTITION_TYPE_PARTITION_TABLE) {
|
||||
esp_flash_set_dangerous_write_protection(esp_flash_default_chip, false);
|
||||
}
|
||||
|
||||
if (image_size != OTA_WITH_SEQUENTIAL_WRITES) {
|
||||
// If input image size is 0 or OTA_SIZE_UNKNOWN, erase entire partition
|
||||
size_t erase_size;
|
||||
if ((image_size == 0) || (image_size == OTA_SIZE_UNKNOWN)) {
|
||||
erase_size = partition->size;
|
||||
} else {
|
||||
erase_size = ALIGN_UP(image_size, partition->erase_size);
|
||||
}
|
||||
return esp_partition_erase_range(partition, 0, erase_size);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_ota_set_final_partition(esp_ota_handle_t handle, const esp_partition_t *final, bool finalize_with_copy)
|
||||
{
|
||||
ota_ops_entry_t *it = get_ota_ops_entry(handle);
|
||||
if (final == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (it == NULL) {
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
if (it->wrote_size != 0) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
if (it->partition.staging != final) {
|
||||
const esp_partition_t* final_partition = esp_partition_verify(final);
|
||||
if (final_partition == NULL) {
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
ESP_LOGI(TAG,"Staging partition - <%s>. Final partition - <%s>.", it->partition.staging->label, final_partition->label);
|
||||
it->partition.final = final_partition;
|
||||
it->partition.finalize_with_copy = finalize_with_copy;
|
||||
if (final_partition->type == ESP_PARTITION_TYPE_BOOTLOADER) {
|
||||
esp_image_bootloader_offset_set(it->partition.staging->address);
|
||||
}
|
||||
if (final_partition->type == ESP_PARTITION_TYPE_BOOTLOADER || final_partition->type == ESP_PARTITION_TYPE_PARTITION_TABLE) {
|
||||
esp_flash_set_dangerous_write_protection(esp_flash_default_chip, false);
|
||||
}
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@@ -192,23 +238,33 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size)
|
||||
if (it->handle == handle) {
|
||||
if (it->need_erase) {
|
||||
// must erase the partition before writing to it
|
||||
uint32_t first_sector = it->wrote_size / it->part->erase_size; // first affected sector
|
||||
uint32_t last_sector = (it->wrote_size + size - 1) / it->part->erase_size; // last affected sector
|
||||
uint32_t first_sector = it->wrote_size / it->partition.staging->erase_size; // first affected sector
|
||||
uint32_t last_sector = (it->wrote_size + size - 1) / it->partition.staging->erase_size; // last affected sector
|
||||
|
||||
ret = ESP_OK;
|
||||
if ((it->wrote_size % it->part->erase_size) == 0) {
|
||||
ret = esp_partition_erase_range(it->part, it->wrote_size, ((last_sector - first_sector) + 1) * it->part->erase_size);
|
||||
if ((it->wrote_size % it->partition.staging->erase_size) == 0) {
|
||||
ret = esp_partition_erase_range(it->partition.staging, it->wrote_size, ((last_sector - first_sector) + 1) * it->partition.staging->erase_size);
|
||||
} else if (first_sector != last_sector) {
|
||||
ret = esp_partition_erase_range(it->part, (first_sector + 1) * it->part->erase_size, (last_sector - first_sector) * it->part->erase_size);
|
||||
ret = esp_partition_erase_range(it->partition.staging, (first_sector + 1) * it->partition.staging->erase_size, (last_sector - first_sector) * it->partition.staging->erase_size);
|
||||
}
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
if (it->wrote_size == 0 && it->partial_bytes == 0 && size > 0 && data_bytes[0] != ESP_IMAGE_HEADER_MAGIC) {
|
||||
ESP_LOGE(TAG, "OTA image has invalid magic byte (expected 0xE9, saw 0x%02x)", data_bytes[0]);
|
||||
return ESP_ERR_OTA_VALIDATE_FAILED;
|
||||
if (it->wrote_size == 0 && it->partial_bytes == 0 && size > 0) {
|
||||
if (it->partition.final->type == ESP_PARTITION_TYPE_APP || it->partition.final->type == ESP_PARTITION_TYPE_BOOTLOADER) {
|
||||
if (data_bytes[0] != ESP_IMAGE_HEADER_MAGIC) {
|
||||
ESP_LOGE(TAG, "OTA image has invalid magic byte (expected 0xE9, saw 0x%02x)", data_bytes[0]);
|
||||
return ESP_ERR_OTA_VALIDATE_FAILED;
|
||||
}
|
||||
|
||||
} else if (it->partition.final->type == ESP_PARTITION_TYPE_PARTITION_TABLE) {
|
||||
if (*(uint16_t*)data_bytes != (uint16_t)ESP_PARTITION_MAGIC) {
|
||||
ESP_LOGE(TAG, "Partition table image has invalid magic word (expected 0x50AA, saw 0x%04x)", *(uint16_t*)data_bytes);
|
||||
return ESP_ERR_OTA_VALIDATE_FAILED;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (esp_flash_encryption_enabled()) {
|
||||
@@ -224,7 +280,7 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size)
|
||||
return ESP_OK; /* nothing to write yet, just filling buffer */
|
||||
}
|
||||
/* write 16 byte to partition */
|
||||
ret = esp_partition_write(it->part, it->wrote_size, it->partial_data, 16);
|
||||
ret = esp_partition_write(it->partition.staging, it->wrote_size, it->partial_data, 16);
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
@@ -243,7 +299,7 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size)
|
||||
}
|
||||
}
|
||||
|
||||
ret = esp_partition_write(it->part, it->wrote_size, data_bytes, size);
|
||||
ret = esp_partition_write(it->partition.staging, it->wrote_size, data_bytes, size);
|
||||
if(ret == ESP_OK){
|
||||
it->wrote_size += size;
|
||||
}
|
||||
@@ -280,7 +336,7 @@ esp_err_t esp_ota_write_with_offset(esp_ota_handle_t handle, const void *data, s
|
||||
ESP_LOGE(TAG, "Size should be 16byte aligned for flash encryption case");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ret = esp_partition_write(it->part, offset, data_bytes, size);
|
||||
ret = esp_partition_write(it->partition.staging, offset, data_bytes, size);
|
||||
if (ret == ESP_OK) {
|
||||
it->wrote_size += size;
|
||||
}
|
||||
@@ -316,6 +372,34 @@ esp_err_t esp_ota_abort(esp_ota_handle_t handle)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t ota_verify_partition(ota_ops_entry_t *ota_ops)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
if (ota_ops->partition.final->type == ESP_PARTITION_TYPE_APP || ota_ops->partition.final->type == ESP_PARTITION_TYPE_BOOTLOADER) {
|
||||
esp_image_metadata_t data;
|
||||
const esp_partition_pos_t part_pos = {
|
||||
.offset = ota_ops->partition.staging->address,
|
||||
.size = ota_ops->partition.staging->size,
|
||||
};
|
||||
if (esp_image_verify(ESP_IMAGE_VERIFY, &part_pos, &data) != ESP_OK) {
|
||||
return ESP_ERR_OTA_VALIDATE_FAILED;
|
||||
}
|
||||
} else if (ota_ops->partition.final->type == ESP_PARTITION_TYPE_PARTITION_TABLE) {
|
||||
const esp_partition_info_t *partition_table = NULL;
|
||||
esp_partition_mmap_handle_t partition_table_map;
|
||||
ret = esp_partition_mmap(ota_ops->partition.staging, 0, ESP_PARTITION_TABLE_MAX_LEN, ESP_PARTITION_MMAP_DATA, (const void**)&partition_table, &partition_table_map);
|
||||
if (ret == ESP_OK) {
|
||||
int num_partitions;
|
||||
if (esp_partition_table_verify(partition_table, true, &num_partitions) != ESP_OK) {
|
||||
esp_partition_munmap(partition_table_map);
|
||||
return ESP_ERR_OTA_VALIDATE_FAILED;
|
||||
}
|
||||
esp_partition_munmap(partition_table_map);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t esp_ota_end(esp_ota_handle_t handle)
|
||||
{
|
||||
ota_ops_entry_t *it = get_ota_ops_entry(handle);
|
||||
@@ -335,7 +419,7 @@ esp_err_t esp_ota_end(esp_ota_handle_t handle)
|
||||
|
||||
if (it->partial_bytes > 0) {
|
||||
/* Write out last 16 bytes, if necessary */
|
||||
ret = esp_partition_write(it->part, it->wrote_size, it->partial_data, 16);
|
||||
ret = esp_partition_write(it->partition.staging, it->wrote_size, it->partial_data, 16);
|
||||
if (ret != ESP_OK) {
|
||||
ret = ESP_ERR_INVALID_STATE;
|
||||
goto cleanup;
|
||||
@@ -344,18 +428,21 @@ esp_err_t esp_ota_end(esp_ota_handle_t handle)
|
||||
it->partial_bytes = 0;
|
||||
}
|
||||
|
||||
esp_image_metadata_t data;
|
||||
const esp_partition_pos_t part_pos = {
|
||||
.offset = it->part->address,
|
||||
.size = it->part->size,
|
||||
};
|
||||
|
||||
if (esp_image_verify(ESP_IMAGE_VERIFY, &part_pos, &data) != ESP_OK) {
|
||||
ret = ESP_ERR_OTA_VALIDATE_FAILED;
|
||||
goto cleanup;
|
||||
ret = ota_verify_partition(it);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "New image failed verification");
|
||||
} else {
|
||||
if (it->partition.finalize_with_copy) {
|
||||
ESP_LOGI(TAG, "Copy from <%s> staging partition to <%s>...", it->partition.staging->label, it->partition.final->label);
|
||||
ret = esp_partition_copy(it->partition.final, 0, it->partition.staging, 0, it->partition.final->size);
|
||||
}
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if (it->partition.final->type == ESP_PARTITION_TYPE_BOOTLOADER) {
|
||||
// In esp_ota_begin, bootloader offset was updated, here we return it to default.
|
||||
esp_image_bootloader_offset_set(ESP_PRIMARY_BOOTLOADER_OFFSET);
|
||||
}
|
||||
LIST_REMOVE(it, entries);
|
||||
free(it);
|
||||
return ret;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -82,7 +82,11 @@ int esp_ota_get_app_elf_sha256(char* dst, size_t size) __attribute__((deprecated
|
||||
* it will lead to the ESP_ERR_OTA_ROLLBACK_INVALID_STATE error. Confirm the running app before to run download a new app,
|
||||
* use esp_ota_mark_app_valid_cancel_rollback() function for it (this should be done as early as possible when you first download a new application).
|
||||
*
|
||||
* @param partition Pointer to info for partition which will receive the OTA update. Required.
|
||||
* Note: Rollback is applicable only for app type partitions.
|
||||
*
|
||||
* @param partition Pointer to info for partition which will receive the OTA update. Required.
|
||||
* This is considered as the staging partition (where OTA is downloaded), be default this also considered as the final partition which supposed to be updated.
|
||||
* The final partition can be overwritten using esp_ota_set_final_partition() after calling esp_ota_begin() to relocate contents to the final destination partition.
|
||||
* @param image_size Size of new OTA app image. Partition will be erased in order to receive this size of image. If 0 or OTA_SIZE_UNKNOWN, the entire partition is erased.
|
||||
* @param out_handle On success, returns a handle which should be used for subsequent esp_ota_write() and esp_ota_end() calls.
|
||||
|
||||
@@ -99,6 +103,31 @@ int esp_ota_get_app_elf_sha256(char* dst, size_t size) __attribute__((deprecated
|
||||
*/
|
||||
esp_err_t esp_ota_begin(const esp_partition_t* partition, size_t image_size, esp_ota_handle_t* out_handle);
|
||||
|
||||
/**
|
||||
* @brief Set the final destination partition for OTA update
|
||||
*
|
||||
* This function configures the specified final partition as the destination for the OTA update.
|
||||
* It also allows setting a flag to indicate if the image should be copied from the staging
|
||||
* partition to the final partition after the OTA update completes. Otherwise, copying will need
|
||||
* to be handled by custom code using esp_partition_copy().
|
||||
*
|
||||
* @note This can be called after esp_ota_begin() and before the OTA update has started (before esp_ota_write()).
|
||||
*
|
||||
* @param handle OTA update handle obtained from esp_ota_begin().
|
||||
* @param final Pointer to the final destination partition where the new image will be verified and potentially finalized.
|
||||
* This partition must not be NULL.
|
||||
* @param finalize_with_copy Boolean flag indicating if the downloaded image should be copied
|
||||
* from the staging partition to the final partition upon completion.
|
||||
* Set to False if you intend to perform the final copy process manually later.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: final destination partition set successfully.
|
||||
* - ESP_ERR_INVALID_STATE: Once the OTA update has started, changing the final destination partition is prohibited.
|
||||
* - ESP_ERR_INVALID_ARG: Invalid arguments were passed (e.g., final partition is NULL).
|
||||
* - ESP_ERR_NOT_FOUND: OTA handle not found or final partition verification failed.
|
||||
*/
|
||||
esp_err_t esp_ota_set_final_partition(esp_ota_handle_t handle, const esp_partition_t *final, bool finalize_with_copy);
|
||||
|
||||
/**
|
||||
* @brief Write OTA update data to partition
|
||||
*
|
||||
@@ -113,9 +142,8 @@ esp_err_t esp_ota_begin(const esp_partition_t* partition, size_t image_size, esp
|
||||
* @return
|
||||
* - ESP_OK: Data was written to flash successfully, or size = 0
|
||||
* - ESP_ERR_INVALID_ARG: handle is invalid.
|
||||
* - ESP_ERR_OTA_VALIDATE_FAILED: First byte of image contains invalid app image magic byte.
|
||||
* - ESP_ERR_OTA_VALIDATE_FAILED: First byte of image contains invalid image magic byte.
|
||||
* - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash write failed.
|
||||
* - ESP_ERR_OTA_SELECT_INFO_INVALID: OTA data partition has invalid contents
|
||||
* - ESP_ERR_INVALID_SIZE: if write would go out of bounds of the partition
|
||||
* - or one of error codes from lower-level flash driver.
|
||||
*/
|
||||
@@ -138,9 +166,7 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void* data, size_t size);
|
||||
* @return
|
||||
* - ESP_OK: Data was written to flash successfully.
|
||||
* - ESP_ERR_INVALID_ARG: handle is invalid.
|
||||
* - ESP_ERR_OTA_VALIDATE_FAILED: First byte of image contains invalid app image magic byte.
|
||||
* - ESP_ERR_FLASH_OP_TIMEOUT or ESP_ERR_FLASH_OP_FAIL: Flash write failed.
|
||||
* - ESP_ERR_OTA_SELECT_INFO_INVALID: OTA data partition has invalid contents
|
||||
*/
|
||||
esp_err_t esp_ota_write_with_offset(esp_ota_handle_t handle, const void *data, size_t size, uint32_t offset);
|
||||
|
||||
@@ -150,6 +176,11 @@ esp_err_t esp_ota_write_with_offset(esp_ota_handle_t handle, const void *data, s
|
||||
* @param handle Handle obtained from esp_ota_begin().
|
||||
*
|
||||
* @note After calling esp_ota_end(), the handle is no longer valid and any memory associated with it is freed (regardless of result).
|
||||
* @note If either the final or staging partitions were for the bootloader, then at the end of this function,
|
||||
* the bootloader is reset to its default offset: esp_image_bootloader_offset_set(ESP_PRIMARY_BOOTLOADER_OFFSET)
|
||||
*
|
||||
* If the finalize_with_copy option is set, the staging partition will be copied to the final partition at the end of this function.
|
||||
* Otherwise, copying will need to be handled by custom code using esp_partition_copy().
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Newly written OTA app image is valid.
|
||||
@@ -258,7 +289,7 @@ esp_err_t esp_ota_get_partition_description(const esp_partition_t *partition, es
|
||||
* @brief Returns the description structure of the bootloader.
|
||||
*
|
||||
* @param[in] bootloader_partition Pointer to bootloader partition.
|
||||
* If NULL, then the current bootloader is used (the default location).
|
||||
* If NULL, then the PRIMARY bootloader is used (the default location).
|
||||
* offset = CONFIG_BOOTLOADER_OFFSET_IN_FLASH,
|
||||
* size = CONFIG_PARTITION_TABLE_OFFSET - CONFIG_BOOTLOADER_OFFSET_IN_FLASH,
|
||||
* @param[out] desc Structure of info about bootloader.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
components/app_update/test_apps:
|
||||
enable:
|
||||
- if: CONFIG_NAME == "defaults" and IDF_TARGET != "linux"
|
||||
- if: CONFIG_NAME == "defaults" and IDF_TARGET in ["esp32", "esp32c2", "esp32c3", "esp32c5", "esp32c6", "esp32c61", "esp32h2", "esp32p4", "esp32s2", "esp32s3"]
|
||||
- if: CONFIG_NAME == "xip_psram" and IDF_TARGET in ["esp32s2", "esp32s3", "esp32p4"]
|
||||
# S2 doesn't have ROM for flash
|
||||
- if: CONFIG_NAME == "xip_psram_with_rom_impl" and IDF_TARGET in ["esp32s3", "esp32p4"]
|
||||
|
||||
@@ -0,0 +1,256 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "esp_ota_ops.h"
|
||||
#include "esp_partition.h"
|
||||
#include "esp_flash_partitions.h"
|
||||
#include "esp_flash_internal.h"
|
||||
#include "spi_flash_mmap.h"
|
||||
#include "esp_image_format.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_log.h"
|
||||
#include "unity.h"
|
||||
#include "nvs_flash.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
static const char *TAG = "test";
|
||||
|
||||
static uint8_t buffer[SPI_FLASH_SEC_SIZE];
|
||||
|
||||
// Find the unused offset after the last partition, checking that it is of the required size
|
||||
static uint32_t find_unused_space(size_t required_size)
|
||||
{
|
||||
esp_partition_iterator_t it = esp_partition_find(ESP_PARTITION_TYPE_ANY, ESP_PARTITION_SUBTYPE_ANY, NULL);
|
||||
TEST_ASSERT_NOT_NULL(it);
|
||||
const esp_partition_t* latest_partition = esp_partition_get(it);
|
||||
for (; it != NULL; it = esp_partition_next(it)) {
|
||||
const esp_partition_t *p = esp_partition_get(it);
|
||||
if (p->address > latest_partition->address) {
|
||||
latest_partition = p;
|
||||
}
|
||||
}
|
||||
esp_partition_iterator_release(it);
|
||||
TEST_ASSERT_NOT_NULL(latest_partition);
|
||||
|
||||
#if CONFIG_IDF_TARGET_LINUX
|
||||
uint32_t flash_chip_size;
|
||||
esp_flash_get_size(NULL, &flash_chip_size);
|
||||
#else
|
||||
uint32_t flash_chip_size = esp_flash_default_chip->size;
|
||||
#endif // CONFIG_IDF_TARGET_LINUX
|
||||
uint32_t unused_offset = latest_partition->address + latest_partition->size;
|
||||
TEST_ASSERT_GREATER_OR_EQUAL_UINT32(required_size, flash_chip_size - unused_offset);
|
||||
return unused_offset;
|
||||
}
|
||||
|
||||
static void check_after_reboot(void)
|
||||
{
|
||||
ESP_LOGI(TAG, "App runs");
|
||||
}
|
||||
|
||||
static void download_new_image_from_partition(esp_ota_handle_t update_handle, const esp_partition_t *copy_from_part)
|
||||
{
|
||||
uint32_t offset = 0;
|
||||
ESP_LOGI(TAG, "Downloading image...");
|
||||
do {
|
||||
TEST_ESP_OK(esp_partition_read(copy_from_part, offset, buffer, sizeof(buffer)));
|
||||
TEST_ESP_OK(esp_ota_write(update_handle, buffer, sizeof(buffer)));
|
||||
offset += sizeof(buffer);
|
||||
} while (offset < copy_from_part->size);
|
||||
}
|
||||
|
||||
static void start_bootloader_ota_update_via_ota_bootloader_part(void)
|
||||
{
|
||||
const esp_partition_t *primary_bootloader;
|
||||
TEST_ESP_OK(esp_partition_register_external(NULL, ESP_PRIMARY_BOOTLOADER_OFFSET, ESP_BOOTLOADER_SIZE, "PrimaryBTLDR", ESP_PARTITION_TYPE_BOOTLOADER, ESP_PARTITION_SUBTYPE_BOOTLOADER_PRIMARY, &primary_bootloader));
|
||||
|
||||
const esp_partition_t *ota_bootloader;
|
||||
const uint32_t ota_bootloader_offset = find_unused_space(ESP_BOOTLOADER_SIZE);
|
||||
TEST_ESP_OK(esp_partition_register_external(NULL, ota_bootloader_offset, ESP_BOOTLOADER_SIZE, "OtaBTLDR", ESP_PARTITION_TYPE_BOOTLOADER, ESP_PARTITION_SUBTYPE_BOOTLOADER_OTA, &ota_bootloader));
|
||||
|
||||
esp_ota_handle_t update_handle;
|
||||
TEST_ESP_OK(esp_ota_begin(ota_bootloader, OTA_WITH_SEQUENTIAL_WRITES, &update_handle));
|
||||
TEST_ESP_OK(esp_ota_set_final_partition(update_handle, primary_bootloader, true));
|
||||
download_new_image_from_partition(update_handle, primary_bootloader);
|
||||
TEST_ESP_OK(esp_ota_end(update_handle));
|
||||
|
||||
TEST_ESP_OK(esp_partition_deregister_external(primary_bootloader));
|
||||
TEST_ESP_OK(esp_partition_deregister_external(ota_bootloader));
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
TEST_CASE_MULTIPLE_STAGES("OTA update of bootloader via temp partition", "[bootloader_ota][reset=SW_CPU_RESET]", start_bootloader_ota_update_via_ota_bootloader_part, check_after_reboot);
|
||||
|
||||
static void start_bootloader_ota_update_via_primary_bootloader_part(void)
|
||||
{
|
||||
const esp_partition_t *primary_bootloader;
|
||||
TEST_ESP_OK(esp_partition_register_external(NULL, ESP_PRIMARY_BOOTLOADER_OFFSET, ESP_BOOTLOADER_SIZE, "PrimaryBTLDR", ESP_PARTITION_TYPE_BOOTLOADER, ESP_PARTITION_SUBTYPE_BOOTLOADER_PRIMARY, &primary_bootloader));
|
||||
|
||||
esp_ota_handle_t update_handle;
|
||||
TEST_ESP_OK(esp_ota_begin(primary_bootloader, OTA_WITH_SEQUENTIAL_WRITES, &update_handle));
|
||||
download_new_image_from_partition(update_handle, primary_bootloader);
|
||||
TEST_ESP_OK(esp_ota_end(update_handle));
|
||||
|
||||
TEST_ESP_OK(esp_partition_deregister_external(primary_bootloader));
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
TEST_CASE_MULTIPLE_STAGES("OTA update of bootloader via primary partition", "[bootloader_ota][reset=SW_CPU_RESET]", start_bootloader_ota_update_via_primary_bootloader_part, check_after_reboot);
|
||||
|
||||
static void start_partition_table_ota_update_via_ota_part_table(void)
|
||||
{
|
||||
const esp_partition_t *primary_partition_table;
|
||||
const esp_partition_t *ota_partition_table;
|
||||
TEST_ESP_OK(esp_partition_register_external(NULL, ESP_PRIMARY_PARTITION_TABLE_OFFSET, ESP_PARTITION_TABLE_SIZE, "PrimaryPrtTable", ESP_PARTITION_TYPE_PARTITION_TABLE, ESP_PARTITION_SUBTYPE_PARTITION_TABLE_PRIMARY, &primary_partition_table));
|
||||
|
||||
uint32_t ota_partition_table_offset = find_unused_space(ESP_PARTITION_TABLE_SIZE);
|
||||
TEST_ESP_OK(esp_partition_register_external(NULL, ota_partition_table_offset, ESP_PARTITION_TABLE_SIZE, "OtaPrtTable", ESP_PARTITION_TYPE_PARTITION_TABLE, ESP_PARTITION_SUBTYPE_PARTITION_TABLE_OTA, &ota_partition_table));
|
||||
|
||||
esp_ota_handle_t update_handle;
|
||||
TEST_ESP_OK(esp_ota_begin(ota_partition_table, OTA_WITH_SEQUENTIAL_WRITES, &update_handle));
|
||||
TEST_ESP_OK(esp_ota_set_final_partition(update_handle, primary_partition_table, true));
|
||||
download_new_image_from_partition(update_handle, primary_partition_table);
|
||||
TEST_ESP_OK(esp_ota_end(update_handle));
|
||||
|
||||
TEST_ESP_OK(esp_partition_deregister_external(primary_partition_table));
|
||||
TEST_ESP_OK(esp_partition_deregister_external(ota_partition_table));
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
TEST_CASE_MULTIPLE_STAGES("OTA update of partition_table via temp partition", "[partition_table_ota][reset=SW_CPU_RESET]", start_partition_table_ota_update_via_ota_part_table, check_after_reboot);
|
||||
|
||||
static void start_partition_table_ota_update_via_primary_part_table(void)
|
||||
{
|
||||
const esp_partition_t *primary_partition_table;
|
||||
TEST_ESP_OK(esp_partition_register_external(NULL, ESP_PRIMARY_PARTITION_TABLE_OFFSET, ESP_PARTITION_TABLE_SIZE, "PrimaryPrtTable", ESP_PARTITION_TYPE_PARTITION_TABLE, ESP_PARTITION_SUBTYPE_PARTITION_TABLE_PRIMARY, &primary_partition_table));
|
||||
|
||||
esp_ota_handle_t update_handle;
|
||||
TEST_ESP_OK(esp_ota_begin(primary_partition_table, OTA_WITH_SEQUENTIAL_WRITES, &update_handle));
|
||||
download_new_image_from_partition(update_handle, primary_partition_table);
|
||||
TEST_ESP_OK(esp_ota_end(update_handle));
|
||||
|
||||
TEST_ESP_OK(esp_partition_deregister_external(primary_partition_table));
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
TEST_CASE_MULTIPLE_STAGES("OTA update of partition_table via primary partition", "[partition_table_ota][reset=SW_CPU_RESET]", start_partition_table_ota_update_via_primary_part_table, check_after_reboot);
|
||||
|
||||
TEST_CASE("OTA update of NVS partition", "[nvs_ota]")
|
||||
{
|
||||
// intilaize "nvs" partition and define a var (magic_value).
|
||||
TEST_ESP_OK(nvs_flash_erase());
|
||||
TEST_ESP_OK(nvs_flash_init());
|
||||
nvs_handle_t my_handle;
|
||||
TEST_ESP_OK(nvs_open("namespace", NVS_READWRITE, &my_handle));
|
||||
uint32_t magic_value = 0x0729FEED;
|
||||
TEST_ESP_OK(nvs_set_u32(my_handle, "magic_value", magic_value));
|
||||
TEST_ESP_OK(nvs_commit(my_handle));
|
||||
magic_value = 0;
|
||||
TEST_ESP_OK(nvs_get_u32(my_handle, "magic_value", &magic_value));
|
||||
TEST_ASSERT_EQUAL_HEX(0x0729FEED, magic_value);
|
||||
nvs_close(my_handle);
|
||||
TEST_ESP_OK(nvs_flash_deinit());
|
||||
|
||||
// register a new "nvs2" partition
|
||||
const esp_partition_t *nvs_part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, "nvs");
|
||||
const esp_partition_t *nvs2_part;
|
||||
TEST_ESP_OK(esp_partition_register_external(NULL, find_unused_space(nvs_part->size), nvs_part->size, "nvs2", ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, &nvs2_part));
|
||||
ESP_LOGI(TAG, "Use %s partition (0x%08" PRIx32 ") to load a new image", nvs2_part->label, nvs2_part->address);
|
||||
TEST_ESP_OK(nvs_flash_erase_partition("nvs2"));
|
||||
|
||||
// OTA update of the new "nvs2" partition, taking "nvs" partition as source.
|
||||
esp_ota_handle_t update_handle;
|
||||
TEST_ESP_OK(esp_ota_begin(nvs2_part, OTA_WITH_SEQUENTIAL_WRITES, &update_handle));
|
||||
download_new_image_from_partition(update_handle, nvs_part);
|
||||
TEST_ESP_OK(esp_ota_end(update_handle));
|
||||
|
||||
// init "nvs2" partition and check if the magic_value == 0x0729FEED
|
||||
TEST_ESP_OK(nvs_flash_init_partition("nvs2"));
|
||||
nvs_handle_t my_handle2;
|
||||
TEST_ESP_OK(nvs_open_from_partition("nvs2", "namespace", NVS_READWRITE, &my_handle2));
|
||||
magic_value = 0;
|
||||
TEST_ESP_OK(nvs_get_u32(my_handle2, "magic_value", &magic_value));
|
||||
TEST_ASSERT_EQUAL_HEX(0x0729FEED, magic_value);
|
||||
nvs_close(my_handle2);
|
||||
TEST_ESP_OK(nvs_flash_deinit_partition("nvs2"));
|
||||
|
||||
// deregister "nvs2"
|
||||
TEST_ESP_OK(esp_partition_deregister_external(nvs2_part));
|
||||
|
||||
TEST_ESP_OK(nvs_flash_erase());
|
||||
}
|
||||
|
||||
static void start_bootloader_ota_update_via_app_part(void)
|
||||
{
|
||||
const esp_partition_t *primary_bootloader;
|
||||
TEST_ESP_OK(esp_partition_register_external(NULL, ESP_PRIMARY_BOOTLOADER_OFFSET, ESP_BOOTLOADER_SIZE, "PrimaryBTLDR", ESP_PARTITION_TYPE_BOOTLOADER, ESP_PARTITION_SUBTYPE_BOOTLOADER_PRIMARY, &primary_bootloader));
|
||||
|
||||
const esp_partition_t *free_app_ota_partition = esp_ota_get_next_update_partition(NULL);
|
||||
esp_ota_handle_t update_handle;
|
||||
TEST_ESP_OK(esp_ota_begin(free_app_ota_partition, OTA_WITH_SEQUENTIAL_WRITES, &update_handle));
|
||||
TEST_ESP_OK(esp_ota_set_final_partition(update_handle, primary_bootloader, true));
|
||||
download_new_image_from_partition(update_handle, primary_bootloader);
|
||||
TEST_ESP_OK(esp_ota_end(update_handle));
|
||||
|
||||
TEST_ESP_OK(esp_partition_deregister_external(primary_bootloader));
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
TEST_CASE_MULTIPLE_STAGES("OTA update of bootloader via a free ota partition", "[bootloader_ota][reset=SW_CPU_RESET]", start_bootloader_ota_update_via_app_part, check_after_reboot);
|
||||
|
||||
static void start_partition_table_ota_update_via_app_part(void)
|
||||
{
|
||||
const esp_partition_t *primary_partition_table;
|
||||
TEST_ESP_OK(esp_partition_register_external(NULL, ESP_PRIMARY_PARTITION_TABLE_OFFSET, ESP_PARTITION_TABLE_SIZE, "PrimaryPrtTable", ESP_PARTITION_TYPE_PARTITION_TABLE, ESP_PARTITION_SUBTYPE_PARTITION_TABLE_PRIMARY, &primary_partition_table));
|
||||
|
||||
const esp_partition_t *free_app_ota_partition = esp_ota_get_next_update_partition(NULL);
|
||||
esp_ota_handle_t update_handle;
|
||||
TEST_ESP_OK(esp_ota_begin(free_app_ota_partition, OTA_WITH_SEQUENTIAL_WRITES, &update_handle));
|
||||
TEST_ESP_OK(esp_ota_set_final_partition(update_handle, primary_partition_table, true));
|
||||
download_new_image_from_partition(update_handle, primary_partition_table);
|
||||
TEST_ESP_OK(esp_ota_end(update_handle));
|
||||
|
||||
TEST_ESP_OK(esp_partition_deregister_external(primary_partition_table));
|
||||
esp_restart();
|
||||
}
|
||||
|
||||
TEST_CASE_MULTIPLE_STAGES("OTA update of partition_table via a free ota partition", "[partition_table_ota][reset=SW_CPU_RESET]", start_partition_table_ota_update_via_app_part, check_after_reboot);
|
||||
|
||||
TEST_CASE("OTA update of NVS partition via a free ota partition", "[nvs_ota]")
|
||||
{
|
||||
// intilaize "nvs" partition and define a var (magic_value).
|
||||
const esp_partition_t *nvs_part = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, "nvs");
|
||||
TEST_ESP_OK(nvs_flash_erase());
|
||||
TEST_ESP_OK(nvs_flash_init());
|
||||
nvs_handle_t my_handle;
|
||||
TEST_ESP_OK(nvs_open("namespace", NVS_READWRITE, &my_handle));
|
||||
uint32_t magic_value = 0x0729FEED;
|
||||
TEST_ESP_OK(nvs_set_u32(my_handle, "magic_value", magic_value));
|
||||
TEST_ESP_OK(nvs_commit(my_handle));
|
||||
magic_value = 0;
|
||||
TEST_ESP_OK(nvs_get_u32(my_handle, "magic_value", &magic_value));
|
||||
TEST_ASSERT_EQUAL_HEX(0x0729FEED, magic_value);
|
||||
nvs_close(my_handle);
|
||||
TEST_ESP_OK(nvs_flash_deinit());
|
||||
|
||||
// 1. OTA update nvs partition into free_app_ota_partition
|
||||
// 2. copy free_app_ota_partition into the original nvs partition (which was erased before coping)
|
||||
const esp_partition_t *free_app_ota_partition = esp_ota_get_next_update_partition(NULL);
|
||||
esp_ota_handle_t update_handle;
|
||||
TEST_ESP_OK(esp_ota_begin(free_app_ota_partition, OTA_WITH_SEQUENTIAL_WRITES, &update_handle));
|
||||
TEST_ESP_OK(esp_ota_set_final_partition(update_handle, nvs_part, true));
|
||||
download_new_image_from_partition(update_handle, nvs_part);
|
||||
TEST_ESP_OK(esp_ota_end(update_handle));
|
||||
|
||||
// Check if the magic_value == 0x0729FEED
|
||||
TEST_ESP_OK(nvs_flash_init());
|
||||
TEST_ESP_OK(nvs_open("namespace", NVS_READONLY, &my_handle));
|
||||
magic_value = 0;
|
||||
TEST_ESP_OK(nvs_get_u32(my_handle, "magic_value", &magic_value));
|
||||
TEST_ASSERT_EQUAL_HEX(0x0729FEED, magic_value);
|
||||
nvs_close(my_handle);
|
||||
TEST_ESP_OK(nvs_flash_deinit());
|
||||
TEST_ESP_OK(nvs_flash_erase());
|
||||
}
|
||||
@@ -43,7 +43,12 @@ static const char *TAG = "ota_test";
|
||||
static void set_boot_count_in_nvs(uint8_t boot_count)
|
||||
{
|
||||
nvs_handle_t boot_count_handle;
|
||||
TEST_ESP_OK(nvs_open(BOOT_COUNT_NAMESPACE, NVS_READWRITE, &boot_count_handle));
|
||||
esp_err_t err = nvs_open(BOOT_COUNT_NAMESPACE, NVS_READWRITE, &boot_count_handle);
|
||||
if (err != ESP_OK) {
|
||||
TEST_ESP_OK(nvs_flash_erase());
|
||||
TEST_ESP_OK(nvs_flash_init());
|
||||
TEST_ESP_OK(nvs_open(BOOT_COUNT_NAMESPACE, NVS_READWRITE, &boot_count_handle));
|
||||
}
|
||||
TEST_ESP_OK(nvs_set_u8(boot_count_handle, "boot_count", boot_count));
|
||||
TEST_ESP_OK(nvs_commit(boot_count_handle));
|
||||
nvs_close(boot_count_handle);
|
||||
|
||||
68
components/bootloader/Kconfig.app_rollback
Normal file
68
components/bootloader/Kconfig.app_rollback
Normal file
@@ -0,0 +1,68 @@
|
||||
menu "Application Rollback"
|
||||
|
||||
config BOOTLOADER_APP_ROLLBACK_ENABLE
|
||||
bool "Enable app rollback support"
|
||||
default n
|
||||
help
|
||||
After updating the app, the bootloader runs a new app with the "ESP_OTA_IMG_PENDING_VERIFY" state set.
|
||||
This state prevents the re-run of this app. After the first boot of the new app in the user code, the
|
||||
function should be called to confirm the operability of the app or vice versa about its non-operability.
|
||||
If the app is working, then it is marked as valid. Otherwise, it is marked as not valid and rolls back to
|
||||
the previous working app. A reboot is performed, and the app is booted before the software update.
|
||||
Note: If during the first boot a new app the power goes out or the WDT works, then roll back will happen.
|
||||
Rollback is possible only between the apps with the same security versions.
|
||||
|
||||
config BOOTLOADER_APP_ANTI_ROLLBACK
|
||||
bool "Enable app anti-rollback support"
|
||||
depends on BOOTLOADER_APP_ROLLBACK_ENABLE
|
||||
default n
|
||||
help
|
||||
This option prevents rollback to previous firmware/application image with lower security version.
|
||||
|
||||
config BOOTLOADER_APP_SECURE_VERSION
|
||||
int "eFuse secure version of app"
|
||||
depends on BOOTLOADER_APP_ANTI_ROLLBACK
|
||||
default 0
|
||||
help
|
||||
The secure version is the sequence number stored in the header of each firmware.
|
||||
The security version is set in the bootloader, version is recorded in the eFuse field
|
||||
as the number of set ones. The allocated number of bits in the efuse field
|
||||
for storing the security version is limited (see BOOTLOADER_APP_SEC_VER_SIZE_EFUSE_FIELD option).
|
||||
|
||||
Bootloader: When bootloader selects an app to boot, an app is selected that has
|
||||
a security version greater or equal that recorded in eFuse field.
|
||||
The app is booted with a higher (or equal) secure version.
|
||||
|
||||
The security version is worth increasing if in previous versions there is
|
||||
a significant vulnerability and their use is not acceptable.
|
||||
|
||||
Your partition table should has a scheme with ota_0 + ota_1 (without factory).
|
||||
|
||||
config BOOTLOADER_APP_SEC_VER_SIZE_EFUSE_FIELD
|
||||
int "Size of the efuse secure version field"
|
||||
depends on BOOTLOADER_APP_ANTI_ROLLBACK
|
||||
range 1 32 if IDF_TARGET_ESP32
|
||||
default 32 if IDF_TARGET_ESP32
|
||||
range 1 4 if IDF_TARGET_ESP32C2
|
||||
default 4 if IDF_TARGET_ESP32C2
|
||||
range 1 16
|
||||
default 16
|
||||
help
|
||||
The size of the efuse secure version field.
|
||||
Its length is limited to 32 bits for ESP32 and 16 bits for ESP32-S2.
|
||||
This determines how many times the security version can be increased.
|
||||
|
||||
config BOOTLOADER_EFUSE_SECURE_VERSION_EMULATE
|
||||
bool "Emulate operations with efuse secure version(only test)"
|
||||
default n
|
||||
depends on BOOTLOADER_APP_ANTI_ROLLBACK
|
||||
select EFUSE_VIRTUAL
|
||||
select EFUSE_VIRTUAL_KEEP_IN_FLASH
|
||||
help
|
||||
This option allows to emulate read/write operations with all eFuses and efuse secure version.
|
||||
It allows to test anti-rollback implementation without permanent write eFuse bits.
|
||||
There should be an entry in partition table with following details: `emul_efuse, data, efuse, , 0x2000`.
|
||||
|
||||
This option enables: EFUSE_VIRTUAL and EFUSE_VIRTUAL_KEEP_IN_FLASH.
|
||||
|
||||
endmenu
|
||||
25
components/bootloader/Kconfig.bootloader_rollback
Normal file
25
components/bootloader/Kconfig.bootloader_rollback
Normal file
@@ -0,0 +1,25 @@
|
||||
menu "Bootloader Rollback"
|
||||
|
||||
config BOOTLOADER_ANTI_ROLLBACK_ENABLE
|
||||
bool "Enable bootloader rollback support"
|
||||
depends on SOC_RECOVERY_BOOTLOADER_SUPPORTED
|
||||
default n
|
||||
help
|
||||
This option prevents rollback to previous bootloader image with lower security version.
|
||||
|
||||
config BOOTLOADER_SECURE_VERSION
|
||||
int "Secure version of bootloader"
|
||||
depends on BOOTLOADER_ANTI_ROLLBACK_ENABLE
|
||||
default 0
|
||||
range 0 4
|
||||
help
|
||||
The secure version is the sequence number stored in the header of each bootloader.
|
||||
|
||||
The ROM Bootloader which runs the 2nd stage bootloader (PRIMARY or RECOVERY) checks that
|
||||
the security version is greater or equal that recorded in the eFuse field.
|
||||
Bootloaders that have a secure version in the image < secure version in efuse will not boot.
|
||||
|
||||
The security version is worth increasing if in previous versions there is
|
||||
a significant vulnerability and their use is not acceptable.
|
||||
|
||||
endmenu
|
||||
@@ -1,6 +1,8 @@
|
||||
menu "Bootloader config"
|
||||
|
||||
orsource "../esp_bootloader_format/Kconfig.bootloader"
|
||||
orsource "Kconfig.app_rollback"
|
||||
orsource "Kconfig.bootloader_rollback"
|
||||
|
||||
config BOOTLOADER_OFFSET_IN_FLASH
|
||||
hex
|
||||
@@ -312,71 +314,6 @@ menu "Bootloader config"
|
||||
- these options can increase the execution time.
|
||||
Note: RTC_WDT will reset while encryption operations will be performed.
|
||||
|
||||
config BOOTLOADER_APP_ROLLBACK_ENABLE
|
||||
bool "Enable app rollback support"
|
||||
default n
|
||||
help
|
||||
After updating the app, the bootloader runs a new app with the "ESP_OTA_IMG_PENDING_VERIFY" state set.
|
||||
This state prevents the re-run of this app. After the first boot of the new app in the user code, the
|
||||
function should be called to confirm the operability of the app or vice versa about its non-operability.
|
||||
If the app is working, then it is marked as valid. Otherwise, it is marked as not valid and rolls back to
|
||||
the previous working app. A reboot is performed, and the app is booted before the software update.
|
||||
Note: If during the first boot a new app the power goes out or the WDT works, then roll back will happen.
|
||||
Rollback is possible only between the apps with the same security versions.
|
||||
|
||||
config BOOTLOADER_APP_ANTI_ROLLBACK
|
||||
bool "Enable app anti-rollback support"
|
||||
depends on BOOTLOADER_APP_ROLLBACK_ENABLE
|
||||
default n
|
||||
help
|
||||
This option prevents rollback to previous firmware/application image with lower security version.
|
||||
|
||||
config BOOTLOADER_APP_SECURE_VERSION
|
||||
int "eFuse secure version of app"
|
||||
depends on BOOTLOADER_APP_ANTI_ROLLBACK
|
||||
default 0
|
||||
help
|
||||
The secure version is the sequence number stored in the header of each firmware.
|
||||
The security version is set in the bootloader, version is recorded in the eFuse field
|
||||
as the number of set ones. The allocated number of bits in the efuse field
|
||||
for storing the security version is limited (see BOOTLOADER_APP_SEC_VER_SIZE_EFUSE_FIELD option).
|
||||
|
||||
Bootloader: When bootloader selects an app to boot, an app is selected that has
|
||||
a security version greater or equal that recorded in eFuse field.
|
||||
The app is booted with a higher (or equal) secure version.
|
||||
|
||||
The security version is worth increasing if in previous versions there is
|
||||
a significant vulnerability and their use is not acceptable.
|
||||
|
||||
Your partition table should has a scheme with ota_0 + ota_1 (without factory).
|
||||
|
||||
config BOOTLOADER_APP_SEC_VER_SIZE_EFUSE_FIELD
|
||||
int "Size of the efuse secure version field"
|
||||
depends on BOOTLOADER_APP_ANTI_ROLLBACK
|
||||
range 1 32 if IDF_TARGET_ESP32
|
||||
default 32 if IDF_TARGET_ESP32
|
||||
range 1 4 if IDF_TARGET_ESP32C2
|
||||
default 4 if IDF_TARGET_ESP32C2
|
||||
range 1 16
|
||||
default 16
|
||||
help
|
||||
The size of the efuse secure version field.
|
||||
Its length is limited to 32 bits for ESP32 and 16 bits for ESP32-S2.
|
||||
This determines how many times the security version can be increased.
|
||||
|
||||
config BOOTLOADER_EFUSE_SECURE_VERSION_EMULATE
|
||||
bool "Emulate operations with efuse secure version(only test)"
|
||||
default n
|
||||
depends on BOOTLOADER_APP_ANTI_ROLLBACK
|
||||
select EFUSE_VIRTUAL
|
||||
select EFUSE_VIRTUAL_KEEP_IN_FLASH
|
||||
help
|
||||
This option allows to emulate read/write operations with all eFuses and efuse secure version.
|
||||
It allows to test anti-rollback implementation without permanent write eFuse bits.
|
||||
There should be an entry in partition table with following details: `emul_efuse, data, efuse, , 0x2000`.
|
||||
|
||||
This option enables: EFUSE_VIRTUAL and EFUSE_VIRTUAL_KEEP_IN_FLASH.
|
||||
|
||||
config BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP
|
||||
bool "Skip image validation when exiting deep sleep"
|
||||
# note: dependencies for this config item are different to other "skip image validation"
|
||||
|
||||
@@ -116,8 +116,13 @@ idf_build_get_property(sdkconfig SDKCONFIG)
|
||||
idf_build_get_property(python PYTHON)
|
||||
idf_build_get_property(extra_cmake_args EXTRA_CMAKE_ARGS)
|
||||
|
||||
# We cannot pass lists are a parameter to the external project without modifying the ';' separator
|
||||
# BOOTLOADER_EXTRA_COMPONENT_DIRS may have been set by the `main` component, do not overwrite it
|
||||
idf_build_get_property(bootloader_extra_component_dirs BOOTLOADER_EXTRA_COMPONENT_DIRS)
|
||||
list(APPEND bootloader_extra_component_dirs "${CMAKE_CURRENT_LIST_DIR}")
|
||||
|
||||
# We cannot pass lists as a parameter to the external project without modifying the ';' separator
|
||||
string(REPLACE ";" "|" BOOTLOADER_IGNORE_EXTRA_COMPONENT "${BOOTLOADER_IGNORE_EXTRA_COMPONENT}")
|
||||
string(REPLACE ";" "|" bootloader_extra_component_dirs "${bootloader_extra_component_dirs}")
|
||||
|
||||
externalproject_add(bootloader
|
||||
SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/subproject"
|
||||
@@ -127,7 +132,7 @@ externalproject_add(bootloader
|
||||
LIST_SEPARATOR |
|
||||
CMAKE_ARGS -DSDKCONFIG=${sdkconfig} -DIDF_PATH=${idf_path} -DIDF_TARGET=${idf_target}
|
||||
-DPYTHON_DEPS_CHECKED=1 -DPYTHON=${python}
|
||||
-DEXTRA_COMPONENT_DIRS=${CMAKE_CURRENT_LIST_DIR}
|
||||
-DEXTRA_COMPONENT_DIRS=${bootloader_extra_component_dirs}
|
||||
-DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
|
||||
-DIGNORE_EXTRA_COMPONENT=${BOOTLOADER_IGNORE_EXTRA_COMPONENT}
|
||||
${sign_key_arg} ${ver_key_arg}
|
||||
|
||||
@@ -34,8 +34,8 @@ set(COMPONENTS
|
||||
esp_system
|
||||
newlib)
|
||||
|
||||
# Make EXTRA_COMPONENT_DIRS variable to point to the bootloader_components directory
|
||||
# of the project being compiled
|
||||
# EXTRA_COMPONENT_DIRS can be populated with directories containing one or several components.
|
||||
# Make sure this variable contains `bootloader_components` directory of the project being compiled.
|
||||
set(PROJECT_EXTRA_COMPONENTS "${PROJECT_SOURCE_DIR}/bootloader_components")
|
||||
if(EXISTS ${PROJECT_EXTRA_COMPONENTS})
|
||||
list(APPEND EXTRA_COMPONENT_DIRS "${PROJECT_EXTRA_COMPONENTS}")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <spi_flash_mmap.h> /* including in bootloader for error values */
|
||||
#include "sdkconfig.h"
|
||||
#include "bootloader_flash.h"
|
||||
#include "soc/ext_mem_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -20,8 +21,11 @@ extern "C" {
|
||||
|
||||
#define FLASH_SECTOR_SIZE 0x1000
|
||||
#define FLASH_BLOCK_SIZE 0x10000
|
||||
|
||||
#define MMAP_ALIGNED_MASK (SPI_FLASH_MMU_PAGE_SIZE - 1)
|
||||
#define MMU_FLASH_MASK (~(SPI_FLASH_MMU_PAGE_SIZE - 1))
|
||||
#define MMU_FLASH_MASK_FROM_VAL(PAGE_SZ) (~((PAGE_SZ) - 1))
|
||||
#define MMU_DROM_END_ENTRY_VADDR_FROM_VAL(PAGE_SZ) (SOC_DRAM_FLASH_ADDRESS_HIGH - (PAGE_SZ))
|
||||
|
||||
/**
|
||||
* MMU mapping must always be in the unit of a SPI_FLASH_MMU_PAGE_SIZE
|
||||
@@ -89,7 +93,7 @@ uint32_t bootloader_mmap_get_free_pages(void);
|
||||
* @param length - Length of data to map.
|
||||
*
|
||||
* @return Pointer to mapped data memory (at src_addr), or NULL
|
||||
* if an allocation error occured.
|
||||
* if an allocation error occurred.
|
||||
*/
|
||||
const void *bootloader_mmap(uint32_t src_addr, uint32_t size);
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ extern "C" {
|
||||
#define PART_TYPE_BOOTLOADER 0x02
|
||||
#define PART_SUBTYPE_BOOTLOADER_PRIMARY 0x00
|
||||
#define PART_SUBTYPE_BOOTLOADER_OTA 0x01
|
||||
#define PART_SUBTYPE_BOOTLOADER_RECOVERY 0x02
|
||||
|
||||
#define PART_TYPE_PARTITION_TABLE 0x03
|
||||
#define PART_SUBTYPE_PARTITION_TABLE_PRIMARY 0x00
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -34,6 +34,7 @@ typedef struct {
|
||||
uint32_t image_len; /* Length of image on flash, in bytes */
|
||||
uint8_t image_digest[32]; /* appended SHA-256 digest */
|
||||
uint32_t secure_version; /* secure version for anti-rollback, it is covered by sha256 (set if CONFIG_BOOTLOADER_APP_ANTI_ROLLBACK=y) */
|
||||
uint32_t mmu_page_size; /* Flash MMU page size per binary header */
|
||||
} esp_image_metadata_t;
|
||||
|
||||
typedef enum {
|
||||
@@ -86,12 +87,12 @@ ESP_STATIC_ASSERT(sizeof(rtc_retain_mem_t) <= ESP_BOOTLOADER_RESERVE_RTC, "Reser
|
||||
#endif // CONFIG_BOOTLOADER_RESERVE_RTC_MEM
|
||||
|
||||
/**
|
||||
* @brief Verify an app image.
|
||||
* @brief Verify an app/bootloader image.
|
||||
*
|
||||
* If encryption is enabled, data will be transparently decrypted.
|
||||
*
|
||||
* @param mode Mode of operation (verify, silent verify, or load).
|
||||
* @param part Partition to load the app from.
|
||||
* @param part Partition to load the app/bootloader from.
|
||||
* @param[inout] data Pointer to the image metadata structure which is be filled in by this function.
|
||||
* 'start_addr' member should be set (to the start address of the image.)
|
||||
* Other fields will all be initialised by this function.
|
||||
@@ -113,11 +114,11 @@ ESP_STATIC_ASSERT(sizeof(rtc_retain_mem_t) <= ESP_BOOTLOADER_RESERVE_RTC, "Reser
|
||||
esp_err_t esp_image_verify(esp_image_load_mode_t mode, const esp_partition_pos_t *part, esp_image_metadata_t *data);
|
||||
|
||||
/**
|
||||
* @brief Get metadata of app
|
||||
* @brief Get metadata of app/bootloader
|
||||
*
|
||||
* If encryption is enabled, data will be transparently decrypted.
|
||||
*
|
||||
* @param part Partition to load the app from.
|
||||
* @param part Partition to load the app/bootloader from.
|
||||
* @param[out] metadata Pointer to the image metadata structure which is be filled in by this function.
|
||||
* Fields will all be initialised by this function.
|
||||
*
|
||||
@@ -171,7 +172,7 @@ esp_err_t bootloader_load_image(const esp_partition_pos_t *part, esp_image_metad
|
||||
esp_err_t bootloader_load_image_no_verify(const esp_partition_pos_t *part, esp_image_metadata_t *data);
|
||||
|
||||
/**
|
||||
* @brief Verify the bootloader image.
|
||||
* @brief Verify the PRIMARY bootloader image.
|
||||
*
|
||||
* @param[out] If result is ESP_OK and this pointer is non-NULL, it
|
||||
* will be set to the length of the bootloader image.
|
||||
@@ -181,7 +182,7 @@ esp_err_t bootloader_load_image_no_verify(const esp_partition_pos_t *part, esp_i
|
||||
esp_err_t esp_image_verify_bootloader(uint32_t *length);
|
||||
|
||||
/**
|
||||
* @brief Verify the bootloader image.
|
||||
* @brief Verify the PRIMARY bootloader image.
|
||||
*
|
||||
* @param[out] Metadata for the image. Only valid if result is ESP_OK.
|
||||
*
|
||||
@@ -197,6 +198,25 @@ esp_err_t esp_image_verify_bootloader_data(esp_image_metadata_t *data);
|
||||
*/
|
||||
int esp_image_get_flash_size(esp_image_flash_size_t app_flash_size);
|
||||
|
||||
/**
|
||||
* @brief Get the ota bootloader offset
|
||||
*
|
||||
* The esp_image_verify functions use the offset to distinguish between application and bootloader verifications.
|
||||
* The application must set the OTA bootloader offset before running any verification functions for the OTA bootloader partition.
|
||||
*
|
||||
* @return ota Bootloader offset. UINT32_MAX - not set.
|
||||
*/
|
||||
uint32_t esp_image_bootloader_offset_get(void);
|
||||
|
||||
/**
|
||||
* @brief Set the ota bootloader offset
|
||||
*
|
||||
* The esp_image_verify functions use the offset to distinguish between application and bootloader verifications.
|
||||
* The application must set the OTA bootloader offset before running any verification functions for the OTA bootloader partition.
|
||||
*
|
||||
* @param offset ota Bootloader offset
|
||||
*/
|
||||
void esp_image_bootloader_offset_set(const uint32_t offset);
|
||||
|
||||
typedef struct {
|
||||
uint32_t drom_addr;
|
||||
|
||||
@@ -64,7 +64,7 @@ __attribute__((weak)) void bootloader_clock_configure(void)
|
||||
// RTC_FAST clock source will be switched to RC_FAST at application startup
|
||||
clk_cfg.fast_clk_src = rtc_clk_fast_src_get();
|
||||
if (clk_cfg.fast_clk_src == SOC_RTC_FAST_CLK_SRC_INVALID) {
|
||||
clk_cfg.fast_clk_src = SOC_RTC_FAST_CLK_SRC_XTAL_DIV;
|
||||
clk_cfg.fast_clk_src = SOC_RTC_FAST_CLK_SRC_DEFAULT;
|
||||
}
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32C6
|
||||
|
||||
@@ -140,13 +140,13 @@ bool bootloader_common_erase_part_type_data(const char *list_erase, bool ota_dat
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t bootloader_common_get_sha256_of_partition (uint32_t address, uint32_t size, int type, uint8_t *out_sha_256)
|
||||
esp_err_t bootloader_common_get_sha256_of_partition(uint32_t address, uint32_t size, int type, uint8_t *out_sha_256)
|
||||
{
|
||||
if (out_sha_256 == NULL || size == 0) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (type == PART_TYPE_APP) {
|
||||
if (type == PART_TYPE_APP || type == PART_TYPE_BOOTLOADER) {
|
||||
const esp_partition_pos_t partition_pos = {
|
||||
.offset = address,
|
||||
.size = size,
|
||||
|
||||
@@ -46,6 +46,9 @@ void bootloader_random_enable(void)
|
||||
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_PERIF_I2C_RSTB);
|
||||
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_PERIF_I2C);
|
||||
|
||||
// enable analog i2c master clock for RNG runtime
|
||||
ANALOG_CLOCK_ENABLE();
|
||||
|
||||
// Config ADC circuit (Analog part) with I2C (HOST ID 0X69) and choose internal voltage as sampling source
|
||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_DTEST_RTC_ADDR, 0);
|
||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_ENT_PERIF_ADDR, 1);
|
||||
@@ -94,6 +97,9 @@ void bootloader_random_disable(void)
|
||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC1_EN_TOUT_ADDR, 0);
|
||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC2_EN_TOUT_ADDR, 0);
|
||||
|
||||
// disable analog i2c master clock
|
||||
ANALOG_CLOCK_DISABLE();
|
||||
|
||||
// disable ADC_CTRL_CLK (SAR ADC function clock)
|
||||
REG_WRITE(PCR_SARADC_CLKM_CONF_REG, 0x00404000);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -40,6 +40,9 @@ void bootloader_random_enable(void)
|
||||
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_PERIF_I2C_RSTB);
|
||||
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_PERIF_I2C);
|
||||
|
||||
// enable analog i2c master clock for RNG runtime
|
||||
ANALOG_CLOCK_ENABLE();
|
||||
|
||||
// Config ADC circuit (Analog part) with I2C(HOST ID 0x69) and chose internal voltage as sampling source
|
||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_DTEST_RTC_ADDR , 2);
|
||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_ENT_RTC_ADDR , 1);
|
||||
@@ -88,6 +91,9 @@ void bootloader_random_disable(void)
|
||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC1_ENCAL_REF_ADDR, 0);
|
||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC2_ENCAL_REF_ADDR, 0);
|
||||
|
||||
// disable analog i2c master clock
|
||||
ANALOG_CLOCK_DISABLE();
|
||||
|
||||
// disable ADC_CTRL_CLK (SAR ADC function clock)
|
||||
REG_WRITE(PCR_SARADC_CLKM_CONF_REG, 0x00404000);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -45,6 +45,9 @@ void bootloader_random_enable(void)
|
||||
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_PERIF_I2C_RSTB);
|
||||
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_PERIF_I2C);
|
||||
|
||||
// enable analog i2c master clock for RNG runtime
|
||||
ANALOG_CLOCK_ENABLE();
|
||||
|
||||
// Config ADC circuit (Analog part) with I2C(HOST ID 0x69) and chose internal voltage as sampling source
|
||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_DTEST_RTC_ADDR , 0);
|
||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC_ENT_RTC_ADDR , 1);
|
||||
@@ -93,6 +96,9 @@ void bootloader_random_disable(void)
|
||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC1_ENCAL_REF_ADDR, 0);
|
||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, ADC_SARADC2_ENCAL_REF_ADDR, 0);
|
||||
|
||||
// disable analog i2c master clock
|
||||
ANALOG_CLOCK_DISABLE();
|
||||
|
||||
// disable ADC_CTRL_CLK (SAR ADC function clock)
|
||||
REG_WRITE(PCR_SARADC_CLKM_CONF_REG, 0x00404000);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -35,6 +35,9 @@ void bootloader_random_enable(void)
|
||||
// some ADC sensor registers are in power group PERIF_I2C and need to be enabled via PMU
|
||||
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_PERIF_I2C);
|
||||
|
||||
// enable analog i2c master clock for RNG runtime
|
||||
ANALOG_CLOCK_ENABLE();
|
||||
|
||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_DTEST, 0);
|
||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_ENT_SAR, 1);
|
||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_EN_TOUT_SAR1_BUS, 1);
|
||||
@@ -80,6 +83,9 @@ void bootloader_random_disable(void)
|
||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_ENT_SAR, 0);
|
||||
REGI2C_WRITE_MASK(I2C_SAR_ADC, I2C_SARADC_EN_TOUT_SAR1_BUS, 0);
|
||||
|
||||
// disable analog i2c master clock
|
||||
ANALOG_CLOCK_DISABLE();
|
||||
|
||||
// disable ADC_CTRL_CLK (SAR ADC function clock)
|
||||
REG_WRITE(PCR_SARADC_CLKM_CONF_REG, 0x00404000);
|
||||
|
||||
|
||||
@@ -62,6 +62,9 @@ void bootloader_random_enable(void)
|
||||
|
||||
SET_PERI_REG_MASK(ADC_CTRL_REG_REG, ADC_START_FORCE); //start force 1
|
||||
|
||||
// enable analog i2c master clock for RNG runtime
|
||||
ANALOG_CLOCK_ENABLE();
|
||||
|
||||
adc1_fix_initcode_set(I2C_SAR_ADC_INIT_CODE_VAL);
|
||||
|
||||
// cfg pattern table
|
||||
@@ -94,6 +97,9 @@ void bootloader_random_enable(void)
|
||||
|
||||
void bootloader_random_disable(void)
|
||||
{
|
||||
// disable analog i2c master clock
|
||||
ANALOG_CLOCK_DISABLE();
|
||||
|
||||
// No-op for now TODO IDF-6497
|
||||
// ADC should be set to defaults here, once ADC API is implemented
|
||||
// OR just keep this empty and let application continue to use RNG initialized by the bootloader
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "esp_rom_spiflash.h"
|
||||
|
||||
#include "soc/soc.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "soc/rtc.h"
|
||||
#include "soc/efuse_periph.h"
|
||||
#include "soc/rtc_periph.h"
|
||||
@@ -66,7 +67,7 @@ static void set_cache_and_start_app(uint32_t drom_addr,
|
||||
uint32_t irom_addr,
|
||||
uint32_t irom_load_addr,
|
||||
uint32_t irom_size,
|
||||
uint32_t entry_addr);
|
||||
const esp_image_metadata_t *data);
|
||||
|
||||
esp_err_t bootloader_common_read_otadata(const esp_partition_pos_t *ota_info, esp_ota_select_entry_t *two_otadata)
|
||||
{
|
||||
@@ -207,6 +208,9 @@ bool bootloader_utility_load_partition_table(bootloader_state_t *bs)
|
||||
case PART_SUBTYPE_BOOTLOADER_OTA:
|
||||
partition_usage = "ota bootloader";
|
||||
break;
|
||||
case PART_SUBTYPE_BOOTLOADER_RECOVERY:
|
||||
partition_usage = "recovery bootloader";
|
||||
break;
|
||||
}
|
||||
break; /* PART_TYPE_BOOTLOADER */
|
||||
case PART_TYPE_PARTITION_TABLE: /* Partition table partition */
|
||||
@@ -789,7 +793,7 @@ static void unpack_load_app(const esp_image_metadata_t *data)
|
||||
rom_addr[1],
|
||||
rom_load_addr[1],
|
||||
rom_size[1],
|
||||
data->image.entry_addr);
|
||||
data);
|
||||
}
|
||||
|
||||
#else //!SOC_MMU_DI_VADDR_SHARED
|
||||
@@ -834,7 +838,7 @@ static void unpack_load_app(const esp_image_metadata_t *data)
|
||||
irom_addr,
|
||||
irom_load_addr,
|
||||
irom_size,
|
||||
data->image.entry_addr);
|
||||
data);
|
||||
}
|
||||
#endif //#if SOC_MMU_DI_VADDR_SHARED
|
||||
|
||||
@@ -859,9 +863,11 @@ static void set_cache_and_start_app(
|
||||
uint32_t irom_addr,
|
||||
uint32_t irom_load_addr,
|
||||
uint32_t irom_size,
|
||||
uint32_t entry_addr)
|
||||
const esp_image_metadata_t *data)
|
||||
{
|
||||
int rc __attribute__((unused));
|
||||
const uint32_t entry_addr = data->image.entry_addr;
|
||||
const uint32_t mmu_page_size = data->mmu_page_size;
|
||||
|
||||
ESP_EARLY_LOGD(TAG, "configure drom and irom and start");
|
||||
//-----------------------Disable Cache to do the mapping---------
|
||||
@@ -871,12 +877,18 @@ static void set_cache_and_start_app(
|
||||
#else
|
||||
cache_hal_disable(CACHE_LL_LEVEL_EXT_MEM, CACHE_TYPE_ALL);
|
||||
#endif
|
||||
|
||||
#if SOC_MMU_PAGE_SIZE_CONFIGURABLE
|
||||
// re-configure MMU page size
|
||||
mmu_ll_set_page_size(0, mmu_page_size);
|
||||
#endif //SOC_MMU_PAGE_SIZE_CONFIGURABLE
|
||||
|
||||
//reset MMU table first
|
||||
mmu_hal_unmap_all();
|
||||
|
||||
//-----------------------MAP DROM--------------------------
|
||||
uint32_t drom_load_addr_aligned = drom_load_addr & MMU_FLASH_MASK;
|
||||
uint32_t drom_addr_aligned = drom_addr & MMU_FLASH_MASK;
|
||||
uint32_t drom_load_addr_aligned = drom_load_addr & MMU_FLASH_MASK_FROM_VAL(mmu_page_size);
|
||||
uint32_t drom_addr_aligned = drom_addr & MMU_FLASH_MASK_FROM_VAL(mmu_page_size);
|
||||
ESP_EARLY_LOGV(TAG, "rodata starts from paddr=0x%08" PRIx32 ", vaddr=0x%08" PRIx32 ", size=0x%" PRIx32, drom_addr, drom_load_addr, drom_size);
|
||||
//The addr is aligned, so we add the mask off length to the size, to make sure the corresponding buses are enabled.
|
||||
drom_size = (drom_load_addr - drom_load_addr_aligned) + drom_size;
|
||||
@@ -894,13 +906,13 @@ static void set_cache_and_start_app(
|
||||
ESP_EARLY_LOGV(TAG, "after mapping rodata, starting from paddr=0x%08" PRIx32 " and vaddr=0x%08" PRIx32 ", 0x%" PRIx32 " bytes are mapped", drom_addr_aligned, drom_load_addr_aligned, actual_mapped_len);
|
||||
}
|
||||
//we use the MMU_LL_END_DROM_ENTRY_ID mmu entry as a map page for app to find the boot partition
|
||||
mmu_hal_map_region(0, MMU_TARGET_FLASH0, MMU_LL_END_DROM_ENTRY_VADDR, drom_addr_aligned, CONFIG_MMU_PAGE_SIZE, &actual_mapped_len);
|
||||
mmu_hal_map_region(0, MMU_TARGET_FLASH0, MMU_DROM_END_ENTRY_VADDR_FROM_VAL(mmu_page_size), drom_addr_aligned, mmu_page_size, &actual_mapped_len);
|
||||
ESP_EARLY_LOGV(TAG, "mapped one page of the rodata, from paddr=0x%08" PRIx32 " and vaddr=0x%08" PRIx32 ", 0x%" PRIx32 " bytes are mapped", drom_addr_aligned, MMU_LL_END_DROM_ENTRY_VADDR, actual_mapped_len);
|
||||
#endif
|
||||
|
||||
//-----------------------MAP IROM--------------------------
|
||||
uint32_t irom_load_addr_aligned = irom_load_addr & MMU_FLASH_MASK;
|
||||
uint32_t irom_addr_aligned = irom_addr & MMU_FLASH_MASK;
|
||||
uint32_t irom_load_addr_aligned = irom_load_addr & MMU_FLASH_MASK_FROM_VAL(mmu_page_size);
|
||||
uint32_t irom_addr_aligned = irom_addr & MMU_FLASH_MASK_FROM_VAL(mmu_page_size);
|
||||
ESP_EARLY_LOGV(TAG, "text starts from paddr=0x%08" PRIx32 ", vaddr=0x%08" PRIx32 ", size=0x%" PRIx32, irom_addr, irom_load_addr, irom_size);
|
||||
//The addr is aligned, so we add the mask off length to the size, to make sure the corresponding buses are enabled.
|
||||
irom_size = (irom_load_addr - irom_load_addr_aligned) + irom_size;
|
||||
|
||||
@@ -85,7 +85,7 @@ static void bootloader_super_wdt_auto_feed(void)
|
||||
|
||||
static inline void bootloader_hardware_init(void)
|
||||
{
|
||||
regi2c_ctrl_ll_master_enable_clock(true);
|
||||
_regi2c_ctrl_ll_master_enable_clock(true); // keep ana i2c mst clock always enabled in bootloader
|
||||
regi2c_ctrl_ll_master_force_enable_clock(true); // TODO: IDF-8667 Remove this?
|
||||
regi2c_ctrl_ll_master_configure_clock();
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ static inline void bootloader_hardware_init(void)
|
||||
esp_rom_spiflash_fix_dummylen(1, 1);
|
||||
#endif
|
||||
|
||||
regi2c_ctrl_ll_master_enable_clock(true);
|
||||
_regi2c_ctrl_ll_master_enable_clock(true); // keep ana i2c mst clock always enabled in bootloader
|
||||
regi2c_ctrl_ll_master_configure_clock();
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ static void bootloader_super_wdt_auto_feed(void)
|
||||
|
||||
static inline void bootloader_hardware_init(void)
|
||||
{
|
||||
regi2c_ctrl_ll_master_enable_clock(true);
|
||||
_regi2c_ctrl_ll_master_enable_clock(true); // keep ana i2c mst clock always enabled in bootloader
|
||||
regi2c_ctrl_ll_master_force_enable_clock(true); // TODO: IDF-9274 Remove this?
|
||||
regi2c_ctrl_ll_master_configure_clock();
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
#include "hal/regi2c_ctrl.h"
|
||||
#include "soc/regi2c_saradc.h"
|
||||
|
||||
//Not supported but common bootloader calls the function. Do nothing
|
||||
void bootloader_ana_clock_glitch_reset_config(bool enable)
|
||||
{
|
||||
// TODO: IDF-9274
|
||||
(void)enable;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ static inline void bootloader_hardware_init(void)
|
||||
CLEAR_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_RFPLL);
|
||||
SET_PERI_REG_MASK(PMU_RF_PWC_REG, PMU_XPD_FORCE_RFPLL);
|
||||
|
||||
regi2c_ctrl_ll_master_enable_clock(true);
|
||||
_regi2c_ctrl_ll_master_enable_clock(true); // keep ana i2c mst clock always enabled in bootloader
|
||||
regi2c_ctrl_ll_master_configure_clock();
|
||||
}
|
||||
|
||||
|
||||
@@ -95,8 +95,7 @@ static void bootloader_super_wdt_auto_feed(void)
|
||||
|
||||
static inline void bootloader_hardware_init(void)
|
||||
{
|
||||
int __DECLARE_RCC_RC_ATOMIC_ENV __attribute__ ((unused)); // To avoid build errors/warnings about __DECLARE_RCC_RC_ATOMIC_ENV
|
||||
regi2c_ctrl_ll_master_enable_clock(true);
|
||||
_regi2c_ctrl_ll_master_enable_clock(true); // keep ana i2c mst clock always enabled in bootloader
|
||||
regi2c_ctrl_ll_master_configure_clock();
|
||||
|
||||
unsigned chip_version = efuse_hal_chip_revision();
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "bootloader_memory_utils.h"
|
||||
#include "soc/soc_caps.h"
|
||||
#include "hal/cache_ll.h"
|
||||
#include "spi_flash_mmap.h"
|
||||
|
||||
#define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1))
|
||||
|
||||
@@ -77,7 +78,7 @@ static esp_err_t process_segment_data(int segment, intptr_t load_addr, uint32_t
|
||||
static esp_err_t verify_image_header(uint32_t src_addr, const esp_image_header_t *image, bool silent);
|
||||
|
||||
/* Verify a segment header */
|
||||
static esp_err_t verify_segment_header(int index, const esp_image_segment_header_t *segment, uint32_t segment_data_offs, bool silent);
|
||||
static esp_err_t verify_segment_header(int index, const esp_image_segment_header_t *segment, uint32_t segment_data_offs, esp_image_metadata_t *metadata, bool silent);
|
||||
|
||||
/* Log-and-fail macro for use in esp_image_load */
|
||||
#define FAIL_LOAD(...) do { \
|
||||
@@ -102,6 +103,24 @@ static esp_err_t process_checksum(bootloader_sha256_handle_t sha_handle, uint32_
|
||||
static esp_err_t __attribute__((unused)) verify_secure_boot_signature(bootloader_sha256_handle_t sha_handle, esp_image_metadata_t *data, uint8_t *image_digest, uint8_t *verified_digest);
|
||||
static esp_err_t __attribute__((unused)) verify_simple_hash(bootloader_sha256_handle_t sha_handle, esp_image_metadata_t *data);
|
||||
|
||||
static uint32_t s_bootloader_partition_offset = ESP_PRIMARY_BOOTLOADER_OFFSET;
|
||||
|
||||
uint32_t esp_image_bootloader_offset_get(void)
|
||||
{
|
||||
return s_bootloader_partition_offset;
|
||||
}
|
||||
|
||||
void esp_image_bootloader_offset_set(const uint32_t offset)
|
||||
{
|
||||
s_bootloader_partition_offset = offset;
|
||||
ESP_LOGI(TAG, "Bootloader offsets for PRIMARY: 0x%x, Secondary: 0x%" PRIx32, ESP_PRIMARY_BOOTLOADER_OFFSET, s_bootloader_partition_offset);
|
||||
}
|
||||
|
||||
static bool is_bootloader(uint32_t offset)
|
||||
{
|
||||
return ((offset == ESP_PRIMARY_BOOTLOADER_OFFSET) || (offset == s_bootloader_partition_offset));
|
||||
}
|
||||
|
||||
static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_t *part, esp_image_metadata_t *data)
|
||||
{
|
||||
#ifdef BOOTLOADER_BUILD
|
||||
@@ -135,7 +154,7 @@ static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_
|
||||
// For secure boot V1 on ESP32, we don't calculate SHA or verify signature on bootloaders.
|
||||
// (For non-secure boot, we don't verify any SHA-256 hash appended to the bootloader because
|
||||
// esptool.py may have rewritten the header - rely on esptool.py having verified the bootloader at flashing time, instead.)
|
||||
verify_sha = (part->offset != ESP_BOOTLOADER_OFFSET) && do_verify;
|
||||
verify_sha = !is_bootloader(part->offset) && do_verify;
|
||||
#endif
|
||||
|
||||
if (part->size > SIXTEEN_MB) {
|
||||
@@ -199,7 +218,7 @@ static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_
|
||||
#if CONFIG_SECURE_BOOT_V2_ENABLED
|
||||
ESP_FAULT_ASSERT(!esp_secure_boot_enabled() || memcmp(image_digest, verified_digest, HASH_LEN) == 0);
|
||||
#else // Secure Boot V1 on ESP32, only verify signatures for apps not bootloaders
|
||||
ESP_FAULT_ASSERT(data->start_addr == ESP_BOOTLOADER_OFFSET || memcmp(image_digest, verified_digest, HASH_LEN) == 0);
|
||||
ESP_FAULT_ASSERT(is_bootloader(data->start_addr) || memcmp(image_digest, verified_digest, HASH_LEN) == 0);
|
||||
#endif
|
||||
|
||||
#endif // SECURE_BOOT_CHECK_SIGNATURE
|
||||
@@ -332,7 +351,8 @@ static esp_err_t verify_image_header(uint32_t src_addr, const esp_image_header_t
|
||||
// Checking the chip revision header *will* print a bunch of other info
|
||||
// regardless of silent setting as this may be important, but don't bother checking it
|
||||
// if it looks like the app partition is erased or otherwise garbage
|
||||
CHECK_ERR(bootloader_common_check_chip_validity(image, ESP_IMAGE_APPLICATION));
|
||||
esp_image_type image_type = is_bootloader(src_addr) ? ESP_IMAGE_BOOTLOADER : ESP_IMAGE_APPLICATION;
|
||||
CHECK_ERR(bootloader_common_check_chip_validity(image, image_type));
|
||||
|
||||
if (image->segment_count > ESP_IMAGE_MAX_SEGMENTS) {
|
||||
FAIL_LOAD("image at 0x%"PRIx32" segment count %d exceeds max %d", src_addr, image->segment_count, ESP_IMAGE_MAX_SEGMENTS);
|
||||
@@ -559,7 +579,7 @@ static esp_err_t process_segment(int index, uint32_t flash_addr, esp_image_segme
|
||||
|
||||
ESP_LOGV(TAG, "segment data length 0x%"PRIx32" data starts 0x%"PRIx32, data_len, data_addr);
|
||||
|
||||
CHECK_ERR(verify_segment_header(index, header, data_addr, silent));
|
||||
CHECK_ERR(verify_segment_header(index, header, data_addr, metadata, silent));
|
||||
|
||||
if (data_len % 4 != 0) {
|
||||
FAIL_LOAD("unaligned segment length 0x%"PRIx32, data_len);
|
||||
@@ -695,7 +715,7 @@ static esp_err_t process_segment_data(int segment, intptr_t load_addr, uint32_t
|
||||
// Case II: Bootloader verifying bootloader
|
||||
// The esp_app_desc_t structure is located in DROM and is always in segment #0.
|
||||
// Anti-rollback check and efuse block version check should handle only Case I from above.
|
||||
if (segment == 0 && metadata->start_addr != ESP_BOOTLOADER_OFFSET) {
|
||||
if (segment == 0 && !is_bootloader(metadata->start_addr)) {
|
||||
/* ESP32 doesn't have more memory and more efuse bits for block major version. */
|
||||
#if !CONFIG_IDF_TARGET_ESP32
|
||||
const esp_app_desc_t *app_desc = (const esp_app_desc_t *)src;
|
||||
@@ -748,7 +768,7 @@ static esp_err_t process_segment_data(int segment, intptr_t load_addr, uint32_t
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t verify_segment_header(int index, const esp_image_segment_header_t *segment, uint32_t segment_data_offs, bool silent)
|
||||
static esp_err_t verify_segment_header(int index, const esp_image_segment_header_t *segment, uint32_t segment_data_offs, esp_image_metadata_t *metadata, bool silent)
|
||||
{
|
||||
if ((segment->data_len & 3) != 0
|
||||
|| segment->data_len >= SIXTEEN_MB) {
|
||||
@@ -761,13 +781,39 @@ static esp_err_t verify_segment_header(int index, const esp_image_segment_header
|
||||
uint32_t load_addr = segment->load_addr;
|
||||
bool map_segment = should_map(load_addr);
|
||||
|
||||
#if SOC_MMU_PAGE_SIZE_CONFIGURABLE
|
||||
/* ESP APP descriptor is present in the DROM segment #0 */
|
||||
if (index == 0 && !is_bootloader(metadata->start_addr)) {
|
||||
const esp_app_desc_t *app_desc = (const esp_app_desc_t *)bootloader_mmap(segment_data_offs, sizeof(esp_app_desc_t));
|
||||
if (!app_desc || app_desc->magic_word != ESP_APP_DESC_MAGIC_WORD) {
|
||||
ESP_LOGE(TAG, "Failed to fetch app description header!");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
// Convert from log base 2 number to actual size while handling legacy image case (value 0)
|
||||
metadata->mmu_page_size = (app_desc->mmu_page_size > 0) ? (1UL << app_desc->mmu_page_size) : SPI_FLASH_MMU_PAGE_SIZE;
|
||||
if (metadata->mmu_page_size != SPI_FLASH_MMU_PAGE_SIZE) {
|
||||
ESP_LOGI(TAG, "MMU page size mismatch, configured: 0x%x, found: 0x%"PRIx32, SPI_FLASH_MMU_PAGE_SIZE, metadata->mmu_page_size);
|
||||
}
|
||||
bootloader_munmap(app_desc);
|
||||
} else if (index == 0 && is_bootloader(metadata->start_addr)) {
|
||||
// Bootloader always uses the default MMU page size
|
||||
metadata->mmu_page_size = SPI_FLASH_MMU_PAGE_SIZE;
|
||||
}
|
||||
#else // SOC_MMU_PAGE_SIZE_CONFIGURABLE
|
||||
metadata->mmu_page_size = SPI_FLASH_MMU_PAGE_SIZE;
|
||||
#endif // !SOC_MMU_PAGE_SIZE_CONFIGURABLE
|
||||
|
||||
const int mmu_page_size = metadata->mmu_page_size;
|
||||
ESP_LOGV(TAG, "MMU page size 0x%x", mmu_page_size);
|
||||
|
||||
/* Check that flash cache mapped segment aligns correctly from flash to its mapped address,
|
||||
relative to the 64KB page mapping size.
|
||||
relative to the MMU page mapping size.
|
||||
*/
|
||||
ESP_LOGV(TAG, "segment %d map_segment %d segment_data_offs 0x%"PRIx32" load_addr 0x%"PRIx32,
|
||||
index, map_segment, segment_data_offs, load_addr);
|
||||
if (map_segment
|
||||
&& ((segment_data_offs % SPI_FLASH_MMU_PAGE_SIZE) != (load_addr % SPI_FLASH_MMU_PAGE_SIZE))) {
|
||||
&& ((segment_data_offs % mmu_page_size) != (load_addr % mmu_page_size))) {
|
||||
if (!silent) {
|
||||
ESP_LOGE(TAG, "Segment %d load address 0x%08"PRIx32", doesn't match data 0x%08"PRIx32,
|
||||
index, load_addr, segment_data_offs);
|
||||
@@ -847,8 +893,8 @@ esp_err_t esp_image_verify_bootloader_data(esp_image_metadata_t *data)
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
const esp_partition_pos_t bootloader_part = {
|
||||
.offset = ESP_BOOTLOADER_OFFSET,
|
||||
.size = ESP_PARTITION_TABLE_OFFSET - ESP_BOOTLOADER_OFFSET,
|
||||
.offset = ESP_PRIMARY_BOOTLOADER_OFFSET,
|
||||
.size = ESP_BOOTLOADER_SIZE,
|
||||
};
|
||||
return esp_image_verify(ESP_IMAGE_VERIFY,
|
||||
&bootloader_part,
|
||||
@@ -871,7 +917,7 @@ static esp_err_t process_appended_hash_and_sig(esp_image_metadata_t *data, uint3
|
||||
#if CONFIG_SECURE_BOOT || CONFIG_SECURE_SIGNED_APPS_NO_SECURE_BOOT
|
||||
|
||||
// Case I: Bootloader part
|
||||
if (part_offset == ESP_BOOTLOADER_OFFSET) {
|
||||
if (is_bootloader(part_offset)) {
|
||||
// For bootloader with secure boot v1, signature stays in an independent flash
|
||||
// sector (offset 0x0) and does not get appended to the image.
|
||||
#if CONFIG_SECURE_BOOT_V2_ENABLED
|
||||
@@ -1005,7 +1051,7 @@ static esp_err_t verify_secure_boot_signature(bootloader_sha256_handle_t sha_han
|
||||
#if CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME || CONFIG_SECURE_SIGNED_APPS_ECDSA_V2_SCHEME
|
||||
data->image_len = end - data->start_addr + sizeof(ets_secure_boot_signature_t);
|
||||
#elif defined(CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME)
|
||||
if (data->start_addr != ESP_BOOTLOADER_OFFSET) {
|
||||
if (!is_bootloader(data->start_addr)) {
|
||||
data->image_len = end - data->start_addr + sizeof(esp_secure_boot_sig_block_t);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -43,7 +43,7 @@ static const char *TAG = "flash_encrypt";
|
||||
|
||||
/* Static functions for stages of flash encryption */
|
||||
static esp_err_t encrypt_bootloader(void);
|
||||
static esp_err_t encrypt_and_load_partition_table(esp_partition_info_t *partition_table, int *num_partitions);
|
||||
static esp_err_t encrypt_and_load_partition_table(uint32_t offset, esp_partition_info_t *partition_table, int *num_partitions);
|
||||
static esp_err_t encrypt_partition(int index, const esp_partition_info_t *partition);
|
||||
static size_t get_flash_encrypt_cnt_value(void);
|
||||
|
||||
@@ -262,12 +262,12 @@ esp_err_t esp_flash_encrypt_contents(void)
|
||||
esp_flash_encryption_enable_key_mgr();
|
||||
#endif
|
||||
|
||||
err = encrypt_bootloader();
|
||||
err = encrypt_bootloader(); // PART_SUBTYPE_BOOTLOADER_PRIMARY
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
err = encrypt_and_load_partition_table(partition_table, &num_partitions);
|
||||
err = encrypt_and_load_partition_table(ESP_PRIMARY_PARTITION_TABLE_OFFSET, partition_table, &num_partitions); // PART_SUBTYPE_PARTITION_TABLE_PRIMARY
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
@@ -277,6 +277,14 @@ esp_err_t esp_flash_encrypt_contents(void)
|
||||
|
||||
/* Go through each partition and encrypt if necessary */
|
||||
for (int i = 0; i < num_partitions; i++) {
|
||||
if ((partition_table[i].type == PART_TYPE_BOOTLOADER && partition_table[i].subtype == PART_SUBTYPE_BOOTLOADER_PRIMARY)
|
||||
|| (partition_table[i].type == PART_TYPE_PARTITION_TABLE && partition_table[i].subtype == PART_SUBTYPE_PARTITION_TABLE_PRIMARY)) {
|
||||
/* Skip encryption of PRIMARY partitions for bootloader and partition table.
|
||||
* PRIMARY partitions have already been encrypted above.
|
||||
* We allow to encrypt partitions that are not PRIMARY.
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
err = encrypt_partition(i, &partition_table[i]);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
@@ -337,13 +345,13 @@ static esp_err_t encrypt_bootloader(void)
|
||||
|
||||
#if CONFIG_SECURE_BOOT_V2_ENABLED
|
||||
/* The image length obtained from esp_image_verify_bootloader includes the sector boundary padding and the signature block lengths */
|
||||
if (ESP_BOOTLOADER_OFFSET + image_length > ESP_PARTITION_TABLE_OFFSET) {
|
||||
ESP_LOGE(TAG, "Bootloader is too large to fit Secure Boot V2 signature sector and partition table (configured offset 0x%x)", ESP_PARTITION_TABLE_OFFSET);
|
||||
if (image_length > ESP_BOOTLOADER_SIZE) {
|
||||
ESP_LOGE(TAG, "Bootloader is too large to fit Secure Boot V2 signature sector and partition table (configured offset 0x%x)", ESP_PRIMARY_PARTITION_TABLE_OFFSET);
|
||||
return ESP_ERR_INVALID_SIZE;
|
||||
}
|
||||
#endif // CONFIG_SECURE_BOOT_V2_ENABLED
|
||||
|
||||
err = esp_flash_encrypt_region(ESP_BOOTLOADER_OFFSET, image_length);
|
||||
err = esp_flash_encrypt_region(ESP_PRIMARY_BOOTLOADER_OFFSET, image_length);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to encrypt bootloader in place: 0x%x", err);
|
||||
return err;
|
||||
@@ -368,33 +376,37 @@ static esp_err_t encrypt_bootloader(void)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t encrypt_and_load_partition_table(esp_partition_info_t *partition_table, int *num_partitions)
|
||||
static esp_err_t read_and_verify_partition_table(uint32_t offset, esp_partition_info_t *partition_table, int *num_partitions)
|
||||
{
|
||||
esp_err_t err;
|
||||
/* Check for plaintext partition table */
|
||||
err = bootloader_flash_read(ESP_PARTITION_TABLE_OFFSET, partition_table, ESP_PARTITION_TABLE_MAX_LEN, false);
|
||||
err = bootloader_flash_read(offset, partition_table, ESP_PARTITION_TABLE_MAX_LEN, false);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to read partition table data");
|
||||
ESP_LOGE(TAG, "Failed to read partition table data at 0x%" PRIx32, offset);
|
||||
return err;
|
||||
}
|
||||
if (esp_partition_table_verify(partition_table, false, num_partitions) == ESP_OK) {
|
||||
ESP_LOGD(TAG, "partition table is plaintext. Encrypting...");
|
||||
esp_err_t err = esp_flash_encrypt_region(ESP_PARTITION_TABLE_OFFSET,
|
||||
FLASH_SECTOR_SIZE);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to encrypt partition table in place. %x", err);
|
||||
return err;
|
||||
}
|
||||
} else {
|
||||
ESP_LOGE(TAG, "Failed to read partition table data - not plaintext?");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
err = esp_partition_table_verify(partition_table, false, num_partitions);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to read partition table data - not plaintext or empty?");
|
||||
}
|
||||
|
||||
/* Valid partition table loaded */
|
||||
ESP_LOGI(TAG, "partition table encrypted and loaded successfully");
|
||||
return ESP_OK;
|
||||
return err;
|
||||
}
|
||||
|
||||
static esp_err_t encrypt_and_load_partition_table(uint32_t offset, esp_partition_info_t *partition_table, int *num_partitions)
|
||||
{
|
||||
esp_err_t err = read_and_verify_partition_table(offset, partition_table, num_partitions);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
ESP_LOGD(TAG, "partition table is plaintext. Encrypting...");
|
||||
err = esp_flash_encrypt_region(offset, FLASH_SECTOR_SIZE);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to encrypt partition table in place. %x", err);
|
||||
return err;
|
||||
}
|
||||
ESP_LOGI(TAG, "partition table encrypted and loaded successfully");
|
||||
return err;
|
||||
}
|
||||
|
||||
static esp_err_t encrypt_partition(int index, const esp_partition_info_t *partition)
|
||||
{
|
||||
@@ -402,19 +414,26 @@ static esp_err_t encrypt_partition(int index, const esp_partition_info_t *partit
|
||||
bool should_encrypt = (partition->flags & PART_FLAG_ENCRYPTED);
|
||||
uint32_t size = partition->pos.size;
|
||||
|
||||
if (partition->type == PART_TYPE_APP) {
|
||||
/* check if the partition holds a valid unencrypted app */
|
||||
if (partition->type == PART_TYPE_APP || partition->type == PART_TYPE_BOOTLOADER) {
|
||||
/* check if the partition holds a valid unencrypted app/bootloader */
|
||||
esp_image_metadata_t image_data = {};
|
||||
err = esp_image_verify(ESP_IMAGE_VERIFY,
|
||||
&partition->pos,
|
||||
&image_data);
|
||||
if (partition->type == PART_TYPE_BOOTLOADER) {
|
||||
esp_image_bootloader_offset_set(partition->pos.offset);
|
||||
}
|
||||
err = esp_image_verify(ESP_IMAGE_VERIFY, &partition->pos, &image_data);
|
||||
should_encrypt = (err == ESP_OK);
|
||||
#ifdef CONFIG_SECURE_FLASH_ENCRYPT_ONLY_IMAGE_LEN_IN_APP_PART
|
||||
if (should_encrypt) {
|
||||
if (partition->type == PART_TYPE_APP && should_encrypt) {
|
||||
// Encrypt only the app image instead of encrypting the whole partition
|
||||
size = image_data.image_len;
|
||||
}
|
||||
#endif
|
||||
} else if (partition->type == PART_TYPE_PARTITION_TABLE) {
|
||||
/* check if the partition holds a valid unencrypted partition table */
|
||||
esp_partition_info_t partition_table[ESP_PARTITION_TABLE_MAX_ENTRIES];
|
||||
int num_partitions;
|
||||
err = read_and_verify_partition_table(partition->pos.offset, partition_table, &num_partitions);
|
||||
should_encrypt = (err == ESP_OK && num_partitions != 0);
|
||||
} else if ((partition->type == PART_TYPE_DATA && partition->subtype == PART_SUBTYPE_DATA_OTA)
|
||||
|| (partition->type == PART_TYPE_DATA && partition->subtype == PART_SUBTYPE_DATA_NVS_KEYS)) {
|
||||
/* check if we have ota data partition and the partition should be encrypted unconditionally */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -52,10 +52,11 @@ esp_err_t esp_partition_table_verify(const esp_partition_info_t *partition_table
|
||||
}
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
//MD5 checksum matches and we continue with the next interation in
|
||||
//MD5 checksum matches and we continue with the next iteration in
|
||||
//order to detect the end of the partition table
|
||||
md5_found = 1;
|
||||
} else if (part->magic == 0xFFFF
|
||||
} else if (num_parts != 0 // the first record cannot be empty, otherwise the whole table is empty
|
||||
&& part->magic == 0xFFFF
|
||||
&& part->type == PART_TYPE_END
|
||||
&& part->subtype == PART_SUBTYPE_END) {
|
||||
ESP_LOGD(TAG, "partition table verified, %d entries", num_parts);
|
||||
|
||||
@@ -4,7 +4,3 @@ components/bootloader_support/test_apps/rtc_custom_section:
|
||||
enable:
|
||||
- if: SOC_RTC_MEM_SUPPORTED == 1
|
||||
reason: this feature is supported on chips that have RTC memory
|
||||
disable:
|
||||
- if: IDF_TARGET == "esp32c61"
|
||||
temporary: true
|
||||
reason: IDF-9260
|
||||
|
||||
@@ -85,6 +85,9 @@ if(CONFIG_BT_ENABLED)
|
||||
elseif(CONFIG_IDF_TARGET_ESP32S3)
|
||||
list(APPEND ldscripts "linker_rw_bt_controller.lf")
|
||||
elseif(CONFIG_IDF_TARGET_ESP32C2)
|
||||
if(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
|
||||
list(APPEND srcs "controller/esp32c2/dummy.c")
|
||||
endif()
|
||||
set(ldscripts "linker_esp32c2.lf")
|
||||
else()
|
||||
list(APPEND ldscripts "linker_esp_ble_controller.lf")
|
||||
@@ -865,11 +868,19 @@ if(CONFIG_BT_ENABLED)
|
||||
elseif(CONFIG_IDF_TARGET_ESP32C3)
|
||||
target_link_directories(${COMPONENT_LIB} INTERFACE
|
||||
"${CMAKE_CURRENT_LIST_DIR}/controller/lib_esp32c3_family/esp32c3")
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
|
||||
if(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app_flash)
|
||||
else()
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
|
||||
endif()
|
||||
elseif(CONFIG_IDF_TARGET_ESP32S3)
|
||||
target_link_directories(${COMPONENT_LIB} INTERFACE
|
||||
"${CMAKE_CURRENT_LIST_DIR}/controller/lib_esp32c3_family/esp32s3")
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
|
||||
if(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app_flash)
|
||||
else()
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
|
||||
endif()
|
||||
elseif(CONFIG_BT_CONTROLLER_ENABLED)
|
||||
if(CONFIG_IDF_TARGET_ESP32C6)
|
||||
add_prebuilt_library(libble_app
|
||||
@@ -878,8 +889,13 @@ if(CONFIG_BT_ENABLED)
|
||||
add_prebuilt_library(libble_app
|
||||
"${CMAKE_CURRENT_LIST_DIR}/controller/lib_esp32c6/esp32c6-bt-lib/esp32c61/libble_app.a")
|
||||
else()
|
||||
add_prebuilt_library(libble_app
|
||||
"controller/lib_${target_name}/${target_name}-bt-lib/libble_app.a")
|
||||
if(CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
|
||||
add_prebuilt_library(libble_app
|
||||
"controller/lib_${target_name}/${target_name}-bt-lib/libble_app_flash.a")
|
||||
else()
|
||||
add_prebuilt_library(libble_app
|
||||
"controller/lib_${target_name}/${target_name}-bt-lib/libble_app.a")
|
||||
endif()
|
||||
endif()
|
||||
target_link_libraries(${COMPONENT_LIB} PRIVATE libble_app)
|
||||
endif()
|
||||
|
||||
@@ -254,9 +254,9 @@ static const btc_func_t profile_tab[BTC_PID_NUM] = {
|
||||
#if CONFIG_BLE_MESH_MBT_SRV
|
||||
[BTC_PID_MBT_SERVER] = {btc_ble_mesh_mbt_server_call_handler, btc_ble_mesh_mbt_server_cb_handler },
|
||||
#endif /* CONFIG_BLE_MESH_MBT_SRV */
|
||||
#if CONFIG_BLE_MESH_BLE_COEX_SUPPORT
|
||||
#if CONFIG_BLE_MESH_BLE_COEX_SUPPORT || CONFIG_BLE_MESH_USE_BLE_50
|
||||
[BTC_PID_BLE_MESH_BLE_COEX] = {btc_ble_mesh_ble_call_handler, btc_ble_mesh_ble_cb_handler },
|
||||
#endif /* CONFIG_BLE_MESH_BLE_COEX_SUPPORT */
|
||||
#endif /* CONFIG_BLE_MESH_BLE_COEX_SUPPORT || CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
#endif /* #if CONFIG_BLE_MESH */
|
||||
};
|
||||
|
||||
@@ -382,7 +382,7 @@ static void btc_deinit_mem(void) {
|
||||
btc_profile_cb_tab = NULL;
|
||||
}
|
||||
|
||||
#if (BLE_INCLUDED == TRUE)
|
||||
#if (BLE_42_FEATURE_SUPPORT == TRUE)
|
||||
if (gl_bta_adv_data_ptr) {
|
||||
osi_free(gl_bta_adv_data_ptr);
|
||||
gl_bta_adv_data_ptr = NULL;
|
||||
@@ -392,7 +392,7 @@ static void btc_deinit_mem(void) {
|
||||
osi_free(gl_bta_scan_rsp_data_ptr);
|
||||
gl_bta_scan_rsp_data_ptr = NULL;
|
||||
}
|
||||
#endif ///BLE_INCLUDED == TRUE
|
||||
#endif // BLE_42_FEATURE_SUPPORT
|
||||
|
||||
#if GATTS_INCLUDED == TRUE && GATT_DYNAMIC_MEMORY == TRUE
|
||||
if (btc_creat_tab_env_ptr) {
|
||||
@@ -444,7 +444,8 @@ static bt_status_t btc_init_mem(void) {
|
||||
}
|
||||
memset((void *)btc_profile_cb_tab, 0, sizeof(void *) * BTC_PID_NUM);
|
||||
|
||||
#if (BLE_INCLUDED == TRUE)
|
||||
#if BTC_DYNAMIC_MEMORY == TRUE
|
||||
#if (BLE_42_FEATURE_SUPPORT == TRUE)
|
||||
if ((gl_bta_adv_data_ptr = (tBTA_BLE_ADV_DATA *)osi_malloc(sizeof(tBTA_BLE_ADV_DATA))) == NULL) {
|
||||
goto error_exit;
|
||||
}
|
||||
@@ -454,7 +455,8 @@ static bt_status_t btc_init_mem(void) {
|
||||
goto error_exit;
|
||||
}
|
||||
memset((void *)gl_bta_scan_rsp_data_ptr, 0, sizeof(tBTA_BLE_ADV_DATA));
|
||||
#endif ///BLE_INCLUDED == TRUE
|
||||
#endif // (BLE_42_FEATURE_SUPPORT == TRUE)
|
||||
#endif // BTC_DYNAMIC_MEMORY == TRUE
|
||||
|
||||
#if GATTS_INCLUDED == TRUE && GATT_DYNAMIC_MEMORY == TRUE
|
||||
if ((btc_creat_tab_env_ptr = (esp_btc_creat_tab_t *)osi_malloc(sizeof(esp_btc_creat_tab_t))) == NULL) {
|
||||
|
||||
@@ -241,5 +241,8 @@ void *osi_calloc_func(size_t size)
|
||||
|
||||
void osi_free_func(void *ptr)
|
||||
{
|
||||
#if HEAP_MEMORY_DEBUG
|
||||
osi_mem_dbg_clean(ptr, __func__, __LINE__);
|
||||
#endif
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,15 @@ void *osi_malloc_func(size_t size);
|
||||
void *osi_calloc_func(size_t size);
|
||||
void osi_free_func(void *ptr);
|
||||
|
||||
// Memory alloc function without print and assertion
|
||||
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST
|
||||
#define osi_malloc_base(size) heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
|
||||
#define osi_calloc_base(size) heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
|
||||
#else
|
||||
#define osi_malloc_base(size) malloc((size))
|
||||
#define osi_calloc_base(size) calloc(1, (size))
|
||||
#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */
|
||||
|
||||
#if HEAP_MEMORY_DEBUG
|
||||
|
||||
void osi_mem_dbg_init(void);
|
||||
@@ -41,13 +50,10 @@ void osi_men_dbg_set_section_start(uint8_t index);
|
||||
void osi_men_dbg_set_section_end(uint8_t index);
|
||||
uint32_t osi_mem_dbg_get_max_size_section(uint8_t index);
|
||||
|
||||
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST
|
||||
#define osi_malloc(size) \
|
||||
({ \
|
||||
void *p; \
|
||||
p = heap_caps_malloc_prefer(size, 2, \
|
||||
MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, \
|
||||
MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \
|
||||
p = osi_malloc_base(size); \
|
||||
osi_mem_dbg_record(p, size, __func__, __LINE__); \
|
||||
(void *)p; \
|
||||
})
|
||||
@@ -55,34 +61,11 @@ uint32_t osi_mem_dbg_get_max_size_section(uint8_t index);
|
||||
#define osi_calloc(size) \
|
||||
({ \
|
||||
void *p; \
|
||||
p = heap_caps_calloc_prefer(1, size, 2, \
|
||||
MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, \
|
||||
MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \
|
||||
p = osi_calloc_base(size); \
|
||||
osi_mem_dbg_record(p, size, __func__, __LINE__); \
|
||||
(void *)p; \
|
||||
})
|
||||
|
||||
#else
|
||||
|
||||
#define osi_malloc(size) \
|
||||
({ \
|
||||
void *p; \
|
||||
p = malloc((size)); \
|
||||
osi_mem_dbg_record(p, size, __func__, __LINE__); \
|
||||
(void *)p; \
|
||||
})
|
||||
|
||||
#define osi_calloc(size) \
|
||||
({ \
|
||||
void *p; \
|
||||
p = calloc(1, (size)); \
|
||||
osi_mem_dbg_record(p, size, __func__, __LINE__); \
|
||||
(void *)p; \
|
||||
})
|
||||
|
||||
#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */
|
||||
|
||||
|
||||
#if 0
|
||||
#define osi_malloc(size) \
|
||||
do { \
|
||||
@@ -122,15 +105,6 @@ do { \
|
||||
|
||||
#else
|
||||
|
||||
// Memory alloc function without print and assertion
|
||||
#if HEAP_ALLOCATION_FROM_SPIRAM_FIRST
|
||||
#define osi_malloc_base(size) heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
|
||||
#define osi_calloc_base(size) heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
|
||||
#else
|
||||
#define osi_malloc_base(size) malloc((size))
|
||||
#define osi_calloc_base(size) calloc(1, (size))
|
||||
#endif /* #if HEAP_ALLOCATION_FROM_SPIRAM_FIRST */
|
||||
|
||||
// Memory alloc function with print and assertion when fails
|
||||
#define osi_malloc(size) osi_malloc_func((size))
|
||||
#define osi_calloc(size) osi_calloc_func((size))
|
||||
|
||||
@@ -444,6 +444,15 @@ config BTDM_CTRL_SCAN_BACKOFF_UPPERLIMITMAX
|
||||
minimize collision of scan request PDUs from nultiple scanners. If scan backoff is disabled, in active
|
||||
scanning, scan request PDU will be sent every time when HW receives scannable ADV PDU.
|
||||
|
||||
config BTDM_CTRL_CHECK_CONNECT_IND_ACCESS_ADDRESS
|
||||
bool "Enable enhanced Access Address check in CONNECT_IND"
|
||||
default n
|
||||
help
|
||||
Enabling this option will add stricter verification of the Access Address in the CONNECT_IND PDU.
|
||||
This improves security by ensuring that only connection requests with valid Access Addresses are accepted.
|
||||
If disabled, only basic checks are applied, improving compatibility.
|
||||
|
||||
|
||||
config BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP
|
||||
bool "BLE adv report flow control supported"
|
||||
depends on (BTDM_CTRL_MODE_BTDM || BTDM_CTRL_MODE_BLE_ONLY)
|
||||
|
||||
@@ -109,86 +109,100 @@ menuconfig BT_LE_50_FEATURE_SUPPORT
|
||||
help
|
||||
Enable BLE 5 feature
|
||||
|
||||
config BT_LE_LL_CFG_FEAT_LE_2M_PHY
|
||||
bool "Enable 2M Phy"
|
||||
depends on BT_LE_50_FEATURE_SUPPORT
|
||||
default y
|
||||
help
|
||||
Enable 2M-PHY
|
||||
|
||||
config BT_LE_LL_CFG_FEAT_LE_CODED_PHY
|
||||
bool "Enable coded Phy"
|
||||
depends on BT_LE_50_FEATURE_SUPPORT
|
||||
default y
|
||||
help
|
||||
Enable coded-PHY
|
||||
|
||||
config BT_LE_EXT_ADV
|
||||
bool "Enable extended advertising"
|
||||
depends on BT_LE_50_FEATURE_SUPPORT
|
||||
default y
|
||||
help
|
||||
Enable this option to do extended advertising. Extended advertising
|
||||
will be supported from BLE 5.0 onwards.
|
||||
|
||||
if BT_LE_EXT_ADV
|
||||
config BT_LE_MAX_EXT_ADV_INSTANCES
|
||||
int "Maximum number of extended advertising instances."
|
||||
range 0 4
|
||||
default 1
|
||||
depends on BT_LE_EXT_ADV
|
||||
help
|
||||
Change this option to set maximum number of extended advertising
|
||||
instances. Minimum there is always one instance of
|
||||
advertising. Enter how many more advertising instances you
|
||||
want.
|
||||
Each extended advertising instance will take about 0.5k DRAM.
|
||||
|
||||
config BT_LE_EXT_ADV_MAX_SIZE
|
||||
int "Maximum length of the advertising data."
|
||||
range 0 1650
|
||||
default 1650
|
||||
depends on BT_LE_EXT_ADV
|
||||
help
|
||||
Defines the length of the extended adv data. The value should not
|
||||
exceed 1650.
|
||||
|
||||
config BT_LE_ENABLE_PERIODIC_ADV
|
||||
bool "Enable periodic advertisement."
|
||||
default y
|
||||
depends on BT_LE_EXT_ADV
|
||||
help
|
||||
Enable this option to start periodic advertisement.
|
||||
|
||||
config BT_LE_PERIODIC_ADV_SYNC_TRANSFER
|
||||
bool "Enable Transfer Sync Events"
|
||||
depends on BT_LE_ENABLE_PERIODIC_ADV
|
||||
if BT_LE_50_FEATURE_SUPPORT
|
||||
config BT_LE_LL_CFG_FEAT_LE_2M_PHY
|
||||
bool "Enable 2M Phy"
|
||||
depends on BT_LE_50_FEATURE_SUPPORT
|
||||
default y
|
||||
help
|
||||
This enables controller transfer periodic sync events to host
|
||||
Enable 2M-PHY
|
||||
|
||||
config BT_LE_LL_CFG_FEAT_LE_CODED_PHY
|
||||
bool "Enable coded Phy"
|
||||
depends on BT_LE_50_FEATURE_SUPPORT
|
||||
default y
|
||||
help
|
||||
Enable coded-PHY
|
||||
|
||||
config BT_LE_EXT_ADV
|
||||
bool "Enable extended advertising"
|
||||
depends on BT_LE_50_FEATURE_SUPPORT
|
||||
default y
|
||||
help
|
||||
Enable this option to do extended advertising. Extended advertising
|
||||
will be supported from BLE 5.0 onwards.
|
||||
|
||||
if BT_LE_EXT_ADV
|
||||
config BT_LE_MAX_EXT_ADV_INSTANCES
|
||||
int "Maximum number of extended advertising instances."
|
||||
range 0 4
|
||||
default 1
|
||||
depends on BT_LE_EXT_ADV
|
||||
help
|
||||
Change this option to set maximum number of extended advertising
|
||||
instances. Minimum there is always one instance of
|
||||
advertising. Enter how many more advertising instances you
|
||||
want.
|
||||
Each extended advertising instance will take about 0.5k DRAM.
|
||||
|
||||
config BT_LE_EXT_ADV_MAX_SIZE
|
||||
int "Maximum length of the advertising data."
|
||||
range 0 1650
|
||||
default 1650
|
||||
depends on BT_LE_EXT_ADV
|
||||
help
|
||||
Defines the length of the extended adv data. The value should not
|
||||
exceed 1650.
|
||||
|
||||
config BT_LE_ENABLE_PERIODIC_ADV
|
||||
bool "Enable periodic advertisement."
|
||||
default y
|
||||
depends on BT_LE_EXT_ADV
|
||||
help
|
||||
Enable this option to start periodic advertisement.
|
||||
|
||||
config BT_LE_PERIODIC_ADV_SYNC_TRANSFER
|
||||
bool "Enable Transfer Sync Events"
|
||||
depends on BT_LE_ENABLE_PERIODIC_ADV
|
||||
default y
|
||||
help
|
||||
This enables controller transfer periodic sync events to host
|
||||
endif
|
||||
|
||||
config BT_LE_EXT_SCAN
|
||||
bool "Enable extended scanning"
|
||||
depends on BT_LE_50_FEATURE_SUPPORT && BT_LE_ROLE_OBSERVER_ENABLE
|
||||
default y
|
||||
help
|
||||
Enable this option to do extended scanning.
|
||||
|
||||
config BT_LE_ENABLE_PERIODIC_SYNC
|
||||
bool "Enable periodic sync"
|
||||
default y
|
||||
depends on BT_LE_EXT_SCAN
|
||||
help
|
||||
Enable this option to receive periodic advertisement.
|
||||
|
||||
if BT_LE_ENABLE_PERIODIC_SYNC
|
||||
config BT_LE_MAX_PERIODIC_SYNCS
|
||||
int "Maximum number of periodic advertising syncs"
|
||||
range 0 3
|
||||
default 1 if BT_LE_ENABLE_PERIODIC_ADV
|
||||
default 0
|
||||
help
|
||||
Set this option to set the upper limit for number of periodic sync
|
||||
connections. This should be less than maximum connections allowed by
|
||||
controller.
|
||||
|
||||
config BT_LE_MAX_PERIODIC_ADVERTISER_LIST
|
||||
int "Maximum number of periodic advertiser list"
|
||||
range 1 5
|
||||
default 5
|
||||
help
|
||||
Set this option to set the upper limit for number of periodic advertiser list.
|
||||
endif
|
||||
endif
|
||||
|
||||
config BT_LE_MAX_PERIODIC_SYNCS
|
||||
int "Maximum number of periodic advertising syncs"
|
||||
depends on BT_LE_50_FEATURE_SUPPORT && !BT_NIMBLE_ENABLED
|
||||
|
||||
range 0 3
|
||||
default 1 if BT_LE_ENABLE_PERIODIC_ADV
|
||||
default 0
|
||||
help
|
||||
Set this option to set the upper limit for number of periodic sync
|
||||
connections. This should be less than maximum connections allowed by
|
||||
controller.
|
||||
|
||||
config BT_LE_MAX_PERIODIC_ADVERTISER_LIST
|
||||
int "Maximum number of periodic advertiser list"
|
||||
depends on BT_LE_50_FEATURE_SUPPORT && !BT_NIMBLE_ENABLED
|
||||
range 1 5
|
||||
default 5
|
||||
help
|
||||
Set this option to set the upper limit for number of periodic advertiser list.
|
||||
|
||||
menu "Memory Settings"
|
||||
depends on !BT_NIMBLE_ENABLED
|
||||
|
||||
@@ -523,6 +537,10 @@ config BT_LE_TX_CCA_ENABLED
|
||||
help
|
||||
Enable CCA feature to cancel sending the packet if the signal power is stronger than CCA threshold.
|
||||
|
||||
config BT_LE_DTM_ENABLED
|
||||
bool "Enable Direct Test Mode (DTM) feature"
|
||||
default n
|
||||
|
||||
config BT_LE_CCA_RSSI_THRESH
|
||||
int "CCA RSSI threshold value"
|
||||
depends on BT_LE_TX_CCA_ENABLED
|
||||
@@ -531,6 +549,10 @@ config BT_LE_CCA_RSSI_THRESH
|
||||
help
|
||||
Power threshold of CCA in unit of -1 dBm.
|
||||
|
||||
config BT_LE_FEAT_LL_ENCRYPTION
|
||||
bool "Enable controller ACL encryption"
|
||||
default y
|
||||
|
||||
config BT_LE_ROLE_CENTROL_ENABLE
|
||||
bool "Enable BLE Centrol role function"
|
||||
depends on !BT_NIMBLE_ENABLED
|
||||
@@ -617,3 +639,23 @@ config BT_LE_DFT_TX_POWER_LEVEL_DBM_EFF
|
||||
default 18 if BT_LE_DFT_TX_POWER_LEVEL_P18
|
||||
default 20 if BT_LE_DFT_TX_POWER_LEVEL_P20
|
||||
default 0
|
||||
|
||||
config BT_CTRL_RUN_IN_FLASH_ONLY
|
||||
bool "Reduce BLE IRAM usage (READ DOCS FIRST) (EXPERIMENTAL)"
|
||||
default n
|
||||
help
|
||||
Move most IRAM into flash. This will increase the usage of flash and reduce ble performance.
|
||||
Because the code is moved to the flash, the execution speed of the code is reduced.
|
||||
To have a small impact on performance, you need to enable flash suspend (SPI_FLASH_AUTO_SUSPEND).
|
||||
|
||||
- Only one Tx-Rx can be performed in each connection interval. Therefore, reduce the connection interval
|
||||
as much as possible to improve the throughput. If you want higher connection performance, you can
|
||||
enable BT_LE_PLACE_CONN_RELATED_INTO_IRAM to put the connection-related code into iram.
|
||||
- For HCI_LE_Extended_Create_Connection command, only 1M phy's connection parameters will be applied.
|
||||
Other phys' will be ignored.
|
||||
- For extended scanning, we may be unable to receive the extended adv with 300us MAFS.
|
||||
|
||||
config BT_LE_PLACE_CONN_RELATED_INTO_IRAM
|
||||
bool "Place the connection-related code into IRAM"
|
||||
depends on BT_CTRL_RUN_IN_FLASH_ONLY
|
||||
default n
|
||||
|
||||
@@ -156,6 +156,10 @@ extern int ble_get_npl_element_info(esp_bt_controller_config_t *cfg, ble_npl_cou
|
||||
extern void bt_track_pll_cap(void);
|
||||
extern char *ble_controller_get_compile_version(void);
|
||||
extern const char *r_ble_controller_get_rom_compile_version(void);
|
||||
#if CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
|
||||
extern void ble_ll_supported_features_init(void);
|
||||
#endif //CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
|
||||
|
||||
#if CONFIG_BT_RELEASE_IRAM
|
||||
extern uint32_t _iram_bt_text_start;
|
||||
extern uint32_t _bss_bt_end;
|
||||
@@ -534,7 +538,12 @@ static int esp_ecc_gen_dh_key(const uint8_t *peer_pub_key_x, const uint8_t *peer
|
||||
|
||||
static int esp_intr_alloc_wrapper(int source, int flags, intr_handler_t handler, void *arg, void **ret_handle_in)
|
||||
{
|
||||
#if CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
|
||||
int rc = esp_intr_alloc(source, flags, handler, arg, (intr_handle_t *)ret_handle_in);
|
||||
#else
|
||||
int rc = esp_intr_alloc(source, flags | ESP_INTR_FLAG_IRAM, handler, arg, (intr_handle_t *)ret_handle_in);
|
||||
#endif
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@@ -743,6 +752,8 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* If we place the ble code into flash, don't need to initialize ROM. */
|
||||
#if !CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
|
||||
#if DEFAULT_BT_LE_50_FEATURE_SUPPORT || DEFAULT_BT_LE_ROLE_CENTROL || DEFAULT_BT_LE_ROLE_OBSERVER
|
||||
extern int esp_ble_rom_func_ptr_init_all(void);
|
||||
esp_ble_rom_func_ptr_init_all();
|
||||
@@ -751,6 +762,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
|
||||
extern int esp_ble_rom_func_ptr_init_legacy_adv_and_slave(void);
|
||||
esp_ble_rom_func_ptr_init_legacy_adv_and_slave();
|
||||
#endif
|
||||
#endif //!CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
|
||||
|
||||
/* Initialize the function pointers for OS porting */
|
||||
npl_freertos_funcs_init();
|
||||
@@ -800,6 +812,11 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
|
||||
#if CONFIG_SW_COEXIST_ENABLE
|
||||
coex_init();
|
||||
#endif
|
||||
|
||||
#if CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
|
||||
ble_ll_supported_features_init();
|
||||
#endif //CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
|
||||
|
||||
ret = ble_controller_init(cfg);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "ble_controller_init failed %d", ret);
|
||||
|
||||
320
components/bt/controller/esp32c2/dummy.c
Normal file
320
components/bt/controller/esp32c2/dummy.c
Normal file
@@ -0,0 +1,320 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include "esp_bt_cfg.h"
|
||||
|
||||
#define BLE_ERR_UNKNOWN_HCI_CMD (0x01)
|
||||
/* LL Features */
|
||||
#define BLE_LL_FEAT_LE_ENCRYPTION (0x0000000001)
|
||||
#define BLE_LL_FEAT_CONN_PARM_REQ (0x0000000002)
|
||||
#define BLE_LL_FEAT_EXTENDED_REJ (0x0000000004)
|
||||
#define BLE_LL_FEAT_PERIPH_INIT (0x0000000008)
|
||||
#define BLE_LL_FEAT_LE_PING (0x0000000010)
|
||||
#define BLE_LL_FEAT_DATA_LEN_EXT (0x0000000020)
|
||||
#define BLE_LL_FEAT_LL_PRIVACY (0x0000000040)
|
||||
#define BLE_LL_FEAT_EXT_SCAN_FILT (0x0000000080)
|
||||
#define BLE_LL_FEAT_LE_2M_PHY (0x0000000100)
|
||||
#define BLE_LL_FEAT_STABLE_MOD_ID_TX (0x0000000200)
|
||||
#define BLE_LL_FEAT_STABLE_MOD_ID_RX (0x0000000400)
|
||||
#define BLE_LL_FEAT_LE_CODED_PHY (0x0000000800)
|
||||
#define BLE_LL_FEAT_EXT_ADV (0x0000001000)
|
||||
#define BLE_LL_FEAT_PERIODIC_ADV (0x0000002000)
|
||||
#define BLE_LL_FEAT_CSA2 (0x0000004000)
|
||||
#define BLE_LL_FEAT_LE_POWER_CLASS_1 (0x0000008000)
|
||||
#define BLE_LL_FEAT_MIN_USED_CHAN (0x0000010000)
|
||||
#define BLE_LL_FEAT_CTE_REQ (0x0000020000)
|
||||
#define BLE_LL_FEAT_CTE_RSP (0x0000040000)
|
||||
#define BLE_LL_FEAT_CTE_TX (0x0000080000)
|
||||
#define BLE_LL_FEAT_CTE_RX (0x0000100000)
|
||||
#define BLE_LL_FEAT_CTE_AOD (0x0000200000)
|
||||
#define BLE_LL_FEAT_CTE_AOA (0x0000400000)
|
||||
#define BLE_LL_FEAT_CTE_RECV (0x0000800000)
|
||||
#define BLE_LL_FEAT_SYNC_TRANS_SEND (0x0001000000)
|
||||
#define BLE_LL_FEAT_SYNC_TRANS_RECV (0x0002000000)
|
||||
#define BLE_LL_FEAT_SCA_UPDATE (0x0004000000)
|
||||
#define BLE_LL_FEAT_REM_PKEY (0x0008000000)
|
||||
#define BLE_LL_FEAT_CIS_CENTRAL (0x0010000000)
|
||||
#define BLE_LL_FEAT_CIS_PERIPH (0x0020000000)
|
||||
#define BLE_LL_FEAT_ISO_BROADCASTER (0x0040000000)
|
||||
#define BLE_LL_FEAT_SYNC_RECV (0x0080000000)
|
||||
#define BLE_LL_FEAT_CIS_HOST (0x0100000000)
|
||||
#define BLE_LL_FEAT_POWER_CTRL_REQ (0x0200000000)
|
||||
#define BLE_LL_FEAT_POWER_CHANGE_IND (0x0400000000)
|
||||
#define BLE_LL_FEAT_PATH_LOSS_MON (0x0800000000)
|
||||
#define BLE_LL_FEAT_PERIODIC_ADV_ADI (0x1000000000)
|
||||
#define BLE_LL_FEAT_CONN_SUBRATING (0x2000000000)
|
||||
#define BLE_LL_FEAT_CONN_SUBRATING_HOST (0x4000000000)
|
||||
#define BLE_LL_FEAT_CHANNEL_CLASS (0x8000000000)
|
||||
|
||||
uint64_t ble_ll_supported_features;
|
||||
|
||||
void
|
||||
ble_ll_supported_features_init(void)
|
||||
{
|
||||
ble_ll_supported_features = BLE_LL_FEAT_EXTENDED_REJ;
|
||||
ble_ll_supported_features |= BLE_LL_FEAT_DATA_LEN_EXT;
|
||||
|
||||
#if DEFAULT_BT_LE_ROLE_CENTROL || DEFAULT_BT_LE_ROLE_PERIPHERAL
|
||||
ble_ll_supported_features |= BLE_LL_FEAT_PERIPH_INIT;
|
||||
ble_ll_supported_features |= BLE_LL_FEAT_CONN_PARM_REQ;
|
||||
#endif
|
||||
|
||||
#if CONFIG_BT_LE_FEAT_LL_ENCRYPTION
|
||||
ble_ll_supported_features |= BLE_LL_FEAT_LE_ENCRYPTION;
|
||||
#endif
|
||||
|
||||
ble_ll_supported_features |= (BLE_LL_FEAT_LL_PRIVACY | BLE_LL_FEAT_EXT_SCAN_FILT);
|
||||
ble_ll_supported_features |= BLE_LL_FEAT_LE_PING;
|
||||
|
||||
#if DEFAULT_BT_LE_EXT_ADV
|
||||
ble_ll_supported_features |= BLE_LL_FEAT_EXT_ADV;
|
||||
#endif
|
||||
|
||||
#if DEFAULT_BT_LE_PERIODIC_ADV
|
||||
ble_ll_supported_features |= BLE_LL_FEAT_PERIODIC_ADV;
|
||||
ble_ll_supported_features |= BLE_LL_FEAT_PERIODIC_ADV_ADI;
|
||||
#endif
|
||||
|
||||
#if DEFAULT_BT_LE_PAST
|
||||
ble_ll_supported_features |= BLE_LL_FEAT_SYNC_TRANS_RECV;
|
||||
ble_ll_supported_features |= BLE_LL_FEAT_SYNC_TRANS_SEND;
|
||||
#endif
|
||||
|
||||
#if DEGAULT_BT_LE_2M_PHY
|
||||
ble_ll_supported_features |= BLE_LL_FEAT_LE_2M_PHY;
|
||||
#endif
|
||||
|
||||
#if DEGAULT_BT_LE_CODED_PHY
|
||||
ble_ll_supported_features |= BLE_LL_FEAT_LE_CODED_PHY;
|
||||
#endif
|
||||
|
||||
#if DEFAULT_BT_LE_50_FEATURE_SUPPORT
|
||||
ble_ll_supported_features |= BLE_LL_FEAT_CSA2;
|
||||
ble_ll_supported_features |= BLE_LL_FEAT_SCA_UPDATE;
|
||||
ble_ll_supported_features |= BLE_LL_FEAT_REM_PKEY;
|
||||
ble_ll_supported_features |= BLE_LL_FEAT_CHANNEL_CLASS;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !DEFAULT_BT_LE_ROLE_BROADCASTER
|
||||
void r_ble_ll_adv_rpa_timeout(void) { }
|
||||
void r_ble_lll_adv_halt(void) { }
|
||||
void r_ble_lll_adv_event_rmvd_from_sched(void) { }
|
||||
void r_ble_lll_adv_ext_event_rmvd_from_sched(void) { }
|
||||
int r_ble_ll_adv_enabled(void) { return 0; }
|
||||
int r_ble_ll_adv_can_chg_whitelist(void) { return 1; }
|
||||
int r_ble_ll_adv_set_random_addr(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
void r_ble_ll_adv_reset(void) { }
|
||||
void r_ble_ll_adv_init(void) { }
|
||||
void r_ble_ll_adv_deinit(void) { }
|
||||
int r_ble_ll_adv_env_init(void) { return 0; }
|
||||
void r_ble_ll_adv_env_deinit(void) { }
|
||||
int r_ble_lll_adv_rx_pkt_isr(void) { return -1; }
|
||||
void r_ble_ll_adv_rx_pkt_in(void) { }
|
||||
int r_ble_ll_adv_set_adv_params(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_adv_read_txpwr(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_hci_set_adv_data(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_hci_set_scan_rsp_data(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_hci_adv_set_enable(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_adv_vendor_hci_legacy_adv_clear(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_adv_set_data_related_addr_change(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
#endif // !DEFAULT_BT_LE_ROLE_BROADCASTER
|
||||
|
||||
#if !DEFAULT_BT_LE_EXT_ADV
|
||||
bool r_ble_ll_adv_ext_check_data_itvl(void) { return true; }
|
||||
void r_ble_lll_adv_coex_dpc_update_on_aux_scheduled(void) { }
|
||||
void r_ble_lll_adv_coex_dpc_calc_pti_update_itvl(void) { }
|
||||
void r_ble_lll_adv_sec_done(void) { }
|
||||
int r_ble_lll_adv_sec_schedule_next_aux(void) { return 0; }
|
||||
void r_ble_lll_adv_sec_event_done(void) { }
|
||||
int r_ble_lll_adv_secondary_tx_start_cb(void) { return 0; }
|
||||
void r_ble_lll_adv_aux_schedule(void) { }
|
||||
void r_ble_lll_adv_update_rsp_offset(void) { }
|
||||
int r_ble_ll_adv_hci_set_random_addr(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_adv_ext_set_param(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_adv_ext_set_adv_data(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_adv_ext_set_scan_rsp(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_adv_ext_set_enable(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_adv_rd_max_adv_data_len(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_adv_rd_sup_adv_sets(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_adv_remove(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_adv_clear_all(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
#endif //!DEFAULT_BT_LE_EXT_ADV
|
||||
|
||||
#if !DEFAULT_BT_LE_PERIODIC_ADV
|
||||
void r_ble_ll_adv_sm_stop_periodic(void) { }
|
||||
void r_ble_lll_adv_periodic_event_done(void) { }
|
||||
int r_ble_lll_adv_sync_tx_start_cb(void) { return 0; }
|
||||
void r_ble_lll_adv_sync_tx_end(void) { }
|
||||
int r_ble_lll_adv_periodic_start(void) { return 0; }
|
||||
void r_ble_lll_adv_periodic_rmvd_from_sched(void) { }
|
||||
int r_ble_ll_adv_periodic_set_param(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_adv_periodic_set_data(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_adv_periodic_enable(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
#endif //!DEFAULT_BT_LE_PERIODIC_ADV
|
||||
|
||||
#if !DEFAULT_BT_LE_ROLE_OBSERVER
|
||||
void r_ble_lll_scan_halt(void) { }
|
||||
void r_ble_ll_scan_end_adv_evt(void) { }
|
||||
void r_ble_ll_scan_rx_pkt_in(void) { }
|
||||
int r_ble_lll_scan_rx_pkt_isr(void) { return -1; }
|
||||
int r_ble_ll_scan_env_init(void) { return 0; }
|
||||
void r_ble_ll_scan_env_deinit(void) { }
|
||||
void r_ble_ll_scan_init(void) { }
|
||||
void r_ble_ll_scan_deinit(void) { }
|
||||
void r_ble_ll_scan_reset(void) { }
|
||||
int r_ble_ll_scan_can_chg_whitelist(void) { return 1; }
|
||||
int r_ble_ll_scan_enabled(void) { return false; }
|
||||
int r_ble_lll_scan_chk_resume(void) { return -1; }
|
||||
int r_ble_ll_scan_set_scan_params(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_hci_scan_set_enable(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_scan_hci_update_adv_report_flow_ctrl(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_scan_hci_set_adv_report_flow_ctrl(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
#endif //!DEFAULT_BT_LE_ROLE_OBSERVER
|
||||
|
||||
#if !DEFAULT_BT_LE_EXT_SCAN
|
||||
void r_ble_lll_scan_duration_period_timers_restart(void) { }
|
||||
void r_ble_lll_scan_duration_period_timers_stop(void) { }
|
||||
int r_ble_ll_hci_send_legacy_ext_adv_report(void) { return -1; }
|
||||
void r_ble_lll_sched_rmv_elem_type(void) { }
|
||||
void r_ble_ll_scan_send_truncated(void) { }
|
||||
void r_ble_ll_scan_aux_data_unref(void) { }
|
||||
void r_ble_lll_scan_sched_remove(void) { }
|
||||
void r_ble_lll_scan_aux_data_free(void) { }
|
||||
void r_ble_lll_aux_scan_drop(void) { }
|
||||
int r_ble_lll_sched_aux_scan(void) { return -1; }
|
||||
int r_ble_lll_scan_rx_isr_on_aux(void) { return -1; }
|
||||
void r_ble_lll_scan_period_timer_cb(void) { }
|
||||
void r_ble_lll_scan_duration_timer_cb(void) { }
|
||||
void r_ble_ll_scan_rx_pkt_in_on_aux(void) { }
|
||||
int r_ble_ll_set_ext_scan_params(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_hci_ext_scan_set_enable(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
#endif //!DEFAULT_BT_LE_EXT_SCAN
|
||||
|
||||
#if !DEFAULT_BT_LE_ROLE_CENTROL
|
||||
void r_ble_ll_init_rx_pkt_in(void) { }
|
||||
int r_ble_lll_init_rx_pkt_isr(void) { return -1; }
|
||||
int r_ble_ll_conn_create(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_conn_create_cancel(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
#endif //!DEFAULT_BT_LE_ROLE_CENTROL
|
||||
|
||||
#if !DEFAULT_BT_LE_ROLE_CENTROL || !DEFAULT_BT_LE_EXT_SCAN
|
||||
int r_ble_ll_ext_conn_create(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
#endif //!DEFAULT_BT_LE_ROLE_CENTROL || !DEFAULT_BT_LE_EXT_SCAN
|
||||
|
||||
#if !DEFAULT_BT_LE_ROLE_PERIPHERAL
|
||||
int r_ble_ll_conn_slave_start(void) { return 0; }
|
||||
#endif //!DEFAULT_BT_LE_ROLE_PERIPHERAL
|
||||
|
||||
#if !DEFAULT_BT_LE_ROLE_CENTROL && !DEFAULT_BT_LE_ROLE_PERIPHERAL
|
||||
void r_ble_ll_conn_rx_data_pdu(void) { }
|
||||
int r_ble_lll_conn_rx_pkt_isr(void) { return -1; }
|
||||
int r_ble_ll_hci_disconnect(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_conn_hci_rd_rem_ver_cmd(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_conn_hci_update(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_conn_hci_rd_chan_map(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_conn_hci_read_rem_features(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_conn_hci_param_rr(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_conn_hci_param_nrr(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
#endif //!DEFAULT_BT_LE_ROLE_CENTROL && !DEFAULT_BT_LE_ROLE_PERIPHERAL
|
||||
|
||||
#if !CONFIG_BT_LE_FEAT_LL_ENCRYPTION
|
||||
int r_ble_ll_conn_chk_phy_upd_start(void) { return -1; }
|
||||
void r_ble_ll_hci_ev_encrypt_chg(void) { }
|
||||
int r_ble_ll_ctrl_enc_allowed_pdu_rx(void) { return 1; }
|
||||
int r_ble_ll_ctrl_enc_allowed_pdu_tx(void) { return 1; }
|
||||
uint8_t r_ble_ll_ctrl_rx_start_enc_rsp(void) { return 0x07; }
|
||||
uint8_t r_ble_ll_ctrl_rx_pause_enc_rsp(void) { return 0x07; }
|
||||
int r_ble_ll_hci_le_encrypt(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
#endif //!CONFIG_BT_LE_FEAT_LL_ENCRYPTION
|
||||
|
||||
#if !DEFAULT_BT_LE_ROLE_PERIPHERAL || !CONFIG_BT_LE_FEAT_LL_ENCRYPTION
|
||||
uint8_t r_ble_ll_ctrl_rx_pause_enc_req(void) { return 0x07; }
|
||||
uint8_t r_ble_ll_ctrl_rx_enc_req(void) { return 0x07; }
|
||||
int r_ble_ll_conn_hci_le_ltk_reply(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_conn_hci_le_ltk_neg_reply(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
#endif //!DEFAULT_BT_LE_ROLE_PERIPHERAL || !CONFIG_BT_LE_FEAT_LL_ENCRYPTION
|
||||
|
||||
#if !DEFAULT_BT_LE_ROLE_CENTROL || !CONFIG_BT_LE_FEAT_LL_ENCRYPTION
|
||||
uint8_t r_ble_ll_ctrl_rx_start_enc_req(void) { return 0x07; }
|
||||
void r_ble_ll_ctrl_rx_enc_rsp(void) { }
|
||||
void r_ble_ll_ctrl_enc_req_make(void) { }
|
||||
int r_ble_ll_conn_hci_le_start_encrypt(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
#endif //!DEFAULT_BT_LE_ROLE_CENTROL || !CONFIG_BT_LE_FEAT_LL_ENCRYPTION
|
||||
|
||||
#if !DEGAULT_BT_LE_2M_PHY && !DEGAULT_BT_LE_CODED_PHY
|
||||
void r_ble_ll_ctrl_phy_update_proc_complete(void) { }
|
||||
void r_ble_ll_ctrl_phy_update_cancel(void) { }
|
||||
uint8_t r_ble_ll_ctrl_rx_phy_update_ind(void) { return 0x07; }
|
||||
uint8_t r_ble_ll_ctrl_rx_phy_rsp(void) { return 0x07; }
|
||||
uint8_t r_ble_ll_ctrl_rx_phy_req(void) { return 0x07; }
|
||||
void r_ble_ll_ctrl_phy_req_rsp_make(void) { }
|
||||
#endif //DEGAULT_BT_LE_2M_PHY && DEGAULT_BT_LE_CODED_PHY
|
||||
|
||||
#if !DEFAULT_BT_LE_PERIODIC_SYNC
|
||||
void r_ble_lll_sync_halt(void) { }
|
||||
void r_ble_lll_sync_rmvd_from_sched(void) { }
|
||||
int r_ble_ll_sync_list_search(void) { return -1; }
|
||||
uint8_t r_ble_ll_ctrl_rx_periodic_sync_ind(void) { return 0x07; }
|
||||
void r_ble_ll_sync_rx_pkt_in(void) { }
|
||||
int r_ble_lll_sync_rx_pkt_isr(void) { return -1; }
|
||||
int r_ble_ll_sync_env_init(void) { return 0; }
|
||||
void r_ble_ll_sync_env_deinit(void) { }
|
||||
void r_ble_ll_sync_init(void) { }
|
||||
void r_ble_ll_sync_deinit(void) { }
|
||||
void r_ble_ll_sync_reset(void) { }
|
||||
bool r_ble_ll_sync_enabled(void) { return false; }
|
||||
int r_ble_ll_sync_create(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_sync_cancel(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_sync_terminate(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_sync_list_add(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_sync_list_remove(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_sync_list_clear(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_sync_list_size(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_sync_receive_enable(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
#endif //!DEFAULT_BT_LE_PERIODIC_SYNC
|
||||
|
||||
#if !DEFAULT_BT_LE_PAST || !DEFAULT_BT_LE_PERIODIC_ADV
|
||||
int r_ble_ll_adv_periodic_set_info_transfer(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
#endif //!DEFAULT_BT_LE_PAST || !DEFAULT_BT_LE_PERIODIC_ADV
|
||||
|
||||
#if !DEFAULT_BT_LE_PAST || !DEFAULT_BT_LE_PERIODIC_SYNC
|
||||
int r_ble_ll_sync_transfer(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_set_sync_transfer_params(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_set_default_sync_transfer_params(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
#endif //!DEFAULT_BT_LE_PAST || !DEFAULT_BT_LE_PERIODIC_SYNC
|
||||
|
||||
#if !DEFAULT_BT_LE_50_FEATURE_SUPPORT
|
||||
uint8_t r_ble_ll_ctrl_rx_channel_reporting_ind(void) { return 0x07; }
|
||||
uint8_t r_ble_ll_ctrl_rx_channel_status_ind(void) { return 0x07; }
|
||||
uint8_t r_ble_ll_ctrl_rx_sca_req(void) { return 0x07; }
|
||||
uint8_t r_ble_ll_ctrl_rx_sca_rsp(void) { return 0x07; }
|
||||
void r_ble_ll_ctrl_channel_class_reporting_make(void) { }
|
||||
void r_ble_ll_ctrl_channel_class_enable_make(void) { }
|
||||
void r_ble_ll_ctrl_sca_req_rsp_make(void) { }
|
||||
int r_ble_ll_modify_sca(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_conn_req_peer_sca(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
#endif //!DEFAULT_BT_LE_50_FEATURE_SUPPORT
|
||||
|
||||
#if !DEFAULT_BT_LE_50_FEATURE_SUPPORT
|
||||
int r_ble_ll_conn_hci_le_rd_phy(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_hci_le_set_def_phy(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_ll_conn_hci_le_set_phy(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
#endif //!DEFAULT_BT_LE_50_FEATURE_SUPPORT
|
||||
|
||||
#if !CONFIG_BT_LE_DTM_ENABLED
|
||||
void r_ble_lll_dtm_rx_pkt_in(void) { }
|
||||
int r_ble_lll_dtm_rx_isr_end(void) { return -1; }
|
||||
void r_ble_lll_dtm_reset(void) { }
|
||||
void r_ble_lll_dtm_init(void) { }
|
||||
void r_ble_lll_dtm_deinit(void) { }
|
||||
int r_ble_lll_dtm_env_init(void) { return 0; }
|
||||
void r_ble_lll_dtm_env_deinit(void) { }
|
||||
int r_ble_lll_hci_dtm_tx_test(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_lll_hci_dtm_rx_test(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_lll_dtm_end_test(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_lll_hci_dtm_rx_test_v2(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
int r_ble_lll_hci_dtm_tx_test_v2(void) { return BLE_ERR_UNKNOWN_HCI_CMD; }
|
||||
#endif //!CONFIG_BT_LE_DTM_ENABLED
|
||||
@@ -45,6 +45,14 @@ extern "C" {
|
||||
#define DEFAULT_BT_LE_50_FEATURE_SUPPORT (0)
|
||||
#endif
|
||||
|
||||
#define DEGAULT_BT_LE_2M_PHY (CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_2M_PHY)
|
||||
#define DEGAULT_BT_LE_CODED_PHY (CONFIG_BT_NIMBLE_LL_CFG_FEAT_LE_CODED_PHY)
|
||||
#define DEFAULT_BT_LE_EXT_ADV (CONFIG_BT_NIMBLE_EXT_ADV)
|
||||
#define DEFAULT_BT_LE_PERIODIC_ADV (CONFIG_BT_NIMBLE_ENABLE_PERIODIC_ADV)
|
||||
#define DEFAULT_BT_LE_EXT_SCAN (CONFIG_BT_NIMBLE_EXT_SCAN)
|
||||
#define DEFAULT_BT_LE_PERIODIC_SYNC (CONFIG_BT_NIMBLE_ENABLE_PERIODIC_SYNC)
|
||||
#define DEFAULT_BT_LE_PAST (CONFIG_BT_NIMBLE_PERIODIC_ADV_SYNC_TRANSFER)
|
||||
|
||||
#define DEFAULT_BT_LE_ROLE_OBSERVER MYNEWT_VAL(BLE_ROLE_OBSERVER)
|
||||
#define DEFAULT_BT_LE_ROLE_CENTROL MYNEWT_VAL(BLE_ROLE_CENTRAL)
|
||||
#define DEFAULT_BT_LE_ROLE_PERIPHERAL MYNEWT_VAL(BLE_ROLE_PERIPHERAL)
|
||||
@@ -122,12 +130,55 @@ extern "C" {
|
||||
#else
|
||||
#define DEFAULT_BT_LE_HCI_EVT_LO_BUF_COUNT (8)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_LE_50_FEATURE_SUPPORT)
|
||||
#define DEFAULT_BT_LE_50_FEATURE_SUPPORT (1)
|
||||
#else
|
||||
#define DEFAULT_BT_LE_50_FEATURE_SUPPORT (0)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_LE_LL_CFG_FEAT_LE_2M_PHY)
|
||||
#define DEGAULT_BT_LE_2M_PHY (CONFIG_BT_LE_LL_CFG_FEAT_LE_2M_PHY)
|
||||
#else
|
||||
#define DEGAULT_BT_LE_2M_PHY (0)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_LE_LL_CFG_FEAT_LE_CODED_PHY)
|
||||
#define DEGAULT_BT_LE_CODED_PHY (CONFIG_BT_LE_LL_CFG_FEAT_LE_CODED_PHY)
|
||||
#else
|
||||
#define DEGAULT_BT_LE_CODED_PHY (0)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_LE_EXT_ADV)
|
||||
#define DEFAULT_BT_LE_EXT_ADV (CONFIG_BT_LE_EXT_ADV)
|
||||
#else
|
||||
#define DEFAULT_BT_LE_EXT_ADV (0)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_LE_ENABLE_PERIODIC_ADV)
|
||||
#define DEFAULT_BT_LE_PERIODIC_ADV (CONFIG_BT_LE_ENABLE_PERIODIC_ADV)
|
||||
#else
|
||||
#define DEFAULT_BT_LE_PERIODIC_ADV (0)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_LE_EXT_SCAN)
|
||||
#define DEFAULT_BT_LE_EXT_SCAN (CONFIG_BT_LE_EXT_SCAN)
|
||||
#else
|
||||
#define DEFAULT_BT_LE_EXT_SCAN (0)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_LE_ENABLE_PERIODIC_SYNC)
|
||||
#define DEFAULT_BT_LE_PERIODIC_SYNC (CONFIG_BT_LE_ENABLE_PERIODIC_SYNC)
|
||||
#else
|
||||
#define DEFAULT_BT_LE_PERIODIC_SYNC (0)
|
||||
#endif
|
||||
|
||||
#if defined(BT_LE_PERIODIC_ADV_SYNC_TRANSFER)
|
||||
#define DEFAULT_BT_LE_PAST (BT_LE_PERIODIC_ADV_SYNC_TRANSFER)
|
||||
#else
|
||||
#define DEFAULT_BT_LE_PAST (0)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_BT_LE_ROLE_CENTROL_ENABLE)
|
||||
#define DEFAULT_BT_LE_ROLE_CENTROL (1)
|
||||
#else
|
||||
|
||||
@@ -226,6 +226,7 @@ config BT_CTRL_DFT_TX_POWER_LEVEL_EFF
|
||||
|
||||
config BT_CTRL_BLE_ADV_REPORT_FLOW_CTRL_SUPP
|
||||
bool "BLE adv report flow control supported"
|
||||
depends on (!BT_CTRL_RUN_IN_FLASH_ONLY) || (BT_CTRL_RUN_IN_FLASH_ONLY && BT_CTRL_BLE_SCAN)
|
||||
default y
|
||||
help
|
||||
The function is mainly used to enable flow control for advertising reports. When it is enabled,
|
||||
@@ -512,3 +513,38 @@ menu "BLE disconnect when instant passed"
|
||||
If this option is enabled, Controller will terminate the connection
|
||||
when instant passed in PHY update procedure.
|
||||
endmenu
|
||||
config BT_CTRL_RUN_IN_FLASH_ONLY
|
||||
bool "Put all BLE Controller code in flash"
|
||||
default n
|
||||
help
|
||||
If this option is enabled, all code for the Bluetooth controller will be moved from ROM and IRAM
|
||||
to flash, saving over 20K bytes of memory. However, it will require more flash resources and the
|
||||
performance of Bluetooth will decrease If this option is enabled, Bluetooth may not work properly
|
||||
during erasing flash. It is recommended to turn on the auto suspend function of flash. After auto
|
||||
suspend is turned on, Bluetooth interrupts can be executed normally during erasing flash, with less
|
||||
impact on Bluetooth performance.
|
||||
|
||||
config BT_CTRL_DTM_ENABLE
|
||||
depends on BT_CTRL_RUN_IN_FLASH_ONLY
|
||||
bool "Enable direct test mode feature"
|
||||
default n
|
||||
|
||||
config BT_CTRL_BLE_MASTER
|
||||
depends on BT_CTRL_RUN_IN_FLASH_ONLY
|
||||
bool "Enable BLE master role feature"
|
||||
default y
|
||||
|
||||
config BT_CTRL_BLE_TEST
|
||||
depends on BT_CTRL_RUN_IN_FLASH_ONLY
|
||||
bool "Enable BLE QA test feature"
|
||||
default n
|
||||
|
||||
config BT_CTRL_BLE_SCAN
|
||||
depends on BT_CTRL_RUN_IN_FLASH_ONLY
|
||||
bool "Enable BLE scan feature"
|
||||
default y
|
||||
|
||||
config BT_CTRL_BLE_SECURITY_ENABLE
|
||||
depends on BT_CTRL_RUN_IN_FLASH_ONLY && BT_CONTROLLER_ONLY
|
||||
bool "Enable BLE security feature"
|
||||
default y
|
||||
|
||||
@@ -499,7 +499,11 @@ static int interrupt_alloc_wrapper(int cpu_id, int source, intr_handler_t handle
|
||||
{
|
||||
btdm_isr_alloc_t p;
|
||||
p.source = source;
|
||||
#if CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY
|
||||
p.flags = ESP_INTR_FLAG_LEVEL3;
|
||||
#else
|
||||
p.flags = ESP_INTR_FLAG_LEVEL3 | ESP_INTR_FLAG_IRAM;
|
||||
#endif
|
||||
p.fn = handler;
|
||||
p.arg = arg;
|
||||
p.handle = (intr_handle_t *)ret_handle;
|
||||
@@ -1426,6 +1430,10 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
|
||||
|
||||
ESP_LOGI(BT_LOG_TAG, "BT controller compile version [%s]", btdm_controller_get_compile_version());
|
||||
|
||||
#if (CONFIG_BT_CTRL_RUN_IN_FLASH_ONLY)
|
||||
ESP_LOGI(BT_LOG_TAG,"Put all controller code in flash");
|
||||
#endif
|
||||
|
||||
if ((err = btdm_low_power_mode_init(cfg)) != ESP_OK) {
|
||||
ESP_LOGE(BT_LOG_TAG, "Low power module initialization failed");
|
||||
goto error;
|
||||
|
||||
0
components/bt/controller/esp32h21/Kconfig.in
Normal file
0
components/bt/controller/esp32h21/Kconfig.in
Normal file
Submodule components/bt/controller/lib_esp32 updated: c3f6258cfb...4f9869a760
Submodule components/bt/controller/lib_esp32c2/esp32c2-bt-lib updated: e5c7ef0bf7...99ea7d1483
Submodule components/bt/controller/lib_esp32c3_family updated: eeb2782618...6470c01165
Submodule components/bt/controller/lib_esp32c6/esp32c6-bt-lib updated: 69f16a7a63...b86a06d38c
Submodule components/bt/controller/lib_esp32h2/esp32h2-bt-lib updated: 50f567fff5...90f1ef76ab
@@ -21,13 +21,25 @@ if BLE_MESH
|
||||
for mesh packets. And this could help avoid collision of
|
||||
advertising packets.
|
||||
|
||||
menuconfig BLE_MESH_USE_BLE_50
|
||||
bool "Support using BLE 5.0 APIs for BLE Mesh"
|
||||
depends on BLE_MESH_EXPERIMENTAL
|
||||
depends on IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3
|
||||
select BT_NIMBLE_50_FEATURE_SUPPORT if BT_NIMBLE_ENABLED
|
||||
select BT_NIMBLE_EXT_ADV if BT_NIMBLE_ENABLED
|
||||
select BT_BLE_50_FEATURES_SUPPORTED if BT_BLUEDROID_ENABLED
|
||||
select BT_LE_50_FEATURE_SUPPORT if IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32H2
|
||||
default n
|
||||
help
|
||||
This option to enable BLE Mesh using some BLE 5.0 APIs.
|
||||
|
||||
config BLE_MESH_USE_DUPLICATE_SCAN
|
||||
bool "Support Duplicate Scan in BLE Mesh"
|
||||
select BTDM_BLE_SCAN_DUPL if IDF_TARGET_ESP32
|
||||
select BTDM_BLE_MESH_SCAN_DUPL_EN if IDF_TARGET_ESP32
|
||||
select BT_CTRL_BLE_SCAN_DUPL if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3
|
||||
select BT_CTRL_BLE_MESH_SCAN_DUPL_EN if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32S3
|
||||
select BT_LE_SCAN_DUPL if IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32H2
|
||||
select BT_LE_SCAN_DUPL if IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32H2 || IDF_TARGET_ESP32C61 || IDF_TARGET_ESP32C5
|
||||
select BT_NIMBLE_VS_SUPPORT if BT_NIMBLE_ENABLED
|
||||
default y
|
||||
help
|
||||
@@ -415,6 +427,13 @@ if BLE_MESH
|
||||
will store the solicitation src and solicitation sequence number of
|
||||
the received Solicitation PDU message.
|
||||
|
||||
config BLE_MESH_PROXY_CLI_SRV_COEXIST
|
||||
bool "Support Proxy Client and Proxy Server coexistence"
|
||||
depends on BLE_MESH_EXPERIMENTAL
|
||||
default n
|
||||
help
|
||||
Enable this option to support the coexistence of proxy client and proxy server.
|
||||
|
||||
config BLE_MESH_GATT_PROXY_CLIENT
|
||||
bool "BLE Mesh GATT Proxy Client"
|
||||
select BLE_MESH_PROXY
|
||||
@@ -1646,5 +1665,7 @@ if BLE_MESH
|
||||
Make BLE Mesh Experimental features visible.
|
||||
Experimental features list:
|
||||
- CONFIG_BLE_MESH_NOT_RELAY_REPLAY_MSG
|
||||
- CONFIG_BLE_MESH_USE_BLE_50
|
||||
- CONFIG_BLE_MESH_PROXY_CLI_SRV_COEXIST
|
||||
|
||||
endif # BLE_MESH
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -12,14 +12,14 @@
|
||||
#include "btc_ble_mesh_ble.h"
|
||||
#include "esp_ble_mesh_ble_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_BLE_COEX_SUPPORT
|
||||
#if (CONFIG_BLE_MESH_BLE_COEX_SUPPORT || CONFIG_BLE_MESH_USE_BLE_50)
|
||||
esp_err_t esp_ble_mesh_register_ble_callback(esp_ble_mesh_ble_cb_t callback)
|
||||
{
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_BLE_MESH_BLE_COEX, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_BLE_COEX_SUPPORT */
|
||||
#endif /* (CONFIG_BLE_MESH_BLE_COEX_SUPPORT || CONFIG_BLE_MESH_USE_BLE_50) */
|
||||
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
|
||||
esp_err_t esp_ble_mesh_start_ble_advertising(const esp_ble_mesh_ble_adv_param_t *param,
|
||||
@@ -100,3 +100,23 @@ esp_err_t esp_ble_mesh_stop_ble_scanning(void)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
|
||||
|
||||
esp_err_t esp_ble_mesh_scan_params_update(esp_ble_mesh_scan_param_t *scan_param)
|
||||
{
|
||||
btc_ble_mesh_ble_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!scan_param) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_BLE_MESH_BLE_COEX;
|
||||
msg.act = BTC_BLE_MESH_ACT_UPDATE_SCAN_PARAMS;
|
||||
|
||||
arg.scan_params.scan_interval = scan_param->scan_interval;
|
||||
arg.scan_params.uncoded_scan_window = scan_param->uncoded_scan_window;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_ble_args_t), NULL, NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -9,6 +9,10 @@
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BT_NIMBLE_ENABLED
|
||||
#include "host/ble_gap.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -20,9 +24,38 @@ typedef enum {
|
||||
ESP_BLE_MESH_START_BLE_SCANNING_COMP_EVT, /*!< Start BLE scanning completion event */
|
||||
ESP_BLE_MESH_STOP_BLE_SCANNING_COMP_EVT, /*!< Stop BLE scanning completion event */
|
||||
ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT, /*!< Scanning BLE advertising packets event */
|
||||
ESP_BLE_MESH_SCAN_PARAMS_UPDATE_COMP_EVT, /*!< Scan parameters update completion event */
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BT_NIMBLE_ENABLED
|
||||
ESP_BLE_MESH_NIMBLE_GAP_EVENT_EVT, /*!< NIMBLE GAP event */
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BT_NIMBLE_ENABLED */
|
||||
ESP_BLE_MESH_BLE_EVT_MAX,
|
||||
} esp_ble_mesh_ble_cb_event_t;
|
||||
|
||||
/** Context of BLE advertising report. */
|
||||
typedef struct {
|
||||
uint8_t addr[6]; /*!< Device address */
|
||||
uint8_t addr_type; /*!< Device address type */
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
uint8_t adv_type __attribute__((deprecated("`event_type` should be used to determine the advertising type"))); /*!< advertising type */
|
||||
#else
|
||||
uint8_t adv_type; /*!< Advertising type */
|
||||
#endif
|
||||
uint8_t *data; /*!< Advertising data */
|
||||
uint16_t length; /*!< Advertising data length */
|
||||
int8_t rssi; /*!< RSSI of the advertising packet */
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
uint8_t event_type; /*!< Extended advertising event type */
|
||||
uint8_t primary_phy; /*!< Extended advertising primary PHY */
|
||||
uint8_t secondary_phy; /*!< Extended advertising secondary PHY */
|
||||
uint8_t sid; /*!< Extended advertising set ID */
|
||||
uint8_t tx_power; /*!< Extended advertising TX power */
|
||||
uint8_t dir_addr_type; /*!< Direct address type */
|
||||
uint8_t dir_addr[6]; /*!< Direct address */
|
||||
uint8_t data_status; /*!< Data type */
|
||||
uint16_t per_adv_interval; /*!< Periodic advertising interval */
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
} esp_ble_mesh_ble_adv_rpt_t;
|
||||
|
||||
/** BLE operation callback parameters */
|
||||
typedef union {
|
||||
/**
|
||||
@@ -52,16 +85,24 @@ typedef union {
|
||||
int err_code; /*!< Indicate the result of stopping BLE scanning */
|
||||
} stop_ble_scan_comp; /*!< Event parameters of ESP_BLE_MESH_STOP_BLE_SCANNING_COMP_EVT */
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT
|
||||
* @brief Event parameters of ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT
|
||||
*/
|
||||
struct {
|
||||
uint8_t addr[6]; /*!< Device address */
|
||||
uint8_t addr_type; /*!< Device address type */
|
||||
uint8_t adv_type; /*!< Advertising data type */
|
||||
uint8_t *data; /*!< Advertising data */
|
||||
uint16_t length; /*!< Advertising data length */
|
||||
int8_t rssi; /*!< RSSI of the advertising packet */
|
||||
} scan_ble_adv_pkt; /*!< Event parameters of ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT */
|
||||
esp_ble_mesh_ble_adv_rpt_t scan_ble_adv_pkt;
|
||||
/**
|
||||
* @brief Event parameter of ESP_BLE_MESH_SCAN_PARAMS_UPDATE_COMP_EVT
|
||||
*/
|
||||
struct ble_mesh_scan_params_update_comp_param {
|
||||
int err_code; /*!< Indicates the result of updating scan parameters */
|
||||
} scan_params_update_comp; /*!< Event parameter of ESP_BLE_MESH_SCAN_PARAMS_UPDATE_COMP_EVT */
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BT_NIMBLE_ENABLED
|
||||
/**
|
||||
* @brief Event parameters of ESP_BLE_MESH_NIMBLE_GAP_EVENT_EVT
|
||||
*/
|
||||
struct ble_mesh_nimble_gap_event_evt_param {
|
||||
struct ble_gap_event event; /*!< GAP event parameters for NimBLE Host */
|
||||
void *arg; /*!< User parameters */
|
||||
} nimble_gap_evt; /*!< Event parameters of ESP_BLE_MESH_NIMBLE_GAP_EVENT_EVT */
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BT_NIMBLE_ENABLED */
|
||||
} esp_ble_mesh_ble_cb_param_t;
|
||||
|
||||
/**
|
||||
@@ -175,6 +216,33 @@ esp_err_t esp_ble_mesh_start_ble_scanning(esp_ble_mesh_ble_scan_param_t *param);
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_stop_ble_scanning(void);
|
||||
|
||||
/**
|
||||
* @brief Update BLE Mesh scan parameters.
|
||||
*
|
||||
* @note
|
||||
* 1. This function shall be used after ESP BLE Mesh is initialized!
|
||||
* Parameters `scan_interval` and `uncoded_scan_window` must both
|
||||
* be multiples of 8.
|
||||
*
|
||||
* 2. If the config BLE_MESH_USE_BLE_50 is enabled, within the scan_interval:
|
||||
* - If uncoded_scan_window is not zero, the scan_interval is divided into
|
||||
* two parts:
|
||||
* - uncoded_scan_window: Used for performing uncoded scanning.
|
||||
* - (scan_interval - uncoded_scan_window): The remaining time is
|
||||
* used for coded scanning (coded_scan).
|
||||
* - If uncoded_scan_window is set to 0, it means the entire scan_interval
|
||||
* is used for coded scanning.
|
||||
* - If uncoded_scan_window is equal to scan_interval, it means the entire
|
||||
* scan_interval is used for uncoded scanning.
|
||||
*
|
||||
* @param[in] scan_param: Scan parameters
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - ESP_FAIL: Invalid parameters or unable transfer this command to the stack
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_scan_params_update(esp_ble_mesh_scan_param_t *scan_param);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -415,6 +415,29 @@ typedef struct {
|
||||
bool erase_flash; /*!< Indicate if erasing flash when deinit mesh stack */
|
||||
} esp_ble_mesh_deinit_param_t;
|
||||
|
||||
/** Scan parameters */
|
||||
typedef struct {
|
||||
/**
|
||||
* Scan interval.
|
||||
*
|
||||
* Range: 0x0004 to 0x4000.
|
||||
*
|
||||
* Time = N * 0.625 ms. Time Range: 2.5 ms to 10.24 s
|
||||
*/
|
||||
uint16_t scan_interval;
|
||||
|
||||
/**
|
||||
* Uncoded Scan window.
|
||||
*
|
||||
* Time scanned on uncoded PHY within a scan interval.
|
||||
*
|
||||
* Range: 0x0004 to 0x4000.
|
||||
*
|
||||
* Time = N * 0.625 ms. Time Range: 2.5 ms to 10.24 s
|
||||
*/
|
||||
uint16_t uncoded_scan_window;
|
||||
} esp_ble_mesh_scan_param_t;
|
||||
|
||||
/** Format of Unicast Address Range */
|
||||
typedef struct {
|
||||
uint16_t len_present:1, /*!< Indicate the presence or absence of the RangeLength field */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -13,8 +13,7 @@
|
||||
#include "mesh/adapter.h"
|
||||
#include "esp_ble_mesh_ble_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_BLE_COEX_SUPPORT
|
||||
|
||||
#if (CONFIG_BLE_MESH_BLE_COEX_SUPPORT || CONFIG_BLE_MESH_USE_BLE_50)
|
||||
static void btc_ble_mesh_ble_copy_req_data(btc_msg_t *msg, void *p_dst, void *p_src)
|
||||
{
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
@@ -29,6 +28,7 @@ static void btc_ble_mesh_ble_copy_req_data(btc_msg_t *msg, void *p_dst, void *p_
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT:
|
||||
if (p_src_data->scan_ble_adv_pkt.data && p_src_data->scan_ble_adv_pkt.length) {
|
||||
memcpy(&p_dst_data->scan_ble_adv_pkt, &p_src_data->scan_ble_adv_pkt, sizeof(p_src_data->scan_ble_adv_pkt));
|
||||
p_dst_data->scan_ble_adv_pkt.length = p_src_data->scan_ble_adv_pkt.length;
|
||||
p_dst_data->scan_ble_adv_pkt.data = bt_mesh_calloc(p_src_data->scan_ble_adv_pkt.length);
|
||||
if (p_dst_data->scan_ble_adv_pkt.data) {
|
||||
@@ -86,26 +86,34 @@ static void btc_ble_mesh_ble_callback(esp_ble_mesh_ble_cb_param_t *cb_params, ui
|
||||
btc_ble_mesh_ble_copy_req_data, btc_ble_mesh_ble_free_req_data);
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
void bt_mesh_ble_scan_cb_evt_to_btc(const bt_mesh_addr_t *addr,
|
||||
uint8_t adv_type, uint8_t data[],
|
||||
uint16_t length, int8_t rssi)
|
||||
#if CONFIG_BT_NIMBLE_ENABLED && CONFIG_BLE_MESH_USE_BLE_50
|
||||
void bt_mesh_ble_nimble_evt_to_btc(struct ble_gap_event *event, void *arg)
|
||||
{
|
||||
esp_ble_mesh_ble_cb_param_t param = {0};
|
||||
|
||||
if (addr == NULL) {
|
||||
if (event == NULL) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(param.scan_ble_adv_pkt.addr, addr->val, sizeof(addr->val));
|
||||
param.scan_ble_adv_pkt.addr_type = addr->type;
|
||||
if (data && length) {
|
||||
param.scan_ble_adv_pkt.data = data;
|
||||
param.scan_ble_adv_pkt.length = length;
|
||||
memcpy(¶m.nimble_gap_evt.event, event, sizeof(struct ble_gap_event));
|
||||
param.nimble_gap_evt.arg = arg;
|
||||
|
||||
btc_ble_mesh_ble_callback(¶m, ESP_BLE_MESH_NIMBLE_GAP_EVENT_EVT);
|
||||
}
|
||||
#endif /* CONFIG_BT_NIMBLE_ENABLED && CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
void bt_mesh_ble_scan_cb_evt_to_btc(bt_mesh_ble_adv_report_t *adv_report)
|
||||
{
|
||||
esp_ble_mesh_ble_cb_param_t param = {0};
|
||||
|
||||
if (adv_report == NULL) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
param.scan_ble_adv_pkt.adv_type = adv_type;
|
||||
param.scan_ble_adv_pkt.rssi = rssi;
|
||||
|
||||
memcpy(¶m.scan_ble_adv_pkt, adv_report, sizeof(bt_mesh_ble_adv_report_t));
|
||||
|
||||
btc_ble_mesh_ble_callback(¶m, ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT);
|
||||
}
|
||||
@@ -157,6 +165,14 @@ void btc_ble_mesh_ble_call_handler(btc_msg_t *msg)
|
||||
btc_ble_mesh_ble_callback(¶m, ESP_BLE_MESH_STOP_BLE_SCANNING_COMP_EVT);
|
||||
break;
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
|
||||
case BTC_BLE_MESH_ACT_UPDATE_SCAN_PARAMS:
|
||||
struct bt_mesh_scan_param scan_param = {
|
||||
.interval = arg->scan_params.scan_interval,
|
||||
.window = arg->scan_params.uncoded_scan_window,
|
||||
};
|
||||
param.scan_params_update_comp.err_code = bt_mesh_scan_param_update(&scan_param);
|
||||
btc_ble_mesh_ble_callback(¶m, ESP_BLE_MESH_SCAN_PARAMS_UPDATE_COMP_EVT);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
@@ -191,5 +207,4 @@ void btc_ble_mesh_ble_cb_handler(btc_msg_t *msg)
|
||||
|
||||
btc_ble_mesh_ble_free_req_data(msg);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_BLE_COEX_SUPPORT */
|
||||
#endif /* (CONFIG_BLE_MESH_BLE_COEX_SUPPORT || CONFIG_BLE_MESH_USE_BLE_50) */
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#endif /* CONFIG_BLE_MESH_V11_SUPPORT */
|
||||
|
||||
#include "adv.h"
|
||||
#include "scan.h"
|
||||
#include "mesh/kernel.h"
|
||||
#include "mesh/proxy.h"
|
||||
#include "mesh.h"
|
||||
@@ -2948,6 +2949,7 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg)
|
||||
.ctx.send_tag = arg->model_send.ctx->send_tag,
|
||||
.msg_timeout = arg->model_send.msg_timeout,
|
||||
};
|
||||
|
||||
err = bt_mesh_client_send_msg(¶m, buf, arg->model_send.need_rsp,
|
||||
btc_ble_mesh_client_model_timeout_cb);
|
||||
bt_mesh_free_buf(buf);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -16,6 +16,30 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint8_t addr[6]; /*!< Device address */
|
||||
uint8_t addr_type; /*!< Device address type */
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
uint8_t adv_type __attribute__((deprecated("`event_type` should be used to determine the advertising type"))); /*!< advertising type */
|
||||
#else
|
||||
uint8_t adv_type; /*!< Advertising type */
|
||||
#endif
|
||||
uint8_t *data; /*!< Advertising data */
|
||||
uint16_t length; /*!< Advertising data length */
|
||||
int8_t rssi; /*!< RSSI of the advertising packet */
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
uint8_t event_type; /*!< Extended advertising event type */
|
||||
uint8_t primary_phy; /*!< Extended advertising primary PHY */
|
||||
uint8_t secondary_phy; /*!< Extended advertising secondary PHY */
|
||||
uint8_t sid; /*!< Extended advertising set ID */
|
||||
uint8_t tx_power; /*!< Extended advertising TX power */
|
||||
uint8_t dir_addr_type; /*!< Direct address type */
|
||||
uint8_t dir_addr[6]; /*!< Direct address */
|
||||
uint8_t data_status; /*!< Data type */
|
||||
uint16_t per_adv_interval; /*!< Periodic advertising interval */
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
} bt_mesh_ble_adv_report_t;
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
esp_ble_mesh_ble_adv_param_t param;
|
||||
@@ -30,6 +54,10 @@ typedef union {
|
||||
struct {
|
||||
/* RFU */
|
||||
} stop_ble_scan;
|
||||
struct ble_mesh_scan_params {
|
||||
uint16_t scan_interval;
|
||||
uint16_t uncoded_scan_window;
|
||||
} scan_params;
|
||||
} btc_ble_mesh_ble_args_t;
|
||||
|
||||
typedef enum {
|
||||
@@ -37,11 +65,14 @@ typedef enum {
|
||||
BTC_BLE_MESH_ACT_STOP_BLE_ADV,
|
||||
BTC_BLE_MESH_ACT_START_BLE_SCAN,
|
||||
BTC_BLE_MESH_ACT_STOP_BLE_SCAN,
|
||||
BTC_BLE_MESH_ACT_UPDATE_SCAN_PARAMS,
|
||||
} btc_ble_mesh_ble_act_t;
|
||||
|
||||
void bt_mesh_ble_scan_cb_evt_to_btc(const bt_mesh_addr_t *addr,
|
||||
uint8_t adv_type, uint8_t data[],
|
||||
uint16_t length, int8_t rssi);
|
||||
void bt_mesh_ble_scan_cb_evt_to_btc(bt_mesh_ble_adv_report_t *adv_report);
|
||||
|
||||
#if CONFIG_BT_NIMBLE_ENABLED && CONFIG_BLE_MESH_USE_BLE_50
|
||||
void bt_mesh_ble_nimble_evt_to_btc(struct ble_gap_event *event, void *arg);
|
||||
#endif /* CONFIG_BT_NIMBLE_ENABLED && CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
|
||||
void btc_ble_mesh_ble_call_handler(btc_msg_t *msg);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
@@ -200,7 +200,7 @@ extern "C" {
|
||||
* { MY_PWM0 , MY_PWM1 }
|
||||
*
|
||||
* @param LEN The length of the sequence. Must be an integer literal less
|
||||
* than 255.
|
||||
* than 255 (ref: utils_loops.h).
|
||||
* @param F A macro function that accepts at least two arguments:
|
||||
* <tt>F(i, ...)</tt>. @p F is called repeatedly in the expansion.
|
||||
* Its first argument @p i is the index in the sequence, and
|
||||
|
||||
@@ -45,6 +45,14 @@ static const uint8_t adv_type[] = {
|
||||
[BLE_MESH_ADV_URI] = BLE_MESH_DATA_URI,
|
||||
};
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
#define ESP_BLE_MESH_INST_UNUSED_ELT_(IDX, _) [IDX] = {.id = IDX}
|
||||
|
||||
static struct bt_mesh_adv_inst adv_insts[BLE_MESH_ADV_INS_CNT] = {
|
||||
LISTIFY(BLE_MESH_ADV_INS_CNT, ESP_BLE_MESH_INST_UNUSED_ELT_, (,)),
|
||||
};
|
||||
#endif
|
||||
|
||||
NET_BUF_POOL_DEFINE(adv_buf_pool, CONFIG_BLE_MESH_ADV_BUF_COUNT,
|
||||
BLE_MESH_ADV_DATA_SIZE, BLE_MESH_ADV_USER_DATA_SIZE, NULL);
|
||||
|
||||
@@ -122,11 +130,51 @@ struct bt_mesh_adv_task {
|
||||
|
||||
static struct bt_mesh_adv_task adv_task;
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
bool bt_mesh_is_adv_inst_used(uint8_t adv_inst_id)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(adv_insts); i++) {
|
||||
if (adv_insts[i].id == adv_inst_id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t bt_mesh_get_proxy_inst(void)
|
||||
{
|
||||
return adv_insts[0].id;
|
||||
}
|
||||
|
||||
void bt_mesh_adv_inst_deinit(void)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(adv_insts); i++) {
|
||||
bt_le_ext_adv_stop(adv_insts[i].id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct bt_mesh_adv *adv_alloc(int id)
|
||||
{
|
||||
return &adv_pool[id];
|
||||
}
|
||||
|
||||
int ble_mesh_adv_task_wakeup(uint16_t adv_inst_id)
|
||||
{
|
||||
xTaskNotify(adv_task.handle, BIT(adv_inst_id), eSetBits);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline bool ble_mesh_adv_task_wait(uint32_t timeout, uint32_t *notify)
|
||||
{
|
||||
return xTaskNotifyWait(UINT32_MAX, UINT32_MAX, notify, timeout) == pdTRUE;
|
||||
}
|
||||
|
||||
static inline void adv_send_start(uint16_t duration, int err,
|
||||
const struct bt_mesh_send_cb *cb,
|
||||
void *cb_data)
|
||||
@@ -155,8 +203,16 @@ uint16_t bt_mesh_pdu_duration(uint8_t xmit)
|
||||
return duration;
|
||||
}
|
||||
|
||||
static inline TickType_t K_WAIT(int32_t val)
|
||||
{
|
||||
return (val == K_FOREVER) ? portMAX_DELAY : (val / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
static inline int adv_send(struct net_buf *buf)
|
||||
{
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
struct bt_mesh_adv_inst *adv_ins = &adv_insts[0];
|
||||
#endif
|
||||
const struct bt_mesh_send_cb *cb = BLE_MESH_ADV(buf)->cb;
|
||||
void *cb_data = BLE_MESH_ADV(buf)->cb_data;
|
||||
struct bt_mesh_adv_param param = {0};
|
||||
@@ -187,6 +243,11 @@ static inline int adv_send(struct net_buf *buf)
|
||||
param.interval_min = ADV_SCAN_UNIT(adv_int);
|
||||
param.interval_max = param.interval_min;
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
param.adv_duration = duration;
|
||||
param.adv_count = BLE_MESH_TRANSMIT_COUNT(BLE_MESH_ADV(buf)->xmit) + 1;
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_PROXY_SOLIC_PDU_TX
|
||||
if (BLE_MESH_ADV(buf)->type == BLE_MESH_ADV_PROXY_SOLIC) {
|
||||
bt_mesh_adv_buf_ref_debug(__func__, buf, 3U, BLE_MESH_BUF_REF_SMALL);
|
||||
@@ -195,12 +256,24 @@ static inline int adv_send(struct net_buf *buf)
|
||||
BLE_MESH_ADV_DATA_BYTES(BLE_MESH_DATA_UUID16_ALL, 0x59, 0x18),
|
||||
BLE_MESH_ADV_DATA(BLE_MESH_DATA_SVC_DATA16, buf->data, buf->len),
|
||||
};
|
||||
err = bt_le_adv_start(¶m, solic_ad, 3, NULL, 0);
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
param.primary_phy = BLE_MESH_ADV_PHY_1M;
|
||||
param.secondary_phy = BLE_MESH_ADV_PHY_1M;
|
||||
err = bt_le_ext_adv_start(adv_ins->id, ¶m, &ad, 3, NULL, 0);
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
err = bt_le_adv_start(¶m, &ad, 3, NULL, 0);
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
bt_mesh_adv_buf_ref_debug(__func__, buf, 4U, BLE_MESH_BUF_REF_SMALL);
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
param.primary_phy = BLE_MESH_ADV_PHY_1M;
|
||||
param.secondary_phy = BLE_MESH_ADV_PHY_1M;
|
||||
err = bt_le_ext_adv_start(adv_ins->id, ¶m, &ad, 1, NULL, 0);
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
err = bt_le_adv_start(¶m, &ad, 1, NULL, 0);
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
}
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
|
||||
} else {
|
||||
@@ -229,7 +302,11 @@ static inline int adv_send(struct net_buf *buf)
|
||||
|
||||
bt_mesh_adv_buf_ref_debug(__func__, buf, 3U, BLE_MESH_BUF_REF_SMALL);
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
err = bt_mesh_ble_ext_adv_start(adv_ins->id, &tx->param, &data);
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
err = bt_mesh_ble_adv_start(&tx->param, &data);
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
|
||||
|
||||
@@ -242,9 +319,19 @@ static inline int adv_send(struct net_buf *buf)
|
||||
|
||||
BT_DBG("Advertising started. Sleeping %u ms", duration);
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
if (!ble_mesh_adv_task_wait(K_WAIT(K_FOREVER), NULL)) {
|
||||
BT_WARN("Advertising didn't finish on time");
|
||||
bt_le_ext_adv_stop(adv_ins->id);
|
||||
}
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
k_sleep(K_MSEC(duration));
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
|
||||
#if !CONFIG_BLE_MESH_USE_BLE_50
|
||||
err = bt_le_adv_stop();
|
||||
#endif
|
||||
|
||||
adv_send_end(err, cb, cb_data);
|
||||
if (err) {
|
||||
BT_ERR("Stop advertising failed: err %d", err);
|
||||
@@ -255,11 +342,6 @@ static inline int adv_send(struct net_buf *buf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline TickType_t K_WAIT(int32_t val)
|
||||
{
|
||||
return (val == K_FOREVER) ? portMAX_DELAY : (val / portTICK_PERIOD_MS);
|
||||
}
|
||||
|
||||
static void adv_thread(void *p)
|
||||
{
|
||||
#if CONFIG_BLE_MESH_RELAY_ADV_BUF
|
||||
@@ -679,6 +761,10 @@ void bt_mesh_adv_deinit(void)
|
||||
return;
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
bt_mesh_adv_inst_deinit();
|
||||
#endif
|
||||
|
||||
vTaskDelete(adv_task.handle);
|
||||
adv_task.handle = NULL;
|
||||
#if (CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && \
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017 Intel Corporation
|
||||
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "mesh/atomic.h"
|
||||
#include "mesh/access.h"
|
||||
#include "mesh/adapter.h"
|
||||
#include "mesh/utils.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -67,6 +68,19 @@ typedef enum {
|
||||
BLE_MESH_BUF_REF_MAX,
|
||||
} bt_mesh_buf_ref_flag_t;
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
|
||||
#define BLE_MESH_ADV_INS_UNUSED 0xFF
|
||||
#define BLE_MESH_ADV_INS_CNT 1
|
||||
|
||||
struct bt_mesh_adv_inst {
|
||||
uint8_t id;
|
||||
};
|
||||
|
||||
int ble_mesh_adv_task_wakeup(uint16_t adv_inst_id);
|
||||
bool bt_mesh_is_adv_inst_used(uint8_t adv_inst_id);
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
|
||||
void bt_mesh_adv_buf_ref_debug(const char *func, struct net_buf *buf,
|
||||
uint8_t ref_cmp, bt_mesh_buf_ref_flag_t flag);
|
||||
|
||||
@@ -81,6 +95,10 @@ void bt_mesh_adv_send(struct net_buf *buf, uint8_t xmit,
|
||||
const struct bt_mesh_send_cb *cb,
|
||||
void *cb_data);
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50 && (CONFIG_BLE_MESH_GATT_PROXY_SERVER || CONFIG_BLE_MESH_PB_GATT)
|
||||
uint8_t bt_mesh_get_proxy_inst(void);
|
||||
#endif
|
||||
|
||||
struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, int32_t timeout);
|
||||
|
||||
void bt_mesh_relay_adv_send(struct net_buf *buf, uint8_t xmit,
|
||||
|
||||
@@ -29,8 +29,10 @@
|
||||
#include "mesh/adapter.h"
|
||||
#include "mesh/common.h"
|
||||
#include "prov_pvnr.h"
|
||||
#include "scan.h"
|
||||
#include "net.h"
|
||||
#include "beacon.h"
|
||||
#include "btc_ble_mesh_ble.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_V11_SUPPORT
|
||||
#include "mesh_v1.1/utils.h"
|
||||
@@ -60,7 +62,10 @@ static uint8_t bt_mesh_private_key[32];
|
||||
|
||||
/* Scan related functions */
|
||||
static bt_mesh_scan_cb_t *bt_mesh_scan_dev_found_cb;
|
||||
|
||||
#if !CONFIG_BLE_MESH_USE_BLE_50
|
||||
static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data);
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_SERVER || \
|
||||
@@ -104,6 +109,14 @@ static struct bt_mesh_prov_conn_cb *bt_mesh_gattc_conn_cb;
|
||||
static tBTA_GATTC_IF bt_mesh_gattc_if;
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BLE_MESH_SUPPORT_BLE_ADV
|
||||
static inline void bt_mesh_set_ble_adv_running();
|
||||
|
||||
static inline void bt_mesh_unset_ble_adv_running();
|
||||
|
||||
static inline bool bt_mesh_is_ble_adv_running();
|
||||
#endif
|
||||
|
||||
int bt_mesh_host_init(void)
|
||||
{
|
||||
return 0;
|
||||
@@ -138,11 +151,18 @@ void bt_mesh_hci_init(void)
|
||||
|
||||
const uint8_t *p = controller_get_interface()->get_ble_supported_states();
|
||||
uint64_t states_fh = 0, states_sh = 0;
|
||||
STREAM_TO_UINT32(states_fh, p);
|
||||
STREAM_TO_UINT32(states_sh, p);
|
||||
|
||||
/* macro STREAM_TO_UINT32 expansion */
|
||||
states_fh = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + ((((uint32_t)(*((p) + 2)))) << 16) + ((((uint32_t)(*((p) + 3)))) << 24));
|
||||
(p) += 4;
|
||||
|
||||
states_sh = (((uint32_t)(*(p))) + ((((uint32_t)(*((p) + 1)))) << 8) + ((((uint32_t)(*((p) + 2)))) << 16) + ((((uint32_t)(*((p) + 3)))) << 24));
|
||||
(p) += 4;
|
||||
|
||||
bt_mesh_dev.le.states = (states_sh << 32) | states_fh;
|
||||
}
|
||||
|
||||
#if !CONFIG_BLE_MESH_USE_BLE_50
|
||||
static void bt_mesh_scan_results_change_2_bta(tBTM_INQ_RESULTS *p_inq, uint8_t *p_eir,
|
||||
tBTA_DM_SEARCH_CBACK *p_scan_cback)
|
||||
{
|
||||
@@ -185,6 +205,189 @@ static void bt_mesh_scan_results_cb(tBTM_INQ_RESULTS *p_inq, uint8_t *p_eir)
|
||||
{
|
||||
bt_mesh_scan_results_change_2_bta(p_inq, p_eir, bt_mesh_scan_result_callback);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
extern void btc_ble_5_gap_callback(tBTA_DM_BLE_5_GAP_EVENT event,
|
||||
tBTA_DM_BLE_5_GAP_CB_PARAMS *params);
|
||||
|
||||
void bt_mesh_ble_ext_adv_report(tBTM_BLE_EXT_ADV_REPORT *ext_adv_report)
|
||||
{
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
bt_mesh_ble_adv_report_t adv_rpt = {0};
|
||||
|
||||
if (bt_mesh_ble_scan_state_get()) {
|
||||
memcpy(adv_rpt.addr, ext_adv_report->addr, BLE_MESH_ADDR_LEN);
|
||||
memcpy(adv_rpt.dir_addr, ext_adv_report->dir_addr, BLE_MESH_ADDR_LEN);
|
||||
|
||||
adv_rpt.addr_type = ext_adv_report->addr_type;
|
||||
adv_rpt.data = ext_adv_report->adv_data;
|
||||
adv_rpt.length = ext_adv_report->adv_data_len;
|
||||
adv_rpt.rssi = ext_adv_report->rssi;
|
||||
adv_rpt.event_type = ext_adv_report->event_type;
|
||||
adv_rpt.primary_phy = ext_adv_report->primary_phy;
|
||||
adv_rpt.secondary_phy = ext_adv_report->secondry_phy;
|
||||
adv_rpt.sid = ext_adv_report->sid;
|
||||
adv_rpt.tx_power = ext_adv_report->tx_power;
|
||||
adv_rpt.dir_addr_type = ext_adv_report->dir_addr_type;
|
||||
adv_rpt.data_status = ext_adv_report->data_status;
|
||||
adv_rpt.per_adv_interval = ext_adv_report->per_adv_interval;
|
||||
|
||||
bt_mesh_ble_scan_cb_evt_to_btc(&adv_rpt);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
|
||||
}
|
||||
|
||||
static bool bt_mesh_scan_result_process(tBTM_BLE_EXT_ADV_REPORT *ext_adv_report)
|
||||
{
|
||||
struct bt_mesh_adv_report adv_rpt = {0};
|
||||
|
||||
assert(ext_adv_report);
|
||||
|
||||
adv_rpt.addr.type = ext_adv_report->addr_type;
|
||||
memcpy(adv_rpt.addr.val, ext_adv_report->addr, BLE_MESH_ADDR_LEN);
|
||||
adv_rpt.primary_phy = ext_adv_report->primary_phy;
|
||||
adv_rpt.secondary_phy = ext_adv_report->secondry_phy;
|
||||
adv_rpt.rssi = ext_adv_report->rssi;
|
||||
|
||||
if (!(ext_adv_report->event_type & BTM_BLE_ADV_LEGACY_MASK)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BT_DBG("Recv adv report type %04x", ext_adv_report->event_type);
|
||||
|
||||
switch (ext_adv_report->event_type) {
|
||||
case BLE_MESH_ADV_IND:
|
||||
case BLE_MESH_ADV_DIRECT_IND:
|
||||
case BLE_MESH_ADV_SCAN_IND:
|
||||
case BLE_MESH_ADV_NONCONN_IND:
|
||||
case BLE_MESH_ADV_SCAN_RSP:
|
||||
adv_rpt.adv_type = ext_adv_report->event_type;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (bt_mesh_scan_dev_found_cb) {
|
||||
net_buf_simple_init_with_data(&adv_rpt.adv_data, ext_adv_report->adv_data, ext_adv_report->adv_data_len);
|
||||
bt_mesh_scan_dev_found_cb(&adv_rpt);
|
||||
if (adv_rpt.adv_data.len != ext_adv_report->adv_data_len) {
|
||||
/* The advertising data has been processed by Mesh Protocol */
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void ble_mesh_5_gap_callback(tBTA_DM_BLE_5_GAP_EVENT event,
|
||||
tBTA_DM_BLE_5_GAP_CB_PARAMS *params)
|
||||
{
|
||||
BT_DBG("recv event %d", event);
|
||||
|
||||
switch (event) {
|
||||
case BTA_DM_BLE_5_GAP_EXT_ADV_SET_PARAMS_COMPLETE_EVT:
|
||||
if (!bt_mesh_is_adv_inst_used(params->set_params.instance)) {
|
||||
goto transfer_to_user;
|
||||
}
|
||||
if (params->set_params.status != BTM_SUCCESS) {
|
||||
BT_ERR("BTA_DM_BLE_5_GAP_EXT_ADV_SET_PARAMS_COMPLETE_EVT Failed");
|
||||
}
|
||||
break;
|
||||
case BTA_DM_BLE_5_GAP_EXT_ADV_DATA_SET_COMPLETE_EVT:
|
||||
if (!bt_mesh_is_adv_inst_used(params->adv_data_set.instance)) {
|
||||
goto transfer_to_user;
|
||||
}
|
||||
if (params->adv_data_set.status != BTM_SUCCESS) {
|
||||
BT_ERR("BTA_DM_BLE_5_GAP_EXT_ADV_DATA_SET_COMPLETE_EVT Failed");
|
||||
}
|
||||
break;
|
||||
case BTA_DM_BLE_5_GAP_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT:
|
||||
if (!bt_mesh_is_adv_inst_used(params->scan_rsp_data_set.instance)) {
|
||||
goto transfer_to_user;
|
||||
}
|
||||
if (params->scan_rsp_data_set.status != BTM_SUCCESS) {
|
||||
BT_ERR("BTA_DM_BLE_5_GAP_EXT_SCAN_RSP_DATA_SET_COMPLETE_EVT Failed");
|
||||
}
|
||||
break;
|
||||
case BTA_DM_BLE_5_GAP_EXT_ADV_START_COMPLETE_EVT:
|
||||
if (!bt_mesh_is_adv_inst_used(params->adv_start.instance[0])) {
|
||||
goto transfer_to_user;
|
||||
}
|
||||
if (params->adv_start.status != BTM_SUCCESS) {
|
||||
BT_ERR("BTA_DM_BLE_5_GAP_EXT_ADV_START_COMPLETE_EVT Failed");
|
||||
}
|
||||
break;
|
||||
case BTA_DM_BLE_5_GAP_EXT_ADV_STOP_COMPLETE_EVT:
|
||||
if (!bt_mesh_is_adv_inst_used(params->adv_start.instance[0])) {
|
||||
goto transfer_to_user;
|
||||
}
|
||||
if (params->adv_start.status != BTM_SUCCESS) {
|
||||
BT_ERR("BTA_DM_BLE_5_GAP_EXT_ADV_STOP_COMPLETE_EVT Failed");
|
||||
}
|
||||
break;
|
||||
case BTA_DM_BLE_5_GAP_ADV_TERMINATED_EVT:
|
||||
if (!bt_mesh_is_adv_inst_used(params->adv_term.adv_handle)) {
|
||||
goto transfer_to_user;
|
||||
}
|
||||
if (params->adv_term.status == 0x43 || /* Limit reached */
|
||||
params->adv_term.status == 0x3C) { /* Advertising timeout */
|
||||
ble_mesh_adv_task_wakeup(params->adv_term.adv_handle);
|
||||
}
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
|
||||
/**
|
||||
* This judgment is to distinguish between the termination
|
||||
* events of BLE connectable broadcasting and proxy connectable
|
||||
* adv under the same instance ID, that is, when the status is 0.
|
||||
*
|
||||
* Since the host task and adv task are currently operated in
|
||||
* series, there is no need to consider competition issues between
|
||||
* tasks.
|
||||
*
|
||||
* @attention: once multiple adv instances are used, the adv task
|
||||
* and host will be asynchronous, and it is necessary to consider
|
||||
* the issue of resource competition.
|
||||
*/
|
||||
if (bt_mesh_is_ble_adv_running() &&
|
||||
params->adv_term.status == 0x00) {
|
||||
/* The unset operation must be performed before waking up the
|
||||
* adv task; performing the unset after waking up the adv task
|
||||
* could lead to resource contention issues.
|
||||
*/
|
||||
bt_mesh_unset_ble_adv_running();
|
||||
ble_mesh_adv_task_wakeup(params->adv_term.adv_handle);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
|
||||
break;
|
||||
case BTA_DM_BLE_5_GAP_EXT_ADV_REPORT_EVT:
|
||||
if (!bt_mesh_scan_result_process(¶ms->ext_adv_report)) {
|
||||
bt_mesh_ble_ext_adv_report(¶ms->ext_adv_report);
|
||||
}
|
||||
break;
|
||||
case BTA_DM_BLE_5_GAP_EXT_SCAN_START_COMPLETE_EVT:
|
||||
if (params->scan_start.status != BTM_SUCCESS) {
|
||||
BT_ERR("BTA_DM_BLE_5_GAP_EXT_SCAN_START_COMPLETE_EVT Failed");
|
||||
}
|
||||
break;
|
||||
case BTA_DM_BLE_5_GAP_EXT_SCAN_STOP_COMPLETE_EVT:
|
||||
if (params->scan_stop.status != BTM_SUCCESS) {
|
||||
BT_ERR("BTM_BLE_5_GAP_EXT_SCAN_START_COMPLETE_EVT Failed");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
goto transfer_to_user;
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
transfer_to_user:
|
||||
btc_ble_5_gap_callback(event, params);
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool valid_adv_param(const struct bt_mesh_adv_param *param)
|
||||
{
|
||||
@@ -205,7 +408,12 @@ static bool valid_adv_param(const struct bt_mesh_adv_param *param)
|
||||
return true;
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
static int set_adv_data(uint16_t hci_op, const uint8_t inst_id,
|
||||
const struct bt_mesh_adv_data *ad, size_t ad_len)
|
||||
#else
|
||||
static int set_adv_data(uint16_t hci_op, const struct bt_mesh_adv_data *ad, size_t ad_len)
|
||||
#endif
|
||||
{
|
||||
struct bt_mesh_hci_cp_set_adv_data param = {0};
|
||||
int i;
|
||||
@@ -227,16 +435,22 @@ static int set_adv_data(uint16_t hci_op, const struct bt_mesh_adv_data *ad, size
|
||||
param.len += ad[i].data_len;
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
BTA_DmBleGapConfigExtAdvDataRaw(hci_op == BLE_MESH_HCI_OP_SET_SCAN_RSP_DATA,
|
||||
inst_id, param.len, param.data);
|
||||
#else
|
||||
/* Set adv data and scan rsp data. */
|
||||
if (hci_op == BLE_MESH_HCI_OP_SET_ADV_DATA) {
|
||||
BLE_MESH_BTM_CHECK_STATUS(BTM_BleWriteAdvDataRaw(param.data, param.len));
|
||||
} else if (hci_op == BLE_MESH_HCI_OP_SET_SCAN_RSP_DATA) {
|
||||
BLE_MESH_BTM_CHECK_STATUS(BTM_BleWriteScanRspRaw(param.data, param.len));
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if !CONFIG_BLE_MESH_USE_BLE_50
|
||||
static void start_adv_completed_cb(uint8_t status)
|
||||
{
|
||||
#if BLE_MESH_DEV
|
||||
@@ -245,6 +459,7 @@ static void start_adv_completed_cb(uint8_t status)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool valid_scan_param(const struct bt_mesh_scan_param *param)
|
||||
{
|
||||
@@ -276,15 +491,54 @@ static bool valid_scan_param(const struct bt_mesh_scan_param *param)
|
||||
static int start_le_scan(uint8_t scan_type, uint16_t interval, uint16_t window,
|
||||
uint8_t filter_dup, uint8_t scan_fil_policy)
|
||||
{
|
||||
#if !CONFIG_BLE_MESH_USE_BLE_50
|
||||
uint8_t addr_type_own = BLE_MESH_ADDR_PUBLIC; /* Currently only support Public Address */
|
||||
tGATT_IF client_if = 0xFF; /* Default GATT interface id */
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
tBTA_DM_BLE_EXT_SCAN_PARAMS ext_scan_params = {0};
|
||||
|
||||
if (interval == 0 ||
|
||||
interval < window) {
|
||||
BT_ERR("invalid scan param itvl %d win %d", interval, window);
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
ext_scan_params.own_addr_type = BLE_MESH_ADDR_PUBLIC;
|
||||
ext_scan_params.filter_policy = scan_fil_policy;
|
||||
ext_scan_params.scan_duplicate = filter_dup;
|
||||
|
||||
if (window == 0) {
|
||||
ext_scan_params.cfg_mask = BTM_BLE_GAP_EXT_SCAN_CODE_MASK;
|
||||
} else if (interval > window) {
|
||||
ext_scan_params.cfg_mask = BTM_BLE_GAP_EXT_SCAN_UNCODE_MASK | BTM_BLE_GAP_EXT_SCAN_CODE_MASK;
|
||||
} else {
|
||||
// interval == window
|
||||
ext_scan_params.cfg_mask = BTM_BLE_GAP_EXT_SCAN_UNCODE_MASK;
|
||||
}
|
||||
|
||||
ext_scan_params.uncoded_cfg.scan_type = scan_type;
|
||||
ext_scan_params.uncoded_cfg.scan_interval = interval;
|
||||
ext_scan_params.uncoded_cfg.scan_window = window;
|
||||
|
||||
ext_scan_params.coded_cfg.scan_type = scan_type;
|
||||
ext_scan_params.coded_cfg.scan_interval = interval;
|
||||
ext_scan_params.coded_cfg.scan_window = interval - window;
|
||||
|
||||
BTA_DmBleGapSetExtScanParams(&ext_scan_params);
|
||||
|
||||
BTM_BleGapRegisterCallback(ble_mesh_5_gap_callback);
|
||||
|
||||
BTA_DmBleGapExtScan(true, 0, 0);
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
BLE_MESH_BTM_CHECK_STATUS(
|
||||
BTM_BleSetScanFilterParams(client_if, interval, window, scan_type, addr_type_own,
|
||||
filter_dup, scan_fil_policy, NULL));
|
||||
|
||||
/* BLE Mesh scan permanently, so no duration of scan here */
|
||||
BLE_MESH_BTM_CHECK_STATUS(BTM_BleScan(true, 0, bt_mesh_scan_results_cb, NULL, NULL));
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
|
||||
#if BLE_MESH_DEV
|
||||
if (scan_type == BLE_MESH_SCAN_ACTIVE) {
|
||||
@@ -297,22 +551,32 @@ static int start_le_scan(uint8_t scan_type, uint16_t interval, uint16_t window,
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if !CONFIG_BLE_MESH_USE_BLE_50
|
||||
static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data)
|
||||
{
|
||||
struct net_buf_simple buf = {0};
|
||||
bt_mesh_addr_t addr = {0};
|
||||
struct bt_mesh_adv_report adv_rpt = {0};
|
||||
|
||||
BT_DBG("%s, event %d", __func__, event);
|
||||
|
||||
if (event == BTA_DM_INQ_RES_EVT) {
|
||||
/* TODO: How to process scan response here? PS: p_data->inq_res.scan_rsp_len */
|
||||
addr.type = p_data->inq_res.ble_addr_type;
|
||||
memcpy(addr.val, p_data->inq_res.bd_addr, BLE_MESH_ADDR_LEN);
|
||||
|
||||
net_buf_simple_init_with_data(&buf, p_data->inq_res.p_eir, p_data->inq_res.adv_data_len);
|
||||
adv_rpt.addr.type = p_data->inq_res.ble_addr_type;
|
||||
adv_rpt.rssi = p_data->inq_res.rssi;
|
||||
adv_rpt.adv_type = p_data->inq_res.ble_evt_type;
|
||||
|
||||
memcpy(adv_rpt.addr.val, p_data->inq_res.bd_addr, BLE_MESH_ADDR_LEN);
|
||||
|
||||
net_buf_simple_init_with_data(&adv_rpt.adv_data, p_data->inq_res.p_eir, p_data->inq_res.adv_data_len);
|
||||
|
||||
if (bt_mesh_scan_dev_found_cb) {
|
||||
bt_mesh_scan_dev_found_cb(&addr, p_data->inq_res.rssi, p_data->inq_res.ble_evt_type, &buf, p_data->inq_res.scan_rsp_len);
|
||||
bt_mesh_scan_dev_found_cb(&adv_rpt);
|
||||
|
||||
if (p_data->inq_res.scan_rsp_len) {
|
||||
adv_rpt.adv_type = BLE_MESH_ADV_SCAN_RSP;
|
||||
net_buf_simple_init_with_data(&adv_rpt.adv_data, p_data->inq_res.p_eir + p_data->inq_res.adv_data_len, p_data->inq_res.scan_rsp_len);
|
||||
bt_mesh_scan_dev_found_cb(&adv_rpt);
|
||||
}
|
||||
}
|
||||
} else if (event == BTA_DM_INQ_CMPL_EVT) {
|
||||
BT_INFO("Scan completed, number of scan response %d", p_data->inq_cmpl.num_resps);
|
||||
@@ -320,7 +584,132 @@ static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARC
|
||||
BT_WARN("Unexpected scan result event %d", event);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
int bt_le_ext_adv_start(const uint8_t inst_id,
|
||||
const struct bt_mesh_adv_param *param,
|
||||
const struct bt_mesh_adv_data *ad, size_t ad_len,
|
||||
const struct bt_mesh_adv_data *sd, size_t sd_len)
|
||||
{
|
||||
tBTA_DM_BLE_GAP_EXT_ADV_PARAMS ext_adv_params = {0};
|
||||
tBTA_DM_BLE_EXT_ADV ext_adv = {0};
|
||||
uint16_t interval = 0U;
|
||||
int err = 0;
|
||||
|
||||
assert(param);
|
||||
|
||||
#if BLE_MESH_DEV
|
||||
if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING)) {
|
||||
return -EALREADY;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!valid_adv_param(param)) {
|
||||
BT_ERR("Invalid adv parameters");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
memset(&ext_adv_params, 0, sizeof(tBTA_DM_BLE_GAP_EXT_ADV_PARAMS));
|
||||
|
||||
if (param->options & BLE_MESH_ADV_OPT_CONNECTABLE) {
|
||||
ext_adv_params.type = BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_IND;
|
||||
} else if (sd != NULL) {
|
||||
ext_adv_params.type = BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_SCAN;
|
||||
} else {
|
||||
if (param->primary_phy == BLE_MESH_ADV_PHY_1M &&
|
||||
param->secondary_phy == BLE_MESH_ADV_PHY_1M) {
|
||||
ext_adv_params.type = BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_NONCONN;
|
||||
} else {
|
||||
BT_ERR("Unsupported PHY: pri %d sec %d",param->primary_phy, param->secondary_phy);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_PRB_SRV
|
||||
/* NOTE: When a Mesh Private beacon is advertised, the Mesh Private beacon shall
|
||||
* use a resolvable private address or a non-resolvable private address in the
|
||||
* AdvA field of the advertising PDU.
|
||||
*/
|
||||
if (ad->type == BLE_MESH_DATA_MESH_BEACON && ad->data[0] == BEACON_TYPE_PRIVATE) {
|
||||
ext_adv_params.own_addr_type = BLE_MESH_ADDR_RANDOM;
|
||||
} else {
|
||||
ext_adv_params.own_addr_type = BLE_MESH_ADDR_PUBLIC;
|
||||
}
|
||||
#else
|
||||
ext_adv_params.own_addr_type = BLE_MESH_ADDR_PUBLIC;
|
||||
#endif
|
||||
|
||||
ext_adv_params.sid = inst_id;
|
||||
ext_adv_params.max_skip = 0;
|
||||
ext_adv_params.tx_power = 0x7F;
|
||||
ext_adv_params.scan_req_notif = false;
|
||||
ext_adv_params.primary_phy = param->primary_phy;
|
||||
ext_adv_params.secondary_phy = param->secondary_phy;
|
||||
ext_adv_params.filter_policy = BLE_MESH_AP_SCAN_CONN_ALL;
|
||||
ext_adv_params.channel_map = BLE_MESH_ADV_CHNL_37 | BLE_MESH_ADV_CHNL_38 | BLE_MESH_ADV_CHNL_39;
|
||||
|
||||
interval = param->interval_min;
|
||||
|
||||
#if CONFIG_BLE_MESH_RANDOM_ADV_INTERVAL
|
||||
/* If non-connectable mesh packets are transmitted with an adv interval
|
||||
* not smaller than 10ms, then we will use a random adv interval between
|
||||
* [interval / 2, interval] for them.
|
||||
*/
|
||||
if (adv_type == BLE_MESH_ADV_NONCONN_IND && interval >= 16) {
|
||||
interval >>= 1;
|
||||
interval += (bt_mesh_get_rand() % (interval + 1));
|
||||
|
||||
BT_INFO("%u->%u", param->interval_min, interval);
|
||||
}
|
||||
#endif
|
||||
|
||||
ext_adv_params.interval_min = interval;
|
||||
ext_adv_params.interval_max = interval;
|
||||
|
||||
/* Check if we can start adv using BTM_BleSetAdvParamsStartAdvCheck */
|
||||
BTA_DmBleGapExtAdvSetParams(inst_id, &ext_adv_params);
|
||||
|
||||
err = set_adv_data(BLE_MESH_HCI_OP_SET_ADV_DATA, inst_id, ad, ad_len);
|
||||
if (err) {
|
||||
BT_ERR("Failed to set adv data, err %d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
/*
|
||||
* We need to set SCAN_RSP when enabling advertising type that allows
|
||||
* for Scan Requests.
|
||||
*
|
||||
* If sd was not provided but we enable connectable undirected
|
||||
* advertising sd needs to be cleared from values set by previous calls.
|
||||
* Clearing sd is done by calling set_adv_data() with NULL data and zero len.
|
||||
* So following condition check is unusual but correct.
|
||||
*/
|
||||
if (sd && (param->options & BLE_MESH_ADV_OPT_CONNECTABLE)) {
|
||||
err = set_adv_data(BLE_MESH_HCI_OP_SET_SCAN_RSP_DATA, inst_id, sd, sd_len);
|
||||
if (err) {
|
||||
BT_ERR("Failed to set scan rsp data err %d", err);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
ext_adv.instance = inst_id;
|
||||
ext_adv.duration = param->adv_duration / 10;
|
||||
ext_adv.max_events = param->adv_count;
|
||||
|
||||
BTA_DmBleGapExtAdvEnable(true, 1, &ext_adv);
|
||||
|
||||
#if BLE_MESH_DEV
|
||||
bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING);
|
||||
|
||||
if (!(param->options & BLE_MESH_ADV_OPT_ONE_TIME)) {
|
||||
bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_KEEP_ADVERTISING);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
/* APIs functions */
|
||||
int bt_le_adv_start(const struct bt_mesh_adv_param *param,
|
||||
const struct bt_mesh_adv_data *ad, size_t ad_len,
|
||||
@@ -348,7 +737,7 @@ int bt_le_adv_start(const struct bt_mesh_adv_param *param,
|
||||
|
||||
err = set_adv_data(BLE_MESH_HCI_OP_SET_ADV_DATA, ad, ad_len);
|
||||
if (err) {
|
||||
BT_ERR("Failed to set adv data");
|
||||
BT_ERR("Failed to set adv data, err %d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -364,7 +753,7 @@ int bt_le_adv_start(const struct bt_mesh_adv_param *param,
|
||||
if (sd && (param->options & BLE_MESH_ADV_OPT_CONNECTABLE)) {
|
||||
err = set_adv_data(BLE_MESH_HCI_OP_SET_SCAN_RSP_DATA, sd, sd_len);
|
||||
if (err) {
|
||||
BT_ERR("Failed to set scan rsp data");
|
||||
BT_ERR("Failed to set scan rsp data, err %d", err);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
@@ -427,8 +816,97 @@ int bt_le_adv_start(const struct bt_mesh_adv_param *param,
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
|
||||
static bool _ble_adv_running_flag;
|
||||
|
||||
static inline void bt_mesh_set_ble_adv_running()
|
||||
{
|
||||
_ble_adv_running_flag = true;
|
||||
}
|
||||
|
||||
static inline void bt_mesh_unset_ble_adv_running()
|
||||
{
|
||||
_ble_adv_running_flag = false;
|
||||
}
|
||||
|
||||
static inline bool bt_mesh_is_ble_adv_running()
|
||||
{
|
||||
return _ble_adv_running_flag == true;
|
||||
}
|
||||
|
||||
int bt_mesh_ble_ext_adv_start(const uint8_t inst_id,
|
||||
const struct bt_mesh_ble_adv_param *param,
|
||||
const struct bt_mesh_ble_adv_data *data)
|
||||
{
|
||||
tBTA_DM_BLE_GAP_EXT_ADV_PARAMS ext_adv_params = {0};
|
||||
tBTA_DM_BLE_EXT_ADV ext_adv = {0};
|
||||
struct bt_mesh_hci_cp_set_adv_data set = {0};
|
||||
|
||||
if (data && param->adv_type != BLE_MESH_ADV_DIRECT_IND &&
|
||||
param->adv_type != BLE_MESH_ADV_DIRECT_IND_LOW_DUTY) {
|
||||
if (data->adv_data_len) {
|
||||
set.len = data->adv_data_len;
|
||||
memcpy(set.data, data->adv_data, data->adv_data_len);
|
||||
BTA_DmBleGapConfigExtAdvDataRaw(false, inst_id, set.len, set.data);
|
||||
}
|
||||
if (data->scan_rsp_data_len && param->adv_type != BLE_MESH_ADV_NONCONN_IND) {
|
||||
set.len = data->scan_rsp_data_len;
|
||||
memcpy(set.data, data->scan_rsp_data, data->scan_rsp_data_len);
|
||||
BTA_DmBleGapConfigExtAdvDataRaw(true, inst_id, set.len, set.data);
|
||||
}
|
||||
}
|
||||
|
||||
switch (param->adv_type) {
|
||||
case BLE_MESH_ADV_IND:
|
||||
case BLE_MESH_ADV_DIRECT_IND:
|
||||
case BLE_MESH_ADV_SCAN_IND:
|
||||
case BLE_MESH_ADV_NONCONN_IND:
|
||||
case BLE_MESH_ADV_SCAN_RSP:
|
||||
ext_adv_params.type = param->adv_type;
|
||||
break;
|
||||
default:
|
||||
BT_ERR("Unsupported adv type %d", param->adv_type);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ext_adv_params.max_skip = 0;
|
||||
ext_adv_params.tx_power = 0x7F;
|
||||
ext_adv_params.sid = inst_id;
|
||||
ext_adv_params.scan_req_notif = false;
|
||||
ext_adv_params.own_addr_type = param->own_addr_type;
|
||||
ext_adv_params.interval_min = param->interval;
|
||||
ext_adv_params.interval_max = param->interval;
|
||||
ext_adv_params.primary_phy = BLE_MESH_ADV_PHY_1M;
|
||||
ext_adv_params.secondary_phy = BLE_MESH_ADV_PHY_1M;
|
||||
ext_adv_params.filter_policy = BLE_MESH_AP_SCAN_CONN_ALL;
|
||||
ext_adv_params.channel_map = BLE_MESH_ADV_CHNL_37 | BLE_MESH_ADV_CHNL_38 | BLE_MESH_ADV_CHNL_39;
|
||||
|
||||
if (param->own_addr_type == BLE_MESH_ADDR_PUBLIC_ID ||
|
||||
param->own_addr_type == BLE_MESH_ADDR_RANDOM_ID ||
|
||||
param->adv_type == BLE_MESH_ADV_DIRECT_IND ||
|
||||
param->adv_type == BLE_MESH_ADV_DIRECT_IND_LOW_DUTY) {
|
||||
ext_adv_params.peer_addr_type = param->peer_addr_type;
|
||||
memcpy(ext_adv_params.peer_addr, param->peer_addr, BLE_MESH_ADDR_LEN);
|
||||
}
|
||||
|
||||
ext_adv.instance = inst_id;
|
||||
ext_adv.duration = param->duration;
|
||||
ext_adv.max_events = param->count;
|
||||
|
||||
/* Check if we can start adv using BTM_BleSetAdvParamsStartAdvCheck */
|
||||
BTA_DmBleGapExtAdvSetParams(inst_id, &ext_adv_params);
|
||||
|
||||
BTA_DmBleGapExtAdvEnable(true, 1, &ext_adv);
|
||||
|
||||
bt_mesh_set_ble_adv_running();
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
int bt_mesh_ble_adv_start(const struct bt_mesh_ble_adv_param *param,
|
||||
const struct bt_mesh_ble_adv_data *data)
|
||||
{
|
||||
@@ -470,8 +948,32 @@ int bt_mesh_ble_adv_start(const struct bt_mesh_ble_adv_param *param,
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
int bt_le_ext_adv_stop(uint8_t inst_id)
|
||||
{
|
||||
tBTA_DM_BLE_EXT_ADV ext_adv = {0};
|
||||
|
||||
#if BLE_MESH_DEV
|
||||
bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_KEEP_ADVERTISING);
|
||||
if (!bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING)) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
ext_adv.instance = inst_id;
|
||||
|
||||
BTA_DmBleGapExtAdvEnable(false, 1, &ext_adv);
|
||||
|
||||
#if BLE_MESH_DEV
|
||||
bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
int bt_le_adv_stop(void)
|
||||
{
|
||||
#if BLE_MESH_DEV
|
||||
@@ -489,6 +991,7 @@ int bt_le_adv_stop(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
|
||||
int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t cb)
|
||||
{
|
||||
@@ -530,7 +1033,11 @@ int bt_le_scan_stop(void)
|
||||
return -EALREADY;
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
BTA_DmBleGapExtScan(false, 0 ,0);
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
BLE_MESH_BTM_CHECK_STATUS(BTM_BleScan(false, 0, NULL, NULL, NULL));
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
|
||||
bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING);
|
||||
bt_mesh_scan_dev_found_cb = NULL;
|
||||
@@ -657,6 +1164,19 @@ static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
|
||||
/* When connection is created, advertising will be stopped automatically. */
|
||||
bt_mesh_atomic_test_and_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING);
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \
|
||||
(CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT)
|
||||
/* Check if this connection is created by Proxy client */
|
||||
for (size_t i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
if (!memcmp(bt_mesh_gattc_info[i].addr.val, p_data->conn.remote_bda, BLE_MESH_ADDR_LEN)) {
|
||||
BT_WARN("Already create connection with %s by proxy client",
|
||||
bt_hex(p_data->conn.remote_bda, BLE_MESH_ADDR_LEN));
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (bt_mesh_gatts_conn_cb != NULL && bt_mesh_gatts_conn_cb->connected != NULL) {
|
||||
uint8_t index = BLE_MESH_GATT_GET_CONN_ID(p_data->conn.conn_id);
|
||||
if (index < BLE_MESH_MAX_CONN) {
|
||||
@@ -1198,6 +1718,9 @@ uint16_t bt_mesh_gattc_get_service_uuid(struct bt_mesh_conn *conn)
|
||||
|
||||
int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, uint16_t service_uuid)
|
||||
{
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
tBTA_DM_BLE_CONN_PARAMS conn_1m_param = {0};
|
||||
#endif
|
||||
uint8_t zero[6] = {0};
|
||||
int i;
|
||||
|
||||
@@ -1240,21 +1763,47 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, uint16_t service_uuid)
|
||||
}
|
||||
|
||||
if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) {
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
BTA_DmBleGapExtScan(false, 0 ,0);
|
||||
#else
|
||||
BLE_MESH_BTM_CHECK_STATUS(BTM_BleScan(false, 0, NULL, NULL, NULL));
|
||||
#endif
|
||||
bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING);
|
||||
}
|
||||
|
||||
BT_DBG("Create conn with %s", bt_hex(addr->val, BLE_MESH_ADDR_LEN));
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
/* Min_interval: 15ms 0x18, 0x18, 0x00, 0x64
|
||||
* Max_interval: 15ms
|
||||
* Slave_latency: 0x0
|
||||
* Supervision_timeout: 1s
|
||||
*/
|
||||
conn_1m_param.scan_interval = 0x0020;
|
||||
conn_1m_param.scan_window = 0x0020;
|
||||
conn_1m_param.interval_min = 0x18;
|
||||
conn_1m_param.interval_max = 0x18;
|
||||
conn_1m_param.latency = 0;
|
||||
conn_1m_param.supervision_timeout = 0x64;
|
||||
conn_1m_param.min_ce_len = 0;
|
||||
conn_1m_param.max_ce_len = 0;
|
||||
|
||||
BTA_DmBleGapPreferExtConnectParamsSet(bt_mesh_gattc_info[i].addr.val, 0x01, &conn_1m_param ,NULL, NULL);
|
||||
|
||||
BTA_GATTC_Enh_Open(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr.val,
|
||||
bt_mesh_gattc_info[i].addr.type, true, BTA_GATT_TRANSPORT_LE, TRUE, BLE_ADDR_UNKNOWN_TYPE);
|
||||
#else
|
||||
/* Min_interval: 15ms
|
||||
* Max_interval: 15ms
|
||||
* Slave_latency: 0x0
|
||||
* Supervision_timeout: 1s
|
||||
*/
|
||||
|
||||
BTA_DmSetBlePrefConnParams(bt_mesh_gattc_info[i].addr.val, 0x18, 0x18, 0x00, 0x64);
|
||||
|
||||
BTA_GATTC_Open(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr.val,
|
||||
bt_mesh_gattc_info[i].addr.type, true, BTA_GATT_TRANSPORT_LE, FALSE);
|
||||
BTA_GATTC_Enh_Open(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr.val,
|
||||
bt_mesh_gattc_info[i].addr.type, true, BTA_GATT_TRANSPORT_LE, FALSE, BLE_ADDR_UNKNOWN_TYPE);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1655,11 +2204,15 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
* use BTM_BleScan() to re-enable scan.
|
||||
*/
|
||||
if (!bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) {
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
BTA_DmBleGapExtScan(true, 0 ,0);
|
||||
#else
|
||||
tBTM_STATUS status = BTM_BleScan(true, 0, bt_mesh_scan_results_cb, NULL, NULL);
|
||||
if (status != BTM_SUCCESS && status != BTM_CMD_STARTED) {
|
||||
BT_ERR("Invalid scan status %d", status);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017 Intel Corporation
|
||||
* SPDX-FileContributor: 2018-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017 Nordic Semiconductor ASA
|
||||
* SPDX-FileCopyrightText: 2015-2017 Intel Corporation
|
||||
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -21,18 +21,78 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/* BLE Mesh Max Connection Count */
|
||||
/**
|
||||
* The maximum number of connection count is limited by
|
||||
* the resources allocated by both the host and the controller
|
||||
* components, so the actual number of available connections
|
||||
* is the minimum of the resources from both.
|
||||
*
|
||||
* On the C3/S3 platform, the controller uses the macro `CONFIG_BT_CTRL_BLE_MAX_ACT`,
|
||||
* but adv and scan also occupy this resource, so the actual number of available
|
||||
* connections is (CONFIG_BT_CTRL_BLE_MAX_ACT - adv instance count - scan).
|
||||
* However, the macro allocation on the host is entirely for connections,
|
||||
* so on the C3/S3 platform, the maximum number of connectable devices should
|
||||
* be determined by the configuration at the host minus the number of
|
||||
* advertising instances and scan from the controller's configuration.
|
||||
*/
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#define BLE_MESH_MAX_CONN 1
|
||||
#elif (CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3)
|
||||
/* @todo: must ensure CONFIG_BT_CTRL_BLE_MAX_ACT is greater than 2 */
|
||||
#if CONFIG_BT_ACL_CONNECTIONS > (CONFIG_BT_CTRL_BLE_MAX_ACT - 2)
|
||||
/* decrease the adv,scan */
|
||||
#define BLE_MESH_MAX_CONN (CONFIG_BT_CTRL_BLE_MAX_ACT - 2)
|
||||
#else
|
||||
#define BLE_MESH_MAX_CONN CONFIG_BT_ACL_CONNECTIONS
|
||||
#endif /* CONFIG_BT_ACL_CONNECTIONS > (CONFIG_BT_CTRL_BLE_MAX_ACT - 2) */
|
||||
#elif CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C5
|
||||
#if CONFIG_BT_ACL_CONNECTIONS > CONFIG_BT_LE_MAX_CONNECTIONS
|
||||
#define BLE_MESH_MAX_CONN CONFIG_BT_LE_MAX_CONNECTIONS
|
||||
#else
|
||||
#define BLE_MESH_MAX_CONN CONFIG_BT_ACL_CONNECTIONS
|
||||
#endif /* CONFIG_BT_ACL_CONNECTIONS > CONFIG_BT_LE_MAX_CONNECTIONS */
|
||||
#else
|
||||
/* default setting */
|
||||
#define BLE_MESH_MAX_CONN 1
|
||||
#endif
|
||||
#endif /* CONFIG_BT_BLUEDROID_ENABLED */
|
||||
|
||||
#ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#define BLE_MESH_MAX_CONN 1
|
||||
#elif (CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32S3)
|
||||
/* @todo: must ensure CONFIG_BT_CTRL_BLE_MAX_ACT is greater than 2 */
|
||||
#if CONFIG_BT_NIMBLE_MAX_CONNECTIONS > (CONFIG_BT_CTRL_BLE_MAX_ACT - 2)
|
||||
/* decrease the adv,scan */
|
||||
#define BLE_MESH_MAX_CONN (CONFIG_BT_CTRL_BLE_MAX_ACT - 2)
|
||||
#else
|
||||
#define BLE_MESH_MAX_CONN CONFIG_BT_NIMBLE_MAX_CONNECTIONS
|
||||
#endif /* CONFIG_BT_NIMBLE_MAX_CONNECTIONS > (CONFIG_BT_CTRL_BLE_MAX_ACT - 2) */
|
||||
#elif CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C5
|
||||
#define BLE_MESH_MAX_CONN CONFIG_BT_NIMBLE_MAX_CONNECTIONS
|
||||
#else
|
||||
/* default setting */
|
||||
#define BLE_MESH_MAX_CONN 1
|
||||
#endif
|
||||
#endif /* CONFIG_BT_NIMBLE_ENABLED */
|
||||
|
||||
#define BLE_MESH_GAP_ADV_MAX_LEN 31
|
||||
|
||||
#define BLE_MESH_GATT_DEF_MTU_SIZE 23
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
#define BLE_MESH_ADV_PHY_UNASSIGNED 0
|
||||
#define BLE_MESH_ADV_PHY_1M 1
|
||||
#define BLE_MESH_ADV_PHY_2M 2
|
||||
#define BLE_MESH_ADV_PHY_CODED 3
|
||||
#define BLE_MESH_ADV_PHY_OPTION_NO_PREFER 0
|
||||
#define BLE_MESH_ADV_PHY_OPTION_PREFER_S2 1
|
||||
#define BLE_MESH_ADV_PHY_OPTION_PREFER_S8 2
|
||||
#define BLE_MESH_ADV_PHY_OPTION_REQUIRE_S2 3
|
||||
#define BLE_MESH_ADV_PHY_OPTION_REQUIRE_S8 4
|
||||
#endif
|
||||
|
||||
/* BD ADDR types */
|
||||
#define BLE_MESH_ADDR_PUBLIC 0x00
|
||||
#define BLE_MESH_ADDR_RANDOM 0x01
|
||||
@@ -43,11 +103,22 @@ extern "C" {
|
||||
#define BLE_MESH_ADDR_LEN 0x06
|
||||
|
||||
/* Advertising types */
|
||||
#if !CONFIG_BLE_MESH_USE_BLE_50
|
||||
#define BLE_MESH_ADV_IND 0x00
|
||||
#define BLE_MESH_ADV_DIRECT_IND 0x01
|
||||
#define BLE_MESH_ADV_SCAN_IND 0x02
|
||||
#define BLE_MESH_ADV_NONCONN_IND 0x03
|
||||
#define BLE_MESH_ADV_DIRECT_IND_LOW_DUTY 0x04
|
||||
#define BLE_MESH_ADV_SCAN_RSP 0x04
|
||||
#else
|
||||
/* Bluetooth Core Spec 6.0, Vol 4, Part E, 7.7.65.13 */
|
||||
#define BLE_MESH_ADV_IND (0x13)
|
||||
#define BLE_MESH_ADV_DIRECT_IND (0x15)
|
||||
#define BLE_MESH_ADV_SCAN_IND (0x12)
|
||||
#define BLE_MESH_ADV_NONCONN_IND (0x10)
|
||||
#define BLE_MESH_ADV_DIRECT_IND_LOW_DUTY (0x1b)
|
||||
#define BLE_MESH_ADV_SCAN_RSP (0x1b)
|
||||
#endif
|
||||
|
||||
/* advertising channel map */
|
||||
#define BLE_MESH_ADV_CHNL_37 BIT(0)
|
||||
@@ -400,8 +471,32 @@ struct bt_mesh_adv_param {
|
||||
|
||||
/** Maximum Advertising Interval (N * 0.625) */
|
||||
uint16_t interval_max;
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
/** Maximum Advertising Duration (N * 0.625) */
|
||||
uint16_t adv_duration;
|
||||
|
||||
/** Advertising Packages Number */
|
||||
uint16_t adv_count;
|
||||
|
||||
/** Advertising Primary PHY */
|
||||
uint8_t primary_phy;
|
||||
|
||||
/** Advertising Secondary PHY */
|
||||
uint8_t secondary_phy;
|
||||
#endif
|
||||
};
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
enum bt_mesh_adv_inst_type {
|
||||
BLE_MESH_ADV_PROXY_INS,
|
||||
BLE_MESH_ADV_INS,
|
||||
BLE_MESH_EXT_ADV_INS,
|
||||
BLE_MESH_BLE_ADV_INS,
|
||||
BLE_MESH_ADV_INS_TYPE_NUMS,
|
||||
};
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
|
||||
enum bt_mesh_ble_adv_priority {
|
||||
BLE_MESH_BLE_ADV_PRIO_LOW,
|
||||
@@ -441,7 +536,7 @@ struct bt_mesh_scan_param {
|
||||
/** Scan interval (N * 0.625 ms) */
|
||||
uint16_t interval;
|
||||
|
||||
/** Scan window (N * 0.625 ms) */
|
||||
/** Uncoded phy Scan window (N * 0.625 ms) */
|
||||
uint16_t window;
|
||||
|
||||
/** BLE scan filter policy */
|
||||
@@ -453,21 +548,38 @@ struct bt_mesh_conn {
|
||||
bt_mesh_atomic_t ref;
|
||||
};
|
||||
|
||||
/* BLE Mesh advertising report */
|
||||
struct bt_mesh_adv_report {
|
||||
/* Advertiser LE address and type. */
|
||||
bt_mesh_addr_t addr;
|
||||
|
||||
/* Strength of advertiser signal. */
|
||||
int8_t rssi;
|
||||
|
||||
/* Type of advertising response from advertiser. */
|
||||
uint8_t adv_type;
|
||||
|
||||
/* Buffer containing advertiser data. */
|
||||
struct net_buf_simple adv_data;
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
/* Primary advertising PHY */
|
||||
uint8_t primary_phy;
|
||||
|
||||
/* Secondary advertising PHY */
|
||||
uint8_t secondary_phy;
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
};
|
||||
|
||||
/** @typedef bt_mesh_scan_cb_t
|
||||
* @brief Callback type for reporting LE scan results.
|
||||
*
|
||||
* A function of this type is given to the bt_le_scan_start() function
|
||||
* and will be called for any discovered LE device.
|
||||
*
|
||||
* @param addr Advertiser LE address and type.
|
||||
* @param rssi Strength of advertiser signal.
|
||||
* @param adv_type Type of advertising response from advertiser.
|
||||
* @param data Buffer containing advertiser data.
|
||||
* @param scan_rsp_len Scan Response data length.
|
||||
* @param adv_rpt: BLE Mesh advertising report.
|
||||
*/
|
||||
typedef void bt_mesh_scan_cb_t(const bt_mesh_addr_t *addr, int8_t rssi,
|
||||
uint8_t adv_type, struct net_buf_simple *buf,
|
||||
uint8_t scan_rsp_len);
|
||||
typedef void bt_mesh_scan_cb_t(struct bt_mesh_adv_report *adv_rpt);
|
||||
|
||||
/* @typedef bt_mesh_dh_key_cb_t
|
||||
* @brief Callback type for DH Key calculation.
|
||||
@@ -553,7 +665,7 @@ struct bt_mesh_gatt_attr {
|
||||
* @param len Length of data to read
|
||||
* @param offset Offset to start reading from
|
||||
*
|
||||
* @return Number fo bytes read, or in case of an error
|
||||
* @return Number of bytes read, or in case of an error
|
||||
* BLE_MESH_GATT_ERR() with a specific ATT error code.
|
||||
*/
|
||||
ssize_t (*read)(struct bt_mesh_conn *conn,
|
||||
@@ -684,6 +796,21 @@ struct bt_mesh_gatt_attr {
|
||||
int bt_mesh_host_init(void);
|
||||
int bt_mesh_host_deinit(void);
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
int bt_le_ext_adv_start(const uint8_t inst_id,
|
||||
const struct bt_mesh_adv_param *param,
|
||||
const struct bt_mesh_adv_data *ad, size_t ad_len,
|
||||
const struct bt_mesh_adv_data *sd, size_t sd_len);
|
||||
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
|
||||
int bt_mesh_ble_ext_adv_start(const uint8_t inst_id,
|
||||
const struct bt_mesh_ble_adv_param *param,
|
||||
const struct bt_mesh_ble_adv_data *adv_data);
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
|
||||
|
||||
int bt_le_ext_adv_stop(uint8_t inst_id);
|
||||
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
int bt_le_adv_start(const struct bt_mesh_adv_param *param,
|
||||
const struct bt_mesh_adv_data *ad, size_t ad_len,
|
||||
const struct bt_mesh_adv_data *sd, size_t sd_len);
|
||||
@@ -691,9 +818,10 @@ int bt_le_adv_start(const struct bt_mesh_adv_param *param,
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
|
||||
int bt_mesh_ble_adv_start(const struct bt_mesh_ble_adv_param *param,
|
||||
const struct bt_mesh_ble_adv_data *data);
|
||||
#endif
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
|
||||
|
||||
int bt_le_adv_stop(void);
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
|
||||
int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t cb);
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "crypto.h"
|
||||
#include "adv.h"
|
||||
#include "net.h"
|
||||
#include "scan.h"
|
||||
#include "mesh.h"
|
||||
#include "lpn.h"
|
||||
@@ -836,6 +837,9 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
|
||||
uint16_t dst = 0U;
|
||||
int err = 0;
|
||||
|
||||
/* The variable is not used when proxy server or proxy client is disabled. */
|
||||
ARG_UNUSED(dst);
|
||||
|
||||
BT_DBG("net_idx 0x%04x new_key %u len %u", sub->net_idx, new_key,
|
||||
buf->len);
|
||||
|
||||
@@ -913,18 +917,22 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
|
||||
return err;
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&
|
||||
bt_mesh_proxy_server_relay(&buf->b, dst) &&
|
||||
BLE_MESH_ADDR_IS_UNICAST(dst)) {
|
||||
/**
|
||||
* TODO: Find a way to determine how the message was sent previously
|
||||
* during a retransmission, to avoid ineffective advertising.
|
||||
*/
|
||||
#if CONFIG_BLE_MESH_GATT_PROXY_SERVER
|
||||
if (bt_mesh_proxy_server_relay(&buf->b, dst) &&
|
||||
BLE_MESH_ADDR_IS_UNICAST(dst) &&
|
||||
bt_mesh_proxy_server_find_client_by_addr(dst)) {
|
||||
send_cb_finalize(cb, cb_data);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT) &&
|
||||
bt_mesh_proxy_client_relay(&buf->b, dst)) {
|
||||
send_cb_finalize(cb, cb_data);
|
||||
return 0;
|
||||
}
|
||||
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
bt_mesh_proxy_client_relay(&buf->b, dst);
|
||||
#endif
|
||||
|
||||
bt_mesh_adv_send(buf, BLE_MESH_ADV(buf)->xmit, cb, cb_data);
|
||||
return 0;
|
||||
@@ -1051,6 +1059,7 @@ static void bt_mesh_net_adv_xmit_update(struct bt_mesh_net_tx *tx)
|
||||
int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data)
|
||||
{
|
||||
const struct bt_mesh_send_cb *send_cb = cb;
|
||||
uint8_t bearer = BLE_MESH_ALL_BEARERS;
|
||||
int err = 0;
|
||||
|
||||
@@ -1115,31 +1124,48 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
|
||||
* shall drop all messages secured using the friendship security
|
||||
* credentials."
|
||||
*/
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&
|
||||
(bearer & BLE_MESH_GATT_BEARER) &&
|
||||
(tx->ctx->send_ttl != 1U ||
|
||||
bt_mesh_tag_relay(tx->ctx->send_tag)) &&
|
||||
#if CONFIG_BLE_MESH_GATT_PROXY_SERVER
|
||||
if ((bearer & BLE_MESH_GATT_BEARER) &&
|
||||
(tx->ctx->send_ttl != 1U || bt_mesh_tag_relay(tx->ctx->send_tag)) &&
|
||||
tx->ctx->send_cred != BLE_MESH_FRIENDSHIP_CRED) {
|
||||
if (bt_mesh_proxy_server_relay(&buf->b, tx->ctx->addr) &&
|
||||
BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
|
||||
/* Notify completion if this only went
|
||||
* through the Mesh Proxy.
|
||||
/* When the destination address is identified as a proxy client
|
||||
* address, the message will be sent only to the proxy client.
|
||||
* This action will enhance the efficiency of the proxy server
|
||||
* in sending data packets.
|
||||
*
|
||||
* It should be noted that this approach does not significantly
|
||||
* reduce the number of advertising packets in the air, as other
|
||||
* proxy clients may receive the message and resend it through
|
||||
* a advertising method.
|
||||
*/
|
||||
if ((bearer & (~BLE_MESH_GATT_BEARER)) == 0) {
|
||||
send_cb_finalize(cb, cb_data);
|
||||
if (bt_mesh_proxy_server_find_client_by_addr(tx->ctx->addr)) {
|
||||
send_cb_finalize(send_cb, cb_data);
|
||||
send_cb = NULL;
|
||||
|
||||
err = 0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Finalize transmission if this only went through GATT bearer */
|
||||
if ((bearer & (~BLE_MESH_GATT_BEARER)) == 0) {
|
||||
send_cb_finalize(send_cb, cb_data);
|
||||
send_cb = NULL;
|
||||
|
||||
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
/* This message will not be transmitted by proxy client */
|
||||
if (!bt_mesh_proxy_client_get_conn_count()) {
|
||||
goto done;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_GATT_PROXY_SERVER */
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT) &&
|
||||
(bearer & BLE_MESH_GATT_BEARER) &&
|
||||
(tx->ctx->send_ttl != 1U ||
|
||||
bt_mesh_tag_relay(tx->ctx->send_tag)) &&
|
||||
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
if ((bearer & BLE_MESH_GATT_BEARER) &&
|
||||
(tx->ctx->send_ttl != 1U || bt_mesh_tag_relay(tx->ctx->send_tag)) &&
|
||||
tx->ctx->send_cred != BLE_MESH_FRIENDSHIP_CRED) {
|
||||
if (bt_mesh_proxy_client_relay(&buf->b, tx->ctx->addr)) {
|
||||
/* If Proxy Client succeeds to send messages with GATT bearer,
|
||||
@@ -1147,45 +1173,43 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
|
||||
* connection has been created with Proxy Client, here we will
|
||||
* use advertising bearer for the messages.
|
||||
*/
|
||||
send_cb_finalize(cb, cb_data);
|
||||
if ((bearer & (~BLE_MESH_GATT_BEARER)) == 0) {
|
||||
send_cb_finalize(send_cb, cb_data);
|
||||
send_cb = NULL;
|
||||
|
||||
err = 0;
|
||||
goto done;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
|
||||
|
||||
/* Deliver to local network interface if necessary */
|
||||
if (((IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) ||
|
||||
(IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en())) &&
|
||||
(bt_mesh_fixed_group_match(tx->ctx->addr) || bt_mesh_elem_find(tx->ctx->addr))) {
|
||||
/**
|
||||
* If the target address isn't a unicast address, then the callback function
|
||||
* will be called by `adv task` in place of here, to avoid the callback function
|
||||
* being called twice.
|
||||
/* If the target address isn't a unicast address, then the callback
|
||||
* function will be called by mesh adv task instead of called here
|
||||
* to avoid the callback function being called twice.
|
||||
* See BLEMESH24-76 for more details.
|
||||
*/
|
||||
if (BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) {
|
||||
if (cb && cb->start) {
|
||||
cb->start(0, 0, cb_data);
|
||||
if (send_cb && send_cb->start) {
|
||||
send_cb->start(0, 0, cb_data);
|
||||
}
|
||||
|
||||
net_buf_slist_put(&bt_mesh.local_queue, net_buf_ref(buf));
|
||||
|
||||
if (cb && cb->end) {
|
||||
cb->end(0, cb_data);
|
||||
if (send_cb && send_cb->end) {
|
||||
send_cb->end(0, cb_data);
|
||||
}
|
||||
|
||||
bt_mesh_net_local();
|
||||
|
||||
err = 0;
|
||||
|
||||
goto done;
|
||||
} else {
|
||||
net_buf_slist_put(&bt_mesh.local_queue, net_buf_ref(buf));
|
||||
bt_mesh_net_local();
|
||||
}
|
||||
|
||||
err = 0;
|
||||
net_buf_slist_put(&bt_mesh.local_queue, net_buf_ref(buf));
|
||||
bt_mesh_net_local();
|
||||
}
|
||||
|
||||
if ((bearer & BLE_MESH_ADV_BEARER) &&
|
||||
@@ -1207,7 +1231,6 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
|
||||
BLE_MESH_TRANSMIT_COUNT(tx->xmit), BLE_MESH_TRANSMIT_INT(tx->xmit));
|
||||
bt_mesh_adv_send(buf, tx->xmit, cb, cb_data);
|
||||
|
||||
err = 0;
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -1727,8 +1750,8 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
|
||||
* shall drop all messages secured using the friendship security
|
||||
* credentials.
|
||||
*/
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&
|
||||
(bearer & BLE_MESH_GATT_BEARER) &&
|
||||
#if CONFIG_BLE_MESH_GATT_PROXY_SERVER
|
||||
if ((bearer & BLE_MESH_GATT_BEARER) &&
|
||||
((bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED &&
|
||||
cred != BLE_MESH_FRIENDSHIP_CRED) ||
|
||||
#if CONFIG_BLE_MESH_PRB_SRV
|
||||
@@ -1738,11 +1761,14 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf,
|
||||
rx->ctx.recv_cred == BLE_MESH_FRIENDSHIP_CRED)) {
|
||||
if (bt_mesh_proxy_server_relay(&buf->b, rx->ctx.recv_dst) &&
|
||||
BLE_MESH_ADDR_IS_UNICAST(rx->ctx.recv_dst)) {
|
||||
if ((bearer & (~BLE_MESH_GATT_BEARER)) == 0) {
|
||||
|
||||
if (((bearer & (~BLE_MESH_GATT_BEARER)) == 0) ||
|
||||
bt_mesh_proxy_server_find_client_by_addr(rx->ctx.recv_dst)) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_GATT_PROXY_SERVER */
|
||||
|
||||
if (((bearer & BLE_MESH_ADV_BEARER) && relay_to_adv(rx->net_if)) ||
|
||||
netkey_changed ||
|
||||
@@ -1892,24 +1918,26 @@ static bool ignore_net_msg(uint16_t src, uint16_t dst)
|
||||
return false;
|
||||
}
|
||||
|
||||
void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi,
|
||||
enum bt_mesh_net_if net_if)
|
||||
void bt_mesh_generic_net_recv(struct net_buf_simple *data,
|
||||
struct bt_mesh_net_rx *rx,
|
||||
enum bt_mesh_net_if net_if)
|
||||
{
|
||||
NET_BUF_SIMPLE_DEFINE(buf, 29);
|
||||
struct bt_mesh_net_rx rx = { .ctx.recv_rssi = rssi };
|
||||
struct net_buf_simple_state state = {0};
|
||||
|
||||
BT_DBG("rssi %d net_if %u", rssi, net_if);
|
||||
assert(rx);
|
||||
|
||||
BT_DBG("rssi %d net_if %u", rx->ctx.recv_rssi, net_if);
|
||||
|
||||
if (!ready_to_recv()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (bt_mesh_net_decode(data, net_if, &rx, &buf)) {
|
||||
if (bt_mesh_net_decode(data, net_if, rx, &buf)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ignore_net_msg(rx.ctx.addr, rx.ctx.recv_dst)) {
|
||||
if (ignore_net_msg(rx->ctx.addr, rx->ctx.recv_dst)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1919,26 +1947,26 @@ void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi,
|
||||
BT_BQB(BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_NODE | \
|
||||
BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_NET,
|
||||
"\nNetRecv: ctl: %d, src: %d, dst: %d, ttl: %d, data: 0x%s",
|
||||
rx.ctl, rx.ctx.addr, rx.ctx.recv_dst, rx.ctx.recv_ttl,
|
||||
rx->ctl, rx->ctx.addr, rx->ctx.recv_dst, rx->ctx.recv_ttl,
|
||||
bt_hex(buf.data + BLE_MESH_NET_HDR_LEN, buf.len - BLE_MESH_NET_HDR_LEN));
|
||||
|
||||
/* If trying to handle a message with DST set to all-directed-forwarding-nodes,
|
||||
* we need to make sure the directed forwarding functionality is enabled in the
|
||||
* corresponding subnet.
|
||||
*/
|
||||
rx.local_match = (bt_mesh_fixed_group_match(rx.ctx.recv_dst) ||
|
||||
bt_mesh_fixed_direct_match(rx.sub, rx.ctx.recv_dst) ||
|
||||
bt_mesh_elem_find(rx.ctx.recv_dst));
|
||||
rx->local_match = (bt_mesh_fixed_group_match(rx->ctx.recv_dst) ||
|
||||
bt_mesh_fixed_direct_match(rx->sub, rx->ctx.recv_dst) ||
|
||||
bt_mesh_elem_find(rx->ctx.recv_dst));
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&
|
||||
#if CONFIG_BLE_MESH_PRB_SRV
|
||||
bt_mesh_private_gatt_proxy_state_get() != BLE_MESH_PRIVATE_GATT_PROXY_ENABLED &&
|
||||
#endif
|
||||
net_if == BLE_MESH_NET_IF_PROXY) {
|
||||
bt_mesh_proxy_server_addr_add(data, rx.ctx.addr);
|
||||
bt_mesh_proxy_server_addr_add(data, rx->ctx.addr);
|
||||
|
||||
if (bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_DISABLED &&
|
||||
!rx.local_match) {
|
||||
!rx->local_match) {
|
||||
BT_INFO("Proxy is disabled; ignoring message");
|
||||
return;
|
||||
}
|
||||
@@ -1951,11 +1979,11 @@ void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi,
|
||||
* tag the Network PDU with the immutable-credentials tag.
|
||||
*/
|
||||
#if CONFIG_BLE_MESH_DF_SRV
|
||||
if (rx.sub->directed_proxy == BLE_MESH_DIRECTED_PROXY_ENABLED &&
|
||||
rx.sub->use_directed == BLE_MESH_PROXY_USE_DIRECTED_ENABLED &&
|
||||
!bt_mesh_addr_in_uar(&rx.sub->proxy_client_uar, rx.ctx.addr) &&
|
||||
!bt_mesh_proxy_server_find_client_by_addr(rx.ctx.addr)) {
|
||||
rx.ctx.recv_tag |= BLE_MESH_TAG_IMMUTABLE_CRED;
|
||||
if (rx->sub->directed_proxy == BLE_MESH_DIRECTED_PROXY_ENABLED &&
|
||||
rx->sub->use_directed == BLE_MESH_PROXY_USE_DIRECTED_ENABLED &&
|
||||
!bt_mesh_addr_in_uar(&rx->sub->proxy_client_uar, rx->ctx.addr) &&
|
||||
!bt_mesh_proxy_server_find_client_by_addr(rx->ctx.addr)) {
|
||||
rx->ctx.recv_tag |= BLE_MESH_TAG_IMMUTABLE_CRED;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_DF_SRV */
|
||||
}
|
||||
@@ -1967,24 +1995,24 @@ void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi,
|
||||
* credentials. Remove it from the message cache so that we accept
|
||||
* it again in the future.
|
||||
*/
|
||||
if (bt_mesh_trans_recv(&buf, &rx) == -EAGAIN) {
|
||||
if (bt_mesh_trans_recv(&buf, rx) == -EAGAIN) {
|
||||
BT_WARN("Removing rejected message from Network Message Cache");
|
||||
msg_cache[rx.msg_cache_idx].src = BLE_MESH_ADDR_UNASSIGNED;
|
||||
msg_cache[rx->msg_cache_idx].src = BLE_MESH_ADDR_UNASSIGNED;
|
||||
/* Rewind the next index now that we're not using this entry */
|
||||
msg_cache_next = rx.msg_cache_idx;
|
||||
msg_cache_next = rx->msg_cache_idx;
|
||||
}
|
||||
|
||||
/* Relay if this was a group/virtual address, or if the destination
|
||||
* was neither a local element nor an LPN we're Friends for.
|
||||
*/
|
||||
if (!BLE_MESH_ADDR_IS_UNICAST(rx.ctx.recv_dst) ||
|
||||
(!rx.local_match && !rx.friend_match
|
||||
if (!BLE_MESH_ADDR_IS_UNICAST(rx->ctx.recv_dst) ||
|
||||
(!rx->local_match && !rx->friend_match
|
||||
#if CONFIG_BLE_MESH_NOT_RELAY_REPLAY_MSG
|
||||
&& !rx.replay_msg
|
||||
&& !rx->replay_msg
|
||||
#endif
|
||||
)) {
|
||||
net_buf_simple_restore(&buf, &state);
|
||||
bt_mesh_net_relay(&buf, &rx);
|
||||
bt_mesh_net_relay(&buf, rx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017 Intel Corporation
|
||||
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -465,8 +465,16 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
|
||||
int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if,
|
||||
struct bt_mesh_net_rx *rx, struct net_buf_simple *buf);
|
||||
|
||||
void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi,
|
||||
enum bt_mesh_net_if net_if);
|
||||
void bt_mesh_generic_net_recv(struct net_buf_simple *data,
|
||||
struct bt_mesh_net_rx *rx,
|
||||
enum bt_mesh_net_if net_if);
|
||||
|
||||
static inline void bt_mesh_net_recv(struct net_buf_simple *data, int8_t rssi,
|
||||
enum bt_mesh_net_if net_if)
|
||||
{
|
||||
struct bt_mesh_net_rx rx = { .ctx.recv_rssi = rssi };
|
||||
bt_mesh_generic_net_recv(data, &rx, net_if);
|
||||
}
|
||||
|
||||
bool bt_mesh_primary_subnet_exist(void);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017 Nordic Semiconductor ASA
|
||||
* SPDX-FileCopyrightText: 2015-2016 Intel Corporation
|
||||
* SPDX-FileContributor: 2018-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -27,6 +27,8 @@
|
||||
#include "mesh/hci.h"
|
||||
#include "mesh/common.h"
|
||||
#include "prov_pvnr.h"
|
||||
#include "scan.h"
|
||||
#include "btc_ble_mesh_ble.h"
|
||||
|
||||
/** @def BT_UUID_MESH_PROV
|
||||
* @brief Mesh Provisioning Service
|
||||
@@ -69,7 +71,6 @@ static uint8_t bt_mesh_private_key[32];
|
||||
|
||||
/* Scan related functions */
|
||||
static bt_mesh_scan_cb_t *bt_mesh_scan_dev_found_cb;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
/* the gatt database list to save the attribute table */
|
||||
static sys_slist_t bt_mesh_gatts_db;
|
||||
@@ -79,10 +80,57 @@ static struct bt_mesh_conn bt_mesh_gatts_conn[BLE_MESH_MAX_CONN];
|
||||
static struct bt_mesh_conn_cb *bt_mesh_gatts_conn_cb;
|
||||
|
||||
static uint8_t bt_mesh_gatts_addr[6];
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
static bool g_gatts_svcs_add = false;
|
||||
#endif
|
||||
#endif /* CONFIG_BLE_MESH_NODE */
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50 && CONFIG_BLE_MESH_SUPPORT_BLE_ADV
|
||||
static inline void bt_mesh_set_ble_adv_running();
|
||||
|
||||
static inline void bt_mesh_unset_ble_adv_running();
|
||||
|
||||
static inline bool bt_mesh_is_ble_adv_running();
|
||||
#endif
|
||||
|
||||
static bool g_host_init = false;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_USE_BLE_50
|
||||
|
||||
#define BT_MESH_GATTS_CONN_UNUSED 0xFF
|
||||
|
||||
static void bt_mesh_gatts_conn_init(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < BLE_MESH_MAX_CONN; i++) {
|
||||
bt_mesh_gatts_conn[i].handle = BT_MESH_GATTS_CONN_UNUSED;
|
||||
}
|
||||
}
|
||||
|
||||
static int bt_mesh_find_free_conn_idx(void)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < BLE_MESH_MAX_CONN; i++) {
|
||||
if (bt_mesh_gatts_conn[i].handle == BT_MESH_GATTS_CONN_UNUSED) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
static int bt_mesh_find_conn_idx(uint16_t conn_handle)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < BLE_MESH_MAX_CONN; i++) {
|
||||
if (bt_mesh_gatts_conn[i].handle == conn_handle) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -ENODEV;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
|
||||
int bt_mesh_host_init(void)
|
||||
{
|
||||
int rc;
|
||||
@@ -145,7 +193,13 @@ void bt_mesh_hci_init(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
static struct ble_gap_ext_disc_params uncoded_disc_params;
|
||||
static struct ble_gap_ext_disc_params coded_disc_params;
|
||||
#else
|
||||
static struct ble_gap_disc_params scan_param;
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
static struct gattc_prov_info {
|
||||
@@ -350,13 +404,19 @@ static int svc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
|
||||
}
|
||||
|
||||
uuid = &service->uuid;
|
||||
uuid_length = (uint8_t) (uuid->u.type == BLE_UUID_TYPE_16 ? 2 : 16);
|
||||
uuid_length = (uint8_t)(uuid->u.type == BLE_UUID_TYPE_16 ? 2 : 16);
|
||||
if (uuid_length != 2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
if (bt_mesh_gattc_info[i].service_uuid == (uint16_t)BLE_UUID16(uuid)->value) {
|
||||
/**
|
||||
* In scenarios with multiple connections, to prevent
|
||||
* subsequent connections from affecting the first one,
|
||||
* a check for the connection handle is needed here.
|
||||
*/
|
||||
if (bt_mesh_gattc_info[i].conn.handle == conn_handle &&
|
||||
bt_mesh_gattc_info[i].service_uuid == (uint16_t)BLE_UUID16(uuid)->value) {
|
||||
bt_mesh_gattc_info[i].start_handle = service->start_handle;
|
||||
bt_mesh_gattc_info[i].end_handle = service->end_handle;
|
||||
break;
|
||||
@@ -398,9 +458,45 @@ static int svc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
|
||||
}
|
||||
#endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
|
||||
|
||||
static int disc_cb(struct ble_gap_event *event, void *arg)
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
void bt_mesh_ble_ext_adv_report(struct ble_gap_ext_disc_desc *desc)
|
||||
{
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
bt_mesh_ble_adv_report_t adv_rpt = {0};
|
||||
if (bt_mesh_ble_scan_state_get()) {
|
||||
memcpy(adv_rpt.addr, desc->addr.val, BLE_MESH_ADDR_LEN);
|
||||
memcpy(adv_rpt.dir_addr, desc->direct_addr.val, BLE_MESH_ADDR_LEN);
|
||||
|
||||
/* Here, only a shallow copy needs to be implemented;
|
||||
* deep copying behavior occurs in btc_ble_mesh_ble_copy_req_data. */
|
||||
adv_rpt.data = desc->data;
|
||||
|
||||
adv_rpt.event_type = desc->props;
|
||||
adv_rpt.addr_type = desc->addr.type;
|
||||
adv_rpt.length = desc->length_data;
|
||||
adv_rpt.rssi = desc->rssi;
|
||||
adv_rpt.primary_phy = desc->prim_phy;
|
||||
adv_rpt.secondary_phy = desc->sec_phy;
|
||||
adv_rpt.sid = desc->sid;
|
||||
adv_rpt.tx_power = desc->tx_power;
|
||||
adv_rpt.dir_addr_type = desc->direct_addr.type;
|
||||
adv_rpt.data_status = desc->data_status;
|
||||
adv_rpt.per_adv_interval = desc->periodic_adv_itvl;
|
||||
|
||||
bt_mesh_ble_scan_cb_evt_to_btc(&adv_rpt);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
|
||||
}
|
||||
#endif
|
||||
|
||||
int disc_cb(struct ble_gap_event *event, void *arg)
|
||||
{
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
struct ble_gap_ext_disc_desc *desc;
|
||||
#else
|
||||
struct ble_gap_disc_desc *desc;
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
int rc, i;
|
||||
@@ -412,21 +508,58 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
|
||||
#endif
|
||||
|
||||
switch (event->type) {
|
||||
case BLE_GAP_EVENT_DISC: {
|
||||
struct net_buf_simple buf = {0};
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
case BLE_GAP_EVENT_EXT_DISC: {
|
||||
struct bt_mesh_adv_report adv_rpt = {0};
|
||||
|
||||
desc = &event->disc;
|
||||
net_buf_simple_init_with_data(&buf, (void *)desc->data, desc->length_data);
|
||||
desc = &event->ext_disc;
|
||||
|
||||
memcpy(&adv_rpt.addr, &desc->addr, sizeof(bt_mesh_addr_t));
|
||||
adv_rpt.rssi = desc->rssi;
|
||||
adv_rpt.adv_type = desc->props;
|
||||
adv_rpt.primary_phy = desc->prim_phy;
|
||||
adv_rpt.secondary_phy = desc->sec_phy;
|
||||
|
||||
net_buf_simple_init_with_data(&adv_rpt.adv_data, (void *)desc->data, desc->length_data);
|
||||
|
||||
if (bt_mesh_scan_dev_found_cb) {
|
||||
/* TODO: Support Scan Response data length for NimBLE host */
|
||||
bt_mesh_scan_dev_found_cb((bt_mesh_addr_t *)&desc->addr, desc->rssi, desc->event_type, &buf, 0);
|
||||
if (desc->props & BLE_HCI_ADV_LEGACY_MASK) {
|
||||
bt_mesh_scan_dev_found_cb(&adv_rpt);
|
||||
}
|
||||
}
|
||||
|
||||
/* Mesh didn't process that data */
|
||||
if (adv_rpt.adv_data.len == desc->length_data) {
|
||||
bt_mesh_ble_ext_adv_report(desc);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
case BLE_GAP_EVENT_DISC: {
|
||||
struct bt_mesh_adv_report adv_rpt = {0};
|
||||
|
||||
desc = &event->disc;
|
||||
|
||||
adv_rpt.rssi = desc->rssi;
|
||||
adv_rpt.adv_type = desc->event_type;
|
||||
|
||||
memcpy(&adv_rpt.addr, &desc->addr, sizeof(bt_mesh_addr_t));
|
||||
|
||||
net_buf_simple_init_with_data(&adv_rpt.adv_data, (void *)desc->data, desc->length_data);
|
||||
|
||||
if (bt_mesh_scan_dev_found_cb) {
|
||||
/* TODO: Support Scan Response data length for NimBLE host */
|
||||
bt_mesh_scan_dev_found_cb(&adv_rpt);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
case BLE_GAP_EVENT_CONNECT:
|
||||
/* @todo: process connect failed event */
|
||||
if (event->connect.status == 0) {
|
||||
/* Connection successfully established. */
|
||||
MODLOG_DFLT(INFO, "Connection established ");
|
||||
@@ -442,10 +575,21 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == ARRAY_SIZE(bt_mesh_gattc_info)) {
|
||||
goto transfer_to_user;
|
||||
}
|
||||
} else {
|
||||
goto transfer_to_user;
|
||||
}
|
||||
}
|
||||
if (!bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) {
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
rc = ble_gap_ext_disc(BLE_OWN_ADDR_PUBLIC, 0, 0, 0, 0, 0,
|
||||
uncoded_disc_params.itvl ? &uncoded_disc_params : NULL,
|
||||
coded_disc_params.itvl ? &coded_disc_params : NULL, disc_cb, NULL);
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
rc = ble_gap_disc(BLE_OWN_ADDR_PUBLIC, BLE_HS_FOREVER, &scan_param, disc_cb, NULL);
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
if (rc != 0) {
|
||||
BT_ERR("Invalid scan status %d", rc);
|
||||
break;
|
||||
@@ -494,7 +638,13 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
|
||||
bt_mesh_gattc_info[i].wr_desc_done = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == ARRAY_SIZE(bt_mesh_gattc_info)) {
|
||||
goto transfer_to_user;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
goto transfer_to_user;
|
||||
}
|
||||
break;
|
||||
case BLE_GAP_EVENT_MTU:
|
||||
@@ -521,6 +671,8 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
|
||||
}
|
||||
/* Search Mesh Provisioning Service or Mesh Proxy Service */
|
||||
ble_gattc_disc_all_svcs(bt_mesh_gattc_info[i].conn.handle, svc_disced, NULL);
|
||||
} else {
|
||||
goto transfer_to_user;
|
||||
}
|
||||
break;
|
||||
case BLE_GAP_EVENT_NOTIFY_RX:
|
||||
@@ -531,8 +683,8 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
|
||||
}
|
||||
|
||||
if (i == ARRAY_SIZE(bt_mesh_gattc_info)) {
|
||||
BT_ERR("Conn handle 0x%04x not found", event->notify_rx.conn_handle);
|
||||
return 0;
|
||||
BT_DBG("Conn handle 0x%04x not blonges to Mesh", event->notify_rx.conn_handle);
|
||||
goto transfer_to_user;
|
||||
}
|
||||
|
||||
conn = &bt_mesh_gattc_info[i].conn;
|
||||
@@ -557,7 +709,7 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
|
||||
if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROV_VAL) {
|
||||
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->prov_notify != NULL) {
|
||||
len = bt_mesh_gattc_conn_cb->prov_notify(&bt_mesh_gattc_info[i].conn,
|
||||
notif_data, notif_len);
|
||||
notif_data, notif_len);
|
||||
if (len < 0) {
|
||||
BT_ERR("prov_notify failed");
|
||||
bt_mesh_gattc_disconnect(conn);
|
||||
@@ -568,7 +720,7 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
|
||||
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->proxy_notify != NULL &&
|
||||
bt_mesh_gattc_info[i].wr_desc_done) {
|
||||
len = bt_mesh_gattc_conn_cb->proxy_notify(&bt_mesh_gattc_info[i].conn,
|
||||
notif_data, notif_len);
|
||||
notif_data, notif_len);
|
||||
if (len < 0) {
|
||||
BT_ERR("proxy_notify failed");
|
||||
bt_mesh_gattc_disconnect(conn);
|
||||
@@ -579,14 +731,53 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
goto transfer_to_user;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
transfer_to_user:
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
bt_mesh_ble_nimble_evt_to_btc(event, arg);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
/**
|
||||
* @brief Get the gap callback function used by BLE Mesh
|
||||
*
|
||||
* @note The user must get the mesh gap event handler function
|
||||
* through the bt_mesh_nimble_gap_cb_get function and pass
|
||||
* it in as a callback function when using the api:
|
||||
* ble_gap_ext_connect, ble_gap_ext_disc, ble_gap_connect,
|
||||
* and ble_gap_disc.
|
||||
*
|
||||
* @return void*
|
||||
*/
|
||||
void *bt_mesh_nimble_gap_cb_get(void)
|
||||
{
|
||||
return (void*)disc_cb;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int start_le_scan(uint8_t scan_type, uint16_t interval, uint16_t window, uint8_t filter_dup)
|
||||
{
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
uncoded_disc_params.itvl = (window ? interval : 0);
|
||||
uncoded_disc_params.window = window;
|
||||
|
||||
coded_disc_params.itvl = ((interval > window) ? interval : 0);
|
||||
coded_disc_params.window = ((interval > window) ? interval - window : 0);
|
||||
|
||||
coded_disc_params.passive = (scan_type == BLE_MESH_SCAN_PASSIVE);
|
||||
uncoded_disc_params.passive = (scan_type == BLE_MESH_SCAN_PASSIVE);
|
||||
|
||||
ble_gap_ext_disc(BLE_OWN_ADDR_PUBLIC, 0, 0, filter_dup, 0, 0,
|
||||
uncoded_disc_params.itvl ? &uncoded_disc_params : NULL,
|
||||
coded_disc_params.itvl ? &coded_disc_params : NULL, disc_cb, NULL);
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
scan_param.filter_duplicates = filter_dup;
|
||||
scan_param.itvl = interval;
|
||||
scan_param.window = window;
|
||||
@@ -597,6 +788,7 @@ static int start_le_scan(uint8_t scan_type, uint16_t interval, uint16_t window,
|
||||
scan_param.passive = 0;
|
||||
}
|
||||
ble_gap_disc(BLE_OWN_ADDR_PUBLIC, BLE_HS_FOREVER, &scan_param, disc_cb, NULL);
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
|
||||
#if BLE_MESH_DEV
|
||||
if (scan_type == BLE_MESH_SCAN_ACTIVE) {
|
||||
@@ -648,12 +840,38 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
/* When connection is created, advertising will be stopped automatically. */
|
||||
bt_mesh_atomic_test_and_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING);
|
||||
#endif
|
||||
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \
|
||||
(CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT)
|
||||
/* Check if this connection is created by Proxy client */
|
||||
for (size_t i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
if (!memcmp(bt_mesh_gattc_info[i].addr.val, desc.peer_id_addr.val, BLE_MESH_ADDR_LEN)) {
|
||||
BT_WARN("Already create connection with %s by proxy client",
|
||||
bt_hex(desc.peer_id_addr.val, BLE_MESH_ADDR_LEN));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (bt_mesh_gatts_conn_cb != NULL && bt_mesh_gatts_conn_cb->connected != NULL) {
|
||||
uint8_t index = BLE_MESH_GATT_GET_CONN_ID(event->connect.conn_handle);
|
||||
int index = 0;
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
index = bt_mesh_find_free_conn_idx();
|
||||
if (index != -ENOMEM) {
|
||||
bt_mesh_gatts_conn[index].handle = BLE_MESH_GATT_GET_CONN_ID(event->connect.conn_handle);
|
||||
(bt_mesh_gatts_conn_cb->connected)(&bt_mesh_gatts_conn[index], 0);
|
||||
} else {
|
||||
BT_ERR("No space for new connection");
|
||||
ble_gap_terminate(event->connect.conn_handle, BLE_ERR_CONN_LIMIT);
|
||||
}
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
index = BLE_MESH_GATT_GET_CONN_ID(event->connect.conn_handle);
|
||||
if (index < BLE_MESH_MAX_CONN) {
|
||||
bt_mesh_gatts_conn[index].handle = BLE_MESH_GATT_GET_CONN_ID(event->connect.conn_handle);
|
||||
(bt_mesh_gatts_conn_cb->connected)(&bt_mesh_gatts_conn[index], 0);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
memcpy(bt_mesh_gatts_addr, desc.peer_id_addr.val, BLE_MESH_ADDR_LEN);
|
||||
/* This is for EspBleMesh Android app. When it tries to connect with the
|
||||
* device at the first time and it fails due to some reason. And after
|
||||
@@ -673,11 +891,23 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
bt_mesh_atomic_test_and_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING);
|
||||
#endif
|
||||
if (bt_mesh_gatts_conn_cb != NULL && bt_mesh_gatts_conn_cb->disconnected != NULL) {
|
||||
uint8_t index = BLE_MESH_GATT_GET_CONN_ID(event->disconnect.conn.conn_handle);
|
||||
int index = 0;
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
index = bt_mesh_find_conn_idx(BLE_MESH_GATT_GET_CONN_ID(event->disconnect.conn.conn_handle));
|
||||
if (index != -ENODEV) {
|
||||
bt_mesh_gatts_conn[index].handle = BLE_MESH_GATT_GET_CONN_ID(event->disconnect.conn.conn_handle);
|
||||
(bt_mesh_gatts_conn_cb->disconnected)(&bt_mesh_gatts_conn[index], event->disconnect.reason);
|
||||
} else {
|
||||
BT_ERR("No device");
|
||||
}
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
index = BLE_MESH_GATT_GET_CONN_ID(event->disconnect.conn.conn_handle);
|
||||
if (index < BLE_MESH_MAX_CONN) {
|
||||
bt_mesh_gatts_conn[index].handle = BLE_MESH_GATT_GET_CONN_ID(event->disconnect.conn.conn_handle);
|
||||
(bt_mesh_gatts_conn_cb->disconnected)(&bt_mesh_gatts_conn[index], event->disconnect.reason);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
bt_mesh_gatts_conn[index].handle = 0;
|
||||
memset(bt_mesh_gatts_addr, 0x0, BLE_MESH_ADDR_LEN);
|
||||
}
|
||||
|
||||
@@ -693,8 +923,38 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_ADV_COMPLETE:
|
||||
MODLOG_DFLT(INFO, "advertise complete; reason=%d",
|
||||
event->adv_complete.reason);
|
||||
BT_DBG("advertise complete; reason=%d",
|
||||
event->adv_complete.reason);
|
||||
/* Limit Reached (0x43) and Advertising Timeout (0x3C) will cause BLE_HS_ETIMEOUT to be set. */
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
if (event->adv_complete.reason == BLE_HS_ETIMEOUT) {
|
||||
ble_mesh_adv_task_wakeup(event->adv_complete.instance);
|
||||
}
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
|
||||
/**
|
||||
* This judgment is to distinguish between the termination
|
||||
* events of BLE connectable broadcasting and proxy connectable
|
||||
* adv under the same instance ID, that is, when the status is 0.
|
||||
*
|
||||
* Since the host task and adv task are currently operated in
|
||||
* series, there is no need to consider competition issues between
|
||||
* tasks.
|
||||
*
|
||||
* @attention: once multiple adv instances are used, the adv task
|
||||
* and host will be asynchronous, and it is necessary to consider
|
||||
* the issue of resource competition.
|
||||
*/
|
||||
if (bt_mesh_is_ble_adv_running() &&
|
||||
event->adv_complete.reason == 0) {
|
||||
/* The unset operation must be performed before waking up the
|
||||
* adv task; performing the unset after waking up the adv task
|
||||
* could lead to resource contention issues.
|
||||
*/
|
||||
bt_mesh_unset_ble_adv_running();
|
||||
ble_mesh_adv_task_wakeup(event->adv_complete.instance);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
return 0;
|
||||
|
||||
case BLE_GAP_EVENT_ENC_CHANGE:
|
||||
@@ -717,10 +977,20 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
event->subscribe.prev_indicate,
|
||||
event->subscribe.cur_indicate);
|
||||
struct bt_mesh_gatt_attr *attr = bt_mesh_gatts_find_attr_by_handle(event->subscribe.attr_handle + 1);
|
||||
uint8_t index = BLE_MESH_GATT_GET_CONN_ID(event->subscribe.conn_handle);
|
||||
int index = 0;
|
||||
uint16_t len = 0;
|
||||
uint16_t ccc_val = 0;
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
index = bt_mesh_find_conn_idx(BLE_MESH_GATT_GET_CONN_ID(event->subscribe.conn_handle));
|
||||
if (index == -ENODEV) {
|
||||
BT_ERR("Couldn't find conn %d", event->subscribe.conn_handle);
|
||||
return 0;
|
||||
}
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
index = BLE_MESH_GATT_GET_CONN_ID(event->subscribe.conn_handle);
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
|
||||
if (event->subscribe.prev_notify != event->subscribe.cur_notify) {
|
||||
ccc_val = event->subscribe.cur_notify;
|
||||
} else if (event->subscribe.prev_indicate != event->subscribe.cur_indicate) {
|
||||
@@ -773,10 +1043,231 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
#else
|
||||
static int gap_event_cb(struct ble_gap_event *event, void *arg)
|
||||
{
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
switch (event->type) {
|
||||
case BLE_GAP_EVENT_ADV_COMPLETE:
|
||||
BT_DBG("Provisioner advertise complete; reason=%d",
|
||||
event->adv_complete.reason);
|
||||
/* Limit Reached (0x43) and Advertising Timeout (0x3C) will cause BLE_HS_ETIMEOUT to be set. */
|
||||
if (event->adv_complete.reason == BLE_HS_ETIMEOUT) {
|
||||
ble_mesh_adv_task_wakeup(event->adv_complete.instance);
|
||||
}
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
|
||||
/**
|
||||
* This judgment is to distinguish between the termination
|
||||
* events of BLE connectable broadcasting and proxy connectable
|
||||
* adv under the same instance ID, that is, when the status is 0.
|
||||
*
|
||||
* Since the host task and adv task are currently operated in
|
||||
* series, there is no need to consider competition issues between
|
||||
* tasks.
|
||||
*
|
||||
* @attention: once multiple adv instances are used, the adv task
|
||||
* and host will be asynchronous, and it is necessary to consider
|
||||
* the issue of resource competition.
|
||||
*/
|
||||
if (bt_mesh_is_ble_adv_running() &&
|
||||
event->adv_complete.reason == 0) {
|
||||
/* The unset operation must be performed before waking up the
|
||||
* adv task; performing the unset after waking up the adv task
|
||||
* could lead to resource contention issues.
|
||||
*/
|
||||
bt_mesh_unset_ble_adv_running();
|
||||
ble_mesh_adv_task_wakeup(event->adv_complete.instance);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
|
||||
break;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_NODE */
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
int bt_le_ext_adv_start(const uint8_t inst_id,
|
||||
const struct bt_mesh_adv_param *param,
|
||||
const struct bt_mesh_adv_data *ad, size_t ad_len,
|
||||
const struct bt_mesh_adv_data *sd, size_t sd_len)
|
||||
{
|
||||
struct ble_gap_ext_adv_params adv_params = {0};
|
||||
struct os_mbuf *data = NULL;
|
||||
struct os_mbuf *scan_rsp = NULL;
|
||||
uint8_t *buf = NULL;
|
||||
uint16_t interval = 0;
|
||||
uint8_t buf_len = 0;
|
||||
int err = 0;
|
||||
|
||||
err = ble_gap_ext_adv_active(inst_id);
|
||||
if (err) {
|
||||
BT_ERR("adv inst(%d) is running %d", inst_id, err);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
#if BLE_MESH_DEV
|
||||
if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING)) {
|
||||
return -EALREADY;
|
||||
}
|
||||
#endif
|
||||
buf = bt_mesh_calloc(ad_len * BLE_HS_ADV_MAX_SZ);
|
||||
if (!buf) {
|
||||
BT_ERR("ad buffer alloc failed");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
err = set_ad(ad, ad_len, buf, &buf_len);
|
||||
if (err) {
|
||||
bt_mesh_free(buf);
|
||||
BT_ERR("set_ad failed: err %d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
data = os_msys_get_pkthdr(buf_len, 0);
|
||||
if (!data) {
|
||||
bt_mesh_free(buf);
|
||||
BT_ERR("os buf get failed");
|
||||
return -ENOBUFS;
|
||||
}
|
||||
|
||||
err = os_mbuf_append(data, buf, buf_len);
|
||||
if (err) {
|
||||
bt_mesh_free(buf);
|
||||
BT_ERR("Append ad data to os buf failed %d", err);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
bt_mesh_free(buf);
|
||||
|
||||
if (sd && (param->options & BLE_MESH_ADV_OPT_CONNECTABLE)) {
|
||||
buf_len = 0;
|
||||
|
||||
buf = bt_mesh_calloc(sd_len * BLE_HS_ADV_MAX_SZ);
|
||||
if (!buf) {
|
||||
BT_ERR("ad buffer alloc failed");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
err = set_ad(sd, sd_len, buf, &buf_len);
|
||||
if (err) {
|
||||
bt_mesh_free(buf);
|
||||
BT_ERR("set_ad failed: err %d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
scan_rsp = os_msys_get_pkthdr(buf_len, 0);
|
||||
if (!data) {
|
||||
bt_mesh_free(buf);
|
||||
BT_ERR("os buf get failed");
|
||||
return -ENOBUFS;
|
||||
}
|
||||
|
||||
err = os_mbuf_append(scan_rsp, buf, buf_len);
|
||||
if (err) {
|
||||
bt_mesh_free(buf);
|
||||
BT_ERR("Append ad data to os buf failed %d", err);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
bt_mesh_free(buf);
|
||||
}
|
||||
|
||||
memset(&adv_params, 0, sizeof adv_params);
|
||||
|
||||
assert(param);
|
||||
|
||||
if (param->options & BLE_MESH_ADV_OPT_CONNECTABLE) {
|
||||
adv_params.connectable = true;
|
||||
adv_params.scannable = true;
|
||||
adv_params.legacy_pdu = true;
|
||||
} else if (sd != NULL) {
|
||||
adv_params.connectable = false;
|
||||
adv_params.scannable = true;
|
||||
adv_params.legacy_pdu = true;
|
||||
} else {
|
||||
if (param->primary_phy == BLE_MESH_ADV_PHY_1M &&
|
||||
param->secondary_phy == BLE_MESH_ADV_PHY_1M) {
|
||||
adv_params.legacy_pdu = true;
|
||||
}
|
||||
}
|
||||
|
||||
adv_params.sid = inst_id;
|
||||
adv_params.primary_phy = param->primary_phy;
|
||||
adv_params.secondary_phy = param->secondary_phy;
|
||||
adv_params.tx_power = 0x7F; // tx power will be selected by controller
|
||||
adv_params.own_addr_type = BLE_OWN_ADDR_PUBLIC;
|
||||
|
||||
interval = param->interval_min;
|
||||
|
||||
#if CONFIG_BLE_MESH_RANDOM_ADV_INTERVAL
|
||||
/* If non-connectable mesh packets are transmitted with an adv interval
|
||||
* not smaller than 10ms, then we will use a random adv interval between
|
||||
* [interval / 2, interval] for them.
|
||||
*/
|
||||
if (adv_params.conn_mode == BLE_GAP_CONN_MODE_NON &&
|
||||
adv_params.disc_mode == BLE_GAP_DISC_MODE_NON && interval >= 16) {
|
||||
interval >>= 1;
|
||||
interval += (bt_mesh_get_rand() % (interval + 1));
|
||||
|
||||
adv_params->high_duty_directed = true;
|
||||
|
||||
BT_INFO("%u->%u", param->interval_min, interval);
|
||||
}
|
||||
#endif
|
||||
|
||||
adv_params.itvl_min = interval;
|
||||
adv_params.itvl_max = interval;
|
||||
|
||||
err = ble_gap_ext_adv_configure(inst_id, &adv_params, NULL, gap_event_cb, NULL);
|
||||
if (err != 0) {
|
||||
BT_ERR("Advertising config failed: err %d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = ble_gap_ext_adv_set_data(inst_id, data);
|
||||
if (err != 0) {
|
||||
BT_ERR("Advertising set failed: err %d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (scan_rsp) {
|
||||
err = ble_gap_ext_adv_rsp_set_data(inst_id, scan_rsp);
|
||||
if (err != 0) {
|
||||
BT_ERR("scan rsp set failed: err %d", err);
|
||||
return err;
|
||||
} else {
|
||||
BT_INFO("scan rsp set succeed\n");
|
||||
}
|
||||
}
|
||||
|
||||
again:
|
||||
|
||||
if (param->adv_duration < 10 &&
|
||||
param->adv_duration != 0) {
|
||||
BT_WARN("adv duration shall not be less than 10ms");
|
||||
}
|
||||
|
||||
err = ble_gap_ext_adv_start(inst_id, param->adv_duration ?
|
||||
2 + param->adv_duration / 10 : 0, param->adv_count);
|
||||
if (err) {
|
||||
if (err == BLE_HS_EALREADY) {
|
||||
ble_gap_ext_adv_stop(inst_id);
|
||||
goto again;
|
||||
}
|
||||
|
||||
BT_ERR("Advertising start failed: err %d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
#if BLE_MESH_DEV
|
||||
bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING);
|
||||
|
||||
if (!(param->options & BLE_MESH_ADV_OPT_ONE_TIME)) {
|
||||
bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_KEEP_ADVERTISING);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
/* APIs functions */
|
||||
int bt_le_adv_start(const struct bt_mesh_adv_param *param,
|
||||
const struct bt_mesh_adv_data *ad, size_t ad_len,
|
||||
@@ -877,8 +1368,146 @@ again:
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
|
||||
static bool _ble_adv_running_flag;
|
||||
|
||||
static inline void bt_mesh_set_ble_adv_running()
|
||||
{
|
||||
_ble_adv_running_flag = true;
|
||||
}
|
||||
|
||||
static inline void bt_mesh_unset_ble_adv_running()
|
||||
{
|
||||
_ble_adv_running_flag = false;
|
||||
}
|
||||
|
||||
static inline bool bt_mesh_is_ble_adv_running()
|
||||
{
|
||||
return _ble_adv_running_flag == true;
|
||||
}
|
||||
|
||||
int bt_mesh_ble_ext_adv_start(const uint8_t inst_id,
|
||||
const struct bt_mesh_ble_adv_param *param,
|
||||
const struct bt_mesh_ble_adv_data *adv_data)
|
||||
{
|
||||
struct ble_gap_ext_adv_params adv_params = {0};
|
||||
struct os_mbuf *data = NULL;
|
||||
int err = 0;
|
||||
|
||||
assert(param);
|
||||
|
||||
switch (param->adv_type) {
|
||||
case BLE_MESH_ADV_IND:
|
||||
adv_params.connectable = true;
|
||||
adv_params.scannable = true;
|
||||
adv_params.legacy_pdu = true;
|
||||
break;
|
||||
case BLE_MESH_ADV_DIRECT_IND:
|
||||
adv_params.connectable = true;
|
||||
adv_params.scannable = false;
|
||||
adv_params.directed = true;
|
||||
adv_params.high_duty_directed = false;
|
||||
adv_params.legacy_pdu = true;
|
||||
break;
|
||||
case BLE_MESH_ADV_SCAN_IND:
|
||||
adv_params.connectable = false;
|
||||
adv_params.scannable = true;
|
||||
adv_params.directed = false;
|
||||
adv_params.high_duty_directed = false;
|
||||
adv_params.legacy_pdu = true;
|
||||
break;
|
||||
case BLE_MESH_ADV_NONCONN_IND:
|
||||
adv_params.connectable = false;
|
||||
adv_params.scannable = false;
|
||||
adv_params.directed = false;
|
||||
adv_params.high_duty_directed = false;
|
||||
adv_params.legacy_pdu = true;
|
||||
break;
|
||||
case BLE_MESH_ADV_DIRECT_IND_LOW_DUTY:
|
||||
adv_params.connectable = true;
|
||||
adv_params.scannable = false;
|
||||
adv_params.directed = true;
|
||||
adv_params.high_duty_directed = true;
|
||||
adv_params.legacy_pdu = true;
|
||||
break;
|
||||
}
|
||||
|
||||
adv_params.itvl_min = param->interval;
|
||||
adv_params.itvl_max = param->interval;
|
||||
adv_params.channel_map = BLE_MESH_ADV_CHNL_37 | BLE_MESH_ADV_CHNL_38 | BLE_MESH_ADV_CHNL_39;
|
||||
adv_params.filter_policy = BLE_MESH_AP_SCAN_CONN_ALL;
|
||||
adv_params.primary_phy = BLE_MESH_ADV_PHY_1M;
|
||||
adv_params.secondary_phy = BLE_MESH_ADV_PHY_1M;
|
||||
|
||||
if (param->own_addr_type == BLE_MESH_ADDR_PUBLIC_ID ||
|
||||
param->own_addr_type == BLE_MESH_ADDR_RANDOM_ID ||
|
||||
param->adv_type == BLE_MESH_ADV_DIRECT_IND ||
|
||||
param->adv_type == BLE_MESH_ADV_DIRECT_IND_LOW_DUTY) {
|
||||
adv_params.peer.type = param->peer_addr_type;
|
||||
memcpy(adv_params.peer.val, param->peer_addr, BLE_MESH_ADDR_LEN);
|
||||
}
|
||||
|
||||
|
||||
if (ble_gap_ext_adv_configure(inst_id, &adv_params, NULL,
|
||||
gap_event_cb, NULL)) {
|
||||
BT_ERR("ble adv configure failed\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (adv_data && param->adv_type != BLE_MESH_ADV_DIRECT_IND &&
|
||||
param->adv_type != BLE_MESH_ADV_DIRECT_IND_LOW_DUTY) {
|
||||
if (adv_data->adv_data_len) {
|
||||
data = os_msys_get_pkthdr(adv_data->adv_data_len, 0);
|
||||
if (!data) {
|
||||
BT_ERR("Failed to alloc buffer for ble");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (os_mbuf_append(data, adv_data->adv_data, adv_data->adv_data_len)) {
|
||||
BT_ERR("Append data failed");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err = ble_gap_ext_adv_set_data(inst_id, data);
|
||||
if (err) {
|
||||
BT_ERR("Failed to set advertising data, err %d", err);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
if (adv_data->scan_rsp_data_len && param->adv_type != BLE_MESH_ADV_NONCONN_IND) {
|
||||
data = os_msys_get_pkthdr(adv_data->scan_rsp_data_len, 0);
|
||||
if (!data) {
|
||||
BT_ERR("Failed to alloc buffer for ble");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (os_mbuf_append(data, adv_data->scan_rsp_data, adv_data->scan_rsp_data_len)) {
|
||||
BT_ERR("Append data failed");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = ble_gap_ext_adv_rsp_set_data(inst_id, data);
|
||||
if (err) {
|
||||
BT_ERR("Failed to set scan rsp data, err %d", err);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
err = ble_gap_ext_adv_start(inst_id, 2 + param->duration / 10, param->count);
|
||||
if (err) {
|
||||
BT_ERR("Failed to start advertising, err %d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
bt_mesh_set_ble_adv_running();
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
int bt_mesh_ble_adv_start(const struct bt_mesh_ble_adv_param *param,
|
||||
const struct bt_mesh_ble_adv_data *data)
|
||||
{
|
||||
@@ -949,8 +1578,27 @@ int bt_mesh_ble_adv_start(const struct bt_mesh_ble_adv_param *param,
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
int bt_le_ext_adv_stop(uint8_t inst_id)
|
||||
{
|
||||
#if BLE_MESH_DEV
|
||||
bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_KEEP_ADVERTISING);
|
||||
if (!bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING)) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
ble_gap_ext_adv_stop(inst_id);
|
||||
|
||||
#if BLE_MESH_DEV
|
||||
bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
int bt_le_adv_stop(void)
|
||||
{
|
||||
#if BLE_MESH_DEV
|
||||
@@ -967,6 +1615,7 @@ int bt_le_adv_stop(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
|
||||
int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t cb)
|
||||
{
|
||||
@@ -987,6 +1636,7 @@ int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t c
|
||||
|
||||
err = start_le_scan(param->type, param->interval, param->window, param->filter_dup);
|
||||
if (err) {
|
||||
BT_ERR("Failed to start advertising, err %d", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -1554,6 +2204,7 @@ int bt_mesh_gattc_write_no_rsp(struct bt_mesh_conn *conn,
|
||||
|
||||
om = ble_hs_mbuf_from_flat(data, len);
|
||||
if (om == NULL) {
|
||||
BT_ERR("om buffer alloc failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1622,9 +2273,19 @@ static int proxy_char_access_cb(uint16_t conn_handle, uint16_t attr_handle,
|
||||
{
|
||||
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR || ctxt->op == BLE_GATT_ACCESS_OP_WRITE_DSC) {
|
||||
struct bt_mesh_gatt_attr *attr = bt_mesh_gatts_find_attr_by_handle(attr_handle);
|
||||
uint8_t index = BLE_MESH_GATT_GET_CONN_ID(conn_handle);
|
||||
int index = 0;
|
||||
uint16_t len = 0;
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
index = bt_mesh_find_conn_idx(BLE_MESH_GATT_GET_CONN_ID(conn_handle));
|
||||
if (index == -ENODEV) {
|
||||
BT_ERR("Unknown conn handle");
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
index = BLE_MESH_GATT_GET_CONN_ID(conn_handle);
|
||||
#endif
|
||||
|
||||
BT_DBG("write, handle %d, len %d, data %s", attr_handle,
|
||||
ctxt->om->om_len,
|
||||
bt_hex(ctxt->om->om_data, ctxt->om->om_len));
|
||||
@@ -1713,6 +2374,58 @@ void gatt_register_cb(struct ble_gatt_register_ctxt *ctxt,
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
void bt_mesh_gatts_svcs_add(void)
|
||||
{
|
||||
ble_hs_cfg.gatts_register_cb = gatt_register_cb;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
int rc = 0;
|
||||
|
||||
ble_svc_gap_init();
|
||||
ble_svc_gatt_init();
|
||||
|
||||
rc = ble_gatts_count_cfg(svc_defs);
|
||||
assert(rc == 0);
|
||||
|
||||
rc = ble_gatts_add_svcs(svc_defs);
|
||||
assert(rc == 0);
|
||||
|
||||
g_gatts_svcs_add = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void bt_mesh_gatt_init(void)
|
||||
{
|
||||
ble_att_set_preferred_mtu(BLE_MESH_GATT_DEF_MTU_SIZE);
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
static bool init = false;
|
||||
|
||||
if (init == false) {
|
||||
|
||||
__ASSERT(g_gatts_svcs_add, "func bt_mesh_gatts_svcs_add should be called before mesh init");
|
||||
|
||||
ble_gatts_svc_set_visibility(prov_svc_start_handle, 1);
|
||||
ble_gatts_svc_set_visibility(proxy_svc_start_handle, 0);
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
bt_mesh_gatts_conn_init();
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
init = true;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_NODE */
|
||||
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
for (int i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
bt_mesh_gattc_info[i].conn.handle = 0xFFFF;
|
||||
bt_mesh_gattc_info[i].mtu = BLE_ATT_MTU_DFLT;
|
||||
bt_mesh_gattc_info[i].wr_desc_done = false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
void bt_mesh_gatt_init(void)
|
||||
{
|
||||
ble_att_set_preferred_mtu(BLE_ATT_MTU_DFLT);
|
||||
@@ -1751,6 +2464,7 @@ void bt_mesh_gatt_init(void)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
|
||||
#if CONFIG_BLE_MESH_DEINIT
|
||||
void bt_mesh_gatt_deinit(void)
|
||||
@@ -1981,12 +2695,12 @@ int bt_mesh_update_exceptional_list(uint8_t sub_code, uint32_t type, void *info)
|
||||
|
||||
if ((sub_code > BLE_MESH_EXCEP_LIST_SUB_CODE_CLEAN) ||
|
||||
(sub_code < BLE_MESH_EXCEP_LIST_SUB_CODE_CLEAN &&
|
||||
type > BLE_MESH_EXCEP_LIST_TYPE_MESH_PROXY_ADV) ||
|
||||
type > BLE_MESH_EXCEP_LIST_TYPE_MAX) ||
|
||||
(sub_code == BLE_MESH_EXCEP_LIST_SUB_CODE_CLEAN &&
|
||||
!(type & BLE_MESH_EXCEP_LIST_CLEAN_ALL_LIST))) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == BLE_MESH_EXCEP_LIST_TYPE_MESH_LINK_ID) {
|
||||
if (!info) {
|
||||
|
||||
@@ -1471,6 +1471,9 @@ int bt_mesh_pb_gatt_close(struct bt_mesh_conn *conn, uint8_t reason)
|
||||
if (bt_mesh_atomic_test_bit(prov_link.flags, PB_REMOTE)) {
|
||||
prov_link.pb_remote_cbd = true;
|
||||
prov_link.pb_remote_reset = true;
|
||||
/* @todo: the close reason is disconnect reason, not the
|
||||
* link close reason, should change it to link close reason?
|
||||
*/
|
||||
prov_link.pb_remote_close(&prov_link, reason);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -820,6 +820,23 @@ int bt_mesh_proxy_client_disconnect(uint8_t conn_handle)
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint16_t bt_mesh_proxy_client_get_conn_count(void)
|
||||
{
|
||||
uint16_t count = 0;
|
||||
|
||||
for (size_t i = 0; i < ARRAY_SIZE(servers); i++) {
|
||||
struct bt_mesh_proxy_server *server = &servers[i];
|
||||
|
||||
if (!server->conn || server->conn_type != CLI_PROXY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
bool bt_mesh_proxy_client_relay(struct net_buf_simple *buf, uint16_t dst)
|
||||
{
|
||||
bool send = false;
|
||||
|
||||
@@ -104,6 +104,8 @@ int bt_mesh_proxy_client_disconnect(uint8_t conn_handle);
|
||||
|
||||
bool bt_mesh_proxy_client_beacon_send(struct bt_mesh_subnet *sub, bool private);
|
||||
|
||||
uint16_t bt_mesh_proxy_client_get_conn_count(void);
|
||||
|
||||
bool bt_mesh_proxy_client_relay(struct net_buf_simple *buf, uint16_t dst);
|
||||
|
||||
int bt_mesh_proxy_client_cfg_send(uint8_t conn_handle, uint16_t net_idx,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017 Intel Corporation
|
||||
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileContributor: 2018-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -29,12 +29,16 @@
|
||||
#if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_SERVER
|
||||
|
||||
#if !CONFIG_BLE_MESH_BQB_TEST
|
||||
#if !CONFIG_BLE_MESH_BQB_TEST && !CONFIG_BLE_MESH_PROXY_CLI_SRV_COEXIST && !CONFIG_BLE_MESH_RPR_SRV
|
||||
/* Not support enabling Proxy Client and Proxy Server simultaneously */
|
||||
_Static_assert(!(IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) && IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)),
|
||||
"Not support Proxy Server and Proxy Client simultaneously");
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
static uint8_t proxy_adv_inst = BLE_MESH_ADV_INS_UNUSED;
|
||||
#endif
|
||||
|
||||
#define ADV_OPT (BLE_MESH_ADV_OPT_CONNECTABLE | BLE_MESH_ADV_OPT_ONE_TIME)
|
||||
|
||||
#if CONFIG_BLE_MESH_GATT_PROXY_SERVER && \
|
||||
@@ -52,12 +56,24 @@ static const struct bt_mesh_adv_param slow_adv_param = {
|
||||
.options = ADV_OPT,
|
||||
.interval_min = BLE_MESH_GAP_ADV_SLOW_INT_MIN,
|
||||
.interval_max = BLE_MESH_GAP_ADV_SLOW_INT_MAX,
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
.primary_phy = BLE_MESH_ADV_PHY_1M,
|
||||
.secondary_phy = BLE_MESH_ADV_PHY_1M,
|
||||
.adv_duration = 0,
|
||||
.adv_count = 0,
|
||||
#endif
|
||||
};
|
||||
|
||||
static const struct bt_mesh_adv_param fast_adv_param = {
|
||||
.options = ADV_OPT,
|
||||
.interval_min = BLE_MESH_GAP_ADV_FAST_INT_MIN_0,
|
||||
.interval_max = BLE_MESH_GAP_ADV_FAST_INT_MAX_0,
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
.primary_phy = BLE_MESH_ADV_PHY_1M,
|
||||
.secondary_phy = BLE_MESH_ADV_PHY_1M,
|
||||
.adv_duration = 0,
|
||||
.adv_count = 0,
|
||||
#endif
|
||||
};
|
||||
|
||||
static bool proxy_adv_enabled;
|
||||
@@ -1465,8 +1481,13 @@ static int node_id_adv(struct bt_mesh_subnet *sub)
|
||||
memcpy(proxy_svc_data + 3, tmp + 8, 8);
|
||||
proxy_sd_len = gatt_proxy_adv_create(&proxy_sd);
|
||||
|
||||
err = bt_le_adv_start(&fast_adv_param, node_id_ad,
|
||||
ARRAY_SIZE(node_id_ad), &proxy_sd, proxy_sd_len);
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
err = bt_le_ext_adv_start(proxy_adv_inst, &fast_adv_param, node_id_ad,
|
||||
ARRAY_SIZE(node_id_ad), &proxy_sd, proxy_sd_len);
|
||||
#else
|
||||
err = bt_le_adv_start(&fast_adv_param, node_id_ad,
|
||||
ARRAY_SIZE(node_id_ad), &proxy_sd, proxy_sd_len);
|
||||
#endif
|
||||
if (err) {
|
||||
BT_WARN("Failed to advertise using Node ID (err %d)", err);
|
||||
return err;
|
||||
@@ -1491,8 +1512,13 @@ static int net_id_adv(struct bt_mesh_subnet *sub)
|
||||
memcpy(proxy_svc_data + 3, sub->keys[sub->kr_flag].net_id, 8);
|
||||
proxy_sd_len = gatt_proxy_adv_create(&proxy_sd);
|
||||
|
||||
err = bt_le_adv_start(&slow_adv_param, net_id_ad,
|
||||
ARRAY_SIZE(net_id_ad), &proxy_sd, proxy_sd_len);
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
err = bt_le_ext_adv_start(proxy_adv_inst, &slow_adv_param, net_id_ad,
|
||||
ARRAY_SIZE(net_id_ad), &proxy_sd, proxy_sd_len);
|
||||
#else
|
||||
err = bt_le_adv_start(&slow_adv_param, net_id_ad,
|
||||
ARRAY_SIZE(net_id_ad), &proxy_sd, proxy_sd_len);
|
||||
#endif
|
||||
if (err) {
|
||||
BT_WARN("Failed to advertise using Network ID (err %d)", err);
|
||||
return err;
|
||||
@@ -1836,13 +1862,20 @@ int32_t bt_mesh_proxy_server_adv_start(void)
|
||||
return K_FOREVER;
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
if (proxy_adv_inst == BLE_MESH_ADV_INS_UNUSED) {
|
||||
BT_ERR("Proxy adv inst is not initialized!");
|
||||
return K_FOREVER;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_PB_GATT
|
||||
if (prov_fast_adv) {
|
||||
prov_start_time = k_uptime_get_32();
|
||||
}
|
||||
|
||||
if (!bt_mesh_is_provisioned()) {
|
||||
const struct bt_mesh_adv_param *param;
|
||||
const struct bt_mesh_adv_param *param = NULL;
|
||||
struct bt_mesh_adv_data prov_sd[2];
|
||||
size_t prov_sd_len;
|
||||
|
||||
@@ -1854,8 +1887,14 @@ int32_t bt_mesh_proxy_server_adv_start(void)
|
||||
|
||||
prov_sd_len = gatt_prov_adv_create(prov_sd);
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
if (bt_le_ext_adv_start(proxy_adv_inst, param, prov_ad, ARRAY_SIZE(prov_ad),
|
||||
prov_sd, prov_sd_len) == 0) {
|
||||
#else /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
if (bt_le_adv_start(param, prov_ad, ARRAY_SIZE(prov_ad),
|
||||
prov_sd, prov_sd_len) == 0) {
|
||||
#endif /* CONFIG_BLE_MESH_USE_BLE_50 */
|
||||
|
||||
proxy_adv_enabled = true;
|
||||
|
||||
/* Advertise 60 seconds using fast interval */
|
||||
@@ -1899,7 +1938,16 @@ void bt_mesh_proxy_server_adv_stop(void)
|
||||
return;
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
if (proxy_adv_inst == BLE_MESH_ADV_INS_UNUSED) {
|
||||
BT_ERR("Proxy adv inst is not initialized!");
|
||||
return;
|
||||
}
|
||||
|
||||
err = bt_le_ext_adv_stop(proxy_adv_inst);
|
||||
#else
|
||||
err = bt_le_adv_stop();
|
||||
#endif
|
||||
if (err) {
|
||||
BT_ERR("Failed to stop advertising (err %d)", err);
|
||||
} else {
|
||||
@@ -1916,6 +1964,10 @@ int bt_mesh_proxy_server_init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
proxy_adv_inst = bt_mesh_get_proxy_inst();
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_GATT_PROXY_SERVER
|
||||
bt_mesh_gatts_service_register(&proxy_svc);
|
||||
#endif
|
||||
@@ -1954,6 +2006,10 @@ int bt_mesh_proxy_server_deinit(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_BLE_50
|
||||
proxy_adv_inst = BLE_MESH_ADV_INS_UNUSED;
|
||||
#endif
|
||||
|
||||
proxy_adv_enabled = false;
|
||||
gatt_svc = MESH_GATT_NONE;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "net.h"
|
||||
#include "mesh/adapter.h"
|
||||
#include "adv.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@@ -41,6 +41,22 @@
|
||||
#define PROXY_SVC_DATA_LEN_PRIVATE_NET_ID 0x11
|
||||
#define PROXY_SVC_DATA_LEN_PRIVATE_NODE_ID 0x11
|
||||
|
||||
static struct bt_mesh_scan_param scan_param = {
|
||||
#if CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN
|
||||
.type = BLE_MESH_SCAN_ACTIVE,
|
||||
#else
|
||||
.type = BLE_MESH_SCAN_PASSIVE,
|
||||
#endif
|
||||
#if CONFIG_BLE_MESH_USE_DUPLICATE_SCAN
|
||||
.filter_dup = BLE_MESH_SCAN_FILTER_DUP_ENABLE,
|
||||
#else
|
||||
.filter_dup = BLE_MESH_SCAN_FILTER_DUP_DISABLE,
|
||||
#endif
|
||||
.interval = SCAN_INTERVAL,
|
||||
.window = SCAN_WINDOW,
|
||||
.scan_fil_policy = BLE_MESH_SP_ADV_ALL,
|
||||
};
|
||||
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER || CONFIG_BLE_MESH_RPR_SRV)
|
||||
static const bt_mesh_addr_t *unprov_dev_addr;
|
||||
static uint8_t current_adv_type;
|
||||
@@ -336,13 +352,27 @@ int bt_mesh_stop_ble_scan(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool bt_mesh_ble_scan_state_get(void)
|
||||
{
|
||||
return ble_scan_en;
|
||||
}
|
||||
|
||||
static void inline callback_ble_adv_pkt(const bt_mesh_addr_t *addr,
|
||||
uint8_t adv_type, uint8_t data[],
|
||||
uint16_t length, int8_t rssi)
|
||||
{
|
||||
#if !CONFIG_BLE_MESH_USE_BLE_50
|
||||
bt_mesh_ble_adv_report_t adv_rpt = {0};
|
||||
if (ble_scan_en) {
|
||||
bt_mesh_ble_scan_cb_evt_to_btc(addr, adv_type, data, length, rssi);
|
||||
memcpy(adv_rpt.addr, addr->val, BD_ADDR_LEN);
|
||||
adv_rpt.addr_type = addr->type;
|
||||
adv_rpt.adv_type = adv_type;
|
||||
adv_rpt.length = length;
|
||||
adv_rpt.data = data;
|
||||
adv_rpt.rssi = rssi;
|
||||
bt_mesh_ble_scan_cb_evt_to_btc(&adv_rpt);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
|
||||
|
||||
@@ -364,11 +394,11 @@ static bool rpr_ext_scan_handle_adv_pkt(const bt_mesh_addr_t *addr,
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_RPR_SRV */
|
||||
|
||||
static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
|
||||
int8_t rssi, uint8_t adv_type,
|
||||
struct net_buf_simple *buf,
|
||||
uint8_t scan_rsp_len)
|
||||
static void bt_mesh_scan_cb(struct bt_mesh_adv_report *adv_rpt)
|
||||
{
|
||||
struct net_buf_simple_state buf_state = {0};
|
||||
struct net_buf_simple *buf = &adv_rpt->adv_data;
|
||||
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \
|
||||
CONFIG_BLE_MESH_PROXY_SOLIC_PDU_RX
|
||||
@@ -379,20 +409,44 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
|
||||
uint16_t adv_len = buf->len;
|
||||
#endif
|
||||
|
||||
if (adv_type != BLE_MESH_ADV_NONCONN_IND && adv_type != BLE_MESH_ADV_IND) {
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
|
||||
net_buf_simple_save(buf, &buf_state);
|
||||
|
||||
if (adv_rpt->adv_type != BLE_MESH_ADV_NONCONN_IND &&
|
||||
adv_rpt->adv_type != BLE_MESH_ADV_IND
|
||||
#if CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN
|
||||
&& adv_rpt->adv_type != BLE_MESH_ADV_SCAN_RSP
|
||||
#endif
|
||||
) {
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
callback_ble_adv_pkt(&adv_rpt->addr, adv_rpt->adv_type, adv_data, adv_len, adv_rpt->rssi);
|
||||
#endif
|
||||
net_buf_simple_restore(buf, &buf_state);
|
||||
return;
|
||||
}
|
||||
|
||||
BT_DBG("scan, len %u: %s", buf->len, bt_hex(buf->data, buf->len));
|
||||
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER || CONFIG_BLE_MESH_RPR_SRV)
|
||||
unprov_dev_addr = addr;
|
||||
current_adv_type = adv_type;
|
||||
unprov_dev_addr = &adv_rpt->addr;
|
||||
current_adv_type = adv_rpt->adv_type;
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN
|
||||
if (adv_rpt->adv_type == BLE_MESH_ADV_SCAN_RSP) {
|
||||
/**
|
||||
* scan response is only visible for remote provisioning extend scan.
|
||||
*/
|
||||
if (rpr_ext_scan_handle_adv_pkt(&adv_rpt->addr, adv_data, adv_len)) {
|
||||
return;
|
||||
} else {
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
callback_ble_adv_pkt(&adv_rpt->addr, adv_rpt->adv_type, adv_data, adv_len, adv_rpt->rssi);
|
||||
#endif
|
||||
net_buf_simple_restore(buf, &buf_state);
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN */
|
||||
|
||||
while (buf->len > 1) {
|
||||
struct net_buf_simple_state state;
|
||||
uint8_t len, type;
|
||||
@@ -401,16 +455,18 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
|
||||
/* Check for early termination */
|
||||
if (len == 0U) {
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
|
||||
callback_ble_adv_pkt(&adv_rpt->addr, adv_rpt->adv_type, adv_data, adv_len, adv_rpt->rssi);
|
||||
#endif
|
||||
net_buf_simple_restore(buf, &buf_state);
|
||||
return;
|
||||
}
|
||||
|
||||
if (len > buf->len) {
|
||||
BT_DBG("AD malformed");
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
|
||||
callback_ble_adv_pkt(&adv_rpt->addr, adv_rpt->adv_type, adv_data, adv_len, adv_rpt->rssi);
|
||||
#endif
|
||||
net_buf_simple_restore(buf, &buf_state);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -421,14 +477,17 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
|
||||
buf->len = len - 1;
|
||||
|
||||
if ((type == BLE_MESH_DATA_MESH_PROV || type == BLE_MESH_DATA_MESH_MESSAGE ||
|
||||
type == BLE_MESH_DATA_MESH_BEACON) && (adv_type != BLE_MESH_ADV_NONCONN_IND)) {
|
||||
BT_DBG("Ignore mesh packet (type 0x%02x) with adv_type 0x%02x", type, adv_type);
|
||||
type == BLE_MESH_DATA_MESH_BEACON) && (adv_rpt->adv_type != BLE_MESH_ADV_NONCONN_IND)) {
|
||||
BT_DBG("Ignore mesh packet (type 0x%02x) with adv_type 0x%02x", type, adv_rpt->adv_type);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case BLE_MESH_DATA_MESH_MESSAGE:
|
||||
bt_mesh_net_recv(buf, rssi, BLE_MESH_NET_IF_ADV);
|
||||
struct bt_mesh_net_rx rx = {
|
||||
.ctx.recv_rssi = adv_rpt->rssi,
|
||||
};
|
||||
bt_mesh_generic_net_recv(buf, &rx, BLE_MESH_NET_IF_ADV);
|
||||
break;
|
||||
#if CONFIG_BLE_MESH_PB_ADV
|
||||
case BLE_MESH_DATA_MESH_PROV:
|
||||
@@ -441,7 +500,7 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
|
||||
break;
|
||||
#endif /* CONFIG_BLE_MESH_PB_ADV */
|
||||
case BLE_MESH_DATA_MESH_BEACON:
|
||||
bt_mesh_beacon_recv(buf, rssi);
|
||||
bt_mesh_beacon_recv(buf, adv_rpt->rssi);
|
||||
break;
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \
|
||||
@@ -450,8 +509,9 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
|
||||
if (!adv_flags_valid(buf)) {
|
||||
BT_DBG("Adv Flags mismatch, ignore this adv pkt");
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
|
||||
callback_ble_adv_pkt(&adv_rpt->addr, adv_rpt->adv_type, adv_data, adv_len, adv_rpt->rssi);
|
||||
#endif
|
||||
net_buf_simple_restore(buf, &buf_state);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
@@ -459,7 +519,7 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
|
||||
if (!adv_service_uuid_valid(buf, &uuid)) {
|
||||
BT_DBG("Adv Service UUID mismatch, ignore this adv pkt");
|
||||
#if CONFIG_BLE_MESH_RPR_SRV
|
||||
if (rpr_ext_scan_handle_adv_pkt(addr, adv_data, adv_len)) {
|
||||
if (rpr_ext_scan_handle_adv_pkt(&adv_rpt->addr, adv_data, adv_len)) {
|
||||
/* If handled as extended scan report successfully, then not
|
||||
* notify to the application layer as normal BLE adv packet.
|
||||
*/
|
||||
@@ -467,18 +527,19 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
|
||||
}
|
||||
#endif
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
|
||||
callback_ble_adv_pkt(&adv_rpt->addr, adv_rpt->adv_type, adv_data, adv_len, adv_rpt->rssi);
|
||||
#endif
|
||||
net_buf_simple_restore(buf, &buf_state);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case BLE_MESH_DATA_SVC_DATA16:
|
||||
handle_adv_service_data(buf, addr, uuid, rssi);
|
||||
handle_adv_service_data(buf, &adv_rpt->addr, uuid, adv_rpt->rssi);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
#if CONFIG_BLE_MESH_RPR_SRV
|
||||
if (rpr_ext_scan_handle_adv_pkt(addr, adv_data, adv_len)) {
|
||||
if (rpr_ext_scan_handle_adv_pkt(&adv_rpt->addr, adv_data, adv_len)) {
|
||||
/* If handled as extended scan report successfully, then not
|
||||
* notify to the application layer as normal BLE adv packet.
|
||||
*/
|
||||
@@ -486,44 +547,21 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
|
||||
}
|
||||
#endif
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
|
||||
callback_ble_adv_pkt(&adv_rpt->addr, adv_rpt->adv_type, adv_data, adv_len, adv_rpt->rssi);
|
||||
#endif
|
||||
net_buf_simple_restore(buf, &buf_state);
|
||||
return;
|
||||
}
|
||||
|
||||
net_buf_simple_restore(buf, &state);
|
||||
net_buf_simple_pull(buf, len);
|
||||
}
|
||||
#if CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN
|
||||
if (scan_rsp_len != 0) {
|
||||
/**
|
||||
* scan response is only visible for remote provisioning extend scan.
|
||||
*/
|
||||
rpr_ext_scan_handle_adv_pkt(addr, adv_data + adv_len, scan_rsp_len);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN */
|
||||
}
|
||||
|
||||
int bt_mesh_scan_enable(void)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
struct bt_mesh_scan_param scan_param = {
|
||||
#if CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN
|
||||
.type = BLE_MESH_SCAN_ACTIVE,
|
||||
#else
|
||||
.type = BLE_MESH_SCAN_PASSIVE,
|
||||
#endif
|
||||
#if CONFIG_BLE_MESH_USE_DUPLICATE_SCAN
|
||||
.filter_dup = BLE_MESH_SCAN_FILTER_DUP_ENABLE,
|
||||
#else
|
||||
.filter_dup = BLE_MESH_SCAN_FILTER_DUP_DISABLE,
|
||||
#endif
|
||||
.interval = SCAN_INTERVAL,
|
||||
.window = SCAN_WINDOW,
|
||||
.scan_fil_policy = BLE_MESH_SP_ADV_ALL,
|
||||
};
|
||||
|
||||
err = bt_le_scan_start(&scan_param, bt_mesh_scan_cb);
|
||||
if (err && err != -EALREADY) {
|
||||
BT_ERR("starting scan failed (err %d)", err);
|
||||
@@ -546,6 +584,49 @@ int bt_mesh_scan_disable(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_scan_param_update(struct bt_mesh_scan_param *param)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
if (param == NULL ||
|
||||
param->interval == 0 ||
|
||||
param->interval < param->window) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
scan_param.interval = param->interval;
|
||||
scan_param.window = param->window;
|
||||
|
||||
err = bt_le_scan_stop();
|
||||
if (err) {
|
||||
if (err == -EALREADY) {
|
||||
BT_INFO("New scan parameters will take effect after scan starts");
|
||||
return 0;
|
||||
}
|
||||
BT_ERR("Failed to stop scan (err %d)", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* Since the user only needs to set the scan interval
|
||||
* and scan window parameters, only the interval and
|
||||
* window parameters in the `param` are correct.
|
||||
*
|
||||
* For the aforementioned reason, when updating the scan
|
||||
* parameters, the other parameters also need to be set
|
||||
* correctly, and these other parameters are saved in the
|
||||
* `scan_param`. Therefore, `scan_param` must be used instead
|
||||
* of `param` here.
|
||||
*/
|
||||
err = bt_le_scan_start(&scan_param, bt_mesh_scan_cb);
|
||||
if (err && err != -EALREADY) {
|
||||
BT_ERR("Failed to start scan (err %d)", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_TEST_USE_WHITE_LIST
|
||||
int bt_mesh_scan_with_wl_enable(void)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2017 Intel Corporation
|
||||
* SPDX-FileContributor: 2020-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileContributor: 2020-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -33,16 +33,22 @@ int bt_mesh_scan_enable(void);
|
||||
|
||||
int bt_mesh_scan_disable(void);
|
||||
|
||||
int bt_mesh_scan_param_update(struct bt_mesh_scan_param *scan_param);
|
||||
|
||||
int bt_mesh_scan_with_wl_enable(void);
|
||||
|
||||
struct bt_mesh_ble_scan_param {
|
||||
uint32_t duration;
|
||||
};
|
||||
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
int bt_mesh_start_ble_scan(struct bt_mesh_ble_scan_param *param);
|
||||
|
||||
int bt_mesh_stop_ble_scan(void);
|
||||
|
||||
bool bt_mesh_ble_scan_state_get(void);
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1483,6 +1483,8 @@ int settings_core_commit(void)
|
||||
struct bt_mesh_hb_pub *hb_pub = NULL;
|
||||
struct bt_mesh_cfg_srv *cfg = NULL;
|
||||
|
||||
bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_VALID);
|
||||
|
||||
hb_pub = bt_mesh_hb_pub_get();
|
||||
if (hb_pub && hb_pub->dst != BLE_MESH_ADDR_UNASSIGNED &&
|
||||
hb_pub->count && hb_pub->period) {
|
||||
@@ -1501,7 +1503,6 @@ int settings_core_commit(void)
|
||||
cfg->default_ttl = stored_cfg.cfg.default_ttl;
|
||||
}
|
||||
|
||||
bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_VALID);
|
||||
bt_mesh_net_start();
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_NODE */
|
||||
|
||||
@@ -1217,19 +1217,23 @@ config BT_BLE_RPA_TIMEOUT
|
||||
Default is 900 s (15 minutes). Range is 1 s to 1 hour (3600 s).
|
||||
|
||||
config BT_BLE_50_FEATURES_SUPPORTED
|
||||
bool "Enable BLE 5.0 features"
|
||||
bool "Enable BLE 5.0 features(please disable BLE 4.2 if enable BLE 5.0)"
|
||||
depends on (BT_BLE_ENABLED && ((BT_CONTROLLER_ENABLED && SOC_BLE_50_SUPPORTED) || BT_CONTROLLER_DISABLED))
|
||||
default y
|
||||
help
|
||||
Enabling this option activates BLE 5.0 features.
|
||||
This option is universally supported in chips that support BLE, except for ESP32.
|
||||
BLE 4.2 and BLE 5.0 cannot be used simultaneously.
|
||||
|
||||
|
||||
config BT_BLE_42_FEATURES_SUPPORTED
|
||||
bool "Enable BLE 4.2 features"
|
||||
bool "Enable BLE 4.2 features(please disable BLE 5.0 if enable BLE 4.2)"
|
||||
depends on (BT_BLE_ENABLED && ((BT_CONTROLLER_ENABLED && SOC_BLE_SUPPORTED) || BT_CONTROLLER_DISABLED))
|
||||
default n
|
||||
help
|
||||
This enables BLE 4.2 features.
|
||||
This option is universally supported by all ESP chips with BLE capabilities.
|
||||
BLE 4.2 and BLE 5.0 cannot be used simultaneously.
|
||||
|
||||
config BT_BLE_FEAT_PERIODIC_ADV_SYNC_TRANSFER
|
||||
bool "Enable BLE periodic advertising sync transfer feature"
|
||||
|
||||
@@ -67,8 +67,8 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if)
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
#if (BLE_42_FEATURE_SUPPORT == TRUE)
|
||||
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct)
|
||||
|
||||
esp_err_t esp_ble_gattc_enh_open(esp_gatt_if_t gattc_if, esp_ble_gatt_creat_conn_params_t esp_gatt_create_conn)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
btc_ble_gattc_args_t arg;
|
||||
@@ -79,34 +79,38 @@ esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, e
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_OPEN;
|
||||
arg.open.gattc_if = gattc_if;
|
||||
memcpy(arg.open.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
|
||||
arg.open.remote_addr_type = remote_addr_type;
|
||||
arg.open.is_direct = is_direct;
|
||||
arg.open.is_aux = false;
|
||||
memcpy(arg.open.remote_bda, esp_gatt_create_conn.remote_bda, ESP_BD_ADDR_LEN);
|
||||
arg.open.remote_addr_type = esp_gatt_create_conn.remote_addr_type;
|
||||
arg.open.is_direct = esp_gatt_create_conn.is_direct;
|
||||
arg.open.is_aux= esp_gatt_create_conn.is_aux;
|
||||
arg.open.own_addr_type = esp_gatt_create_conn.own_addr_type;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
#if (BLE_42_FEATURE_SUPPORT == TRUE)
|
||||
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct)
|
||||
{
|
||||
esp_ble_gatt_creat_conn_params_t esp_gatt_create_conn;
|
||||
memcpy(esp_gatt_create_conn.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
|
||||
esp_gatt_create_conn.remote_addr_type = remote_addr_type;
|
||||
esp_gatt_create_conn.is_direct = is_direct;
|
||||
esp_gatt_create_conn.is_aux = false;
|
||||
esp_gatt_create_conn.own_addr_type = 0xff; //undefined, will use local value
|
||||
return esp_ble_gattc_enh_open(gattc_if, esp_gatt_create_conn);
|
||||
}
|
||||
#endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
|
||||
|
||||
#if (BLE_50_FEATURE_SUPPORT == TRUE)
|
||||
esp_err_t esp_ble_gattc_aux_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gattc_args_t arg;
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_AUX_OPEN;
|
||||
arg.open.gattc_if = gattc_if;
|
||||
memcpy(arg.open.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
|
||||
arg.open.remote_addr_type = remote_addr_type;
|
||||
arg.open.is_direct = is_direct;
|
||||
arg.open.is_aux = true;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
|
||||
esp_ble_gatt_creat_conn_params_t esp_gatt_create_conn;
|
||||
memcpy(esp_gatt_create_conn.remote_bda, remote_bda, ESP_BD_ADDR_LEN);
|
||||
esp_gatt_create_conn.remote_addr_type = remote_addr_type;
|
||||
esp_gatt_create_conn.is_direct = is_direct;
|
||||
esp_gatt_create_conn.is_aux = true;
|
||||
esp_gatt_create_conn.own_addr_type = 0xff; //undefined, will use local value
|
||||
return esp_ble_gattc_enh_open(gattc_if, esp_gatt_create_conn);
|
||||
}
|
||||
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
|
||||
|
||||
|
||||
@@ -682,6 +682,15 @@ typedef struct {
|
||||
esp_bt_uuid_t uuid; /*!< Included service UUID. */
|
||||
} esp_gattc_incl_svc_elem_t;
|
||||
|
||||
/** @brief Represents a creat connection element. */
|
||||
typedef struct {
|
||||
esp_bd_addr_t remote_bda; /*!< The Bluetooth address of the remote device */
|
||||
esp_ble_addr_type_t remote_addr_type; /*!< Address type of the remote device */
|
||||
bool is_direct; /*!< Direct connection or background auto connection(by now, background auto connection is not supported */
|
||||
bool is_aux; /*!< Set to true for BLE 5.0 or higher to enable auxiliary connections; set to false for BLE 4.2 or lower. */
|
||||
esp_ble_addr_type_t own_addr_type; /*!< Specifies the address type used in the connection request. Set to 0xFF if the address type is unknown. */
|
||||
} esp_ble_gatt_creat_conn_params_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -314,7 +314,20 @@ esp_err_t esp_ble_gattc_app_register(uint16_t app_id);
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if);
|
||||
|
||||
#if (BLE_42_FEATURE_SUPPORT == TRUE)
|
||||
/**
|
||||
* @brief Open a direct connection or add a background auto connection.
|
||||
* Note: Do not enable both BLE_42_FEATURE_SUPPORT and BLE_50_FEATURE_SUPPORT configuration options simultaneously.
|
||||
*
|
||||
* @param[in] gattc_if: GATT client access interface.
|
||||
* @param[in] esp_gatt_create_conn: Structure containing connection parameters.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Operation successful
|
||||
* - others: Operation failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_enh_open(esp_gatt_if_t gattc_if, esp_ble_gatt_creat_conn_params_t esp_gatt_create_conn);
|
||||
|
||||
/**
|
||||
* @brief Open a direct connection or add a background auto connection
|
||||
*
|
||||
@@ -328,12 +341,14 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gattc_if);
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
#if (BLE_42_FEATURE_SUPPORT == TRUE)
|
||||
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct);
|
||||
#endif // #if (BLE_42_FEATURE_SUPPORT == TRUE)
|
||||
|
||||
#if (BLE_50_FEATURE_SUPPORT == TRUE)
|
||||
esp_err_t esp_ble_gattc_aux_open(esp_gatt_if_t gattc_if, esp_bd_addr_t remote_bda, esp_ble_addr_type_t remote_addr_type, bool is_direct);
|
||||
#endif // #if (BLE_50_FEATURE_SUPPORT == TRUE)
|
||||
|
||||
/**
|
||||
* @brief Close the virtual connection to the GATT server. gattc may have multiple virtual GATT server connections when multiple app_id registered,
|
||||
* this API only close one virtual GATT server connection. if there exist other virtual GATT server connections,
|
||||
|
||||
@@ -6673,7 +6673,8 @@ void btm_dm_start_gatt_discovery (BD_ADDR bd_addr)
|
||||
btm_dm_start_disc_gatt_services(bta_dm_search_cb.conn_id);
|
||||
} else {
|
||||
//TODO need to add addr_type in future
|
||||
BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr, BLE_ADDR_UNKNOWN_TYPE, TRUE, BTA_GATT_TRANSPORT_LE, FALSE);
|
||||
BTA_GATTC_Enh_Open(bta_dm_search_cb.client_if, bd_addr, BLE_ADDR_UNKNOWN_TYPE, TRUE, BTA_GATT_TRANSPORT_LE, FALSE, BLE_ADDR_UNKNOWN_TYPE);
|
||||
|
||||
}
|
||||
}
|
||||
#endif /* #if (GATTC_INCLUDED == TRUE) */
|
||||
|
||||
@@ -70,6 +70,7 @@ static void bta_gattc_req_cback (UINT16 conn_id, UINT32 trans_id, tGATTS_REQ_TYP
|
||||
static tBTA_GATTC_FIND_SERVICE_CB bta_gattc_register_service_change_notify(UINT16 conn_id, BD_ADDR remote_bda);
|
||||
|
||||
extern void btc_gattc_congest_callback(tBTA_GATTC *param);
|
||||
extern uint32_t BTM_BleUpdateOwnType(uint8_t *own_bda_type, tBTM_START_ADV_CMPL_CBACK *cb);
|
||||
|
||||
static const tGATT_CBACK bta_gattc_cl_cback = {
|
||||
bta_gattc_conn_cback,
|
||||
@@ -336,6 +337,10 @@ void bta_gattc_process_api_open (tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg)
|
||||
UNUSED(p_cb);
|
||||
|
||||
if (p_clreg != NULL) {
|
||||
if (p_msg->api_conn.own_addr_type <= BLE_ADDR_TYPE_MAX) {
|
||||
// update own address type for creating connection
|
||||
BTM_BleUpdateOwnType(&p_msg->api_conn.own_addr_type, NULL);
|
||||
}
|
||||
if (p_msg->api_conn.is_direct) {
|
||||
if ((p_clcb = bta_gattc_find_alloc_clcb(p_msg->api_conn.client_if,
|
||||
p_msg->api_conn.remote_bda,
|
||||
|
||||
@@ -128,7 +128,7 @@ void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if)
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BTA_GATTC_Open
|
||||
** Function BTA_GATTC_Enh_Open
|
||||
**
|
||||
** Description Open a direct connection or add a background auto connection
|
||||
** bd address
|
||||
@@ -142,8 +142,8 @@ void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if)
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type,
|
||||
BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport, BOOLEAN is_aux)
|
||||
void BTA_GATTC_Enh_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type,
|
||||
BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport, BOOLEAN is_aux, tBTA_ADDR_TYPE own_addr_type)
|
||||
{
|
||||
tBTA_GATTC_API_OPEN *p_buf;
|
||||
|
||||
@@ -155,6 +155,7 @@ void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE
|
||||
p_buf->transport = transport;
|
||||
p_buf->is_aux = is_aux;
|
||||
p_buf->remote_addr_type = remote_addr_type;
|
||||
p_buf->own_addr_type = own_addr_type;
|
||||
memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);
|
||||
|
||||
|
||||
@@ -472,7 +473,7 @@ void BTA_GATTC_GetGattDb(UINT16 conn_id, UINT16 start_handle, UINT16 end_handle
|
||||
** Description This function is called to read a characteristics value
|
||||
**
|
||||
** Parameters conn_id - connection ID.
|
||||
** handle - characteritic handle to read.
|
||||
** handle - characteristic handle to read.
|
||||
**
|
||||
** Returns None
|
||||
**
|
||||
@@ -607,7 +608,7 @@ void BTA_GATTC_ReadMultipleVariable(UINT16 conn_id, tBTA_GATTC_MULTI *p_read_mul
|
||||
**
|
||||
** Parameters conn_id - connection ID.
|
||||
** s_handle - start handle.
|
||||
** e_handle - end hanle
|
||||
** e_handle - end handle
|
||||
** uuid - The attribute UUID.
|
||||
**
|
||||
** Returns None
|
||||
@@ -687,7 +688,7 @@ void BTA_GATTC_WriteCharValue ( UINT16 conn_id,
|
||||
** Description This function is called to write descriptor value.
|
||||
**
|
||||
** Parameters conn_id - connection ID
|
||||
** handle - descriptor hadle to write.
|
||||
** handle - descriptor handle to write.
|
||||
** write_type - write type.
|
||||
** p_value - the value to be written.
|
||||
**
|
||||
@@ -738,7 +739,7 @@ void BTA_GATTC_WriteCharDescr (UINT16 conn_id,
|
||||
** Description This function is called to prepare write a characteristic value.
|
||||
**
|
||||
** Parameters conn_id - connection ID.
|
||||
** p_char_id - GATT characteritic ID of the service.
|
||||
** p_char_id - GATT characteristic ID of the service.
|
||||
** offset - offset of the write value.
|
||||
** len: length of the data to be written.
|
||||
** p_value - the value to be written.
|
||||
@@ -781,7 +782,7 @@ void BTA_GATTC_PrepareWrite (UINT16 conn_id, UINT16 handle,
|
||||
** Description This function is called to prepare write a characteristic descriptor value.
|
||||
**
|
||||
** Parameters conn_id - connection ID.
|
||||
** p_char_descr_id - GATT characteritic descriptor ID of the service.
|
||||
** p_char_descr_id - GATT characteristic descriptor ID of the service.
|
||||
** offset - offset of the write value.
|
||||
** len: length of the data to be written.
|
||||
** p_value - the value to be written.
|
||||
|
||||
@@ -110,7 +110,7 @@ typedef enum {
|
||||
#define BTA_GATTC_WRITE_PREPARE GATT_WRITE_PREPARE
|
||||
#define BTA_GATTC_INVALID_HANDLE 0
|
||||
|
||||
/* internal strucutre for GATTC register API */
|
||||
/* internal structure for GATTC register API */
|
||||
typedef struct {
|
||||
BT_HDR hdr;
|
||||
tBT_UUID app_uuid;
|
||||
@@ -133,6 +133,7 @@ typedef struct {
|
||||
BOOLEAN is_direct;
|
||||
BOOLEAN is_aux;
|
||||
tBTA_TRANSPORT transport;
|
||||
tBTA_ADDR_TYPE own_addr_type;
|
||||
} tBTA_GATTC_API_OPEN;
|
||||
|
||||
typedef tBTA_GATTC_API_OPEN tBTA_GATTC_API_CANCEL_OPEN;
|
||||
@@ -313,7 +314,7 @@ typedef struct {
|
||||
UINT16 total_char;
|
||||
UINT16 total_attr;
|
||||
UINT8 srvc_hdl_chg; /* service handle change indication pending */
|
||||
UINT16 attr_index; /* cahce NV saving/loading attribute index */
|
||||
UINT16 attr_index; /* cache NV saving/loading attribute index */
|
||||
|
||||
UINT16 mtu;
|
||||
bool update_incl_srvc;
|
||||
|
||||
@@ -117,7 +117,7 @@ static void bta_hh_le_hid_report_dbg(tBTA_HH_DEV_CB *p_cb)
|
||||
if (p_cb->hid_srvc[i].in_use) {
|
||||
p_rpt = &p_cb->hid_srvc[i].report[0];
|
||||
|
||||
APPL_TRACE_DEBUG("\t HID serivce inst: %d", i);
|
||||
APPL_TRACE_DEBUG("\t HID service inst: %d", i);
|
||||
|
||||
for (j = 0; j < BTA_HH_LE_RPT_MAX; j ++, p_rpt++) {
|
||||
rpt_name = "Unknown";
|
||||
@@ -334,14 +334,14 @@ void bta_hh_le_open_conn(tBTA_HH_DEV_CB *p_cb, BD_ADDR remote_bda)
|
||||
bta_hh_cb.le_cb_index[BTA_HH_GET_LE_CB_IDX(p_cb->hid_handle)] = p_cb->index;
|
||||
p_cb->in_use = TRUE;
|
||||
|
||||
BTA_GATTC_Open(bta_hh_cb.gatt_if, remote_bda, BLE_ADDR_UNKNOWN_TYPE, TRUE, BTA_GATT_TRANSPORT_LE, FALSE);
|
||||
BTA_GATTC_Enh_Open(bta_hh_cb.gatt_if, remote_bda, BLE_ADDR_UNKNOWN_TYPE, TRUE, BTA_GATT_TRANSPORT_LE, FALSE, BLE_ADDR_UNKNOWN_TYPE);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function bta_hh_le_fill_16bits_gatt_id
|
||||
**
|
||||
** Description Utility function to fill a GATT ID strucure
|
||||
** Description Utility function to fill a GATT ID structure
|
||||
**
|
||||
*******************************************************************************/
|
||||
void bta_hh_le_fill_16bits_gatt_id(UINT8 inst_id, UINT16 uuid, tBTA_GATT_ID *p_output)
|
||||
@@ -355,7 +355,7 @@ void bta_hh_le_fill_16bits_gatt_id(UINT8 inst_id, UINT16 uuid, tBTA_GATT_ID *p_
|
||||
**
|
||||
** Function bta_hh_le_fill_16bits_srvc_id
|
||||
**
|
||||
** Description Utility function to fill a service ID strucure with a 16 bits
|
||||
** Description Utility function to fill a service ID structure with a 16 bits
|
||||
** service UUID.
|
||||
**
|
||||
*******************************************************************************/
|
||||
@@ -372,7 +372,7 @@ void bta_hh_le_fill_16bits_srvc_id(BOOLEAN is_pri, UINT8 inst_id, UINT16 srvc_uu
|
||||
**
|
||||
** Function bta_hh_le_fill_16bits_char_id
|
||||
**
|
||||
** Description Utility function to fill a char ID strucure with a 16 bits
|
||||
** Description Utility function to fill a char ID structure with a 16 bits
|
||||
** char UUID.
|
||||
**
|
||||
*******************************************************************************/
|
||||
@@ -624,7 +624,7 @@ tBTA_HH_STATUS bta_hh_le_read_char_dscrpt(tBTA_HH_DEV_CB *p_cb, UINT16 srvc_uuid
|
||||
**
|
||||
** Function bta_hh_le_read_rpt_ref_descr
|
||||
**
|
||||
** Description read report refernece descriptors in service discovery process
|
||||
** Description read report reference descriptors in service discovery process
|
||||
**
|
||||
*******************************************************************************/
|
||||
void bta_hh_le_read_rpt_ref_descr(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_LE_RPT *p_rpt)
|
||||
@@ -841,7 +841,7 @@ void bta_hh_le_register_input_notif(tBTA_HH_DEV_CB *p_dev_cb, UINT8 srvc_inst,
|
||||
}
|
||||
}
|
||||
/*
|
||||
else unknow protocol mode */
|
||||
else unknown protocol mode */
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1486,7 +1486,7 @@ void bta_hh_le_gatt_disc_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_STATUS status)
|
||||
{
|
||||
APPL_TRACE_DEBUG("bta_hh_le_gatt_disc_cmpl ");
|
||||
|
||||
/* if open sucessful or protocol mode not desired, keep the connection open but inform app */
|
||||
/* if open successful or protocol mode not desired, keep the connection open but inform app */
|
||||
if (status == BTA_HH_OK || status == BTA_HH_ERR_PROTO) {
|
||||
/* assign a special APP ID temp, since device type unknown */
|
||||
p_cb->app_id = BTA_HH_APP_ID_LE;
|
||||
@@ -1504,7 +1504,7 @@ void bta_hh_le_gatt_disc_cmpl(tBTA_HH_DEV_CB *p_cb, tBTA_HH_STATUS status)
|
||||
**
|
||||
** Function bta_hh_le_srvc_expl_srvc
|
||||
**
|
||||
** Description This function discover the next avaible HID service.
|
||||
** Description This function discover the next available HID service.
|
||||
**
|
||||
** Parameters:
|
||||
**
|
||||
@@ -2076,7 +2076,7 @@ void bta_hh_w4_le_read_descr_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf)
|
||||
**
|
||||
** Function bta_hh_w4_le_write_cmpl
|
||||
**
|
||||
** Description Write charactersitic complete event at W4_CONN st.
|
||||
** Description Write characteristic complete event at W4_CONN st.
|
||||
**
|
||||
** Parameters:
|
||||
**
|
||||
@@ -2104,7 +2104,7 @@ void bta_hh_w4_le_write_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf)
|
||||
**
|
||||
** Function bta_hh_le_write_cmpl
|
||||
**
|
||||
** Description Write charactersitic complete event at CONN st.
|
||||
** Description Write characteristic complete event at CONN st.
|
||||
**
|
||||
** Parameters:
|
||||
**
|
||||
@@ -2162,7 +2162,7 @@ void bta_hh_le_write_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf)
|
||||
**
|
||||
** Function bta_hh_le_write_char_descr_cmpl
|
||||
**
|
||||
** Description Write charactersitic descriptor complete event
|
||||
** Description Write characteristic descriptor complete event
|
||||
**
|
||||
** Parameters:
|
||||
**
|
||||
@@ -2216,7 +2216,7 @@ void bta_hh_le_write_char_descr_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_b
|
||||
**
|
||||
** Function bta_hh_le_input_rpt_notify
|
||||
**
|
||||
** Description process the notificaton event, most likely for input report.
|
||||
** Description process the notification event, most likely for input report.
|
||||
**
|
||||
** Parameters:
|
||||
**
|
||||
@@ -2357,7 +2357,7 @@ void bta_hh_gatt_close(tBTA_HH_DEV_CB *p_cb, tBTA_HH_DATA *p_data)
|
||||
**
|
||||
** Function bta_hh_le_api_disc_act
|
||||
**
|
||||
** Description initaite a Close API to a remote HID device
|
||||
** Description initiate a Close API to a remote HID device
|
||||
**
|
||||
** Returns void
|
||||
**
|
||||
@@ -2601,7 +2601,7 @@ static void bta_hh_le_add_dev_bg_conn(tBTA_HH_DEV_CB *p_cb, BOOLEAN check_bond)
|
||||
if (/*p_cb->dscp_info.flag & BTA_HH_LE_NORMAL_CONN &&*/
|
||||
!p_cb->in_bg_conn && to_add) {
|
||||
/* add device into BG connection to accept remote initiated connection */
|
||||
BTA_GATTC_Open(bta_hh_cb.gatt_if, p_cb->addr, BLE_ADDR_UNKNOWN_TYPE, FALSE, BTA_GATT_TRANSPORT_LE, FALSE);
|
||||
BTA_GATTC_Enh_Open(bta_hh_cb.gatt_if, p_cb->addr, BLE_ADDR_UNKNOWN_TYPE, FALSE, BTA_GATT_TRANSPORT_LE, FALSE, BLE_ADDR_UNKNOWN_TYPE);
|
||||
p_cb->in_bg_conn = TRUE;
|
||||
|
||||
BTA_DmBleSetBgConnType(BTA_DM_BLE_CONN_AUTO, NULL);
|
||||
@@ -2682,7 +2682,7 @@ void bta_hh_le_update_scpp(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf)
|
||||
if (!p_dev_cb->is_le_device ||
|
||||
p_dev_cb->mode != BTA_HH_PROTO_RPT_MODE ||
|
||||
p_dev_cb->scps_supported == FALSE) {
|
||||
APPL_TRACE_ERROR("Can not set ScPP scan paramter as boot host, or remote does not support ScPP ");
|
||||
APPL_TRACE_ERROR("Can not set ScPP scan parameter as boot host, or remote does not support ScPP ");
|
||||
|
||||
cback_data.handle = p_dev_cb->hid_handle;
|
||||
cback_data.status = BTA_HH_ERR;
|
||||
@@ -2908,7 +2908,7 @@ static void bta_hh_le_search_scps_chars(tBTA_HH_DEV_CB *p_cb)
|
||||
**
|
||||
** Function bta_hh_le_register_scpp_notif
|
||||
**
|
||||
** Description register scan parameter refresh notitication complete
|
||||
** Description register scan parameter refresh notification complete
|
||||
**
|
||||
**
|
||||
** Parameters:
|
||||
@@ -2919,7 +2919,7 @@ static void bta_hh_le_register_scpp_notif(tBTA_HH_DEV_CB *p_dev_cb, tBTA_GATT_ST
|
||||
UINT8 sec_flag = 0;
|
||||
tBTA_GATTC_CHAR_ID char_id;
|
||||
|
||||
/* if write scan parameter sucessful */
|
||||
/* if write scan parameter successful */
|
||||
/* if bonded and notification is not enabled, configure the client configuration */
|
||||
if (status == BTA_GATT_OK &&
|
||||
(p_dev_cb->scps_notify & BTA_HH_LE_SCPS_NOTIFY_SPT) != 0 &&
|
||||
@@ -2949,7 +2949,7 @@ static void bta_hh_le_register_scpp_notif(tBTA_HH_DEV_CB *p_dev_cb, tBTA_GATT_ST
|
||||
**
|
||||
** Function bta_hh_le_register_scpp_notif_cmpl
|
||||
**
|
||||
** Description action function to register scan parameter refresh notitication
|
||||
** Description action function to register scan parameter refresh notification
|
||||
**
|
||||
** Parameters:
|
||||
**
|
||||
|
||||
@@ -1512,18 +1512,18 @@ typedef UINT8 tBTA_DM_LINK_TYPE;
|
||||
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_INCLUDE_TX_PWR (1 << 6)
|
||||
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_MASK (0x7F)
|
||||
|
||||
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_IND (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
|
||||
ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE |\
|
||||
ESP_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE)
|
||||
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_LD_DIR (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
|
||||
ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE |\
|
||||
ESP_BLE_GAP_SET_EXT_ADV_PROP_DIRECTED)
|
||||
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_HD_DIR (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
|
||||
ESP_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE |\
|
||||
ESP_BLE_GAP_SET_EXT_ADV_PROP_HD_DIRECTED)
|
||||
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_SCAN (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
|
||||
ESP_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE)
|
||||
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_NONCONN (ESP_BLE_GAP_SET_EXT_ADV_PROP_LEGACY)
|
||||
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_IND (BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
|
||||
BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE |\
|
||||
BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE)
|
||||
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_LD_DIR (BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
|
||||
BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE |\
|
||||
BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_DIRECTED)
|
||||
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_HD_DIR (BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
|
||||
BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_CONNECTABLE |\
|
||||
BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_HD_DIRECTED)
|
||||
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_SCAN (BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY |\
|
||||
BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_SCANNABLE)
|
||||
#define BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY_NONCONN (BTA_DM_BLE_GAP_SET_EXT_ADV_PROP_LEGACY)
|
||||
typedef UINT16 tBTA_DM_BLE_EXT_ADV_TYPE_MASK;
|
||||
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ typedef UINT8 tBTA_GATT_STATUS;
|
||||
#define BTA_GATTC_ADV_VSC_EVT 34 /* ADV VSC event */
|
||||
#define BTA_GATTC_CONNECT_EVT 35 /* GATTC CONNECT event */
|
||||
#define BTA_GATTC_DISCONNECT_EVT 36 /* GATTC DISCONNECT event */
|
||||
#define BTA_GATTC_READ_MULTIPLE_EVT 37 /* GATTC Read mutiple event */
|
||||
#define BTA_GATTC_READ_MULTIPLE_EVT 37 /* GATTC Read multiple event */
|
||||
#define BTA_GATTC_QUEUE_FULL_EVT 38 /* GATTC queue full event */
|
||||
#define BTA_GATTC_ASSOC_EVT 39 /* GATTC association address event */
|
||||
#define BTA_GATTC_GET_ADDR_LIST_EVT 40 /* GATTC get address list in the cache event */
|
||||
@@ -783,9 +783,10 @@ extern void BTA_GATTC_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTC_CBACK *p_clie
|
||||
*******************************************************************************/
|
||||
extern void BTA_GATTC_AppDeregister (tBTA_GATTC_IF client_if);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function BTA_GATTC_Open
|
||||
** Function BTA_GATTC_Enh_Open
|
||||
**
|
||||
** Description Open a direct connection or add a background auto connection
|
||||
** bd address
|
||||
@@ -793,13 +794,14 @@ extern void BTA_GATTC_AppDeregister (tBTA_GATTC_IF client_if);
|
||||
** Parameters client_if: server interface.
|
||||
** remote_bda: remote device BD address.
|
||||
** remote_addr_type: remote device BD address type.
|
||||
** is_direct: direct connection or background auto connection
|
||||
** is_direct: direct connection or background auto connection.
|
||||
** own_addr_type: own address type.
|
||||
**
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
extern void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type,
|
||||
BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport, BOOLEAN is_aux);
|
||||
extern void BTA_GATTC_Enh_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, tBTA_ADDR_TYPE remote_addr_type,
|
||||
BOOLEAN is_direct, tBTA_GATT_TRANSPORT transport, BOOLEAN is_aux, tBTA_ADDR_TYPE own_addr_type);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
@@ -937,8 +939,8 @@ extern void BTA_GATTC_GetGattDb(UINT16 conn_id, UINT16 start_handle, UINT16 end_
|
||||
**
|
||||
** Description This function is called to read a characteristics value
|
||||
**
|
||||
** Parameters conn_id - connectino ID.
|
||||
** handle - characteritic handle to read.
|
||||
** Parameters conn_id - connection ID.
|
||||
** handle - characteristic handle to read.
|
||||
**
|
||||
** Returns None
|
||||
**
|
||||
@@ -953,7 +955,7 @@ void BTA_GATTC_ReadCharacteristic(UINT16 conn_id, UINT16 handle, tBTA_GATT_AUTH_
|
||||
**
|
||||
** Parameters conn_id - connection ID.
|
||||
** s_handle - start handle.
|
||||
** e_handle - end hanle
|
||||
** e_handle - end handle
|
||||
** uuid - The attribute UUID.
|
||||
**
|
||||
** Returns None
|
||||
@@ -1072,7 +1074,7 @@ extern tBTA_GATT_STATUS BTA_GATTC_DeregisterForNotifications (tBTA_GATTC_IF
|
||||
** Description This function is called to prepare write a characteristic value.
|
||||
**
|
||||
** Parameters conn_id - connection ID.
|
||||
** handle - GATT characteritic handle.
|
||||
** handle - GATT characteristic handle.
|
||||
** offset - offset of the write value.
|
||||
** len - length of the data to be written.
|
||||
** p_value - the value to be written.
|
||||
@@ -1094,7 +1096,7 @@ extern void BTA_GATTC_PrepareWrite (UINT16 conn_id,
|
||||
** Description This function is called to prepare write a characteristic descriptor value.
|
||||
**
|
||||
** Parameters conn_id - connection ID.
|
||||
** p_char_descr_id - GATT characteritic descriptor ID of the service.
|
||||
** p_char_descr_id - GATT characteristic descriptor ID of the service.
|
||||
** offset - offset of the write value.
|
||||
** len: length of the data to be written.
|
||||
** p_value - the value to be written.
|
||||
@@ -1238,7 +1240,7 @@ extern void BTA_GATTC_ConfigureMTU (UINT16 conn_id);
|
||||
**
|
||||
** Function BTA_GATTS_Init
|
||||
**
|
||||
** Description This function is called to initalize GATTS module
|
||||
** Description This function is called to initialize GATTS module
|
||||
**
|
||||
** Parameters None
|
||||
**
|
||||
|
||||
@@ -175,8 +175,7 @@ bool btc_avrc_ct_init_p(void)
|
||||
bool btc_avrc_tg_connected_p(void)
|
||||
{
|
||||
return (s_rc_tg_init == BTC_RC_TG_INIT_MAGIC) &&
|
||||
(btc_rc_cb.rc_connected == TRUE) &&
|
||||
(btc_rc_cb.rc_features & BTA_AV_FEAT_RCCT);
|
||||
(btc_rc_cb.rc_connected == TRUE);
|
||||
}
|
||||
|
||||
bool btc_avrc_ct_connected_p(void)
|
||||
@@ -507,7 +506,7 @@ static void handle_rc_connect (tBTA_AV_RC_OPEN *p_rc_open)
|
||||
btc_avrc_ct_cb_to_app(ESP_AVRC_CT_CONNECTION_STATE_EVT, ¶m);
|
||||
}
|
||||
|
||||
if (p_rc_open->peer_features & BTA_AV_FEAT_RCCT) {
|
||||
if (btc_avrc_tg_init_p()) {
|
||||
esp_avrc_tg_cb_param_t param;
|
||||
memset(¶m, 0, sizeof(esp_avrc_tg_cb_param_t));
|
||||
param.conn_stat.connected = true;
|
||||
@@ -580,7 +579,7 @@ static void handle_rc_disconnect (tBTA_AV_RC_CLOSE *p_rc_close)
|
||||
btc_avrc_ct_cb_to_app(ESP_AVRC_CT_CONNECTION_STATE_EVT, ¶m);
|
||||
}
|
||||
|
||||
if (rc_features & BTA_AV_FEAT_RCCT) {
|
||||
if (btc_avrc_tg_init_p()) {
|
||||
esp_avrc_tg_cb_param_t param;
|
||||
memset(¶m, 0, sizeof(esp_avrc_ct_cb_param_t));
|
||||
param.conn_stat.connected = false;
|
||||
@@ -1006,14 +1005,10 @@ void btc_rc_handler(tBTA_AV_EVT event, tBTA_AV *p_data)
|
||||
memcpy(param.conn_stat.remote_bda, btc_rc_cb.rc_addr, sizeof(esp_bd_addr_t));
|
||||
btc_avrc_ct_cb_to_app(ESP_AVRC_CT_CONNECTION_STATE_EVT, ¶m);
|
||||
}
|
||||
if ((p_data->rc_feat.peer_features & BTA_AV_FEAT_RCCT) &&
|
||||
!(old_feats & BTA_AV_FEAT_RCCT)) {
|
||||
esp_avrc_tg_cb_param_t param;
|
||||
memset(¶m, 0, sizeof(esp_avrc_ct_cb_param_t));
|
||||
param.conn_stat.connected = true;
|
||||
memcpy(param.conn_stat.remote_bda, btc_rc_cb.rc_addr, sizeof(esp_bd_addr_t));
|
||||
btc_avrc_tg_cb_to_app(ESP_AVRC_TG_CONNECTION_STATE_EVT, ¶m);
|
||||
}
|
||||
/**
|
||||
* @note ESP_AVRC_TG_CONNECTION_STATE_EVT has been reported on rc connect/disconnect event,
|
||||
* it doesn't rely on the SDP results.
|
||||
*/
|
||||
} while (0);
|
||||
btc_rc_cb.rc_features = p_data->rc_feat.peer_features;
|
||||
btc_rc_cb.rc_ct_features = p_data->rc_feat.peer_ct_features;
|
||||
|
||||
@@ -958,7 +958,7 @@ static void btc_read_ble_rssi_cmpl_callback(void *p_data)
|
||||
}
|
||||
|
||||
#if (BLE_50_FEATURE_SUPPORT == TRUE)
|
||||
static void btc_ble_5_gap_callback(tBTA_DM_BLE_5_GAP_EVENT event,
|
||||
void btc_ble_5_gap_callback(tBTA_DM_BLE_5_GAP_EVENT event,
|
||||
tBTA_DM_BLE_5_GAP_CB_PARAMS *params)
|
||||
{
|
||||
esp_ble_gap_cb_param_t param;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
@@ -212,9 +212,10 @@ static void btc_gattc_app_unregister(btc_ble_gattc_args_t *arg)
|
||||
static void btc_gattc_open(btc_ble_gattc_args_t *arg)
|
||||
{
|
||||
tBTA_GATT_TRANSPORT transport = BTA_GATT_TRANSPORT_LE;
|
||||
BTA_GATTC_Open(arg->open.gattc_if, arg->open.remote_bda,
|
||||
|
||||
BTA_GATTC_Enh_Open(arg->open.gattc_if, arg->open.remote_bda,
|
||||
arg->open.remote_addr_type, arg->open.is_direct,
|
||||
transport, arg->open.is_aux);
|
||||
transport, arg->open.is_aux, arg->open.own_addr_type);
|
||||
}
|
||||
|
||||
static void btc_gattc_close(btc_ble_gattc_args_t *arg)
|
||||
|
||||
@@ -11,11 +11,13 @@
|
||||
#include "esp_gap_ble_api.h"
|
||||
|
||||
#if BTC_DYNAMIC_MEMORY == TRUE
|
||||
#if (BLE_42_FEATURE_SUPPORT == TRUE)
|
||||
#include "bta/bta_api.h"
|
||||
extern tBTA_BLE_ADV_DATA *gl_bta_adv_data_ptr;
|
||||
extern tBTA_BLE_ADV_DATA *gl_bta_scan_rsp_data_ptr;
|
||||
#define gl_bta_adv_data (*gl_bta_adv_data_ptr)
|
||||
#define gl_bta_scan_rsp_data (*gl_bta_scan_rsp_data_ptr)
|
||||
#endif // BLE_42_FEATURE_SUPPORT
|
||||
#endif
|
||||
|
||||
#define BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)))
|
||||
|
||||
@@ -57,6 +57,7 @@ typedef union {
|
||||
esp_ble_addr_type_t remote_addr_type;
|
||||
bool is_direct;
|
||||
bool is_aux;
|
||||
esp_ble_addr_type_t own_addr_type;
|
||||
} open;
|
||||
//BTC_GATTC_ACT_CLOSE,
|
||||
struct close_arg {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user