forked from espressif/esp-idf
Compare commits
1666 Commits
Author | SHA1 | Date | |
---|---|---|---|
c198f34f48 | |||
e17cdbf2fb | |||
c7b83717b0 | |||
31594a0ae5 | |||
2fd3f8e076 | |||
865453bbe5 | |||
b60af85f98 | |||
d75cb43257 | |||
e1b0e367f5 | |||
2be0def9b5 | |||
b681d4e415 | |||
8f7f429488 | |||
ab830517bf | |||
9c897ef280 | |||
c69ceefb27 | |||
47a5ef0b56 | |||
1f1de86ed9 | |||
1738f01c10 | |||
66e45d143b | |||
f8997beb0d | |||
1b792c4687 | |||
c6897a43ce | |||
9d82fc4447 | |||
62034d4432 | |||
9bd41e2431 | |||
7a8c9d88e9 | |||
da8f10bbac | |||
97c8be7194 | |||
1e9367f48e | |||
de3a428985 | |||
cd961e7fff | |||
f5db736aa6 | |||
1ea2b57b41 | |||
5e2fceafa6 | |||
fb9f140fa5 | |||
51ee6e482e | |||
004ea31cb7 | |||
6980b57a97 | |||
e0c2145cc7 | |||
e2526915b7 | |||
14e6b55923 | |||
620049646d | |||
16898897a9 | |||
9aecaa6fd0 | |||
bf341d966c | |||
b9d288879d | |||
23aff378f4 | |||
ffefe603ae | |||
8c6ec0bd48 | |||
8ef0017662 | |||
0d5ec69adc | |||
ac5511972f | |||
4dab171c9f | |||
d8ef56e630 | |||
27fe437412 | |||
bfcaa64b49 | |||
41c82efcb9 | |||
cb1a17e7ce | |||
c97984de99 | |||
45ee699eae | |||
4c453660ae | |||
fd1a67dd61 | |||
1f76c9014b | |||
84f3d3e69a | |||
afb5248ec8 | |||
b1e5705bbd | |||
5438706922 | |||
cd99f0856c | |||
7180526645 | |||
b9ca1e9b48 | |||
d7612c14c9 | |||
a22cd6f542 | |||
1f075dc346 | |||
9daeddac0b | |||
4789575f49 | |||
dc433b50b0 | |||
069182853e | |||
911cc3710b | |||
a1f743772f | |||
74b48f1df7 | |||
935deb4082 | |||
1e84e87f7f | |||
27a3d44f68 | |||
381f2008ac | |||
3e664c8a80 | |||
7b9f8c0e8c | |||
90a763b5a8 | |||
eb36b63e7d | |||
cf5d810bae | |||
a81a6c5471 | |||
c08d81a91f | |||
7e0abf78f9 | |||
8d1a99e026 | |||
e836297b55 | |||
10785bc1e4 | |||
7c6ada7f86 | |||
931577bc11 | |||
ee15d4c3af | |||
998b67094b | |||
bb2ce2cb4e | |||
97b6b435a8 | |||
c8906224fd | |||
fe3fd4d561 | |||
89568b73d6 | |||
fd91bf4500 | |||
f99c367e5d | |||
fa34265c4b | |||
1ddac24b0a | |||
c0a586bdea | |||
4ae45ff756 | |||
3c3eab0bd8 | |||
2a63d1058e | |||
3a12c7ee8d | |||
3319702355 | |||
7c53e88b05 | |||
5b5a36a7b2 | |||
6aa902c509 | |||
bf9587132b | |||
83bda9f63e | |||
bd3de5c295 | |||
f01bfeddb9 | |||
ba35834ec8 | |||
98116a627e | |||
842a55cda3 | |||
97a0523b34 | |||
5241d68bf4 | |||
b1a5c00ee7 | |||
e1af1fe126 | |||
4f06532e80 | |||
966e45598b | |||
49e26e05e9 | |||
0f1801d6b4 | |||
d3f11b1e9d | |||
538117a904 | |||
3a0652602a | |||
b79fc8271f | |||
b8afe13b3a | |||
099daf7873 | |||
932ac7abf1 | |||
2ac583cd12 | |||
db84ddc82f | |||
6eb2b46592 | |||
f50680310e | |||
3d6b03d98c | |||
f4cadc56c0 | |||
13756c6a55 | |||
1b3ac526a7 | |||
9a8dbbc281 | |||
b8520d0c9c | |||
492297339c | |||
189c04279c | |||
7355493a35 | |||
57ff3f92a5 | |||
63685a3a40 | |||
da66ddd4c1 | |||
cc9d0e1e99 | |||
72b35dec11 | |||
ffe4d844bf | |||
f417181e62 | |||
9a29375f7d | |||
22ca7adccb | |||
f9ec761215 | |||
544fa05bd1 | |||
9fe035e4f5 | |||
dcd6e82826 | |||
97631de46c | |||
2a82c353d9 | |||
e17a8e1904 | |||
b63bbedc65 | |||
13b0633e8d | |||
fe5c9bb03e | |||
a418a52ea1 | |||
75b10c80ff | |||
12b6656d90 | |||
c1215f27ed | |||
92f41b098b | |||
92aed6c759 | |||
c6db3a426a | |||
97649c45eb | |||
6d5bb47512 | |||
7e839a82de | |||
02ce0744f0 | |||
f60c8c8164 | |||
c3f3dda7df | |||
a92185263e | |||
3a535daa8c | |||
9ed4215787 | |||
3826b80f3a | |||
9933037c0d | |||
f946e296a2 | |||
90cdceac39 | |||
2da1f2059e | |||
7638d92400 | |||
a395f3592b | |||
e71033b6ee | |||
44b47f79e1 | |||
b7c4925d0b | |||
69084bafec | |||
056890a41a | |||
0d1da69fb3 | |||
997ac7e166 | |||
21d2fa6934 | |||
645b200d73 | |||
a38bbe46d0 | |||
6f788a81dd | |||
2750bb8e16 | |||
150910ccd8 | |||
450f99f0f9 | |||
8dabab4e36 | |||
fe3ec246c0 | |||
c277240dc6 | |||
4403af7267 | |||
d6d7a2ad12 | |||
cffcac6106 | |||
6bd7cadc7b | |||
c10fd0edb2 | |||
29422884d8 | |||
efcb1959bc | |||
396cc61bab | |||
b8c1824e37 | |||
1750acfa17 | |||
bf86c59ec4 | |||
ff084d86b2 | |||
4afdc394c9 | |||
280baea4f7 | |||
f8946dc471 | |||
4628a37435 | |||
d70f854edb | |||
961f79612a | |||
a630e1317d | |||
e67d29b4e8 | |||
40f124b0d0 | |||
c907da0656 | |||
37ce175bb5 | |||
f4bb2b466c | |||
18b6ed65f1 | |||
87968f8406 | |||
2333667cb5 | |||
fa8d8de05e | |||
43ee2976f2 | |||
63e4510e9e | |||
e4af49ca23 | |||
98c4c98840 | |||
8db219c292 | |||
fb2d6a44eb | |||
c2afe02507 | |||
5311a60af2 | |||
da1ed49a65 | |||
356bf67443 | |||
8cfb4a2426 | |||
f71577afe0 | |||
34e1d1d69f | |||
4567b6e866 | |||
08333362e3 | |||
5b215dbc9e | |||
b8274496f9 | |||
188eb221aa | |||
ca9ff949a1 | |||
d481781180 | |||
2c4f90dab2 | |||
a7302a6880 | |||
cc49472ea4 | |||
fdfc95812c | |||
ad93815681 | |||
195160af94 | |||
1f79b580f9 | |||
b68f07dbc7 | |||
761a3cdeae | |||
54c71781a9 | |||
657ae5e11e | |||
8ed7a899d7 | |||
90118531a7 | |||
fcef475989 | |||
b6bc7e9df8 | |||
0503b02312 | |||
10311644e4 | |||
46d8dad2e1 | |||
f6da7f3305 | |||
52496189d9 | |||
ed04398a8c | |||
62396e3b23 | |||
37c2b7e9b7 | |||
490af40be5 | |||
89a1f8e7a9 | |||
c1f23ada19 | |||
1b6572ec9f | |||
0e2236a2f1 | |||
e109c9980c | |||
a2eec8a1e2 | |||
b1c383211c | |||
dc70cd1304 | |||
e7e776a535 | |||
6b6a883824 | |||
77feee975e | |||
a585bb54e4 | |||
471237dab6 | |||
8938eed1c4 | |||
fed98cd6ad | |||
65fb2ead1a | |||
52ecfeb337 | |||
3a5be7ce26 | |||
c13fe0be6e | |||
ba17e97665 | |||
85b96879f2 | |||
428e9b008c | |||
1c6c6998bc | |||
b497628ef6 | |||
131bfd90a4 | |||
42b126e4dd | |||
e508a64ae9 | |||
261d107abd | |||
528e9b2818 | |||
47d859b2a4 | |||
9ef16af05e | |||
3a06fa4bd9 | |||
afcbf0d311 | |||
47d6b3f2b3 | |||
10b5436cc9 | |||
5e8695d7be | |||
829b16a997 | |||
7b5a3b50f0 | |||
cb918dcd2f | |||
638b36cc6b | |||
59443eca02 | |||
7799954d99 | |||
fc27117299 | |||
eb52b1da96 | |||
4e8a53aec2 | |||
938530b193 | |||
c6f7abbe94 | |||
e2886115dc | |||
e85a444cd0 | |||
2d04130ce0 | |||
bdf6d3e8cb | |||
e06a5587c7 | |||
228ab398b9 | |||
9cff5797a1 | |||
53317da676 | |||
1cdd2b0609 | |||
a0da80fe89 | |||
f3ff34d818 | |||
392fb4b916 | |||
8812365c6f | |||
9d76fd62d7 | |||
a60e9c136b | |||
968d0fbb13 | |||
c1f3b20273 | |||
b91448aa03 | |||
fb63cf75ad | |||
834089c4b2 | |||
a47f4ae9fe | |||
e2dd35e6f6 | |||
bebd1b4106 | |||
6ebb73df7c | |||
52f661fa41 | |||
45e0d59b3b | |||
ad718c53cd | |||
53398c646a | |||
8ba74ad9f7 | |||
1b2748e00f | |||
ecf8427b1e | |||
62acc8734f | |||
d6a07efed5 | |||
83aaee86d8 | |||
6317ef13f8 | |||
e032384c7f | |||
0715c86211 | |||
aa2400f5f0 | |||
9468af050b | |||
dec0bca0ba | |||
0d2ab9459d | |||
3f32d1020d | |||
34b845e484 | |||
bffeb8705c | |||
64be5f1010 | |||
b35c3dd84f | |||
8b53ac9056 | |||
9760595f2f | |||
1fec915bdb | |||
744948e189 | |||
5f7f2cc70b | |||
fa0f3dc13c | |||
f74bb4e5a9 | |||
0fcd502613 | |||
2d7b596c9e | |||
38b0243807 | |||
75b33a1072 | |||
b691ef7e69 | |||
7e2e162653 | |||
44d6bbea8b | |||
6713bade96 | |||
432b4c8863 | |||
f74dbafbbe | |||
e48e6aa9df | |||
03a09c1f51 | |||
a819237722 | |||
4ebe0d8a2f | |||
c4c18c79a0 | |||
6282936f19 | |||
6f7c750f0d | |||
faa740028c | |||
2d7508bd58 | |||
31ecdcd3f6 | |||
620e747355 | |||
d6bf822ab8 | |||
85d2d2fcf8 | |||
ce1e71c0de | |||
a9f6042d41 | |||
de3421718d | |||
8668c11a12 | |||
3b862da384 | |||
a02ac1ffd3 | |||
025e2b0439 | |||
43a328a7c3 | |||
fbb5ada91d | |||
53e93c0a10 | |||
22c82a4e28 | |||
976c3787c3 | |||
1c89992335 | |||
7720cd9c34 | |||
fe7ebf75a0 | |||
5c4d7e61c2 | |||
427aeec530 | |||
b7e6c18f8c | |||
382fa9072d | |||
cca370df47 | |||
ddfc19d531 | |||
c8a4ad9c3b | |||
0182a84c2b | |||
52d9d07422 | |||
5dd8bf4fe5 | |||
edb2a4af41 | |||
801bbcc7ad | |||
2427847229 | |||
bf7435d80d | |||
ebaf8ae461 | |||
64c2f8605a | |||
6710148748 | |||
be2d72b660 | |||
aee941a087 | |||
73f601554b | |||
aff13c0fbc | |||
5f3f5f15b2 | |||
286f8c76b6 | |||
b5e93053e5 | |||
c6d2c43661 | |||
bd9025f817 | |||
7bdef15e85 | |||
20dc46ca49 | |||
592645f0c0 | |||
a582fbdfdc | |||
30c89dc11d | |||
9d21d0a671 | |||
45370f4fae | |||
5b3734a04a | |||
cabe0a44b7 | |||
b766dc00eb | |||
d3c35e1c5f | |||
fca2d78459 | |||
1ef020f0a6 | |||
9b31bd54da | |||
c9307cb16e | |||
f4739d69ab | |||
a303b53209 | |||
99a6072824 | |||
77be96fd87 | |||
3217cd4734 | |||
37d8033906 | |||
6daf14a031 | |||
bb20c40fd8 | |||
4256b1098c | |||
649d834c16 | |||
026accbb91 | |||
f75acede24 | |||
69beb55bbd | |||
161569e3f9 | |||
f5cee05010 | |||
e7f40fca68 | |||
6a9b351b67 | |||
1ae727bbc2 | |||
369222f811 | |||
0499dfdd0c | |||
1273982045 | |||
5da4c0f125 | |||
8e08156141 | |||
a6ea010898 | |||
217e90ec5c | |||
ec2817a285 | |||
ee4fb9b182 | |||
29d5a4dcc3 | |||
f124c30b6f | |||
38b15816b4 | |||
3dddf0c81d | |||
ea28da9b61 | |||
de6d8c6521 | |||
30e4f83127 | |||
3d4d56727a | |||
611160e90e | |||
bb3bec200c | |||
87669b23da | |||
f7e870e45d | |||
7765b07898 | |||
329ae0a987 | |||
50efa84dc4 | |||
c57de0d6ca | |||
753eaa03a6 | |||
f59d1dfab9 | |||
9a141cc0ce | |||
a4c72cfa28 | |||
40636d6a49 | |||
62c44408c2 | |||
e87d95f895 | |||
6956d43f29 | |||
d09d5479a8 | |||
f69fe10e7e | |||
9b274cc989 | |||
a64acef06f | |||
c33dc7afd1 | |||
2b19bc9efa | |||
a8035d21ef | |||
5b73ec939c | |||
d950d3b6b0 | |||
5a2445bb96 | |||
f835edbf5c | |||
87bd31983c | |||
fc18d7972e | |||
8171579a5c | |||
4dd4a1a2e0 | |||
d925b564cd | |||
941e7771d9 | |||
552baf659c | |||
fee376dcdc | |||
7eada9f4d3 | |||
3dc7dc9e97 | |||
2c85e830e0 | |||
5de5eb5676 | |||
ffc87ab7d9 | |||
b8991833ca | |||
3dbff1638c | |||
77e7b15190 | |||
5707296aff | |||
2c995da190 | |||
0bd483bbf5 | |||
05314b6ce0 | |||
eec0934081 | |||
ab63824600 | |||
62d1f3f9ba | |||
ae5603381d | |||
c3324a82a3 | |||
be7b859198 | |||
c2167f137a | |||
b21f42b279 | |||
3873c9e260 | |||
1fb0861b9c | |||
e989d59a4e | |||
7b9c04b773 | |||
9798f2c9b0 | |||
0a8fd1d44b | |||
50cf0c2d24 | |||
ae202d81ec | |||
e645e2e5d6 | |||
c78f5cde40 | |||
f39b02f299 | |||
8eff4e7a47 | |||
88ddddbd3f | |||
61807f6e52 | |||
c53fe053e7 | |||
230e8f5c92 | |||
c94d7fe982 | |||
ea1c51639f | |||
447d19776c | |||
dad5cc4aeb | |||
e44307504a | |||
a67d205468 | |||
22cfa7ea6a | |||
bc5ba60ceb | |||
73733396cd | |||
4f74fd9e95 | |||
09e669dba2 | |||
467bf2f53f | |||
3a5457efe4 | |||
5bb72ea5cc | |||
573f5de99a | |||
5b1a3b801f | |||
18b4ae2a65 | |||
00fb496eda | |||
ad7f8ed0ff | |||
5468184381 | |||
21dc6d1bf1 | |||
e4575b20a1 | |||
86dd11f176 | |||
29a995dd78 | |||
d397767f5d | |||
2357d05427 | |||
b6b1cf216b | |||
cf5ef7f0e1 | |||
07c41378fb | |||
e8834b66c5 | |||
4c1ad38f79 | |||
b9d1afdb86 | |||
f1d98671d2 | |||
2178f319c4 | |||
a59a8edfc0 | |||
fd10a095dd | |||
538b04bf14 | |||
534b8a7940 | |||
cbf4d51ddb | |||
91e435d662 | |||
ab1f6299ff | |||
7cbf4c4330 | |||
32c3db089b | |||
c8289caa23 | |||
73381b5582 | |||
5ca047ac9b | |||
eda943b7c5 | |||
e76038ed76 | |||
9f6f510ce2 | |||
f68b6e6c60 | |||
718efee074 | |||
db2eec2096 | |||
e552ea0d9c | |||
10526ca207 | |||
55bb405583 | |||
246e97c721 | |||
3689b94882 | |||
591606ba59 | |||
2b351a936c | |||
caee4c24a9 | |||
c3171252ec | |||
8171702293 | |||
572ccd503f | |||
176f146678 | |||
0cad7edf40 | |||
96a650169a | |||
a281b667bb | |||
02c3881b7e | |||
1bc0f5ac0a | |||
c89640103f | |||
e365d1ff60 | |||
77eb201241 | |||
447708ef05 | |||
b6615a6c5a | |||
634a5e9355 | |||
353826cacc | |||
abc2b2c968 | |||
153c1f991d | |||
976dc42931 | |||
865c1dd3dc | |||
c92efa0ae3 | |||
1e0bb9c4d3 | |||
d1d5de9aa5 | |||
de8a512228 | |||
52c3aa87b5 | |||
4836d295a8 | |||
f4e6607e7e | |||
af66eab249 | |||
16dd05981b | |||
da7eaade68 | |||
365cc0c1c8 | |||
5a0124a103 | |||
163bffd0c4 | |||
20fd302201 | |||
a20c4a79e6 | |||
68961436f1 | |||
dcde5626ad | |||
65f1be59ad | |||
961af7f903 | |||
157ce5953a | |||
bdd7461235 | |||
d1c78c72d9 | |||
96469ad3dd | |||
3932df3966 | |||
ad78c86936 | |||
e810e4f036 | |||
27a6550800 | |||
18c753ba67 | |||
1b1139ed55 | |||
10a618e7b2 | |||
e877d96ee2 | |||
4c1903a83e | |||
d9fa1f6436 | |||
1d59af5c84 | |||
70fb594873 | |||
6dadc60c8e | |||
79d7cb2751 | |||
d363fafb0b | |||
0c136620d9 | |||
c01f0a08fc | |||
d94867aaac | |||
fcfc04c42a | |||
2afcd77874 | |||
12e86a7c1b | |||
e2b314522e | |||
87bcb95180 | |||
ca42c8ec5c | |||
d48b719e66 | |||
cf500b3f47 | |||
ff88343a10 | |||
66a798dbf2 | |||
2598844423 | |||
402fe837c1 | |||
e05d42d910 | |||
895dd44f8e | |||
ecf065e2a6 | |||
5444c8a462 | |||
4b27c84095 | |||
53d7b12c29 | |||
5d258af93c | |||
3bca931923 | |||
751e0d205d | |||
0d25a9cff8 | |||
580246d6ff | |||
7caa230cf9 | |||
e957cfe0eb | |||
63c006ac91 | |||
c48760e2d1 | |||
9f49a27c12 | |||
df61488e54 | |||
f7f81c33f7 | |||
dc66bcb5ac | |||
15edb0d4b5 | |||
ccfe70872e | |||
aecb2bd8ee | |||
37fb85b998 | |||
66acb32665 | |||
52baa25aa1 | |||
73a4063163 | |||
ef1d0b3d2e | |||
e0ee809d7d | |||
684ffdfe70 | |||
98e7bc3375 | |||
9c4e79dafa | |||
09e48edd87 | |||
3db75c4e9d | |||
7b7c641076 | |||
49ee45e89b | |||
c44bc3752f | |||
5a0ee17ae2 | |||
83482b8912 | |||
7b60e83fd0 | |||
0e83f4b960 | |||
dab3d1750e | |||
4a1cfff12c | |||
df7fc6c452 | |||
d5d05b053a | |||
46238b6ef0 | |||
1cffedd6d2 | |||
e14f4d3fdb | |||
d4e9953212 | |||
387905a4ad | |||
0ff3ceba32 | |||
b29209e3db | |||
805ee815d0 | |||
8a849b29f2 | |||
66315e71fe | |||
e55af6c8a5 | |||
b7fb9be045 | |||
59ff505809 | |||
d95e91b344 | |||
67b87e1bd8 | |||
890a62b53e | |||
754c91f9e1 | |||
8350f2fb6e | |||
d83520060c | |||
4b11a05391 | |||
4b662d1a22 | |||
214cc69fc1 | |||
1e526a5d7d | |||
167966380b | |||
e348a291ad | |||
ecd9d2515f | |||
88a3f963c4 | |||
6870c87aac | |||
f78c8cc0db | |||
e797e742f8 | |||
627b5a4cae | |||
3c88fa5a1e | |||
8ad40cecb4 | |||
98b6fe8f30 | |||
5f5a398662 | |||
04b8564249 | |||
c2f46eb802 | |||
bee6612ab9 | |||
2c87065521 | |||
f280be4a86 | |||
89523af91f | |||
c7ba54ed73 | |||
d1311d1e23 | |||
94cb7e8b8f | |||
01db565aef | |||
e7b34b921d | |||
ab98baff14 | |||
26bfb1cf10 | |||
b022bb2770 | |||
e1ad627a0f | |||
9d359b814f | |||
1ced3f9750 | |||
edb19cd748 | |||
9e8b44e353 | |||
df3aef80c0 | |||
b204bc1bd6 | |||
b131fffa84 | |||
bca0b85fc3 | |||
445635fe45 | |||
10c498ae7d | |||
723c8d9899 | |||
97b1f0f60c | |||
b695152d43 | |||
31f9c88269 | |||
28e393c062 | |||
67d7fad764 | |||
ae72c7d417 | |||
e42c8d2f1f | |||
b5df4843b2 | |||
33ddc213ad | |||
42e694bb8f | |||
48fda05b3e | |||
146c714541 | |||
e9ece1255a | |||
c570f51b53 | |||
67055161c1 | |||
5c223e17cb | |||
aa8fffcd73 | |||
67ed9b5799 | |||
7da1603a1c | |||
824c358097 | |||
5123c80060 | |||
86cd54117e | |||
d425a25875 | |||
217e95d4db | |||
7891ba1e24 | |||
585120da0d | |||
420d436199 | |||
124ec431e6 | |||
3a96d07e11 | |||
245047e82d | |||
4e8ebc2463 | |||
e963390324 | |||
febabaa55a | |||
b4dc11a409 | |||
15111210a1 | |||
eff8dedb2b | |||
aefe9e0b03 | |||
da530f01dc | |||
8acffd2931 | |||
39ef55261c | |||
101c1a953a | |||
b9edf4783c | |||
da669efa0c | |||
1f54e90bb4 | |||
444b5582a7 | |||
eca90124fb | |||
645715c1b0 | |||
887f5040da | |||
1d4b8a742d | |||
d28f1682fc | |||
41a3759314 | |||
3adfa1ac78 | |||
85e3c733ff | |||
f6517cf4e7 | |||
636a719f4d | |||
92ce5c1f23 | |||
df1c6fd95c | |||
bbe75af7a3 | |||
4634ad6fa4 | |||
5ccf6cd381 | |||
259d1924cb | |||
1bd4fe1f50 | |||
62458dbb90 | |||
d81dbd48ed | |||
0dea1b38cb | |||
e1115c951e | |||
2973114938 | |||
2222f842d6 | |||
8b89fbe88b | |||
2c1bf3ec3b | |||
aaa7476456 | |||
b72ab0b1f8 | |||
5704b13bc9 | |||
32fa7c6c6c | |||
d4348656ec | |||
c3b300064b | |||
bbd9a8a44d | |||
72f43489a5 | |||
5f9a48c352 | |||
5b97931527 | |||
89d9b2ac27 | |||
72ce618f9a | |||
36dc7ae71e | |||
7fa85d9a6a | |||
7b57311a0e | |||
6e52afaa2b | |||
ad412850d0 | |||
20d33f27d6 | |||
34690034e6 | |||
84012fa82f | |||
ffcd55bbf2 | |||
e1e082072c | |||
329f7f8210 | |||
0cc8639e2f | |||
a88420c860 | |||
21ef71fa2b | |||
346f09bf1c | |||
ce4a8af3c7 | |||
e3a7fb2fd4 | |||
9b9ff7b183 | |||
7308f60a74 | |||
50fc403018 | |||
0b65005ffd | |||
60ba33afa9 | |||
d90f3f9119 | |||
7d40d308bb | |||
0dda8869cd | |||
8a0ae62a03 | |||
6c15b3c44e | |||
4680bae94d | |||
ce0189dd5a | |||
90403c658c | |||
c4c3696d9b | |||
ca5c632b38 | |||
a7bd982556 | |||
8647e5a839 | |||
065d64555d | |||
2a3ecaa926 | |||
b76c3afa3a | |||
ab7eafa3b8 | |||
367397385e | |||
632cfa5a82 | |||
6dddeaec5b | |||
8988fb9b8d | |||
bd187b022f | |||
7ba69e5439 | |||
75af20e687 | |||
5952694160 | |||
1c87f1df05 | |||
e40e694cf9 | |||
476a54886f | |||
45f7edd4f2 | |||
fea61290d3 | |||
899ef49272 | |||
ade43317ca | |||
58d37de620 | |||
1e8f68f829 | |||
a27ea5a6c8 | |||
d54f4bd691 | |||
84c0fde0e8 | |||
292333a27c | |||
1c8ce47465 | |||
bd59c89540 | |||
c3fe42250c | |||
f664527eb4 | |||
9b7dca3769 | |||
24efb6308d | |||
6f22d7590e | |||
91903234a9 | |||
294a00c15d | |||
55203e9c09 | |||
a40a5405b7 | |||
c547044f28 | |||
d4af9d1ce4 | |||
bb0fe3785f | |||
84b9ce81bb | |||
6b1473e084 | |||
975b8d228f | |||
a36a020657 | |||
788fe71b6b | |||
9c96e4554c | |||
c9ca1fbe78 | |||
e3e5a41bc9 | |||
c47cbe8139 | |||
d2fd9c10b3 | |||
3d888ca777 | |||
2a5679c253 | |||
b7259bab36 | |||
a3f71eeeb4 | |||
3512a775bc | |||
869742de00 | |||
2a4e91553d | |||
fc1f1902a8 | |||
9ba5899206 | |||
6b6cf151cf | |||
897acd6a1d | |||
cc36e415c0 | |||
a43e5feee8 | |||
ab6139b9df | |||
6e42afb45b | |||
252aaf2ab7 | |||
9ff30e81c5 | |||
7bc32cb773 | |||
12cb99e815 | |||
866dde5025 | |||
829080e10e | |||
67504984c1 | |||
29c40aa784 | |||
6e22f6bae9 | |||
23a36bdd77 | |||
b3af5fb2c3 | |||
a603bf9e02 | |||
9ff88e9f0e | |||
c83a8c4cc7 | |||
000c0b4b8a | |||
d8061fa8d9 | |||
6e148c0051 | |||
612d8f173f | |||
221e89cf59 | |||
f5dde8b17e | |||
4fc12259dd | |||
40bc362809 | |||
5ef1b39002 | |||
c519d78e00 | |||
fe6bc06366 | |||
535fa9615c | |||
c4f38c361e | |||
75c82c5bc7 | |||
b57953efdf | |||
b89a2bb266 | |||
4d735d8279 | |||
c370a8f7ce | |||
55fafa887c | |||
46691df851 | |||
ac0731e977 | |||
bd72a9ab2b | |||
f1b651af7e | |||
550ed39ea3 | |||
67a48580fa | |||
5e536a3f43 | |||
7f7397e67f | |||
59680bbaff | |||
07a88fbb7c | |||
828cc1318b | |||
19fcd9cc19 | |||
ba01132b41 | |||
9587b53b2f | |||
95083233c5 | |||
ceeee9036c | |||
7e2f701a3c | |||
be13513378 | |||
ca38f1eb0a | |||
36edd91060 | |||
b41752b95c | |||
b3b7fcf51c | |||
b8c893774f | |||
d101da4ca4 | |||
a716442c72 | |||
103503ba56 | |||
50b5b3184e | |||
69ce0cea68 | |||
77fd8095e0 | |||
16e33e3e33 | |||
491d564f5a | |||
4c01c1a034 | |||
ee6ff6bdd2 | |||
907e206dff | |||
b20943ad43 | |||
839893cfce | |||
5cf858bee3 | |||
b6e69b5014 | |||
f8874e6940 | |||
f5a7c9635f | |||
f5d37dd416 | |||
1ecd5ab91d | |||
9c9b64ee17 | |||
7ab64c5345 | |||
0116d5d096 | |||
6db66c96d6 | |||
8d54933e10 | |||
b1e907ccf1 | |||
370aa39045 | |||
9b19b21073 | |||
88baff4cbb | |||
4ea2935b1a | |||
a1cd7d0ef5 | |||
113721f8fc | |||
5cc9ef901e | |||
ea8fae9ded | |||
9d38b0ab9b | |||
faaf08c441 | |||
f9e22b627e | |||
b6e2163e5e | |||
40c9f0599c | |||
aceb46efc2 | |||
15c8337424 | |||
bf35465658 | |||
289b8bcea7 | |||
0d5eb50ce2 | |||
353f893d95 | |||
a55bd7339c | |||
56accfe4c4 | |||
7ab2ffb45f | |||
6cbc7dc2cd | |||
c711a048bb | |||
5eb5b1148a | |||
4b41f19a01 | |||
c735e7edf5 | |||
f31a804c1e | |||
d168611bbf | |||
b85f877817 | |||
6ae54e7fd2 | |||
0ff9b0a812 | |||
a19fa857ad | |||
dd99fc77cb | |||
4daa605bd3 | |||
43aafb0d86 | |||
6aba4efca0 | |||
5cff7b1d55 | |||
5925f6458a | |||
97f10f6509 | |||
be80b6f270 | |||
ee70736a03 | |||
9e55345c43 | |||
6b66850dc1 | |||
e0e391dce3 | |||
0a1919abff | |||
af82516cfb | |||
6baa5f0d7b | |||
c5bbe87425 | |||
5e52e5f6f5 | |||
f82010fa6a | |||
cf3b2df4a4 | |||
08e7bce4ea | |||
a945ae8a9d | |||
b33828e254 | |||
ae64d9e738 | |||
6861f7d5d8 | |||
c5a6fc9c7e | |||
3b8b057894 | |||
e69ee31e1a | |||
846a2f95f4 | |||
74623ac9d5 | |||
37c155c359 | |||
194a3b09dc | |||
1b8905e544 | |||
d0093c7675 | |||
de6f21936f | |||
46486a863c | |||
29bc65e719 | |||
7de0c391ac | |||
326b42560d | |||
6f768b74e4 | |||
aa6481837f | |||
bd3caffdcd | |||
a5b4fda207 | |||
7070fea6e4 | |||
d35226c656 | |||
4be2170250 | |||
29d3c40a25 | |||
7cdc2f2b81 | |||
50319bb03c | |||
0ea6d39686 | |||
298f23c958 | |||
1e12199832 | |||
36a66a7243 | |||
4eec4fbc99 | |||
b00f38f91c | |||
3c6b1b4c0a | |||
2c531d5bb3 | |||
1bd7944316 | |||
75dd9835f6 | |||
bda0c84552 | |||
eacefba1c6 | |||
69895387ee | |||
c89d045322 | |||
7708bf6158 | |||
10f3d92f6c | |||
5fb93a14ae | |||
63592b667c | |||
ba06ecf96d | |||
8793aab0e3 | |||
d32ee233af | |||
049402ae8d | |||
977d98cb6d | |||
983a4be42e | |||
0c87b1c12d | |||
5ea193115b | |||
6971cdbad5 | |||
0af793f6ef | |||
e1ce31483d | |||
492cece316 | |||
55b56a1557 | |||
2f73d76768 | |||
63c8dd2981 | |||
a02a782ee9 | |||
0c06be9bcd | |||
d3921346a9 | |||
c3d33f4232 | |||
ad4dfed632 | |||
4a8effcbb9 | |||
d2666545d1 | |||
6f410cb7c4 | |||
8df1369d0a | |||
7d3d56ff9a | |||
edb84c19dd | |||
3b89497b39 | |||
841aba8948 | |||
84b51781c8 | |||
58f0a94cdf | |||
3cfd7eebd1 | |||
4775176d7f | |||
eeff638c97 | |||
ca01e8698f | |||
db7e28b8c7 | |||
13537ce279 | |||
cc187a43b3 | |||
b4588f7d92 | |||
59b313fdcf | |||
74056dea91 | |||
2eadacbf29 | |||
3c32f5a726 | |||
55cd9206d5 | |||
80412dfbb8 | |||
502a2aed2a | |||
d075bcab98 | |||
88f6e2b60d | |||
e789d85e69 | |||
eb8f6f942a | |||
715cb64288 | |||
52fa4c7f96 | |||
f02d095ff1 | |||
ab73b3fd8e | |||
dc4cd3ae7c | |||
3db186d5d1 | |||
db3d03f9ac | |||
4a42368603 | |||
db0897705f | |||
276cbb69f3 | |||
c973bea7d1 | |||
6191429df5 | |||
5a1848a5a6 | |||
e9d4659175 | |||
0266ad95d7 | |||
19163393a9 | |||
9d587eb8fd | |||
32e20304a7 | |||
1cfeb8be7f | |||
222ac1dd60 | |||
63dae58176 | |||
e07023b9c7 | |||
ddae67f50f | |||
c595429db0 | |||
b929611d5d | |||
e9f64eb1c3 | |||
56c1646e2a | |||
204553ec6c | |||
87141efd1e | |||
260d6f83b7 | |||
8860c1b94c | |||
31b164ccb1 | |||
c96ce01d87 | |||
97f72da56e | |||
3e93b8fed9 | |||
295a9eea82 | |||
06d445759a | |||
b1efdd5eb1 | |||
42ccb7277f | |||
cffbc32253 | |||
8f5564af84 | |||
6a6bac2c62 | |||
526f253b2e | |||
2f40c4449f | |||
8ab29292ab | |||
9af8947e55 | |||
800cb0fff8 | |||
362e8e0a1f | |||
de648753b0 | |||
aed5dc63b7 | |||
21c5be311c | |||
0a41241e10 | |||
e3472c1c99 | |||
175109d196 | |||
61d376109c | |||
fd4b6fd47e | |||
b348b55d1e | |||
82a5b05948 | |||
95718d9ef9 | |||
33c0ddce40 | |||
bf4b513e83 | |||
91fff8c897 | |||
7ea60199a6 | |||
2b84b673bf | |||
c2e24e306f | |||
a85459e245 | |||
a0434371b0 | |||
1717c2face | |||
ee0f8adaed | |||
949e7c6f85 | |||
f14cdd5d3a | |||
15daee9a0f | |||
de85de7c51 | |||
27ae9d3e2c | |||
7db21de3b3 | |||
cec0f25484 | |||
f232b07e4e | |||
78b13034ef | |||
099bf88b2e | |||
466d450b4b | |||
a742255f8e | |||
dd89b2dc0d | |||
654a3913eb | |||
fefa9b7fe9 | |||
547fd926a9 | |||
d6cbfc7f19 | |||
61405472e4 | |||
541d8aef37 | |||
f9bfc83295 | |||
3fa198b8a2 | |||
9778b163b1 | |||
e006d21419 | |||
4214179de1 | |||
5c98ff015e | |||
b56c7d9066 | |||
d67e764ef6 | |||
1554fd3d8a | |||
0cd5e28bce | |||
c1cd396b95 | |||
f7a2bfc873 | |||
4b1cbe87b3 | |||
8b2291a718 | |||
fca4124f70 | |||
d35d765395 | |||
94092a148c | |||
68e8a7e0ba | |||
62ac50f9d7 | |||
fefd52f093 | |||
7c379f8a65 | |||
fca858dd58 | |||
c28828d255 | |||
d595793caa | |||
67eef52822 | |||
6f7acf6a21 | |||
df96c73471 | |||
3ceb5b3718 | |||
d51bd36142 | |||
bd01c359bd | |||
c5cb44d813 | |||
43d8950682 | |||
d4e700e744 | |||
ddaa9d4523 | |||
fadbfdadf4 | |||
58044063dd | |||
67f9448e71 | |||
5b516b107a | |||
6366c20858 | |||
27ec86cd8e | |||
3b3050b09f | |||
69c8d9211f | |||
6254bf443e | |||
198953df8f | |||
87fa7af6b7 | |||
e558b2237d | |||
eb5bafeb65 | |||
9a389162ab | |||
e6fc2a7bc8 | |||
2fb9cad1b4 | |||
13ef9cf4bc | |||
1229590a2c | |||
7d934dafb8 | |||
6c9864ce86 | |||
4952b3baed | |||
ee234472c1 | |||
c50952ebaf | |||
20085a0fcd | |||
19449289d0 | |||
f5645cc9d8 | |||
0c92ca5175 | |||
a41bcacf31 | |||
f4243de752 | |||
e9c6f119de | |||
1ea008d22e | |||
585d53dfa8 | |||
1f480f4570 | |||
d10ad9a4b1 | |||
0effd9b257 | |||
0c4e55e3bd | |||
a2a71fc68f | |||
ae063d96c2 | |||
3948065c24 | |||
33eab40f2a | |||
f59ef5e6ef | |||
b7ae3ff9bd | |||
a2a89fb95d | |||
ffe0cca423 | |||
b3410b9210 | |||
b08b0f0949 | |||
f646cdd6a8 | |||
445f727e7a | |||
e1562311bf | |||
afc1362ea6 | |||
5a09cfe70a | |||
858f4745fd | |||
d880672076 | |||
90a8945930 | |||
34b9e6c677 | |||
1ac44aa202 | |||
7053737110 | |||
acb92c225f | |||
072d01da2f | |||
87d68ebb98 | |||
89f7e62011 | |||
4fe18a9258 | |||
51c32997b1 | |||
40af109144 | |||
ec5c123ef7 | |||
4573688862 | |||
cd301cc324 | |||
9a1c5a903f | |||
655e201b1c | |||
5e09d473c7 | |||
bf7f40007a | |||
a2c55e2c37 | |||
4b59f7e2c7 | |||
716298f8e3 | |||
38060c0b58 | |||
3c01f68a78 | |||
a5bf353e3f | |||
51b7247033 | |||
52dcf1c180 | |||
26379f7d3e | |||
8dc421c7e1 | |||
79590d2e21 | |||
c17d55eb9b | |||
7c34711c07 | |||
cf8dd62fc4 | |||
f96d28172b | |||
f538b63458 | |||
6c7895fbac | |||
a8494b68e1 | |||
8367bc4571 | |||
374e9b32d4 | |||
7fdc9571ba | |||
f9f42a9d90 | |||
820ed5c7f1 | |||
69147fc4ec | |||
88f8f91d40 | |||
06337f1034 | |||
40f66c3117 | |||
db1111ef79 | |||
dbaf0f1e93 | |||
906280e767 | |||
55abe2eba8 | |||
fbe215f3c0 | |||
6e0b8af978 | |||
b8fe1fdf27 | |||
355a210a38 | |||
5c4f7948d4 | |||
bc81db3676 | |||
737215c50f | |||
2925b5f42b | |||
cc95d14d80 | |||
1717232f11 | |||
98742664e8 | |||
2aba19e00d | |||
9f024df9e5 | |||
af3c81b68a | |||
bac92d579f | |||
b445b59c5e | |||
9b31a2e7f9 | |||
71ffae5d6e | |||
c092f9b881 | |||
582a493739 | |||
2976f5daea | |||
4414e829de | |||
e4704e0875 | |||
f5fc735711 | |||
7815cd9ff4 | |||
da113cdfa8 | |||
48e6195506 | |||
1cdea40bba | |||
3d462d7d81 | |||
aa6347339c | |||
8488f292c2 | |||
6431a5e185 | |||
27b28c0249 | |||
b29bc240a7 | |||
940e87c0da | |||
60eaca9637 | |||
e01333514d | |||
f0519c674f | |||
de9186b908 | |||
5cd45a6d80 | |||
1fa6db757d | |||
7f84669054 | |||
e82ac041cd | |||
47f9c0e301 | |||
d09a43fc1e | |||
a003bcde29 | |||
492065463d | |||
85c15812c9 | |||
ba43902fb8 | |||
eda9d8ffa8 | |||
f4c84ea2b2 | |||
fefd64fa83 | |||
70b1ab76e8 | |||
6bc77d79a6 | |||
4c09dc6270 | |||
570653bc7b | |||
2241dda536 | |||
a559d55379 | |||
c99eac2f0b | |||
a1764ec5b0 | |||
5ce7ec848c | |||
15cdd2859a | |||
a0abb4dfdc | |||
f5b678f7ba | |||
1af819d19b | |||
408d1d9f93 | |||
f70dcd9ab5 | |||
a251485359 | |||
ee86ee0094 | |||
5dbabae9dc | |||
48fe9dfce7 | |||
5f2d918437 | |||
32756b165e | |||
74b299c4c7 | |||
27e9cb785a | |||
60fed38c0f | |||
a66955b36a | |||
535b378869 | |||
e36b3e0d04 | |||
2afafe890a | |||
e7c8a36d46 | |||
0e21d1e372 | |||
96cd373265 | |||
00f0cdcc92 | |||
425486223e | |||
d6026823fa | |||
c57ba38d67 | |||
250e219279 | |||
233d4b94bd | |||
d19c1c4b3c | |||
e7a33878bb | |||
74c528d836 | |||
c55689ca18 | |||
b8c2fedec9 | |||
23c5770156 | |||
4c668ff3d3 | |||
4a623798f1 | |||
0f191c3366 | |||
077d68c752 | |||
4d10eb20db | |||
94327c10ed | |||
328c659cd3 | |||
8e34adb94c | |||
7d41eb6f52 | |||
2a014db549 | |||
6c207ea6d2 | |||
2611e23bd2 | |||
4b2ef7303e | |||
21af266a11 | |||
711c8472fc | |||
df06f7d715 | |||
a280f0a9ba | |||
9177f5d32e | |||
4045dc8508 | |||
f4f2724a4e | |||
dbc0a9b3f4 | |||
83fc174310 | |||
6fad6eb9f1 | |||
9c5067a998 | |||
3b16089cb2 | |||
de3eed647f | |||
c4654298ce | |||
9c8c6b5cd5 | |||
dc8701601d | |||
402a118299 | |||
5487700bf1 | |||
cd492747e1 | |||
9cdbda325a | |||
9bf147515c | |||
3a9750746f | |||
0809136836 | |||
124b735ac5 | |||
a74d85945a | |||
ce4334f4bf | |||
5c217d8bb6 | |||
0664f82431 | |||
0350ea5744 | |||
145682b854 | |||
1e54e5ddef | |||
3f4da83520 | |||
8609b3730d | |||
e8d33e4faf | |||
8908d52efa | |||
5a244bc935 | |||
ea35218d2a | |||
d01af529f6 | |||
3b86e7e099 | |||
bd8baba0dc | |||
8954c989f4 | |||
f6c90adb42 | |||
a0ebe4d18c | |||
eb11a748e7 | |||
c8e605cd71 | |||
0f9e14de9a | |||
73fd009d40 | |||
17afd49e01 | |||
8cdb2538d3 | |||
cbd24259b2 | |||
9aa61d634b | |||
e547329935 | |||
6ae3311f48 | |||
1adf837577 | |||
b76a10dd4f | |||
911f931ccb | |||
c74521f06d | |||
317f0d496a | |||
ca735340f9 | |||
45af9bf3ec | |||
cdd3f6e8e7 | |||
7acdc2f7fc | |||
c6c18ef2e8 | |||
9eec899f49 | |||
549d026dc3 | |||
9ebdcf5b37 | |||
a0d7dd770c | |||
21c1682a7a | |||
4541e065e4 | |||
81298c3f70 | |||
33069f3133 | |||
04f589b1c7 | |||
901ae4d11c | |||
bdf8df61c0 | |||
d41f3cc759 | |||
1ae9541176 | |||
224c221ddd | |||
2ad0e78210 | |||
546cf10c5d | |||
994e632a59 | |||
5799999e41 | |||
4e1c41c7e1 | |||
371565be3e | |||
12353ff3d8 | |||
fc1119331a | |||
7d30c6d799 | |||
73384c1b52 | |||
c67c3aa14e | |||
70dee9f4bb | |||
bf6e745ac0 | |||
e89392596c | |||
a8bec381bc | |||
4f46828464 | |||
15011e0d16 | |||
7261e72ef7 | |||
aedf89237f | |||
7848dd949f | |||
ba26fdba4c | |||
1a3bb06916 | |||
274b0b8d8a | |||
9dcb48b86b | |||
ee42e3d714 | |||
c2a4dd0c68 | |||
3733c9f8e5 | |||
38ff669727 | |||
c324e7a435 | |||
c62d5e942e | |||
3e4e538087 | |||
b99a39535b | |||
f6523748fc | |||
09b4bb5eba | |||
e751c59d5d | |||
c0e1f83a91 | |||
fd61f75db9 | |||
abe0225ef5 | |||
b530b26e1b | |||
51e208533e | |||
c014d32193 | |||
19980ace1f |
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
2
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -38,7 +38,7 @@ If the issue cannot be solved after the steps before, please follow these instru
|
||||
- Development Kit: [ESP32-Wrover-Kit|ESP32-DevKitC|ESP32-PICO-Kit|ESP32-LyraT|ESP32-LyraTD-MSC|none]
|
||||
- Kit version (for WroverKit/PicoKit/DevKitC): [v1|v2|v3|v4]
|
||||
- Module or chip used: [ESP32-WROOM-32|ESP32-WROOM-32D|ESP32-WROOM-32U|ESP32-WROVER|ESP32-WROVER-I|ESP32-WROVER-B|ESP32-WROVER-IB|ESP32-SOLO-1|ESP32-PICO-D4|ESP32]
|
||||
- IDF version (run ``git describe --tags`` to find it):
|
||||
- IDF version (run ``git describe`` to find it):
|
||||
// v3.2-dev-1148-g96cd3b75c
|
||||
- Build System: [Make|CMake|idf.py]
|
||||
- Compiler version (run ``xtensa-esp32-elf-gcc --version`` to find it):
|
||||
|
17
.github/workflows/release_zips.yml
vendored
Normal file
17
.github/workflows/release_zips.yml
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
name: Create zip file with recursive source clone for release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- v*
|
||||
|
||||
jobs:
|
||||
release_zips:
|
||||
name: Create release zip file
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Create a recursive clone source zip
|
||||
uses: espressif/github-actions/release_zips@master
|
||||
env:
|
||||
RELEASE_PROJECT_NAME: ESP-IDF
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
@ -8,6 +8,18 @@ stages:
|
||||
- deploy
|
||||
- post_check
|
||||
|
||||
# pipelines will not be created in such two cases:
|
||||
# 1. MR push
|
||||
# 2. push not on "master/release" branches, and not tagged
|
||||
# This behavior could be changed after the `rules: changes` feature is implemented
|
||||
workflow:
|
||||
rules:
|
||||
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
|
||||
when: never
|
||||
- if: '$CI_COMMIT_REF_NAME != "master" && $CI_COMMIT_BRANCH !~ /^release\/v/ && $CI_COMMIT_TAG !~ /^v\d+\.\d+(\.\d+)?($|-)/ && $CI_PIPELINE_SOURCE == "push"'
|
||||
when: never
|
||||
- when: always
|
||||
|
||||
variables:
|
||||
# System environment
|
||||
|
||||
@ -16,9 +28,8 @@ variables:
|
||||
|
||||
# GitLab-CI environment
|
||||
|
||||
# more attempts for more robust
|
||||
GET_SOURCES_ATTEMPTS: "10"
|
||||
ARTIFACT_DOWNLOAD_ATTEMPTS: "10"
|
||||
# XXX_ATTEMPTS variables (https://docs.gitlab.com/ce/ci/yaml/README.html#job-stages-attempts) are not defined here.
|
||||
# Use values from "CI / CD Settings" - "Variables".
|
||||
|
||||
# GIT_STRATEGY is not defined here.
|
||||
# Use an option from "CI / CD Settings" - "General pipelines".
|
||||
@ -36,19 +47,23 @@ variables:
|
||||
|
||||
UNIT_TEST_BUILD_SYSTEM: cmake
|
||||
EXAMPLE_TEST_BUILD_SYSTEM: cmake
|
||||
# IDF environment
|
||||
|
||||
IDF_PATH: "$CI_PROJECT_DIR"
|
||||
BATCH_BUILD: "1"
|
||||
V: "0"
|
||||
APPLY_BOT_FILTER_SCRIPT: "$CI_PROJECT_DIR/tools/ci/apply_bot_filter.py"
|
||||
CHECKOUT_REF_SCRIPT: "$CI_PROJECT_DIR/tools/ci/checkout_project_ref.py"
|
||||
CUSTOM_TOOLCHAIN_PATH: "/opt/xtensa-custom"
|
||||
|
||||
# Docker images
|
||||
# Docker images
|
||||
BOT_DOCKER_IMAGE_TAG: ":latest"
|
||||
# target test config file, used by assign test job
|
||||
# target test config file, used by assign test job
|
||||
CI_TARGET_TEST_CONFIG_FILE: "$CI_PROJECT_DIR/tools/ci/config/target-test.yml"
|
||||
# target test repo parameters
|
||||
TEST_ENV_CONFIG_REPO: "https://gitlab-ci-token:${BOT_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/qa/ci-test-runner-configs.git"
|
||||
CI_AUTO_TEST_SCRIPT_REPO_URL: "https://gitlab-ci-token:${BOT_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/qa/auto_test_script.git"
|
||||
CI_AUTO_TEST_SCRIPT_REPO_BRANCH: "ci/v3.1"
|
||||
|
||||
# Versioned esp-idf-doc env image to use for all document building jobs
|
||||
ESP_IDF_DOC_ENV_IMAGE: "$CI_DOCKER_REGISTRY/esp-idf-doc-env:v7"
|
||||
|
||||
|
||||
|
||||
@ -56,25 +71,6 @@ variables:
|
||||
.apply_bot_filter: &apply_bot_filter
|
||||
python $APPLY_BOT_FILTER_SCRIPT || exit 0
|
||||
|
||||
.setup_custom_toolchain: &setup_custom_toolchain |
|
||||
if [ "$IDF_XTENSA_TOOLCHAIN_URL" ] ; then
|
||||
echo "Use a custom toolchain: ${IDF_XTENSA_TOOLCHAIN_URL:-Unknown}"
|
||||
rm -rf "$CUSTOM_TOOLCHAIN_PATH" &&
|
||||
mkdir -p -v "$CUSTOM_TOOLCHAIN_PATH" &&
|
||||
pushd "$CUSTOM_TOOLCHAIN_PATH" &&
|
||||
curl -sSL -o xtensa-custom.xxx "$IDF_XTENSA_TOOLCHAIN_URL" &&
|
||||
ls -l xtensa-custom.xxx &&
|
||||
tar xf xtensa-custom.xxx --strip-components 1 &&
|
||||
ls -l . &&
|
||||
popd
|
||||
PATH=$CUSTOM_TOOLCHAIN_PATH/bin:$PATH
|
||||
export PATH
|
||||
fi
|
||||
|
||||
.cleanup_custom_toolchain: &cleanup_custom_toolchain |
|
||||
echo "Cleaning up $CUSTOM_TOOLCHAIN_PATH"
|
||||
rm -rf "$CUSTOM_TOOLCHAIN_PATH"
|
||||
|
||||
.setup_tools_unless_target_test: &setup_tools_unless_target_test |
|
||||
if [[ "$SETUP_TOOLS" == "1" || "$CI_JOB_STAGE" != "target_test" ]]; then
|
||||
tools/idf_tools.py --non-interactive install && eval "$(tools/idf_tools.py --non-interactive export)" || exit 1
|
||||
@ -96,13 +92,10 @@ before_script:
|
||||
- echo -e "Host gitlab.espressif.cn\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
|
||||
# Set some options and environment for CI
|
||||
- source tools/ci/configure_ci_environment.sh
|
||||
|
||||
- *setup_tools_unless_target_test
|
||||
|
||||
- *fetch_submodules
|
||||
|
||||
- *setup_custom_toolchain
|
||||
|
||||
# used for check scripts which we want to run unconditionally
|
||||
.before_script_lesser_nofilter:
|
||||
variables:
|
||||
@ -111,7 +104,6 @@ before_script:
|
||||
- echo "Not setting up GitLab key, not fetching submodules, not applying bot filter"
|
||||
- source tools/ci/setup_python.sh
|
||||
- source tools/ci/configure_ci_environment.sh
|
||||
- *setup_custom_toolchain
|
||||
|
||||
# used for everything else where we want to do no prep, except for bot filter
|
||||
.before_script_lesser:
|
||||
@ -123,10 +115,6 @@ before_script:
|
||||
# apply bot filter in before script
|
||||
- *apply_bot_filter
|
||||
- source tools/ci/configure_ci_environment.sh
|
||||
- *setup_custom_toolchain
|
||||
|
||||
after_script:
|
||||
- *cleanup_custom_toolchain
|
||||
|
||||
.check_job_template:
|
||||
stage: pre_check
|
||||
@ -151,9 +139,17 @@ after_script:
|
||||
dependencies: []
|
||||
before_script:
|
||||
- *apply_bot_filter
|
||||
- $IDF_PATH/tools/idf_tools.py install-python-env
|
||||
# On macOS, these tools need to be installed
|
||||
- $IDF_PATH/tools/idf_tools.py --non-interactive install cmake ninja
|
||||
# This adds tools (compilers) and the version-specific Python environment to PATH
|
||||
- *setup_tools_unless_target_test
|
||||
- *setup_custom_toolchain
|
||||
# Install packages required by CI scripts into IDF Python environment
|
||||
- pip install -r $IDF_PATH/tools/ci/python_packages/ttfw_idf/requirements.txt
|
||||
- source tools/ci/configure_ci_environment.sh
|
||||
# Part of tools/ci/setup_python.sh; we don't use pyenv on macOS, so can't run the rest of the script.
|
||||
- export PYTHONPATH="$IDF_PATH/tools:$IDF_PATH/tools/ci/python_packages:$PYTHONPATH"
|
||||
- *fetch_submodules
|
||||
|
||||
include:
|
||||
- '/tools/ci/config/pre_check.yml'
|
||||
|
6
.gitlab/CODEOWNERS
Normal file
6
.gitlab/CODEOWNERS
Normal file
@ -0,0 +1,6 @@
|
||||
# For the syntax of this file, see:
|
||||
#
|
||||
# https://docs.gitlab.com/ee/user/project/code_owners.html#the-syntax-of-code-owners-files
|
||||
#
|
||||
|
||||
* @esp-idf-codeowners/all-maintainers
|
@ -1,6 +1,12 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
project(esp-idf C CXX ASM)
|
||||
|
||||
if(CMAKE_CURRENT_LIST_DIR STREQUAL CMAKE_SOURCE_DIR)
|
||||
message(FATAL_ERROR "Current directory '${CMAKE_CURRENT_LIST_DIR}' is not buildable. "
|
||||
"Change directories to one of the example projects in '${CMAKE_CURRENT_LIST_DIR}/examples' and try "
|
||||
"again.")
|
||||
endif()
|
||||
|
||||
unset(compile_options)
|
||||
unset(c_compile_options)
|
||||
unset(cxx_compile_options)
|
||||
@ -10,15 +16,31 @@ unset(link_options)
|
||||
# Add the following build specifications here, since these seem to be dependent
|
||||
# on config values on the root Kconfig.
|
||||
|
||||
if(CONFIG_COMPILER_OPTIMIZATION_SIZE)
|
||||
list(APPEND compile_options "-Os")
|
||||
list(APPEND compile_options "-freorder-blocks")
|
||||
elseif(CONFIG_COMPILER_OPTIMIZATION_DEFAULT)
|
||||
list(APPEND compile_options "-Og")
|
||||
elseif(CONFIG_COMPILER_OPTIMIZATION_NONE)
|
||||
list(APPEND compile_options "-O0")
|
||||
elseif(CONFIG_COMPILER_OPTIMIZATION_PERF)
|
||||
list(APPEND compile_options "-O2")
|
||||
if(NOT BOOTLOADER_BUILD)
|
||||
|
||||
if(CONFIG_COMPILER_OPTIMIZATION_SIZE)
|
||||
list(APPEND compile_options "-Os")
|
||||
list(APPEND compile_options "-freorder-blocks")
|
||||
elseif(CONFIG_COMPILER_OPTIMIZATION_DEFAULT)
|
||||
list(APPEND compile_options "-Og")
|
||||
elseif(CONFIG_COMPILER_OPTIMIZATION_NONE)
|
||||
list(APPEND compile_options "-O0")
|
||||
elseif(CONFIG_COMPILER_OPTIMIZATION_PERF)
|
||||
list(APPEND compile_options "-O2")
|
||||
endif()
|
||||
|
||||
else() # BOOTLOADER_BUILD
|
||||
|
||||
if(CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE)
|
||||
list(APPEND compile_options "-Os")
|
||||
list(APPEND compile_options "-freorder-blocks")
|
||||
elseif(CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG)
|
||||
list(APPEND compile_options "-Og")
|
||||
elseif(CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_NONE)
|
||||
list(APPEND compile_options "-O0")
|
||||
elseif(CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_PERF)
|
||||
list(APPEND compile_options "-O2")
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
|
12
Kconfig
12
Kconfig
@ -46,12 +46,11 @@ mainmenu "Espressif IoT Development Framework Configuration"
|
||||
a crosstool-ng gcc setup that is in your PATH.
|
||||
|
||||
config SDK_PYTHON
|
||||
string "Python 2 interpreter"
|
||||
string "Python interpreter"
|
||||
depends on !IDF_CMAKE
|
||||
default "python"
|
||||
help
|
||||
The executable name/path that is used to run python. On some systems Python 2.x
|
||||
may need to be invoked as python2.
|
||||
The executable name/path that is used to run python.
|
||||
|
||||
(Note: This option is used with the legacy GNU Make build system only.)
|
||||
|
||||
@ -116,7 +115,7 @@ mainmenu "Espressif IoT Development Framework Configuration"
|
||||
mon reset halt
|
||||
# Run to a specific point in ROM code,
|
||||
# where most of initialization is complete.
|
||||
thb *0x40007901
|
||||
thb *0x40007d54
|
||||
c
|
||||
# Load the application into RAM
|
||||
load
|
||||
@ -172,7 +171,7 @@ mainmenu "Espressif IoT Development Framework Configuration"
|
||||
prompt "Optimization Level"
|
||||
default COMPILER_OPTIMIZATION_DEFAULT
|
||||
help
|
||||
This option sets compiler optimization level (gcc -O argument).
|
||||
This option sets compiler optimization level (gcc -O argument) for the app.
|
||||
|
||||
- The "Default" setting will add the -0g flag to CFLAGS.
|
||||
- The "Size" setting will add the -0s flag to CFLAGS.
|
||||
@ -190,6 +189,9 @@ mainmenu "Espressif IoT Development Framework Configuration"
|
||||
|
||||
Note that custom optimization levels may be unsupported.
|
||||
|
||||
Compiler optimization for the IDF bootloader is set separately,
|
||||
see the BOOTLOADER_COMPILER_OPTIMIZATION setting.
|
||||
|
||||
config COMPILER_OPTIMIZATION_DEFAULT
|
||||
bool "Debug (-Og)"
|
||||
config COMPILER_OPTIMIZATION_SIZE
|
||||
|
24
README.md
24
README.md
@ -2,9 +2,7 @@
|
||||
|
||||
* [中文版](./README_CN.md)
|
||||
|
||||
[](https://docs.espressif.com/projects/esp-idf/en/latest/?badge=latest)
|
||||
|
||||
ESP-IDF is the official development framework for the [ESP32](https://espressif.com/en/products/hardware/esp32/overview) chip.
|
||||
ESP-IDF is the official development framework for the [ESP32](https://espressif.com/en/products/hardware/esp32/overview) chip provided for Windows, Linux and macOS.
|
||||
|
||||
# Developing With ESP-IDF
|
||||
|
||||
@ -37,25 +35,15 @@ See the Getting Started guide links above for a detailed setup guide. This is a
|
||||
|
||||
## Setup Build Environment
|
||||
|
||||
(See Getting Started guide for a full list of required steps with details.)
|
||||
(See the Getting Started guide listed above for a full list of required steps with more details.)
|
||||
|
||||
* Install host build dependencies mentioned in Getting Started guide.
|
||||
* Add `tools/` directory to the PATH
|
||||
* Run `python -m pip install -r requirements.txt` to install Python dependencies
|
||||
* Install host build dependencies mentioned in the Getting Started guide.
|
||||
* Run the install script to set up the build environment. The options include `install.bat` or `install.ps1` for Windows, and `install.sh` for Unix shells.
|
||||
* Run the export script on Windows (`export.bat`) or source it on Unix (`source export.sh`) in every shell environment before using ESP-IDF.
|
||||
|
||||
## Configuring the Project
|
||||
|
||||
`idf.py menuconfig`
|
||||
|
||||
* Opens a text-based configuration menu for the project.
|
||||
* Use up & down arrow keys to navigate the menu.
|
||||
* Use Enter key to go into a submenu, Escape key to go out or to exit.
|
||||
* Type `?` to see a help screen. Enter key exits the help screen.
|
||||
* Use Space key, or `Y` and `N` keys to enable (Yes) and disable (No) configuration items with checkboxes "`[*]`"
|
||||
* Pressing `?` while highlighting a configuration item displays help about that item.
|
||||
* Type `/` to search the configuration items.
|
||||
|
||||
Once done configuring, press Escape multiple times to exit and say "Yes" to save the new configuration when prompted.
|
||||
`idf.py menuconfig` opens a text-based configuration menu where you can configure the project.
|
||||
|
||||
## Compiling the Project
|
||||
|
||||
|
@ -39,4 +39,4 @@ target_compile_options(${COMPONENT_LIB} PRIVATE "-fno-profile-arcs" "-fno-test-c
|
||||
|
||||
# Force app_trace to also appear later than gcov in link line
|
||||
idf_component_get_property(app_trace app_trace COMPONENT_LIB)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE $<TARGET_FILE:${app_trace}> gcov $<TARGET_FILE:${app_trace}> ${LIBC})
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE $<TARGET_FILE:${app_trace}> gcov $<TARGET_FILE:${app_trace}> c)
|
||||
|
@ -3,10 +3,11 @@ archive: libapp_trace.a
|
||||
entries:
|
||||
app_trace (noflash)
|
||||
app_trace_util (noflash)
|
||||
SEGGER_SYSVIEW (noflash)
|
||||
SEGGER_RTT_esp32 (noflash)
|
||||
SEGGER_SYSVIEW_Config_FreeRTOS (noflash)
|
||||
SEGGER_SYSVIEW_FreeRTOS (noflash)
|
||||
if SYSVIEW_ENABLE = y:
|
||||
SEGGER_SYSVIEW (noflash)
|
||||
SEGGER_RTT_esp32 (noflash)
|
||||
SEGGER_SYSVIEW_Config_FreeRTOS (noflash)
|
||||
SEGGER_SYSVIEW_FreeRTOS (noflash)
|
||||
|
||||
[mapping:driver]
|
||||
archive: libdriver.a
|
||||
|
@ -22,4 +22,14 @@ menu "Application manager"
|
||||
The PROJECT_NAME variable from the build system will not affect the firmware image.
|
||||
This value will not be contained in the esp_app_desc structure.
|
||||
|
||||
config APP_RETRIEVE_LEN_ELF_SHA
|
||||
int "The length of APP ELF SHA is stored in RAM(chars)"
|
||||
default 16
|
||||
range 8 64
|
||||
help
|
||||
At startup, the app will read this many hex characters from the embedded APP ELF SHA-256 hash value
|
||||
and store it in static RAM. This ensures the app ELF SHA-256 value is always available
|
||||
if it needs to be printed by the panic handler code.
|
||||
Changing this value will change the size of a static buffer, in bytes.
|
||||
|
||||
endmenu # "Application manager"
|
||||
|
@ -72,13 +72,38 @@ static inline char IRAM_ATTR to_hex_digit(unsigned val)
|
||||
return (val < 10) ? ('0' + val) : ('a' + val - 10);
|
||||
}
|
||||
|
||||
__attribute__((constructor)) void esp_ota_init_app_elf_sha256(void)
|
||||
{
|
||||
esp_ota_get_app_elf_sha256(NULL, 0);
|
||||
}
|
||||
|
||||
/* The esp_app_desc.app_elf_sha256 should be possible to print in panic handler during cache is disabled.
|
||||
* But because the cache is disabled the reading esp_app_desc.app_elf_sha256 is not right and
|
||||
* can lead to a complete lock-up of the CPU.
|
||||
* For this reason we do a reading of esp_app_desc.app_elf_sha256 while start up in esp_ota_init_app_elf_sha256()
|
||||
* and keep it in the static s_app_elf_sha256 value.
|
||||
*/
|
||||
int IRAM_ATTR esp_ota_get_app_elf_sha256(char* dst, size_t size)
|
||||
{
|
||||
size_t n = MIN((size - 1) / 2, sizeof(esp_app_desc.app_elf_sha256));
|
||||
const uint8_t* src = esp_app_desc.app_elf_sha256;
|
||||
static char s_app_elf_sha256[CONFIG_APP_RETRIEVE_LEN_ELF_SHA / 2];
|
||||
static bool first_call = true;
|
||||
if (first_call) {
|
||||
first_call = false;
|
||||
// At -O2 optimization level, GCC optimizes out the copying of the first byte of the app_elf_sha256,
|
||||
// because it is zero at compile time, and only modified afterwards by esptool.
|
||||
// Casting to volatile disables the optimization.
|
||||
const volatile uint8_t* src = (const volatile uint8_t*)esp_app_desc.app_elf_sha256;
|
||||
for (size_t i = 0; i < sizeof(s_app_elf_sha256); ++i) {
|
||||
s_app_elf_sha256[i] = src[i];
|
||||
}
|
||||
}
|
||||
if (dst == NULL || size == 0) {
|
||||
return 0;
|
||||
}
|
||||
size_t n = MIN((size - 1) / 2, sizeof(s_app_elf_sha256));
|
||||
for (size_t i = 0; i < n; ++i) {
|
||||
dst[2*i] = to_hex_digit(src[i] >> 4);
|
||||
dst[2*i + 1] = to_hex_digit(src[i] & 0xf);
|
||||
dst[2*i] = to_hex_digit(s_app_elf_sha256[i] >> 4);
|
||||
dst[2*i + 1] = to_hex_digit(s_app_elf_sha256[i] & 0xf);
|
||||
}
|
||||
dst[2*n] = 0;
|
||||
return 2*n + 1;
|
||||
|
@ -157,7 +157,8 @@ esp_err_t esp_ota_begin(const esp_partition_t *partition, size_t image_size, esp
|
||||
if ((image_size == 0) || (image_size == OTA_SIZE_UNKNOWN)) {
|
||||
ret = esp_partition_erase_range(partition, 0, partition->size);
|
||||
} else {
|
||||
ret = esp_partition_erase_range(partition, 0, (image_size / SPI_FLASH_SEC_SIZE + 1) * SPI_FLASH_SEC_SIZE);
|
||||
const int aligned_erase_size = (image_size + SPI_FLASH_SEC_SIZE - 1) & ~(SPI_FLASH_SEC_SIZE - 1);
|
||||
ret = esp_partition_erase_range(partition, 0, aligned_erase_size);
|
||||
}
|
||||
|
||||
if (ret != ESP_OK) {
|
||||
|
@ -87,9 +87,8 @@ class OtatoolTarget():
|
||||
seq = bytearray(self.otadata[start:start + 4])
|
||||
crc = bytearray(self.otadata[start + 28:start + 32])
|
||||
|
||||
seq = struct.unpack('>I', seq)
|
||||
crc = struct.unpack('>I', crc)
|
||||
|
||||
seq = struct.unpack('I', seq)
|
||||
crc = struct.unpack('I', crc)
|
||||
info.append(otadata_info(seq[0], crc[0]))
|
||||
|
||||
return info
|
||||
@ -108,7 +107,7 @@ class OtatoolTarget():
|
||||
|
||||
def is_otadata_info_valid(status):
|
||||
seq = status.seq % (1 << 32)
|
||||
crc = hex(binascii.crc32(struct.pack("I", seq), 0xFFFFFFFF) % (1 << 32))
|
||||
crc = binascii.crc32(struct.pack('I', seq), 0xFFFFFFFF) % (1 << 32)
|
||||
return seq < (int('0xFFFFFFFF', 16) % (1 << 32)) and status.crc == crc
|
||||
|
||||
partition_table = self.target.partition_table
|
||||
@ -219,8 +218,8 @@ def _read_otadata(target):
|
||||
|
||||
otadata_info = target._get_otadata_info()
|
||||
|
||||
print(" {:8s} \t {:8s} | \t {:8s} \t {:8s}".format("OTA_SEQ", "CRC", "OTA_SEQ", "CRC"))
|
||||
print("Firmware: 0x{:8x} \t0x{:8x} | \t0x{:8x} \t 0x{:8x}".format(otadata_info[0].seq, otadata_info[0].crc,
|
||||
print(' {:8s} \t {:8s} | \t {:8s} \t {:8s}'.format('OTA_SEQ', 'CRC', 'OTA_SEQ', 'CRC'))
|
||||
print('Firmware: 0x{:08x} \t0x{:08x} | \t0x{:08x} \t 0x{:08x}'.format(otadata_info[0].seq, otadata_info[0].crc,
|
||||
otadata_info[1].seq, otadata_info[1].crc))
|
||||
|
||||
|
||||
@ -249,6 +248,10 @@ def _erase_ota_partition(target, ota_id):
|
||||
|
||||
|
||||
def main():
|
||||
if sys.version_info[0] < 3:
|
||||
print("WARNING: Support for Python 2 is deprecated and will be removed in future versions.", file=sys.stderr)
|
||||
elif sys.version_info[0] == 3 and sys.version_info[1] < 6:
|
||||
print("WARNING: Python 3 versions older than 3.6 are not supported.", file=sys.stderr)
|
||||
global quiet
|
||||
|
||||
parser = argparse.ArgumentParser("ESP-IDF OTA Partitions Tool")
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
TEST_CASE("esp_ota_get_app_elf_sha256 test", "[esp_app_desc]")
|
||||
{
|
||||
const int sha256_hex_len = 64;
|
||||
const int sha256_hex_len = CONFIG_APP_RETRIEVE_LEN_ELF_SHA;
|
||||
char dst[sha256_hex_len + 2];
|
||||
const char fill = 0xcc;
|
||||
int res;
|
||||
|
@ -6,7 +6,7 @@ if(BOOTLOADER_BUILD OR NOT CONFIG_APP_BUILD_BOOTLOADER)
|
||||
endif()
|
||||
|
||||
# When secure boot is enabled, do not flash bootloader along with invocation of `idf.py flash`
|
||||
if(NOT CONFIG_SECURE_BOOT_ENABLED)
|
||||
if(NOT CONFIG_SECURE_BOOT)
|
||||
set(flash_bootloader FLASH_IN_PROJECT)
|
||||
endif()
|
||||
|
||||
|
@ -1,4 +1,29 @@
|
||||
menu "Bootloader config"
|
||||
|
||||
choice BOOTLOADER_COMPILER_OPTIMIZATION
|
||||
prompt "Bootloader optimization Level"
|
||||
default BOOTLOADER_COMPILER_OPTIMIZATION_SIZE
|
||||
help
|
||||
This option sets compiler optimization level (gcc -O argument)
|
||||
for the bootloader.
|
||||
|
||||
- The default "Size" setting will add the -0s flag to CFLAGS.
|
||||
- The "Debug" setting will add the -Og flag to CFLAGS.
|
||||
- The "Performance" setting will add the -O2 flag to CFLAGS.
|
||||
- The "None" setting will add the -O0 flag to CFLAGS.
|
||||
|
||||
Note that custom optimization levels may be unsupported.
|
||||
|
||||
config BOOTLOADER_COMPILER_OPTIMIZATION_SIZE
|
||||
bool "Size (-Os)"
|
||||
config BOOTLOADER_COMPILER_OPTIMIZATION_DEBUG
|
||||
bool "Debug (-Og)"
|
||||
config BOOTLOADER_COMPILER_OPTIMIZATION_PERF
|
||||
bool "Optimize for performance (-O2)"
|
||||
config BOOTLOADER_COMPILER_OPTIMIZATION_NONE
|
||||
bool "Debug without optimization (-O0)"
|
||||
endchoice
|
||||
|
||||
choice BOOTLOADER_LOG_LEVEL
|
||||
bool "Bootloader log verbosity"
|
||||
default BOOTLOADER_LOG_LEVEL_INFO
|
||||
@ -224,7 +249,7 @@ menu "Bootloader config"
|
||||
|
||||
config BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP
|
||||
bool "Skip image validation when exiting deep sleep"
|
||||
depends on (SECURE_BOOT_ENABLED && SECURE_BOOT_INSECURE) || !SECURE_BOOT_ENABLED
|
||||
depends on (SECURE_BOOT && SECURE_BOOT_INSECURE) || !SECURE_BOOT
|
||||
default n
|
||||
help
|
||||
This option disables the normal validation of an image coming out of
|
||||
@ -279,12 +304,12 @@ menu "Security features"
|
||||
config SECURE_SIGNED_ON_BOOT
|
||||
bool
|
||||
default y
|
||||
depends on SECURE_BOOT_ENABLED || SECURE_SIGNED_ON_BOOT_NO_SECURE_BOOT
|
||||
depends on SECURE_BOOT || SECURE_SIGNED_ON_BOOT_NO_SECURE_BOOT
|
||||
|
||||
config SECURE_SIGNED_ON_UPDATE
|
||||
bool
|
||||
default y
|
||||
depends on SECURE_BOOT_ENABLED || SECURE_SIGNED_ON_UPDATE_NO_SECURE_BOOT
|
||||
depends on SECURE_BOOT || SECURE_SIGNED_ON_UPDATE_NO_SECURE_BOOT
|
||||
|
||||
config SECURE_SIGNED_APPS
|
||||
bool
|
||||
@ -298,8 +323,7 @@ menu "Security features"
|
||||
|
||||
config SECURE_SIGNED_APPS_NO_SECURE_BOOT
|
||||
bool "Require signed app images"
|
||||
default n
|
||||
depends on !SECURE_BOOT_ENABLED
|
||||
depends on !SECURE_BOOT
|
||||
help
|
||||
Require apps to be signed to verify their integrity.
|
||||
|
||||
@ -308,6 +332,35 @@ menu "Security features"
|
||||
against remote network access, but not physical access. Compared to using hardware Secure Boot this option
|
||||
is much simpler to implement.
|
||||
|
||||
choice SECURE_SIGNED_APPS_SCHEME
|
||||
bool "App Signing Scheme"
|
||||
depends on SECURE_BOOT || SECURE_SIGNED_APPS_NO_SECURE_BOOT
|
||||
default SECURE_SIGNED_APPS_ECDSA_SCHEME if SECURE_BOOT_V1_ENABLED
|
||||
default SECURE_SIGNED_APPS_RSA_SCHEME if SECURE_BOOT_V2_ENABLED
|
||||
help
|
||||
Select the Secure App signing scheme. Depends on the Chip Revision.
|
||||
There are two options:
|
||||
1. ECDSA based secure boot scheme. (Only choice for Secure Boot V1)
|
||||
Supported in ESP32 and ESP32-ECO3.
|
||||
2. The RSA based secure boot scheme. (Only choice for Secure Boot V2)
|
||||
Supported in ESP32-ECO3. (ESP32 Chip Revision 3 onwards)
|
||||
|
||||
config SECURE_SIGNED_APPS_ECDSA_SCHEME
|
||||
bool "ECDSA"
|
||||
depends on IDF_TARGET_ESP32 && (SECURE_SIGNED_APPS_NO_SECURE_BOOT || SECURE_BOOT_V1_ENABLED)
|
||||
help
|
||||
Embeds the ECDSA public key in the bootloader and signs the application with an ECDSA key.
|
||||
|
||||
Refer to the documentation before enabling.
|
||||
|
||||
config SECURE_SIGNED_APPS_RSA_SCHEME
|
||||
bool "RSA"
|
||||
depends on ESP32_REV_MIN_3 && SECURE_BOOT_V2_ENABLED
|
||||
help
|
||||
Appends the RSA-3072 based Signature block to the application.
|
||||
Refer to <Secure Boot Version 2 documentation link> before enabling.
|
||||
endchoice
|
||||
|
||||
config SECURE_SIGNED_ON_BOOT_NO_SECURE_BOOT
|
||||
bool "Bootloader verifies app signatures"
|
||||
default n
|
||||
@ -334,23 +387,48 @@ menu "Security features"
|
||||
If hardware secure boot is not enabled, this option still adds significant security against network-based
|
||||
attackers by preventing spoofing of OTA updates.
|
||||
|
||||
config SECURE_BOOT_ENABLED
|
||||
bool "Enable hardware secure boot in bootloader (READ DOCS FIRST)"
|
||||
config SECURE_BOOT
|
||||
bool "Enable hardware Secure Boot in bootloader (READ DOCS FIRST)"
|
||||
default n
|
||||
help
|
||||
Build a bootloader which enables secure boot on first boot.
|
||||
Build a bootloader which enables Secure Boot on first boot.
|
||||
|
||||
Once enabled, secure boot will not boot a modified bootloader. The bootloader will only load a partition
|
||||
Once enabled, Secure Boot will not boot a modified bootloader. The bootloader will only load a partition
|
||||
table or boot an app if the data has a verified digital signature. There are implications for reflashing
|
||||
updated apps once secure boot is enabled.
|
||||
|
||||
When enabling secure boot, JTAG and ROM BASIC Interpreter are permanently disabled by default.
|
||||
|
||||
Refer to https://docs.espressif.com/projects/esp-idf/en/latest/security/secure-boot.html before enabling.
|
||||
choice SECURE_BOOT_VERSION
|
||||
bool "Select secure boot version"
|
||||
default SECURE_BOOT_V2_ENABLED if ESP32_REV_MIN_3
|
||||
depends on SECURE_BOOT
|
||||
help
|
||||
Select the Secure Boot Version. Depends on the Chip Revision.
|
||||
Secure Boot V2 is the new RSA based secure boot scheme.
|
||||
Supported in ESP32-ECO3. (ESP32 Chip Revision 3 onwards)
|
||||
Secure Boot V1 is the AES based secure boot scheme.
|
||||
Supported in ESP32 and ESP32-ECO3.
|
||||
|
||||
config SECURE_BOOT_V1_ENABLED
|
||||
bool "Enable Secure Boot version 1"
|
||||
depends on IDF_TARGET_ESP32
|
||||
help
|
||||
Build a bootloader which enables secure boot version 1 on first boot.
|
||||
Refer to the Secure Boot section of the ESP-IDF Programmer's Guide for this version before enabling.
|
||||
|
||||
config SECURE_BOOT_V2_ENABLED
|
||||
bool "Enable Secure Boot version 2"
|
||||
depends on ESP32_REV_MIN_3
|
||||
help
|
||||
Build a bootloader which enables Secure Boot version 2 on first boot.
|
||||
Refer to Secure Boot V2 section of the ESP-IDF Programmer's Guide for this version before enabling.
|
||||
|
||||
endchoice
|
||||
|
||||
choice SECURE_BOOTLOADER_MODE
|
||||
bool "Secure bootloader mode"
|
||||
depends on SECURE_BOOT_ENABLED
|
||||
depends on SECURE_BOOT_V1_ENABLED
|
||||
default SECURE_BOOTLOADER_ONE_TIME_FLASH
|
||||
|
||||
config SECURE_BOOTLOADER_ONE_TIME_FLASH
|
||||
@ -385,7 +463,8 @@ menu "Security features"
|
||||
If enabled (default), these binary files are signed as part of the build process. The file named in
|
||||
"Secure boot private signing key" will be used to sign the image.
|
||||
|
||||
If disabled, unsigned app/partition data will be built. They must be signed manually using espsecure.py
|
||||
If disabled, unsigned app/partition data will be built. They must be signed manually using espsecure.py.
|
||||
Version 1 to enable ECDSA Based Secure Boot and Version 2 to enable RSA based Secure Boot.
|
||||
(for example, on a remote signing server.)
|
||||
|
||||
config SECURE_BOOT_SIGNING_KEY
|
||||
@ -395,28 +474,32 @@ menu "Security features"
|
||||
help
|
||||
Path to the key file used to sign app images.
|
||||
|
||||
Key file is an ECDSA private key (NIST256p curve) in PEM format.
|
||||
Key file is an ECDSA private key (NIST256p curve) in PEM format for Secure Boot V1.
|
||||
Key file is an RSA private key in PEM format for Secure Boot V2.
|
||||
|
||||
Path is evaluated relative to the project directory.
|
||||
|
||||
You can generate a new signing key by running the following command:
|
||||
espsecure.py generate_signing_key secure_boot_signing_key.pem
|
||||
|
||||
See https://docs.espressif.com/projects/esp-idf/en/latest/security/secure-boot.html for details.
|
||||
See the Secure Boot section of the ESP-IDF Programmer's Guide for this version for details.
|
||||
|
||||
config SECURE_BOOT_VERIFICATION_KEY
|
||||
string "Secure boot public signature verification key"
|
||||
depends on SECURE_SIGNED_APPS && !SECURE_BOOT_BUILD_SIGNED_BINARIES
|
||||
depends on SECURE_SIGNED_APPS && !SECURE_BOOT_BUILD_SIGNED_BINARIES && !SECURE_SIGNED_APPS_RSA_SCHEME
|
||||
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
|
||||
Path to a public key file used to verify signed images.
|
||||
Secure Boot V1: This ECDSA public key is compiled into the bootloader and/or
|
||||
app, to verify app images.
|
||||
Secure Boot V2: This RSA public key is compiled into the signature block at
|
||||
the end of the bootloader/app.
|
||||
|
||||
Key file is in raw binary format, and can be extracted from a
|
||||
PEM formatted private key using the espsecure.py
|
||||
extract_public_key command.
|
||||
|
||||
Refer to https://docs.espressif.com/projects/esp-idf/en/latest/security/secure-boot.html before enabling.
|
||||
Refer to the Secure Boot section of the ESP-IDF Programmer's Guide for this version before enabling.
|
||||
|
||||
choice SECURE_BOOTLOADER_KEY_ENCODING
|
||||
bool "Hardware Key Encoding"
|
||||
@ -443,7 +526,7 @@ menu "Security features"
|
||||
|
||||
config SECURE_BOOT_INSECURE
|
||||
bool "Allow potentially insecure options"
|
||||
depends on SECURE_BOOT_ENABLED
|
||||
depends on SECURE_BOOT
|
||||
default N
|
||||
help
|
||||
You can disable some of the default protections offered by secure boot, in order to enable testing or a
|
||||
@ -451,11 +534,12 @@ menu "Security features"
|
||||
|
||||
Only enable these options if you are very sure.
|
||||
|
||||
Refer to https://docs.espressif.com/projects/esp-idf/en/latest/security/secure-boot.html before enabling.
|
||||
Refer to the Secure Boot section of the ESP-IDF Programmer's Guide for this version before enabling.
|
||||
|
||||
config SECURE_FLASH_ENC_ENABLED
|
||||
bool "Enable flash encryption on boot (READ DOCS FIRST)"
|
||||
default N
|
||||
select SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE
|
||||
help
|
||||
If this option is set, flash contents will be encrypted by the bootloader on first boot.
|
||||
|
||||
@ -495,7 +579,7 @@ menu "Security features"
|
||||
Select Release mode only for production or manufacturing. Once enabled you can not reflash using UART
|
||||
bootloader
|
||||
|
||||
Refer to https://docs.espressif.com/projects/esp-idf/en/latest/security/secure-boot.html and
|
||||
Refer to the Secure Boot section of the ESP-IDF Programmer's Guide for this version and
|
||||
https://docs.espressif.com/projects/esp-idf/en/latest/security/flash-encryption.html for details.
|
||||
|
||||
config SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
|
||||
@ -504,6 +588,7 @@ menu "Security features"
|
||||
|
||||
config SECURE_FLASH_ENCRYPTION_MODE_RELEASE
|
||||
bool "Release"
|
||||
select PARTITION_TABLE_MD5 if !ESP32_COMPATIBLE_PRE_V3_1_BOOTLOADERS
|
||||
|
||||
endchoice
|
||||
|
||||
@ -557,6 +642,18 @@ menu "Security features"
|
||||
image to this length. It is generally not recommended to set this option, unless you have a legacy
|
||||
partitioning scheme which doesn't support 64KB aligned partition lengths.
|
||||
|
||||
config SECURE_BOOT_V2_ALLOW_EFUSE_RD_DIS
|
||||
bool "Allow additional read protecting of efuses"
|
||||
depends on SECURE_BOOT_INSECURE && SECURE_BOOT_V2_ENABLED
|
||||
help
|
||||
If not set (default, recommended), on first boot the bootloader will burn the WR_DIS_RD_DIS
|
||||
efuse when Secure Boot is enabled. This prevents any more efuses from being read protected.
|
||||
|
||||
If this option is set, it will remain possible to write the EFUSE_RD_DIS efuse field after Secure
|
||||
Boot is enabled. This may allow an attacker to read-protect the BLK2 efuse holding the public
|
||||
key digest, causing an immediate denial of service and possibly allowing an additional fault
|
||||
injection attack to bypass the signature protection.
|
||||
|
||||
config SECURE_FLASH_UART_BOOTLOADER_ALLOW_ENC
|
||||
bool "Leave UART bootloader encryption enabled"
|
||||
depends on SECURE_FLASH_ENCRYPTION_MODE_DEVELOPMENT
|
||||
@ -603,5 +700,23 @@ menu "Security features"
|
||||
the wrong device. The device needs to have flash encryption already enabled using espefuse.py.
|
||||
|
||||
endmenu # Potentially Insecure
|
||||
|
||||
config SECURE_DISABLE_ROM_DL_MODE
|
||||
bool "Permanently disable ROM Download Mode"
|
||||
depends on ESP32_REV_MIN_3
|
||||
default n
|
||||
help
|
||||
If set, during startup the app will burn an eFuse bit to permanently disable the UART ROM
|
||||
Download Mode. This prevents any future use of esptool.py, espefuse.py and similar tools.
|
||||
|
||||
Once disabled, if the SoC is booted with strapping pins set for ROM Download Mode
|
||||
then an error is printed instead.
|
||||
|
||||
It is recommended to enable this option in any production application where Flash
|
||||
Encryption and/or Secure Boot is enabled and access to Download Mode is not required.
|
||||
|
||||
It is also possible to permanently disable Download Mode by calling
|
||||
esp_efuse_disable_rom_download_mode() at runtime.
|
||||
|
||||
endmenu # Security features
|
||||
|
||||
|
@ -45,7 +45,7 @@ clean: bootloader-clean
|
||||
bootloader-list-components:
|
||||
$(BOOTLOADER_MAKE) list-components
|
||||
|
||||
ifndef CONFIG_SECURE_BOOT_ENABLED
|
||||
ifndef CONFIG_SECURE_BOOT
|
||||
# If secure boot disabled, bootloader flashing is integrated
|
||||
# with 'make flash' and no warnings are printed.
|
||||
|
||||
@ -115,13 +115,35 @@ $(BOOTLOADER_DIGEST_BIN): $(BOOTLOADER_BIN) $(SECURE_BOOTLOADER_KEY) | check_pyt
|
||||
@echo "DIGEST $(notdir $@)"
|
||||
$(ESPSECUREPY) digest_secure_bootloader -k $(SECURE_BOOTLOADER_KEY) -o $@ $<
|
||||
|
||||
else # CONFIG_SECURE_BOOT_ENABLED && !CONFIG_SECURE_BOOTLOADER_REFLASHABLE && !CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH
|
||||
else ifdef CONFIG_SECURE_BOOT_V2_ENABLED
|
||||
BOOTLOADER_SIGNED_BIN := $(BOOTLOADER_BUILD_DIR)/bootloader-signed.bin
|
||||
ifdef CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES
|
||||
bootloader: $(BOOTLOADER_BIN) $(SDKCONFIG_MAKEFILE) | check_python_dependencies
|
||||
$(ESPSECUREPY) sign_data --keyfile $(SECURE_BOOT_SIGNING_KEY) --version 2 \
|
||||
-o $(BOOTLOADER_SIGNED_BIN) $(BOOTLOADER_BIN)
|
||||
else
|
||||
bootloader: $(BOOTLOADER_BIN) $(SDKCONFIG_MAKEFILE) | check_python_dependencies
|
||||
@echo "Bootloader not signed. Sign the bootloader before flashing."
|
||||
@echo "To sign the bootloader, you can use this command:"
|
||||
@echo "espsecure.py sign_data --keyfile SECURE_BOOT_SIGNING_KEY --version 2 $(BOOTLOADER_BIN)"
|
||||
endif
|
||||
@echo $(SEPARATOR)
|
||||
@echo "Use the following command to flash the bootloader:"
|
||||
ifdef CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES
|
||||
@echo "$(ESPTOOLPY_WRITE_FLASH) $(BOOTLOADER_OFFSET) $(BOOTLOADER_SIGNED_BIN)"
|
||||
else
|
||||
@echo "$(ESPTOOLPY_WRITE_FLASH) $(BOOTLOADER_OFFSET) $(BOOTLOADER_BIN)"
|
||||
endif
|
||||
@echo $(SEPARATOR)
|
||||
|
||||
else # CONFIG_SECURE_BOOT && !CONFIG_SECURE_BOOTLOADER_REFLASHABLE \
|
||||
&& !CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH && !CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME
|
||||
bootloader:
|
||||
@echo "Invalid bootloader target: bad sdkconfig?"
|
||||
@exit 1
|
||||
endif
|
||||
|
||||
ifndef CONFIG_SECURE_BOOT_ENABLED
|
||||
ifndef CONFIG_SECURE_BOOT
|
||||
# don't build bootloader by default if secure boot is enabled
|
||||
all_binaries: $(BOOTLOADER_BIN)
|
||||
endif
|
||||
@ -131,3 +153,8 @@ bootloader-clean: $(SDKCONFIG_MAKEFILE)
|
||||
ifdef CONFIG_SECURE_BOOTLOADER_REFLASHABLE
|
||||
rm -f $(SECURE_BOOTLOADER_KEY) $(BOOTLOADER_DIGEST_BIN)
|
||||
endif
|
||||
ifdef CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME
|
||||
ifdef CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES
|
||||
rm -f $(BOOTLOADER_SIGNED_BIN)
|
||||
endif
|
||||
endif
|
@ -19,8 +19,8 @@ set(bootloader_binary_files
|
||||
|
||||
idf_build_get_property(project_dir PROJECT_DIR)
|
||||
|
||||
# There are some additional processing when CONFIG_CONFIG_SECURE_SIGNED_APPS. This happens
|
||||
# when either CONFIG_SECURE_BOOT_ENABLED or SECURE_BOOT_BUILD_SIGNED_BINARIES.
|
||||
# There are some additional processing when CONFIG_SECURE_SIGNED_APPS. This happens
|
||||
# when either CONFIG_SECURE_BOOT_V1_ENABLED or CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES.
|
||||
# For both cases, the user either sets binaries to be signed during build or not
|
||||
# using CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES.
|
||||
#
|
||||
@ -29,7 +29,13 @@ idf_build_get_property(project_dir PROJECT_DIR)
|
||||
if(CONFIG_SECURE_SIGNED_APPS)
|
||||
add_custom_target(gen_secure_boot_keys)
|
||||
|
||||
if(CONFIG_SECURE_BOOT_ENABLED)
|
||||
if(CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME)
|
||||
set(secure_apps_signing_scheme "1")
|
||||
elseif(CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME)
|
||||
set(secure_apps_signing_scheme "2")
|
||||
endif()
|
||||
|
||||
if(CONFIG_SECURE_BOOT_V1_ENABLED)
|
||||
# Check that the configuration is sane
|
||||
if((CONFIG_SECURE_BOOTLOADER_REFLASHABLE AND CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH) OR
|
||||
(NOT CONFIG_SECURE_BOOTLOADER_REFLASHABLE AND NOT CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH))
|
||||
@ -60,7 +66,8 @@ if(CONFIG_SECURE_SIGNED_APPS)
|
||||
# (to pick up a new signing key if one exists, etc.)
|
||||
fail_at_build_time(gen_secure_boot_signing_key
|
||||
"Secure Boot Signing Key ${CONFIG_SECURE_BOOT_SIGNING_KEY} does not exist. Generate using:"
|
||||
"\tespsecure.py generate_signing_key ${CONFIG_SECURE_BOOT_SIGNING_KEY}")
|
||||
"\tespsecure.py generate_signing_key --version ${secure_apps_signing_scheme} \
|
||||
${CONFIG_SECURE_BOOT_SIGNING_KEY}")
|
||||
else()
|
||||
add_custom_target(gen_secure_boot_signing_key)
|
||||
endif()
|
||||
@ -70,7 +77,7 @@ if(CONFIG_SECURE_SIGNED_APPS)
|
||||
set(ver_key_arg)
|
||||
|
||||
add_dependencies(gen_secure_boot_keys gen_secure_boot_signing_key)
|
||||
else()
|
||||
elseif(CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME)
|
||||
|
||||
get_filename_component(secure_boot_verification_key
|
||||
${CONFIG_SECURE_BOOT_VERIFICATION_KEY}
|
||||
@ -83,7 +90,7 @@ if(CONFIG_SECURE_SIGNED_APPS)
|
||||
fail_at_build_time(gen_secure_boot_verification_key
|
||||
"Secure Boot Verification Public Key ${CONFIG_SECURE_BOOT_VERIFICATION_KEY} does not exist."
|
||||
"\tThis can be extracted from the private signing key."
|
||||
"\tSee docs/security/secure-boot.rst for details.")
|
||||
"\tSee docs/security/secure-boot-v1.rst for details.")
|
||||
else()
|
||||
add_custom_target(gen_secure_boot_verification_key)
|
||||
endif()
|
||||
|
@ -20,3 +20,6 @@ CONFIG_FLASH_ENCRYPTION_INSECURE CONFIG_SECURE_FLASH_
|
||||
CONFIG_FLASH_ENCRYPTION_UART_BOOTLOADER_ALLOW_ENCRYPT CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_ENC
|
||||
CONFIG_FLASH_ENCRYPTION_UART_BOOTLOADER_ALLOW_DECRYPT CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_DEC
|
||||
CONFIG_FLASH_ENCRYPTION_UART_BOOTLOADER_ALLOW_CACHE CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_CACHE
|
||||
|
||||
# Secure Boot Scheme
|
||||
CONFIG_SECURE_BOOT_ENABLED CONFIG_SECURE_BOOT_V1_ENABLED
|
||||
|
@ -83,6 +83,39 @@ if(CONFIG_SECURE_BOOTLOADER_REFLASHABLE)
|
||||
add_custom_target (gen_bootloader_digest_bin ALL DEPENDS "${bootloader_digest_bin}")
|
||||
endif()
|
||||
|
||||
if(CONFIG_SECURE_BOOT_V2_ENABLED)
|
||||
if(CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES)
|
||||
get_filename_component(secure_boot_signing_key
|
||||
"${SECURE_BOOT_SIGNING_KEY}" ABSOLUTE BASE_DIR "${project_dir}")
|
||||
|
||||
if(NOT EXISTS "${secure_boot_signing_key}")
|
||||
message(FATAL_ERROR
|
||||
"Secure Boot Signing Key Not found."
|
||||
"\nGenerate the Secure Boot V2 RSA-PSS 3072 Key."
|
||||
"\nTo generate one, you can use this command:"
|
||||
"\n\t${espsecurepy} generate_signing_key --version 2 ${SECURE_BOOT_SIGNING_KEY}")
|
||||
endif()
|
||||
|
||||
set(bootloader_unsigned_bin "bootloader-unsigned.bin")
|
||||
add_custom_command(OUTPUT ".signed_bin_timestamp"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/${PROJECT_BIN}" "${CMAKE_BINARY_DIR}/${bootloader_unsigned_bin}"
|
||||
COMMAND ${ESPSECUREPY} sign_data --version 2 --keyfile "${secure_boot_signing_key}"
|
||||
-o "${CMAKE_BINARY_DIR}/${PROJECT_BIN}" "${CMAKE_BINARY_DIR}/${bootloader_unsigned_bin}"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "Generated signed binary image ${build_dir}/${PROJECT_BIN}"
|
||||
"from ${CMAKE_BINARY_DIR}/${bootloader_unsigned_bin}"
|
||||
COMMAND ${CMAKE_COMMAND} -E md5sum "${CMAKE_BINARY_DIR}/${PROJECT_BIN}" > "${CMAKE_BINARY_DIR}/.signed_bin_timestamp"
|
||||
DEPENDS "${build_dir}/.bin_timestamp"
|
||||
VERBATIM
|
||||
COMMENT "Generated the signed Bootloader")
|
||||
else()
|
||||
add_custom_command(OUTPUT ".signed_bin_timestamp"
|
||||
VERBATIM
|
||||
COMMENT "Bootloader generated but not signed")
|
||||
endif()
|
||||
|
||||
add_custom_target (gen_signed_bootloader ALL DEPENDS "${build_dir}/.signed_bin_timestamp")
|
||||
endif()
|
||||
|
||||
if(CONFIG_SECURE_BOOTLOADER_ONE_TIME_FLASH)
|
||||
add_custom_command(TARGET bootloader.elf POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E echo
|
||||
@ -126,4 +159,18 @@ elseif(CONFIG_SECURE_BOOTLOADER_REFLASHABLE)
|
||||
"* Not recommended to re-use the same secure boot keyfile on multiple production devices."
|
||||
DEPENDS gen_secure_bootloader_key gen_bootloader_digest_bin
|
||||
VERBATIM)
|
||||
elseif(CONFIG_SECURE_BOOT_V2_ENABLED)
|
||||
add_custom_command(TARGET bootloader.elf POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E echo
|
||||
"=============================================================================="
|
||||
COMMAND ${CMAKE_COMMAND} -E echo
|
||||
"Bootloader built. Secure boot enabled, so bootloader not flashed automatically."
|
||||
COMMAND ${CMAKE_COMMAND} -E echo
|
||||
"Secure boot enabled, so bootloader not flashed automatically."
|
||||
COMMAND ${CMAKE_COMMAND} -E echo
|
||||
"\t${esptoolpy_write_flash} ${BOOTLOADER_OFFSET} ${CMAKE_BINARY_DIR}/bootloader.bin"
|
||||
COMMAND ${CMAKE_COMMAND} -E echo
|
||||
"=============================================================================="
|
||||
DEPENDS gen_signed_bootloader
|
||||
VERBATIM)
|
||||
endif()
|
||||
|
@ -1,3 +1,3 @@
|
||||
# only compile the "micro-ecc/uECC.c" source file
|
||||
idf_component_register(SRCS "micro-ecc/uECC.c"
|
||||
INCLUDE_DIRS micro-ecc)
|
||||
# only compile the "uECC_verify_antifault.c" file which includes the "micro-ecc/uECC.c" source file
|
||||
idf_component_register(SRCS "uECC_verify_antifault.c"
|
||||
INCLUDE_DIRS . micro-ecc)
|
||||
|
@ -1,8 +1,6 @@
|
||||
# only compile the micro-ecc/uECC.c source file
|
||||
# (SRCDIRS is needed so build system can find the source file)
|
||||
COMPONENT_SRCDIRS := micro-ecc
|
||||
COMPONENT_OBJS := micro-ecc/uECC.o
|
||||
# only compile the "uECC_verify_antifault.c" file which includes the "micro-ecc/uECC.c" source file
|
||||
COMPONENT_SRCDIRS := .
|
||||
|
||||
COMPONENT_ADD_INCLUDEDIRS := micro-ecc
|
||||
COMPONENT_ADD_INCLUDEDIRS := . micro-ecc
|
||||
|
||||
COMPONENT_SUBMODULES := micro-ecc
|
||||
|
@ -0,0 +1,141 @@
|
||||
/* Copyright 2014, Kenneth MacKay. Licensed under the BSD 2-clause license.
|
||||
|
||||
Modifications Copyright 2020, Espressif Systems (Shanghai) PTE LTD. Licensed under the BSD
|
||||
2-clause license.
|
||||
*/
|
||||
|
||||
/* uECC_verify() calls a number of static functions form here and
|
||||
uses other definitions, so we just build that whole source file here and then append
|
||||
our modified version uECC_verify_antifault(). */
|
||||
#include "micro-ecc/uECC.c"
|
||||
|
||||
/* Version of uECC_verify() which also copies message_hash into verified_hash,
|
||||
but only if the signature is valid. Does this in an FI resistant way.
|
||||
*/
|
||||
int uECC_verify_antifault(const uint8_t *public_key,
|
||||
const uint8_t *message_hash,
|
||||
unsigned hash_size,
|
||||
const uint8_t *signature,
|
||||
uECC_Curve curve,
|
||||
uint8_t *verified_hash) {
|
||||
uECC_word_t u1[uECC_MAX_WORDS], u2[uECC_MAX_WORDS];
|
||||
uECC_word_t z[uECC_MAX_WORDS];
|
||||
uECC_word_t sum[uECC_MAX_WORDS * 2];
|
||||
uECC_word_t rx[uECC_MAX_WORDS];
|
||||
uECC_word_t ry[uECC_MAX_WORDS];
|
||||
uECC_word_t tx[uECC_MAX_WORDS];
|
||||
uECC_word_t ty[uECC_MAX_WORDS];
|
||||
uECC_word_t tz[uECC_MAX_WORDS];
|
||||
const uECC_word_t *points[4];
|
||||
const uECC_word_t *point;
|
||||
bitcount_t num_bits;
|
||||
bitcount_t i;
|
||||
#if uECC_VLI_NATIVE_LITTLE_ENDIAN
|
||||
uECC_word_t *_public = (uECC_word_t *)public_key;
|
||||
#else
|
||||
uECC_word_t _public[uECC_MAX_WORDS * 2];
|
||||
#endif
|
||||
uECC_word_t r[uECC_MAX_WORDS], s[uECC_MAX_WORDS];
|
||||
wordcount_t num_words = curve->num_words;
|
||||
wordcount_t num_n_words = BITS_TO_WORDS(curve->num_n_bits);
|
||||
|
||||
rx[num_n_words - 1] = 0;
|
||||
r[num_n_words - 1] = 0;
|
||||
s[num_n_words - 1] = 0;
|
||||
|
||||
#if uECC_VLI_NATIVE_LITTLE_ENDIAN
|
||||
bcopy((uint8_t *) r, signature, curve->num_bytes);
|
||||
bcopy((uint8_t *) s, signature + curve->num_bytes, curve->num_bytes);
|
||||
#else
|
||||
uECC_vli_bytesToNative(_public, public_key, curve->num_bytes);
|
||||
uECC_vli_bytesToNative(
|
||||
_public + num_words, public_key + curve->num_bytes, curve->num_bytes);
|
||||
uECC_vli_bytesToNative(r, signature, curve->num_bytes);
|
||||
uECC_vli_bytesToNative(s, signature + curve->num_bytes, curve->num_bytes);
|
||||
#endif
|
||||
|
||||
/* r, s must not be 0. */
|
||||
if (uECC_vli_isZero(r, num_words) || uECC_vli_isZero(s, num_words)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* r, s must be < n. */
|
||||
if (uECC_vli_cmp(curve->n, r, num_n_words) != 1 ||
|
||||
uECC_vli_cmp(curve->n, s, num_n_words) != 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Calculate u1 and u2. */
|
||||
uECC_vli_modInv(z, s, curve->n, num_n_words); /* z = 1/s */
|
||||
u1[num_n_words - 1] = 0;
|
||||
bits2int(u1, message_hash, hash_size, curve);
|
||||
uECC_vli_modMult(u1, u1, z, curve->n, num_n_words); /* u1 = e/s */
|
||||
uECC_vli_modMult(u2, r, z, curve->n, num_n_words); /* u2 = r/s */
|
||||
|
||||
/* Calculate sum = G + Q. */
|
||||
uECC_vli_set(sum, _public, num_words);
|
||||
uECC_vli_set(sum + num_words, _public + num_words, num_words);
|
||||
uECC_vli_set(tx, curve->G, num_words);
|
||||
uECC_vli_set(ty, curve->G + num_words, num_words);
|
||||
uECC_vli_modSub(z, sum, tx, curve->p, num_words); /* z = x2 - x1 */
|
||||
XYcZ_add(tx, ty, sum, sum + num_words, curve);
|
||||
uECC_vli_modInv(z, z, curve->p, num_words); /* z = 1/z */
|
||||
apply_z(sum, sum + num_words, z, curve);
|
||||
|
||||
/* Use Shamir's trick to calculate u1*G + u2*Q */
|
||||
points[0] = 0;
|
||||
points[1] = curve->G;
|
||||
points[2] = _public;
|
||||
points[3] = sum;
|
||||
num_bits = smax(uECC_vli_numBits(u1, num_n_words),
|
||||
uECC_vli_numBits(u2, num_n_words));
|
||||
|
||||
point = points[(!!uECC_vli_testBit(u1, num_bits - 1)) |
|
||||
((!!uECC_vli_testBit(u2, num_bits - 1)) << 1)];
|
||||
uECC_vli_set(rx, point, num_words);
|
||||
uECC_vli_set(ry, point + num_words, num_words);
|
||||
uECC_vli_clear(z, num_words);
|
||||
z[0] = 1;
|
||||
|
||||
for (i = num_bits - 2; i >= 0; --i) {
|
||||
uECC_word_t index;
|
||||
curve->double_jacobian(rx, ry, z, curve);
|
||||
|
||||
index = (!!uECC_vli_testBit(u1, i)) | ((!!uECC_vli_testBit(u2, i)) << 1);
|
||||
point = points[index];
|
||||
if (point) {
|
||||
uECC_vli_set(tx, point, num_words);
|
||||
uECC_vli_set(ty, point + num_words, num_words);
|
||||
apply_z(tx, ty, z, curve);
|
||||
uECC_vli_modSub(tz, rx, tx, curve->p, num_words); /* Z = x2 - x1 */
|
||||
XYcZ_add(tx, ty, rx, ry, curve);
|
||||
uECC_vli_modMult_fast(z, z, tz, curve);
|
||||
}
|
||||
}
|
||||
|
||||
uECC_vli_modInv(z, z, curve->p, num_words); /* Z = 1/Z */
|
||||
apply_z(rx, ry, z, curve);
|
||||
|
||||
/* v = x1 (mod n) */
|
||||
if (uECC_vli_cmp(curve->n, rx, num_n_words) != 1) {
|
||||
uECC_vli_sub(rx, rx, curve->n, num_n_words);
|
||||
}
|
||||
|
||||
/* Anti-FI addition. Copy message_hash into verified_hash, but do it in a
|
||||
way that it will only happen if v == r (ie, rx == r)
|
||||
*/
|
||||
const uECC_word_t *mhash_words = (const uECC_word_t *)message_hash;
|
||||
uECC_word_t *vhash_words = (uECC_word_t *)verified_hash;
|
||||
unsigned hash_words = hash_size / sizeof(uECC_word_t);
|
||||
for (int w = 0; w < hash_words; w++) {
|
||||
/* note: using curve->num_words here to encourage compiler to re-read this variable */
|
||||
vhash_words[w] = mhash_words[w] ^ rx[w % curve->num_words] ^ r[w % curve->num_words];
|
||||
}
|
||||
/* Curve may be longer than hash, in which case keep reading the rest of the bytes */
|
||||
for (int w = hash_words; w < curve->num_words; w++) {
|
||||
vhash_words[w % hash_words] |= rx[w] ^ r[w];
|
||||
}
|
||||
|
||||
/* Accept only if v == r. */
|
||||
return (int)(uECC_vli_equal(rx, r, num_words));
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
/* Copyright 2014, Kenneth MacKay. Licensed under the BSD 2-clause license.
|
||||
|
||||
Modifications Copyright 2020, Espressif Systems (Shanghai) PTE LTD. Licensed under the BSD
|
||||
2-clause license.
|
||||
*/
|
||||
#pragma once
|
||||
#include "uECC.h"
|
||||
|
||||
/* Version uECC_verify() that also copies message_hash to verified_hash
|
||||
if the signature is valid, and does it in a way that is harder to attack
|
||||
with fault injection.
|
||||
*/
|
||||
int uECC_verify_antifault(const uint8_t *public_key,
|
||||
const uint8_t *message_hash,
|
||||
unsigned hash_size,
|
||||
const uint8_t *signature,
|
||||
uECC_Curve curve,
|
||||
uint8_t *verified_hash);
|
@ -17,6 +17,9 @@ ifdef CONFIG_IDF_TARGET_ESP32
|
||||
ifndef CONFIG_SPI_FLASH_ROM_DRIVER_PATCH
|
||||
LINKER_SCRIPTS += $(IDF_PATH)/components/esp_rom/$(IDF_TARGET)/ld/$(IDF_TARGET).rom.spiflash.ld
|
||||
endif
|
||||
ifdef CONFIG_ESP32_REV_MIN_3
|
||||
LINKER_SCRIPTS += $(IDF_PATH)/components/esp_rom/$(IDF_TARGET)/ld/$(IDF_TARGET).rom.eco3.ld
|
||||
endif
|
||||
endif
|
||||
|
||||
COMPONENT_ADD_LDFLAGS += -L $(COMPONENT_PATH) $(addprefix -T ,$(LINKER_SCRIPTS))
|
||||
|
@ -44,6 +44,7 @@ SECTIONS
|
||||
*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.*)
|
||||
*libbootloader_support.a:bootloader_efuse_esp32.*(.literal .text .literal.* .text.*)
|
||||
*libbootloader_support.a:bootloader_utility.*(.literal .text .literal.* .text.*)
|
||||
*libbootloader_support.a:bootloader_sha.*(.literal .text .literal.* .text.*)
|
||||
*libbootloader_support.a:esp_image_format.*(.literal .text .literal.* .text.*)
|
||||
@ -75,6 +76,7 @@ SECTIONS
|
||||
.dram0.bss (NOLOAD) :
|
||||
{
|
||||
. = ALIGN (8);
|
||||
_dram_start = ABSOLUTE(.);
|
||||
_bss_start = ABSOLUTE(.);
|
||||
*(.dynsbss)
|
||||
*(.sbss)
|
||||
@ -151,6 +153,7 @@ SECTIONS
|
||||
*(.gnu.linkonce.lit4.*)
|
||||
_lit4_end = ABSOLUTE(.);
|
||||
. = ALIGN(4);
|
||||
_dram_end = ABSOLUTE(.);
|
||||
} >dram_seg
|
||||
|
||||
.iram.text :
|
||||
|
@ -37,6 +37,7 @@ SECTIONS
|
||||
*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.*)
|
||||
*libbootloader_support.a:bootloader_efuse_esp32s2.*(.literal .text .literal.* .text.*)
|
||||
*libbootloader_support.a:bootloader_utility.*(.literal .text .literal.* .text.*)
|
||||
*libbootloader_support.a:bootloader_sha.*(.literal .text .literal.* .text.*)
|
||||
*libbootloader_support.a:esp_image_format.*(.literal .text .literal.* .text.*)
|
||||
@ -67,6 +68,7 @@ SECTIONS
|
||||
.dram0.bss (NOLOAD) :
|
||||
{
|
||||
. = ALIGN (8);
|
||||
_dram_start = ABSOLUTE(.);
|
||||
_bss_start = ABSOLUTE(.);
|
||||
*(.dynsbss)
|
||||
*(.sbss)
|
||||
@ -143,7 +145,7 @@ SECTIONS
|
||||
*(.gnu.linkonce.lit4.*)
|
||||
_lit4_end = ABSOLUTE(.);
|
||||
. = ALIGN(4);
|
||||
_heap_start = ABSOLUTE(.);
|
||||
_dram_end = ABSOLUTE(.);
|
||||
} >dram_seg
|
||||
|
||||
.iram.text :
|
||||
|
@ -20,22 +20,34 @@ if(BOOTLOADER_BUILD)
|
||||
set(include_dirs "include" "include_bootloader")
|
||||
set(priv_requires micro-ecc spi_flash efuse)
|
||||
list(APPEND srcs
|
||||
"src/bootloader_init.c"
|
||||
"src/${IDF_TARGET}/bootloader_sha.c"
|
||||
"src/${IDF_TARGET}/flash_encrypt.c"
|
||||
"src/${IDF_TARGET}/secure_boot_signatures.c"
|
||||
"src/${IDF_TARGET}/secure_boot.c"
|
||||
"src/${IDF_TARGET}/bootloader_${IDF_TARGET}.c"
|
||||
)
|
||||
"src/bootloader_init.c"
|
||||
"src/${IDF_TARGET}/bootloader_sha.c"
|
||||
"src/${IDF_TARGET}/flash_encrypt.c"
|
||||
"src/${IDF_TARGET}/bootloader_${IDF_TARGET}.c"
|
||||
)
|
||||
else()
|
||||
list(APPEND srcs
|
||||
"src/idf/bootloader_sha.c"
|
||||
"src/idf/secure_boot_signatures.c")
|
||||
"src/idf/bootloader_sha.c")
|
||||
set(include_dirs "include")
|
||||
set(priv_include_dirs "include_bootloader")
|
||||
set(priv_requires spi_flash mbedtls efuse)
|
||||
endif()
|
||||
|
||||
if(CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME OR CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME)
|
||||
if(BOOTLOADER_BUILD)
|
||||
list(APPEND srcs
|
||||
"src/${IDF_TARGET}/secure_boot_signatures.c")
|
||||
else()
|
||||
list(APPEND srcs
|
||||
"src/idf/secure_boot_signatures.c")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(CONFIG_SECURE_BOOT AND BOOTLOADER_BUILD)
|
||||
list(APPEND srcs
|
||||
"src/${IDF_TARGET}/secure_boot.c")
|
||||
endif()
|
||||
|
||||
set(requires soc) #unfortunately the header directly uses SOC registers
|
||||
|
||||
idf_component_register(SRCS "${srcs}"
|
||||
@ -44,7 +56,7 @@ idf_component_register(SRCS "${srcs}"
|
||||
REQUIRES "${requires}"
|
||||
PRIV_REQUIRES "${priv_requires}")
|
||||
|
||||
if(CONFIG_SECURE_SIGNED_APPS)
|
||||
if(CONFIG_SECURE_SIGNED_APPS AND (CONFIG_SECURE_BOOT_V1_ENABLED OR CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME))
|
||||
if(BOOTLOADER_BUILD)
|
||||
# Whether CONFIG_SECURE_BOOT_BUILD_SIGNED_BINARIES or not, we need verification key to embed
|
||||
# in the library.
|
||||
|
@ -22,11 +22,23 @@ endif
|
||||
COMPONENT_OBJEXCLUDE += src/bootloader_flash_config_esp32s2beta.o \
|
||||
src/bootloader_efuse_esp32s2beta.o
|
||||
|
||||
ifndef CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME
|
||||
ifndef CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME
|
||||
COMPONENT_OBJEXCLUDE += src/$(IDF_TARGET)/secure_boot_signatures.o \
|
||||
src/idf/secure_boot_signatures.o
|
||||
endif
|
||||
endif
|
||||
|
||||
ifndef CONFIG_SECURE_BOOT
|
||||
COMPONENT_OBJEXCLUDE += src/$(IDF_TARGET)/secure_boot.o
|
||||
endif
|
||||
|
||||
#
|
||||
# Secure boot signing key support
|
||||
#
|
||||
ifdef CONFIG_SECURE_SIGNED_APPS
|
||||
|
||||
ifdef CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME
|
||||
# this path is created relative to the component build directory
|
||||
SECURE_BOOT_VERIFICATION_KEY := $(abspath signature_verification_key.bin)
|
||||
|
||||
@ -41,7 +53,7 @@ ORIG_SECURE_BOOT_VERIFICATION_KEY := $(call resolvepath,$(call dequote,$(CONFIG_
|
||||
$(ORIG_SECURE_BOOT_VERIFICATION_KEY):
|
||||
@echo "Secure boot verification public key '$@' missing."
|
||||
@echo "This can be extracted from the private signing key, see"
|
||||
@echo "docs/security/secure-boot.rst for details."
|
||||
@echo "docs/security/secure-boot-v1.rst for details."
|
||||
exit 1
|
||||
|
||||
# copy it into the build dir, so the secure boot verification key has
|
||||
@ -55,4 +67,5 @@ COMPONENT_EXTRA_CLEAN += $(SECURE_BOOT_VERIFICATION_KEY)
|
||||
|
||||
COMPONENT_EMBED_FILES := $(SECURE_BOOT_VERIFICATION_KEY)
|
||||
|
||||
endif #CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME
|
||||
endif #CONFIG_SECURE_SIGNED_APPS
|
||||
|
@ -27,6 +27,14 @@ extern "C" {
|
||||
*/
|
||||
void bootloader_flash_update_id(void);
|
||||
|
||||
/**
|
||||
* @brief Update the flash size in g_rom_flashchip (global esp_rom_spiflash_chip_t structure).
|
||||
*
|
||||
* @param size The size to store, in bytes.
|
||||
* @return None
|
||||
*/
|
||||
void bootloader_flash_update_size(uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Set the flash CS setup and hold time.
|
||||
*
|
||||
|
@ -128,6 +128,10 @@ esp_err_t esp_flash_encrypt_region(uint32_t src_addr, size_t data_length);
|
||||
* is enabled but secure boot is not used. This should protect against
|
||||
* serial re-flashing of an unauthorised code in absence of secure boot.
|
||||
*
|
||||
* @note On ESP32 V3 only, write protecting FLASH_CRYPT_CNT will also prevent
|
||||
* disabling UART Download Mode. If both are wanted, call
|
||||
* esp_efuse_disable_rom_download_mode() before calling this function.
|
||||
*
|
||||
*/
|
||||
void esp_flash_write_protect_crypt_cnt(void);
|
||||
|
||||
|
@ -42,6 +42,9 @@ extern "C" {
|
||||
|
||||
#define PART_FLAG_ENCRYPTED (1<<0)
|
||||
|
||||
/* The md5sum value is found this many bytes after the ESP_PARTITION_MAGIC_MD5 offset */
|
||||
#define ESP_PARTITION_MD5_OFFSET 16
|
||||
|
||||
/* Pre-partition table fixed flash offsets */
|
||||
#define ESP_BOOTLOADER_DIGEST_OFFSET 0x0
|
||||
#define ESP_BOOTLOADER_OFFSET 0x1000 /* Offset of bootloader image. Has matching value in bootloader KConfig.projbuild file. */
|
||||
|
@ -169,6 +169,14 @@ esp_err_t esp_image_verify_bootloader(uint32_t *length);
|
||||
*/
|
||||
esp_err_t esp_image_verify_bootloader_data(esp_image_metadata_t *data);
|
||||
|
||||
/**
|
||||
* @brief Get the flash size of the image
|
||||
*
|
||||
* @param app_flash_size The value configured in the image header
|
||||
* @return Actual size, in bytes.
|
||||
*/
|
||||
int esp_image_get_flash_size(esp_image_flash_size_t app_flash_size);
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint32_t drom_addr;
|
||||
|
@ -16,13 +16,18 @@
|
||||
#include <stdbool.h>
|
||||
#include <esp_err.h>
|
||||
#include "soc/efuse_periph.h"
|
||||
#include "esp_image_format.h"
|
||||
|
||||
#include "sdkconfig.h"
|
||||
#if CONFIG_IDF_TARGET_ESP32S2BETA
|
||||
#include "esp32s2beta/rom/efuse.h"
|
||||
#else
|
||||
#include "esp32/rom/secure_boot.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SECURE_BOOT_ENABLED
|
||||
typedef struct ets_secure_boot_signature ets_secure_boot_signature_t;
|
||||
|
||||
#ifdef CONFIG_SECURE_BOOT_V1_ENABLED
|
||||
#if !defined(CONFIG_SECURE_SIGNED_ON_BOOT) || !defined(CONFIG_SECURE_SIGNED_ON_UPDATE) || !defined(CONFIG_SECURE_SIGNED_APPS)
|
||||
#error "internal sdkconfig error, secure boot should always enable all signature options"
|
||||
#endif
|
||||
@ -47,16 +52,23 @@ extern "C" {
|
||||
static inline bool esp_secure_boot_enabled(void)
|
||||
{
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
return REG_READ(EFUSE_BLK0_RDATA6_REG) & EFUSE_RD_ABS_DONE_0;
|
||||
#ifdef CONFIG_SECURE_BOOT_V1_ENABLED
|
||||
return REG_READ(EFUSE_BLK0_RDATA6_REG) & EFUSE_RD_ABS_DONE_0;
|
||||
#elif CONFIG_SECURE_BOOT_V2_ENABLED
|
||||
return ets_use_secure_boot_v2();
|
||||
#endif
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2BETA
|
||||
return ets_efuse_secure_boot_enabled();
|
||||
#endif
|
||||
return false; /* Secure Boot not enabled in menuconfig */
|
||||
}
|
||||
|
||||
/** @brief Generate secure digest from bootloader image
|
||||
*
|
||||
* @important This function is intended to be called from bootloader code only.
|
||||
*
|
||||
* This function is only used in the context of the Secure Boot V1 scheme.
|
||||
*
|
||||
* If secure boot is not yet enabled for bootloader, this will:
|
||||
* 1) generate the secure boot key and burn it on EFUSE
|
||||
* (without enabling R/W protection)
|
||||
@ -73,18 +85,17 @@ static inline bool esp_secure_boot_enabled(void)
|
||||
*/
|
||||
esp_err_t esp_secure_boot_generate_digest(void);
|
||||
|
||||
/** @brief Enable secure boot if it is not already enabled.
|
||||
/** @brief Enable secure boot V1 if it is not already enabled.
|
||||
*
|
||||
* @important If this function succeeds, secure boot is permanently
|
||||
* @important If this function succeeds, secure boot V1 is permanently
|
||||
* enabled on the chip via efuse.
|
||||
*
|
||||
* @important This function is intended to be called from bootloader code only.
|
||||
*
|
||||
* @important This will enable r/w protection of secure boot key on EFUSE,
|
||||
* therefore it is to be ensured that esp_secure_boot_generate_digest()
|
||||
* is called before this
|
||||
*
|
||||
* If secure boot is not yet enabled for bootloader, this will
|
||||
* @important In case of Secure Boot V1, this will enable r/w protection
|
||||
* of secure boot key on EFUSE, therefore it is to be ensured that
|
||||
* esp_secure_boot_generate_digest() is called before this .If secure boot is not
|
||||
* yet enabled for bootloader, this will
|
||||
* 1) enable R/W protection of secure boot key on EFUSE
|
||||
* 2) enable secure boot by blowing the EFUSE_RD_ABS_DONE_0 efuse.
|
||||
*
|
||||
@ -100,35 +111,97 @@ esp_err_t esp_secure_boot_generate_digest(void);
|
||||
*/
|
||||
esp_err_t esp_secure_boot_permanently_enable(void);
|
||||
|
||||
/** @brief Verify the secure boot signature (determinstic ECDSA w/ SHA256) appended to some binary data in flash.
|
||||
/** @brief Enables secure boot V2 if it is not already enabled.
|
||||
*
|
||||
* Public key is compiled into the calling program. See docs/security/secure-boot.rst for details.
|
||||
* @important If this function succeeds, secure boot V2 is permanently
|
||||
* enabled on the chip via efuse.
|
||||
*
|
||||
* @important This function is intended to be called from bootloader code only.
|
||||
*
|
||||
* @important In case of Secure Boot V2, this will enable write protection
|
||||
* of secure boot key on EFUSE in BLK2. .If secure boot is not
|
||||
* yet enabled for bootloader, this will
|
||||
* 1) enable W protection of secure boot key on EFUSE
|
||||
* 2) enable secure boot by blowing the EFUSE_RD_ABS_DONE_1 efuse.
|
||||
*
|
||||
* This function does not verify secure boot of the bootloader (the
|
||||
* ROM bootloader does this.)
|
||||
*
|
||||
* @param image_data Image metadata of the application to be loaded.
|
||||
*
|
||||
* Will fail if efuses have been part-burned in a way that indicates
|
||||
* secure boot should not or could not be correctly enabled.
|
||||
*
|
||||
* @return ESP_ERR_INVALID_STATE if efuse state doesn't allow
|
||||
* secure boot to be enabled cleanly. ESP_OK if secure boot
|
||||
* is enabled on this chip from now on.
|
||||
*/
|
||||
esp_err_t esp_secure_boot_v2_permanently_enable(const esp_image_metadata_t *image_data);
|
||||
|
||||
/** @brief Verify the secure boot signature appended to some binary data in flash.
|
||||
*
|
||||
* For ECDSA Scheme (Secure Boot V1) - deterministic ECDSA w/ SHA256 image
|
||||
* For RSA Scheme (Secure Boot V2) - RSA-PSS Verification of the SHA-256 image
|
||||
*
|
||||
* Public key is compiled into the calling program in the ECDSA Scheme.
|
||||
* See the apt docs/security/secure-boot-v1.rst or docs/security/secure-boot-v2.rst for details.
|
||||
*
|
||||
* @param src_addr Starting offset of the data in flash.
|
||||
* @param length Length of data in bytes. Signature is appended -after- length bytes.
|
||||
*
|
||||
* If flash encryption is enabled, the image will be transparently decrypted while being verified.
|
||||
*
|
||||
* @note This function doesn't have any fault injection resistance so should not be called
|
||||
* during a secure boot itself (but can be called when verifying an update, etc.)
|
||||
*
|
||||
* @return ESP_OK if signature is valid, ESP_ERR_INVALID_STATE if
|
||||
* signature fails, ESP_FAIL for other failures (ie can't read flash).
|
||||
*/
|
||||
esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length);
|
||||
|
||||
/** @brief Verify the secure boot signature block (deterministic ECDSA w/ SHA256) based on the SHA256 hash of some data.
|
||||
*
|
||||
* Similar to esp_secure_boot_verify_signature(), but can be used when the digest is precalculated.
|
||||
* @param sig_block Pointer to signature block data
|
||||
* @param image_digest Pointer to 32 byte buffer holding SHA-256 hash.
|
||||
*
|
||||
*/
|
||||
|
||||
/** @brief Secure boot verification block, on-flash data format. */
|
||||
typedef struct {
|
||||
uint32_t version;
|
||||
uint8_t signature[64];
|
||||
} esp_secure_boot_sig_block_t;
|
||||
|
||||
esp_err_t esp_secure_boot_verify_signature_block(const esp_secure_boot_sig_block_t *sig_block, const uint8_t *image_digest);
|
||||
/** @brief Verify the ECDSA secure boot signature block for Secure Boot V1.
|
||||
*
|
||||
* Calculates Deterministic ECDSA w/ SHA256 based on the SHA256 hash of the image. ECDSA signature
|
||||
* verification must be enabled in project configuration to use this function.
|
||||
*
|
||||
* Similar to esp_secure_boot_verify_signature(), but can be used when the digest is precalculated.
|
||||
* @param sig_block Pointer to ECDSA signature block data
|
||||
* @param image_digest Pointer to 32 byte buffer holding SHA-256 hash.
|
||||
* @param verified_digest Pointer to 32 byte buffer that will receive verified digest if verification completes. (Used during bootloader implementation only, result is invalid otherwise.)
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_secure_boot_verify_ecdsa_signature_block(const esp_secure_boot_sig_block_t *sig_block, const uint8_t *image_digest, uint8_t *verified_digest);
|
||||
|
||||
|
||||
/** @brief Verify the RSA secure boot signature block for Secure Boot V2.
|
||||
*
|
||||
* Performs RSA-PSS Verification of the SHA-256 image based on the public key
|
||||
* in the signature block, compared against the public key digest stored in efuse.
|
||||
*
|
||||
* Similar to esp_secure_boot_verify_signature(), but can be used when the digest is precalculated.
|
||||
* @param sig_block Pointer to RSA signature block data
|
||||
* @param image_digest Pointer to 32 byte buffer holding SHA-256 hash.
|
||||
* @param verified_digest Pointer to 32 byte buffer that will receive verified digest if verification completes. (Used during bootloader implementation only, result is invalid otherwise.)
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_secure_boot_verify_rsa_signature_block(const ets_secure_boot_signature_t *sig_block, const uint8_t *image_digest, uint8_t *verified_digest);
|
||||
|
||||
/** @brief Legacy ECDSA verification function
|
||||
*
|
||||
* @note Deprecated, call either esp_secure_boot_verify_ecdsa_signature_block() or esp_secure_boot_verify_rsa_signature_block() instead.
|
||||
*
|
||||
* @param sig_block Pointer to ECDSA signature block data
|
||||
* @param image_digest Pointer to 32 byte buffer holding SHA-256 hash.
|
||||
*/
|
||||
esp_err_t esp_secure_boot_verify_signature_block(const esp_secure_boot_sig_block_t *sig_block, const uint8_t *image_digest)
|
||||
__attribute__((deprecated("use esp_secure_boot_verify_ecdsa_signature_block instead")));
|
||||
|
||||
|
||||
#define FLASH_OFFS_SECURE_BOOT_IV_DIGEST 0
|
||||
|
||||
|
@ -18,9 +18,11 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <esp_err.h>
|
||||
#include <esp_spi_flash.h> /* including in bootloader for error values */
|
||||
|
||||
#define FLASH_SECTOR_SIZE 0x1000
|
||||
#define FLASH_BLOCK_SIZE 0x10000
|
||||
#define MMAP_ALIGNED_MASK 0x0000FFFF
|
||||
|
||||
/* Provide a Flash API for bootloader_support code,
|
||||
that can be used from bootloader or app code.
|
||||
|
@ -108,3 +108,17 @@ esp_err_t bootloader_sha256_hex_to_str(char *out_str, const uint8_t *in_array_he
|
||||
* @param label Label to print at beginning of log line.
|
||||
*/
|
||||
void bootloader_debug_buffer(const void *buffer, size_t length, const char *label);
|
||||
|
||||
/** @brief Generates the digest of the data between offset & offset+length.
|
||||
*
|
||||
* This function should be used when the size of the data is larger than 3.2MB.
|
||||
* The MMU capacity is 3.2MB (50 pages - 64KB each). This function generates the SHA-256
|
||||
* of the data in chunks of 3.2MB, considering the MMU capacity.
|
||||
*
|
||||
* @param[in] flash_offset Offset of the data in flash.
|
||||
* @param[in] len Length of data in bytes.
|
||||
* @param[out] digest Pointer to buffer where the digest is written, if ESP_OK is returned.
|
||||
*
|
||||
* @return ESP_OK if secure boot digest is generated successfully.
|
||||
*/
|
||||
esp_err_t bootloader_sha256_flash_contents(uint32_t flash_offset, uint32_t len, uint8_t *digest);
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "esp_flash_partitions.h"
|
||||
#include "bootloader_flash.h"
|
||||
#include "bootloader_common.h"
|
||||
#include "bootloader_utility.h"
|
||||
#include "soc/gpio_periph.h"
|
||||
#include "soc/rtc.h"
|
||||
#include "soc/efuse_reg.h"
|
||||
@ -187,22 +188,7 @@ esp_err_t bootloader_common_get_sha256_of_partition (uint32_t address, uint32_t
|
||||
size = data.image_len;
|
||||
}
|
||||
// If image is type by data then hash is calculated for entire image.
|
||||
const void *partition_bin = bootloader_mmap(address, size);
|
||||
if (partition_bin == NULL) {
|
||||
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", address, size);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
bootloader_sha256_handle_t sha_handle = bootloader_sha256_start();
|
||||
if (sha_handle == NULL) {
|
||||
bootloader_munmap(partition_bin);
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
bootloader_sha256_data(sha_handle, partition_bin, size);
|
||||
bootloader_sha256_finish(sha_handle, out_sha_256);
|
||||
|
||||
bootloader_munmap(partition_bin);
|
||||
|
||||
return ESP_OK;
|
||||
return bootloader_sha256_flash_contents(address, size, out_sha_256);
|
||||
}
|
||||
|
||||
int bootloader_common_select_otadata(const esp_ota_select_entry_t *two_otadata, bool *valid_two_otadata, bool max)
|
||||
@ -248,13 +234,15 @@ esp_err_t bootloader_common_get_partition_description(const esp_partition_pos_t
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
const uint8_t *image = bootloader_mmap(partition->offset, partition->size);
|
||||
const uint32_t app_desc_offset = sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t);
|
||||
const uint32_t mmap_size = app_desc_offset + sizeof(esp_app_desc_t);
|
||||
const uint8_t *image = bootloader_mmap(partition->offset, mmap_size);
|
||||
if (image == NULL) {
|
||||
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", partition->offset, partition->size);
|
||||
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", partition->offset, mmap_size);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
memcpy(app_desc, image + sizeof(esp_image_header_t) + sizeof(esp_image_segment_header_t), sizeof(esp_app_desc_t));
|
||||
memcpy(app_desc, image + app_desc_offset, sizeof(esp_app_desc_t));
|
||||
bootloader_munmap(image);
|
||||
|
||||
if (app_desc->magic_word != ESP_APP_DESC_MAGIC_WORD) {
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
#include <bootloader_flash.h>
|
||||
#include <esp_log.h>
|
||||
#include <esp_spi_flash.h> /* including in bootloader for error values */
|
||||
#include <esp_flash_encrypt.h>
|
||||
#if CONFIG_IDF_TARGET_ESP32S2BETA
|
||||
#include "esp32s2beta/rom/spi_flash.h"
|
||||
|
@ -32,6 +32,11 @@ void bootloader_flash_update_id(void)
|
||||
g_rom_flashchip.device_id = bootloader_read_flash_id();
|
||||
}
|
||||
|
||||
void bootloader_flash_update_size(uint32_t size)
|
||||
{
|
||||
g_rom_flashchip.chip_size = size;
|
||||
}
|
||||
|
||||
void IRAM_ATTR bootloader_flash_cs_timing_config(void)
|
||||
{
|
||||
SET_PERI_REG_MASK(SPI_USER_REG(0), SPI_CS_HOLD_M | SPI_CS_SETUP_M);
|
||||
@ -62,6 +67,7 @@ void IRAM_ATTR bootloader_flash_clock_config(const esp_image_header_t* pfhdr)
|
||||
break;
|
||||
}
|
||||
esp_rom_spiflash_config_clk(spi_clk_div, 0);
|
||||
esp_rom_spiflash_config_clk(spi_clk_div, 1);
|
||||
}
|
||||
|
||||
void IRAM_ATTR bootloader_flash_gpio_config(const esp_image_header_t* pfhdr)
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_attr.h"
|
||||
#include "esp_log.h"
|
||||
#include "bootloader_init.h"
|
||||
#include "bootloader_flash.h"
|
||||
@ -30,7 +31,7 @@
|
||||
|
||||
static const char *TAG = "boot";
|
||||
|
||||
esp_image_header_t bootloader_image_hdr;
|
||||
esp_image_header_t WORD_ALIGNED_ATTR bootloader_image_hdr;
|
||||
|
||||
void bootloader_clear_bss_section(void)
|
||||
{
|
||||
|
@ -555,11 +555,19 @@ static void load_image(const esp_image_metadata_t *image_data)
|
||||
* then Step 6 enables secure boot.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_SECURE_BOOT_ENABLED) || defined(CONFIG_SECURE_FLASH_ENC_ENABLED)
|
||||
#if defined(CONFIG_SECURE_BOOT) || defined(CONFIG_SECURE_FLASH_ENC_ENABLED)
|
||||
esp_err_t err;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SECURE_BOOT_ENABLED
|
||||
#ifdef CONFIG_SECURE_BOOT_V2_ENABLED
|
||||
err = esp_secure_boot_v2_permanently_enable(image_data);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Secure Boot v2 failed (%d)", err);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SECURE_BOOT_V1_ENABLED
|
||||
/* Steps 1 & 2 (see above for full description):
|
||||
* 1) Generate secure boot EFUSE key
|
||||
* 2) Compute digest of plaintext bootloader
|
||||
@ -586,7 +594,7 @@ static void load_image(const esp_image_metadata_t *image_data)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SECURE_BOOT_ENABLED
|
||||
#ifdef CONFIG_SECURE_BOOT_V1_ENABLED
|
||||
/* Step 6 (see above for full description):
|
||||
* 6) Burn EFUSE to enable secure boot
|
||||
*/
|
||||
@ -816,3 +824,37 @@ void bootloader_debug_buffer(const void *buffer, size_t length, const char *labe
|
||||
ESP_LOGD(TAG, "%s: %s", label, hexbuf);
|
||||
#endif
|
||||
}
|
||||
|
||||
esp_err_t bootloader_sha256_flash_contents(uint32_t flash_offset, uint32_t len, uint8_t *digest)
|
||||
{
|
||||
if (digest == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* Handling firmware images larger than MMU capacity */
|
||||
uint32_t mmu_free_pages_count = bootloader_mmap_get_free_pages();
|
||||
bootloader_sha256_handle_t sha_handle = NULL;
|
||||
|
||||
sha_handle = bootloader_sha256_start();
|
||||
if (sha_handle == NULL) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
while (len > 0) {
|
||||
uint32_t mmu_page_offset = ((flash_offset & MMAP_ALIGNED_MASK) != 0) ? 1 : 0; /* Skip 1st MMU Page if it is already populated */
|
||||
uint32_t partial_image_len = MIN(len, ((mmu_free_pages_count - mmu_page_offset) * SPI_FLASH_MMU_PAGE_SIZE)); /* Read the image that fits in the free MMU pages */
|
||||
|
||||
const void * image = bootloader_mmap(flash_offset, partial_image_len);
|
||||
if (image == NULL) {
|
||||
bootloader_sha256_finish(sha_handle, NULL);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
bootloader_sha256_data(sha_handle, image, partial_image_len);
|
||||
bootloader_munmap(image);
|
||||
|
||||
flash_offset += partial_image_len;
|
||||
len -= partial_image_len;
|
||||
}
|
||||
bootloader_sha256_finish(sha_handle, digest);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
@ -73,6 +73,10 @@ esp_err_t esp_flash_encrypt_check_and_update(void)
|
||||
|
||||
static esp_err_t initialise_flash_encryption(void)
|
||||
{
|
||||
uint32_t new_wdata0 = 0;
|
||||
uint32_t new_wdata5 = 0;
|
||||
uint32_t new_wdata6 = 0;
|
||||
|
||||
uint32_t coding_scheme = REG_GET_FIELD(EFUSE_BLK0_RDATA6_REG, EFUSE_CODING_SCHEME);
|
||||
if (coding_scheme != EFUSE_CODING_SCHEME_VAL_NONE && coding_scheme != EFUSE_CODING_SCHEME_VAL_34) {
|
||||
ESP_LOGE(TAG, "Unknown/unsupported CODING_SCHEME value 0x%x", coding_scheme);
|
||||
@ -97,11 +101,10 @@ static esp_err_t initialise_flash_encryption(void)
|
||||
&& REG_READ(EFUSE_BLK1_RDATA7_REG) == 0) {
|
||||
ESP_LOGI(TAG, "Generating new flash encryption key...");
|
||||
esp_efuse_write_random_key(EFUSE_BLK1_WDATA0_REG);
|
||||
esp_efuse_burn_new_values();
|
||||
// defer efuse programming step to the end
|
||||
|
||||
ESP_LOGI(TAG, "Read & write protecting new key...");
|
||||
REG_WRITE(EFUSE_BLK0_WDATA0_REG, EFUSE_WR_DIS_BLK1 | EFUSE_RD_DIS_BLK1);
|
||||
esp_efuse_burn_new_values();
|
||||
new_wdata0 |= EFUSE_WR_DIS_BLK1 | EFUSE_RD_DIS_BLK1;
|
||||
} else {
|
||||
|
||||
if(!(efuse_key_read_protected && efuse_key_write_protected)) {
|
||||
@ -122,34 +125,36 @@ static esp_err_t initialise_flash_encryption(void)
|
||||
operation does nothing. Please note this is not recommended!
|
||||
*/
|
||||
ESP_LOGI(TAG, "Setting CRYPT_CONFIG efuse to 0xF");
|
||||
REG_WRITE(EFUSE_BLK0_WDATA5_REG, EFUSE_FLASH_CRYPT_CONFIG_M);
|
||||
esp_efuse_burn_new_values();
|
||||
new_wdata5 |= EFUSE_FLASH_CRYPT_CONFIG_M;
|
||||
|
||||
uint32_t new_wdata6 = 0;
|
||||
#ifndef CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_ENC
|
||||
ESP_LOGI(TAG, "Disable UART bootloader encryption...");
|
||||
new_wdata6 |= EFUSE_DISABLE_DL_ENCRYPT;
|
||||
#else
|
||||
ESP_LOGW(TAG, "Not disabling UART bootloader encryption");
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_DEC
|
||||
ESP_LOGI(TAG, "Disable UART bootloader decryption...");
|
||||
new_wdata6 |= EFUSE_DISABLE_DL_DECRYPT;
|
||||
#else
|
||||
ESP_LOGW(TAG, "Not disabling UART bootloader decryption - SECURITY COMPROMISED");
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SECURE_FLASH_UART_BOOTLOADER_ALLOW_CACHE
|
||||
ESP_LOGI(TAG, "Disable UART bootloader MMU cache...");
|
||||
new_wdata6 |= EFUSE_DISABLE_DL_CACHE;
|
||||
#else
|
||||
ESP_LOGW(TAG, "Not disabling UART bootloader MMU cache - SECURITY COMPROMISED");
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SECURE_BOOT_ALLOW_JTAG
|
||||
ESP_LOGI(TAG, "Disable JTAG...");
|
||||
new_wdata6 |= EFUSE_RD_DISABLE_JTAG;
|
||||
#else
|
||||
ESP_LOGW(TAG, "Not disabling JTAG - SECURITY COMPROMISED");
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SECURE_BOOT_ALLOW_ROM_BASIC
|
||||
ESP_LOGI(TAG, "Disable ROM BASIC interpreter fallback...");
|
||||
new_wdata6 |= EFUSE_RD_CONSOLE_DEBUG_DISABLE;
|
||||
@ -157,10 +162,16 @@ static esp_err_t initialise_flash_encryption(void)
|
||||
ESP_LOGW(TAG, "Not disabling ROM BASIC fallback - SECURITY COMPROMISED");
|
||||
#endif
|
||||
|
||||
if (new_wdata6 != 0) {
|
||||
REG_WRITE(EFUSE_BLK0_WDATA6_REG, new_wdata6);
|
||||
esp_efuse_burn_new_values();
|
||||
}
|
||||
#if defined(CONFIG_SECURE_BOOT_V2_ENABLED) && !defined(CONFIG_SECURE_BOOT_V2_ALLOW_EFUSE_RD_DIS)
|
||||
// This bit is set when enabling Secure Boot V2, but we can't enable it until this later point in the first boot
|
||||
// otherwise the Flash Encryption key cannot be read protected
|
||||
new_wdata0 |= EFUSE_WR_DIS_RD_DIS;
|
||||
#endif
|
||||
|
||||
REG_WRITE(EFUSE_BLK0_WDATA0_REG, new_wdata0);
|
||||
REG_WRITE(EFUSE_BLK0_WDATA5_REG, new_wdata5);
|
||||
REG_WRITE(EFUSE_BLK0_WDATA6_REG, new_wdata6);
|
||||
esp_efuse_burn_new_values();
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@ -210,16 +221,19 @@ static esp_err_t encrypt_flash_contents(uint32_t flash_crypt_cnt, bool flash_cry
|
||||
|
||||
ESP_LOGD(TAG, "All flash regions checked for encryption pass");
|
||||
|
||||
uint32_t new_flash_crypt_cnt;
|
||||
#ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE
|
||||
// Go straight to max, permanently enabled
|
||||
ESP_LOGI(TAG, "Setting FLASH_CRYPT_CNT for permanent encryption");
|
||||
new_flash_crypt_cnt = EFUSE_FLASH_CRYPT_CNT;
|
||||
#else
|
||||
/* Set least significant 0-bit in flash_crypt_cnt */
|
||||
int ffs_inv = __builtin_ffs((~flash_crypt_cnt) & EFUSE_RD_FLASH_CRYPT_CNT);
|
||||
/* ffs_inv shouldn't be zero, as zero implies flash_crypt_cnt == EFUSE_RD_FLASH_CRYPT_CNT (0x7F) */
|
||||
uint32_t new_flash_crypt_cnt = flash_crypt_cnt + (1 << (ffs_inv - 1));
|
||||
new_flash_crypt_cnt = flash_crypt_cnt + (1 << (ffs_inv - 1));
|
||||
#endif
|
||||
ESP_LOGD(TAG, "FLASH_CRYPT_CNT 0x%x -> 0x%x", flash_crypt_cnt, new_flash_crypt_cnt);
|
||||
uint32_t wdata0_reg = ((new_flash_crypt_cnt & EFUSE_FLASH_CRYPT_CNT) << EFUSE_FLASH_CRYPT_CNT_S);
|
||||
#ifdef CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE
|
||||
ESP_LOGI(TAG, "Write protecting FLASH_CRYPT_CNT eFuse");
|
||||
wdata0_reg |= EFUSE_WR_DIS_FLASH_CRYPT_CNT;
|
||||
#endif
|
||||
|
||||
REG_WRITE(EFUSE_BLK0_WDATA0_REG, wdata0_reg);
|
||||
esp_efuse_burn_new_values();
|
||||
@ -236,13 +250,22 @@ static esp_err_t encrypt_bootloader(void)
|
||||
/* Check for plaintext bootloader (verification will fail if it's already encrypted) */
|
||||
if (esp_image_verify_bootloader(&image_length) == ESP_OK) {
|
||||
ESP_LOGD(TAG, "bootloader is plaintext. Encrypting...");
|
||||
|
||||
#if CONFIG_SECURE_BOOT_V2_ENABLED
|
||||
/* The image length obtained from esp_image_verify_bootloader includes the sector boundary padding and the signature block lengths */
|
||||
if (ESP_BOOTLOADER_OFFSET + image_length > ESP_PARTITION_TABLE_OFFSET) {
|
||||
ESP_LOGE(TAG, "Bootloader is too large to fit Secure Boot V2 signature sector and partition table (configured offset 0x%x)", ESP_PARTITION_TABLE_OFFSET);
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
#endif // CONFIG_SECURE_BOOT_V2_ENABLED
|
||||
|
||||
err = esp_flash_encrypt_region(ESP_BOOTLOADER_OFFSET, image_length);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to encrypt bootloader in place: 0x%x", err);
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SECURE_BOOT_ENABLED
|
||||
#ifdef CONFIG_SECURE_BOOT_V1_ENABLED
|
||||
/* If secure boot is enabled and bootloader was plaintext, also
|
||||
* need to encrypt secure boot IV+digest.
|
||||
*/
|
||||
@ -355,4 +378,4 @@ esp_err_t esp_flash_encrypt_region(uint32_t src_addr, size_t data_length)
|
||||
flash_failed:
|
||||
ESP_LOGE(TAG, "flash operation failed: 0x%x", err);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
@ -20,10 +20,12 @@
|
||||
|
||||
#include "esp32/rom/cache.h"
|
||||
#include "esp32/rom/ets_sys.h"
|
||||
#include "esp32/rom/secure_boot.h"
|
||||
#include "esp32/rom/crc.h"
|
||||
|
||||
#include "soc/efuse_periph.h"
|
||||
#include "soc/rtc_periph.h"
|
||||
#include "bootloader_sha.h"
|
||||
#include "bootloader_utility.h"
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
@ -38,8 +40,8 @@
|
||||
* from the bootloader code.
|
||||
*/
|
||||
|
||||
static const char* TAG = "secure_boot";
|
||||
|
||||
#ifdef CONFIG_SECURE_BOOT_V1_ENABLED
|
||||
static const char *TAG = "secure_boot_v1";
|
||||
/**
|
||||
* @function : secure_boot_generate
|
||||
* @description: generate boot digest (aka "abstract") & iv
|
||||
@ -94,12 +96,6 @@ static bool secure_boot_generate(uint32_t image_len){
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Burn values written to the efuse write registers */
|
||||
static inline void burn_efuses(void)
|
||||
{
|
||||
esp_efuse_burn_new_values();
|
||||
}
|
||||
|
||||
esp_err_t esp_secure_boot_generate_digest(void)
|
||||
{
|
||||
esp_err_t err;
|
||||
@ -139,7 +135,7 @@ esp_err_t esp_secure_boot_generate_digest(void)
|
||||
&& REG_READ(EFUSE_BLK2_RDATA7_REG) == 0) {
|
||||
ESP_LOGI(TAG, "Generating new secure boot key...");
|
||||
esp_efuse_write_random_key(EFUSE_BLK2_WDATA0_REG);
|
||||
burn_efuses();
|
||||
esp_efuse_burn_new_values();
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Using pre-loaded secure boot key in EFUSE block 2");
|
||||
}
|
||||
@ -162,6 +158,9 @@ esp_err_t esp_secure_boot_generate_digest(void)
|
||||
|
||||
esp_err_t esp_secure_boot_permanently_enable(void)
|
||||
{
|
||||
uint32_t new_wdata0 = 0;
|
||||
uint32_t new_wdata6 = 0;
|
||||
|
||||
if (esp_secure_boot_enabled()) {
|
||||
ESP_LOGI(TAG, "bootloader secure boot is already enabled, continuing..");
|
||||
return ESP_OK;
|
||||
@ -173,8 +172,7 @@ esp_err_t esp_secure_boot_permanently_enable(void)
|
||||
if (efuse_key_read_protected == false
|
||||
&& efuse_key_write_protected == false) {
|
||||
ESP_LOGI(TAG, "Read & write protecting new key...");
|
||||
REG_WRITE(EFUSE_BLK0_WDATA0_REG, EFUSE_WR_DIS_BLK2 | EFUSE_RD_DIS_BLK2);
|
||||
burn_efuses();
|
||||
new_wdata0 = EFUSE_WR_DIS_BLK2 | EFUSE_RD_DIS_BLK2;
|
||||
efuse_key_read_protected = true;
|
||||
efuse_key_write_protected = true;
|
||||
}
|
||||
@ -191,7 +189,7 @@ esp_err_t esp_secure_boot_permanently_enable(void)
|
||||
ESP_LOGI(TAG, "blowing secure boot efuse...");
|
||||
ESP_LOGD(TAG, "before updating, EFUSE_BLK0_RDATA6 %x", REG_READ(EFUSE_BLK0_RDATA6_REG));
|
||||
|
||||
uint32_t new_wdata6 = EFUSE_RD_ABS_DONE_0;
|
||||
new_wdata6 |= EFUSE_RD_ABS_DONE_0;
|
||||
|
||||
#ifndef CONFIG_SECURE_BOOT_ALLOW_JTAG
|
||||
ESP_LOGI(TAG, "Disable JTAG...");
|
||||
@ -207,8 +205,9 @@ esp_err_t esp_secure_boot_permanently_enable(void)
|
||||
ESP_LOGW(TAG, "Not disabling ROM BASIC fallback - SECURITY COMPROMISED");
|
||||
#endif
|
||||
|
||||
REG_WRITE(EFUSE_BLK0_WDATA0_REG, new_wdata0);
|
||||
REG_WRITE(EFUSE_BLK0_WDATA6_REG, new_wdata6);
|
||||
burn_efuses();
|
||||
esp_efuse_burn_new_values();
|
||||
uint32_t after = REG_READ(EFUSE_BLK0_RDATA6_REG);
|
||||
ESP_LOGD(TAG, "after updating, EFUSE_BLK0_RDATA6 %x", after);
|
||||
if (after & EFUSE_RD_ABS_DONE_0) {
|
||||
@ -219,3 +218,228 @@ esp_err_t esp_secure_boot_permanently_enable(void)
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
}
|
||||
#elif CONFIG_SECURE_BOOT_V2_ENABLED
|
||||
|
||||
#define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1))
|
||||
static const char *TAG = "secure_boot_v2";
|
||||
|
||||
#define SIG_BLOCK_MAGIC_BYTE 0xe7
|
||||
#define CRC_SIGN_BLOCK_LEN 1196
|
||||
#define SIG_BLOCK_PADDING 4096
|
||||
|
||||
#define DIGEST_LEN 32
|
||||
|
||||
static esp_err_t validate_signature_block(const ets_secure_boot_signature_t *sig_block, uint8_t *digest)
|
||||
{
|
||||
uint32_t crc = crc32_le(0, (uint8_t *)sig_block, CRC_SIGN_BLOCK_LEN);
|
||||
if (sig_block->block[0].magic_byte == SIG_BLOCK_MAGIC_BYTE && sig_block->block[0].block_crc == crc && !memcmp(digest, sig_block->block[0].image_digest, DIGEST_LEN)) {
|
||||
ESP_LOGI(TAG, "valid signature block found");
|
||||
return ESP_OK;
|
||||
}
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
static esp_err_t secure_boot_v2_digest_generate(uint32_t flash_offset, uint32_t flash_size, uint8_t *public_key_digest)
|
||||
{
|
||||
esp_err_t ret = ESP_FAIL;
|
||||
|
||||
uint8_t image_digest[DIGEST_LEN] = {0};
|
||||
size_t sig_block_addr = flash_offset + ALIGN_UP(flash_size, FLASH_SECTOR_SIZE);
|
||||
ret = bootloader_sha256_flash_contents(flash_offset, sig_block_addr - flash_offset, image_digest);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "error generating image digest, %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ESP_LOGD(TAG, "reading signature block");
|
||||
const ets_secure_boot_signature_t *sig_block = bootloader_mmap(sig_block_addr, sizeof(ets_secure_boot_signature_t));
|
||||
if (sig_block == NULL) {
|
||||
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", sig_block_addr, sizeof(ets_secure_boot_signature_t));
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Validating Signature block */
|
||||
ret = validate_signature_block(sig_block, image_digest);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "signature block (address 0x%x) validation failed %d", sig_block_addr, ret);
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Verifying Signature block */
|
||||
uint8_t verified_digest[DIGEST_LEN] = {0};
|
||||
|
||||
/* Generating the SHA of the public key components in the signature block */
|
||||
bootloader_sha256_handle_t sig_block_sha;
|
||||
sig_block_sha = bootloader_sha256_start();
|
||||
bootloader_sha256_data(sig_block_sha, &sig_block->block[0].key, sizeof(sig_block->block[0].key));
|
||||
bootloader_sha256_finish(sig_block_sha, public_key_digest);
|
||||
|
||||
secure_boot_v2_status_t error;
|
||||
error = ets_secure_boot_verify_signature(sig_block, image_digest, public_key_digest, verified_digest);
|
||||
if (error != SBV2_SUCCESS) {
|
||||
ESP_LOGE(TAG, "secure boot v2 verification failed %d", error);
|
||||
ret = ESP_FAIL;
|
||||
goto done;
|
||||
} else {
|
||||
ret = ESP_OK;
|
||||
}
|
||||
|
||||
done:
|
||||
bootloader_munmap(sig_block);
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t esp_secure_boot_v2_permanently_enable(const esp_image_metadata_t *image_data)
|
||||
{
|
||||
uint32_t new_wdata0 = 0;
|
||||
uint32_t new_wdata6 = 0;
|
||||
|
||||
ESP_LOGI(TAG, "enabling secure boot v2...");
|
||||
esp_err_t ret;
|
||||
if (esp_secure_boot_enabled()) {
|
||||
ESP_LOGI(TAG, "secure boot v2 is already enabled. Continuing..");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
uint32_t coding_scheme = REG_GET_FIELD(EFUSE_BLK0_RDATA6_REG, EFUSE_CODING_SCHEME);
|
||||
if (coding_scheme != EFUSE_CODING_SCHEME_VAL_NONE) {
|
||||
ESP_LOGE(TAG, "No coding schemes are supported in secure boot v2.(Detected scheme: 0x%x)", coding_scheme);
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
/* Verify the bootloader */
|
||||
esp_image_metadata_t bootloader_data = { 0 };
|
||||
ret = esp_image_verify_bootloader_data(&bootloader_data);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "bootloader image appears invalid! error %d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
uint8_t boot_pub_key_digest[DIGEST_LEN];
|
||||
uint32_t dis_reg = REG_READ(EFUSE_BLK0_RDATA0_REG);
|
||||
bool efuse_key_read_protected = dis_reg & EFUSE_RD_DIS_BLK2;
|
||||
bool efuse_key_write_protected = dis_reg & EFUSE_WR_DIS_BLK2;
|
||||
uint32_t efuse_blk2_r0, efuse_blk2_r1, efuse_blk2_r2, efuse_blk2_r3, efuse_blk2_r4, efuse_blk2_r5, efuse_blk2_r6, efuse_blk2_r7;
|
||||
efuse_blk2_r0 = REG_READ(EFUSE_BLK2_RDATA0_REG);
|
||||
efuse_blk2_r1 = REG_READ(EFUSE_BLK2_RDATA1_REG);
|
||||
efuse_blk2_r2 = REG_READ(EFUSE_BLK2_RDATA2_REG);
|
||||
efuse_blk2_r3 = REG_READ(EFUSE_BLK2_RDATA3_REG);
|
||||
efuse_blk2_r4 = REG_READ(EFUSE_BLK2_RDATA4_REG);
|
||||
efuse_blk2_r5 = REG_READ(EFUSE_BLK2_RDATA5_REG);
|
||||
efuse_blk2_r6 = REG_READ(EFUSE_BLK2_RDATA6_REG);
|
||||
efuse_blk2_r7 = REG_READ(EFUSE_BLK2_RDATA7_REG);
|
||||
|
||||
if (efuse_key_read_protected == true) {
|
||||
ESP_LOGE(TAG, "Secure Boot v2 digest(BLK2) read protected, aborting....");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
if (efuse_key_write_protected == false
|
||||
&& efuse_blk2_r0 == 0 && efuse_blk2_r1 == 0
|
||||
&& efuse_blk2_r2 == 0 && efuse_blk2_r3 == 0
|
||||
&& efuse_blk2_r4 == 0 && efuse_blk2_r5 == 0
|
||||
&& efuse_blk2_r6 == 0 && efuse_blk2_r7 == 0) {
|
||||
/* Verifies the signature block appended to the image matches with the signature block of the app to be loaded */
|
||||
ret = secure_boot_v2_digest_generate(bootloader_data.start_addr, bootloader_data.image_len - SIG_BLOCK_PADDING, boot_pub_key_digest);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Public key digest generation failed");
|
||||
return ret;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Burning public key hash to efuse.");
|
||||
uint32_t *boot_public_key_digest_ptr = (uint32_t *) boot_pub_key_digest;
|
||||
for (int i = 0; i < 8 ; i++) {
|
||||
REG_WRITE(EFUSE_BLK2_WDATA0_REG + 4 * i, boot_public_key_digest_ptr[i]);
|
||||
ESP_LOGD(TAG, "EFUSE_BLKx_WDATA%d_REG = 0x%08x", i, boot_public_key_digest_ptr[i]);
|
||||
}
|
||||
// delay burning until second half of this function
|
||||
|
||||
} else {
|
||||
uint32_t efuse_blk2_digest[8];
|
||||
efuse_blk2_digest[0] = efuse_blk2_r0;
|
||||
efuse_blk2_digest[1] = efuse_blk2_r1;
|
||||
efuse_blk2_digest[2] = efuse_blk2_r2;
|
||||
efuse_blk2_digest[3] = efuse_blk2_r3;
|
||||
efuse_blk2_digest[4] = efuse_blk2_r4;
|
||||
efuse_blk2_digest[5] = efuse_blk2_r5;
|
||||
efuse_blk2_digest[6] = efuse_blk2_r6;
|
||||
efuse_blk2_digest[7] = efuse_blk2_r7;
|
||||
memcpy(boot_pub_key_digest, efuse_blk2_digest, DIGEST_LEN);
|
||||
ESP_LOGW(TAG, "Using pre-loaded secure boot v2 public key digest in EFUSE block 2");
|
||||
}
|
||||
|
||||
// This case is needed either if a pre-burned digest is present but not write-protected,
|
||||
// or if we are burning the digest now
|
||||
if (efuse_key_write_protected == false) {
|
||||
ESP_LOGI(TAG, "Write protecting public key digest...");
|
||||
new_wdata0 |= EFUSE_WR_DIS_BLK2; // delay burning until second half of this function
|
||||
}
|
||||
|
||||
uint8_t app_pub_key_digest[DIGEST_LEN];
|
||||
ret = secure_boot_v2_digest_generate(image_data->start_addr, image_data->image_len - SIG_BLOCK_PADDING, app_pub_key_digest);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Application signature block is invalid.");
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Confirming if the public key in the bootloader's signature block matches with the one in the application's signature block */
|
||||
if (memcmp(boot_pub_key_digest, app_pub_key_digest, DIGEST_LEN) != 0) {
|
||||
ESP_LOGE(TAG, "Application not signed with a valid private key.");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
if (efuse_key_read_protected) {
|
||||
ESP_LOGE(TAG, "Efuse BLK2 (public key digest) is read protected. Refusing to blow secure boot efuse.");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "blowing secure boot efuse...");
|
||||
ESP_LOGD(TAG, "before updating, EFUSE_BLK0_RDATA6 %x", REG_READ(EFUSE_BLK0_RDATA6_REG));
|
||||
|
||||
new_wdata6 |= EFUSE_RD_ABS_DONE_1;
|
||||
|
||||
#ifndef CONFIG_SECURE_BOOT_ALLOW_JTAG
|
||||
ESP_LOGI(TAG, "Disable JTAG...");
|
||||
new_wdata6 |= EFUSE_RD_DISABLE_JTAG;
|
||||
#else
|
||||
ESP_LOGW(TAG, "Not disabling JTAG - SECURITY COMPROMISED");
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SECURE_BOOT_ALLOW_ROM_BASIC
|
||||
ESP_LOGI(TAG, "Disable ROM BASIC interpreter fallback...");
|
||||
new_wdata6 |= EFUSE_RD_CONSOLE_DEBUG_DISABLE;
|
||||
#else
|
||||
ESP_LOGW(TAG, "Not disabling ROM BASIC fallback - SECURITY COMPROMISED");
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SECURE_BOOT_V2_ALLOW_EFUSE_RD_DIS
|
||||
bool rd_dis_now = true;
|
||||
#ifdef CONFIG_SECURE_FLASH_ENC_ENABLED
|
||||
/* If flash encryption is not enabled yet then don't read-disable efuses yet, do it later in the boot
|
||||
when Flash Encryption is being enabled */
|
||||
rd_dis_now = esp_flash_encryption_enabled();
|
||||
#endif
|
||||
if (rd_dis_now) {
|
||||
ESP_LOGI(TAG, "Prevent read disabling of additional efuses...");
|
||||
new_wdata0 |= EFUSE_WR_DIS_RD_DIS;
|
||||
}
|
||||
#else
|
||||
ESP_LOGW(TAG, "Allowing read disabling of additional efuses - SECURITY COMPROMISED");
|
||||
#endif
|
||||
|
||||
REG_WRITE(EFUSE_BLK0_WDATA0_REG, new_wdata0);
|
||||
REG_WRITE(EFUSE_BLK0_WDATA6_REG, new_wdata6);
|
||||
esp_efuse_burn_new_values();
|
||||
uint32_t after = REG_READ(EFUSE_BLK0_RDATA6_REG);
|
||||
ESP_LOGD(TAG, "after updating, EFUSE_BLK0_RDATA0 0x%08x EFUSE_BLK0_RDATA6 0x%08x",
|
||||
REG_READ(EFUSE_BLK0_RDATA0_REG), after);
|
||||
if (after & EFUSE_RD_ABS_DONE_1) {
|
||||
ESP_LOGI(TAG, "secure boot v2 is now enabled.");
|
||||
return ESP_OK;
|
||||
} else {
|
||||
ESP_LOGE(TAG, " secure boot v2 not enabled, EFUSE_RD_ABS_DONE_1 is probably write protected!");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // CONFIG_SECURE_BOOT_V2_ENABLED
|
||||
|
@ -15,62 +15,40 @@
|
||||
|
||||
#include "bootloader_flash.h"
|
||||
#include "bootloader_sha.h"
|
||||
#include "bootloader_utility.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_image_format.h"
|
||||
#include "esp_secure_boot.h"
|
||||
#include "esp_spi_flash.h"
|
||||
#include "esp_fault.h"
|
||||
#include "esp32/rom/sha.h"
|
||||
#include "uECC.h"
|
||||
#include "uECC_verify_antifault.h"
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <string.h>
|
||||
|
||||
static const char *TAG = "secure_boot";
|
||||
#define DIGEST_LEN 32
|
||||
|
||||
#ifdef CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME
|
||||
extern const uint8_t signature_verification_key_start[] asm("_binary_signature_verification_key_bin_start");
|
||||
extern const uint8_t signature_verification_key_end[] asm("_binary_signature_verification_key_bin_end");
|
||||
|
||||
#define SIGNATURE_VERIFICATION_KEYLEN 64
|
||||
|
||||
#define DIGEST_LEN 32
|
||||
|
||||
/* Mmap source address mask */
|
||||
#define MMAP_ALIGNED_MASK 0x0000FFFF
|
||||
|
||||
esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length)
|
||||
{
|
||||
uint8_t digest[DIGEST_LEN];
|
||||
const uint8_t *data;
|
||||
uint8_t verified_digest[DIGEST_LEN] = { 0 }; /* ignored in this function */
|
||||
const esp_secure_boot_sig_block_t *sigblock;
|
||||
|
||||
ESP_LOGD(TAG, "verifying signature src_addr 0x%x length 0x%x", src_addr, length);
|
||||
|
||||
bootloader_sha256_handle_t handle = bootloader_sha256_start();
|
||||
|
||||
uint32_t free_page_count = bootloader_mmap_get_free_pages();
|
||||
ESP_LOGD(TAG, "free data page_count 0x%08x", free_page_count);
|
||||
|
||||
int32_t data_len_remain = length;
|
||||
uint32_t data_addr = src_addr;
|
||||
while (data_len_remain > 0) {
|
||||
uint32_t offset_page = ((data_addr & MMAP_ALIGNED_MASK) != 0) ? 1 : 0;
|
||||
/* Data we could map in case we are not aligned to PAGE boundary is one page size lesser. */
|
||||
uint32_t data_len = MIN(data_len_remain, ((free_page_count - offset_page) * SPI_FLASH_MMU_PAGE_SIZE));
|
||||
data = (const uint8_t *) bootloader_mmap(data_addr, data_len);
|
||||
if(!data) {
|
||||
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", data_addr, data_len);
|
||||
bootloader_sha256_finish(handle, NULL);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
bootloader_sha256_data(handle, data, data_len);
|
||||
bootloader_munmap(data);
|
||||
|
||||
data_addr += data_len;
|
||||
data_len_remain -= data_len;
|
||||
esp_err_t err = bootloader_sha256_flash_contents(src_addr, length, digest);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Done! Get the digest */
|
||||
bootloader_sha256_finish(handle, digest);
|
||||
|
||||
// Map the signature block
|
||||
sigblock = (const esp_secure_boot_sig_block_t *) bootloader_mmap(src_addr + length, sizeof(esp_secure_boot_sig_block_t));
|
||||
if(!sigblock) {
|
||||
@ -78,7 +56,7 @@ esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length)
|
||||
return ESP_FAIL;
|
||||
}
|
||||
// Verify the signature
|
||||
esp_err_t err = esp_secure_boot_verify_signature_block(sigblock, digest);
|
||||
err = esp_secure_boot_verify_ecdsa_signature_block(sigblock, digest, verified_digest);
|
||||
// Unmap
|
||||
bootloader_munmap(sigblock);
|
||||
|
||||
@ -86,6 +64,12 @@ esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length)
|
||||
}
|
||||
|
||||
esp_err_t esp_secure_boot_verify_signature_block(const esp_secure_boot_sig_block_t *sig_block, const uint8_t *image_digest)
|
||||
{
|
||||
uint8_t verified_digest[DIGEST_LEN] = { 0 };
|
||||
return esp_secure_boot_verify_ecdsa_signature_block(sig_block, image_digest, verified_digest);
|
||||
}
|
||||
|
||||
esp_err_t esp_secure_boot_verify_ecdsa_signature_block(const esp_secure_boot_sig_block_t *sig_block, const uint8_t *image_digest, uint8_t *verified_digest)
|
||||
{
|
||||
ptrdiff_t keylen;
|
||||
|
||||
@ -103,11 +87,98 @@ esp_err_t esp_secure_boot_verify_signature_block(const esp_secure_boot_sig_block
|
||||
ESP_LOGD(TAG, "Verifying secure boot signature");
|
||||
|
||||
bool is_valid;
|
||||
is_valid = uECC_verify(signature_verification_key_start,
|
||||
is_valid = uECC_verify_antifault(signature_verification_key_start,
|
||||
image_digest,
|
||||
DIGEST_LEN,
|
||||
sig_block->signature,
|
||||
uECC_secp256r1());
|
||||
uECC_secp256r1(),
|
||||
verified_digest);
|
||||
ESP_LOGD(TAG, "Verification result %d", is_valid);
|
||||
|
||||
return is_valid ? ESP_OK : ESP_ERR_IMAGE_INVALID;
|
||||
}
|
||||
|
||||
#elif CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME
|
||||
#define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1))
|
||||
|
||||
esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length)
|
||||
{
|
||||
uint8_t digest[DIGEST_LEN] = {0};
|
||||
uint8_t verified_digest[DIGEST_LEN] = {0}; // ignored in this function
|
||||
const uint8_t *data;
|
||||
|
||||
/* Padding to round off the input to the nearest 4k boundary */
|
||||
int padded_length = ALIGN_UP(length, FLASH_SECTOR_SIZE);
|
||||
ESP_LOGD(TAG, "verifying src_addr 0x%x length", src_addr, padded_length);
|
||||
|
||||
data = bootloader_mmap(src_addr, padded_length + sizeof(ets_secure_boot_signature_t));
|
||||
if (data == NULL) {
|
||||
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", src_addr, padded_length);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
/* Calculate digest of main image */
|
||||
esp_err_t err = bootloader_sha256_flash_contents(src_addr, padded_length, digest);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Digest calculation failed 0x%x, 0x%x", src_addr, padded_length);
|
||||
bootloader_munmap(data);
|
||||
return err;
|
||||
}
|
||||
|
||||
const ets_secure_boot_signature_t *sig_block = (const ets_secure_boot_signature_t *)(data + padded_length);
|
||||
err = esp_secure_boot_verify_rsa_signature_block(sig_block, digest, verified_digest);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Secure Boot V2 verification failed.");
|
||||
}
|
||||
|
||||
bootloader_munmap(data);
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t esp_secure_boot_verify_rsa_signature_block(const ets_secure_boot_signature_t *sig_block, const uint8_t *image_digest, uint8_t *verified_digest)
|
||||
{
|
||||
secure_boot_v2_status_t r;
|
||||
uint8_t efuse_trusted_digest[DIGEST_LEN] = {0}, sig_block_trusted_digest[DIGEST_LEN] = {0};
|
||||
|
||||
memcpy(efuse_trusted_digest, (uint8_t *)EFUSE_BLK2_RDATA0_REG, DIGEST_LEN); /* EFUSE_BLK2_RDATA0_REG - Stores the Secure Boot Public Key Digest */
|
||||
|
||||
if (!ets_use_secure_boot_v2()) {
|
||||
ESP_LOGI(TAG, "Secure Boot eFuse bit(ABS_DONE_1) not yet programmed.");
|
||||
|
||||
/* Generating the SHA of the public key components in the signature block */
|
||||
bootloader_sha256_handle_t sig_block_sha;
|
||||
sig_block_sha = bootloader_sha256_start();
|
||||
bootloader_sha256_data(sig_block_sha, &sig_block->block[0].key, sizeof(sig_block->block[0].key));
|
||||
bootloader_sha256_finish(sig_block_sha, (unsigned char *)sig_block_trusted_digest);
|
||||
|
||||
#if CONFIG_SECURE_BOOT_V2_ENABLED
|
||||
if (memcmp(efuse_trusted_digest, sig_block_trusted_digest, DIGEST_LEN) != 0) {
|
||||
/* Most likely explanation for this is that BLK2 is empty, and we're going to burn it
|
||||
after we verify that the signature is valid. However, if BLK2 is not empty then we need to
|
||||
fail here.
|
||||
*/
|
||||
bool all_zeroes = true;
|
||||
for (int i = 0; i < DIGEST_LEN; i++) {
|
||||
all_zeroes = all_zeroes && (efuse_trusted_digest[i] == 0);
|
||||
}
|
||||
if (!all_zeroes) {
|
||||
ESP_LOGE(TAG, "Different public key digest burned to eFuse BLK2");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
}
|
||||
|
||||
ESP_FAULT_ASSERT(!ets_use_secure_boot_v2());
|
||||
#endif
|
||||
|
||||
memcpy(efuse_trusted_digest, sig_block_trusted_digest, DIGEST_LEN);
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "Verifying with RSA-PSS...");
|
||||
r = ets_secure_boot_verify_signature(sig_block, image_digest, efuse_trusted_digest, verified_digest);
|
||||
if (r != SBV2_SUCCESS) {
|
||||
ESP_LOGE(TAG, "Secure Boot V2 verification failed.");
|
||||
}
|
||||
|
||||
return (r == SBV2_SUCCESS) ? ESP_OK : ESP_ERR_IMAGE_INVALID;
|
||||
}
|
||||
#endif
|
||||
|
@ -191,6 +191,15 @@ static esp_err_t encrypt_bootloader(void)
|
||||
/* Check for plaintext bootloader (verification will fail if it's already encrypted) */
|
||||
if (esp_image_verify_bootloader(&image_length) == ESP_OK) {
|
||||
ESP_LOGD(TAG, "bootloader is plaintext. Encrypting...");
|
||||
|
||||
#if CONFIG_SECURE_BOOT_V2_ENABLED
|
||||
/* The image length obtained from esp_image_verify_bootloader includes the sector boundary padding and the signature block lengths */
|
||||
if (ESP_BOOTLOADER_OFFSET + image_length > ESP_PARTITION_TABLE_OFFSET) {
|
||||
ESP_LOGE(TAG, "Bootloader is too large to fit Secure Boot V2 signature sector and partition table (configured offset 0x%x)", ESP_PARTITION_TABLE_OFFSET);
|
||||
return ESP_ERR_INVALID_SIZE;
|
||||
}
|
||||
#endif // CONFIG_SECURE_BOOT_V2_ENABLED
|
||||
|
||||
err = esp_flash_encrypt_region(ESP_BOOTLOADER_OFFSET, image_length);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Failed to encrypt bootloader in place: 0x%x", err);
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "esp_log.h"
|
||||
#include "esp32s2beta/rom/secure_boot.h"
|
||||
|
||||
#define TAG "secure_boot"
|
||||
static const char *TAG = "secure_boot";
|
||||
|
||||
esp_err_t esp_secure_boot_permanently_enable(void)
|
||||
{
|
||||
|
@ -27,6 +27,7 @@ esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length)
|
||||
{
|
||||
ets_secure_boot_key_digests_t trusted_keys = { 0 };
|
||||
uint8_t digest[DIGEST_LEN];
|
||||
uint8_t verified_digest[DIGEST_LEN] = { 0 }; /* Note: this function doesn't do any anti-FI checks on this buffer */
|
||||
const uint8_t *data;
|
||||
|
||||
ESP_LOGD(TAG, "verifying signature src_addr 0x%x length 0x%x", src_addr, length);
|
||||
@ -37,7 +38,7 @@ esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length)
|
||||
}
|
||||
|
||||
data = bootloader_mmap(src_addr, length + sizeof(struct ets_secure_boot_sig_block));
|
||||
if(data == NULL) {
|
||||
if (data == NULL) {
|
||||
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", src_addr, length+sizeof(ets_secure_boot_signature_t));
|
||||
return ESP_FAIL;
|
||||
}
|
||||
@ -57,36 +58,25 @@ esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length)
|
||||
if (r == ETS_OK) {
|
||||
const ets_secure_boot_signature_t *sig = (const ets_secure_boot_signature_t *)(data + length);
|
||||
// TODO: calling this function in IDF app context is unsafe
|
||||
r = ets_secure_boot_verify_signature(sig, digest, &trusted_keys);
|
||||
r = ets_secure_boot_verify_signature(sig, digest, &trusted_keys, verified_digest);
|
||||
}
|
||||
bootloader_munmap(data);
|
||||
|
||||
return (r == ETS_OK) ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t esp_secure_boot_verify_signature_block(uint32_t sig_block_flash_offs, const uint8_t *image_digest)
|
||||
esp_err_t esp_secure_boot_verify_rsa_signature_block(const ets_secure_boot_signature_t *sig_block, const uint8_t *image_digest, uint8_t *verified_digest)
|
||||
{
|
||||
ets_secure_boot_key_digests_t trusted_keys;
|
||||
|
||||
assert(sig_block_flash_offs % 4096 == 0); // TODO: enforce this in a better way
|
||||
|
||||
const ets_secure_boot_signature_t *sig = bootloader_mmap(sig_block_flash_offs, sizeof(ets_secure_boot_signature_t));
|
||||
|
||||
if (sig == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to mmap data at offset 0x%x", sig_block_flash_offs);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
int r = ets_secure_boot_read_key_digests(&trusted_keys);
|
||||
if (r != 0) {
|
||||
ESP_LOGE(TAG, "No trusted key digests were found in efuse!");
|
||||
} else {
|
||||
ESP_LOGD(TAG, "Verifying with RSA-PSS...");
|
||||
// TODO: calling this function in IDF app context is unsafe
|
||||
r = ets_secure_boot_verify_signature(sig, image_digest, &trusted_keys);
|
||||
r = ets_secure_boot_verify_signature(sig_block, image_digest, &trusted_keys, verified_digest);
|
||||
}
|
||||
|
||||
bootloader_munmap(sig);
|
||||
|
||||
return (r == 0) ? ESP_OK : ESP_ERR_IMAGE_INVALID;
|
||||
}
|
||||
|
@ -16,13 +16,16 @@
|
||||
#include <soc/cpu.h>
|
||||
#include <bootloader_utility.h>
|
||||
#include <esp_secure_boot.h>
|
||||
#include <esp_fault.h>
|
||||
#include <esp_log.h>
|
||||
#include <esp_attr.h>
|
||||
#include <esp_spi_flash.h>
|
||||
#include <bootloader_flash.h>
|
||||
#include <bootloader_random.h>
|
||||
#include <bootloader_sha.h>
|
||||
#include "bootloader_util.h"
|
||||
#include "bootloader_common.h"
|
||||
#include "soc/soc_memory_layout.h"
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#include <esp32/rom/rtc.h>
|
||||
#include <esp32/rom/secure_boot.h>
|
||||
@ -37,11 +40,11 @@
|
||||
*/
|
||||
#ifdef BOOTLOADER_BUILD
|
||||
#ifdef CONFIG_SECURE_SIGNED_ON_BOOT
|
||||
#define SECURE_BOOT_CHECK_SIGNATURE
|
||||
#define SECURE_BOOT_CHECK_SIGNATURE 1
|
||||
#endif
|
||||
#else /* !BOOTLOADER_BUILD */
|
||||
#ifdef CONFIG_SECURE_SIGNED_ON_UPDATE
|
||||
#define SECURE_BOOT_CHECK_SIGNATURE
|
||||
#define SECURE_BOOT_CHECK_SIGNATURE 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -55,18 +58,12 @@ static const char *TAG = "esp_image";
|
||||
/* Headroom to ensure between stack SP (at time of checking) and data loaded from flash */
|
||||
#define STACK_LOAD_HEADROOM 32768
|
||||
|
||||
/* Mmap source address mask */
|
||||
#define MMAP_ALIGNED_MASK 0x0000FFFF
|
||||
|
||||
#ifdef BOOTLOADER_BUILD
|
||||
/* 64 bits of random data to obfuscate loaded RAM with, until verification is complete
|
||||
(Means loaded code isn't executable until after the secure boot check.)
|
||||
*/
|
||||
static uint32_t ram_obfs_value[2];
|
||||
|
||||
/* Range of IRAM used by the loader, defined in ld script */
|
||||
extern int _loader_text_start;
|
||||
extern int _loader_text_end;
|
||||
#endif
|
||||
|
||||
/* Return true if load_addr is an address the bootloader should load into */
|
||||
@ -97,7 +94,7 @@ static esp_err_t verify_segment_header(int index, const esp_image_segment_header
|
||||
|
||||
static esp_err_t verify_checksum(bootloader_sha256_handle_t sha_handle, uint32_t checksum_word, esp_image_metadata_t *data);
|
||||
|
||||
static esp_err_t __attribute__((unused)) verify_secure_boot_signature(bootloader_sha256_handle_t sha_handle, esp_image_metadata_t *data);
|
||||
static esp_err_t __attribute__((unused)) verify_secure_boot_signature(bootloader_sha256_handle_t sha_handle, esp_image_metadata_t *data, uint8_t *image_digest, uint8_t *verified_digest);
|
||||
static esp_err_t __attribute__((unused)) verify_simple_hash(bootloader_sha256_handle_t sha_handle, esp_image_metadata_t *data);
|
||||
|
||||
static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_t *part, esp_image_metadata_t *data)
|
||||
@ -115,6 +112,11 @@ static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_
|
||||
uint32_t checksum_word = ESP_ROM_CHECKSUM_INITIAL;
|
||||
uint32_t *checksum = NULL;
|
||||
bootloader_sha256_handle_t sha_handle = NULL;
|
||||
#if SECURE_BOOT_CHECK_SIGNATURE
|
||||
/* used for anti-FI checks */
|
||||
uint8_t image_digest[HASH_LEN] = { [ 0 ... 31] = 0xEE };
|
||||
uint8_t verified_digest[HASH_LEN] = { [ 0 ... 31 ] = 0x01 };
|
||||
#endif
|
||||
|
||||
if (data == NULL || part == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
@ -172,6 +174,7 @@ static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_
|
||||
for (int i = 0; i < data->image.segment_count; i++) {
|
||||
esp_image_segment_header_t *header = &data->segments[i];
|
||||
ESP_LOGV(TAG, "loading segment header %d at offset 0x%x", i, next_addr);
|
||||
|
||||
err = process_segment(i, next_addr, header, silent, do_load, sha_handle, checksum);
|
||||
if (err != ESP_OK) {
|
||||
goto err;
|
||||
@ -197,14 +200,14 @@ static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_
|
||||
}
|
||||
}
|
||||
|
||||
/* For secure boot on ESP32, we don't calculate SHA or verify signautre on bootloaders.
|
||||
For ESP32S2, we do verify signature on botoloaders which includes the SHA calculation.
|
||||
/* For secure boot V1 on ESP32, we don't calculate SHA or verify signature on bootloaders.
|
||||
For Secure Boot V2, we do verify signature on bootloader which includes the SHA calculation.
|
||||
|
||||
(For non-secure boot, we don't verify any SHA-256 hash appended to the bootloader because
|
||||
esptool.py may have rewritten the header - rely on esptool.py having verified the bootloader at flashing time, instead.)
|
||||
*/
|
||||
bool verify_sha;
|
||||
#if defined(CONFIG_SECURE_BOOT_ENABLED) && defined(CONFIG_IDF_TARGET_ESP32S2BETA)
|
||||
#if CONFIG_SECURE_BOOT_V2_ENABLED
|
||||
verify_sha = true;
|
||||
#else // ESP32, or ESP32S2 without secure boot enabled
|
||||
verify_sha = (data->start_addr != ESP_BOOTLOADER_OFFSET);
|
||||
@ -217,8 +220,18 @@ static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_
|
||||
|
||||
#ifdef SECURE_BOOT_CHECK_SIGNATURE
|
||||
// secure boot images have a signature appended
|
||||
err = verify_secure_boot_signature(sha_handle, data);
|
||||
#else
|
||||
#if defined(BOOTLOADER_BUILD) && !defined(CONFIG_SECURE_BOOT)
|
||||
// If secure boot is not enabled in hardware, then
|
||||
// skip the signature check in bootloader when the debugger is attached.
|
||||
// This is done to allow for breakpoints in Flash.
|
||||
if (!esp_cpu_in_ocd_debug_mode()) {
|
||||
#else // CONFIG_SECURE_BOOT
|
||||
if (true) {
|
||||
#endif // end checking for JTAG
|
||||
err = verify_secure_boot_signature(sha_handle, data, image_digest, verified_digest);
|
||||
sha_handle = NULL; // verify_secure_boot_signature finishes sha_handle
|
||||
}
|
||||
#else // SECURE_BOOT_CHECK_SIGNATURE
|
||||
// No secure boot, but SHA-256 can be appended for basic corruption detection
|
||||
if (sha_handle != NULL && !esp_cpu_in_ocd_debug_mode()) {
|
||||
err = verify_simple_hash(sha_handle, data);
|
||||
@ -250,7 +263,28 @@ static esp_err_t image_load(esp_image_load_mode_t mode, const esp_partition_pos_
|
||||
}
|
||||
|
||||
#ifdef BOOTLOADER_BUILD
|
||||
if (do_load && ram_obfs_value[0] != 0 && ram_obfs_value[1] != 0) { // Need to deobfuscate RAM
|
||||
|
||||
#ifdef SECURE_BOOT_CHECK_SIGNATURE
|
||||
/* If signature was checked in bootloader build, verified_digest should equal image_digest
|
||||
|
||||
This is to detect any fault injection that caused signature verification to not complete normally.
|
||||
|
||||
Any attack which bypasses this check should be of limited use as the RAM contents are still obfuscated, therefore we do the check
|
||||
immediately before we deobfuscate.
|
||||
|
||||
Note: the conditions for making this check are the same as for setting verify_sha above, but on ESP32 SB V1 we move the test for
|
||||
"only verify signature in bootloader" into the macro so it's tested multiple times.
|
||||
*/
|
||||
#if CONFIG_SECURE_BOOT_V2_ENABLED
|
||||
ESP_FAULT_ASSERT(memcmp(image_digest, verified_digest, HASH_LEN) == 0);
|
||||
#else // Secure Boot V1 on ESP32, only verify signatures for apps not bootloaders
|
||||
ESP_FAULT_ASSERT(data->start_addr == ESP_BOOTLOADER_OFFSET || memcmp(image_digest, verified_digest, HASH_LEN) == 0);
|
||||
#endif
|
||||
|
||||
#endif // SECURE_BOOT_CHECK_SIGNATURE
|
||||
|
||||
// Deobfuscate RAM
|
||||
if (do_load && ram_obfs_value[0] != 0 && ram_obfs_value[1] != 0) {
|
||||
for (int i = 0; i < data->image.segment_count; i++) {
|
||||
uint32_t load_addr = data->segments[i].load_addr;
|
||||
if (should_load(load_addr)) {
|
||||
@ -336,6 +370,127 @@ static esp_err_t verify_image_header(uint32_t src_addr, const esp_image_header_t
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifdef BOOTLOADER_BUILD
|
||||
/* Check the region load_addr - load_end doesn't overlap any memory used by the bootloader, registers, or other invalid memory
|
||||
*/
|
||||
static bool verify_load_addresses(int segment_index, intptr_t load_addr, intptr_t load_end, bool print_error, bool no_recurse)
|
||||
{
|
||||
/* Addresses of static data and the "loader" section of bootloader IRAM, all defined in ld script */
|
||||
const char *reason = NULL;
|
||||
extern int _dram_start, _dram_end, _loader_text_start, _loader_text_end;
|
||||
void *load_addr_p = (void *)load_addr;
|
||||
void *load_end_p = (void *)load_end;
|
||||
|
||||
if (load_end == load_addr) {
|
||||
return true; // zero-length segments are fine
|
||||
}
|
||||
assert(load_end > load_addr); // data_len<16MB is checked in verify_segment_header() which is called before this, so this should always be true
|
||||
|
||||
if (esp_ptr_in_dram(load_addr_p) && esp_ptr_in_dram(load_end_p)) { /* Writing to DRAM */
|
||||
/* Check if we're clobbering the stack */
|
||||
intptr_t sp = (intptr_t)get_sp();
|
||||
if (bootloader_util_regions_overlap(sp - STACK_LOAD_HEADROOM, SOC_ROM_STACK_START,
|
||||
load_addr, load_end)) {
|
||||
reason = "overlaps bootloader stack";
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
/* Check if we're clobbering static data
|
||||
|
||||
(_dram_start.._dram_end includes bss, data, rodata sections in DRAM)
|
||||
*/
|
||||
if (bootloader_util_regions_overlap((intptr_t)&_dram_start, (intptr_t)&_dram_end, load_addr, load_end)) {
|
||||
reason = "overlaps bootloader data";
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
/* LAST DRAM CHECK (recursive): for D/IRAM, check the equivalent IRAM addresses if needed
|
||||
|
||||
Allow for the possibility that even though both pointers are IRAM, only part of the region is in a D/IRAM
|
||||
section. In which case we recurse to check the part which falls in D/IRAM.
|
||||
|
||||
Note: We start with SOC_DIRAM_DRAM_LOW/HIGH and convert that address to IRAM to account for any reversing of word order
|
||||
(chip-specific).
|
||||
*/
|
||||
if (!no_recurse && bootloader_util_regions_overlap(SOC_DIRAM_DRAM_LOW, SOC_DIRAM_DRAM_HIGH, load_addr, load_end)) {
|
||||
intptr_t iram_load_addr, iram_load_end;
|
||||
|
||||
if (esp_ptr_in_diram_dram(load_addr_p)) {
|
||||
iram_load_addr = (intptr_t)esp_ptr_diram_dram_to_iram(load_addr_p);
|
||||
} else {
|
||||
iram_load_addr = (intptr_t)esp_ptr_diram_dram_to_iram((void *)SOC_DIRAM_DRAM_LOW);
|
||||
}
|
||||
|
||||
if (esp_ptr_in_diram_dram(load_end_p)) {
|
||||
iram_load_end = (intptr_t)esp_ptr_diram_dram_to_iram(load_end_p);
|
||||
} else {
|
||||
iram_load_end = (intptr_t)esp_ptr_diram_dram_to_iram((void *)SOC_DIRAM_DRAM_HIGH);
|
||||
}
|
||||
|
||||
if (iram_load_end < iram_load_addr) {
|
||||
return verify_load_addresses(segment_index, iram_load_end, iram_load_addr, print_error, true);
|
||||
} else {
|
||||
return verify_load_addresses(segment_index, iram_load_addr, iram_load_end, print_error, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (esp_ptr_in_iram(load_addr_p) && esp_ptr_in_iram(load_end_p)) { /* Writing to IRAM */
|
||||
/* Check for overlap of 'loader' section of IRAM */
|
||||
if (bootloader_util_regions_overlap((intptr_t)&_loader_text_start, (intptr_t)&_loader_text_end,
|
||||
load_addr, load_end)) {
|
||||
reason = "overlaps loader IRAM";
|
||||
goto invalid;
|
||||
}
|
||||
|
||||
/* LAST IRAM CHECK (recursive): for D/IRAM, check the equivalent DRAM address if needed
|
||||
|
||||
Allow for the possibility that even though both pointers are IRAM, only part of the region is in a D/IRAM
|
||||
section. In which case we recurse to check the part which falls in D/IRAM.
|
||||
Note: We start with SOC_DIRAM_IRAM_LOW/HIGH and convert that address to DRAM to account for any reversing of word order
|
||||
(chip-specific).
|
||||
*/
|
||||
if (!no_recurse && bootloader_util_regions_overlap(SOC_DIRAM_IRAM_LOW, SOC_DIRAM_IRAM_HIGH, load_addr, load_end)) {
|
||||
intptr_t dram_load_addr, dram_load_end;
|
||||
|
||||
if (esp_ptr_in_diram_iram(load_addr_p)) {
|
||||
dram_load_addr = (intptr_t)esp_ptr_diram_iram_to_dram(load_addr_p);
|
||||
} else {
|
||||
dram_load_addr = (intptr_t)esp_ptr_diram_iram_to_dram((void *)SOC_DIRAM_IRAM_LOW);
|
||||
}
|
||||
|
||||
if (esp_ptr_in_diram_iram(load_end_p)) {
|
||||
dram_load_end = (intptr_t)esp_ptr_diram_iram_to_dram(load_end_p);
|
||||
} else {
|
||||
dram_load_end = (intptr_t)esp_ptr_diram_iram_to_dram((void *)SOC_DIRAM_IRAM_HIGH);
|
||||
}
|
||||
|
||||
if (dram_load_end < dram_load_addr) {
|
||||
return verify_load_addresses(segment_index, dram_load_end, dram_load_addr, print_error, true);
|
||||
} else {
|
||||
return verify_load_addresses(segment_index, dram_load_addr, dram_load_end, print_error, true);
|
||||
}
|
||||
}
|
||||
/* Sections entirely in RTC memory won't overlap with a vanilla bootloader but are valid load addresses, thus skipping them from the check */
|
||||
} else if (esp_ptr_in_rtc_iram_fast(load_addr_p) && esp_ptr_in_rtc_iram_fast(load_end_p)){
|
||||
return true;
|
||||
} else if (esp_ptr_in_rtc_dram_fast(load_addr_p) && esp_ptr_in_rtc_dram_fast(load_end_p)){
|
||||
return true;
|
||||
} else if (esp_ptr_in_rtc_slow(load_addr_p) && esp_ptr_in_rtc_slow(load_end_p)) {
|
||||
return true;
|
||||
} else { /* Not a DRAM or an IRAM or RTC Fast IRAM, RTC Fast DRAM or RTC Slow address */
|
||||
reason = "bad load address range";
|
||||
goto invalid;
|
||||
}
|
||||
return true;
|
||||
|
||||
invalid:
|
||||
if (print_error) {
|
||||
ESP_LOGE(TAG, "Segment %d 0x%08x-0x%08x invalid: %s", segment_index, load_addr, load_end, reason);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif // BOOTLOADER_BUILD
|
||||
|
||||
static esp_err_t process_segment(int index, uint32_t flash_addr, esp_image_segment_header_t *header, bool silent, bool do_load, bootloader_sha256_handle_t sha_handle, uint32_t *checksum)
|
||||
{
|
||||
esp_err_t err;
|
||||
@ -378,34 +533,9 @@ static esp_err_t process_segment(int index, uint32_t flash_addr, esp_image_segme
|
||||
|
||||
#ifdef BOOTLOADER_BUILD
|
||||
/* Before loading segment, check it doesn't clobber bootloader RAM. */
|
||||
if (do_load) {
|
||||
const intptr_t load_end = load_addr + data_len;
|
||||
if (load_end < (intptr_t) SOC_DRAM_HIGH) {
|
||||
/* Writing to DRAM */
|
||||
intptr_t sp = (intptr_t)get_sp();
|
||||
if (load_end > sp - STACK_LOAD_HEADROOM) {
|
||||
/* Bootloader .data/.rodata/.bss is above the stack, so this
|
||||
* also checks that we aren't overwriting these segments.
|
||||
*
|
||||
* TODO: This assumes specific arrangement of sections we have
|
||||
* in the ESP32. Rewrite this in a generic way to support other
|
||||
* layouts.
|
||||
*/
|
||||
ESP_LOGE(TAG, "Segment %d end address 0x%08x too high (bootloader stack 0x%08x limit 0x%08x)",
|
||||
index, load_end, sp, sp - STACK_LOAD_HEADROOM);
|
||||
return ESP_ERR_IMAGE_INVALID;
|
||||
}
|
||||
} else {
|
||||
/* Writing to IRAM */
|
||||
const intptr_t loader_iram_start = (intptr_t) &_loader_text_start;
|
||||
const intptr_t loader_iram_end = (intptr_t) &_loader_text_end;
|
||||
|
||||
if (bootloader_util_regions_overlap(loader_iram_start, loader_iram_end,
|
||||
load_addr, load_end)) {
|
||||
ESP_LOGE(TAG, "Segment %d (0x%08x-0x%08x) overlaps bootloader IRAM (0x%08x-0x%08x)",
|
||||
index, load_addr, load_end, loader_iram_start, loader_iram_end);
|
||||
return ESP_ERR_IMAGE_INVALID;
|
||||
}
|
||||
if (do_load && data_len > 0) {
|
||||
if (!verify_load_addresses(index, load_addr, load_addr + data_len, true, false)) {
|
||||
return ESP_ERR_IMAGE_INVALID;
|
||||
}
|
||||
}
|
||||
#endif // BOOTLOADER_BUILD
|
||||
@ -415,6 +545,10 @@ static esp_err_t process_segment(int index, uint32_t flash_addr, esp_image_segme
|
||||
|
||||
int32_t data_len_remain = data_len;
|
||||
while (data_len_remain > 0) {
|
||||
#if SECURE_BOOT_CHECK_SIGNATURE && defined(BOOTLOADER_BUILD)
|
||||
/* Double check the address verification done above */
|
||||
ESP_FAULT_ASSERT(!do_load || verify_load_addresses(0, load_addr, load_addr + data_len_remain, false, false));
|
||||
#endif
|
||||
uint32_t offset_page = ((data_addr & MMAP_ALIGNED_MASK) != 0) ? 1 : 0;
|
||||
/* Data we could map in case we are not aligned to PAGE boundary is one page size lesser. */
|
||||
data_len = MIN(data_len_remain, ((free_page_count - offset_page) * SPI_FLASH_MMU_PAGE_SIZE));
|
||||
@ -440,7 +574,7 @@ static esp_err_t process_segment_data(intptr_t load_addr, uint32_t data_addr, ui
|
||||
{
|
||||
// If we are not loading, and the checksum is empty, skip processing this
|
||||
// segment for data
|
||||
if(!do_load && checksum == NULL) {
|
||||
if (!do_load && checksum == NULL) {
|
||||
ESP_LOGD(TAG, "skipping checksum for segment");
|
||||
return ESP_OK;
|
||||
}
|
||||
@ -599,7 +733,7 @@ static esp_err_t verify_checksum(bootloader_sha256_handle_t sha_handle, uint32_t
|
||||
length = (length + 15) & ~15; // Pad to next full 16 byte block
|
||||
|
||||
// Verify checksum
|
||||
uint8_t buf[16];
|
||||
WORD_ALIGNED_ATTR uint8_t buf[16];
|
||||
esp_err_t err = bootloader_flash_read(data->start_addr + unpadded_length, buf, length - unpadded_length, true);
|
||||
uint8_t calc = buf[length - unpadded_length - 1];
|
||||
uint8_t checksum = (checksum_word >> 24)
|
||||
@ -623,9 +757,9 @@ static esp_err_t verify_checksum(bootloader_sha256_handle_t sha_handle, uint32_t
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t verify_secure_boot_signature(bootloader_sha256_handle_t sha_handle, esp_image_metadata_t *data)
|
||||
static esp_err_t verify_secure_boot_signature(bootloader_sha256_handle_t sha_handle, esp_image_metadata_t *data, uint8_t *image_digest, uint8_t *verified_digest)
|
||||
{
|
||||
uint8_t image_hash[HASH_LEN] = { 0 };
|
||||
#ifdef SECURE_BOOT_CHECK_SIGNATURE
|
||||
uint32_t end = data->start_addr + data->image_len;
|
||||
|
||||
ESP_LOGI(TAG, "Verifying image signature...");
|
||||
@ -638,25 +772,36 @@ static esp_err_t verify_secure_boot_signature(bootloader_sha256_handle_t sha_han
|
||||
bootloader_munmap(simple_hash);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32S2BETA
|
||||
// Pad to 4096 byte sector boundary
|
||||
if (end % FLASH_SECTOR_SIZE != 0) {
|
||||
uint32_t pad_len = FLASH_SECTOR_SIZE - (end % FLASH_SECTOR_SIZE);
|
||||
const void *padding = bootloader_mmap(end, pad_len);
|
||||
bootloader_sha256_data(sha_handle, padding, pad_len);
|
||||
#if CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME
|
||||
// End of the image needs to be padded all the way to a 4KB boundary, after the simple hash
|
||||
// (for apps they are usually already padded due to --secure-pad-v2, only a problem if this option was not used.)
|
||||
uint32_t padded_end = (end + FLASH_SECTOR_SIZE - 1) & ~(FLASH_SECTOR_SIZE-1);
|
||||
if (padded_end > end) {
|
||||
const void *padding = bootloader_mmap(end, padded_end - end);
|
||||
bootloader_sha256_data(sha_handle, padding, padded_end - end);
|
||||
bootloader_munmap(padding);
|
||||
end += pad_len;
|
||||
end = padded_end;
|
||||
}
|
||||
#endif
|
||||
|
||||
bootloader_sha256_finish(sha_handle, image_hash);
|
||||
bootloader_sha256_finish(sha_handle, image_digest);
|
||||
|
||||
// Log the hash for debugging
|
||||
bootloader_debug_buffer(image_hash, HASH_LEN, "Calculated secure boot hash");
|
||||
bootloader_debug_buffer(image_digest, HASH_LEN, "Calculated secure boot hash");
|
||||
|
||||
// Use hash to verify signature block
|
||||
const esp_secure_boot_sig_block_t *sig_block = bootloader_mmap(data->start_addr + data->image_len, sizeof(esp_secure_boot_sig_block_t));
|
||||
esp_err_t err = esp_secure_boot_verify_signature_block(sig_block, image_hash);
|
||||
esp_err_t err = ESP_ERR_IMAGE_INVALID;
|
||||
const void *sig_block;
|
||||
#ifdef CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME
|
||||
ESP_FAULT_ASSERT(memcmp(image_digest, verified_digest, HASH_LEN) != 0); /* sanity check that these values start differently */
|
||||
sig_block = bootloader_mmap(data->start_addr + data->image_len, sizeof(esp_secure_boot_sig_block_t));
|
||||
err = esp_secure_boot_verify_ecdsa_signature_block(sig_block, image_digest, verified_digest);
|
||||
#elif CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME
|
||||
ESP_FAULT_ASSERT(memcmp(image_digest, verified_digest, HASH_LEN) != 0); /* sanity check that these values start differently */
|
||||
sig_block = bootloader_mmap(end, sizeof(ets_secure_boot_signature_t));
|
||||
err = esp_secure_boot_verify_rsa_signature_block(sig_block, image_digest, verified_digest);
|
||||
#endif
|
||||
|
||||
bootloader_munmap(sig_block);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Secure boot signature verification failed");
|
||||
@ -677,11 +822,12 @@ static esp_err_t verify_secure_boot_signature(bootloader_sha256_handle_t sha_han
|
||||
return ESP_ERR_IMAGE_INVALID;
|
||||
}
|
||||
|
||||
#if CONFIG_IDF_TARGET_ESP32S2BETA
|
||||
#if CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME
|
||||
// Adjust image length result to include the appended signature
|
||||
data->image_len = end - data->start_addr + sizeof(ets_secure_boot_signature_t);
|
||||
#endif
|
||||
|
||||
#endif // SECURE_BOOT_CHECK_SIGNATURE
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
@ -705,3 +851,21 @@ static esp_err_t verify_simple_hash(bootloader_sha256_handle_t sha_handle, esp_i
|
||||
bootloader_munmap(hash);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
int esp_image_get_flash_size(esp_image_flash_size_t app_flash_size)
|
||||
{
|
||||
switch (app_flash_size) {
|
||||
case ESP_IMAGE_FLASH_SIZE_1MB:
|
||||
return 1 * 1024 * 1024;
|
||||
case ESP_IMAGE_FLASH_SIZE_2MB:
|
||||
return 2 * 1024 * 1024;
|
||||
case ESP_IMAGE_FLASH_SIZE_4MB:
|
||||
return 4 * 1024 * 1024;
|
||||
case ESP_IMAGE_FLASH_SIZE_8MB:
|
||||
return 8 * 1024 * 1024;
|
||||
case ESP_IMAGE_FLASH_SIZE_16MB:
|
||||
return 16 * 1024 * 1024;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
@ -31,16 +31,25 @@ void esp_flash_encryption_init_checks()
|
||||
// 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
|
||||
#ifdef CONFIG_SECURE_BOOT
|
||||
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);
|
||||
bool flash_crypt_cnt_wr_dis = esp_efuse_read_field_bit(ESP_EFUSE_WR_DIS_FLASH_CRYPT_CNT);
|
||||
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();
|
||||
uint8_t flash_crypt_cnt = 0;
|
||||
esp_efuse_read_field_blob(ESP_EFUSE_FLASH_CRYPT_CNT, &flash_crypt_cnt,
|
||||
ESP_EFUSE_FLASH_CRYPT_CNT[0]->bit_count);
|
||||
if (flash_crypt_cnt == (1<<(ESP_EFUSE_FLASH_CRYPT_CNT[0]->bit_count))-1) {
|
||||
// If encryption counter is already max, no need to write protect it
|
||||
// (this distinction is important on ESP32 ECO3 where write-protecting FLASH_CRYPT_CNT also write-protects UART_DL_DIS)
|
||||
flash_crypt_cnt_wr_dis = true;
|
||||
}
|
||||
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_BOOT
|
||||
#endif // CONFIG_SECURE_FLASH_ENCRYPTION_MODE_RELEASE
|
||||
|
||||
// Second check is to print a warning or error if the current running flash encryption mode
|
||||
@ -48,39 +57,44 @@ void esp_flash_encryption_init_checks()
|
||||
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.");
|
||||
ESP_LOGE(TAG, "Flash encryption settings error: app is configured for RELEASE but efuses are set for DEVELOPMENT");
|
||||
ESP_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)");
|
||||
ESP_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");
|
||||
ESP_LOGI(TAG, "Flash encryption mode is RELEASE");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void esp_flash_write_protect_crypt_cnt(void)
|
||||
{
|
||||
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_efuse_write_field_cnt(ESP_EFUSE_WR_DIS_FLASH_CRYPT_CNT, 1);
|
||||
}
|
||||
esp_efuse_write_field_bit(ESP_EFUSE_WR_DIS_FLASH_CRYPT_CNT);
|
||||
}
|
||||
|
||||
esp_flash_enc_mode_t esp_get_flash_encryption_mode(void)
|
||||
{
|
||||
uint8_t efuse_flash_crypt_cnt_wr_protected = 0;
|
||||
bool efuse_flash_crypt_cnt_wr_protected;
|
||||
uint8_t dis_dl_enc = 0, dis_dl_dec = 0, dis_dl_cache = 0;
|
||||
esp_flash_enc_mode_t mode = ESP_FLASH_ENC_MODE_DEVELOPMENT;
|
||||
|
||||
if (esp_flash_encryption_enabled()) {
|
||||
/* Check if FLASH CRYPT CNT is write protected */
|
||||
esp_efuse_read_field_blob(ESP_EFUSE_WR_DIS_FLASH_CRYPT_CNT, &efuse_flash_crypt_cnt_wr_protected, 1);
|
||||
efuse_flash_crypt_cnt_wr_protected = esp_efuse_read_field_bit(ESP_EFUSE_WR_DIS_FLASH_CRYPT_CNT);
|
||||
if (!efuse_flash_crypt_cnt_wr_protected) {
|
||||
uint8_t flash_crypt_cnt = 0;
|
||||
esp_efuse_read_field_blob(ESP_EFUSE_FLASH_CRYPT_CNT, &flash_crypt_cnt, ESP_EFUSE_FLASH_CRYPT_CNT[0]->bit_count);
|
||||
if (flash_crypt_cnt == (1 << (ESP_EFUSE_FLASH_CRYPT_CNT[0]->bit_count)) - 1) {
|
||||
efuse_flash_crypt_cnt_wr_protected = true; // CRYPT_CNT at max is same as write protected
|
||||
}
|
||||
}
|
||||
|
||||
if (efuse_flash_crypt_cnt_wr_protected) {
|
||||
esp_efuse_read_field_blob(ESP_EFUSE_DISABLE_DL_CACHE, &dis_dl_cache, 1);
|
||||
esp_efuse_read_field_blob(ESP_EFUSE_DISABLE_DL_ENCRYPT, &dis_dl_enc, 1);
|
||||
esp_efuse_read_field_blob(ESP_EFUSE_DISABLE_DL_DECRYPT, &dis_dl_dec, 1);
|
||||
dis_dl_cache = esp_efuse_read_field_bit(ESP_EFUSE_DISABLE_DL_CACHE);
|
||||
dis_dl_enc = esp_efuse_read_field_bit(ESP_EFUSE_DISABLE_DL_ENCRYPT);
|
||||
dis_dl_dec = esp_efuse_read_field_bit(ESP_EFUSE_DISABLE_DL_DECRYPT);
|
||||
|
||||
/* Check if DISABLE_DL_DECRYPT, DISABLE_DL_ENCRYPT & DISABLE_DL_CACHE are set */
|
||||
if ( dis_dl_cache && dis_dl_enc && dis_dl_dec ) {
|
||||
mode = ESP_FLASH_ENC_MODE_RELEASE;
|
||||
|
@ -52,7 +52,7 @@ esp_err_t esp_partition_table_verify(const esp_partition_info_t *partition_table
|
||||
MD5Update(&context, (unsigned char *) partition_table, num_parts * sizeof(esp_partition_info_t));
|
||||
MD5Final(digest, &context);
|
||||
|
||||
unsigned char *md5sum = ((unsigned char *) part) + 16; // skip the 2B magic number and the 14B fillup bytes
|
||||
unsigned char *md5sum = ((unsigned char *) part) + ESP_PARTITION_MD5_OFFSET;
|
||||
|
||||
if (memcmp(md5sum, digest, sizeof(digest)) != 0) {
|
||||
if (log_errors) {
|
||||
|
@ -12,6 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#include "bootloader_sha.h"
|
||||
#include "bootloader_flash.h"
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
@ -15,46 +15,55 @@
|
||||
|
||||
#include "bootloader_flash.h"
|
||||
#include "bootloader_sha.h"
|
||||
#include "bootloader_utility.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_image_format.h"
|
||||
#include "esp_secure_boot.h"
|
||||
#include "mbedtls/sha256.h"
|
||||
#include "mbedtls/x509.h"
|
||||
#include "mbedtls/md.h"
|
||||
#include "mbedtls/platform.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ctr_drbg.h"
|
||||
#include <string.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
static const char *TAG = "secure_boot";
|
||||
#define DIGEST_LEN 32
|
||||
|
||||
#ifdef CONFIG_SECURE_SIGNED_APPS_ECDSA_SCHEME
|
||||
static const char *TAG = "secure_boot_v1";
|
||||
|
||||
extern const uint8_t signature_verification_key_start[] asm("_binary_signature_verification_key_bin_start");
|
||||
extern const uint8_t signature_verification_key_end[] asm("_binary_signature_verification_key_bin_end");
|
||||
|
||||
#define SIGNATURE_VERIFICATION_KEYLEN 64
|
||||
|
||||
#define DIGEST_LEN 32
|
||||
|
||||
esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length)
|
||||
{
|
||||
uint8_t digest[DIGEST_LEN];
|
||||
const uint8_t *data;
|
||||
uint8_t verified_digest[DIGEST_LEN];
|
||||
const esp_secure_boot_sig_block_t *sigblock;
|
||||
|
||||
ESP_LOGD(TAG, "verifying signature src_addr 0x%x length 0x%x", src_addr, length);
|
||||
|
||||
data = bootloader_mmap(src_addr, length + sizeof(esp_secure_boot_sig_block_t));
|
||||
if (data == NULL) {
|
||||
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", src_addr, length + sizeof(esp_secure_boot_sig_block_t));
|
||||
return ESP_FAIL;
|
||||
esp_err_t err = bootloader_sha256_flash_contents(src_addr, length, digest);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Digest calculation failed 0x%x, 0x%x", src_addr, length);
|
||||
return err;
|
||||
}
|
||||
|
||||
// Calculate digest of main image
|
||||
mbedtls_sha256_ret(data, length, digest, 0);
|
||||
|
||||
// Map the signature block and verify the signature
|
||||
sigblock = (const esp_secure_boot_sig_block_t *)(data + length);
|
||||
esp_err_t err = esp_secure_boot_verify_signature_block(sigblock, digest);
|
||||
bootloader_munmap(data);
|
||||
sigblock = (const esp_secure_boot_sig_block_t *)bootloader_mmap(src_addr + length, sizeof(esp_secure_boot_sig_block_t));
|
||||
if (sigblock == NULL) {
|
||||
ESP_LOGE(TAG, "bootloader_mmap(0x%x, 0x%x) failed", src_addr + length, sizeof(esp_secure_boot_sig_block_t));
|
||||
return ESP_FAIL;
|
||||
}
|
||||
err = esp_secure_boot_verify_ecdsa_signature_block(sigblock, digest, verified_digest);
|
||||
bootloader_munmap(sigblock);
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t esp_secure_boot_verify_signature_block(const esp_secure_boot_sig_block_t *sig_block, const uint8_t *image_digest)
|
||||
esp_err_t esp_secure_boot_verify_ecdsa_signature_block(const esp_secure_boot_sig_block_t *sig_block, const uint8_t *image_digest, uint8_t *verified_digest)
|
||||
{
|
||||
#if !(defined(CONFIG_MBEDTLS_ECDSA_C) && defined(CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED))
|
||||
ESP_LOGE(TAG, "Signature verification requires ECDSA & SECP256R1 curve enabled");
|
||||
@ -62,6 +71,9 @@ esp_err_t esp_secure_boot_verify_signature_block(const esp_secure_boot_sig_block
|
||||
#else
|
||||
ptrdiff_t keylen;
|
||||
|
||||
/* Note: in IDF app image verification we don't add any fault injection resistance, boot-time checks only */
|
||||
memset(verified_digest, 0, DIGEST_LEN);
|
||||
|
||||
keylen = signature_verification_key_end - signature_verification_key_start;
|
||||
if (keylen != SIGNATURE_VERIFICATION_KEYLEN) {
|
||||
ESP_LOGE(TAG, "Embedded public verification key has wrong length %d", keylen);
|
||||
@ -123,3 +135,147 @@ cleanup:
|
||||
return ret == 0 ? ESP_OK : ESP_ERR_IMAGE_INVALID;
|
||||
#endif // CONFIG_MBEDTLS_ECDSA_C && CONFIG_MBEDTLS_ECP_DP_SECP256R1_ENABLED
|
||||
}
|
||||
|
||||
#elif CONFIG_SECURE_SIGNED_APPS_RSA_SCHEME
|
||||
|
||||
static const char *TAG = "secure_boot_v2";
|
||||
#define ALIGN_UP(num, align) (((num) + ((align) - 1)) & ~((align) - 1))
|
||||
#define RSA_KEY_SIZE 384 /* RSA 3072 Bits */
|
||||
|
||||
esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length)
|
||||
{
|
||||
uint8_t digest[DIGEST_LEN] = {0};
|
||||
uint8_t verified_digest[DIGEST_LEN] = {0};
|
||||
|
||||
/* Rounding off length to the upper 4k boundary */
|
||||
uint32_t padded_length = ALIGN_UP(length, FLASH_SECTOR_SIZE);
|
||||
ESP_LOGD(TAG, "verifying signature src_addr 0x%x length 0x%x", src_addr, length);
|
||||
|
||||
esp_err_t err = bootloader_sha256_flash_contents(src_addr, padded_length, digest);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Digest calculation failed 0x%x, 0x%x", src_addr, padded_length);
|
||||
return err;
|
||||
}
|
||||
|
||||
const ets_secure_boot_signature_t *sig_block = bootloader_mmap(src_addr + padded_length, sizeof(ets_secure_boot_signature_t));
|
||||
if (sig_block == NULL) {
|
||||
ESP_LOGE(TAG, "Failed to mmap data at offset 0x%x", src_addr + padded_length);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
err = esp_secure_boot_verify_rsa_signature_block(sig_block, digest, verified_digest);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGE(TAG, "Secure Boot V2 verification failed.");
|
||||
}
|
||||
bootloader_munmap(sig_block);
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t esp_secure_boot_verify_rsa_signature_block(const ets_secure_boot_signature_t *sig_block, const uint8_t *image_digest, uint8_t *verified_digest)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
#if CONFIG_SECURE_BOOT_V2_ENABLED /* Verify key against efuse block */
|
||||
uint8_t efuse_trusted_digest[DIGEST_LEN] = {0}, sig_block_trusted_digest[DIGEST_LEN] = {0};
|
||||
memcpy(efuse_trusted_digest, (uint8_t *) EFUSE_BLK2_RDATA0_REG, sizeof(efuse_trusted_digest));
|
||||
|
||||
/* Note: in IDF verification we don't add any fault injection resistance, as we don't expect this to be called
|
||||
during boot-time verification. */
|
||||
memset(verified_digest, 0, DIGEST_LEN);
|
||||
|
||||
/* Generating the SHA of the public key components in the signature block */
|
||||
bootloader_sha256_handle_t sig_block_sha;
|
||||
sig_block_sha = bootloader_sha256_start();
|
||||
bootloader_sha256_data(sig_block_sha, &sig_block->block[0].key, sizeof(sig_block->block[0].key));
|
||||
bootloader_sha256_finish(sig_block_sha, (unsigned char *)sig_block_trusted_digest);
|
||||
|
||||
if (memcmp(efuse_trusted_digest, sig_block_trusted_digest, DIGEST_LEN) != 0) {
|
||||
const uint8_t zeroes[DIGEST_LEN] = {0};
|
||||
/* Can't continue if secure boot is enabled, OR if a different digest is already written in efuse BLK2
|
||||
|
||||
(If BLK2 is empty and Secure Boot is disabled then we assume that it will be enabled later.)
|
||||
*/
|
||||
if (esp_secure_boot_enabled() || memcmp(efuse_trusted_digest, zeroes, DIGEST_LEN) != 0) {
|
||||
ESP_LOGE(TAG, "Public key digest in eFuse BLK2 and the signature block don't match.");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
ESP_LOGI(TAG, "Verifying with RSA-PSS...");
|
||||
int ret = 0;
|
||||
mbedtls_rsa_context pk;
|
||||
mbedtls_entropy_context entropy;
|
||||
mbedtls_ctr_drbg_context ctr_drbg;
|
||||
unsigned char *sig_be = calloc(1, RSA_KEY_SIZE);
|
||||
unsigned char *buf = calloc(1, RSA_KEY_SIZE);
|
||||
if (sig_be == NULL || buf == NULL) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
mbedtls_entropy_init(&entropy);
|
||||
mbedtls_ctr_drbg_init(&ctr_drbg);
|
||||
ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, NULL, 0);
|
||||
if (ret != 0) {
|
||||
ESP_LOGE(TAG, "mbedtls_ctr_drbg_seed returned -0x%04x\n", ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
for (i = 0; i < SECURE_BOOT_NUM_BLOCKS; i++) {
|
||||
const mbedtls_mpi N = { .s = 1,
|
||||
.n = sizeof(sig_block->block[i].key.n)/sizeof(mbedtls_mpi_uint),
|
||||
.p = (void *)sig_block->block[i].key.n,
|
||||
};
|
||||
const mbedtls_mpi e = { .s = 1,
|
||||
.n = sizeof(sig_block->block[i].key.e)/sizeof(mbedtls_mpi_uint), // 1
|
||||
.p = (void *)&sig_block->block[i].key.e,
|
||||
};
|
||||
mbedtls_rsa_init(&pk, MBEDTLS_RSA_PKCS_V21, MBEDTLS_MD_SHA256);
|
||||
ret = mbedtls_rsa_import(&pk, &N, NULL, NULL, NULL, &e);
|
||||
if (ret != 0) {
|
||||
ESP_LOGE(TAG, "Failed mbedtls_rsa_import, err: %d", ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ret = mbedtls_rsa_complete(&pk);
|
||||
if (ret != 0) {
|
||||
ESP_LOGE(TAG, "Failed mbedtls_rsa_complete, err: %d", ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ret = mbedtls_rsa_check_pubkey(&pk);
|
||||
if (ret != 0) {
|
||||
ESP_LOGI(TAG, "Key is not an RSA key -%0x", -ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Signature needs to be byte swapped into BE representation */
|
||||
for (int j = 0; j < RSA_KEY_SIZE; j++) {
|
||||
sig_be[RSA_KEY_SIZE- j - 1] = sig_block->block[i].signature[j];
|
||||
}
|
||||
|
||||
ret = mbedtls_rsa_public( &pk, sig_be, buf);
|
||||
if (ret != 0) {
|
||||
ESP_LOGE(TAG, "mbedtls_rsa_public failed, err: %d", ret);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
ret = mbedtls_rsa_rsassa_pss_verify( &pk, mbedtls_ctr_drbg_random, &ctr_drbg, MBEDTLS_RSA_PUBLIC, MBEDTLS_MD_SHA256, DIGEST_LEN,
|
||||
image_digest, sig_be);
|
||||
if (ret != 0) {
|
||||
ESP_LOGE(TAG, "Failed mbedtls_rsa_rsassa_pss_verify, err: %d", ret);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Signature verified successfully!");
|
||||
}
|
||||
exit:
|
||||
mbedtls_rsa_free(&pk);
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(sig_be);
|
||||
free(buf);
|
||||
return (!ret) ? ESP_OK : ESP_ERR_IMAGE_INVALID;
|
||||
}
|
||||
#endif
|
||||
|
@ -95,6 +95,7 @@ if(CONFIG_BT_ENABLED)
|
||||
"host/bluedroid/bta/dm/bta_dm_main.c"
|
||||
"host/bluedroid/bta/dm/bta_dm_pm.c"
|
||||
"host/bluedroid/bta/dm/bta_dm_sco.c"
|
||||
"host/bluedroid/bta/dm/bta_dm_qos.c"
|
||||
"host/bluedroid/bta/gatt/bta_gatt_common.c"
|
||||
"host/bluedroid/bta/gatt/bta_gattc_act.c"
|
||||
"host/bluedroid/bta/gatt/bta_gattc_api.c"
|
||||
@ -312,6 +313,7 @@ if(CONFIG_BT_ENABLED)
|
||||
if(CONFIG_BLE_MESH)
|
||||
list(APPEND include_dirs
|
||||
"esp_ble_mesh/mesh_common/include"
|
||||
"esp_ble_mesh/mesh_common/tinycrypt/include"
|
||||
"esp_ble_mesh/mesh_core"
|
||||
"esp_ble_mesh/mesh_core/include"
|
||||
"esp_ble_mesh/mesh_core/storage"
|
||||
@ -323,7 +325,8 @@ if(CONFIG_BT_ENABLED)
|
||||
"esp_ble_mesh/api/models/include"
|
||||
"esp_ble_mesh/api")
|
||||
|
||||
list(APPEND srcs "esp_ble_mesh/api/core/esp_ble_mesh_common_api.c"
|
||||
list(APPEND srcs "esp_ble_mesh/api/core/esp_ble_mesh_ble_api.c"
|
||||
"esp_ble_mesh/api/core/esp_ble_mesh_common_api.c"
|
||||
"esp_ble_mesh/api/core/esp_ble_mesh_local_data_operation_api.c"
|
||||
"esp_ble_mesh/api/core/esp_ble_mesh_low_power_api.c"
|
||||
"esp_ble_mesh/api/core/esp_ble_mesh_networking_api.c"
|
||||
@ -335,6 +338,7 @@ if(CONFIG_BT_ENABLED)
|
||||
"esp_ble_mesh/api/models/esp_ble_mesh_lighting_model_api.c"
|
||||
"esp_ble_mesh/api/models/esp_ble_mesh_sensor_model_api.c"
|
||||
"esp_ble_mesh/api/models/esp_ble_mesh_time_scene_model_api.c"
|
||||
"esp_ble_mesh/btc/btc_ble_mesh_ble.c"
|
||||
"esp_ble_mesh/btc/btc_ble_mesh_config_model.c"
|
||||
"esp_ble_mesh/btc/btc_ble_mesh_generic_model.c"
|
||||
"esp_ble_mesh/btc/btc_ble_mesh_health_model.c"
|
||||
@ -342,11 +346,27 @@ 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_common/mesh_aes_encrypt.c"
|
||||
"esp_ble_mesh/mesh_common/tinycrypt/src/aes_decrypt.c"
|
||||
"esp_ble_mesh/mesh_common/tinycrypt/src/aes_encrypt.c"
|
||||
"esp_ble_mesh/mesh_common/tinycrypt/src/cbc_mode.c"
|
||||
"esp_ble_mesh/mesh_common/tinycrypt/src/ccm_mode.c"
|
||||
"esp_ble_mesh/mesh_common/tinycrypt/src/cmac_mode.c"
|
||||
"esp_ble_mesh/mesh_common/tinycrypt/src/ctr_mode.c"
|
||||
"esp_ble_mesh/mesh_common/tinycrypt/src/ctr_prng.c"
|
||||
"esp_ble_mesh/mesh_common/tinycrypt/src/ecc_dh.c"
|
||||
"esp_ble_mesh/mesh_common/tinycrypt/src/ecc_dsa.c"
|
||||
"esp_ble_mesh/mesh_common/tinycrypt/src/ecc_platform_specific.c"
|
||||
"esp_ble_mesh/mesh_common/tinycrypt/src/ecc.c"
|
||||
"esp_ble_mesh/mesh_common/tinycrypt/src/hmac_prng.c"
|
||||
"esp_ble_mesh/mesh_common/tinycrypt/src/hmac.c"
|
||||
"esp_ble_mesh/mesh_common/tinycrypt/src/sha256.c"
|
||||
"esp_ble_mesh/mesh_common/tinycrypt/src/utils.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_mutex.c"
|
||||
"esp_ble_mesh/mesh_common/mesh_timer.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"
|
||||
@ -355,27 +375,30 @@ if(CONFIG_BT_ENABLED)
|
||||
"esp_ble_mesh/mesh_core/cfg_cli.c"
|
||||
"esp_ble_mesh/mesh_core/cfg_srv.c"
|
||||
"esp_ble_mesh/mesh_core/crypto.c"
|
||||
"esp_ble_mesh/mesh_core/fast_prov.c"
|
||||
"esp_ble_mesh/mesh_core/friend.c"
|
||||
"esp_ble_mesh/mesh_core/health_cli.c"
|
||||
"esp_ble_mesh/mesh_core/health_srv.c"
|
||||
"esp_ble_mesh/mesh_core/local_operation.c"
|
||||
"esp_ble_mesh/mesh_core/lpn.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/proxy_client.c"
|
||||
"esp_ble_mesh/mesh_core/proxy_server.c"
|
||||
"esp_ble_mesh/mesh_core/settings_uid.c"
|
||||
"esp_ble_mesh/mesh_core/settings.c"
|
||||
"esp_ble_mesh/mesh_core/scan.c"
|
||||
"esp_ble_mesh/mesh_core/test.c"
|
||||
"esp_ble_mesh/mesh_core/transport.c"
|
||||
"esp_ble_mesh/mesh_models/common/device_property.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"
|
||||
@ -481,6 +504,7 @@ if(CONFIG_BT_ENABLED)
|
||||
"host/nimble/nimble/nimble/host/src/ble_hs_adv.c"
|
||||
"host/nimble/nimble/nimble/host/src/ble_hs_hci.c"
|
||||
"host/nimble/nimble/nimble/host/src/ble_hs_hci_util.c"
|
||||
"host/nimble/nimble/nimble/host/src/ble_hs_resolv.c"
|
||||
"host/nimble/nimble/nimble/host/store/ram/src/ble_store_ram.c"
|
||||
"host/nimble/nimble/nimble/host/store/config/src/ble_store_config.c"
|
||||
"host/nimble/nimble/nimble/host/store/config/src/ble_store_nvs.c"
|
||||
@ -496,7 +520,8 @@ if(CONFIG_BT_ENABLED)
|
||||
"host/nimble/nimble/porting/nimble/src/mem.c"
|
||||
"host/nimble/nimble/porting/nimble/src/os_mbuf.c"
|
||||
"host/nimble/nimble/porting/nimble/src/os_cputime.c"
|
||||
"host/nimble/esp-hci/src/esp_nimble_hci.c")
|
||||
"host/nimble/esp-hci/src/esp_nimble_hci.c"
|
||||
"host/nimble/port/src/esp_nimble_mem.c")
|
||||
|
||||
if (CONFIG_BLE_MESH)
|
||||
list(APPEND srcs "esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c")
|
||||
@ -543,6 +568,6 @@ idf_component_register(SRCS "${srcs}"
|
||||
if(CONFIG_BT_ENABLED)
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-implicit-fallthrough -Wno-unused-const-variable)
|
||||
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-L${CMAKE_CURRENT_LIST_DIR}/controller/lib")
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "-L${CMAKE_CURRENT_LIST_DIR}/controller/lib/esp32")
|
||||
target_link_libraries(${COMPONENT_LIB} PUBLIC btdm_app)
|
||||
endif()
|
||||
|
@ -78,6 +78,47 @@ menu "Bluetooth"
|
||||
default 1 if BTDM_CTRL_BR_EDR_SCO_DATA_PATH_PCM
|
||||
default 0
|
||||
|
||||
menuconfig BTDM_CTRL_PCM_ROLE_EDGE_CONFIG
|
||||
bool "PCM Signal Config (Role and Polar)"
|
||||
depends on BTDM_CTRL_BR_EDR_SCO_DATA_PATH_PCM
|
||||
default y
|
||||
|
||||
choice BTDM_CTRL_PCM_ROLE
|
||||
prompt "PCM Role"
|
||||
depends on BTDM_CTRL_PCM_ROLE_EDGE_CONFIG
|
||||
help
|
||||
PCM role can be configured as PCM master or PCM slave
|
||||
|
||||
config BTDM_CTRL_PCM_ROLE_MASTER
|
||||
bool "PCM Master"
|
||||
config BTDM_CTRL_PCM_ROLE_SLAVE
|
||||
bool "PCM Slave"
|
||||
endchoice
|
||||
|
||||
choice BTDM_CTRL_PCM_POLAR
|
||||
prompt "PCM Polar"
|
||||
depends on BTDM_CTRL_PCM_ROLE_EDGE_CONFIG
|
||||
help
|
||||
PCM polarity can be configured as Falling Edge or Rising Edge
|
||||
|
||||
config BTDM_CTRL_PCM_POLAR_FALLING_EDGE
|
||||
bool "Falling Edge"
|
||||
config BTDM_CTRL_PCM_POLAR_RISING_EDGE
|
||||
bool "Rising Edge"
|
||||
endchoice
|
||||
|
||||
config BTDM_CTRL_PCM_ROLE_EFF
|
||||
int
|
||||
default 0 if BTDM_CTRL_PCM_ROLE_MASTER
|
||||
default 1 if BTDM_CTRL_PCM_ROLE_SLAVE
|
||||
default 0
|
||||
|
||||
config BTDM_CTRL_PCM_POLAR_EFF
|
||||
int
|
||||
default 0 if BTDM_CTRL_PCM_POLAR_FALLING_EDGE
|
||||
default 1 if BTDM_CTRL_PCM_POLAR_RISING_EDGE
|
||||
default 0
|
||||
|
||||
config BTDM_CTRL_AUTO_LATENCY
|
||||
bool "Auto latency"
|
||||
depends on BTDM_CTRL_MODE_BTDM
|
||||
@ -91,6 +132,19 @@ menu "Bluetooth"
|
||||
default BTDM_CTRL_AUTO_LATENCY if BTDM_CTRL_MODE_BTDM
|
||||
default n
|
||||
|
||||
config BTDM_CTRL_LEGACY_AUTH_VENDOR_EVT
|
||||
bool "Legacy Authentication Vendor Specific Event Enable"
|
||||
depends on BTDM_CTRL_MODE_BR_EDR_ONLY || BTDM_CTRL_MODE_BTDM
|
||||
default y
|
||||
help
|
||||
To protect from BIAS attack during Legacy authentication,
|
||||
Legacy authentication Vendor specific event should be enabled
|
||||
|
||||
config BTDM_CTRL_LEGACY_AUTH_VENDOR_EVT_EFF
|
||||
bool
|
||||
default BTDM_CTRL_LEGACY_AUTH_VENDOR_EVT if BTDM_CTRL_MODE_BR_EDR_ONLY || BTDM_CTRL_MODE_BTDM
|
||||
default 0
|
||||
|
||||
|
||||
config BTDM_CTRL_BLE_MAX_CONN_EFF
|
||||
int
|
||||
@ -333,7 +387,7 @@ menu "Bluetooth"
|
||||
|
||||
config BTDM_CTRL_FULL_SCAN_SUPPORTED
|
||||
bool "BLE full scan feature supported"
|
||||
depends on BTDM_CONTROLLER_MODE_BLE_ONLY || BTDM_CONTROLLER_MODE_BTDM
|
||||
depends on BTDM_CTRL_MODE_BLE_ONLY || BTDM_CTRL_MODE_BTDM
|
||||
default y
|
||||
help
|
||||
The full scan function is mainly used to provide BLE scan performance.
|
||||
@ -373,21 +427,6 @@ 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
|
||||
|
@ -57,6 +57,7 @@
|
||||
#endif
|
||||
|
||||
#if CONFIG_BLE_MESH
|
||||
#include "btc_ble_mesh_ble.h"
|
||||
#include "btc_ble_mesh_prov.h"
|
||||
#include "btc_ble_mesh_health_model.h"
|
||||
#include "btc_ble_mesh_config_model.h"
|
||||
@ -68,7 +69,7 @@
|
||||
|
||||
#define BTC_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE)
|
||||
#define BTC_TASK_STACK_SIZE (BT_BTC_TASK_STACK_SIZE + BT_TASK_EXTRA_STACK_SIZE) //by menuconfig
|
||||
#define BTC_TASK_NAME "btcT"
|
||||
#define BTC_TASK_NAME "BTC_TASK"
|
||||
#define BTC_TASK_PRIO (BT_TASK_MAX_PRIORITIES - 6)
|
||||
|
||||
osi_thread_t *btc_thread;
|
||||
@ -93,9 +94,9 @@ static const btc_func_t profile_tab[BTC_PID_NUM] = {
|
||||
#endif ///BLE_INCLUDED == TRUE
|
||||
[BTC_PID_BLE_HID] = {NULL, NULL},
|
||||
[BTC_PID_SPPLIKE] = {NULL, NULL},
|
||||
#if (GATTS_INCLUDED == TRUE)
|
||||
#if (BLUFI_INCLUDED == TRUE)
|
||||
[BTC_PID_BLUFI] = {btc_blufi_call_handler, btc_blufi_cb_handler },
|
||||
#endif ///GATTS_INCLUDED == TRUE
|
||||
#endif ///BLUFI_INCLUDED == TRUE
|
||||
[BTC_PID_DM_SEC] = {NULL, btc_dm_sec_cb_handler },
|
||||
#endif
|
||||
[BTC_PID_ALARM] = {btc_alarm_handler, NULL },
|
||||
@ -124,18 +125,43 @@ static const btc_func_t profile_tab[BTC_PID_NUM] = {
|
||||
#if CONFIG_BLE_MESH
|
||||
[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 },
|
||||
#if CONFIG_BLE_MESH_HEALTH_CLI
|
||||
[BTC_PID_HEALTH_CLIENT] = {btc_ble_mesh_health_client_call_handler, btc_ble_mesh_health_client_cb_handler },
|
||||
#endif /* CONFIG_BLE_MESH_HEALTH_CLI */
|
||||
#if CONFIG_BLE_MESH_HEALTH_SRV
|
||||
[BTC_PID_HEALTH_SERVER] = {btc_ble_mesh_health_server_call_handler, btc_ble_mesh_health_server_cb_handler },
|
||||
#endif /* CONFIG_BLE_MESH_HEALTH_SRV */
|
||||
#if CONFIG_BLE_MESH_CFG_CLI
|
||||
[BTC_PID_CONFIG_CLIENT] = {btc_ble_mesh_config_client_call_handler, btc_ble_mesh_config_client_cb_handler },
|
||||
#endif /* CONFIG_BLE_MESH_CFG_CLI */
|
||||
[BTC_PID_CONFIG_SERVER] = {NULL, btc_ble_mesh_config_server_cb_handler },
|
||||
#if CONFIG_BLE_MESH_GENERIC_CLIENT
|
||||
[BTC_PID_GENERIC_CLIENT] = {btc_ble_mesh_generic_client_call_handler, btc_ble_mesh_generic_client_cb_handler },
|
||||
#endif /* CONFIG_BLE_MESH_GENERIC_CLIENT */
|
||||
#if CONFIG_BLE_MESH_LIGHTING_CLIENT
|
||||
[BTC_PID_LIGHTING_CLIENT] = {btc_ble_mesh_lighting_client_call_handler, btc_ble_mesh_lighting_client_cb_handler },
|
||||
#endif /* CONFIG_BLE_MESH_LIGHTING_CLIENT */
|
||||
#if CONFIG_BLE_MESH_SENSOR_CLI
|
||||
[BTC_PID_SENSOR_CLIENT] = {btc_ble_mesh_sensor_client_call_handler, btc_ble_mesh_sensor_client_cb_handler },
|
||||
#endif /* CONFIG_BLE_MESH_SENSOR_CLI */
|
||||
#if CONFIG_BLE_MESH_TIME_SCENE_CLIENT
|
||||
[BTC_PID_TIME_SCENE_CLIENT] = {btc_ble_mesh_time_scene_client_call_handler, btc_ble_mesh_time_scene_client_cb_handler},
|
||||
#endif /* CONFIG_BLE_MESH_TIME_SCENE_CLIENT */
|
||||
#if CONFIG_BLE_MESH_GENERIC_SERVER
|
||||
[BTC_PID_GENERIC_SERVER] = {NULL, btc_ble_mesh_generic_server_cb_handler },
|
||||
#endif /* CONFIG_BLE_MESH_GENERIC_SERVER */
|
||||
#if CONFIG_BLE_MESH_LIGHTING_SERVER
|
||||
[BTC_PID_LIGHTING_SERVER] = {NULL, btc_ble_mesh_lighting_server_cb_handler },
|
||||
#endif /* CONFIG_BLE_MESH_LIGHTING_SERVER */
|
||||
#if CONFIG_BLE_MESH_SENSOR_SERVER
|
||||
[BTC_PID_SENSOR_SERVER] = {NULL, btc_ble_mesh_sensor_server_cb_handler },
|
||||
#endif /* CONFIG_BLE_MESH_SENSOR_SERVER */
|
||||
#if CONFIG_BLE_MESH_TIME_SCENE_SERVER
|
||||
[BTC_PID_TIME_SCENE_SERVER] = {NULL, btc_ble_mesh_time_scene_server_cb_handler},
|
||||
#endif /* CONFIG_BLE_MESH_TIME_SCENE_SERVER */
|
||||
#if CONFIG_BLE_MESH_BLE_COEX_SUPPORT
|
||||
[BTC_PID_BLE_MESH_BLE_COEX] = {btc_ble_mesh_ble_call_handler, btc_ble_mesh_ble_cb_handler },
|
||||
#endif /* CONFIG_BLE_MESH_BLE_COEX_SUPPORT */
|
||||
#endif /* #if CONFIG_BLE_MESH */
|
||||
};
|
||||
|
||||
@ -185,6 +211,15 @@ static bt_status_t btc_task_post(btc_msg_t *msg, uint32_t timeout)
|
||||
return BT_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* transfer an message to another module in the different task.
|
||||
* @param msg message
|
||||
* @param arg paramter
|
||||
* @param arg_len length of paramter
|
||||
* @param copy_func deep copy function
|
||||
* @return BT_STATUS_SUCCESS: success
|
||||
* others: fail
|
||||
*/
|
||||
bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg_deep_copy_t copy_func)
|
||||
{
|
||||
btc_msg_t lmsg;
|
||||
@ -214,6 +249,34 @@ bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* transfer an message to another module in tha same task.
|
||||
* @param msg message
|
||||
* @param arg paramter
|
||||
* @return BT_STATUS_SUCCESS: success
|
||||
* others: fail
|
||||
*/
|
||||
bt_status_t btc_inter_profile_call(btc_msg_t *msg, void *arg)
|
||||
{
|
||||
if (msg == NULL) {
|
||||
return BT_STATUS_PARM_INVALID;
|
||||
}
|
||||
|
||||
msg->arg = arg;
|
||||
switch (msg->sig) {
|
||||
case BTC_SIG_API_CALL:
|
||||
profile_tab[msg->pid].btc_call(msg);
|
||||
break;
|
||||
case BTC_SIG_API_CB:
|
||||
profile_tab[msg->pid].btc_cb(msg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return BT_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
#if BTC_DYNAMIC_MEMORY
|
||||
|
||||
static void btc_deinit_mem(void) {
|
||||
@ -244,12 +307,13 @@ static void btc_deinit_mem(void) {
|
||||
osi_free(btc_creat_tab_env_ptr);
|
||||
btc_creat_tab_env_ptr = NULL;
|
||||
}
|
||||
|
||||
#if (BLUFI_INCLUDED == TRUE)
|
||||
if (blufi_env_ptr) {
|
||||
osi_free(blufi_env_ptr);
|
||||
blufi_env_ptr = NULL;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if BTC_HF_CLIENT_INCLUDED == TRUE && HFP_DYNAMIC_MEMORY == TRUE
|
||||
if (hf_client_local_param_ptr) {
|
||||
@ -298,12 +362,13 @@ static bt_status_t btc_init_mem(void) {
|
||||
goto error_exit;
|
||||
}
|
||||
memset((void *)btc_creat_tab_env_ptr, 0, sizeof(esp_btc_creat_tab_t));
|
||||
|
||||
#if (BLUFI_INCLUDED == TRUE)
|
||||
if ((blufi_env_ptr = (tBLUFI_ENV *)osi_malloc(sizeof(tBLUFI_ENV))) == NULL) {
|
||||
goto error_exit;
|
||||
}
|
||||
memset((void *)blufi_env_ptr, 0, sizeof(tBLUFI_ENV));
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if BTC_HF_CLIENT_INCLUDED == TRUE && HFP_DYNAMIC_MEMORY == TRUE
|
||||
if ((hf_client_local_param_ptr = (hf_client_local_param_t *)osi_malloc(sizeof(hf_client_local_param_t))) == NULL) {
|
||||
@ -331,9 +396,9 @@ error_exit:;
|
||||
}
|
||||
#endif ///BTC_DYNAMIC_MEMORY
|
||||
|
||||
int btc_init(void)
|
||||
bt_status_t btc_init(void)
|
||||
{
|
||||
btc_thread = osi_thread_create("BTC_TASK", BTC_TASK_STACK_SIZE, BTC_TASK_PRIO, BTC_TASK_PINNED_TO_CORE, 2);
|
||||
btc_thread = osi_thread_create(BTC_TASK_NAME, BTC_TASK_STACK_SIZE, BTC_TASK_PRIO, BTC_TASK_PINNED_TO_CORE, 2);
|
||||
if (btc_thread == NULL) {
|
||||
return BT_STATUS_NOMEM;
|
||||
}
|
||||
@ -378,3 +443,8 @@ bool btc_check_queue_is_congest(void)
|
||||
return false;
|
||||
}
|
||||
|
||||
int get_btc_work_queue_size(void)
|
||||
{
|
||||
return osi_thread_queue_wait_size(btc_thread, 0);
|
||||
}
|
||||
|
||||
|
@ -53,7 +53,9 @@ typedef enum {
|
||||
BTC_PID_GAP_BLE,
|
||||
BTC_PID_BLE_HID,
|
||||
BTC_PID_SPPLIKE,
|
||||
#if (BLUFI_INCLUDED == TRUE)
|
||||
BTC_PID_BLUFI,
|
||||
#endif ///BLUFI_INCLUDED == TRUE
|
||||
BTC_PID_DM_SEC,
|
||||
BTC_PID_ALARM,
|
||||
#if (CLASSIC_BT_INCLUDED == TRUE)
|
||||
@ -85,6 +87,7 @@ typedef enum {
|
||||
BTC_PID_LIGHTING_SERVER,
|
||||
BTC_PID_SENSOR_SERVER,
|
||||
BTC_PID_TIME_SCENE_SERVER,
|
||||
BTC_PID_BLE_MESH_BLE_COEX,
|
||||
#endif /* CONFIG_BLE_MESH */
|
||||
BTC_PID_NUM,
|
||||
} btc_pid_t; //btc profile id
|
||||
@ -96,10 +99,29 @@ typedef struct {
|
||||
|
||||
typedef void (* btc_arg_deep_copy_t)(btc_msg_t *msg, void *dst, void *src);
|
||||
|
||||
/**
|
||||
* transfer an message to another module in the different task.
|
||||
* @param msg message
|
||||
* @param arg paramter
|
||||
* @param arg_len length of paramter
|
||||
* @param copy_func deep copy function
|
||||
* @return BT_STATUS_SUCCESS: success
|
||||
* others: fail
|
||||
*/
|
||||
bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg_deep_copy_t copy_func);
|
||||
|
||||
int btc_init(void);
|
||||
/**
|
||||
* transfer an message to another module in tha same task.
|
||||
* @param msg message
|
||||
* @param arg paramter
|
||||
* @return BT_STATUS_SUCCESS: success
|
||||
* others: fail
|
||||
*/
|
||||
bt_status_t btc_inter_profile_call(btc_msg_t *msg, void *arg);
|
||||
|
||||
bt_status_t btc_init(void);
|
||||
void btc_deinit(void);
|
||||
bool btc_check_queue_is_congest(void);
|
||||
int get_btc_work_queue_size(void);
|
||||
|
||||
#endif /* __BTC_TASK_H__ */
|
||||
|
@ -40,14 +40,14 @@
|
||||
/**********************************************************
|
||||
* Thread/Task reference
|
||||
**********************************************************/
|
||||
#ifdef CONFIG_BLUEDROID_PINNED_TO_CORE
|
||||
#define UC_TASK_PINNED_TO_CORE (CONFIG_BLUEDROID_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_BLUEDROID_PINNED_TO_CORE : tskNO_AFFINITY)
|
||||
#ifdef CONFIG_BT_BLUEDROID_PINNED_TO_CORE
|
||||
#define UC_TASK_PINNED_TO_CORE (CONFIG_BT_BLUEDROID_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_BT_BLUEDROID_PINNED_TO_CORE : tskNO_AFFINITY)
|
||||
#else
|
||||
#define UC_TASK_PINNED_TO_CORE (0)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BTC_TASK_STACK_SIZE
|
||||
#define UC_BTC_TASK_STACK_SIZE CONFIG_BTC_TASK_STACK_SIZE
|
||||
#ifdef CONFIG_BT_BTC_TASK_STACK_SIZE
|
||||
#define UC_BTC_TASK_STACK_SIZE CONFIG_BT_BTC_TASK_STACK_SIZE
|
||||
#else
|
||||
#define UC_BTC_TASK_STACK_SIZE 4096
|
||||
#endif
|
||||
|
@ -267,6 +267,7 @@ bool config_remove_key(config_t *config, const char *section, const char *key)
|
||||
assert(config != NULL);
|
||||
assert(section != NULL);
|
||||
assert(key != NULL);
|
||||
bool ret;
|
||||
|
||||
section_t *sec = section_find(config, section);
|
||||
entry_t *entry = entry_find(config, section, key);
|
||||
@ -274,7 +275,12 @@ bool config_remove_key(config_t *config, const char *section, const char *key)
|
||||
return false;
|
||||
}
|
||||
|
||||
return list_remove(sec->entries, entry);
|
||||
ret = list_remove(sec->entries, entry);
|
||||
if (list_length(sec->entries) == 0) {
|
||||
OSI_TRACE_DEBUG("%s remove section name:%s",__func__, section);
|
||||
ret &= config_remove_section(config, section);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
const config_section_node_t *config_section_begin(const config_t *config)
|
||||
|
@ -22,6 +22,10 @@ list_t *list_new(list_free_cb callback);
|
||||
|
||||
|
||||
list_node_t *list_free_node(list_t *list, list_node_t *node);
|
||||
|
||||
// similar with list_free_node, this function doesn't free the node data
|
||||
list_node_t *list_delete_node(list_t *list, list_node_t *node);
|
||||
|
||||
// Frees the list. This function accepts NULL as an argument, in which case it
|
||||
// behaves like a no-op.
|
||||
void list_free(list_t *list);
|
||||
@ -75,6 +79,9 @@ bool list_append(list_t *list, void *data);
|
||||
|
||||
bool list_remove(list_t *list, void *data);
|
||||
|
||||
// similar with list_remove, but do not free the node data
|
||||
bool list_delete(list_t *list, void *data);
|
||||
|
||||
// Removes all elements in the list. Calling this function will return the list to the
|
||||
// same state it was in after |list_new|. |list| may not be NULL.
|
||||
void list_clear(list_t *list);
|
||||
|
@ -186,6 +186,36 @@ bool list_remove(list_t *list, void *data)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool list_delete(list_t *list, void *data)
|
||||
{
|
||||
assert(list != NULL);
|
||||
assert(data != NULL);
|
||||
|
||||
if (list_is_empty(list)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (list->head->data == data) {
|
||||
list_node_t *next = list_delete_node(list, list->head);
|
||||
if (list->tail == list->head) {
|
||||
list->tail = next;
|
||||
}
|
||||
list->head = next;
|
||||
return true;
|
||||
}
|
||||
|
||||
for (list_node_t *prev = list->head, *node = list->head->next; node; prev = node, node = node->next)
|
||||
if (node->data == data) {
|
||||
prev->next = list_delete_node(list, node);
|
||||
if (list->tail == node) {
|
||||
list->tail = prev;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void list_clear(list_t *list)
|
||||
{
|
||||
assert(list != NULL);
|
||||
@ -251,3 +281,17 @@ list_node_t *list_free_node(list_t *list, list_node_t *node)
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
// remove the element from list but do not free the node data
|
||||
list_node_t *list_delete_node(list_t *list, list_node_t *node)
|
||||
{
|
||||
assert(list != NULL);
|
||||
assert(node != NULL);
|
||||
|
||||
list_node_t *next = node->next;
|
||||
|
||||
osi_free(node);
|
||||
--list->length;
|
||||
|
||||
return next;
|
||||
}
|
@ -9,11 +9,11 @@ COMPONENT_ADD_INCLUDEDIRS := include
|
||||
|
||||
LIBS := btdm_app
|
||||
|
||||
COMPONENT_ADD_LDFLAGS := -lbt -L $(COMPONENT_PATH)/controller/lib \
|
||||
COMPONENT_ADD_LDFLAGS := -lbt -L $(COMPONENT_PATH)/controller/lib/esp32 \
|
||||
$(addprefix -l,$(LIBS))
|
||||
|
||||
# re-link program if BT binary libs change
|
||||
COMPONENT_ADD_LINKER_DEPS := $(patsubst %,$(COMPONENT_PATH)/controller/lib/lib%.a,$(LIBS))
|
||||
COMPONENT_ADD_LINKER_DEPS := $(patsubst %,$(COMPONENT_PATH)/controller/lib/esp32/lib%.a,$(LIBS))
|
||||
|
||||
COMPONENT_SUBMODULES += controller/lib
|
||||
|
||||
@ -137,6 +137,7 @@ endif
|
||||
|
||||
ifdef CONFIG_BLE_MESH
|
||||
COMPONENT_ADD_INCLUDEDIRS += esp_ble_mesh/mesh_common/include \
|
||||
esp_ble_mesh/mesh_common/tinycrypt/include \
|
||||
esp_ble_mesh/mesh_core \
|
||||
esp_ble_mesh/mesh_core/include \
|
||||
esp_ble_mesh/mesh_core/storage \
|
||||
@ -149,9 +150,11 @@ COMPONENT_ADD_INCLUDEDIRS += esp_ble_mesh/mesh_common/include \
|
||||
esp_ble_mesh/api
|
||||
|
||||
COMPONENT_SRCDIRS += esp_ble_mesh/mesh_common \
|
||||
esp_ble_mesh/mesh_common/tinycrypt/src \
|
||||
esp_ble_mesh/mesh_core \
|
||||
esp_ble_mesh/mesh_core/storage \
|
||||
esp_ble_mesh/btc \
|
||||
esp_ble_mesh/mesh_models/common \
|
||||
esp_ble_mesh/mesh_models/client \
|
||||
esp_ble_mesh/mesh_models/server \
|
||||
esp_ble_mesh/api/core \
|
||||
@ -197,7 +200,8 @@ COMPONENT_SRCDIRS += host/nimble/nimble/nimble/host/src
|
||||
host/nimble/nimble/nimble/host/util/src \
|
||||
host/nimble/nimble/nimble/host/store/ram/src \
|
||||
host/nimble/nimble/nimble/host/store/config/src \
|
||||
host/nimble/esp-hci/src
|
||||
host/nimble/esp-hci/src \
|
||||
host/nimble/port/src
|
||||
|
||||
ifndef CONFIG_BT_NIMBLE_CRYPTO_STACK_MBEDTLS
|
||||
COMPONENT_SRCDIRS += host/nimble/nimble/ext/tinycrypt/src
|
||||
|
@ -79,14 +79,6 @@
|
||||
#define BTDM_MIN_SLEEP_DURATION (12) // threshold of interval in slots to allow to fall into modem sleep
|
||||
#define BTDM_MODEM_WAKE_UP_DELAY (4) // delay in slots of modem wake up procedure, including re-enable PHY/RF
|
||||
|
||||
#ifdef CONFIG_PM_ENABLE
|
||||
#ifndef CONFIG_BTDM_LPCLK_SEL_MAIN_XTAL
|
||||
#define BTDM_ALLOW_LIGHT_SLEEP 1
|
||||
#else
|
||||
#define BTDM_ALLOW_LIGHT_SLEEP 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define BT_DEBUG(...)
|
||||
#define BT_API_CALL_CHECK(info, api_call, ret) \
|
||||
do{\
|
||||
@ -98,7 +90,7 @@ do{\
|
||||
} while(0)
|
||||
|
||||
#define OSI_FUNCS_TIME_BLOCKING 0xffffffff
|
||||
#define OSI_VERSION 0x00010001
|
||||
#define OSI_VERSION 0x00010002
|
||||
#define OSI_MAGIC_VALUE 0xFADEBEAD
|
||||
|
||||
/* SPIRAM Configuration */
|
||||
@ -175,14 +167,25 @@ struct osi_funcs_t {
|
||||
void (* _btdm_sleep_exit_phase1)(void); /* called from ISR */
|
||||
void (* _btdm_sleep_exit_phase2)(void); /* called from ISR */
|
||||
void (* _btdm_sleep_exit_phase3)(void); /* called from task */
|
||||
bool (* _coex_bt_wakeup_request)(void);
|
||||
void (* _coex_bt_wakeup_request_end)(void);
|
||||
int (* _coex_bt_request)(uint32_t event, uint32_t latency, uint32_t duration);
|
||||
int (* _coex_bt_release)(uint32_t event);
|
||||
int (* _coex_register_bt_cb)(coex_func_cb_t cb);
|
||||
uint32_t (* _coex_bb_reset_lock)(void);
|
||||
void (* _coex_bb_reset_unlock)(uint32_t restore);
|
||||
int (* _coex_schm_register_btdm_callback)(void *callback);
|
||||
void (* _coex_schm_status_bit_clear)(uint32_t type, uint32_t status);
|
||||
void (* _coex_schm_status_bit_set)(uint32_t type, uint32_t status);
|
||||
uint32_t (* _coex_schm_interval_get)(void);
|
||||
uint8_t (* _coex_schm_curr_period_get)(void);
|
||||
void *(* _coex_schm_curr_phase_get)(void);
|
||||
int (* _coex_wifi_channel_get)(uint8_t *primary, uint8_t *secondary);
|
||||
int (* _coex_register_wifi_channel_change_callback)(void *cb);
|
||||
uint32_t _magic;
|
||||
};
|
||||
|
||||
typedef void (*workitem_handler_t)(void* arg);
|
||||
|
||||
/* External functions or values
|
||||
************************************************************************
|
||||
@ -199,13 +202,14 @@ extern void btdm_controller_disable(void);
|
||||
extern uint8_t btdm_controller_get_mode(void);
|
||||
extern const char *btdm_controller_get_compile_version(void);
|
||||
extern void btdm_rf_bb_init_phase2(void); // shall be called after PHY/RF is enabled
|
||||
extern int btdm_dispatch_work_to_controller(workitem_handler_t callback, void *arg, bool blocking);
|
||||
/* Sleep */
|
||||
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(bool request_lock);
|
||||
extern void btdm_wakeup_request_end(void);
|
||||
extern void btdm_wakeup_request(void);
|
||||
extern void btdm_in_wakeup_requesting_set(bool in_wakeup_requesting);
|
||||
/* Low Power Clock */
|
||||
extern bool btdm_lpclk_select_src(uint32_t sel);
|
||||
extern bool btdm_lpclk_set_div(uint32_t div);
|
||||
@ -221,12 +225,19 @@ extern int bredr_txpwr_get(int *min_power_level, int *max_power_level);
|
||||
extern void bredr_sco_datapath_set(uint8_t data_path);
|
||||
extern void btdm_controller_scan_duplicate_list_clear(void);
|
||||
/* Coexistence */
|
||||
extern int coex_bt_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration);
|
||||
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 int coex_bt_request(uint32_t event, uint32_t latency, uint32_t duration);
|
||||
extern int coex_bt_release(uint32_t event);
|
||||
extern int coex_register_bt_cb(coex_func_cb_t cb);
|
||||
extern uint32_t coex_bb_reset_lock(void);
|
||||
extern void coex_bb_reset_unlock(uint32_t restore);
|
||||
extern int coex_schm_register_btdm_callback(void *callback);
|
||||
extern void coex_schm_status_bit_clear(uint32_t type, uint32_t status);
|
||||
extern void coex_schm_status_bit_set(uint32_t type, uint32_t status);
|
||||
extern uint32_t coex_schm_interval_get(void);
|
||||
extern uint8_t coex_schm_curr_period_get(void);
|
||||
extern void * coex_schm_curr_phase_get(void);
|
||||
extern int coex_wifi_channel_get(uint8_t *primary, uint8_t *secondary);
|
||||
extern int coex_register_wifi_channel_change_callback(void *cb);
|
||||
|
||||
extern char _bss_start_btdm;
|
||||
extern char _bss_end_btdm;
|
||||
@ -288,8 +299,22 @@ static uint32_t IRAM_ATTR btdm_us_2_lpcycles(uint32_t us);
|
||||
static bool IRAM_ATTR btdm_sleep_check_duration(uint32_t *slot_cnt);
|
||||
static void btdm_sleep_enter_phase1_wrapper(uint32_t lpcycles);
|
||||
static void btdm_sleep_enter_phase2_wrapper(void);
|
||||
static void IRAM_ATTR btdm_sleep_exit_phase1_wrapper(void);
|
||||
static void btdm_sleep_exit_phase3_wrapper(void);
|
||||
static bool coex_bt_wakeup_request(void);
|
||||
static void coex_bt_wakeup_request_end(void);
|
||||
static int coex_bt_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration);
|
||||
static int coex_bt_release_wrapper(uint32_t event);
|
||||
static int coex_register_bt_cb_wrapper(coex_func_cb_t cb);
|
||||
static uint32_t coex_bb_reset_lock_wrapper(void);
|
||||
static void coex_bb_reset_unlock_wrapper(uint32_t restore);
|
||||
static int coex_schm_register_btdm_callback_wrapper(void *callback);
|
||||
static void coex_schm_status_bit_clear_wrapper(uint32_t type, uint32_t status);
|
||||
static void coex_schm_status_bit_set_wrapper(uint32_t type, uint32_t status);
|
||||
static uint32_t coex_schm_interval_get_wrapper(void);
|
||||
static uint8_t coex_schm_curr_period_get_wrapper(void);
|
||||
static void * coex_schm_curr_phase_get_wrapper(void);
|
||||
static int coex_wifi_channel_get_wrapper(uint8_t *primary, uint8_t *secondary);
|
||||
static int coex_register_wifi_channel_change_callback_wrapper(void *cb);
|
||||
|
||||
/* Local variable definition
|
||||
***************************************************************************
|
||||
@ -334,14 +359,24 @@ static const struct osi_funcs_t osi_funcs_ro = {
|
||||
._btdm_sleep_check_duration = btdm_sleep_check_duration,
|
||||
._btdm_sleep_enter_phase1 = btdm_sleep_enter_phase1_wrapper,
|
||||
._btdm_sleep_enter_phase2 = btdm_sleep_enter_phase2_wrapper,
|
||||
._btdm_sleep_exit_phase1 = btdm_sleep_exit_phase1_wrapper,
|
||||
._btdm_sleep_exit_phase1 = NULL,
|
||||
._btdm_sleep_exit_phase2 = NULL,
|
||||
._btdm_sleep_exit_phase3 = btdm_sleep_exit_phase3_wrapper,
|
||||
._coex_bt_wakeup_request = coex_bt_wakeup_request,
|
||||
._coex_bt_wakeup_request_end = coex_bt_wakeup_request_end,
|
||||
._coex_bt_request = coex_bt_request_wrapper,
|
||||
._coex_bt_release = coex_bt_release_wrapper,
|
||||
._coex_register_bt_cb = coex_register_bt_cb_wrapper,
|
||||
._coex_bb_reset_lock = coex_bb_reset_lock_wrapper,
|
||||
._coex_bb_reset_unlock = coex_bb_reset_unlock_wrapper,
|
||||
._coex_schm_register_btdm_callback = coex_schm_register_btdm_callback_wrapper,
|
||||
._coex_schm_status_bit_clear = coex_schm_status_bit_clear_wrapper,
|
||||
._coex_schm_status_bit_set = coex_schm_status_bit_set_wrapper,
|
||||
._coex_schm_interval_get = coex_schm_interval_get_wrapper,
|
||||
._coex_schm_curr_period_get = coex_schm_curr_period_get_wrapper,
|
||||
._coex_schm_curr_phase_get = coex_schm_curr_phase_get_wrapper,
|
||||
._coex_wifi_channel_get = coex_wifi_channel_get_wrapper,
|
||||
._coex_register_wifi_channel_change_callback = coex_register_wifi_channel_change_callback_wrapper,
|
||||
._magic = OSI_MAGIC_VALUE,
|
||||
};
|
||||
|
||||
@ -384,16 +419,22 @@ static DRAM_ATTR portMUX_TYPE global_int_mux = portMUX_INITIALIZER_UNLOCKED;
|
||||
static DRAM_ATTR uint32_t btdm_lpcycle_us = 0;
|
||||
static DRAM_ATTR uint8_t btdm_lpcycle_us_frac = 0; // number of fractional bit for btdm_lpcycle_us
|
||||
|
||||
#if CONFIG_BTDM_MODEM_SLEEP_MODE_ORIG
|
||||
// used low power clock
|
||||
static DRAM_ATTR uint8_t btdm_lpclk_sel;
|
||||
#endif /* #ifdef CONFIG_BTDM_MODEM_SLEEP_MODE_ORIG */
|
||||
|
||||
static DRAM_ATTR QueueHandle_t s_wakeup_req_sem = NULL;
|
||||
#ifdef CONFIG_PM_ENABLE
|
||||
static DRAM_ATTR esp_timer_handle_t s_btdm_slp_tmr;
|
||||
static DRAM_ATTR esp_pm_lock_handle_t s_pm_lock;
|
||||
static DRAM_ATTR QueueHandle_t s_pm_lock_sem = NULL;
|
||||
#if !BTDM_ALLOW_LIGHT_SLEEP
|
||||
static bool s_pm_lock_acquired = true;
|
||||
static DRAM_ATTR bool s_btdm_allow_light_sleep;
|
||||
// pm_lock to prevent light sleep when using main crystal as Bluetooth low power clock
|
||||
static DRAM_ATTR esp_pm_lock_handle_t s_light_sleep_pm_lock;
|
||||
#endif /* #if !BTDM_ALLOW_LIGHT_SLEEP */
|
||||
static void btdm_slp_tmr_callback(void *arg);
|
||||
#endif
|
||||
#endif /* #ifdef CONFIG_PM_ENABLE */
|
||||
|
||||
|
||||
static inline void btdm_check_and_init_bb(void)
|
||||
{
|
||||
@ -848,8 +889,10 @@ static void btdm_sleep_enter_phase2_wrapper(void)
|
||||
esp_modem_sleep_enter(MODEM_BLE_MODULE);
|
||||
esp_modem_sleep_enter(MODEM_CLASSIC_BT_MODULE);
|
||||
#ifdef CONFIG_PM_ENABLE
|
||||
esp_pm_lock_release(s_pm_lock);
|
||||
semphr_give_wrapper(s_pm_lock_sem);
|
||||
if (s_pm_lock_acquired) {
|
||||
esp_pm_lock_release(s_pm_lock);
|
||||
s_pm_lock_acquired = false;
|
||||
}
|
||||
#endif
|
||||
} else if (btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_EVED) {
|
||||
esp_modem_sleep_enter(MODEM_BLE_MODULE);
|
||||
@ -858,17 +901,15 @@ static void btdm_sleep_enter_phase2_wrapper(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void IRAM_ATTR btdm_sleep_exit_phase1_wrapper(void)
|
||||
static void btdm_sleep_exit_phase3_wrapper(void)
|
||||
{
|
||||
#ifdef CONFIG_PM_ENABLE
|
||||
if (semphr_take_from_isr_wrapper(s_pm_lock_sem, NULL) == pdTRUE) {
|
||||
if (!s_pm_lock_acquired) {
|
||||
s_pm_lock_acquired = true;
|
||||
esp_pm_lock_acquire(s_pm_lock);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void btdm_sleep_exit_phase3_wrapper(void)
|
||||
{
|
||||
if (btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_ORIG) {
|
||||
esp_modem_sleep_exit(MODEM_BLE_MODULE);
|
||||
esp_modem_sleep_exit(MODEM_CLASSIC_BT_MODULE);
|
||||
@ -884,14 +925,224 @@ static void btdm_sleep_exit_phase3_wrapper(void)
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM_ENABLE
|
||||
static void IRAM_ATTR btdm_slp_tmr_callback(void *arg)
|
||||
static void btdm_slp_tmr_customer_callback(void * arg)
|
||||
{
|
||||
if (semphr_take_wrapper(s_pm_lock_sem, 0) == pdTRUE) {
|
||||
(void)(arg);
|
||||
|
||||
if (!s_pm_lock_acquired) {
|
||||
s_pm_lock_acquired = true;
|
||||
esp_pm_lock_acquire(s_pm_lock);
|
||||
}
|
||||
}
|
||||
|
||||
static void IRAM_ATTR btdm_slp_tmr_callback(void *arg)
|
||||
{
|
||||
(void)(arg);
|
||||
btdm_dispatch_work_to_controller(btdm_slp_tmr_customer_callback, NULL, true);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define BTDM_ASYNC_WAKEUP_REQ_HCI 0
|
||||
#define BTDM_ASYNC_WAKEUP_REQ_COEX 1
|
||||
#define BTDM_ASYNC_WAKEUP_REQ_CTRL_DISA 2
|
||||
#define BTDM_ASYNC_WAKEUP_REQMAX 3
|
||||
|
||||
static void btdm_wakeup_request_callback(void * arg)
|
||||
{
|
||||
(void)(arg);
|
||||
|
||||
#if CONFIG_PM_ENABLE
|
||||
if (!s_pm_lock_acquired) {
|
||||
s_pm_lock_acquired = true;
|
||||
esp_pm_lock_acquire(s_pm_lock);
|
||||
}
|
||||
esp_timer_stop(s_btdm_slp_tmr);
|
||||
#endif
|
||||
btdm_wakeup_request();
|
||||
|
||||
semphr_give_wrapper(s_wakeup_req_sem);
|
||||
}
|
||||
|
||||
static bool async_wakeup_request(int event)
|
||||
{
|
||||
bool do_wakeup_request = false;
|
||||
|
||||
switch (event) {
|
||||
case BTDM_ASYNC_WAKEUP_REQ_HCI:
|
||||
btdm_in_wakeup_requesting_set(true);
|
||||
// NO break
|
||||
case BTDM_ASYNC_WAKEUP_REQ_CTRL_DISA:
|
||||
if (!btdm_power_state_active()) {
|
||||
do_wakeup_request = true;
|
||||
|
||||
btdm_dispatch_work_to_controller(btdm_wakeup_request_callback, NULL, true);
|
||||
semphr_take_wrapper(s_wakeup_req_sem, OSI_FUNCS_TIME_BLOCKING);
|
||||
}
|
||||
break;
|
||||
case BTDM_ASYNC_WAKEUP_REQ_COEX:
|
||||
if (!btdm_power_state_active()) {
|
||||
do_wakeup_request = true;
|
||||
#if CONFIG_PM_ENABLE
|
||||
if (!s_pm_lock_acquired) {
|
||||
s_pm_lock_acquired = true;
|
||||
esp_pm_lock_acquire(s_pm_lock);
|
||||
}
|
||||
esp_timer_stop(s_btdm_slp_tmr);
|
||||
#endif
|
||||
btdm_wakeup_request();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return do_wakeup_request;
|
||||
}
|
||||
|
||||
static void async_wakeup_request_end(int event)
|
||||
{
|
||||
bool request_lock = false;
|
||||
switch (event) {
|
||||
case BTDM_ASYNC_WAKEUP_REQ_HCI:
|
||||
request_lock = true;
|
||||
break;
|
||||
case BTDM_ASYNC_WAKEUP_REQ_COEX:
|
||||
case BTDM_ASYNC_WAKEUP_REQ_CTRL_DISA:
|
||||
request_lock = false;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (request_lock) {
|
||||
btdm_in_wakeup_requesting_set(false);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static bool coex_bt_wakeup_request(void)
|
||||
{
|
||||
return async_wakeup_request(BTDM_ASYNC_WAKEUP_REQ_COEX);
|
||||
}
|
||||
|
||||
static void coex_bt_wakeup_request_end(void)
|
||||
{
|
||||
async_wakeup_request_end(BTDM_ASYNC_WAKEUP_REQ_COEX);
|
||||
return;
|
||||
}
|
||||
|
||||
static int IRAM_ATTR coex_bt_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration)
|
||||
{
|
||||
#if CONFIG_SW_COEXIST_ENABLE
|
||||
return coex_bt_request(event, latency, duration);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int IRAM_ATTR coex_bt_release_wrapper(uint32_t event)
|
||||
{
|
||||
#if CONFIG_SW_COEXIST_ENABLE
|
||||
return coex_bt_release(event);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int coex_register_bt_cb_wrapper(coex_func_cb_t cb)
|
||||
{
|
||||
#if CONFIG_SW_COEXIST_ENABLE
|
||||
return coex_register_bt_cb(cb);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static uint32_t IRAM_ATTR coex_bb_reset_lock_wrapper(void)
|
||||
{
|
||||
#if CONFIG_SW_COEXIST_ENABLE
|
||||
return coex_bb_reset_lock();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void IRAM_ATTR coex_bb_reset_unlock_wrapper(uint32_t restore)
|
||||
{
|
||||
#if CONFIG_SW_COEXIST_ENABLE
|
||||
coex_bb_reset_unlock(restore);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int coex_schm_register_btdm_callback_wrapper(void *callback)
|
||||
{
|
||||
#if CONFIG_SW_COEXIST_ENABLE
|
||||
return coex_schm_register_btdm_callback(callback);
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void coex_schm_status_bit_clear_wrapper(uint32_t type, uint32_t status)
|
||||
{
|
||||
#if CONFIG_SW_COEXIST_ENABLE
|
||||
coex_schm_status_bit_clear(type, status);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void coex_schm_status_bit_set_wrapper(uint32_t type, uint32_t status)
|
||||
{
|
||||
#if CONFIG_SW_COEXIST_ENABLE
|
||||
coex_schm_status_bit_set(type, status);
|
||||
#endif
|
||||
}
|
||||
|
||||
static uint32_t coex_schm_interval_get_wrapper(void)
|
||||
{
|
||||
#if CONFIG_SW_COEXIST_ENABLE
|
||||
return coex_schm_interval_get();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static uint8_t coex_schm_curr_period_get_wrapper(void)
|
||||
{
|
||||
#if CONFIG_SW_COEXIST_ENABLE
|
||||
return coex_schm_curr_period_get();
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void * coex_schm_curr_phase_get_wrapper(void)
|
||||
{
|
||||
#if CONFIG_SW_COEXIST_ENABLE
|
||||
return coex_schm_curr_phase_get();
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int coex_wifi_channel_get_wrapper(uint8_t *primary, uint8_t *secondary)
|
||||
{
|
||||
#if CONFIG_SW_COEXIST_ENABLE
|
||||
return coex_wifi_channel_get(primary, secondary);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
static int coex_register_wifi_channel_change_callback_wrapper(void *cb)
|
||||
{
|
||||
#if CONFIG_SW_COEXIST_ENABLE
|
||||
return coex_register_wifi_channel_change_callback(cb);
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool esp_vhci_host_check_send_available(void)
|
||||
{
|
||||
return API_vhci_host_check_send_available();
|
||||
@ -899,24 +1150,11 @@ 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)) {
|
||||
esp_pm_lock_acquire(s_pm_lock);
|
||||
}
|
||||
esp_timer_stop(s_btdm_slp_tmr);
|
||||
#endif
|
||||
do_wakeup_request = true;
|
||||
btdm_wakeup_request(true);
|
||||
}
|
||||
async_wakeup_request(BTDM_ASYNC_WAKEUP_REQ_HCI);
|
||||
|
||||
API_vhci_host_send_packet(data, len);
|
||||
|
||||
if (do_wakeup_request) {
|
||||
btdm_wakeup_request_end();
|
||||
}
|
||||
async_wakeup_request_end(BTDM_ASYNC_WAKEUP_REQ_HCI);
|
||||
}
|
||||
|
||||
esp_err_t esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callback)
|
||||
@ -975,7 +1213,7 @@ static esp_err_t try_heap_caps_add_region(intptr_t start, intptr_t end)
|
||||
esp_err_t esp_bt_controller_mem_release(esp_bt_mode_t mode)
|
||||
{
|
||||
bool update = true;
|
||||
intptr_t mem_start, mem_end;
|
||||
intptr_t mem_start=(intptr_t) NULL, mem_end=(intptr_t) NULL;
|
||||
|
||||
if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_IDLE) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
@ -1085,6 +1323,11 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
|
||||
esp_err_t err;
|
||||
uint32_t btdm_cfg_mask = 0;
|
||||
|
||||
//if all the bt available memory was already released, cannot initialize bluetooth controller
|
||||
if (btdm_dram_available_region[0].mode == ESP_BT_MODE_IDLE) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
osi_funcs_p = (struct osi_funcs_t *)malloc_internal_wrapper(sizeof(struct osi_funcs_t));
|
||||
if (osi_funcs_p == NULL) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
@ -1099,11 +1342,6 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
//if all the bt available memory was already released, cannot initialize bluetooth controller
|
||||
if (btdm_dram_available_region[0].mode == ESP_BT_MODE_IDLE) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
if (cfg == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
@ -1133,12 +1371,73 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
|
||||
memset(btdm_queue_table, 0, sizeof(btdm_queue_item_t) * BTDM_MAX_QUEUE_NUM);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_PM_ENABLE
|
||||
#if !BTDM_ALLOW_LIGHT_SLEEP
|
||||
if ((err = esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "btLS", &s_light_sleep_pm_lock)) != ESP_OK) {
|
||||
s_wakeup_req_sem = semphr_create_wrapper(1, 0);
|
||||
if (s_wakeup_req_sem == NULL) {
|
||||
err = ESP_ERR_NO_MEM;
|
||||
goto error;
|
||||
}
|
||||
#endif /* #if !BTDM_ALLOW_LIGHT_SLEEP */
|
||||
|
||||
btdm_controller_mem_init();
|
||||
|
||||
periph_module_enable(PERIPH_BT_MODULE);
|
||||
|
||||
#ifdef CONFIG_PM_ENABLE
|
||||
s_btdm_allow_light_sleep = false;
|
||||
#endif
|
||||
|
||||
// set default sleep clock cycle and its fractional bits
|
||||
btdm_lpcycle_us_frac = RTC_CLK_CAL_FRACT;
|
||||
btdm_lpcycle_us = 2 << (btdm_lpcycle_us_frac);
|
||||
|
||||
#if CONFIG_BTDM_MODEM_SLEEP_MODE_ORIG
|
||||
|
||||
btdm_lpclk_sel = BTDM_LPCLK_SEL_XTAL; // set default value
|
||||
#if CONFIG_BTDM_LPCLK_SEL_EXT_32K_XTAL
|
||||
// check whether or not EXT_CRYS is working
|
||||
if (rtc_clk_slow_freq_get() == RTC_SLOW_FREQ_32K_XTAL) {
|
||||
btdm_lpclk_sel = BTDM_LPCLK_SEL_XTAL32K; // set default value
|
||||
#ifdef CONFIG_PM_ENABLE
|
||||
s_btdm_allow_light_sleep = true;
|
||||
#endif
|
||||
} else {
|
||||
ESP_LOGW(BTDM_LOG_TAG, "32.768kHz XTAL not detected, fall back to main XTAL as Bluetooth sleep clock\n"
|
||||
"light sleep mode will not be able to apply when bluetooth is enabled");
|
||||
btdm_lpclk_sel = BTDM_LPCLK_SEL_XTAL; // set default value
|
||||
}
|
||||
#else
|
||||
btdm_lpclk_sel = BTDM_LPCLK_SEL_XTAL; // set default value
|
||||
#endif
|
||||
|
||||
bool select_src_ret, set_div_ret;
|
||||
if (btdm_lpclk_sel == BTDM_LPCLK_SEL_XTAL) {
|
||||
select_src_ret = btdm_lpclk_select_src(BTDM_LPCLK_SEL_XTAL);
|
||||
set_div_ret = btdm_lpclk_set_div(rtc_clk_xtal_freq_get() * 2 - 1);
|
||||
assert(select_src_ret && set_div_ret);
|
||||
btdm_lpcycle_us_frac = RTC_CLK_CAL_FRACT;
|
||||
btdm_lpcycle_us = 2 << (btdm_lpcycle_us_frac);
|
||||
} else { // btdm_lpclk_sel == BTDM_LPCLK_SEL_XTAL32K
|
||||
select_src_ret = btdm_lpclk_select_src(BTDM_LPCLK_SEL_XTAL32K);
|
||||
set_div_ret = btdm_lpclk_set_div(0);
|
||||
assert(select_src_ret && set_div_ret);
|
||||
btdm_lpcycle_us_frac = RTC_CLK_CAL_FRACT;
|
||||
btdm_lpcycle_us = (RTC_CLK_CAL_FRACT > 15) ? (1000000 << (RTC_CLK_CAL_FRACT - 15)) :
|
||||
(1000000 >> (15 - RTC_CLK_CAL_FRACT));
|
||||
assert(btdm_lpcycle_us != 0);
|
||||
}
|
||||
btdm_controller_set_sleep_mode(BTDM_MODEM_SLEEP_MODE_ORIG);
|
||||
|
||||
#elif CONFIG_BTDM_MODEM_SLEEP_MODE_EVED
|
||||
btdm_controller_set_sleep_mode(BTDM_MODEM_SLEEP_MODE_EVED);
|
||||
#else
|
||||
btdm_controller_set_sleep_mode(BTDM_MODEM_SLEEP_MODE_NONE);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_PM_ENABLE
|
||||
if (!s_btdm_allow_light_sleep) {
|
||||
if ((err = esp_pm_lock_create(ESP_PM_NO_LIGHT_SLEEP, 0, "btLS", &s_light_sleep_pm_lock)) != ESP_OK) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
if ((err = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "bt", &s_pm_lock)) != ESP_OK) {
|
||||
goto error;
|
||||
}
|
||||
@ -1151,42 +1450,7 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
|
||||
goto error;
|
||||
}
|
||||
|
||||
s_pm_lock_sem = semphr_create_wrapper(1, 0);
|
||||
if (s_pm_lock_sem == NULL) {
|
||||
err = ESP_ERR_NO_MEM;
|
||||
goto error;
|
||||
}
|
||||
#endif
|
||||
|
||||
btdm_controller_mem_init();
|
||||
|
||||
periph_module_enable(PERIPH_BT_MODULE);
|
||||
|
||||
btdm_lpcycle_us_frac = RTC_CLK_CAL_FRACT;
|
||||
btdm_lpcycle_us = 32 << btdm_lpcycle_us_frac;
|
||||
#if CONFIG_BTDM_MODEM_SLEEP_MODE_ORIG
|
||||
bool select_src_ret = false;
|
||||
bool set_div_ret = false;
|
||||
#if CONFIG_BTDM_LPCLK_SEL_MAIN_XTAL
|
||||
select_src_ret = btdm_lpclk_select_src(BTDM_LPCLK_SEL_XTAL);
|
||||
set_div_ret = btdm_lpclk_set_div(rtc_clk_xtal_freq_get() * 2 - 1);
|
||||
assert(select_src_ret && set_div_ret);
|
||||
btdm_lpcycle_us_frac = RTC_CLK_CAL_FRACT;
|
||||
btdm_lpcycle_us = 2 << (btdm_lpcycle_us_frac);
|
||||
#elif CONFIG_BTDM_LPCLK_SEL_EXT_32K_XTAL
|
||||
select_src_ret = btdm_lpclk_select_src(BTDM_LPCLK_SEL_XTAL32K);
|
||||
set_div_ret = btdm_lpclk_set_div(0);
|
||||
assert(select_src_ret && set_div_ret);
|
||||
btdm_lpcycle_us_frac = RTC_CLK_CAL_FRACT;
|
||||
btdm_lpcycle_us = (RTC_CLK_CAL_FRACT > 15) ? (1000000 << (RTC_CLK_CAL_FRACT - 15)) :
|
||||
(1000000 >> (15 - RTC_CLK_CAL_FRACT));
|
||||
assert(btdm_lpcycle_us != 0);
|
||||
#endif // CONFIG_BTDM_LPCLK_SEL_XX
|
||||
btdm_controller_set_sleep_mode(BTDM_MODEM_SLEEP_MODE_ORIG);
|
||||
#elif CONFIG_BTDM_MODEM_SLEEP_MODE_EVED
|
||||
btdm_controller_set_sleep_mode(BTDM_MODEM_SLEEP_MODE_EVED);
|
||||
#else
|
||||
btdm_controller_set_sleep_mode(BTDM_MODEM_SLEEP_MODE_NONE);
|
||||
s_pm_lock_acquired = true;
|
||||
#endif
|
||||
|
||||
btdm_cfg_mask = btdm_config_mask_load();
|
||||
@ -1196,24 +1460,18 @@ 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;
|
||||
|
||||
error:
|
||||
#ifdef CONFIG_PM_ENABLE
|
||||
#if !BTDM_ALLOW_LIGHT_SLEEP
|
||||
if (s_light_sleep_pm_lock != NULL) {
|
||||
esp_pm_lock_delete(s_light_sleep_pm_lock);
|
||||
s_light_sleep_pm_lock = NULL;
|
||||
if (!s_btdm_allow_light_sleep) {
|
||||
if (s_light_sleep_pm_lock != NULL) {
|
||||
esp_pm_lock_delete(s_light_sleep_pm_lock);
|
||||
s_light_sleep_pm_lock = NULL;
|
||||
}
|
||||
}
|
||||
#endif /* #if !BTDM_ALLOW_LIGHT_SLEEP */
|
||||
if (s_pm_lock != NULL) {
|
||||
esp_pm_lock_delete(s_pm_lock);
|
||||
s_pm_lock = NULL;
|
||||
@ -1222,11 +1480,11 @@ error:
|
||||
esp_timer_delete(s_btdm_slp_tmr);
|
||||
s_btdm_slp_tmr = NULL;
|
||||
}
|
||||
if (s_pm_lock_sem) {
|
||||
semphr_delete_wrapper(s_pm_lock_sem);
|
||||
s_pm_lock_sem = NULL;
|
||||
}
|
||||
#endif
|
||||
if (s_wakeup_req_sem) {
|
||||
semphr_delete_wrapper(s_wakeup_req_sem);
|
||||
s_wakeup_req_sem = NULL;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -1241,18 +1499,17 @@ esp_err_t esp_bt_controller_deinit(void)
|
||||
periph_module_disable(PERIPH_BT_MODULE);
|
||||
|
||||
#ifdef CONFIG_PM_ENABLE
|
||||
#if !BTDM_ALLOW_LIGHT_SLEEP
|
||||
esp_pm_lock_delete(s_light_sleep_pm_lock);
|
||||
s_light_sleep_pm_lock = NULL;
|
||||
#endif /* #if !BTDM_ALLOW_LIGHT_SLEEP */
|
||||
esp_pm_lock_delete(s_pm_lock);
|
||||
s_pm_lock = NULL;
|
||||
if (!s_btdm_allow_light_sleep) {
|
||||
esp_pm_lock_delete(s_light_sleep_pm_lock);
|
||||
s_light_sleep_pm_lock = NULL;
|
||||
}
|
||||
esp_timer_stop(s_btdm_slp_tmr);
|
||||
esp_timer_delete(s_btdm_slp_tmr);
|
||||
s_btdm_slp_tmr = NULL;
|
||||
semphr_delete_wrapper(s_pm_lock_sem);
|
||||
s_pm_lock_sem = NULL;
|
||||
s_pm_lock_acquired = false;
|
||||
#endif
|
||||
semphr_delete_wrapper(s_wakeup_req_sem);
|
||||
s_wakeup_req_sem = NULL;
|
||||
|
||||
#if CONFIG_SPIRAM_USE_MALLOC
|
||||
vSemaphoreDelete(btdm_queue_table_mux);
|
||||
@ -1271,6 +1528,19 @@ esp_err_t esp_bt_controller_deinit(void)
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void bt_shutdown(void)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
ESP_LOGD(BTDM_LOG_TAG, "stop Bluetooth");
|
||||
|
||||
ret = esp_bt_controller_disable();
|
||||
if (ESP_OK != ret) {
|
||||
ESP_LOGW(BTDM_LOG_TAG, "controller disable ret=%d", ret);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
|
||||
{
|
||||
int ret;
|
||||
@ -1285,9 +1555,9 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM_ENABLE
|
||||
#if !BTDM_ALLOW_LIGHT_SLEEP
|
||||
esp_pm_lock_acquire(s_light_sleep_pm_lock);
|
||||
#endif /* #if !BTDM_ALLOW_LIGHT_SLEEP */
|
||||
if (!s_btdm_allow_light_sleep) {
|
||||
esp_pm_lock_acquire(s_light_sleep_pm_lock);
|
||||
}
|
||||
esp_pm_lock_acquire(s_pm_lock);
|
||||
#endif
|
||||
|
||||
@ -1325,15 +1595,19 @@ esp_err_t esp_bt_controller_enable(esp_bt_mode_t mode)
|
||||
}
|
||||
esp_phy_rf_deinit(PHY_BT_MODULE);
|
||||
#ifdef CONFIG_PM_ENABLE
|
||||
#if !BTDM_ALLOW_LIGHT_SLEEP
|
||||
esp_pm_lock_release(s_light_sleep_pm_lock);
|
||||
#endif /* #if !BTDM_ALLOW_LIGHT_SLEEP */
|
||||
if (!s_btdm_allow_light_sleep) {
|
||||
esp_pm_lock_release(s_light_sleep_pm_lock);
|
||||
}
|
||||
esp_pm_lock_release(s_pm_lock);
|
||||
#endif
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_ENABLED;
|
||||
ret = esp_register_shutdown_handler(bt_shutdown);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGW(BTDM_LOG_TAG, "Register shutdown handler failed, ret = 0x%x", ret);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
@ -1347,9 +1621,7 @@ esp_err_t esp_bt_controller_disable(void)
|
||||
// disable modem sleep and wake up from sleep mode
|
||||
if (btdm_controller_get_sleep_mode() == BTDM_MODEM_SLEEP_MODE_ORIG) {
|
||||
btdm_controller_enable_sleep(false);
|
||||
if (!btdm_power_state_active()) {
|
||||
btdm_wakeup_request(false);
|
||||
}
|
||||
async_wakeup_request(BTDM_ASYNC_WAKEUP_REQ_CTRL_DISA);
|
||||
while (!btdm_power_state_active()) {
|
||||
ets_delay_us(1000);
|
||||
}
|
||||
@ -1366,11 +1638,12 @@ esp_err_t esp_bt_controller_disable(void)
|
||||
}
|
||||
esp_phy_rf_deinit(PHY_BT_MODULE);
|
||||
btdm_controller_status = ESP_BT_CONTROLLER_STATUS_INITED;
|
||||
esp_unregister_shutdown_handler(bt_shutdown);
|
||||
|
||||
#ifdef CONFIG_PM_ENABLE
|
||||
#if !BTDM_ALLOW_LIGHT_SLEEP
|
||||
esp_pm_lock_release(s_light_sleep_pm_lock);
|
||||
#endif /* #if !BTDM_ALLOW_LIGHT_SLEEP */
|
||||
if (!s_btdm_allow_light_sleep) {
|
||||
esp_pm_lock_release(s_light_sleep_pm_lock);
|
||||
}
|
||||
esp_pm_lock_release(s_pm_lock);
|
||||
#endif
|
||||
|
||||
@ -1382,7 +1655,6 @@ esp_bt_controller_status_t esp_bt_controller_get_status(void)
|
||||
return btdm_controller_status;
|
||||
}
|
||||
|
||||
|
||||
/* extra functions */
|
||||
esp_err_t esp_ble_tx_power_set(esp_ble_power_type_t power_type, esp_power_level_t power_level)
|
||||
{
|
||||
@ -1469,26 +1741,6 @@ esp_err_t esp_bt_sleep_disable (void)
|
||||
return status;
|
||||
}
|
||||
|
||||
bool esp_bt_controller_is_sleeping(void)
|
||||
{
|
||||
if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_ENABLED ||
|
||||
btdm_controller_get_sleep_mode() != BTDM_MODEM_SLEEP_MODE_ORIG) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !btdm_power_state_active();
|
||||
}
|
||||
|
||||
void esp_bt_controller_wakeup_request(void)
|
||||
{
|
||||
if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_ENABLED ||
|
||||
btdm_controller_get_sleep_mode() != BTDM_MODEM_SLEEP_MODE_ORIG) {
|
||||
return;
|
||||
}
|
||||
|
||||
btdm_wakeup_request(false);
|
||||
}
|
||||
|
||||
esp_err_t esp_bredr_sco_datapath_set(esp_sco_data_path_t data_path)
|
||||
{
|
||||
if (btdm_controller_status != ESP_BT_CONTROLLER_STATUS_ENABLED) {
|
||||
|
Submodule components/bt/controller/lib updated: e9b76dc715...41866ca55b
@ -9,8 +9,8 @@ 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
|
||||
select BTDM_BLE_SCAN_DUPL
|
||||
select BTDM_BLE_MESH_SCAN_DUPL_EN
|
||||
default y
|
||||
help
|
||||
Enable this option to allow using specific duplicate scan filter
|
||||
@ -18,6 +18,102 @@ if BLE_MESH
|
||||
option in the Bluetooth Controller section in menuconfig, which is
|
||||
"Scan Duplicate By Device Address and Advertising Data".
|
||||
|
||||
choice BLE_MESH_MEM_ALLOC_MODE
|
||||
prompt "Memory allocation strategy"
|
||||
default BLE_MESH_MEM_ALLOC_MODE_INTERNAL
|
||||
help
|
||||
Allocation strategy for BLE Mesh stack, essentially provides ability to
|
||||
allocate all required dynamic allocations from,
|
||||
|
||||
- Internal DRAM memory only
|
||||
- External SPIRAM memory only
|
||||
- Either internal or external memory based on default malloc()
|
||||
behavior in ESP-IDF
|
||||
|
||||
Recommended mode here is always internal, since that is most preferred
|
||||
from security perspective. But if application requirement does not allow
|
||||
sufficient free internal memory then alternate mode can be selected.
|
||||
|
||||
config BLE_MESH_MEM_ALLOC_MODE_INTERNAL
|
||||
bool "Internal DRAM"
|
||||
|
||||
config BLE_MESH_MEM_ALLOC_MODE_EXTERNAL
|
||||
bool "External SPIRAM"
|
||||
depends on ESP32_SPIRAM_SUPPORT
|
||||
|
||||
config BLE_MESH_MEM_ALLOC_MODE_DEFAULT
|
||||
bool "Default alloc mode"
|
||||
depends on ESP32_SPIRAM_SUPPORT
|
||||
help
|
||||
Enable this option to use the default memory allocation strategy when
|
||||
external SPIRAM is enabled. See the SPIRAM options for more details.
|
||||
|
||||
endchoice # BLE_MESH_MEM_ALLOC_MODE
|
||||
|
||||
config BLE_MESH_FREERTOS_STATIC_ALLOC
|
||||
bool "Enable FreeRTOS static allocation"
|
||||
depends on FREERTOS_SUPPORT_STATIC_ALLOCATION && ESP32_SPIRAM_SUPPORT
|
||||
default n
|
||||
help
|
||||
Enable this option to use FreeRTOS static allocation APIs for BLE Mesh,
|
||||
which provides the ability to use different dynamic memory (i.e. SPIRAM)
|
||||
for FreeRTOS objects.
|
||||
If this option is disabled, the FreeRTOS static allocation APIs will not
|
||||
be used, and internal DRAM will be allocated for FreeRTOS objects.
|
||||
|
||||
choice BLE_MESH_FREERTOS_STATIC_ALLOC_MODE
|
||||
prompt "Memory allocation for FreeRTOS objects"
|
||||
depends on BLE_MESH_FREERTOS_STATIC_ALLOC
|
||||
help
|
||||
Choose the memory to be used for FreeRTOS objects.
|
||||
|
||||
config BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL
|
||||
bool "External SPIRAM"
|
||||
depends on ESP32_SPIRAM_SUPPORT
|
||||
help
|
||||
If enabled, BLE Mesh allocates dynamic memory from external SPIRAM for
|
||||
FreeRTOS objects, i.e. mutex, queue, and task stack. External SPIRAM
|
||||
can only be used for task stack when SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY
|
||||
is enabled. See the SPIRAM options for more details.
|
||||
|
||||
endchoice # BLE_MESH_FREERTOS_STATIC_ALLOC_MODE
|
||||
|
||||
config BLE_MESH_DEINIT
|
||||
bool "Support de-initialize BLE Mesh stack"
|
||||
default y
|
||||
help
|
||||
If enabled, users can use the function esp_ble_mesh_deinit() to de-initialize
|
||||
the whole BLE Mesh stack.
|
||||
|
||||
menu "BLE Mesh and BLE coexistence support"
|
||||
|
||||
config BLE_MESH_SUPPORT_BLE_ADV
|
||||
bool "Support sending normal BLE advertising packets"
|
||||
default n
|
||||
help
|
||||
When selected, users can send normal BLE advertising packets
|
||||
with specific API.
|
||||
|
||||
if BLE_MESH_SUPPORT_BLE_ADV
|
||||
|
||||
config BLE_MESH_BLE_ADV_BUF_COUNT
|
||||
int "Number of advertising buffers for BLE advertising packets"
|
||||
default 3
|
||||
range 1 255
|
||||
help
|
||||
Number of advertising buffers for BLE packets available.
|
||||
|
||||
endif # BLE_MESH_SUPPORT_BLE_ADV
|
||||
|
||||
config BLE_MESH_SUPPORT_BLE_SCAN
|
||||
bool "Support scanning normal BLE advertising packets"
|
||||
default n
|
||||
help
|
||||
When selected, users can register a callback and receive normal BLE
|
||||
advertising packets in the application layer.
|
||||
|
||||
endmenu # BLE Mesh and BLE coexistence support
|
||||
|
||||
config BLE_MESH_FAST_PROV
|
||||
bool "Enable BLE Mesh Fast Provisioning"
|
||||
select BLE_MESH_NODE
|
||||
@ -49,7 +145,7 @@ if BLE_MESH
|
||||
|
||||
config BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM
|
||||
int "Maximum number of unprovisioned devices that can be added to device queue"
|
||||
default 20
|
||||
default 10
|
||||
range 1 100
|
||||
help
|
||||
This option specifies how many unprovisioned devices can be added to device
|
||||
@ -57,25 +153,14 @@ if BLE_MESH
|
||||
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 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.
|
||||
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"
|
||||
default 20
|
||||
default 10
|
||||
range 1 1000
|
||||
help
|
||||
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
|
||||
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
|
||||
@ -116,12 +201,34 @@ if BLE_MESH
|
||||
|
||||
config BLE_MESH_PROVISIONER_APP_KEY_COUNT
|
||||
int "Maximum number of application keys that can be owned by Provisioner"
|
||||
default 9
|
||||
default 3
|
||||
range 1 4096
|
||||
help
|
||||
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.
|
||||
|
||||
config BLE_MESH_PROVISIONER_RECV_HB
|
||||
bool "Support receiving Heartbeat messages"
|
||||
default n
|
||||
help
|
||||
When this option is enabled, Provisioner can call specific functions to enable
|
||||
or disable receiving Heartbeat messages and notify them to the application layer.
|
||||
|
||||
if BLE_MESH_PROVISIONER_RECV_HB
|
||||
|
||||
config BLE_MESH_PROVISIONER_RECV_HB_FILTER_SIZE
|
||||
int "Maximum number of filter entries for receiving Heartbeat messages"
|
||||
default 3
|
||||
range 1 1000
|
||||
help
|
||||
This option specifies how many heartbeat filter entries Provisioner supports.
|
||||
The heartbeat filter (acceptlist or rejectlist) entries are used to store a
|
||||
list of SRC and DST which can be used to decide if a heartbeat message will
|
||||
be processed and notified to the application layer by Provisioner.
|
||||
Note: The filter is an empty rejectlist by default.
|
||||
|
||||
endif # BLE_MESH_PROVISIONER_RECV_HB
|
||||
|
||||
endif # BLE_MESH_PROVISIONER
|
||||
|
||||
# Virtual option enabled whenever Generic Provisioning layer is needed
|
||||
@ -141,6 +248,19 @@ if BLE_MESH
|
||||
advertising bearer. This option should be enabled if PB-ADV is
|
||||
going to be used during provisioning procedure.
|
||||
|
||||
config BLE_MESH_UNPROVISIONED_BEACON_INTERVAL
|
||||
int "Interval between two consecutive Unprovisioned Device Beacon"
|
||||
depends on BLE_MESH_NODE && BLE_MESH_PB_ADV
|
||||
default 5
|
||||
default 3 if BLE_MESH_FAST_PROV
|
||||
range 1 100
|
||||
help
|
||||
This option specifies the interval of sending two consecutive unprovisioned
|
||||
device beacon, users can use this option to change the frequency of sending
|
||||
unprovisioned device beacon. For example, if the value is 5, it means the
|
||||
unprovisioned device beacon will send every 5 seconds. When the option of
|
||||
BLE_MESH_FAST_PROV is selected, the value is better to be 3 seconds, or less.
|
||||
|
||||
config BLE_MESH_PB_GATT
|
||||
bool "Provisioning support using GATT (PB-GATT)"
|
||||
select BLE_MESH_PROXY
|
||||
@ -168,15 +288,6 @@ if BLE_MESH
|
||||
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_SERVER
|
||||
@ -191,23 +302,28 @@ if BLE_MESH
|
||||
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"
|
||||
depends on BLE_MESH_GATT_PROXY_SERVER
|
||||
default 4
|
||||
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.
|
||||
|
||||
config BLE_MESH_PROXY_FILTER_SIZE
|
||||
int "Maximum number of filter entries per Proxy Client"
|
||||
default 1
|
||||
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
|
||||
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_NET_BUF_POOL_USAGE
|
||||
bool "BLE Mesh net buffer pool usage tracking"
|
||||
bool
|
||||
default y
|
||||
help
|
||||
Enable BLE Mesh net buffer pool tracking. This option is used to introduce another
|
||||
@ -215,16 +331,20 @@ if BLE_MESH
|
||||
devices. Recommend to enable this option as default.
|
||||
|
||||
config BLE_MESH_SETTINGS
|
||||
bool "Store BLE Mesh Node configuration persistently"
|
||||
bool "Store BLE Mesh configuration persistently"
|
||||
default n
|
||||
help
|
||||
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.
|
||||
When selected, the BLE Mesh stack will take care of storing/restoring the BLE
|
||||
Mesh configuration persistently in flash.
|
||||
If the device is a BLE Mesh node, when this option is enabled, the configuration
|
||||
of the device will be stored persistently, including unicast address, NetKey,
|
||||
AppKey, etc.
|
||||
And if the device is a BLE Mesh Provisioner, the information of the device will
|
||||
be stored persistently, including the information of provisioned nodes, NetKey,
|
||||
AppKey, etc.
|
||||
|
||||
if BLE_MESH_SETTINGS
|
||||
|
||||
config BLE_MESH_STORE_TIMEOUT
|
||||
int "Delay (in seconds) before storing anything persistently"
|
||||
range 0 1000000
|
||||
@ -239,7 +359,7 @@ if BLE_MESH
|
||||
config BLE_MESH_SEQ_STORE_RATE
|
||||
int "How often the sequence number gets updated in storage"
|
||||
range 0 1000000
|
||||
default 128
|
||||
default 0
|
||||
help
|
||||
This value defines how often the local sequence number gets updated in
|
||||
persistent storage (i.e. flash). e.g. a value of 100 means that the
|
||||
@ -254,7 +374,7 @@ if BLE_MESH
|
||||
config BLE_MESH_RPL_STORE_TIMEOUT
|
||||
int "Minimum frequency that the RPL gets updated in storage"
|
||||
range 0 1000000
|
||||
default 5
|
||||
default 0
|
||||
help
|
||||
This value defines in seconds how soon the RPL (Replay Protection List)
|
||||
gets written to persistent storage after a change occurs. If the node
|
||||
@ -267,6 +387,73 @@ if BLE_MESH
|
||||
introduce message replay attacks and system security will be in a
|
||||
vulnerable state.
|
||||
|
||||
config BLE_MESH_SETTINGS_BACKWARD_COMPATIBILITY
|
||||
bool "A specific option for settings backward compatibility"
|
||||
depends on BLE_MESH_NODE
|
||||
default n
|
||||
help
|
||||
This option is created to solve the issue of failure in recovering
|
||||
node information after mesh stack updates. In the old version mesh
|
||||
stack, there is no key of "mesh/role" in nvs. In the new version
|
||||
mesh stack, key of "mesh/role" is added in nvs, recovering node
|
||||
information needs to check "mesh/role" key in nvs and implements
|
||||
selective recovery of mesh node information. Therefore, there may
|
||||
be failure in recovering node information during node restarting
|
||||
after OTA.
|
||||
|
||||
The new version mesh stack adds the option of "mesh/role" because
|
||||
we have added the support of storing Provisioner information, while
|
||||
the old version only supports storing node information.
|
||||
|
||||
If users are updating their nodes from old version to new version,
|
||||
we recommend enabling this option, so that system could set the flag
|
||||
in advance before recovering node information and make sure the node
|
||||
information recovering could work as expected.
|
||||
|
||||
config BLE_MESH_SPECIFIC_PARTITION
|
||||
bool "Use a specific NVS partition for BLE Mesh"
|
||||
default n
|
||||
help
|
||||
When selected, the mesh stack will use a specified NVS partition instead of
|
||||
default NVS partition. Note that the specified partition must be registered
|
||||
with NVS using nvs_flash_init_partition() API, and the partition must exists
|
||||
in the csv file.
|
||||
When Provisioner needs to store a large amount of nodes' information in the
|
||||
flash (e.g. more than 20), this option is recommended to be enabled.
|
||||
|
||||
config BLE_MESH_PARTITION_NAME
|
||||
string "Name of the NVS partition for BLE Mesh"
|
||||
depends on BLE_MESH_SPECIFIC_PARTITION
|
||||
default "ble_mesh"
|
||||
help
|
||||
This value defines the name of the specified NVS partition used by the
|
||||
mesh stack.
|
||||
|
||||
config BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
bool "Support using multiple NVS namespaces by Provisioner"
|
||||
depends on BLE_MESH_PROVISIONER
|
||||
default n
|
||||
help
|
||||
When selected, Provisioner can use different NVS namespaces to store
|
||||
different instances of mesh information.
|
||||
For example, if in the first room, Provisioner uses NetKey A, AppKey
|
||||
A and provisions three devices, these information will be treated as
|
||||
mesh information instance A. When the Provisioner moves to the second
|
||||
room, it uses NetKey B, AppKey B and provisions two devices, then the
|
||||
information will be treated as mesh information instance B.
|
||||
Here instance A and instance B will be stored in different namespaces.
|
||||
With this option enabled, Provisioner needs to use specific functions
|
||||
to open the corresponding NVS namespace, restore the mesh information,
|
||||
release the mesh information or erase the mesh information.
|
||||
|
||||
config BLE_MESH_MAX_NVS_NAMESPACE
|
||||
int "Maximum number of NVS namespaces"
|
||||
depends on BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
default 2
|
||||
range 1 255
|
||||
help
|
||||
This option specifies the maximum NVS namespaces supported by Provisioner.
|
||||
|
||||
endif # if BLE_MESH_SETTINGS
|
||||
|
||||
config BLE_MESH_SUBNET_COUNT
|
||||
@ -319,6 +506,11 @@ if BLE_MESH
|
||||
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.
|
||||
For Provisioner, the replay protection list size should not be smaller than
|
||||
the maximum number of nodes whose information can be stored. And the element
|
||||
number of each node should also be taken into consideration. For example, if
|
||||
Provisioner can provision up to 20 nodes and each node contains two elements,
|
||||
then the replay protection list size of Provisioner should be at least 40.
|
||||
|
||||
config BLE_MESH_MSG_CACHE_SIZE
|
||||
int "Network message cache size"
|
||||
@ -403,7 +595,7 @@ if BLE_MESH
|
||||
|
||||
config BLE_MESH_TX_SEG_MAX
|
||||
int "Maximum number of segments in outgoing messages"
|
||||
default 20
|
||||
default 32
|
||||
range 2 32
|
||||
help
|
||||
Maximum number of segments supported for outgoing messages.
|
||||
@ -737,104 +929,138 @@ if BLE_MESH
|
||||
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"
|
||||
menu "Support for BLE Mesh Foundation models"
|
||||
|
||||
config BLE_MESH_CFG_CLI
|
||||
bool "Configuration Client Model"
|
||||
bool "Configuration Client model"
|
||||
help
|
||||
Enable support for Configuration client model.
|
||||
Enable support for Configuration Client model.
|
||||
|
||||
config BLE_MESH_HEALTH_CLI
|
||||
bool "Health Client Model"
|
||||
bool "Health Client model"
|
||||
help
|
||||
Enable support for Health client model.
|
||||
Enable support for Health Client model.
|
||||
|
||||
config BLE_MESH_HEALTH_SRV
|
||||
bool "Health Server model"
|
||||
default y
|
||||
help
|
||||
Enable support for Health Server model.
|
||||
|
||||
endmenu #Support for BLE Mesh Foundation models
|
||||
|
||||
menu "Support for BLE Mesh Client/Server models"
|
||||
|
||||
config BLE_MESH_GENERIC_ONOFF_CLI
|
||||
bool "Generic OnOff Client Model"
|
||||
bool "Generic OnOff Client model"
|
||||
help
|
||||
Enable support for Generic OnOff client model.
|
||||
Enable support for Generic OnOff Client model.
|
||||
|
||||
config BLE_MESH_GENERIC_LEVEL_CLI
|
||||
bool "Generic Level Client Model"
|
||||
bool "Generic Level Client model"
|
||||
help
|
||||
Enable support for Generic Level client model.
|
||||
Enable support for Generic Level Client model.
|
||||
|
||||
config BLE_MESH_GENERIC_DEF_TRANS_TIME_CLI
|
||||
bool "Generic Default Transition Time Client Model"
|
||||
bool "Generic Default Transition Time Client model"
|
||||
help
|
||||
Enable support for Generic Default Transition Time client model.
|
||||
Enable support for Generic Default Transition Time Client model.
|
||||
|
||||
config BLE_MESH_GENERIC_POWER_ONOFF_CLI
|
||||
bool "Generic Power Onoff Client Model"
|
||||
bool "Generic Power OnOff Client model"
|
||||
help
|
||||
Enable support for Generic Power Onoff client model.
|
||||
Enable support for Generic Power OnOff Client model.
|
||||
|
||||
config BLE_MESH_GENERIC_POWER_LEVEL_CLI
|
||||
bool "Generic Power Level Client Model"
|
||||
bool "Generic Power Level Client model"
|
||||
help
|
||||
Enable support for Generic Power Level client model.
|
||||
Enable support for Generic Power Level Client model.
|
||||
|
||||
config BLE_MESH_GENERIC_BATTERY_CLI
|
||||
bool "Generic Battery Client Model"
|
||||
bool "Generic Battery Client model"
|
||||
help
|
||||
Enable support for Generic Battery client model.
|
||||
Enable support for Generic Battery Client model.
|
||||
|
||||
config BLE_MESH_GENERIC_LOCATION_CLI
|
||||
bool "Generic Location Client Model"
|
||||
bool "Generic Location Client model"
|
||||
help
|
||||
Enable support for Generic Location client model.
|
||||
Enable support for Generic Location Client model.
|
||||
|
||||
config BLE_MESH_GENERIC_PROPERTY_CLI
|
||||
bool "Generic Property Client Model"
|
||||
bool "Generic Property Client model"
|
||||
help
|
||||
Enable support for Generic Property client model.
|
||||
Enable support for Generic Property Client model.
|
||||
|
||||
config BLE_MESH_SENSOR_CLI
|
||||
bool "Sensor Client Model"
|
||||
bool "Sensor Client model"
|
||||
help
|
||||
Enable support for Sensor client model.
|
||||
Enable support for Sensor Client model.
|
||||
|
||||
config BLE_MESH_TIME_CLI
|
||||
bool "Time Client Model"
|
||||
bool "Time Client model"
|
||||
help
|
||||
Enable support for Time client model.
|
||||
Enable support for Time Client model.
|
||||
|
||||
config BLE_MESH_SCENE_CLI
|
||||
bool "Scene Client Model"
|
||||
bool "Scene Client model"
|
||||
help
|
||||
Enable support for Scene client model.
|
||||
Enable support for Scene Client model.
|
||||
|
||||
config BLE_MESH_SCHEDULER_CLI
|
||||
bool "Scheduler Client Model"
|
||||
bool "Scheduler Client model"
|
||||
help
|
||||
Enable support for Scheduler client model.
|
||||
Enable support for Scheduler Client model.
|
||||
|
||||
config BLE_MESH_LIGHT_LIGHTNESS_CLI
|
||||
bool "Light Lightness Client Model"
|
||||
bool "Light Lightness Client model"
|
||||
help
|
||||
Enable support for Light Lightness client model.
|
||||
Enable support for Light Lightness Client model.
|
||||
|
||||
config BLE_MESH_LIGHT_CTL_CLI
|
||||
bool "Light CTL Client Model"
|
||||
bool "Light CTL Client model"
|
||||
help
|
||||
Enable support for Light CTL client model.
|
||||
Enable support for Light CTL Client model.
|
||||
|
||||
config BLE_MESH_LIGHT_HSL_CLI
|
||||
bool "Light HSL Client Model"
|
||||
bool "Light HSL Client model"
|
||||
help
|
||||
Enable support for Light HSL client model.
|
||||
Enable support for Light HSL Client model.
|
||||
|
||||
config BLE_MESH_LIGHT_XYL_CLI
|
||||
bool "Light XYL Client Model"
|
||||
bool "Light XYL Client model"
|
||||
help
|
||||
Enable support for Light XYL client model.
|
||||
Enable support for Light XYL Client model.
|
||||
|
||||
config BLE_MESH_LIGHT_LC_CLI
|
||||
bool "Light LC Client Model"
|
||||
bool "Light LC Client model"
|
||||
help
|
||||
Enable support for Light LC client model.
|
||||
Enable support for Light LC Client model.
|
||||
|
||||
endmenu
|
||||
config BLE_MESH_GENERIC_SERVER
|
||||
bool "Generic server models"
|
||||
default y
|
||||
help
|
||||
Enable support for Generic server models.
|
||||
|
||||
config BLE_MESH_SENSOR_SERVER
|
||||
bool "Sensor server models"
|
||||
default y
|
||||
help
|
||||
Enable support for Sensor server models.
|
||||
|
||||
config BLE_MESH_TIME_SCENE_SERVER
|
||||
bool "Time and Scenes server models"
|
||||
default y
|
||||
help
|
||||
Enable support for Time and Scenes server models.
|
||||
|
||||
config BLE_MESH_LIGHTING_SERVER
|
||||
bool "Lighting server models"
|
||||
default y
|
||||
help
|
||||
Enable support for Lighting server models.
|
||||
|
||||
endmenu #Support for BLE Mesh Client/Server models
|
||||
|
||||
config BLE_MESH_IV_UPDATE_TEST
|
||||
bool "Test the IV Update Procedure"
|
||||
@ -853,6 +1079,26 @@ if BLE_MESH
|
||||
This option adds extra self-tests which are run every time BLE Mesh
|
||||
networking is initialized.
|
||||
|
||||
if BLE_MESH_SELF_TEST
|
||||
|
||||
config BLE_MESH_TEST_AUTO_ENTER_NETWORK
|
||||
bool "Unprovisioned device enters mesh network automatically"
|
||||
default y
|
||||
help
|
||||
With this option enabled, an unprovisioned device can automatically
|
||||
enters mesh network using a specific test function without the pro-
|
||||
visioning procedure. And on the Provisioner side, a test function
|
||||
needs to be invoked to add the node information into the mesh stack.
|
||||
|
||||
config BLE_MESH_TEST_USE_WHITE_LIST
|
||||
bool "Use white list to filter mesh advertising packets"
|
||||
default n
|
||||
help
|
||||
With this option enabled, users can use white list to filter mesh
|
||||
advertising packets while scanning.
|
||||
|
||||
endif # BLE_MESH_SELF_TEST
|
||||
|
||||
config BLE_MESH_SHELL
|
||||
bool "Enable BLE Mesh shell"
|
||||
default n
|
||||
|
110
components/bt/esp_ble_mesh/api/core/esp_ble_mesh_ble_api.c
Normal file
110
components/bt/esp_ble_mesh/api/core/esp_ble_mesh_ble_api.c
Normal file
@ -0,0 +1,110 @@
|
||||
// Copyright 2017-2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
|
||||
#include "btc_ble_mesh_ble.h"
|
||||
#include "esp_ble_mesh_ble_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_BLE_COEX_SUPPORT
|
||||
esp_err_t esp_ble_mesh_register_ble_callback(esp_ble_mesh_ble_cb_t callback)
|
||||
{
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_BLE_MESH_BLE_COEX, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_BLE_COEX_SUPPORT */
|
||||
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
|
||||
esp_err_t esp_ble_mesh_start_ble_advertising(const esp_ble_mesh_ble_adv_param_t *param,
|
||||
const esp_ble_mesh_ble_adv_data_t *data)
|
||||
{
|
||||
btc_ble_mesh_ble_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (param == 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_BLE_MESH_BLE_COEX;
|
||||
msg.act = BTC_BLE_MESH_ACT_START_BLE_ADV;
|
||||
|
||||
memcpy(&arg.start_ble_adv.param, param, sizeof(esp_ble_mesh_ble_adv_param_t));
|
||||
if (data) {
|
||||
memcpy(&arg.start_ble_adv.data, data, sizeof(esp_ble_mesh_ble_adv_data_t));
|
||||
}
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_ble_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_stop_ble_advertising(uint8_t index)
|
||||
{
|
||||
btc_ble_mesh_ble_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (index >= CONFIG_BLE_MESH_BLE_ADV_BUF_COUNT) {
|
||||
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_BLE_MESH_BLE_COEX;
|
||||
msg.act = BTC_BLE_MESH_ACT_STOP_BLE_ADV;
|
||||
|
||||
arg.stop_ble_adv.index = index;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_ble_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
|
||||
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
esp_err_t esp_ble_mesh_start_ble_scanning(esp_ble_mesh_ble_scan_param_t *param)
|
||||
{
|
||||
btc_ble_mesh_ble_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_BLE_MESH_BLE_COEX;
|
||||
msg.act = BTC_BLE_MESH_ACT_START_BLE_SCAN;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_ble_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_stop_ble_scanning(void)
|
||||
{
|
||||
btc_ble_mesh_ble_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_BLE_MESH_BLE_COEX;
|
||||
msg.act = BTC_BLE_MESH_ACT_STOP_BLE_SCAN;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_ble_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
|
@ -17,10 +17,6 @@
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
#include "osi/alarm.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
|
||||
#include "btc_ble_mesh_prov.h"
|
||||
@ -31,7 +27,7 @@ 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;
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
if (prov == NULL || comp == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
@ -46,7 +42,7 @@ esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp
|
||||
|
||||
// Create a semaphore
|
||||
if ((semaphore = xSemaphoreCreateCounting(1, 0)) == NULL) {
|
||||
LOG_ERROR("%s, Failed to allocate memory for the semaphore", __func__);
|
||||
BT_ERR("Failed to create semaphore");
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
@ -61,7 +57,7 @@ esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp
|
||||
|
||||
if (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL) != BT_STATUS_SUCCESS) {
|
||||
vSemaphoreDelete(semaphore);
|
||||
LOG_ERROR("%s, BLE Mesh initialise failed", __func__);
|
||||
BT_ERR("Failed to start mesh init");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
@ -73,3 +69,25 @@ esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_DEINIT
|
||||
esp_err_t esp_ble_mesh_deinit(esp_ble_mesh_deinit_param_t *param)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (param == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
arg.mesh_deinit.param.erase_flash = param->erase_flash;
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
msg.act = BTC_BLE_MESH_ACT_DEINIT_MESH;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_DEINIT */
|
||||
|
@ -13,10 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
|
||||
@ -36,7 +33,8 @@ uint16_t esp_ble_mesh_get_primary_element_address(void)
|
||||
return btc_ble_mesh_get_primary_addr();
|
||||
}
|
||||
|
||||
uint16_t *esp_ble_mesh_is_model_subscribed_to_group(esp_ble_mesh_model_t *model, uint16_t group_addr)
|
||||
uint16_t *esp_ble_mesh_is_model_subscribed_to_group(esp_ble_mesh_model_t *model,
|
||||
uint16_t group_addr)
|
||||
{
|
||||
if (model == NULL) {
|
||||
return NULL;
|
||||
@ -46,6 +44,9 @@ uint16_t *esp_ble_mesh_is_model_subscribed_to_group(esp_ble_mesh_model_t *model,
|
||||
|
||||
esp_ble_mesh_elem_t *esp_ble_mesh_find_element(uint16_t element_addr)
|
||||
{
|
||||
if (!ESP_BLE_MESH_ADDR_IS_UNICAST(element_addr)) {
|
||||
return NULL;
|
||||
}
|
||||
return btc_ble_mesh_elem_find(element_addr);
|
||||
}
|
||||
|
||||
@ -55,7 +56,7 @@ uint8_t esp_ble_mesh_get_element_count(void)
|
||||
}
|
||||
|
||||
esp_ble_mesh_model_t *esp_ble_mesh_find_vendor_model(const esp_ble_mesh_elem_t *element,
|
||||
uint16_t company_id, uint16_t model_id)
|
||||
uint16_t company_id, uint16_t model_id)
|
||||
{
|
||||
if (element == NULL) {
|
||||
return NULL;
|
||||
@ -63,7 +64,8 @@ esp_ble_mesh_model_t *esp_ble_mesh_find_vendor_model(const esp_ble_mesh_elem_t *
|
||||
return btc_ble_mesh_model_find_vnd(element, company_id, model_id);
|
||||
}
|
||||
|
||||
esp_ble_mesh_model_t *esp_ble_mesh_find_sig_model(const esp_ble_mesh_elem_t *element, uint16_t model_id)
|
||||
esp_ble_mesh_model_t *esp_ble_mesh_find_sig_model(const esp_ble_mesh_elem_t *element,
|
||||
uint16_t model_id)
|
||||
{
|
||||
if (element == NULL) {
|
||||
return NULL;
|
||||
@ -76,3 +78,138 @@ const esp_ble_mesh_comp_t *esp_ble_mesh_get_composition_data(void)
|
||||
return btc_ble_mesh_comp_get();
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_model_subscribe_group_addr(uint16_t element_addr, uint16_t company_id,
|
||||
uint16_t model_id, uint16_t group_addr)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!ESP_BLE_MESH_ADDR_IS_UNICAST(element_addr) ||
|
||||
!ESP_BLE_MESH_ADDR_IS_GROUP(group_addr)) {
|
||||
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_MODEL_SUBSCRIBE_GROUP_ADDR;
|
||||
|
||||
arg.model_sub_group_addr.element_addr = element_addr;
|
||||
arg.model_sub_group_addr.company_id = company_id;
|
||||
arg.model_sub_group_addr.model_id = model_id;
|
||||
arg.model_sub_group_addr.group_addr = group_addr;
|
||||
|
||||
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_model_unsubscribe_group_addr(uint16_t element_addr, uint16_t company_id,
|
||||
uint16_t model_id, uint16_t group_addr)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!ESP_BLE_MESH_ADDR_IS_UNICAST(element_addr) ||
|
||||
!ESP_BLE_MESH_ADDR_IS_GROUP(group_addr)) {
|
||||
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_MODEL_UNSUBSCRIBE_GROUP_ADDR;
|
||||
|
||||
arg.model_unsub_group_addr.element_addr = element_addr;
|
||||
arg.model_unsub_group_addr.company_id = company_id;
|
||||
arg.model_unsub_group_addr.model_id = model_id;
|
||||
arg.model_unsub_group_addr.group_addr = group_addr;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_NODE
|
||||
|
||||
const uint8_t *esp_ble_mesh_node_get_local_net_key(uint16_t net_idx)
|
||||
{
|
||||
return btc_ble_mesh_node_get_local_net_key(net_idx);
|
||||
}
|
||||
|
||||
const uint8_t *esp_ble_mesh_node_get_local_app_key(uint16_t app_idx)
|
||||
{
|
||||
return btc_ble_mesh_node_get_local_app_key(app_idx);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_node_add_local_net_key(const uint8_t net_key[16], uint16_t net_idx)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (net_key == NULL || net_idx > 0xFFF) {
|
||||
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_NODE_ADD_LOCAL_NET_KEY;
|
||||
|
||||
arg.node_add_local_net_key.net_idx = net_idx;
|
||||
memcpy(arg.node_add_local_net_key.net_key, net_key, 16);
|
||||
|
||||
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_node_add_local_app_key(const uint8_t app_key[16], uint16_t net_idx, uint16_t app_idx)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (app_key == NULL || net_idx > 0xFFF || app_idx > 0xFFF) {
|
||||
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_NODE_ADD_LOCAL_APP_KEY;
|
||||
|
||||
arg.node_add_local_app_key.net_idx = net_idx;
|
||||
arg.node_add_local_app_key.app_idx = app_idx;
|
||||
memcpy(arg.node_add_local_app_key.app_key, app_key, 16);
|
||||
|
||||
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_node_bind_app_key_to_local_model(uint16_t element_addr, uint16_t company_id,
|
||||
uint16_t model_id, uint16_t app_idx)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!ESP_BLE_MESH_ADDR_IS_UNICAST(element_addr) || app_idx > 0xFFF) {
|
||||
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_NODE_BIND_APP_KEY_TO_MODEL;
|
||||
|
||||
arg.node_local_mod_app_bind.element_addr = element_addr;
|
||||
arg.node_local_mod_app_bind.model_id = model_id;
|
||||
arg.node_local_mod_app_bind.company_id = company_id;
|
||||
arg.node_local_mod_app_bind.app_idx = app_idx;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_NODE */
|
||||
|
@ -14,8 +14,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
|
||||
#include "btc_ble_mesh_prov.h"
|
||||
|
@ -13,10 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
|
||||
@ -26,28 +23,28 @@
|
||||
#define ESP_BLE_MESH_TX_SDU_MAX ((CONFIG_BLE_MESH_ADV_BUF_COUNT - 3) * 12)
|
||||
|
||||
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)
|
||||
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;
|
||||
uint8_t *msg_data = NULL;
|
||||
btc_msg_t msg = {0};
|
||||
esp_err_t status;
|
||||
esp_err_t status = ESP_OK;
|
||||
|
||||
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__);
|
||||
BT_ERR("Invalid destination address 0x0000");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (device_role > ROLE_FAST_PROV) {
|
||||
LOG_ERROR("%s, Invalid device role 0x%02x", __func__, device_role);
|
||||
BT_ERR("Invalid device role 0x%02x", device_role);
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -66,19 +63,19 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
|
||||
if (act == BTC_BLE_MESH_ACT_MODEL_PUBLISH) {
|
||||
if (op_len + length > model->pub->msg->size) {
|
||||
LOG_ERROR("%s, Model publication msg size %d is too small", __func__, model->pub->msg->size);
|
||||
BT_ERR("Too small publication msg size %d", model->pub->msg->size);
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
if (act == BTC_BLE_MESH_ACT_MODEL_PUBLISH) {
|
||||
mic_len = 4;
|
||||
mic_len = ESP_BLE_MESH_MIC_SHORT;
|
||||
} else {
|
||||
mic_len = ctx->send_rel ? 8 : 4;
|
||||
mic_len = ctx->send_rel ? ESP_BLE_MESH_MIC_LONG : ESP_BLE_MESH_MIC_SHORT;
|
||||
}
|
||||
|
||||
if (op_len + length + mic_len > MIN(ESP_BLE_MESH_SDU_MAX_LEN, ESP_BLE_MESH_TX_SDU_MAX)) {
|
||||
LOG_ERROR("%s, Data length %d is too large", __func__, length);
|
||||
BT_ERR("Too large data length %d", length);
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -86,7 +83,7 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
bt_mesh_model_msg_init(model->pub->msg, opcode);
|
||||
net_buf_simple_add_mem(model->pub->msg, data, length);
|
||||
} else {
|
||||
msg_data = (uint8_t *)osi_malloc(op_len + length);
|
||||
msg_data = (uint8_t *)bt_mesh_malloc(op_len + length);
|
||||
if (msg_data == NULL) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
@ -115,7 +112,7 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
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);
|
||||
bt_mesh_free(msg_data);
|
||||
|
||||
return status;
|
||||
}
|
||||
@ -129,7 +126,7 @@ esp_err_t esp_ble_mesh_register_custom_model_callback(esp_ble_mesh_model_cb_t ca
|
||||
|
||||
esp_err_t esp_ble_mesh_model_msg_opcode_init(uint8_t *data, uint32_t opcode)
|
||||
{
|
||||
uint16_t val;
|
||||
uint16_t val = 0;
|
||||
|
||||
if (data == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
@ -161,28 +158,53 @@ esp_err_t esp_ble_mesh_client_model_init(esp_ble_mesh_model_t *model)
|
||||
if (model == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return btc_ble_mesh_client_model_init(model);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_server_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
esp_ble_mesh_msg_ctx_t *ctx, uint32_t opcode,
|
||||
uint16_t length, uint8_t *data)
|
||||
#if CONFIG_BLE_MESH_DEINIT
|
||||
esp_err_t esp_ble_mesh_client_model_deinit(esp_ble_mesh_model_t *model)
|
||||
{
|
||||
if (!model || !ctx) {
|
||||
if (model == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return btc_ble_mesh_client_model_deinit(model);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_DEINIT */
|
||||
|
||||
esp_err_t esp_ble_mesh_server_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
esp_ble_mesh_msg_ctx_t *ctx,
|
||||
uint32_t opcode,
|
||||
uint16_t length, uint8_t *data)
|
||||
{
|
||||
if (model == NULL || ctx == NULL ||
|
||||
ctx->net_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
ctx->app_idx == ESP_BLE_MESH_KEY_UNUSED) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
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,
|
||||
esp_ble_mesh_msg_ctx_t *ctx, uint32_t opcode,
|
||||
uint16_t length, uint8_t *data, int32_t msg_timeout,
|
||||
bool need_rsp, esp_ble_mesh_dev_role_t device_role)
|
||||
esp_ble_mesh_msg_ctx_t *ctx,
|
||||
uint32_t opcode,
|
||||
uint16_t length, uint8_t *data,
|
||||
int32_t msg_timeout, bool need_rsp,
|
||||
esp_ble_mesh_dev_role_t device_role)
|
||||
{
|
||||
if (!model || !ctx) {
|
||||
if (model == NULL || ctx == NULL ||
|
||||
ctx->net_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
ctx->app_idx == ESP_BLE_MESH_KEY_UNUSED) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
return ble_mesh_model_send_msg(model, ctx, opcode, BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND,
|
||||
length, data, msg_timeout, need_rsp, device_role);
|
||||
}
|
||||
@ -191,16 +213,19 @@ 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)
|
||||
{
|
||||
if (!model || !model->pub || !model->pub->msg) {
|
||||
if (model == NULL || model->pub == NULL || model->pub->msg == NULL ||
|
||||
model->pub->publish_addr == ESP_BLE_MESH_ADDR_UNASSIGNED) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
return ble_mesh_model_send_msg(model, NULL, opcode, BTC_BLE_MESH_ACT_MODEL_PUBLISH,
|
||||
length, data, 0, false, device_role);
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_SERVER_MODEL
|
||||
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)
|
||||
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};
|
||||
@ -222,6 +247,7 @@ esp_err_t esp_ble_mesh_server_model_update_state(esp_ble_mesh_model_t *model,
|
||||
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);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SERVER_MODEL */
|
||||
|
||||
esp_err_t esp_ble_mesh_node_local_reset(void)
|
||||
{
|
||||
@ -238,7 +264,7 @@ esp_err_t esp_ble_mesh_node_local_reset(void)
|
||||
|
||||
#if (CONFIG_BLE_MESH_PROVISIONER)
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_set_node_name(int index, const char *name)
|
||||
esp_err_t esp_ble_mesh_provisioner_set_node_name(uint16_t index, const char *name)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
@ -255,27 +281,130 @@ esp_err_t esp_ble_mesh_provisioner_set_node_name(int index, const char *name)
|
||||
|
||||
arg.set_node_name.index = index;
|
||||
memset(arg.set_node_name.name, 0, sizeof(arg.set_node_name.name));
|
||||
memcpy(arg.set_node_name.name, name, strlen(name));
|
||||
strncpy(arg.set_node_name.name, name, ESP_BLE_MESH_NODE_NAME_MAX_LEN);
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
const char *esp_ble_mesh_provisioner_get_node_name(int index)
|
||||
const char *esp_ble_mesh_provisioner_get_node_name(uint16_t index)
|
||||
{
|
||||
return bt_mesh_provisioner_get_node_name(index);
|
||||
}
|
||||
|
||||
int esp_ble_mesh_provisioner_get_node_index(const char *name)
|
||||
uint16_t esp_ble_mesh_provisioner_get_node_index(const char *name)
|
||||
{
|
||||
if (!name || (strlen(name) > ESP_BLE_MESH_NODE_NAME_MAX_LEN)) {
|
||||
return -EINVAL;
|
||||
return ESP_BLE_MESH_INVALID_NODE_INDEX;
|
||||
}
|
||||
|
||||
return bt_mesh_provisioner_get_node_index(name);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_store_node_comp_data(uint16_t unicast_addr,
|
||||
uint8_t *data, uint16_t length)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!ESP_BLE_MESH_ADDR_IS_UNICAST(unicast_addr) || !data || length <= 14) {
|
||||
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_PROVISIONER_STORE_NODE_COMP_DATA;
|
||||
|
||||
arg.store_node_comp_data.unicast_addr = unicast_addr;
|
||||
arg.store_node_comp_data.length = length;
|
||||
arg.store_node_comp_data.data = data;
|
||||
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_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_uuid(const uint8_t uuid[16])
|
||||
{
|
||||
if (!uuid) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return btc_ble_mesh_provisioner_get_node_with_uuid(uuid);
|
||||
}
|
||||
|
||||
esp_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_addr(uint16_t unicast_addr)
|
||||
{
|
||||
if (!ESP_BLE_MESH_ADDR_IS_UNICAST(unicast_addr)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return btc_ble_mesh_provisioner_get_node_with_addr(unicast_addr);
|
||||
}
|
||||
|
||||
esp_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_name(const char *name)
|
||||
{
|
||||
if (!name || (strlen(name) > ESP_BLE_MESH_NODE_NAME_MAX_LEN)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return btc_ble_mesh_provisioner_get_node_with_name(name);
|
||||
}
|
||||
|
||||
uint16_t esp_ble_mesh_provisioner_get_prov_node_count(void)
|
||||
{
|
||||
return btc_ble_mesh_provisioner_get_prov_node_count();
|
||||
}
|
||||
|
||||
const esp_ble_mesh_node_t **esp_ble_mesh_provisioner_get_node_table_entry(void)
|
||||
{
|
||||
return btc_ble_mesh_provisioner_get_node_table_entry();
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_delete_node_with_uuid(const uint8_t uuid[16])
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!uuid) {
|
||||
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_PROVISIONER_DELETE_NODE_WITH_UUID;
|
||||
|
||||
memcpy(arg.delete_node_with_uuid.uuid, uuid, 16);
|
||||
|
||||
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_provisioner_delete_node_with_addr(uint16_t unicast_addr)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!ESP_BLE_MESH_ADDR_IS_UNICAST(unicast_addr)) {
|
||||
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_PROVISIONER_DELETE_NODE_WITH_ADDR;
|
||||
|
||||
arg.delete_node_with_addr.unicast_addr = unicast_addr;
|
||||
|
||||
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_provisioner_add_local_app_key(const uint8_t app_key[16],
|
||||
uint16_t net_idx, uint16_t app_idx)
|
||||
uint16_t net_idx, uint16_t app_idx)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
@ -284,7 +413,7 @@ esp_err_t esp_ble_mesh_provisioner_add_local_app_key(const uint8_t app_key[16],
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_PROV;
|
||||
msg.act = BTC_BLE_MESH_ACT_PROVISIONER_SET_LOCAL_APP_KEY;
|
||||
msg.act = BTC_BLE_MESH_ACT_PROVISIONER_ADD_LOCAL_APP_KEY;
|
||||
|
||||
arg.add_local_app_key.net_idx = net_idx;
|
||||
arg.add_local_app_key.app_idx = app_idx;
|
||||
@ -297,13 +426,36 @@ esp_err_t esp_ble_mesh_provisioner_add_local_app_key(const uint8_t app_key[16],
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_update_local_app_key(const uint8_t app_key[16],
|
||||
uint16_t net_idx, uint16_t app_idx)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (app_key == 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_PROV;
|
||||
msg.act = BTC_BLE_MESH_ACT_PROVISIONER_UPDATE_LOCAL_APP_KEY;
|
||||
|
||||
memcpy(arg.update_local_app_key.app_key, app_key, 16);
|
||||
arg.update_local_app_key.net_idx = net_idx;
|
||||
arg.update_local_app_key.app_idx = app_idx;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
const uint8_t *esp_ble_mesh_provisioner_get_local_app_key(uint16_t net_idx, uint16_t app_idx)
|
||||
{
|
||||
return bt_mesh_provisioner_local_app_key_get(net_idx, app_idx);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_bind_app_key_to_local_model(uint16_t element_addr, uint16_t app_idx,
|
||||
uint16_t model_id, uint16_t company_id)
|
||||
uint16_t model_id, uint16_t company_id)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
@ -351,11 +503,271 @@ esp_err_t esp_ble_mesh_provisioner_add_local_net_key(const uint8_t net_key[16],
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_update_local_net_key(const uint8_t net_key[16], uint16_t net_idx)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (net_key == 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_PROV;
|
||||
msg.act = BTC_BLE_MESH_ACT_PROVISIONER_UPDATE_LOCAL_NET_KEY;
|
||||
|
||||
memcpy(arg.update_local_net_key.net_key, net_key, 16);
|
||||
arg.update_local_net_key.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);
|
||||
}
|
||||
|
||||
const uint8_t *esp_ble_mesh_provisioner_get_local_net_key(uint16_t net_idx)
|
||||
{
|
||||
return bt_mesh_provisioner_local_net_key_get(net_idx);
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_PROVISIONER_RECV_HB
|
||||
esp_err_t esp_ble_mesh_provisioner_recv_heartbeat(bool enable)
|
||||
{
|
||||
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_PROVISIONER_ENABLE_HEARTBEAT_RECV;
|
||||
|
||||
arg.enable_heartbeat_recv.enable = enable;
|
||||
|
||||
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_provisioner_set_heartbeat_filter_type(uint8_t type)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (type > ESP_BLE_MESH_HEARTBEAT_FILTER_REJECTLIST) {
|
||||
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_PROVISIONER_SET_HEARTBEAT_FILTER_TYPE;
|
||||
|
||||
arg.set_heartbeat_filter_type.type = 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_provisioner_set_heartbeat_filter_info(uint8_t op, esp_ble_mesh_heartbeat_filter_info_t *info)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (op > ESP_BLE_MESH_HEARTBEAT_FILTER_REMOVE || info == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (!ESP_BLE_MESH_ADDR_IS_UNICAST(info->hb_src) &&
|
||||
!ESP_BLE_MESH_ADDR_IS_UNICAST(info->hb_dst) &&
|
||||
!ESP_BLE_MESH_ADDR_IS_GROUP(info->hb_dst)) {
|
||||
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_PROVISIONER_SET_HEARTBEAT_FILTER_INFO;
|
||||
|
||||
arg.set_heartbeat_filter_info.op = op;
|
||||
arg.set_heartbeat_filter_info.hb_src = info->hb_src;
|
||||
arg.set_heartbeat_filter_info.hb_dst = info->hb_dst;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_PROVISIONER_RECV_HB */
|
||||
|
||||
#if CONFIG_BLE_MESH_SETTINGS
|
||||
esp_err_t esp_ble_mesh_provisioner_direct_erase_settings(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_PROVISIONER_DIRECT_ERASE_SETTINGS;
|
||||
|
||||
return (btc_transfer_context(&msg, NULL, 0, NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SETTINGS */
|
||||
|
||||
#if CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE
|
||||
esp_err_t esp_ble_mesh_provisioner_open_settings_with_index(uint8_t index)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (index >= CONFIG_BLE_MESH_MAX_NVS_NAMESPACE) {
|
||||
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_PROVISIONER_OPEN_SETTINGS_WITH_INDEX;
|
||||
|
||||
arg.open_settings_with_index.index = index;
|
||||
|
||||
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_provisioner_open_settings_with_uid(const char *uid)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!uid || strlen(uid) > ESP_BLE_MESH_SETTINGS_UID_SIZE) {
|
||||
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_PROVISIONER_OPEN_SETTINGS_WITH_UID;
|
||||
|
||||
strncpy(arg.open_settings_with_uid.uid, uid, ESP_BLE_MESH_SETTINGS_UID_SIZE);
|
||||
|
||||
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_provisioner_close_settings_with_index(uint8_t index, bool erase)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (index >= CONFIG_BLE_MESH_MAX_NVS_NAMESPACE) {
|
||||
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_PROVISIONER_CLOSE_SETTINGS_WITH_INDEX;
|
||||
|
||||
arg.close_settings_with_index.index = index;
|
||||
arg.close_settings_with_index.erase = erase;
|
||||
|
||||
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_provisioner_close_settings_with_uid(const char *uid, bool erase)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!uid || strlen(uid) > ESP_BLE_MESH_SETTINGS_UID_SIZE) {
|
||||
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_PROVISIONER_CLOSE_SETTINGS_WITH_UID;
|
||||
|
||||
strncpy(arg.close_settings_with_uid.uid, uid, ESP_BLE_MESH_SETTINGS_UID_SIZE);
|
||||
arg.close_settings_with_uid.erase = erase;
|
||||
|
||||
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_provisioner_delete_settings_with_index(uint8_t index)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (index >= CONFIG_BLE_MESH_MAX_NVS_NAMESPACE) {
|
||||
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_PROVISIONER_DELETE_SETTINGS_WITH_INDEX;
|
||||
|
||||
arg.delete_settings_with_index.index = index;
|
||||
|
||||
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_provisioner_delete_settings_with_uid(const char *uid)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!uid || strlen(uid) > ESP_BLE_MESH_SETTINGS_UID_SIZE) {
|
||||
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_PROVISIONER_DELETE_SETTINGS_WITH_UID;
|
||||
|
||||
strncpy(arg.delete_settings_with_uid.uid, uid, ESP_BLE_MESH_SETTINGS_UID_SIZE);
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
const char *esp_ble_mesh_provisioner_get_settings_uid(uint8_t index)
|
||||
{
|
||||
if (index >= CONFIG_BLE_MESH_MAX_NVS_NAMESPACE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return btc_ble_mesh_provisioner_get_settings_uid(index);
|
||||
}
|
||||
|
||||
uint8_t esp_ble_mesh_provisioner_get_settings_index(const char *uid)
|
||||
{
|
||||
if (!uid || strlen(uid) > ESP_BLE_MESH_SETTINGS_UID_SIZE) {
|
||||
return ESP_BLE_MESH_INVALID_SETTINGS_IDX;
|
||||
}
|
||||
|
||||
return btc_ble_mesh_provisioner_get_settings_index(uid);
|
||||
}
|
||||
|
||||
uint8_t esp_ble_mesh_provisioner_get_free_settings_count(void)
|
||||
{
|
||||
return btc_ble_mesh_provisioner_get_free_settings_count();
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE */
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_PROVISIONER */
|
||||
|
||||
#if (CONFIG_BLE_MESH_FAST_PROV)
|
||||
|
@ -13,9 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
|
||||
@ -37,11 +35,29 @@ bool esp_ble_mesh_node_is_provisioned(void)
|
||||
return bt_mesh_is_provisioned();
|
||||
}
|
||||
|
||||
static bool prov_bearers_valid(esp_ble_mesh_prov_bearer_t bearers)
|
||||
{
|
||||
if ((!(bearers & (ESP_BLE_MESH_PROV_ADV | ESP_BLE_MESH_PROV_GATT))) ||
|
||||
(IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) &&
|
||||
!IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) &&
|
||||
!(bearers & ESP_BLE_MESH_PROV_ADV)) ||
|
||||
(!IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) &&
|
||||
IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) &&
|
||||
!(bearers & ESP_BLE_MESH_PROV_GATT))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
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};
|
||||
|
||||
if (prov_bearers_valid(bearers) == false) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
@ -58,6 +74,10 @@ 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};
|
||||
|
||||
if (prov_bearers_valid(bearers) == false) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
@ -70,7 +90,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};
|
||||
@ -118,7 +138,7 @@ esp_err_t esp_ble_mesh_node_input_string(const char *string)
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!string) {
|
||||
if (!string || strlen(string) > ESP_BLE_MESH_PROV_INPUT_OOB_MAX_LEN) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -128,7 +148,8 @@ esp_err_t esp_ble_mesh_node_input_string(const char *string)
|
||||
msg.pid = BTC_PID_PROV;
|
||||
msg.act = BTC_BLE_MESH_ACT_INPUT_STRING;
|
||||
memset(arg.input_string.string, 0, sizeof(arg.input_string.string));
|
||||
strncpy(arg.input_string.string, string, strlen(string));
|
||||
strncpy(arg.input_string.string, string,
|
||||
MIN(strlen(string), sizeof(arg.input_string.string)));
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
@ -150,14 +171,15 @@ esp_err_t esp_ble_mesh_set_unprovisioned_device_name(const char *name)
|
||||
msg.act = BTC_BLE_MESH_ACT_SET_DEVICE_NAME;
|
||||
|
||||
memset(arg.set_device_name.name, 0, sizeof(arg.set_device_name.name));
|
||||
memcpy(arg.set_device_name.name, name, strlen(name));
|
||||
strncpy(arg.set_device_name.name, name, ESP_BLE_MESH_DEVICE_NAME_MAX_LEN);
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
#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};
|
||||
@ -185,7 +207,8 @@ esp_err_t esp_ble_mesh_provisioner_input_string(const char *string, uint8_t link
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!string || link_idx >= MAX_PROV_LINK_IDX) {
|
||||
if (!string || strlen(string) > ESP_BLE_MESH_PROV_OUTPUT_OOB_MAX_LEN ||
|
||||
link_idx >= MAX_PROV_LINK_IDX) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -196,7 +219,8 @@ esp_err_t esp_ble_mesh_provisioner_input_string(const char *string, uint8_t link
|
||||
msg.act = BTC_BLE_MESH_ACT_PROVISIONER_INPUT_STR;
|
||||
|
||||
memset(arg.provisioner_input_str.string, 0, sizeof(arg.provisioner_input_str.string));
|
||||
strncpy(arg.provisioner_input_str.string, string, strlen(string));
|
||||
strncpy(arg.provisioner_input_str.string, string,
|
||||
MIN(strlen(string), sizeof(arg.provisioner_input_str.string)));
|
||||
arg.provisioner_input_str.link_idx = link_idx;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
@ -230,6 +254,10 @@ 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};
|
||||
|
||||
if (prov_bearers_valid(bearers) == false) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
@ -247,6 +275,10 @@ 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};
|
||||
|
||||
if (prov_bearers_valid(bearers) == false) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
@ -260,7 +292,7 @@ esp_err_t esp_ble_mesh_provisioner_prov_disable(esp_ble_mesh_prov_bearer_t beare
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_add_unprov_dev(esp_ble_mesh_unprov_dev_add_t *add_dev,
|
||||
esp_ble_mesh_dev_add_flag_t flags)
|
||||
esp_ble_mesh_dev_add_flag_t flags)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
@ -285,6 +317,40 @@ esp_err_t esp_ble_mesh_provisioner_add_unprov_dev(esp_ble_mesh_unprov_dev_add_t
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_prov_device_with_addr(const uint8_t uuid[16],
|
||||
esp_ble_mesh_bd_addr_t addr,
|
||||
esp_ble_mesh_addr_type_t addr_type,
|
||||
esp_ble_mesh_prov_bearer_t bearer,
|
||||
uint16_t oob_info, uint16_t unicast_addr)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (uuid == NULL || (bearer == ESP_BLE_MESH_PROV_GATT && (addr == NULL ||
|
||||
addr_type > ESP_BLE_MESH_ADDR_TYPE_RANDOM)) ||
|
||||
(bearer != ESP_BLE_MESH_PROV_ADV && bearer != ESP_BLE_MESH_PROV_GATT) ||
|
||||
!ESP_BLE_MESH_ADDR_IS_UNICAST(unicast_addr)) {
|
||||
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_PROVISIONER_PROV_DEV_WITH_ADDR;
|
||||
|
||||
memcpy(arg.provisioner_prov_dev_with_addr.uuid, uuid, 16);
|
||||
if (addr) {
|
||||
memcpy(arg.provisioner_prov_dev_with_addr.addr, addr, BD_ADDR_LEN);
|
||||
arg.provisioner_prov_dev_with_addr.addr_type = addr_type;
|
||||
}
|
||||
arg.provisioner_prov_dev_with_addr.bearer = bearer;
|
||||
arg.provisioner_prov_dev_with_addr.oob_info = oob_info;
|
||||
arg.provisioner_prov_dev_with_addr.unicast_addr = unicast_addr;
|
||||
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_provisioner_delete_dev(esp_ble_mesh_device_delete_t *del_dev)
|
||||
{
|
||||
uint8_t val = DEL_DEV_ADDR_FLAG | DEL_DEV_UUID_FLAG;
|
||||
@ -313,11 +379,15 @@ esp_err_t esp_ble_mesh_provisioner_delete_dev(esp_ble_mesh_device_delete_t *del_
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_set_dev_uuid_match(const uint8_t *match_val, uint8_t match_len,
|
||||
uint8_t offset, bool prov_after_match)
|
||||
uint8_t offset, bool prov_after_match)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (match_len + offset > ESP_BLE_MESH_OCTET16_LEN) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
@ -362,6 +432,47 @@ esp_err_t esp_ble_mesh_provisioner_set_prov_data_info(esp_ble_mesh_prov_data_inf
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_provisioner_set_static_oob_value(const uint8_t *value, uint8_t length)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (value == NULL || length == 0 || length > 16) {
|
||||
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_PROVISIONER_SET_STATIC_OOB_VAL;
|
||||
|
||||
arg.set_static_oob_val.length = length;
|
||||
memcpy(arg.set_static_oob_val.value, value, length);
|
||||
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_provisioner_set_primary_elem_addr(uint16_t addr)
|
||||
{
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!ESP_BLE_MESH_ADDR_IS_UNICAST(addr)) {
|
||||
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_PROVISIONER_SET_PRIMARY_ELEM_ADDR;
|
||||
|
||||
arg.set_primary_elem_addr.addr = addr;
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_PROVISIONER */
|
||||
|
||||
/* The following APIs are for fast provisioning */
|
||||
@ -373,7 +484,8 @@ esp_err_t esp_ble_mesh_set_fast_prov_info(esp_ble_mesh_fast_prov_info_t *fast_pr
|
||||
btc_ble_mesh_prov_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (fast_prov_info == NULL) {
|
||||
if (fast_prov_info == NULL || (fast_prov_info->offset +
|
||||
fast_prov_info->match_len > ESP_BLE_MESH_OCTET16_LEN)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,7 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
|
||||
@ -62,7 +60,8 @@ esp_err_t esp_ble_mesh_proxy_gatt_disable(void)
|
||||
}
|
||||
|
||||
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)
|
||||
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};
|
||||
@ -102,8 +101,8 @@ esp_err_t esp_ble_mesh_proxy_client_disconnect(uint8_t conn_handle)
|
||||
== 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)
|
||||
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};
|
||||
@ -126,8 +125,8 @@ esp_err_t esp_ble_mesh_proxy_client_set_filter_type(uint8_t conn_handle,
|
||||
== 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)
|
||||
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};
|
||||
@ -151,8 +150,8 @@ esp_err_t esp_ble_mesh_proxy_client_add_filter_addr(uint8_t conn_handle,
|
||||
== 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)
|
||||
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};
|
||||
|
@ -0,0 +1,190 @@
|
||||
// Copyright 2017-2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _ESP_BLE_MESH_BLE_API_H_
|
||||
#define _ESP_BLE_MESH_BLE_API_H_
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** This enum value is the event of BLE operations */
|
||||
typedef enum {
|
||||
ESP_BLE_MESH_START_BLE_ADVERTISING_COMP_EVT, /*!< Start BLE advertising completion event */
|
||||
ESP_BLE_MESH_STOP_BLE_ADVERTISING_COMP_EVT, /*!< Stop BLE advertising completion event */
|
||||
ESP_BLE_MESH_START_BLE_SCANNING_COMP_EVT, /*!< Start BLE scanning completion event */
|
||||
ESP_BLE_MESH_STOP_BLE_SCANNING_COMP_EVT, /*!< Stop BLE scanning completion event */
|
||||
ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT, /*!< Scanning BLE advertising packets event */
|
||||
ESP_BLE_MESH_BLE_EVT_MAX,
|
||||
} esp_ble_mesh_ble_cb_event_t;
|
||||
|
||||
/** BLE operation callback parameters */
|
||||
typedef union {
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_START_BLE_ADVERTISING_COMP_EVT
|
||||
*/
|
||||
struct {
|
||||
int err_code; /*!< Indicate the result of starting BLE advertising */
|
||||
uint8_t index; /*!< Index of the BLE advertising */
|
||||
} start_ble_advertising_comp; /*!< Event parameters of ESP_BLE_MESH_START_BLE_ADVERTISING_COMP_EVT */
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_STOP_BLE_ADVERTISING_COMP_EVT
|
||||
*/
|
||||
struct {
|
||||
int err_code; /*!< Indicate the result of stopping BLE advertising */
|
||||
uint8_t index; /*!< Index of the BLE advertising */
|
||||
} stop_ble_advertising_comp; /*!< Event parameters of ESP_BLE_MESH_STOP_BLE_ADVERTISING_COMP_EVT */
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_START_BLE_SCANNING_COMP_EVT
|
||||
*/
|
||||
struct {
|
||||
int err_code; /*!< Indicate the result of starting BLE scanning */
|
||||
} start_ble_scan_comp; /*!< Event parameters of ESP_BLE_MESH_START_BLE_SCANNING_COMP_EVT */
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_STOP_BLE_SCANNING_COMP_EVT
|
||||
*/
|
||||
struct {
|
||||
int err_code; /*!< Indicate the result of stopping BLE scanning */
|
||||
} stop_ble_scan_comp; /*!< Event parameters of ESP_BLE_MESH_STOP_BLE_SCANNING_COMP_EVT */
|
||||
/**
|
||||
* @brief ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT
|
||||
*/
|
||||
struct {
|
||||
uint8_t addr[6]; /*!< Device address */
|
||||
uint8_t addr_type; /*!< Device address type */
|
||||
uint8_t adv_type; /*!< Advertising data type */
|
||||
uint8_t *data; /*!< Advertising data */
|
||||
uint16_t length; /*!< Advertising data length */
|
||||
int8_t rssi; /*!< RSSI of the advertising packet */
|
||||
} scan_ble_adv_pkt; /*!< Event parameters of ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT */
|
||||
} esp_ble_mesh_ble_cb_param_t;
|
||||
|
||||
/**
|
||||
* @brief BLE scanning callback function type
|
||||
*
|
||||
* @param event: BLE scanning callback event type
|
||||
* @param param: BLE scanning callback parameter
|
||||
*/
|
||||
typedef void (* esp_ble_mesh_ble_cb_t)(esp_ble_mesh_ble_cb_event_t event,
|
||||
esp_ble_mesh_ble_cb_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief Register BLE scanning callback.
|
||||
*
|
||||
* @param[in] callback: Pointer to the BLE scaning callback function.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_register_ble_callback(esp_ble_mesh_ble_cb_t callback);
|
||||
|
||||
/** Count for sending BLE advertising packet infinitely */
|
||||
#define ESP_BLE_MESH_BLE_ADV_INFINITE 0xFFFF
|
||||
|
||||
/*!< This enum value is the priority of BLE advertising packet */
|
||||
typedef enum {
|
||||
ESP_BLE_MESH_BLE_ADV_PRIO_LOW,
|
||||
ESP_BLE_MESH_BLE_ADV_PRIO_HIGH,
|
||||
} esp_ble_mesh_ble_adv_priority_t;
|
||||
|
||||
/** Context of BLE advertising parameters. */
|
||||
typedef struct {
|
||||
uint16_t interval; /*!< BLE advertising interval */
|
||||
uint8_t adv_type; /*!< BLE advertising type */
|
||||
uint8_t own_addr_type; /*!< Own address type */
|
||||
uint8_t peer_addr_type; /*!< Peer address type */
|
||||
uint8_t peer_addr[BD_ADDR_LEN]; /*!< Peer address */
|
||||
uint16_t duration; /*!< Duration is milliseconds */
|
||||
uint16_t period; /*!< Period in milliseconds */
|
||||
uint16_t count; /*!< Number of advertising duration */
|
||||
uint8_t priority:2; /*!< Priority of BLE advertising packet */
|
||||
} esp_ble_mesh_ble_adv_param_t;
|
||||
|
||||
/** Context of BLE advertising data. */
|
||||
typedef struct {
|
||||
uint8_t adv_data_len; /*!< Advertising data length */
|
||||
uint8_t adv_data[31]; /*!< Advertising data */
|
||||
uint8_t scan_rsp_data_len; /*!< Scan response data length */
|
||||
uint8_t scan_rsp_data[31]; /*!< Scan response data */
|
||||
} esp_ble_mesh_ble_adv_data_t;
|
||||
|
||||
/**
|
||||
* @brief This function is called to start BLE advertising with the corresponding data
|
||||
* and parameters while BLE Mesh is working at the same time.
|
||||
*
|
||||
* @note 1. When this function is called, the BLE advertising packet will be posted to
|
||||
* the BLE mesh adv queue in the mesh stack and waited to be sent.
|
||||
* 2. In the BLE advertising parameters, the "duration" means the time used for
|
||||
* sending the BLE advertising packet each time, it shall not be smaller than the
|
||||
* advertising interval. When the packet is sent successfully, it will be posted
|
||||
* to the adv queue again after the "period" time if the "count" is bigger than 0.
|
||||
* The "count" means how many durations the packet will be sent after it is sent
|
||||
* successfully for the first time. And if the "count" is set to 0xFFFF, which
|
||||
* means the packet will be sent infinitely.
|
||||
* 3. The "priority" means the priority of BLE advertising packet compared with
|
||||
* BLE Mesh packets. Currently two options (i.e. low/high) are provided. If the
|
||||
* "priority" is high, the BLE advertising packet will be posted to the front of
|
||||
* adv queue. Otherwise it will be posted to the back of adv queue.
|
||||
*
|
||||
* @param[in] param: Pointer to the BLE advertising parameters
|
||||
* @param[in] data: Pointer to the BLE advertising data and scan response data
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_start_ble_advertising(const esp_ble_mesh_ble_adv_param_t *param,
|
||||
const esp_ble_mesh_ble_adv_data_t *data);
|
||||
|
||||
/**
|
||||
* @brief This function is called to stop BLE advertising with the corresponding index.
|
||||
*
|
||||
* @param[in] index: Index of BLE advertising
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_stop_ble_advertising(uint8_t index);
|
||||
|
||||
/** Context of BLE scanning parameters. */
|
||||
typedef struct {
|
||||
uint32_t duration; /*!< Duration used to scan normal BLE advertising packets */
|
||||
} esp_ble_mesh_ble_scan_param_t;
|
||||
|
||||
/**
|
||||
* @brief This function is called to start scanning normal BLE advertising packets
|
||||
* and notifying the packets to the application layer.
|
||||
*
|
||||
* @param[in] param: Pointer to the BLE scanning parameters
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_start_ble_scanning(esp_ble_mesh_ble_scan_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief This function is called to stop notifying normal BLE advertising packets
|
||||
* to the application layer.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_stop_ble_scanning(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_BLE_MESH_BLE_API_H_ */
|
@ -17,6 +17,10 @@
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize BLE Mesh module.
|
||||
* This API initializes provisioning capabilities and composition data information.
|
||||
@ -34,4 +38,20 @@
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp);
|
||||
|
||||
/**
|
||||
* @brief De-initialize BLE Mesh module.
|
||||
*
|
||||
* @note This function shall be invoked after esp_ble_mesh_client_model_deinit().
|
||||
*
|
||||
* @param[in] param: Pointer to the structure of BLE Mesh deinit parameters.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_deinit(esp_ble_mesh_deinit_param_t *param);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_BLE_MESH_COMMON_API_H_ */
|
||||
|
@ -17,6 +17,10 @@
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Get the model publish period, the unit is ms.
|
||||
*
|
||||
@ -51,7 +55,8 @@ uint16_t esp_ble_mesh_get_primary_element_address(void);
|
||||
* to 0x0000 in order to unsubscribe the model from the group.
|
||||
*
|
||||
*/
|
||||
uint16_t *esp_ble_mesh_is_model_subscribed_to_group(esp_ble_mesh_model_t *model, uint16_t group_addr);
|
||||
uint16_t *esp_ble_mesh_is_model_subscribed_to_group(esp_ble_mesh_model_t *model,
|
||||
uint16_t group_addr);
|
||||
|
||||
/**
|
||||
* @brief Find the BLE Mesh element pointer via the element address.
|
||||
@ -83,7 +88,7 @@ uint8_t esp_ble_mesh_get_element_count(void);
|
||||
*
|
||||
*/
|
||||
esp_ble_mesh_model_t *esp_ble_mesh_find_vendor_model(const esp_ble_mesh_elem_t *element,
|
||||
uint16_t company_id, uint16_t model_id);
|
||||
uint16_t company_id, uint16_t model_id);
|
||||
|
||||
/**
|
||||
* @brief Find the SIG model with the given element and Model id.
|
||||
@ -94,7 +99,8 @@ esp_ble_mesh_model_t *esp_ble_mesh_find_vendor_model(const esp_ble_mesh_elem_t *
|
||||
* @return Pointer to the SIG Model on success, or NULL on failure which means the SIG Model is not found.
|
||||
*
|
||||
*/
|
||||
esp_ble_mesh_model_t *esp_ble_mesh_find_sig_model(const esp_ble_mesh_elem_t *element, uint16_t model_id);
|
||||
esp_ble_mesh_model_t *esp_ble_mesh_find_sig_model(const esp_ble_mesh_elem_t *element,
|
||||
uint16_t model_id);
|
||||
|
||||
/**
|
||||
* @brief Get the Composition data which has been registered.
|
||||
@ -104,4 +110,106 @@ esp_ble_mesh_model_t *esp_ble_mesh_find_sig_model(const esp_ble_mesh_elem_t *ele
|
||||
*/
|
||||
const esp_ble_mesh_comp_t *esp_ble_mesh_get_composition_data(void);
|
||||
|
||||
/**
|
||||
* @brief A local model of node or Provisioner subscribes a group address.
|
||||
*
|
||||
* @note This function shall not be invoked before node is provisioned or Provisioner is enabled.
|
||||
*
|
||||
* @param[in] element_addr: Unicast address of the element to which the model belongs.
|
||||
* @param[in] company_id: A 16-bit company identifier.
|
||||
* @param[in] model_id: A 16-bit model identifier.
|
||||
* @param[in] group_addr: The group address to be subscribed.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_model_subscribe_group_addr(uint16_t element_addr, uint16_t company_id,
|
||||
uint16_t model_id, uint16_t group_addr);
|
||||
|
||||
/**
|
||||
* @brief A local model of node or Provisioner unsubscribes a group address.
|
||||
*
|
||||
* @note This function shall not be invoked before node is provisioned or Provisioner is enabled.
|
||||
*
|
||||
* @param[in] element_addr: Unicast address of the element to which the model belongs.
|
||||
* @param[in] company_id: A 16-bit company identifier.
|
||||
* @param[in] model_id: A 16-bit model identifier.
|
||||
* @param[in] group_addr: The subscribed group address.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_model_unsubscribe_group_addr(uint16_t element_addr, uint16_t company_id,
|
||||
uint16_t model_id, uint16_t group_addr);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Node to get the local NetKey.
|
||||
*
|
||||
* @param[in] net_idx: NetKey index.
|
||||
*
|
||||
* @return NetKey on success, or NULL on failure.
|
||||
*
|
||||
*/
|
||||
const uint8_t *esp_ble_mesh_node_get_local_net_key(uint16_t net_idx);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Node to get the local AppKey.
|
||||
*
|
||||
* @param[in] app_idx: AppKey index.
|
||||
*
|
||||
* @return AppKey on success, or NULL on failure.
|
||||
*
|
||||
*/
|
||||
const uint8_t *esp_ble_mesh_node_get_local_app_key(uint16_t app_idx);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Node to add a local NetKey.
|
||||
*
|
||||
* @param[in] net_key: NetKey to be added.
|
||||
* @param[in] net_idx: NetKey Index.
|
||||
*
|
||||
* @note This function can only be called after the device is provisioned.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_node_add_local_net_key(const uint8_t net_key[16], uint16_t net_idx);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Node to add a local AppKey.
|
||||
*
|
||||
* @param[in] app_key: AppKey to be added.
|
||||
* @param[in] net_idx: NetKey Index.
|
||||
* @param[in] app_idx: AppKey Index.
|
||||
*
|
||||
* @note The net_idx must be an existing one.
|
||||
* This function can only be called after the device is provisioned.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_node_add_local_app_key(const uint8_t app_key[16], uint16_t net_idx, uint16_t app_idx);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Node to bind AppKey to model locally.
|
||||
*
|
||||
* @param[in] element_addr: Node local element address
|
||||
* @param[in] company_id: Node local company id
|
||||
* @param[in] model_id: Node local model id
|
||||
* @param[in] app_idx: Node local appkey index
|
||||
*
|
||||
* @note If going to bind app_key with local vendor model, the company_id
|
||||
* shall be set to 0xFFFF.
|
||||
* This function can only be called after the device is provisioned.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_node_bind_app_key_to_local_model(uint16_t element_addr, uint16_t company_id,
|
||||
uint16_t model_id, uint16_t app_idx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_BLE_MESH_LOCAL_DATA_OPERATION_API_H_ */
|
||||
|
@ -17,6 +17,10 @@
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enable BLE Mesh device LPN functionality.
|
||||
*
|
||||
@ -58,4 +62,8 @@ esp_err_t esp_ble_mesh_lpn_disable(bool force);
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_lpn_poll(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_BLE_MESH_LOW_POWER_API_H_ */
|
||||
|
@ -17,9 +17,13 @@
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief: event, event code of user-defined model events; param, parameters of user-defined model events */
|
||||
typedef void (* esp_ble_mesh_model_cb_t)(esp_ble_mesh_model_cb_event_t event,
|
||||
esp_ble_mesh_model_cb_param_t *param);
|
||||
esp_ble_mesh_model_cb_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief Register BLE Mesh callback for user-defined models' operations.
|
||||
@ -75,6 +79,18 @@ esp_err_t esp_ble_mesh_model_msg_opcode_init(uint8_t *data, uint32_t opcode);
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_client_model_init(esp_ble_mesh_model_t *model);
|
||||
|
||||
/**
|
||||
* @brief De-initialize the user-defined client model.
|
||||
*
|
||||
* @note This function shall be invoked before esp_ble_mesh_deinit() is called.
|
||||
*
|
||||
* @param[in] model: Pointer of the Client model.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_client_model_deinit(esp_ble_mesh_model_t *model);
|
||||
|
||||
/**
|
||||
* @brief Send server model messages(such as server model status messages).
|
||||
*
|
||||
@ -88,8 +104,9 @@ esp_err_t esp_ble_mesh_client_model_init(esp_ble_mesh_model_t *model);
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_server_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
esp_ble_mesh_msg_ctx_t *ctx, uint32_t opcode,
|
||||
uint16_t length, uint8_t *data);
|
||||
esp_ble_mesh_msg_ctx_t *ctx,
|
||||
uint32_t opcode,
|
||||
uint16_t length, uint8_t *data);
|
||||
|
||||
/**
|
||||
* @brief Send client model message (such as model get, set, etc).
|
||||
@ -107,9 +124,11 @@ esp_err_t esp_ble_mesh_server_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_client_model_send_msg(esp_ble_mesh_model_t *model,
|
||||
esp_ble_mesh_msg_ctx_t *ctx, uint32_t opcode,
|
||||
uint16_t length, uint8_t *data, int32_t msg_timeout,
|
||||
bool need_rsp, esp_ble_mesh_dev_role_t device_role);
|
||||
esp_ble_mesh_msg_ctx_t *ctx,
|
||||
uint32_t opcode,
|
||||
uint16_t length, uint8_t *data,
|
||||
int32_t msg_timeout, bool need_rsp,
|
||||
esp_ble_mesh_dev_role_t device_role);
|
||||
|
||||
/**
|
||||
* @brief Send a model publication message.
|
||||
@ -150,8 +169,8 @@ esp_err_t esp_ble_mesh_model_publish(esp_ble_mesh_model_t *model, uint32_t opcod
|
||||
*
|
||||
*/
|
||||
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);
|
||||
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.
|
||||
@ -176,7 +195,7 @@ esp_err_t esp_ble_mesh_node_local_reset(void);
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_set_node_name(int index, const char *name);
|
||||
esp_err_t esp_ble_mesh_provisioner_set_node_name(uint16_t index, const char *name);
|
||||
|
||||
/**
|
||||
* @brief This function is called to get the node (provisioned device) name.
|
||||
@ -188,20 +207,119 @@ esp_err_t esp_ble_mesh_provisioner_set_node_name(int index, const char *name);
|
||||
* @return Node name on success, or NULL on failure.
|
||||
*
|
||||
*/
|
||||
const char *esp_ble_mesh_provisioner_get_node_name(int index);
|
||||
const char *esp_ble_mesh_provisioner_get_node_name(uint16_t index);
|
||||
|
||||
/**
|
||||
* @brief This function is called to get the node (provisioned device) index.
|
||||
*
|
||||
* @param[in] name: Name of the node (end by '\0').
|
||||
*
|
||||
* @return Node index on success, or (negative) error code from errno.h on failure.
|
||||
* @return Node index on success, or an invalid value (0xFFFF) on failure.
|
||||
*
|
||||
*/
|
||||
int esp_ble_mesh_provisioner_get_node_index(const char *name);
|
||||
uint16_t esp_ble_mesh_provisioner_get_node_index(const char *name);
|
||||
|
||||
/**
|
||||
* @brief This function is called to set the app key for the local BLE Mesh stack.
|
||||
* @brief This function is called to store the Composition Data of the node.
|
||||
*
|
||||
* @param[in] unicast_addr: Element address of the node
|
||||
* @param[in] data: Pointer of Composition Data
|
||||
* @param[in] length: Length of Composition Data
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_store_node_comp_data(uint16_t unicast_addr,
|
||||
uint8_t *data, uint16_t length);
|
||||
|
||||
/**
|
||||
* @brief This function is called to get the provisioned node information
|
||||
* with the node device uuid.
|
||||
*
|
||||
* @param[in] uuid: Device UUID of the node
|
||||
*
|
||||
* @return Pointer of the node info struct or NULL on failure.
|
||||
*
|
||||
*/
|
||||
esp_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_uuid(const uint8_t uuid[16]);
|
||||
|
||||
/**
|
||||
* @brief This function is called to get the provisioned node information
|
||||
* with the node unicast address.
|
||||
*
|
||||
* @param[in] unicast_addr: Unicast address of the node
|
||||
*
|
||||
* @return Pointer of the node info struct or NULL on failure.
|
||||
*
|
||||
*/
|
||||
esp_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_addr(uint16_t unicast_addr);
|
||||
|
||||
/**
|
||||
* @brief This function is called to get the provisioned node information
|
||||
* with the node name.
|
||||
*
|
||||
* @param[in] name: Name of the node (end by '\0').
|
||||
*
|
||||
* @return Pointer of the node info struct or NULL on failure.
|
||||
*
|
||||
*/
|
||||
esp_ble_mesh_node_t *esp_ble_mesh_provisioner_get_node_with_name(const char *name);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to get provisioned node count.
|
||||
*
|
||||
* @return Number of the provisioned nodes.
|
||||
*
|
||||
*/
|
||||
uint16_t esp_ble_mesh_provisioner_get_prov_node_count(void);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to get the entry of the node table.
|
||||
*
|
||||
* @note After invoking the function to get the entry of nodes, users can use the "for"
|
||||
* loop combined with the macro CONFIG_BLE_MESH_MAX_PROV_NODES to get each node's
|
||||
* information. Before trying to read the node's information, users need to check
|
||||
* if the node exists, i.e. if the *(esp_ble_mesh_node_t **node) is NULL.
|
||||
* For example:
|
||||
* ```
|
||||
* const esp_ble_mesh_node_t **entry = esp_ble_mesh_provisioner_get_node_table_entry();
|
||||
* for (int i = 0; i < CONFIG_BLE_MESH_MAX_PROV_NODES; i++) {
|
||||
* const esp_ble_mesh_node_t *node = entry[i];
|
||||
* if (node) {
|
||||
* ......
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @return Pointer to the start of the node table.
|
||||
*
|
||||
*/
|
||||
const esp_ble_mesh_node_t **esp_ble_mesh_provisioner_get_node_table_entry(void);
|
||||
|
||||
/**
|
||||
* @brief This function is called to delete the provisioned node information
|
||||
* with the node device uuid.
|
||||
*
|
||||
* @param[in] uuid: Device UUID of the node
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_delete_node_with_uuid(const uint8_t uuid[16]);
|
||||
|
||||
/**
|
||||
* @brief This function is called to delete the provisioned node information
|
||||
* with the node unicast address.
|
||||
*
|
||||
* @param[in] unicast_addr: Unicast address of the node
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_delete_node_with_addr(uint16_t unicast_addr);
|
||||
|
||||
/**
|
||||
* @brief This function is called to add a local AppKey for Provisioner.
|
||||
*
|
||||
* @param[in] app_key: The app key to be set for the local BLE Mesh stack.
|
||||
* @param[in] net_idx: The network key index.
|
||||
@ -215,7 +333,21 @@ int esp_ble_mesh_provisioner_get_node_index(const char *name);
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_add_local_app_key(const uint8_t app_key[16], uint16_t net_idx, uint16_t app_idx);
|
||||
esp_err_t esp_ble_mesh_provisioner_add_local_app_key(const uint8_t app_key[16],
|
||||
uint16_t net_idx, uint16_t app_idx);
|
||||
|
||||
/**
|
||||
* @brief This function is used to update a local AppKey for Provisioner.
|
||||
*
|
||||
* @param[in] app_key: Value of the AppKey.
|
||||
* @param[in] net_idx: Corresponding NetKey Index.
|
||||
* @param[in] app_idx: The AppKey Index
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_update_local_app_key(const uint8_t app_key[16],
|
||||
uint16_t net_idx, uint16_t app_idx);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to get the local app key value.
|
||||
@ -243,7 +375,7 @@ const uint8_t *esp_ble_mesh_provisioner_get_local_app_key(uint16_t net_idx, uint
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_bind_app_key_to_local_model(uint16_t element_addr, uint16_t app_idx,
|
||||
uint16_t model_id, uint16_t company_id);
|
||||
uint16_t model_id, uint16_t company_id);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to add local network key.
|
||||
@ -260,6 +392,17 @@ esp_err_t esp_ble_mesh_provisioner_bind_app_key_to_local_model(uint16_t element_
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_add_local_net_key(const uint8_t net_key[16], uint16_t net_idx);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to update a local network key.
|
||||
*
|
||||
* @param[in] net_key: Value of the NetKey.
|
||||
* @param[in] net_idx: The NetKey Index.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_update_local_net_key(const uint8_t net_key[16], uint16_t net_idx);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to get the local network key value.
|
||||
*
|
||||
@ -270,6 +413,231 @@ esp_err_t esp_ble_mesh_provisioner_add_local_net_key(const uint8_t net_key[16],
|
||||
*/
|
||||
const uint8_t *esp_ble_mesh_provisioner_get_local_net_key(uint16_t net_idx);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to enable or disable receiving
|
||||
* heartbeat messages.
|
||||
*
|
||||
* @note If enabling receiving heartbeat message successfully, the filter will
|
||||
* be an empty rejectlist by default, which means all heartbeat messages
|
||||
* received by the Provisioner will be reported to the application layer.
|
||||
*
|
||||
* @param[in] enable: Enable or disable receiving heartbeat messages.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_recv_heartbeat(bool enable);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to set the heartbeat filter type.
|
||||
*
|
||||
* @note 1. If the filter type is not the same with the current value, then all the
|
||||
* filter entries will be cleaned.
|
||||
* 2. If the previous type is rejectlist, and changed to acceptlist, then the
|
||||
* filter will be an empty acceptlist, which means no heartbeat messages
|
||||
* will be reported. Users need to add SRC or DST into the filter entry,
|
||||
* then heartbeat messages from the SRC or to the DST will be reported.
|
||||
*
|
||||
* @param[in] type: Heartbeat filter type (acceptlist or rejectlist).
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_set_heartbeat_filter_type(uint8_t type);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to add or remove a heartbeat filter entry.
|
||||
*
|
||||
* @note 1. If the operation is "ADD", the "hb_src" can be set to the SRC (can only be a
|
||||
* unicast address) of heartbeat messages, and the "hb_dst" can be set to the
|
||||
* DST (unicast address or group address), at least one of them needs to be set.
|
||||
* - If only one of them is set, the filter entry will only use the configured
|
||||
* SRC or DST to filter heartbeat messages.
|
||||
* - If both of them are set, the SRC and DST will both be used to decide if a
|
||||
* heartbeat message will be handled.
|
||||
* - If SRC or DST already exists in some filter entry, then the corresponding
|
||||
* entry will be cleaned firstly, then a new entry will be allocated to store
|
||||
* the information.
|
||||
* 2. If the operation is "REMOVE", the "hb_src" can be set to the SRC (can only be
|
||||
* a unicast address) of heartbeat messages, and the "hb_dst" can be set to the
|
||||
* DST (unicast address or group address), at least one of them needs to be set.
|
||||
* - The filter entry with the same SRC or DST will be removed.
|
||||
*
|
||||
* @param[in] op: Add or REMOVE
|
||||
* @param[in] info: Heartbeat filter entry information, including:
|
||||
* hb_src - Heartbeat source address;
|
||||
* hb_dst - Heartbeat destination address;
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_set_heartbeat_filter_info(uint8_t op, esp_ble_mesh_heartbeat_filter_info_t *info);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to directly erase the mesh
|
||||
* information from nvs namespace.
|
||||
*
|
||||
* @note This function can be invoked when the mesh stack is not initialized
|
||||
* or has been de-initialized.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_direct_erase_settings(void);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to open a nvs namespace
|
||||
* for storing mesh information.
|
||||
*
|
||||
* @note Before open another nvs namespace, the previously opened nvs
|
||||
* namespace must be closed firstly.
|
||||
*
|
||||
* @param[in] index: Settings index.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_open_settings_with_index(uint8_t index);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to open a nvs namespace
|
||||
* for storing mesh information.
|
||||
*
|
||||
* @note Before open another nvs namespace, the previously opened nvs
|
||||
* namespace must be closed firstly.
|
||||
*
|
||||
* @param[in] uid: Settings user id.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_open_settings_with_uid(const char *uid);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to close a nvs namespace
|
||||
* which is opened previously for storing mesh information.
|
||||
*
|
||||
* @note 1. Before closing the nvs namespace, it must be open.
|
||||
* 2. When the function is invoked, the Provisioner functionality
|
||||
* will be disabled firstly, and:
|
||||
* a) If the "erase" flag is set to false, the mesh information
|
||||
* will be cleaned (e.g. removing NetKey, AppKey, nodes, etc)
|
||||
* from the mesh stack.
|
||||
* b) If the "erase" flag is set to true, the mesh information
|
||||
* stored in the nvs namespace will also be erased besides
|
||||
* been cleaned from the mesh stack.
|
||||
* 3. If Provisioner tries to work properly again, we can invoke the
|
||||
* open function to open a new nvs namespace or a previously added
|
||||
* one, and restore the mesh information from it if not erased.
|
||||
* 4. The working process shall be as following:
|
||||
* a) Open settings A
|
||||
* b) Start to provision and control nodes
|
||||
* c) Close settings A
|
||||
* d) Open settings B
|
||||
* e) Start to provision and control other nodes
|
||||
* f) Close settings B
|
||||
* g) ......
|
||||
*
|
||||
* @param[in] index: Settings index.
|
||||
* @param[in] erase: Indicate if erasing mesh information.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_close_settings_with_index(uint8_t index, bool erase);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to close a nvs namespace
|
||||
* which is opened previously for storing mesh information.
|
||||
*
|
||||
* @note 1. Before closing the nvs namespace, it must be open.
|
||||
* 2. When the function is invoked, the Provisioner functionality
|
||||
* will be disabled firstly, and:
|
||||
* a) If the "erase" flag is set to false, the mesh information
|
||||
* will be cleaned (e.g. removing NetKey, AppKey, nodes, etc)
|
||||
* from the mesh stack.
|
||||
* b) If the "erase" flag is set to true, the mesh information
|
||||
* stored in the nvs namespace will also be erased besides
|
||||
* been cleaned from the mesh stack.
|
||||
* 3. If Provisioner tries to work properly again, we can invoke the
|
||||
* open function to open a new nvs namespace or a previously added
|
||||
* one, and restore the mesh information from it if not erased.
|
||||
* 4. The working process shall be as following:
|
||||
* a) Open settings A
|
||||
* b) Start to provision and control nodes
|
||||
* c) Close settings A
|
||||
* d) Open settings B
|
||||
* e) Start to provision and control other nodes
|
||||
* f) Close settings B
|
||||
* g) ......
|
||||
*
|
||||
* @param[in] uid: Settings user id.
|
||||
* @param[in] erase: Indicate if erasing mesh information.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_close_settings_with_uid(const char *uid, bool erase);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to erase the mesh information
|
||||
* and settings user id from a nvs namespace.
|
||||
*
|
||||
* @note When this function is called, the nvs namespace must not be open.
|
||||
* This function is used to erase the mesh information and settings
|
||||
* user id which are not used currently.
|
||||
*
|
||||
* @param[in] index: Settings index.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_delete_settings_with_index(uint8_t index);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to erase the mesh information
|
||||
* and settings user id from a nvs namespace.
|
||||
*
|
||||
* @note When this function is called, the nvs namespace must not be open.
|
||||
* This function is used to erase the mesh information and settings
|
||||
* user id which are not used currently.
|
||||
*
|
||||
* @param[in] uid: Settings user id.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_delete_settings_with_uid(const char *uid);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to get settings user id.
|
||||
*
|
||||
* @param[in] index: Settings index.
|
||||
*
|
||||
* @return Setting user id on success or NULL on failure.
|
||||
*
|
||||
*/
|
||||
const char *esp_ble_mesh_provisioner_get_settings_uid(uint8_t index);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to get settings index.
|
||||
*
|
||||
* @param[in] uid: Settings user id.
|
||||
*
|
||||
* @return Settings index.
|
||||
*
|
||||
*/
|
||||
uint8_t esp_ble_mesh_provisioner_get_settings_index(const char *uid);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to get the number of free
|
||||
* settings user id.
|
||||
*
|
||||
* @return Number of free settings user id.
|
||||
*
|
||||
*/
|
||||
uint8_t esp_ble_mesh_provisioner_get_free_settings_count(void);
|
||||
|
||||
/**
|
||||
* @brief This function is called to get fast provisioning application key.
|
||||
*
|
||||
@ -281,4 +649,8 @@ const uint8_t *esp_ble_mesh_provisioner_get_local_net_key(uint16_t net_idx);
|
||||
*/
|
||||
const uint8_t *esp_ble_mesh_get_fast_prov_app_key(uint16_t net_idx, uint16_t app_idx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_BLE_MESH_NETWORKING_API_H_ */
|
||||
|
@ -17,6 +17,10 @@
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @brief: event, event code of provisioning events; param, parameters of provisioning events */
|
||||
typedef void (* esp_ble_mesh_prov_cb_t)(esp_ble_mesh_prov_cb_event_t event,
|
||||
esp_ble_mesh_prov_cb_param_t *param);
|
||||
@ -72,7 +76,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 +128,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.
|
||||
@ -228,15 +232,42 @@ esp_err_t esp_ble_mesh_provisioner_prov_disable(esp_ble_mesh_prov_bearer_t beare
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_add_unprov_dev(esp_ble_mesh_unprov_dev_add_t *add_dev,
|
||||
esp_ble_mesh_dev_add_flag_t flags);
|
||||
esp_ble_mesh_dev_add_flag_t flags);
|
||||
|
||||
/** @brief Provision an unprovisioned device and assign a fixed unicast address for it in advance.
|
||||
*
|
||||
* @param[in] uuid: Device UUID of the unprovisioned device
|
||||
* @param[in] addr: Device address of the unprovisioned device
|
||||
* @param[in] addr_type: Device address type of the unprovisioned device
|
||||
* @param[in] bearer: Provisioning bearer going to be used by Provisioner
|
||||
* @param[in] oob_info: OOB info of the unprovisioned device
|
||||
* @param[in] unicast_addr: Unicast address going to be allocated for the unprovisioned device
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*
|
||||
* @note: 1. Currently address type only supports public address and static random address.
|
||||
* 2. Bearer must be equal to ESP_BLE_MESH_PROV_ADV or ESP_BLE_MESH_PROV_GATT, since
|
||||
* Provisioner will start to provision a device immediately once this function is
|
||||
* invoked. And the input bearer must be identical with the one within the parameters
|
||||
* of the ESP_BLE_MESH_PROVISIONER_RECV_UNPROV_ADV_PKT_EVT event.
|
||||
* 3. If this function is used by a Provisioner to provision devices, the application
|
||||
* should take care of the assigned unicast address and avoid overlap of the unicast
|
||||
* addresses of different nodes.
|
||||
* 4. Recommend to use only one of the functions "esp_ble_mesh_provisioner_add_unprov_dev"
|
||||
* and "esp_ble_mesh_provisioner_prov_device_with_addr" by a Provisioner.
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_prov_device_with_addr(const uint8_t uuid[16],
|
||||
esp_ble_mesh_bd_addr_t addr,
|
||||
esp_ble_mesh_addr_type_t addr_type,
|
||||
esp_ble_mesh_prov_bearer_t bearer,
|
||||
uint16_t oob_info, uint16_t unicast_addr);
|
||||
|
||||
/**
|
||||
* @brief Delete device from queue, reset current provisioning link and reset the node.
|
||||
* @brief Delete device from queue, and reset current provisioning link with the device.
|
||||
*
|
||||
* @note If the device is in the queue, remove it from the queue; if the device is being
|
||||
* provisioned, terminate the provisioning procedure; if the device has already
|
||||
* been provisioned, reset the device. And either one of the addr or device UUID
|
||||
* can be input.
|
||||
* @note If the device is in the queue, remove it from the queue; if the device is
|
||||
* being provisioned, terminate the provisioning procedure. Either one of the
|
||||
* device address or device UUID can be used as input.
|
||||
*
|
||||
* @param[in] del_dev: Pointer to a struct containing the device information.
|
||||
*
|
||||
@ -260,8 +291,8 @@ esp_err_t esp_ble_mesh_provisioner_delete_dev(esp_ble_mesh_device_delete_t *del_
|
||||
*
|
||||
*/
|
||||
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);
|
||||
const uint8_t adv_type, const uint8_t *dev_uuid,
|
||||
uint16_t oob_info, esp_ble_mesh_prov_bearer_t bearer);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to set the part of the device UUID
|
||||
@ -277,7 +308,7 @@ typedef void (*esp_ble_mesh_prov_adv_cb_t)(const esp_ble_mesh_bd_addr_t addr, co
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_set_dev_uuid_match(const uint8_t *match_val, uint8_t match_len,
|
||||
uint8_t offset, bool prov_after_match);
|
||||
uint8_t offset, bool prov_after_match);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to set provisioning data information
|
||||
@ -290,6 +321,41 @@ esp_err_t esp_ble_mesh_provisioner_set_dev_uuid_match(const uint8_t *match_val,
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_set_prov_data_info(esp_ble_mesh_prov_data_info_t *prov_data_info);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to set static oob value used for provisioning.
|
||||
*
|
||||
* @note The Bluetooth SIG recommends that mesh implementations enforce a randomly selected
|
||||
* AuthValue using all of the available bits, where permitted by the implementation.
|
||||
* A large entropy helps ensure that a brute-force of the AuthValue, even a static
|
||||
* AuthValue, cannot normally be completed in a reasonable time (CVE-2020-26557).
|
||||
*
|
||||
* @param[in] value: Pointer to the static oob value.
|
||||
* @param[in] length: Length of the static oob value.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_set_static_oob_value(const uint8_t *value, uint8_t length);
|
||||
|
||||
/**
|
||||
* @brief This function is called by Provisioner to set own Primary element address.
|
||||
*
|
||||
* @note This API must be invoked when BLE Mesh initialization is completed successfully,
|
||||
* and can be invoked before Provisioner functionality is enabled.
|
||||
* Once this API is invoked successfully, the prov_unicast_addr value in the struct
|
||||
* esp_ble_mesh_prov_t will be ignored, and Provisioner will use this address as its
|
||||
* own primary element address.
|
||||
* And if the unicast address going to assigned for the next unprovisioned device is
|
||||
* smaller than the input address + element number of Provisioner, then the address
|
||||
* for the next unprovisioned device will be recalculated internally.
|
||||
*
|
||||
* @param[in] addr: Unicast address of the Primary element of Provisioner.
|
||||
*
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_provisioner_set_primary_elem_addr(uint16_t addr);
|
||||
|
||||
/**
|
||||
* @brief This function is called to set provisioning data information before starting
|
||||
* fast provisioning.
|
||||
@ -311,4 +377,8 @@ esp_err_t esp_ble_mesh_set_fast_prov_info(esp_ble_mesh_fast_prov_info_t *fast_pr
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_set_fast_prov_action(esp_ble_mesh_fast_prov_action_t action);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_BLE_MESH_PROVISIONING_API_H_ */
|
||||
|
@ -17,6 +17,10 @@
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enable advertising with Node Identity.
|
||||
*
|
||||
@ -61,7 +65,8 @@ esp_err_t esp_ble_mesh_proxy_gatt_disable(void);
|
||||
*
|
||||
*/
|
||||
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);
|
||||
esp_ble_mesh_addr_type_t addr_type,
|
||||
uint16_t net_idx);
|
||||
|
||||
/**
|
||||
* @brief Proxy Client terminates a connection with the Proxy Server.
|
||||
@ -83,8 +88,8 @@ esp_err_t esp_ble_mesh_proxy_client_disconnect(uint8_t conn_handle);
|
||||
* @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);
|
||||
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.
|
||||
@ -97,8 +102,8 @@ esp_err_t esp_ble_mesh_proxy_client_set_filter_type(uint8_t conn_handle,
|
||||
* @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);
|
||||
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.
|
||||
@ -111,8 +116,12 @@ esp_err_t esp_ble_mesh_proxy_client_add_filter_addr(uint8_t conn_handle,
|
||||
* @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);
|
||||
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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_BLE_MESH_PROXY_API_H_ */
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -14,12 +14,12 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "btc_ble_mesh_config_model.h"
|
||||
#include "esp_ble_mesh_config_model_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_CFG_CLI
|
||||
esp_err_t esp_ble_mesh_register_config_client_callback(esp_ble_mesh_cfg_client_cb_t callback)
|
||||
{
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
@ -27,20 +27,35 @@ esp_err_t esp_ble_mesh_register_config_client_callback(esp_ble_mesh_cfg_client_c
|
||||
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)
|
||||
static bool config_client_get_need_param(esp_ble_mesh_opcode_t opcode)
|
||||
{
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_CONFIG_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
switch (opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_LPN_POLLTIMEOUT_GET:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
esp_ble_mesh_cfg_client_get_state_t *get_state)
|
||||
{
|
||||
btc_ble_mesh_config_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !get_state) {
|
||||
if (params == NULL || params->model == NULL ||
|
||||
params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
!ESP_BLE_MESH_ADDR_IS_UNICAST(params->ctx.addr) ||
|
||||
(config_client_get_need_param(params->opcode) && get_state == NULL)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -57,12 +72,15 @@ esp_err_t esp_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_
|
||||
}
|
||||
|
||||
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)
|
||||
esp_ble_mesh_cfg_client_set_state_t *set_state)
|
||||
{
|
||||
btc_ble_mesh_config_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !set_state) {
|
||||
if (params == NULL || params->model == NULL ||
|
||||
params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
!ESP_BLE_MESH_ADDR_IS_UNICAST(params->ctx.addr) ||
|
||||
(params->opcode != ESP_BLE_MESH_MODEL_OP_NODE_RESET && set_state == NULL)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -77,3 +95,11 @@ esp_err_t esp_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_
|
||||
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);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_CFG_CLI */
|
||||
|
||||
esp_err_t esp_ble_mesh_register_config_server_callback(esp_ble_mesh_cfg_server_cb_t callback)
|
||||
{
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_CONFIG_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
@ -14,12 +14,12 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "btc_ble_mesh_generic_model.h"
|
||||
#include "esp_ble_mesh_generic_model_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_GENERIC_CLIENT
|
||||
esp_err_t esp_ble_mesh_register_generic_client_callback(esp_ble_mesh_generic_client_cb_t callback)
|
||||
{
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
@ -27,13 +27,30 @@ esp_err_t esp_ble_mesh_register_generic_client_callback(esp_ble_mesh_generic_cli
|
||||
return (btc_profile_cb_set(BTC_PID_GENERIC_CLIENT, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
static bool generic_client_get_need_param(esp_ble_mesh_opcode_t opcode)
|
||||
{
|
||||
switch (opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTY_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_generic_client_get_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_generic_client_get_state_t *get_state)
|
||||
esp_ble_mesh_generic_client_get_state_t *get_state)
|
||||
{
|
||||
btc_ble_mesh_generic_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !get_state) {
|
||||
if (params == NULL || params->model == NULL ||
|
||||
params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED ||
|
||||
(generic_client_get_need_param(params->opcode) && get_state == NULL)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -50,12 +67,15 @@ 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)
|
||||
esp_ble_mesh_generic_client_set_state_t *set_state)
|
||||
{
|
||||
btc_ble_mesh_generic_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !set_state) {
|
||||
if (params == NULL || params->model == NULL || set_state == NULL ||
|
||||
params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -70,10 +90,13 @@ 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);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_GENERIC_CLIENT */
|
||||
|
||||
#if CONFIG_BLE_MESH_GENERIC_SERVER
|
||||
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);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_GENERIC_SERVER */
|
||||
|
@ -14,12 +14,12 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "btc_ble_mesh_health_model.h"
|
||||
#include "esp_ble_mesh_health_model_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_HEALTH_CLI
|
||||
esp_err_t esp_ble_mesh_register_health_client_callback(esp_ble_mesh_health_client_cb_t callback)
|
||||
{
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
@ -27,20 +27,17 @@ esp_err_t esp_ble_mesh_register_health_client_callback(esp_ble_mesh_health_clien
|
||||
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_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_HEALTH_SERVER, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_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_get_state_t *get_state)
|
||||
{
|
||||
btc_ble_mesh_health_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !get_state) {
|
||||
if (params == NULL || params->model == NULL ||
|
||||
params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED ||
|
||||
(params->opcode == ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET && get_state == NULL)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -57,12 +54,15 @@ esp_err_t esp_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_
|
||||
}
|
||||
|
||||
esp_err_t esp_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_set_state_t *set_state)
|
||||
{
|
||||
btc_ble_mesh_health_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !set_state) {
|
||||
if (params == NULL || params->model == NULL || set_state == NULL ||
|
||||
params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -77,6 +77,15 @@ esp_err_t esp_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_health_client_args_t), btc_ble_mesh_health_client_arg_deep_copy)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_HEALTH_CLI */
|
||||
|
||||
#if CONFIG_BLE_MESH_HEALTH_SRV
|
||||
esp_err_t esp_ble_mesh_register_health_server_callback(esp_ble_mesh_health_server_cb_t callback)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_health_server_fault_update(esp_ble_mesh_elem_t *element)
|
||||
{
|
||||
@ -97,3 +106,4 @@ esp_err_t esp_ble_mesh_health_server_fault_update(esp_ble_mesh_elem_t *element)
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_health_server_args_t), NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_HEALTH_SRV */
|
||||
|
@ -14,12 +14,12 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "btc_ble_mesh_lighting_model.h"
|
||||
#include "esp_ble_mesh_lighting_model_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_LIGHTING_CLIENT
|
||||
esp_err_t esp_ble_mesh_register_light_client_callback(esp_ble_mesh_light_client_cb_t callback)
|
||||
{
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
@ -28,12 +28,16 @@ esp_err_t esp_ble_mesh_register_light_client_callback(esp_ble_mesh_light_client_
|
||||
}
|
||||
|
||||
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)
|
||||
esp_ble_mesh_light_client_get_state_t *get_state)
|
||||
{
|
||||
btc_ble_mesh_lighting_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !get_state) {
|
||||
if (params == NULL || params->model == NULL ||
|
||||
params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED ||
|
||||
(params->opcode == ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET && get_state == NULL)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -50,12 +54,15 @@ esp_err_t esp_ble_mesh_light_client_get_state(esp_ble_mesh_client_common_param_t
|
||||
}
|
||||
|
||||
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)
|
||||
esp_ble_mesh_light_client_set_state_t *set_state)
|
||||
{
|
||||
btc_ble_mesh_lighting_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !set_state) {
|
||||
if (params == NULL || params->model == NULL || set_state == NULL ||
|
||||
params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -70,10 +77,13 @@ esp_err_t esp_ble_mesh_light_client_set_state(esp_ble_mesh_client_common_param_t
|
||||
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);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_LIGHTING_CLIENT */
|
||||
|
||||
#if CONFIG_BLE_MESH_LIGHTING_SERVER
|
||||
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);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_LIGHTING_SERVER */
|
||||
|
@ -14,12 +14,12 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "btc_ble_mesh_sensor_model.h"
|
||||
#include "esp_ble_mesh_sensor_model_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_SENSOR_CLI
|
||||
esp_err_t esp_ble_mesh_register_sensor_client_callback(esp_ble_mesh_sensor_client_cb_t callback)
|
||||
{
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
@ -28,12 +28,15 @@ esp_err_t esp_ble_mesh_register_sensor_client_callback(esp_ble_mesh_sensor_clien
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_sensor_client_get_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_sensor_client_get_state_t *get_state)
|
||||
esp_ble_mesh_sensor_client_get_state_t *get_state)
|
||||
{
|
||||
btc_ble_mesh_sensor_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !get_state) {
|
||||
if (params == NULL || params->model == NULL || get_state == NULL ||
|
||||
params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -50,12 +53,15 @@ 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)
|
||||
esp_ble_mesh_sensor_client_set_state_t *set_state)
|
||||
{
|
||||
btc_ble_mesh_sensor_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !set_state) {
|
||||
if (params == NULL || params->model == NULL || set_state == NULL ||
|
||||
params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -70,12 +76,13 @@ esp_err_t esp_ble_mesh_sensor_client_set_state(esp_ble_mesh_client_common_param_
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_sensor_client_args_t), btc_ble_mesh_sensor_client_arg_deep_copy)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SENSOR_CLI */
|
||||
|
||||
#if CONFIG_BLE_MESH_SENSOR_SERVER
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_SENSOR_SERVER */
|
||||
|
@ -14,12 +14,12 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "btc/btc_task.h"
|
||||
#include "btc/btc_manage.h"
|
||||
|
||||
#include "btc_ble_mesh_time_scene_model.h"
|
||||
#include "esp_ble_mesh_time_scene_model_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_TIME_SCENE_CLIENT
|
||||
esp_err_t esp_ble_mesh_register_time_scene_client_callback(esp_ble_mesh_time_scene_client_cb_t callback)
|
||||
{
|
||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||
@ -28,12 +28,16 @@ esp_err_t esp_ble_mesh_register_time_scene_client_callback(esp_ble_mesh_time_sce
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_mesh_time_scene_client_get_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_time_scene_client_get_state_t *get_state)
|
||||
esp_ble_mesh_time_scene_client_get_state_t *get_state)
|
||||
{
|
||||
btc_ble_mesh_time_scene_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !get_state) {
|
||||
if (params == NULL || params->model == NULL ||
|
||||
params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED ||
|
||||
(params->opcode == ESP_BLE_MESH_MODEL_OP_SCHEDULER_ACT_GET && get_state == NULL)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -50,12 +54,15 @@ 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)
|
||||
esp_ble_mesh_time_scene_client_set_state_t *set_state)
|
||||
{
|
||||
btc_ble_mesh_time_scene_client_args_t arg = {0};
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
if (!params || !params->model || !params->ctx.addr || !set_state) {
|
||||
if (params == NULL || params->model == NULL || set_state == NULL ||
|
||||
params->ctx.net_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.app_idx == ESP_BLE_MESH_KEY_UNUSED ||
|
||||
params->ctx.addr == ESP_BLE_MESH_ADDR_UNASSIGNED) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@ -70,11 +77,13 @@ esp_err_t esp_ble_mesh_time_scene_client_set_state(esp_ble_mesh_client_common_pa
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_time_scene_client_args_t), btc_ble_mesh_time_scene_client_arg_deep_copy)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_TIME_SCENE_CLIENT */
|
||||
|
||||
#if CONFIG_BLE_MESH_TIME_SCENE_SERVER
|
||||
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);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_TIME_SCENE_SERVER */
|
||||
|
@ -17,6 +17,10 @@
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_CFG_SRV
|
||||
*
|
||||
* @brief Define a new Config Server Model.
|
||||
@ -752,7 +756,7 @@ typedef enum {
|
||||
* @param param: Pointer to callback parameter
|
||||
*/
|
||||
typedef void (* esp_ble_mesh_cfg_client_cb_t)(esp_ble_mesh_cfg_client_cb_event_t event,
|
||||
esp_ble_mesh_cfg_client_cb_param_t *param);
|
||||
esp_ble_mesh_cfg_client_cb_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief Configuration Server Model callback function type
|
||||
@ -760,7 +764,7 @@ typedef void (* esp_ble_mesh_cfg_client_cb_t)(esp_ble_mesh_cfg_client_cb_event_t
|
||||
* @param param: Pointer to callback parameter
|
||||
*/
|
||||
typedef void (* esp_ble_mesh_cfg_server_cb_t)(esp_ble_mesh_cfg_server_cb_event_t event,
|
||||
esp_ble_mesh_cfg_server_cb_param_t *param);
|
||||
esp_ble_mesh_cfg_server_cb_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief Register BLE Mesh Config Client Model callback.
|
||||
@ -796,7 +800,7 @@ esp_err_t esp_ble_mesh_register_config_server_callback(esp_ble_mesh_cfg_server_c
|
||||
*
|
||||
*/
|
||||
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);
|
||||
esp_ble_mesh_cfg_client_get_state_t *get_state);
|
||||
|
||||
/**
|
||||
* @brief Set the value of the Configuration Server Model states using the Config Client Model set messages.
|
||||
@ -812,7 +816,11 @@ esp_err_t esp_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_
|
||||
*
|
||||
*/
|
||||
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);
|
||||
esp_ble_mesh_cfg_client_set_state_t *set_state);
|
||||
|
||||
#endif /** _ESP_BLE_MESH_CONFIG_MODEL_API_H_ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_BLE_MESH_CONFIG_MODEL_API_H_ */
|
||||
|
||||
|
@ -21,6 +21,10 @@
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_GEN_ONOFF_CLI
|
||||
*
|
||||
* @brief Define a new Generic OnOff Client Model.
|
||||
@ -256,7 +260,7 @@ typedef struct {
|
||||
/** Parameters of Generic Admin Property Set. */
|
||||
typedef struct {
|
||||
uint16_t property_id; /*!< Property ID identifying a Generic Admin Property */
|
||||
uint8_t user_access; /*!< Enumeration indicating user accessn */
|
||||
uint8_t user_access; /*!< Enumeration indicating user access */
|
||||
struct net_buf_simple *property_value; /*!< Raw value for the Admin Property */
|
||||
} esp_ble_mesh_gen_admin_property_set_t;
|
||||
|
||||
@ -363,10 +367,10 @@ typedef struct {
|
||||
|
||||
/** Parameters of Generic Battery Status. */
|
||||
typedef struct {
|
||||
u32_t battery_level : 8; /*!< Value of Generic Battery Level state */
|
||||
u32_t time_to_discharge : 24; /*!< Value of Generic Battery Time to Discharge state */
|
||||
u32_t time_to_charge : 24; /*!< Value of Generic Battery Time to Charge state */
|
||||
u32_t flags : 8; /*!< Value of Generic Battery Flags state */
|
||||
uint32_t battery_level : 8; /*!< Value of Generic Battery Level state */
|
||||
uint32_t time_to_discharge : 24; /*!< Value of Generic Battery Time to Discharge state */
|
||||
uint32_t time_to_charge : 24; /*!< Value of Generic Battery Time to Charge state */
|
||||
uint32_t flags : 8; /*!< Value of Generic Battery Flags state */
|
||||
} esp_ble_mesh_gen_battery_status_cb_t;
|
||||
|
||||
/** Parameters of Generic Location Global Status. */
|
||||
@ -479,7 +483,7 @@ typedef enum {
|
||||
* @param param: Pointer to callback parameter
|
||||
*/
|
||||
typedef void (* esp_ble_mesh_generic_client_cb_t)(esp_ble_mesh_generic_client_cb_event_t event,
|
||||
esp_ble_mesh_generic_client_cb_param_t *param);
|
||||
esp_ble_mesh_generic_client_cb_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief Register BLE Mesh Generic Client Model callback.
|
||||
@ -505,7 +509,7 @@ esp_err_t esp_ble_mesh_register_generic_client_callback(esp_ble_mesh_generic_cli
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_generic_client_get_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_generic_client_get_state_t *get_state);
|
||||
esp_ble_mesh_generic_client_get_state_t *get_state);
|
||||
|
||||
/**
|
||||
* @brief Set the value of Generic Server Model states using the Generic Client Model set messages.
|
||||
@ -521,7 +525,7 @@ 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);
|
||||
esp_ble_mesh_generic_client_set_state_t *set_state);
|
||||
|
||||
/**
|
||||
* @brief Generic Server Models related context.
|
||||
@ -1281,7 +1285,7 @@ typedef enum {
|
||||
* @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);
|
||||
esp_ble_mesh_generic_server_cb_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief Register BLE Mesh Generic Server Model callback.
|
||||
@ -1293,5 +1297,9 @@ typedef void (* esp_ble_mesh_generic_server_cb_t)(esp_ble_mesh_generic_server_cb
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_register_generic_server_callback(esp_ble_mesh_generic_server_cb_t callback);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_BLE_MESH_GENERIC_MODEL_API_H_ */
|
||||
|
||||
|
@ -17,6 +17,10 @@
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_HEALTH_SRV
|
||||
*
|
||||
* @brief Define a new Health Server Model.
|
||||
@ -331,7 +335,7 @@ typedef enum {
|
||||
* @param param: Pointer to callback parameter
|
||||
*/
|
||||
typedef void (* esp_ble_mesh_health_client_cb_t)(esp_ble_mesh_health_client_cb_event_t event,
|
||||
esp_ble_mesh_health_client_cb_param_t *param);
|
||||
esp_ble_mesh_health_client_cb_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief Health Server Model callback function type
|
||||
@ -339,7 +343,7 @@ typedef void (* esp_ble_mesh_health_client_cb_t)(esp_ble_mesh_health_client_cb_e
|
||||
* @param param: Pointer to callback parameter
|
||||
*/
|
||||
typedef void (* esp_ble_mesh_health_server_cb_t)(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 *param);
|
||||
|
||||
/**
|
||||
* @brief Register BLE Mesh Health Model callback, the callback will report Health Client & Server Model events.
|
||||
@ -375,7 +379,7 @@ esp_err_t esp_ble_mesh_register_health_server_callback(esp_ble_mesh_health_serve
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_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_get_state_t *get_state);
|
||||
|
||||
/**
|
||||
* @brief This function is called to set the Health Server states using the Health Client Model set messages.
|
||||
@ -391,7 +395,7 @@ esp_err_t esp_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_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_set_state_t *set_state);
|
||||
|
||||
/**
|
||||
* @brief This function is called by the Health Server Model to update the context of its Health Current status.
|
||||
@ -403,4 +407,8 @@ esp_err_t esp_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_health_server_fault_update(esp_ble_mesh_elem_t *element);
|
||||
|
||||
#endif /** _ESP_BLE_MESH_HEALTH_MODEL_API_H_ */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_BLE_MESH_HEALTH_MODEL_API_H_ */
|
||||
|
@ -21,6 +21,10 @@
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_LIGHT_LIGHTNESS_CLI
|
||||
*
|
||||
* @brief Define a new Light Lightness Client Model.
|
||||
@ -535,7 +539,7 @@ typedef enum {
|
||||
* @param param: Pointer to callback parameter
|
||||
*/
|
||||
typedef void (* esp_ble_mesh_light_client_cb_t)(esp_ble_mesh_light_client_cb_event_t event,
|
||||
esp_ble_mesh_light_client_cb_param_t *param);
|
||||
esp_ble_mesh_light_client_cb_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief Register BLE Mesh Light Client Model callback.
|
||||
@ -561,7 +565,7 @@ esp_err_t esp_ble_mesh_register_light_client_callback(esp_ble_mesh_light_client_
|
||||
*
|
||||
*/
|
||||
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);
|
||||
esp_ble_mesh_light_client_get_state_t *get_state);
|
||||
|
||||
/**
|
||||
* @brief Set the value of Light Server Model states using the Light Client Model set messages.
|
||||
@ -577,7 +581,7 @@ esp_err_t esp_ble_mesh_light_client_get_state(esp_ble_mesh_client_common_param_t
|
||||
*
|
||||
*/
|
||||
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);
|
||||
esp_ble_mesh_light_client_set_state_t *set_state);
|
||||
|
||||
/**
|
||||
* @brief Lighting Server Models related context.
|
||||
@ -1061,7 +1065,7 @@ typedef struct {
|
||||
* Occupancy state upon receiving a Sensor Status message from an
|
||||
* occupancy sensor.
|
||||
*/
|
||||
uint32_t time_occupancy_delay; /*!< The value of Light LC Time Occupany Delay state */
|
||||
uint32_t time_occupancy_delay; /*!< The value of Light LC Time Occupancy Delay state */
|
||||
/**
|
||||
* A timing state that determines the time the controlled lights fade
|
||||
* to the level determined by the Light LC Lightness On state.
|
||||
@ -1341,7 +1345,7 @@ typedef struct {
|
||||
|
||||
/** Parameter of Light LC Occupancy Mode state change event */
|
||||
typedef struct {
|
||||
uint8_t mode; /*!< The value of Light LC Occupany Mode state */
|
||||
uint8_t mode; /*!< The value of Light LC Occupancy Mode state */
|
||||
} esp_ble_mesh_state_change_light_lc_om_set_t;
|
||||
|
||||
/** Parameter of Light LC Light OnOff state change event */
|
||||
@ -1659,7 +1663,7 @@ typedef enum {
|
||||
* @param param: Pointer to callback parameter
|
||||
*/
|
||||
typedef void (* esp_ble_mesh_lighting_server_cb_t)(esp_ble_mesh_lighting_server_cb_event_t event,
|
||||
esp_ble_mesh_lighting_server_cb_param_t *param);
|
||||
esp_ble_mesh_lighting_server_cb_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief Register BLE Mesh Lighting Server Model callback.
|
||||
@ -1671,5 +1675,9 @@ typedef void (* esp_ble_mesh_lighting_server_cb_t)(esp_ble_mesh_lighting_server_
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_register_lighting_server_callback(esp_ble_mesh_lighting_server_cb_t callback);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_BLE_MESH_LIGHTING_MODEL_API_H_ */
|
||||
|
||||
|
@ -21,6 +21,10 @@
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_SENSOR_CLI
|
||||
*
|
||||
* @brief Define a new Sensor Client Model.
|
||||
@ -211,7 +215,7 @@ typedef enum {
|
||||
* @param param: Pointer to callback parameter
|
||||
*/
|
||||
typedef void (* esp_ble_mesh_sensor_client_cb_t)(esp_ble_mesh_sensor_client_cb_event_t event,
|
||||
esp_ble_mesh_sensor_client_cb_param_t *param);
|
||||
esp_ble_mesh_sensor_client_cb_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief Register BLE Mesh Sensor Client Model callback.
|
||||
@ -237,7 +241,7 @@ esp_err_t esp_ble_mesh_register_sensor_client_callback(esp_ble_mesh_sensor_clien
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_sensor_client_get_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_sensor_client_get_state_t *get_state);
|
||||
esp_ble_mesh_sensor_client_get_state_t *get_state);
|
||||
|
||||
/**
|
||||
* @brief Set the value of Sensor Server Model states using the Sensor Client Model set messages.
|
||||
@ -253,7 +257,7 @@ 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);
|
||||
esp_ble_mesh_sensor_client_set_state_t *set_state);
|
||||
|
||||
/**
|
||||
* @brief Sensor Server Models related context.
|
||||
@ -345,6 +349,91 @@ esp_err_t esp_ble_mesh_sensor_client_set_state(esp_ble_mesh_client_common_param_
|
||||
*/
|
||||
#define ESP_BLE_MESH_SENSOR_DATA_ZERO_LEN 0x7F
|
||||
|
||||
/** @def ESP_BLE_MESH_GET_SENSOR_DATA_FORMAT
|
||||
*
|
||||
* @brief Get format of the sensor data.
|
||||
*
|
||||
* @note Multiple sensor data may be concatenated. Make sure the _data pointer is
|
||||
* updated before getting the format of the corresponding sensor data.
|
||||
*
|
||||
* @param _data Pointer to the start of the sensor data.
|
||||
*
|
||||
* @return Format of the sensor data.
|
||||
*/
|
||||
#define ESP_BLE_MESH_GET_SENSOR_DATA_FORMAT(_data) (((_data)[0]) & BIT_MASK(1))
|
||||
|
||||
/** @def ESP_BLE_MESH_GET_SENSOR_DATA_LENGTH
|
||||
*
|
||||
* @brief Get length of the sensor data.
|
||||
*
|
||||
* @note Multiple sensor data may be concatenated. Make sure the _data pointer is
|
||||
* updated before getting the length of the corresponding sensor data.
|
||||
*
|
||||
* @param _data Pointer to the start of the sensor data.
|
||||
* @param _fmt Format of the sensor data.
|
||||
*
|
||||
* @return Length (zero-based) of the sensor data.
|
||||
*/
|
||||
#define ESP_BLE_MESH_GET_SENSOR_DATA_LENGTH(_data, _fmt) \
|
||||
(((_fmt) == ESP_BLE_MESH_SENSOR_DATA_FORMAT_A) ? ((((_data)[0]) >> 1) & BIT_MASK(4)) : ((((_data)[0]) >> 1) & BIT_MASK(7)))
|
||||
|
||||
/** @def ESP_BLE_MESH_GET_SENSOR_DATA_PROPERTY_ID
|
||||
*
|
||||
* @brief Get Sensor Property ID of the sensor data.
|
||||
*
|
||||
* @note Multiple sensor data may be concatenated. Make sure the _data pointer is
|
||||
* updated before getting Sensor Property ID of the corresponding sensor data.
|
||||
*
|
||||
* @param _data Pointer to the start of the sensor data.
|
||||
* @param _fmt Format of the sensor data.
|
||||
*
|
||||
* @return Sensor Property ID of the sensor data.
|
||||
*/
|
||||
#define ESP_BLE_MESH_GET_SENSOR_DATA_PROPERTY_ID(_data, _fmt) \
|
||||
(((_fmt) == ESP_BLE_MESH_SENSOR_DATA_FORMAT_A) ? ((((_data)[1]) << 3) | (((_data)[0]) >> 5)) : ((((_data)[2]) << 8) | ((_data)[1])))
|
||||
|
||||
/** @def ESP_BLE_MESH_SENSOR_DATA_FORMAT_A_MPID
|
||||
*
|
||||
* @brief Generate a MPID value for sensor data with Format A.
|
||||
*
|
||||
* @note 1. The Format field is 0b0 and indicates that Format A is used.
|
||||
* 2. The Length field is a 1-based uint4 value (valid range 0x0–0xF,
|
||||
* representing range of 1–16).
|
||||
* 3. The Property ID is an 11-bit bit field representing 11 LSb of a Property ID.
|
||||
* 4. This format may be used for Property Values that are not longer than 16
|
||||
* octets and for Property IDs less than 0x0800.
|
||||
*
|
||||
* @param _len Length of Sensor Raw value.
|
||||
* @param _id Sensor Property ID.
|
||||
*
|
||||
* @return 2-octet MPID value for sensor data with Format A.
|
||||
*
|
||||
*/
|
||||
#define ESP_BLE_MESH_SENSOR_DATA_FORMAT_A_MPID(_len, _id) \
|
||||
((((_id) & BIT_MASK(11)) << 5) | (((_len) & BIT_MASK(4)) << 1) | ESP_BLE_MESH_SENSOR_DATA_FORMAT_A)
|
||||
|
||||
/** @def ESP_BLE_MESH_SENSOR_DATA_FORMAT_B_MPID
|
||||
*
|
||||
* @brief Generate a MPID value for sensor data with Format B.
|
||||
*
|
||||
* @note 1. The Format field is 0b1 and indicates Format B is used.
|
||||
* 2. 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.
|
||||
* 3. The Property ID is a 16-bit bit field representing a Property ID.
|
||||
* 4. This format may be used for Property Values not longer than 128 octets and for
|
||||
* any Property IDs. Property values longer than 128 octets are not supported by
|
||||
* the Sensor Status message.
|
||||
* 5. Exclude the generated 1-octet value, the 2-octet Sensor Property ID
|
||||
*
|
||||
* @param _len Length of Sensor Raw value.
|
||||
* @param _id Sensor Property ID.
|
||||
*
|
||||
* @return 3-octet MPID value for sensor data with Format B.
|
||||
*
|
||||
*/
|
||||
#define ESP_BLE_MESH_SENSOR_DATA_FORMAT_B_MPID(_len, _id) \
|
||||
(((_id) << 8) | (((_len) & BIT_MASK(7)) << 1) | ESP_BLE_MESH_SENSOR_DATA_FORMAT_B)
|
||||
|
||||
/** This enum value is value of Sensor Sampling Function */
|
||||
enum esp_ble_mesh_sensor_sample_func {
|
||||
ESP_BLE_MESH_SAMPLE_FUNC_UNSPECIFIED,
|
||||
@ -523,7 +612,7 @@ typedef struct {
|
||||
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) */
|
||||
struct net_buf_simple *raw_value; /*!< Raw value containing X1 and X2 (optional) */
|
||||
} esp_ble_mesh_server_recv_sensor_series_get_t;
|
||||
|
||||
/**
|
||||
@ -609,7 +698,7 @@ typedef enum {
|
||||
* @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);
|
||||
esp_ble_mesh_sensor_server_cb_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief Register BLE Mesh Sensor Server Model callback.
|
||||
@ -621,6 +710,10 @@ typedef void (* esp_ble_mesh_sensor_server_cb_t)(esp_ble_mesh_sensor_server_cb_e
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_register_sensor_server_callback(esp_ble_mesh_sensor_server_cb_t callback);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_BLE_MESH_SENSOR_MODEL_API_H_ */
|
||||
|
||||
|
||||
|
@ -21,6 +21,10 @@
|
||||
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @def ESP_BLE_MESH_MODEL_TIME_CLI
|
||||
*
|
||||
* @brief Define a new Time Client Model.
|
||||
@ -272,7 +276,7 @@ typedef enum {
|
||||
* @param param: Pointer to callback parameter
|
||||
*/
|
||||
typedef void (* esp_ble_mesh_time_scene_client_cb_t)(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_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief Register BLE Mesh Time Scene Client Model callback.
|
||||
@ -297,7 +301,7 @@ esp_err_t esp_ble_mesh_register_time_scene_client_callback(esp_ble_mesh_time_sce
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_time_scene_client_get_state(esp_ble_mesh_client_common_param_t *params,
|
||||
esp_ble_mesh_time_scene_client_get_state_t *get_state);
|
||||
esp_ble_mesh_time_scene_client_get_state_t *get_state);
|
||||
|
||||
/**
|
||||
* @brief Set the value of Time Scene Server Model states using the Time Scene Client Model set messages.
|
||||
@ -312,7 +316,7 @@ esp_err_t esp_ble_mesh_time_scene_client_get_state(esp_ble_mesh_client_common_pa
|
||||
* @return ESP_OK on success or error code otherwise.
|
||||
*/
|
||||
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);
|
||||
esp_ble_mesh_time_scene_client_set_state_t *set_state);
|
||||
|
||||
/**
|
||||
* @brief Time Scene Server Models related context.
|
||||
@ -434,11 +438,11 @@ esp_err_t esp_ble_mesh_time_scene_client_set_state(esp_ble_mesh_client_common_pa
|
||||
#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_UTC_DELTA_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_TAI_OF_DELTA_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 */
|
||||
@ -896,7 +900,7 @@ typedef enum {
|
||||
* @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);
|
||||
esp_ble_mesh_time_scene_server_cb_param_t *param);
|
||||
|
||||
/**
|
||||
* @brief Register BLE Mesh Time and Scenes Server Model callback.
|
||||
@ -908,5 +912,9 @@ typedef void (* esp_ble_mesh_time_scene_server_cb_t)(esp_ble_mesh_time_scene_ser
|
||||
*/
|
||||
esp_err_t esp_ble_mesh_register_time_scene_server_callback(esp_ble_mesh_time_scene_server_cb_t callback);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ESP_BLE_MESH_TIME_SCENE_MODEL_API_H_ */
|
||||
|
||||
|
203
components/bt/esp_ble_mesh/btc/btc_ble_mesh_ble.c
Normal file
203
components/bt/esp_ble_mesh/btc/btc_ble_mesh_ble.c
Normal file
@ -0,0 +1,203 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "btc_ble_mesh_ble.h"
|
||||
#include "adv.h"
|
||||
#include "scan.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
#include "esp_ble_mesh_ble_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_BLE_COEX_SUPPORT
|
||||
|
||||
static void btc_ble_mesh_ble_copy_req_data(btc_msg_t *msg, void *p_dst, void *p_src)
|
||||
{
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
esp_ble_mesh_ble_cb_param_t *p_dst_data = (esp_ble_mesh_ble_cb_param_t *)p_dst;
|
||||
esp_ble_mesh_ble_cb_param_t *p_src_data = (esp_ble_mesh_ble_cb_param_t *)p_src;
|
||||
|
||||
if (!msg || !p_src_data || !p_dst_data) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT:
|
||||
if (p_src_data->scan_ble_adv_pkt.data && p_src_data->scan_ble_adv_pkt.length) {
|
||||
p_dst_data->scan_ble_adv_pkt.length = p_src_data->scan_ble_adv_pkt.length;
|
||||
p_dst_data->scan_ble_adv_pkt.data = bt_mesh_calloc(p_src_data->scan_ble_adv_pkt.length);
|
||||
if (p_dst_data->scan_ble_adv_pkt.data) {
|
||||
memcpy(p_dst_data->scan_ble_adv_pkt.data, p_src_data->scan_ble_adv_pkt.data,
|
||||
p_src_data->scan_ble_adv_pkt.length);
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_ble_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
esp_ble_mesh_ble_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (esp_ble_mesh_ble_cb_param_t *)msg->arg;
|
||||
|
||||
switch (msg->act) {
|
||||
case ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT:
|
||||
if (arg->scan_ble_adv_pkt.data) {
|
||||
bt_mesh_free(arg->scan_ble_adv_pkt.data);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
|
||||
}
|
||||
|
||||
static void btc_ble_mesh_ble_callback(esp_ble_mesh_ble_cb_param_t *cb_params, uint8_t act)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_BLE_MESH_BLE_COEX)) {
|
||||
return;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_BLE_MESH_BLE_COEX;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_ble_cb_param_t),
|
||||
btc_ble_mesh_ble_copy_req_data);
|
||||
}
|
||||
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
void bt_mesh_ble_scan_cb_evt_to_btc(const bt_mesh_addr_t *addr,
|
||||
uint8_t adv_type, uint8_t data[],
|
||||
uint16_t length, int8_t rssi)
|
||||
{
|
||||
esp_ble_mesh_ble_cb_param_t param = {0};
|
||||
|
||||
if (addr == NULL) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(param.scan_ble_adv_pkt.addr, addr->val, sizeof(addr->val));
|
||||
param.scan_ble_adv_pkt.addr_type = addr->type;
|
||||
if (data && length) {
|
||||
param.scan_ble_adv_pkt.data = data;
|
||||
param.scan_ble_adv_pkt.length = length;
|
||||
}
|
||||
param.scan_ble_adv_pkt.adv_type = adv_type;
|
||||
param.scan_ble_adv_pkt.rssi = rssi;
|
||||
|
||||
btc_ble_mesh_ble_callback(¶m, ESP_BLE_MESH_SCAN_BLE_ADVERTISING_PKT_EVT);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
|
||||
|
||||
void btc_ble_mesh_ble_call_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_ble_cb_param_t param = {0};
|
||||
btc_ble_mesh_ble_args_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
arg = (btc_ble_mesh_ble_args_t *)msg->arg;
|
||||
|
||||
switch (msg->act) {
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
|
||||
case BTC_BLE_MESH_ACT_START_BLE_ADV: {
|
||||
struct bt_mesh_ble_adv_param *set = (struct bt_mesh_ble_adv_param *)&arg->start_ble_adv.param;
|
||||
struct bt_mesh_ble_adv_data *data = NULL;
|
||||
if (arg->start_ble_adv.data.adv_data_len || arg->start_ble_adv.data.scan_rsp_data_len) {
|
||||
data = (struct bt_mesh_ble_adv_data *)&arg->start_ble_adv.data;
|
||||
}
|
||||
|
||||
param.start_ble_advertising_comp.err_code =
|
||||
bt_mesh_start_ble_advertising(set, data, ¶m.start_ble_advertising_comp.index);
|
||||
|
||||
btc_ble_mesh_ble_callback(¶m, ESP_BLE_MESH_START_BLE_ADVERTISING_COMP_EVT);
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_STOP_BLE_ADV:
|
||||
param.stop_ble_advertising_comp.index = arg->stop_ble_adv.index;
|
||||
param.stop_ble_advertising_comp.err_code =
|
||||
bt_mesh_stop_ble_advertising(arg->stop_ble_adv.index);
|
||||
|
||||
btc_ble_mesh_ble_callback(¶m, ESP_BLE_MESH_STOP_BLE_ADVERTISING_COMP_EVT);
|
||||
break;
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
|
||||
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
|
||||
case BTC_BLE_MESH_ACT_START_BLE_SCAN:
|
||||
param.start_ble_scan_comp.err_code =
|
||||
bt_mesh_start_ble_scan((struct bt_mesh_ble_scan_param *)&arg->start_ble_scan.param);
|
||||
btc_ble_mesh_ble_callback(¶m, ESP_BLE_MESH_START_BLE_SCANNING_COMP_EVT);
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_STOP_BLE_SCAN:
|
||||
param.stop_ble_scan_comp.err_code = bt_mesh_stop_ble_scan();
|
||||
btc_ble_mesh_ble_callback(¶m, ESP_BLE_MESH_STOP_BLE_SCANNING_COMP_EVT);
|
||||
break;
|
||||
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void btc_ble_mesh_ble_cb_to_app(esp_ble_mesh_ble_cb_event_t event,
|
||||
esp_ble_mesh_ble_cb_param_t *param)
|
||||
{
|
||||
esp_ble_mesh_ble_cb_t btc_ble_mesh_cb =
|
||||
(esp_ble_mesh_ble_cb_t)btc_profile_cb_get(BTC_PID_BLE_MESH_BLE_COEX);
|
||||
if (btc_ble_mesh_cb) {
|
||||
btc_ble_mesh_cb(event, param);
|
||||
}
|
||||
}
|
||||
|
||||
void btc_ble_mesh_ble_cb_handler(btc_msg_t *msg)
|
||||
{
|
||||
esp_ble_mesh_ble_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
param = (esp_ble_mesh_ble_cb_param_t *)msg->arg;
|
||||
|
||||
if (msg->act < ESP_BLE_MESH_BLE_EVT_MAX) {
|
||||
btc_ble_mesh_ble_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_ble_free_req_data(msg);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_BLE_COEX_SUPPORT */
|
@ -15,22 +15,17 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "osi/allocator.h"
|
||||
|
||||
#include "cfg_cli.h"
|
||||
#include "mesh_common.h"
|
||||
#include "btc_ble_mesh_config_model.h"
|
||||
#include "foundation.h"
|
||||
#include "esp_ble_mesh_config_model_api.h"
|
||||
|
||||
#define CID_NVAL 0xffff
|
||||
|
||||
extern s32_t config_msg_timeout;
|
||||
#if CONFIG_BLE_MESH_CFG_CLI
|
||||
#include "cfg_cli.h"
|
||||
|
||||
/* 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_param_t *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);
|
||||
@ -45,39 +40,53 @@ void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE: {
|
||||
dst->cfg_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->cfg_client_get_state.get_state = (esp_ble_mesh_cfg_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_cfg_client_get_state_t));
|
||||
if (dst->cfg_client_get_state.params && dst->cfg_client_get_state.get_state) {
|
||||
dst->cfg_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (dst->cfg_client_get_state.params) {
|
||||
memcpy(dst->cfg_client_get_state.params, src->cfg_client_get_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->cfg_client_get_state.get_state, src->cfg_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_cfg_client_get_state_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
if (src->cfg_client_get_state.get_state) {
|
||||
dst->cfg_client_get_state.get_state = (esp_ble_mesh_cfg_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_cfg_client_get_state_t));
|
||||
if (dst->cfg_client_get_state.get_state) {
|
||||
memcpy(dst->cfg_client_get_state.get_state, src->cfg_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_cfg_client_get_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE: {
|
||||
dst->cfg_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->cfg_client_set_state.set_state = (esp_ble_mesh_cfg_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_cfg_client_set_state_t));
|
||||
if (dst->cfg_client_set_state.params && dst->cfg_client_set_state.set_state) {
|
||||
dst->cfg_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (dst->cfg_client_set_state.params) {
|
||||
memcpy(dst->cfg_client_set_state.params, src->cfg_client_set_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->cfg_client_set_state.set_state, src->cfg_client_set_state.set_state,
|
||||
sizeof(esp_ble_mesh_cfg_client_set_state_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
if (src->cfg_client_set_state.set_state) {
|
||||
dst->cfg_client_set_state.set_state = (esp_ble_mesh_cfg_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_cfg_client_set_state_t));
|
||||
if (dst->cfg_client_set_state.set_state) {
|
||||
memcpy(dst->cfg_client_set_state.set_state, src->cfg_client_set_state.set_state,
|
||||
sizeof(esp_ble_mesh_cfg_client_set_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act);
|
||||
BT_DBG("%s, Unknown act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -87,7 +96,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -96,18 +105,18 @@ static void btc_ble_mesh_config_client_arg_deep_free(btc_msg_t *msg)
|
||||
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);
|
||||
bt_mesh_free(arg->cfg_client_get_state.params);
|
||||
}
|
||||
if (arg->cfg_client_get_state.get_state) {
|
||||
osi_free(arg->cfg_client_get_state.get_state);
|
||||
bt_mesh_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);
|
||||
bt_mesh_free(arg->cfg_client_set_state.params);
|
||||
}
|
||||
if (arg->cfg_client_set_state.set_state) {
|
||||
osi_free(arg->cfg_client_set_state.set_state);
|
||||
bt_mesh_free(arg->cfg_client_set_state.set_state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -119,17 +128,17 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
{
|
||||
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;
|
||||
u16_t length;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
p_dest_data->params = bt_mesh_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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -148,7 +157,7 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.comp_data_status.composition_data->len;
|
||||
p_dest_data->status_cb.comp_data_status.composition_data = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.comp_data_status.composition_data) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.comp_data_status.composition_data,
|
||||
@ -164,7 +173,7 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.model_sub_list.sub_addr->len;
|
||||
p_dest_data->status_cb.model_sub_list.sub_addr = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.model_sub_list.sub_addr) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.model_sub_list.sub_addr,
|
||||
@ -178,7 +187,7 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.netkey_list.net_idx->len;
|
||||
p_dest_data->status_cb.netkey_list.net_idx = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.netkey_list.net_idx) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.netkey_list.net_idx,
|
||||
@ -192,7 +201,7 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.appkey_list.app_idx->len;
|
||||
p_dest_data->status_cb.appkey_list.app_idx = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.appkey_list.app_idx) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.appkey_list.app_idx,
|
||||
@ -208,7 +217,7 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.model_app_list.app_idx->len;
|
||||
p_dest_data->status_cb.model_app_list.app_idx = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.model_app_list.app_idx) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.model_app_list.app_idx,
|
||||
@ -232,7 +241,7 @@ static void btc_ble_mesh_config_client_free_req_data(btc_msg_t *msg)
|
||||
esp_ble_mesh_cfg_client_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -274,7 +283,7 @@ static void btc_ble_mesh_config_client_free_req_data(btc_msg_t *msg)
|
||||
}
|
||||
case ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
osi_free(arg->params);
|
||||
bt_mesh_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -286,7 +295,7 @@ static void btc_ble_mesh_config_client_callback(esp_ble_mesh_cfg_client_cb_param
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_CONFIG_CLIENT)) {
|
||||
@ -297,22 +306,21 @@ static void btc_ble_mesh_config_client_callback(esp_ble_mesh_cfg_client_cb_param
|
||||
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_config_client_copy_req_data);
|
||||
btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_cfg_client_cb_param_t),
|
||||
btc_ble_mesh_config_client_copy_req_data);
|
||||
}
|
||||
|
||||
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 bt_mesh_config_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_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;
|
||||
uint8_t act;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -330,7 +338,7 @@ void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
act = ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown config client event type %d", __func__, evt_type);
|
||||
BT_ERR("Unknown Config client event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -342,154 +350,178 @@ void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
params.ctx.recv_op = ctx->recv_op;
|
||||
params.ctx.recv_dst = ctx->recv_dst;
|
||||
params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
cb_params.error_code = 0;
|
||||
cb_params.params = ¶ms;
|
||||
|
||||
if (val && len) {
|
||||
length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb);
|
||||
memcpy(&cb_params.status_cb, val, length);
|
||||
memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb)));
|
||||
}
|
||||
|
||||
btc_ble_mesh_config_client_callback(&cb_params, act);
|
||||
return;
|
||||
}
|
||||
|
||||
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_ble_mesh_config_client_publish_callback(uint32_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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_config_client_cb_evt_to_btc(opcode,
|
||||
BTC_BLE_MESH_EVT_CONFIG_CLIENT_PUBLISH, 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;
|
||||
}
|
||||
|
||||
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)
|
||||
esp_ble_mesh_cfg_client_get_state_t *get)
|
||||
{
|
||||
struct bt_mesh_msg_ctx ctx = {0};
|
||||
bt_mesh_client_common_param_t param = {0};
|
||||
|
||||
if (!params || !cb) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
if (params == NULL) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ctx.net_idx = params->ctx.net_idx;
|
||||
ctx.app_idx = BLE_MESH_KEY_DEV;
|
||||
ctx.addr = params->ctx.addr;
|
||||
ctx.send_rel = params->ctx.send_rel;
|
||||
ctx.send_ttl = params->ctx.send_ttl;
|
||||
|
||||
config_msg_timeout = params->msg_timeout;
|
||||
|
||||
switch (params->opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_BEACON_GET:
|
||||
return (cb->error_code = bt_mesh_cfg_beacon_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_GET:
|
||||
return (cb->error_code = bt_mesh_cfg_ttl_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_FRIEND_GET:
|
||||
return (cb->error_code = bt_mesh_cfg_friend_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_GET:
|
||||
return (cb->error_code = bt_mesh_cfg_gatt_proxy_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_RELAY_GET:
|
||||
return (cb->error_code = bt_mesh_cfg_relay_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET:
|
||||
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 (cb->error_code = bt_mesh_cfg_hb_pub_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_GET:
|
||||
return (cb->error_code = bt_mesh_cfg_hb_sub_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET:
|
||||
return (cb->error_code = bt_mesh_cfg_comp_data_get(&ctx, get->comp_data_get.page));
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET:
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET:
|
||||
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 (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 (cb->error_code = bt_mesh_cfg_net_key_get(&ctx));
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET:
|
||||
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 (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 (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 (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 (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 (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 (cb->error_code = bt_mesh_cfg_net_transmit_get(&ctx));
|
||||
if (get == NULL) {
|
||||
BT_ERR("Invalid Configuration Get");
|
||||
return -EINVAL;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
return (cb->error_code = -EINVAL);
|
||||
break;
|
||||
}
|
||||
|
||||
param.opcode = params->opcode;
|
||||
param.model = (struct bt_mesh_model *)params->model;
|
||||
param.ctx.net_idx = params->ctx.net_idx;
|
||||
param.ctx.app_idx = BLE_MESH_KEY_DEV;
|
||||
param.ctx.addr = params->ctx.addr;
|
||||
param.ctx.send_rel = params->ctx.send_rel;
|
||||
param.ctx.send_ttl = params->ctx.send_ttl;
|
||||
param.msg_timeout = params->msg_timeout;
|
||||
param.msg_role = params->msg_role;
|
||||
|
||||
switch (param.opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_BEACON_GET:
|
||||
return bt_mesh_cfg_beacon_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_GET:
|
||||
return bt_mesh_cfg_ttl_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_FRIEND_GET:
|
||||
return bt_mesh_cfg_friend_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_GET:
|
||||
return bt_mesh_cfg_gatt_proxy_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_RELAY_GET:
|
||||
return bt_mesh_cfg_relay_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET:
|
||||
return bt_mesh_cfg_mod_pub_get(¶m, 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 bt_mesh_cfg_hb_pub_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_GET:
|
||||
return bt_mesh_cfg_hb_sub_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET:
|
||||
return bt_mesh_cfg_comp_data_get(¶m, get->comp_data_get.page);
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET:
|
||||
return bt_mesh_cfg_mod_sub_get(¶m, 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 bt_mesh_cfg_mod_sub_get_vnd(¶m, 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 bt_mesh_cfg_net_key_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET:
|
||||
return bt_mesh_cfg_app_key_get(¶m, get->app_key_get.net_idx);
|
||||
case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_GET:
|
||||
return bt_mesh_cfg_node_identity_get(¶m, get->node_identity_get.net_idx);
|
||||
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET:
|
||||
return bt_mesh_cfg_mod_app_get(¶m, 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 bt_mesh_cfg_mod_app_get_vnd(¶m, 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 bt_mesh_cfg_kr_phase_get(¶m, get->kr_phase_get.net_idx);
|
||||
case ESP_BLE_MESH_MODEL_OP_LPN_POLLTIMEOUT_GET:
|
||||
return bt_mesh_cfg_lpn_timeout_get(¶m, get->lpn_pollto_get.lpn_addr);
|
||||
case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_GET:
|
||||
return bt_mesh_cfg_net_transmit_get(¶m);
|
||||
default:
|
||||
BT_ERR("Invalid Configuration Get opcode 0x%04x", param.opcode);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
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)
|
||||
esp_ble_mesh_cfg_client_set_state_t *set)
|
||||
{
|
||||
struct bt_mesh_msg_ctx ctx = {0};
|
||||
bt_mesh_client_common_param_t param = {0};
|
||||
|
||||
if (!params || !set || !cb) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
if (params == NULL) {
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ctx.net_idx = params->ctx.net_idx;
|
||||
ctx.app_idx = BLE_MESH_KEY_DEV;
|
||||
ctx.addr = params->ctx.addr;
|
||||
ctx.send_rel = params->ctx.send_rel;
|
||||
ctx.send_ttl = params->ctx.send_ttl;
|
||||
if (params->opcode != ESP_BLE_MESH_MODEL_OP_NODE_RESET && set == NULL) {
|
||||
BT_ERR("Invalid Configuration Set");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
config_msg_timeout = params->msg_timeout;
|
||||
param.opcode = params->opcode;
|
||||
param.model = (struct bt_mesh_model *)params->model;
|
||||
param.ctx.net_idx = params->ctx.net_idx;
|
||||
param.ctx.app_idx = BLE_MESH_KEY_DEV;
|
||||
param.ctx.addr = params->ctx.addr;
|
||||
param.ctx.send_rel = params->ctx.send_rel;
|
||||
param.ctx.send_ttl = params->ctx.send_ttl;
|
||||
param.msg_timeout = params->msg_timeout;
|
||||
param.msg_role = params->msg_role;
|
||||
|
||||
switch (params->opcode) {
|
||||
switch (param.opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_BEACON_SET:
|
||||
return (cb->error_code = bt_mesh_cfg_beacon_set(&ctx, set->beacon_set.beacon));
|
||||
return bt_mesh_cfg_beacon_set(¶m, set->beacon_set.beacon);
|
||||
case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_SET:
|
||||
return (cb->error_code = bt_mesh_cfg_ttl_set(&ctx, set->default_ttl_set.ttl));
|
||||
return bt_mesh_cfg_ttl_set(¶m, set->default_ttl_set.ttl);
|
||||
case ESP_BLE_MESH_MODEL_OP_FRIEND_SET:
|
||||
return (cb->error_code = bt_mesh_cfg_friend_set(&ctx, set->friend_set.friend_state));
|
||||
return bt_mesh_cfg_friend_set(¶m, set->friend_set.friend_state);
|
||||
case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_SET:
|
||||
return (cb->error_code = bt_mesh_cfg_gatt_proxy_set(&ctx, set->gatt_proxy_set.gatt_proxy));
|
||||
return bt_mesh_cfg_gatt_proxy_set(¶m, set->gatt_proxy_set.gatt_proxy);
|
||||
case ESP_BLE_MESH_MODEL_OP_RELAY_SET:
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_relay_set(&ctx, set->relay_set.relay, set->relay_set.relay_retransmit));
|
||||
return bt_mesh_cfg_relay_set(¶m, set->relay_set.relay,
|
||||
set->relay_set.relay_retransmit);
|
||||
case ESP_BLE_MESH_MODEL_OP_NET_KEY_ADD:
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_net_key_add(&ctx, set->net_key_add.net_idx,
|
||||
&set->net_key_add.net_key[0]));
|
||||
return bt_mesh_cfg_net_key_add(¶m, set->net_key_add.net_idx,
|
||||
&set->net_key_add.net_key[0]);
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_ADD:
|
||||
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]));
|
||||
return bt_mesh_cfg_app_key_add(¶m, 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 (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));
|
||||
return bt_mesh_cfg_mod_app_bind(¶m, 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->model_pub_set.publish_addr,
|
||||
@ -499,50 +531,46 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param
|
||||
.period = set->model_pub_set.publish_period,
|
||||
.transmit = set->model_pub_set.publish_retransmit,
|
||||
};
|
||||
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));
|
||||
return bt_mesh_cfg_mod_pub_set(¶m, 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 (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));
|
||||
return bt_mesh_cfg_mod_sub_add(¶m, 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 (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));
|
||||
return bt_mesh_cfg_mod_sub_del(¶m, 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 (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));
|
||||
return bt_mesh_cfg_mod_sub_overwrite(¶m, 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 (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));
|
||||
return bt_mesh_cfg_mod_sub_va_add(¶m, 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 (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));
|
||||
return bt_mesh_cfg_mod_sub_va_overwrite(¶m, 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 (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));
|
||||
return bt_mesh_cfg_mod_sub_va_del(¶m, 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 (cb->error_code =
|
||||
bt_mesh_cfg_hb_sub_set(&ctx,
|
||||
(struct bt_mesh_cfg_hb_sub *)&set->heartbeat_sub_set));
|
||||
return bt_mesh_cfg_hb_sub_set(¶m, (struct bt_mesh_cfg_hb_sub *)&set->heartbeat_sub_set);
|
||||
case ESP_BLE_MESH_MODEL_OP_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));
|
||||
return bt_mesh_cfg_hb_pub_set(¶m, (struct bt_mesh_cfg_hb_pub *)&set->heartbeat_pub_set);
|
||||
case ESP_BLE_MESH_MODEL_OP_NODE_RESET:
|
||||
return (cb->error_code = bt_mesh_cfg_node_reset(&ctx));
|
||||
return bt_mesh_cfg_node_reset(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_VIRTUAL_ADDR_SET: {
|
||||
struct bt_mesh_cfg_mod_pub model_pub = {
|
||||
.app_idx = set->model_pub_va_set.publish_app_idx,
|
||||
@ -551,49 +579,43 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param
|
||||
.period = set->model_pub_va_set.publish_period,
|
||||
.transmit = set->model_pub_va_set.publish_retransmit,
|
||||
};
|
||||
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));
|
||||
return bt_mesh_cfg_mod_pub_va_set(¶m, 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 (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));
|
||||
return bt_mesh_cfg_mod_sub_del_all(¶m, 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 (cb->error_code =
|
||||
bt_mesh_cfg_net_key_update(&ctx, set->net_key_update.net_idx,
|
||||
set->net_key_update.net_key));
|
||||
return bt_mesh_cfg_net_key_update(¶m, set->net_key_update.net_idx,
|
||||
set->net_key_update.net_key);
|
||||
case ESP_BLE_MESH_MODEL_OP_NET_KEY_DELETE:
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_net_key_delete(&ctx, set->net_key_delete.net_idx));
|
||||
return bt_mesh_cfg_net_key_delete(¶m, set->net_key_delete.net_idx);
|
||||
case ESP_BLE_MESH_MODEL_OP_APP_KEY_UPDATE:
|
||||
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));
|
||||
return bt_mesh_cfg_app_key_update(¶m, 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 (cb->error_code =
|
||||
bt_mesh_cfg_app_key_delete(&ctx, set->app_key_delete.net_idx,
|
||||
set->app_key_delete.app_idx));
|
||||
return bt_mesh_cfg_app_key_delete(¶m, set->app_key_delete.net_idx,
|
||||
set->app_key_delete.app_idx);
|
||||
case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_SET:
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_node_identity_set(&ctx, set->node_identity_set.net_idx,
|
||||
set->node_identity_set.identity));
|
||||
return bt_mesh_cfg_node_identity_set(¶m, set->node_identity_set.net_idx,
|
||||
set->node_identity_set.identity);
|
||||
case ESP_BLE_MESH_MODEL_OP_MODEL_APP_UNBIND:
|
||||
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));
|
||||
return bt_mesh_cfg_mod_app_unbind(¶m, 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 (cb->error_code =
|
||||
bt_mesh_cfg_kr_phase_set(&ctx, set->kr_phase_set.net_idx,
|
||||
set->kr_phase_set.transition));
|
||||
return bt_mesh_cfg_kr_phase_set(¶m, set->kr_phase_set.net_idx,
|
||||
set->kr_phase_set.transition);
|
||||
case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_SET:
|
||||
return (cb->error_code =
|
||||
bt_mesh_cfg_net_transmit_set(&ctx, set->net_transmit_set.net_transmit));
|
||||
return bt_mesh_cfg_net_transmit_set(¶m, set->net_transmit_set.net_transmit);
|
||||
default:
|
||||
LOG_ERROR("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
return (cb->error_code = -EINVAL);
|
||||
BT_ERR("Invalid Configuration Set opcode 0x%04x", param.opcode);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -603,10 +625,9 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -615,15 +636,8 @@ void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg)
|
||||
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);
|
||||
cb.error_code = btc_ble_mesh_config_client_get_state(arg->cfg_client_get_state.params,
|
||||
arg->cfg_client_get_state.get_state);
|
||||
if (cb.error_code) {
|
||||
btc_ble_mesh_config_client_callback(&cb, ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT);
|
||||
}
|
||||
@ -631,15 +645,8 @@ void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg)
|
||||
}
|
||||
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);
|
||||
cb.error_code = btc_ble_mesh_config_client_set_state(arg->cfg_client_set_state.params,
|
||||
arg->cfg_client_set_state.set_state);
|
||||
if (cb.error_code) {
|
||||
btc_ble_mesh_config_client_callback(&cb, ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT);
|
||||
}
|
||||
@ -658,7 +665,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -667,17 +674,19 @@ void btc_ble_mesh_config_client_cb_handler(btc_msg_t *msg)
|
||||
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);
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_config_client_free_req_data(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_CFG_CLI */
|
||||
|
||||
/* 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_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);
|
||||
@ -690,7 +699,7 @@ static void btc_ble_mesh_config_server_callback(esp_ble_mesh_cfg_server_cb_param
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_CONFIG_SERVER)) {
|
||||
@ -704,17 +713,15 @@ static void btc_ble_mesh_config_server_callback(esp_ble_mesh_cfg_server_cb_param
|
||||
btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_cfg_server_cb_param_t), NULL);
|
||||
}
|
||||
|
||||
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)
|
||||
void bt_mesh_config_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_cfg_server_cb_param_t cb_params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -723,7 +730,7 @@ void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type,
|
||||
act = ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown config server event type %d", __func__, evt_type);
|
||||
BT_ERR("Unknown Config server event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -734,10 +741,11 @@ void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type,
|
||||
cb_params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
cb_params.ctx.recv_op = ctx->recv_op;
|
||||
cb_params.ctx.recv_dst = ctx->recv_dst;
|
||||
cb_params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
cb_params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
if (val && len) {
|
||||
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
|
||||
memcpy(&cb_params.value, val, length);
|
||||
memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value)));
|
||||
}
|
||||
|
||||
btc_ble_mesh_config_server_callback(&cb_params, act);
|
||||
@ -749,7 +757,7 @@ void btc_ble_mesh_config_server_cb_handler(btc_msg_t *msg)
|
||||
esp_ble_mesh_cfg_server_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -758,6 +766,6 @@ void btc_ble_mesh_config_server_cb_handler(btc_msg_t *msg)
|
||||
if (msg->act < ESP_BLE_MESH_CFG_SERVER_EVT_MAX) {
|
||||
btc_ble_mesh_config_server_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
|
@ -15,17 +15,16 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "osi/allocator.h"
|
||||
|
||||
#include "generic_client.h"
|
||||
#include "btc_ble_mesh_generic_model.h"
|
||||
#include "esp_ble_mesh_generic_model_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_GENERIC_CLIENT
|
||||
#include "generic_client.h"
|
||||
|
||||
/* 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_param_t *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);
|
||||
@ -38,30 +37,37 @@ 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;
|
||||
u16_t length;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE: {
|
||||
dst->generic_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->generic_client_get_state.get_state = (esp_ble_mesh_generic_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_generic_client_get_state_t));
|
||||
if (dst->generic_client_get_state.params && dst->generic_client_get_state.get_state) {
|
||||
dst->generic_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (dst->generic_client_get_state.params) {
|
||||
memcpy(dst->generic_client_get_state.params, src->generic_client_get_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->generic_client_get_state.get_state, src->generic_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_generic_client_get_state_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
if (src->generic_client_get_state.get_state) {
|
||||
dst->generic_client_get_state.get_state = (esp_ble_mesh_generic_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_generic_client_get_state_t));
|
||||
if (dst->generic_client_get_state.get_state) {
|
||||
memcpy(dst->generic_client_get_state.get_state, src->generic_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_generic_client_get_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE: {
|
||||
dst->generic_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->generic_client_set_state.set_state = (esp_ble_mesh_generic_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_generic_client_set_state_t));
|
||||
dst->generic_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->generic_client_set_state.set_state = (esp_ble_mesh_generic_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_generic_client_set_state_t));
|
||||
if (dst->generic_client_set_state.params && dst->generic_client_set_state.set_state) {
|
||||
memcpy(dst->generic_client_set_state.params, src->generic_client_set_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
@ -74,7 +80,7 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi
|
||||
length = src->generic_client_set_state.set_state->user_property_set.property_value->len;
|
||||
dst->generic_client_set_state.set_state->user_property_set.property_value = bt_mesh_alloc_buf(length);
|
||||
if (!dst->generic_client_set_state.set_state->user_property_set.property_value) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->generic_client_set_state.set_state->user_property_set.property_value,
|
||||
@ -87,7 +93,7 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi
|
||||
length = src->generic_client_set_state.set_state->admin_property_set.property_value->len;
|
||||
dst->generic_client_set_state.set_state->admin_property_set.property_value = bt_mesh_alloc_buf(length);
|
||||
if (!dst->generic_client_set_state.set_state->admin_property_set.property_value) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->generic_client_set_state.set_state->admin_property_set.property_value,
|
||||
@ -99,12 +105,12 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act);
|
||||
BT_DBG("%s, Unknown act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -114,7 +120,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -123,10 +129,10 @@ static void btc_ble_mesh_generic_client_arg_deep_free(btc_msg_t *msg)
|
||||
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);
|
||||
bt_mesh_free(arg->generic_client_get_state.params);
|
||||
}
|
||||
if (arg->generic_client_get_state.get_state) {
|
||||
osi_free(arg->generic_client_get_state.get_state);
|
||||
bt_mesh_free(arg->generic_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE:
|
||||
@ -143,10 +149,10 @@ static void btc_ble_mesh_generic_client_arg_deep_free(btc_msg_t *msg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
osi_free(arg->generic_client_set_state.set_state);
|
||||
bt_mesh_free(arg->generic_client_set_state.set_state);
|
||||
}
|
||||
if (arg->generic_client_set_state.params) {
|
||||
osi_free(arg->generic_client_set_state.params);
|
||||
bt_mesh_free(arg->generic_client_set_state.params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -158,17 +164,17 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
{
|
||||
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;
|
||||
u16_t length;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
p_dest_data->params = bt_mesh_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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -187,7 +193,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
length = p_src_data->status_cb.user_properties_status.property_ids->len;
|
||||
p_dest_data->status_cb.user_properties_status.property_ids = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.user_properties_status.property_ids) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.user_properties_status.property_ids,
|
||||
@ -202,7 +208,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
length = p_src_data->status_cb.user_property_status.property_value->len;
|
||||
p_dest_data->status_cb.user_property_status.property_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.user_property_status.property_value) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.user_property_status.property_value,
|
||||
@ -216,7 +222,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
length = p_src_data->status_cb.admin_properties_status.property_ids->len;
|
||||
p_dest_data->status_cb.admin_properties_status.property_ids = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.admin_properties_status.property_ids) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.admin_properties_status.property_ids,
|
||||
@ -231,7 +237,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
length = p_src_data->status_cb.admin_property_status.property_value->len;
|
||||
p_dest_data->status_cb.admin_property_status.property_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.admin_property_status.property_value) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.admin_property_status.property_value,
|
||||
@ -245,7 +251,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
length = p_src_data->status_cb.manufacturer_properties_status.property_ids->len;
|
||||
p_dest_data->status_cb.manufacturer_properties_status.property_ids = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.manufacturer_properties_status.property_ids) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.manufacturer_properties_status.property_ids,
|
||||
@ -260,7 +266,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
length = p_src_data->status_cb.manufacturer_property_status.property_value->len;
|
||||
p_dest_data->status_cb.manufacturer_property_status.property_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.manufacturer_property_status.property_value) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.manufacturer_property_status.property_value,
|
||||
@ -274,7 +280,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
length = p_src_data->status_cb.client_properties_status.property_ids->len;
|
||||
p_dest_data->status_cb.client_properties_status.property_ids = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.client_properties_status.property_ids) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.client_properties_status.property_ids,
|
||||
@ -298,7 +304,7 @@ static void btc_ble_mesh_generic_client_free_req_data(btc_msg_t *msg)
|
||||
esp_ble_mesh_generic_client_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -347,7 +353,7 @@ static void btc_ble_mesh_generic_client_free_req_data(btc_msg_t *msg)
|
||||
}
|
||||
case ESP_BLE_MESH_GENERIC_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
osi_free(arg->params);
|
||||
bt_mesh_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -359,7 +365,7 @@ static void btc_ble_mesh_generic_client_callback(esp_ble_mesh_generic_client_cb_
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_GENERIC_CLIENT)) {
|
||||
@ -370,22 +376,21 @@ static void btc_ble_mesh_generic_client_callback(esp_ble_mesh_generic_client_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_generic_client_copy_req_data);
|
||||
btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_generic_client_cb_param_t),
|
||||
btc_ble_mesh_generic_client_copy_req_data);
|
||||
}
|
||||
|
||||
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)
|
||||
void bt_mesh_generic_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_generic_client_cb_param_t cb_params = {0};
|
||||
esp_ble_mesh_client_common_param_t params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -403,7 +408,7 @@ void bt_mesh_generic_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
act = ESP_BLE_MESH_GENERIC_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown generic client event type %d", __func__, evt_type);
|
||||
BT_ERR("Unknown Generic client event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -415,31 +420,31 @@ void bt_mesh_generic_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
params.ctx.recv_op = ctx->recv_op;
|
||||
params.ctx.recv_dst = ctx->recv_dst;
|
||||
params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
cb_params.error_code = 0;
|
||||
cb_params.params = ¶ms;
|
||||
|
||||
if (val && len) {
|
||||
length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb);
|
||||
memcpy(&cb_params.status_cb, val, length);
|
||||
memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb)));
|
||||
}
|
||||
|
||||
btc_ble_mesh_generic_client_callback(&cb_params, act);
|
||||
return;
|
||||
}
|
||||
|
||||
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 btc_ble_mesh_generic_client_publish_callback(uint32_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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_generic_client_cb_evt_to_btc(opcode,
|
||||
BTC_BLE_MESH_EVT_GENERIC_CLIENT_PUBLISH, 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;
|
||||
}
|
||||
|
||||
@ -449,10 +454,9 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
|
||||
btc_ble_mesh_generic_client_args_t *arg = NULL;
|
||||
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) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -461,12 +465,6 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE: {
|
||||
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_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
common.model = (struct bt_mesh_model *)params->model;
|
||||
common.ctx.net_idx = params->ctx.net_idx;
|
||||
@ -475,10 +473,10 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
|
||||
common.ctx.send_rel = params->ctx.send_rel;
|
||||
common.ctx.send_ttl = params->ctx.send_ttl;
|
||||
common.msg_timeout = params->msg_timeout;
|
||||
common.msg_role = params->msg_role;
|
||||
|
||||
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);
|
||||
cb.error_code = bt_mesh_generic_client_get_state(&common, arg->generic_client_get_state.get_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_generic_client_callback(&cb, ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT);
|
||||
@ -487,12 +485,6 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE: {
|
||||
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_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
common.model = (struct bt_mesh_model *)params->model;
|
||||
common.ctx.net_idx = params->ctx.net_idx;
|
||||
@ -501,10 +493,10 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
|
||||
common.ctx.send_rel = params->ctx.send_rel;
|
||||
common.ctx.send_ttl = params->ctx.send_ttl;
|
||||
common.msg_timeout = params->msg_timeout;
|
||||
common.msg_role = params->msg_role;
|
||||
|
||||
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);
|
||||
cb.error_code = bt_mesh_generic_client_set_state(&common, arg->generic_client_set_state.set_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_generic_client_callback(&cb, ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT);
|
||||
@ -524,7 +516,7 @@ void btc_ble_mesh_generic_client_cb_handler(btc_msg_t *msg)
|
||||
esp_ble_mesh_generic_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -533,18 +525,21 @@ void btc_ble_mesh_generic_client_cb_handler(btc_msg_t *msg)
|
||||
if (msg->act < ESP_BLE_MESH_GENERIC_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_generic_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_generic_client_free_req_data(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_GENERIC_CLIENT */
|
||||
|
||||
#if CONFIG_BLE_MESH_GENERIC_SERVER
|
||||
|
||||
/* 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)
|
||||
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);
|
||||
@ -557,10 +552,10 @@ static void btc_ble_mesh_generic_server_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
{
|
||||
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;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -573,7 +568,7 @@ static void btc_ble_mesh_generic_server_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.user_property_set.value,
|
||||
@ -587,7 +582,7 @@ static void btc_ble_mesh_generic_server_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.admin_property_set.value,
|
||||
@ -607,7 +602,7 @@ static void btc_ble_mesh_generic_server_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.set.user_property.property_value,
|
||||
@ -621,7 +616,7 @@ static void btc_ble_mesh_generic_server_copy_req_data(btc_msg_t *msg, void *p_de
|
||||
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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.set.admin_property.property_value,
|
||||
@ -643,7 +638,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -687,7 +682,7 @@ static void btc_ble_mesh_generic_server_callback(esp_ble_mesh_generic_server_cb_
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_GENERIC_SERVER)) {
|
||||
@ -698,21 +693,19 @@ static void btc_ble_mesh_generic_server_callback(esp_ble_mesh_generic_server_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);
|
||||
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)
|
||||
void bt_mesh_generic_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_generic_server_cb_param_t cb_params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (model == NULL || ctx == NULL) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -727,7 +720,7 @@ void bt_mesh_generic_server_cb_evt_to_btc(u8_t evt_type,
|
||||
act = ESP_BLE_MESH_GENERIC_SERVER_RECV_SET_MSG_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown Generic Server event type", __func__);
|
||||
BT_ERR("Unknown Generic Server event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -738,10 +731,11 @@ void bt_mesh_generic_server_cb_evt_to_btc(u8_t evt_type,
|
||||
cb_params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
cb_params.ctx.recv_op = ctx->recv_op;
|
||||
cb_params.ctx.recv_dst = ctx->recv_dst;
|
||||
cb_params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
cb_params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
if (val && len) {
|
||||
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
|
||||
memcpy(&cb_params.value, val, length);
|
||||
memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value)));
|
||||
}
|
||||
|
||||
btc_ble_mesh_generic_server_callback(&cb_params, act);
|
||||
@ -753,7 +747,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -762,9 +756,11 @@ void btc_ble_mesh_generic_server_cb_handler(btc_msg_t *msg)
|
||||
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);
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_generic_server_free_req_data(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_GENERIC_SERVER */
|
||||
|
@ -15,23 +15,17 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "btc/btc_task.h"
|
||||
#include "osi/allocator.h"
|
||||
|
||||
#include "health_srv.h"
|
||||
#include "health_cli.h"
|
||||
#include "mesh_common.h"
|
||||
|
||||
#include "btc_ble_mesh_health_model.h"
|
||||
#include "esp_ble_mesh_defs.h"
|
||||
#include "foundation.h"
|
||||
#include "esp_ble_mesh_health_model_api.h"
|
||||
|
||||
extern s32_t health_msg_timeout;
|
||||
#if CONFIG_BLE_MESH_HEALTH_CLI
|
||||
#include "health_cli.h"
|
||||
|
||||
/* 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_param_t *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);
|
||||
@ -46,39 +40,46 @@ void btc_ble_mesh_health_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
btc_ble_mesh_health_client_args_t *src = (btc_ble_mesh_health_client_args_t *)p_src;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_GET_STATE: {
|
||||
dst->health_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->health_client_get_state.get_state = (esp_ble_mesh_health_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_health_client_get_state_t));
|
||||
if (dst->health_client_get_state.params && dst->health_client_get_state.get_state) {
|
||||
dst->health_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (dst->health_client_get_state.params) {
|
||||
memcpy(dst->health_client_get_state.params, src->health_client_get_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->health_client_get_state.get_state, src->health_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_health_client_get_state_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
if (src->health_client_get_state.get_state) {
|
||||
dst->health_client_get_state.get_state = (esp_ble_mesh_health_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_health_client_get_state_t));
|
||||
if (dst->health_client_get_state.get_state) {
|
||||
memcpy(dst->health_client_get_state.get_state, src->health_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_health_client_get_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_SET_STATE: {
|
||||
dst->health_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->health_client_set_state.set_state = (esp_ble_mesh_health_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_health_client_set_state_t));
|
||||
dst->health_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->health_client_set_state.set_state = (esp_ble_mesh_health_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_health_client_set_state_t));
|
||||
if (dst->health_client_set_state.params && dst->health_client_set_state.set_state) {
|
||||
memcpy(dst->health_client_set_state.params, src->health_client_set_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->health_client_set_state.set_state, src->health_client_set_state.set_state,
|
||||
sizeof(esp_ble_mesh_health_client_set_state_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act);
|
||||
BT_DBG("%s, Unknown act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -88,7 +89,7 @@ static void btc_ble_mesh_health_client_arg_deep_free(btc_msg_t *msg)
|
||||
btc_ble_mesh_health_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -97,18 +98,18 @@ static void btc_ble_mesh_health_client_arg_deep_free(btc_msg_t *msg)
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_GET_STATE:
|
||||
if (arg->health_client_get_state.params) {
|
||||
osi_free(arg->health_client_get_state.params);
|
||||
bt_mesh_free(arg->health_client_get_state.params);
|
||||
}
|
||||
if (arg->health_client_get_state.get_state) {
|
||||
osi_free(arg->health_client_get_state.get_state);
|
||||
bt_mesh_free(arg->health_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_SET_STATE:
|
||||
if (arg->health_client_set_state.params) {
|
||||
osi_free(arg->health_client_set_state.params);
|
||||
bt_mesh_free(arg->health_client_set_state.params);
|
||||
}
|
||||
if (arg->health_client_set_state.set_state) {
|
||||
osi_free(arg->health_client_set_state.set_state);
|
||||
bt_mesh_free(arg->health_client_set_state.set_state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -120,17 +121,17 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
{
|
||||
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;
|
||||
u16_t length;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
p_dest_data->params = bt_mesh_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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -148,7 +149,7 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.current_status.fault_array->len;
|
||||
p_dest_data->status_cb.current_status.fault_array = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.current_status.fault_array) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.current_status.fault_array,
|
||||
@ -164,7 +165,7 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.fault_status.fault_array->len;
|
||||
p_dest_data->status_cb.fault_status.fault_array = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.fault_status.fault_array) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.fault_status.fault_array,
|
||||
@ -188,7 +189,7 @@ static void btc_ble_mesh_health_client_free_req_data(btc_msg_t *msg)
|
||||
esp_ble_mesh_health_client_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -215,7 +216,7 @@ static void btc_ble_mesh_health_client_free_req_data(btc_msg_t *msg)
|
||||
}
|
||||
case ESP_BLE_MESH_HEALTH_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
osi_free(arg->params);
|
||||
bt_mesh_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -227,7 +228,7 @@ static void btc_ble_mesh_health_client_callback(esp_ble_mesh_health_client_cb_pa
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_HEALTH_CLIENT)) {
|
||||
@ -238,22 +239,21 @@ static void btc_ble_mesh_health_client_callback(esp_ble_mesh_health_client_cb_pa
|
||||
msg.pid = BTC_PID_HEALTH_CLIENT;
|
||||
msg.act = act;
|
||||
|
||||
btc_transfer_context(&msg, cb_params,
|
||||
sizeof(esp_ble_mesh_health_client_cb_param_t), btc_ble_mesh_health_client_copy_req_data);
|
||||
btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_health_client_cb_param_t),
|
||||
btc_ble_mesh_health_client_copy_req_data);
|
||||
}
|
||||
|
||||
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)
|
||||
void bt_mesh_health_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, uint16_t len)
|
||||
{
|
||||
esp_ble_mesh_health_client_cb_param_t cb_params = {0};
|
||||
esp_ble_mesh_client_common_param_t params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -271,7 +271,7 @@ void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
act = ESP_BLE_MESH_HEALTH_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown health client event type %d", __func__, evt_type);
|
||||
BT_ERR("Unknown Health client event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -283,115 +283,114 @@ void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
params.ctx.recv_op = ctx->recv_op;
|
||||
params.ctx.recv_dst = ctx->recv_dst;
|
||||
params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
cb_params.error_code = 0;
|
||||
cb_params.params = ¶ms;
|
||||
|
||||
if (val && len) {
|
||||
length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb);
|
||||
memcpy(&cb_params.status_cb, val, length);
|
||||
memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb)));
|
||||
}
|
||||
|
||||
btc_ble_mesh_health_client_callback(&cb_params, act);
|
||||
return;
|
||||
}
|
||||
|
||||
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_ble_mesh_health_publish_callback(uint32_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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_health_client_cb_evt_to_btc(opcode,
|
||||
BTC_BLE_MESH_EVT_HEALTH_CLIENT_PUBLISH, 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;
|
||||
}
|
||||
|
||||
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)
|
||||
esp_ble_mesh_health_client_get_state_t *get)
|
||||
{
|
||||
struct bt_mesh_msg_ctx ctx = {0};
|
||||
bt_mesh_client_common_param_t param = {0};
|
||||
|
||||
if (!params || !cb) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
if (params == NULL) {
|
||||
BT_ERR("%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;
|
||||
if (params->opcode == ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET && get == NULL) {
|
||||
BT_ERR("Invalid Health Get");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
health_msg_timeout = params->msg_timeout;
|
||||
param.opcode = params->opcode;
|
||||
param.model = (struct bt_mesh_model *)params->model;
|
||||
param.ctx.net_idx = params->ctx.net_idx;
|
||||
param.ctx.app_idx = params->ctx.app_idx;
|
||||
param.ctx.addr = params->ctx.addr;
|
||||
param.ctx.send_rel = params->ctx.send_rel;
|
||||
param.ctx.send_ttl = params->ctx.send_ttl;
|
||||
param.msg_timeout = params->msg_timeout;
|
||||
param.msg_role = params->msg_role;
|
||||
|
||||
switch (params->opcode) {
|
||||
switch (param.opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_ATTENTION_GET:
|
||||
return (cb->error_code = bt_mesh_health_attention_get(&ctx));
|
||||
return bt_mesh_health_attention_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_GET:
|
||||
return (cb->error_code = bt_mesh_health_period_get(&ctx));
|
||||
return bt_mesh_health_period_get(¶m);
|
||||
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET:
|
||||
return (cb->error_code = bt_mesh_health_fault_get(&ctx, get->fault_get.company_id));
|
||||
return bt_mesh_health_fault_get(¶m, get->fault_get.company_id);
|
||||
default:
|
||||
LOG_ERROR("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
return (cb->error_code = -EINVAL);
|
||||
BT_ERR("Invalid Health Get opcode 0x%04x", param.opcode);
|
||||
return -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)
|
||||
esp_ble_mesh_health_client_set_state_t *set)
|
||||
{
|
||||
struct bt_mesh_msg_ctx ctx = {0};
|
||||
bt_mesh_client_common_param_t param = {0};
|
||||
|
||||
if (!params || !set || !cb) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
if (params == NULL || set == NULL) {
|
||||
BT_ERR("%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;
|
||||
param.opcode = params->opcode;
|
||||
param.model = (struct bt_mesh_model *)params->model;
|
||||
param.ctx.net_idx = params->ctx.net_idx;
|
||||
param.ctx.app_idx = params->ctx.app_idx;
|
||||
param.ctx.addr = params->ctx.addr;
|
||||
param.ctx.send_rel = params->ctx.send_rel;
|
||||
param.ctx.send_ttl = params->ctx.send_ttl;
|
||||
param.msg_timeout = params->msg_timeout;
|
||||
param.msg_role = params->msg_role;
|
||||
|
||||
health_msg_timeout = params->msg_timeout;
|
||||
|
||||
switch (params->opcode) {
|
||||
switch (param.opcode) {
|
||||
case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET:
|
||||
return (cb->error_code =
|
||||
bt_mesh_health_attention_set(&ctx, set->attention_set.attention, true));
|
||||
return bt_mesh_health_attention_set(¶m, 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));
|
||||
return bt_mesh_health_attention_set(¶m, 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));
|
||||
return bt_mesh_health_period_set(¶m, 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));
|
||||
return bt_mesh_health_period_set(¶m, 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));
|
||||
return bt_mesh_health_fault_test(¶m, 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));
|
||||
return bt_mesh_health_fault_test(¶m, 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));
|
||||
return bt_mesh_health_fault_clear(¶m, 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));
|
||||
return bt_mesh_health_fault_clear(¶m, set->fault_clear.company_id, false);
|
||||
default:
|
||||
LOG_ERROR("%s, Invalid opcode 0x%x", __func__, params->opcode);
|
||||
return (cb->error_code = -EINVAL);
|
||||
BT_ERR("Invalid Health Set opcode 0x%04x", param.opcode);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -401,10 +400,9 @@ 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 cb = {0};
|
||||
bt_mesh_role_param_t role_param = {0};
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -413,14 +411,8 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_GET_STATE: {
|
||||
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__);
|
||||
break;
|
||||
}
|
||||
btc_ble_mesh_health_client_get_state(arg->health_client_get_state.params,
|
||||
arg->health_client_get_state.get_state, &cb);
|
||||
cb.error_code = btc_ble_mesh_health_client_get_state(arg->health_client_get_state.params,
|
||||
arg->health_client_get_state.get_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_health_client_callback(&cb, ESP_BLE_MESH_HEALTH_CLIENT_GET_STATE_EVT);
|
||||
@ -429,14 +421,8 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_HEALTH_CLIENT_SET_STATE: {
|
||||
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__);
|
||||
break;
|
||||
}
|
||||
btc_ble_mesh_health_client_set_state(arg->health_client_set_state.params,
|
||||
arg->health_client_set_state.set_state, &cb);
|
||||
cb.error_code = btc_ble_mesh_health_client_set_state(arg->health_client_set_state.params,
|
||||
arg->health_client_set_state.set_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_health_client_callback(&cb, ESP_BLE_MESH_HEALTH_CLIENT_SET_STATE_EVT);
|
||||
@ -456,7 +442,7 @@ void btc_ble_mesh_health_client_cb_handler(btc_msg_t *msg)
|
||||
esp_ble_mesh_health_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -465,17 +451,22 @@ void btc_ble_mesh_health_client_cb_handler(btc_msg_t *msg)
|
||||
if (msg->act < ESP_BLE_MESH_HEALTH_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_health_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_health_client_free_req_data(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_HEALTH_CLI */
|
||||
|
||||
#if CONFIG_BLE_MESH_HEALTH_SRV
|
||||
#include "health_srv.h"
|
||||
|
||||
/* 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 *param)
|
||||
{
|
||||
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);
|
||||
@ -487,7 +478,7 @@ static inline void btc_ble_mesh_health_server_cb_to_app(esp_ble_mesh_health_serv
|
||||
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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -502,7 +493,7 @@ void btc_ble_mesh_health_server_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
static void btc_ble_mesh_health_server_arg_deep_free(btc_msg_t *msg)
|
||||
{
|
||||
if (!msg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -517,7 +508,7 @@ static void btc_ble_mesh_health_server_arg_deep_free(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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -532,7 +523,7 @@ static void btc_ble_mesh_health_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
static void btc_ble_mesh_health_server_free_req_data(btc_msg_t *msg)
|
||||
{
|
||||
if (!msg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -548,7 +539,7 @@ static void btc_ble_mesh_health_server_callback(esp_ble_mesh_health_server_cb_pa
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_HEALTH_SERVER)) {
|
||||
@ -559,8 +550,8 @@ static void btc_ble_mesh_health_server_callback(esp_ble_mesh_health_server_cb_pa
|
||||
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);
|
||||
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)
|
||||
@ -569,7 +560,7 @@ void btc_ble_mesh_health_server_call_handler(btc_msg_t *msg)
|
||||
btc_ble_mesh_health_server_args_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -595,7 +586,7 @@ void btc_ble_mesh_health_server_cb_handler(btc_msg_t *msg)
|
||||
esp_ble_mesh_health_server_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -604,14 +595,14 @@ void btc_ble_mesh_health_server_cb_handler(btc_msg_t *msg)
|
||||
if (msg->act < ESP_BLE_MESH_HEALTH_SERVER_EVT_MAX) {
|
||||
btc_ble_mesh_health_server_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
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)
|
||||
void btc_ble_mesh_health_server_fault_clear(struct bt_mesh_model *model, uint16_t company_id)
|
||||
{
|
||||
esp_ble_mesh_health_server_cb_param_t param = {0};
|
||||
|
||||
@ -621,7 +612,8 @@ void btc_ble_mesh_health_server_fault_clear(struct bt_mesh_model *model, u16_t c
|
||||
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)
|
||||
void btc_ble_mesh_health_server_fault_test(struct bt_mesh_model *model,
|
||||
uint8_t test_id, uint16_t company_id)
|
||||
{
|
||||
esp_ble_mesh_health_server_cb_param_t param = {0};
|
||||
|
||||
@ -632,7 +624,7 @@ void btc_ble_mesh_health_server_fault_test(struct bt_mesh_model *model, u8_t tes
|
||||
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)
|
||||
void btc_ble_mesh_health_server_attention_on(struct bt_mesh_model *model, uint8_t time)
|
||||
{
|
||||
esp_ble_mesh_health_server_cb_param_t param = {0};
|
||||
|
||||
@ -650,3 +642,4 @@ void btc_ble_mesh_health_server_attention_off(struct bt_mesh_model *model)
|
||||
|
||||
btc_ble_mesh_health_server_callback(¶m, ESP_BLE_MESH_HEALTH_SERVER_ATTENTION_OFF_EVT);
|
||||
}
|
||||
#endif /* CONFIG_BLE_MESH_HEALTH_SRV */
|
||||
|
@ -15,17 +15,16 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "osi/allocator.h"
|
||||
|
||||
#include "lighting_client.h"
|
||||
#include "btc_ble_mesh_lighting_model.h"
|
||||
#include "esp_ble_mesh_lighting_model_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_LIGHTING_CLIENT
|
||||
#include "lighting_client.h"
|
||||
|
||||
/* 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_param_t *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);
|
||||
@ -40,39 +39,46 @@ void btc_ble_mesh_lighting_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, vo
|
||||
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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
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) {
|
||||
dst->light_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (dst->light_client_get_state.params) {
|
||||
memcpy(dst->light_client_get_state.params, src->light_client_get_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->light_client_get_state.get_state, src->light_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_light_client_get_state_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
if (src->light_client_get_state.get_state) {
|
||||
dst->light_client_get_state.get_state = (esp_ble_mesh_light_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_light_client_get_state_t));
|
||||
if (dst->light_client_get_state.get_state) {
|
||||
memcpy(dst->light_client_get_state.get_state, src->light_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_light_client_get_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
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));
|
||||
dst->light_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->light_client_set_state.set_state = (esp_ble_mesh_light_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_light_client_set_state_t));
|
||||
if (dst->light_client_set_state.params && dst->light_client_set_state.set_state) {
|
||||
memcpy(dst->light_client_set_state.params, src->light_client_set_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->light_client_set_state.set_state, src->light_client_set_state.set_state,
|
||||
sizeof(esp_ble_mesh_light_client_set_state_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act);
|
||||
BT_DBG("%s, Unknown act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -82,7 +88,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -91,18 +97,18 @@ static void btc_ble_mesh_lighting_client_arg_deep_free(btc_msg_t *msg)
|
||||
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);
|
||||
bt_mesh_free(arg->light_client_get_state.params);
|
||||
}
|
||||
if (arg->light_client_get_state.get_state) {
|
||||
osi_free(arg->light_client_get_state.get_state);
|
||||
bt_mesh_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);
|
||||
bt_mesh_free(arg->light_client_set_state.params);
|
||||
}
|
||||
if (arg->light_client_set_state.set_state) {
|
||||
osi_free(arg->light_client_set_state.set_state);
|
||||
bt_mesh_free(arg->light_client_set_state.set_state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -114,17 +120,17 @@ static void btc_ble_mesh_lighting_client_copy_req_data(btc_msg_t *msg, void *p_d
|
||||
{
|
||||
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;
|
||||
u16_t length;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
p_dest_data->params = bt_mesh_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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -144,7 +150,7 @@ static void btc_ble_mesh_lighting_client_copy_req_data(btc_msg_t *msg, void *p_d
|
||||
length = p_src_data->status_cb.lc_property_status.property_value->len;
|
||||
p_dest_data->status_cb.lc_property_status.property_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.lc_property_status.property_value) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.lc_property_status.property_value,
|
||||
@ -168,7 +174,7 @@ static void btc_ble_mesh_lighting_client_free_req_data(btc_msg_t *msg)
|
||||
esp_ble_mesh_light_client_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -191,7 +197,7 @@ static void btc_ble_mesh_lighting_client_free_req_data(btc_msg_t *msg)
|
||||
}
|
||||
case ESP_BLE_MESH_LIGHT_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
osi_free(arg->params);
|
||||
bt_mesh_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -203,7 +209,7 @@ static void btc_ble_mesh_lighting_client_callback(esp_ble_mesh_light_client_cb_p
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_LIGHTING_CLIENT)) {
|
||||
@ -214,22 +220,21 @@ static void btc_ble_mesh_lighting_client_callback(esp_ble_mesh_light_client_cb_p
|
||||
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_lighting_client_copy_req_data);
|
||||
btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_light_client_cb_param_t),
|
||||
btc_ble_mesh_lighting_client_copy_req_data);
|
||||
}
|
||||
|
||||
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)
|
||||
void bt_mesh_lighting_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_light_client_cb_param_t cb_params = {0};
|
||||
esp_ble_mesh_client_common_param_t params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -247,7 +252,7 @@ void bt_mesh_lighting_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
act = ESP_BLE_MESH_LIGHT_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown lighting client event type", __func__);
|
||||
BT_ERR("Unknown Lighting client event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -259,31 +264,31 @@ void bt_mesh_lighting_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
params.ctx.recv_op = ctx->recv_op;
|
||||
params.ctx.recv_dst = ctx->recv_dst;
|
||||
params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
cb_params.error_code = 0;
|
||||
cb_params.params = ¶ms;
|
||||
|
||||
if (val && len) {
|
||||
length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb);
|
||||
memcpy(&cb_params.status_cb, val, length);
|
||||
memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb)));
|
||||
}
|
||||
|
||||
btc_ble_mesh_lighting_client_callback(&cb_params, act);
|
||||
return;
|
||||
}
|
||||
|
||||
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 btc_ble_mesh_lighting_client_publish_callback(uint32_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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_lighting_client_cb_evt_to_btc(opcode,
|
||||
BTC_BLE_MESH_EVT_LIGHTING_CLIENT_PUBLISH, 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;
|
||||
}
|
||||
|
||||
@ -293,10 +298,9 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
|
||||
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) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -305,12 +309,6 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
|
||||
switch (msg->act) {
|
||||
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_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
common.model = (struct bt_mesh_model *)params->model;
|
||||
common.ctx.net_idx = params->ctx.net_idx;
|
||||
@ -319,10 +317,10 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
|
||||
common.ctx.send_rel = params->ctx.send_rel;
|
||||
common.ctx.send_ttl = params->ctx.send_ttl;
|
||||
common.msg_timeout = params->msg_timeout;
|
||||
common.msg_role = params->msg_role;
|
||||
|
||||
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);
|
||||
cb.error_code = bt_mesh_light_client_get_state(&common, arg->light_client_get_state.get_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_lighting_client_callback(&cb, ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT);
|
||||
@ -331,12 +329,6 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
|
||||
}
|
||||
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_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
common.model = (struct bt_mesh_model *)params->model;
|
||||
common.ctx.net_idx = params->ctx.net_idx;
|
||||
@ -345,10 +337,10 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
|
||||
common.ctx.send_rel = params->ctx.send_rel;
|
||||
common.ctx.send_ttl = params->ctx.send_ttl;
|
||||
common.msg_timeout = params->msg_timeout;
|
||||
common.msg_role = params->msg_role;
|
||||
|
||||
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);
|
||||
cb.error_code = bt_mesh_light_client_set_state(&common, arg->light_client_set_state.set_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_lighting_client_callback(&cb, ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT);
|
||||
@ -368,7 +360,7 @@ void btc_ble_mesh_lighting_client_cb_handler(btc_msg_t *msg)
|
||||
esp_ble_mesh_light_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -377,18 +369,21 @@ void btc_ble_mesh_lighting_client_cb_handler(btc_msg_t *msg)
|
||||
if (msg->act < ESP_BLE_MESH_LIGHT_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_lighting_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_lighting_client_free_req_data(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_LIGHTING_CLIENT */
|
||||
|
||||
#if CONFIG_BLE_MESH_LIGHTING_SERVER
|
||||
|
||||
/* 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)
|
||||
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);
|
||||
@ -401,10 +396,10 @@ static void btc_ble_mesh_lighting_server_copy_req_data(btc_msg_t *msg, void *p_d
|
||||
{
|
||||
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;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -416,7 +411,7 @@ static void btc_ble_mesh_lighting_server_copy_req_data(btc_msg_t *msg, void *p_d
|
||||
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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.lc_property_set.property_value,
|
||||
@ -432,7 +427,7 @@ static void btc_ble_mesh_lighting_server_copy_req_data(btc_msg_t *msg, void *p_d
|
||||
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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.set.lc_property.property_value,
|
||||
@ -447,7 +442,7 @@ static void btc_ble_mesh_lighting_server_copy_req_data(btc_msg_t *msg, void *p_d
|
||||
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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.status.sensor_status.data,
|
||||
@ -466,7 +461,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -499,7 +494,7 @@ static void btc_ble_mesh_lighting_server_callback(esp_ble_mesh_lighting_server_c
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_LIGHTING_SERVER)) {
|
||||
@ -510,21 +505,19 @@ static void btc_ble_mesh_lighting_server_callback(esp_ble_mesh_lighting_server_c
|
||||
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);
|
||||
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)
|
||||
void bt_mesh_lighting_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_lighting_server_cb_param_t cb_params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (model == NULL || ctx == NULL) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -542,7 +535,7 @@ void bt_mesh_lighting_server_cb_evt_to_btc(u8_t evt_type,
|
||||
act = ESP_BLE_MESH_LIGHTING_SERVER_RECV_STATUS_MSG_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown Lighting Server event type", __func__);
|
||||
BT_ERR("Unknown Lighting server event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -553,10 +546,11 @@ void bt_mesh_lighting_server_cb_evt_to_btc(u8_t evt_type,
|
||||
cb_params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
cb_params.ctx.recv_op = ctx->recv_op;
|
||||
cb_params.ctx.recv_dst = ctx->recv_dst;
|
||||
cb_params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
cb_params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
if (val && len) {
|
||||
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
|
||||
memcpy(&cb_params.value, val, length);
|
||||
memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value)));
|
||||
}
|
||||
|
||||
btc_ble_mesh_lighting_server_callback(&cb_params, act);
|
||||
@ -568,7 +562,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -577,9 +571,11 @@ void btc_ble_mesh_lighting_server_cb_handler(btc_msg_t *msg)
|
||||
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);
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_lighting_server_free_req_data(msg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_LIGHTING_SERVER */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -15,17 +15,16 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "osi/allocator.h"
|
||||
|
||||
#include "sensor_client.h"
|
||||
#include "btc_ble_mesh_sensor_model.h"
|
||||
#include "esp_ble_mesh_sensor_model_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_SENSOR_CLI
|
||||
#include "sensor_client.h"
|
||||
|
||||
/* 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_param_t *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);
|
||||
@ -38,17 +37,17 @@ 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;
|
||||
u16_t length;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE: {
|
||||
dst->sensor_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->sensor_client_get_state.get_state = (esp_ble_mesh_sensor_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_sensor_client_get_state_t));
|
||||
dst->sensor_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->sensor_client_get_state.get_state = (esp_ble_mesh_sensor_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_sensor_client_get_state_t));
|
||||
if (dst->sensor_client_get_state.params && dst->sensor_client_get_state.get_state) {
|
||||
memcpy(dst->sensor_client_get_state.params, src->sensor_client_get_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
@ -61,7 +60,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
length = src->sensor_client_get_state.get_state->column_get.raw_value_x->len;
|
||||
dst->sensor_client_get_state.get_state->column_get.raw_value_x = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_get_state.get_state->column_get.raw_value_x) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_get_state.get_state->column_get.raw_value_x,
|
||||
@ -74,7 +73,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
length = src->sensor_client_get_state.get_state->series_get.raw_value_x1->len;
|
||||
dst->sensor_client_get_state.get_state->series_get.raw_value_x1 = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_get_state.get_state->series_get.raw_value_x1) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_get_state.get_state->series_get.raw_value_x1,
|
||||
@ -85,7 +84,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
length = src->sensor_client_get_state.get_state->series_get.raw_value_x2->len;
|
||||
dst->sensor_client_get_state.get_state->series_get.raw_value_x2 = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_get_state.get_state->series_get.raw_value_x2) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_get_state.get_state->series_get.raw_value_x2,
|
||||
@ -97,13 +96,13 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE: {
|
||||
dst->sensor_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->sensor_client_set_state.set_state = (esp_ble_mesh_sensor_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_sensor_client_set_state_t));
|
||||
dst->sensor_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->sensor_client_set_state.set_state = (esp_ble_mesh_sensor_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_sensor_client_set_state_t));
|
||||
if (dst->sensor_client_set_state.params && dst->sensor_client_set_state.set_state) {
|
||||
memcpy(dst->sensor_client_set_state.params, src->sensor_client_set_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
@ -116,7 +115,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
length = src->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down->len;
|
||||
dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down,
|
||||
@ -127,7 +126,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
length = src->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up->len;
|
||||
dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up,
|
||||
@ -138,7 +137,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
length = src->sensor_client_set_state.set_state->cadence_set.fast_cadence_low->len;
|
||||
dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_low = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_low) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_low,
|
||||
@ -149,7 +148,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
length = src->sensor_client_set_state.set_state->cadence_set.fast_cadence_high->len;
|
||||
dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_high = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_high) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_high,
|
||||
@ -162,7 +161,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
length = src->sensor_client_set_state.set_state->setting_set.sensor_setting_raw->len;
|
||||
dst->sensor_client_set_state.set_state->setting_set.sensor_setting_raw = bt_mesh_alloc_buf(length);
|
||||
if (!dst->sensor_client_set_state.set_state->setting_set.sensor_setting_raw) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->setting_set.sensor_setting_raw,
|
||||
@ -174,12 +173,12 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act);
|
||||
BT_DBG("%s, Unknown act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -189,7 +188,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -211,10 +210,10 @@ void btc_ble_mesh_sensor_client_arg_deep_free(btc_msg_t *msg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
osi_free(arg->sensor_client_get_state.get_state);
|
||||
bt_mesh_free(arg->sensor_client_get_state.get_state);
|
||||
}
|
||||
if (arg->sensor_client_get_state.params) {
|
||||
osi_free(arg->sensor_client_get_state.params);
|
||||
bt_mesh_free(arg->sensor_client_get_state.params);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE:
|
||||
@ -234,10 +233,10 @@ void btc_ble_mesh_sensor_client_arg_deep_free(btc_msg_t *msg)
|
||||
break;
|
||||
}
|
||||
}
|
||||
osi_free(arg->sensor_client_set_state.set_state);
|
||||
bt_mesh_free(arg->sensor_client_set_state.set_state);
|
||||
}
|
||||
if (arg->sensor_client_set_state.params) {
|
||||
osi_free(arg->sensor_client_set_state.params);
|
||||
bt_mesh_free(arg->sensor_client_set_state.params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -249,17 +248,17 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
{
|
||||
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;
|
||||
u16_t length;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
p_dest_data->params = bt_mesh_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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -278,7 +277,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.descriptor_status.descriptor->len;
|
||||
p_dest_data->status_cb.descriptor_status.descriptor = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.descriptor_status.descriptor) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.descriptor_status.descriptor,
|
||||
@ -293,7 +292,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.cadence_status.sensor_cadence_value->len;
|
||||
p_dest_data->status_cb.cadence_status.sensor_cadence_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.cadence_status.sensor_cadence_value) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.cadence_status.sensor_cadence_value,
|
||||
@ -307,7 +306,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.settings_status.sensor_setting_property_ids->len;
|
||||
p_dest_data->status_cb.settings_status.sensor_setting_property_ids = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.settings_status.sensor_setting_property_ids) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.settings_status.sensor_setting_property_ids,
|
||||
@ -322,7 +321,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.setting_status.sensor_setting_raw->len;
|
||||
p_dest_data->status_cb.setting_status.sensor_setting_raw = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.setting_status.sensor_setting_raw) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.setting_status.sensor_setting_raw,
|
||||
@ -336,7 +335,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.sensor_status.marshalled_sensor_data->len;
|
||||
p_dest_data->status_cb.sensor_status.marshalled_sensor_data = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.sensor_status.marshalled_sensor_data) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.sensor_status.marshalled_sensor_data,
|
||||
@ -350,7 +349,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.column_status.sensor_column_value->len;
|
||||
p_dest_data->status_cb.column_status.sensor_column_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.column_status.sensor_column_value) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.column_status.sensor_column_value,
|
||||
@ -364,7 +363,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
length = p_src_data->status_cb.series_status.sensor_series_value->len;
|
||||
p_dest_data->status_cb.series_status.sensor_series_value = bt_mesh_alloc_buf(length);
|
||||
if (!p_dest_data->status_cb.series_status.sensor_series_value) {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.series_status.sensor_series_value,
|
||||
@ -388,7 +387,7 @@ static void btc_ble_mesh_sensor_client_free_req_data(btc_msg_t *msg)
|
||||
esp_ble_mesh_sensor_client_cb_param_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -436,7 +435,7 @@ static void btc_ble_mesh_sensor_client_free_req_data(btc_msg_t *msg)
|
||||
}
|
||||
case ESP_BLE_MESH_SENSOR_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
osi_free(arg->params);
|
||||
bt_mesh_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -448,7 +447,7 @@ static void btc_ble_mesh_sensor_client_callback(esp_ble_mesh_sensor_client_cb_pa
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_SENSOR_CLIENT)) {
|
||||
@ -459,22 +458,21 @@ static void btc_ble_mesh_sensor_client_callback(esp_ble_mesh_sensor_client_cb_pa
|
||||
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_sensor_client_copy_req_data);
|
||||
btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_sensor_client_cb_param_t),
|
||||
btc_ble_mesh_sensor_client_copy_req_data);
|
||||
}
|
||||
|
||||
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)
|
||||
void bt_mesh_sensor_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_sensor_client_cb_param_t cb_params = {0};
|
||||
esp_ble_mesh_client_common_param_t params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -492,7 +490,7 @@ void bt_mesh_sensor_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
act = ESP_BLE_MESH_SENSOR_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown sensor client event type %d", __func__, evt_type);
|
||||
BT_ERR("Unknown Sensor client event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -504,31 +502,31 @@ void bt_mesh_sensor_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
params.ctx.recv_op = ctx->recv_op;
|
||||
params.ctx.recv_dst = ctx->recv_dst;
|
||||
params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
cb_params.error_code = 0;
|
||||
cb_params.params = ¶ms;
|
||||
|
||||
if (val && len) {
|
||||
length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb);
|
||||
memcpy(&cb_params.status_cb, val, length);
|
||||
memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb)));
|
||||
}
|
||||
|
||||
btc_ble_mesh_sensor_client_callback(&cb_params, act);
|
||||
return;
|
||||
}
|
||||
|
||||
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 btc_ble_mesh_sensor_client_publish_callback(uint32_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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_sensor_client_cb_evt_to_btc(opcode,
|
||||
BTC_BLE_MESH_EVT_SENSOR_CLIENT_PUBLISH, 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;
|
||||
}
|
||||
|
||||
@ -538,10 +536,9 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
|
||||
btc_ble_mesh_sensor_client_args_t *arg = NULL;
|
||||
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) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -550,12 +547,6 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE: {
|
||||
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_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
common.model = (struct bt_mesh_model *)params->model;
|
||||
common.ctx.net_idx = params->ctx.net_idx;
|
||||
@ -564,10 +555,10 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
|
||||
common.ctx.send_rel = params->ctx.send_rel;
|
||||
common.ctx.send_ttl = params->ctx.send_ttl;
|
||||
common.msg_timeout = params->msg_timeout;
|
||||
common.msg_role = params->msg_role;
|
||||
|
||||
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);
|
||||
cb.error_code = bt_mesh_sensor_client_get_state(&common, arg->sensor_client_get_state.get_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_sensor_client_callback(&cb, ESP_BLE_MESH_SENSOR_CLIENT_GET_STATE_EVT);
|
||||
@ -576,12 +567,6 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE: {
|
||||
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_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
common.model = (struct bt_mesh_model *)params->model;
|
||||
common.ctx.net_idx = params->ctx.net_idx;
|
||||
@ -590,10 +575,10 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
|
||||
common.ctx.send_rel = params->ctx.send_rel;
|
||||
common.ctx.send_ttl = params->ctx.send_ttl;
|
||||
common.msg_timeout = params->msg_timeout;
|
||||
common.msg_role = params->msg_role;
|
||||
|
||||
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);
|
||||
cb.error_code = bt_mesh_sensor_client_set_state(&common, arg->sensor_client_set_state.set_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_sensor_client_callback(&cb, ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT);
|
||||
@ -613,7 +598,7 @@ void btc_ble_mesh_sensor_client_cb_handler(btc_msg_t *msg)
|
||||
esp_ble_mesh_sensor_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -622,18 +607,21 @@ void btc_ble_mesh_sensor_client_cb_handler(btc_msg_t *msg)
|
||||
if (msg->act < ESP_BLE_MESH_SENSOR_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_sensor_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_sensor_client_free_req_data(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_SENSOR_CLI */
|
||||
|
||||
#if CONFIG_BLE_MESH_SENSOR_SERVER
|
||||
|
||||
/* 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)
|
||||
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);
|
||||
@ -646,10 +634,10 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
{
|
||||
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;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -661,7 +649,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_down,
|
||||
@ -672,7 +660,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_up,
|
||||
@ -683,7 +671,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_low,
|
||||
@ -694,7 +682,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_high,
|
||||
@ -707,7 +695,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_setting_set.setting_value,
|
||||
@ -722,7 +710,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.get.sensor_column.raw_value_x,
|
||||
@ -734,7 +722,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.get.sensor_series.raw_value,
|
||||
@ -750,7 +738,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.set.sensor_cadence.cadence,
|
||||
@ -763,7 +751,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des
|
||||
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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->value.set.sensor_setting.setting_raw,
|
||||
@ -782,7 +770,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -826,7 +814,7 @@ static void btc_ble_mesh_sensor_server_callback(esp_ble_mesh_sensor_server_cb_pa
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_SENSOR_SERVER)) {
|
||||
@ -837,21 +825,19 @@ static void btc_ble_mesh_sensor_server_callback(esp_ble_mesh_sensor_server_cb_pa
|
||||
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);
|
||||
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)
|
||||
void bt_mesh_sensor_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_sensor_server_cb_param_t cb_params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (model == NULL || ctx == NULL) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -866,7 +852,7 @@ void bt_mesh_sensor_server_cb_evt_to_btc(u8_t evt_type,
|
||||
act = ESP_BLE_MESH_SENSOR_SERVER_RECV_SET_MSG_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown Sensor Server event type", __func__);
|
||||
BT_ERR("Unknown Sensor server event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -877,10 +863,11 @@ void bt_mesh_sensor_server_cb_evt_to_btc(u8_t evt_type,
|
||||
cb_params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
cb_params.ctx.recv_op = ctx->recv_op;
|
||||
cb_params.ctx.recv_dst = ctx->recv_dst;
|
||||
cb_params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
cb_params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
if (val && len) {
|
||||
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
|
||||
memcpy(&cb_params.value, val, length);
|
||||
memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value)));
|
||||
}
|
||||
|
||||
btc_ble_mesh_sensor_server_callback(&cb_params, act);
|
||||
@ -892,7 +879,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -901,9 +888,11 @@ void btc_ble_mesh_sensor_server_cb_handler(btc_msg_t *msg)
|
||||
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);
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_sensor_server_free_req_data(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_SENSOR_SERVER */
|
||||
|
@ -15,17 +15,16 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "btc/btc_manage.h"
|
||||
#include "osi/allocator.h"
|
||||
|
||||
#include "time_scene_client.h"
|
||||
#include "btc_ble_mesh_time_scene_model.h"
|
||||
#include "esp_ble_mesh_time_scene_model_api.h"
|
||||
|
||||
#if CONFIG_BLE_MESH_TIME_SCENE_CLIENT
|
||||
#include "time_scene_client.h"
|
||||
|
||||
/* 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_param_t *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);
|
||||
@ -40,39 +39,46 @@ void btc_ble_mesh_time_scene_client_arg_deep_copy(btc_msg_t *msg, void *p_dest,
|
||||
btc_ble_mesh_time_scene_client_args_t *src = (btc_ble_mesh_time_scene_client_args_t *)p_src;
|
||||
|
||||
if (!msg || !dst || !src) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE: {
|
||||
dst->time_scene_client_get_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->time_scene_client_get_state.get_state = (esp_ble_mesh_time_scene_client_get_state_t *)osi_malloc(sizeof(esp_ble_mesh_time_scene_client_get_state_t));
|
||||
if (dst->time_scene_client_get_state.params && dst->time_scene_client_get_state.get_state) {
|
||||
dst->time_scene_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
if (dst->time_scene_client_get_state.params) {
|
||||
memcpy(dst->time_scene_client_get_state.params, src->time_scene_client_get_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->time_scene_client_get_state.get_state, src->time_scene_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_time_scene_client_get_state_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
if (src->time_scene_client_get_state.get_state) {
|
||||
dst->time_scene_client_get_state.get_state = (esp_ble_mesh_time_scene_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_time_scene_client_get_state_t));
|
||||
if (dst->time_scene_client_get_state.get_state) {
|
||||
memcpy(dst->time_scene_client_get_state.get_state, src->time_scene_client_get_state.get_state,
|
||||
sizeof(esp_ble_mesh_time_scene_client_get_state_t));
|
||||
} else {
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE: {
|
||||
dst->time_scene_client_set_state.params = (esp_ble_mesh_client_common_param_t *)osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->time_scene_client_set_state.set_state = (esp_ble_mesh_time_scene_client_set_state_t *)osi_malloc(sizeof(esp_ble_mesh_time_scene_client_set_state_t));
|
||||
dst->time_scene_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
dst->time_scene_client_set_state.set_state = (esp_ble_mesh_time_scene_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_time_scene_client_set_state_t));
|
||||
if (dst->time_scene_client_set_state.params && dst->time_scene_client_set_state.set_state) {
|
||||
memcpy(dst->time_scene_client_set_state.params, src->time_scene_client_set_state.params,
|
||||
sizeof(esp_ble_mesh_client_common_param_t));
|
||||
memcpy(dst->time_scene_client_set_state.set_state, src->time_scene_client_set_state.set_state,
|
||||
sizeof(esp_ble_mesh_time_scene_client_set_state_t));
|
||||
} else {
|
||||
LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act);
|
||||
BT_DBG("%s, Unknown act %d", __func__, msg->act);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -82,7 +88,7 @@ void btc_ble_mesh_time_scene_client_arg_deep_free(btc_msg_t *msg)
|
||||
btc_ble_mesh_time_scene_client_args_t *arg = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -91,18 +97,18 @@ void btc_ble_mesh_time_scene_client_arg_deep_free(btc_msg_t *msg)
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE:
|
||||
if (arg->time_scene_client_get_state.params) {
|
||||
osi_free(arg->time_scene_client_get_state.params);
|
||||
bt_mesh_free(arg->time_scene_client_get_state.params);
|
||||
}
|
||||
if (arg->time_scene_client_get_state.get_state) {
|
||||
osi_free(arg->time_scene_client_get_state.get_state);
|
||||
bt_mesh_free(arg->time_scene_client_get_state.get_state);
|
||||
}
|
||||
break;
|
||||
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE:
|
||||
if (arg->time_scene_client_set_state.params) {
|
||||
osi_free(arg->time_scene_client_set_state.params);
|
||||
bt_mesh_free(arg->time_scene_client_set_state.params);
|
||||
}
|
||||
if (arg->time_scene_client_set_state.set_state) {
|
||||
osi_free(arg->time_scene_client_set_state.set_state);
|
||||
bt_mesh_free(arg->time_scene_client_set_state.set_state);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -114,17 +120,17 @@ static void btc_ble_mesh_time_scene_client_copy_req_data(btc_msg_t *msg, void *p
|
||||
{
|
||||
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;
|
||||
uint16_t length = 0U;
|
||||
|
||||
if (!msg || !p_src_data || !p_dest_data) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_src_data->params) {
|
||||
p_dest_data->params = osi_malloc(sizeof(esp_ble_mesh_client_common_param_t));
|
||||
p_dest_data->params = bt_mesh_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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -145,7 +151,7 @@ static void btc_ble_mesh_time_scene_client_copy_req_data(btc_msg_t *msg, void *p
|
||||
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);
|
||||
BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
|
||||
return;
|
||||
}
|
||||
net_buf_simple_add_mem(p_dest_data->status_cb.scene_register_status.scenes,
|
||||
@ -169,7 +175,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -193,7 +199,7 @@ static void btc_ble_mesh_time_scene_client_free_req_data(btc_msg_t *msg)
|
||||
}
|
||||
case ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT:
|
||||
if (arg->params) {
|
||||
osi_free(arg->params);
|
||||
bt_mesh_free(arg->params);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -205,7 +211,7 @@ static void btc_ble_mesh_time_scene_client_callback(esp_ble_mesh_time_scene_clie
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_TIME_SCENE_CLIENT)) {
|
||||
@ -216,22 +222,21 @@ static void btc_ble_mesh_time_scene_client_callback(esp_ble_mesh_time_scene_clie
|
||||
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_time_scene_client_copy_req_data);
|
||||
btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_time_scene_client_cb_param_t),
|
||||
btc_ble_mesh_time_scene_client_copy_req_data);
|
||||
}
|
||||
|
||||
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)
|
||||
void bt_mesh_time_scene_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
|
||||
struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_time_scene_client_cb_param_t cb_params = {0};
|
||||
esp_ble_mesh_client_common_param_t params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (!model || !ctx) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -249,7 +254,7 @@ void bt_mesh_time_scene_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
act = ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown time scene client event type %d", __func__, evt_type);
|
||||
BT_ERR("Unknown Time Scene client event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -261,31 +266,31 @@ void bt_mesh_time_scene_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type,
|
||||
params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
params.ctx.recv_op = ctx->recv_op;
|
||||
params.ctx.recv_dst = ctx->recv_dst;
|
||||
params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
cb_params.error_code = 0;
|
||||
cb_params.params = ¶ms;
|
||||
|
||||
if (val && len) {
|
||||
length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb);
|
||||
memcpy(&cb_params.status_cb, val, length);
|
||||
memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb)));
|
||||
}
|
||||
|
||||
btc_ble_mesh_time_scene_client_callback(&cb_params, act);
|
||||
return;
|
||||
}
|
||||
|
||||
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 btc_ble_mesh_time_scene_client_publish_callback(uint32_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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
bt_mesh_time_scene_client_cb_evt_to_btc(opcode,
|
||||
BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_PUBLISH, 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;
|
||||
}
|
||||
|
||||
@ -295,10 +300,9 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
|
||||
esp_ble_mesh_client_common_param_t *params = NULL;
|
||||
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) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -307,12 +311,6 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
|
||||
switch (msg->act) {
|
||||
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE: {
|
||||
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_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
common.model = (struct bt_mesh_model *)params->model;
|
||||
common.ctx.net_idx = params->ctx.net_idx;
|
||||
@ -321,10 +319,10 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
|
||||
common.ctx.send_rel = params->ctx.send_rel;
|
||||
common.ctx.send_ttl = params->ctx.send_ttl;
|
||||
common.msg_timeout = params->msg_timeout;
|
||||
common.msg_role = params->msg_role;
|
||||
|
||||
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);
|
||||
cb.error_code = bt_mesh_time_scene_client_get_state(&common, arg->time_scene_client_get_state.get_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_time_scene_client_callback(&cb, ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT);
|
||||
@ -333,12 +331,6 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
|
||||
}
|
||||
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE: {
|
||||
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_client_model_role(&role_param)) {
|
||||
LOG_ERROR("%s, Failed to set model role", __func__);
|
||||
break;
|
||||
}
|
||||
common.opcode = params->opcode;
|
||||
common.model = (struct bt_mesh_model *)params->model;
|
||||
common.ctx.net_idx = params->ctx.net_idx;
|
||||
@ -347,10 +339,10 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
|
||||
common.ctx.send_rel = params->ctx.send_rel;
|
||||
common.ctx.send_ttl = params->ctx.send_ttl;
|
||||
common.msg_timeout = params->msg_timeout;
|
||||
common.msg_role = params->msg_role;
|
||||
|
||||
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);
|
||||
cb.error_code = bt_mesh_time_scene_client_set_state(&common, arg->time_scene_client_set_state.set_state);
|
||||
if (cb.error_code) {
|
||||
/* If send failed, callback error_code to app layer immediately */
|
||||
btc_ble_mesh_time_scene_client_callback(&cb, ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT);
|
||||
@ -370,7 +362,7 @@ void btc_ble_mesh_time_scene_client_cb_handler(btc_msg_t *msg)
|
||||
esp_ble_mesh_time_scene_client_cb_param_t *param = NULL;
|
||||
|
||||
if (!msg || !msg->arg) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -379,18 +371,21 @@ void btc_ble_mesh_time_scene_client_cb_handler(btc_msg_t *msg)
|
||||
if (msg->act < ESP_BLE_MESH_TIME_SCENE_CLIENT_EVT_MAX) {
|
||||
btc_ble_mesh_time_scene_client_cb_to_app(msg->act, param);
|
||||
} else {
|
||||
LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act);
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
btc_ble_mesh_time_scene_client_free_req_data(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_TIME_SCENE_CLIENT */
|
||||
|
||||
#if CONFIG_BLE_MESH_TIME_SCENE_SERVER
|
||||
|
||||
/* 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)
|
||||
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);
|
||||
@ -403,7 +398,7 @@ static void btc_ble_mesh_time_scene_server_callback(esp_ble_mesh_time_scene_serv
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
|
||||
LOG_DEBUG("%s", __func__);
|
||||
BT_DBG("%s", __func__);
|
||||
|
||||
/* If corresponding callback is not registered, event will not be posted. */
|
||||
if (!btc_profile_cb_get(BTC_PID_TIME_SCENE_SERVER)) {
|
||||
@ -414,21 +409,18 @@ static void btc_ble_mesh_time_scene_server_callback(esp_ble_mesh_time_scene_serv
|
||||
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);
|
||||
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)
|
||||
void bt_mesh_time_scene_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
|
||||
struct bt_mesh_msg_ctx *ctx,
|
||||
const uint8_t *val, size_t len)
|
||||
{
|
||||
esp_ble_mesh_time_scene_server_cb_param_t cb_params = {0};
|
||||
size_t length;
|
||||
uint8_t act;
|
||||
uint8_t act = 0U;
|
||||
|
||||
if (model == NULL || ctx == NULL) {
|
||||
LOG_ERROR("%s, Invalid parameter", __func__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -446,7 +438,7 @@ void bt_mesh_time_scene_server_cb_evt_to_btc(u8_t evt_type,
|
||||
act = ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_STATUS_MSG_EVT;
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("%s, Unknown Time Scene Server event type", __func__);
|
||||
BT_ERR("Unknown Time Scene server event type %d", evt_type);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -457,10 +449,11 @@ void bt_mesh_time_scene_server_cb_evt_to_btc(u8_t evt_type,
|
||||
cb_params.ctx.recv_ttl = ctx->recv_ttl;
|
||||
cb_params.ctx.recv_op = ctx->recv_op;
|
||||
cb_params.ctx.recv_dst = ctx->recv_dst;
|
||||
cb_params.ctx.recv_rssi = ctx->recv_rssi;
|
||||
cb_params.ctx.send_ttl = ctx->send_ttl;
|
||||
|
||||
if (val && len) {
|
||||
length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value);
|
||||
memcpy(&cb_params.value, val, length);
|
||||
memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value)));
|
||||
}
|
||||
|
||||
btc_ble_mesh_time_scene_server_callback(&cb_params, act);
|
||||
@ -472,7 +465,7 @@ 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__);
|
||||
BT_ERR("%s, Invalid parameter", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -481,9 +474,10 @@ void btc_ble_mesh_time_scene_server_cb_handler(btc_msg_t *msg)
|
||||
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);
|
||||
BT_ERR("%s, Unknown act %d", __func__, msg->act);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_BLE_MESH_TIME_SCENE_SERVER */
|
||||
|
62
components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_ble.h
Normal file
62
components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_ble.h
Normal file
@ -0,0 +1,62 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef _BTC_BLE_MESH_BLE_H_
|
||||
#define _BTC_BLE_MESH_BLE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "btc/btc_manage.h"
|
||||
#include "mesh_bearer_adapt.h"
|
||||
#include "esp_ble_mesh_ble_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
esp_ble_mesh_ble_adv_param_t param;
|
||||
esp_ble_mesh_ble_adv_data_t data;
|
||||
} start_ble_adv;
|
||||
struct {
|
||||
uint8_t index;
|
||||
} stop_ble_adv;
|
||||
struct {
|
||||
esp_ble_mesh_ble_scan_param_t param;
|
||||
} start_ble_scan;
|
||||
struct {
|
||||
/* RFU */
|
||||
} stop_ble_scan;
|
||||
} btc_ble_mesh_ble_args_t;
|
||||
|
||||
typedef enum {
|
||||
BTC_BLE_MESH_ACT_START_BLE_ADV,
|
||||
BTC_BLE_MESH_ACT_STOP_BLE_ADV,
|
||||
BTC_BLE_MESH_ACT_START_BLE_SCAN,
|
||||
BTC_BLE_MESH_ACT_STOP_BLE_SCAN,
|
||||
} btc_ble_mesh_ble_act_t;
|
||||
|
||||
void bt_mesh_ble_scan_cb_evt_to_btc(const bt_mesh_addr_t *addr,
|
||||
uint8_t adv_type, uint8_t data[],
|
||||
uint16_t length, int8_t rssi);
|
||||
|
||||
void btc_ble_mesh_ble_call_handler(btc_msg_t *msg);
|
||||
|
||||
void btc_ble_mesh_ble_cb_handler(btc_msg_t *msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _BTC_BLE_MESH_BLE_H_ */
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user