forked from espressif/esp-idf
Compare commits
620 Commits
Author | SHA1 | Date | |
---|---|---|---|
463a9d8b7f | |||
ef34e6f6f7 | |||
aa51829ec8 | |||
dcd735759e | |||
a36bbd4e95 | |||
3f8a89504f | |||
1d280a0825 | |||
3b13eba1b2 | |||
1f263434a6 | |||
06cc4e888d | |||
0a2371972a | |||
b7a191a996 | |||
beb73456ee | |||
e3d65c8e3e | |||
d11bca44db | |||
6da2676a3c | |||
15aa9bc041 | |||
509ac2cfc1 | |||
8c23bb4aa9 | |||
989dac1e64 | |||
2ea0062fe8 | |||
5cb04f3e13 | |||
16e102199a | |||
2215aeaad8 | |||
51a1421f65 | |||
0cefe6df78 | |||
20e75ef87d | |||
cb1d440cb8 | |||
e5d25fb51e | |||
8306ddf3c1 | |||
93928a5d11 | |||
96a5e34d7a | |||
6bc284f7b7 | |||
daa2178f30 | |||
92b10b4ba3 | |||
69b0919904 | |||
4cbbe6cca3 | |||
edcba21b28 | |||
e8b454e802 | |||
84029130cf | |||
6cbda6bd22 | |||
dae4da07c3 | |||
ca3b2a8909 | |||
95f0553f40 | |||
09935510bd | |||
fb81b516da | |||
d93bff2699 | |||
03addfb0c5 | |||
0631d185bd | |||
65cfbbda52 | |||
6a18a33bad | |||
6f6677ac42 | |||
0e623d4dbf | |||
d41c020649 | |||
b261647835 | |||
53e6eb8467 | |||
ebaa3e1c3e | |||
66889332ce | |||
23770edb43 | |||
6ea738eeb0 | |||
3e6d04fc86 | |||
9dc45e788d | |||
bf712e4f91 | |||
83813f830d | |||
b0d6c01b04 | |||
f955c49423 | |||
1b15e6cf56 | |||
1ad1e70077 | |||
d8665e5343 | |||
46cb254f21 | |||
20e6d46d44 | |||
a89decd3c1 | |||
1e7933049d | |||
626c58fc67 | |||
03d5742e11 | |||
3c081abb32 | |||
482d2f06c3 | |||
4ffa3dbffb | |||
bf0863a50a | |||
20d435c561 | |||
a82215d161 | |||
dcbcb5fe58 | |||
23e6b47a28 | |||
85656ca77d | |||
6f0f5d79f9 | |||
314a0443ad | |||
3ba9eae86c | |||
a8e01de0e4 | |||
0104a24a36 | |||
643757bfad | |||
30ac846112 | |||
8e54ee3f16 | |||
ba11fed9c1 | |||
bf01dd61f7 | |||
ee6ba0eb47 | |||
45a50ed701 | |||
fd481d9cdd | |||
ec8e057e4c | |||
510ec904c9 | |||
fbdedee4cb | |||
f8e1ee35e2 | |||
06aa755265 | |||
48786c1da0 | |||
e9be102224 | |||
3691ebc273 | |||
31b9329d36 | |||
d00acce7b2 | |||
6e05a79536 | |||
978bf09f83 | |||
7a5d17e1b7 | |||
d3e0301aee | |||
69c0e6243e | |||
cffe7bf3a1 | |||
1041bc800c | |||
dd74a331c7 | |||
6ee7492512 | |||
9bf656e12e | |||
6ae4c29191 | |||
3fcecdd12e | |||
f3c8907cef | |||
7db756fbd9 | |||
1d72766f1a | |||
5d03ae7428 | |||
bfbc10e2d8 | |||
1fd0e6f482 | |||
21995978e1 | |||
e0b6ad0d1a | |||
2b5a8fe5ea | |||
bb7e52a4a8 | |||
c0597aaf69 | |||
87c30adfed | |||
3636bf5813 | |||
ea2959af36 | |||
585654388f | |||
939d5a0f6a | |||
4d3c650b49 | |||
2318e6828d | |||
262acbc0a8 | |||
2b2f0d0f28 | |||
2887131b39 | |||
104299353d | |||
19d394a366 | |||
e4312f8ab5 | |||
1930c56bd2 | |||
5e67f9578d | |||
46a172178a | |||
e6006a6bdf | |||
a5b803540a | |||
673ccaa1e5 | |||
08e55b8a66 | |||
0508ad525a | |||
97defec6cd | |||
96e6049dab | |||
37154d4c08 | |||
14dd44c05f | |||
42a462d584 | |||
c68bd605f8 | |||
f37837f785 | |||
69c86bc37e | |||
14f1a30e38 | |||
afeed3cc6f | |||
139913baa2 | |||
e324013ed6 | |||
8d189d9fb4 | |||
e7a6fdca54 | |||
48dfbe05a4 | |||
5d00321d07 | |||
2e8ad19e35 | |||
c45830d03f | |||
7725ce4999 | |||
97488fe806 | |||
e3f0854771 | |||
b5d04a21fb | |||
337b1df430 | |||
41e64bd79c | |||
2b7681ec4f | |||
668c0dfb9b | |||
0b0f8d6d6c | |||
a8f956e590 | |||
3b879ce8c3 | |||
5102308b2b | |||
f95a723412 | |||
88cbc26f4d | |||
1b53af2e88 | |||
376107b2ae | |||
c9294aff6f | |||
99fb9a3f7c | |||
e5773cc2fe | |||
4e6c575fed | |||
8353ecdf36 | |||
5bb0b39700 | |||
9214c887f7 | |||
ebc2e7bce0 | |||
065e386c57 | |||
c595b2fa8c | |||
eb95bc68c4 | |||
2b208eecde | |||
f9f49107ca | |||
fae116bb2e | |||
8d90156c07 | |||
f22d46515b | |||
27cb3d7f72 | |||
e0e62232e0 | |||
a302d210b9 | |||
a32c72a1b2 | |||
f1850b54f3 | |||
c85abf87b5 | |||
9029ccd21b | |||
eaeb36375a | |||
805bc06127 | |||
4702cd1b51 | |||
720528ef11 | |||
d934badaa7 | |||
35b91ebf2d | |||
6c7f72cc1b | |||
7061c8aec2 | |||
3ba8ae7a62 | |||
2c27c55679 | |||
68ad6ad63a | |||
981b2496cb | |||
077b727608 | |||
79f36e85d5 | |||
d49077c13b | |||
0c2202ef3e | |||
e4137cc6ca | |||
308e4fcce1 | |||
a6d40e3583 | |||
95b5745c3c | |||
bc3134594d | |||
8300945189 | |||
c9ca3a05fc | |||
ecce2bc926 | |||
b69898257a | |||
22548d0ea4 | |||
088ac409d7 | |||
14ce4cde2e | |||
83cd515817 | |||
d48d9a1c88 | |||
f54cab62a2 | |||
c64d4236fb | |||
90568fbf00 | |||
475a746e46 | |||
947fc14a3f | |||
6f6629e568 | |||
4c4b1da7e7 | |||
9cc272978c | |||
5cb6a49c1e | |||
56d1e4411e | |||
05510e513b | |||
5e042803a2 | |||
74d06101b1 | |||
2cd3018c0a | |||
1a8e5a40d6 | |||
b529c6f282 | |||
7a05879024 | |||
1611386431 | |||
6181686489 | |||
0562281353 | |||
8bc1f6e2f5 | |||
dd99a6dbe8 | |||
5a686d7ad1 | |||
0ca0e7d3cc | |||
f06ef95610 | |||
0078896347 | |||
44599d3a84 | |||
0fa7dcb946 | |||
d3a8dcb929 | |||
4e8c1b91c0 | |||
4ed0d006b4 | |||
e85804824e | |||
304f6a577a | |||
29690afc57 | |||
98450e80e5 | |||
1007473a3b | |||
e875f59ed5 | |||
4f946ea00e | |||
666f87109f | |||
154f315a49 | |||
b175ec77ad | |||
f9fa039826 | |||
b54528696a | |||
fae64f79bb | |||
4f297ed3fa | |||
8eaa440221 | |||
56d5548747 | |||
665a341147 | |||
cab589af9d | |||
19e355e080 | |||
1cf2da8d67 | |||
744625f234 | |||
5e505898df | |||
3a1d0e9352 | |||
8afd0de501 | |||
1f7a66a22e | |||
bcc19b7826 | |||
0a03a55c1e | |||
61f26c985e | |||
165e778d7e | |||
859ddcdb63 | |||
c599d7aa49 | |||
da636bd4ac | |||
834893d8e4 | |||
059052acaa | |||
996db972f0 | |||
4ddc6916c3 | |||
c06519a759 | |||
f1e8a49836 | |||
09cc922b42 | |||
34c33f7440 | |||
5464aaac45 | |||
054e2dbb44 | |||
59a186b27e | |||
62a609190d | |||
9f1d992ef9 | |||
7cb3d5bc4a | |||
de27a71a56 | |||
ed8ddf7e76 | |||
3860753818 | |||
2056b891d3 | |||
c6a6740e3f | |||
dd1615d57c | |||
106f066254 | |||
32b8b60dc5 | |||
4283b59dde | |||
be894757ff | |||
3d0466ccd1 | |||
92adc524a2 | |||
0fc30f4379 | |||
905fdbc1ad | |||
3a115a1ad2 | |||
019c72e4fc | |||
21ecf51a40 | |||
3c97f7e42e | |||
de9b0b1c56 | |||
57a13b09cc | |||
6a60c4a046 | |||
f96c02adac | |||
9351ae7dc9 | |||
2cde888a6d | |||
c94434917d | |||
fb32429387 | |||
1cc6d2ef62 | |||
128d650d7d | |||
090dd78355 | |||
706df7ab12 | |||
cfa355c705 | |||
a87e699104 | |||
7566bfb548 | |||
57335cfc26 | |||
7a6faa093b | |||
a389312750 | |||
7d267a340f | |||
783ef22dd3 | |||
4f193dfa71 | |||
c875e5698a | |||
4cafa3e76e | |||
1e5ea2827c | |||
cf5331b9f1 | |||
28a2e6a775 | |||
34a327791c | |||
8bcf5a19d5 | |||
66a46de2a7 | |||
bcd496be49 | |||
79923d0199 | |||
858b3d2277 | |||
dedaf624db | |||
9ca33a260f | |||
abdf12dc9e | |||
10d26549fa | |||
26676c2b8f | |||
d9cfb05eb6 | |||
4322e89006 | |||
96748f3037 | |||
5a94142481 | |||
e5ff431b35 | |||
c225801b3e | |||
610e3cac31 | |||
c776991233 | |||
041fcceddf | |||
899957f521 | |||
815d7674ef | |||
57527ba6f9 | |||
a21eb04cc6 | |||
116d0c8145 | |||
dda49709fe | |||
ebffa5f9f2 | |||
fc738680f8 | |||
1c586ebcfd | |||
499accb652 | |||
988147a451 | |||
9e6c56f9f2 | |||
1b6eb69f53 | |||
daa65b6f91 | |||
7f9626d378 | |||
6cad60f34b | |||
b4c7ed999c | |||
8a5c08df98 | |||
b1eac64865 | |||
4e7b559101 | |||
43616f6f05 | |||
3b9ab9caa6 | |||
0dc9ddb77c | |||
9ab92331c4 | |||
08416d05ba | |||
200c82561a | |||
2e05c6020f | |||
d139c851f3 | |||
365e3fd685 | |||
71fad5e2c0 | |||
94ba3a20cb | |||
5a7d3ef319 | |||
e4a4e6ed81 | |||
8094e880c6 | |||
35b9223cf4 | |||
fe97d14e0f | |||
2c16557ee7 | |||
5f8e5db268 | |||
a9fe3165c4 | |||
b01036e13e | |||
10649ae23b | |||
c4306f7942 | |||
62be877ada | |||
546026d018 | |||
05d3665a14 | |||
0bba92b2a0 | |||
399477cd10 | |||
d3b54ec84a | |||
e4b44f3488 | |||
ca80b0445d | |||
1e01accaa4 | |||
2ca3735edd | |||
b9a2639ab4 | |||
77f186a7b9 | |||
89e848c820 | |||
5e0cc123ee | |||
536c131114 | |||
ef17d8bba1 | |||
3194e12479 | |||
bb52613bea | |||
4ee065df79 | |||
63c2834d7b | |||
dbf2c3d480 | |||
582d5de497 | |||
5a351af83f | |||
a6fc9bf246 | |||
d52b244ae8 | |||
00e3cb672b | |||
67eb732dbe | |||
c53a5ee427 | |||
69241907a5 | |||
d4ee21bd6d | |||
5b69614e32 | |||
3e12967535 | |||
d9f1219a21 | |||
f3fc4916d2 | |||
b17ca9cb38 | |||
801010dac6 | |||
f84394e550 | |||
a0256b9e9d | |||
a37694741c | |||
fae124a2c1 | |||
ad100e497a | |||
da8c09c463 | |||
6df148aa54 | |||
3fc9b022b6 | |||
28ee1c0da2 | |||
05b306bae1 | |||
8dbb2083ea | |||
a8590c7e8e | |||
8876cda09b | |||
cec1c5f856 | |||
a7107d9bbd | |||
850684438b | |||
9d00f3b420 | |||
72264ca9b9 | |||
da2025a74a | |||
93bad7a0de | |||
55f687c763 | |||
329388fa47 | |||
0f36dabcaf | |||
0299e22dd0 | |||
f072c5af4e | |||
6982663380 | |||
1d970ad276 | |||
a73cc70af9 | |||
225ee8e5d1 | |||
fa4cd56d00 | |||
15f8b0fccc | |||
97080afba2 | |||
612822d8c9 | |||
ff6cb921c3 | |||
6f7b7c552d | |||
e00186e683 | |||
a734b3b1bc | |||
6de637811f | |||
6ec0c6743a | |||
299c86cc84 | |||
d123f6c04b | |||
3c17bf1a6f | |||
8fb20e4529 | |||
e020d1055a | |||
05e4b28a74 | |||
27bc688ed8 | |||
a214fb2821 | |||
6b7b9d1550 | |||
18b873b2e3 | |||
d1755c1484 | |||
152ebb104d | |||
e3b304997f | |||
1e20ed4849 | |||
59b663c43d | |||
e9e28c1265 | |||
7030d612e2 | |||
2c852b0d74 | |||
708bff3b17 | |||
317f4c5ff5 | |||
2c025824d7 | |||
9b95064018 | |||
ecdffe531e | |||
31be6be147 | |||
305a4a1b57 | |||
e659f1b15a | |||
2c49592216 | |||
6afb2743e7 | |||
f7b458841f | |||
f1e9b8299f | |||
9ce1b8986a | |||
c5bea8dddb | |||
ba6b502cc9 | |||
3b0b5f92a7 | |||
d6bc1b3cbc | |||
199c4e55f2 | |||
61339353e9 | |||
3b2dda5197 | |||
1b8ed9abf0 | |||
f9453ef93d | |||
dcf571c1cd | |||
538c56426a | |||
1402e78844 | |||
01f0c8ef16 | |||
a774406b91 | |||
c9bff93080 | |||
4b8e4ff248 | |||
9dbf979cf3 | |||
ad70ab8957 | |||
cd5dc4d05f | |||
ebb9384681 | |||
0d3fde04ff | |||
0552ec5791 | |||
524eef9225 | |||
955f7e2877 | |||
e28834aa15 | |||
ac03786412 | |||
a5dae2ff43 | |||
1d0142d25d | |||
65ef597da6 | |||
310beae373 | |||
cf0caaec11 | |||
4af9504a65 | |||
64bece146c | |||
6b348b94e3 | |||
6222040888 | |||
ea1037742d | |||
465d46e9dd | |||
e71e4da388 | |||
c711e969cc | |||
3f1ec39a8d | |||
f62798cb8b | |||
b6c89984a9 | |||
520ecb0c4d | |||
b669495d97 | |||
8778c551eb | |||
c34d313a86 | |||
ebcb3a22b8 | |||
6781d01e89 | |||
4c9f30a869 | |||
61ba1c3026 | |||
90bbea65c1 | |||
672e9f4abc | |||
cb3d458050 | |||
b72ff61899 | |||
83b9727c42 | |||
7bb8b5ba9e | |||
1f5f6adcb6 | |||
aa0bb29404 | |||
2264ea7714 | |||
a626b26cf9 | |||
1cc860216e | |||
16ee476a77 | |||
674ecc3b56 | |||
43efee5232 | |||
5dab23ea98 | |||
79afd2d580 | |||
a8e8919bbf | |||
ba0f4f17ed | |||
a63b3c4fe6 | |||
6b8c75d87c | |||
68d82abe52 | |||
ec31f235e9 | |||
7e9d90b180 | |||
d4fcbe37f3 | |||
b9a5f764ba | |||
764b70d7e6 | |||
a1496b90e5 | |||
622d6d5504 | |||
1b903111b6 | |||
69ef694178 | |||
81651b47a4 | |||
30dc86179c | |||
eff3ac05b3 | |||
e5349d47a8 | |||
4253adf42b | |||
088ed65194 | |||
0ce94950b7 | |||
ae8b2684d7 | |||
9c51f679a7 | |||
5c07acad46 | |||
70af759dd2 | |||
76191a0f55 | |||
f0c3114f2f |
@ -22,11 +22,18 @@ variables:
|
||||
# GIT_STRATEGY is not defined here.
|
||||
# Use an option from "CI / CD Settings" - "General pipelines".
|
||||
|
||||
# "normal" strategy for fetching only top-level submodules since nothing requires the sub-submodules code for building IDF.
|
||||
# If the "recursive" strategy is used we have a problem with using relative URLs for sub-submodules.
|
||||
GIT_SUBMODULE_STRATEGY: normal
|
||||
# we will download archive for each submodule instead of clone.
|
||||
# we don't do "recursive" when fetch submodule as they're not used in CI now.
|
||||
GIT_SUBMODULE_STRATEGY: none
|
||||
SUBMODULE_FETCH_TOOL: "tools/ci/ci_fetch_submodule.py"
|
||||
# by default we will fetch all submodules
|
||||
# jobs can overwrite this variable to only fetch submodules they required
|
||||
# set to "none" if don't need to fetch submodules
|
||||
SUBMODULES_TO_FETCH: "all"
|
||||
# tell build system do not check submodule update as we download archive instead of clone
|
||||
IDF_SKIP_CHECK_SUBMODULES: 1
|
||||
|
||||
UNIT_TEST_BUILD_SYSTEM: make
|
||||
UNIT_TEST_BUILD_SYSTEM: cmake
|
||||
# IDF environment
|
||||
|
||||
IDF_PATH: "$CI_PROJECT_DIR"
|
||||
@ -42,6 +49,7 @@ variables:
|
||||
CI_TARGET_TEST_CONFIG_FILE: "$CI_PROJECT_DIR/tools/ci/config/target-test.yml"
|
||||
|
||||
|
||||
|
||||
# before each job, we need to check if this job is filtered by bot stage/job filter
|
||||
.apply_bot_filter: &apply_bot_filter
|
||||
python $APPLY_BOT_FILTER_SCRIPT || exit 0
|
||||
@ -70,12 +78,10 @@ variables:
|
||||
tools/idf_tools.py --non-interactive install && eval "$(tools/idf_tools.py --non-interactive export)" || exit 1
|
||||
fi
|
||||
|
||||
.show_submodule_urls: &show_submodule_urls |
|
||||
git config --get-regexp '^submodule\..*\.url$' || true
|
||||
.fetch_submodules: &fetch_submodules |
|
||||
python $SUBMODULE_FETCH_TOOL -s $SUBMODULES_TO_FETCH
|
||||
|
||||
before_script:
|
||||
- echo "Running common script"
|
||||
- *show_submodule_urls
|
||||
- source tools/ci/setup_python.sh
|
||||
# apply bot filter in before script
|
||||
- *apply_bot_filter
|
||||
@ -91,6 +97,8 @@ before_script:
|
||||
|
||||
- *setup_tools_unless_target_test
|
||||
|
||||
- *fetch_submodules
|
||||
|
||||
- *setup_custom_toolchain
|
||||
|
||||
# used for check scripts which we want to run unconditionally
|
||||
|
@ -5,6 +5,7 @@ unset(compile_options)
|
||||
unset(c_compile_options)
|
||||
unset(cxx_compile_options)
|
||||
unset(compile_definitions)
|
||||
unset(link_options)
|
||||
|
||||
# Add the following build specifications here, since these seem to be dependent
|
||||
# on config values on the root Kconfig.
|
||||
@ -22,6 +23,13 @@ else()
|
||||
list(APPEND cxx_compile_options "-fno-exceptions")
|
||||
endif()
|
||||
|
||||
if(CONFIG_COMPILER_CXX_RTTI)
|
||||
list(APPEND cxx_compile_options "-frtti")
|
||||
else()
|
||||
list(APPEND cxx_compile_options "-fno-rtti")
|
||||
list(APPEND link_options "-fno-rtti") # used to invoke correct multilib variant (no-rtti) during linking
|
||||
endif()
|
||||
|
||||
if(CONFIG_COMPILER_DISABLE_GCC8_WARNINGS)
|
||||
list(APPEND compile_options "-Wno-parentheses"
|
||||
"-Wno-sizeof-pointer-memaccess"
|
||||
@ -54,11 +62,13 @@ elseif(CONFIG_COMPILER_STACK_CHECK_MODE_ALL)
|
||||
list(APPEND compile_options "-fstack-protector-all")
|
||||
endif()
|
||||
|
||||
list(APPEND link_options "-fno-lto")
|
||||
|
||||
idf_build_set_property(COMPILE_OPTIONS "${compile_options}" APPEND)
|
||||
idf_build_set_property(C_COMPILE_OPTIONS "${c_compile_options}" APPEND)
|
||||
idf_build_set_property(CXX_COMPILE_OPTIONS "${cxx_compile_options}" APPEND)
|
||||
idf_build_set_property(COMPILE_DEFINITIONS "${compile_definitions}" APPEND)
|
||||
idf_build_set_property(LINK_OPTIONS "${link_options}" APPEND)
|
||||
|
||||
idf_build_get_property(build_component_targets __BUILD_COMPONENT_TARGETS)
|
||||
|
||||
|
13
Kconfig
13
Kconfig
@ -29,6 +29,10 @@ mainmenu "Espressif IoT Development Framework Configuration"
|
||||
default "IDF_TARGET_NOT_SET" if IDF_TARGET_ENV=""
|
||||
default IDF_TARGET_ENV
|
||||
|
||||
config IDF_FIRMWARE_CHIP_ID
|
||||
hex
|
||||
default 0x0000 if IDF_TARGET="esp32"
|
||||
default 0xFFFF
|
||||
|
||||
menu "SDK tool configuration"
|
||||
config SDK_TOOLPREFIX
|
||||
@ -145,6 +149,15 @@ mainmenu "Espressif IoT Development Framework Configuration"
|
||||
Size (in bytes) of the emergency memory pool for C++ exceptions. This pool will be used to allocate
|
||||
memory for thrown exceptions when there is not enough memory on the heap.
|
||||
|
||||
config COMPILER_CXX_RTTI
|
||||
# Invisible option, until the toolchain with RTTI support is released.
|
||||
# Use prompt "Enable C++ run-time type info (RTTI)" when updating.
|
||||
bool
|
||||
help
|
||||
Enabling this option compiles all C++ files with RTTI support enabled.
|
||||
This increases binary size (typically by tens of kB) but allows using
|
||||
dynamic_cast conversion and typeid operator.
|
||||
|
||||
choice COMPILER_STACK_CHECK_MODE
|
||||
prompt "Stack smashing protection mode"
|
||||
default COMPILER_STACK_CHECK_MODE_NONE
|
||||
|
@ -39,7 +39,7 @@ See the Getting Started guide links above for a detailed setup guide. This is a
|
||||
|
||||
* Install host build dependencies mentioned in Getting Started guide.
|
||||
* Add `tools/` directory to the PATH
|
||||
* Run `python -m pip install requirements.txt` to install Python dependencies
|
||||
* Run `python -m pip install -r requirements.txt` to install Python dependencies
|
||||
|
||||
## Configuring the Project
|
||||
|
||||
|
66
SUPPORT_POLICY.md
Normal file
66
SUPPORT_POLICY.md
Normal file
@ -0,0 +1,66 @@
|
||||
The latest support policy for ESP-IDF can be found at [https://github.com/espressif/esp-idf/blob/master/SUPPORT_POLICY.md](https://github.com/espressif/esp-idf/blob/master/SUPPORT_POLICY.md)
|
||||
|
||||
Support Period Policy
|
||||
=====================
|
||||
|
||||
Each ESP-IDF major and minor release (V4.0, V4.1, etc) is supported for
|
||||
18 months after the initial stable release date.
|
||||
|
||||
Supported means that the ESP-IDF team will continue to apply bug fixes,
|
||||
security fixes, etc to the release branch on GitHub, and periodically
|
||||
make new bugfix releases as needed.
|
||||
|
||||
Users are encouraged to upgrade to a newer ESP-IDF release before the
|
||||
support period finishes and the release becomes End of Life (EOL). It is
|
||||
our policy to not continue fixing bugs in End of Life releases.
|
||||
|
||||
Pre-release versions (betas, previews, `-rc` and `-dev` versions, etc)
|
||||
are not covered by any support period. Sometimes a particular feature is
|
||||
marked as \"Preview\" in a release, which means it is also not covered
|
||||
by the support period.
|
||||
|
||||
The ESP-IDF Programming Guide has information about the
|
||||
[different versions of ESP-IDF](https://docs.espressif.com/projects/esp-idf/en/latest/versions.html)
|
||||
(major, minor, bugfix, etc).
|
||||
|
||||
Long Term Support releases
|
||||
--------------------------
|
||||
|
||||
Some releases (starting with ESP-IDF V3.3) are designated Long Term
|
||||
Support (LTS). LTS releases are supported for 30 months (2.5 years)
|
||||
after the initial stable release date.
|
||||
|
||||
A new LTS release will be made at least every 18 months. This means
|
||||
there will always be a period of at least 12 months to upgrade from the
|
||||
previous LTS release to the following LTS release.
|
||||
|
||||
Example
|
||||
-------
|
||||
|
||||
ESP-IDF V3.3 was released in September 2019 and is a Long Term Support
|
||||
(LTS) release, meaning it will be supported for 30 months until February
|
||||
2022.
|
||||
|
||||
- The first V3.3 release was `v3.3` in September 2019.
|
||||
- The ESP-IDF team continues to backport bug fixes, security fixes,
|
||||
etc to the release branch `release/v3.3`.
|
||||
- Periodically stable bugfix releases are created from the release
|
||||
branch. For example `v3.3.1`, `v3.3.2`, etc. Users are encouraged to
|
||||
always update to the latest bugfix release.
|
||||
- V3.3 bugfix releases continue until February 2022, when all V3.3.x
|
||||
releases become End of Life.
|
||||
|
||||
Existing Releases
|
||||
-----------------
|
||||
|
||||
ESP-IDF release V3.3 and all newer releases will follow this support
|
||||
period policy. The support period for each release will be announced
|
||||
when the release is made.
|
||||
|
||||
For releases made before the support period policy was announced,
|
||||
the following support periods apply:
|
||||
|
||||
- ESP-IDF V3.1.x and V3.2.x will both be supported until October 2020.
|
||||
- ESP-IDF V3.0.9 (planned for October 2019) will be the last V3.0
|
||||
bugfix release. ESP-IDF V3.0.x is End of Life from October 2019.
|
||||
- ESP-IDF versions before V3.0 are already End of Life.
|
@ -40,9 +40,6 @@ read_otadata: $(PARTITION_TABLE_CSV_PATH) partition_table_get_info | check_pytho
|
||||
--partition-table-offset $(partition_table_offset) \
|
||||
read_otadata
|
||||
|
||||
erase_ota: erase_otadata
|
||||
@echo "WARNING: erase_ota is deprecated. Use erase_otadata instead."
|
||||
|
||||
all: blank_ota_data
|
||||
flash: blank_ota_data
|
||||
ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
|
||||
|
@ -42,7 +42,7 @@
|
||||
#include "esp_efuse.h"
|
||||
|
||||
|
||||
#define SUB_TYPE_ID(i) (i & 0x0F)
|
||||
#define SUB_TYPE_ID(i) (i & 0x0F)
|
||||
|
||||
typedef struct ota_ops_entry_ {
|
||||
uint32_t handle;
|
||||
@ -200,7 +200,7 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size)
|
||||
// must erase the partition before writing to it
|
||||
assert(it->erased_size > 0 && "must erase the partition before writing to it");
|
||||
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]);
|
||||
ESP_LOGE(TAG, "OTA image has invalid magic byte (expected 0xE9, saw 0x%02x)", data_bytes[0]);
|
||||
return ESP_ERR_OTA_VALIDATE_FAILED;
|
||||
}
|
||||
|
||||
|
@ -444,7 +444,7 @@ static void test_flow4(void)
|
||||
// 2 Stage: run factory -> check it -> copy factory to OTA0 -> reboot --//--
|
||||
// 3 Stage: run OTA0 -> check it -> set_pin_factory_reset -> reboot --//--
|
||||
// 4 Stage: run factory -> check it -> erase OTA_DATA for next tests -> PASS
|
||||
TEST_CASE_MULTIPLE_STAGES("Switching between factory, OTA0, sets pin_factory_reset, factory", "[app_update][timeout=90][reset=DEEPSLEEP_RESET, DEEPSLEEP_RESET, DEEPSLEEP_RESET]", start_test, test_flow4, test_flow4, test_flow4);
|
||||
TEST_CASE_MULTIPLE_STAGES("Switching between factory, OTA0, sets pin_factory_reset, factory", "[app_update][timeout=90][ignore][reset=DEEPSLEEP_RESET, DEEPSLEEP_RESET, DEEPSLEEP_RESET]", start_test, test_flow4, test_flow4, test_flow4);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BOOTLOADER_APP_TEST
|
||||
@ -487,7 +487,7 @@ static void test_flow5(void)
|
||||
// 2 Stage: run factory -> check it -> copy factory to Test and set pin_test_app -> reboot --//--
|
||||
// 3 Stage: run test -> check it -> reset pin_test_app -> reboot --//--
|
||||
// 4 Stage: run factory -> check it -> erase OTA_DATA for next tests -> PASS
|
||||
TEST_CASE_MULTIPLE_STAGES("Switching between factory, test, factory", "[app_update][timeout=90][reset=DEEPSLEEP_RESET, DEEPSLEEP_RESET, DEEPSLEEP_RESET]", start_test, test_flow5, test_flow5, test_flow5);
|
||||
TEST_CASE_MULTIPLE_STAGES("Switching between factory, test, factory", "[app_update][timeout=90][ignore][reset=DEEPSLEEP_RESET, DEEPSLEEP_RESET, DEEPSLEEP_RESET]", start_test, test_flow5, test_flow5, test_flow5);
|
||||
#endif
|
||||
|
||||
static const esp_partition_t* app_update(void)
|
||||
|
@ -338,7 +338,7 @@ menu "Security features"
|
||||
config SECURE_BOOT_SIGNING_KEY
|
||||
string "Secure boot private signing key"
|
||||
depends on SECURE_BOOT_BUILD_SIGNED_BINARIES
|
||||
default secure_boot_signing_key.pem
|
||||
default "secure_boot_signing_key.pem"
|
||||
help
|
||||
Path to the key file used to sign app images.
|
||||
|
||||
@ -354,7 +354,7 @@ menu "Security features"
|
||||
config SECURE_BOOT_VERIFICATION_KEY
|
||||
string "Secure boot public signature verification key"
|
||||
depends on SECURE_SIGNED_APPS && !SECURE_BOOT_BUILD_SIGNED_BINARIES
|
||||
default signature_verification_key.bin
|
||||
default "signature_verification_key.bin"
|
||||
help
|
||||
Path to a public key file used to verify signed images. This key is compiled into the bootloader and/or
|
||||
app, to verify app images.
|
||||
@ -368,7 +368,7 @@ menu "Security features"
|
||||
choice SECURE_BOOTLOADER_KEY_ENCODING
|
||||
bool "Hardware Key Encoding"
|
||||
depends on SECURE_BOOTLOADER_REFLASHABLE
|
||||
default SECURE_BOOTLOADER_NO_ENCODING
|
||||
default SECURE_BOOTLOADER_KEY_ENCODING_256BIT
|
||||
help
|
||||
|
||||
In reflashable secure bootloader mode, a hardware key is derived from the signing key (with SHA-256) and
|
||||
@ -515,6 +515,20 @@ menu "Security features"
|
||||
|
||||
Only set this option in testing environments.
|
||||
|
||||
config SECURE_FLASH_REQUIRE_ALREADY_ENABLED
|
||||
bool "Require flash encryption to be already enabled"
|
||||
depends on SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
|
||||
default N
|
||||
help
|
||||
If not set (default), and flash encryption is not yet enabled in eFuses, the 2nd stage bootloader
|
||||
will enable flash encryption: generate the flash encryption key and program eFuses.
|
||||
If this option is set, and flash encryption is not yet enabled, the bootloader will error out and
|
||||
reboot.
|
||||
If flash encryption is enabled in eFuses, this option does not change the bootloader behavior.
|
||||
|
||||
Only use this option in testing environments, to avoid accidentally enabling flash encryption on
|
||||
the wrong device. The device needs to have flash encryption already enabled using espefuse.py.
|
||||
|
||||
endmenu # Potentially Insecure
|
||||
endmenu # Security features
|
||||
|
||||
|
@ -75,7 +75,8 @@ if(CONFIG_SECURE_BOOTLOADER_REFLASHABLE)
|
||||
add_custom_command(OUTPUT "${bootloader_digest_bin}"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "DIGEST ${bootloader_digest_bin}"
|
||||
COMMAND ${ESPSECUREPY} digest_secure_bootloader --keyfile "${secure_bootloader_key}"
|
||||
-o "${bootloader_digest_bin}" "${CMAKE_BINARY_DIR}/bootloader.bin"
|
||||
-o "${bootloader_digest_bin}" "${CMAKE_BINARY_DIR}/bootloader.bin"
|
||||
MAIN_DEPENDENCY "${CMAKE_BINARY_DIR}/.bin_timestamp"
|
||||
DEPENDS gen_secure_bootloader_key gen_project_binary
|
||||
VERBATIM)
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "bootloader_common.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_image_format.h"
|
||||
#include "esp32/rom/rtc.h"
|
||||
|
||||
static const char* TAG = "boot";
|
||||
|
||||
@ -74,7 +75,8 @@ static int selected_boot_partition(const bootloader_state_t *bs)
|
||||
int boot_index = bootloader_utility_get_selected_boot_partition(bs);
|
||||
if (boot_index == INVALID_INDEX) {
|
||||
return boot_index; // Unrecoverable failure (not due to corrupt ota data or bad partition contents)
|
||||
} else {
|
||||
}
|
||||
if (rtc_get_reset_reason(0) != DEEPSLEEP_RESET) {
|
||||
// Factory firmware.
|
||||
#ifdef CONFIG_BOOTLOADER_FACTORY_RESET
|
||||
if (bootloader_common_check_long_hold_gpio(CONFIG_BOOTLOADER_NUM_PIN_FACTORY_RESET, CONFIG_BOOTLOADER_HOLD_TIME_GPIO) == 1) {
|
||||
|
@ -40,6 +40,7 @@ SECTIONS
|
||||
*(.iram1 .iram1.*) /* catch stray IRAM_ATTR */
|
||||
*liblog.a:(.literal .text .literal.* .text.*)
|
||||
*libgcc.a:(.literal .text .literal.* .text.*)
|
||||
*libbootloader_support.a:bootloader_clock.*(.literal .text .literal.* .text.*)
|
||||
*libbootloader_support.a:bootloader_common.*(.literal .text .literal.* .text.*)
|
||||
*libbootloader_support.a:bootloader_flash.*(.literal .text .literal.* .text.*)
|
||||
*libbootloader_support.a:bootloader_random.*(.literal .text .literal.* .text.*)
|
||||
@ -53,6 +54,7 @@ SECTIONS
|
||||
*libmicro-ecc.a:*.*(.literal .text .literal.* .text.*)
|
||||
*libspi_flash.a:*.*(.literal .text .literal.* .text.*)
|
||||
*libsoc.a:rtc_wdt.*(.literal .text .literal.* .text.*)
|
||||
*libsoc.a:rtc_clk.*(.literal .text .literal.* .text.*)
|
||||
*libefuse.a:*.*(.literal .text .literal.* .text.*)
|
||||
*(.fini.literal)
|
||||
*(.fini)
|
||||
|
@ -36,30 +36,60 @@ idf_component_register(SRCS "${srcs}"
|
||||
REQUIRES "${requires}"
|
||||
PRIV_REQUIRES "${priv_requires}")
|
||||
|
||||
if(BOOTLOADER_BUILD AND CONFIG_SECURE_SIGNED_APPS)
|
||||
# Whether CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES or not, we need verification key to embed
|
||||
# in the library.
|
||||
if(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
|
||||
# We generate the key from the signing key. The signing key is passed from the main project.
|
||||
get_filename_component(secure_boot_signing_key
|
||||
"${SECURE_BOOT_SIGNING_KEY}"
|
||||
ABSOLUTE BASE_DIR "${project_dir}")
|
||||
get_filename_component(secure_boot_verification_key
|
||||
"signature_verification_key.bin"
|
||||
ABSOLUTE BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
add_custom_command(OUTPUT "${secure_boot_verification_key}"
|
||||
COMMAND ${ESPSECUREPY}
|
||||
if(CONFIG_SECURE_SIGNED_APPS)
|
||||
if(BOOTLOADER_BUILD)
|
||||
# Whether CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES or not, we need verification key to embed
|
||||
# in the library.
|
||||
if(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
|
||||
# We generate the key from the signing key. The signing key is passed from the main project.
|
||||
get_filename_component(secure_boot_signing_key
|
||||
"${SECURE_BOOT_SIGNING_KEY}"
|
||||
ABSOLUTE BASE_DIR "${project_dir}")
|
||||
get_filename_component(secure_boot_verification_key
|
||||
"signature_verification_key.bin"
|
||||
ABSOLUTE BASE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
add_custom_command(OUTPUT "${secure_boot_verification_key}"
|
||||
COMMAND ${ESPSECUREPY}
|
||||
extract_public_key --keyfile "${secure_boot_signing_key}"
|
||||
"${secure_boot_verification_key}"
|
||||
VERBATIM)
|
||||
else()
|
||||
# We expect to 'inherit' the verification key passed from main project.
|
||||
get_filename_component(secure_boot_verification_key
|
||||
${SECURE_BOOT_VERIFICATION_KEY}
|
||||
ABSOLUTE BASE_DIR "${project_dir}")
|
||||
DEPENDS ${secure_boot_signing_key}
|
||||
VERBATIM)
|
||||
else()
|
||||
# We expect to 'inherit' the verification key passed from main project.
|
||||
get_filename_component(secure_boot_verification_key
|
||||
${SECURE_BOOT_VERIFICATION_KEY}
|
||||
ABSOLUTE BASE_DIR "${project_dir}")
|
||||
endif()
|
||||
else() # normal app build
|
||||
idf_build_get_property(project_dir PROJECT_DIR)
|
||||
|
||||
if(CONFIG_SECURE_BOOT_VERIFICATION_KEY)
|
||||
# verification-only build supplies verification key
|
||||
set(secure_boot_verification_key ${CONFIG_SECURE_BOOT_VERIFICATION_KEY})
|
||||
get_filename_component(secure_boot_verification_key
|
||||
${secure_boot_verification_key}
|
||||
ABSOLUTE BASE_DIR "${project_dir}")
|
||||
else()
|
||||
# sign at build time, extracts key from signing key
|
||||
set(secure_boot_verification_key "${CMAKE_BINARY_DIR}/signature_verification_key.bin")
|
||||
get_filename_component(secure_boot_signing_key
|
||||
${CONFIG_SECURE_BOOT_SIGNING_KEY}
|
||||
ABSOLUTE BASE_DIR "${project_dir}")
|
||||
|
||||
add_custom_command(OUTPUT "${secure_boot_verification_key}"
|
||||
COMMAND ${ESPSECUREPY}
|
||||
extract_public_key --keyfile "${secure_boot_signing_key}"
|
||||
"${secure_boot_verification_key}"
|
||||
WORKING_DIRECTORY ${project_dir}
|
||||
DEPENDS ${secure_boot_signing_key}
|
||||
VERBATIM)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_add_binary_data(${COMPONENT_LIB} "${secure_boot_verification_key}" "BINARY")
|
||||
# Embed the verification key in the binary (app & bootloader)
|
||||
#
|
||||
target_add_binary_data(${COMPONENT_LIB} "${secure_boot_verification_key}" "BINARY"
|
||||
RENAME_TO signature_verification_key_bin)
|
||||
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES
|
||||
"${secure_boot_verification_key}")
|
||||
|
@ -15,6 +15,7 @@
|
||||
#pragma once
|
||||
#include "esp_flash_partitions.h"
|
||||
#include "esp_image_format.h"
|
||||
#include "esp_app_format.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -27,6 +28,11 @@ typedef enum {
|
||||
GPIO_NOT_HOLD = 0 /*!< If the GPIO input is not low */
|
||||
} esp_comm_gpio_hold_t;
|
||||
|
||||
typedef enum {
|
||||
ESP_IMAGE_BOOTLOADER,
|
||||
ESP_IMAGE_APPLICATION
|
||||
} esp_image_type;
|
||||
|
||||
/**
|
||||
* @brief Calculate crc for the OTA data select.
|
||||
*
|
||||
@ -129,7 +135,7 @@ int bootloader_common_select_otadata(const esp_ota_select_entry_t *two_otadata,
|
||||
|
||||
/**
|
||||
* @brief Returns esp_app_desc structure for app partition. This structure includes app version.
|
||||
*
|
||||
*
|
||||
* Returns a description for the requested app partition.
|
||||
* @param[in] partition App partition description.
|
||||
* @param[out] app_desc Structure of info about app.
|
||||
@ -141,6 +147,24 @@ int bootloader_common_select_otadata(const esp_ota_select_entry_t *two_otadata,
|
||||
*/
|
||||
esp_err_t bootloader_common_get_partition_description(const esp_partition_pos_t *partition, esp_app_desc_t *app_desc);
|
||||
|
||||
/**
|
||||
* @brief Get chip revision
|
||||
*
|
||||
* @return Chip revision number
|
||||
*/
|
||||
uint8_t bootloader_common_get_chip_revision(void);
|
||||
|
||||
/**
|
||||
* @brief Check if the image (bootloader and application) has valid chip ID and revision
|
||||
*
|
||||
* @param[in] img_hdr: image header
|
||||
* @param[in] type: image type, bootloader or application
|
||||
* @return
|
||||
* - ESP_OK: image and chip are matched well
|
||||
* - ESP_FAIL: image doesn't match to the chip
|
||||
*/
|
||||
esp_err_t bootloader_common_check_chip_validity(const esp_image_header_t* img_hdr, esp_image_type type);
|
||||
|
||||
/**
|
||||
* @brief Configure VDDSDIO, call this API to rise VDDSDIO to 1.9V when VDDSDIO regulator is enabled as 1.8V mode.
|
||||
*/
|
||||
|
@ -13,6 +13,19 @@
|
||||
// limitations under the License.
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
* @brief ESP chip ID
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_CHIP_ID_ESP32 = 0x0000, /*!< chip ID: ESP32 */
|
||||
ESP_CHIP_ID_INVALID = 0xFFFF /*!< Invalid chip ID (we defined it to make sure the esp_chip_id_t is 2 bytes size) */
|
||||
} __attribute__((packed)) esp_chip_id_t;
|
||||
|
||||
/** @cond */
|
||||
_Static_assert(sizeof(esp_chip_id_t) == 2, "esp_chip_id_t should be 16 bit");
|
||||
/** @endcond */
|
||||
|
||||
/**
|
||||
* @brief SPI flash mode, used in esp_image_header_t
|
||||
*/
|
||||
@ -63,7 +76,9 @@ typedef struct {
|
||||
* the IDF bootloader uses software to configure the WP
|
||||
* pin and sets this field to 0xEE=disabled) */
|
||||
uint8_t spi_pin_drv[3]; /*!< Drive settings for the SPI flash pins (read by ROM bootloader) */
|
||||
uint8_t reserved[11]; /*!< Reserved bytes in ESP32 additional header space, currently unused */
|
||||
esp_chip_id_t chip_id; /*!< Chip identification number */
|
||||
uint8_t min_chip_rev; /*!< Minimum chip revision supported by image */
|
||||
uint8_t reserved[8]; /*!< Reserved bytes in additional header space, currently unused */
|
||||
uint8_t hash_appended; /*!< If 1, a SHA256 digest "simple hash" (of the entire image) is appended after the checksum.
|
||||
* Included in image length. This digest
|
||||
* is separate to secure boot and only used for detecting corruption.
|
||||
|
@ -133,6 +133,21 @@ void esp_flash_write_protect_crypt_cnt();
|
||||
*/
|
||||
esp_flash_enc_mode_t esp_get_flash_encryption_mode();
|
||||
|
||||
|
||||
/** @brief Check the flash encryption mode during startup
|
||||
*
|
||||
* @note This function is called automatically during app startup,
|
||||
* it doesn't need to be called from the app.
|
||||
*
|
||||
* Verifies the flash encryption config during startup:
|
||||
*
|
||||
* - Correct any insecure flash encryption settings if hardware
|
||||
* Secure Boot is enabled.
|
||||
* - Log warnings if the efuse config doesn't match the project
|
||||
* config in any way
|
||||
*/
|
||||
void esp_flash_encryption_init_checks(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -98,12 +98,6 @@ typedef struct {
|
||||
esp_err_t esp_partition_table_verify(const esp_partition_info_t *partition_table, bool log_errors, int *num_partitions);
|
||||
|
||||
|
||||
/* This function is included for compatibility with the ESP-IDF v3.x API */
|
||||
inline static __attribute__((deprecated)) esp_err_t esp_partition_table_basic_verify(const esp_partition_info_t *partition_table, bool log_errors, int *num_partitions)
|
||||
{
|
||||
return esp_partition_table_verify(partition_table, log_errors, num_partitions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the region on the main flash is safe to write.
|
||||
*
|
||||
|
@ -51,36 +51,6 @@ typedef enum {
|
||||
#endif
|
||||
} esp_image_load_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Verify and (optionally, in bootloader mode) load an app image.
|
||||
*
|
||||
* This name is deprecated and is included for compatibility with the ESP-IDF v3.x API.
|
||||
* It will be removed in V4.0 version.
|
||||
* Function has been renamed to esp_image_verify().
|
||||
* Use function esp_image_verify() to verify a image. And use function bootloader_load_image() to load image from a bootloader space.
|
||||
*
|
||||
* 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[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.
|
||||
*
|
||||
* Image validation checks:
|
||||
* - Magic byte.
|
||||
* - Partition smaller than 16MB.
|
||||
* - All segments & image fit in partition.
|
||||
* - 8 bit image checksum is valid.
|
||||
* - SHA-256 of image is valid (if image has this appended).
|
||||
* - (Signature) if signature verification is enabled.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK if verify or load was successful
|
||||
* - ESP_ERR_IMAGE_FLASH_FAIL if a SPI flash error occurs
|
||||
* - ESP_ERR_IMAGE_INVALID if the image appears invalid.
|
||||
* - ESP_ERR_INVALID_ARG if the partition or data pointers are invalid.
|
||||
*/
|
||||
esp_err_t esp_image_load(esp_image_load_mode_t mode, const esp_partition_pos_t *part, esp_image_metadata_t *data) __attribute__((deprecated));
|
||||
|
||||
/**
|
||||
* @brief Verify an app image.
|
||||
*
|
||||
|
@ -58,3 +58,12 @@ void bootloader_clock_configure()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef BOOTLOADER_BUILD
|
||||
|
||||
int esp_clk_apb_freq(void)
|
||||
{
|
||||
return rtc_clk_apb_freq_get();
|
||||
}
|
||||
|
||||
#endif // BOOTLOADER_BUILD
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "bootloader_common.h"
|
||||
#include "soc/gpio_periph.h"
|
||||
#include "soc/rtc.h"
|
||||
#include "soc/efuse_reg.h"
|
||||
#include "soc/apb_ctrl_reg.h"
|
||||
#include "esp_image_format.h"
|
||||
#include "bootloader_sha.h"
|
||||
#include "sys/param.h"
|
||||
@ -270,3 +272,51 @@ void bootloader_common_vddsdio_configure()
|
||||
}
|
||||
#endif // CONFIG_BOOTLOADER_VDDSDIO_BOOST
|
||||
}
|
||||
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
||||
uint8_t bootloader_common_get_chip_revision(void)
|
||||
{
|
||||
uint8_t eco_bit0, eco_bit1, eco_bit2;
|
||||
eco_bit0 = (REG_READ(EFUSE_BLK0_RDATA3_REG) & 0xF000) >> 15;
|
||||
eco_bit1 = (REG_READ(EFUSE_BLK0_RDATA5_REG) & 0x100000) >> 20;
|
||||
eco_bit2 = (REG_READ(APB_CTRL_DATE_REG) & 0x80000000) >> 31;
|
||||
uint32_t combine_value = (eco_bit2 << 2) | (eco_bit1 << 1) | eco_bit0;
|
||||
uint8_t chip_ver = 0;
|
||||
switch (combine_value) {
|
||||
case 0:
|
||||
chip_ver = 0;
|
||||
break;
|
||||
case 1:
|
||||
chip_ver = 1;
|
||||
break;
|
||||
case 3:
|
||||
chip_ver = 2;
|
||||
break;
|
||||
case 7:
|
||||
chip_ver = 3;
|
||||
break;
|
||||
default:
|
||||
chip_ver = 0;
|
||||
break;
|
||||
}
|
||||
return chip_ver;
|
||||
}
|
||||
#endif
|
||||
|
||||
esp_err_t bootloader_common_check_chip_validity(const esp_image_header_t* img_hdr, esp_image_type type)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
esp_chip_id_t chip_id = CONFIG_IDF_FIRMWARE_CHIP_ID;
|
||||
if (chip_id != img_hdr->chip_id) {
|
||||
ESP_LOGE(TAG, "mismatch chip ID, expected %d, found %d", chip_id, img_hdr->chip_id);
|
||||
err = ESP_FAIL;
|
||||
}
|
||||
uint8_t revision = bootloader_common_get_chip_revision();
|
||||
if (revision < img_hdr->min_chip_rev) {
|
||||
ESP_LOGE(TAG, "can't run on lower chip revision, expected %d, found %d", revision, img_hdr->min_chip_rev);
|
||||
err = ESP_FAIL;
|
||||
} else if (revision != img_hdr->min_chip_rev) {
|
||||
ESP_LOGI(TAG, "chip revision: %d, min. %s chip revision: %d", revision, type == ESP_IMAGE_BOOTLOADER ? "bootloader" : "application", img_hdr->min_chip_rev);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
@ -127,6 +127,14 @@ static esp_err_t bootloader_main()
|
||||
ESP_LOGE(TAG, "failed to load bootloader header!");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
/* Check chip ID and minimum chip revision that supported by this image */
|
||||
uint8_t revision = bootloader_common_get_chip_revision();
|
||||
ESP_LOGI(TAG, "Chip Revision: %d", revision);
|
||||
if (bootloader_common_check_chip_validity(&fhdr, ESP_IMAGE_BOOTLOADER) != ESP_OK) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
bootloader_init_flash_configure(&fhdr);
|
||||
#if (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ == 240)
|
||||
//Check if ESP32 is rated for a CPU frequency of 160MHz only
|
||||
|
@ -114,17 +114,18 @@ void bootloader_random_enable(void)
|
||||
|
||||
void bootloader_random_disable(void)
|
||||
{
|
||||
/* Disable i2s clock */
|
||||
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_I2S0_CLK_EN);
|
||||
|
||||
|
||||
/* Reset some i2s configuration (possibly redundant as we reset entire
|
||||
I2S peripheral further down). */
|
||||
CLEAR_PERI_REG_MASK(I2S_CONF_REG(0), I2S_RX_START);
|
||||
SET_PERI_REG_MASK(I2S_CONF_REG(0), I2S_RX_RESET);
|
||||
CLEAR_PERI_REG_MASK(I2S_CONF_REG(0), I2S_RX_RESET);
|
||||
CLEAR_PERI_REG_MASK(I2S_CONF2_REG(0), I2S_CAMERA_EN);
|
||||
CLEAR_PERI_REG_MASK(I2S_CONF2_REG(0), I2S_LCD_EN);
|
||||
CLEAR_PERI_REG_MASK(I2S_CONF2_REG(0), I2S_DATA_ENABLE_TEST_EN);
|
||||
CLEAR_PERI_REG_MASK(I2S_CONF2_REG(0), I2S_DATA_ENABLE);
|
||||
CLEAR_PERI_REG_MASK(I2S_CONF_REG(0), I2S_RX_START);
|
||||
|
||||
/* Disable i2s clock */
|
||||
DPORT_CLEAR_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_I2S0_CLK_EN);
|
||||
|
||||
/* Restore SYSCON mode registers */
|
||||
CLEAR_PERI_REG_MASK(SENS_SAR_READ_CTRL_REG, SENS_SAR1_DIG_FORCE);
|
||||
|
@ -37,7 +37,7 @@ static const char *TAG = "flash_encrypt";
|
||||
|
||||
/* Static functions for stages of flash encryption */
|
||||
static esp_err_t initialise_flash_encryption(void);
|
||||
static esp_err_t encrypt_flash_contents(uint32_t flash_crypt_cnt, bool flash_crypt_wr_dis);
|
||||
static esp_err_t encrypt_flash_contents(uint32_t flash_crypt_cnt, bool flash_crypt_wr_dis) __attribute__((unused));
|
||||
static esp_err_t encrypt_bootloader();
|
||||
static esp_err_t encrypt_and_load_partition_table(esp_partition_info_t *partition_table, int *num_partitions);
|
||||
static esp_err_t encrypt_partition(int index, const esp_partition_info_t *partition);
|
||||
@ -60,8 +60,14 @@ esp_err_t esp_flash_encrypt_check_and_update(void)
|
||||
return ESP_OK;
|
||||
}
|
||||
else {
|
||||
#ifndef CONFIG_SECURE_FLASH_REQUIRE_ALREADY_ENABLED
|
||||
/* Flash is not encrypted, so encrypt it! */
|
||||
return encrypt_flash_contents(flash_crypt_cnt, flash_crypt_wr_dis);
|
||||
#else
|
||||
ESP_LOGE(TAG, "flash encryption is not enabled, and SECURE_FLASH_REQUIRE_ALREADY_ENABLED "
|
||||
"is set, refusing to boot.");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
#endif // CONFIG_SECURE_FLASH_REQUIRE_ALREADY_ENABLED
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <bootloader_random.h>
|
||||
#include <bootloader_sha.h>
|
||||
#include "bootloader_util.h"
|
||||
#include "bootloader_common.h"
|
||||
|
||||
/* Checking signatures as part of verifying images is necessary:
|
||||
- Always if secure boot is enabled
|
||||
@ -268,8 +269,6 @@ esp_err_t esp_image_verify(esp_image_load_mode_t mode, const esp_partition_pos_t
|
||||
return image_load(mode, part, data);
|
||||
}
|
||||
|
||||
esp_err_t esp_image_load(esp_image_load_mode_t mode, const esp_partition_pos_t *part, esp_image_metadata_t *data) __attribute__((alias("esp_image_verify")));
|
||||
|
||||
static esp_err_t verify_image_header(uint32_t src_addr, const esp_image_header_t *image, bool silent)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
@ -280,6 +279,9 @@ static esp_err_t verify_image_header(uint32_t src_addr, const esp_image_header_t
|
||||
}
|
||||
err = ESP_ERR_IMAGE_INVALID;
|
||||
}
|
||||
if (bootloader_common_check_chip_validity(image, ESP_IMAGE_APPLICATION) != ESP_OK) {
|
||||
err = ESP_ERR_IMAGE_INVALID;
|
||||
}
|
||||
if (!silent) {
|
||||
if (image->spi_mode > ESP_IMAGE_SPI_MODE_SLOW_READ) {
|
||||
ESP_LOGW(TAG, "image at 0x%x has invalid SPI mode %d", src_addr, image->spi_mode);
|
||||
|
@ -13,9 +13,51 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <strings.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_efuse.h"
|
||||
#include "esp_efuse_table.h"
|
||||
#include "esp_flash_encrypt.h"
|
||||
#include "esp_secure_boot.h"
|
||||
|
||||
#ifndef BOOTLOADER_BUILD
|
||||
static const char *TAG = "flash_encrypt";
|
||||
|
||||
void esp_flash_encryption_init_checks()
|
||||
{
|
||||
esp_flash_enc_mode_t mode;
|
||||
|
||||
// First check is: if Release mode flash encryption & secure boot are enabled then
|
||||
// FLASH_CRYPT_CNT *must* be write protected. This will have happened automatically
|
||||
// if bootloader is IDF V4.0 or newer but may not have happened for previous ESP-IDF bootloaders.
|
||||
#ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE
|
||||
#ifdef CONFIG_SECURE_BOOT_ENABLED
|
||||
if (esp_secure_boot_enabled() && esp_flash_encryption_enabled()) {
|
||||
uint8_t flash_crypt_cnt_wr_dis = 0;
|
||||
esp_efuse_read_field_blob(ESP_EFUSE_WR_DIS_FLASH_CRYPT_CNT, &flash_crypt_cnt_wr_dis, 1);
|
||||
if (!flash_crypt_cnt_wr_dis) {
|
||||
ESP_EARLY_LOGE(TAG, "Flash encryption & Secure Boot together requires FLASH_CRYPT_CNT efuse to be write protected. Fixing now...");
|
||||
esp_flash_write_protect_crypt_cnt();
|
||||
}
|
||||
}
|
||||
#endif // CONFIG_SECURE_BOOT_ENABLED
|
||||
#endif // CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE
|
||||
|
||||
// Second check is to print a warning or error if the current running flash encryption mode
|
||||
// doesn't match the expectation from project config (due to mismatched bootloader and app, probably)
|
||||
mode = esp_get_flash_encryption_mode();
|
||||
if (mode == ESP_FLASH_ENC_MODE_DEVELOPMENT) {
|
||||
#ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE
|
||||
ESP_EARLY_LOGE(TAG, "Flash encryption settings error: app is configured for RELEASE but efuses are set for DEVELOPMENT");
|
||||
ESP_EARLY_LOGE(TAG, "Mismatch found in security options in bootloader menuconfig and efuse settings. Device is not secure.");
|
||||
#else
|
||||
ESP_EARLY_LOGW(TAG, "Flash encryption mode is DEVELOPMENT (not secure)");
|
||||
#endif
|
||||
} else if (mode == ESP_FLASH_ENC_MODE_RELEASE) {
|
||||
ESP_EARLY_LOGI(TAG, "Flash encryption mode is RELEASE");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void esp_flash_write_protect_crypt_cnt()
|
||||
{
|
||||
|
@ -289,15 +289,23 @@ if(CONFIG_BT_ENABLED)
|
||||
"host/bluedroid/stack/smp/smp_l2c.c"
|
||||
"host/bluedroid/stack/smp/smp_main.c"
|
||||
"host/bluedroid/stack/smp/smp_utils.c")
|
||||
|
||||
if(CONFIG_BLE_MESH)
|
||||
list(APPEND srcs "esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c")
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
if(CONFIG_BLE_MESH)
|
||||
list(APPEND include_dirs
|
||||
"esp_ble_mesh/mesh_common/include"
|
||||
"esp_ble_mesh/mesh_core"
|
||||
"esp_ble_mesh/mesh_core/include"
|
||||
"esp_ble_mesh/mesh_core/settings"
|
||||
"esp_ble_mesh/mesh_core/storage"
|
||||
"esp_ble_mesh/btc/include"
|
||||
"esp_ble_mesh/mesh_models/include"
|
||||
"esp_ble_mesh/mesh_models/common/include"
|
||||
"esp_ble_mesh/mesh_models/client/include"
|
||||
"esp_ble_mesh/mesh_models/server/include"
|
||||
"esp_ble_mesh/api/core/include"
|
||||
"esp_ble_mesh/api/models/include"
|
||||
"esp_ble_mesh/api")
|
||||
@ -321,7 +329,13 @@ if(CONFIG_BT_ENABLED)
|
||||
"esp_ble_mesh/btc/btc_ble_mesh_prov.c"
|
||||
"esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c"
|
||||
"esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c"
|
||||
"esp_ble_mesh/mesh_core/settings/settings_nvs.c"
|
||||
"esp_ble_mesh/mesh_common/mesh_aes_encrypt.c"
|
||||
"esp_ble_mesh/mesh_common/mesh_atomic.c"
|
||||
"esp_ble_mesh/mesh_common/mesh_buf.c"
|
||||
"esp_ble_mesh/mesh_common/mesh_common.c"
|
||||
"esp_ble_mesh/mesh_common/mesh_kernel.c"
|
||||
"esp_ble_mesh/mesh_common/mesh_util.c"
|
||||
"esp_ble_mesh/mesh_core/storage/settings_nvs.c"
|
||||
"esp_ble_mesh/mesh_core/access.c"
|
||||
"esp_ble_mesh/mesh_core/adv.c"
|
||||
"esp_ble_mesh/mesh_core/beacon.c"
|
||||
@ -332,30 +346,30 @@ if(CONFIG_BT_ENABLED)
|
||||
"esp_ble_mesh/mesh_core/health_cli.c"
|
||||
"esp_ble_mesh/mesh_core/health_srv.c"
|
||||
"esp_ble_mesh/mesh_core/lpn.c"
|
||||
"esp_ble_mesh/mesh_core/mesh_aes_encrypt.c"
|
||||
"esp_ble_mesh/mesh_core/mesh_atomic.c"
|
||||
"esp_ble_mesh/mesh_core/mesh_bearer_adapt.c"
|
||||
"esp_ble_mesh/mesh_core/mesh_buf.c"
|
||||
"esp_ble_mesh/mesh_core/mesh_hci.c"
|
||||
"esp_ble_mesh/mesh_core/mesh_kernel.c"
|
||||
"esp_ble_mesh/mesh_core/mesh_main.c"
|
||||
"esp_ble_mesh/mesh_core/mesh_util.c"
|
||||
"esp_ble_mesh/mesh_core/main.c"
|
||||
"esp_ble_mesh/mesh_core/net.c"
|
||||
"esp_ble_mesh/mesh_core/prov.c"
|
||||
"esp_ble_mesh/mesh_core/provisioner_beacon.c"
|
||||
"esp_ble_mesh/mesh_core/provisioner_main.c"
|
||||
"esp_ble_mesh/mesh_core/provisioner_prov.c"
|
||||
"esp_ble_mesh/mesh_core/provisioner_proxy.c"
|
||||
"esp_ble_mesh/mesh_core/proxy.c"
|
||||
"esp_ble_mesh/mesh_core/proxy_client.c"
|
||||
"esp_ble_mesh/mesh_core/proxy_server.c"
|
||||
"esp_ble_mesh/mesh_core/settings.c"
|
||||
"esp_ble_mesh/mesh_core/test.c"
|
||||
"esp_ble_mesh/mesh_core/transport.c"
|
||||
"esp_ble_mesh/mesh_models/generic_client.c"
|
||||
"esp_ble_mesh/mesh_models/lighting_client.c"
|
||||
"esp_ble_mesh/mesh_models/mesh_common.c"
|
||||
"esp_ble_mesh/mesh_models/model_common.c"
|
||||
"esp_ble_mesh/mesh_models/sensor_client.c"
|
||||
"esp_ble_mesh/mesh_models/time_scene_client.c")
|
||||
"esp_ble_mesh/mesh_models/client/client_common.c"
|
||||
"esp_ble_mesh/mesh_models/client/generic_client.c"
|
||||
"esp_ble_mesh/mesh_models/client/lighting_client.c"
|
||||
"esp_ble_mesh/mesh_models/client/sensor_client.c"
|
||||
"esp_ble_mesh/mesh_models/client/time_scene_client.c"
|
||||
"esp_ble_mesh/mesh_models/server/device_property.c"
|
||||
"esp_ble_mesh/mesh_models/server/generic_server.c"
|
||||
"esp_ble_mesh/mesh_models/server/lighting_server.c"
|
||||
"esp_ble_mesh/mesh_models/server/sensor_server.c"
|
||||
"esp_ble_mesh/mesh_models/server/server_common.c"
|
||||
"esp_ble_mesh/mesh_models/server/state_binding.c"
|
||||
"esp_ble_mesh/mesh_models/server/state_transition.c"
|
||||
"esp_ble_mesh/mesh_models/server/time_scene_server.c")
|
||||
endif()
|
||||
|
||||
if(CONFIG_BT_NIMBLE_ENABLED)
|
||||
@ -376,9 +390,13 @@ if(CONFIG_BT_ENABLED)
|
||||
host/nimble/nimble/nimble/host/store/ram/include
|
||||
host/nimble/nimble/nimble/host/store/config/include
|
||||
host/nimble/nimble/porting/npl/freertos/include
|
||||
host/nimble/nimble/ext/tinycrypt/include
|
||||
host/nimble/esp-hci/include)
|
||||
|
||||
if(NOT CONFIG_BT_NIMBLE_CRYPTO_STACK_MBEDTLS)
|
||||
|
||||
list(APPEND include_dirs
|
||||
host/nimble/nimble/ext/tinycrypt/include)
|
||||
|
||||
list(APPEND srcs "host/nimble/nimble/ext/tinycrypt/src/utils.c"
|
||||
"host/nimble/nimble/ext/tinycrypt/src/sha256.c"
|
||||
"host/nimble/nimble/ext/tinycrypt/src/ecc.c"
|
||||
@ -393,8 +411,10 @@ if(CONFIG_BT_ENABLED)
|
||||
"host/nimble/nimble/ext/tinycrypt/src/hmac_prng.c"
|
||||
"host/nimble/nimble/ext/tinycrypt/src/ecc_platform_specific.c"
|
||||
"host/nimble/nimble/ext/tinycrypt/src/hmac.c"
|
||||
"host/nimble/nimble/ext/tinycrypt/src/cbc_mode.c"
|
||||
"host/nimble/nimble/nimble/host/util/src/addr.c"
|
||||
"host/nimble/nimble/ext/tinycrypt/src/cbc_mode.c")
|
||||
endif()
|
||||
|
||||
list(APPEND srcs "host/nimble/nimble/nimble/host/util/src/addr.c"
|
||||
"host/nimble/nimble/nimble/host/services/gatt/src/ble_svc_gatt.c"
|
||||
"host/nimble/nimble/nimble/host/services/tps/src/ble_svc_tps.c"
|
||||
"host/nimble/nimble/nimble/host/services/ias/src/ble_svc_ias.c"
|
||||
@ -462,6 +482,10 @@ if(CONFIG_BT_ENABLED)
|
||||
"host/nimble/nimble/porting/nimble/src/os_cputime.c"
|
||||
"host/nimble/esp-hci/src/esp_nimble_hci.c")
|
||||
|
||||
if (CONFIG_BLE_MESH)
|
||||
list(APPEND srcs "esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c")
|
||||
endif()
|
||||
|
||||
if(CONFIG_BT_NIMBLE_MESH)
|
||||
|
||||
list(APPEND include_dirs
|
||||
|
@ -1,4 +1,4 @@
|
||||
menu Bluetooth
|
||||
menu "Bluetooth"
|
||||
|
||||
config BT_ENABLED
|
||||
bool "Bluetooth"
|
||||
@ -358,6 +358,21 @@ menu Bluetooth
|
||||
If you set `BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD` to a small value or printf every adv lost event, it
|
||||
may cause adv packets lost more.
|
||||
|
||||
menuconfig BTDM_COEX_BT_OPTIONS
|
||||
bool "Coexistence Bluetooth Side Options"
|
||||
depends on ESP32_WIFI_SW_COEXIST_ENABLE
|
||||
default n
|
||||
help
|
||||
Options of Bluetooth Side of WiFi and bluetooth coexistence.
|
||||
|
||||
config BTDM_COEX_BLE_ADV_HIGH_PRIORITY
|
||||
bool "Improve BLE ADV priority for WiFi & BLE coexistence"
|
||||
depends on BTDM_COEX_BT_OPTIONS
|
||||
default n
|
||||
help
|
||||
Improve BLE ADV coexistence priority to make it better performance.
|
||||
For example, BLE mesh need to enable this option to improve BLE adv performance.
|
||||
|
||||
endmenu
|
||||
|
||||
choice BT_HOST
|
||||
@ -378,6 +393,13 @@ menu Bluetooth
|
||||
help
|
||||
This option is recommended for BLE only usecases to save on memory
|
||||
|
||||
config BT_CONTROLLER_ONLY
|
||||
bool "Controller Only"
|
||||
help
|
||||
This option is recommended when you want to communicate directly with the
|
||||
controller (without any host) or when you are using any other host stack
|
||||
not supported by Espressif (not mentioned here).
|
||||
|
||||
endchoice
|
||||
|
||||
menu "Bluedroid Options"
|
||||
@ -395,7 +417,6 @@ endmenu
|
||||
|
||||
menuconfig BLE_MESH
|
||||
bool "ESP BLE Mesh Support"
|
||||
depends on BT_BLUEDROID_ENABLED
|
||||
help
|
||||
This option enables ESP BLE Mesh support. The specific features that are
|
||||
available may depend on other features that have been enabled in the
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "esp_log.h"
|
||||
#include "bt_common.h"
|
||||
#include "osi/allocator.h"
|
||||
#include "btc/btc_alarm.h"
|
||||
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
#include "common/bt_target.h"
|
||||
@ -32,7 +33,6 @@
|
||||
#include "btc_blufi_prf.h"
|
||||
#include "blufi_int.h"
|
||||
#include "btc/btc_dm.h"
|
||||
#include "btc/btc_alarm.h"
|
||||
#include "bta/bta_gatt_api.h"
|
||||
#if CLASSIC_BT_INCLUDED
|
||||
#include "btc/btc_profile_queue.h"
|
||||
@ -94,7 +94,9 @@ static const btc_func_t profile_tab[BTC_PID_NUM] = {
|
||||
[BTC_PID_BLUFI] = {btc_blufi_call_handler, btc_blufi_cb_handler },
|
||||
#endif ///GATTS_INCLUDED == TRUE
|
||||
[BTC_PID_DM_SEC] = {NULL, btc_dm_sec_cb_handler },
|
||||
#endif
|
||||
[BTC_PID_ALARM] = {btc_alarm_handler, NULL },
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
#if CLASSIC_BT_INCLUDED
|
||||
#if (BTC_GAP_BT_INCLUDED == TRUE)
|
||||
[BTC_PID_GAP_BT] = {btc_gap_bt_call_handler, btc_gap_bt_cb_handler },
|
||||
@ -114,16 +116,20 @@ static const btc_func_t profile_tab[BTC_PID_NUM] = {
|
||||
#endif /* #if CLASSIC_BT_INCLUDED */
|
||||
#endif
|
||||
#if CONFIG_BLE_MESH
|
||||
[BTC_PID_PROV] = {btc_mesh_prov_call_handler, btc_mesh_prov_cb_handler},
|
||||
[BTC_PID_MODEL] = {btc_mesh_model_call_handler, btc_mesh_model_cb_handler},
|
||||
[BTC_PID_HEALTH_CLIENT] = {btc_mesh_health_client_call_handler, btc_mesh_health_client_cb_handler},
|
||||
[BTC_PID_HEALTH_SERVER] = {btc_mesh_health_server_call_handler, btc_mesh_health_server_cb_handler},
|
||||
[BTC_PID_CFG_CLIENT] = {btc_mesh_cfg_client_call_handler, btc_mesh_cfg_client_cb_handler},
|
||||
[BTC_PID_CFG_SERVER] = {NULL , btc_mesh_cfg_server_cb_handler},
|
||||
[BTC_PID_GENERIC_CLIENT] = {btc_mesh_generic_client_call_handler, btc_mesh_generic_client_cb_handler},
|
||||
[BTC_PID_LIGHT_CLIENT] = {btc_mesh_light_client_call_handler, btc_mesh_light_client_cb_handler},
|
||||
[BTC_PID_SENSOR_CLIENT] = {btc_mesh_sensor_client_call_handler, btc_mesh_sensor_client_cb_handler},
|
||||
[BTC_PID_TIME_SCENE_CLIENT] = {btc_mesh_time_scene_client_call_handler, btc_mesh_time_scene_client_cb_handler},
|
||||
[BTC_PID_PROV] = {btc_ble_mesh_prov_call_handler, btc_ble_mesh_prov_cb_handler },
|
||||
[BTC_PID_MODEL] = {btc_ble_mesh_model_call_handler, btc_ble_mesh_model_cb_handler },
|
||||
[BTC_PID_HEALTH_CLIENT] = {btc_ble_mesh_health_client_call_handler, btc_ble_mesh_health_client_cb_handler },
|
||||
[BTC_PID_HEALTH_SERVER] = {btc_ble_mesh_health_server_call_handler, btc_ble_mesh_health_server_cb_handler },
|
||||
[BTC_PID_CONFIG_CLIENT] = {btc_ble_mesh_config_client_call_handler, btc_ble_mesh_config_client_cb_handler },
|
||||
[BTC_PID_CONFIG_SERVER] = {NULL, btc_ble_mesh_config_server_cb_handler },
|
||||
[BTC_PID_GENERIC_CLIENT] = {btc_ble_mesh_generic_client_call_handler, btc_ble_mesh_generic_client_cb_handler },
|
||||
[BTC_PID_LIGHTING_CLIENT] = {btc_ble_mesh_lighting_client_call_handler, btc_ble_mesh_lighting_client_cb_handler },
|
||||
[BTC_PID_SENSOR_CLIENT] = {btc_ble_mesh_sensor_client_call_handler, btc_ble_mesh_sensor_client_cb_handler },
|
||||
[BTC_PID_TIME_SCENE_CLIENT] = {btc_ble_mesh_time_scene_client_call_handler, btc_ble_mesh_time_scene_client_cb_handler},
|
||||
[BTC_PID_GENERIC_SERVER] = {NULL, btc_ble_mesh_generic_server_cb_handler },
|
||||
[BTC_PID_LIGHTING_SERVER] = {NULL, btc_ble_mesh_lighting_server_cb_handler },
|
||||
[BTC_PID_SENSOR_SERVER] = {NULL, btc_ble_mesh_sensor_server_cb_handler },
|
||||
[BTC_PID_TIME_SCENE_SERVER] = {NULL, btc_ble_mesh_time_scene_server_cb_handler},
|
||||
#endif /* #if CONFIG_BLE_MESH */
|
||||
};
|
||||
|
||||
@ -321,7 +327,7 @@ error_exit:;
|
||||
|
||||
int btc_init(void)
|
||||
{
|
||||
btc_thread = osi_thread_create("BTC_TASK", BTC_TASK_STACK_SIZE, BTC_TASK_PRIO, BTC_TASK_PINNED_TO_CORE, 3);
|
||||
btc_thread = osi_thread_create("BTC_TASK", BTC_TASK_STACK_SIZE, BTC_TASK_PRIO, BTC_TASK_PINNED_TO_CORE, 2);
|
||||
if (btc_thread == NULL) {
|
||||
return BT_STATUS_NOMEM;
|
||||
}
|
||||
|
@ -15,9 +15,7 @@
|
||||
#ifndef __BTC_MANAGE_H__
|
||||
#define __BTC_MANAGE_H__
|
||||
|
||||
#include "bta/bta_api.h"
|
||||
#include "btc/btc_task.h"
|
||||
#include "esp_bt_defs.h"
|
||||
|
||||
#if BTC_DYNAMIC_MEMORY == FALSE
|
||||
extern void *btc_profile_cb_tab[BTC_PID_NUM];
|
||||
|
@ -72,12 +72,16 @@ typedef enum {
|
||||
BTC_PID_MODEL,
|
||||
BTC_PID_HEALTH_CLIENT,
|
||||
BTC_PID_HEALTH_SERVER,
|
||||
BTC_PID_CFG_CLIENT,
|
||||
BTC_PID_CFG_SERVER,
|
||||
BTC_PID_CONFIG_CLIENT,
|
||||
BTC_PID_CONFIG_SERVER,
|
||||
BTC_PID_GENERIC_CLIENT,
|
||||
BTC_PID_LIGHT_CLIENT,
|
||||
BTC_PID_LIGHTING_CLIENT,
|
||||
BTC_PID_SENSOR_CLIENT,
|
||||
BTC_PID_TIME_SCENE_CLIENT,
|
||||
BTC_PID_GENERIC_SERVER,
|
||||
BTC_PID_LIGHTING_SERVER,
|
||||
BTC_PID_SENSOR_SERVER,
|
||||
BTC_PID_TIME_SCENE_SERVER,
|
||||
#endif /* CONFIG_BLE_MESH */
|
||||
BTC_PID_NUM,
|
||||
} btc_pid_t; //btc profile id
|
||||
|
@ -49,7 +49,7 @@
|
||||
#ifdef CONFIG_BTC_TASK_STACK_SIZE
|
||||
#define UC_BTC_TASK_STACK_SIZE CONFIG_BTC_TASK_STACK_SIZE
|
||||
#else
|
||||
#define UC_BTC_TASK_STACK_SIZE 3072
|
||||
#define UC_BTC_TASK_STACK_SIZE 4096
|
||||
#endif
|
||||
|
||||
/**********************************************************
|
||||
|
@ -409,6 +409,16 @@ bool config_save(const config_t *config, const char *filename)
|
||||
for (const list_node_t *node = list_begin(config->sections); node != list_end(config->sections); node = list_next(node)) {
|
||||
const section_t *section = (const section_t *)list_node(node);
|
||||
w_cnt = snprintf(line, 1024, "[%s]\n", section->name);
|
||||
if(w_cnt < 0) {
|
||||
OSI_TRACE_ERROR("snprintf error w_cnt %d.",w_cnt);
|
||||
err_code |= 0x10;
|
||||
goto error;
|
||||
}
|
||||
if(w_cnt_total + w_cnt > config_size + 100) {
|
||||
OSI_TRACE_ERROR("%s, memcpy size (w_cnt + w_cnt_total = %d) is larger than buffer size (config_size = %d).", __func__, (w_cnt + w_cnt_total),config_size);
|
||||
err_code |= 0x20;
|
||||
goto error;
|
||||
}
|
||||
OSI_TRACE_DEBUG("section name: %s, w_cnt + w_cnt_total = %d\n", section->name, w_cnt + w_cnt_total);
|
||||
memcpy(buf + w_cnt_total, line, w_cnt);
|
||||
w_cnt_total += w_cnt;
|
||||
@ -417,6 +427,16 @@ bool config_save(const config_t *config, const char *filename)
|
||||
const entry_t *entry = (const entry_t *)list_node(enode);
|
||||
OSI_TRACE_DEBUG("(key, val): (%s, %s)\n", entry->key, entry->value);
|
||||
w_cnt = snprintf(line, 1024, "%s = %s\n", entry->key, entry->value);
|
||||
if(w_cnt < 0) {
|
||||
OSI_TRACE_ERROR("snprintf error w_cnt %d.",w_cnt);
|
||||
err_code |= 0x10;
|
||||
goto error;
|
||||
}
|
||||
if(w_cnt_total + w_cnt > config_size + 100) {
|
||||
OSI_TRACE_ERROR("%s, memcpy size (w_cnt + w_cnt_total = %d) is larger than buffer size.(config_size = %d)", __func__, w_cnt + w_cnt_total,config_size);
|
||||
err_code |= 0x20;
|
||||
goto error;
|
||||
}
|
||||
OSI_TRACE_DEBUG("%s, w_cnt + w_cnt_total = %d", __func__, w_cnt + w_cnt_total);
|
||||
memcpy(buf + w_cnt_total, line, w_cnt);
|
||||
w_cnt_total += w_cnt;
|
||||
|
@ -152,7 +152,7 @@ void *fixed_queue_dequeue(fixed_queue_t *queue, uint32_t timeout)
|
||||
|
||||
assert(queue != NULL);
|
||||
|
||||
if (osi_sem_take(queue->dequeue_sem, timeout) != 0) {
|
||||
if (osi_sem_take(&queue->dequeue_sem, timeout) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -206,14 +206,14 @@ void *fixed_queue_try_remove_from_queue(fixed_queue_t *queue, void *data)
|
||||
|
||||
osi_mutex_lock(&queue->lock, OSI_MUTEX_MAX_TIMEOUT);
|
||||
if (list_contains(queue->list, data) &&
|
||||
osi_sem_take(queue->dequeue_sem, 0) == 0) {
|
||||
osi_sem_take(&queue->dequeue_sem, 0) == 0) {
|
||||
removed = list_remove(queue->list, data);
|
||||
assert(removed);
|
||||
}
|
||||
osi_mutex_unlock(&queue->lock);
|
||||
|
||||
if (removed) {
|
||||
osi_sem_give(queue->enqueue_sem);
|
||||
osi_sem_give(&queue->enqueue_sem);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -129,28 +129,39 @@ COMPONENT_PRIV_INCLUDEDIRS += common/btc/include \
|
||||
COMPONENT_SRCDIRS += common/osi \
|
||||
common/btc/core
|
||||
|
||||
ifdef CONFIG_BLE_MESH
|
||||
|
||||
COMPONENT_SRCDIRS += esp_ble_mesh/mesh_core/bluedroid_host
|
||||
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef CONFIG_BLE_MESH
|
||||
COMPONENT_ADD_INCLUDEDIRS += esp_ble_mesh/mesh_core \
|
||||
esp_ble_mesh/mesh_core/include \
|
||||
esp_ble_mesh/mesh_core/settings \
|
||||
esp_ble_mesh/btc/include \
|
||||
esp_ble_mesh/mesh_models/include \
|
||||
esp_ble_mesh/api/core/include \
|
||||
esp_ble_mesh/api/models/include \
|
||||
esp_ble_mesh/api
|
||||
COMPONENT_ADD_INCLUDEDIRS += esp_ble_mesh/mesh_common/include \
|
||||
esp_ble_mesh/mesh_core \
|
||||
esp_ble_mesh/mesh_core/include \
|
||||
esp_ble_mesh/mesh_core/storage \
|
||||
esp_ble_mesh/btc/include \
|
||||
esp_ble_mesh/mesh_models/common/include \
|
||||
esp_ble_mesh/mesh_models/client/include \
|
||||
esp_ble_mesh/mesh_models/server/include \
|
||||
esp_ble_mesh/api/core/include \
|
||||
esp_ble_mesh/api/models/include \
|
||||
esp_ble_mesh/api
|
||||
|
||||
COMPONENT_SRCDIRS += esp_ble_mesh/mesh_core \
|
||||
esp_ble_mesh/mesh_core/settings \
|
||||
esp_ble_mesh/btc \
|
||||
esp_ble_mesh/mesh_models \
|
||||
esp_ble_mesh/api/core \
|
||||
esp_ble_mesh/api/models
|
||||
COMPONENT_SRCDIRS += esp_ble_mesh/mesh_common \
|
||||
esp_ble_mesh/mesh_core \
|
||||
esp_ble_mesh/mesh_core/storage \
|
||||
esp_ble_mesh/btc \
|
||||
esp_ble_mesh/mesh_models/client \
|
||||
esp_ble_mesh/mesh_models/server \
|
||||
esp_ble_mesh/api/core \
|
||||
esp_ble_mesh/api/models
|
||||
endif
|
||||
|
||||
|
||||
ifdef CONFIG_BT_NIMBLE_ENABLED
|
||||
|
||||
COMPONENT_ADD_INCLUDEDIRS += host/nimble/nimble/nimble/include \
|
||||
host/nimble/nimble/nimble/host/include \
|
||||
host/nimble/nimble/porting/nimble/include \
|
||||
@ -165,14 +176,16 @@ COMPONENT_ADD_INCLUDEDIRS += host/nimble/nimble/nimble/include
|
||||
host/nimble/nimble/nimble/host/util/include \
|
||||
host/nimble/nimble/nimble/host/store/ram/include \
|
||||
host/nimble/nimble/nimble/host/store/config/include \
|
||||
host/nimble/nimble/ext/tinycrypt/include \
|
||||
host/nimble/esp-hci/include \
|
||||
host/nimble/port/include
|
||||
|
||||
ifndef CONFIG_BT_NIMBLE_CRYPTO_STACK_MBEDTLS
|
||||
COMPONENT_ADD_INCLUDEDIRS += host/nimble/nimble/ext/tinycrypt/include
|
||||
endif
|
||||
|
||||
COMPONENT_SRCDIRS += host/nimble/nimble/nimble/host/src \
|
||||
host/nimble/nimble/porting/nimble/src \
|
||||
host/nimble/nimble/porting/npl/freertos/src \
|
||||
host/nimble/nimble/ext/tinycrypt/src \
|
||||
host/nimble/nimble/nimble/host/services/ans/src \
|
||||
host/nimble/nimble/nimble/host/services/bas/src \
|
||||
host/nimble/nimble/nimble/host/services/gap/src \
|
||||
@ -185,8 +198,23 @@ COMPONENT_SRCDIRS += host/nimble/nimble/nimble/host/src
|
||||
host/nimble/nimble/nimble/host/store/config/src \
|
||||
host/nimble/esp-hci/src
|
||||
|
||||
ifndef CONFIG_BT_NIMBLE_CRYPTO_STACK_MBEDTLS
|
||||
COMPONENT_SRCDIRS += host/nimble/nimble/ext/tinycrypt/src
|
||||
endif
|
||||
|
||||
COMPONENT_OBJEXCLUDE += host/nimble/nimble/nimble/host/store/config/src/ble_store_config_conf.o
|
||||
|
||||
ifdef CONFIG_BLE_MESH
|
||||
COMPONENT_PRIV_INCLUDEDIRS += common/btc/include \
|
||||
common/include
|
||||
|
||||
COMPONENT_SRCDIRS += common/osi \
|
||||
common/btc/core \
|
||||
esp_ble_mesh/mesh_core/nimble_host
|
||||
|
||||
COMPONENT_ADD_INCLUDEDIRS += common/osi/include
|
||||
endif
|
||||
|
||||
ifdef CONFIG_BT_NIMBLE_MESH
|
||||
|
||||
COMPONENT_ADD_INCLUDEDIRS += host/nimble/nimble/nimble/host/mesh/include
|
||||
|
@ -203,7 +203,8 @@ extern void btdm_controller_enable_sleep(bool enable);
|
||||
extern void btdm_controller_set_sleep_mode(uint8_t mode);
|
||||
extern uint8_t btdm_controller_get_sleep_mode(void);
|
||||
extern bool btdm_power_state_active(void);
|
||||
extern void btdm_wakeup_request(void);
|
||||
extern void btdm_wakeup_request(bool request_lock);
|
||||
extern void btdm_wakeup_request_end(void);
|
||||
/* Low Power Clock */
|
||||
extern bool btdm_lpclk_select_src(uint32_t sel);
|
||||
extern bool btdm_lpclk_set_div(uint32_t div);
|
||||
@ -224,6 +225,7 @@ extern int coex_bt_release_wrapper(uint32_t event);
|
||||
extern int coex_register_bt_cb_wrapper(coex_func_cb_t cb);
|
||||
extern uint32_t coex_bb_reset_lock_wrapper(void);
|
||||
extern void coex_bb_reset_unlock_wrapper(uint32_t restore);
|
||||
extern void coex_ble_adv_priority_high_set(bool high);
|
||||
|
||||
extern char _bss_start_btdm;
|
||||
extern char _bss_end_btdm;
|
||||
@ -740,7 +742,7 @@ static void task_delete_wrapper(void *task_handle)
|
||||
|
||||
static bool IRAM_ATTR is_in_isr_wrapper(void)
|
||||
{
|
||||
return (bool)xPortInIsrContext();
|
||||
return !xPortCanYield();
|
||||
}
|
||||
|
||||
static void IRAM_ATTR cause_sw_intr(void *arg)
|
||||
@ -765,7 +767,7 @@ static int IRAM_ATTR cause_sw_intr_to_core_wrapper(int core_id, int intr_no)
|
||||
|
||||
static void *malloc_internal_wrapper(size_t size)
|
||||
{
|
||||
return heap_caps_malloc(size, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL);
|
||||
return heap_caps_malloc(size, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL);
|
||||
}
|
||||
|
||||
static int32_t IRAM_ATTR read_mac_wrapper(uint8_t mac[6])
|
||||
@ -893,6 +895,8 @@ bool esp_vhci_host_check_send_available(void)
|
||||
|
||||
void esp_vhci_host_send_packet(uint8_t *data, uint16_t len)
|
||||
{
|
||||
bool do_wakeup_request = false;
|
||||
|
||||
if (!btdm_power_state_active()) {
|
||||
#if CONFIG_PM_ENABLE
|
||||
if (semphr_take_wrapper(s_pm_lock_sem, 0)) {
|
||||
@ -900,9 +904,15 @@ void esp_vhci_host_send_packet(uint8_t *data, uint16_t len)
|
||||
}
|
||||
esp_timer_stop(s_btdm_slp_tmr);
|
||||
#endif
|
||||
btdm_wakeup_request();
|
||||
do_wakeup_request = true;
|
||||
btdm_wakeup_request(true);
|
||||
}
|
||||
|
||||
API_vhci_host_send_packet(data, len);
|
||||
|
||||
if (do_wakeup_request) {
|
||||
btdm_wakeup_request_end();
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callback)
|
||||
@ -1182,6 +1192,12 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
|
||||
goto error;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BTDM_COEX_BLE_ADV_HIGH_PRIORITY
|
||||
coex_ble_adv_priority_high_set(true);
|
||||
#else
|
||||
coex_ble_adv_priority_high_set(false);
|
||||
#endif
|
||||
|
||||
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED;
|
||||
|
||||
return ESP_OK;
|
||||
@ -1328,7 +1344,7 @@ esp_err_t esp_bt_controller_disable(void)
|
||||
if (btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_ORIG) {
|
||||
btdm_controller_enable_sleep(false);
|
||||
if (!btdm_power_state_active()) {
|
||||
btdm_wakeup_request();
|
||||
btdm_wakeup_request(false);
|
||||
}
|
||||
while (!btdm_power_state_active()) {
|
||||
ets_delay_us(1000);
|
||||
@ -1466,7 +1482,7 @@ void esp_bt_controller_wakeup_request(void)
|
||||
return;
|
||||
}
|
||||
|
||||
btdm_wakeup_request();
|
||||
btdm_wakeup_request(false);
|
||||
}
|
||||
|
||||
esp_err_t esp_bredr_sco_datapath_set(esp_sco_data_path_t data_path)
|
||||
|
Submodule components/bt/controller/lib updated: cc2fd1177d...5a2416f8b8
@ -8,12 +8,15 @@ if BLE_MESH
|
||||
|
||||
config BLE_MESH_USE_DUPLICATE_SCAN
|
||||
bool "Support Duplicate Scan in BLE Mesh"
|
||||
depends on BT_BLUEDROID_ENABLED
|
||||
select BLE_SCAN_DUPLICATE
|
||||
select BLE_MESH_SCAN_DUPLICATE_EN
|
||||
default y
|
||||
help
|
||||
Enable this option to allow using specific duplicate scan filter
|
||||
in BLE Mesh, and Scan Duplicate Type must be set to 0x02.
|
||||
in BLE Mesh, and Scan Duplicate Type must be set by choosing the
|
||||
option in the Bluetooth Controller section in menuconfig, which is
|
||||
"Scan Duplicate By Device Address and Advertising Data".
|
||||
|
||||
config BLE_MESH_FAST_PROV
|
||||
bool "Enable BLE Mesh Fast Provisioning"
|
||||
@ -23,16 +26,24 @@ if BLE_MESH
|
||||
default n
|
||||
help
|
||||
Enable this option to allow BLE Mesh fast provisioning solution to be used.
|
||||
When there are multiple unprovisioned devices around, fast provisioning can
|
||||
greatly reduce the time consumption of the whole provisioning process.
|
||||
When this option is enabled, and after an unprovisioned device is provisioned
|
||||
into a node successfully, it can be changed to a temporary Provisioner.
|
||||
|
||||
config BLE_MESH_NODE
|
||||
bool "Support for BLE Mesh Node"
|
||||
help
|
||||
Enable the device to be provisioned into a node.
|
||||
Enable the device to be provisioned into a node. This option should be
|
||||
enabled when an unprovisioned device is going to be provisioned into a
|
||||
node and communicate with other nodes in the BLE Mesh network.
|
||||
|
||||
config BLE_MESH_PROVISIONER
|
||||
bool "Support for BLE Mesh Provisioner"
|
||||
help
|
||||
Enable the device to be a provisioner.
|
||||
Enable the device to be a Provisioner. The option should be enabled when
|
||||
a device is going to act as a Provisioner and provision unprovisioned
|
||||
devices into the BLE Mesh network.
|
||||
|
||||
if BLE_MESH_PROVISIONER
|
||||
|
||||
@ -41,57 +52,75 @@ if BLE_MESH
|
||||
default 20
|
||||
range 1 100
|
||||
help
|
||||
This option specifies how may unprovisioned devices can be added to device
|
||||
queue for provisioning.
|
||||
This option specifies how many unprovisioned devices can be added to device
|
||||
queue for provisioning. Users can use this option to define the size of the
|
||||
queue in the bottom layer which is used to store unprovisioned device
|
||||
information (e.g. Device UUID, address).
|
||||
|
||||
config BLE_MESH_MAX_STORED_NODES
|
||||
int "Maximum number of nodes whose information can be stored"
|
||||
default 20
|
||||
range 1 1000
|
||||
range BLE_MESH_MAX_PROV_NODES 1000
|
||||
help
|
||||
This option specifies the maximum number of nodes whose information can be
|
||||
stored by a provisioner in its upper layer.
|
||||
stored by a Provisioner in its upper layer.
|
||||
Users can change this value according to the number of nodes whose information
|
||||
(e.g. Device UUID, unicast address, element number) are going to be stored by
|
||||
a Provisioner. And the nodes include the provisioned ones and user-added ones.
|
||||
|
||||
config BLE_MESH_MAX_PROV_NODES
|
||||
int "Maximum number of devices that can be provisioned by provisioner"
|
||||
int "Maximum number of devices that can be provisioned by Provisioner"
|
||||
default 20
|
||||
range 1 100
|
||||
range 1 1000
|
||||
help
|
||||
This option specifies how many devices can be provisioned by provisioner.
|
||||
This option specifies how many devices can be provisioned by a Provisioner.
|
||||
This value indicates the maximum number of unprovisioned devices which can be
|
||||
provisioned by a Provisioner. For instance,if the value is 6, it means the
|
||||
Provisioner can provision up to 6 unprovisioned devices.
|
||||
Theoretically a Provisioner without the limitation of its memory can provision
|
||||
up to 32766 unprovisioned devices, here we limit the maximum number to 100
|
||||
just to limit the memory used by a Provisioner. The bigger the value is, the
|
||||
more memory it will cost by a Provisioner to store the information of nodes.
|
||||
|
||||
if BLE_MESH_PB_ADV
|
||||
config BLE_MESH_PBA_SAME_TIME
|
||||
int "Maximum number of PB-ADV running at the same time by provisioner"
|
||||
int "Maximum number of PB-ADV running at the same time by Provisioner"
|
||||
default 2
|
||||
range 1 10
|
||||
help
|
||||
This option specifies how many devices can be provisioned at the same
|
||||
time using PB-ADV.
|
||||
This option specifies how many devices can be provisioned at the same time
|
||||
using PB-ADV. For examples, if the value is 2, it means a Provisioner can
|
||||
provision two unprovisioned devices with PB-ADV at the same time.
|
||||
|
||||
endif # BLE_MESH_PB_ADV
|
||||
|
||||
if BLE_MESH_PB_GATT
|
||||
config BLE_MESH_PBG_SAME_TIME
|
||||
int "Maximum number of PB-GATT running at the same time by provisioner"
|
||||
int "Maximum number of PB-GATT running at the same time by Provisioner"
|
||||
default 1
|
||||
range 1 5
|
||||
help
|
||||
This option specifies how many devices can be provisioned at the same
|
||||
time using PB-GATT.
|
||||
time using PB-GATT. For example, if the value is 2, it means a Provisioner
|
||||
can provision two unprovisioned devices with PB-GATT at the same time.
|
||||
|
||||
endif # BLE_MESH_PB_GATT
|
||||
|
||||
config BLE_MESH_PROVISIONER_SUBNET_COUNT
|
||||
int "Maximum number of mesh subnets that can be created by provisioner"
|
||||
int "Maximum number of mesh subnets that can be created by Provisioner"
|
||||
default 3
|
||||
range 1 4096
|
||||
help
|
||||
This option specifies how many subnets per network a provisioner can create.
|
||||
This option specifies how many subnets per network a Provisioner can create.
|
||||
Indeed, this value decides the number of network keys which can be added by a Provisioner.
|
||||
|
||||
config BLE_MESH_PROVISIONER_APP_KEY_COUNT
|
||||
int "Maximum number of application keys that can be owned by provisioner"
|
||||
int "Maximum number of application keys that can be owned by Provisioner"
|
||||
default 9
|
||||
range 1 4096
|
||||
help
|
||||
This option specifies how many application keys the provisioner can have.
|
||||
This option specifies how many application keys the Provisioner can have.
|
||||
Indeed, this value decides the number of the application keys which can be added by a Provisioner.
|
||||
|
||||
endif # BLE_MESH_PROVISIONER
|
||||
|
||||
@ -109,7 +138,8 @@ if BLE_MESH
|
||||
default y
|
||||
help
|
||||
Enable this option to allow the device to be provisioned over the
|
||||
advertising bearer.
|
||||
advertising bearer. This option should be enabled if PB-ADV is
|
||||
going to be used during provisioning procedure.
|
||||
|
||||
config BLE_MESH_PB_GATT
|
||||
bool "Provisioning support using GATT (PB-GATT)"
|
||||
@ -117,6 +147,8 @@ if BLE_MESH
|
||||
select BLE_MESH_PROV
|
||||
help
|
||||
Enable this option to allow the device to be provisioned over GATT.
|
||||
This option should be enabled if PB-GATT is going to be used during
|
||||
provisioning procedure.
|
||||
|
||||
# Virtual option enabled whenever any Proxy protocol is needed
|
||||
config BLE_MESH_PROXY
|
||||
@ -126,16 +158,28 @@ if BLE_MESH
|
||||
Enable this option to support BLE Mesh Proxy protocol used by PB-GATT
|
||||
and other proxy pdu transmission.
|
||||
|
||||
config BLE_MESH_GATT_PROXY
|
||||
bool "BLE Mesh GATT Proxy Service"
|
||||
config BLE_MESH_GATT_PROXY_SERVER
|
||||
bool "BLE Mesh GATT Proxy Server"
|
||||
select BLE_MESH_PROXY
|
||||
depends on BLE_MESH_NODE
|
||||
default y
|
||||
help
|
||||
This option enables support for Mesh GATT Proxy Service, i.e. the
|
||||
ability to act as a proxy between a Mesh GATT Client and a Mesh network.
|
||||
This option should be enabled if a node is going to be a Proxy Server.
|
||||
|
||||
config BLE_MESH_GATT_PROXY_CLIENT
|
||||
bool "BLE Mesh GATT Proxy Client"
|
||||
select BLE_MESH_PROXY
|
||||
default n
|
||||
help
|
||||
This option enables support for Mesh GATT Proxy Client. The Proxy Client
|
||||
can use the GATT bearer to send mesh messages to a node that supports the
|
||||
advertising bearer.
|
||||
|
||||
config BLE_MESH_NODE_ID_TIMEOUT
|
||||
int "Node Identity advertising timeout"
|
||||
depends on BLE_MESH_GATT_PROXY
|
||||
depends on BLE_MESH_GATT_PROXY_SERVER
|
||||
range 1 60
|
||||
default 60
|
||||
help
|
||||
@ -143,16 +187,22 @@ if BLE_MESH
|
||||
Node Identity. The given value is in seconds. The specification limits
|
||||
this to 60 seconds and lists it as the recommended value as well.
|
||||
So leaving the default value is the safest option.
|
||||
When an unprovisioned device is provisioned successfully and becomes a
|
||||
node, it will start to advertise using Node Identity during the time
|
||||
set by this option. And after that, Network ID will be advertised.
|
||||
|
||||
if BLE_MESH_PROXY
|
||||
|
||||
config BLE_MESH_PROXY_FILTER_SIZE
|
||||
int "Maximum number of filter entries per Proxy Client"
|
||||
default 1
|
||||
default 3 if BLE_MESH_GATT_PROXY
|
||||
default 3 if BLE_MESH_GATT_PROXY_SERVER
|
||||
range 1 32767
|
||||
help
|
||||
This option specifies how many Proxy Filter entries the local node supports.
|
||||
The entries of Proxy filter (whitelist or blacklist) are used to store a
|
||||
list of addresses which can be used to decide which messages will be forwarded
|
||||
to the Proxy Client by the Proxy Server.
|
||||
|
||||
endif # BLE_MESH_PROXY
|
||||
|
||||
@ -160,7 +210,9 @@ if BLE_MESH
|
||||
bool "BLE Mesh net buffer pool usage tracking"
|
||||
default y
|
||||
help
|
||||
Enable BLE Mesh net buffer pool tracking.
|
||||
Enable BLE Mesh net buffer pool tracking. This option is used to introduce another
|
||||
variable in the bottom layer to record the usage of advertising buffers of BLE Mesh
|
||||
devices. Recommend to enable this option as default.
|
||||
|
||||
config BLE_MESH_SETTINGS
|
||||
bool "Store BLE Mesh Node configuration persistently"
|
||||
@ -169,6 +221,8 @@ if BLE_MESH
|
||||
When selected, the BLE Mesh stack will take care of storing/restoring the
|
||||
BLE Mesh configuration persistently in flash. Currently this only supports
|
||||
storing BLE Mesh node configuration.
|
||||
Currently enabling this option will only store BLE Mesh nodes' information
|
||||
in the flash.
|
||||
|
||||
if BLE_MESH_SETTINGS
|
||||
config BLE_MESH_STORE_TIMEOUT
|
||||
@ -178,6 +232,9 @@ if BLE_MESH
|
||||
help
|
||||
This value defines in seconds how soon any pending changes are actually
|
||||
written into persistent storage (flash) after a change occurs.
|
||||
The option allows nodes to delay a certain period of time to save proper
|
||||
information to flash. The default value is 0, which means information
|
||||
will be stored immediately once there are updates.
|
||||
|
||||
config BLE_MESH_SEQ_STORE_RATE
|
||||
int "How often the sequence number gets updated in storage"
|
||||
@ -199,16 +256,17 @@ if BLE_MESH
|
||||
range 0 1000000
|
||||
default 5
|
||||
help
|
||||
This value defines in seconds how soon the RPL(Replay Protection List)
|
||||
This value defines in seconds how soon the RPL (Replay Protection List)
|
||||
gets written to persistent storage after a change occurs. If the node
|
||||
receives messages frequently, then a large value is recommended. If the
|
||||
node receives messages rarely, then the value can be as low as 0 (which
|
||||
means the PRL is written into the storage immediately).
|
||||
means the RPL is written into the storage immediately).
|
||||
Note that if the node operates in a security-sensitive case, and there is
|
||||
a risk of sudden power-off, then a value of 0 is strongly recommended.
|
||||
Otherwise, a power loss before RPL being written into the storage may
|
||||
introduce message replay attacks and system security will be in a
|
||||
vulnerable state.
|
||||
|
||||
endif # if BLE_MESH_SETTINGS
|
||||
|
||||
config BLE_MESH_SUBNET_COUNT
|
||||
@ -217,6 +275,7 @@ if BLE_MESH
|
||||
range 1 4096
|
||||
help
|
||||
This option specifies how many subnets a Mesh network can have at the same time.
|
||||
Indeed, this value decides the number of the network keys which can be owned by a node.
|
||||
|
||||
config BLE_MESH_APP_KEY_COUNT
|
||||
int "Maximum number of application keys per network"
|
||||
@ -224,6 +283,7 @@ if BLE_MESH
|
||||
range 1 4096
|
||||
help
|
||||
This option specifies how many application keys the device can store per network.
|
||||
Indeed, this value decides the number of the application keys which can be owned by a node.
|
||||
|
||||
config BLE_MESH_MODEL_KEY_COUNT
|
||||
int "Maximum number of application keys per model"
|
||||
@ -247,6 +307,7 @@ if BLE_MESH
|
||||
range 0 4096
|
||||
help
|
||||
This option specifies how many Label UUIDs can be stored.
|
||||
Indeed, this value decides the number of the Virtual Addresses can be supported by a node.
|
||||
|
||||
config BLE_MESH_CRPL
|
||||
int "Maximum capacity of the replay protection list"
|
||||
@ -255,6 +316,9 @@ if BLE_MESH
|
||||
help
|
||||
This option specifies the maximum capacity of the replay protection list.
|
||||
It is similar to Network message cache size, but has a different purpose.
|
||||
The replay protection list is used to prevent a node from replay attack,
|
||||
which will store the source address and sequence number of the received
|
||||
mesh messages.
|
||||
|
||||
config BLE_MESH_MSG_CACHE_SIZE
|
||||
int "Network message cache size"
|
||||
@ -264,6 +328,8 @@ if BLE_MESH
|
||||
Number of messages that are cached for the network. This helps prevent
|
||||
unnecessary decryption operations and unnecessary relays. This option
|
||||
is similar to Replay protection list, but has a different purpose.
|
||||
A node is not required to cache the entire Network PDU and may cache
|
||||
only part of it for tracking, such as values for SRC/SEQ or others.
|
||||
|
||||
config BLE_MESH_ADV_BUF_COUNT
|
||||
int "Number of advertising buffers"
|
||||
@ -309,6 +375,11 @@ if BLE_MESH
|
||||
range 1 BLE_MESH_ADV_BUF_COUNT
|
||||
help
|
||||
Maximum number of simultaneous outgoing multi-segment and/or reliable messages.
|
||||
The default value is 1, which means the device can only send one segmented
|
||||
message at a time. And if another segmented message is going to be sent, it
|
||||
should wait for the completion of the previous one.
|
||||
If users are going to send multiple segmented messages at the same time, this
|
||||
value should be configured properly.
|
||||
|
||||
config BLE_MESH_RX_SEG_MSG_COUNT
|
||||
int "Maximum number of simultaneous incoming segmented messages"
|
||||
@ -316,6 +387,11 @@ if BLE_MESH
|
||||
range 1 255
|
||||
help
|
||||
Maximum number of simultaneous incoming multi-segment and/or reliable messages.
|
||||
The default value is 1, which means the device can only receive one segmented
|
||||
message at a time. And if another segmented message is going to be received,
|
||||
it should wait for the completion of the previous one.
|
||||
If users are going to receive multiple segmented messages at the same time, this
|
||||
value should be configured properly.
|
||||
|
||||
config BLE_MESH_RX_SDU_MAX
|
||||
int "Maximum incoming Upper Transport Access PDU length"
|
||||
@ -351,32 +427,69 @@ if BLE_MESH
|
||||
|
||||
config BLE_MESH_RELAY
|
||||
bool "Relay support"
|
||||
depends on BLE_MESH_NODE
|
||||
default y
|
||||
help
|
||||
Support for acting as a Mesh Relay Node.
|
||||
Support for acting as a Mesh Relay Node. Enabling this option will allow
|
||||
a node to support the Relay feature, and the Relay feature can still
|
||||
be enabled or disabled by proper configuration messages. Disabling this
|
||||
option will let a node not support the Relay feature.
|
||||
|
||||
if BLE_MESH_RELAY
|
||||
|
||||
config BLE_MESH_RELAY_ADV_BUF
|
||||
bool "Use separate advertising buffers for relay packets"
|
||||
default n
|
||||
help
|
||||
When selected, self-send packets will be put in a high-priority
|
||||
queue and relay packets will be put in a low-priority queue.
|
||||
|
||||
if BLE_MESH_RELAY_ADV_BUF
|
||||
|
||||
config BLE_MESH_RELAY_ADV_BUF_COUNT
|
||||
int "Number of advertising buffers for relay packets"
|
||||
default 60
|
||||
range 6 256
|
||||
help
|
||||
Number of advertising buffers for relay packets available.
|
||||
|
||||
endif # BLE_MESH_RELAY_ADV_BUF
|
||||
|
||||
endif # BLE_MESH_RELAY
|
||||
|
||||
config BLE_MESH_LOW_POWER
|
||||
bool "Support for Low Power features"
|
||||
depends on BLE_MESH_NODE
|
||||
help
|
||||
Enable this option to operate as a Low Power Node.
|
||||
Enable this option to operate as a Low Power Node. If low power consumption
|
||||
is required by a node, this option should be enabled. And once the node
|
||||
enters the mesh network, it will try to find a Friend node and establish a
|
||||
friendship.
|
||||
|
||||
if BLE_MESH_LOW_POWER
|
||||
|
||||
config BLE_MESH_LPN_ESTABLISHMENT
|
||||
bool "Perform Friendship establishment using low power"
|
||||
default y
|
||||
default n
|
||||
help
|
||||
Perform the Friendship establishment using low power with the help of a
|
||||
reduced scan duty cycle. The downside of this is that the node may miss
|
||||
out on messages intended for it until it has successfully set up Friendship
|
||||
with a Friend node.
|
||||
When this option is enabled, the node will stop scanning for a period of
|
||||
time after a Friend Request or Friend Poll is sent, so as to reduce more
|
||||
power consumption.
|
||||
|
||||
config BLE_MESH_LPN_AUTO
|
||||
bool "Automatically start looking for Friend nodes once provisioned"
|
||||
default y
|
||||
default n
|
||||
help
|
||||
Once provisioned, automatically enable LPN functionality and start looking
|
||||
for Friend nodes. If this option is disabled LPN mode needs to be manually
|
||||
enabled by calling bt_mesh_lpn_set(true).
|
||||
When an unprovisioned device is provisioned successfully and becomes a node,
|
||||
enabling this option will trigger the node starts to send Friend Request at
|
||||
a certain period until it finds a proper Friend node.
|
||||
|
||||
config BLE_MESH_LPN_AUTO_TIMEOUT
|
||||
int "Time from last received message before going to LPN mode"
|
||||
@ -389,7 +502,7 @@ if BLE_MESH
|
||||
|
||||
config BLE_MESH_LPN_RETRY_TIMEOUT
|
||||
int "Retry timeout for Friend requests"
|
||||
default 8
|
||||
default 6
|
||||
range 1 3600
|
||||
help
|
||||
Time in seconds between Friend Requests, if a previous Friend Request did
|
||||
@ -402,6 +515,8 @@ if BLE_MESH
|
||||
help
|
||||
The contribution of the RSSI, measured by the Friend node, used in Friend
|
||||
Offer Delay calculations. 0 = 1, 1 = 1.5, 2 = 2, 3 = 2.5.
|
||||
RSSIFactor, one of the parameters carried by Friend Request sent by Low Power
|
||||
node, which is used to calculate the Friend Offer Delay.
|
||||
|
||||
config BLE_MESH_LPN_RECV_WIN_FACTOR
|
||||
int "ReceiveWindowFactor, used in Friend Offer Delay calculation"
|
||||
@ -410,6 +525,8 @@ if BLE_MESH
|
||||
help
|
||||
The contribution of the supported Receive Window used in Friend Offer
|
||||
Delay calculations. 0 = 1, 1 = 1.5, 2 = 2, 3 = 2.5.
|
||||
ReceiveWindowFactor, one of the parameters carried by Friend Request sent by
|
||||
Low Power node, which is used to calculate the Friend Offer Delay.
|
||||
|
||||
config BLE_MESH_LPN_MIN_QUEUE_SIZE
|
||||
int "Minimum size of the acceptable friend queue (MinQueueSizeLog)"
|
||||
@ -440,6 +557,8 @@ if BLE_MESH
|
||||
the Friend node before the PollTimeout timer expires, then the
|
||||
friendship is considered terminated. The value is in units of 100
|
||||
milliseconds, so e.g. a value of 300 means 30 seconds.
|
||||
The smaller the value, the faster the Low Power node tries to get
|
||||
messages from corresponding Friend node and vice versa.
|
||||
|
||||
config BLE_MESH_LPN_INIT_POLL_TIMEOUT
|
||||
int "The starting value of the PollTimeout timer"
|
||||
@ -467,10 +586,12 @@ if BLE_MESH
|
||||
default 8
|
||||
help
|
||||
Maximum number of groups to which the LPN can subscribe.
|
||||
|
||||
endif # BLE_MESH_LOW_POWER
|
||||
|
||||
config BLE_MESH_FRIEND
|
||||
bool "Support for acting as a Friend Node"
|
||||
depends on BLE_MESH_NODE
|
||||
help
|
||||
Enable this option to be able to act as a Friend Node.
|
||||
|
||||
@ -489,6 +610,8 @@ if BLE_MESH
|
||||
default 16
|
||||
help
|
||||
Minimum number of buffers available to be stored for each local Friend Queue.
|
||||
This option decides the size of each buffer which can be used by a Friend node
|
||||
to store messages for each Low Power node.
|
||||
|
||||
config BLE_MESH_FRIEND_SUB_LIST_SIZE
|
||||
int "Friend Subscription List Size"
|
||||
@ -496,7 +619,9 @@ if BLE_MESH
|
||||
default 3
|
||||
help
|
||||
Size of the Subscription List that can be supported by a Friend node for a
|
||||
Low Power node.
|
||||
Low Power node. And Low Power node can send Friend Subscription List Add or
|
||||
Friend Subscription List Remove messages to the Friend node to add or remove
|
||||
subscription addresses.
|
||||
|
||||
config BLE_MESH_FRIEND_LPN_COUNT
|
||||
int "Number of supported LPN nodes"
|
||||
@ -504,6 +629,9 @@ if BLE_MESH
|
||||
default 2
|
||||
help
|
||||
Number of Low Power Nodes with which a Friend can have Friendship simultaneously.
|
||||
A Friend node can have friendship with multiple Low Power nodes at the same time,
|
||||
while a Low Power node can only establish friendship with only one Friend node at
|
||||
the same time.
|
||||
|
||||
config BLE_MESH_FRIEND_SEG_RX
|
||||
int "Number of incomplete segment lists per LPN"
|
||||
@ -521,7 +649,8 @@ if BLE_MESH
|
||||
depends on BLE_MESH
|
||||
default n
|
||||
help
|
||||
Select this to save the BLE Mesh related rodata code size.
|
||||
Select this to save the BLE Mesh related rodata code size. Enabling this option
|
||||
will disable the output of BLE Mesh debug log.
|
||||
|
||||
menu "BLE Mesh STACK DEBUG LOG LEVEL"
|
||||
depends on BLE_MESH && !BLE_MESH_NO_LOG
|
||||
@ -597,12 +726,6 @@ if BLE_MESH
|
||||
|
||||
endmenu #BLE Mesh NET BUF DEBUG LOG LEVEL
|
||||
|
||||
config BLE_MESH_IRQ_LOCK
|
||||
bool "Used the IRQ lock instead of task lock"
|
||||
help
|
||||
To improve the real-time requirements of bt controller in BLE Mesh,
|
||||
task lock is used to replace IRQ lock.
|
||||
|
||||
config BLE_MESH_CLIENT_MSG_TIMEOUT
|
||||
int "Timeout(ms) for client message response"
|
||||
range 100 1200000
|
||||
@ -610,6 +733,10 @@ if BLE_MESH
|
||||
help
|
||||
Timeout value used by the node to get response of the acknowledged
|
||||
message which is sent by the client model.
|
||||
This value indicates the maximum time that a client model waits for
|
||||
the response of the sent acknowledged messages. If a client model
|
||||
uses 0 as the timeout value when sending acknowledged messages, then
|
||||
the default value will be used which is four seconds.
|
||||
|
||||
menu "Support for BLE Mesh Client Models"
|
||||
|
||||
@ -716,6 +843,7 @@ if BLE_MESH
|
||||
help
|
||||
This option removes the 96 hour limit of the IV Update Procedure and
|
||||
lets the state to be changed at any time.
|
||||
If IV Update test mode is going to be used, this option should be enabled.
|
||||
|
||||
menu "BLE Mesh specific test option"
|
||||
|
||||
@ -801,3 +929,4 @@ if BLE_MESH
|
||||
endmenu
|
||||
|
||||
endif # BLE_MESH
|
||||
|
||||
|
21
components/bt/esp_ble_mesh/README.md
Normal file
21
components/bt/esp_ble_mesh/README.md
Normal file
@ -0,0 +1,21 @@
|
||||
# ESP-BLE-MESH Component
|
||||
|
||||
This is Espressif Bluetooth Low Energy Mesh component folder.
|
||||
|
||||
This component is a part of Espressif IoT Development Framework (ESP-IDF). For the latest documentation please refer to [ESP-IDF Programming Guide](https://docs.espressif.com/projects/esp-idf/en/latest/index.html).
|
||||
|
||||
The ESP-BLE-MESH networking enables many-to-many (m:m) device communications and is optimized for creating large-scale device networks.
|
||||
|
||||
|
||||
### [ESP-BLE-MESH Documentation](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/esp_ble_mesh/index.html)
|
||||
|
||||
- [Getting Started](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/esp_ble_mesh/index.html##getting-started-with-ble-mesh)
|
||||
- [Architecture](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/esp_ble_mesh/arhitecture.html)
|
||||
- [Feature List](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/esp_ble_mesh/ble_mesh-feature-list.html)
|
||||
- [FAQ](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/esp_ble_mesh/ble_mesh_faq.html)
|
||||
- [API Reference](https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/bluetooth/ble_mesh.html)
|
||||
|
||||
|
||||
### [ESP-BLE-MESH Examples](https://github.com/espressif/esp-idf/tree/master/examples/bluetooth/esp_ble_mesh)
|
||||
|
||||
- Refer to **ESP-BLE-MESH Examples** of [Getting Started](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/esp_ble_mesh/index.html##getting-started-with-ble-mesh) for the tutorials of ESP BLE Mesh examples.
|
@ -19,10 +19,9 @@
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
#include "osi/alarm.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_prov.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
@ -32,12 +31,18 @@ esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
SemaphoreHandle_t semaphore = NULL;
|
||||
btc_msg_t msg = {0};
|
||||
esp_err_t ret;
|
||||
|
||||
if (prov == NULL || comp == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
ret = bt_mesh_host_init();
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Create a semaphore
|
||||
if ((semaphore = xSemaphoreCreateCounting(1, 0)) == NULL) {
|
||||
|
@ -19,8 +19,6 @@
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_prov.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
@ -15,12 +15,51 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_prov.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
esp_err_t esp_ble_mesh_lpn_enable(void)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
msg.act = BTC_BLE_MESH_ACT_LPN_ENABLE;
|
||||
|
||||
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_lpn_disable(bool force)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
msg.act = BTC_BLE_MESH_ACT_LPN_DISABLE;
|
||||
|
||||
arg.lpn_disable.force = force;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_lpn_poll(void)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
msg.act = BTC_BLE_MESH_ACT_LPN_POLL;
|
||||
|
||||
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -19,21 +19,19 @@
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_prov.h"
|
||||
#include "esp_ble_mesh_networking_api.h"
|
||||
|
||||
#define ESP_BLE_MESH_TX_SDU_MAX ((CONFIG_BLE_MESH_ADV_BUF_COUNT - 3) * 12)
|
||||
|
||||
static esp_err_t ble_mesh_send_msg(esp_ble_mesh_model_t *model,
|
||||
esp_ble_mesh_msg_ctx_t *ctx,
|
||||
uint32_t opcode,
|
||||
btc_ble_mesh_model_act_t act,
|
||||
uint16_t length, uint8_t *data,
|
||||
int32_t msg_timeout, bool need_rsp,
|
||||
esp_ble_mesh_dev_role_t device_role)
|
||||
static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
esp_ble_mesh_msg_ctx_t *ctx,
|
||||
uint32_t opcode,
|
||||
btc_ble_mesh_model_act_t act,
|
||||
uint16_t length, uint8_t *data,
|
||||
int32_t msg_timeout, bool need_rsp,
|
||||
esp_ble_mesh_dev_role_t device_role)
|
||||
{
|
||||
btc_ble_mesh_model_args_t arg = {0};
|
||||
uint8_t op_len = 0, mic_len = 0;
|
||||
@ -41,9 +39,15 @@ static esp_err_t ble_mesh_send_msg(esp_ble_mesh_model_t *model,
|
||||
btc_msg_t msg = {0};
|
||||
esp_err_t status;
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
if (ctx && ctx->addr == ESP_BLE_MESH_ADDR_UNASSIGNED) {
|
||||
LOG_ERROR("%s, Invalid destination address 0x0000", __func__);
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (device_role > ROLE_FAST_PROV) {
|
||||
LOG_ERROR("%s, Invalid device role 0x%02x", __func__, device_role);
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -108,7 +112,7 @@ static esp_err_t ble_mesh_send_msg(esp_ble_mesh_model_t *model,
|
||||
arg.model_send.msg_timeout = msg_timeout;
|
||||
}
|
||||
|
||||
status = (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_model_args_t), btc_ble_mesh_prov_arg_deep_copy)
|
||||
status = (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_model_args_t), btc_ble_mesh_model_arg_deep_copy)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
|
||||
osi_free(msg_data);
|
||||
@ -118,7 +122,7 @@ static esp_err_t ble_mesh_send_msg(esp_ble_mesh_model_t *model,
|
||||
|
||||
esp_err_t esp_ble_mesh_register_custom_model_callback(esp_ble_mesh_model_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_MODEL, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
@ -157,7 +161,7 @@ esp_err_t esp_ble_mesh_client_model_init(esp_ble_mesh_model_t *model)
|
||||
if (model == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
return btc_ble_mesh_client_init(model);
|
||||
return btc_ble_mesh_client_model_init(model);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_server_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
@ -167,8 +171,8 @@ esp_err_t esp_ble_mesh_server_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
if (!model || !ctx) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
return ble_mesh_send_msg(model, ctx, opcode, BTC_BLE_MESH_ACT_SERVER_MODEL_SEND,
|
||||
length, data, 0, false, ROLE_NODE);
|
||||
return ble_mesh_model_send_msg(model, ctx, opcode, BTC_BLE_MESH_ACT_SERVER_MODEL_SEND,
|
||||
length, data, 0, false, ROLE_NODE);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_client_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
@ -179,8 +183,8 @@ esp_err_t esp_ble_mesh_client_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
if (!model || !ctx) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
return ble_mesh_send_msg(model, ctx, opcode, BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND,
|
||||
length, data, msg_timeout, need_rsp, device_role);
|
||||
return ble_mesh_model_send_msg(model, ctx, opcode, BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND,
|
||||
length, data, msg_timeout, need_rsp, device_role);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_model_publish(esp_ble_mesh_model_t *model, uint32_t opcode,
|
||||
@ -190,15 +194,40 @@ esp_err_t esp_ble_mesh_model_publish(esp_ble_mesh_model_t *model, uint32_t opcod
|
||||
if (!model || !model->pub || !model->pub->msg) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
return ble_mesh_send_msg(model, NULL, opcode, BTC_BLE_MESH_ACT_MODEL_PUBLISH,
|
||||
length, data, 0, false, device_role);
|
||||
return ble_mesh_model_send_msg(model, NULL, opcode, BTC_BLE_MESH_ACT_MODEL_PUBLISH,
|
||||
length, data, 0, false, device_role);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_server_model_update_state(esp_ble_mesh_model_t *model,
|
||||
esp_ble_mesh_server_state_type_t type,
|
||||
esp_ble_mesh_server_state_value_t *value)
|
||||
{
|
||||
btc_ble_mesh_model_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!model || !value || type >= ESP_BLE_MESH_SERVER_MODEL_STATE_MAX) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
arg.model_update_state.model = model;
|
||||
arg.model_update_state.type = type;
|
||||
arg.model_update_state.value = value;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_MODEL;
|
||||
msg.act = BTC_BLE_MESH_ACT_SERVER_MODEL_UPDATE_STATE;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_model_args_t), btc_ble_mesh_model_arg_deep_copy)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_node_local_reset(void)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -218,7 +247,7 @@ esp_err_t esp_ble_mesh_provisioner_set_node_name(int index, const char *name)
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -251,7 +280,7 @@ esp_err_t esp_ble_mesh_provisioner_add_local_app_key(const uint8_t app_key[16],
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -283,7 +312,7 @@ esp_err_t esp_ble_mesh_provisioner_bind_app_key_to_local_model(uint16_t element_
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -306,7 +335,7 @@ esp_err_t esp_ble_mesh_provisioner_add_local_net_key(const uint8_t net_key[16],
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
|
@ -18,8 +18,6 @@
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_prov.h"
|
||||
#include "esp_ble_mesh_provisioning_api.h"
|
||||
@ -29,7 +27,7 @@
|
||||
|
||||
esp_err_t esp_ble_mesh_register_prov_callback(esp_ble_mesh_prov_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_PROV, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
@ -44,7 +42,7 @@ esp_err_t esp_ble_mesh_node_prov_enable(esp_ble_mesh_prov_bearer_t bearers)
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -60,7 +58,7 @@ esp_err_t esp_ble_mesh_node_prov_disable(esp_ble_mesh_prov_bearer_t bearers)
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -72,7 +70,7 @@ esp_err_t esp_ble_mesh_node_prov_disable(esp_ble_mesh_prov_bearer_t bearers)
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_node_set_oob_pub_key(uint8_t pub_key_x[32], uint8_t pub_key_y[32],
|
||||
uint8_t private_key[32])
|
||||
uint8_t private_key[32])
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
@ -81,7 +79,7 @@ esp_err_t esp_ble_mesh_node_set_oob_pub_key(uint8_t pub_key_x[32], uint8_t pub_k
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -104,7 +102,7 @@ esp_err_t esp_ble_mesh_node_input_number(uint32_t number)
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -124,7 +122,7 @@ esp_err_t esp_ble_mesh_node_input_string(const char *string)
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -145,7 +143,7 @@ esp_err_t esp_ble_mesh_set_unprovisioned_device_name(const char *name)
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -159,7 +157,7 @@ esp_err_t esp_ble_mesh_set_unprovisioned_device_name(const char *name)
|
||||
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER)
|
||||
esp_err_t esp_ble_mesh_provisioner_read_oob_pub_key(uint8_t link_idx, uint8_t pub_key_x[32],
|
||||
uint8_t pub_key_y[32])
|
||||
uint8_t pub_key_y[32])
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
@ -168,7 +166,7 @@ esp_err_t esp_ble_mesh_provisioner_read_oob_pub_key(uint8_t link_idx, uint8_t pu
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -191,7 +189,7 @@ esp_err_t esp_ble_mesh_provisioner_input_string(const char *string, uint8_t link
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -214,7 +212,7 @@ esp_err_t esp_ble_mesh_provisioner_input_number(uint32_t number, uint8_t link_id
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -232,7 +230,7 @@ esp_err_t esp_ble_mesh_provisioner_prov_enable(esp_ble_mesh_prov_bearer_t bearer
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -249,7 +247,7 @@ esp_err_t esp_ble_mesh_provisioner_prov_disable(esp_ble_mesh_prov_bearer_t beare
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -271,7 +269,7 @@ esp_err_t esp_ble_mesh_provisioner_add_unprov_dev(esp_ble_mesh_unprov_dev_add_t
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -280,7 +278,7 @@ esp_err_t esp_ble_mesh_provisioner_add_unprov_dev(esp_ble_mesh_unprov_dev_add_t
|
||||
arg.provisioner_dev_add.add_dev.addr_type = add_dev->addr_type;
|
||||
arg.provisioner_dev_add.add_dev.oob_info = add_dev->oob_info;
|
||||
arg.provisioner_dev_add.add_dev.bearer = add_dev->bearer;
|
||||
memcpy(arg.provisioner_dev_add.add_dev.addr, add_dev->addr, sizeof(esp_bd_addr_t));
|
||||
memcpy(arg.provisioner_dev_add.add_dev.addr, add_dev->addr, sizeof(esp_ble_mesh_bd_addr_t));
|
||||
memcpy(arg.provisioner_dev_add.add_dev.uuid, add_dev->uuid, 16);
|
||||
arg.provisioner_dev_add.flags = flags;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
@ -297,7 +295,7 @@ esp_err_t esp_ble_mesh_provisioner_delete_dev(esp_ble_mesh_device_delete_t *del_
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -306,7 +304,7 @@ esp_err_t esp_ble_mesh_provisioner_delete_dev(esp_ble_mesh_device_delete_t *del_
|
||||
arg.provisioner_dev_del.del_dev.flag = del_dev->flag;
|
||||
if (del_dev->flag & DEL_DEV_ADDR_FLAG) {
|
||||
arg.provisioner_dev_del.del_dev.addr_type = del_dev->addr_type;
|
||||
memcpy(arg.provisioner_dev_del.del_dev.addr, del_dev->addr, sizeof(esp_bd_addr_t));
|
||||
memcpy(arg.provisioner_dev_del.del_dev.addr, del_dev->addr, sizeof(esp_ble_mesh_bd_addr_t));
|
||||
} else if (del_dev->flag & DEL_DEV_UUID_FLAG) {
|
||||
memcpy(arg.provisioner_dev_del.del_dev.uuid, del_dev->uuid, 16);
|
||||
}
|
||||
@ -320,7 +318,7 @@ esp_err_t esp_ble_mesh_provisioner_set_dev_uuid_match(const uint8_t *match_val,
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -346,7 +344,7 @@ esp_err_t esp_ble_mesh_provisioner_set_prov_data_info(esp_ble_mesh_prov_data_inf
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -379,7 +377,7 @@ esp_err_t esp_ble_mesh_set_fast_prov_info(esp_ble_mesh_fast_prov_info_t *fast_pr
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -408,7 +406,7 @@ esp_err_t esp_ble_mesh_set_fast_prov_action(esp_ble_mesh_fast_prov_action_t acti
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
|
@ -18,8 +18,6 @@
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_prov.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
@ -28,7 +26,7 @@ esp_err_t esp_ble_mesh_proxy_identity_enable(void)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -41,7 +39,7 @@ esp_err_t esp_ble_mesh_proxy_gatt_enable(void)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -54,7 +52,7 @@ esp_err_t esp_ble_mesh_proxy_gatt_disable(void)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
@ -63,3 +61,117 @@ esp_err_t esp_ble_mesh_proxy_gatt_disable(void)
|
||||
return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_proxy_client_connect(esp_ble_mesh_bd_addr_t addr,
|
||||
esp_ble_mesh_addr_type_t addr_type, uint16_t net_idx)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!addr || addr_type > ESP_BLE_MESH_ADDR_TYPE_RANDOM) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
msg.act = BTC_BLE_MESH_ACT_PROXY_CLIENT_CONNECT;
|
||||
|
||||
memcpy(arg.proxy_client_connect.addr, addr, BD_ADDR_LEN);
|
||||
arg.proxy_client_connect.addr_type = addr_type;
|
||||
arg.proxy_client_connect.net_idx = net_idx;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_proxy_client_disconnect(uint8_t conn_handle)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
msg.act = BTC_BLE_MESH_ACT_PROXY_CLIENT_DISCONNECT;
|
||||
|
||||
arg.proxy_client_disconnect.conn_handle = conn_handle;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_proxy_client_set_filter_type(uint8_t conn_handle,
|
||||
uint16_t net_idx, esp_ble_mesh_proxy_filter_type_t filter_type)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (filter_type > PROXY_FILTER_BLACKLIST) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
msg.act = BTC_BLE_MESH_ACT_PROXY_CLIENT_SET_FILTER_TYPE;
|
||||
|
||||
arg.proxy_client_set_filter_type.conn_handle = conn_handle;
|
||||
arg.proxy_client_set_filter_type.net_idx = net_idx;
|
||||
arg.proxy_client_set_filter_type.filter_type = filter_type;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_proxy_client_add_filter_addr(uint8_t conn_handle,
|
||||
uint16_t net_idx, uint16_t *addr, uint16_t addr_num)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!addr || addr_num == 0) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
msg.act = BTC_BLE_MESH_ACT_PROXY_CLIENT_ADD_FILTER_ADDR;
|
||||
|
||||
arg.proxy_client_add_filter_addr.conn_handle = conn_handle;
|
||||
arg.proxy_client_add_filter_addr.net_idx = net_idx;
|
||||
arg.proxy_client_add_filter_addr.addr_num = addr_num;
|
||||
arg.proxy_client_add_filter_addr.addr = addr;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), btc_ble_mesh_prov_arg_deep_copy)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_proxy_client_remove_filter_addr(uint8_t conn_handle,
|
||||
uint16_t net_idx, uint16_t *addr, uint16_t addr_num)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!addr || addr_num == 0) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
msg.act = BTC_BLE_MESH_ACT_PROXY_CLIENT_REMOVE_FILTER_ADDR;
|
||||
|
||||
arg.proxy_client_remove_filter_addr.conn_handle = conn_handle;
|
||||
arg.proxy_client_remove_filter_addr.net_idx = net_idx;
|
||||
arg.proxy_client_remove_filter_addr.addr_num = addr_num;
|
||||
arg.proxy_client_remove_filter_addr.addr = addr;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), btc_ble_mesh_prov_arg_deep_copy)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -17,4 +17,45 @@
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
/**
|
||||
* @brief Enable BLE Mesh device LPN functionality.
|
||||
*
|
||||
* @note This API enables LPN functionality. Once called, the proper
|
||||
* Friend Request will be sent.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_lpn_enable(void);
|
||||
|
||||
/**
|
||||
* @brief Disable BLE Mesh device LPN functionality.
|
||||
*
|
||||
* @param[in] force: when disabling LPN functionality, use this flag to indicate
|
||||
* whether directly clear corresponding information or just
|
||||
* send friend clear to disable it if friendship has already
|
||||
* been established.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_lpn_disable(bool force);
|
||||
|
||||
/**
|
||||
* @brief LPN tries to poll messages from the Friend Node.
|
||||
*
|
||||
* @note The Friend Poll message is sent by a Low Power node to ask the Friend
|
||||
* node to send a message that it has stored for the Low Power node.
|
||||
* Users can call this API to send Friend Poll message manually. If this
|
||||
* API is not invoked, the bottom layer of the Low Power node will send
|
||||
* Friend Poll before the PollTimeout timer expires.
|
||||
* If the corresponding Friend Update is received and MD is set to 0,
|
||||
* which means there are no messages for the Low Power node, then the
|
||||
* Low Power node will stop scanning.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_lpn_poll(void);
|
||||
|
||||
#endif /* _ESP_BLE_MESH_LOW_POWER_API_H_ */
|
||||
|
@ -134,6 +134,25 @@ esp_err_t esp_ble_mesh_model_publish(esp_ble_mesh_model_t *model, uint32_t opcod
|
||||
uint16_t length, uint8_t *data,
|
||||
esp_ble_mesh_dev_role_t device_role);
|
||||
|
||||
/**
|
||||
* @brief Update a server model state value. If the model publication
|
||||
* state is set properly (e.g. publish address is set to a valid
|
||||
* address), it will publish corresponding status message.
|
||||
*
|
||||
* @note Currently this API is used to update bound state value, not
|
||||
* for all server model states.
|
||||
*
|
||||
* @param[in] model: Server model which is going to update the state.
|
||||
* @param[in] type: Server model state type.
|
||||
* @param[in] value: Server model state value.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_server_model_update_state(esp_ble_mesh_model_t *model,
|
||||
esp_ble_mesh_server_state_type_t type,
|
||||
esp_ble_mesh_server_state_value_t *value);
|
||||
|
||||
/**
|
||||
* @brief Reset the provisioning procedure of the local BLE Mesh node.
|
||||
*
|
||||
|
@ -72,7 +72,7 @@ esp_err_t esp_ble_mesh_node_prov_disable(esp_ble_mesh_prov_bearer_t bearers);
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_node_set_oob_pub_key(uint8_t pub_key_x[32], uint8_t pub_key_y[32],
|
||||
uint8_t private_key[32]);
|
||||
uint8_t private_key[32]);
|
||||
|
||||
/**
|
||||
* @brief Provide provisioning input OOB number.
|
||||
@ -124,7 +124,7 @@ esp_err_t esp_ble_mesh_set_unprovisioned_device_name(const char *name);
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_read_oob_pub_key(uint8_t link_idx, uint8_t pub_key_x[32],
|
||||
uint8_t pub_key_y[32]);
|
||||
uint8_t pub_key_y[32]);
|
||||
|
||||
/**
|
||||
* @brief Provide provisioning input OOB string.
|
||||
@ -259,7 +259,7 @@ esp_err_t esp_ble_mesh_provisioner_delete_dev(esp_ble_mesh_device_delete_t *del_
|
||||
* @param[in] bearer: Adv packet received from PB-GATT or PB-ADV bearer.
|
||||
*
|
||||
*/
|
||||
typedef void (*esp_ble_mesh_prov_adv_cb_t)(const esp_bd_addr_t addr, const esp_ble_addr_type_t addr_type,
|
||||
typedef void (*esp_ble_mesh_prov_adv_cb_t)(const esp_ble_mesh_bd_addr_t addr, const esp_ble_mesh_addr_type_t addr_type,
|
||||
const uint8_t adv_type, const uint8_t *dev_uuid,
|
||||
uint16_t oob_info, esp_ble_mesh_prov_bearer_t bearer);
|
||||
|
||||
|
@ -49,5 +49,70 @@ esp_err_t esp_ble_mesh_proxy_gatt_enable(void);
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_proxy_gatt_disable(void);
|
||||
|
||||
/**
|
||||
* @brief Proxy Client creates a connection with the Proxy Server.
|
||||
*
|
||||
* @param[in] addr: Device address of the Proxy Server.
|
||||
* @param[in] addr_type: Device address type(public or static random).
|
||||
* @param[in] net_idx: NetKey Index related with Network ID in the Mesh Proxy
|
||||
* advertising packet.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_proxy_client_connect(esp_ble_mesh_bd_addr_t addr,
|
||||
esp_ble_mesh_addr_type_t addr_type, uint16_t net_idx);
|
||||
|
||||
/**
|
||||
* @brief Proxy Client terminates a connection with the Proxy Server.
|
||||
*
|
||||
* @param[in] conn_handle: Proxy connection handle.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_proxy_client_disconnect(uint8_t conn_handle);
|
||||
|
||||
/**
|
||||
* @brief Proxy Client sets the filter type of the Proxy Server.
|
||||
*
|
||||
* @param[in] conn_handle: Proxy connection handle.
|
||||
* @param[in] net_idx: Corresponding NetKey Index.
|
||||
* @param[in] filter_type: whitelist or blacklist.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_proxy_client_set_filter_type(uint8_t conn_handle,
|
||||
uint16_t net_idx, esp_ble_mesh_proxy_filter_type_t filter_type);
|
||||
|
||||
/**
|
||||
* @brief Proxy Client adds address to the Proxy Server filter list.
|
||||
*
|
||||
* @param[in] conn_handle: Proxy connection handle.
|
||||
* @param[in] net_idx: Corresponding NetKey Index.
|
||||
* @param[in] addr: Pointer to the filter address.
|
||||
* @param[in] addr_num: Number of the filter address.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_proxy_client_add_filter_addr(uint8_t conn_handle,
|
||||
uint16_t net_idx, uint16_t *addr, uint16_t addr_num);
|
||||
|
||||
/**
|
||||
* @brief Proxy Client removes address from the Proxy Server filter list.
|
||||
*
|
||||
* @param[in] conn_handle: Proxy connection handle.
|
||||
* @param[in] net_idx: Corresponding NetKey Index.
|
||||
* @param[in] addr: Pointer to the filter address.
|
||||
* @param[in] addr_num: Number of the filter address.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_proxy_client_remove_filter_addr(uint8_t conn_handle,
|
||||
uint16_t net_idx, uint16_t *addr, uint16_t addr_num);
|
||||
|
||||
#endif /* _ESP_BLE_MESH_PROXY_API_H_ */
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -17,66 +17,63 @@
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_config_model.h"
|
||||
#include "esp_ble_mesh_config_model_api.h"
|
||||
|
||||
esp_err_t esp_ble_mesh_register_config_client_callback(esp_ble_mesh_cfg_client_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_CFG_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
return (btc_profile_cb_set(BTC_PID_CONFIG_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_register_config_server_callback(esp_ble_mesh_cfg_server_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_CFG_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
return (btc_profile_cb_set(BTC_PID_CONFIG_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_cfg_client_get_state_t *get_state)
|
||||
{
|
||||
btc_ble_mesh_cfg_client_args_t arg = {0};
|
||||
btc_ble_mesh_config_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !get_state) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_CFG_CLIENT;
|
||||
msg.pid = BTC_PID_CONFIG_CLIENT;
|
||||
msg.act = BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE;
|
||||
arg.cfg_client_get_state.params = params;
|
||||
arg.cfg_client_get_state.get_state = get_state;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_cfg_client_args_t), btc_ble_mesh_cfg_client_arg_deep_copy)
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_config_client_args_t), btc_ble_mesh_config_client_arg_deep_copy)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_cfg_client_set_state_t *set_state)
|
||||
{
|
||||
btc_ble_mesh_cfg_client_args_t arg = {0};
|
||||
btc_ble_mesh_config_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !set_state) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_CFG_CLIENT;
|
||||
msg.pid = BTC_PID_CONFIG_CLIENT;
|
||||
msg.act = BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE;
|
||||
arg.cfg_client_set_state.params = params;
|
||||
arg.cfg_client_set_state.set_state = set_state;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_cfg_client_args_t), btc_ble_mesh_cfg_client_arg_deep_copy)
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_config_client_args_t), btc_ble_mesh_config_client_arg_deep_copy)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -17,15 +17,12 @@
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_generic_model.h"
|
||||
#include "esp_ble_mesh_generic_model_api.h"
|
||||
|
||||
esp_err_t esp_ble_mesh_register_generic_client_callback(esp_ble_mesh_generic_client_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_GENERIC_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
@ -40,7 +37,7 @@ esp_err_t esp_ble_mesh_generic_client_get_state(esp_ble_mesh_client_common_param
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GENERIC_CLIENT;
|
||||
@ -62,7 +59,7 @@ esp_err_t esp_ble_mesh_generic_client_set_state(esp_ble_mesh_client_common_param
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GENERIC_CLIENT;
|
||||
@ -73,3 +70,10 @@ esp_err_t esp_ble_mesh_generic_client_set_state(esp_ble_mesh_client_common_param
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_generic_client_args_t), btc_ble_mesh_generic_client_arg_deep_copy)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_register_generic_server_callback(esp_ble_mesh_generic_server_cb_t callback)
|
||||
{
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_GENERIC_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -17,22 +17,19 @@
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_health_model.h"
|
||||
#include "esp_ble_mesh_health_model_api.h"
|
||||
|
||||
esp_err_t esp_ble_mesh_register_health_client_callback(esp_ble_mesh_health_client_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_HEALTH_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_register_health_server_callback(esp_ble_mesh_health_server_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_HEALTH_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
@ -47,7 +44,7 @@ esp_err_t esp_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_HEALTH_CLIENT;
|
||||
@ -69,7 +66,7 @@ esp_err_t esp_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_HEALTH_CLIENT;
|
||||
@ -86,12 +83,16 @@ esp_err_t esp_ble_mesh_health_server_fault_update(esp_ble_mesh_elem_t *element)
|
||||
btc_ble_mesh_health_server_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
if (element == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_HEALTH_SERVER;
|
||||
msg.act = BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE;
|
||||
arg.fault_update.element = element;
|
||||
arg.health_fault_update.element = element;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_health_server_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
|
@ -17,60 +17,63 @@
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_lighting_model.h"
|
||||
#include "esp_ble_mesh_lighting_model_api.h"
|
||||
|
||||
esp_err_t esp_ble_mesh_register_light_client_callback(esp_ble_mesh_light_client_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_LIGHT_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
return (btc_profile_cb_set(BTC_PID_LIGHTING_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_light_client_get_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_light_client_get_state_t *get_state)
|
||||
{
|
||||
btc_ble_mesh_light_client_args_t arg = {0};
|
||||
btc_ble_mesh_lighting_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !get_state) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_LIGHT_CLIENT;
|
||||
msg.act = BTC_BLE_MESH_ACT_LIGHT_CLIENT_GET_STATE;
|
||||
msg.pid = BTC_PID_LIGHTING_CLIENT;
|
||||
msg.act = BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE;
|
||||
arg.light_client_get_state.params = params;
|
||||
arg.light_client_get_state.get_state = get_state;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_light_client_args_t), btc_ble_mesh_light_client_arg_deep_copy)
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_lighting_client_args_t), btc_ble_mesh_lighting_client_arg_deep_copy)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_light_client_set_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_light_client_set_state_t *set_state)
|
||||
{
|
||||
btc_ble_mesh_light_client_args_t arg = {0};
|
||||
btc_ble_mesh_lighting_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !set_state) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_LIGHT_CLIENT;
|
||||
msg.act = BTC_BLE_MESH_ACT_LIGHT_CLIENT_SET_STATE;
|
||||
msg.pid = BTC_PID_LIGHTING_CLIENT;
|
||||
msg.act = BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE;
|
||||
arg.light_client_set_state.params = params;
|
||||
arg.light_client_set_state.set_state = set_state;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_light_client_args_t), btc_ble_mesh_light_client_arg_deep_copy)
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_lighting_client_args_t), btc_ble_mesh_lighting_client_arg_deep_copy)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_register_lighting_server_callback(esp_ble_mesh_lighting_server_cb_t callback)
|
||||
{
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_LIGHTING_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -17,15 +17,12 @@
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_sensor_model.h"
|
||||
#include "esp_ble_mesh_sensor_model_api.h"
|
||||
|
||||
esp_err_t esp_ble_mesh_register_sensor_client_callback(esp_ble_mesh_sensor_client_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_SENSOR_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
@ -40,7 +37,7 @@ esp_err_t esp_ble_mesh_sensor_client_get_state(esp_ble_mesh_client_common_param_
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_SENSOR_CLIENT;
|
||||
@ -62,7 +59,7 @@ esp_err_t esp_ble_mesh_sensor_client_set_state(esp_ble_mesh_client_common_param_
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_SENSOR_CLIENT;
|
||||
@ -74,3 +71,11 @@ esp_err_t esp_ble_mesh_sensor_client_set_state(esp_ble_mesh_client_common_param_
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_register_sensor_server_callback(esp_ble_mesh_sensor_server_cb_t callback)
|
||||
{
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_SENSOR_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,15 +17,12 @@
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "esp_bt_defs.h"
|
||||
#include "esp_bt_main.h"
|
||||
|
||||
#include "btc_ble_mesh_time_scene_model.h"
|
||||
#include "esp_ble_mesh_time_scene_model_api.h"
|
||||
|
||||
esp_err_t esp_ble_mesh_register_time_scene_client_callback(esp_ble_mesh_time_scene_client_cb_t callback)
|
||||
{
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_TIME_SCENE_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
@ -40,7 +37,7 @@ esp_err_t esp_ble_mesh_time_scene_client_get_state(esp_ble_mesh_client_common_pa
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_TIME_SCENE_CLIENT;
|
||||
@ -62,7 +59,7 @@ esp_err_t esp_ble_mesh_time_scene_client_set_state(esp_ble_mesh_client_common_pa
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_TIME_SCENE_CLIENT;
|
||||
@ -74,3 +71,10 @@ esp_err_t esp_ble_mesh_time_scene_client_set_state(esp_ble_mesh_client_common_pa
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_register_time_scene_server_callback(esp_ble_mesh_time_scene_server_cb_t callback)
|
||||
{
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_TIME_SCENE_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
@ -79,8 +79,8 @@ typedef struct esp_ble_mesh_cfg_srv {
|
||||
uint8_t min_hops; /*!< Minimum hops when receiving Heartbeat messages */
|
||||
uint8_t max_hops; /*!< Maximum hops when receiving Heartbeat messages */
|
||||
|
||||
/** Optional subscription tracking function */
|
||||
void (*func)(uint8_t hops, uint16_t feature);
|
||||
/** Optional heartbeat subscription tracking function */
|
||||
esp_ble_mesh_cb_t heartbeat_recv_cb;
|
||||
} heartbeat_sub;
|
||||
} esp_ble_mesh_cfg_srv_t;
|
||||
|
||||
@ -513,8 +513,8 @@ typedef struct {
|
||||
|
||||
/** Parameters of Config Network Transmit Status */
|
||||
typedef struct {
|
||||
uint8_t net_trans_count:3; /*!< Number of transmissions for each Network PDU originating from the node */
|
||||
uint8_t net_trans_step :5; /*!< Maximum hops when receiving Heartbeat messages */
|
||||
uint8_t net_trans_count: 3; /*!< Number of transmissions for each Network PDU originating from the node */
|
||||
uint8_t net_trans_step : 5; /*!< Maximum hops when receiving Heartbeat messages */
|
||||
} esp_ble_mesh_cfg_net_trans_status_cb_t;
|
||||
|
||||
/** Parameters of Config SIG/Vendor Subscription List */
|
||||
@ -610,28 +610,135 @@ typedef enum {
|
||||
ESP_BLE_MESH_CFG_CLIENT_EVT_MAX,
|
||||
} esp_ble_mesh_cfg_client_cb_event_t;
|
||||
|
||||
/** Parameter of Config AppKey Add */
|
||||
/**
|
||||
* @brief Configuration Server model related context.
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
uint16_t app_idx; /*!< AppKey Index of the Config AppKey Add */
|
||||
} esp_ble_mesh_cfg_srv_app_key_add_cb_t;
|
||||
uint16_t element_addr; /*!< Element Address */
|
||||
uint16_t pub_addr; /*!< Publish Address */
|
||||
uint16_t app_idx; /*!< AppKey Index */
|
||||
bool cred_flag; /*!< Friendship Credential Flag */
|
||||
uint8_t pub_ttl; /*!< Publish TTL */
|
||||
uint8_t pub_period; /*!< Publish Period */
|
||||
uint8_t pub_retransmit; /*!< Publish Retransmit */
|
||||
uint16_t company_id; /*!< Company ID */
|
||||
uint16_t model_id; /*!< Model ID */
|
||||
} esp_ble_mesh_state_change_cfg_mod_pub_set_t;
|
||||
|
||||
/** Parameters of Config Model Subscription Add */
|
||||
typedef struct {
|
||||
uint16_t element_addr; /*!< Element Address */
|
||||
uint16_t sub_addr; /*!< Subscription Address */
|
||||
uint16_t company_id; /*!< Company ID */
|
||||
uint16_t model_id; /*!< Model ID */
|
||||
} esp_ble_mesh_state_change_cfg_model_sub_add_t;
|
||||
|
||||
/** Parameters of Config Model Subscription Delete */
|
||||
typedef struct {
|
||||
uint16_t element_addr; /*!< Element Address */
|
||||
uint16_t sub_addr; /*!< Subscription Address */
|
||||
uint16_t company_id; /*!< Company ID */
|
||||
uint16_t model_id; /*!< Model ID */
|
||||
} esp_ble_mesh_state_change_cfg_model_sub_delete_t;
|
||||
|
||||
/** Parameters of Config NetKey Add */
|
||||
typedef struct {
|
||||
uint16_t net_idx; /*!< NetKey Index */
|
||||
uint8_t net_key[16]; /*!< NetKey */
|
||||
} esp_ble_mesh_state_change_cfg_netkey_add_t;
|
||||
|
||||
/** Parameters of Config NetKey Update */
|
||||
typedef struct {
|
||||
uint16_t net_idx; /*!< NetKey Index */
|
||||
uint8_t net_key[16]; /*!< NetKey */
|
||||
} esp_ble_mesh_state_change_cfg_netkey_update_t;
|
||||
|
||||
/** Parameter of Config NetKey Delete */
|
||||
typedef struct {
|
||||
uint16_t net_idx; /*!< NetKey Index */
|
||||
} esp_ble_mesh_state_change_cfg_netkey_delete_t;
|
||||
|
||||
/** Parameters of Config AppKey Add */
|
||||
typedef struct {
|
||||
uint16_t net_idx; /*!< NetKey Index */
|
||||
uint16_t app_idx; /*!< AppKey Index */
|
||||
uint8_t app_key[16]; /*!< AppKey */
|
||||
} esp_ble_mesh_state_change_cfg_appkey_add_t;
|
||||
|
||||
/** Parameters of Config AppKey Update */
|
||||
typedef struct {
|
||||
uint16_t net_idx; /*!< NetKey Index */
|
||||
uint16_t app_idx; /*!< AppKey Index */
|
||||
uint8_t app_key[16]; /*!< AppKey */
|
||||
} esp_ble_mesh_state_change_cfg_appkey_update_t;
|
||||
|
||||
/** Parameters of Config AppKey Delete */
|
||||
typedef struct {
|
||||
uint16_t net_idx; /*!< NetKey Index */
|
||||
uint16_t app_idx; /*!< AppKey Index */
|
||||
} esp_ble_mesh_state_change_cfg_appkey_delete_t;
|
||||
|
||||
/** Parameters of Config Model App Bind */
|
||||
typedef struct {
|
||||
uint16_t element_addr; /*!< Element Address */
|
||||
uint16_t app_idx; /*!< AppKey Index */
|
||||
uint16_t company_id; /*!< Company ID */
|
||||
uint16_t model_id; /*!< Model ID */
|
||||
} esp_ble_mesh_state_change_cfg_model_app_bind_t;
|
||||
|
||||
/** Parameters of Config Model App Unbind */
|
||||
typedef struct {
|
||||
uint16_t element_addr; /*!< Element Address */
|
||||
uint16_t app_idx; /*!< AppKey Index */
|
||||
uint16_t company_id; /*!< Company ID */
|
||||
uint16_t model_id; /*!< Model ID */
|
||||
} esp_ble_mesh_state_change_cfg_model_app_unbind_t;
|
||||
|
||||
/** Parameters of Config Key Refresh Phase Set */
|
||||
typedef struct {
|
||||
uint16_t net_idx; /*!< NetKey Index */
|
||||
uint8_t kr_phase; /*!< New Key Refresh Phase Transition */
|
||||
} esp_ble_mesh_state_change_cfg_kr_phase_set_t;
|
||||
|
||||
/**
|
||||
* @brief Configuration Server Model received message union
|
||||
* @brief Configuration Server model state change value union
|
||||
*/
|
||||
typedef union {
|
||||
esp_ble_mesh_cfg_srv_app_key_add_cb_t app_key_add; /*!< The Config AppKey Add event value */
|
||||
} esp_ble_mesh_cfg_server_common_cb_param_t;
|
||||
/**
|
||||
* The recv_op in ctx can be used to decide which state is changed.
|
||||
*/
|
||||
esp_ble_mesh_state_change_cfg_mod_pub_set_t mod_pub_set; /*!< Config Model Publication Set */
|
||||
esp_ble_mesh_state_change_cfg_model_sub_add_t mod_sub_add; /*!< Config Model Subscription Add */
|
||||
esp_ble_mesh_state_change_cfg_model_sub_delete_t mod_sub_delete; /*!< Config Model Subscription Delete */
|
||||
esp_ble_mesh_state_change_cfg_netkey_add_t netkey_add; /*!< Config NetKey Add */
|
||||
esp_ble_mesh_state_change_cfg_netkey_update_t netkey_update; /*!< Config NetKey Update */
|
||||
esp_ble_mesh_state_change_cfg_netkey_delete_t netkey_delete; /*!< Config NetKey Delete */
|
||||
esp_ble_mesh_state_change_cfg_appkey_add_t appkey_add; /*!< Config AppKey Add */
|
||||
esp_ble_mesh_state_change_cfg_appkey_update_t appkey_update; /*!< Config AppKey Update */
|
||||
esp_ble_mesh_state_change_cfg_appkey_delete_t appkey_delete; /*!< Config AppKey Delete */
|
||||
esp_ble_mesh_state_change_cfg_model_app_bind_t mod_app_bind; /*!< Config Model App Bind */
|
||||
esp_ble_mesh_state_change_cfg_model_app_unbind_t mod_app_unbind; /*!< Config Model App Unbind */
|
||||
esp_ble_mesh_state_change_cfg_kr_phase_set_t kr_phase_set; /*!< Config Key Refresh Phase Set */
|
||||
} esp_ble_mesh_cfg_server_state_change_t;
|
||||
|
||||
/** Configuration Server Model callback parameters */
|
||||
/**
|
||||
* @brief Configuration Server model callback value union
|
||||
*/
|
||||
typedef union {
|
||||
esp_ble_mesh_cfg_server_state_change_t state_change; /*!< ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT */
|
||||
} esp_ble_mesh_cfg_server_cb_value_t;
|
||||
|
||||
/** Configuration Server model callback parameters */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the server model structure */
|
||||
esp_ble_mesh_msg_ctx_t ctx; /*!< The context of the received message */
|
||||
esp_ble_mesh_cfg_server_common_cb_param_t status_cb; /*!< The received configuration message callback values */
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the server model structure */
|
||||
esp_ble_mesh_msg_ctx_t ctx; /*!< Context of the received message */
|
||||
esp_ble_mesh_cfg_server_cb_value_t value; /*!< Value of the received configuration messages */
|
||||
} esp_ble_mesh_cfg_server_cb_param_t;
|
||||
|
||||
/** This enum value is the event of Configuration Server Model */
|
||||
/** This enum value is the event of Configuration Server model */
|
||||
typedef enum {
|
||||
ESP_BLE_MESH_CFG_SERVER_RECV_MSG_EVT,
|
||||
ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT,
|
||||
ESP_BLE_MESH_CFG_SERVER_EVT_MAX,
|
||||
} esp_ble_mesh_cfg_server_cb_event_t;
|
||||
|
||||
|
@ -19,7 +19,6 @@
|
||||
#ifndef _ESP_BLE_MESH_GENERIC_MODEL_API_H_
|
||||
#define _ESP_BLE_MESH_GENERIC_MODEL_API_H_
|
||||
|
||||
#include "generic_client.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_GEN_ONOFF_CLI
|
||||
@ -524,6 +523,775 @@ esp_err_t esp_ble_mesh_generic_client_get_state(esp_ble_mesh_client_common_param
|
||||
esp_err_t esp_ble_mesh_generic_client_set_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_generic_client_set_state_t *set_state);
|
||||
|
||||
/**
|
||||
* @brief Generic Server Models related context.
|
||||
*/
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_GEN_ONOFF_SRV
|
||||
*
|
||||
* @brief Define a new Generic OnOff Server Model.
|
||||
*
|
||||
* @note 1. The Generic OnOff Server Model is a root model.
|
||||
* 2. This model shall support model publication and model subscription.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_gen_onoff_srv_t.
|
||||
*
|
||||
* @return New Generic OnOff Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_GEN_ONOFF_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_GEN_LEVEL_SRV
|
||||
*
|
||||
* @brief Define a new Generic Level Server Model.
|
||||
*
|
||||
* @note 1. The Generic Level Server Model is a root model.
|
||||
* 2. This model shall support model publication and model subscription.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_gen_level_srv_t.
|
||||
*
|
||||
* @return New Generic Level Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_GEN_LEVEL_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_LEVEL_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_GEN_DEF_TRANS_TIME_SRV
|
||||
*
|
||||
* @brief Define a new Generic Default Transition Time Server Model.
|
||||
*
|
||||
* @note 1. The Generic Default Transition Time Server Model is a root model.
|
||||
* 2. This model shall support model publication and model subscription.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_gen_def_trans_time_srv_t.
|
||||
*
|
||||
* @return New Generic Default Transition Time Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_GEN_DEF_TRANS_TIME_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_GEN_POWER_ONOFF_SRV
|
||||
*
|
||||
* @brief Define a new Generic Power OnOff Server Model.
|
||||
*
|
||||
* @note 1. The Generic Power OnOff Server model extends the Generic OnOff Server
|
||||
* model. When this model is present on an element, the corresponding
|
||||
* Generic Power OnOff Setup Server model shall also be present.
|
||||
* 2. This model may be used to represent a variety of devices that do not
|
||||
* fit any of the model descriptions that have been defined but support
|
||||
* the generic properties of On/Off.
|
||||
* 3. This model shall support model publication and model subscription.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_gen_power_onoff_srv_t.
|
||||
*
|
||||
* @return New Generic Power OnOff Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_GEN_POWER_ONOFF_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_GEN_POWER_ONOFF_SETUP_SRV
|
||||
*
|
||||
* @brief Define a new Generic Power OnOff Setup Server Model.
|
||||
*
|
||||
* @note 1. The Generic Power OnOff Setup Server model extends the Generic Power
|
||||
* OnOff Server model and the Generic Default Transition Time Server model.
|
||||
* 2. This model shall support model subscription.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_gen_power_onoff_setup_srv_t.
|
||||
*
|
||||
* @return New Generic Power OnOff Setup Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_GEN_POWER_ONOFF_SETUP_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_GEN_POWER_LEVEL_SRV
|
||||
*
|
||||
* @brief Define a new Generic Power Level Server Model.
|
||||
*
|
||||
* @note 1. The Generic Power Level Server model extends the Generic Power OnOff
|
||||
* Server model and the Generic Level Server model. When this model is
|
||||
* present on an Element, the corresponding Generic Power Level Setup
|
||||
* Server model shall also be present.
|
||||
* 2. This model shall support model publication and model subscription.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_gen_power_level_srv_t.
|
||||
*
|
||||
* @return New Generic Power Level Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_GEN_POWER_LEVEL_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_GEN_POWER_LEVEL_SETUP_SRV
|
||||
*
|
||||
* @brief Define a new Generic Power Level Setup Server Model.
|
||||
*
|
||||
* @note 1. The Generic Power Level Setup Server model extends the Generic Power
|
||||
* Level Server model and the Generic Power OnOff Setup Server model.
|
||||
* 2. This model shall support model subscription.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_gen_power_level_setup_srv_t.
|
||||
*
|
||||
* @return New Generic Power Level Setup Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_GEN_POWER_LEVEL_SETUP_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_GEN_BATTERY_SRV
|
||||
*
|
||||
* @brief Define a new Generic Battery Server Model.
|
||||
*
|
||||
* @note 1. The Generic Battery Server Model is a root model.
|
||||
* 2. This model shall support model publication and model subscription.
|
||||
* 3. The model may be used to represent an element that is powered by a battery.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_gen_battery_srv_t.
|
||||
*
|
||||
* @return New Generic Battery Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_GEN_BATTERY_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_BATTERY_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_GEN_LOCATION_SRV
|
||||
*
|
||||
* @brief Define a new Generic Location Server Model.
|
||||
*
|
||||
* @note 1. The Generic Location Server model is a root model. When this model
|
||||
* is present on an Element, the corresponding Generic Location Setup
|
||||
* Server model shall also be present.
|
||||
* 2. This model shall support model publication and model subscription.
|
||||
* 3. The model may be used to represent an element that knows its
|
||||
* location (global or local).
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_gen_location_srv_t.
|
||||
*
|
||||
* @return New Generic Location Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_GEN_LOCATION_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_LOCATION_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_GEN_LOCATION_SETUP_SRV
|
||||
*
|
||||
* @brief Define a new Generic Location Setup Server Model.
|
||||
*
|
||||
* @note 1. The Generic Location Setup Server model extends the Generic Location
|
||||
* Server model.
|
||||
* 2. This model shall support model subscription.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_gen_location_setup_srv_t.
|
||||
*
|
||||
* @return New Generic Location Setup Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_GEN_LOCATION_SETUP_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_GEN_USER_PROP_SRV
|
||||
*
|
||||
* @brief Define a new Generic User Property Server Model.
|
||||
*
|
||||
* @note 1. The Generic User Property Server model is a root model.
|
||||
* 2. This model shall support model publication and model subscription.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_gen_user_prop_srv_t.
|
||||
*
|
||||
* @return New Generic User Property Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_GEN_USER_PROP_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_USER_PROP_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_GEN_ADMIN_PROP_SRV
|
||||
*
|
||||
* @brief Define a new Generic Admin Property Server Model.
|
||||
*
|
||||
* @note 1. The Generic Admin Property Server model extends the Generic User
|
||||
* Property Server model.
|
||||
* 2. This model shall support model publication and model subscription.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_gen_admin_prop_srv_t.
|
||||
*
|
||||
* @return New Generic Admin Property Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_GEN_ADMIN_PROP_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_GEN_MANUFACTURER_PROP_SRV
|
||||
*
|
||||
* @brief Define a new Generic Manufacturer Property Server Model.
|
||||
*
|
||||
* @note 1. The Generic Manufacturer Property Server model extends the Generic
|
||||
* User Property Server model.
|
||||
* 2. This model shall support model publication and model subscription.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_gen_manu_prop_srv_t.
|
||||
*
|
||||
* @return New Generic Manufacturer Property Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_GEN_MANUFACTURER_PROP_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_GEN_CLIENT_PROP_SRV
|
||||
*
|
||||
* @brief Define a new Generic User Property Server Model.
|
||||
*
|
||||
* @note 1. The Generic Client Property Server model is a root model.
|
||||
* 2. This model shall support model publication and model subscription.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_gen_client_prop_srv_t.
|
||||
*
|
||||
* @return New Generic Client Property Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_GEN_CLIENT_PROP_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** Parameters of Generic OnOff state */
|
||||
typedef struct {
|
||||
uint8_t onoff; /*!< The present value of the Generic OnOff state */
|
||||
uint8_t target_onoff; /*!< The target value of the Generic OnOff state */
|
||||
} esp_ble_mesh_gen_onoff_state_t;
|
||||
|
||||
/** User data of Generic OnOff Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic OnOff Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
esp_ble_mesh_gen_onoff_state_t state; /*!< Parameters of the Generic OnOff state */
|
||||
esp_ble_mesh_last_msg_info_t last; /*!< Parameters of the last received set message */
|
||||
esp_ble_mesh_state_transition_t transition; /*!< Parameters of state transition */
|
||||
} esp_ble_mesh_gen_onoff_srv_t;
|
||||
|
||||
/** Parameters of Generic Level state */
|
||||
typedef struct {
|
||||
int16_t level; /*!< The present value of the Generic Level state */
|
||||
int16_t target_level; /*!< The target value of the Generic Level state */
|
||||
|
||||
/**
|
||||
* When a new transaction starts, level should be set to last_last, and use
|
||||
* "level + incoming delta" to calculate the target level. In another word,
|
||||
* "last_level" is used to record "level" of the last transaction, and
|
||||
* "last_delta" is used to record the previously received delta_level value.
|
||||
*/
|
||||
int16_t last_level; /*!< The last value of the Generic Level state */
|
||||
int32_t last_delta; /*!< The last delta change of the Generic Level state */
|
||||
|
||||
bool move_start; /*!< Indicate if the transition of the Generic Level state has been started */
|
||||
bool positive; /*!< Indicate if the transition is positive or negative */
|
||||
} esp_ble_mesh_gen_level_state_t;
|
||||
|
||||
/** User data of Generic Level Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Level Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
esp_ble_mesh_gen_level_state_t state; /*!< Parameters of the Generic Level state */
|
||||
esp_ble_mesh_last_msg_info_t last; /*!< Parameters of the last received set message */
|
||||
esp_ble_mesh_state_transition_t transition; /*!< Parameters of state transition */
|
||||
int32_t tt_delta_level; /*!< Delta change value of level state transition */
|
||||
} esp_ble_mesh_gen_level_srv_t;
|
||||
|
||||
/** Parameter of Generic Default Transition Time state */
|
||||
typedef struct {
|
||||
uint8_t trans_time; /*!< The value of the Generic Default Transition Time state */
|
||||
} esp_ble_mesh_gen_def_trans_time_state_t;
|
||||
|
||||
/** User data of Generic Default Transition Time Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Default Transition Time Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
esp_ble_mesh_gen_def_trans_time_state_t state; /*!< Parameters of the Generic Default Transition Time state */
|
||||
} esp_ble_mesh_gen_def_trans_time_srv_t;
|
||||
|
||||
/** Parameter of Generic OnPowerUp state */
|
||||
typedef struct {
|
||||
uint8_t onpowerup; /*!< The value of the Generic OnPowerUp state */
|
||||
} esp_ble_mesh_gen_onpowerup_state_t;
|
||||
|
||||
/** User data of Generic Power OnOff Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Power OnOff Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
esp_ble_mesh_gen_onpowerup_state_t *state; /*!< Parameters of the Generic OnPowerUp state */
|
||||
} esp_ble_mesh_gen_power_onoff_srv_t;
|
||||
|
||||
/** User data of Generic Power OnOff Setup Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Power OnOff Setup Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
esp_ble_mesh_gen_onpowerup_state_t *state; /*!< Parameters of the Generic OnPowerUp state */
|
||||
} esp_ble_mesh_gen_power_onoff_setup_srv_t;
|
||||
|
||||
/** Parameters of Generic Power Level state */
|
||||
typedef struct {
|
||||
uint16_t power_actual; /*!< The present value of the Generic Power Actual state */
|
||||
uint16_t target_power_actual; /*!< The target value of the Generic Power Actual state */
|
||||
|
||||
uint16_t power_last; /*!< The value of the Generic Power Last state */
|
||||
uint16_t power_default; /*!< The value of the Generic Power Default state */
|
||||
|
||||
uint8_t status_code; /*!< The status code of setting Generic Power Range state */
|
||||
uint16_t power_range_min; /*!< The minimum value of the Generic Power Range state */
|
||||
uint16_t power_range_max; /*!< The maximum value of the Generic Power Range state */
|
||||
} esp_ble_mesh_gen_power_level_state_t;
|
||||
|
||||
/** User data of Generic Power Level Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Power Level Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
esp_ble_mesh_gen_power_level_state_t *state; /*!< Parameters of the Generic Power Level state */
|
||||
esp_ble_mesh_last_msg_info_t last; /*!< Parameters of the last received set message */
|
||||
esp_ble_mesh_state_transition_t transition; /*!< Parameters of state transition */
|
||||
int32_t tt_delta_level; /*!< Delta change value of level state transition */
|
||||
} esp_ble_mesh_gen_power_level_srv_t;
|
||||
|
||||
/** User data of Generic Power Level Setup Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Power Level Setup Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
esp_ble_mesh_gen_power_level_state_t *state; /*!< Parameters of the Generic Power Level state */
|
||||
} esp_ble_mesh_gen_power_level_setup_srv_t;
|
||||
|
||||
/** Parameters of Generic Battery state */
|
||||
typedef struct {
|
||||
uint32_t battery_level : 8, /*!< The value of the Generic Battery Level state */
|
||||
time_to_discharge : 24; /*!< The value of the Generic Battery Time to Discharge state */
|
||||
uint32_t time_to_charge : 24, /*!< The value of the Generic Battery Time to Charge state */
|
||||
battery_flags : 8; /*!< The value of the Generic Battery Flags state */
|
||||
} esp_ble_mesh_gen_battery_state_t;
|
||||
|
||||
/** User data of Generic Battery Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Battery Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
esp_ble_mesh_gen_battery_state_t state; /*!< Parameters of the Generic Battery state */
|
||||
} esp_ble_mesh_gen_battery_srv_t;
|
||||
|
||||
/** Parameters of Generic Location state */
|
||||
typedef struct {
|
||||
int32_t global_latitude; /*!< The value of the Global Latitude field */
|
||||
int32_t global_longitude; /*!< The value of the Global Longtitude field */
|
||||
int16_t global_altitude; /*!< The value of the Global Altitude field */
|
||||
int16_t local_north; /*!< The value of the Local North field */
|
||||
int16_t local_east; /*!< The value of the Local East field */
|
||||
int16_t local_altitude; /*!< The value of the Local Altitude field */
|
||||
uint8_t floor_number; /*!< The value of the Floor Number field */
|
||||
uint16_t uncertainty; /*!< The value of the Uncertainty field */
|
||||
} esp_ble_mesh_gen_location_state_t;
|
||||
|
||||
/** User data of Generic Location Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Location Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
esp_ble_mesh_gen_location_state_t *state; /*!< Parameters of the Generic Location state */
|
||||
} esp_ble_mesh_gen_location_srv_t;
|
||||
|
||||
/** User data of Generic Location Setup Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Location Setup Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
esp_ble_mesh_gen_location_state_t *state; /*!< Parameters of the Generic Location state */
|
||||
} esp_ble_mesh_gen_location_setup_srv_t;
|
||||
|
||||
/** This enum value is the access vlue of Generic User Property */
|
||||
typedef enum {
|
||||
ESP_BLE_MESH_GEN_USER_ACCESS_PROHIBIT,
|
||||
ESP_BLE_MESH_GEN_USER_ACCESS_READ,
|
||||
ESP_BLE_MESH_GEN_USER_ACCESS_WRITE,
|
||||
ESP_BLE_MESH_GEN_USER_ACCESS_READ_WRITE,
|
||||
} esp_ble_mesh_gen_user_prop_access_t;
|
||||
|
||||
/** This enum value is the access value of Generic Admin Property */
|
||||
typedef enum {
|
||||
ESP_BLE_MESH_GEN_ADMIN_NOT_USER_PROP,
|
||||
ESP_BLE_MESH_GEN_ADMIN_ACCESS_READ,
|
||||
ESP_BLE_MESH_GEN_ADMIN_ACCESS_WRITE,
|
||||
ESP_BLE_MESH_GEN_ADMIN_ACCESS_READ_WRITE,
|
||||
} esp_ble_mesh_gen_admin_prop_access_t;
|
||||
|
||||
/** This enum value is the access value of Generic Manufacturer Property */
|
||||
typedef enum {
|
||||
ESP_BLE_MESH_GEN_MANU_NOT_USER_PROP,
|
||||
ESP_BLE_MESH_GEN_MANU_ACCESS_READ,
|
||||
} esp_ble_mesh_gen_manu_prop_access_t;
|
||||
|
||||
/** Parameters of Generic Property states */
|
||||
typedef struct {
|
||||
uint16_t id; /*!< The value of User/Admin/Manufacturer Property ID */
|
||||
uint8_t user_access; /*!< The value of User Access field */
|
||||
uint8_t admin_access; /*!< The value of Admin Access field */
|
||||
uint8_t manu_access; /*!< The value of Manufacturer Access field */
|
||||
struct net_buf_simple *val; /*!< The value of User/Admin/Manufacturer Property */
|
||||
} esp_ble_mesh_generic_property_t;
|
||||
|
||||
/** User data of Generic User Property Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic User Property Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
uint8_t property_count; /*!< Generic User Property count */
|
||||
esp_ble_mesh_generic_property_t *properties; /*!< Parameters of the Generic User Property state */
|
||||
} esp_ble_mesh_gen_user_prop_srv_t;
|
||||
|
||||
/** User data of Generic Admin Property Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Admin Property Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
uint8_t property_count; /*!< Generic Admin Property count */
|
||||
esp_ble_mesh_generic_property_t *properties; /*!< Parameters of the Generic Admin Property state */
|
||||
} esp_ble_mesh_gen_admin_prop_srv_t;
|
||||
|
||||
/** User data of Generic Manufacturer Property Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Manufacturer Property Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
uint8_t property_count; /*!< Generic Manufacturer Property count */
|
||||
esp_ble_mesh_generic_property_t *properties; /*!< Parameters of the Generic Manufacturer Property state */
|
||||
} esp_ble_mesh_gen_manu_prop_srv_t;
|
||||
|
||||
/** User data of Generic Client Property Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Generic Client Property Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
uint8_t id_count; /*!< Generic Client Property ID count */
|
||||
uint16_t *property_ids; /*!< Parameters of the Generic Client Property state */
|
||||
} esp_ble_mesh_gen_client_prop_srv_t;
|
||||
|
||||
/** Parameter of Generic OnOff Set state change event */
|
||||
typedef struct {
|
||||
uint8_t onoff; /*!< The value of Generic OnOff state */
|
||||
} esp_ble_mesh_state_change_gen_onoff_set_t;
|
||||
|
||||
/** Parameter of Generic Level Set state change event */
|
||||
typedef struct {
|
||||
int16_t level; /*!< The value of Generic Level state */
|
||||
} esp_ble_mesh_state_change_gen_level_set_t;
|
||||
|
||||
/** Parameter of Generic Delta Set state change event */
|
||||
typedef struct {
|
||||
int16_t level; /*!< The value of Generic Level state */
|
||||
} esp_ble_mesh_state_change_gen_delta_set_t;
|
||||
|
||||
/** Parameter of Generic Move Set state change event */
|
||||
typedef struct {
|
||||
int16_t level; /*!< The value of Generic Level state */
|
||||
} esp_ble_mesh_state_change_gen_move_set_t;
|
||||
|
||||
/** Parameter of Generic Default Transition Time Set state change event */
|
||||
typedef struct {
|
||||
uint8_t trans_time; /*!< The value of Generic Default Transition Time state */
|
||||
} esp_ble_mesh_state_change_gen_def_trans_time_set_t;
|
||||
|
||||
/** Parameter of Generic OnPowerUp Set state change event */
|
||||
typedef struct {
|
||||
uint8_t onpowerup; /*!< The value of Generic OnPowerUp state */
|
||||
} esp_ble_mesh_state_change_gen_onpowerup_set_t;
|
||||
|
||||
/** Parameter of Generic Power Level Set state change event */
|
||||
typedef struct {
|
||||
uint16_t power; /*!< The value of Generic Power Actual state */
|
||||
} esp_ble_mesh_state_change_gen_power_level_set_t;
|
||||
|
||||
/** Parameter of Generic Power Default Set state change event */
|
||||
typedef struct {
|
||||
uint16_t power; /*!< The value of Generic Power Default state */
|
||||
} esp_ble_mesh_state_change_gen_power_default_set_t;
|
||||
|
||||
/** Parameters of Generic Power Range Set state change event */
|
||||
typedef struct {
|
||||
uint16_t range_min; /*!< The minimum value of Generic Power Range state */
|
||||
uint16_t range_max; /*!< The maximum value of Generic Power Range state */
|
||||
} esp_ble_mesh_state_change_gen_power_range_set_t;
|
||||
|
||||
/** Parameters of Generic Location Global Set state change event */
|
||||
typedef struct {
|
||||
int32_t latitude; /*!< The Global Latitude value of Generic Location state */
|
||||
int32_t longitude; /*!< The Global Longitude value of Generic Location state */
|
||||
int16_t altitude; /*!< The Global Altitude value of Generic Location state */
|
||||
} esp_ble_mesh_state_change_gen_loc_global_set_t;
|
||||
|
||||
/** Parameters of Generic Location Local Set state change event */
|
||||
typedef struct {
|
||||
int16_t north; /*!< The Local North value of Generic Location state */
|
||||
int16_t east; /*!< The Local East value of Generic Location state */
|
||||
int16_t altitude; /*!< The Local Altitude value of Generic Location state */
|
||||
uint8_t floor_number; /*!< The Floor Number value of Generic Location state */
|
||||
uint16_t uncertainty; /*!< The Uncertainty value of Generic Location state */
|
||||
} esp_ble_mesh_state_change_gen_loc_local_set_t;
|
||||
|
||||
/** Parameters of Generic User Property Set state change event */
|
||||
typedef struct {
|
||||
uint16_t id; /*!< The property id of Generic User Property state */
|
||||
struct net_buf_simple *value; /*!< The property value of Generic User Property state */
|
||||
} esp_ble_mesh_state_change_gen_user_property_set_t;
|
||||
|
||||
/** Parameters of Generic Admin Property Set state change event */
|
||||
typedef struct {
|
||||
uint16_t id; /*!< The property id of Generic Admin Property state */
|
||||
uint8_t access; /*!< The property access of Generic Admin Property state */
|
||||
struct net_buf_simple *value; /*!< The property value of Generic Admin Property state */
|
||||
} esp_ble_mesh_state_change_gen_admin_property_set_t;
|
||||
|
||||
/** Parameters of Generic Manufacturer Property Set state change event */
|
||||
typedef struct {
|
||||
uint16_t id; /*!< The property id of Generic Manufacturer Property state */
|
||||
uint8_t access; /*!< The property value of Generic Manufacturer Property state */
|
||||
} esp_ble_mesh_state_change_gen_manu_property_set_t;
|
||||
|
||||
/**
|
||||
* @brief Generic Server Model state change value union
|
||||
*/
|
||||
typedef union {
|
||||
/**
|
||||
* The recv_op in ctx can be used to decide which state is changed.
|
||||
*/
|
||||
esp_ble_mesh_state_change_gen_onoff_set_t onoff_set; /*!< Generic OnOff Set */
|
||||
esp_ble_mesh_state_change_gen_level_set_t level_set; /*!< Generic Level Set */
|
||||
esp_ble_mesh_state_change_gen_delta_set_t delta_set; /*!< Generic Delta Set */
|
||||
esp_ble_mesh_state_change_gen_move_set_t move_set; /*!< Generic Move Set */
|
||||
esp_ble_mesh_state_change_gen_def_trans_time_set_t def_trans_time_set; /*!< Generic Default Transition Time Set */
|
||||
esp_ble_mesh_state_change_gen_onpowerup_set_t onpowerup_set; /*!< Generic OnPowerUp Set */
|
||||
esp_ble_mesh_state_change_gen_power_level_set_t power_level_set; /*!< Generic Power Level Set */
|
||||
esp_ble_mesh_state_change_gen_power_default_set_t power_default_set; /*!< Generic Power Default Set */
|
||||
esp_ble_mesh_state_change_gen_power_range_set_t power_range_set; /*!< Generic Power Range Set */
|
||||
esp_ble_mesh_state_change_gen_loc_global_set_t loc_global_set; /*!< Generic Location Global Set */
|
||||
esp_ble_mesh_state_change_gen_loc_local_set_t loc_local_set; /*!< Generic Location Local Set */
|
||||
esp_ble_mesh_state_change_gen_user_property_set_t user_property_set; /*!< Generic User Property Set */
|
||||
esp_ble_mesh_state_change_gen_admin_property_set_t admin_property_set; /*!< Generic Admin Property Set */
|
||||
esp_ble_mesh_state_change_gen_manu_property_set_t manu_property_set; /*!< Generic Manufactuer Property Set */
|
||||
} esp_ble_mesh_generic_server_state_change_t;
|
||||
|
||||
/** Context of the received Generic User Property Get message */
|
||||
typedef struct {
|
||||
uint16_t property_id; /*!< Property ID identifying a Generic User Property */
|
||||
} esp_ble_mesh_server_recv_gen_user_property_get_t;
|
||||
|
||||
/** Context of the received Generic Admin Property Get message */
|
||||
typedef struct {
|
||||
uint16_t property_id; /*!< Property ID identifying a Generic Admin Property */
|
||||
} esp_ble_mesh_server_recv_gen_admin_property_get_t;
|
||||
|
||||
/** Context of the received Generic Manufacturer Property message */
|
||||
typedef struct {
|
||||
uint16_t property_id; /*!< Property ID identifying a Generic Manufacturer Property */
|
||||
} esp_ble_mesh_server_recv_gen_manufacturer_property_get_t;
|
||||
|
||||
/** Context of the received Generic Client Properties Get message */
|
||||
typedef struct {
|
||||
uint16_t property_id; /*!< A starting Client Property ID present within an element */
|
||||
} esp_ble_mesh_server_recv_gen_client_properties_get_t;
|
||||
|
||||
/**
|
||||
* @brief Generic Server Model received get message union
|
||||
*/
|
||||
typedef union {
|
||||
esp_ble_mesh_server_recv_gen_user_property_get_t user_property; /*!< Generic User Property Get */
|
||||
esp_ble_mesh_server_recv_gen_admin_property_get_t admin_property; /*!< Generic Admin Property Get */
|
||||
esp_ble_mesh_server_recv_gen_manufacturer_property_get_t manu_property; /*!< Generic Manufacturer Property Get */
|
||||
esp_ble_mesh_server_recv_gen_client_properties_get_t client_properties; /*!< Generic Client Properties Get */
|
||||
} esp_ble_mesh_generic_server_recv_get_msg_t;
|
||||
|
||||
/** Context of the received Generic OnOff Set message */
|
||||
typedef struct {
|
||||
bool op_en; /*!< Indicate if optional parameters are included */
|
||||
uint8_t onoff; /*!< Target value of Generic OnOff state */
|
||||
uint8_t tid; /*!< Transaction ID */
|
||||
uint8_t trans_time; /*!< Time to complete state transition (optional) */
|
||||
uint8_t delay; /*!< Indicate message execution delay (C.1) */
|
||||
} esp_ble_mesh_server_recv_gen_onoff_set_t;
|
||||
|
||||
/** Context of the received Generic Level Set message */
|
||||
typedef struct {
|
||||
bool op_en; /*!< Indicate if optional parameters are included */
|
||||
int16_t level; /*!< Target value of Generic Level state */
|
||||
uint8_t tid; /*!< Transaction ID */
|
||||
uint8_t trans_time; /*!< Time to complete state transition (optional) */
|
||||
uint8_t delay; /*!< Indicate message execution delay (C.1) */
|
||||
} esp_ble_mesh_server_recv_gen_level_set_t;
|
||||
|
||||
/** Context of the received Generic Delta Set message */
|
||||
typedef struct {
|
||||
bool op_en; /*!< Indicate if optional parameters are included */
|
||||
int32_t delta_level; /*!< Delta change of Generic Level state */
|
||||
uint8_t tid; /*!< Transaction ID */
|
||||
uint8_t trans_time; /*!< Time to complete state transition (optional) */
|
||||
uint8_t delay; /*!< Indicate message execution delay (C.1) */
|
||||
} esp_ble_mesh_server_recv_gen_delta_set_t;
|
||||
|
||||
/** Context of the received Generic Move Set message */
|
||||
typedef struct {
|
||||
bool op_en; /*!< Indicate if optional parameters are included */
|
||||
int16_t delta_level; /*!< Delta Level step to calculate Move speed for Generic Level state */
|
||||
uint8_t tid; /*!< Transaction ID */
|
||||
uint8_t trans_time; /*!< Time to complete state transition (optional) */
|
||||
uint8_t delay; /*!< Indicate message execution delay (C.1) */
|
||||
} esp_ble_mesh_server_recv_gen_move_set_t;
|
||||
|
||||
/** Context of the received Generic Default Transition Time Set message */
|
||||
typedef struct {
|
||||
uint8_t trans_time; /*!< The value of the Generic Default Transition Time state */
|
||||
} esp_ble_mesh_server_recv_gen_def_trans_time_set_t;
|
||||
|
||||
/** Context of the received Generic OnPowerUp Set message */
|
||||
typedef struct {
|
||||
uint8_t onpowerup; /*!< The value of the Generic OnPowerUp state */
|
||||
} esp_ble_mesh_server_recv_gen_onpowerup_set_t;
|
||||
|
||||
/** Context of the received Generic Power Level Set message */
|
||||
typedef struct {
|
||||
bool op_en; /*!< Indicate if optional parameters are included */
|
||||
uint16_t power; /*!< Target value of Generic Power Actual state */
|
||||
uint8_t tid; /*!< Transaction ID */
|
||||
uint8_t trans_time; /*!< Time to complete state transition (optional) */
|
||||
uint8_t delay; /*!< Indicate message execution delay (C.1) */
|
||||
} esp_ble_mesh_server_recv_gen_power_level_set_t;
|
||||
|
||||
/** Context of the received Generic Power Default Set message */
|
||||
typedef struct {
|
||||
uint16_t power; /*!< The value of the Generic Power Default state */
|
||||
} esp_ble_mesh_server_recv_gen_power_default_set_t;
|
||||
|
||||
/** Context of the received Generic Power Range Set message */
|
||||
typedef struct {
|
||||
uint16_t range_min; /*!< Value of Range Min field of Generic Power Range state */
|
||||
uint16_t range_max; /*!< Value of Range Max field of Generic Power Range state */
|
||||
} esp_ble_mesh_server_recv_gen_power_range_set_t;
|
||||
|
||||
/** Context of the received Generic Location Global Set message */
|
||||
typedef struct {
|
||||
int32_t global_latitude; /*!< Global Coordinates (Latitude) */
|
||||
int32_t global_longitude; /*!< Global Coordinates (Longitude) */
|
||||
int16_t global_altitude; /*!< Global Altitude */
|
||||
} esp_ble_mesh_server_recv_gen_loc_global_set_t;
|
||||
|
||||
/** Context of the received Generic Location Local Set message */
|
||||
typedef struct {
|
||||
int16_t local_north; /*!< Local Coordinates (North) */
|
||||
int16_t local_east; /*!< Local Coordinates (East) */
|
||||
int16_t local_altitude; /*!< Local Altitude */
|
||||
uint8_t floor_number; /*!< Floor Number */
|
||||
uint16_t uncertainty; /*!< Uncertainty */
|
||||
} esp_ble_mesh_server_recv_gen_loc_local_set_t;
|
||||
|
||||
/** Context of the received Generic User Property Set message */
|
||||
typedef struct {
|
||||
uint16_t property_id; /*!< Property ID identifying a Generic User Property */
|
||||
struct net_buf_simple *property_value; /*!< Raw value for the User Property */
|
||||
} esp_ble_mesh_server_recv_gen_user_property_set_t;
|
||||
|
||||
/** Context of the received Generic Admin Property Set message */
|
||||
typedef struct {
|
||||
uint16_t property_id; /*!< Property ID identifying a Generic Admin Property */
|
||||
uint8_t user_access; /*!< Enumeration indicating user accessn */
|
||||
struct net_buf_simple *property_value; /*!< Raw value for the Admin Property */
|
||||
} esp_ble_mesh_server_recv_gen_admin_property_set_t;
|
||||
|
||||
/** Context of the received Generic Manufacturer Property Set message */
|
||||
typedef struct {
|
||||
uint16_t property_id; /*!< Property ID identifying a Generic Manufacturer Property */
|
||||
uint8_t user_access; /*!< Enumeration indicating user access */
|
||||
} esp_ble_mesh_server_recv_gen_manufacturer_property_set_t;
|
||||
|
||||
/**
|
||||
* @brief Generic Server Model received set message union
|
||||
*/
|
||||
typedef union {
|
||||
esp_ble_mesh_server_recv_gen_onoff_set_t onoff; /*!< Generic OnOff Set/Generic OnOff Set Unack */
|
||||
esp_ble_mesh_server_recv_gen_level_set_t level; /*!< Generic Level Set/Generic Level Set Unack */
|
||||
esp_ble_mesh_server_recv_gen_delta_set_t delta; /*!< Generic Delta Set/Generic Delta Set Unack */
|
||||
esp_ble_mesh_server_recv_gen_move_set_t move; /*!< Generic Move Set/Generic Move Set Unack */
|
||||
esp_ble_mesh_server_recv_gen_def_trans_time_set_t def_trans_time; /*!< Generic Default Transition Time Set/Generic Default Transition Time Set Unack */
|
||||
esp_ble_mesh_server_recv_gen_onpowerup_set_t onpowerup; /*!< Generic OnPowerUp Set/Generic OnPowerUp Set Unack */
|
||||
esp_ble_mesh_server_recv_gen_power_level_set_t power_level; /*!< Generic Power Level Set/Generic Power Level Set Unack */
|
||||
esp_ble_mesh_server_recv_gen_power_default_set_t power_default; /*!< Generic Power Default Set/Generic Power Default Set Unack */
|
||||
esp_ble_mesh_server_recv_gen_power_range_set_t power_range; /*!< Generic Power Range Set/Generic Power Range Set Unack */
|
||||
esp_ble_mesh_server_recv_gen_loc_global_set_t location_global; /*!< Generic Location Global Set/Generic Location Global Set Unack */
|
||||
esp_ble_mesh_server_recv_gen_loc_local_set_t location_local; /*!< Generic Location Local Set/Generic Location Local Set Unack */
|
||||
esp_ble_mesh_server_recv_gen_user_property_set_t user_property; /*!< Generic User Property Set/Generic User Property Set Unack */
|
||||
esp_ble_mesh_server_recv_gen_admin_property_set_t admin_property; /*!< Generic Admin Property Set/Generic Admin Property Set Unack */
|
||||
esp_ble_mesh_server_recv_gen_manufacturer_property_set_t manu_property; /*!< Generic Manufacturer Property Set/Generic Manufacturer Property Set Unack */
|
||||
} esp_ble_mesh_generic_server_recv_set_msg_t;
|
||||
|
||||
/**
|
||||
* @brief Generic Server Model callback value union
|
||||
*/
|
||||
typedef union {
|
||||
esp_ble_mesh_generic_server_state_change_t state_change; /*!< ESP_BLE_MESH_GENERIC_SERVER_STATE_CHANGE_EVT */
|
||||
esp_ble_mesh_generic_server_recv_get_msg_t get; /*!< ESP_BLE_MESH_GENERIC_SERVER_RECV_GET_MSG_EVT */
|
||||
esp_ble_mesh_generic_server_recv_set_msg_t set; /*!< ESP_BLE_MESH_GENERIC_SERVER_RECV_SET_MSG_EVT */
|
||||
} esp_ble_mesh_generic_server_cb_value_t;
|
||||
|
||||
/** Generic Server Model callback parameters */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to Generic Server Models */
|
||||
esp_ble_mesh_msg_ctx_t ctx; /*!< Context of the received messages */
|
||||
esp_ble_mesh_generic_server_cb_value_t value; /*!< Value of the received Generic Messages */
|
||||
} esp_ble_mesh_generic_server_cb_param_t;
|
||||
|
||||
/** This enum value is the event of Generic Server Model */
|
||||
typedef enum {
|
||||
/**
|
||||
* 1. When get_auto_rsp is set to ESP_BLE_MESH_SERVER_AUTO_RSP, no event will be
|
||||
* callback to the application layer when Generic Get messages are received.
|
||||
* 2. When set_auto_rsp is set to ESP_BLE_MESH_SERVER_AUTO_RSP, this event will
|
||||
* be callback to the application layer when Generic Set/Set Unack messages
|
||||
* are received.
|
||||
*/
|
||||
ESP_BLE_MESH_GENERIC_SERVER_STATE_CHANGE_EVT,
|
||||
/**
|
||||
* When get_auto_rsp is set to ESP_BLE_MESH_SERVER_RSP_BY_APP, this event will be
|
||||
* callback to the application layer when Generic Get messages are received.
|
||||
*/
|
||||
ESP_BLE_MESH_GENERIC_SERVER_RECV_GET_MSG_EVT,
|
||||
/**
|
||||
* When set_auto_rsp is set to ESP_BLE_MESH_SERVER_RSP_BY_APP, this event will be
|
||||
* callback to the application layer when Generic Set/Set Unack messages are received.
|
||||
*/
|
||||
ESP_BLE_MESH_GENERIC_SERVER_RECV_SET_MSG_EVT,
|
||||
ESP_BLE_MESH_GENERIC_SERVER_EVT_MAX,
|
||||
} esp_ble_mesh_generic_server_cb_event_t;
|
||||
|
||||
/**
|
||||
* @brief Bluetooth Mesh Generic Server Model function.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Generic Server Model callback function type
|
||||
* @param event: Event type
|
||||
* @param param: Pointer to callback parameter
|
||||
*/
|
||||
typedef void (* esp_ble_mesh_generic_server_cb_t)(esp_ble_mesh_generic_server_cb_event_t event,
|
||||
esp_ble_mesh_generic_server_cb_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief Register BLE Mesh Generic Server Model callback.
|
||||
*
|
||||
* @param[in] callback: Pointer to the callback function.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_register_generic_server_callback(esp_ble_mesh_generic_server_cb_t callback);
|
||||
|
||||
#endif /* _ESP_BLE_MESH_GENERIC_MODEL_API_H_ */
|
||||
|
||||
|
@ -47,39 +47,123 @@
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_HEALTH_CLI, \
|
||||
NULL, NULL, cli_data)
|
||||
|
||||
/** Health Server Model callbacks */
|
||||
/** @def ESP_BLE_MESH_HEALTH_PUB_DEFINE
|
||||
*
|
||||
* A helper to define a health publication context
|
||||
*
|
||||
* @param _name Name given to the publication context variable.
|
||||
* @param _max Maximum number of faults the element can have.
|
||||
* @param _role Role of the device which contains the model.
|
||||
*/
|
||||
#define ESP_BLE_MESH_HEALTH_PUB_DEFINE(_name, _max, _role) \
|
||||
ESP_BLE_MESH_MODEL_PUB_DEFINE(_name, (1 + 3 + (_max)), _role)
|
||||
|
||||
/**
|
||||
* SIG identifier of Health Fault Test.
|
||||
* 0x01 ~ 0xFF: Vendor Specific Test.
|
||||
*/
|
||||
#define ESP_BLE_MESH_HEALTH_STANDARD_TEST 0x00
|
||||
|
||||
/**
|
||||
* Fault values of Health Fault Test.
|
||||
* 0x33 ~ 0x7F: Reserved for Future Use.
|
||||
* 0x80 ~ 0xFF: Vendor Specific Warning/Error.
|
||||
*/
|
||||
#define ESP_BLE_MESH_NO_FAULT 0x00
|
||||
#define ESP_BLE_MESH_BATTERY_LOW_WARNING 0x01
|
||||
#define ESP_BLE_MESH_BATTERY_LOW_ERROR 0x02
|
||||
#define ESP_BLE_MESH_SUPPLY_VOLTAGE_TOO_LOW_WARNING 0x03
|
||||
#define ESP_BLE_MESH_SUPPLY_VOLTAGE_TOO_LOW_ERROR 0x04
|
||||
#define ESP_BLE_MESH_SUPPLY_VOLTAGE_TOO_HIGH_WARNING 0x05
|
||||
#define ESP_BLE_MESH_SUPPLY_VOLTAGE_TOO_HIGH_ERROR 0x06
|
||||
#define ESP_BLE_MESH_POWER_SUPPLY_INTERRUPTED_WARNING 0x07
|
||||
#define ESP_BLE_MESH_POWER_SUPPLY_INTERRUPTED_ERROR 0x08
|
||||
#define ESP_BLE_MESH_NO_LOAD_WARNING 0x09
|
||||
#define ESP_BLE_MESH_NO_LOAD_ERROR 0x0A
|
||||
#define ESP_BLE_MESH_OVERLOAD_WARNING 0x0B
|
||||
#define ESP_BLE_MESH_OVERLOAD_ERROR 0x0C
|
||||
#define ESP_BLE_MESH_OVERHEAT_WARNING 0x0D
|
||||
#define ESP_BLE_MESH_OVERHEAT_ERROR 0x0E
|
||||
#define ESP_BLE_MESH_CONDENSATION_WARNING 0x0F
|
||||
#define ESP_BLE_MESH_CONDENSATION_ERROR 0x10
|
||||
#define ESP_BLE_MESH_VIBRATION_WARNING 0x11
|
||||
#define ESP_BLE_MESH_VIBRATION_ERROR 0x12
|
||||
#define ESP_BLE_MESH_CONFIGURATION_WARNING 0x13
|
||||
#define ESP_BLE_MESH_CONFIGURATION_ERROR 0x14
|
||||
#define ESP_BLE_MESH_ELEMENT_NOT_CALIBRATED_WARNING 0x15
|
||||
#define ESP_BLE_MESH_ELEMENT_NOT_CALIBRATED_ERROR 0x16
|
||||
#define ESP_BLE_MESH_MEMORY_WARNING 0x17
|
||||
#define ESP_BLE_MESH_MEMORY_ERROR 0x18
|
||||
#define ESP_BLE_MESH_SELF_TEST_WARNING 0x19
|
||||
#define ESP_BLE_MESH_SELF_TEST_ERROR 0x1A
|
||||
#define ESP_BLE_MESH_INPUT_TOO_LOW_WARNING 0x1B
|
||||
#define ESP_BLE_MESH_INPUT_TOO_LOW_ERROR 0x1C
|
||||
#define ESP_BLE_MESH_INPUT_TOO_HIGH_WARNING 0x1D
|
||||
#define ESP_BLE_MESH_INPUT_TOO_HIGH_ERROR 0x1E
|
||||
#define ESP_BLE_MESH_INPUT_NO_CHANGE_WARNING 0x1F
|
||||
#define ESP_BLE_MESH_INPUT_NO_CHANGE_ERROR 0x20
|
||||
#define ESP_BLE_MESH_ACTUATOR_BLOCKED_WARNING 0x21
|
||||
#define ESP_BLE_MESH_ACTUATOR_BLOCKED_ERROR 0x22
|
||||
#define ESP_BLE_MESH_HOUSING_OPENED_WARNING 0x23
|
||||
#define ESP_BLE_MESH_HOUSING_OPENED_ERROR 0x24
|
||||
#define ESP_BLE_MESH_TAMPER_WARNING 0x25
|
||||
#define ESP_BLE_MESH_TAMPER_ERROR 0x26
|
||||
#define ESP_BLE_MESH_DEVICE_MOVED_WARNING 0x27
|
||||
#define ESP_BLE_MESH_DEVICE_MOVED_ERROR 0x28
|
||||
#define ESP_BLE_MESH_DEVICE_DROPPED_WARNING 0x29
|
||||
#define ESP_BLE_MESH_DEVICE_DROPPED_ERROR 0x2A
|
||||
#define ESP_BLE_MESH_OVERFLOW_WARNING 0x2B
|
||||
#define ESP_BLE_MESH_OVERFLOW_ERROR 0x2C
|
||||
#define ESP_BLE_MESH_EMPTY_WARNING 0x2D
|
||||
#define ESP_BLE_MESH_EMPTY_ERROR 0x2E
|
||||
#define ESP_BLE_MESH_INTERNAL_BUS_WARNING 0x2F
|
||||
#define ESP_BLE_MESH_INTERNAL_BUS_ERROR 0x30
|
||||
#define ESP_BLE_MESH_MECHANISM_JAMMED_WARNING 0x31
|
||||
#define ESP_BLE_MESH_MECHANISM_JAMMED_ERROR 0x32
|
||||
|
||||
/** ESP BLE Mesh Health Server callback */
|
||||
typedef struct {
|
||||
/** Fetch current faults */
|
||||
int (*fault_get_cur)(esp_ble_mesh_model_t *model, uint8_t *test_id,
|
||||
uint16_t *company_id, uint8_t *faults, uint8_t *fault_count);
|
||||
/** Clear health registered faults. Initialized by the stack. */
|
||||
esp_ble_mesh_cb_t fault_clear;
|
||||
|
||||
/** Fetch registered faults */
|
||||
int (*fault_get_reg)(esp_ble_mesh_model_t *model, uint16_t company_id,
|
||||
uint8_t *test_id, uint8_t *faults, uint8_t *fault_count);
|
||||
/** Run a specific health test. Initialized by the stack. */
|
||||
esp_ble_mesh_cb_t fault_test;
|
||||
|
||||
/** Clear registered faults */
|
||||
int (*fault_clear)(esp_ble_mesh_model_t *model, uint16_t company_id);
|
||||
/** Health attention on callback. Initialized by the stack. */
|
||||
esp_ble_mesh_cb_t attention_on;
|
||||
|
||||
/** Run a specific test */
|
||||
int (*fault_test)(esp_ble_mesh_model_t *model, uint8_t test_id, uint16_t company_id);
|
||||
|
||||
/** Attention on */
|
||||
void (*attn_on)(esp_ble_mesh_model_t *model);
|
||||
|
||||
/** Attention off */
|
||||
void (*attn_off)(esp_ble_mesh_model_t *model);
|
||||
/** Health attention off callback. Initialized by the stack. */
|
||||
esp_ble_mesh_cb_t attention_off;
|
||||
} esp_ble_mesh_health_srv_cb_t;
|
||||
|
||||
/** Health Server Model Context */
|
||||
#define ESP_BLE_MESH_HEALTH_FAULT_ARRAY_SIZE 32
|
||||
|
||||
/** ESP BLE Mesh Health Server test Context */
|
||||
typedef struct {
|
||||
uint8_t id_count; /*!< Number of Health self-test ID */
|
||||
const uint8_t *test_ids; /*!< Array of Health self-test IDs */
|
||||
uint16_t company_id; /*!< Company ID used to identify the Health Fault state */
|
||||
uint8_t prev_test_id; /*!< Current test ID of the health fault test */
|
||||
uint8_t current_faults[ESP_BLE_MESH_HEALTH_FAULT_ARRAY_SIZE]; /*!< Array of current faults */
|
||||
uint8_t registered_faults[ESP_BLE_MESH_HEALTH_FAULT_ARRAY_SIZE]; /*!< Array of registered faults */
|
||||
} __attribute__((packed)) esp_ble_mesh_health_test_t;
|
||||
|
||||
/** ESP BLE Mesh Health Server Model Context */
|
||||
typedef struct {
|
||||
/** Pointer to Health Server Model */
|
||||
esp_ble_mesh_model_t *model;
|
||||
|
||||
/** Optional callback struct */
|
||||
const esp_ble_mesh_health_srv_cb_t *cb;
|
||||
/** Health callback struct */
|
||||
esp_ble_mesh_health_srv_cb_t health_cb;
|
||||
|
||||
/** Attention Timer state */
|
||||
struct k_delayed_work attn_timer;
|
||||
struct k_delayed_work attention_timer;
|
||||
|
||||
/** Attention Timer start flag */
|
||||
bool attention_timer_start;
|
||||
|
||||
/** Health Server fault test */
|
||||
esp_ble_mesh_health_test_t health_test;
|
||||
} esp_ble_mesh_health_srv_t;
|
||||
|
||||
/** Parameter of Health Fault Get */
|
||||
@ -186,14 +270,54 @@ typedef enum {
|
||||
ESP_BLE_MESH_HEALTH_CLIENT_EVT_MAX,
|
||||
} esp_ble_mesh_health_client_cb_event_t;
|
||||
|
||||
/** Health Server Model callback parameter */
|
||||
/** Parameter of publishing Health Current Status completion event */
|
||||
typedef struct {
|
||||
int error_code; /*!< Appropriate error code */
|
||||
int error_code; /*!< The result of publishing Health Current Status */
|
||||
esp_ble_mesh_elem_t *element; /*!< Pointer to the element which contains the Health Server Model */
|
||||
} esp_ble_mesh_health_fault_update_comp_cb_t;
|
||||
|
||||
/** Parameters of Health Fault Clear event */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Health Server Model */
|
||||
uint16_t company_id; /*!< Bluetooth assigned 16-bit Company ID */
|
||||
} esp_ble_mesh_health_fault_clear_cb_t;
|
||||
|
||||
/** Parameters of Health Fault Test event */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Health Server Model */
|
||||
uint8_t test_id; /*!< ID of a specific test to be performed */
|
||||
uint16_t company_id; /*!< Bluetooth assigned 16-bit Company ID */
|
||||
} esp_ble_mesh_health_fault_test_cb_t;
|
||||
|
||||
/** Parameter of Health Attention On event */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Health Server Model */
|
||||
uint8_t time; /*!< Duration of attention timer on (in seconds) */
|
||||
} esp_ble_mesh_health_attention_on_cb_t;
|
||||
|
||||
/** Parameter of Health Attention Off event */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Health Server Model */
|
||||
} esp_ble_mesh_health_attention_off_cb_t;
|
||||
|
||||
/**
|
||||
* @brief Health Server Model callback parameters union
|
||||
*/
|
||||
typedef union {
|
||||
esp_ble_mesh_health_fault_update_comp_cb_t fault_update_comp; /*!< ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMP_EVT */
|
||||
esp_ble_mesh_health_fault_clear_cb_t fault_clear; /*!< ESP_BLE_MESH_HEALTH_SERVER_FAULT_CLEAR_EVT */
|
||||
esp_ble_mesh_health_fault_test_cb_t fault_test; /*!< ESP_BLE_MESH_HEALTH_SERVER_FAULT_TEST_EVT */
|
||||
esp_ble_mesh_health_attention_on_cb_t attention_on; /*!< ESP_BLE_MESH_HEALTH_SERVER_ATTENTION_ON_EVT */
|
||||
esp_ble_mesh_health_attention_off_cb_t attention_off; /*!< ESP_BLE_MESH_HEALTH_SERVER_ATTENTION_OFF_EVT */
|
||||
} esp_ble_mesh_health_server_cb_param_t;
|
||||
|
||||
/** This enum value is the event of Health Server Model */
|
||||
typedef enum {
|
||||
ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMPLETE_EVT,
|
||||
ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMP_EVT,
|
||||
ESP_BLE_MESH_HEALTH_SERVER_FAULT_CLEAR_EVT,
|
||||
ESP_BLE_MESH_HEALTH_SERVER_FAULT_TEST_EVT,
|
||||
ESP_BLE_MESH_HEALTH_SERVER_ATTENTION_ON_EVT,
|
||||
ESP_BLE_MESH_HEALTH_SERVER_ATTENTION_OFF_EVT,
|
||||
ESP_BLE_MESH_HEALTH_SERVER_EVT_MAX,
|
||||
} esp_ble_mesh_health_server_cb_event_t;
|
||||
|
||||
@ -270,7 +394,7 @@ esp_err_t esp_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_
|
||||
esp_ble_mesh_health_client_set_state_t *set_state);
|
||||
|
||||
/**
|
||||
* @brief This function is called by the Health Server Model to start to publish its Current Health Fault.
|
||||
* @brief This function is called by the Health Server Model to update the context of its Health Current status.
|
||||
*
|
||||
* @param[in] element: The element to which the Health Server Model belongs.
|
||||
*
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -19,7 +19,6 @@
|
||||
#ifndef _ESP_BLE_MESH_SENSOR_MODEL_API_H_
|
||||
#define _ESP_BLE_MESH_SENSOR_MODEL_API_H_
|
||||
|
||||
#include "sensor_client.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_SENSOR_CLI
|
||||
@ -45,60 +44,60 @@
|
||||
/** Parameters of Sensor Descriptor Get */
|
||||
typedef struct {
|
||||
bool op_en; /*!< Indicate if optional parameters are included */
|
||||
u16_t property_id; /*!< Property ID of a sensor (optional) */
|
||||
uint16_t property_id; /*!< Property ID of a sensor (optional) */
|
||||
} esp_ble_mesh_sensor_descriptor_get_t;
|
||||
|
||||
/** Parameter of Sensor Cadence Get */
|
||||
typedef struct {
|
||||
u16_t property_id; /*!< Property ID of a sensor */
|
||||
uint16_t property_id; /*!< Property ID of a sensor */
|
||||
} esp_ble_mesh_sensor_cadence_get_t;
|
||||
|
||||
/** Parameters of Sensor Cadence Set */
|
||||
typedef struct {
|
||||
u16_t property_id; /*!< Property ID for the sensor */
|
||||
u8_t fast_cadence_period_divisor : 7, /*!< Divisor for the publish period */
|
||||
status_trigger_type : 1; /*!< The unit and format of the Status Trigger Delta fields */
|
||||
uint16_t property_id; /*!< Property ID for the sensor */
|
||||
uint8_t fast_cadence_period_divisor : 7, /*!< Divisor for the publish period */
|
||||
status_trigger_type : 1; /*!< The unit and format of the Status Trigger Delta fields */
|
||||
struct net_buf_simple *status_trigger_delta_down; /*!< Delta down value that triggers a status message */
|
||||
struct net_buf_simple *status_trigger_delta_up; /*!< Delta up value that triggers a status message */
|
||||
u8_t status_min_interval; /*!< Minimum interval between two consecutive Status messages */
|
||||
uint8_t status_min_interval; /*!< Minimum interval between two consecutive Status messages */
|
||||
struct net_buf_simple *fast_cadence_low; /*!< Low value for the fast cadence range */
|
||||
struct net_buf_simple *fast_cadence_high; /*!< Fast value for the fast cadence range */
|
||||
} esp_ble_mesh_sensor_cadence_set_t;
|
||||
|
||||
/** Parameter of Sensor Settings Get */
|
||||
typedef struct {
|
||||
u16_t sensor_property_id; /*!< Property ID of a sensor */
|
||||
uint16_t sensor_property_id; /*!< Property ID of a sensor */
|
||||
} esp_ble_mesh_sensor_settings_get_t;
|
||||
|
||||
/** Parameters of Sensor Setting Get */
|
||||
typedef struct {
|
||||
u16_t sensor_property_id; /*!< Property ID of a sensor */
|
||||
u16_t sensor_setting_property_id; /*!< Setting ID identifying a setting within a sensor */
|
||||
uint16_t sensor_property_id; /*!< Property ID of a sensor */
|
||||
uint16_t sensor_setting_property_id; /*!< Setting ID identifying a setting within a sensor */
|
||||
} esp_ble_mesh_sensor_setting_get_t;
|
||||
|
||||
/** Parameters of Sensor Setting Set */
|
||||
typedef struct {
|
||||
u16_t sensor_property_id; /*!< Property ID identifying a sensor */
|
||||
u16_t sensor_setting_property_id; /*!< Setting ID identifying a setting within a sensor */
|
||||
uint16_t sensor_property_id; /*!< Property ID identifying a sensor */
|
||||
uint16_t sensor_setting_property_id; /*!< Setting ID identifying a setting within a sensor */
|
||||
struct net_buf_simple *sensor_setting_raw; /*!< Raw value for the setting */
|
||||
} esp_ble_mesh_sensor_setting_set_t;
|
||||
|
||||
/** Parameters of Sensor Get */
|
||||
typedef struct {
|
||||
bool op_en; /*!< Indicate if optional parameters are included */
|
||||
u16_t property_id; /*!< Property ID for the sensor (optional) */
|
||||
bool op_en; /*!< Indicate if optional parameters are included */
|
||||
uint16_t property_id; /*!< Property ID for the sensor (optional) */
|
||||
} esp_ble_mesh_sensor_get_t;
|
||||
|
||||
/** Parameters of Sensor Column Get */
|
||||
typedef struct {
|
||||
u16_t property_id; /*!< Property identifying a sensor */
|
||||
uint16_t property_id; /*!< Property identifying a sensor */
|
||||
struct net_buf_simple *raw_value_x; /*!< Raw value identifying a column */
|
||||
} esp_ble_mesh_sensor_column_get_t;
|
||||
|
||||
/** Parameters of Sensor Series Get */
|
||||
typedef struct {
|
||||
bool op_en; /*!< Indicate if optional parameters are included */
|
||||
u16_t property_id; /*!< Property identifying a sensor */
|
||||
bool op_en; /*!< Indicate if optional parameters are included */
|
||||
uint16_t property_id; /*!< Property identifying a sensor */
|
||||
struct net_buf_simple *raw_value_x1; /*!< Raw value identifying a starting column (optional) */
|
||||
struct net_buf_simple *raw_value_x2; /*!< Raw value identifying an ending column (C.1) */
|
||||
} esp_ble_mesh_sensor_series_get_t;
|
||||
@ -135,22 +134,22 @@ typedef struct {
|
||||
|
||||
/** Parameters of Sensor Cadence Status */
|
||||
typedef struct {
|
||||
u16_t property_id; /*!< Property for the sensor */
|
||||
uint16_t property_id; /*!< Property for the sensor */
|
||||
struct net_buf_simple *sensor_cadence_value; /*!< Value of sensor cadence state */
|
||||
} esp_ble_mesh_sensor_cadence_status_cb_t;
|
||||
|
||||
/** Parameters of Sensor Settings Status */
|
||||
typedef struct {
|
||||
u16_t sensor_property_id; /*!< Property ID identifying a sensor */
|
||||
uint16_t sensor_property_id; /*!< Property ID identifying a sensor */
|
||||
struct net_buf_simple *sensor_setting_property_ids; /*!< A sequence of N sensor setting property IDs (optional) */
|
||||
} esp_ble_mesh_sensor_settings_status_cb_t;
|
||||
|
||||
/** Parameters of Sensor Setting Status */
|
||||
typedef struct {
|
||||
bool op_en; /*!< Indicate id optional parameters are included */
|
||||
u16_t sensor_property_id; /*!< Property ID identifying a sensor */
|
||||
u16_t sensor_setting_property_id; /*!< Setting ID identifying a setting within a sensor */
|
||||
u8_t sensor_setting_access; /*!< Read/Write access rights for the setting (optional) */
|
||||
bool op_en; /*!< Indicate id optional parameters are included */
|
||||
uint16_t sensor_property_id; /*!< Property ID identifying a sensor */
|
||||
uint16_t sensor_setting_property_id; /*!< Setting ID identifying a setting within a sensor */
|
||||
uint8_t sensor_setting_access; /*!< Read/Write access rights for the setting (optional) */
|
||||
struct net_buf_simple *sensor_setting_raw; /*!< Raw value for the setting */
|
||||
} esp_ble_mesh_sensor_setting_status_cb_t;
|
||||
|
||||
@ -161,13 +160,13 @@ typedef struct {
|
||||
|
||||
/** Parameters of Sensor Column Status */
|
||||
typedef struct {
|
||||
u16_t property_id; /*!< Property identifying a sensor and the Y axis */
|
||||
uint16_t property_id; /*!< Property identifying a sensor and the Y axis */
|
||||
struct net_buf_simple *sensor_column_value; /*!< Left values of sensor column status */
|
||||
} esp_ble_mesh_sensor_column_status_cb_t;
|
||||
|
||||
/** Parameters of Sensor Series Status */
|
||||
typedef struct {
|
||||
u16_t property_id; /*!< Property identifying a sensor and the Y axis */
|
||||
uint16_t property_id; /*!< Property identifying a sensor and the Y axis */
|
||||
struct net_buf_simple *sensor_series_value; /*!< Left values of sensor series status */
|
||||
} esp_ble_mesh_sensor_series_status_cb_t;
|
||||
|
||||
@ -256,6 +255,372 @@ esp_err_t esp_ble_mesh_sensor_client_get_state(esp_ble_mesh_client_common_param_
|
||||
esp_err_t esp_ble_mesh_sensor_client_set_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_sensor_client_set_state_t *set_state);
|
||||
|
||||
/**
|
||||
* @brief Sensor Server Models related context.
|
||||
*/
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_SENSOR_SRV
|
||||
*
|
||||
* @brief Define a new Sensor Server Model.
|
||||
*
|
||||
* @note 1. The Sensor Server model is a root model. When this model is present
|
||||
* on an element, the corresponding Sensor Setup Server model shall
|
||||
* also be present.
|
||||
* 2. This model shall support model publication and model subscription.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_sensor_srv_t.
|
||||
*
|
||||
* @return New Sensor Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_SENSOR_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_SENSOR_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_SENSOR_SETUP_SRV
|
||||
*
|
||||
* @brief Define a new Sensor Setup Server Model.
|
||||
*
|
||||
* @note 1. The Sensor Setup Server model extends the Sensor Server model.
|
||||
* 2. This model shall support model publication and model subscription.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_sensor_setup_srv_t.
|
||||
*
|
||||
* @return New Sensor Setup Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_SENSOR_SETUP_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
#define ESP_BLE_MESH_INVALID_SENSOR_PROPERTY_ID 0x0000 /*!< Invalid Sensor Property ID */
|
||||
|
||||
#define ESP_BLE_MESH_SENSOR_PROPERTY_ID_LEN 0x02 /*!< Length of Sensor Property ID */
|
||||
|
||||
#define ESP_BLE_MESH_SENSOR_DESCRIPTOR_LEN 0x08 /*!< Length of Sensor Descriptor state */
|
||||
|
||||
#define ESP_BLE_MESH_SENSOR_UNSPECIFIED_POS_TOLERANCE 0x000 /*!< Unspecified Sensor Positive Tolerance */
|
||||
#define ESP_BLE_MESH_SENSOR_UNSPECIFIED_NEG_TOLERANCE 0x000 /*!< Unspecified Sensor Negative Tolerance */
|
||||
|
||||
#define ESP_BLE_MESH_SENSOR_NOT_APPL_MEASURE_PERIOD 0x00 /*!< Not applicable Sensor Measurement Period */
|
||||
|
||||
#define ESP_BLE_MESH_SENSOR_NOT_APPL_UPDATE_INTERVAL 0x00 /*!< Not applicable Sensor Update Interval */
|
||||
|
||||
#define ESP_BLE_MESH_INVALID_SENSOR_SETTING_PROPERTY_ID 0x0000 /*!< Invalid Sensor Setting Property ID */
|
||||
|
||||
#define ESP_BLE_MESH_SENSOR_SETTING_PROPERTY_ID_LEN 0x02 /*!< Length of Sensor Setting Property ID */
|
||||
#define ESP_BLE_MESH_SENSOR_SETTING_ACCESS_LEN 0x01 /*!< Length of Sensor Setting Access */
|
||||
|
||||
#define ESP_BLE_MESH_SENSOR_SETTING_ACCESS_READ 0x01 /*!< Sensor Setting Access - Read */
|
||||
#define ESP_BLE_MESH_SENSOR_SETTING_ACCESS_READ_WRITE 0x03 /*!< Sensor Setting Access - Read & Write */
|
||||
|
||||
#define ESP_BLE_MESH_SENSOR_DIVISOR_TRIGGER_TYPE_LEN 0x01 /*!< Length of Sensor Divisor Trigger Type */
|
||||
#define ESP_BLE_MESH_SENSOR_STATUS_MIN_INTERVAL_LEN 0x01 /*!< Length of Sensor Status Min Interval */
|
||||
|
||||
#define ESP_BLE_MESH_SENSOR_PERIOD_DIVISOR_MAX_VALUE 15 /*!< Maximum value of Sensor Period Divisor */
|
||||
|
||||
#define ESP_BLE_MESH_SENSOR_STATUS_MIN_INTERVAL_MAX 26 /*!< Maximum value of Sensor Status Min Interval */
|
||||
|
||||
/**
|
||||
* Sensor Status Trigger Type - Format Type of the characteristic
|
||||
* that the Sensor Property ID state references
|
||||
*/
|
||||
#define ESP_BLE_MESH_SENSOR_STATUS_TRIGGER_TYPE_CHAR 0
|
||||
/** Sensor Status Trigger Type - Format Type "uint16" */
|
||||
#define ESP_BLE_MESH_SENSOR_STATUS_TRIGGER_TYPE_UINT16 1
|
||||
|
||||
#define ESP_BLE_MESH_SENSOR_DATA_FORMAT_A 0x00 /*!< Sensor Data Format A */
|
||||
#define ESP_BLE_MESH_SENSOR_DATA_FORMAT_B 0x01 /*!< Sensor Data Format B */
|
||||
|
||||
#define ESP_BLE_MESH_SENSOR_DATA_FORMAT_A_MPID_LEN 0x02 /*!< MPID length of Sensor Data Format A */
|
||||
#define ESP_BLE_MESH_SENSOR_DATA_FORMAT_B_MPID_LEN 0x03 /*!< MPID length of Sensor Data Format B */
|
||||
|
||||
/**
|
||||
* Zero length of Sensor Data.
|
||||
*
|
||||
* Note:
|
||||
* The Length field is a 1-based uint7 value (valid range 0x0–0x7F,
|
||||
* representing range of 1–127). The value 0x7F represents a length
|
||||
* of zero.
|
||||
*/
|
||||
#define ESP_BLE_MESH_SENSOR_DATA_ZERO_LEN 0x7F
|
||||
|
||||
/** This enum value is value of Sensor Sampling Function */
|
||||
enum esp_ble_mesh_sensor_sample_func {
|
||||
ESP_BLE_MESH_SAMPLE_FUNC_UNSPECIFIED,
|
||||
ESP_BLE_MESH_SAMPLE_FUNC_INSTANTANEOUS,
|
||||
ESP_BLE_MESH_SAMPLE_FUNC_ARITHMETIC_MEAN,
|
||||
ESP_BLE_MESH_SAMPLE_FUNC_RMS,
|
||||
ESP_BLE_MESH_SAMPLE_FUNC_MAXIMUM,
|
||||
ESP_BLE_MESH_SAMPLE_FUNC_MINIMUM,
|
||||
ESP_BLE_MESH_SAMPLE_FUNC_ACCUMULATED,
|
||||
ESP_BLE_MESH_SAMPLE_FUNC_COUNT,
|
||||
};
|
||||
|
||||
/** Parameters of Sensor Descriptor state */
|
||||
typedef struct {
|
||||
uint32_t positive_tolerance : 12, /*!< The value of Sensor Positive Tolerance field */
|
||||
negative_tolerance : 12, /*!< The value of Sensor Negative Tolerance field */
|
||||
sampling_function : 8; /*!< The value of Sensor Sampling Function field */
|
||||
uint8_t measure_period; /*!< The value of Sensor Measurement Period field */
|
||||
uint8_t update_interval; /*!< The value of Sensor Update Interval field */
|
||||
} esp_ble_mesh_sensor_descriptor_t;
|
||||
|
||||
/** Parameters of Sensor Setting state */
|
||||
typedef struct {
|
||||
uint16_t property_id; /*!< The value of Sensor Setting Property ID field */
|
||||
uint8_t access; /*!< The value of Sensor Setting Access field */
|
||||
struct net_buf_simple *raw; /*!< The value of Sensor Setting Raw field */
|
||||
} esp_ble_mesh_sensor_setting_t;
|
||||
|
||||
/** Parameters of Sensor Cadence state */
|
||||
typedef struct {
|
||||
uint8_t period_divisor : 7, /*!< The value of Fast Cadence Period Divisor field */
|
||||
trigger_type : 1; /*!< The value of Status Trigger Type field */
|
||||
/**
|
||||
* Note:
|
||||
* The parameter "size" in trigger_delta_down, trigger_delta_up, fast_cadence_low &
|
||||
* fast_cadence_high indicates the exact length of these four parameters, and they
|
||||
* are associated with the Sensor Property ID. Users need to initialize the "size"
|
||||
* precisely.
|
||||
*/
|
||||
struct net_buf_simple *trigger_delta_down; /*!< The value of Status Trigger Delta Down field */
|
||||
struct net_buf_simple *trigger_delta_up; /*!< The value of Status Trigger Delta Up field */
|
||||
uint8_t min_interval; /*!< The value of Status Min Interval field */
|
||||
struct net_buf_simple *fast_cadence_low; /*!< The value of Fast Cadence Low field */
|
||||
struct net_buf_simple *fast_cadence_high; /*!< The value of Fast Cadence High field */
|
||||
} esp_ble_mesh_sensor_cadence_t;
|
||||
|
||||
/** Parameters of Sensor Data state */
|
||||
typedef struct {
|
||||
/**
|
||||
* Format A: The Length field is a 1-based uint4 value (valid range 0x0–0xF,
|
||||
* representing range of 1 – 16).
|
||||
* Format B: The Length field is a 1-based uint7 value (valid range 0x0–0x7F,
|
||||
* representing range of 1 – 127). The value 0x7F represents a
|
||||
* length of zero.
|
||||
*/
|
||||
uint8_t format : 1, /*!< The value of the Sensor Data format */
|
||||
length : 7; /*!< The value of the Sensor Data length */
|
||||
struct net_buf_simple *raw_value; /*!< The value of Sensor Data raw value */
|
||||
} esp_ble_mesh_sensor_data_t;
|
||||
|
||||
/** Parameters of Sensor Series Column state */
|
||||
typedef struct {
|
||||
struct net_buf_simple *raw_value_x; /*!< The value of Sensor Raw Value X field */
|
||||
struct net_buf_simple *column_width; /*!< The value of Sensor Column Width field */
|
||||
struct net_buf_simple *raw_value_y; /*!< The value of Sensor Raw Value Y field */
|
||||
} esp_ble_mesh_sensor_series_column_t;
|
||||
|
||||
/** Parameters of Sensor states */
|
||||
typedef struct {
|
||||
uint16_t sensor_property_id; /*!< The value of Sensor Property ID field */
|
||||
|
||||
/* Constant throughout the lifetime of an element */
|
||||
esp_ble_mesh_sensor_descriptor_t descriptor; /*!< Parameters of the Sensor Descriptor state */
|
||||
|
||||
/**
|
||||
* Multiple Sensor Setting states may be present for each sensor.
|
||||
* The Sensor Setting Property ID values shall be unique for each
|
||||
* Sensor Property ID that identifies a sensor within an element.
|
||||
*/
|
||||
const uint8_t setting_count; /*!< */
|
||||
esp_ble_mesh_sensor_setting_t *settings; /*!< Parameters of the Sensor Setting state */
|
||||
|
||||
/**
|
||||
* The Sensor Cadence state may be not supported by sensors based
|
||||
* on device properties referencing "non-scalar characteristics"
|
||||
* such as "histograms" or "composite characteristics".
|
||||
*/
|
||||
esp_ble_mesh_sensor_cadence_t *cadence; /*!< Parameters of the Sensor Cadence state */
|
||||
|
||||
esp_ble_mesh_sensor_data_t sensor_data; /*!< Parameters of the Sensor Data state */
|
||||
|
||||
esp_ble_mesh_sensor_series_column_t series_column; /*!< Parameters of the Sensor Series Column state */
|
||||
} esp_ble_mesh_sensor_state_t;
|
||||
|
||||
/** User data of Sensor Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Sensor Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
const uint8_t state_count; /*!< Sensor state count */
|
||||
esp_ble_mesh_sensor_state_t *states; /*!< Parameters of the Sensor states */
|
||||
} esp_ble_mesh_sensor_srv_t;
|
||||
|
||||
/** User data of Sensor Setup Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Sensor Setup Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
const uint8_t state_count; /*!< Sensor state count */
|
||||
esp_ble_mesh_sensor_state_t *states; /*!< Parameters of the Sensor states */
|
||||
} esp_ble_mesh_sensor_setup_srv_t;
|
||||
|
||||
/** Parameters of Sensor Cadence Set state change event */
|
||||
typedef struct {
|
||||
uint16_t property_id; /*!< The value of Sensor Property ID state */
|
||||
uint8_t period_divisor : 7, /*!< The value of Fast Cadence Period Divisor state */
|
||||
trigger_type : 1; /*!< The value of Status Trigger Type state */
|
||||
struct net_buf_simple *trigger_delta_down; /*!< The value of Status Trigger Delta Down state */
|
||||
struct net_buf_simple *trigger_delta_up; /*!< The value of Status Trigger Delta Up state */
|
||||
uint8_t min_interval; /*!< The value of Status Min Interval state */
|
||||
struct net_buf_simple *fast_cadence_low; /*!< The value of Fast Cadence Low state */
|
||||
struct net_buf_simple *fast_cadence_high; /*!< The value of Fast Cadence High state */
|
||||
} esp_ble_mesh_state_change_sensor_cadence_set_t;
|
||||
|
||||
/** Parameters of Sensor Setting Set state change event */
|
||||
typedef struct {
|
||||
uint16_t property_id; /*!< The value of Sensor Property ID state */
|
||||
uint16_t setting_property_id; /*!< The value of Sensor Setting Property ID state */
|
||||
struct net_buf_simple *setting_value; /*!< The value of Sensor Property Value state */
|
||||
} esp_ble_mesh_state_change_sensor_setting_set_t;
|
||||
|
||||
/**
|
||||
* @brief Sensor Server Model state change value union
|
||||
*/
|
||||
typedef union {
|
||||
/**
|
||||
* The recv_op in ctx can be used to decide which state is changed.
|
||||
*/
|
||||
esp_ble_mesh_state_change_sensor_cadence_set_t sensor_cadence_set; /*!< Sensor Cadence Set */
|
||||
esp_ble_mesh_state_change_sensor_setting_set_t sensor_setting_set; /*!< Sensor Setting Set */
|
||||
} esp_ble_mesh_sensor_server_state_change_t;
|
||||
|
||||
/** Context of the received Sensor Descriptor Get message */
|
||||
typedef struct {
|
||||
bool op_en; /*!< Indicate if optional parameters are included */
|
||||
uint16_t property_id; /*!< Property ID of a sensor (optional) */
|
||||
} esp_ble_mesh_server_recv_sensor_descriptor_get_t;
|
||||
|
||||
/** Context of the received Sensor Cadence Get message */
|
||||
typedef struct {
|
||||
uint16_t property_id; /*!< Property ID of a sensor */
|
||||
} esp_ble_mesh_server_recv_sensor_cadence_get_t;
|
||||
|
||||
/** Context of the received Sensor Settings Get message */
|
||||
typedef struct {
|
||||
uint16_t property_id; /*!< Property ID of a sensor */
|
||||
} esp_ble_mesh_server_recv_sensor_settings_get_t;
|
||||
|
||||
/** Context of the received Sensor Setting Get message */
|
||||
typedef struct {
|
||||
uint16_t property_id; /*!< Property ID of a sensor */
|
||||
uint16_t setting_property_id; /*!< Setting ID identifying a setting within a sensor */
|
||||
} esp_ble_mesh_server_recv_sensor_setting_get_t;
|
||||
|
||||
/** Context of the received Sensor Get message */
|
||||
typedef struct {
|
||||
bool op_en; /*!< Indicate if optional parameters are included */
|
||||
uint16_t property_id; /*!< Property ID for the sensor (optional) */
|
||||
} esp_ble_mesh_server_recv_sensor_get_t;
|
||||
|
||||
/** Context of the received Sensor Column Get message */
|
||||
typedef struct {
|
||||
uint16_t property_id; /*!< Property identifying a sensor */
|
||||
struct net_buf_simple *raw_value_x; /*!< Raw value identifying a column */
|
||||
} esp_ble_mesh_server_recv_sensor_column_get_t;
|
||||
|
||||
/** Context of the received Sensor Series Get message */
|
||||
typedef struct {
|
||||
bool op_en; /*!< Indicate if optional parameters are included */
|
||||
uint16_t property_id; /*!< Property identifying a sensor */
|
||||
struct net_buf_simple *raw_value; /*!< Raw value containg X1 and X2 (optional) */
|
||||
} esp_ble_mesh_server_recv_sensor_series_get_t;
|
||||
|
||||
/**
|
||||
* @brief Sensor Server Model received get message union
|
||||
*/
|
||||
typedef union {
|
||||
esp_ble_mesh_server_recv_sensor_descriptor_get_t sensor_descriptor; /*!< Sensor Descriptor Get */
|
||||
esp_ble_mesh_server_recv_sensor_cadence_get_t sensor_cadence; /*!< Sensor Cadence Get */
|
||||
esp_ble_mesh_server_recv_sensor_settings_get_t sensor_settings; /*!< Sensor Settings Get */
|
||||
esp_ble_mesh_server_recv_sensor_setting_get_t sensor_setting; /*!< Sensor Setting Get */
|
||||
esp_ble_mesh_server_recv_sensor_get_t sensor_data; /*!< Sensor Get */
|
||||
esp_ble_mesh_server_recv_sensor_column_get_t sensor_column; /*!< Sensor Column Get */
|
||||
esp_ble_mesh_server_recv_sensor_series_get_t sensor_series; /*!< Sensor Series Get */
|
||||
} esp_ble_mesh_sensor_server_recv_get_msg_t;
|
||||
|
||||
/** Context of the received Sensor Cadence Set message */
|
||||
typedef struct {
|
||||
uint16_t property_id; /*!< Property ID for the sensor */
|
||||
struct net_buf_simple *cadence; /*!< Value of Sensor Cadence state */
|
||||
} esp_ble_mesh_server_recv_sensor_cadence_set_t;
|
||||
|
||||
/** Context of the received Sensor Setting Set message */
|
||||
typedef struct {
|
||||
uint16_t property_id; /*!< Property ID identifying a sensor */
|
||||
uint16_t setting_property_id; /*!< Setting ID identifying a setting within a sensor */
|
||||
struct net_buf_simple *setting_raw; /*!< Raw value for the setting */
|
||||
} esp_ble_mesh_server_recv_sensor_setting_set_t;
|
||||
|
||||
/**
|
||||
* @brief Sensor Server Model received set message union
|
||||
*/
|
||||
typedef union {
|
||||
esp_ble_mesh_server_recv_sensor_cadence_set_t sensor_cadence; /*!< Sensor Cadence Set */
|
||||
esp_ble_mesh_server_recv_sensor_setting_set_t sensor_setting; /*!< Sensor Setting Set */
|
||||
} esp_ble_mesh_sensor_server_recv_set_msg_t;
|
||||
|
||||
/**
|
||||
* @brief Sensor Server Model callback value union
|
||||
*/
|
||||
typedef union {
|
||||
esp_ble_mesh_sensor_server_state_change_t state_change; /*!< ESP_BLE_MESH_SENSOR_SERVER_STATE_CHANGE_EVT */
|
||||
esp_ble_mesh_sensor_server_recv_get_msg_t get; /*!< ESP_BLE_MESH_SENSOR_SERVER_RECV_GET_MSG_EVT */
|
||||
esp_ble_mesh_sensor_server_recv_set_msg_t set; /*!< ESP_BLE_MESH_SENSOR_SERVER_RECV_SET_MSG_EVT */
|
||||
} esp_ble_mesh_sensor_server_cb_value_t;
|
||||
|
||||
/** Sensor Server Model callback parameters */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to Sensor Server Models */
|
||||
esp_ble_mesh_msg_ctx_t ctx; /*!< Context of the received messages */
|
||||
esp_ble_mesh_sensor_server_cb_value_t value; /*!< Value of the received Sensor Messages */
|
||||
} esp_ble_mesh_sensor_server_cb_param_t;
|
||||
|
||||
/** This enum value is the event of Sensor Server Model */
|
||||
typedef enum {
|
||||
/**
|
||||
* 1. When get_auto_rsp is set to ESP_BLE_MESH_SERVER_AUTO_RSP, no event will be
|
||||
* callback to the application layer when Sensor Get messages are received.
|
||||
* 2. When set_auto_rsp is set to ESP_BLE_MESH_SERVER_AUTO_RSP, this event will
|
||||
* be callback to the application layer when Sensor Set/Set Unack messages
|
||||
* are received.
|
||||
*/
|
||||
ESP_BLE_MESH_SENSOR_SERVER_STATE_CHANGE_EVT,
|
||||
/**
|
||||
* When get_auto_rsp is set to ESP_BLE_MESH_SERVER_RSP_BY_APP, this event will be
|
||||
* callback to the application layer when Sensor Get messages are received.
|
||||
*/
|
||||
ESP_BLE_MESH_SENSOR_SERVER_RECV_GET_MSG_EVT,
|
||||
/**
|
||||
* When set_auto_rsp is set to ESP_BLE_MESH_SERVER_RSP_BY_APP, this event will be
|
||||
* callback to the application layer when Sensor Set/Set Unack messages are received.
|
||||
*/
|
||||
ESP_BLE_MESH_SENSOR_SERVER_RECV_SET_MSG_EVT,
|
||||
ESP_BLE_MESH_SENSOR_SERVER_EVT_MAX,
|
||||
} esp_ble_mesh_sensor_server_cb_event_t;
|
||||
|
||||
/**
|
||||
* @brief Bluetooth Mesh Sensor Server Model function.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Sensor Server Model callback function type
|
||||
* @param event: Event type
|
||||
* @param param: Pointer to callback parameter
|
||||
*/
|
||||
typedef void (* esp_ble_mesh_sensor_server_cb_t)(esp_ble_mesh_sensor_server_cb_event_t event,
|
||||
esp_ble_mesh_sensor_server_cb_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief Register BLE Mesh Sensor Server Model callback.
|
||||
*
|
||||
* @param[in] callback: Pointer to the callback function.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_register_sensor_server_callback(esp_ble_mesh_sensor_server_cb_t callback);
|
||||
|
||||
#endif /* _ESP_BLE_MESH_SENSOR_MODEL_API_H_ */
|
||||
|
||||
|
||||
|
@ -19,7 +19,6 @@
|
||||
#ifndef _ESP_BLE_MESH_TIME_SCENE_MODEL_API_H_
|
||||
#define _ESP_BLE_MESH_TIME_SCENE_MODEL_API_H_
|
||||
|
||||
#include "time_scene_client.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_TIME_CLI
|
||||
@ -76,69 +75,69 @@
|
||||
|
||||
/** Parameters of Time Set */
|
||||
typedef struct {
|
||||
u8_t tai_seconds[5]; /*!< The current TAI time in seconds */
|
||||
u8_t sub_second; /*!< The sub-second time in units of 1/256 second */
|
||||
u8_t uncertainty; /*!< The estimated uncertainty in 10-millisecond steps */
|
||||
u16_t time_authority : 1; /*!< 0 = No Time Authority, 1 = Time Authority */
|
||||
u16_t tai_utc_delta : 15; /*!< Current difference between TAI and UTC in seconds */
|
||||
u8_t time_zone_offset; /*!< The local time zone offset in 15-minute increments */
|
||||
uint8_t tai_seconds[5]; /*!< The current TAI time in seconds */
|
||||
uint8_t sub_second; /*!< The sub-second time in units of 1/256 second */
|
||||
uint8_t uncertainty; /*!< The estimated uncertainty in 10-millisecond steps */
|
||||
uint16_t time_authority : 1; /*!< 0 = No Time Authority, 1 = Time Authority */
|
||||
uint16_t tai_utc_delta : 15; /*!< Current difference between TAI and UTC in seconds */
|
||||
uint8_t time_zone_offset; /*!< The local time zone offset in 15-minute increments */
|
||||
} esp_ble_mesh_time_set_t;
|
||||
|
||||
/** Parameters of Time Zone Set */
|
||||
typedef struct {
|
||||
u8_t time_zone_offset_new; /*!< Upcoming local time zone offset */
|
||||
u8_t tai_zone_change[5]; /*!< TAI Seconds time of the upcoming Time Zone Offset change */
|
||||
uint8_t time_zone_offset_new; /*!< Upcoming local time zone offset */
|
||||
uint8_t tai_zone_change[5]; /*!< TAI Seconds time of the upcoming Time Zone Offset change */
|
||||
} esp_ble_mesh_time_zone_set_t;
|
||||
|
||||
/** Parameters of TAI-UTC Delta Set */
|
||||
typedef struct {
|
||||
u16_t tai_utc_delta_new : 15; /*!< Upcoming difference between TAI and UTC in seconds */
|
||||
u16_t padding : 1; /*!< Always 0b0. Other values are Prohibited. */
|
||||
u8_t tai_delta_change[5]; /*!< TAI Seconds time of the upcoming TAI-UTC Delta change */
|
||||
uint16_t tai_utc_delta_new : 15; /*!< Upcoming difference between TAI and UTC in seconds */
|
||||
uint16_t padding : 1; /*!< Always 0b0. Other values are Prohibited. */
|
||||
uint8_t tai_delta_change[5]; /*!< TAI Seconds time of the upcoming TAI-UTC Delta change */
|
||||
} esp_ble_mesh_tai_utc_delta_set_t;
|
||||
|
||||
/** Parameter of Time Role Set */
|
||||
typedef struct {
|
||||
u8_t time_role; /*!< The Time Role for the element */
|
||||
uint8_t time_role; /*!< The Time Role for the element */
|
||||
} esp_ble_mesh_time_role_set_t;
|
||||
|
||||
/** Parameter of Scene Store */
|
||||
typedef struct {
|
||||
u16_t scene_number; /*!< The number of scenes to be stored */
|
||||
uint16_t scene_number; /*!< The number of scenes to be stored */
|
||||
} esp_ble_mesh_scene_store_t;
|
||||
|
||||
/** Parameters of Scene Recall */
|
||||
typedef struct {
|
||||
bool op_en; /*!< Indicate if optional parameters are included */
|
||||
u16_t scene_number; /*!< The number of scenes to be recalled */
|
||||
u8_t tid; /*!< Transaction ID */
|
||||
u8_t trans_time; /*!< Time to complete state transition (optional) */
|
||||
u8_t delay; /*!< Indicate message execution delay (C.1) */
|
||||
bool op_en; /*!< Indicate if optional parameters are included */
|
||||
uint16_t scene_number; /*!< The number of scenes to be recalled */
|
||||
uint8_t tid; /*!< Transaction ID */
|
||||
uint8_t trans_time; /*!< Time to complete state transition (optional) */
|
||||
uint8_t delay; /*!< Indicate message execution delay (C.1) */
|
||||
} esp_ble_mesh_scene_recall_t;
|
||||
|
||||
/** Parameter of Scene Delete */
|
||||
typedef struct {
|
||||
u16_t scene_number; /*!< The number of scenes to be deleted */
|
||||
uint16_t scene_number; /*!< The number of scenes to be deleted */
|
||||
} esp_ble_mesh_scene_delete_t;
|
||||
|
||||
/** Parameter of Scheduler Action Get */
|
||||
typedef struct {
|
||||
u8_t index; /*!< Index of the Schedule Register entry to get */
|
||||
uint8_t index; /*!< Index of the Schedule Register entry to get */
|
||||
} esp_ble_mesh_scheduler_act_get_t;
|
||||
|
||||
/** Parameters of Scheduler Action Set */
|
||||
typedef struct {
|
||||
u64_t index : 4; /*!< Index of the Schedule Register entry to set */
|
||||
u64_t year : 7; /*!< Scheduled year for the action */
|
||||
u64_t month : 12; /*!< Scheduled month for the action */
|
||||
u64_t day : 5; /*!< Scheduled day of the month for the action */
|
||||
u64_t hour : 5; /*!< Scheduled hour for the action */
|
||||
u64_t minute : 6; /*!< Scheduled minute for the action */
|
||||
u64_t second : 6; /*!< Scheduled second for the action */
|
||||
u64_t day_of_week : 7; /*!< Schedule days of the week for the action */
|
||||
u64_t action : 4; /*!< Action to be performed at the scheduled time */
|
||||
u64_t trans_time : 8; /*!< Transition time for this action */
|
||||
u16_t scene_number; /*!< Transition time for this action */
|
||||
uint64_t index : 4; /*!< Index of the Schedule Register entry to set */
|
||||
uint64_t year : 7; /*!< Scheduled year for the action */
|
||||
uint64_t month : 12; /*!< Scheduled month for the action */
|
||||
uint64_t day : 5; /*!< Scheduled day of the month for the action */
|
||||
uint64_t hour : 5; /*!< Scheduled hour for the action */
|
||||
uint64_t minute : 6; /*!< Scheduled minute for the action */
|
||||
uint64_t second : 6; /*!< Scheduled second for the action */
|
||||
uint64_t day_of_week : 7; /*!< Schedule days of the week for the action */
|
||||
uint64_t action : 4; /*!< Action to be performed at the scheduled time */
|
||||
uint64_t trans_time : 8; /*!< Transition time for this action */
|
||||
uint16_t scene_number; /*!< Transition time for this action */
|
||||
} esp_ble_mesh_scheduler_act_set_t;
|
||||
|
||||
/**
|
||||
@ -168,69 +167,69 @@ typedef union {
|
||||
|
||||
/** Parameters of Time Status */
|
||||
typedef struct {
|
||||
u8_t tai_seconds[5]; /*!< The current TAI time in seconds */
|
||||
u8_t sub_second; /*!< The sub-second time in units of 1/256 second */
|
||||
u8_t uncertainty; /*!< The estimated uncertainty in 10-millisecond steps */
|
||||
u16_t time_authority : 1; /*!< 0 = No Time Authority, 1 = Time Authority */
|
||||
u16_t tai_utc_delta : 15; /*!< Current difference between TAI and UTC in seconds */
|
||||
u8_t time_zone_offset; /*!< The local time zone offset in 15-minute increments */
|
||||
uint8_t tai_seconds[5]; /*!< The current TAI time in seconds */
|
||||
uint8_t sub_second; /*!< The sub-second time in units of 1/256 second */
|
||||
uint8_t uncertainty; /*!< The estimated uncertainty in 10-millisecond steps */
|
||||
uint16_t time_authority : 1; /*!< 0 = No Time Authority, 1 = Time Authority */
|
||||
uint16_t tai_utc_delta : 15; /*!< Current difference between TAI and UTC in seconds */
|
||||
uint8_t time_zone_offset; /*!< The local time zone offset in 15-minute increments */
|
||||
} esp_ble_mesh_time_status_cb_t;
|
||||
|
||||
/** Parameters of Time Zone Status */
|
||||
typedef struct {
|
||||
u8_t time_zone_offset_curr; /*!< Current local time zone offset */
|
||||
u8_t time_zone_offset_new; /*!< Upcoming local time zone offset */
|
||||
u8_t tai_zone_change[5]; /*!< TAI Seconds time of the upcoming Time Zone Offset change */
|
||||
uint8_t time_zone_offset_curr; /*!< Current local time zone offset */
|
||||
uint8_t time_zone_offset_new; /*!< Upcoming local time zone offset */
|
||||
uint8_t tai_zone_change[5]; /*!< TAI Seconds time of the upcoming Time Zone Offset change */
|
||||
} esp_ble_mesh_time_zone_status_cb_t;
|
||||
|
||||
/** Parameters of TAI-UTC Delta Status */
|
||||
typedef struct {
|
||||
u16_t tai_utc_delta_curr : 15; /*!< Current difference between TAI and UTC in seconds */
|
||||
u16_t padding_1 : 1; /*!< Always 0b0. Other values are Prohibited. */
|
||||
u16_t tai_utc_delta_new : 15; /*!< Upcoming difference between TAI and UTC in seconds */
|
||||
u16_t padding_2 : 1; /*!< Always 0b0. Other values are Prohibited. */
|
||||
u8_t tai_delta_change[5]; /*!< TAI Seconds time of the upcoming TAI-UTC Delta change */
|
||||
uint16_t tai_utc_delta_curr : 15; /*!< Current difference between TAI and UTC in seconds */
|
||||
uint16_t padding_1 : 1; /*!< Always 0b0. Other values are Prohibited. */
|
||||
uint16_t tai_utc_delta_new : 15; /*!< Upcoming difference between TAI and UTC in seconds */
|
||||
uint16_t padding_2 : 1; /*!< Always 0b0. Other values are Prohibited. */
|
||||
uint8_t tai_delta_change[5]; /*!< TAI Seconds time of the upcoming TAI-UTC Delta change */
|
||||
} esp_ble_mesh_tai_utc_delta_status_cb_t;
|
||||
|
||||
/** Parameter of Time Role Status */
|
||||
typedef struct {
|
||||
u8_t time_role; /*!< The Time Role for the element */
|
||||
uint8_t time_role; /*!< The Time Role for the element */
|
||||
} esp_ble_mesh_time_role_status_cb_t;
|
||||
|
||||
/** Parameters of Scene Status */
|
||||
typedef struct {
|
||||
bool op_en; /*!< Indicate if optional parameters are included */
|
||||
u8_t status_code; /*!< Status code of the last operation */
|
||||
u16_t current_scene; /*!< Scene Number of the current scene */
|
||||
u16_t target_scene; /*!< Scene Number of the target scene (optional) */
|
||||
u8_t remain_time; /*!< Time to complete state transition (C.1) */
|
||||
bool op_en; /*!< Indicate if optional parameters are included */
|
||||
uint8_t status_code; /*!< Status code of the last operation */
|
||||
uint16_t current_scene; /*!< Scene Number of the current scene */
|
||||
uint16_t target_scene; /*!< Scene Number of the target scene (optional) */
|
||||
uint8_t remain_time; /*!< Time to complete state transition (C.1) */
|
||||
} esp_ble_mesh_scene_status_cb_t;
|
||||
|
||||
/** Parameters of Scene Register Status */
|
||||
typedef struct {
|
||||
u8_t status_code; /*!< Status code for the previous operation */
|
||||
u16_t current_scene; /*!< Scene Number of the current scene */
|
||||
uint8_t status_code; /*!< Status code for the previous operation */
|
||||
uint16_t current_scene; /*!< Scene Number of the current scene */
|
||||
struct net_buf_simple *scenes; /*!< A list of scenes stored within an element */
|
||||
} esp_ble_mesh_scene_register_status_cb_t;
|
||||
|
||||
/** Parameter of Scheduler Status */
|
||||
typedef struct {
|
||||
u16_t schedules; /*!< Bit field indicating defined Actions in the Schedule Register */
|
||||
uint16_t schedules; /*!< Bit field indicating defined Actions in the Schedule Register */
|
||||
} esp_ble_mesh_scheduler_status_cb_t;
|
||||
|
||||
/** Parameters of Scheduler Action Status */
|
||||
typedef struct {
|
||||
u64_t index : 4; /*!< Enumerates (selects) a Schedule Register entry */
|
||||
u64_t year : 7; /*!< Scheduled year for the action */
|
||||
u64_t month : 12; /*!< Scheduled month for the action */
|
||||
u64_t day : 5; /*!< Scheduled day of the month for the action */
|
||||
u64_t hour : 5; /*!< Scheduled hour for the action */
|
||||
u64_t minute : 6; /*!< Scheduled minute for the action */
|
||||
u64_t second : 6; /*!< Scheduled second for the action */
|
||||
u64_t day_of_week : 7; /*!< Schedule days of the week for the action */
|
||||
u64_t action : 4; /*!< Action to be performed at the scheduled time */
|
||||
u64_t trans_time : 8; /*!< Transition time for this action */
|
||||
u16_t scene_number; /*!< Transition time for this action */
|
||||
uint64_t index : 4; /*!< Enumerates (selects) a Schedule Register entry */
|
||||
uint64_t year : 7; /*!< Scheduled year for the action */
|
||||
uint64_t month : 12; /*!< Scheduled month for the action */
|
||||
uint64_t day : 5; /*!< Scheduled day of the month for the action */
|
||||
uint64_t hour : 5; /*!< Scheduled hour for the action */
|
||||
uint64_t minute : 6; /*!< Scheduled minute for the action */
|
||||
uint64_t second : 6; /*!< Scheduled second for the action */
|
||||
uint64_t day_of_week : 7; /*!< Schedule days of the week for the action */
|
||||
uint64_t action : 4; /*!< Action to be performed at the scheduled time */
|
||||
uint64_t trans_time : 8; /*!< Transition time for this action */
|
||||
uint16_t scene_number; /*!< Transition time for this action */
|
||||
} esp_ble_mesh_scheduler_act_status_cb_t;
|
||||
|
||||
/**
|
||||
@ -315,5 +314,599 @@ esp_err_t esp_ble_mesh_time_scene_client_get_state(esp_ble_mesh_client_common_pa
|
||||
esp_err_t esp_ble_mesh_time_scene_client_set_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_time_scene_client_set_state_t *set_state);
|
||||
|
||||
/**
|
||||
* @brief Time Scene Server Models related context.
|
||||
*/
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_TIME_SRV
|
||||
*
|
||||
* @brief Define a new Time Server Model.
|
||||
*
|
||||
* @note 1. The Time Server model is a root model. When this model is present on an
|
||||
* Element, the corresponding Time Setup Server model shall also be present.
|
||||
* 2. This model shall support model publication and model subscription.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_time_srv_t.
|
||||
*
|
||||
* @return New Time Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_TIME_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_TIME_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_TIME_SETUP_SRV
|
||||
*
|
||||
* @brief Define a new Time Setup Server Model.
|
||||
*
|
||||
* @note 1. The Time Setup Server model extends the Time Server model. Time is
|
||||
* sensitive information that is propagated across a mesh network.
|
||||
* 2. Only an authorized Time Client should be allowed to change the Time
|
||||
* and Time Role states. A dedicated application key Bluetooth SIG
|
||||
* Proprietary should be used on the Time Setup Server to restrict
|
||||
* access to the server to only authorized Time Clients.
|
||||
* 3. This model does not support subscribing nor publishing.
|
||||
*
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_time_setup_srv_t.
|
||||
*
|
||||
* @return New Time Setup Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_TIME_SETUP_SRV(srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_TIME_SETUP_SRV, \
|
||||
NULL, NULL, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_SCENE_SRV
|
||||
*
|
||||
* @brief Define a new Scene Server Model.
|
||||
*
|
||||
* @note 1. The Scene Server model is a root model. When this model is present
|
||||
* on an Element, the corresponding Scene Setup Server model shall
|
||||
* also be present.
|
||||
* 2. This model shall support model publication and model subscription.
|
||||
* 3. The model may be present only on the Primary element of a node.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_scene_srv_t.
|
||||
*
|
||||
* @return New Scene Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_SCENE_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_SCENE_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_SCENE_SETUP_SRV
|
||||
*
|
||||
* @brief Define a new Scene Setup Server Model.
|
||||
*
|
||||
* @note 1. The Scene Setup Server model extends the Scene Server model and
|
||||
* the Generic Default Transition Time Server model.
|
||||
* 2. This model shall support model subscription.
|
||||
* 3. The model may be present only on the Primary element of a node.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_scene_setup_srv_t.
|
||||
*
|
||||
* @return New Scene Setup Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_SCENE_SETUP_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_SCENE_SETUP_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_SCHEDULER_SRV
|
||||
*
|
||||
* @brief Define a new Scheduler Server Model.
|
||||
*
|
||||
* @note 1. The Scheduler Server model extends the Scene Server model. When
|
||||
* this model is present on an Element, the corresponding Scheduler
|
||||
* Setup Server model shall also be present.
|
||||
* 2. This model shall support model publication and model subscription.
|
||||
* 3. The model may be present only on the Primary element of a node.
|
||||
* 4. The model requires the Time Server model shall be present on the element.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_scheduler_srv_t.
|
||||
*
|
||||
* @return New Scheduler Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_SCHEDULER_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_SCHEDULER_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_SCHEDULER_SETUP_SRV
|
||||
*
|
||||
* @brief Define a new Scheduler Setup Server Model.
|
||||
*
|
||||
* @note 1. The Scheduler Setup Server model extends the Scheduler Server and
|
||||
* the Scene Setup Server models.
|
||||
* 2. This model shall support model subscription.
|
||||
* 3. The model may be present only on the Primary element of a node.
|
||||
*
|
||||
* @param srv_pub Pointer to the unique struct esp_ble_mesh_model_pub_t.
|
||||
* @param srv_data Pointer to the unique struct esp_ble_mesh_scheduler_setup_srv_t.
|
||||
*
|
||||
* @return New Scheduler Setup Server Model instance.
|
||||
*/
|
||||
#define ESP_BLE_MESH_MODEL_SCHEDULER_SETUP_SRV(srv_pub, srv_data) \
|
||||
ESP_BLE_MESH_SIG_MODEL(ESP_BLE_MESH_MODEL_ID_SCHEDULER_SETUP_SRV, \
|
||||
NULL, srv_pub, srv_data)
|
||||
|
||||
#define ESP_BLE_MESH_UNKNOWN_TAI_SECONDS 0x0000000000 /*!< Unknown TAI Seconds */
|
||||
#define ESP_BLE_MESH_UNKNOWN_TAI_ZONE_CHANGE 0x0000000000 /*!< Unknown TAI of Zone Change */
|
||||
#define ESP_BLE_MESH_UNKNOWN_TAI_DELTA_CHANGE 0x0000000000 /*!< Unknown TAI of Delta Change */
|
||||
|
||||
#define ESP_BLE_MESH_TAI_UTC_DELAT_MAX_VALUE 0x7FFF /*!< Maximum TAI-UTC Delta value */
|
||||
|
||||
#define ESP_BLE_MESH_TAI_SECONDS_LEN 0x05 /*!< Length of TAI Seconds */
|
||||
#define ESP_BLE_MESH_TAI_OF_ZONE_CHANGE_LEN 0x05 /*!< Length of TAI of Zone Change */
|
||||
#define ESP_BLE_MESH_TAI_OF_DELAT_CHANGE_LEN 0x05 /*!< Length of TAI of Delta Change */
|
||||
|
||||
#define ESP_BLE_MESH_INVALID_SCENE_NUMBER 0x0000 /*!< Invalid Scene Number */
|
||||
#define ESP_BLE_MESH_SCENE_NUMBER_LEN 0x02 /*!< Length of the Scene Number */
|
||||
|
||||
#define ESP_BLE_MESH_SCHEDULE_YEAR_ANY_YEAR 0x64 /*!< Any year of the Scheduled year */
|
||||
|
||||
#define ESP_BLE_MESH_SCHEDULE_DAY_ANY_DAY 0x00 /*!< Any day of the Scheduled day */
|
||||
|
||||
#define ESP_BLE_MESH_SCHEDULE_HOUR_ANY_HOUR 0x18 /*!< Any hour of the Scheduled hour */
|
||||
#define ESP_BLE_MESH_SCHEDULE_HOUR_ONCE_A_DAY 0x19 /*!< Any hour of the Scheduled Day */
|
||||
|
||||
#define ESP_BLE_MESH_SCHEDULE_SEC_ANY_OF_HOUR 0x3C /*!< Any minute of the Scheduled hour */
|
||||
#define ESP_BLE_MESH_SCHEDULE_SEC_EVERY_15_MIN 0x3D /*!< Every 15 minutes of the Scheduled hour */
|
||||
#define ESP_BLE_MESH_SCHEDULE_SEC_EVERY_20_MIN 0x3E /*!< Every 20 minutes of the Scheduled hour */
|
||||
#define ESP_BLE_MESH_SCHEDULE_SEC_ONCE_AN_HOUR 0x3F /*!< Once of the Scheduled hour */
|
||||
|
||||
#define ESP_BLE_MESH_SCHEDULE_SEC_ANY_OF_MIN 0x3C /*!< Any second of the Scheduled minute */
|
||||
#define ESP_BLE_MESH_SCHEDULE_SEC_EVERY_15_SEC 0x3D /*!< Every 15 seconds of the Scheduled minute */
|
||||
#define ESP_BLE_MESH_SCHEDULE_SEC_EVERY_20_SEC 0x3E /*!< Every 20 seconds of the Scheduled minute */
|
||||
#define ESP_BLE_MESH_SCHEDULE_SEC_ONCE_AN_MIN 0x3F /*!< Once of the Scheduled minute */
|
||||
|
||||
#define ESP_BLE_MESH_SCHEDULE_ACT_TURN_OFF 0x00 /*!< Scheduled Action - Turn Off */
|
||||
#define ESP_BLE_MESH_SCHEDULE_ACT_TURN_ON 0x01 /*!< Scheduled Action - Turn On */
|
||||
#define ESP_BLE_MESH_SCHEDULE_ACT_SCENE_RECALL 0x02 /*!< Scheduled Action - Scene Recall */
|
||||
#define ESP_BLE_MESH_SCHEDULE_ACT_NO_ACTION 0x0F /*!< Scheduled Action - No Action */
|
||||
|
||||
#define ESP_BLE_MESH_SCHEDULE_SCENE_NO_SCENE 0x0000 /*!< Scheduled Scene - No Scene */
|
||||
|
||||
#define ESP_BLE_MESH_SCHEDULE_ENTRY_MAX_INDEX 0x0F /*!< Maximum number of Scheduled entries */
|
||||
|
||||
#define ESP_BLE_MESH_TIME_NONE 0x00 /*!< Time Role - None */
|
||||
#define ESP_BLE_MESH_TIME_AUTHORITY 0x01 /*!< Time Role - Mesh Time Authority */
|
||||
#define ESP_BLE_MESH_TIME_RELAY 0x02 /*!< Time Role - Mesh Time Relay */
|
||||
#define ESP_BLE_MESH_TIME_CLINET 0x03 /*!< Time Role - Mesh Time Client */
|
||||
|
||||
#define ESP_BLE_MESH_SCENE_SUCCESS 0x00 /*!< Scene operation - Success */
|
||||
#define ESP_BLE_MESH_SCENE_REG_FULL 0x01 /*!< Scene operation - Scene Register Full */
|
||||
#define ESP_BLE_MESH_SCENE_NOT_FOUND 0x02 /*!< Scene operation - Scene Not Found */
|
||||
|
||||
/** Parameters of Time state */
|
||||
typedef struct {
|
||||
struct {
|
||||
uint8_t tai_seconds[5]; /*!< The value of the TAI Seconds state */
|
||||
uint8_t subsecond; /*!< The value of the Subsecond field */
|
||||
uint8_t uncertainty; /*!< The value of the Uncertainty field */
|
||||
uint8_t time_zone_offset_curr; /*!< The value of the Time Zone Offset Current field */
|
||||
uint8_t time_zone_offset_new; /*!< The value of the Time Zone Offset New state */
|
||||
uint8_t tai_zone_change[5]; /*!< The value of the TAI of Zone Chaneg field */
|
||||
uint16_t time_authority : 1, /*!< The value of the Time Authority bit */
|
||||
tai_utc_delta_curr : 15; /*!< The value of the TAI-UTC Delta Current state */
|
||||
uint16_t tai_utc_delta_new : 15; /*!< The value of the TAI-UTC Delta New state */
|
||||
uint8_t tai_delta_change[5]; /*!< The value of the TAI of Delta Change field */
|
||||
} time; /*!< Parameters of the Time state */
|
||||
uint8_t time_role; /*!< The value of the Time Role state */
|
||||
} esp_ble_mesh_time_state_t;
|
||||
|
||||
/** User data of Time Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Time Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
esp_ble_mesh_time_state_t *state; /*!< Parameters of the Time state */
|
||||
} esp_ble_mesh_time_srv_t;
|
||||
|
||||
/** User data of Time Setup Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Time Setup Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
esp_ble_mesh_time_state_t *state; /*!< Parameters of the Time state */
|
||||
} esp_ble_mesh_time_setup_srv_t;
|
||||
|
||||
/**
|
||||
* 1. Scene Store is an operation of storing values of a present state of an element.
|
||||
* 2. The structure and meaning of the stored state is determined by a model. States
|
||||
* to be stored are specified by each model.
|
||||
* 3. The Scene Store operation shall persistently store all values of all states
|
||||
* marked as Stored with Scene for all models present on all elements of a node.
|
||||
* 4. If a model is extending another model, the extending model shall determine the
|
||||
* Stored with Scene behavior of that model.
|
||||
*/
|
||||
|
||||
/** Parameters of Scene Register state */
|
||||
typedef struct {
|
||||
uint16_t scene_number; /*!< The value of the Scene Number */
|
||||
uint8_t scene_type; /*!< The value of the Scene Type */
|
||||
/**
|
||||
* Scene value may use a union to represent later, the union contains
|
||||
* structures of all the model states which can be stored in a scene.
|
||||
*/
|
||||
struct net_buf_simple *scene_value; /*!< The value of the Scene Value */
|
||||
} esp_ble_mesh_scene_register_t;
|
||||
|
||||
/**
|
||||
* Parameters of Scenes state.
|
||||
*
|
||||
* Scenes serve as memory banks for storage of states (e.g., a power level
|
||||
* or a light level/color). Values of states of an element can be stored
|
||||
* as a scene and can be recalled later from the scene memory.
|
||||
*
|
||||
* A scene is represented by a Scene Number, which is a 16-bit non-zero,
|
||||
* mesh-wide value. (There can be a maximum of 65535 scenes in a mesh
|
||||
* network.) The meaning of a scene, as well as the state storage container
|
||||
* associated with it, are determined by a model.
|
||||
*
|
||||
* The Scenes state change may start numerous parallel model transitions.
|
||||
* In that case, each individual model handles the transition internally.
|
||||
*
|
||||
* The scene transition is defined as a group of individual model transitions
|
||||
* started by a Scene Recall operation. The scene transition is in progress
|
||||
* when at least one transition from the group of individual model transitions
|
||||
* is in progress.
|
||||
*/
|
||||
typedef struct {
|
||||
const uint16_t scene_count; /*!< The Scenes state's scene count */
|
||||
esp_ble_mesh_scene_register_t *scenes; /*!< Parameters of the Scenes state */
|
||||
|
||||
/**
|
||||
* The Current Scene state is a 16-bit value that contains either the Scene
|
||||
* Number of the currently active scene or a value of 0x0000 when no scene
|
||||
* is active.
|
||||
*
|
||||
* When a Scene Store operation or a Scene Recall operation completes with
|
||||
* success, the Current Scene state value shall be to the Scene Number used
|
||||
* during that operation.
|
||||
*
|
||||
* When the Current Scene Number is deleted from a Scene Register state as a
|
||||
* result of Scene Delete operation, the Current Scene state shall be set to
|
||||
* 0x0000.
|
||||
*
|
||||
* When any of the element's state that is marked as “Stored with Scene” has
|
||||
* changed not as a result of a Scene Recall operation, the value of the
|
||||
* Current Scene state shall be set to 0x0000.
|
||||
*
|
||||
* When a scene transition is in progress, the value of the Current Scene
|
||||
* state shall be set to 0x0000.
|
||||
*/
|
||||
uint16_t current_scene; /*!< The value of the Current Scene state */
|
||||
|
||||
/**
|
||||
* The Target Scene state is a 16-bit value that contains the target Scene
|
||||
* Number when a scene transition is in progress.
|
||||
*
|
||||
* When the scene transition is in progress and the target Scene Number is
|
||||
* deleted from a Scene Register state as a result of Scene Delete operation,
|
||||
* the Target Scene state shall be set to 0x0000.
|
||||
*
|
||||
* When the scene transition is in progress and a new Scene Number is stored
|
||||
* in the Scene Register as a result of Scene Store operation, the Target
|
||||
* Scene state shall be set to the new Scene Number.
|
||||
*
|
||||
* When the scene transition is not in progress, the value of the Target Scene
|
||||
* state shall be set to 0x0000.
|
||||
*/
|
||||
uint16_t target_scene; /*!< The value of the Target Scene state */
|
||||
|
||||
/* Indicate the status code for the last operation */
|
||||
uint8_t status_code; /*!< The status code of the last scene operation */
|
||||
|
||||
/* Indicate if scene transition is in progress */
|
||||
bool in_progress; /*!< Indicate if the scene transition is in progress */
|
||||
} esp_ble_mesh_scenes_state_t;
|
||||
|
||||
/** User data of Scene Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Scene Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
esp_ble_mesh_scenes_state_t *state; /*!< Parameters of the Scenes state */
|
||||
esp_ble_mesh_last_msg_info_t last; /*!< Parameters of the last received set message */
|
||||
esp_ble_mesh_state_transition_t transition; /*!< Parameters of state transition */
|
||||
} esp_ble_mesh_scene_srv_t;
|
||||
|
||||
/** User data of Scene Setup Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Scene Setup Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
esp_ble_mesh_scenes_state_t *state; /*!< Parameters of the Scenes state */
|
||||
} esp_ble_mesh_scene_setup_srv_t;
|
||||
|
||||
/** Parameters of Scheduler Register state */
|
||||
typedef struct {
|
||||
bool in_use; /*!< Indicate if the registered schedule is in use */
|
||||
uint64_t year : 7, /*!< The value of Scheduled year for the action */
|
||||
month : 12, /*!< The value of Scheduled month for the action */
|
||||
day : 5, /*!< The value of Scheduled day of the month for the action */
|
||||
hour : 5, /*!< The value of Scheduled hour for the action */
|
||||
minute : 6, /*!< The value of Scheduled minute for the action */
|
||||
second : 6, /*!< The value of Scheduled second for the action */
|
||||
day_of_week : 7, /*!< The value of Schedule days of the week for the action */
|
||||
action : 4, /*!< The value of Action to be performed at the scheduled time */
|
||||
trans_time : 8; /*!< The value of Transition time for this action */
|
||||
uint16_t scene_number; /*!< The value of Scene Number to be used for some actions */
|
||||
} esp_ble_mesh_schedule_register_t;
|
||||
|
||||
/** Parameters of Scheduler state */
|
||||
typedef struct {
|
||||
const uint8_t schedule_count; /*!< Scheduler count */
|
||||
esp_ble_mesh_schedule_register_t *schedules; /*!< Up to 16 scheduled entries */
|
||||
} esp_ble_mesh_scheduler_state_t;
|
||||
|
||||
/** User data of Scheduler Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Scheduler Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
esp_ble_mesh_scheduler_state_t *state; /*!< Parameters of the Scheduler state */
|
||||
} esp_ble_mesh_scheduler_srv_t;
|
||||
|
||||
/** User data of Scheduler Setup Server Model */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to the Scheduler Setup Server Model. Initialized internally. */
|
||||
esp_ble_mesh_server_rsp_ctrl_t rsp_ctrl; /*!< Response control of the server model received messages */
|
||||
esp_ble_mesh_scheduler_state_t *state; /*!< Parameters of the Scheduler state */
|
||||
} esp_ble_mesh_scheduler_setup_srv_t;
|
||||
|
||||
/** Parameters of Time Set state change event */
|
||||
typedef struct {
|
||||
uint8_t tai_seconds[5]; /*!< The current TAI time in seconds */
|
||||
uint8_t subsecond; /*!< The sub-second time in units of 1/256 second */
|
||||
uint8_t uncertainty; /*!< The estimated uncertainty in 10-millisecond steps */
|
||||
uint16_t time_authority : 1; /*!< 0 = No Time Authority, 1 = Time Authority */
|
||||
uint16_t tai_utc_delta_curr : 15; /*!< Current difference between TAI and UTC in seconds */
|
||||
uint8_t time_zone_offset_curr; /*!< The local time zone offset in 15-minute increments */
|
||||
} esp_ble_mesh_state_change_time_set_t;
|
||||
|
||||
/** Parameters of Time Status state change event */
|
||||
typedef struct {
|
||||
uint8_t tai_seconds[5]; /*!< The current TAI time in seconds */
|
||||
uint8_t subsecond; /*!< The sub-second time in units of 1/256 second */
|
||||
uint8_t uncertainty; /*!< The estimated uncertainty in 10-millisecond steps */
|
||||
uint16_t time_authority : 1; /*!< 0 = No Time Authority, 1 = Time Authority */
|
||||
uint16_t tai_utc_delta_curr : 15; /*!< Current difference between TAI and UTC in seconds */
|
||||
uint8_t time_zone_offset_curr; /*!< The local time zone offset in 15-minute increments */
|
||||
} esp_ble_mesh_state_change_time_status_t;
|
||||
|
||||
/** Parameters of Time Zone Set state change event */
|
||||
typedef struct {
|
||||
uint8_t time_zone_offset_new; /*!< Upcoming local time zone offset */
|
||||
uint8_t tai_zone_change[5]; /*!< TAI Seconds time of the upcoming Time Zone Offset change */
|
||||
} esp_ble_mesh_state_change_time_zone_set_t;
|
||||
|
||||
/** Parameters of TAI UTC Delta Set state change event */
|
||||
typedef struct {
|
||||
uint16_t tai_utc_delta_new : 15; /*!< Upcoming difference between TAI and UTC in seconds */
|
||||
uint8_t tai_delta_change[5]; /*!< TAI Seconds time of the upcoming TAI-UTC Delta change */
|
||||
} esp_ble_mesh_state_change_tai_utc_delta_set_t;
|
||||
|
||||
/** Parameter of Time Role Set state change event */
|
||||
typedef struct {
|
||||
uint8_t time_role; /*!< The Time Role for the element */
|
||||
} esp_ble_mesh_state_change_time_role_set_t;
|
||||
|
||||
/** Parameter of Scene Store state change event */
|
||||
typedef struct {
|
||||
uint16_t scene_number; /*!< The number of scenes to be stored */
|
||||
} esp_ble_mesh_state_change_scene_store_t;
|
||||
|
||||
/** Parameter of Scene Recall state change event */
|
||||
typedef struct {
|
||||
uint16_t scene_number; /*!< The number of scenes to be recalled */
|
||||
} esp_ble_mesh_state_change_scene_recall_t;
|
||||
|
||||
/** Parameter of Scene Delete state change event */
|
||||
typedef struct {
|
||||
uint16_t scene_number; /*!< The number of scenes to be deleted */
|
||||
} esp_ble_mesh_state_change_scene_delete_t;
|
||||
|
||||
/** Parameter of Scheduler Action Set state change event */
|
||||
typedef struct {
|
||||
uint64_t index : 4; /*!< Index of the Schedule Register entry to set */
|
||||
uint64_t year : 7; /*!< Scheduled year for the action */
|
||||
uint64_t month : 12; /*!< Scheduled month for the action */
|
||||
uint64_t day : 5; /*!< Scheduled day of the month for the action */
|
||||
uint64_t hour : 5; /*!< Scheduled hour for the action */
|
||||
uint64_t minute : 6; /*!< Scheduled minute for the action */
|
||||
uint64_t second : 6; /*!< Scheduled second for the action */
|
||||
uint64_t day_of_week : 7; /*!< Schedule days of the week for the action */
|
||||
uint64_t action : 4; /*!< Action to be performed at the scheduled time */
|
||||
uint64_t trans_time : 8; /*!< Transition time for this action */
|
||||
uint16_t scene_number; /*!< Scene number to be used for some actions */
|
||||
} esp_ble_mesh_state_change_scheduler_act_set_t;
|
||||
|
||||
/**
|
||||
* @brief Time Scene Server Model state change value union
|
||||
*/
|
||||
typedef union {
|
||||
/**
|
||||
* The recv_op in ctx can be used to decide which state is changed.
|
||||
*/
|
||||
esp_ble_mesh_state_change_time_set_t time_set; /*!< Time Set */
|
||||
esp_ble_mesh_state_change_time_status_t time_status; /*!< Time Status */
|
||||
esp_ble_mesh_state_change_time_zone_set_t time_zone_set; /*!< Time Zone Set */
|
||||
esp_ble_mesh_state_change_tai_utc_delta_set_t tai_utc_delta_set; /*!< TAI UTC Delta Set */
|
||||
esp_ble_mesh_state_change_time_role_set_t time_role_set; /*!< Time Role Set */
|
||||
esp_ble_mesh_state_change_scene_store_t scene_store; /*!< Scene Store */
|
||||
esp_ble_mesh_state_change_scene_recall_t scene_recall; /*!< Scene Recall */
|
||||
esp_ble_mesh_state_change_scene_delete_t scene_delete; /*!< Scene Delete */
|
||||
esp_ble_mesh_state_change_scheduler_act_set_t scheduler_act_set; /*!< Scheduler Action Set */
|
||||
} esp_ble_mesh_time_scene_server_state_change_t;
|
||||
|
||||
/** Context of the received Scheduler Action Get message */
|
||||
typedef struct {
|
||||
uint8_t index; /*!< Index of the Schedule Register entry to get */
|
||||
} esp_ble_mesh_server_recv_scheduler_act_get_t;
|
||||
|
||||
/**
|
||||
* @brief Time Scene Server Model received get message union
|
||||
*/
|
||||
typedef union {
|
||||
esp_ble_mesh_server_recv_scheduler_act_get_t scheduler_act; /*!< Scheduler Action Get */
|
||||
} esp_ble_mesh_time_scene_server_recv_get_msg_t;
|
||||
|
||||
/** Context of the received Time Set message */
|
||||
typedef struct {
|
||||
uint8_t tai_seconds[5]; /*!< The current TAI time in seconds */
|
||||
uint8_t subsecond; /*!< The sub-second time in units of 1/256 second */
|
||||
uint8_t uncertainty; /*!< The estimated uncertainty in 10-millisecond steps */
|
||||
uint16_t time_authority : 1; /*!< 0 = No Time Authority, 1 = Time Authority */
|
||||
uint16_t tai_utc_delta : 15; /*!< Current difference between TAI and UTC in seconds */
|
||||
uint8_t time_zone_offset; /*!< The local time zone offset in 15-minute increments */
|
||||
} esp_ble_mesh_server_recv_time_set_t;
|
||||
|
||||
/** Context of the received Time Zone Set message */
|
||||
typedef struct {
|
||||
uint8_t time_zone_offset_new; /*!< Upcoming local time zone offset */
|
||||
uint8_t tai_zone_change[5]; /*!< TAI Seconds time of the upcoming Time Zone Offset change */
|
||||
} esp_ble_mesh_server_recv_time_zone_set_t;
|
||||
|
||||
/** Context of the received TAI UTC Delta Set message */
|
||||
typedef struct {
|
||||
uint16_t tai_utc_delta_new : 15; /*!< Upcoming difference between TAI and UTC in seconds */
|
||||
uint16_t padding : 1; /*!< Always 0b0. Other values are Prohibited. */
|
||||
uint8_t tai_delta_change[5]; /*!< TAI Seconds time of the upcoming TAI-UTC Delta change */
|
||||
} esp_ble_mesh_server_recv_tai_utc_delta_set_t;
|
||||
|
||||
/** Context of the received Time Role Set message */
|
||||
typedef struct {
|
||||
uint8_t time_role; /*!< The Time Role for the element */
|
||||
} esp_ble_mesh_server_recv_time_role_set_t;
|
||||
|
||||
/** Context of the received Scene Store message */
|
||||
typedef struct {
|
||||
uint16_t scene_number; /*!< The number of scenes to be stored */
|
||||
} esp_ble_mesh_server_recv_scene_store_t;
|
||||
|
||||
/** Context of the received Scene Recall message */
|
||||
typedef struct {
|
||||
bool op_en; /*!< Indicate if optional parameters are included */
|
||||
uint16_t scene_number; /*!< The number of scenes to be recalled */
|
||||
uint8_t tid; /*!< Transaction ID */
|
||||
uint8_t trans_time; /*!< Time to complete state transition (optional) */
|
||||
uint8_t delay; /*!< Indicate message execution delay (C.1) */
|
||||
} esp_ble_mesh_server_recv_scene_recall_t;
|
||||
|
||||
/** Context of the received Scene Delete message */
|
||||
typedef struct {
|
||||
uint16_t scene_number; /*!< The number of scenes to be deleted */
|
||||
} esp_ble_mesh_server_recv_scene_delete_t;
|
||||
|
||||
/** Context of the received Scheduler Action Set message */
|
||||
typedef struct {
|
||||
uint64_t index : 4; /*!< Index of the Schedule Register entry to set */
|
||||
uint64_t year : 7; /*!< Scheduled year for the action */
|
||||
uint64_t month : 12; /*!< Scheduled month for the action */
|
||||
uint64_t day : 5; /*!< Scheduled day of the month for the action */
|
||||
uint64_t hour : 5; /*!< Scheduled hour for the action */
|
||||
uint64_t minute : 6; /*!< Scheduled minute for the action */
|
||||
uint64_t second : 6; /*!< Scheduled second for the action */
|
||||
uint64_t day_of_week : 7; /*!< Schedule days of the week for the action */
|
||||
uint64_t action : 4; /*!< Action to be performed at the scheduled time */
|
||||
uint64_t trans_time : 8; /*!< Transition time for this action */
|
||||
uint16_t scene_number; /*!< Scene number to be used for some actions */
|
||||
} esp_ble_mesh_server_recv_scheduler_act_set_t;
|
||||
|
||||
/**
|
||||
* @brief Time Scene Server Model received set message union
|
||||
*/
|
||||
typedef union {
|
||||
esp_ble_mesh_server_recv_time_set_t time; /*!< Time Set */
|
||||
esp_ble_mesh_server_recv_time_zone_set_t time_zone; /*!< Time Zone Set */
|
||||
esp_ble_mesh_server_recv_tai_utc_delta_set_t tai_utc_delta; /*!< TAI-UTC Delta Set */
|
||||
esp_ble_mesh_server_recv_time_role_set_t time_role; /*!< Time Role Set */
|
||||
esp_ble_mesh_server_recv_scene_store_t scene_store; /*!< Scene Store/Scene Store Unack */
|
||||
esp_ble_mesh_server_recv_scene_recall_t scene_recall; /*!< Scene Recall/Scene Recall Unack */
|
||||
esp_ble_mesh_server_recv_scene_delete_t scene_delete; /*!< Scene Delete/Scene Delete Unack */
|
||||
esp_ble_mesh_server_recv_scheduler_act_set_t scheduler_act; /*!< Scheduler Action Set/Scheduler Action Set Unack */
|
||||
} esp_ble_mesh_time_scene_server_recv_set_msg_t;
|
||||
|
||||
/** Context of the received Time Status message */
|
||||
typedef struct {
|
||||
uint8_t tai_seconds[5]; /*!< The current TAI time in seconds */
|
||||
uint8_t subsecond; /*!< The sub-second time in units of 1/256 second */
|
||||
uint8_t uncertainty; /*!< The estimated uncertainty in 10-millisecond steps */
|
||||
uint16_t time_authority : 1; /*!< 0 = No Time Authority, 1 = Time Authority */
|
||||
uint16_t tai_utc_delta : 15; /*!< Current difference between TAI and UTC in seconds */
|
||||
uint8_t time_zone_offset; /*!< The local time zone offset in 15-minute increments */
|
||||
} esp_ble_mesh_server_recv_time_status_t;
|
||||
|
||||
/**
|
||||
* @brief Time Scene Server Model received status message union
|
||||
*/
|
||||
typedef union {
|
||||
esp_ble_mesh_server_recv_time_status_t time_status; /*!< Time Status */
|
||||
} esp_ble_mesh_time_scene_server_recv_status_msg_t;
|
||||
|
||||
/**
|
||||
* @brief Time Scene Server Model callback value union
|
||||
*/
|
||||
typedef union {
|
||||
esp_ble_mesh_time_scene_server_state_change_t state_change; /*!< ESP_BLE_MESH_TIME_SCENE_SERVER_STATE_CHANGE_EVT */
|
||||
esp_ble_mesh_time_scene_server_recv_get_msg_t get; /*!< ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_GET_MSG_EVT */
|
||||
esp_ble_mesh_time_scene_server_recv_set_msg_t set; /*!< ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_SET_MSG_EVT */
|
||||
esp_ble_mesh_time_scene_server_recv_status_msg_t status; /*!< ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_STATUS_MSG_EVT */
|
||||
} esp_ble_mesh_time_scene_server_cb_value_t;
|
||||
|
||||
/** Time Scene Server Model callback parameters */
|
||||
typedef struct {
|
||||
esp_ble_mesh_model_t *model; /*!< Pointer to Time and Scenes Server Models */
|
||||
esp_ble_mesh_msg_ctx_t ctx; /*!< Context of the received messages */
|
||||
esp_ble_mesh_time_scene_server_cb_value_t value; /*!< Value of the received Time and Scenes Messages */
|
||||
} esp_ble_mesh_time_scene_server_cb_param_t;
|
||||
|
||||
/** This enum value is the event of Time Scene Server Model */
|
||||
typedef enum {
|
||||
/**
|
||||
* 1. When get_auto_rsp is set to ESP_BLE_MESH_SERVER_AUTO_RSP, no event will be
|
||||
* callback to the application layer when Time Scene Get messages are received.
|
||||
* 2. When set_auto_rsp is set to ESP_BLE_MESH_SERVER_AUTO_RSP, this event will
|
||||
* be callback to the application layer when Time Scene Set/Set Unack messages
|
||||
* are received.
|
||||
*/
|
||||
ESP_BLE_MESH_TIME_SCENE_SERVER_STATE_CHANGE_EVT,
|
||||
/**
|
||||
* When get_auto_rsp is set to ESP_BLE_MESH_SERVER_RSP_BY_APP, this event will be
|
||||
* callback to the application layer when Time Scene Get messages are received.
|
||||
*/
|
||||
ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_GET_MSG_EVT,
|
||||
/**
|
||||
* When set_auto_rsp is set to ESP_BLE_MESH_SERVER_RSP_BY_APP, this event will be
|
||||
* callback to the application layer when Time Scene Set/Set Unack messages are received.
|
||||
*/
|
||||
ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_SET_MSG_EVT,
|
||||
/**
|
||||
* When status_auto_rsp is set to ESP_BLE_MESH_SERVER_RSP_BY_APP, this event will
|
||||
* be callback to the application layer when TIme Status message is received.
|
||||
*/
|
||||
ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_STATUS_MSG_EVT,
|
||||
ESP_BLE_MESH_TIME_SCENE_SERVER_EVT_MAX,
|
||||
} esp_ble_mesh_time_scene_server_cb_event_t;
|
||||
|
||||
/**
|
||||
* @brief Bluetooth Mesh Time and Scenes Server Model function.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Time Scene Server Model callback function type
|
||||
* @param event: Event type
|
||||
* @param param: Pointer to callback parameter
|
||||
*/
|
||||
typedef void (* esp_ble_mesh_time_scene_server_cb_t)(esp_ble_mesh_time_scene_server_cb_event_t event,
|
||||
esp_ble_mesh_time_scene_server_cb_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief Register BLE Mesh Time and Scenes Server Model callback.
|
||||
*
|
||||
* @param[in] callback: Pointer to the callback function.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_register_time_scene_server_callback(esp_ble_mesh_time_scene_server_cb_t callback);
|
||||
|
||||
#endif /* _ESP_BLE_MESH_TIME_SCENE_MODEL_API_H_ */
|
||||
|
||||
|
@ -27,28 +27,22 @@
|
||||
|
||||
extern s32_t config_msg_timeout;
|
||||
|
||||
static inline void btc_ble_mesh_cfg_client_cb_to_app(esp_ble_mesh_cfg_client_cb_event_t event,
|
||||
/* Configuration Client Model related functions */
|
||||
|
||||
static inline void btc_ble_mesh_config_client_cb_to_app(esp_ble_mesh_cfg_client_cb_event_t event,
|
||||
esp_ble_mesh_cfg_client_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_cfg_client_cb_t btc_mesh_cb = (esp_ble_mesh_cfg_client_cb_t)btc_profile_cb_get(BTC_PID_CFG_CLIENT);
|
||||
if (btc_mesh_cb) {
|
||||
btc_mesh_cb(event, param);
|
||||
esp_ble_mesh_cfg_client_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_cfg_client_cb_t)btc_profile_cb_get(BTC_PID_CONFIG_CLIENT);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void btc_ble_mesh_cfg_server_cb_to_app(esp_ble_mesh_cfg_server_cb_event_t event,
|
||||
esp_ble_mesh_cfg_server_cb_param_t *param)
|
||||
void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_cfg_server_cb_t btc_mesh_cb = (esp_ble_mesh_cfg_server_cb_t)btc_profile_cb_get(BTC_PID_CFG_SERVER);
|
||||
if (btc_mesh_cb) {
|
||||
btc_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_cfg_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
btc_ble_mesh_cfg_client_args_t *dst = (btc_ble_mesh_cfg_client_args_t *)p_dest;
|
||||
btc_ble_mesh_cfg_client_args_t *src = (btc_ble_mesh_cfg_client_args_t *)p_src;
|
||||
btc_ble_mesh_config_client_args_t *dst = (btc_ble_mesh_config_client_args_t *)p_dest;
|
||||
btc_ble_mesh_config_client_args_t *src = (btc_ble_mesh_config_client_args_t *)p_src;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
@ -88,11 +82,43 @@ void btc_ble_mesh_cfg_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_cfg_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
static void btc_ble_mesh_config_client_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_config_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_config_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE:
|
||||
if (arg->cfg_client_get_state.params) {
|
||||
osi_free(arg->cfg_client_get_state.params);
|
||||
}
|
||||
if (arg->cfg_client_get_state.get_state) {
|
||||
osi_free(arg->cfg_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE:
|
||||
if (arg->cfg_client_set_state.params) {
|
||||
osi_free(arg->cfg_client_set_state.params);
|
||||
}
|
||||
if (arg->cfg_client_set_state.set_state) {
|
||||
osi_free(arg->cfg_client_set_state.set_state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_cfg_client_cb_param_t *p_dest_data = (esp_ble_mesh_cfg_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_cfg_client_cb_param_t *p_src_data = (esp_ble_mesh_cfg_client_cb_param_t *)p_src;
|
||||
u32_t opcode;
|
||||
u16_t length;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
@ -100,13 +126,22 @@ static void btc_ble_mesh_cfg_client_copy_req_data(btc_msg_t *msg, void *p_dest,
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (!p_dest_data->params) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_CFG_CLIENT_PUBLISH_EVT:
|
||||
if (p_src_data->params) {
|
||||
opcode = p_src_data->params->opcode;
|
||||
switch (opcode) {
|
||||
switch (p_src_data->params->opcode) {
|
||||
case OP_DEV_COMP_DATA_GET:
|
||||
case OP_DEV_COMP_DATA_STATUS:
|
||||
if (p_src_data->status_cb.comp_data_status.composition_data) {
|
||||
@ -186,24 +221,15 @@ static void btc_ble_mesh_cfg_client_copy_req_data(btc_msg_t *msg, void *p_dest,
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT:
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (p_dest_data->params) {
|
||||
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_cfg_client_free_req_data(btc_msg_t *msg)
|
||||
static void btc_ble_mesh_config_client_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_cfg_client_cb_param_t *arg = NULL;
|
||||
u32_t opcode;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
@ -217,8 +243,7 @@ static void btc_ble_mesh_cfg_client_free_req_data(btc_msg_t *msg)
|
||||
case ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_CFG_CLIENT_PUBLISH_EVT:
|
||||
if (arg->params) {
|
||||
opcode = arg->params->opcode;
|
||||
switch (opcode) {
|
||||
switch (arg->params->opcode) {
|
||||
case OP_DEV_COMP_DATA_GET:
|
||||
case OP_DEV_COMP_DATA_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.comp_data_status.composition_data);
|
||||
@ -257,63 +282,33 @@ static void btc_ble_mesh_cfg_client_free_req_data(btc_msg_t *msg)
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_cfg_client_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_cfg_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_cfg_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE:
|
||||
if (arg->cfg_client_get_state.params) {
|
||||
osi_free(arg->cfg_client_get_state.params);
|
||||
}
|
||||
if (arg->cfg_client_get_state.get_state) {
|
||||
osi_free(arg->cfg_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE:
|
||||
if (arg->cfg_client_set_state.params) {
|
||||
osi_free(arg->cfg_client_set_state.params);
|
||||
}
|
||||
if (arg->cfg_client_set_state.set_state) {
|
||||
osi_free(arg->cfg_client_set_state.set_state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void btc_mesh_cfg_client_callback(esp_ble_mesh_cfg_client_cb_param_t *cb_params, uint8_t act)
|
||||
static void btc_ble_mesh_config_client_callback(esp_ble_mesh_cfg_client_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_CONFIG_CLIENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_CFG_CLIENT;
|
||||
msg.pid = BTC_PID_CONFIG_CLIENT;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params,
|
||||
sizeof(esp_ble_mesh_cfg_client_cb_param_t), btc_ble_mesh_cfg_client_copy_req_data);
|
||||
sizeof(esp_ble_mesh_cfg_client_cb_param_t), btc_ble_mesh_config_client_copy_req_data);
|
||||
}
|
||||
|
||||
void bt_mesh_callback_config_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_cfg_client_cb_param_t cb_params = {0};
|
||||
esp_ble_mesh_client_common_param_t params = {0};
|
||||
size_t length;
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
|
||||
if (!model || !ctx) {
|
||||
@ -322,16 +317,16 @@ void bt_mesh_callback_config_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case 0x00:
|
||||
case BTC_BLE_MESH_EVT_CONFIG_CLIENT_GET_STATE:
|
||||
act = ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT;
|
||||
break;
|
||||
case 0x01:
|
||||
case BTC_BLE_MESH_EVT_CONFIG_CLIENT_SET_STATE:
|
||||
act = ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT;
|
||||
break;
|
||||
case 0x02:
|
||||
case BTC_BLE_MESH_EVT_CONFIG_CLIENT_PUBLISH:
|
||||
act = ESP_BLE_MESH_CFG_CLIENT_PUBLISH_EVT;
|
||||
break;
|
||||
case 0x03:
|
||||
case BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT:
|
||||
act = ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
@ -356,101 +351,32 @@ void bt_mesh_callback_config_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
memcpy(&cb_params.status_cb, val, length);
|
||||
}
|
||||
|
||||
btc_mesh_cfg_client_callback(&cb_params, act);
|
||||
btc_ble_mesh_config_client_callback(&cb_params, act);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void btc_mesh_cfg_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
|
||||
void btc_ble_mesh_config_client_publish_callback(u32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
if (!model || !ctx || !buf) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_callback_config_status_to_btc(opcode, 0x02, model, ctx, buf->data, buf->len);
|
||||
bt_mesh_config_client_cb_evt_to_btc(opcode,
|
||||
BTC_BLE_MESH_EVT_CONFIG_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_cfg_client_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_cfg_client_cb_param_t cfg_client_cb = {0};
|
||||
btc_ble_mesh_cfg_client_args_t *arg = NULL;
|
||||
bt_mesh_role_param_t role_param = {0};
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_cfg_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE: {
|
||||
cfg_client_cb.params = arg->cfg_client_get_state.params;
|
||||
role_param.model = (struct bt_mesh_model *)cfg_client_cb.params->model;
|
||||
role_param.role = cfg_client_cb.params->msg_role;
|
||||
if (bt_mesh_set_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
return;
|
||||
}
|
||||
btc_ble_mesh_config_client_get_state(arg->cfg_client_get_state.params,
|
||||
arg->cfg_client_get_state.get_state,
|
||||
&cfg_client_cb);
|
||||
if (cfg_client_cb.error_code) {
|
||||
btc_mesh_cfg_client_callback(&cfg_client_cb, ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE: {
|
||||
cfg_client_cb.params = arg->cfg_client_set_state.params;
|
||||
role_param.model = (struct bt_mesh_model *)cfg_client_cb.params->model;
|
||||
role_param.role = cfg_client_cb.params->msg_role;
|
||||
if (bt_mesh_set_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
return;
|
||||
}
|
||||
btc_ble_mesh_config_client_set_state(arg->cfg_client_set_state.params,
|
||||
arg->cfg_client_set_state.set_state,
|
||||
&cfg_client_cb);
|
||||
if (cfg_client_cb.error_code) {
|
||||
btc_mesh_cfg_client_callback(&cfg_client_cb, ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
btc_ble_mesh_cfg_client_arg_deep_free(msg);
|
||||
}
|
||||
|
||||
void btc_mesh_cfg_client_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_cfg_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_cfg_client_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_CFG_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_cfg_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_cfg_client_free_req_data(msg);
|
||||
}
|
||||
|
||||
int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_cfg_client_get_state_t *get_state,
|
||||
esp_ble_mesh_cfg_client_cb_param_t *cfg_client_cb)
|
||||
static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_cfg_client_get_state_t *get,
|
||||
esp_ble_mesh_cfg_client_cb_param_t *cb)
|
||||
{
|
||||
struct bt_mesh_msg_ctx ctx = {0};
|
||||
|
||||
if (!params || !cfg_client_cb) {
|
||||
if (!params || !cb) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
@ -465,66 +391,68 @@ int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *par
|
||||
|
||||
switch (params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_BEACON_GET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_beacon_get(&ctx));
|
||||
return (cb->error_code = bt_mesh_cfg_beacon_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_GET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_ttl_get(&ctx));
|
||||
return (cb->error_code = bt_mesh_cfg_ttl_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_FRIEND_GET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_friend_get(&ctx));
|
||||
return (cb->error_code = bt_mesh_cfg_friend_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_GET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_gatt_proxy_get(&ctx));
|
||||
return (cb->error_code = bt_mesh_cfg_gatt_proxy_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_RELAY_GET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_relay_get(&ctx));
|
||||
return (cb->error_code = bt_mesh_cfg_relay_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_mod_pub_get(&ctx, get_state->model_pub_get.element_addr, get_state->model_pub_get.model_id,
|
||||
get_state->model_pub_get.company_id));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_mod_pub_get(&ctx, get->model_pub_get.element_addr,
|
||||
get->model_pub_get.model_id, get->model_pub_get.company_id));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_GET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_hb_pub_get(&ctx));
|
||||
return (cb->error_code = bt_mesh_cfg_hb_pub_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_GET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_hb_sub_get(&ctx));
|
||||
return (cb->error_code = bt_mesh_cfg_hb_sub_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_comp_data_get(&ctx, get_state->comp_data_get.page));
|
||||
return (cb->error_code = bt_mesh_cfg_comp_data_get(&ctx, get->comp_data_get.page));
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_mod_sub_get(&ctx, get_state->sig_model_sub_get.element_addr, get_state->sig_model_sub_get.model_id));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_mod_sub_get(&ctx, get->sig_model_sub_get.element_addr,
|
||||
get->sig_model_sub_get.model_id));
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_mod_sub_get_vnd(&ctx, get_state->vnd_model_sub_get.element_addr,
|
||||
get_state->vnd_model_sub_get.model_id, get_state->vnd_model_sub_get.company_id));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_mod_sub_get_vnd(&ctx, get->vnd_model_sub_get.element_addr,
|
||||
get->vnd_model_sub_get.model_id, get->vnd_model_sub_get.company_id));
|
||||
case ESP_BLE_MESH_MODEL_OP_NET_KEY_GET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_net_key_get(&ctx));
|
||||
return (cb->error_code = bt_mesh_cfg_net_key_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_app_key_get(&ctx, get_state->app_key_get.net_idx));
|
||||
return (cb->error_code = bt_mesh_cfg_app_key_get(&ctx, get->app_key_get.net_idx));
|
||||
case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_GET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_node_identity_get(&ctx, get_state->node_identity_get.net_idx));
|
||||
return (cb->error_code = bt_mesh_cfg_node_identity_get(&ctx, get->node_identity_get.net_idx));
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_mod_app_get(&ctx, get_state->sig_model_app_get.element_addr, get_state->sig_model_app_get.model_id));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_mod_app_get(&ctx, get->sig_model_app_get.element_addr,
|
||||
get->sig_model_app_get.model_id));
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_mod_app_get_vnd(&ctx, get_state->vnd_model_app_get.element_addr,
|
||||
get_state->vnd_model_app_get.model_id, get_state->vnd_model_app_get.company_id));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_mod_app_get_vnd(&ctx, get->vnd_model_app_get.element_addr,
|
||||
get->vnd_model_app_get.model_id, get->vnd_model_app_get.company_id));
|
||||
case ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_GET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_kr_phase_get(&ctx, get_state->kr_phase_get.net_idx));
|
||||
return (cb->error_code = bt_mesh_cfg_kr_phase_get(&ctx, get->kr_phase_get.net_idx));
|
||||
case ESP_BLE_MESH_MODEL_OP_LPN_POLLTIMEOUT_GET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_lpn_timeout_get(&ctx, get_state->lpn_pollto_get.lpn_addr));
|
||||
return (cb->error_code = bt_mesh_cfg_lpn_timeout_get(&ctx, get->lpn_pollto_get.lpn_addr));
|
||||
case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_GET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_net_transmit_get(&ctx));
|
||||
return (cb->error_code = bt_mesh_cfg_net_transmit_get(&ctx));
|
||||
default:
|
||||
BT_WARN("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
return (cfg_client_cb->error_code = -EINVAL);
|
||||
LOG_ERROR("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
return (cb->error_code = -EINVAL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_cfg_client_set_state_t *set_state,
|
||||
esp_ble_mesh_cfg_client_cb_param_t *cfg_client_cb)
|
||||
static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_cfg_client_set_state_t *set,
|
||||
esp_ble_mesh_cfg_client_cb_param_t *cb)
|
||||
{
|
||||
struct bt_mesh_msg_ctx ctx = {0};
|
||||
|
||||
if (!params || !set_state || !cfg_client_cb) {
|
||||
if (!params || !set || !cb) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
@ -539,141 +467,250 @@ int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_t *par
|
||||
|
||||
switch (params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_BEACON_SET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_beacon_set(&ctx, set_state->beacon_set.beacon));
|
||||
return (cb->error_code = bt_mesh_cfg_beacon_set(&ctx, set->beacon_set.beacon));
|
||||
case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_SET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_ttl_set(&ctx, set_state->default_ttl_set.ttl));
|
||||
return (cb->error_code = bt_mesh_cfg_ttl_set(&ctx, set->default_ttl_set.ttl));
|
||||
case ESP_BLE_MESH_MODEL_OP_FRIEND_SET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_friend_set(&ctx, set_state->friend_set.friend_state));
|
||||
return (cb->error_code = bt_mesh_cfg_friend_set(&ctx, set->friend_set.friend_state));
|
||||
case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_SET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_gatt_proxy_set(&ctx, set_state->gatt_proxy_set.gatt_proxy));
|
||||
return (cb->error_code = bt_mesh_cfg_gatt_proxy_set(&ctx, set->gatt_proxy_set.gatt_proxy));
|
||||
case ESP_BLE_MESH_MODEL_OP_RELAY_SET:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_relay_set(&ctx, set_state->relay_set.relay, set_state->relay_set.relay_retransmit));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_relay_set(&ctx, set->relay_set.relay, set->relay_set.relay_retransmit));
|
||||
case ESP_BLE_MESH_MODEL_OP_NET_KEY_ADD:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_net_key_add(&ctx, set_state->net_key_add.net_idx, &set_state->net_key_add.net_key[0]));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_net_key_add(&ctx, set->net_key_add.net_idx,
|
||||
&set->net_key_add.net_key[0]));
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_ADD:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_app_key_add(&ctx, set_state->app_key_add.net_idx,
|
||||
set_state->app_key_add.app_idx, &set_state->app_key_add.app_key[0]));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_app_key_add(&ctx, set->app_key_add.net_idx,
|
||||
set->app_key_add.app_idx, &set->app_key_add.app_key[0]));
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_APP_BIND:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_mod_app_bind(&ctx, set_state->model_app_bind.element_addr, set_state->model_app_bind.model_app_idx,
|
||||
set_state->model_app_bind.model_id, set_state->model_app_bind.company_id));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_mod_app_bind(&ctx, set->model_app_bind.element_addr,
|
||||
set->model_app_bind.model_app_idx, set->model_app_bind.model_id,
|
||||
set->model_app_bind.company_id));
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_SET: {
|
||||
struct bt_mesh_cfg_mod_pub model_pub = {
|
||||
.addr = set_state->model_pub_set.publish_addr,
|
||||
.app_idx = set_state->model_pub_set.publish_app_idx,
|
||||
.cred_flag = set_state->model_pub_set.cred_flag,
|
||||
.ttl = set_state->model_pub_set.publish_ttl,
|
||||
.period = set_state->model_pub_set.publish_period,
|
||||
.transmit = set_state->model_pub_set.publish_retransmit,
|
||||
.addr = set->model_pub_set.publish_addr,
|
||||
.app_idx = set->model_pub_set.publish_app_idx,
|
||||
.cred_flag = set->model_pub_set.cred_flag,
|
||||
.ttl = set->model_pub_set.publish_ttl,
|
||||
.period = set->model_pub_set.publish_period,
|
||||
.transmit = set->model_pub_set.publish_retransmit,
|
||||
};
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_mod_pub_set(&ctx, set_state->model_pub_set.element_addr, set_state->model_pub_set.model_id,
|
||||
set_state->model_pub_set.company_id, &model_pub));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_mod_pub_set(&ctx, set->model_pub_set.element_addr,
|
||||
set->model_pub_set.model_id, set->model_pub_set.company_id, &model_pub));
|
||||
}
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_ADD:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_mod_sub_add(&ctx, set_state->model_sub_add.element_addr, set_state->model_sub_add.sub_addr,
|
||||
set_state->model_sub_add.model_id, set_state->model_sub_add.company_id));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_mod_sub_add(&ctx, set->model_sub_add.element_addr,
|
||||
set->model_sub_add.sub_addr, set->model_sub_add.model_id,
|
||||
set->model_sub_add.company_id));
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_mod_sub_del(&ctx, set_state->model_sub_delete.element_addr, set_state->model_sub_delete.sub_addr,
|
||||
set_state->model_sub_delete.model_id, set_state->model_sub_delete.company_id));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_mod_sub_del(&ctx, set->model_sub_delete.element_addr,
|
||||
set->model_sub_delete.sub_addr, set->model_sub_delete.model_id,
|
||||
set->model_sub_delete.company_id));
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_OVERWRITE:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_mod_sub_overwrite(&ctx, set_state->model_sub_overwrite.element_addr, set_state->model_sub_overwrite.sub_addr,
|
||||
set_state->model_sub_overwrite.model_id, set_state->model_sub_overwrite.company_id));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_mod_sub_overwrite(&ctx, set->model_sub_overwrite.element_addr,
|
||||
set->model_sub_overwrite.sub_addr, set->model_sub_overwrite.model_id,
|
||||
set->model_sub_overwrite.company_id));
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_ADD:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_mod_sub_va_add(&ctx, set_state->model_sub_va_add.element_addr, &set_state->model_sub_va_add.label_uuid[0],
|
||||
set_state->model_sub_va_add.model_id, set_state->model_sub_va_add.company_id));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_mod_sub_va_add(&ctx, set->model_sub_va_add.element_addr,
|
||||
&set->model_sub_va_add.label_uuid[0], set->model_sub_va_add.model_id,
|
||||
set->model_sub_va_add.company_id));
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_OVERWRITE:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_mod_sub_va_overwrite(&ctx, set_state->model_sub_va_overwrite.element_addr, &set_state->model_sub_va_overwrite.label_uuid[0],
|
||||
set_state->model_sub_va_overwrite.model_id, set_state->model_sub_va_overwrite.company_id));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_mod_sub_va_overwrite(&ctx, set->model_sub_va_overwrite.element_addr,
|
||||
&set->model_sub_va_overwrite.label_uuid[0], set->model_sub_va_overwrite.model_id,
|
||||
set->model_sub_va_overwrite.company_id));
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_DELETE:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_mod_sub_va_del(&ctx, set_state->model_sub_va_delete.element_addr, &set_state->model_sub_va_delete.label_uuid[0],
|
||||
set_state->model_sub_va_delete.model_id, set_state->model_sub_va_delete.company_id));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_mod_sub_va_del(&ctx, set->model_sub_va_delete.element_addr,
|
||||
&set->model_sub_va_delete.label_uuid[0], set->model_sub_va_delete.model_id,
|
||||
set->model_sub_va_delete.company_id));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_SET:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_hb_sub_set(&ctx, (struct bt_mesh_cfg_hb_sub *)&set_state->heartbeat_sub_set));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_hb_sub_set(&ctx,
|
||||
(struct bt_mesh_cfg_hb_sub *)&set->heartbeat_sub_set));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_SET:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_hb_pub_set(&ctx, (const struct bt_mesh_cfg_hb_pub *)&set_state->heartbeat_pub_set));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_hb_pub_set(&ctx,
|
||||
(const struct bt_mesh_cfg_hb_pub *)&set->heartbeat_pub_set));
|
||||
case ESP_BLE_MESH_MODEL_OP_NODE_RESET:
|
||||
return (cfg_client_cb->error_code = bt_mesh_cfg_node_reset(&ctx));
|
||||
return (cb->error_code = bt_mesh_cfg_node_reset(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_VIRTUAL_ADDR_SET: {
|
||||
struct bt_mesh_cfg_mod_pub model_pub = {
|
||||
.app_idx = set_state->model_pub_va_set.publish_app_idx,
|
||||
.cred_flag = set_state->model_pub_va_set.cred_flag,
|
||||
.ttl = set_state->model_pub_va_set.publish_ttl,
|
||||
.period = set_state->model_pub_va_set.publish_period,
|
||||
.transmit = set_state->model_pub_va_set.publish_retransmit,
|
||||
.app_idx = set->model_pub_va_set.publish_app_idx,
|
||||
.cred_flag = set->model_pub_va_set.cred_flag,
|
||||
.ttl = set->model_pub_va_set.publish_ttl,
|
||||
.period = set->model_pub_va_set.publish_period,
|
||||
.transmit = set->model_pub_va_set.publish_retransmit,
|
||||
};
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_mod_pub_va_set(&ctx, set_state->model_pub_va_set.element_addr, set_state->model_pub_va_set.model_id,
|
||||
set_state->model_pub_va_set.company_id, set_state->model_pub_va_set.label_uuid, &model_pub));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_mod_pub_va_set(&ctx, set->model_pub_va_set.element_addr,
|
||||
set->model_pub_va_set.model_id, set->model_pub_va_set.company_id,
|
||||
set->model_pub_va_set.label_uuid, &model_pub));
|
||||
}
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE_ALL:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_mod_sub_del_all(&ctx, set_state->model_sub_delete_all.element_addr,
|
||||
set_state->model_sub_delete_all.model_id, set_state->model_sub_delete_all.company_id));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_mod_sub_del_all(&ctx, set->model_sub_delete_all.element_addr,
|
||||
set->model_sub_delete_all.model_id, set->model_sub_delete_all.company_id));
|
||||
case ESP_BLE_MESH_MODEL_OP_NET_KEY_UPDATE:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_net_key_update(&ctx, set_state->net_key_update.net_idx, set_state->net_key_update.net_key));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_net_key_update(&ctx, set->net_key_update.net_idx,
|
||||
set->net_key_update.net_key));
|
||||
case ESP_BLE_MESH_MODEL_OP_NET_KEY_DELETE:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_net_key_delete(&ctx, set_state->net_key_delete.net_idx));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_net_key_delete(&ctx, set->net_key_delete.net_idx));
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_UPDATE:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_app_key_update(&ctx, set_state->app_key_update.net_idx, set_state->app_key_update.app_idx,
|
||||
set_state->app_key_update.app_key));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_app_key_update(&ctx, set->app_key_update.net_idx,
|
||||
set->app_key_update.app_idx, set->app_key_update.app_key));
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_DELETE:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_app_key_delete(&ctx, set_state->app_key_delete.net_idx, set_state->app_key_delete.app_idx));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_app_key_delete(&ctx, set->app_key_delete.net_idx,
|
||||
set->app_key_delete.app_idx));
|
||||
case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_SET:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_node_identity_set(&ctx, set_state->node_identity_set.net_idx, set_state->node_identity_set.identity));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_node_identity_set(&ctx, set->node_identity_set.net_idx,
|
||||
set->node_identity_set.identity));
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_APP_UNBIND:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_mod_app_unbind(&ctx, set_state->model_app_unbind.element_addr, set_state->model_app_unbind.model_app_idx,
|
||||
set_state->model_app_unbind.model_id, set_state->model_app_unbind.company_id));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_mod_app_unbind(&ctx, set->model_app_unbind.element_addr,
|
||||
set->model_app_unbind.model_app_idx, set->model_app_unbind.model_id,
|
||||
set->model_app_unbind.company_id));
|
||||
case ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_SET:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_kr_phase_set(&ctx, set_state->kr_phase_set.net_idx, set_state->kr_phase_set.transition));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_kr_phase_set(&ctx, set->kr_phase_set.net_idx,
|
||||
set->kr_phase_set.transition));
|
||||
case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_SET:
|
||||
return (cfg_client_cb->error_code =
|
||||
bt_mesh_cfg_net_transmit_set(&ctx, set_state->net_transmit_set.net_transmit));
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_net_transmit_set(&ctx, set->net_transmit_set.net_transmit));
|
||||
default:
|
||||
BT_WARN("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
return (cfg_client_cb->error_code = -EINVAL);
|
||||
LOG_ERROR("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
return (cb->error_code = -EINVAL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void btc_mesh_cfg_server_callback(esp_ble_mesh_cfg_server_cb_param_t *cb_params, uint8_t act)
|
||||
void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_config_client_args_t *arg = NULL;
|
||||
esp_ble_mesh_cfg_client_cb_param_t cb = {0};
|
||||
bt_mesh_role_param_t role_param = {0};
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_config_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE: {
|
||||
cb.params = arg->cfg_client_get_state.params;
|
||||
role_param.model = (struct bt_mesh_model *)cb.params->model;
|
||||
role_param.role = cb.params->msg_role;
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
btc_ble_mesh_config_client_get_state(arg->cfg_client_get_state.params,
|
||||
arg->cfg_client_get_state.get_state,
|
||||
&cb);
|
||||
if (cb.error_code) {
|
||||
btc_ble_mesh_config_client_callback(&cb, ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE: {
|
||||
cb.params = arg->cfg_client_set_state.params;
|
||||
role_param.model = (struct bt_mesh_model *)cb.params->model;
|
||||
role_param.role = cb.params->msg_role;
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
btc_ble_mesh_config_client_set_state(arg->cfg_client_set_state.params,
|
||||
arg->cfg_client_set_state.set_state,
|
||||
&cb);
|
||||
if (cb.error_code) {
|
||||
btc_ble_mesh_config_client_callback(&cb, ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
btc_ble_mesh_config_client_arg_deep_free(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_ble_mesh_config_client_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_cfg_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_cfg_client_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_CFG_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_config_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_config_client_free_req_data(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Configuration Server Model related functions */
|
||||
|
||||
static inline void btc_ble_mesh_config_server_cb_to_app(esp_ble_mesh_cfg_server_cb_event_t event,
|
||||
esp_ble_mesh_cfg_server_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_cfg_server_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_cfg_server_cb_t)btc_profile_cb_get(BTC_PID_CONFIG_SERVER);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_config_server_callback(esp_ble_mesh_cfg_server_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_CONFIG_SERVER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_CFG_SERVER;
|
||||
msg.pid = BTC_PID_CONFIG_SERVER;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_cfg_server_cb_param_t), NULL);
|
||||
}
|
||||
|
||||
void bt_mesh_callback_cfg_server_event_to_btc(u8_t evt_type, struct bt_mesh_model *model,
|
||||
void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_cfg_server_cb_param_t cb_params = {0};
|
||||
size_t length;
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
|
||||
if (!model || !ctx) {
|
||||
@ -682,8 +719,8 @@ void bt_mesh_callback_cfg_server_event_to_btc(u8_t evt_type, struct bt_mesh_mode
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case 0x00:
|
||||
act = ESP_BLE_MESH_CFG_SERVER_RECV_MSG_EVT;
|
||||
case BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE:
|
||||
act = ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown config server event type %d", __func__, evt_type);
|
||||
@ -699,14 +736,15 @@ void bt_mesh_callback_cfg_server_event_to_btc(u8_t evt_type, struct bt_mesh_mode
|
||||
cb_params.ctx.recv_dst = ctx->recv_dst;
|
||||
|
||||
if (val && len) {
|
||||
length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb);
|
||||
memcpy(&cb_params.status_cb, val, length);
|
||||
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
|
||||
memcpy(&cb_params.value, val, length);
|
||||
}
|
||||
|
||||
btc_mesh_cfg_server_callback(&cb_params, act);
|
||||
btc_ble_mesh_config_server_callback(&cb_params, act);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_cfg_server_cb_handler(btc_msg_t *msg)
|
||||
void btc_ble_mesh_config_server_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_cfg_server_cb_param_t *param = NULL;
|
||||
|
||||
@ -718,7 +756,7 @@ void btc_mesh_cfg_server_cb_handler(btc_msg_t *msg)
|
||||
param = (esp_ble_mesh_cfg_server_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_CFG_SERVER_EVT_MAX) {
|
||||
btc_ble_mesh_cfg_server_cb_to_app(msg->act, param);
|
||||
btc_ble_mesh_config_server_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
@ -18,16 +18,19 @@
|
||||
#include "btc/btc_manage.h"
|
||||
#include "osi/allocator.h"
|
||||
|
||||
#include "cfg_cli.h"
|
||||
#include "generic_client.h"
|
||||
#include "btc_ble_mesh_generic_model.h"
|
||||
#include "esp_ble_mesh_generic_model_api.h"
|
||||
|
||||
static inline void btc_ble_mesh_cb_to_app(esp_ble_mesh_generic_client_cb_event_t event,
|
||||
/* Generic Client Models related functions */
|
||||
|
||||
static inline void btc_ble_mesh_generic_client_cb_to_app(esp_ble_mesh_generic_client_cb_event_t event,
|
||||
esp_ble_mesh_generic_client_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_generic_client_cb_t btc_mesh_cb = (esp_ble_mesh_generic_client_cb_t)btc_profile_cb_get(BTC_PID_GENERIC_CLIENT);
|
||||
if (btc_mesh_cb) {
|
||||
btc_mesh_cb(event, param);
|
||||
esp_ble_mesh_generic_client_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_generic_client_cb_t)btc_profile_cb_get(BTC_PID_GENERIC_CLIENT);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +38,6 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi
|
||||
{
|
||||
btc_ble_mesh_generic_client_args_t *dst = (btc_ble_mesh_generic_client_args_t *)p_dest;
|
||||
btc_ble_mesh_generic_client_args_t *src = (btc_ble_mesh_generic_client_args_t *)p_src;
|
||||
u32_t opcode;
|
||||
u16_t length;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
@ -66,8 +68,7 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi
|
||||
memcpy(dst->generic_client_set_state.set_state, src->generic_client_set_state.set_state,
|
||||
sizeof(esp_ble_mesh_generic_client_set_state_t));
|
||||
|
||||
opcode = src->generic_client_set_state.params->opcode;
|
||||
switch (opcode) {
|
||||
switch (src->generic_client_set_state.params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
|
||||
if (src->generic_client_set_state.set_state->user_property_set.property_value) {
|
||||
length = src->generic_client_set_state.set_state->user_property_set.property_value->len;
|
||||
@ -108,11 +109,55 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
static void btc_ble_mesh_generic_client_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_generic_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_generic_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE:
|
||||
if (arg->generic_client_get_state.params) {
|
||||
osi_free(arg->generic_client_get_state.params);
|
||||
}
|
||||
if (arg->generic_client_get_state.get_state) {
|
||||
osi_free(arg->generic_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE:
|
||||
if (arg->generic_client_set_state.set_state) {
|
||||
if (arg->generic_client_set_state.params) {
|
||||
switch (arg->generic_client_set_state.params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
|
||||
bt_mesh_free_buf(arg->generic_client_set_state.set_state->user_property_set.property_value);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
|
||||
bt_mesh_free_buf(arg->generic_client_set_state.set_state->admin_property_set.property_value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
osi_free(arg->generic_client_set_state.set_state);
|
||||
}
|
||||
if (arg->generic_client_set_state.params) {
|
||||
osi_free(arg->generic_client_set_state.params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_generic_client_cb_param_t *p_dest_data = (esp_ble_mesh_generic_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_generic_client_cb_param_t *p_src_data = (esp_ble_mesh_generic_client_cb_param_t *)p_src;
|
||||
u32_t opcode;
|
||||
u16_t length;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
@ -120,13 +165,22 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (!p_dest_data->params) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_PUBLISH_EVT:
|
||||
if (p_src_data->params) {
|
||||
opcode = p_src_data->params->opcode;
|
||||
switch (opcode) {
|
||||
switch (p_src_data->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS:
|
||||
if (p_src_data->status_cb.user_properties_status.property_ids) {
|
||||
@ -233,24 +287,15 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_TIMEOUT_EVT:
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (p_dest_data->params) {
|
||||
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
|
||||
static void btc_ble_mesh_generic_client_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_generic_client_cb_param_t *arg = NULL;
|
||||
u32_t opcode;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
@ -264,8 +309,7 @@ static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_PUBLISH_EVT:
|
||||
if (arg->params) {
|
||||
opcode = arg->params->opcode;
|
||||
switch (opcode) {
|
||||
switch (arg->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.user_properties_status.property_ids);
|
||||
@ -311,70 +355,26 @@ static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_generic_client_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_generic_client_args_t *arg = NULL;
|
||||
u32_t opcode = 0;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_generic_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE:
|
||||
if (arg->generic_client_get_state.params) {
|
||||
osi_free(arg->generic_client_get_state.params);
|
||||
}
|
||||
if (arg->generic_client_get_state.get_state) {
|
||||
osi_free(arg->generic_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE:
|
||||
if (arg->generic_client_set_state.params) {
|
||||
opcode = arg->generic_client_set_state.params->opcode;
|
||||
osi_free(arg->generic_client_set_state.params);
|
||||
}
|
||||
if (arg->generic_client_set_state.set_state) {
|
||||
if (opcode) {
|
||||
switch (opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
|
||||
bt_mesh_free_buf(arg->generic_client_set_state.set_state->user_property_set.property_value);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
|
||||
bt_mesh_free_buf(arg->generic_client_set_state.set_state->admin_property_set.property_value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
osi_free(arg->generic_client_set_state.set_state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void btc_mesh_generic_client_callback(esp_ble_mesh_generic_client_cb_param_t *cb_params, uint8_t act)
|
||||
static void btc_ble_mesh_generic_client_callback(esp_ble_mesh_generic_client_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_GENERIC_CLIENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_GENERIC_CLIENT;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params,
|
||||
sizeof(esp_ble_mesh_generic_client_cb_param_t), btc_ble_mesh_copy_req_data);
|
||||
sizeof(esp_ble_mesh_generic_client_cb_param_t), btc_ble_mesh_generic_client_copy_req_data);
|
||||
}
|
||||
|
||||
void bt_mesh_callback_generic_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
void bt_mesh_generic_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len)
|
||||
@ -390,16 +390,16 @@ void bt_mesh_callback_generic_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case 0x00:
|
||||
case BTC_BLE_MESH_EVT_GENERIC_CLIENT_GET_STATE:
|
||||
act = ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT;
|
||||
break;
|
||||
case 0x01:
|
||||
case BTC_BLE_MESH_EVT_GENERIC_CLIENT_SET_STATE:
|
||||
act = ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT;
|
||||
break;
|
||||
case 0x02:
|
||||
case BTC_BLE_MESH_EVT_GENERIC_CLIENT_PUBLISH:
|
||||
act = ESP_BLE_MESH_GENERIC_CLIENT_PUBLISH_EVT;
|
||||
break;
|
||||
case 0x03:
|
||||
case BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT:
|
||||
act = ESP_BLE_MESH_GENERIC_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
@ -424,26 +424,31 @@ void bt_mesh_callback_generic_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
memcpy(&cb_params.status_cb, val, length);
|
||||
}
|
||||
|
||||
btc_mesh_generic_client_callback(&cb_params, act);
|
||||
btc_ble_mesh_generic_client_callback(&cb_params, act);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_generic_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
|
||||
void btc_ble_mesh_generic_client_publish_callback(u32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
if (!model || !ctx || !buf) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_callback_generic_status_to_btc(opcode, 0x02, model, ctx, buf->data, buf->len);
|
||||
bt_mesh_generic_client_cb_evt_to_btc(opcode,
|
||||
BTC_BLE_MESH_EVT_GENERIC_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_generic_client_call_handler(btc_msg_t *msg)
|
||||
void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_generic_client_cb_param_t generic_client_cb = {0};
|
||||
esp_ble_mesh_client_common_param_t *params = NULL;
|
||||
btc_ble_mesh_generic_client_args_t *arg = NULL;
|
||||
struct bt_mesh_common_param common = {0};
|
||||
esp_ble_mesh_generic_client_cb_param_t cb = {0};
|
||||
bt_mesh_client_common_param_t common = {0};
|
||||
bt_mesh_role_param_t role_param = {0};
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
@ -458,9 +463,9 @@ void btc_mesh_generic_client_call_handler(btc_msg_t *msg)
|
||||
params = arg->generic_client_get_state.params;
|
||||
role_param.model = (struct bt_mesh_model *)params->model;
|
||||
role_param.role = params->msg_role;
|
||||
if (bt_mesh_set_model_role(&role_param)) {
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
common.model = (struct bt_mesh_model *)params->model;
|
||||
@ -471,15 +476,12 @@ void btc_mesh_generic_client_call_handler(btc_msg_t *msg)
|
||||
common.ctx.send_ttl = params->ctx.send_ttl;
|
||||
common.msg_timeout = params->msg_timeout;
|
||||
|
||||
generic_client_cb.params = arg->generic_client_get_state.params;
|
||||
generic_client_cb.error_code =
|
||||
bt_mesh_generic_client_get_state(&common,
|
||||
(void *)arg->generic_client_get_state.get_state,
|
||||
(void *)&generic_client_cb.status_cb);
|
||||
if (generic_client_cb.error_code) {
|
||||
cb.params = arg->generic_client_get_state.params;
|
||||
cb.error_code = bt_mesh_generic_client_get_state(&common,
|
||||
(void *)arg->generic_client_get_state.get_state, (void *)&cb.status_cb);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_mesh_generic_client_callback(&generic_client_cb,
|
||||
ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT);
|
||||
btc_ble_mesh_generic_client_callback(&cb, ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -487,9 +489,9 @@ void btc_mesh_generic_client_call_handler(btc_msg_t *msg)
|
||||
params = arg->generic_client_set_state.params;
|
||||
role_param.model = (struct bt_mesh_model *)params->model;
|
||||
role_param.role = params->msg_role;
|
||||
if (bt_mesh_set_model_role(&role_param)) {
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
common.model = (struct bt_mesh_model *)params->model;
|
||||
@ -500,15 +502,12 @@ void btc_mesh_generic_client_call_handler(btc_msg_t *msg)
|
||||
common.ctx.send_ttl = params->ctx.send_ttl;
|
||||
common.msg_timeout = params->msg_timeout;
|
||||
|
||||
generic_client_cb.params = arg->generic_client_set_state.params;
|
||||
generic_client_cb.error_code =
|
||||
bt_mesh_generic_client_set_state(&common,
|
||||
(void *)arg->generic_client_set_state.set_state,
|
||||
(void *)&generic_client_cb.status_cb);
|
||||
if (generic_client_cb.error_code) {
|
||||
cb.params = arg->generic_client_set_state.params;
|
||||
cb.error_code = bt_mesh_generic_client_set_state(&common,
|
||||
(void *)arg->generic_client_set_state.set_state, (void *)&cb.status_cb);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_mesh_generic_client_callback(&generic_client_cb,
|
||||
ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT);
|
||||
btc_ble_mesh_generic_client_callback(&cb, ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -517,9 +516,10 @@ void btc_mesh_generic_client_call_handler(btc_msg_t *msg)
|
||||
}
|
||||
|
||||
btc_ble_mesh_generic_client_arg_deep_free(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_generic_client_cb_handler(btc_msg_t *msg)
|
||||
void btc_ble_mesh_generic_client_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_generic_client_cb_param_t *param = NULL;
|
||||
|
||||
@ -531,10 +531,240 @@ void btc_mesh_generic_client_cb_handler(btc_msg_t *msg)
|
||||
param = (esp_ble_mesh_generic_client_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_GENERIC_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_cb_to_app(msg->act, param);
|
||||
btc_ble_mesh_generic_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_free_req_data(msg);
|
||||
btc_ble_mesh_generic_client_free_req_data(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Generic Server Models related functions */
|
||||
|
||||
static inline void btc_ble_mesh_generic_server_cb_to_app(
|
||||
esp_ble_mesh_generic_server_cb_event_t event,
|
||||
esp_ble_mesh_generic_server_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_generic_server_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_generic_server_cb_t)btc_profile_cb_get(BTC_PID_GENERIC_SERVER);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_generic_server_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_generic_server_cb_param_t *p_dest_data = (esp_ble_mesh_generic_server_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_generic_server_cb_param_t *p_src_data = (esp_ble_mesh_generic_server_cb_param_t *)p_src;
|
||||
u16_t length;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_GENERIC_SERVER_STATE_CHANGE_EVT:
|
||||
switch (p_src_data->ctx.recv_op) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK:
|
||||
if (p_src_data->value.state_change.user_property_set.value) {
|
||||
length = p_src_data->value.state_change.user_property_set.value->len;
|
||||
p_dest_data->value.state_change.user_property_set.value = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.state_change.user_property_set.value == NULL) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.user_property_set.value,
|
||||
p_src_data->value.state_change.user_property_set.value->data,
|
||||
p_src_data->value.state_change.user_property_set.value->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK:
|
||||
if (p_src_data->value.state_change.admin_property_set.value) {
|
||||
length = p_src_data->value.state_change.admin_property_set.value->len;
|
||||
p_dest_data->value.state_change.admin_property_set.value = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.state_change.admin_property_set.value == NULL) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.admin_property_set.value,
|
||||
p_src_data->value.state_change.admin_property_set.value->data,
|
||||
p_src_data->value.state_change.admin_property_set.value->len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_GENERIC_SERVER_RECV_SET_MSG_EVT:
|
||||
switch (p_src_data->ctx.recv_op) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK:
|
||||
if (p_src_data->value.set.user_property.property_value) {
|
||||
length = p_src_data->value.set.user_property.property_value->len;
|
||||
p_dest_data->value.set.user_property.property_value = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.set.user_property.property_value == NULL) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.set.user_property.property_value,
|
||||
p_src_data->value.set.user_property.property_value->data,
|
||||
p_src_data->value.set.user_property.property_value->len);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK:
|
||||
if (p_src_data->value.set.admin_property.property_value) {
|
||||
length = p_src_data->value.set.admin_property.property_value->len;
|
||||
p_dest_data->value.set.admin_property.property_value = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.set.admin_property.property_value == NULL) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.set.admin_property.property_value,
|
||||
p_src_data->value.set.admin_property.property_value->data,
|
||||
p_src_data->value.set.admin_property.property_value->len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_generic_server_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_generic_server_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (esp_ble_mesh_generic_server_cb_param_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_GENERIC_SERVER_STATE_CHANGE_EVT:
|
||||
switch (arg->ctx.recv_op) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK:
|
||||
bt_mesh_free_buf(arg->value.state_change.user_property_set.value);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK:
|
||||
bt_mesh_free_buf(arg->value.state_change.admin_property_set.value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_GENERIC_SERVER_RECV_SET_MSG_EVT:
|
||||
switch (arg->ctx.recv_op) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK:
|
||||
bt_mesh_free_buf(arg->value.set.user_property.property_value);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK:
|
||||
bt_mesh_free_buf(arg->value.set.admin_property.property_value);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_generic_server_callback(esp_ble_mesh_generic_server_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_GENERIC_SERVER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_GENERIC_SERVER;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params,
|
||||
sizeof(esp_ble_mesh_generic_server_cb_param_t), btc_ble_mesh_generic_server_copy_req_data);
|
||||
}
|
||||
|
||||
void bt_mesh_generic_server_cb_evt_to_btc(u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_generic_server_cb_param_t cb_params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
|
||||
if (model == NULL || ctx == NULL) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case BTC_BLE_MESH_EVT_GENERIC_SERVER_STATE_CHANGE:
|
||||
act = ESP_BLE_MESH_GENERIC_SERVER_STATE_CHANGE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_GENERIC_SERVER_RECV_GET_MSG:
|
||||
act = ESP_BLE_MESH_GENERIC_SERVER_RECV_GET_MSG_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_GENERIC_SERVER_RECV_SET_MSG:
|
||||
act = ESP_BLE_MESH_GENERIC_SERVER_RECV_SET_MSG_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown Generic Server event type", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
cb_params.model = (esp_ble_mesh_model_t *)model;
|
||||
cb_params.ctx.net_idx = ctx->net_idx;
|
||||
cb_params.ctx.app_idx = ctx->app_idx;
|
||||
cb_params.ctx.addr = ctx->addr;
|
||||
cb_params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
cb_params.ctx.recv_op = ctx->recv_op;
|
||||
cb_params.ctx.recv_dst = ctx->recv_dst;
|
||||
|
||||
if (val && len) {
|
||||
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
|
||||
memcpy(&cb_params.value, val, length);
|
||||
}
|
||||
|
||||
btc_ble_mesh_generic_server_callback(&cb_params, act);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_ble_mesh_generic_server_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_generic_server_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_generic_server_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_GENERIC_SERVER_EVT_MAX) {
|
||||
btc_ble_mesh_generic_server_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_generic_server_free_req_data(msg);
|
||||
return;
|
||||
}
|
||||
|
@ -28,21 +28,15 @@
|
||||
|
||||
extern s32_t health_msg_timeout;
|
||||
|
||||
/* Health Client Model related functions */
|
||||
|
||||
static inline void btc_ble_mesh_health_client_cb_to_app(esp_ble_mesh_health_client_cb_event_t event,
|
||||
esp_ble_mesh_health_client_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_health_client_cb_t btc_mesh_cb = (esp_ble_mesh_health_client_cb_t)btc_profile_cb_get(BTC_PID_HEALTH_CLIENT);
|
||||
if (btc_mesh_cb) {
|
||||
btc_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void btc_ble_mesh_health_server_cb_to_app(esp_ble_mesh_health_server_cb_event_t event,
|
||||
esp_ble_mesh_health_server_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_health_server_cb_t btc_mesh_cb = (esp_ble_mesh_health_server_cb_t)btc_profile_cb_get(BTC_PID_HEALTH_SERVER);
|
||||
if (btc_mesh_cb) {
|
||||
btc_mesh_cb(event, param);
|
||||
esp_ble_mesh_health_client_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_health_client_cb_t)btc_profile_cb_get(BTC_PID_HEALTH_CLIENT);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,45 +114,12 @@ static void btc_ble_mesh_health_client_arg_deep_free(btc_msg_t *msg)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_server_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
if (!msg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_health_server_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
if (!msg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_health_client_cb_param_t *p_dest_data = (esp_ble_mesh_health_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_health_client_cb_param_t *p_src_data = (esp_ble_mesh_health_client_cb_param_t *)p_src;
|
||||
u32_t opcode;
|
||||
u16_t length;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
@ -166,13 +127,22 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (!p_dest_data->params) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_HEALTH_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_HEALTH_CLIENT_PUBLISH_EVT:
|
||||
if (p_src_data->params) {
|
||||
opcode = p_src_data->params->opcode;
|
||||
switch (opcode) {
|
||||
switch (p_src_data->params->opcode) {
|
||||
case OP_HEALTH_CURRENT_STATUS:
|
||||
if (p_src_data->status_cb.current_status.fault_array) {
|
||||
length = p_src_data->status_cb.current_status.fault_array->len;
|
||||
@ -207,14 +177,6 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_HEALTH_CLIENT_TIMEOUT_EVT:
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (p_dest_data->params) {
|
||||
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -224,7 +186,6 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
static void btc_ble_mesh_health_client_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_health_client_cb_param_t *arg = NULL;
|
||||
u32_t opcode;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
@ -238,8 +199,7 @@ static void btc_ble_mesh_health_client_free_req_data(btc_msg_t *msg)
|
||||
case ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_HEALTH_CLIENT_PUBLISH_EVT:
|
||||
if (arg->params) {
|
||||
opcode = arg->params->opcode;
|
||||
switch (opcode) {
|
||||
switch (arg->params->opcode) {
|
||||
case OP_HEALTH_CURRENT_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.current_status.fault_array);
|
||||
break;
|
||||
@ -263,42 +223,17 @@ static void btc_ble_mesh_health_client_free_req_data(btc_msg_t *msg)
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_health_server_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
if (!msg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMPLETE_EVT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_health_server_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
if (!msg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMPLETE_EVT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_mesh_health_client_callback(esp_ble_mesh_health_client_cb_param_t *cb_params, uint8_t act)
|
||||
static void btc_ble_mesh_health_client_callback(esp_ble_mesh_health_client_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_HEALTH_CLIENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_HEALTH_CLIENT;
|
||||
msg.act = act;
|
||||
@ -307,107 +242,7 @@ static void btc_mesh_health_client_callback(esp_ble_mesh_health_client_cb_param_
|
||||
sizeof(esp_ble_mesh_health_client_cb_param_t), btc_ble_mesh_health_client_copy_req_data);
|
||||
}
|
||||
|
||||
static void btc_mesh_health_server_callback(esp_ble_mesh_health_server_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_HEALTH_SERVER;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params,
|
||||
sizeof(esp_ble_mesh_health_server_cb_param_t), btc_ble_mesh_health_server_copy_req_data);
|
||||
}
|
||||
|
||||
int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_health_client_get_state_t *get_state,
|
||||
esp_ble_mesh_health_client_cb_param_t *client_cb)
|
||||
{
|
||||
struct bt_mesh_msg_ctx ctx = {0};
|
||||
|
||||
if (!params || !client_cb) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ctx.net_idx = params->ctx.net_idx;
|
||||
ctx.app_idx = params->ctx.app_idx;
|
||||
ctx.addr = params->ctx.addr;
|
||||
ctx.send_rel = params->ctx.send_rel;
|
||||
ctx.send_ttl = params->ctx.send_ttl;
|
||||
|
||||
health_msg_timeout = params->msg_timeout;
|
||||
|
||||
switch (params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_ATTENTION_GET:
|
||||
return (client_cb->error_code = bt_mesh_health_attention_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_GET:
|
||||
return (client_cb->error_code = bt_mesh_health_period_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET:
|
||||
return (client_cb->error_code = bt_mesh_health_fault_get(&ctx, get_state->fault_get.company_id));
|
||||
default:
|
||||
BT_WARN("%s, invalid opcode 0x%x", __func__, params->opcode);
|
||||
return (client_cb->error_code = -EINVAL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int btc_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_health_client_set_state_t *set_state,
|
||||
esp_ble_mesh_health_client_cb_param_t *client_cb)
|
||||
{
|
||||
struct bt_mesh_msg_ctx ctx = {0};
|
||||
|
||||
if (!params || !set_state || !client_cb) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ctx.net_idx = params->ctx.net_idx;
|
||||
ctx.app_idx = params->ctx.app_idx;
|
||||
ctx.addr = params->ctx.addr;
|
||||
ctx.send_rel = params->ctx.send_rel;
|
||||
ctx.send_ttl = params->ctx.send_ttl;
|
||||
|
||||
health_msg_timeout = params->msg_timeout;
|
||||
|
||||
switch (params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET:
|
||||
return (client_cb->error_code =
|
||||
bt_mesh_health_attention_set(&ctx, set_state->attention_set.attention, true));
|
||||
case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET_UNACK:
|
||||
return (client_cb->error_code =
|
||||
bt_mesh_health_attention_set(&ctx, set_state->attention_set.attention, false));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET:
|
||||
return (client_cb->error_code =
|
||||
bt_mesh_health_period_set(&ctx, set_state->period_set.fast_period_divisor, true));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET_UNACK:
|
||||
return (client_cb->error_code =
|
||||
bt_mesh_health_period_set(&ctx, set_state->period_set.fast_period_divisor, false));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST:
|
||||
return (client_cb->error_code =
|
||||
bt_mesh_health_fault_test(&ctx, set_state->fault_test.company_id, set_state->fault_test.test_id, true));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST_UNACK:
|
||||
return (client_cb->error_code =
|
||||
bt_mesh_health_fault_test(&ctx, set_state->fault_test.company_id, set_state->fault_test.test_id, false));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR:
|
||||
return (client_cb->error_code =
|
||||
bt_mesh_health_fault_clear(&ctx, set_state->fault_clear.company_id, true));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR_UNACK:
|
||||
return (client_cb->error_code =
|
||||
bt_mesh_health_fault_clear(&ctx, set_state->fault_clear.company_id, false));
|
||||
default:
|
||||
BT_WARN("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
return (client_cb->error_code = -EINVAL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bt_mesh_callback_health_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, u16_t len)
|
||||
@ -423,16 +258,16 @@ void bt_mesh_callback_health_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case 0x00:
|
||||
case BTC_BLE_MESH_EVT_HEALTH_CLIENT_GET_STATE:
|
||||
act = ESP_BLE_MESH_HEALTH_CLIENT_GET_STATE_EVT;
|
||||
break;
|
||||
case 0x01:
|
||||
case BTC_BLE_MESH_EVT_HEALTH_CLIENT_SET_STATE:
|
||||
act = ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT;
|
||||
break;
|
||||
case 0x02:
|
||||
case BTC_BLE_MESH_EVT_HEALTH_CLIENT_PUBLISH:
|
||||
act = ESP_BLE_MESH_HEALTH_CLIENT_PUBLISH_EVT;
|
||||
break;
|
||||
case 0x03:
|
||||
case BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT:
|
||||
act = ESP_BLE_MESH_HEALTH_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
@ -457,24 +292,115 @@ void bt_mesh_callback_health_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
memcpy(&cb_params.status_cb, val, length);
|
||||
}
|
||||
|
||||
btc_mesh_health_client_callback(&cb_params, act);
|
||||
btc_ble_mesh_health_client_callback(&cb_params, act);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_health_publish_callback(u32_t opcode, struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
|
||||
void btc_ble_mesh_health_publish_callback(u32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
if (!model || !ctx || !buf) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_callback_health_status_to_btc(opcode, 0x02, model, ctx, buf->data, buf->len);
|
||||
bt_mesh_health_client_cb_evt_to_btc(opcode,
|
||||
BTC_BLE_MESH_EVT_HEALTH_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_health_client_call_handler(btc_msg_t *msg)
|
||||
static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_health_client_get_state_t *get,
|
||||
esp_ble_mesh_health_client_cb_param_t *cb)
|
||||
{
|
||||
struct bt_mesh_msg_ctx ctx = {0};
|
||||
|
||||
if (!params || !cb) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ctx.net_idx = params->ctx.net_idx;
|
||||
ctx.app_idx = params->ctx.app_idx;
|
||||
ctx.addr = params->ctx.addr;
|
||||
ctx.send_rel = params->ctx.send_rel;
|
||||
ctx.send_ttl = params->ctx.send_ttl;
|
||||
|
||||
health_msg_timeout = params->msg_timeout;
|
||||
|
||||
switch (params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_ATTENTION_GET:
|
||||
return (cb->error_code = bt_mesh_health_attention_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_GET:
|
||||
return (cb->error_code = bt_mesh_health_period_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET:
|
||||
return (cb->error_code = bt_mesh_health_fault_get(&ctx, get->fault_get.company_id));
|
||||
default:
|
||||
LOG_ERROR("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
return (cb->error_code = -EINVAL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int btc_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_health_client_set_state_t *set,
|
||||
esp_ble_mesh_health_client_cb_param_t *cb)
|
||||
{
|
||||
struct bt_mesh_msg_ctx ctx = {0};
|
||||
|
||||
if (!params || !set || !cb) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ctx.net_idx = params->ctx.net_idx;
|
||||
ctx.app_idx = params->ctx.app_idx;
|
||||
ctx.addr = params->ctx.addr;
|
||||
ctx.send_rel = params->ctx.send_rel;
|
||||
ctx.send_ttl = params->ctx.send_ttl;
|
||||
|
||||
health_msg_timeout = params->msg_timeout;
|
||||
|
||||
switch (params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET:
|
||||
return (cb->error_code =
|
||||
bt_mesh_health_attention_set(&ctx, set->attention_set.attention, true));
|
||||
case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET_UNACK:
|
||||
return (cb->error_code =
|
||||
bt_mesh_health_attention_set(&ctx, set->attention_set.attention, false));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET:
|
||||
return (cb->error_code =
|
||||
bt_mesh_health_period_set(&ctx, set->period_set.fast_period_divisor, true));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET_UNACK:
|
||||
return (cb->error_code =
|
||||
bt_mesh_health_period_set(&ctx, set->period_set.fast_period_divisor, false));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST:
|
||||
return (cb->error_code =
|
||||
bt_mesh_health_fault_test(&ctx, set->fault_test.company_id, set->fault_test.test_id, true));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST_UNACK:
|
||||
return (cb->error_code =
|
||||
bt_mesh_health_fault_test(&ctx, set->fault_test.company_id, set->fault_test.test_id, false));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR:
|
||||
return (cb->error_code =
|
||||
bt_mesh_health_fault_clear(&ctx, set->fault_clear.company_id, true));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR_UNACK:
|
||||
return (cb->error_code =
|
||||
bt_mesh_health_fault_clear(&ctx, set->fault_clear.company_id, false));
|
||||
default:
|
||||
LOG_ERROR("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
return (cb->error_code = -EINVAL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_health_client_args_t *arg = NULL;
|
||||
esp_ble_mesh_health_client_cb_param_t health_client_cb = {0};
|
||||
esp_ble_mesh_health_client_cb_param_t cb = {0};
|
||||
bt_mesh_role_param_t role_param = {0};
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
@ -486,36 +412,34 @@ void btc_mesh_health_client_call_handler(btc_msg_t *msg)
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_GET_STATE: {
|
||||
health_client_cb.params = arg->health_client_get_state.params;
|
||||
role_param.model = (struct bt_mesh_model *)health_client_cb.params->model;
|
||||
role_param.role = health_client_cb.params->msg_role;
|
||||
if (bt_mesh_set_model_role(&role_param)) {
|
||||
cb.params = arg->health_client_get_state.params;
|
||||
role_param.model = (struct bt_mesh_model *)cb.params->model;
|
||||
role_param.role = cb.params->msg_role;
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
btc_ble_mesh_health_client_get_state(arg->health_client_get_state.params,
|
||||
arg->health_client_get_state.get_state,
|
||||
&health_client_cb);
|
||||
if (health_client_cb.error_code) {
|
||||
arg->health_client_get_state.get_state, &cb);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_mesh_health_client_callback(&health_client_cb, ESP_BLE_MESH_HEALTH_CLIENT_GET_STATE_EVT);
|
||||
btc_ble_mesh_health_client_callback(&cb, ESP_BLE_MESH_HEALTH_CLIENT_GET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_SET_STATE: {
|
||||
health_client_cb.params = arg->health_client_set_state.params;
|
||||
role_param.model = (struct bt_mesh_model *)health_client_cb.params->model;
|
||||
role_param.role = health_client_cb.params->msg_role;
|
||||
if (bt_mesh_set_model_role(&role_param)) {
|
||||
cb.params = arg->health_client_set_state.params;
|
||||
role_param.model = (struct bt_mesh_model *)cb.params->model;
|
||||
role_param.role = cb.params->msg_role;
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
btc_ble_mesh_health_client_set_state(arg->health_client_set_state.params,
|
||||
arg->health_client_set_state.set_state,
|
||||
&health_client_cb);
|
||||
if (health_client_cb.error_code) {
|
||||
arg->health_client_set_state.set_state, &cb);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_mesh_health_client_callback(&health_client_cb, ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT);
|
||||
btc_ble_mesh_health_client_callback(&cb, ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -527,7 +451,7 @@ void btc_mesh_health_client_call_handler(btc_msg_t *msg)
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_health_client_cb_handler(btc_msg_t *msg)
|
||||
void btc_ble_mesh_health_client_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_health_client_cb_param_t *param = NULL;
|
||||
|
||||
@ -545,11 +469,103 @@ void btc_mesh_health_client_cb_handler(btc_msg_t *msg)
|
||||
}
|
||||
|
||||
btc_ble_mesh_health_client_free_req_data(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_health_server_call_handler(btc_msg_t *msg)
|
||||
/* Health Server Model related functions */
|
||||
|
||||
static inline void btc_ble_mesh_health_server_cb_to_app(esp_ble_mesh_health_server_cb_event_t event,
|
||||
esp_ble_mesh_health_server_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_health_server_cb_param_t health_server_cb = {0};
|
||||
esp_ble_mesh_health_server_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_health_server_cb_t)btc_profile_cb_get(BTC_PID_HEALTH_SERVER);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_server_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
if (!msg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_health_server_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
if (!msg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_health_server_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
if (!msg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMP_EVT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_health_server_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
if (!msg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMP_EVT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_health_server_callback(esp_ble_mesh_health_server_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_HEALTH_SERVER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_HEALTH_SERVER;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params,
|
||||
sizeof(esp_ble_mesh_health_server_cb_param_t), btc_ble_mesh_health_server_copy_req_data);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_server_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_health_server_cb_param_t param = {0};
|
||||
btc_ble_mesh_health_server_args_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
@ -560,18 +576,21 @@ void btc_mesh_health_server_call_handler(btc_msg_t *msg)
|
||||
arg = (btc_ble_mesh_health_server_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE: {
|
||||
health_server_cb.error_code = bt_mesh_fault_update((struct bt_mesh_elem *)arg->fault_update.element);
|
||||
btc_mesh_health_server_callback(&health_server_cb, ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMPLETE_EVT);
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE:
|
||||
param.fault_update_comp.element = arg->health_fault_update.element;
|
||||
param.fault_update_comp.error_code =
|
||||
bt_mesh_fault_update((struct bt_mesh_elem *)arg->health_fault_update.element);
|
||||
btc_ble_mesh_health_server_callback(¶m, ESP_BLE_MESH_HEALTH_SERVER_FAULT_UPDATE_COMP_EVT);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
btc_ble_mesh_health_server_arg_deep_free(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_health_server_cb_handler(btc_msg_t *msg)
|
||||
void btc_ble_mesh_health_server_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_health_server_cb_param_t *param = NULL;
|
||||
|
||||
@ -589,4 +608,45 @@ void btc_mesh_health_server_cb_handler(btc_msg_t *msg)
|
||||
}
|
||||
|
||||
btc_ble_mesh_health_server_free_req_data(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_server_fault_clear(struct bt_mesh_model *model, u16_t company_id)
|
||||
{
|
||||
esp_ble_mesh_health_server_cb_param_t param = {0};
|
||||
|
||||
param.fault_clear.model = (esp_ble_mesh_model_t *)model;
|
||||
param.fault_clear.company_id = company_id;
|
||||
|
||||
btc_ble_mesh_health_server_callback(¶m, ESP_BLE_MESH_HEALTH_SERVER_FAULT_CLEAR_EVT);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_server_fault_test(struct bt_mesh_model *model, u8_t test_id, u16_t company_id)
|
||||
{
|
||||
esp_ble_mesh_health_server_cb_param_t param = {0};
|
||||
|
||||
param.fault_test.model = (esp_ble_mesh_model_t *)model;
|
||||
param.fault_test.test_id = test_id;
|
||||
param.fault_test.company_id = company_id;
|
||||
|
||||
btc_ble_mesh_health_server_callback(¶m, ESP_BLE_MESH_HEALTH_SERVER_FAULT_TEST_EVT);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_server_attention_on(struct bt_mesh_model *model, u8_t time)
|
||||
{
|
||||
esp_ble_mesh_health_server_cb_param_t param = {0};
|
||||
|
||||
param.attention_on.model = (esp_ble_mesh_model_t *)model;
|
||||
param.attention_on.time = time;
|
||||
|
||||
btc_ble_mesh_health_server_callback(¶m, ESP_BLE_MESH_HEALTH_SERVER_ATTENTION_ON_EVT);
|
||||
}
|
||||
|
||||
void btc_ble_mesh_health_server_attention_off(struct bt_mesh_model *model)
|
||||
{
|
||||
esp_ble_mesh_health_server_cb_param_t param = {0};
|
||||
|
||||
param.attention_off.model = (esp_ble_mesh_model_t *)model;
|
||||
|
||||
btc_ble_mesh_health_server_callback(¶m, ESP_BLE_MESH_HEALTH_SERVER_ATTENTION_OFF_EVT);
|
||||
}
|
||||
|
@ -22,19 +22,22 @@
|
||||
#include "btc_ble_mesh_lighting_model.h"
|
||||
#include "esp_ble_mesh_lighting_model_api.h"
|
||||
|
||||
static inline void btc_ble_mesh_cb_to_app(esp_ble_mesh_light_client_cb_event_t event,
|
||||
/* Lighting Client Models related functions */
|
||||
|
||||
static inline void btc_ble_mesh_lighting_client_cb_to_app(esp_ble_mesh_light_client_cb_event_t event,
|
||||
esp_ble_mesh_light_client_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_light_client_cb_t btc_mesh_cb = (esp_ble_mesh_light_client_cb_t)btc_profile_cb_get(BTC_PID_LIGHT_CLIENT);
|
||||
if (btc_mesh_cb) {
|
||||
btc_mesh_cb(event, param);
|
||||
esp_ble_mesh_light_client_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_light_client_cb_t)btc_profile_cb_get(BTC_PID_LIGHTING_CLIENT);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_light_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
void btc_ble_mesh_lighting_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
btc_ble_mesh_light_client_args_t *dst = (btc_ble_mesh_light_client_args_t *)p_dest;
|
||||
btc_ble_mesh_light_client_args_t *src = (btc_ble_mesh_light_client_args_t *)p_src;
|
||||
btc_ble_mesh_lighting_client_args_t *dst = (btc_ble_mesh_lighting_client_args_t *)p_dest;
|
||||
btc_ble_mesh_lighting_client_args_t *src = (btc_ble_mesh_lighting_client_args_t *)p_src;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
@ -42,7 +45,7 @@ void btc_ble_mesh_light_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_LIGHT_CLIENT_GET_STATE: {
|
||||
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE: {
|
||||
dst->light_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->light_client_get_state.get_state = (esp_ble_mesh_light_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_light_client_get_state_t));
|
||||
if (dst->light_client_get_state.params && dst->light_client_get_state.get_state) {
|
||||
@ -55,7 +58,7 @@ void btc_ble_mesh_light_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_LIGHT_CLIENT_SET_STATE: {
|
||||
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE: {
|
||||
dst->light_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->light_client_set_state.set_state = (esp_ble_mesh_light_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_light_client_set_state_t));
|
||||
if (dst->light_client_set_state.params && dst->light_client_set_state.set_state) {
|
||||
@ -74,11 +77,43 @@ void btc_ble_mesh_light_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
static void btc_ble_mesh_lighting_client_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_lighting_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_lighting_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE:
|
||||
if (arg->light_client_get_state.params) {
|
||||
osi_free(arg->light_client_get_state.params);
|
||||
}
|
||||
if (arg->light_client_get_state.get_state) {
|
||||
osi_free(arg->light_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE:
|
||||
if (arg->light_client_set_state.params) {
|
||||
osi_free(arg->light_client_set_state.params);
|
||||
}
|
||||
if (arg->light_client_set_state.set_state) {
|
||||
osi_free(arg->light_client_set_state.set_state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_lighting_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_light_client_cb_param_t *p_dest_data = (esp_ble_mesh_light_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_light_client_cb_param_t *p_src_data = (esp_ble_mesh_light_client_cb_param_t *)p_src;
|
||||
u32_t opcode;
|
||||
u16_t length;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
@ -86,13 +121,22 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (!p_dest_data->params) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_LIGHT_CLIENT_PUBLISH_EVT:
|
||||
if (p_src_data->params) {
|
||||
opcode = p_src_data->params->opcode;
|
||||
switch (opcode) {
|
||||
switch (p_src_data->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS:
|
||||
@ -113,24 +157,15 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_LIGHT_CLIENT_TIMEOUT_EVT:
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (p_dest_data->params) {
|
||||
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
|
||||
static void btc_ble_mesh_lighting_client_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_light_client_cb_param_t *arg = NULL;
|
||||
u32_t opcode;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
@ -144,8 +179,7 @@ static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
|
||||
case ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_LIGHT_CLIENT_PUBLISH_EVT:
|
||||
if (arg->params) {
|
||||
opcode = arg->params->opcode;
|
||||
switch (opcode) {
|
||||
switch (arg->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET:
|
||||
case ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS:
|
||||
@ -165,56 +199,26 @@ static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_light_client_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_light_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_light_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_LIGHT_CLIENT_GET_STATE:
|
||||
if (arg->light_client_get_state.params) {
|
||||
osi_free(arg->light_client_get_state.params);
|
||||
}
|
||||
if (arg->light_client_get_state.get_state) {
|
||||
osi_free(arg->light_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_LIGHT_CLIENT_SET_STATE:
|
||||
if (arg->light_client_set_state.params) {
|
||||
osi_free(arg->light_client_set_state.params);
|
||||
}
|
||||
if (arg->light_client_set_state.set_state) {
|
||||
osi_free(arg->light_client_set_state.set_state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void btc_mesh_light_client_callback(esp_ble_mesh_light_client_cb_param_t *cb_params, uint8_t act)
|
||||
static void btc_ble_mesh_lighting_client_callback(esp_ble_mesh_light_client_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_LIGHTING_CLIENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_LIGHT_CLIENT;
|
||||
msg.pid = BTC_PID_LIGHTING_CLIENT;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params,
|
||||
sizeof(esp_ble_mesh_light_client_cb_param_t), btc_ble_mesh_copy_req_data);
|
||||
sizeof(esp_ble_mesh_light_client_cb_param_t), btc_ble_mesh_lighting_client_copy_req_data);
|
||||
}
|
||||
|
||||
void bt_mesh_callback_light_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
void bt_mesh_lighting_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len)
|
||||
@ -230,16 +234,16 @@ void bt_mesh_callback_light_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case 0x00:
|
||||
case BTC_BLE_MESH_EVT_LIGHTING_CLIENT_GET_STATE:
|
||||
act = ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT;
|
||||
break;
|
||||
case 0x01:
|
||||
case BTC_BLE_MESH_EVT_LIGHTING_CLIENT_SET_STATE:
|
||||
act = ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT;
|
||||
break;
|
||||
case 0x02:
|
||||
case BTC_BLE_MESH_EVT_LIGHTING_CLIENT_PUBLISH:
|
||||
act = ESP_BLE_MESH_LIGHT_CLIENT_PUBLISH_EVT;
|
||||
break;
|
||||
case 0x03:
|
||||
case BTC_BLE_MESH_EVT_LIGHTING_CLIENT_TIMEOUT:
|
||||
act = ESP_BLE_MESH_LIGHT_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
@ -264,26 +268,31 @@ void bt_mesh_callback_light_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
memcpy(&cb_params.status_cb, val, length);
|
||||
}
|
||||
|
||||
btc_mesh_light_client_callback(&cb_params, act);
|
||||
btc_ble_mesh_lighting_client_callback(&cb_params, act);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_light_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
|
||||
void btc_ble_mesh_lighting_client_publish_callback(u32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
if (!model || !ctx || !buf) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_callback_light_status_to_btc(opcode, 0x02, model, ctx, buf->data, buf->len);
|
||||
bt_mesh_lighting_client_cb_evt_to_btc(opcode,
|
||||
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_light_client_call_handler(btc_msg_t *msg)
|
||||
void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_light_client_cb_param_t light_client_cb = {0};
|
||||
esp_ble_mesh_client_common_param_t *params = NULL;
|
||||
btc_ble_mesh_light_client_args_t *arg = NULL;
|
||||
struct bt_mesh_common_param common = {0};
|
||||
btc_ble_mesh_lighting_client_args_t *arg = NULL;
|
||||
esp_ble_mesh_light_client_cb_param_t cb = {0};
|
||||
bt_mesh_client_common_param_t common = {0};
|
||||
bt_mesh_role_param_t role_param = {0};
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
@ -291,16 +300,16 @@ void btc_mesh_light_client_call_handler(btc_msg_t *msg)
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_light_client_args_t *)(msg->arg);
|
||||
arg = (btc_ble_mesh_lighting_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_LIGHT_CLIENT_GET_STATE: {
|
||||
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE: {
|
||||
params = arg->light_client_get_state.params;
|
||||
role_param.model = (struct bt_mesh_model *)params->model;
|
||||
role_param.role = params->msg_role;
|
||||
if (bt_mesh_set_model_role(&role_param)) {
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
common.model = (struct bt_mesh_model *)params->model;
|
||||
@ -311,25 +320,22 @@ void btc_mesh_light_client_call_handler(btc_msg_t *msg)
|
||||
common.ctx.send_ttl = params->ctx.send_ttl;
|
||||
common.msg_timeout = params->msg_timeout;
|
||||
|
||||
light_client_cb.params = arg->light_client_get_state.params;
|
||||
light_client_cb.error_code =
|
||||
bt_mesh_light_client_get_state(&common,
|
||||
(void *)arg->light_client_get_state.get_state,
|
||||
(void *)&light_client_cb.status_cb);
|
||||
if (light_client_cb.error_code) {
|
||||
cb.params = arg->light_client_get_state.params;
|
||||
cb.error_code = bt_mesh_light_client_get_state(&common,
|
||||
(void *)arg->light_client_get_state.get_state, (void *)&cb.status_cb);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_mesh_light_client_callback(&light_client_cb,
|
||||
ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT);
|
||||
btc_ble_mesh_lighting_client_callback(&cb, ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_LIGHT_CLIENT_SET_STATE: {
|
||||
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE: {
|
||||
params = arg->light_client_set_state.params;
|
||||
role_param.model = (struct bt_mesh_model *)params->model;
|
||||
role_param.role = params->msg_role;
|
||||
if (bt_mesh_set_model_role(&role_param)) {
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
common.model = (struct bt_mesh_model *)params->model;
|
||||
@ -340,15 +346,12 @@ void btc_mesh_light_client_call_handler(btc_msg_t *msg)
|
||||
common.ctx.send_ttl = params->ctx.send_ttl;
|
||||
common.msg_timeout = params->msg_timeout;
|
||||
|
||||
light_client_cb.params = arg->light_client_set_state.params;
|
||||
light_client_cb.error_code =
|
||||
bt_mesh_light_client_set_state(&common,
|
||||
(void *)arg->light_client_set_state.set_state,
|
||||
(void *)&light_client_cb.status_cb);
|
||||
if (light_client_cb.error_code) {
|
||||
cb.params = arg->light_client_set_state.params;
|
||||
cb.error_code = bt_mesh_light_client_set_state(&common,
|
||||
(void *)arg->light_client_set_state.set_state, (void *)&cb.status_cb);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_mesh_light_client_callback(&light_client_cb,
|
||||
ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT);
|
||||
btc_ble_mesh_lighting_client_callback(&cb, ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -356,10 +359,11 @@ void btc_mesh_light_client_call_handler(btc_msg_t *msg)
|
||||
break;
|
||||
}
|
||||
|
||||
btc_ble_mesh_light_client_arg_deep_free(msg);
|
||||
btc_ble_mesh_lighting_client_arg_deep_free(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_light_client_cb_handler(btc_msg_t *msg)
|
||||
void btc_ble_mesh_lighting_client_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_light_client_cb_param_t *param = NULL;
|
||||
|
||||
@ -371,11 +375,211 @@ void btc_mesh_light_client_cb_handler(btc_msg_t *msg)
|
||||
param = (esp_ble_mesh_light_client_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_LIGHT_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_cb_to_app(msg->act, param);
|
||||
btc_ble_mesh_lighting_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_free_req_data(msg);
|
||||
btc_ble_mesh_lighting_client_free_req_data(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Lighting Server Models related functions */
|
||||
|
||||
static inline void btc_ble_mesh_lighting_server_cb_to_app(
|
||||
esp_ble_mesh_lighting_server_cb_event_t event,
|
||||
esp_ble_mesh_lighting_server_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_lighting_server_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_lighting_server_cb_t)btc_profile_cb_get(BTC_PID_LIGHTING_SERVER);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_lighting_server_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_lighting_server_cb_param_t *p_dest_data = (esp_ble_mesh_lighting_server_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_lighting_server_cb_param_t *p_src_data = (esp_ble_mesh_lighting_server_cb_param_t *)p_src;
|
||||
u16_t length;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_LIGHTING_SERVER_STATE_CHANGE_EVT:
|
||||
if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET ||
|
||||
p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK) {
|
||||
if (p_src_data->value.state_change.lc_property_set.property_value) {
|
||||
length = p_src_data->value.state_change.lc_property_set.property_value->len;
|
||||
p_dest_data->value.state_change.lc_property_set.property_value = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.state_change.lc_property_set.property_value == NULL) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.lc_property_set.property_value,
|
||||
p_src_data->value.state_change.lc_property_set.property_value->data,
|
||||
p_src_data->value.state_change.lc_property_set.property_value->len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_LIGHTING_SERVER_RECV_SET_MSG_EVT:
|
||||
if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET ||
|
||||
p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK) {
|
||||
if (p_src_data->value.set.lc_property.property_value) {
|
||||
length = p_src_data->value.set.lc_property.property_value->len;
|
||||
p_dest_data->value.set.lc_property.property_value = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.set.lc_property.property_value == NULL) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.set.lc_property.property_value,
|
||||
p_src_data->value.set.lc_property.property_value->data,
|
||||
p_src_data->value.set.lc_property.property_value->len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_LIGHTING_SERVER_RECV_STATUS_MSG_EVT:
|
||||
if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_STATUS) {
|
||||
if (p_src_data->value.status.sensor_status.data) {
|
||||
length = p_src_data->value.status.sensor_status.data->len;
|
||||
p_dest_data->value.status.sensor_status.data = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.status.sensor_status.data == NULL) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.status.sensor_status.data,
|
||||
p_src_data->value.status.sensor_status.data->data,
|
||||
p_src_data->value.status.sensor_status.data->len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_lighting_server_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_lighting_server_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (esp_ble_mesh_lighting_server_cb_param_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_LIGHTING_SERVER_STATE_CHANGE_EVT:
|
||||
if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET ||
|
||||
arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK) {
|
||||
bt_mesh_free_buf(arg->value.state_change.lc_property_set.property_value);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_LIGHTING_SERVER_RECV_SET_MSG_EVT:
|
||||
if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET ||
|
||||
arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK) {
|
||||
bt_mesh_free_buf(arg->value.set.lc_property.property_value);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_LIGHTING_SERVER_RECV_STATUS_MSG_EVT:
|
||||
if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_STATUS) {
|
||||
bt_mesh_free_buf(arg->value.status.sensor_status.data);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_lighting_server_callback(esp_ble_mesh_lighting_server_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_LIGHTING_SERVER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_LIGHTING_SERVER;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(
|
||||
&msg, cb_params, sizeof(esp_ble_mesh_lighting_server_cb_param_t), btc_ble_mesh_lighting_server_copy_req_data);
|
||||
}
|
||||
|
||||
void bt_mesh_lighting_server_cb_evt_to_btc(u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_lighting_server_cb_param_t cb_params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
|
||||
if (model == NULL || ctx == NULL) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE:
|
||||
act = ESP_BLE_MESH_LIGHTING_SERVER_STATE_CHANGE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_GET_MSG:
|
||||
act = ESP_BLE_MESH_LIGHTING_SERVER_RECV_GET_MSG_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG:
|
||||
act = ESP_BLE_MESH_LIGHTING_SERVER_RECV_SET_MSG_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_STATUS_MSG:
|
||||
act = ESP_BLE_MESH_LIGHTING_SERVER_RECV_STATUS_MSG_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown Lighting Server event type", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
cb_params.model = (esp_ble_mesh_model_t *)model;
|
||||
cb_params.ctx.net_idx = ctx->net_idx;
|
||||
cb_params.ctx.app_idx = ctx->app_idx;
|
||||
cb_params.ctx.addr = ctx->addr;
|
||||
cb_params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
cb_params.ctx.recv_op = ctx->recv_op;
|
||||
cb_params.ctx.recv_dst = ctx->recv_dst;
|
||||
|
||||
if (val && len) {
|
||||
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
|
||||
memcpy(&cb_params.value, val, length);
|
||||
}
|
||||
|
||||
btc_ble_mesh_lighting_server_callback(&cb_params, act);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_ble_mesh_lighting_server_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_lighting_server_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_lighting_server_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_LIGHTING_SERVER_EVT_MAX) {
|
||||
btc_ble_mesh_lighting_server_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_lighting_server_free_req_data(msg);
|
||||
return;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -22,12 +22,15 @@
|
||||
#include "btc_ble_mesh_sensor_model.h"
|
||||
#include "esp_ble_mesh_sensor_model_api.h"
|
||||
|
||||
static inline void btc_ble_mesh_cb_to_app(esp_ble_mesh_sensor_client_cb_event_t event,
|
||||
/* Sensor Client Models related functions */
|
||||
|
||||
static inline void btc_ble_mesh_sensor_client_cb_to_app(esp_ble_mesh_sensor_client_cb_event_t event,
|
||||
esp_ble_mesh_sensor_client_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_sensor_client_cb_t btc_mesh_cb = (esp_ble_mesh_sensor_client_cb_t)btc_profile_cb_get(BTC_PID_SENSOR_CLIENT);
|
||||
if (btc_mesh_cb) {
|
||||
btc_mesh_cb(event, param);
|
||||
esp_ble_mesh_sensor_client_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_sensor_client_cb_t)btc_profile_cb_get(BTC_PID_SENSOR_CLIENT);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +38,6 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
{
|
||||
btc_ble_mesh_sensor_client_args_t *dst = (btc_ble_mesh_sensor_client_args_t *)p_dest;
|
||||
btc_ble_mesh_sensor_client_args_t *src = (btc_ble_mesh_sensor_client_args_t *)p_src;
|
||||
u32_t opcode;
|
||||
u16_t length;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
@ -53,8 +55,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
memcpy(dst->sensor_client_get_state.get_state, src->sensor_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_sensor_client_get_state_t));
|
||||
|
||||
opcode = src->sensor_client_get_state.params->opcode;
|
||||
switch (opcode) {
|
||||
switch (src->sensor_client_get_state.params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET:
|
||||
if (src->sensor_client_get_state.get_state->column_get.raw_value_x) {
|
||||
length = src->sensor_client_get_state.get_state->column_get.raw_value_x->len;
|
||||
@ -109,8 +110,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
memcpy(dst->sensor_client_set_state.set_state, src->sensor_client_set_state.set_state,
|
||||
sizeof(esp_ble_mesh_sensor_client_set_state_t));
|
||||
|
||||
opcode = src->sensor_client_set_state.params->opcode;
|
||||
switch (opcode) {
|
||||
switch (src->sensor_client_set_state.params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET:
|
||||
if (src->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down) {
|
||||
length = src->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down->len;
|
||||
@ -184,11 +184,71 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
void btc_ble_mesh_sensor_client_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_sensor_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_sensor_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE:
|
||||
if (arg->sensor_client_get_state.get_state) {
|
||||
if (arg->sensor_client_get_state.params) {
|
||||
switch (arg->sensor_client_get_state.params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET:
|
||||
bt_mesh_free_buf(arg->sensor_client_get_state.get_state->column_get.raw_value_x);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_GET:
|
||||
bt_mesh_free_buf(arg->sensor_client_get_state.get_state->series_get.raw_value_x1);
|
||||
bt_mesh_free_buf(arg->sensor_client_get_state.get_state->series_get.raw_value_x2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
osi_free(arg->sensor_client_get_state.get_state);
|
||||
}
|
||||
if (arg->sensor_client_get_state.params) {
|
||||
osi_free(arg->sensor_client_get_state.params);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE:
|
||||
if (arg->sensor_client_set_state.set_state) {
|
||||
if (arg->sensor_client_set_state.params) {
|
||||
switch (arg->sensor_client_set_state.params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET:
|
||||
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down);
|
||||
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up);
|
||||
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.fast_cadence_low);
|
||||
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.fast_cadence_high);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET:
|
||||
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->setting_set.sensor_setting_raw);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
osi_free(arg->sensor_client_set_state.set_state);
|
||||
}
|
||||
if (arg->sensor_client_set_state.params) {
|
||||
osi_free(arg->sensor_client_set_state.params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_sensor_client_cb_param_t *p_dest_data = (esp_ble_mesh_sensor_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_sensor_client_cb_param_t *p_src_data = (esp_ble_mesh_sensor_client_cb_param_t *)p_src;
|
||||
u32_t opcode;
|
||||
u16_t length;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
@ -196,13 +256,22 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (!p_dest_data->params) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_SENSOR_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_SENSOR_CLIENT_PUBLISH_EVT:
|
||||
if (p_src_data->params) {
|
||||
opcode = p_src_data->params->opcode;
|
||||
switch (opcode) {
|
||||
switch (p_src_data->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS:
|
||||
if (p_src_data->status_cb.descriptor_status.descriptor) {
|
||||
@ -308,24 +377,15 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_SENSOR_CLIENT_TIMEOUT_EVT:
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (p_dest_data->params) {
|
||||
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
|
||||
static void btc_ble_mesh_sensor_client_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_sensor_client_cb_param_t *arg = NULL;
|
||||
u32_t opcode;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
@ -339,8 +399,7 @@ static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
|
||||
case ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_SENSOR_CLIENT_PUBLISH_EVT:
|
||||
if (arg->params) {
|
||||
opcode = arg->params->opcode;
|
||||
switch (opcode) {
|
||||
switch (arg->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.descriptor_status.descriptor);
|
||||
@ -385,87 +444,26 @@ static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_sensor_client_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_sensor_client_args_t *arg = NULL;
|
||||
u32_t opcode = 0;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_sensor_client_args_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE:
|
||||
if (arg->sensor_client_get_state.params) {
|
||||
opcode = arg->sensor_client_get_state.params->opcode;
|
||||
osi_free(arg->sensor_client_get_state.params);
|
||||
}
|
||||
if (arg->sensor_client_get_state.get_state) {
|
||||
if (opcode) {
|
||||
switch (opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET:
|
||||
bt_mesh_free_buf(arg->sensor_client_get_state.get_state->column_get.raw_value_x);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_GET:
|
||||
bt_mesh_free_buf(arg->sensor_client_get_state.get_state->series_get.raw_value_x1);
|
||||
bt_mesh_free_buf(arg->sensor_client_get_state.get_state->series_get.raw_value_x2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
osi_free(arg->sensor_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE:
|
||||
if (arg->sensor_client_set_state.params) {
|
||||
opcode = arg->sensor_client_set_state.params->opcode;
|
||||
osi_free(arg->sensor_client_set_state.params);
|
||||
}
|
||||
if (arg->sensor_client_set_state.set_state) {
|
||||
if (opcode) {
|
||||
switch (opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET:
|
||||
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down);
|
||||
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up);
|
||||
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.fast_cadence_low);
|
||||
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->cadence_set.fast_cadence_high);
|
||||
break;
|
||||
case ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET:
|
||||
bt_mesh_free_buf(arg->sensor_client_set_state.set_state->setting_set.sensor_setting_raw);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
osi_free(arg->sensor_client_set_state.set_state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void btc_mesh_sensor_client_callback(esp_ble_mesh_sensor_client_cb_param_t *cb_params, uint8_t act)
|
||||
static void btc_ble_mesh_sensor_client_callback(esp_ble_mesh_sensor_client_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_SENSOR_CLIENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_SENSOR_CLIENT;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params,
|
||||
sizeof(esp_ble_mesh_sensor_client_cb_param_t), btc_ble_mesh_copy_req_data);
|
||||
sizeof(esp_ble_mesh_sensor_client_cb_param_t), btc_ble_mesh_sensor_client_copy_req_data);
|
||||
}
|
||||
|
||||
void bt_mesh_callback_sensor_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
void bt_mesh_sensor_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len)
|
||||
@ -481,16 +479,16 @@ void bt_mesh_callback_sensor_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case 0x00:
|
||||
case BTC_BLE_MESH_EVT_SENSOR_CLIENT_GET_STATE:
|
||||
act = ESP_BLE_MESH_SENSOR_CLIENT_GET_STATE_EVT;
|
||||
break;
|
||||
case 0x01:
|
||||
case BTC_BLE_MESH_EVT_SENSOR_CLIENT_SET_STATE:
|
||||
act = ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT;
|
||||
break;
|
||||
case 0x02:
|
||||
case BTC_BLE_MESH_EVT_SENSOR_CLIENT_PUBLISH:
|
||||
act = ESP_BLE_MESH_SENSOR_CLIENT_PUBLISH_EVT;
|
||||
break;
|
||||
case 0x03:
|
||||
case BTC_BLE_MESH_EVT_SENSOR_CLIENT_TIMEOUT:
|
||||
act = ESP_BLE_MESH_SENSOR_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
@ -515,26 +513,31 @@ void bt_mesh_callback_sensor_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
memcpy(&cb_params.status_cb, val, length);
|
||||
}
|
||||
|
||||
btc_mesh_sensor_client_callback(&cb_params, act);
|
||||
btc_ble_mesh_sensor_client_callback(&cb_params, act);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_sensor_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
|
||||
void btc_ble_mesh_sensor_client_publish_callback(u32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
if (!model || !ctx || !buf) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_callback_sensor_status_to_btc(opcode, 0x02, model, ctx, buf->data, buf->len);
|
||||
bt_mesh_sensor_client_cb_evt_to_btc(opcode,
|
||||
BTC_BLE_MESH_EVT_SENSOR_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_sensor_client_call_handler(btc_msg_t *msg)
|
||||
void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_sensor_client_cb_param_t sensor_client_cb = {0};
|
||||
esp_ble_mesh_client_common_param_t *params = NULL;
|
||||
btc_ble_mesh_sensor_client_args_t *arg = NULL;
|
||||
struct bt_mesh_common_param common = {0};
|
||||
esp_ble_mesh_sensor_client_cb_param_t cb = {0};
|
||||
bt_mesh_client_common_param_t common = {0};
|
||||
bt_mesh_role_param_t role_param = {0};
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
@ -549,9 +552,9 @@ void btc_mesh_sensor_client_call_handler(btc_msg_t *msg)
|
||||
params = arg->sensor_client_get_state.params;
|
||||
role_param.model = (struct bt_mesh_model *)params->model;
|
||||
role_param.role = params->msg_role;
|
||||
if (bt_mesh_set_model_role(&role_param)) {
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
common.model = (struct bt_mesh_model *)params->model;
|
||||
@ -562,15 +565,12 @@ void btc_mesh_sensor_client_call_handler(btc_msg_t *msg)
|
||||
common.ctx.send_ttl = params->ctx.send_ttl;
|
||||
common.msg_timeout = params->msg_timeout;
|
||||
|
||||
sensor_client_cb.params = arg->sensor_client_get_state.params;
|
||||
sensor_client_cb.error_code =
|
||||
bt_mesh_sensor_client_get_state(&common,
|
||||
(void *)arg->sensor_client_get_state.get_state,
|
||||
(void *)&sensor_client_cb.status_cb);
|
||||
if (sensor_client_cb.error_code) {
|
||||
cb.params = arg->sensor_client_get_state.params;
|
||||
cb.error_code = bt_mesh_sensor_client_get_state(&common,
|
||||
(void *)arg->sensor_client_get_state.get_state, (void *)&cb.status_cb);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_mesh_sensor_client_callback(&sensor_client_cb,
|
||||
ESP_BLE_MESH_SENSOR_CLIENT_GET_STATE_EVT);
|
||||
btc_ble_mesh_sensor_client_callback(&cb, ESP_BLE_MESH_SENSOR_CLIENT_GET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -578,9 +578,9 @@ void btc_mesh_sensor_client_call_handler(btc_msg_t *msg)
|
||||
params = arg->sensor_client_set_state.params;
|
||||
role_param.model = (struct bt_mesh_model *)params->model;
|
||||
role_param.role = params->msg_role;
|
||||
if (bt_mesh_set_model_role(&role_param)) {
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
common.model = (struct bt_mesh_model *)params->model;
|
||||
@ -591,15 +591,12 @@ void btc_mesh_sensor_client_call_handler(btc_msg_t *msg)
|
||||
common.ctx.send_ttl = params->ctx.send_ttl;
|
||||
common.msg_timeout = params->msg_timeout;
|
||||
|
||||
sensor_client_cb.params = arg->sensor_client_set_state.params;
|
||||
sensor_client_cb.error_code =
|
||||
bt_mesh_sensor_client_set_state(&common,
|
||||
(void *)arg->sensor_client_set_state.set_state,
|
||||
(void *)&sensor_client_cb.status_cb);
|
||||
if (sensor_client_cb.error_code) {
|
||||
cb.params = arg->sensor_client_set_state.params;
|
||||
cb.error_code = bt_mesh_sensor_client_set_state(&common,
|
||||
(void *)arg->sensor_client_set_state.set_state, (void *)&cb.status_cb);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_mesh_sensor_client_callback(&sensor_client_cb,
|
||||
ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT);
|
||||
btc_ble_mesh_sensor_client_callback(&cb, ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -608,9 +605,10 @@ void btc_mesh_sensor_client_call_handler(btc_msg_t *msg)
|
||||
}
|
||||
|
||||
btc_ble_mesh_sensor_client_arg_deep_free(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_sensor_client_cb_handler(btc_msg_t *msg)
|
||||
void btc_ble_mesh_sensor_client_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_sensor_client_cb_param_t *param = NULL;
|
||||
|
||||
@ -622,11 +620,290 @@ void btc_mesh_sensor_client_cb_handler(btc_msg_t *msg)
|
||||
param = (esp_ble_mesh_sensor_client_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_SENSOR_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_cb_to_app(msg->act, param);
|
||||
btc_ble_mesh_sensor_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_free_req_data(msg);
|
||||
btc_ble_mesh_sensor_client_free_req_data(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Sensor Server Models related functions */
|
||||
|
||||
static inline void btc_ble_mesh_sensor_server_cb_to_app(
|
||||
esp_ble_mesh_sensor_server_cb_event_t event,
|
||||
esp_ble_mesh_sensor_server_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_sensor_server_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_sensor_server_cb_t)btc_profile_cb_get(BTC_PID_SENSOR_SERVER);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_sensor_server_cb_param_t *p_dest_data = (esp_ble_mesh_sensor_server_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_sensor_server_cb_param_t *p_src_data = (esp_ble_mesh_sensor_server_cb_param_t *)p_src;
|
||||
u16_t length;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_SENSOR_SERVER_STATE_CHANGE_EVT:
|
||||
if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET ||
|
||||
p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK) {
|
||||
if (p_src_data->value.state_change.sensor_cadence_set.trigger_delta_down) {
|
||||
length = p_src_data->value.state_change.sensor_cadence_set.trigger_delta_down->len;
|
||||
p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_down = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_down == NULL) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_down,
|
||||
p_src_data->value.state_change.sensor_cadence_set.trigger_delta_down->data,
|
||||
p_src_data->value.state_change.sensor_cadence_set.trigger_delta_down->len);
|
||||
}
|
||||
if (p_src_data->value.state_change.sensor_cadence_set.trigger_delta_up) {
|
||||
length = p_src_data->value.state_change.sensor_cadence_set.trigger_delta_up->len;
|
||||
p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_up = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_up == NULL) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_up,
|
||||
p_src_data->value.state_change.sensor_cadence_set.trigger_delta_up->data,
|
||||
p_src_data->value.state_change.sensor_cadence_set.trigger_delta_up->len);
|
||||
}
|
||||
if (p_src_data->value.state_change.sensor_cadence_set.fast_cadence_low) {
|
||||
length = p_src_data->value.state_change.sensor_cadence_set.fast_cadence_low->len;
|
||||
p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_low = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_low == NULL) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_low,
|
||||
p_src_data->value.state_change.sensor_cadence_set.fast_cadence_low->data,
|
||||
p_src_data->value.state_change.sensor_cadence_set.fast_cadence_low->len);
|
||||
}
|
||||
if (p_src_data->value.state_change.sensor_cadence_set.fast_cadence_high) {
|
||||
length = p_src_data->value.state_change.sensor_cadence_set.fast_cadence_high->len;
|
||||
p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_high = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_high == NULL) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_high,
|
||||
p_src_data->value.state_change.sensor_cadence_set.fast_cadence_high->data,
|
||||
p_src_data->value.state_change.sensor_cadence_set.fast_cadence_high->len);
|
||||
}
|
||||
} else if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET ||
|
||||
p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK) {
|
||||
if (p_src_data->value.state_change.sensor_setting_set.setting_value) {
|
||||
length = p_src_data->value.state_change.sensor_setting_set.setting_value->len;
|
||||
p_dest_data->value.state_change.sensor_setting_set.setting_value = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.state_change.sensor_setting_set.setting_value == NULL) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_setting_set.setting_value,
|
||||
p_src_data->value.state_change.sensor_setting_set.setting_value->data,
|
||||
p_src_data->value.state_change.sensor_setting_set.setting_value->len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_SENSOR_SERVER_RECV_GET_MSG_EVT:
|
||||
if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET) {
|
||||
if (p_src_data->value.get.sensor_column.raw_value_x) {
|
||||
length = p_src_data->value.get.sensor_column.raw_value_x->len;
|
||||
p_dest_data->value.get.sensor_column.raw_value_x = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.get.sensor_column.raw_value_x == NULL) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.get.sensor_column.raw_value_x,
|
||||
p_src_data->value.get.sensor_column.raw_value_x->data,
|
||||
p_src_data->value.get.sensor_column.raw_value_x->len);
|
||||
}
|
||||
} else if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_GET) {
|
||||
if (p_src_data->value.get.sensor_series.raw_value) {
|
||||
length = p_src_data->value.get.sensor_series.raw_value->len;
|
||||
p_dest_data->value.get.sensor_series.raw_value = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.get.sensor_series.raw_value == NULL) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.get.sensor_series.raw_value,
|
||||
p_src_data->value.get.sensor_series.raw_value->data,
|
||||
p_src_data->value.get.sensor_series.raw_value->len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_SENSOR_SERVER_RECV_SET_MSG_EVT:
|
||||
if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET ||
|
||||
p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK) {
|
||||
if (p_src_data->value.set.sensor_cadence.cadence) {
|
||||
length = p_src_data->value.set.sensor_cadence.cadence->len;
|
||||
p_dest_data->value.set.sensor_cadence.cadence = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.set.sensor_cadence.cadence == NULL) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.set.sensor_cadence.cadence,
|
||||
p_src_data->value.set.sensor_cadence.cadence->data,
|
||||
p_src_data->value.set.sensor_cadence.cadence->len);
|
||||
}
|
||||
} else if (p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET ||
|
||||
p_src_data->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK) {
|
||||
if (p_src_data->value.set.sensor_setting.setting_raw) {
|
||||
length = p_src_data->value.set.sensor_setting.setting_raw->len;
|
||||
p_dest_data->value.set.sensor_setting.setting_raw = bt_mesh_alloc_buf(length);
|
||||
if (p_dest_data->value.set.sensor_setting.setting_raw == NULL) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.set.sensor_setting.setting_raw,
|
||||
p_src_data->value.set.sensor_setting.setting_raw->data,
|
||||
p_src_data->value.set.sensor_setting.setting_raw->len);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_sensor_server_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_sensor_server_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (esp_ble_mesh_sensor_server_cb_param_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_SENSOR_SERVER_STATE_CHANGE_EVT:
|
||||
if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET ||
|
||||
arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK) {
|
||||
bt_mesh_free_buf(arg->value.state_change.sensor_cadence_set.trigger_delta_down);
|
||||
bt_mesh_free_buf(arg->value.state_change.sensor_cadence_set.trigger_delta_up);
|
||||
bt_mesh_free_buf(arg->value.state_change.sensor_cadence_set.fast_cadence_low);
|
||||
bt_mesh_free_buf(arg->value.state_change.sensor_cadence_set.fast_cadence_high);
|
||||
} else if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET ||
|
||||
arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK) {
|
||||
bt_mesh_free_buf(arg->value.state_change.sensor_setting_set.setting_value);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_SENSOR_SERVER_RECV_GET_MSG_EVT:
|
||||
if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET) {
|
||||
bt_mesh_free_buf(arg->value.get.sensor_column.raw_value_x);
|
||||
} else if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_GET) {
|
||||
bt_mesh_free_buf(arg->value.get.sensor_series.raw_value);
|
||||
}
|
||||
break;
|
||||
case ESP_BLE_MESH_SENSOR_SERVER_RECV_SET_MSG_EVT:
|
||||
if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET ||
|
||||
arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK) {
|
||||
bt_mesh_free_buf(arg->value.set.sensor_cadence.cadence);
|
||||
} else if (arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET ||
|
||||
arg->ctx.recv_op == ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK) {
|
||||
bt_mesh_free_buf(arg->value.set.sensor_setting.setting_raw);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_sensor_server_callback(esp_ble_mesh_sensor_server_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_SENSOR_SERVER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_SENSOR_SERVER;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(
|
||||
&msg, cb_params, sizeof(esp_ble_mesh_sensor_server_cb_param_t), btc_ble_mesh_sensor_server_copy_req_data);
|
||||
}
|
||||
|
||||
void bt_mesh_sensor_server_cb_evt_to_btc(u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_sensor_server_cb_param_t cb_params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
|
||||
if (model == NULL || ctx == NULL) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case BTC_BLE_MESH_EVT_SENSOR_SERVER_STATE_CHANGE:
|
||||
act = ESP_BLE_MESH_SENSOR_SERVER_STATE_CHANGE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_SENSOR_SERVER_RECV_GET_MSG:
|
||||
act = ESP_BLE_MESH_SENSOR_SERVER_RECV_GET_MSG_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_SENSOR_SERVER_RECV_SET_MSG:
|
||||
act = ESP_BLE_MESH_SENSOR_SERVER_RECV_SET_MSG_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown Sensor Server event type", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
cb_params.model = (esp_ble_mesh_model_t *)model;
|
||||
cb_params.ctx.net_idx = ctx->net_idx;
|
||||
cb_params.ctx.app_idx = ctx->app_idx;
|
||||
cb_params.ctx.addr = ctx->addr;
|
||||
cb_params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
cb_params.ctx.recv_op = ctx->recv_op;
|
||||
cb_params.ctx.recv_dst = ctx->recv_dst;
|
||||
|
||||
if (val && len) {
|
||||
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
|
||||
memcpy(&cb_params.value, val, length);
|
||||
}
|
||||
|
||||
btc_ble_mesh_sensor_server_callback(&cb_params, act);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_ble_mesh_sensor_server_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_sensor_server_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_sensor_server_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_SENSOR_SERVER_EVT_MAX) {
|
||||
btc_ble_mesh_sensor_server_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_sensor_server_free_req_data(msg);
|
||||
return;
|
||||
}
|
||||
|
@ -22,12 +22,15 @@
|
||||
#include "btc_ble_mesh_time_scene_model.h"
|
||||
#include "esp_ble_mesh_time_scene_model_api.h"
|
||||
|
||||
static inline void btc_ble_mesh_cb_to_app(esp_ble_mesh_time_scene_client_cb_event_t event,
|
||||
/* Time and Scenes Client Models related functions */
|
||||
|
||||
static inline void btc_ble_mesh_time_scene_client_cb_to_app(esp_ble_mesh_time_scene_client_cb_event_t event,
|
||||
esp_ble_mesh_time_scene_client_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_time_scene_client_cb_t btc_mesh_cb = (esp_ble_mesh_time_scene_client_cb_t)btc_profile_cb_get(BTC_PID_TIME_SCENE_CLIENT);
|
||||
if (btc_mesh_cb) {
|
||||
btc_mesh_cb(event, param);
|
||||
esp_ble_mesh_time_scene_client_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_time_scene_client_cb_t)btc_profile_cb_get(BTC_PID_TIME_SCENE_CLIENT);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,99 +77,6 @@ void btc_ble_mesh_time_scene_client_arg_deep_copy(btc_msg_t *msg, void *p_dest,
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_time_scene_client_cb_param_t *p_dest_data = (esp_ble_mesh_time_scene_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_time_scene_client_cb_param_t *p_src_data = (esp_ble_mesh_time_scene_client_cb_param_t *)p_src;
|
||||
u32_t opcode;
|
||||
u16_t length;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_PUBLISH_EVT:
|
||||
if (p_src_data->params) {
|
||||
opcode = p_src_data->params->opcode;
|
||||
switch (opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_STORE:
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_DELETE:
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS:
|
||||
if (p_src_data->status_cb.scene_register_status.scenes) {
|
||||
length = p_src_data->status_cb.scene_register_status.scenes->len;
|
||||
p_dest_data->status_cb.scene_register_status.scenes = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.scene_register_status.scenes) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.scene_register_status.scenes,
|
||||
p_src_data->status_cb.scene_register_status.scenes->data,
|
||||
p_src_data->status_cb.scene_register_status.scenes->len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT:
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (p_dest_data->params) {
|
||||
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_time_scene_client_cb_param_t *arg = NULL;
|
||||
u32_t opcode;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (esp_ble_mesh_time_scene_client_cb_param_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_PUBLISH_EVT:
|
||||
if (arg->params) {
|
||||
opcode = arg->params->opcode;
|
||||
switch (opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_STORE:
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_DELETE:
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.scene_register_status.scenes);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
osi_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_time_scene_client_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
btc_ble_mesh_time_scene_client_args_t *arg = NULL;
|
||||
@ -198,25 +108,119 @@ void btc_ble_mesh_time_scene_client_arg_deep_free(btc_msg_t *msg)
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void btc_mesh_time_scene_client_callback(esp_ble_mesh_time_scene_client_cb_param_t *cb_params, uint8_t act)
|
||||
static void btc_ble_mesh_time_scene_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
|
||||
{
|
||||
esp_ble_mesh_time_scene_client_cb_param_t *p_dest_data = (esp_ble_mesh_time_scene_client_cb_param_t *)p_dest;
|
||||
esp_ble_mesh_time_scene_client_cb_param_t *p_src_data = (esp_ble_mesh_time_scene_client_cb_param_t *)p_src;
|
||||
u16_t length;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (!p_dest_data->params) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t));
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_PUBLISH_EVT:
|
||||
if (p_src_data->params) {
|
||||
switch (p_src_data->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_STORE:
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_DELETE:
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS:
|
||||
if (p_src_data->status_cb.scene_register_status.scenes) {
|
||||
length = p_src_data->status_cb.scene_register_status.scenes->len;
|
||||
p_dest_data->status_cb.scene_register_status.scenes = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.scene_register_status.scenes) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.scene_register_status.scenes,
|
||||
p_src_data->status_cb.scene_register_status.scenes->data,
|
||||
p_src_data->status_cb.scene_register_status.scenes->len);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_time_scene_client_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_time_scene_client_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (esp_ble_mesh_time_scene_client_cb_param_t *)(msg->arg);
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT:
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT:
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_PUBLISH_EVT:
|
||||
if (arg->params) {
|
||||
switch (arg->params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_STORE:
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_DELETE:
|
||||
case ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS:
|
||||
bt_mesh_free_buf(arg->status_cb.scene_register_status.scenes);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
osi_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_time_scene_client_callback(esp_ble_mesh_time_scene_client_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_TIME_SCENE_CLIENT)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_TIME_SCENE_CLIENT;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params,
|
||||
sizeof(esp_ble_mesh_time_scene_client_cb_param_t), btc_ble_mesh_copy_req_data);
|
||||
sizeof(esp_ble_mesh_time_scene_client_cb_param_t), btc_ble_mesh_time_scene_client_copy_req_data);
|
||||
}
|
||||
|
||||
void bt_mesh_callback_time_scene_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
void bt_mesh_time_scene_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len)
|
||||
@ -232,16 +236,16 @@ void bt_mesh_callback_time_scene_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case 0x00:
|
||||
case BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_GET_STATE:
|
||||
act = ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT;
|
||||
break;
|
||||
case 0x01:
|
||||
case BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_SET_STATE:
|
||||
act = ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT;
|
||||
break;
|
||||
case 0x02:
|
||||
case BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_PUBLISH:
|
||||
act = ESP_BLE_MESH_TIME_SCENE_CLIENT_PUBLISH_EVT;
|
||||
break;
|
||||
case 0x03:
|
||||
case BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_TIMEOUT:
|
||||
act = ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
@ -266,26 +270,31 @@ void bt_mesh_callback_time_scene_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
memcpy(&cb_params.status_cb, val, length);
|
||||
}
|
||||
|
||||
btc_mesh_time_scene_client_callback(&cb_params, act);
|
||||
btc_ble_mesh_time_scene_client_callback(&cb_params, act);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_time_scene_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
|
||||
void btc_ble_mesh_time_scene_client_publish_callback(u32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
if (!model || !ctx || !buf) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_callback_time_scene_status_to_btc(opcode, 0x02, model, ctx, buf->data, buf->len);
|
||||
bt_mesh_time_scene_client_cb_evt_to_btc(opcode,
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_PUBLISH, model, ctx, buf->data, buf->len);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_time_scene_client_call_handler(btc_msg_t *msg)
|
||||
void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_time_scene_client_cb_param_t time_scene_client_cb = {0};
|
||||
btc_ble_mesh_time_scene_client_args_t *arg = NULL;
|
||||
esp_ble_mesh_client_common_param_t *params = NULL;
|
||||
struct bt_mesh_common_param common = {0};
|
||||
esp_ble_mesh_time_scene_client_cb_param_t cb = {0};
|
||||
bt_mesh_client_common_param_t common = {0};
|
||||
bt_mesh_role_param_t role_param = {0};
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
@ -300,9 +309,9 @@ void btc_mesh_time_scene_client_call_handler(btc_msg_t *msg)
|
||||
params = arg->time_scene_client_get_state.params;
|
||||
role_param.model = (struct bt_mesh_model *)params->model;
|
||||
role_param.role = params->msg_role;
|
||||
if (bt_mesh_set_model_role(&role_param)) {
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
common.model = (struct bt_mesh_model *)params->model;
|
||||
@ -313,15 +322,12 @@ void btc_mesh_time_scene_client_call_handler(btc_msg_t *msg)
|
||||
common.ctx.send_ttl = params->ctx.send_ttl;
|
||||
common.msg_timeout = params->msg_timeout;
|
||||
|
||||
time_scene_client_cb.params = arg->time_scene_client_get_state.params;
|
||||
time_scene_client_cb.error_code =
|
||||
bt_mesh_time_scene_client_get_state(&common,
|
||||
(void *)arg->time_scene_client_get_state.get_state,
|
||||
(void *)&time_scene_client_cb.status_cb);
|
||||
if (time_scene_client_cb.error_code) {
|
||||
cb.params = arg->time_scene_client_get_state.params;
|
||||
cb.error_code = bt_mesh_time_scene_client_get_state(&common,
|
||||
(void *)arg->time_scene_client_get_state.get_state, (void *)&cb.status_cb);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_mesh_time_scene_client_callback(&time_scene_client_cb,
|
||||
ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT);
|
||||
btc_ble_mesh_time_scene_client_callback(&cb, ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -329,9 +335,9 @@ void btc_mesh_time_scene_client_call_handler(btc_msg_t *msg)
|
||||
params = arg->time_scene_client_set_state.params;
|
||||
role_param.model = (struct bt_mesh_model *)params->model;
|
||||
role_param.role = params->msg_role;
|
||||
if (bt_mesh_set_model_role(&role_param)) {
|
||||
if (bt_mesh_set_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
return;
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
common.model = (struct bt_mesh_model *)params->model;
|
||||
@ -342,15 +348,12 @@ void btc_mesh_time_scene_client_call_handler(btc_msg_t *msg)
|
||||
common.ctx.send_ttl = params->ctx.send_ttl;
|
||||
common.msg_timeout = params->msg_timeout;
|
||||
|
||||
time_scene_client_cb.params = arg->time_scene_client_set_state.params;
|
||||
time_scene_client_cb.error_code =
|
||||
bt_mesh_time_scene_client_set_state(&common,
|
||||
(void *)arg->time_scene_client_set_state.set_state,
|
||||
(void *)&time_scene_client_cb.status_cb);
|
||||
if (time_scene_client_cb.error_code) {
|
||||
cb.params = arg->time_scene_client_set_state.params;
|
||||
cb.error_code = bt_mesh_time_scene_client_set_state(&common,
|
||||
(void *)arg->time_scene_client_set_state.set_state, (void *)&cb.status_cb);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_mesh_time_scene_client_callback(&time_scene_client_cb,
|
||||
ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT);
|
||||
btc_ble_mesh_time_scene_client_callback(&cb, ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -359,9 +362,10 @@ void btc_mesh_time_scene_client_call_handler(btc_msg_t *msg)
|
||||
}
|
||||
|
||||
btc_ble_mesh_time_scene_client_arg_deep_free(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_mesh_time_scene_client_cb_handler(btc_msg_t *msg)
|
||||
void btc_ble_mesh_time_scene_client_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_time_scene_client_cb_param_t *param = NULL;
|
||||
|
||||
@ -373,11 +377,113 @@ void btc_mesh_time_scene_client_cb_handler(btc_msg_t *msg)
|
||||
param = (esp_ble_mesh_time_scene_client_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_TIME_SCENE_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_cb_to_app(msg->act, param);
|
||||
btc_ble_mesh_time_scene_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_free_req_data(msg);
|
||||
btc_ble_mesh_time_scene_client_free_req_data(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Time and Scenes Server Models related functions */
|
||||
|
||||
static inline void btc_ble_mesh_time_scene_server_cb_to_app(
|
||||
esp_ble_mesh_time_scene_server_cb_event_t event,
|
||||
esp_ble_mesh_time_scene_server_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_time_scene_server_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_time_scene_server_cb_t)btc_profile_cb_get(BTC_PID_TIME_SCENE_SERVER);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_time_scene_server_callback(esp_ble_mesh_time_scene_server_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_TIME_SCENE_SERVER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_TIME_SCENE_SERVER;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(
|
||||
&msg, cb_params, sizeof(esp_ble_mesh_time_scene_server_cb_param_t), NULL);
|
||||
}
|
||||
|
||||
void bt_mesh_time_scene_server_cb_evt_to_btc(u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_time_scene_server_cb_param_t cb_params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
|
||||
if (model == NULL || ctx == NULL) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (evt_type) {
|
||||
case BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_STATE_CHANGE:
|
||||
act = ESP_BLE_MESH_TIME_SCENE_SERVER_STATE_CHANGE_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_RECV_GET_MSG:
|
||||
act = ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_GET_MSG_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_RECV_SET_MSG:
|
||||
act = ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_SET_MSG_EVT;
|
||||
break;
|
||||
case BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_RECV_STATUS_MSG:
|
||||
act = ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_STATUS_MSG_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown Time Scene Server event type", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
cb_params.model = (esp_ble_mesh_model_t *)model;
|
||||
cb_params.ctx.net_idx = ctx->net_idx;
|
||||
cb_params.ctx.app_idx = ctx->app_idx;
|
||||
cb_params.ctx.addr = ctx->addr;
|
||||
cb_params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
cb_params.ctx.recv_op = ctx->recv_op;
|
||||
cb_params.ctx.recv_dst = ctx->recv_dst;
|
||||
|
||||
if (val && len) {
|
||||
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
|
||||
memcpy(&cb_params.value, val, length);
|
||||
}
|
||||
|
||||
btc_ble_mesh_time_scene_server_callback(&cb_params, act);
|
||||
return;
|
||||
}
|
||||
|
||||
void btc_ble_mesh_time_scene_server_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_time_scene_server_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_time_scene_server_cb_param_t *)(msg->arg);
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_TIME_SCENE_SERVER_EVT_MAX) {
|
||||
btc_ble_mesh_time_scene_server_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -22,42 +22,53 @@
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE,
|
||||
} btc_ble_mesh_cfg_client_act_t;
|
||||
BTC_BLE_MESH_ACT_CONFIG_CLIENT_MAX,
|
||||
} btc_ble_mesh_config_client_act_t;
|
||||
|
||||
typedef union {
|
||||
struct ble_mesh_clg_client_get_state_reg_args {
|
||||
struct ble_mesh_cfg_client_get_state_reg_args {
|
||||
esp_ble_mesh_client_common_param_t *params;
|
||||
esp_ble_mesh_cfg_client_get_state_t *get_state;
|
||||
} cfg_client_get_state;
|
||||
struct ble_mesh_clg_client_set_state_reg_args {
|
||||
struct ble_mesh_cfg_client_set_state_reg_args {
|
||||
esp_ble_mesh_client_common_param_t *params;
|
||||
esp_ble_mesh_cfg_client_set_state_t *set_state;
|
||||
} cfg_client_set_state;
|
||||
} btc_ble_mesh_cfg_client_args_t;
|
||||
} btc_ble_mesh_config_client_args_t;
|
||||
|
||||
void btc_mesh_cfg_client_call_handler(btc_msg_t *msg);
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_CONFIG_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_EVT_CONFIG_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_EVT_CONFIG_CLIENT_PUBLISH,
|
||||
BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT,
|
||||
BTC_BLE_MESH_EVT_CONFIG_CLIENT_MAX,
|
||||
} btc_ble_mesh_config_client_evt_t;
|
||||
|
||||
void btc_mesh_cfg_client_cb_handler(btc_msg_t *msg);
|
||||
void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_cfg_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
void btc_ble_mesh_config_client_cb_handler(btc_msg_t *msg);
|
||||
|
||||
int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *params, esp_ble_mesh_cfg_client_get_state_t *get_state,
|
||||
esp_ble_mesh_cfg_client_cb_param_t *cfg_client_cb);
|
||||
void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_t *params, esp_ble_mesh_cfg_client_set_state_t *set_state,
|
||||
esp_ble_mesh_cfg_client_cb_param_t *cfg_client_cb);
|
||||
void btc_ble_mesh_config_client_publish_callback(u32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf);
|
||||
|
||||
void btc_mesh_cfg_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf);
|
||||
|
||||
void bt_mesh_callback_config_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len);
|
||||
|
||||
void btc_mesh_cfg_server_cb_handler(btc_msg_t *msg);
|
||||
void btc_ble_mesh_config_server_cb_handler(btc_msg_t *msg);
|
||||
|
||||
void bt_mesh_callback_cfg_server_event_to_btc(u8_t evt_type, struct bt_mesh_model *model,
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
|
||||
BTC_BLE_MESH_EVT_CONFIG_SERVER_MAX,
|
||||
} btc_ble_mesh_config_server_evt_t;
|
||||
|
||||
void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len);
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_ACT_GENERIC_CLIENT_MAX,
|
||||
} btc_ble_mesh_generic_client_act_t;
|
||||
|
||||
typedef union {
|
||||
@ -35,18 +36,42 @@ typedef union {
|
||||
} generic_client_set_state;
|
||||
} btc_ble_mesh_generic_client_args_t;
|
||||
|
||||
void btc_mesh_generic_client_call_handler(btc_msg_t *msg);
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_GENERIC_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_EVT_GENERIC_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_EVT_GENERIC_CLIENT_PUBLISH,
|
||||
BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT,
|
||||
BTC_BLE_MESH_EVT_GENERIC_CLIENT_MAX,
|
||||
} btc_ble_mesh_generic_client_evt_t;
|
||||
|
||||
void btc_mesh_generic_client_cb_handler(btc_msg_t *msg);
|
||||
void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_generic_client_cb_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
void btc_mesh_generic_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf);
|
||||
void btc_ble_mesh_generic_client_publish_callback(u32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf);
|
||||
|
||||
void bt_mesh_callback_generic_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
void bt_mesh_generic_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len);
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_GENERIC_SERVER_STATE_CHANGE,
|
||||
BTC_BLE_MESH_EVT_GENERIC_SERVER_RECV_GET_MSG,
|
||||
BTC_BLE_MESH_EVT_GENERIC_SERVER_RECV_SET_MSG,
|
||||
BTC_BLE_MESH_EVT_GENERIC_SERVER_MAX,
|
||||
} btc_ble_mesh_generic_server_evt_t;
|
||||
|
||||
void bt_mesh_generic_server_cb_evt_to_btc(u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len);
|
||||
|
||||
void btc_ble_mesh_generic_server_cb_handler(btc_msg_t *msg);
|
||||
|
||||
#endif /* _BTC_BLE_MESH_GENERIC_MODEL_H_ */
|
||||
|
@ -25,11 +25,6 @@ typedef enum {
|
||||
BTC_BLE_MESH_ACT_HEALTH_CLIENT_MAX,
|
||||
} btc_ble_mesh_health_client_act_t;
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE,
|
||||
BTC_BLE_MESH_ACT_HEALTH_SERVER_MAX,
|
||||
} btc_ble_mesh_health_server_act_t;
|
||||
|
||||
typedef union {
|
||||
struct ble_mesh_health_client_get_state_reg_args {
|
||||
esp_ble_mesh_client_common_param_t *params;
|
||||
@ -41,38 +36,53 @@ typedef union {
|
||||
} health_client_set_state;
|
||||
} btc_ble_mesh_health_client_args_t;
|
||||
|
||||
typedef union {
|
||||
struct ble_mesh_health_server_fault_update_args {
|
||||
esp_ble_mesh_elem_t *element;
|
||||
} fault_update;
|
||||
} btc_ble_mesh_health_server_args_t;
|
||||
|
||||
void btc_mesh_health_client_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_mesh_health_client_cb_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_mesh_health_server_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_mesh_health_server_cb_handler(btc_msg_t *msg);
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_HEALTH_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_EVT_HEALTH_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_EVT_HEALTH_CLIENT_PUBLISH,
|
||||
BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT,
|
||||
BTC_BLE_MESH_EVT_HEALTH_CLIENT_MAX,
|
||||
} btc_ble_mesh_health_client_evt_t;
|
||||
|
||||
void btc_ble_mesh_health_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
void btc_ble_mesh_health_server_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg);
|
||||
|
||||
int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_health_client_get_state_t *get_state,
|
||||
esp_ble_mesh_health_client_cb_param_t *client_cb);
|
||||
void btc_ble_mesh_health_client_cb_handler(btc_msg_t *msg);
|
||||
|
||||
int btc_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_health_client_set_state_t *set_state,
|
||||
esp_ble_mesh_health_client_cb_param_t *client_cb);
|
||||
void btc_ble_mesh_health_publish_callback(u32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf);
|
||||
|
||||
void btc_mesh_health_publish_callback(u32_t opcode, struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf);
|
||||
|
||||
void bt_mesh_callback_health_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, u16_t len);
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_HEALTH_SERVER_FAULT_UPDATE,
|
||||
BTC_BLE_MESH_ACT_HEALTH_SERVER_MAX,
|
||||
} btc_ble_mesh_health_server_act_t;
|
||||
|
||||
typedef union {
|
||||
struct ble_mesh_health_server_fault_update_args {
|
||||
esp_ble_mesh_elem_t *element;
|
||||
} health_fault_update;
|
||||
} btc_ble_mesh_health_server_args_t;
|
||||
|
||||
void btc_ble_mesh_health_server_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_health_server_cb_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_health_server_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
void btc_ble_mesh_health_server_fault_clear(struct bt_mesh_model *model, u16_t company_id);
|
||||
|
||||
void btc_ble_mesh_health_server_fault_test(struct bt_mesh_model *model, u8_t test_id, u16_t company_id);
|
||||
|
||||
void btc_ble_mesh_health_server_attention_on(struct bt_mesh_model *model, u8_t time);
|
||||
|
||||
void btc_ble_mesh_health_server_attention_off(struct bt_mesh_model *model);
|
||||
|
||||
#endif /* _BTC_BLE_MESH_HEALTH_MODEL_H_ */
|
||||
|
@ -20,9 +20,10 @@
|
||||
#include "esp_ble_mesh_lighting_model_api.h"
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_LIGHT_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_ACT_LIGHT_CLIENT_SET_STATE,
|
||||
} btc_ble_mesh_light_client_act_t;
|
||||
BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_ACT_LIGHTING_CLIENT_MAX,
|
||||
} btc_ble_mesh_lighting_client_act_t;
|
||||
|
||||
typedef union {
|
||||
struct ble_mesh_light_client_get_state_reg_args {
|
||||
@ -33,21 +34,46 @@ typedef union {
|
||||
esp_ble_mesh_client_common_param_t *params;
|
||||
esp_ble_mesh_light_client_set_state_t *set_state;
|
||||
} light_client_set_state;
|
||||
} btc_ble_mesh_light_client_args_t;
|
||||
} btc_ble_mesh_lighting_client_args_t;
|
||||
|
||||
void btc_mesh_light_client_call_handler(btc_msg_t *msg);
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_PUBLISH,
|
||||
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_TIMEOUT,
|
||||
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_MAX,
|
||||
} btc_ble_mesh_lighting_client_evt_t;
|
||||
|
||||
void btc_mesh_light_client_cb_handler(btc_msg_t *msg);
|
||||
void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_light_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
void btc_ble_mesh_lighting_client_cb_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_mesh_light_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf);
|
||||
void btc_ble_mesh_lighting_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
void bt_mesh_callback_light_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
void btc_ble_mesh_lighting_client_publish_callback(u32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf);
|
||||
|
||||
void bt_mesh_lighting_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len);
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE,
|
||||
BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_GET_MSG,
|
||||
BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_SET_MSG,
|
||||
BTC_BLE_MESH_EVT_LIGHTING_SERVER_RECV_STATUS_MSG,
|
||||
BTC_BLE_MESH_EVT_LIGHTING_SERVER_MAX,
|
||||
} btc_ble_mesh_lighting_server_evt_t;
|
||||
|
||||
void bt_mesh_lighting_server_cb_evt_to_btc(u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len);
|
||||
|
||||
void btc_ble_mesh_lighting_server_cb_handler(btc_msg_t *msg);
|
||||
|
||||
#endif /* _BTC_BLE_MESH_LIGHTING_MODEL_H_ */
|
||||
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "esp_bt_defs.h"
|
||||
|
||||
#include "mesh_access.h"
|
||||
#include "mesh_buf.h"
|
||||
@ -56,12 +55,21 @@ typedef enum {
|
||||
BTC_BLE_MESH_ACT_PROVISIONER_ADD_LOCAL_NET_KEY,
|
||||
BTC_BLE_MESH_ACT_SET_FAST_PROV_INFO,
|
||||
BTC_BLE_MESH_ACT_SET_FAST_PROV_ACTION,
|
||||
BTC_BLE_MESH_ACT_LPN_ENABLE,
|
||||
BTC_BLE_MESH_ACT_LPN_DISABLE,
|
||||
BTC_BLE_MESH_ACT_LPN_POLL,
|
||||
BTC_BLE_MESH_ACT_PROXY_CLIENT_CONNECT,
|
||||
BTC_BLE_MESH_ACT_PROXY_CLIENT_DISCONNECT,
|
||||
BTC_BLE_MESH_ACT_PROXY_CLIENT_SET_FILTER_TYPE,
|
||||
BTC_BLE_MESH_ACT_PROXY_CLIENT_ADD_FILTER_ADDR,
|
||||
BTC_BLE_MESH_ACT_PROXY_CLIENT_REMOVE_FILTER_ADDR,
|
||||
} btc_ble_mesh_prov_act_t;
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_MODEL_PUBLISH,
|
||||
BTC_BLE_MESH_ACT_SERVER_MODEL_SEND,
|
||||
BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND
|
||||
BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND,
|
||||
BTC_BLE_MESH_ACT_SERVER_MODEL_UPDATE_STATE,
|
||||
} btc_ble_mesh_model_act_t;
|
||||
|
||||
typedef union {
|
||||
@ -157,6 +165,40 @@ typedef union {
|
||||
struct ble_mesh_set_fast_prov_action_args {
|
||||
uint8_t action;
|
||||
} set_fast_prov_action;
|
||||
struct ble_mesh_lpn_enable_args {
|
||||
/* RFU */
|
||||
} lpn_enable;
|
||||
struct ble_mesh_lpn_disable_args {
|
||||
bool force;
|
||||
} lpn_disable;
|
||||
struct ble_mesh_lpn_poll_args {
|
||||
/* RFU */
|
||||
} lpn_poll;
|
||||
struct ble_mesh_proxy_client_connect_args {
|
||||
uint8_t addr[6];
|
||||
uint8_t addr_type;
|
||||
uint16_t net_idx;
|
||||
} proxy_client_connect;
|
||||
struct ble_mesh_proxy_client_disconnect_args {
|
||||
uint8_t conn_handle;
|
||||
} proxy_client_disconnect;
|
||||
struct ble_mesh_proxy_client_set_filter_type_args {
|
||||
uint8_t conn_handle;
|
||||
uint16_t net_idx;
|
||||
uint8_t filter_type;
|
||||
} proxy_client_set_filter_type;
|
||||
struct ble_mesh_proxy_client_add_filter_addr_args {
|
||||
uint8_t conn_handle;
|
||||
uint16_t net_idx;
|
||||
uint16_t addr_num;
|
||||
uint16_t *addr;
|
||||
} proxy_client_add_filter_addr;
|
||||
struct ble_mesh_proxy_client_remove_filter_addr_args {
|
||||
uint8_t conn_handle;
|
||||
uint16_t net_idx;
|
||||
uint16_t addr_num;
|
||||
uint16_t *addr;
|
||||
} proxy_client_remove_filter_addr;
|
||||
} btc_ble_mesh_prov_args_t;
|
||||
|
||||
typedef union {
|
||||
@ -174,13 +216,18 @@ typedef union {
|
||||
uint8_t device_role;
|
||||
int32_t msg_timeout;
|
||||
} model_send;
|
||||
struct ble_mesh_server_model_update_state_args {
|
||||
esp_ble_mesh_model_t *model;
|
||||
esp_ble_mesh_server_state_type_t type;
|
||||
esp_ble_mesh_server_state_value_t *value;
|
||||
} model_update_state;
|
||||
} btc_ble_mesh_model_args_t;
|
||||
|
||||
void btc_ble_mesh_prov_arg_deep_free(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_prov_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
int btc_ble_mesh_client_init(esp_ble_mesh_model_t *model);
|
||||
void btc_ble_mesh_model_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
int btc_ble_mesh_client_model_init(esp_ble_mesh_model_t *model);
|
||||
|
||||
int32_t btc_ble_mesh_model_pub_period_get(esp_ble_mesh_model_t *mod);
|
||||
|
||||
@ -200,11 +247,10 @@ esp_ble_mesh_model_t *btc_ble_mesh_model_find(const esp_ble_mesh_elem_t *elem,
|
||||
|
||||
const esp_ble_mesh_comp_t *btc_ble_mesh_comp_get(void);
|
||||
|
||||
void btc_mesh_model_call_handler(btc_msg_t *msg);
|
||||
void btc_mesh_model_cb_handler(btc_msg_t *msg);
|
||||
void btc_ble_mesh_model_call_handler(btc_msg_t *msg);
|
||||
void btc_ble_mesh_model_cb_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_mesh_prov_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_mesh_prov_cb_handler(btc_msg_t *msg);
|
||||
void btc_ble_mesh_prov_call_handler(btc_msg_t *msg);
|
||||
void btc_ble_mesh_prov_cb_handler(btc_msg_t *msg);
|
||||
|
||||
#endif /* _BTC_BLE_MESH_PROV_H_ */
|
||||
|
@ -22,6 +22,7 @@
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_ACT_SENSOR_CLIENT_MAX,
|
||||
} btc_ble_mesh_sensor_client_act_t;
|
||||
|
||||
typedef union {
|
||||
@ -35,19 +36,43 @@ typedef union {
|
||||
} sensor_client_set_state;
|
||||
} btc_ble_mesh_sensor_client_args_t;
|
||||
|
||||
void btc_mesh_sensor_client_call_handler(btc_msg_t *msg);
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_SENSOR_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_EVT_SENSOR_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_EVT_SENSOR_CLIENT_PUBLISH,
|
||||
BTC_BLE_MESH_EVT_SENSOR_CLIENT_TIMEOUT,
|
||||
BTC_BLE_MESH_EVT_SENSOR_CLIENT_MAX,
|
||||
} btc_ble_mesh_sensor_client_evt_t;
|
||||
|
||||
void btc_mesh_sensor_client_cb_handler(btc_msg_t *msg);
|
||||
void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_sensor_client_cb_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
void btc_mesh_sensor_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf);
|
||||
void btc_ble_mesh_sensor_client_publish_callback(u32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf);
|
||||
|
||||
void bt_mesh_callback_sensor_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
void bt_mesh_sensor_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len);
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_SENSOR_SERVER_STATE_CHANGE,
|
||||
BTC_BLE_MESH_EVT_SENSOR_SERVER_RECV_GET_MSG,
|
||||
BTC_BLE_MESH_EVT_SENSOR_SERVER_RECV_SET_MSG,
|
||||
BTC_BLE_MESH_EVT_SENSOR_SERVER_MAX,
|
||||
} btc_ble_mesh_sensor_server_evt_t;
|
||||
|
||||
void bt_mesh_sensor_server_cb_evt_to_btc(u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len);
|
||||
|
||||
void btc_ble_mesh_sensor_server_cb_handler(btc_msg_t *msg);
|
||||
|
||||
#endif /* _BTC_BLE_MESH_SENSOR_MODEL_H_ */
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_MAX,
|
||||
} btc_ble_mesh_time_scene_client_act_t;
|
||||
|
||||
typedef union {
|
||||
@ -35,19 +36,44 @@ typedef union {
|
||||
} time_scene_client_set_state;
|
||||
} btc_ble_mesh_time_scene_client_args_t;
|
||||
|
||||
void btc_mesh_time_scene_client_call_handler(btc_msg_t *msg);
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_GET_STATE,
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_SET_STATE,
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_PUBLISH,
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_TIMEOUT,
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_MAX,
|
||||
} btc_ble_mesh_time_scene_client_evt_t;
|
||||
|
||||
void btc_mesh_time_scene_client_cb_handler(btc_msg_t *msg);
|
||||
void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_time_scene_client_cb_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_time_scene_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
|
||||
|
||||
void btc_mesh_time_scene_client_publish_callback(u32_t opcode, struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf);
|
||||
void btc_ble_mesh_time_scene_client_publish_callback(u32_t opcode,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
struct net_buf_simple *buf);
|
||||
|
||||
void bt_mesh_callback_time_scene_status_to_btc(u32_t opcode, u8_t evt_type,
|
||||
void bt_mesh_time_scene_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len);
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_STATE_CHANGE,
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_RECV_GET_MSG,
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_RECV_SET_MSG,
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_RECV_STATUS_MSG,
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_MAX,
|
||||
} btc_ble_mesh_time_scene_server_evt_t;
|
||||
|
||||
void bt_mesh_time_scene_server_cb_evt_to_btc(u8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const u8_t *val, size_t len);
|
||||
|
||||
void btc_ble_mesh_time_scene_server_cb_handler(btc_msg_t *msg);
|
||||
|
||||
#endif /* _BTC_BLE_MESH_TIME_SCENE_MODEL_H_ */
|
||||
|
||||
|
@ -544,8 +544,8 @@ struct net_buf {
|
||||
};
|
||||
|
||||
struct net_buf_data_cb {
|
||||
u8_t * (*alloc)(struct net_buf *buf, size_t *size, s32_t timeout);
|
||||
u8_t * (*ref)(struct net_buf *buf, u8_t *data);
|
||||
u8_t *(*alloc)(struct net_buf *buf, size_t *size, s32_t timeout);
|
||||
u8_t *(*ref)(struct net_buf *buf, u8_t *data);
|
||||
void (*unref)(struct net_buf *buf, u8_t *data);
|
||||
};
|
||||
|
||||
@ -709,7 +709,7 @@ int net_buf_id(struct net_buf *buf);
|
||||
*/
|
||||
#if defined(CONFIG_BLE_MESH_NET_BUF_LOG)
|
||||
struct net_buf *net_buf_alloc_fixed_debug(struct net_buf_pool *pool, s32_t timeout,
|
||||
const char *func, int line);
|
||||
const char *func, int line);
|
||||
#define net_buf_alloc_fixed(_pool, _timeout) \
|
||||
net_buf_alloc_fixed_debug(_pool, _timeout, __func__, __LINE__)
|
||||
#else
|
@ -24,6 +24,7 @@
|
||||
#include "mesh_types.h"
|
||||
#include "mesh_buf.h"
|
||||
#include "mesh_trace.h"
|
||||
#include "mesh_access.h"
|
||||
|
||||
/**
|
||||
* @brief This function allocates memory to store outgoing message.
|
||||
@ -43,4 +44,18 @@ struct net_buf_simple *bt_mesh_alloc_buf(u16_t size);
|
||||
*/
|
||||
void bt_mesh_free_buf(struct net_buf_simple *buf);
|
||||
|
||||
/**
|
||||
* @brief This function gets device role for stack internal use.
|
||||
*
|
||||
* @Note Currently Provisioner only support client models, Node supports
|
||||
* client models and server models. Hence if srv_send is set to be
|
||||
* TRUE, then role NODE will be returned.
|
||||
*
|
||||
* @param[in] model: Pointer to the model structure
|
||||
* @param[in] srv_send: Indicate if the message is sent by a server model
|
||||
*
|
||||
* @return 0 - Node, 1 - Provisioner
|
||||
*/
|
||||
u8_t bt_mesh_get_device_role(struct bt_mesh_model *model, bool srv_send);
|
||||
|
||||
#endif /* _MESH_COMMON_H_ */
|
@ -182,6 +182,8 @@ struct k_delayed_work {
|
||||
*/
|
||||
int k_delayed_work_submit(struct k_delayed_work *work, s32_t delay);
|
||||
|
||||
int k_delayed_work_submit_periodic(struct k_delayed_work *work, s32_t period);
|
||||
|
||||
/**
|
||||
* @brief Get time remaining before a delayed work gets scheduled.
|
||||
*
|
||||
@ -266,8 +268,14 @@ s64_t k_uptime_get(void);
|
||||
*/
|
||||
void k_sleep(s32_t duration);
|
||||
|
||||
unsigned int bt_mesh_irq_lock(void);
|
||||
void bt_mesh_irq_unlock(unsigned int key);
|
||||
void bt_mesh_list_lock(void);
|
||||
void bt_mesh_list_unlock(void);
|
||||
|
||||
void bt_mesh_buf_lock(void);
|
||||
void bt_mesh_buf_unlock(void);
|
||||
|
||||
void bt_mesh_atomic_lock(void);
|
||||
void bt_mesh_atomic_unlock(void);
|
||||
|
||||
void bt_mesh_k_init(void);
|
||||
|
@ -47,6 +47,12 @@
|
||||
|
||||
#define MESH_TRACE_TAG "BLE_MESH"
|
||||
|
||||
#define LOG_ERROR(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_ERROR) esp_log_write(ESP_LOG_ERROR, "BT_LOG", LOG_FORMAT(E, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); }
|
||||
#define LOG_WARN(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_WARN) esp_log_write(ESP_LOG_WARN, "BT_LOG", LOG_FORMAT(W, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); }
|
||||
#define LOG_INFO(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_INFO) esp_log_write(ESP_LOG_INFO, "BT_LOG", LOG_FORMAT(I, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); }
|
||||
#define LOG_DEBUG(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_DEBUG) esp_log_write(ESP_LOG_DEBUG, "BT_LOG", LOG_FORMAT(D, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); }
|
||||
#define LOG_VERBOSE(format, ... ) {if (LOG_LOCAL_LEVEL >= ESP_LOG_VERBOSE) esp_log_write(ESP_LOG_VERBOSE, "BT_LOG", LOG_FORMAT(V, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__); }
|
||||
|
||||
#if (LOG_LOCAL_LEVEL >= 4)
|
||||
#define BLE_MESH_LOG_LOCAL_LEVEL_MAPPING (LOG_LOCAL_LEVEL + 1)
|
||||
#else
|
@ -55,15 +55,14 @@ bt_mesh_atomic_val_t bt_mesh_atomic_get(const bt_mesh_atomic_t *target)
|
||||
*/
|
||||
bt_mesh_atomic_val_t bt_mesh_atomic_set(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value)
|
||||
{
|
||||
unsigned int key;
|
||||
bt_mesh_atomic_val_t ret;
|
||||
|
||||
key = bt_mesh_irq_lock();
|
||||
bt_mesh_atomic_lock();
|
||||
|
||||
ret = *target;
|
||||
*target = value;
|
||||
|
||||
bt_mesh_irq_unlock(key);
|
||||
bt_mesh_atomic_unlock();
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -83,15 +82,14 @@ bt_mesh_atomic_val_t bt_mesh_atomic_set(bt_mesh_atomic_t *target, bt_mesh_atomic
|
||||
*/
|
||||
bt_mesh_atomic_val_t bt_mesh_atomic_or(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value)
|
||||
{
|
||||
unsigned int key;
|
||||
bt_mesh_atomic_val_t ret;
|
||||
|
||||
key = bt_mesh_irq_lock();
|
||||
bt_mesh_atomic_lock();
|
||||
|
||||
ret = *target;
|
||||
*target |= value;
|
||||
|
||||
bt_mesh_irq_unlock(key);
|
||||
bt_mesh_atomic_unlock();
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -111,15 +109,14 @@ bt_mesh_atomic_val_t bt_mesh_atomic_or(bt_mesh_atomic_t *target, bt_mesh_atomic_
|
||||
*/
|
||||
bt_mesh_atomic_val_t bt_mesh_atomic_and(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value)
|
||||
{
|
||||
unsigned int key;
|
||||
bt_mesh_atomic_val_t ret;
|
||||
|
||||
key = bt_mesh_irq_lock();
|
||||
bt_mesh_atomic_lock();
|
||||
|
||||
ret = *target;
|
||||
*target &= value;
|
||||
|
||||
bt_mesh_irq_unlock(key);
|
||||
bt_mesh_atomic_unlock();
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -137,15 +134,14 @@ bt_mesh_atomic_val_t bt_mesh_atomic_and(bt_mesh_atomic_t *target, bt_mesh_atomic
|
||||
*/
|
||||
bt_mesh_atomic_val_t bt_mesh_atomic_dec(bt_mesh_atomic_t *target)
|
||||
{
|
||||
unsigned int key;
|
||||
bt_mesh_atomic_val_t ret;
|
||||
|
||||
key = bt_mesh_irq_lock();
|
||||
bt_mesh_atomic_lock();
|
||||
|
||||
ret = *target;
|
||||
(*target)--;
|
||||
|
||||
bt_mesh_irq_unlock(key);
|
||||
bt_mesh_atomic_unlock();
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -163,15 +159,14 @@ bt_mesh_atomic_val_t bt_mesh_atomic_dec(bt_mesh_atomic_t *target)
|
||||
*/
|
||||
bt_mesh_atomic_val_t bt_mesh_atomic_inc(bt_mesh_atomic_t *target)
|
||||
{
|
||||
unsigned int key;
|
||||
bt_mesh_atomic_val_t ret;
|
||||
|
||||
key = bt_mesh_irq_lock();
|
||||
bt_mesh_atomic_lock();
|
||||
|
||||
ret = *target;
|
||||
(*target)++;
|
||||
|
||||
bt_mesh_irq_unlock(key);
|
||||
bt_mesh_atomic_unlock();
|
||||
|
||||
return ret;
|
||||
}
|
@ -233,7 +233,6 @@ void net_buf_simple_reserve(struct net_buf_simple *buf, size_t reserve)
|
||||
void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf)
|
||||
{
|
||||
struct net_buf *tail;
|
||||
unsigned int key;
|
||||
|
||||
NET_BUF_ASSERT(list);
|
||||
NET_BUF_ASSERT(buf);
|
||||
@ -242,21 +241,20 @@ void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf)
|
||||
tail->flags |= NET_BUF_FRAGS;
|
||||
}
|
||||
|
||||
key = bt_mesh_irq_lock();
|
||||
bt_mesh_list_lock();
|
||||
sys_slist_append_list(list, &buf->node, &tail->node);
|
||||
bt_mesh_irq_unlock(key);
|
||||
bt_mesh_list_unlock();
|
||||
}
|
||||
|
||||
struct net_buf *net_buf_slist_get(sys_slist_t *list)
|
||||
{
|
||||
struct net_buf *buf, *frag;
|
||||
unsigned int key;
|
||||
|
||||
NET_BUF_ASSERT(list);
|
||||
|
||||
key = bt_mesh_irq_lock();
|
||||
bt_mesh_list_lock();
|
||||
buf = (void *)sys_slist_get(list);
|
||||
bt_mesh_irq_unlock(key);
|
||||
bt_mesh_list_unlock();
|
||||
|
||||
if (!buf) {
|
||||
return NULL;
|
||||
@ -264,9 +262,9 @@ struct net_buf *net_buf_slist_get(sys_slist_t *list)
|
||||
|
||||
/* Get any fragments belonging to this buffer */
|
||||
for (frag = buf; (frag->flags & NET_BUF_FRAGS); frag = frag->frags) {
|
||||
key = bt_mesh_irq_lock();
|
||||
bt_mesh_list_lock();
|
||||
frag->frags = (void *)sys_slist_get(list);
|
||||
bt_mesh_irq_unlock(key);
|
||||
bt_mesh_list_unlock();
|
||||
|
||||
NET_BUF_ASSERT(frag->frags);
|
||||
|
||||
@ -310,7 +308,7 @@ void net_buf_unref(struct net_buf *buf)
|
||||
}
|
||||
#endif
|
||||
NET_BUF_DBG("buf %p ref %u pool %p frags %p", buf, buf->ref,
|
||||
buf->pool, buf->frags);
|
||||
buf->pool, buf->frags);
|
||||
|
||||
/* Changed by Espressif. Add !buf->ref to avoid minus 0 */
|
||||
if (!buf->ref || --buf->ref > 0) {
|
||||
@ -325,7 +323,7 @@ void net_buf_unref(struct net_buf *buf)
|
||||
#if defined(CONFIG_BLE_MESH_NET_BUF_POOL_USAGE)
|
||||
pool->avail_count++;
|
||||
NET_BUF_DBG("%s, pool %p, avail_count %d, uninit_count %d", __func__,
|
||||
pool, pool->avail_count, pool->uninit_count);
|
||||
pool, pool->avail_count, pool->uninit_count);
|
||||
NET_BUF_ASSERT(pool->avail_count <= pool->buf_count);
|
||||
#endif
|
||||
|
||||
@ -366,25 +364,24 @@ static u8_t *data_alloc(struct net_buf *buf, size_t *size, s32_t timeout)
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_NET_BUF_LOG)
|
||||
struct net_buf *net_buf_alloc_len_debug(struct net_buf_pool *pool, size_t size,
|
||||
s32_t timeout, const char *func, int line)
|
||||
s32_t timeout, const char *func, int line)
|
||||
#else
|
||||
struct net_buf *net_buf_alloc_len(struct net_buf_pool *pool, size_t size,
|
||||
s32_t timeout)
|
||||
s32_t timeout)
|
||||
#endif
|
||||
{
|
||||
struct net_buf *buf = NULL;
|
||||
unsigned int key;
|
||||
int i;
|
||||
|
||||
NET_BUF_ASSERT(pool);
|
||||
|
||||
NET_BUF_DBG("%s, pool %p, uninit_count %d, buf_count %d", __func__,
|
||||
pool, pool->uninit_count, pool->buf_count);
|
||||
pool, pool->uninit_count, pool->buf_count);
|
||||
|
||||
/* We need to lock interrupts temporarily to prevent race conditions
|
||||
* when accessing pool->uninit_count.
|
||||
*/
|
||||
key = bt_mesh_irq_lock();
|
||||
bt_mesh_buf_lock();
|
||||
|
||||
/* If there are uninitialized buffers we're guaranteed to succeed
|
||||
* with the allocation one way or another.
|
||||
@ -394,13 +391,13 @@ struct net_buf *net_buf_alloc_len(struct net_buf_pool *pool, size_t size,
|
||||
for (i = pool->buf_count; i > 0; i--) {
|
||||
buf = pool_get_uninit(pool, i);
|
||||
if (!buf->ref) {
|
||||
bt_mesh_irq_unlock(key);
|
||||
bt_mesh_buf_unlock();
|
||||
goto success;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bt_mesh_irq_unlock(key);
|
||||
bt_mesh_buf_unlock();
|
||||
|
||||
NET_BUF_ERR("%s, Failed to get free buffer", __func__);
|
||||
return NULL;
|
||||
@ -436,8 +433,8 @@ success:
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_NET_BUF_LOG)
|
||||
struct net_buf *net_buf_alloc_fixed_debug(struct net_buf_pool *pool,
|
||||
s32_t timeout, const char *func,
|
||||
int line)
|
||||
s32_t timeout, const char *func,
|
||||
int line)
|
||||
{
|
||||
const struct net_buf_pool_fixed *fixed = pool->alloc->alloc_data;
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "client_common.h"
|
||||
#include "mesh_common.h"
|
||||
|
||||
struct net_buf_simple *bt_mesh_alloc_buf(u16_t size)
|
||||
@ -44,3 +45,22 @@ void bt_mesh_free_buf(struct net_buf_simple *buf)
|
||||
osi_free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
u8_t bt_mesh_get_device_role(struct bt_mesh_model *model, bool srv_send)
|
||||
{
|
||||
bt_mesh_client_user_data_t *client = NULL;
|
||||
|
||||
if (srv_send) {
|
||||
BT_DBG("%s, Message is sent by a server model", __func__);
|
||||
return NODE;
|
||||
}
|
||||
|
||||
if (!model || !model->user_data) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return ROLE_NVAL;
|
||||
}
|
||||
|
||||
client = (bt_mesh_client_user_data_t *)model->user_data;
|
||||
|
||||
return client->msg_role;
|
||||
}
|
@ -14,8 +14,7 @@
|
||||
#include "osi/alarm.h"
|
||||
#include "osi/hash_functions.h"
|
||||
|
||||
#include "common/bt_trace.h"
|
||||
#include "common/bt_defs.h"
|
||||
#include "bt_common.h"
|
||||
|
||||
#include "esp_timer.h"
|
||||
|
||||
@ -25,7 +24,9 @@
|
||||
#include "provisioner_prov.h"
|
||||
|
||||
static osi_mutex_t bm_alarm_lock;
|
||||
static osi_mutex_t bm_irq_lock;
|
||||
static osi_mutex_t bm_list_lock;
|
||||
static osi_mutex_t bm_buf_lock;
|
||||
static osi_mutex_t bm_atomic_lock;
|
||||
static hash_map_t *bm_alarm_hash_map;
|
||||
static const size_t BLE_MESH_GENERAL_ALARM_HASH_MAP_SIZE = 20 + CONFIG_BLE_MESH_PBA_SAME_TIME + \
|
||||
CONFIG_BLE_MESH_PBG_SAME_TIME;
|
||||
@ -38,35 +39,34 @@ typedef struct alarm_t {
|
||||
int64_t deadline_us;
|
||||
} osi_alarm_t;
|
||||
|
||||
static void bt_mesh_alarm_cb(void *data)
|
||||
void bt_mesh_list_lock(void)
|
||||
{
|
||||
assert(data != NULL);
|
||||
struct k_delayed_work *work = (struct k_delayed_work *)data;
|
||||
work->work.handler(&work->work);
|
||||
return;
|
||||
osi_mutex_lock(&bm_list_lock, OSI_MUTEX_MAX_TIMEOUT);
|
||||
}
|
||||
|
||||
unsigned int bt_mesh_irq_lock(void)
|
||||
void bt_mesh_list_unlock(void)
|
||||
{
|
||||
#if defined(CONFIG_BLE_MESH_IRQ_LOCK) && CONFIG_BLE_MESH_IRQ_LOCK
|
||||
unsigned int key = XTOS_SET_INTLEVEL(XCHAL_EXCM_LEVEL);
|
||||
return key;
|
||||
#else
|
||||
/* Change by Espressif. In BLE Mesh, in order to improve the real-time
|
||||
* requirements of bt controller, we use task lock to replace IRQ lock.
|
||||
*/
|
||||
osi_mutex_lock(&bm_irq_lock, OSI_MUTEX_MAX_TIMEOUT);
|
||||
return 0;
|
||||
#endif
|
||||
osi_mutex_unlock(&bm_list_lock);
|
||||
}
|
||||
|
||||
void bt_mesh_irq_unlock(unsigned int key)
|
||||
void bt_mesh_buf_lock(void)
|
||||
{
|
||||
#if defined(CONFIG_BLE_MESH_IRQ_LOCK) && CONFIG_BLE_MESH_IRQ_LOCK
|
||||
XTOS_RESTORE_INTLEVEL(key);
|
||||
#else
|
||||
osi_mutex_unlock(&bm_irq_lock);
|
||||
#endif
|
||||
osi_mutex_lock(&bm_buf_lock, OSI_MUTEX_MAX_TIMEOUT);
|
||||
}
|
||||
|
||||
void bt_mesh_buf_unlock(void)
|
||||
{
|
||||
osi_mutex_unlock(&bm_buf_lock);
|
||||
}
|
||||
|
||||
void bt_mesh_atomic_lock(void)
|
||||
{
|
||||
osi_mutex_lock(&bm_atomic_lock, OSI_MUTEX_MAX_TIMEOUT);
|
||||
}
|
||||
|
||||
void bt_mesh_atomic_unlock(void)
|
||||
{
|
||||
osi_mutex_unlock(&bm_atomic_lock);
|
||||
}
|
||||
|
||||
s64_t k_uptime_get(void)
|
||||
@ -94,7 +94,9 @@ void k_sleep(s32_t duration)
|
||||
void bt_mesh_k_init(void)
|
||||
{
|
||||
osi_mutex_new(&bm_alarm_lock);
|
||||
osi_mutex_new(&bm_irq_lock);
|
||||
osi_mutex_new(&bm_list_lock);
|
||||
osi_mutex_new(&bm_buf_lock);
|
||||
osi_mutex_new(&bm_atomic_lock);
|
||||
bm_alarm_hash_map = hash_map_new(BLE_MESH_GENERAL_ALARM_HASH_MAP_SIZE,
|
||||
hash_function_pointer, NULL,
|
||||
(data_free_fn)osi_alarm_free, NULL);
|
||||
@ -111,9 +113,10 @@ void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler)
|
||||
|
||||
osi_mutex_lock(&bm_alarm_lock, OSI_MUTEX_MAX_TIMEOUT);
|
||||
if (!hash_map_has_key(bm_alarm_hash_map, (void *)work)) {
|
||||
alarm = osi_alarm_new("bt_mesh", bt_mesh_alarm_cb, (void *)work, 0);
|
||||
alarm = osi_alarm_new("bt_mesh", (osi_alarm_callback_t)handler, (void *)&work->work, 0);
|
||||
if (alarm == NULL) {
|
||||
BT_ERR("%s, Unable to create alarm", __func__);
|
||||
osi_mutex_unlock(&bm_alarm_lock);
|
||||
return;
|
||||
}
|
||||
if (!hash_map_set(bm_alarm_hash_map, work, (void *)alarm)) {
|
||||
@ -133,8 +136,7 @@ void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler)
|
||||
return;
|
||||
}
|
||||
|
||||
int k_delayed_work_submit(struct k_delayed_work *work,
|
||||
s32_t delay)
|
||||
int k_delayed_work_submit(struct k_delayed_work *work, s32_t delay)
|
||||
{
|
||||
assert(work != NULL && bm_alarm_hash_map != NULL);
|
||||
|
||||
@ -150,6 +152,23 @@ int k_delayed_work_submit(struct k_delayed_work *work,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int k_delayed_work_submit_periodic(struct k_delayed_work *work, s32_t period)
|
||||
{
|
||||
assert(work != NULL && bm_alarm_hash_map != NULL);
|
||||
|
||||
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
|
||||
if (alarm == NULL) {
|
||||
BT_WARN("%s, Unable to find expected alarm in hash map", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Cancel the alarm first before starting it. */
|
||||
osi_alarm_cancel(alarm);
|
||||
osi_alarm_set_periodic(alarm, period);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int k_delayed_work_cancel(struct k_delayed_work *work)
|
||||
{
|
||||
assert(work != NULL && bm_alarm_hash_map != NULL);
|
||||
@ -175,6 +194,7 @@ int k_delayed_work_free(struct k_delayed_work *work)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
osi_alarm_cancel(alarm);
|
||||
hash_map_erase(bm_alarm_hash_map, work);
|
||||
return 0;
|
||||
}
|
||||
@ -189,17 +209,5 @@ s32_t k_delayed_work_remaining_get(struct k_delayed_work *work)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!alarm->deadline_us) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32_t remain_time = 0;
|
||||
int64_t now = esp_timer_get_time();
|
||||
if ((alarm->deadline_us - now) < 0x1FFFFFFFFFF) {
|
||||
remain_time = (alarm->deadline_us - now) / 1000;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return remain_time;
|
||||
return osi_alarm_get_remaining_ms(alarm);
|
||||
}
|
@ -17,19 +17,11 @@
|
||||
const char *bt_hex(const void *buf, size_t len)
|
||||
{
|
||||
static const char hex[] = "0123456789abcdef";
|
||||
static char hexbufs[4][129];
|
||||
static u8_t curbuf;
|
||||
static char str[129];
|
||||
const u8_t *b = buf;
|
||||
unsigned int mask;
|
||||
char *str;
|
||||
int i;
|
||||
|
||||
mask = bt_mesh_irq_lock();
|
||||
str = hexbufs[curbuf++];
|
||||
curbuf %= ARRAY_SIZE(hexbufs);
|
||||
bt_mesh_irq_unlock(mask);
|
||||
|
||||
len = MIN(len, (sizeof(hexbufs[0]) - 1) / 2);
|
||||
len = MIN(len, (sizeof(str) - 1) / 2);
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
str[i * 2] = hex[b[i] >> 4];
|
@ -27,13 +27,18 @@
|
||||
#include "transport.h"
|
||||
#include "access.h"
|
||||
#include "foundation.h"
|
||||
|
||||
#include "mesh_common.h"
|
||||
#include "provisioner_main.h"
|
||||
|
||||
#include "generic_client.h"
|
||||
#include "sensor_client.h"
|
||||
#include "time_scene_client.h"
|
||||
#include "lighting_client.h"
|
||||
#include "provisioner_main.h"
|
||||
|
||||
#include "generic_server.h"
|
||||
#include "sensor_server.h"
|
||||
#include "time_scene_server.h"
|
||||
#include "lighting_server.h"
|
||||
|
||||
#define BLE_MESH_SDU_MAX_LEN 384
|
||||
|
||||
@ -103,6 +108,41 @@ static const struct {
|
||||
#if defined(CONFIG_BLE_MESH_LIGHT_LC_CLI)
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_LC_CLI, bt_mesh_light_lc_cli_init },
|
||||
#endif
|
||||
{ BLE_MESH_MODEL_ID_GEN_ONOFF_SRV, bt_mesh_gen_onoff_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_LEVEL_SRV, bt_mesh_gen_level_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV, bt_mesh_gen_def_trans_time_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV, bt_mesh_gen_power_onoff_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV, bt_mesh_gen_power_onoff_setup_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV, bt_mesh_gen_power_level_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV, bt_mesh_gen_power_level_setup_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_BATTERY_SRV, bt_mesh_gen_battery_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_LOCATION_SRV, bt_mesh_gen_location_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV, bt_mesh_gen_location_setup_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_USER_PROP_SRV, bt_mesh_gen_user_prop_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV, bt_mesh_gen_admin_prop_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV, bt_mesh_gen_manu_prop_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV, bt_mesh_gen_client_prop_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV, bt_mesh_light_lightness_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV, bt_mesh_light_lightness_setup_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_CTL_SRV, bt_mesh_light_ctl_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV, bt_mesh_light_ctl_setup_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV, bt_mesh_light_ctl_temp_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_HSL_SRV, bt_mesh_light_hsl_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV, bt_mesh_light_hsl_hue_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV, bt_mesh_light_hsl_sat_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV, bt_mesh_light_hsl_setup_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_XYL_SRV, bt_mesh_light_xyl_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV, bt_mesh_light_xyl_setup_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_LC_SRV, bt_mesh_light_lc_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV, bt_mesh_light_lc_setup_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_TIME_SRV, bt_mesh_time_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_TIME_SETUP_SRV, bt_mesh_time_setup_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_SCENE_SRV, bt_mesh_scene_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_SCENE_SETUP_SRV, bt_mesh_scene_setup_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_SCHEDULER_SRV, bt_mesh_scheduler_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_SCHEDULER_SETUP_SRV, bt_mesh_scheduler_setup_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_SENSOR_SRV, bt_mesh_sensor_srv_init },
|
||||
{ BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV, bt_mesh_sensor_setup_srv_init },
|
||||
};
|
||||
|
||||
void bt_mesh_model_foreach(void (*func)(struct bt_mesh_model *mod,
|
||||
@ -220,7 +260,24 @@ static void publish_sent(int err, void *user_data)
|
||||
}
|
||||
}
|
||||
|
||||
static void publish_start(u16_t duration, int err, void *user_data)
|
||||
{
|
||||
struct bt_mesh_model *mod = user_data;
|
||||
struct bt_mesh_model_pub *pub = mod->pub;
|
||||
|
||||
if (err) {
|
||||
BT_ERR("Failed to publish: err %d", err);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Initialize the timestamp for the beginning of a new period */
|
||||
if (pub->count == BLE_MESH_PUB_TRANSMIT_COUNT(pub->retransmit)) {
|
||||
pub->period_start = k_uptime_get_32();
|
||||
}
|
||||
}
|
||||
|
||||
static const struct bt_mesh_send_cb pub_sent_cb = {
|
||||
.start = publish_start,
|
||||
.end = publish_sent,
|
||||
};
|
||||
|
||||
@ -310,8 +367,6 @@ static void mod_publish(struct k_work *work)
|
||||
|
||||
__ASSERT_NO_MSG(pub->update != NULL);
|
||||
|
||||
pub->period_start = k_uptime_get_32();
|
||||
|
||||
/* Callback the model publish update event to the application layer.
|
||||
* In the event, users can update the context of the publish message
|
||||
* which will be published in the next period.
|
||||
@ -326,11 +381,6 @@ static void mod_publish(struct k_work *work)
|
||||
if (err) {
|
||||
BT_ERR("%s, Publishing failed (err %d)", __func__, err);
|
||||
}
|
||||
|
||||
if (pub->count) {
|
||||
/* Retransmissions also control the timer */
|
||||
k_delayed_work_cancel(&pub->timer);
|
||||
}
|
||||
}
|
||||
|
||||
struct bt_mesh_elem *bt_mesh_model_elem(struct bt_mesh_model *mod)
|
||||
@ -495,17 +545,21 @@ static struct bt_mesh_model *bt_mesh_elem_find_group(struct bt_mesh_elem *elem,
|
||||
|
||||
struct bt_mesh_elem *bt_mesh_elem_find(u16_t addr)
|
||||
{
|
||||
int i;
|
||||
u16_t index;
|
||||
|
||||
for (i = 0; i < dev_comp->elem_count; i++) {
|
||||
struct bt_mesh_elem *elem = &dev_comp->elem[i];
|
||||
if (BLE_MESH_ADDR_IS_UNICAST(addr)) {
|
||||
index = (addr - dev_comp->elem[0].addr);
|
||||
if (index < dev_comp->elem_count) {
|
||||
return &dev_comp->elem[index];
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (BLE_MESH_ADDR_IS_GROUP(addr) ||
|
||||
BLE_MESH_ADDR_IS_VIRTUAL(addr)) {
|
||||
if (bt_mesh_elem_find_group(elem, addr)) {
|
||||
return elem;
|
||||
}
|
||||
} else if (elem->addr == addr) {
|
||||
for (index = 0; index < dev_comp->elem_count; index++) {
|
||||
struct bt_mesh_elem *elem = &dev_comp->elem[index];
|
||||
|
||||
if (bt_mesh_elem_find_group(elem, addr)) {
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
@ -616,8 +670,6 @@ bool bt_mesh_fixed_group_match(u16_t addr)
|
||||
}
|
||||
}
|
||||
|
||||
u32_t mesh_opcode;
|
||||
|
||||
void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_model *models, *model;
|
||||
@ -637,8 +689,6 @@ void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
|
||||
|
||||
BT_DBG("OpCode 0x%08x", opcode);
|
||||
|
||||
mesh_opcode = opcode;
|
||||
|
||||
for (i = 0; i < dev_comp->elem_count; i++) {
|
||||
struct bt_mesh_elem *elem = &dev_comp->elem[i];
|
||||
|
||||
@ -673,7 +723,7 @@ void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
|
||||
|
||||
if (buf->len < op->min_len) {
|
||||
BT_ERR("%s, Too short message for OpCode 0x%08x",
|
||||
__func__, opcode);
|
||||
__func__, opcode);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -728,67 +778,72 @@ void bt_mesh_model_msg_init(struct net_buf_simple *msg, u32_t opcode)
|
||||
net_buf_simple_add_le16(msg, opcode & 0xffff);
|
||||
}
|
||||
|
||||
static int model_send(struct bt_mesh_model *model,
|
||||
struct bt_mesh_net_tx *tx, bool implicit_bind,
|
||||
struct net_buf_simple *msg,
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data)
|
||||
static bool ready_to_send(u8_t role, u16_t dst)
|
||||
{
|
||||
bool check = false;
|
||||
u8_t role;
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x dst 0x%04x", tx->ctx->net_idx,
|
||||
tx->ctx->app_idx, tx->ctx->addr);
|
||||
BT_DBG("len %u: %s", msg->len, bt_hex(msg->data, msg->len));
|
||||
|
||||
role = bt_mesh_get_model_role(model, tx->ctx->srv_send);
|
||||
if (role == ROLE_NVAL) {
|
||||
BT_ERR("%s, Failed to get model role", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == NODE) {
|
||||
if (!bt_mesh_is_provisioned()) {
|
||||
BT_ERR("%s, Local node is not yet provisioned", __func__);
|
||||
return -EAGAIN;
|
||||
return false;
|
||||
}
|
||||
if (!bt_mesh_is_provisioner_en()) {
|
||||
check = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == PROVISIONER) {
|
||||
if (!provisioner_check_msg_dst_addr(tx->ctx->addr)) {
|
||||
BT_ERR("%s, Failed to check DST", __func__);
|
||||
return -EINVAL;
|
||||
if (!provisioner_check_msg_dst_addr(dst)) {
|
||||
BT_ERR("%s, Failed to find DST 0x%04x", __func__, dst);
|
||||
return false;
|
||||
}
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
check = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == PROVISIONER) {
|
||||
if (!provisioner_check_msg_dst_addr(tx->ctx->addr)) {
|
||||
if (!provisioner_check_msg_dst_addr(dst)) {
|
||||
BT_ERR("%s, Failed to check DST", __func__);
|
||||
return -EINVAL;
|
||||
return false;
|
||||
}
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
check = true;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
if (!bt_mesh_is_provisioned()) {
|
||||
BT_ERR("%s, Local node is not yet provisioned", __func__);
|
||||
return -EAGAIN;
|
||||
return false;
|
||||
}
|
||||
check = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!check) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static int model_send(struct bt_mesh_model *model,
|
||||
struct bt_mesh_net_tx *tx, bool implicit_bind,
|
||||
struct net_buf_simple *msg,
|
||||
const struct bt_mesh_send_cb *cb, void *cb_data)
|
||||
{
|
||||
u8_t role;
|
||||
|
||||
role = bt_mesh_get_device_role(model, tx->ctx->srv_send);
|
||||
if (role == ROLE_NVAL) {
|
||||
BT_ERR("%s, Failed to get model role", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x dst 0x%04x", tx->ctx->net_idx,
|
||||
tx->ctx->app_idx, tx->ctx->addr);
|
||||
BT_DBG("len %u: %s", msg->len, bt_hex(msg->data, msg->len));
|
||||
|
||||
if (!ready_to_send(role, tx->ctx->addr)) {
|
||||
BT_ERR("%s, fail", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
@ -819,42 +874,13 @@ int bt_mesh_model_send(struct bt_mesh_model *model,
|
||||
struct bt_mesh_subnet *sub = NULL;
|
||||
u8_t role;
|
||||
|
||||
role = bt_mesh_get_model_role(model, ctx->srv_send);
|
||||
role = bt_mesh_get_device_role(model, ctx->srv_send);
|
||||
if (role == ROLE_NVAL) {
|
||||
BT_ERR("%s, Failed to get model role", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == NODE) {
|
||||
if (!bt_mesh_is_provisioner_en()) {
|
||||
sub = bt_mesh_subnet_get(ctx->net_idx);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == PROVISIONER) {
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
sub = provisioner_subnet_get(ctx->net_idx);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == NODE) {
|
||||
sub = bt_mesh_subnet_get(ctx->net_idx);
|
||||
} else if (role == PROVISIONER) {
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
sub = provisioner_subnet_get(ctx->net_idx);
|
||||
}
|
||||
} else if (role == FAST_PROV) {
|
||||
#if CONFIG_BLE_MESH_FAST_PROV
|
||||
sub = get_fast_prov_subnet(ctx->net_idx);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
sub = bt_mesh_tx_netkey_get(role, ctx->net_idx);
|
||||
if (!sub) {
|
||||
BT_ERR("%s, Failed to get subnet", __func__);
|
||||
return -EINVAL;
|
||||
@ -889,7 +915,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model)
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
if (!pub) {
|
||||
if (!pub || !pub->msg) {
|
||||
BT_ERR("%s, Model has no publication support", __func__);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
@ -899,34 +925,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model)
|
||||
return -EADDRNOTAVAIL;
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (pub->dev_role == NODE) {
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
key = bt_mesh_app_key_find(pub->key);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (pub->dev_role == PROVISIONER) {
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
key = provisioner_app_key_find(pub->key);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (pub->dev_role == NODE) {
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
key = bt_mesh_app_key_find(pub->key);
|
||||
}
|
||||
} else if (pub->dev_role == PROVISIONER) {
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
key = provisioner_app_key_find(pub->key);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
key = bt_mesh_tx_appkey_get(pub->dev_role, pub->key, BLE_MESH_KEY_ANY);
|
||||
if (!key) {
|
||||
BT_ERR("%s, Failed to get AppKey", __func__);
|
||||
return -EADDRNOTAVAIL;
|
||||
@ -950,34 +949,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model)
|
||||
|
||||
tx.friend_cred = pub->cred;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (pub->dev_role == NODE) {
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
tx.sub = bt_mesh_subnet_get(ctx.net_idx);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (pub->dev_role == PROVISIONER) {
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
tx.sub = provisioner_subnet_get(ctx.net_idx);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (pub->dev_role == NODE) {
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
tx.sub = bt_mesh_subnet_get(ctx.net_idx);
|
||||
}
|
||||
} else if (pub->dev_role == PROVISIONER) {
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
tx.sub = provisioner_subnet_get(ctx.net_idx);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
tx.sub = bt_mesh_tx_netkey_get(pub->dev_role, ctx.net_idx);
|
||||
if (!tx.sub) {
|
||||
BT_ERR("%s, Failed to get subnet", __func__);
|
||||
return -EADDRNOTAVAIL;
|
||||
@ -1041,3 +1013,281 @@ const struct bt_mesh_comp *bt_mesh_comp_get(void)
|
||||
{
|
||||
return dev_comp;
|
||||
}
|
||||
|
||||
/* APIs used by messages encryption in upper transport layer & network layer */
|
||||
struct bt_mesh_subnet *bt_mesh_tx_netkey_get(u8_t role, u16_t net_idx)
|
||||
{
|
||||
struct bt_mesh_subnet *sub = NULL;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == NODE) {
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
sub = bt_mesh_subnet_get(net_idx);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == PROVISIONER) {
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
sub = provisioner_subnet_get(net_idx);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == NODE) {
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
sub = bt_mesh_subnet_get(net_idx);
|
||||
}
|
||||
} else if (role == PROVISIONER) {
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
sub = provisioner_subnet_get(net_idx);
|
||||
}
|
||||
} else if (role == FAST_PROV) {
|
||||
#if CONFIG_BLE_MESH_FAST_PROV
|
||||
sub = fast_prov_subnet_get(net_idx);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
return sub;
|
||||
}
|
||||
|
||||
const u8_t *bt_mesh_tx_devkey_get(u8_t role, u16_t dst)
|
||||
{
|
||||
const u8_t *key = NULL;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == NODE) {
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
key = bt_mesh.dev_key;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == PROVISIONER) {
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
key = provisioner_dev_key_get(dst);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == NODE) {
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
key = bt_mesh.dev_key;
|
||||
}
|
||||
} else if (role == PROVISIONER) {
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
key = provisioner_dev_key_get(dst);
|
||||
}
|
||||
} else if (role == FAST_PROV) {
|
||||
#if CONFIG_BLE_MESH_FAST_PROV
|
||||
key = fast_prov_dev_key_get(dst);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
struct bt_mesh_app_key *bt_mesh_tx_appkey_get(u8_t role, u16_t app_idx, u16_t net_idx)
|
||||
{
|
||||
struct bt_mesh_app_key *key = NULL;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == NODE) {
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
key = bt_mesh_app_key_find(app_idx);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == PROVISIONER) {
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
key = provisioner_app_key_find(app_idx);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (role == NODE) {
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
key = bt_mesh_app_key_find(app_idx);
|
||||
}
|
||||
} else if (role == PROVISIONER) {
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
key = provisioner_app_key_find(app_idx);
|
||||
}
|
||||
} else if (role == FAST_PROV) {
|
||||
#if CONFIG_BLE_MESH_FAST_PROV
|
||||
key = fast_prov_app_key_find(net_idx, app_idx);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
/* APIs used by messages decryption in network layer & upper transport layer */
|
||||
size_t bt_mesh_rx_netkey_size(void)
|
||||
{
|
||||
size_t size = 0;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
size = ARRAY_SIZE(bt_mesh.sub);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
size = ARRAY_SIZE(bt_mesh.p_sub);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
size = ARRAY_SIZE(bt_mesh.sub);
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
size += ARRAY_SIZE(bt_mesh.p_sub);
|
||||
}
|
||||
#endif
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
struct bt_mesh_subnet *bt_mesh_rx_netkey_get(size_t index)
|
||||
{
|
||||
struct bt_mesh_subnet *sub = NULL;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
sub = &bt_mesh.sub[index];
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
sub = bt_mesh.p_sub[index];
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (index < ARRAY_SIZE(bt_mesh.sub)) {
|
||||
sub = &bt_mesh.sub[index];
|
||||
} else {
|
||||
sub = bt_mesh.p_sub[index - ARRAY_SIZE(bt_mesh.sub)];
|
||||
}
|
||||
#endif
|
||||
|
||||
return sub;
|
||||
}
|
||||
|
||||
size_t bt_mesh_rx_devkey_size(void)
|
||||
{
|
||||
size_t size = 0;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (!bt_mesh_is_provisioner_en()) {
|
||||
size = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
size = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
size = 1;
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
size += 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
const u8_t *bt_mesh_rx_devkey_get(size_t index, u16_t src)
|
||||
{
|
||||
const u8_t *key = NULL;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
key = bt_mesh.dev_key;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
key = provisioner_dev_key_get(src);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (index < 1) {
|
||||
key = bt_mesh.dev_key;
|
||||
} else {
|
||||
key = provisioner_dev_key_get(src);
|
||||
}
|
||||
#endif
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
size_t bt_mesh_rx_appkey_size(void)
|
||||
{
|
||||
size_t size = 0;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
size = ARRAY_SIZE(bt_mesh.app_keys);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
size = ARRAY_SIZE(bt_mesh.p_app_keys);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
size = ARRAY_SIZE(bt_mesh.app_keys);
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
size += ARRAY_SIZE(bt_mesh.p_app_keys);
|
||||
}
|
||||
#endif
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
struct bt_mesh_app_key *bt_mesh_rx_appkey_get(size_t index)
|
||||
{
|
||||
struct bt_mesh_app_key *key = NULL;
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
|
||||
if (bt_mesh_is_provisioned()) {
|
||||
key = &bt_mesh.app_keys[index];
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
key = bt_mesh.p_app_keys[index];
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
|
||||
if (index < ARRAY_SIZE(bt_mesh.app_keys)) {
|
||||
key = &bt_mesh.app_keys[index];
|
||||
} else {
|
||||
key = bt_mesh.p_app_keys[index - ARRAY_SIZE(bt_mesh.app_keys)];
|
||||
}
|
||||
#endif
|
||||
|
||||
return key;
|
||||
}
|
||||
|
@ -57,4 +57,22 @@ void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf);
|
||||
|
||||
int bt_mesh_comp_register(const struct bt_mesh_comp *comp);
|
||||
|
||||
struct bt_mesh_subnet *bt_mesh_tx_netkey_get(u8_t role, u16_t net_idx);
|
||||
|
||||
const u8_t *bt_mesh_tx_devkey_get(u8_t role, u16_t dst);
|
||||
|
||||
struct bt_mesh_app_key *bt_mesh_tx_appkey_get(u8_t role, u16_t app_idx, u16_t net_idx);
|
||||
|
||||
size_t bt_mesh_rx_netkey_size(void);
|
||||
|
||||
struct bt_mesh_subnet *bt_mesh_rx_netkey_get(size_t index);
|
||||
|
||||
size_t bt_mesh_rx_devkey_size(void);
|
||||
|
||||
const u8_t *bt_mesh_rx_devkey_get(size_t index, u16_t src);
|
||||
|
||||
size_t bt_mesh_rx_appkey_size(void);
|
||||
|
||||
struct bt_mesh_app_key *bt_mesh_rx_appkey_get(size_t index);
|
||||
|
||||
#endif /* _ACCESS_H_ */
|
||||
|
@ -7,6 +7,9 @@
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/task.h"
|
||||
@ -27,10 +30,10 @@
|
||||
#include "foundation.h"
|
||||
#include "beacon.h"
|
||||
#include "prov.h"
|
||||
#include "proxy.h"
|
||||
#include "proxy_server.h"
|
||||
|
||||
#include "provisioner_prov.h"
|
||||
#include "provisioner_proxy.h"
|
||||
#include "proxy_client.h"
|
||||
#include "provisioner_beacon.h"
|
||||
|
||||
/* Convert from ms to 0.625ms units */
|
||||
@ -52,7 +55,6 @@
|
||||
#define ADV_STACK_SIZE 768
|
||||
#endif
|
||||
|
||||
static xQueueHandle xBleMeshQueue;
|
||||
static const bt_mesh_addr_t *dev_addr;
|
||||
|
||||
static const u8_t adv_type[] = {
|
||||
@ -67,6 +69,27 @@ NET_BUF_POOL_DEFINE(adv_buf_pool, CONFIG_BLE_MESH_ADV_BUF_COUNT + 3 * CONFIG_BLE
|
||||
|
||||
static struct bt_mesh_adv adv_pool[CONFIG_BLE_MESH_ADV_BUF_COUNT + 3 * CONFIG_BLE_MESH_PBA_SAME_TIME];
|
||||
|
||||
static QueueHandle_t xBleMeshQueue;
|
||||
#define BLE_MESH_QUEUE_SIZE 150
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
|
||||
NET_BUF_POOL_DEFINE(relay_adv_buf_pool, CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT,
|
||||
BLE_MESH_ADV_DATA_SIZE, BLE_MESH_ADV_USER_DATA_SIZE, NULL);
|
||||
|
||||
static struct bt_mesh_adv relay_adv_pool[CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT];
|
||||
|
||||
static QueueHandle_t xBleMeshRelayQueue;
|
||||
#define BLE_MESH_RELAY_QUEUE_SIZE 150
|
||||
|
||||
static QueueSetHandle_t xBleMeshQueueSet;
|
||||
#define BLE_MESH_QUEUE_SET_SIZE (BLE_MESH_QUEUE_SIZE + BLE_MESH_RELAY_QUEUE_SIZE)
|
||||
|
||||
#define BLE_MESH_RELAY_TIME_INTERVAL K_SECONDS(6)
|
||||
#define BLE_MESH_MAX_TIME_INTERVAL 0xFFFFFFFF
|
||||
|
||||
static bool ignore_relay_packet(u32_t timestamp);
|
||||
#endif /* defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
|
||||
|
||||
static struct bt_mesh_adv *adv_alloc(int id)
|
||||
{
|
||||
return &adv_pool[id];
|
||||
@ -103,7 +126,7 @@ static inline int adv_send(struct net_buf *buf)
|
||||
adv_int = MAX(adv_int_min,
|
||||
BLE_MESH_TRANSMIT_INT(BLE_MESH_ADV(buf)->xmit));
|
||||
duration = (BLE_MESH_TRANSMIT_COUNT(BLE_MESH_ADV(buf)->xmit) + 1) *
|
||||
(adv_int + 10);
|
||||
(adv_int + 10);
|
||||
|
||||
BT_DBG("type %u len %u: %s", BLE_MESH_ADV(buf)->type,
|
||||
buf->len, bt_hex(buf->data, buf->len));
|
||||
@ -119,6 +142,8 @@ static inline int adv_send(struct net_buf *buf)
|
||||
param.interval_min = ADV_SCAN_UNIT(adv_int);
|
||||
param.interval_max = param.interval_min;
|
||||
|
||||
bt_mesh_adv_buf_ref_debug(__func__, buf, 3U, BLE_MESH_BUF_REF_SMALL);
|
||||
|
||||
err = bt_le_adv_start(¶m, &ad, 1, NULL, 0);
|
||||
net_buf_unref(buf);
|
||||
adv_send_start(duration, err, cb, cb_data);
|
||||
@ -144,48 +169,114 @@ static inline int adv_send(struct net_buf *buf)
|
||||
|
||||
static void adv_thread(void *p)
|
||||
{
|
||||
struct net_buf **buf = NULL;
|
||||
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
|
||||
QueueSetMemberHandle_t handle;
|
||||
#endif
|
||||
bt_mesh_msg_t msg = {0};
|
||||
int status;
|
||||
|
||||
BT_DBG("started");
|
||||
struct net_buf **buf;
|
||||
|
||||
buf = (struct net_buf **)(&msg.arg);
|
||||
|
||||
BT_DBG("%s, starts", __func__);
|
||||
|
||||
while (1) {
|
||||
*buf = NULL;
|
||||
#if !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PROXY)) {
|
||||
xQueueReceive(xBleMeshQueue, &msg, K_NO_WAIT);
|
||||
while (!(*buf)) {
|
||||
s32_t timeout;
|
||||
BT_DBG("Proxy advertising start");
|
||||
BT_DBG("Mesh Proxy Advertising start");
|
||||
timeout = bt_mesh_proxy_adv_start();
|
||||
BT_DBG("Proxy Advertising up to %d ms", timeout);
|
||||
BT_DBG("Mesh Proxy Advertising up to %d ms", timeout);
|
||||
xQueueReceive(xBleMeshQueue, &msg, timeout);
|
||||
BT_DBG("Proxy advertising stop");
|
||||
BT_DBG("Mesh Proxy Advertising stop");
|
||||
bt_mesh_proxy_adv_stop();
|
||||
}
|
||||
} else {
|
||||
xQueueReceive(xBleMeshQueue, &msg, (portTickType)portMAX_DELAY);
|
||||
xQueueReceive(xBleMeshQueue, &msg, portMAX_DELAY);
|
||||
}
|
||||
#else
|
||||
xQueueReceive(xBleMeshQueue, &msg, (portTickType)portMAX_DELAY);
|
||||
xQueueReceive(xBleMeshQueue, &msg, portMAX_DELAY);
|
||||
#endif
|
||||
#else /* !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_PROXY)) {
|
||||
handle = xQueueSelectFromSet(xBleMeshQueueSet, K_NO_WAIT);
|
||||
if (handle) {
|
||||
if (uxQueueMessagesWaiting(xBleMeshQueue)) {
|
||||
xQueueReceive(xBleMeshQueue, &msg, K_NO_WAIT);
|
||||
} else if (uxQueueMessagesWaiting(xBleMeshRelayQueue)) {
|
||||
xQueueReceive(xBleMeshRelayQueue, &msg, K_NO_WAIT);
|
||||
}
|
||||
} else {
|
||||
while (!(*buf)) {
|
||||
s32_t timeout;
|
||||
BT_DBG("Mesh Proxy Advertising start");
|
||||
timeout = bt_mesh_proxy_adv_start();
|
||||
BT_DBG("Mesh Proxy Advertising up to %d ms", timeout);
|
||||
handle = xQueueSelectFromSet(xBleMeshQueueSet, timeout);
|
||||
BT_DBG("Mesh Proxy Advertising stop");
|
||||
bt_mesh_proxy_adv_stop();
|
||||
if (handle) {
|
||||
if (uxQueueMessagesWaiting(xBleMeshQueue)) {
|
||||
xQueueReceive(xBleMeshQueue, &msg, K_NO_WAIT);
|
||||
} else if (uxQueueMessagesWaiting(xBleMeshRelayQueue)) {
|
||||
xQueueReceive(xBleMeshRelayQueue, &msg, K_NO_WAIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
handle = xQueueSelectFromSet(xBleMeshQueueSet, portMAX_DELAY);
|
||||
if (handle) {
|
||||
if (uxQueueMessagesWaiting(xBleMeshQueue)) {
|
||||
xQueueReceive(xBleMeshQueue, &msg, K_NO_WAIT);
|
||||
} else if (uxQueueMessagesWaiting(xBleMeshRelayQueue)) {
|
||||
xQueueReceive(xBleMeshRelayQueue, &msg, K_NO_WAIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
handle = xQueueSelectFromSet(xBleMeshQueueSet, portMAX_DELAY);
|
||||
if (handle) {
|
||||
if (uxQueueMessagesWaiting(xBleMeshQueue)) {
|
||||
xQueueReceive(xBleMeshQueue, &msg, K_NO_WAIT);
|
||||
} else if (uxQueueMessagesWaiting(xBleMeshRelayQueue)) {
|
||||
xQueueReceive(xBleMeshRelayQueue, &msg, K_NO_WAIT);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
|
||||
|
||||
if (!(*buf)) {
|
||||
if (*buf == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* busy == 0 means this was canceled */
|
||||
if (BLE_MESH_ADV(*buf)->busy) {
|
||||
BLE_MESH_ADV(*buf)->busy = 0U;
|
||||
status = adv_send(*buf);
|
||||
if (status) {
|
||||
if (xQueueSendToFront(xBleMeshQueue, &msg, K_NO_WAIT) != pdTRUE) {
|
||||
BT_ERR("%s, xQueueSendToFront failed", __func__);
|
||||
#if !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
|
||||
if (adv_send(*buf)) {
|
||||
BT_WARN("%s, Failed to send adv packet", __func__);
|
||||
}
|
||||
#else /* !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
|
||||
if (msg.relay && ignore_relay_packet(msg.timestamp)) {
|
||||
/* If the interval between "current time - msg.timestamp" is bigger than
|
||||
* BLE_MESH_RELAY_TIME_INTERVAL, this relay packet will not be sent.
|
||||
*/
|
||||
BT_DBG("%s, Ignore relay packet", __func__);
|
||||
net_buf_unref(*buf);
|
||||
} else {
|
||||
if (adv_send(*buf)) {
|
||||
BT_WARN("%s, Failed to send adv packet", __func__);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
bt_mesh_adv_buf_ref_debug(__func__, *buf, 1U, BLE_MESH_BUF_REF_EQUAL);
|
||||
net_buf_unref(*buf);
|
||||
}
|
||||
|
||||
/* Give other threads a chance to run */
|
||||
@ -193,13 +284,6 @@ static void adv_thread(void *p)
|
||||
}
|
||||
}
|
||||
|
||||
void bt_mesh_adv_update(void)
|
||||
{
|
||||
BT_DBG("%s", __func__);
|
||||
bt_mesh_msg_t msg = {0};
|
||||
bt_mesh_task_post(&msg, 0);
|
||||
}
|
||||
|
||||
struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool,
|
||||
bt_mesh_adv_alloc_t get_id,
|
||||
enum bt_mesh_adv_type type,
|
||||
@ -219,7 +303,7 @@ struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool,
|
||||
}
|
||||
|
||||
BT_DBG("%s, pool = %p, buf_count = %d, uinit_count = %d", __func__,
|
||||
buf->pool, pool->buf_count, pool->uninit_count);
|
||||
buf->pool, pool->buf_count, pool->uninit_count);
|
||||
|
||||
adv = get_id(net_buf_id(buf));
|
||||
BLE_MESH_ADV(buf) = adv;
|
||||
@ -239,17 +323,59 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, u8_t xmit,
|
||||
xmit, timeout);
|
||||
}
|
||||
|
||||
void bt_mesh_task_post(bt_mesh_msg_t *msg, uint32_t timeout)
|
||||
void bt_mesh_adv_buf_ref_debug(const char *func, struct net_buf *buf,
|
||||
u8_t ref_cmp, bt_mesh_buf_ref_flag_t flag)
|
||||
{
|
||||
if (buf == NULL || func == NULL || flag >= BLE_MESH_BUF_REF_MAX) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (flag) {
|
||||
case BLE_MESH_BUF_REF_EQUAL:
|
||||
if (buf->ref != ref_cmp) {
|
||||
BT_ERR("Unexpected ref %d in %s, expect to equal to %d", buf->ref, func, ref_cmp);
|
||||
}
|
||||
break;
|
||||
case BLE_MESH_BUF_REF_SMALL:
|
||||
if (buf->ref >= ref_cmp) {
|
||||
BT_ERR("Unexpected ref %d in %s, expect to smaller than %d", buf->ref, func, ref_cmp);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_mesh_unref_buf(bt_mesh_msg_t *msg)
|
||||
{
|
||||
struct net_buf *buf;
|
||||
|
||||
if (msg->arg) {
|
||||
buf = (struct net_buf *)msg->arg;
|
||||
BLE_MESH_ADV(buf)->busy = 0U;
|
||||
net_buf_unref(buf);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void bt_mesh_task_post(bt_mesh_msg_t *msg, uint32_t timeout)
|
||||
{
|
||||
BT_DBG("%s", __func__);
|
||||
if (xQueueSend(xBleMeshQueue, msg, timeout) != pdTRUE) {
|
||||
BT_ERR("%s, Failed to post msg to queue", __func__);
|
||||
BT_ERR("%s, Failed to send item to queue", __func__);
|
||||
bt_mesh_unref_buf(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
|
||||
void *cb_data)
|
||||
{
|
||||
bt_mesh_msg_t msg = {
|
||||
.relay = false,
|
||||
};
|
||||
|
||||
BT_DBG("type 0x%02x len %u: %s", BLE_MESH_ADV(buf)->type, buf->len,
|
||||
bt_hex(buf->data, buf->len));
|
||||
|
||||
@ -257,21 +383,230 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
|
||||
BLE_MESH_ADV(buf)->cb_data = cb_data;
|
||||
BLE_MESH_ADV(buf)->busy = 1U;
|
||||
|
||||
bt_mesh_msg_t msg = {0};
|
||||
bt_mesh_adv_buf_ref_debug(__func__, buf, 3U, BLE_MESH_BUF_REF_SMALL);
|
||||
|
||||
msg.arg = (void *)net_buf_ref(buf);
|
||||
bt_mesh_task_post(&msg, portMAX_DELAY);
|
||||
}
|
||||
|
||||
void bt_mesh_adv_update(void)
|
||||
{
|
||||
bt_mesh_msg_t msg = {
|
||||
.relay = false,
|
||||
.arg = NULL,
|
||||
};
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
bt_mesh_task_post(&msg, K_NO_WAIT);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
|
||||
static bool ignore_relay_packet(u32_t timestamp)
|
||||
{
|
||||
u32_t now = k_uptime_get_32();
|
||||
u32_t interval;
|
||||
|
||||
if (now > timestamp) {
|
||||
interval = now - timestamp;
|
||||
} else if (now == timestamp) {
|
||||
interval = BLE_MESH_MAX_TIME_INTERVAL;
|
||||
} else {
|
||||
interval = BLE_MESH_MAX_TIME_INTERVAL - (timestamp - now) + 1;
|
||||
}
|
||||
|
||||
return (interval >= BLE_MESH_RELAY_TIME_INTERVAL) ? true : false;
|
||||
}
|
||||
|
||||
static struct bt_mesh_adv *relay_adv_alloc(int id)
|
||||
{
|
||||
return &relay_adv_pool[id];
|
||||
}
|
||||
|
||||
struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, u8_t xmit,
|
||||
s32_t timeout)
|
||||
{
|
||||
return bt_mesh_adv_create_from_pool(&relay_adv_buf_pool, relay_adv_alloc, type,
|
||||
xmit, timeout);
|
||||
}
|
||||
|
||||
static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout)
|
||||
{
|
||||
QueueSetMemberHandle_t handle;
|
||||
bt_mesh_msg_t old_msg = {0};
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
if (xQueueSend(xBleMeshRelayQueue, msg, timeout) == pdTRUE) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* If failed to send packet to the relay queue(queue is full), we will
|
||||
* remove the oldest packet in the queue and put the new one into it.
|
||||
*/
|
||||
handle = xQueueSelectFromSet(xBleMeshQueueSet, K_NO_WAIT);
|
||||
if (handle && uxQueueMessagesWaiting(xBleMeshRelayQueue)) {
|
||||
BT_DBG("%s, Full queue, remove the oldest relay packet", __func__);
|
||||
/* Remove the oldest relay packet from queue */
|
||||
if (xQueueReceive(xBleMeshRelayQueue, &old_msg, K_NO_WAIT) != pdTRUE) {
|
||||
BT_ERR("%s, Failed to remove item from queue", __func__);
|
||||
bt_mesh_unref_buf(msg);
|
||||
return;
|
||||
}
|
||||
/* Unref buf used for the oldest relay packet */
|
||||
bt_mesh_unref_buf(&old_msg);
|
||||
/* Send the latest relay packet to queue */
|
||||
if (xQueueSend(xBleMeshRelayQueue, msg, K_NO_WAIT) != pdTRUE) {
|
||||
BT_ERR("%s, Failed to send item to relay queue", __func__);
|
||||
bt_mesh_unref_buf(msg);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
BT_WARN("%s, Empty queue, but failed to send the relay packet", __func__);
|
||||
bt_mesh_unref_buf(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void bt_mesh_relay_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
|
||||
void *cb_data, u16_t src, u16_t dst)
|
||||
{
|
||||
bt_mesh_msg_t msg = {
|
||||
.relay = true,
|
||||
};
|
||||
|
||||
BT_DBG("type 0x%02x len %u: %s", BLE_MESH_ADV(buf)->type, buf->len,
|
||||
bt_hex(buf->data, buf->len));
|
||||
|
||||
BLE_MESH_ADV(buf)->cb = cb;
|
||||
BLE_MESH_ADV(buf)->cb_data = cb_data;
|
||||
BLE_MESH_ADV(buf)->busy = 1U;
|
||||
|
||||
msg.arg = (void *)net_buf_ref(buf);
|
||||
msg.src = src;
|
||||
msg.dst = dst;
|
||||
msg.timestamp = k_uptime_get_32();
|
||||
/* Use K_NO_WAIT here, if xBleMeshRelayQueue is full return immediately */
|
||||
ble_mesh_relay_task_post(&msg, K_NO_WAIT);
|
||||
}
|
||||
|
||||
u16_t bt_mesh_get_stored_relay_count(void)
|
||||
{
|
||||
return (u16_t)uxQueueMessagesWaiting(xBleMeshRelayQueue);
|
||||
}
|
||||
#endif /* #if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
|
||||
|
||||
const bt_mesh_addr_t *bt_mesh_pba_get_addr(void)
|
||||
{
|
||||
return dev_addr;
|
||||
}
|
||||
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
static bool bt_mesh_is_adv_flags_valid(struct net_buf_simple *buf)
|
||||
{
|
||||
u8_t flags;
|
||||
|
||||
if (buf->len != 1U) {
|
||||
BT_DBG("%s, Unexpected flags length", __func__);
|
||||
return false;
|
||||
}
|
||||
|
||||
flags = net_buf_simple_pull_u8(buf);
|
||||
|
||||
BT_DBG("Received adv pkt with flags: 0x%02x", flags);
|
||||
|
||||
/* Flags context will not be checked curently */
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool bt_mesh_is_adv_srv_uuid_valid(struct net_buf_simple *buf, u16_t *uuid)
|
||||
{
|
||||
if (buf->len != 2U) {
|
||||
BT_DBG("Length not match mesh service uuid");
|
||||
return false;
|
||||
}
|
||||
|
||||
*uuid = net_buf_simple_pull_le16(buf);
|
||||
|
||||
BT_DBG("Received adv pkt with service UUID: %d", *uuid);
|
||||
|
||||
if (*uuid != BLE_MESH_UUID_MESH_PROV_VAL &&
|
||||
*uuid != BLE_MESH_UUID_MESH_PROXY_VAL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (*uuid == BLE_MESH_UUID_MESH_PROV_VAL &&
|
||||
bt_mesh_is_provisioner_en() == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (*uuid == BLE_MESH_UUID_MESH_PROXY_VAL &&
|
||||
!IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#define BLE_MESH_PROV_SRV_DATA_LEN 0x12
|
||||
#define BLE_MESH_PROXY_SRV_DATA_LEN1 0x09
|
||||
#define BLE_MESH_PROXY_SRV_DATA_LEN2 0x11
|
||||
|
||||
static void bt_mesh_adv_srv_data_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr, u16_t uuid)
|
||||
{
|
||||
u16_t type;
|
||||
|
||||
if (!buf || !addr) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
type = net_buf_simple_pull_le16(buf);
|
||||
if (type != uuid) {
|
||||
BT_DBG("%s, Invalid Mesh Service Data UUID 0x%04x", __func__, type);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
|
||||
case BLE_MESH_UUID_MESH_PROV_VAL:
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
if (buf->len != BLE_MESH_PROV_SRV_DATA_LEN) {
|
||||
BT_WARN("%s, Invalid Mesh Prov Service Data length %d", __func__, buf->len);
|
||||
return;
|
||||
}
|
||||
|
||||
BT_DBG("Start to handle Mesh Prov Service Data");
|
||||
provisioner_prov_adv_ind_recv(buf, addr);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
case BLE_MESH_UUID_MESH_PROXY_VAL:
|
||||
if (buf->len != BLE_MESH_PROXY_SRV_DATA_LEN1 &&
|
||||
buf->len != BLE_MESH_PROXY_SRV_DATA_LEN2) {
|
||||
BT_WARN("%s, Invalid Mesh Proxy Service Data length %d", __func__, buf->len);
|
||||
return;
|
||||
}
|
||||
|
||||
BT_DBG("Start to handle Mesh Proxy Service Data");
|
||||
proxy_client_adv_ind_recv(buf, addr);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, s8_t rssi,
|
||||
u8_t adv_type, struct net_buf_simple *buf)
|
||||
{
|
||||
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
|
||||
u16_t uuid = 0;
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
u16_t uuid;
|
||||
#endif
|
||||
|
||||
if (adv_type != BLE_MESH_ADV_NONCONN_IND && adv_type != BLE_MESH_ADV_IND) {
|
||||
@ -306,9 +641,9 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, s8_t rssi,
|
||||
#if 0
|
||||
/* TODO: Check with BLE Mesh BQB test cases */
|
||||
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)) {
|
||||
type == BLE_MESH_DATA_MESH_BEACON) && (adv_type != BLE_MESH_ADV_NONCONN_IND)) {
|
||||
BT_DBG("%s, ignore BLE Mesh packet (type 0x%02x) with adv_type 0x%02x",
|
||||
__func__, type, adv_type);
|
||||
__func__, type, adv_type);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@ -343,30 +678,24 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, s8_t rssi,
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
case BLE_MESH_DATA_FLAGS:
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
if (!provisioner_flags_match(buf)) {
|
||||
BT_DBG("Flags mismatch, ignore this adv pkt");
|
||||
return;
|
||||
}
|
||||
if (!bt_mesh_is_adv_flags_valid(buf)) {
|
||||
BT_DBG("Adv Flags mismatch, ignore this adv pkt");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case BLE_MESH_DATA_UUID16_ALL:
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
uuid = provisioner_srv_uuid_recv(buf);
|
||||
if (!uuid) {
|
||||
BT_DBG("Service UUID mismatch, ignore this adv pkt");
|
||||
return;
|
||||
}
|
||||
if (!bt_mesh_is_adv_srv_uuid_valid(buf, &uuid)) {
|
||||
BT_DBG("Adv Service UUID mismatch, ignore this adv pkt");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case BLE_MESH_DATA_SVC_DATA16:
|
||||
if (bt_mesh_is_provisioner_en()) {
|
||||
provisioner_srv_data_recv(buf, addr, uuid);
|
||||
}
|
||||
bt_mesh_adv_srv_data_recv(buf, addr, uuid);
|
||||
break;
|
||||
#endif /* CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT */
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -380,13 +709,25 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, s8_t rssi,
|
||||
|
||||
void bt_mesh_adv_init(void)
|
||||
{
|
||||
xBleMeshQueue = xQueueCreate(150, sizeof(bt_mesh_msg_t));
|
||||
xTaskCreatePinnedToCore(adv_thread, "BLE_Mesh_ADV_Task", 3072, NULL,
|
||||
configMAX_PRIORITIES - 7, NULL, TASK_PINNED_TO_CORE);
|
||||
xBleMeshQueue = xQueueCreate(BLE_MESH_QUEUE_SIZE, sizeof(bt_mesh_msg_t));
|
||||
configASSERT(xBleMeshQueue);
|
||||
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
|
||||
xBleMeshRelayQueue = xQueueCreate(BLE_MESH_RELAY_QUEUE_SIZE, sizeof(bt_mesh_msg_t));
|
||||
configASSERT(xBleMeshRelayQueue);
|
||||
xBleMeshQueueSet = xQueueCreateSet(BLE_MESH_QUEUE_SET_SIZE);
|
||||
configASSERT(xBleMeshQueueSet);
|
||||
xQueueAddToSet(xBleMeshQueue, xBleMeshQueueSet);
|
||||
xQueueAddToSet(xBleMeshRelayQueue, xBleMeshQueueSet);
|
||||
#endif /* defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
|
||||
int ret = xTaskCreatePinnedToCore(adv_thread, "BLE_Mesh_ADV_Task", 3072, NULL,
|
||||
configMAX_PRIORITIES - 7, NULL, ADV_TASK_CORE);
|
||||
configASSERT(ret == pdTRUE);
|
||||
}
|
||||
|
||||
int bt_mesh_scan_enable(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
struct bt_mesh_scan_param scan_param = {
|
||||
.type = BLE_MESH_SCAN_PASSIVE,
|
||||
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
|
||||
@ -400,12 +741,26 @@ int bt_mesh_scan_enable(void)
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
return bt_le_scan_start(&scan_param, bt_mesh_scan_cb);
|
||||
err = bt_le_scan_start(&scan_param, bt_mesh_scan_cb);
|
||||
if (err && err != -EALREADY) {
|
||||
BT_ERR("starting scan failed (err %d)", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_scan_disable(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
return bt_le_scan_stop();
|
||||
err = bt_le_scan_stop();
|
||||
if (err && err != -EALREADY) {
|
||||
BT_ERR("stopping scan failed (err %d)", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -21,11 +21,11 @@
|
||||
#define BLE_MESH_ADV(buf) (*(struct bt_mesh_adv **)net_buf_user_data(buf))
|
||||
|
||||
typedef struct bt_mesh_msg {
|
||||
uint8_t sig; //event signal
|
||||
uint8_t aid; //application id
|
||||
uint8_t pid; //profile id
|
||||
uint8_t act; //profile action, defined in seprerate header files
|
||||
void *arg; //param for btc function or function param
|
||||
bool relay; /* Flag indicates if the packet is a relayed one */
|
||||
void *arg; /* Pointer to the struct net_buf */
|
||||
u16_t src; /* Source address for relay packets */
|
||||
u16_t dst; /* Destination address for relay packets */
|
||||
u32_t timestamp; /* Timestamp recorded when the relay packet is posted to queue */
|
||||
} bt_mesh_msg_t;
|
||||
|
||||
enum bt_mesh_adv_type {
|
||||
@ -63,6 +63,15 @@ typedef struct bt_mesh_adv *(*bt_mesh_adv_alloc_t)(int id);
|
||||
struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, u8_t xmit,
|
||||
s32_t timeout);
|
||||
|
||||
typedef enum {
|
||||
BLE_MESH_BUF_REF_EQUAL,
|
||||
BLE_MESH_BUF_REF_SMALL,
|
||||
BLE_MESH_BUF_REF_MAX,
|
||||
} bt_mesh_buf_ref_flag_t;
|
||||
|
||||
void bt_mesh_adv_buf_ref_debug(const char *func, struct net_buf *buf,
|
||||
u8_t ref_cmp, bt_mesh_buf_ref_flag_t flag);
|
||||
|
||||
struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool,
|
||||
bt_mesh_adv_alloc_t get_id,
|
||||
enum bt_mesh_adv_type type,
|
||||
@ -73,6 +82,14 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
|
||||
|
||||
const bt_mesh_addr_t *bt_mesh_pba_get_addr(void);
|
||||
|
||||
struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, u8_t xmit,
|
||||
s32_t timeout);
|
||||
|
||||
void bt_mesh_relay_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
|
||||
void *cb_data, u16_t src, u16_t dst);
|
||||
|
||||
u16_t bt_mesh_get_stored_relay_count(void);
|
||||
|
||||
void bt_mesh_adv_update(void);
|
||||
|
||||
void bt_mesh_adv_init(void);
|
||||
@ -81,6 +98,4 @@ int bt_mesh_scan_enable(void);
|
||||
|
||||
int bt_mesh_scan_disable(void);
|
||||
|
||||
void bt_mesh_task_post(bt_mesh_msg_t *msg, uint32_t timeout);
|
||||
|
||||
#endif /* _ADV_H_ */
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "crypto.h"
|
||||
#include "beacon.h"
|
||||
#include "foundation.h"
|
||||
#include "proxy_client.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
|
||||
@ -138,6 +139,18 @@ static int secure_beacon_send(void)
|
||||
continue;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a node enables the Proxy Client functionality, and it
|
||||
* succeeds to send Secure Network Beacon with GATT bearer,
|
||||
* here we will continue to send Secure Network Beacon of
|
||||
* other subnets.
|
||||
*/
|
||||
#if defined(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)
|
||||
if (bt_mesh_proxy_client_beacon_send(sub)) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
buf = bt_mesh_adv_create(BLE_MESH_ADV_BEACON, PROV_XMIT,
|
||||
K_NO_WAIT);
|
||||
if (!buf) {
|
||||
|
@ -19,6 +19,8 @@
|
||||
#include "stack/hcimsgs.h"
|
||||
#include "osi/future.h"
|
||||
#include "osi/allocator.h"
|
||||
#include "bt_common.h"
|
||||
#include "device/controller.h"
|
||||
|
||||
#include "mbedtls/aes.h"
|
||||
|
||||
@ -32,6 +34,8 @@
|
||||
#include "provisioner_prov.h"
|
||||
#include "mesh_common.h"
|
||||
|
||||
struct bt_mesh_dev bt_mesh_dev;
|
||||
|
||||
#define BLE_MESH_BTM_CHECK_STATUS(func) do { \
|
||||
tBTM_STATUS __status = (func); \
|
||||
if ((__status != BTM_SUCCESS) && (__status != BTM_CMD_STARTED)) { \
|
||||
@ -43,7 +47,7 @@
|
||||
#define BLE_MESH_GATT_GET_CONN_ID(conn_id) (((u16_t)(conn_id)) >> 8)
|
||||
#define BLE_MESH_GATT_CREATE_CONN_ID(gatt_if, conn_id) ((u16_t)((((u8_t)(conn_id)) << 8) | ((u8_t)(gatt_if))))
|
||||
|
||||
/* We don't need to manage the BLE_MESH_DEV_ADVERTISING flags in the version of bluedriod,
|
||||
/* We don't need to manage the BLE_MESH_DEV_ADVERTISING flags in the version of bluedriod,
|
||||
* it will manage it in the BTM layer.
|
||||
*/
|
||||
#define BLE_MESH_DEV 0
|
||||
@ -77,13 +81,13 @@ static future_t *future_mesh;
|
||||
static struct bt_mesh_gatt_attr *bt_mesh_gatts_find_attr_by_handle(u16_t handle);
|
||||
#endif /* defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE */
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
#define BLE_MESH_GATTC_APP_UUID_BYTE 0x97
|
||||
static struct gattc_prov_info {
|
||||
/* Service to be found depends on the type of adv pkt received */
|
||||
struct bt_mesh_conn conn;
|
||||
BD_ADDR addr;
|
||||
u8_t addr_type;
|
||||
bt_mesh_addr_t addr;
|
||||
u16_t service_uuid;
|
||||
u16_t mtu;
|
||||
bool wr_desc_done; /* Indicate if write char descriptor event is received */
|
||||
@ -95,10 +99,44 @@ static struct gattc_prov_info {
|
||||
} bt_mesh_gattc_info[BLE_MESH_MAX_CONN];
|
||||
static struct bt_mesh_prov_conn_cb *bt_mesh_gattc_conn_cb;
|
||||
static tBTA_GATTC_IF bt_mesh_gattc_if;
|
||||
#endif /* defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER */
|
||||
#endif
|
||||
|
||||
esp_err_t bt_mesh_host_init(void)
|
||||
{
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void bt_mesh_hci_init(void)
|
||||
{
|
||||
const uint8_t *features = controller_get_interface()->get_features_ble()->as_array;
|
||||
if (features != NULL) {
|
||||
memcpy(bt_mesh_dev.features[0], features, 8);
|
||||
memcpy(bt_mesh_dev.le.features, features, 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently 20ms non-connectable adv interval is supported, and we need to add
|
||||
* a flag to indicate this support.
|
||||
*/
|
||||
#ifdef CONFIG_BLE_MESH_HCI_5_0
|
||||
bt_mesh_dev.hci_version = BLE_MESH_HCI_VERSION_5_0;
|
||||
#else
|
||||
bt_mesh_dev.hci_version = controller_get_interface()->get_bt_version()->hci_version;
|
||||
#endif
|
||||
bt_mesh_dev.lmp_version = controller_get_interface()->get_bt_version()->lmp_version;
|
||||
bt_mesh_dev.hci_revision = controller_get_interface()->get_bt_version()->hci_revision;
|
||||
bt_mesh_dev.lmp_subversion = controller_get_interface()->get_bt_version()->lmp_subversion;
|
||||
bt_mesh_dev.manufacturer = controller_get_interface()->get_bt_version()->manufacturer;
|
||||
|
||||
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);
|
||||
bt_mesh_dev.le.states = (states_sh << 32) | states_fh;
|
||||
}
|
||||
|
||||
static void bt_mesh_scan_results_change_2_bta(tBTM_INQ_RESULTS *p_inq, u8_t *p_eir,
|
||||
tBTA_DM_SEARCH_CBACK *p_scan_cback)
|
||||
tBTA_DM_SEARCH_CBACK *p_scan_cback)
|
||||
{
|
||||
tBTM_INQ_INFO *p_inq_info;
|
||||
tBTA_DM_SEARCH result;
|
||||
@ -474,9 +512,9 @@ static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data)
|
||||
|
||||
if (attr != NULL && attr->write != NULL) {
|
||||
if ((len = attr->write(&bt_mesh_gatts_conn[index], attr,
|
||||
p_data->req_data.p_data->write_req.value,
|
||||
p_data->req_data.p_data->write_req.len,
|
||||
p_data->req_data.p_data->write_req.offset, 0)) > 0) {
|
||||
p_data->req_data.p_data->write_req.value,
|
||||
p_data->req_data.p_data->write_req.len,
|
||||
p_data->req_data.p_data->write_req.offset, 0)) > 0) {
|
||||
if (p_data->req_data.p_data->write_req.need_rsp) {
|
||||
BTA_GATTS_SendRsp(p_data->req_data.conn_id, p_data->req_data.trans_id,
|
||||
p_data->req_data.status, NULL);
|
||||
@ -589,7 +627,7 @@ static struct bt_mesh_gatt_attr *bt_mesh_gatts_find_attr_by_handle(u16_t handle)
|
||||
}
|
||||
|
||||
static void bt_mesh_gatts_foreach_attr(u16_t start_handle, u16_t end_handle,
|
||||
bt_mesh_gatt_attr_func_t func, void *user_data)
|
||||
bt_mesh_gatt_attr_func_t func, void *user_data)
|
||||
{
|
||||
struct bt_mesh_gatt_service *svc = NULL;
|
||||
|
||||
@ -656,8 +694,8 @@ struct gatts_incl {
|
||||
} __packed;
|
||||
|
||||
ssize_t bt_mesh_gatts_attr_read_included(struct bt_mesh_conn *conn,
|
||||
const struct bt_mesh_gatt_attr *attr,
|
||||
void *buf, u16_t len, u16_t offset)
|
||||
const struct bt_mesh_gatt_attr *attr,
|
||||
void *buf, u16_t len, u16_t offset)
|
||||
{
|
||||
struct bt_mesh_gatt_attr *incl = attr->user_data;
|
||||
struct bt_mesh_uuid *uuid = incl->user_data;
|
||||
@ -693,7 +731,7 @@ ssize_t bt_mesh_gatts_attr_read_service(struct bt_mesh_conn *conn,
|
||||
}
|
||||
|
||||
return bt_mesh_gatts_attr_read(conn, attr, buf, len, offset,
|
||||
BLE_MESH_UUID_128(uuid)->val, 16);
|
||||
BLE_MESH_UUID_128(uuid)->val, 16);
|
||||
}
|
||||
|
||||
struct gatts_chrc {
|
||||
@ -973,29 +1011,50 @@ int bt_mesh_gatts_service_start(struct bt_mesh_gatt_service *svc)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bt_mesh_gatts_set_local_device_name(const char *name)
|
||||
{
|
||||
BLE_MESH_BTM_CHECK_STATUS(BTM_SetLocalDeviceName((char *)name));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE */
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
|
||||
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
|
||||
void bt_mesh_gattc_conn_cb_register(struct bt_mesh_prov_conn_cb *cb)
|
||||
{
|
||||
bt_mesh_gattc_conn_cb = cb;
|
||||
}
|
||||
|
||||
u16_t bt_mesh_gattc_get_service_uuid(struct bt_mesh_conn *conn)
|
||||
u8_t bt_mesh_gattc_get_free_conn_count(void)
|
||||
{
|
||||
int i;
|
||||
u8_t count = 0;
|
||||
u8_t i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
if (conn == &bt_mesh_gattc_info[i].conn) {
|
||||
break;
|
||||
for (i = 0U; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
if (bt_mesh_gattc_info[i].conn.handle == 0xFFFF &&
|
||||
bt_mesh_gattc_info[i].service_uuid == 0x0000) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == ARRAY_SIZE(bt_mesh_gattc_info)) {
|
||||
return 0;
|
||||
return count;
|
||||
}
|
||||
|
||||
u16_t bt_mesh_gattc_get_service_uuid(struct bt_mesh_conn *conn)
|
||||
{
|
||||
u8_t i;
|
||||
|
||||
for (i = 0U; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
if (conn == &bt_mesh_gattc_info[i].conn) {
|
||||
return bt_mesh_gattc_info[i].service_uuid;
|
||||
}
|
||||
}
|
||||
|
||||
return bt_mesh_gattc_info[i].service_uuid;
|
||||
BT_ERR("%s, Conn is not found", __func__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** For provisioner acting as a GATT client, it may follow the procedures
|
||||
@ -1014,22 +1073,22 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid)
|
||||
int i;
|
||||
|
||||
if (!addr || !memcmp(addr->val, zero, BLE_MESH_ADDR_LEN) ||
|
||||
(addr->type > BLE_ADDR_RANDOM)) {
|
||||
(addr->type > BLE_ADDR_RANDOM)) {
|
||||
BT_ERR("%s, Invalid remote address", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (service_uuid != BLE_MESH_UUID_MESH_PROV_VAL &&
|
||||
service_uuid != BLE_MESH_UUID_MESH_PROXY_VAL) {
|
||||
service_uuid != BLE_MESH_UUID_MESH_PROXY_VAL) {
|
||||
BT_ERR("%s, Invalid service uuid 0x%04x", __func__, service_uuid);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Check if already creating connection with the device */
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
if (!memcmp(bt_mesh_gattc_info[i].addr, addr->val, BLE_MESH_ADDR_LEN)) {
|
||||
if (!memcmp(bt_mesh_gattc_info[i].addr.val, addr->val, BLE_MESH_ADDR_LEN)) {
|
||||
BT_WARN("%s, Already create connection with %s",
|
||||
__func__, bt_hex(addr->val, BLE_MESH_ADDR_LEN));
|
||||
__func__, bt_hex(addr->val, BLE_MESH_ADDR_LEN));
|
||||
return -EALREADY;
|
||||
}
|
||||
}
|
||||
@ -1037,9 +1096,9 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid)
|
||||
/* Find empty element in queue to store device info */
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
if ((bt_mesh_gattc_info[i].conn.handle == 0xFFFF) &&
|
||||
(bt_mesh_gattc_info[i].service_uuid == 0x0000)) {
|
||||
memcpy(bt_mesh_gattc_info[i].addr, addr->val, BLE_MESH_ADDR_LEN);
|
||||
bt_mesh_gattc_info[i].addr_type = addr->type;
|
||||
(bt_mesh_gattc_info[i].service_uuid == 0x0000)) {
|
||||
memcpy(bt_mesh_gattc_info[i].addr.val, addr->val, BLE_MESH_ADDR_LEN);
|
||||
bt_mesh_gattc_info[i].addr.type = addr->type;
|
||||
/* Service to be found after exhanging mtu size */
|
||||
bt_mesh_gattc_info[i].service_uuid = service_uuid;
|
||||
break;
|
||||
@ -1066,15 +1125,12 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid)
|
||||
* Slave_latency: 0x0
|
||||
* Supervision_timeout: 32 sec
|
||||
*/
|
||||
BTA_DmSetBlePrefConnParams(bt_mesh_gattc_info[i].addr, 0xC8, 0xC8, 0x00, 0xC80);
|
||||
BTA_DmSetBlePrefConnParams(bt_mesh_gattc_info[i].addr.val, 0xC8, 0xC8, 0x00, 0xC80);
|
||||
|
||||
BTA_GATTC_Open(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr,
|
||||
bt_mesh_gattc_info[i].addr_type, true, BTA_GATT_TRANSPORT_LE);
|
||||
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);
|
||||
|
||||
/* Increment pbg_count */
|
||||
provisioner_pbg_count_inc();
|
||||
|
||||
return 0;
|
||||
return i;
|
||||
}
|
||||
|
||||
void bt_mesh_gattc_exchange_mtu(u8_t index)
|
||||
@ -1111,24 +1167,16 @@ int bt_mesh_gattc_write_no_rsp(struct bt_mesh_conn *conn, const struct bt_mesh_g
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
if (conn == &bt_mesh_gattc_info[i].conn) {
|
||||
break;
|
||||
conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle);
|
||||
BTA_GATTC_WriteCharValue(conn_id, bt_mesh_gattc_info[i].data_in_handle,
|
||||
BTA_GATTC_TYPE_WRITE_NO_RSP, len,
|
||||
(u8_t *)data, BTA_GATT_AUTH_REQ_NONE);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == ARRAY_SIZE(bt_mesh_gattc_info)) {
|
||||
BT_ERR("%s, Conn is not found", __func__);
|
||||
/** Here we return 0 for prov_send() return value check in provisioner.c
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle);
|
||||
|
||||
BTA_GATTC_WriteCharValue(conn_id, bt_mesh_gattc_info[i].data_in_handle,
|
||||
BTA_GATTC_TYPE_WRITE_NO_RSP, len,
|
||||
(u8_t *)data, BTA_GATT_AUTH_REQ_NONE);
|
||||
|
||||
return 0;
|
||||
BT_ERR("%s, Conn is not found", __func__);
|
||||
return -EEXIST;
|
||||
}
|
||||
|
||||
void bt_mesh_gattc_disconnect(struct bt_mesh_conn *conn)
|
||||
@ -1146,18 +1194,14 @@ void bt_mesh_gattc_disconnect(struct bt_mesh_conn *conn)
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
if (conn == &bt_mesh_gattc_info[i].conn) {
|
||||
break;
|
||||
conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle);
|
||||
BTA_GATTC_Close(conn_id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == ARRAY_SIZE(bt_mesh_gattc_info)) {
|
||||
BT_ERR("%s, Conn is not found", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle);
|
||||
|
||||
BTA_GATTC_Close(conn_id);
|
||||
BT_ERR("%s, Conn is not found", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
/** Mesh Provisioning Service: 0x1827
|
||||
@ -1197,25 +1241,16 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
if (bt_mesh_gattc_info[i].conn.handle == handle) {
|
||||
bt_mesh_gattc_info[i].mtu = p_data->cfg_mtu.mtu;
|
||||
|
||||
/* Search Mesh Provisioning Service or Mesh Proxy Service */
|
||||
tBT_UUID service_uuid = {
|
||||
.len = sizeof(bt_mesh_gattc_info[i].service_uuid),
|
||||
.uu.uuid16 = bt_mesh_gattc_info[i].service_uuid,
|
||||
};
|
||||
BTA_GATTC_ServiceSearchRequest(p_data->cfg_mtu.conn_id, &service_uuid);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/** Once mtu exchanged accomplished, start to find services, and here
|
||||
* need a flag to indicate which service to find(Mesh Prov Service or
|
||||
* Mesh Proxy Service)
|
||||
*/
|
||||
if (i != ARRAY_SIZE(bt_mesh_gattc_info)) {
|
||||
tBT_UUID service_uuid;
|
||||
u16_t conn_id;
|
||||
|
||||
conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle);
|
||||
service_uuid.len = sizeof(bt_mesh_gattc_info[i].service_uuid);
|
||||
service_uuid.uu.uuid16 = bt_mesh_gattc_info[i].service_uuid;
|
||||
|
||||
/* Search Mesh Provisioning Service or Mesh Proxy Service */
|
||||
BTA_GATTC_ServiceSearchRequest(conn_id, &service_uuid);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -1226,17 +1261,14 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
if (bt_mesh_gattc_info[i].conn.handle == handle) {
|
||||
if (p_data->srvc_res.service_uuid.uuid.len == 2 &&
|
||||
p_data->srvc_res.service_uuid.uuid.uu.uuid16 == bt_mesh_gattc_info[i].service_uuid) {
|
||||
bt_mesh_gattc_info[i].start_handle = p_data->srvc_res.start_handle;
|
||||
bt_mesh_gattc_info[i].end_handle = p_data->srvc_res.end_handle;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i != ARRAY_SIZE(bt_mesh_gattc_info)) {
|
||||
if (p_data->srvc_res.service_uuid.uuid.len == 2 &&
|
||||
p_data->srvc_res.service_uuid.uuid.uu.uuid16 == bt_mesh_gattc_info[i].service_uuid) {
|
||||
bt_mesh_gattc_info[i].start_handle = p_data->srvc_res.start_handle;
|
||||
bt_mesh_gattc_info[i].end_handle = p_data->srvc_res.end_handle;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTA_GATTC_SEARCH_CMPL_EVT: {
|
||||
@ -1247,37 +1279,35 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
if (bt_mesh_gattc_info[i].conn.handle == handle) {
|
||||
conn = &bt_mesh_gattc_info[i].conn;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == ARRAY_SIZE(bt_mesh_gattc_info)) {
|
||||
if (conn == NULL) {
|
||||
BT_ERR("%s, Conn handle is not found", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
conn = &bt_mesh_gattc_info[i].conn;
|
||||
|
||||
if (bt_mesh_gattc_info[i].start_handle == 0x00 ||
|
||||
bt_mesh_gattc_info[i].end_handle == 0x00 ||
|
||||
bt_mesh_gattc_info[i].end_handle == 0x00 ||
|
||||
(bt_mesh_gattc_info[i].start_handle > bt_mesh_gattc_info[i].end_handle)) {
|
||||
bt_mesh_gattc_disconnect(conn);
|
||||
return;
|
||||
}
|
||||
|
||||
u16_t notify_en = BLE_MESH_GATT_CCC_NOTIFY;
|
||||
btgatt_db_element_t *result = NULL;
|
||||
tBT_UUID char_uuid = {0};
|
||||
tBTA_GATT_STATUS status;
|
||||
tBTA_GATT_UNFMT write;
|
||||
int count = 0;
|
||||
int num = 0;
|
||||
u16_t conn_id;
|
||||
tBT_UUID char_uuid;
|
||||
btgatt_db_element_t *result = NULL;
|
||||
tBTA_GATT_STATUS status;
|
||||
u16_t notify_en = BLE_MESH_GATT_CCC_NOTIFY;
|
||||
tBTA_GATT_UNFMT write;
|
||||
|
||||
/* Get the characteristic num within Mesh Provisioning/Proxy Service */
|
||||
conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle);
|
||||
BTA_GATTC_GetDBSizeByType(conn_id, BTGATT_DB_CHARACTERISTIC, bt_mesh_gattc_info[i].start_handle,
|
||||
bt_mesh_gattc_info[i].end_handle, BTA_GATTC_INVALID_HANDLE, &count);
|
||||
BTA_GATTC_GetDBSizeByType(p_data->search_cmpl.conn_id, BTGATT_DB_CHARACTERISTIC,
|
||||
bt_mesh_gattc_info[i].start_handle, bt_mesh_gattc_info[i].end_handle,
|
||||
BTA_GATTC_INVALID_HANDLE, &count);
|
||||
if (count != 2) {
|
||||
bt_mesh_gattc_disconnect(conn);
|
||||
return;
|
||||
@ -1295,7 +1325,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
char_uuid.uu.uuid16 = BLE_MESH_UUID_MESH_PROXY_DATA_IN_VAL + j;
|
||||
}
|
||||
|
||||
BTA_GATTC_GetCharByUUID(conn_id, bt_mesh_gattc_info[i].start_handle,
|
||||
BTA_GATTC_GetCharByUUID(p_data->search_cmpl.conn_id, bt_mesh_gattc_info[i].start_handle,
|
||||
bt_mesh_gattc_info[i].end_handle, char_uuid, &result, &num);
|
||||
|
||||
if (!result) {
|
||||
@ -1324,12 +1354,13 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
}
|
||||
bt_mesh_gattc_info[i].data_out_handle = result[0].attribute_handle;
|
||||
}
|
||||
|
||||
osi_free(result);
|
||||
result = NULL;
|
||||
}
|
||||
|
||||
/* Register Notification fot Mesh Provisioning/Proxy Data Out Characteristic */
|
||||
status = BTA_GATTC_RegisterForNotifications(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr,
|
||||
status = BTA_GATTC_RegisterForNotifications(bt_mesh_gattc_if, bt_mesh_gattc_info[i].addr.val,
|
||||
bt_mesh_gattc_info[i].data_out_handle);
|
||||
if (status != BTA_GATT_OK) {
|
||||
bt_mesh_gattc_disconnect(conn);
|
||||
@ -1339,8 +1370,9 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
/** After notification is registered, get descriptor number of the
|
||||
* Mesh Provisioning/Proxy Data Out Characteristic
|
||||
*/
|
||||
BTA_GATTC_GetDBSizeByType(conn_id, BTGATT_DB_DESCRIPTOR, bt_mesh_gattc_info[i].start_handle,
|
||||
bt_mesh_gattc_info[i].end_handle, bt_mesh_gattc_info[i].data_out_handle, &num);
|
||||
BTA_GATTC_GetDBSizeByType(p_data->search_cmpl.conn_id, BTGATT_DB_DESCRIPTOR,
|
||||
bt_mesh_gattc_info[i].start_handle, bt_mesh_gattc_info[i].end_handle,
|
||||
bt_mesh_gattc_info[i].data_out_handle, &num);
|
||||
if (!num) {
|
||||
bt_mesh_gattc_disconnect(conn);
|
||||
return;
|
||||
@ -1349,9 +1381,8 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
/* Get CCC of Mesh Provisioning/Proxy Data Out Characteristic */
|
||||
char_uuid.len = 2;
|
||||
char_uuid.uu.uuid16 = BLE_MESH_UUID_GATT_CCC_VAL;
|
||||
BTA_GATTC_GetDescrByCharHandle(conn_id, bt_mesh_gattc_info[i].data_out_handle,
|
||||
BTA_GATTC_GetDescrByCharHandle(p_data->search_cmpl.conn_id, bt_mesh_gattc_info[i].data_out_handle,
|
||||
char_uuid, &result, &num);
|
||||
|
||||
if (!result) {
|
||||
bt_mesh_gattc_disconnect(conn);
|
||||
return;
|
||||
@ -1370,7 +1401,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
*/
|
||||
write.len = sizeof(notify_en);
|
||||
write.p_value = (u8_t *)¬ify_en;
|
||||
BTA_GATTC_WriteCharDescr(conn_id, result[0].attribute_handle,
|
||||
BTA_GATTC_WriteCharDescr(p_data->search_cmpl.conn_id, result[0].attribute_handle,
|
||||
BTA_GATTC_TYPE_WRITE, &write, BTA_GATT_AUTH_REQ_NONE);
|
||||
|
||||
osi_free(result);
|
||||
@ -1388,17 +1419,16 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
if (bt_mesh_gattc_info[i].conn.handle == handle) {
|
||||
conn = &bt_mesh_gattc_info[i].conn;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == ARRAY_SIZE(bt_mesh_gattc_info)) {
|
||||
if (conn == NULL) {
|
||||
BT_ERR("%s, Conn handle is not found", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
conn = &bt_mesh_gattc_info[i].conn;
|
||||
|
||||
if (bt_mesh_gattc_info[i].ccc_handle != p_data->write.handle) {
|
||||
BT_WARN("%s, gattc ccc_handle is not matched", __func__);
|
||||
bt_mesh_gattc_disconnect(conn);
|
||||
@ -1407,7 +1437,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
|
||||
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_write_descr != NULL) {
|
||||
len = bt_mesh_gattc_conn_cb->prov_write_descr(&bt_mesh_gattc_info[i].conn, bt_mesh_gattc_info[i].addr);
|
||||
len = bt_mesh_gattc_conn_cb->prov_write_descr(&bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn);
|
||||
if (len < 0) {
|
||||
BT_ERR("%s, prov_write_descr failed", __func__);
|
||||
bt_mesh_gattc_disconnect(conn);
|
||||
@ -1417,12 +1447,13 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
}
|
||||
} else if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROXY_VAL) {
|
||||
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->proxy_write_descr != NULL) {
|
||||
len = bt_mesh_gattc_conn_cb->proxy_write_descr(&bt_mesh_gattc_info[i].conn);
|
||||
len = bt_mesh_gattc_conn_cb->proxy_write_descr(&bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn);
|
||||
if (len < 0) {
|
||||
BT_ERR("%s, proxy_write_descr failed", __func__);
|
||||
bt_mesh_gattc_disconnect(conn);
|
||||
return;
|
||||
}
|
||||
bt_mesh_gattc_info[i].wr_desc_done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1435,18 +1466,22 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
if (bt_mesh_gattc_info[i].conn.handle == handle) {
|
||||
if (bt_mesh_gattc_info[i].wr_desc_done == false) {
|
||||
BT_DBG("Receive notification before finishing to write ccc");
|
||||
return;
|
||||
}
|
||||
|
||||
conn = &bt_mesh_gattc_info[i].conn;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == ARRAY_SIZE(bt_mesh_gattc_info)) {
|
||||
if (conn == NULL) {
|
||||
BT_ERR("%s, Conn handle is not found", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
conn = &bt_mesh_gattc_info[i].conn;
|
||||
|
||||
if (memcmp(bt_mesh_gattc_info[i].addr, p_data->notify.bda, BLE_MESH_ADDR_LEN) ||
|
||||
if (memcmp(bt_mesh_gattc_info[i].addr.val, p_data->notify.bda, BLE_MESH_ADDR_LEN) ||
|
||||
bt_mesh_gattc_info[i].data_out_handle != p_data->notify.handle ||
|
||||
p_data->notify.is_notify == false) {
|
||||
BT_ERR("%s, Notification error", __func__);
|
||||
@ -1457,7 +1492,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
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,
|
||||
p_data->notify.value, p_data->notify.len);
|
||||
p_data->notify.value, p_data->notify.len);
|
||||
if (len < 0) {
|
||||
BT_ERR("%s, prov_notify failed", __func__);
|
||||
bt_mesh_gattc_disconnect(conn);
|
||||
@ -1467,7 +1502,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
} else if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROXY_VAL) {
|
||||
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->proxy_notify != NULL) {
|
||||
len = bt_mesh_gattc_conn_cb->proxy_notify(&bt_mesh_gattc_info[i].conn,
|
||||
p_data->notify.value, p_data->notify.len);
|
||||
p_data->notify.value, p_data->notify.len);
|
||||
if (len < 0) {
|
||||
BT_ERR("%s, proxy_notify failed", __func__);
|
||||
bt_mesh_gattc_disconnect(conn);
|
||||
@ -1522,9 +1557,9 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
|
||||
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->connected != NULL) {
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
if (!memcmp(bt_mesh_gattc_info[i].addr, p_data->connect.remote_bda, BLE_MESH_ADDR_LEN)) {
|
||||
if (!memcmp(bt_mesh_gattc_info[i].addr.val, p_data->connect.remote_bda, BLE_MESH_ADDR_LEN)) {
|
||||
bt_mesh_gattc_info[i].conn.handle = BLE_MESH_GATT_GET_CONN_ID(p_data->connect.conn_id);
|
||||
(bt_mesh_gattc_conn_cb->connected)(bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn, i);
|
||||
(bt_mesh_gattc_conn_cb->connected)(&bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -1543,24 +1578,36 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
|
||||
if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->disconnected != NULL) {
|
||||
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
|
||||
if (!memcmp(bt_mesh_gattc_info[i].addr, p_data->disconnect.remote_bda, BLE_MESH_ADDR_LEN)) {
|
||||
if (!memcmp(bt_mesh_gattc_info[i].addr.val, p_data->disconnect.remote_bda, BLE_MESH_ADDR_LEN)) {
|
||||
if (bt_mesh_gattc_info[i].conn.handle == handle) {
|
||||
(bt_mesh_gattc_conn_cb->disconnected)(&bt_mesh_gattc_info[i].conn, p_data->disconnect.reason);
|
||||
(bt_mesh_gattc_conn_cb->disconnected)(&bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn, p_data->disconnect.reason);
|
||||
if (!bt_mesh_gattc_info[i].wr_desc_done) {
|
||||
/* Add this in case connection is established, connected event comes, but
|
||||
* connection is terminated before server->filter_type is set to PROV.
|
||||
*/
|
||||
provisioner_clear_link_conn_info(bt_mesh_gattc_info[i].addr);
|
||||
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
|
||||
if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROV_VAL) {
|
||||
provisioner_clear_link_conn_info(bt_mesh_gattc_info[i].addr.val);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} else {
|
||||
/* Add this in case connection is failed to be established, and here we
|
||||
* need to clear some provision link info, like connecting flag, device
|
||||
* uuid, address info, etc.
|
||||
*/
|
||||
provisioner_clear_link_conn_info(bt_mesh_gattc_info[i].addr);
|
||||
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
|
||||
if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROV_VAL) {
|
||||
provisioner_clear_link_conn_info(bt_mesh_gattc_info[i].addr.val);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
/* Decrease prov pbg_count */
|
||||
provisioner_pbg_count_dec();
|
||||
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
|
||||
if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROV_VAL) {
|
||||
/* Decrease provisioner pbg_count */
|
||||
provisioner_pbg_count_dec();
|
||||
}
|
||||
#endif
|
||||
/* Reset corresponding gattc info */
|
||||
memset(&bt_mesh_gattc_info[i], 0, sizeof(bt_mesh_gattc_info[i]));
|
||||
bt_mesh_gattc_info[i].conn.handle = 0xFFFF;
|
||||
@ -1580,7 +1627,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER */
|
||||
#endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
|
||||
|
||||
struct bt_mesh_conn *bt_mesh_conn_ref(struct bt_mesh_conn *conn)
|
||||
{
|
||||
@ -1610,7 +1657,8 @@ void bt_mesh_gatt_init(void)
|
||||
BTA_GATTS_AppRegister(&app_uuid, bt_mesh_bta_gatts_cb);
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH_PROVISIONER
|
||||
#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 = GATT_DEF_BLE_MTU_SIZE; /* Default MTU_SIZE 23 */
|
||||
@ -1653,25 +1701,29 @@ void bt_mesh_set_private_key(const u8_t pri_key[32])
|
||||
|
||||
const u8_t *bt_mesh_pub_key_get(void)
|
||||
{
|
||||
Point public_key;
|
||||
BT_OCTET32 pri_key;
|
||||
#if 1
|
||||
BT_OCTET32 private_key = {0};
|
||||
Point public_key = {0};
|
||||
|
||||
if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_HAS_PUB_KEY)) {
|
||||
return bt_mesh_public_key;
|
||||
}
|
||||
#else
|
||||
|
||||
/* BLE Mesh BQB test case MESH/NODE/PROV/UPD/BV-12-C requires
|
||||
* different public key for each provisioning procedure.
|
||||
* Note: if enabled, when Provisioner provision multiple devices
|
||||
* at the same time, this may cause invalid confirmation value.
|
||||
*
|
||||
* Use the following code for generating different private key
|
||||
* for each provisioning procedure.
|
||||
*
|
||||
* if (bt_mesh_rand(bt_mesh_private_key, BT_OCTET32_LEN)) {
|
||||
* BT_ERR("%s, Unable to generate bt_mesh_private_key", __func__);
|
||||
* return NULL;
|
||||
* }
|
||||
*/
|
||||
if (bt_mesh_rand(bt_mesh_private_key, 32)) {
|
||||
BT_ERR("%s, Unable to generate bt_mesh_private_key", __func__);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
mem_rcopy(pri_key, bt_mesh_private_key, 32);
|
||||
ECC_PointMult(&public_key, &(curve_p256.G), (DWORD *)pri_key, KEY_LENGTH_DWORDS_P256);
|
||||
|
||||
memcpy(private_key, bt_mesh_private_key, BT_OCTET32_LEN);
|
||||
ECC_PointMult(&public_key, &(curve_p256.G), (DWORD *)private_key, KEY_LENGTH_DWORDS_P256);
|
||||
|
||||
memcpy(bt_mesh_public_key, public_key.x, BT_OCTET32_LEN);
|
||||
memcpy(bt_mesh_public_key + BT_OCTET32_LEN, public_key.y, BT_OCTET32_LEN);
|
||||
@ -1697,29 +1749,26 @@ bool bt_mesh_check_public_key(const u8_t key[64])
|
||||
|
||||
int bt_mesh_dh_key_gen(const u8_t remote_pk[64], bt_mesh_dh_key_cb_t cb, const u8_t idx)
|
||||
{
|
||||
BT_OCTET32 private_key;
|
||||
Point peer_publ_key;
|
||||
Point new_publ_key;
|
||||
BT_OCTET32 dhkey;
|
||||
BT_OCTET32 private_key = {0};
|
||||
Point peer_pub_key = {0};
|
||||
Point new_pub_key = {0};
|
||||
|
||||
BT_DBG("private key = %s", bt_hex(bt_mesh_private_key, BT_OCTET32_LEN));
|
||||
|
||||
mem_rcopy(private_key, bt_mesh_private_key, BT_OCTET32_LEN);
|
||||
memcpy(peer_publ_key.x, remote_pk, BT_OCTET32_LEN);
|
||||
memcpy(peer_publ_key.y, &remote_pk[BT_OCTET32_LEN], BT_OCTET32_LEN);
|
||||
memcpy(private_key, bt_mesh_private_key, BT_OCTET32_LEN);
|
||||
memcpy(peer_pub_key.x, remote_pk, BT_OCTET32_LEN);
|
||||
memcpy(peer_pub_key.y, &remote_pk[BT_OCTET32_LEN], BT_OCTET32_LEN);
|
||||
|
||||
BT_DBG("remote public key x = %s", bt_hex(peer_publ_key.x, BT_OCTET32_LEN));
|
||||
BT_DBG("remote public key y = %s", bt_hex(peer_publ_key.y, BT_OCTET32_LEN));
|
||||
BT_DBG("remote public key x = %s", bt_hex(peer_pub_key.x, BT_OCTET32_LEN));
|
||||
BT_DBG("remote public key y = %s", bt_hex(peer_pub_key.y, BT_OCTET32_LEN));
|
||||
|
||||
ECC_PointMult(&new_publ_key, &peer_publ_key, (DWORD *) private_key, KEY_LENGTH_DWORDS_P256);
|
||||
ECC_PointMult(&new_pub_key, &peer_pub_key, (DWORD *)private_key, KEY_LENGTH_DWORDS_P256);
|
||||
|
||||
memcpy(dhkey, new_publ_key.x, BT_OCTET32_LEN);
|
||||
|
||||
BT_DBG("new public key x = %s", bt_hex(new_publ_key.x, 32));
|
||||
BT_DBG("new public key y = %s", bt_hex(new_publ_key.y, 32));
|
||||
BT_DBG("new public key x = %s", bt_hex(new_pub_key.x, 32));
|
||||
BT_DBG("new public key y = %s", bt_hex(new_pub_key.y, 32));
|
||||
|
||||
if (cb != NULL) {
|
||||
cb((const u8_t *)dhkey, idx);
|
||||
cb((const u8_t *)new_pub_key.x, idx);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -1835,7 +1884,7 @@ int bt_mesh_update_exceptional_list(u8_t sub_code, u8_t type, void *info)
|
||||
BD_ADDR value = {0};
|
||||
|
||||
if ((sub_code > BLE_MESH_EXCEP_LIST_CLEAN) ||
|
||||
(type > BLE_MESH_EXCEP_INFO_MESH_PROXY_ADV)) {
|
||||
(type > BLE_MESH_EXCEP_INFO_MESH_PROXY_ADV)) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
@ -1845,7 +1894,7 @@ int bt_mesh_update_exceptional_list(u8_t sub_code, u8_t type, void *info)
|
||||
BT_ERR("%s, NULL Provisioning Link ID", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
memcpy(value, info, sizeof(u32_t));
|
||||
sys_memcpy_swap(value, info, sizeof(u32_t));
|
||||
}
|
||||
|
||||
BT_DBG("%s, %s type 0x%x", __func__, sub_code ? "Remove" : "Add", type);
|
@ -12,6 +12,7 @@
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "osi/allocator.h"
|
||||
#include "osi/mutex.h"
|
||||
#include "sdkconfig.h"
|
||||
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL)
|
||||
|
||||
@ -82,36 +83,50 @@ static const bt_mesh_client_op_pair_t cfg_op_pair[] = {
|
||||
{ OP_NET_TRANSMIT_SET, OP_NET_TRANSMIT_STATUS },
|
||||
};
|
||||
|
||||
static osi_mutex_t cfg_client_mutex;
|
||||
|
||||
static void bt_mesh_cfg_client_mutex_new(void)
|
||||
{
|
||||
static bool init;
|
||||
|
||||
if (!init) {
|
||||
osi_mutex_new(&cfg_client_mutex);
|
||||
init = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void bt_mesh_cfg_client_lock(void)
|
||||
{
|
||||
osi_mutex_lock(&cfg_client_mutex, OSI_MUTEX_MAX_TIMEOUT);
|
||||
}
|
||||
|
||||
static void bt_mesh_cfg_client_unlock(void)
|
||||
{
|
||||
osi_mutex_unlock(&cfg_client_mutex);
|
||||
}
|
||||
|
||||
static void timeout_handler(struct k_work *work)
|
||||
{
|
||||
config_internal_data_t *internal = NULL;
|
||||
bt_mesh_config_client_t *client = NULL;
|
||||
struct k_delayed_work *timer = NULL;
|
||||
bt_mesh_client_node_t *node = NULL;
|
||||
|
||||
BT_WARN("Receive configuration status message timeout");
|
||||
|
||||
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
|
||||
if (!node || !node->ctx.model) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
bt_mesh_cfg_client_lock();
|
||||
|
||||
timer = CONTAINER_OF(work, struct k_delayed_work, work);
|
||||
|
||||
if (timer && !k_delayed_work_free(timer)) {
|
||||
node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
|
||||
if (node) {
|
||||
bt_mesh_config_client_cb_evt_to_btc(node->opcode,
|
||||
BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT, node->ctx.model, &node->ctx, NULL, 0);
|
||||
// Don't forget to release the node at the end.
|
||||
bt_mesh_client_free_node(node);
|
||||
}
|
||||
}
|
||||
|
||||
client = (bt_mesh_config_client_t *)node->ctx.model->user_data;
|
||||
if (!client) {
|
||||
BT_ERR("%s, Config Client user_data is NULL", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
internal = (config_internal_data_t *)client->internal_data;
|
||||
if (!internal) {
|
||||
BT_ERR("%s, Config Client internal_data is NULL", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_callback_config_status_to_btc(node->opcode, 0x03, node->ctx.model,
|
||||
&node->ctx, NULL, 0);
|
||||
|
||||
bt_mesh_client_free_node(&internal->queue, node);
|
||||
bt_mesh_cfg_client_unlock();
|
||||
|
||||
return;
|
||||
}
|
||||
@ -120,7 +135,6 @@ static void cfg_client_cancel(struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
void *status, size_t len)
|
||||
{
|
||||
config_internal_data_t *data = NULL;
|
||||
bt_mesh_client_node_t *node = NULL;
|
||||
struct net_buf_simple buf = {0};
|
||||
u8_t evt_type = 0xFF;
|
||||
@ -130,16 +144,13 @@ static void cfg_client_cancel(struct bt_mesh_model *model,
|
||||
return;
|
||||
}
|
||||
|
||||
data = (config_internal_data_t *)cli->internal_data;
|
||||
if (!data) {
|
||||
BT_ERR("%s, Config Client internal_data is NULL", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
/* If it is a publish message, sent to the user directly. */
|
||||
buf.data = (u8_t *)status;
|
||||
buf.len = (u16_t)len;
|
||||
node = bt_mesh_is_model_message_publish(model, ctx, &buf, true);
|
||||
|
||||
bt_mesh_cfg_client_lock();
|
||||
|
||||
node = bt_mesh_is_client_recv_publish_msg(model, ctx, &buf, true);
|
||||
if (!node) {
|
||||
BT_DBG("Unexpected config status message 0x%x", ctx->recv_op);
|
||||
} else {
|
||||
@ -163,7 +174,7 @@ static void cfg_client_cancel(struct bt_mesh_model *model,
|
||||
case OP_HEARTBEAT_SUB_GET:
|
||||
case OP_LPN_TIMEOUT_GET:
|
||||
case OP_NET_TRANSMIT_GET:
|
||||
evt_type = 0x00;
|
||||
evt_type = BTC_BLE_MESH_EVT_CONFIG_CLIENT_GET_STATE;
|
||||
break;
|
||||
case OP_BEACON_SET:
|
||||
case OP_DEFAULT_TTL_SET:
|
||||
@ -193,18 +204,22 @@ static void cfg_client_cancel(struct bt_mesh_model *model,
|
||||
case OP_HEARTBEAT_PUB_SET:
|
||||
case OP_HEARTBEAT_SUB_SET:
|
||||
case OP_NET_TRANSMIT_SET:
|
||||
evt_type = 0x01;
|
||||
evt_type = BTC_BLE_MESH_EVT_CONFIG_CLIENT_SET_STATE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
bt_mesh_callback_config_status_to_btc(node->opcode, evt_type, model,
|
||||
ctx, (const u8_t *)status, len);
|
||||
// Don't forget to release the node at the end.
|
||||
bt_mesh_client_free_node(&data->queue, node);
|
||||
if (!k_delayed_work_free(&node->timer)) {
|
||||
bt_mesh_config_client_cb_evt_to_btc(
|
||||
node->opcode, evt_type, model, ctx, (const u8_t *)status, len);
|
||||
// Don't forget to release the node at the end.
|
||||
bt_mesh_client_free_node(node);
|
||||
}
|
||||
}
|
||||
|
||||
bt_mesh_cfg_client_unlock();
|
||||
|
||||
switch (ctx->recv_op) {
|
||||
case OP_DEV_COMP_DATA_STATUS: {
|
||||
struct bt_mesh_cfg_comp_data_status *val;
|
||||
@ -1653,5 +1668,7 @@ int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary)
|
||||
/* Configuration Model security is device-key based */
|
||||
model->keys[0] = BLE_MESH_KEY_DEV;
|
||||
|
||||
bt_mesh_cfg_client_mutex_new();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include "crypto.h"
|
||||
#include "access.h"
|
||||
#include "beacon.h"
|
||||
#include "proxy.h"
|
||||
#include "proxy_server.h"
|
||||
#include "foundation.h"
|
||||
#include "friend.h"
|
||||
#include "settings.h"
|
||||
@ -53,55 +53,6 @@ static struct label {
|
||||
u8_t uuid[16];
|
||||
} labels[CONFIG_BLE_MESH_LABEL_COUNT];
|
||||
|
||||
static void hb_send(struct bt_mesh_model *model)
|
||||
{
|
||||
struct bt_mesh_cfg_srv *cfg = model->user_data;
|
||||
u16_t feat = 0U;
|
||||
struct __packed {
|
||||
u8_t init_ttl;
|
||||
u16_t feat;
|
||||
} hb;
|
||||
struct bt_mesh_msg_ctx ctx = {
|
||||
.net_idx = cfg->hb_pub.net_idx,
|
||||
.app_idx = BLE_MESH_KEY_UNUSED,
|
||||
.addr = cfg->hb_pub.dst,
|
||||
.send_ttl = cfg->hb_pub.ttl,
|
||||
};
|
||||
struct bt_mesh_net_tx tx = {
|
||||
.sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx),
|
||||
.ctx = &ctx,
|
||||
.src = bt_mesh_model_elem(model)->addr,
|
||||
.xmit = bt_mesh_net_transmit_get(),
|
||||
};
|
||||
|
||||
hb.init_ttl = cfg->hb_pub.ttl;
|
||||
|
||||
if (bt_mesh_relay_get() == BLE_MESH_RELAY_ENABLED) {
|
||||
feat |= BLE_MESH_FEAT_RELAY;
|
||||
}
|
||||
|
||||
if (bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED) {
|
||||
feat |= BLE_MESH_FEAT_PROXY;
|
||||
}
|
||||
|
||||
if (bt_mesh_friend_get() == BLE_MESH_FRIEND_ENABLED) {
|
||||
feat |= BLE_MESH_FEAT_FRIEND;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_LOW_POWER)
|
||||
if (bt_mesh.lpn.state != BLE_MESH_LPN_DISABLED) {
|
||||
feat |= BLE_MESH_FEAT_LOW_POWER;
|
||||
}
|
||||
#endif
|
||||
|
||||
hb.feat = sys_cpu_to_be16(feat);
|
||||
|
||||
BT_DBG("InitTTL %u feat 0x%04x", cfg->hb_pub.ttl, feat);
|
||||
|
||||
bt_mesh_ctl_send(&tx, TRANS_CTL_OP_HEARTBEAT, &hb, sizeof(hb),
|
||||
NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
static int comp_add_elem(struct net_buf_simple *buf, struct bt_mesh_elem *elem,
|
||||
bool primary)
|
||||
{
|
||||
@ -145,7 +96,7 @@ static int comp_get_page_0(struct net_buf_simple *buf)
|
||||
feat |= BLE_MESH_FEAT_RELAY;
|
||||
}
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) {
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
|
||||
feat |= BLE_MESH_FEAT_PROXY;
|
||||
}
|
||||
|
||||
@ -521,10 +472,14 @@ static void app_key_add(struct bt_mesh_model *model,
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(CONFIG_BLE_MESH_FAST_PROV)
|
||||
bt_mesh_callback_cfg_server_event_to_btc(0x0, model, ctx,
|
||||
(u8_t *)&key_app_idx, sizeof(u16_t));
|
||||
#endif
|
||||
if (status == STATUS_SUCCESS) {
|
||||
bt_mesh_cfg_server_state_change_t change = {0};
|
||||
change.cfg_appkey_add.net_idx = key_net_idx;
|
||||
change.cfg_appkey_add.app_idx = key_app_idx;
|
||||
memcpy(change.cfg_appkey_add.app_key, buf->data, 16);
|
||||
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
|
||||
model, ctx, (const u8_t *)&change, sizeof(change));
|
||||
}
|
||||
}
|
||||
|
||||
static void app_key_update(struct bt_mesh_model *model,
|
||||
@ -550,6 +505,15 @@ static void app_key_update(struct bt_mesh_model *model,
|
||||
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
|
||||
BT_ERR("%s, Unable to send Config AppKey Status", __func__);
|
||||
}
|
||||
|
||||
if (status == STATUS_SUCCESS) {
|
||||
bt_mesh_cfg_server_state_change_t change = {0};
|
||||
change.cfg_appkey_update.net_idx = key_net_idx;
|
||||
change.cfg_appkey_update.app_idx = key_app_idx;
|
||||
memcpy(change.cfg_appkey_update.app_key, buf->data, 16);
|
||||
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
|
||||
model, ctx, (const u8_t *)&change, sizeof(change));
|
||||
}
|
||||
}
|
||||
|
||||
struct unbind_data {
|
||||
@ -626,6 +590,14 @@ send_status:
|
||||
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
|
||||
BT_ERR("%s, Unable to send Config AppKey Status", __func__);
|
||||
}
|
||||
|
||||
if (status == STATUS_SUCCESS) {
|
||||
bt_mesh_cfg_server_state_change_t change = {0};
|
||||
change.cfg_appkey_delete.net_idx = key_net_idx;
|
||||
change.cfg_appkey_delete.app_idx = key_app_idx;
|
||||
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
|
||||
model, ctx, (const u8_t *)&change, sizeof(change));
|
||||
}
|
||||
}
|
||||
|
||||
/* Index list length: 3 bytes for every pair and 2 bytes for an odd idx */
|
||||
@ -836,7 +808,6 @@ static void gatt_proxy_set(struct bt_mesh_model *model,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_cfg_srv *cfg = model->user_data;
|
||||
struct bt_mesh_subnet *sub;
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
||||
@ -847,7 +818,7 @@ static void gatt_proxy_set(struct bt_mesh_model *model,
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) ||
|
||||
if (!IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) ||
|
||||
bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_NOT_SUPPORTED) {
|
||||
goto send_status;
|
||||
}
|
||||
@ -895,9 +866,8 @@ static void gatt_proxy_set(struct bt_mesh_model *model,
|
||||
bt_mesh_adv_update();
|
||||
#endif
|
||||
|
||||
sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx);
|
||||
if ((cfg->hb_pub.feat & BLE_MESH_FEAT_PROXY) && sub) {
|
||||
hb_send(model);
|
||||
if (cfg->hb_pub.feat & BLE_MESH_FEAT_PROXY) {
|
||||
bt_mesh_heartbeat_send();
|
||||
}
|
||||
|
||||
send_status:
|
||||
@ -992,7 +962,6 @@ static void relay_set(struct bt_mesh_model *model,
|
||||
if (!cfg) {
|
||||
BT_WARN("No Configuration Server context available");
|
||||
} else if (buf->data[0] == 0x00 || buf->data[0] == 0x01) {
|
||||
struct bt_mesh_subnet *sub;
|
||||
bool change;
|
||||
|
||||
if (cfg->relay == BLE_MESH_RELAY_NOT_SUPPORTED) {
|
||||
@ -1013,9 +982,8 @@ static void relay_set(struct bt_mesh_model *model,
|
||||
BLE_MESH_TRANSMIT_COUNT(cfg->relay_retransmit),
|
||||
BLE_MESH_TRANSMIT_INT(cfg->relay_retransmit));
|
||||
|
||||
sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx);
|
||||
if ((cfg->hb_pub.feat & BLE_MESH_FEAT_RELAY) && sub && change) {
|
||||
hb_send(model);
|
||||
if ((cfg->hb_pub.feat & BLE_MESH_FEAT_RELAY) && change) {
|
||||
bt_mesh_heartbeat_send();
|
||||
}
|
||||
} else {
|
||||
BT_WARN("Invalid Relay value 0x%02x", buf->data[0]);
|
||||
@ -1177,6 +1145,21 @@ static void mod_pub_set(struct bt_mesh_model *model,
|
||||
send_status:
|
||||
send_mod_pub_status(model, ctx, elem_addr, pub_addr, vnd, mod,
|
||||
status, mod_id);
|
||||
|
||||
if (status == STATUS_SUCCESS && mod->pub) {
|
||||
bt_mesh_cfg_server_state_change_t change = {0};
|
||||
change.cfg_mod_pub_set.elem_addr = elem_addr;
|
||||
change.cfg_mod_pub_set.pub_addr = mod->pub->addr;
|
||||
change.cfg_mod_pub_set.app_idx = mod->pub->key;
|
||||
change.cfg_mod_pub_set.cred_flag = mod->pub->cred;
|
||||
change.cfg_mod_pub_set.ttl = mod->pub->ttl;
|
||||
change.cfg_mod_pub_set.period = mod->pub->period;
|
||||
change.cfg_mod_pub_set.transmit = mod->pub->retransmit;
|
||||
change.cfg_mod_pub_set.cid = vnd ? mod->vnd.company : 0xFFFF;
|
||||
change.cfg_mod_pub_set.mod_id = vnd ? mod->vnd.id : mod->id;
|
||||
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
|
||||
model, ctx, (const u8_t *)&change, sizeof(change));
|
||||
}
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_LABEL_COUNT > 0
|
||||
@ -1500,6 +1483,16 @@ static void mod_sub_add(struct bt_mesh_model *model,
|
||||
send_status:
|
||||
send_mod_sub_status(model, ctx, status, elem_addr, sub_addr,
|
||||
mod_id, vnd);
|
||||
|
||||
if (status == STATUS_SUCCESS) {
|
||||
bt_mesh_cfg_server_state_change_t change = {0};
|
||||
change.cfg_mod_sub_add.elem_addr = elem_addr;
|
||||
change.cfg_mod_sub_add.sub_addr = sub_addr;
|
||||
change.cfg_mod_sub_add.cid = vnd ? mod->vnd.company : 0xFFFF;
|
||||
change.cfg_mod_sub_add.mod_id = vnd ? mod->vnd.id : mod->id;
|
||||
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
|
||||
model, ctx, (const u8_t *)&change, sizeof(change));
|
||||
}
|
||||
}
|
||||
|
||||
static void mod_sub_del(struct bt_mesh_model *model,
|
||||
@ -1566,6 +1559,16 @@ static void mod_sub_del(struct bt_mesh_model *model,
|
||||
send_status:
|
||||
send_mod_sub_status(model, ctx, status, elem_addr, sub_addr,
|
||||
mod_id, vnd);
|
||||
|
||||
if (status == STATUS_SUCCESS) {
|
||||
bt_mesh_cfg_server_state_change_t change = {0};
|
||||
change.cfg_mod_sub_delete.elem_addr = elem_addr;
|
||||
change.cfg_mod_sub_delete.sub_addr = sub_addr;
|
||||
change.cfg_mod_sub_delete.cid = vnd ? mod->vnd.company : 0xFFFF;
|
||||
change.cfg_mod_sub_delete.mod_id = vnd ? mod->vnd.id : mod->id;
|
||||
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
|
||||
model, ctx, (const u8_t *)&change, sizeof(change));
|
||||
}
|
||||
}
|
||||
|
||||
static void mod_sub_overwrite(struct bt_mesh_model *model,
|
||||
@ -2219,7 +2222,7 @@ static void net_key_add(struct bt_mesh_model *model,
|
||||
/* Make sure we have valid beacon data to be sent */
|
||||
bt_mesh_net_beacon_update(sub);
|
||||
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) {
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
|
||||
sub->node_id = BLE_MESH_NODE_IDENTITY_STOPPED;
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
bt_mesh_proxy_beacon_send(sub);
|
||||
@ -2230,6 +2233,12 @@ static void net_key_add(struct bt_mesh_model *model,
|
||||
}
|
||||
|
||||
send_net_key_status(model, ctx, idx, STATUS_SUCCESS);
|
||||
|
||||
bt_mesh_cfg_server_state_change_t change = {0};
|
||||
change.cfg_netkey_add.net_idx = sub->net_idx;
|
||||
memcpy(change.cfg_netkey_add.net_key, sub->keys[0].net, 16);
|
||||
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
|
||||
model, ctx, (const u8_t *)&change, sizeof(change));
|
||||
}
|
||||
|
||||
static void net_key_update(struct bt_mesh_model *model,
|
||||
@ -2299,6 +2308,12 @@ static void net_key_update(struct bt_mesh_model *model,
|
||||
bt_mesh_net_beacon_update(sub);
|
||||
|
||||
send_net_key_status(model, ctx, idx, STATUS_SUCCESS);
|
||||
|
||||
bt_mesh_cfg_server_state_change_t change = {0};
|
||||
change.cfg_netkey_update.net_idx = sub->net_idx;
|
||||
memcpy(change.cfg_netkey_update.net_key, sub->keys[1].net, 16);
|
||||
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
|
||||
model, ctx, (const u8_t *)&change, sizeof(change));
|
||||
}
|
||||
|
||||
static void hb_pub_disable(struct bt_mesh_cfg_srv *cfg)
|
||||
@ -2351,6 +2366,13 @@ static void net_key_del(struct bt_mesh_model *model,
|
||||
|
||||
send_status:
|
||||
send_net_key_status(model, ctx, del_idx, status);
|
||||
|
||||
if (status == STATUS_SUCCESS) {
|
||||
bt_mesh_cfg_server_state_change_t change = {0};
|
||||
change.cfg_netkey_delete.net_idx = sub->net_idx;
|
||||
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
|
||||
model, ctx, (const u8_t *)&change, sizeof(change));
|
||||
}
|
||||
}
|
||||
|
||||
static void net_key_get(struct bt_mesh_model *model,
|
||||
@ -2469,7 +2491,7 @@ static void node_identity_set(struct bt_mesh_model *model,
|
||||
* 0x00, the Node Identity state for all subnets shall be set
|
||||
* to 0x00 and shall not be changed."
|
||||
*/
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) &&
|
||||
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) &&
|
||||
bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED) {
|
||||
if (node_id) {
|
||||
bt_mesh_proxy_identity_start(sub);
|
||||
@ -2556,6 +2578,16 @@ send_status:
|
||||
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
|
||||
BT_ERR("%s, Unable to send Config Model App Bind Status", __func__);
|
||||
}
|
||||
|
||||
if (status == STATUS_SUCCESS) {
|
||||
bt_mesh_cfg_server_state_change_t change = {0};
|
||||
change.cfg_mod_app_bind.elem_addr = elem_addr;
|
||||
change.cfg_mod_app_bind.app_idx = key_app_idx;
|
||||
change.cfg_mod_app_bind.cid = vnd ? mod->vnd.company : 0xFFFF;
|
||||
change.cfg_mod_app_bind.mod_id = vnd ? mod->vnd.id : mod->id;
|
||||
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
|
||||
model, ctx, (const u8_t *)&change, sizeof(change));
|
||||
}
|
||||
}
|
||||
|
||||
static void mod_app_unbind(struct bt_mesh_model *model,
|
||||
@ -2602,6 +2634,16 @@ send_status:
|
||||
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
|
||||
BT_ERR("%s, Unable to send Config Model App Unbind Status", __func__);
|
||||
}
|
||||
|
||||
if (status == STATUS_SUCCESS) {
|
||||
bt_mesh_cfg_server_state_change_t change = {0};
|
||||
change.cfg_mod_app_unbind.elem_addr = elem_addr;
|
||||
change.cfg_mod_app_unbind.app_idx = key_app_idx;
|
||||
change.cfg_mod_app_unbind.cid = vnd ? mod->vnd.company : 0xFFFF;
|
||||
change.cfg_mod_app_unbind.mod_id = vnd ? mod->vnd.id : mod->id;
|
||||
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
|
||||
model, ctx, (const u8_t *)&change, sizeof(change));
|
||||
}
|
||||
}
|
||||
|
||||
#define KEY_LIST_LEN (CONFIG_BLE_MESH_MODEL_KEY_COUNT * 2)
|
||||
@ -2731,7 +2773,6 @@ static void friend_set(struct bt_mesh_model *model,
|
||||
struct net_buf_simple *buf)
|
||||
{
|
||||
struct bt_mesh_cfg_srv *cfg = model->user_data;
|
||||
struct bt_mesh_subnet *sub;
|
||||
|
||||
BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s",
|
||||
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
|
||||
@ -2765,9 +2806,8 @@ static void friend_set(struct bt_mesh_model *model,
|
||||
}
|
||||
}
|
||||
|
||||
sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx);
|
||||
if ((cfg->hb_pub.feat & BLE_MESH_FEAT_FRIEND) && sub) {
|
||||
hb_send(model);
|
||||
if (cfg->hb_pub.feat & BLE_MESH_FEAT_FRIEND) {
|
||||
bt_mesh_heartbeat_send();
|
||||
}
|
||||
|
||||
send_status:
|
||||
@ -2912,6 +2952,12 @@ static void krp_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx,
|
||||
}
|
||||
|
||||
send_krp_status(model, ctx, idx, sub->kr_phase, STATUS_SUCCESS);
|
||||
|
||||
bt_mesh_cfg_server_state_change_t change = {0};
|
||||
change.cfg_kr_phase_set.net_idx = idx;
|
||||
change.cfg_kr_phase_set.kr_phase = phase;
|
||||
bt_mesh_config_server_cb_evt_to_btc(BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE,
|
||||
model, ctx, (const u8_t *)&change, sizeof(change));
|
||||
}
|
||||
|
||||
static u8_t hb_log(u16_t val)
|
||||
@ -3121,15 +3167,10 @@ static void hb_sub_send_status(struct bt_mesh_model *model,
|
||||
net_buf_simple_add_u8(&msg, status);
|
||||
net_buf_simple_add_le16(&msg, cfg->hb_sub.src);
|
||||
net_buf_simple_add_le16(&msg, cfg->hb_sub.dst);
|
||||
if (cfg->hb_sub.src == BLE_MESH_ADDR_UNASSIGNED ||
|
||||
cfg->hb_sub.dst == BLE_MESH_ADDR_UNASSIGNED) {
|
||||
memset(net_buf_simple_add(&msg, 4), 0, 4);
|
||||
} else {
|
||||
net_buf_simple_add_u8(&msg, hb_log(period));
|
||||
net_buf_simple_add_u8(&msg, hb_log(cfg->hb_sub.count));
|
||||
net_buf_simple_add_u8(&msg, cfg->hb_sub.min_hops);
|
||||
net_buf_simple_add_u8(&msg, cfg->hb_sub.max_hops);
|
||||
}
|
||||
net_buf_simple_add_u8(&msg, hb_log(period));
|
||||
net_buf_simple_add_u8(&msg, hb_log(cfg->hb_sub.count));
|
||||
net_buf_simple_add_u8(&msg, cfg->hb_sub.min_hops);
|
||||
net_buf_simple_add_u8(&msg, cfg->hb_sub.max_hops);
|
||||
|
||||
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
|
||||
BT_ERR("%s, Unable to send Config Heartbeat Subscription Status", __func__);
|
||||
@ -3188,9 +3229,13 @@ static void heartbeat_sub_set(struct bt_mesh_model *model,
|
||||
* trigger clearing of the values according to
|
||||
* MESH/NODE/CFG/HBS/BV-02-C.
|
||||
*/
|
||||
if (cfg->hb_sub.src != sub_src || cfg->hb_sub.dst != sub_dst) {
|
||||
if (sub_src == BLE_MESH_ADDR_UNASSIGNED ||
|
||||
sub_dst == BLE_MESH_ADDR_UNASSIGNED) {
|
||||
cfg->hb_sub.src = BLE_MESH_ADDR_UNASSIGNED;
|
||||
cfg->hb_sub.dst = BLE_MESH_ADDR_UNASSIGNED;
|
||||
cfg->hb_sub.min_hops = BLE_MESH_TTL_MAX;
|
||||
cfg->hb_sub.max_hops = 0U;
|
||||
cfg->hb_sub.count = 0U;
|
||||
}
|
||||
|
||||
period_ms = 0;
|
||||
@ -3280,7 +3325,6 @@ static void hb_publish(struct k_work *work)
|
||||
struct bt_mesh_cfg_srv *cfg = CONTAINER_OF(work,
|
||||
struct bt_mesh_cfg_srv,
|
||||
hb_pub.timer.work);
|
||||
struct bt_mesh_model *model = cfg->model;
|
||||
struct bt_mesh_subnet *sub;
|
||||
u16_t period_ms;
|
||||
|
||||
@ -3303,7 +3347,7 @@ static void hb_publish(struct k_work *work)
|
||||
k_delayed_work_submit(&cfg->hb_pub.timer, period_ms);
|
||||
}
|
||||
|
||||
hb_send(model);
|
||||
bt_mesh_heartbeat_send();
|
||||
|
||||
if (cfg->hb_pub.count != 0xffff) {
|
||||
cfg->hb_pub.count--;
|
||||
@ -3352,7 +3396,7 @@ int bt_mesh_cfg_srv_init(struct bt_mesh_model *model, bool primary)
|
||||
cfg->frnd = BLE_MESH_FRIEND_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
if (!IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) {
|
||||
if (!IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
|
||||
cfg->gatt_proxy = BLE_MESH_GATT_PROXY_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
@ -261,7 +261,7 @@ static int bt_mesh_ccm_decrypt(const u8_t key[16], u8_t nonce[13],
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < aad_len; i++, j++) {
|
||||
for (; i < aad_len; i++, j++) {
|
||||
pmsg[i] = Xn[i] ^ aad[j];
|
||||
}
|
||||
|
||||
@ -425,7 +425,7 @@ static int bt_mesh_ccm_encrypt(const u8_t key[16], u8_t nonce[13],
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < aad_len; i++, j++) {
|
||||
for (; i < aad_len; i++, j++) {
|
||||
pmsg[i] = Xn[i] ^ aad[j];
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user