1 // Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <string.h>
16 #include <errno.h>
17
18 #include "btc_ble_mesh_prov.h"
19 #include "btc_ble_mesh_config_model.h"
20 #include "btc_ble_mesh_health_model.h"
21 #include "btc_ble_mesh_generic_model.h"
22 #include "btc_ble_mesh_time_scene_model.h"
23 #include "btc_ble_mesh_sensor_model.h"
24 #include "btc_ble_mesh_lighting_model.h"
25
26 #include "adv.h"
27 #include "mesh_kernel.h"
28 #include "mesh_proxy.h"
29 #include "mesh.h"
30 #include "access.h"
31 #include "prov.h"
32 #include "settings_uid.h"
33 #include "proxy_server.h"
34 #include "proxy_client.h"
35 #include "provisioner_prov.h"
36 #include "provisioner_main.h"
37
38 #if CONFIG_BLE_MESH_CFG_CLI
39 #include "cfg_cli.h"
40 #endif /* CONFIG_BLE_MESH_CFG_CLI */
41 #if CONFIG_BLE_MESH_HEALTH_CLI
42 #include "health_cli.h"
43 #endif /* CONFIG_BLE_MESH_HEALTH_CLI */
44 #include "cfg_srv.h"
45 #if CONFIG_BLE_MESH_HEALTH_SRV
46 #include "health_srv.h"
47 #endif /* CONFIG_BLE_MESH_HEALTH_SRV */
48 #if CONFIG_BLE_MESH_GENERIC_CLIENT
49 #include "generic_client.h"
50 #endif /* CONFIG_BLE_MESH_GENERIC_CLIENT */
51 #if CONFIG_BLE_MESH_LIGHTING_CLIENT
52 #include "lighting_client.h"
53 #endif /* CONFIG_BLE_MESH_LIGHTING_CLIENT */
54 #if CONFIG_BLE_MESH_SENSOR_CLI
55 #include "sensor_client.h"
56 #endif /* CONFIG_BLE_MESH_SENSOR_CLI */
57 #if CONFIG_BLE_MESH_TIME_SCENE_CLIENT
58 #include "time_scene_client.h"
59 #endif /* CONFIG_BLE_MESH_TIME_SCENE_CLIENT */
60 #include "client_common.h"
61 #include "state_binding.h"
62 #include "local_operation.h"
63
64 #include "esp_ble_mesh_common_api.h"
65 #include "esp_ble_mesh_provisioning_api.h"
66 #include "esp_ble_mesh_networking_api.h"
67
btc_ble_mesh_prov_cb_to_app(esp_ble_mesh_prov_cb_event_t event,esp_ble_mesh_prov_cb_param_t * param)68 static inline void btc_ble_mesh_prov_cb_to_app(esp_ble_mesh_prov_cb_event_t event,
69 esp_ble_mesh_prov_cb_param_t *param)
70 {
71 esp_ble_mesh_prov_cb_t btc_ble_mesh_cb =
72 (esp_ble_mesh_prov_cb_t)btc_profile_cb_get(BTC_PID_PROV);
73 if (btc_ble_mesh_cb) {
74 btc_ble_mesh_cb(event, param);
75 }
76 }
77
btc_ble_mesh_model_cb_to_app(esp_ble_mesh_model_cb_event_t event,esp_ble_mesh_model_cb_param_t * param)78 static inline void btc_ble_mesh_model_cb_to_app(esp_ble_mesh_model_cb_event_t event,
79 esp_ble_mesh_model_cb_param_t *param)
80 {
81 esp_ble_mesh_model_cb_t btc_ble_mesh_cb =
82 (esp_ble_mesh_model_cb_t)btc_profile_cb_get(BTC_PID_MODEL);
83 if (btc_ble_mesh_cb) {
84 btc_ble_mesh_cb(event, param);
85 }
86 }
87
btc_ble_mesh_prov_arg_deep_copy(btc_msg_t * msg,void * p_dest,void * p_src)88 void btc_ble_mesh_prov_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
89 {
90 btc_ble_mesh_prov_args_t *dst = (btc_ble_mesh_prov_args_t *)p_dest;
91 btc_ble_mesh_prov_args_t *src = (btc_ble_mesh_prov_args_t *)p_src;
92
93 if (!msg || !dst || !src) {
94 BT_ERR("%s, Invalid parameter", __func__);
95 return;
96 }
97
98 switch (msg->act) {
99 case BTC_BLE_MESH_ACT_PROXY_CLIENT_ADD_FILTER_ADDR:
100 dst->proxy_client_add_filter_addr.addr = (uint16_t *)bt_mesh_calloc(src->proxy_client_add_filter_addr.addr_num << 1);
101 if (dst->proxy_client_add_filter_addr.addr) {
102 memcpy(dst->proxy_client_add_filter_addr.addr, src->proxy_client_add_filter_addr.addr,
103 src->proxy_client_add_filter_addr.addr_num << 1);
104 } else {
105 BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
106 }
107 break;
108 case BTC_BLE_MESH_ACT_PROXY_CLIENT_REMOVE_FILTER_ADDR:
109 dst->proxy_client_remove_filter_addr.addr = bt_mesh_calloc(src->proxy_client_remove_filter_addr.addr_num << 1);
110 if (dst->proxy_client_remove_filter_addr.addr) {
111 memcpy(dst->proxy_client_remove_filter_addr.addr, src->proxy_client_remove_filter_addr.addr,
112 src->proxy_client_remove_filter_addr.addr_num << 1);
113 } else {
114 BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
115 }
116 break;
117 case BTC_BLE_MESH_ACT_PROVISIONER_STORE_NODE_COMP_DATA:
118 dst->store_node_comp_data.data = bt_mesh_calloc(src->store_node_comp_data.length);
119 if (dst->store_node_comp_data.data) {
120 memcpy(dst->store_node_comp_data.data, src->store_node_comp_data.data, src->store_node_comp_data.length);
121 } else {
122 BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
123 }
124 break;
125 default:
126 BT_DBG("%s, Unknown act %d", __func__, msg->act);
127 break;
128 }
129 }
130
btc_ble_mesh_prov_arg_deep_free(btc_msg_t * msg)131 static void btc_ble_mesh_prov_arg_deep_free(btc_msg_t *msg)
132 {
133 btc_ble_mesh_prov_args_t *arg = NULL;
134
135 if (!msg || !msg->arg) {
136 BT_ERR("%s, Invalid parameter", __func__);
137 return;
138 }
139
140 arg = (btc_ble_mesh_prov_args_t *)(msg->arg);
141
142 switch (msg->act) {
143 case BTC_BLE_MESH_ACT_PROXY_CLIENT_ADD_FILTER_ADDR:
144 if (arg->proxy_client_add_filter_addr.addr) {
145 bt_mesh_free(arg->proxy_client_add_filter_addr.addr);
146 }
147 break;
148 case BTC_BLE_MESH_ACT_PROXY_CLIENT_REMOVE_FILTER_ADDR:
149 if (arg->proxy_client_remove_filter_addr.addr) {
150 bt_mesh_free(arg->proxy_client_remove_filter_addr.addr);
151 }
152 break;
153 case BTC_BLE_MESH_ACT_PROVISIONER_STORE_NODE_COMP_DATA:
154 if (arg->store_node_comp_data.data) {
155 bt_mesh_free(arg->store_node_comp_data.data);
156 }
157 break;
158 default:
159 break;
160 }
161 }
162
btc_ble_mesh_model_arg_deep_copy(btc_msg_t * msg,void * p_dest,void * p_src)163 void btc_ble_mesh_model_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src)
164 {
165 btc_ble_mesh_model_args_t *dst = (btc_ble_mesh_model_args_t *)p_dest;
166 btc_ble_mesh_model_args_t *src = (btc_ble_mesh_model_args_t *)p_src;
167
168 if (!msg || !dst || !src) {
169 BT_ERR("%s, Invalid parameter", __func__);
170 return;
171 }
172
173 switch (msg->act) {
174 case BTC_BLE_MESH_ACT_SERVER_MODEL_SEND:
175 case BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND: {
176 dst->model_send.data = src->model_send.length ? (uint8_t *)bt_mesh_malloc(src->model_send.length) : NULL;
177 dst->model_send.ctx = bt_mesh_malloc(sizeof(esp_ble_mesh_msg_ctx_t));
178 if (src->model_send.length) {
179 if (dst->model_send.data) {
180 memcpy(dst->model_send.data, src->model_send.data, src->model_send.length);
181 } else {
182 BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
183 }
184 }
185 if (dst->model_send.ctx) {
186 memcpy(dst->model_send.ctx, src->model_send.ctx, sizeof(esp_ble_mesh_msg_ctx_t));
187 } else {
188 BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
189 }
190 break;
191 }
192 case BTC_BLE_MESH_ACT_SERVER_MODEL_UPDATE_STATE:
193 dst->model_update_state.value = bt_mesh_malloc(sizeof(esp_ble_mesh_server_state_value_t));
194 if (dst->model_update_state.value) {
195 memcpy(dst->model_update_state.value, src->model_update_state.value,
196 sizeof(esp_ble_mesh_server_state_value_t));
197 } else {
198 BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
199 }
200 break;
201 default:
202 BT_DBG("%s, Unknown act %d", __func__, msg->act);
203 break;
204 }
205 }
206
btc_ble_mesh_model_arg_deep_free(btc_msg_t * msg)207 static void btc_ble_mesh_model_arg_deep_free(btc_msg_t *msg)
208 {
209 btc_ble_mesh_model_args_t *arg = NULL;
210
211 if (!msg || !msg->arg) {
212 BT_ERR("%s, Invalid parameter", __func__);
213 return;
214 }
215
216 arg = (btc_ble_mesh_model_args_t *)(msg->arg);
217
218 switch (msg->act) {
219 case BTC_BLE_MESH_ACT_SERVER_MODEL_SEND:
220 case BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND:
221 if (arg->model_send.data) {
222 bt_mesh_free(arg->model_send.data);
223 }
224 if (arg->model_send.ctx) {
225 bt_mesh_free(arg->model_send.ctx);
226 }
227 break;
228 case BTC_BLE_MESH_ACT_SERVER_MODEL_UPDATE_STATE:
229 if (arg->model_update_state.value) {
230 bt_mesh_free(arg->model_update_state.value);
231 }
232 break;
233 default:
234 break;
235 }
236
237 return;
238 }
239
btc_ble_mesh_model_copy_req_data(btc_msg_t * msg,void * p_dest,void * p_src)240 static void btc_ble_mesh_model_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src)
241 {
242 esp_ble_mesh_model_cb_param_t *p_dest_data = (esp_ble_mesh_model_cb_param_t *)p_dest;
243 esp_ble_mesh_model_cb_param_t *p_src_data = (esp_ble_mesh_model_cb_param_t *)p_src;
244
245 if (!msg || !p_src_data || !p_dest_data) {
246 BT_ERR("%s, Invalid parameter", __func__);
247 return;
248 }
249
250 switch (msg->act) {
251 case ESP_BLE_MESH_MODEL_OPERATION_EVT: {
252 if (p_src_data->model_operation.ctx && p_src_data->model_operation.msg) {
253 p_dest_data->model_operation.ctx = bt_mesh_malloc(sizeof(esp_ble_mesh_msg_ctx_t));
254 p_dest_data->model_operation.msg = p_src_data->model_operation.length ? (uint8_t *)bt_mesh_malloc(p_src_data->model_operation.length) : NULL;
255 if (p_dest_data->model_operation.ctx) {
256 memcpy(p_dest_data->model_operation.ctx, p_src_data->model_operation.ctx, sizeof(esp_ble_mesh_msg_ctx_t));
257 } else {
258 BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
259 }
260 if (p_src_data->model_operation.length) {
261 if (p_dest_data->model_operation.msg) {
262 memcpy(p_dest_data->model_operation.msg, p_src_data->model_operation.msg, p_src_data->model_operation.length);
263 } else {
264 BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
265 }
266 }
267 }
268 break;
269 }
270 case ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT: {
271 if (p_src_data->client_recv_publish_msg.ctx && p_src_data->client_recv_publish_msg.msg) {
272 p_dest_data->client_recv_publish_msg.ctx = bt_mesh_malloc(sizeof(esp_ble_mesh_msg_ctx_t));
273 p_dest_data->client_recv_publish_msg.msg = p_src_data->client_recv_publish_msg.length ? (uint8_t *)bt_mesh_malloc(p_src_data->client_recv_publish_msg.length) : NULL;
274 if (p_dest_data->client_recv_publish_msg.ctx) {
275 memcpy(p_dest_data->client_recv_publish_msg.ctx, p_src_data->client_recv_publish_msg.ctx, sizeof(esp_ble_mesh_msg_ctx_t));
276 } else {
277 BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
278 }
279 if (p_src_data->client_recv_publish_msg.length) {
280 if (p_dest_data->client_recv_publish_msg.msg) {
281 memcpy(p_dest_data->client_recv_publish_msg.msg, p_src_data->client_recv_publish_msg.msg, p_src_data->client_recv_publish_msg.length);
282 } else {
283 BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
284 }
285 }
286 }
287 break;
288 }
289 case ESP_BLE_MESH_MODEL_SEND_COMP_EVT: {
290 if (p_src_data->model_send_comp.ctx) {
291 p_dest_data->model_send_comp.ctx = bt_mesh_malloc(sizeof(esp_ble_mesh_msg_ctx_t));
292 if (p_dest_data->model_send_comp.ctx) {
293 memcpy(p_dest_data->model_send_comp.ctx, p_src_data->model_send_comp.ctx, sizeof(esp_ble_mesh_msg_ctx_t));
294 } else {
295 BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
296 }
297 }
298 break;
299 }
300 case ESP_BLE_MESH_CLIENT_MODEL_SEND_TIMEOUT_EVT: {
301 if (p_src_data->client_send_timeout.ctx) {
302 p_dest_data->client_send_timeout.ctx = bt_mesh_malloc(sizeof(esp_ble_mesh_msg_ctx_t));
303 if (p_dest_data->client_send_timeout.ctx) {
304 memcpy(p_dest_data->client_send_timeout.ctx, p_src_data->client_send_timeout.ctx, sizeof(esp_ble_mesh_msg_ctx_t));
305 } else {
306 BT_ERR("%s, Out of memory, act %d", __func__, msg->act);
307 }
308 }
309 break;
310 }
311 default:
312 break;
313 }
314 }
315
btc_ble_mesh_model_free_req_data(btc_msg_t * msg)316 static void btc_ble_mesh_model_free_req_data(btc_msg_t *msg)
317 {
318 esp_ble_mesh_model_cb_param_t *arg = NULL;
319
320 if (!msg || !msg->arg) {
321 BT_ERR("%s, Invalid parameter", __func__);
322 return;
323 }
324
325 arg = (esp_ble_mesh_model_cb_param_t *)(msg->arg);
326
327 switch (msg->act) {
328 case ESP_BLE_MESH_MODEL_OPERATION_EVT: {
329 if (arg->model_operation.msg) {
330 bt_mesh_free(arg->model_operation.msg);
331 }
332 if (arg->model_operation.ctx) {
333 bt_mesh_free(arg->model_operation.ctx);
334 }
335 break;
336 }
337 case ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT: {
338 if (arg->client_recv_publish_msg.msg) {
339 bt_mesh_free(arg->client_recv_publish_msg.msg);
340 }
341 if (arg->client_recv_publish_msg.ctx) {
342 bt_mesh_free(arg->client_recv_publish_msg.ctx);
343 }
344 break;
345 }
346 case ESP_BLE_MESH_MODEL_SEND_COMP_EVT: {
347 if (arg->model_send_comp.ctx) {
348 bt_mesh_free(arg->model_send_comp.ctx);
349 }
350 break;
351 }
352 case ESP_BLE_MESH_CLIENT_MODEL_SEND_TIMEOUT_EVT: {
353 if (arg->client_send_timeout.ctx) {
354 bt_mesh_free(arg->client_send_timeout.ctx);
355 }
356 break;
357 }
358 default:
359 break;
360 }
361 }
362
btc_ble_mesh_model_callback(esp_ble_mesh_model_cb_param_t * param,uint8_t act)363 static bt_status_t btc_ble_mesh_model_callback(esp_ble_mesh_model_cb_param_t *param, uint8_t act)
364 {
365 btc_msg_t msg = {0};
366 bt_status_t ret = BT_STATUS_SUCCESS;
367
368 BT_DBG("%s", __func__);
369
370 /* If corresponding callback is not registered, event will not be posted. */
371 if (!btc_profile_cb_get(BTC_PID_MODEL)) {
372 return BT_STATUS_SUCCESS;
373 }
374
375 msg.sig = BTC_SIG_API_CB;
376 msg.pid = BTC_PID_MODEL;
377 msg.act = act;
378
379 ret = btc_transfer_context(&msg, param, sizeof(esp_ble_mesh_model_cb_param_t),
380 btc_ble_mesh_model_copy_req_data);
381 if (ret != BT_STATUS_SUCCESS) {
382 BT_ERR("btc_transfer_context failed");
383 }
384 return ret;
385 }
386
btc_ble_mesh_server_model_op_cb(struct bt_mesh_model * model,struct bt_mesh_msg_ctx * ctx,struct net_buf_simple * buf)387 static void btc_ble_mesh_server_model_op_cb(struct bt_mesh_model *model,
388 struct bt_mesh_msg_ctx *ctx,
389 struct net_buf_simple *buf)
390 {
391 esp_ble_mesh_model_cb_param_t mesh_param = {0};
392
393 mesh_param.model_operation.opcode = ctx->recv_op;
394 mesh_param.model_operation.model = (esp_ble_mesh_model_t *)model;
395 mesh_param.model_operation.ctx = (esp_ble_mesh_msg_ctx_t *)ctx;
396 mesh_param.model_operation.length = buf->len;
397 mesh_param.model_operation.msg = buf->data;
398
399 btc_ble_mesh_model_callback(&mesh_param, ESP_BLE_MESH_MODEL_OPERATION_EVT);
400 return;
401 }
402
btc_ble_mesh_client_model_op_cb(struct bt_mesh_model * model,struct bt_mesh_msg_ctx * ctx,struct net_buf_simple * buf)403 static void btc_ble_mesh_client_model_op_cb(struct bt_mesh_model *model,
404 struct bt_mesh_msg_ctx *ctx,
405 struct net_buf_simple *buf)
406 {
407 esp_ble_mesh_model_cb_param_t mesh_param = {0};
408 bt_mesh_client_node_t *node = NULL;
409
410 if (!model || !model->user_data || !ctx || !buf) {
411 BT_ERR("%s, Invalid parameter", __func__);
412 return;
413 }
414
415 bt_mesh_client_model_lock();
416
417 node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, false);
418 if (node == NULL) {
419 mesh_param.client_recv_publish_msg.opcode = ctx->recv_op;
420 mesh_param.client_recv_publish_msg.model = (esp_ble_mesh_model_t *)model;
421 mesh_param.client_recv_publish_msg.ctx = (esp_ble_mesh_msg_ctx_t *)ctx;
422 mesh_param.client_recv_publish_msg.length = buf->len;
423 mesh_param.client_recv_publish_msg.msg = buf->data;
424 btc_ble_mesh_model_callback(&mesh_param, ESP_BLE_MESH_CLIENT_MODEL_RECV_PUBLISH_MSG_EVT);
425 } else {
426 mesh_param.model_operation.opcode = ctx->recv_op;
427 mesh_param.model_operation.model = (esp_ble_mesh_model_t *)model;
428 mesh_param.model_operation.ctx = (esp_ble_mesh_msg_ctx_t *)ctx;
429 mesh_param.model_operation.length = buf->len;
430 mesh_param.model_operation.msg = buf->data;
431 if (!k_delayed_work_free(&node->timer)) {
432 bt_mesh_client_free_node(node);
433 btc_ble_mesh_model_callback(&mesh_param, ESP_BLE_MESH_MODEL_OPERATION_EVT);
434 }
435 }
436
437 bt_mesh_client_model_unlock();
438 return;
439 }
440
btc_ble_mesh_client_model_timeout_cb(struct k_work * work)441 static void btc_ble_mesh_client_model_timeout_cb(struct k_work *work)
442 {
443 esp_ble_mesh_model_cb_param_t mesh_param = {0};
444 struct k_delayed_work *timer = NULL;
445 bt_mesh_client_node_t *node = NULL;
446 struct bt_mesh_msg_ctx ctx = {0};
447
448 bt_mesh_client_model_lock();
449
450 timer = CONTAINER_OF(work, struct k_delayed_work, work);
451
452 if (timer && !k_delayed_work_free(timer)) {
453 node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work);
454 if (node) {
455 memcpy(&ctx, &node->ctx, sizeof(ctx));
456 mesh_param.client_send_timeout.opcode = node->opcode;
457 mesh_param.client_send_timeout.model = (esp_ble_mesh_model_t *)ctx.model;
458 mesh_param.client_send_timeout.ctx = (esp_ble_mesh_msg_ctx_t *)&ctx;
459 bt_mesh_client_free_node(node);
460 btc_ble_mesh_model_callback(&mesh_param, ESP_BLE_MESH_CLIENT_MODEL_SEND_TIMEOUT_EVT);
461 }
462 }
463
464 bt_mesh_client_model_unlock();
465 return;
466 }
467
btc_ble_mesh_model_send_comp_cb(esp_ble_mesh_model_t * model,esp_ble_mesh_msg_ctx_t * ctx,uint32_t opcode,int err)468 static void btc_ble_mesh_model_send_comp_cb(esp_ble_mesh_model_t *model,
469 esp_ble_mesh_msg_ctx_t *ctx,
470 uint32_t opcode, int err)
471 {
472 esp_ble_mesh_model_cb_param_t mesh_param = {0};
473
474 mesh_param.model_send_comp.err_code = err;
475 mesh_param.model_send_comp.opcode = opcode;
476 mesh_param.model_send_comp.model = model;
477 mesh_param.model_send_comp.ctx = ctx;
478
479 btc_ble_mesh_model_callback(&mesh_param, ESP_BLE_MESH_MODEL_SEND_COMP_EVT);
480 return;
481 }
482
btc_ble_mesh_model_publish_comp_cb(esp_ble_mesh_model_t * model,int err)483 static void btc_ble_mesh_model_publish_comp_cb(esp_ble_mesh_model_t *model, int err)
484 {
485 esp_ble_mesh_model_cb_param_t mesh_param = {0};
486
487 mesh_param.model_publish_comp.err_code = err;
488 mesh_param.model_publish_comp.model = model;
489
490 btc_ble_mesh_model_callback(&mesh_param, ESP_BLE_MESH_MODEL_PUBLISH_COMP_EVT);
491 return;
492 }
493
btc_ble_mesh_model_publish_update(struct bt_mesh_model * mod)494 static int btc_ble_mesh_model_publish_update(struct bt_mesh_model *mod)
495 {
496 esp_ble_mesh_model_cb_param_t mesh_param = {0};
497 bt_status_t ret = BT_STATUS_SUCCESS;
498
499 BT_DBG("%s", __func__);
500
501 mesh_param.model_publish_update.model = (esp_ble_mesh_model_t *)mod;
502
503 ret = btc_ble_mesh_model_callback(&mesh_param, ESP_BLE_MESH_MODEL_PUBLISH_UPDATE_EVT);
504 return (ret == BT_STATUS_SUCCESS) ? 0 : -1;
505 }
506
507 #if CONFIG_BLE_MESH_SERVER_MODEL
btc_ble_mesh_server_model_update_state_comp_cb(esp_ble_mesh_model_t * model,esp_ble_mesh_server_state_type_t type,int err)508 static void btc_ble_mesh_server_model_update_state_comp_cb(esp_ble_mesh_model_t *model,
509 esp_ble_mesh_server_state_type_t type,
510 int err)
511 {
512 esp_ble_mesh_model_cb_param_t mesh_param = {0};
513
514 mesh_param.server_model_update_state.err_code = err;
515 mesh_param.server_model_update_state.model = model;
516 mesh_param.server_model_update_state.type = type;
517
518 btc_ble_mesh_model_callback(&mesh_param, ESP_BLE_MESH_SERVER_MODEL_UPDATE_STATE_COMP_EVT);
519 return;
520 }
521 #endif /* CONFIG_BLE_MESH_SERVER_MODEL */
522
btc_ble_mesh_prov_callback(esp_ble_mesh_prov_cb_param_t * param,uint8_t act)523 static bt_status_t btc_ble_mesh_prov_callback(esp_ble_mesh_prov_cb_param_t *param, uint8_t act)
524 {
525 btc_msg_t msg = {0};
526 bt_status_t ret = BT_STATUS_SUCCESS;
527
528 BT_DBG("%s", __func__);
529
530 /* If corresponding callback is not registered, event will not be posted. */
531 if (!btc_profile_cb_get(BTC_PID_PROV)) {
532 return BT_STATUS_SUCCESS;
533 }
534
535 msg.sig = BTC_SIG_API_CB;
536 msg.pid = BTC_PID_PROV;
537 msg.act = act;
538
539 ret = btc_transfer_context(&msg, param, sizeof(esp_ble_mesh_prov_cb_param_t), NULL);
540 if (ret != BT_STATUS_SUCCESS) {
541 BT_ERR("btc_transfer_context failed");
542 }
543 return ret;
544 }
545
546 #if CONFIG_BLE_MESH_NODE
btc_ble_mesh_oob_pub_key_cb(void)547 static void btc_ble_mesh_oob_pub_key_cb(void)
548 {
549 BT_DBG("%s", __func__);
550
551 btc_ble_mesh_prov_callback(NULL, ESP_BLE_MESH_NODE_PROV_OOB_PUB_KEY_EVT);
552 return;
553 }
554
btc_ble_mesh_output_number_cb(bt_mesh_output_action_t act,uint32_t num)555 static int btc_ble_mesh_output_number_cb(bt_mesh_output_action_t act, uint32_t num)
556 {
557 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
558 bt_status_t ret = BT_STATUS_SUCCESS;
559
560 BT_DBG("%s", __func__);
561
562 mesh_param.node_prov_output_num.action = (esp_ble_mesh_output_action_t)act;
563 mesh_param.node_prov_output_num.number = num;
564
565 ret = btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_NODE_PROV_OUTPUT_NUMBER_EVT);
566 return (ret == BT_STATUS_SUCCESS) ? 0 : -1;
567 }
568
btc_ble_mesh_output_string_cb(const char * str)569 static int btc_ble_mesh_output_string_cb(const char *str)
570 {
571 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
572 bt_status_t ret = BT_STATUS_SUCCESS;
573
574 BT_DBG("%s", __func__);
575
576 strncpy(mesh_param.node_prov_output_str.string, str,
577 MIN(strlen(str), sizeof(mesh_param.node_prov_output_str.string)));
578
579 ret = btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_NODE_PROV_OUTPUT_STRING_EVT);
580 return (ret == BT_STATUS_SUCCESS) ? 0 : -1;
581 }
582
btc_ble_mesh_input_cb(bt_mesh_input_action_t act,uint8_t size)583 static int btc_ble_mesh_input_cb(bt_mesh_input_action_t act, uint8_t size)
584 {
585 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
586 bt_status_t ret = BT_STATUS_SUCCESS;
587
588 BT_DBG("%s", __func__);
589
590 mesh_param.node_prov_input.action = (esp_ble_mesh_input_action_t)act;
591 mesh_param.node_prov_input.size = size;
592
593 ret = btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_NODE_PROV_INPUT_EVT);
594 return (ret == BT_STATUS_SUCCESS) ? 0 : -1;
595 }
596
btc_ble_mesh_link_open_cb(bt_mesh_prov_bearer_t bearer)597 static void btc_ble_mesh_link_open_cb(bt_mesh_prov_bearer_t bearer)
598 {
599 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
600
601 BT_DBG("%s", __func__);
602
603 mesh_param.node_prov_link_open.bearer = (esp_ble_mesh_prov_bearer_t)bearer;
604
605 btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_NODE_PROV_LINK_OPEN_EVT);
606 return;
607 }
608
btc_ble_mesh_link_close_cb(bt_mesh_prov_bearer_t bearer)609 static void btc_ble_mesh_link_close_cb(bt_mesh_prov_bearer_t bearer)
610 {
611 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
612
613 BT_DBG("%s", __func__);
614
615 mesh_param.node_prov_link_close.bearer = (esp_ble_mesh_prov_bearer_t)bearer;
616
617 btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_NODE_PROV_LINK_CLOSE_EVT);
618 return;
619 }
620
btc_ble_mesh_complete_cb(uint16_t net_idx,const uint8_t net_key[16],uint16_t addr,uint8_t flags,uint32_t iv_index)621 static void btc_ble_mesh_complete_cb(uint16_t net_idx, const uint8_t net_key[16],
622 uint16_t addr, uint8_t flags, uint32_t iv_index)
623 {
624 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
625
626 BT_DBG("%s", __func__);
627
628 mesh_param.node_prov_complete.net_idx = net_idx;
629 memcpy(mesh_param.node_prov_complete.net_key, net_key, 16);
630 mesh_param.node_prov_complete.addr = addr;
631 mesh_param.node_prov_complete.flags = flags;
632 mesh_param.node_prov_complete.iv_index = iv_index;
633
634 btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_NODE_PROV_COMPLETE_EVT);
635 return;
636 }
637
btc_ble_mesh_reset_cb(void)638 static void btc_ble_mesh_reset_cb(void)
639 {
640 BT_DBG("%s", __func__);
641
642 btc_ble_mesh_prov_callback(NULL, ESP_BLE_MESH_NODE_PROV_RESET_EVT);
643 return;
644 }
645
btc_ble_mesh_node_get_local_net_key(uint16_t net_idx)646 const uint8_t *btc_ble_mesh_node_get_local_net_key(uint16_t net_idx)
647 {
648 return bt_mesh_node_get_local_net_key(net_idx);
649 }
650
btc_ble_mesh_node_get_local_app_key(uint16_t app_idx)651 const uint8_t *btc_ble_mesh_node_get_local_app_key(uint16_t app_idx)
652 {
653 return bt_mesh_node_get_local_app_key(app_idx);
654 }
655 #endif /* CONFIG_BLE_MESH_NODE */
656
btc_ble_mesh_prov_register_complete_cb(int err_code)657 static void btc_ble_mesh_prov_register_complete_cb(int err_code)
658 {
659 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
660
661 BT_DBG("%s", __func__);
662
663 mesh_param.prov_register_comp.err_code = err_code;
664
665 btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROV_REGISTER_COMP_EVT);
666 return;
667 }
668
btc_ble_mesh_prov_set_complete_cb(esp_ble_mesh_prov_cb_param_t * param,uint8_t act)669 static void btc_ble_mesh_prov_set_complete_cb(esp_ble_mesh_prov_cb_param_t *param, uint8_t act)
670 {
671 BT_DBG("%s", __func__);
672
673 btc_ble_mesh_prov_callback(param, act);
674 return;
675 }
676
677 #if CONFIG_BLE_MESH_PROVISIONER
btc_ble_mesh_provisioner_recv_unprov_adv_pkt_cb(const uint8_t addr[6],const uint8_t addr_type,const uint8_t adv_type,const uint8_t dev_uuid[16],uint16_t oob_info,bt_mesh_prov_bearer_t bearer,int8_t rssi)678 static void btc_ble_mesh_provisioner_recv_unprov_adv_pkt_cb(const uint8_t addr[6], const uint8_t addr_type,
679 const uint8_t adv_type, const uint8_t dev_uuid[16],
680 uint16_t oob_info, bt_mesh_prov_bearer_t bearer,
681 int8_t rssi)
682 {
683 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
684
685 BT_DBG("%s", __func__);
686
687 if (addr == NULL || dev_uuid == NULL ||
688 (bearer != BLE_MESH_PROV_ADV && bearer != BLE_MESH_PROV_GATT)) {
689 BT_ERR("%s, Invalid parameter", __func__);
690 return;
691 }
692
693 memcpy(mesh_param.provisioner_recv_unprov_adv_pkt.dev_uuid, dev_uuid, 16);
694 memcpy(mesh_param.provisioner_recv_unprov_adv_pkt.addr, addr, BLE_MESH_ADDR_LEN);
695 mesh_param.provisioner_recv_unprov_adv_pkt.addr_type = addr_type;
696 mesh_param.provisioner_recv_unprov_adv_pkt.oob_info = oob_info;
697 mesh_param.provisioner_recv_unprov_adv_pkt.adv_type = adv_type;
698 mesh_param.provisioner_recv_unprov_adv_pkt.bearer = bearer;
699 mesh_param.provisioner_recv_unprov_adv_pkt.rssi = rssi;
700
701 btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROVISIONER_RECV_UNPROV_ADV_PKT_EVT);
702 return;
703 }
704
btc_ble_mesh_provisioner_prov_read_oob_pub_key_cb(uint8_t link_idx)705 static int btc_ble_mesh_provisioner_prov_read_oob_pub_key_cb(uint8_t link_idx)
706 {
707 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
708 bt_status_t ret = BT_STATUS_SUCCESS;
709
710 BT_DBG("%s", __func__);
711
712 mesh_param.provisioner_prov_read_oob_pub_key.link_idx = link_idx;
713
714 ret = btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROVISIONER_PROV_READ_OOB_PUB_KEY_EVT);
715 return (ret == BT_STATUS_SUCCESS) ? 0 : -1;
716 }
717
btc_ble_mesh_provisioner_prov_input_cb(uint8_t method,bt_mesh_output_action_t act,uint8_t size,uint8_t link_idx)718 static int btc_ble_mesh_provisioner_prov_input_cb(uint8_t method, bt_mesh_output_action_t act,
719 uint8_t size, uint8_t link_idx)
720 {
721 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
722 bt_status_t ret = BT_STATUS_SUCCESS;
723
724 BT_DBG("%s", __func__);
725
726 mesh_param.provisioner_prov_input.method = (esp_ble_mesh_oob_method_t)method;
727 mesh_param.provisioner_prov_input.action = (esp_ble_mesh_output_action_t)act;
728 mesh_param.provisioner_prov_input.size = size;
729 mesh_param.provisioner_prov_input.link_idx = link_idx;
730
731 ret = btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROVISIONER_PROV_INPUT_EVT);
732 return (ret == BT_STATUS_SUCCESS) ? 0 : -1;
733 }
734
btc_ble_mesh_provisioner_prov_output_cb(uint8_t method,bt_mesh_input_action_t act,void * data,uint8_t size,uint8_t link_idx)735 static int btc_ble_mesh_provisioner_prov_output_cb(uint8_t method, bt_mesh_input_action_t act,
736 void *data, uint8_t size, uint8_t link_idx)
737 {
738 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
739 bt_status_t ret = BT_STATUS_SUCCESS;
740
741 BT_DBG("%s", __func__);
742
743 mesh_param.provisioner_prov_output.method = (esp_ble_mesh_oob_method_t)method;
744 mesh_param.provisioner_prov_output.action = (esp_ble_mesh_input_action_t)act;
745 mesh_param.provisioner_prov_output.size = size;
746 mesh_param.provisioner_prov_output.link_idx = link_idx;
747 if (act == BLE_MESH_ENTER_STRING) {
748 strncpy(mesh_param.provisioner_prov_output.string, (char *)data, size);
749 } else {
750 mesh_param.provisioner_prov_output.number = sys_get_le32((uint8_t *)data);
751 }
752
753 ret = btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROVISIONER_PROV_OUTPUT_EVT);
754 return (ret == BT_STATUS_SUCCESS) ? 0 : -1;
755 }
756
btc_ble_mesh_provisioner_link_open_cb(bt_mesh_prov_bearer_t bearer)757 static void btc_ble_mesh_provisioner_link_open_cb(bt_mesh_prov_bearer_t bearer)
758 {
759 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
760
761 BT_DBG("%s", __func__);
762
763 mesh_param.provisioner_prov_link_open.bearer = (esp_ble_mesh_prov_bearer_t)bearer;
764
765 btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROVISIONER_PROV_LINK_OPEN_EVT);
766 return;
767 }
768
btc_ble_mesh_provisioner_link_close_cb(bt_mesh_prov_bearer_t bearer,uint8_t reason)769 static void btc_ble_mesh_provisioner_link_close_cb(bt_mesh_prov_bearer_t bearer, uint8_t reason)
770 {
771 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
772
773 BT_DBG("%s", __func__);
774
775 mesh_param.provisioner_prov_link_close.bearer = (esp_ble_mesh_prov_bearer_t)bearer;
776 mesh_param.provisioner_prov_link_close.reason = reason;
777
778 btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROVISIONER_PROV_LINK_CLOSE_EVT);
779 return;
780 }
781
btc_ble_mesh_provisioner_prov_complete_cb(uint16_t node_idx,const uint8_t device_uuid[16],uint16_t unicast_addr,uint8_t element_num,uint16_t netkey_idx)782 static void btc_ble_mesh_provisioner_prov_complete_cb(uint16_t node_idx, const uint8_t device_uuid[16],
783 uint16_t unicast_addr, uint8_t element_num,
784 uint16_t netkey_idx)
785 {
786 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
787
788 BT_DBG("%s", __func__);
789
790 mesh_param.provisioner_prov_complete.node_idx = node_idx;
791 mesh_param.provisioner_prov_complete.unicast_addr = unicast_addr;
792 mesh_param.provisioner_prov_complete.element_num = element_num;
793 mesh_param.provisioner_prov_complete.netkey_idx = netkey_idx;
794 memcpy(mesh_param.provisioner_prov_complete.device_uuid, device_uuid, sizeof(esp_ble_mesh_octet16_t));
795
796 btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROVISIONER_PROV_COMPLETE_EVT);
797 return;
798 }
799
btc_ble_mesh_provisioner_get_node_with_uuid(const uint8_t uuid[16])800 esp_ble_mesh_node_t *btc_ble_mesh_provisioner_get_node_with_uuid(const uint8_t uuid[16])
801 {
802 return (esp_ble_mesh_node_t *)bt_mesh_provisioner_get_node_with_uuid(uuid);
803 }
804
btc_ble_mesh_provisioner_get_node_with_addr(uint16_t unicast_addr)805 esp_ble_mesh_node_t *btc_ble_mesh_provisioner_get_node_with_addr(uint16_t unicast_addr)
806 {
807 return (esp_ble_mesh_node_t *)bt_mesh_provisioner_get_node_with_addr(unicast_addr);
808 }
809
btc_ble_mesh_provisioner_get_node_with_name(const char * name)810 esp_ble_mesh_node_t *btc_ble_mesh_provisioner_get_node_with_name(const char *name)
811 {
812 return (esp_ble_mesh_node_t *)bt_mesh_provisioner_get_node_with_name(name);
813 }
814
btc_ble_mesh_provisioner_get_prov_node_count(void)815 uint16_t btc_ble_mesh_provisioner_get_prov_node_count(void)
816 {
817 return bt_mesh_provisioner_get_node_count();
818 }
819
btc_ble_mesh_provisioner_get_node_table_entry(void)820 const esp_ble_mesh_node_t **btc_ble_mesh_provisioner_get_node_table_entry(void)
821 {
822 return (const esp_ble_mesh_node_t **)bt_mesh_provisioner_get_node_table_entry();
823 }
824
825 #if CONFIG_BLE_MESH_PROVISIONER_RECV_HB
btc_ble_mesh_provisioner_recv_heartbeat_cb(uint16_t hb_src,uint16_t hb_dst,uint8_t init_ttl,uint8_t rx_ttl,uint8_t hops,uint16_t feat,int8_t rssi)826 static void btc_ble_mesh_provisioner_recv_heartbeat_cb(uint16_t hb_src, uint16_t hb_dst,
827 uint8_t init_ttl, uint8_t rx_ttl,
828 uint8_t hops, uint16_t feat, int8_t rssi)
829 {
830 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
831
832 mesh_param.provisioner_recv_heartbeat.hb_src = hb_src;
833 mesh_param.provisioner_recv_heartbeat.hb_dst = hb_dst;
834 mesh_param.provisioner_recv_heartbeat.init_ttl = init_ttl;
835 mesh_param.provisioner_recv_heartbeat.rx_ttl = rx_ttl;
836 mesh_param.provisioner_recv_heartbeat.hops = hops;
837 mesh_param.provisioner_recv_heartbeat.feature = feat;
838 mesh_param.provisioner_recv_heartbeat.rssi = rssi;
839
840 btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROVISIONER_RECV_HEARTBEAT_MESSAGE_EVT);
841 }
842 #endif /* CONFIG_BLE_MESH_PROVISIONER_RECV_HB */
843
844 #if CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE
btc_ble_mesh_provisioner_get_settings_uid(uint8_t index)845 const char *btc_ble_mesh_provisioner_get_settings_uid(uint8_t index)
846 {
847 return bt_mesh_provisioner_get_settings_uid(index);
848 }
849
btc_ble_mesh_provisioner_get_settings_index(const char * uid)850 uint8_t btc_ble_mesh_provisioner_get_settings_index(const char *uid)
851 {
852 return bt_mesh_provisioner_get_settings_index(uid);
853 }
854
btc_ble_mesh_provisioner_get_free_settings_count(void)855 uint8_t btc_ble_mesh_provisioner_get_free_settings_count(void)
856 {
857 return bt_mesh_provisioner_get_free_settings_count();
858 }
859 #endif /* CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE */
860
861 #endif /* CONFIG_BLE_MESH_PROVISIONER */
862
btc_ble_mesh_node_recv_heartbeat_cb(uint8_t hops,uint16_t feature)863 static void btc_ble_mesh_node_recv_heartbeat_cb(uint8_t hops, uint16_t feature)
864 {
865 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
866
867 BT_DBG("%s", __func__);
868
869 mesh_param.heartbeat_msg_recv.hops = hops;
870 mesh_param.heartbeat_msg_recv.feature = feature;
871
872 btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_HEARTBEAT_MESSAGE_RECV_EVT);
873 return;
874 }
875
876 #if CONFIG_BLE_MESH_LOW_POWER
btc_ble_mesh_lpn_cb(uint16_t friend_addr,bool established)877 static void btc_ble_mesh_lpn_cb(uint16_t friend_addr, bool established)
878 {
879 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
880 uint8_t act = 0U;
881
882 BT_DBG("%s", __func__);
883
884 if (established) {
885 mesh_param.lpn_friendship_establish.friend_addr = friend_addr;
886 act = ESP_BLE_MESH_LPN_FRIENDSHIP_ESTABLISH_EVT;
887 } else {
888 mesh_param.lpn_friendship_terminate.friend_addr = friend_addr;
889 act = ESP_BLE_MESH_LPN_FRIENDSHIP_TERMINATE_EVT;
890 }
891
892 btc_ble_mesh_prov_callback(&mesh_param, act);
893 return;
894 }
895 #endif /* CONFIG_BLE_MESH_LOW_POWER */
896
897 #if CONFIG_BLE_MESH_FRIEND
btc_ble_mesh_friend_cb(bool establish,uint16_t lpn_addr,uint8_t reason)898 void btc_ble_mesh_friend_cb(bool establish, uint16_t lpn_addr, uint8_t reason)
899 {
900 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
901 uint8_t act = 0U;
902
903 BT_DBG("%s", __func__);
904
905 if (!BLE_MESH_ADDR_IS_UNICAST(lpn_addr)) {
906 BT_ERR("Not a unicast lpn address 0x%04x", lpn_addr);
907 return;
908 }
909
910 if (establish) {
911 mesh_param.frnd_friendship_establish.lpn_addr = lpn_addr;
912 act = ESP_BLE_MESH_FRIEND_FRIENDSHIP_ESTABLISH_EVT;
913 } else {
914 mesh_param.frnd_friendship_terminate.lpn_addr = lpn_addr;
915 mesh_param.frnd_friendship_terminate.reason = reason;
916 act = ESP_BLE_MESH_FRIEND_FRIENDSHIP_TERMINATE_EVT;
917 }
918
919 btc_ble_mesh_prov_callback(&mesh_param, act);
920 return;
921 }
922 #endif /* CONFIG_BLE_MESH_FRIEND */
923
924 #if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
btc_ble_mesh_proxy_client_adv_recv_cb(const bt_mesh_addr_t * addr,uint8_t type,bt_mesh_proxy_adv_ctx_t * ctx,int8_t rssi)925 static void btc_ble_mesh_proxy_client_adv_recv_cb(const bt_mesh_addr_t *addr, uint8_t type,
926 bt_mesh_proxy_adv_ctx_t *ctx, int8_t rssi)
927 {
928 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
929
930 if (!addr || !ctx || type != BLE_MESH_PROXY_ADV_NET_ID) {
931 BT_ERR("%s, Invalid parameter", __func__);
932 return;
933 }
934
935 BT_DBG("%s", __func__);
936
937 mesh_param.proxy_client_recv_adv_pkt.addr_type = addr->type;
938 memcpy(mesh_param.proxy_client_recv_adv_pkt.addr, addr->val, BD_ADDR_LEN);
939 mesh_param.proxy_client_recv_adv_pkt.net_idx = ctx->net_id.net_idx;
940 memcpy(mesh_param.proxy_client_recv_adv_pkt.net_id, ctx->net_id.net_id, 8);
941 mesh_param.proxy_client_recv_adv_pkt.rssi = rssi;
942
943 btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROXY_CLIENT_RECV_ADV_PKT_EVT);
944 return;
945 }
946
btc_ble_mesh_proxy_client_connect_cb(const bt_mesh_addr_t * addr,uint8_t conn_handle,uint16_t net_idx)947 static void btc_ble_mesh_proxy_client_connect_cb(const bt_mesh_addr_t *addr,
948 uint8_t conn_handle, uint16_t net_idx)
949 {
950 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
951
952 if (!addr || conn_handle >= BLE_MESH_MAX_CONN) {
953 BT_ERR("%s, Invalid parameter", __func__);
954 return;
955 }
956
957 BT_DBG("%s", __func__);
958
959 mesh_param.proxy_client_connected.addr_type = addr->type;
960 memcpy(mesh_param.proxy_client_connected.addr, addr->val, BD_ADDR_LEN);
961 mesh_param.proxy_client_connected.conn_handle = conn_handle;
962 mesh_param.proxy_client_connected.net_idx = net_idx;
963
964 btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROXY_CLIENT_CONNECTED_EVT);
965 return;
966 }
967
btc_ble_mesh_proxy_client_disconnect_cb(const bt_mesh_addr_t * addr,uint8_t conn_handle,uint16_t net_idx,uint8_t reason)968 static void btc_ble_mesh_proxy_client_disconnect_cb(const bt_mesh_addr_t *addr, uint8_t conn_handle,
969 uint16_t net_idx, uint8_t reason)
970 {
971 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
972
973 if (!addr || conn_handle >= BLE_MESH_MAX_CONN) {
974 BT_ERR("%s, Invalid parameter", __func__);
975 return;
976 }
977
978 BT_DBG("%s", __func__);
979
980 mesh_param.proxy_client_disconnected.addr_type = addr->type;
981 memcpy(mesh_param.proxy_client_disconnected.addr, addr->val, BD_ADDR_LEN);
982 mesh_param.proxy_client_disconnected.conn_handle = conn_handle;
983 mesh_param.proxy_client_disconnected.net_idx = net_idx;
984 mesh_param.proxy_client_disconnected.reason = reason;
985
986 btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROXY_CLIENT_DISCONNECTED_EVT);
987 return;
988 }
989
btc_ble_mesh_proxy_client_filter_status_recv_cb(uint8_t conn_handle,uint16_t src,uint16_t net_idx,uint8_t filter_type,uint16_t list_size)990 static void btc_ble_mesh_proxy_client_filter_status_recv_cb(uint8_t conn_handle, uint16_t src, uint16_t net_idx,
991 uint8_t filter_type, uint16_t list_size)
992 {
993 esp_ble_mesh_prov_cb_param_t mesh_param = {0};
994
995 if (conn_handle >= BLE_MESH_MAX_CONN) {
996 BT_ERR("%s, Invalid parameter", __func__);
997 return;
998 }
999
1000 BT_DBG("%s", __func__);
1001
1002 mesh_param.proxy_client_recv_filter_status.conn_handle = conn_handle;
1003 mesh_param.proxy_client_recv_filter_status.server_addr = src;
1004 mesh_param.proxy_client_recv_filter_status.net_idx = net_idx;
1005 mesh_param.proxy_client_recv_filter_status.filter_type = filter_type;
1006 mesh_param.proxy_client_recv_filter_status.list_size = list_size;
1007
1008 btc_ble_mesh_prov_callback(&mesh_param, ESP_BLE_MESH_PROXY_CLIENT_RECV_FILTER_STATUS_EVT);
1009 return;
1010 }
1011 #endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
1012
btc_ble_mesh_client_model_init(esp_ble_mesh_model_t * model)1013 int btc_ble_mesh_client_model_init(esp_ble_mesh_model_t *model)
1014 {
1015 if (!bt_mesh_is_initialized()) {
1016 BT_ERR("Mesh stack is not initialized!");
1017 return -EINVAL;
1018 }
1019
1020 __ASSERT(model && model->op, "%s, Invalid parameter", __func__);
1021 esp_ble_mesh_model_op_t *op = model->op;
1022 while (op != NULL && op->opcode != 0) {
1023 op->param_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_client_model_op_cb;
1024 op++;
1025 }
1026 return bt_mesh_client_init((struct bt_mesh_model *)model);
1027 }
1028
1029 #if CONFIG_BLE_MESH_DEINIT
btc_ble_mesh_client_model_deinit(esp_ble_mesh_model_t * model)1030 int btc_ble_mesh_client_model_deinit(esp_ble_mesh_model_t *model)
1031 {
1032 return bt_mesh_client_deinit((struct bt_mesh_model *)model);
1033 }
1034 #endif /* CONFIG_BLE_MESH_DEINIT */
1035
btc_ble_mesh_model_pub_period_get(esp_ble_mesh_model_t * mod)1036 int32_t btc_ble_mesh_model_pub_period_get(esp_ble_mesh_model_t *mod)
1037 {
1038 return bt_mesh_model_pub_period_get((struct bt_mesh_model *)mod);
1039 }
1040
btc_ble_mesh_get_primary_addr(void)1041 uint16_t btc_ble_mesh_get_primary_addr(void)
1042 {
1043 return bt_mesh_primary_addr();
1044 }
1045
btc_ble_mesh_model_find_group(esp_ble_mesh_model_t * mod,uint16_t addr)1046 uint16_t *btc_ble_mesh_model_find_group(esp_ble_mesh_model_t *mod, uint16_t addr)
1047 {
1048 return bt_mesh_model_find_group((struct bt_mesh_model *)mod, addr);
1049 }
1050
btc_ble_mesh_elem_find(uint16_t addr)1051 esp_ble_mesh_elem_t *btc_ble_mesh_elem_find(uint16_t addr)
1052 {
1053 return (esp_ble_mesh_elem_t *)bt_mesh_elem_find(addr);
1054 }
1055
btc_ble_mesh_elem_count(void)1056 uint8_t btc_ble_mesh_elem_count(void)
1057 {
1058 return bt_mesh_elem_count();
1059 }
1060
btc_ble_mesh_model_find_vnd(const esp_ble_mesh_elem_t * elem,uint16_t company,uint16_t id)1061 esp_ble_mesh_model_t *btc_ble_mesh_model_find_vnd(const esp_ble_mesh_elem_t *elem,
1062 uint16_t company, uint16_t id)
1063 {
1064 return (esp_ble_mesh_model_t *)bt_mesh_model_find_vnd((struct bt_mesh_elem *)elem, company, id);
1065 }
1066
btc_ble_mesh_model_find(const esp_ble_mesh_elem_t * elem,uint16_t id)1067 esp_ble_mesh_model_t *btc_ble_mesh_model_find(const esp_ble_mesh_elem_t *elem, uint16_t id)
1068 {
1069 return (esp_ble_mesh_model_t *)bt_mesh_model_find((struct bt_mesh_elem *)elem, id);
1070 }
1071
btc_ble_mesh_comp_get(void)1072 const esp_ble_mesh_comp_t *btc_ble_mesh_comp_get(void)
1073 {
1074 return (const esp_ble_mesh_comp_t *)bt_mesh_comp_get();
1075 }
1076
1077 /* Configuration Models */
1078 extern const struct bt_mesh_model_op bt_mesh_cfg_srv_op[];
1079 extern const struct bt_mesh_model_cb bt_mesh_cfg_srv_cb;
1080 #if CONFIG_BLE_MESH_CFG_CLI
1081 extern const struct bt_mesh_model_op bt_mesh_cfg_cli_op[];
1082 extern const struct bt_mesh_model_cb bt_mesh_cfg_cli_cb;
1083 #endif /* CONFIG_BLE_MESH_CFG_CLI */
1084
1085 /* Health Models */
1086 #if CONFIG_BLE_MESH_HEALTH_SRV
1087 extern const struct bt_mesh_model_op bt_mesh_health_srv_op[];
1088 extern const struct bt_mesh_model_cb bt_mesh_health_srv_cb;
1089 #endif /* CONFIG_BLE_MESH_HEALTH_SRV */
1090 #if CONFIG_BLE_MESH_HEALTH_CLI
1091 extern const struct bt_mesh_model_op bt_mesh_health_cli_op[];
1092 extern const struct bt_mesh_model_cb bt_mesh_health_cli_cb;
1093 #endif /* CONFIG_BLE_MESH_HEALTH_CLI */
1094
1095 /* Generic Client Models */
1096 #if CONFIG_BLE_MESH_GENERIC_CLIENT
1097 extern const struct bt_mesh_model_op bt_mesh_gen_onoff_cli_op[];
1098 extern const struct bt_mesh_model_op bt_mesh_gen_level_cli_op[];
1099 extern const struct bt_mesh_model_op bt_mesh_gen_def_trans_time_cli_op[];
1100 extern const struct bt_mesh_model_op bt_mesh_gen_power_onoff_cli_op[];
1101 extern const struct bt_mesh_model_op bt_mesh_gen_power_level_cli_op[];
1102 extern const struct bt_mesh_model_op bt_mesh_gen_battery_cli_op[];
1103 extern const struct bt_mesh_model_op bt_mesh_gen_location_cli_op[];
1104 extern const struct bt_mesh_model_op bt_mesh_gen_property_cli_op[];
1105 extern const struct bt_mesh_model_cb bt_mesh_generic_client_cb;
1106 #endif /* CONFIG_BLE_MESH_GENERIC_CLIENT */
1107
1108 /* Lighting Client Models */
1109 #if CONFIG_BLE_MESH_LIGHTING_CLIENT
1110 extern const struct bt_mesh_model_op bt_mesh_light_lightness_cli_op[];
1111 extern const struct bt_mesh_model_op bt_mesh_light_ctl_cli_op[];
1112 extern const struct bt_mesh_model_op bt_mesh_light_hsl_cli_op[];
1113 extern const struct bt_mesh_model_op bt_mesh_light_xyl_cli_op[];
1114 extern const struct bt_mesh_model_op bt_mesh_light_lc_cli_op[];
1115 extern const struct bt_mesh_model_cb bt_mesh_lighting_client_cb;
1116 #endif /* CONFIG_BLE_MESH_LIGHTING_CLIENT */
1117
1118 /* Sensor Client Models */
1119 #if CONFIG_BLE_MESH_SENSOR_CLI
1120 extern const struct bt_mesh_model_op bt_mesh_sensor_cli_op[];
1121 extern const struct bt_mesh_model_cb bt_mesh_sensor_client_cb;
1122 #endif /* CONFIG_BLE_MESH_SENSOR_CLI */
1123
1124 /* Time and Scenes Client Models */
1125 #if CONFIG_BLE_MESH_TIME_SCENE_CLIENT
1126 extern const struct bt_mesh_model_op bt_mesh_time_cli_op[];
1127 extern const struct bt_mesh_model_op bt_mesh_scene_cli_op[];
1128 extern const struct bt_mesh_model_op bt_mesh_scheduler_cli_op[];
1129 extern const struct bt_mesh_model_cb bt_mesh_time_scene_client_cb;
1130 #endif /* CONFIG_BLE_MESH_TIME_SCENE_CLIENT */
1131
1132 /* Generic Server Models */
1133 #if CONFIG_BLE_MESH_GENERIC_SERVER
1134 extern const struct bt_mesh_model_op bt_mesh_gen_onoff_srv_op[];
1135 extern const struct bt_mesh_model_op bt_mesh_gen_level_srv_op[];
1136 extern const struct bt_mesh_model_op bt_mesh_gen_def_trans_time_srv_op[];
1137 extern const struct bt_mesh_model_op bt_mesh_gen_power_onoff_srv_op[];
1138 extern const struct bt_mesh_model_op bt_mesh_gen_power_onoff_setup_srv_op[];
1139 extern const struct bt_mesh_model_op bt_mesh_gen_power_level_srv_op[];
1140 extern const struct bt_mesh_model_op bt_mesh_gen_power_level_setup_srv_op[];
1141 extern const struct bt_mesh_model_op bt_mesh_gen_battery_srv_op[];
1142 extern const struct bt_mesh_model_op bt_mesh_gen_location_srv_op[];
1143 extern const struct bt_mesh_model_op bt_mesh_gen_location_setup_srv_op[];
1144 extern const struct bt_mesh_model_op bt_mesh_gen_user_prop_srv_op[];
1145 extern const struct bt_mesh_model_op bt_mesh_gen_admin_prop_srv_op[];
1146 extern const struct bt_mesh_model_op bt_mesh_gen_manu_prop_srv_op[];
1147 extern const struct bt_mesh_model_op bt_mesh_gen_client_prop_srv_op[];
1148 extern const struct bt_mesh_model_cb bt_mesh_gen_onoff_srv_cb;
1149 extern const struct bt_mesh_model_cb bt_mesh_gen_level_srv_cb;
1150 extern const struct bt_mesh_model_cb bt_mesh_gen_def_trans_time_srv_cb;
1151 extern const struct bt_mesh_model_cb bt_mesh_gen_power_onoff_srv_cb;
1152 extern const struct bt_mesh_model_cb bt_mesh_gen_power_onoff_setup_srv_cb;
1153 extern const struct bt_mesh_model_cb bt_mesh_gen_power_level_srv_cb;
1154 extern const struct bt_mesh_model_cb bt_mesh_gen_power_level_setup_srv_cb;
1155 extern const struct bt_mesh_model_cb bt_mesh_gen_battery_srv_cb;
1156 extern const struct bt_mesh_model_cb bt_mesh_gen_location_srv_cb;
1157 extern const struct bt_mesh_model_cb bt_mesh_gen_location_setup_srv_cb;
1158 extern const struct bt_mesh_model_cb bt_mesh_gen_user_prop_srv_cb;
1159 extern const struct bt_mesh_model_cb bt_mesh_gen_admin_prop_srv_cb;
1160 extern const struct bt_mesh_model_cb bt_mesh_gen_manu_prop_srv_cb;
1161 extern const struct bt_mesh_model_cb bt_mesh_gen_client_prop_srv_cb;
1162 #endif /* CONFIG_BLE_MESH_GENERIC_SERVER */
1163
1164 /* Lighting Server Models */
1165 #if CONFIG_BLE_MESH_LIGHTING_SERVER
1166 extern const struct bt_mesh_model_op bt_mesh_light_lightness_srv_op[];
1167 extern const struct bt_mesh_model_op bt_mesh_light_lightness_setup_srv_op[];
1168 extern const struct bt_mesh_model_op bt_mesh_light_ctl_srv_op[];
1169 extern const struct bt_mesh_model_op bt_mesh_light_ctl_setup_srv_op[];
1170 extern const struct bt_mesh_model_op bt_mesh_light_ctl_temp_srv_op[];
1171 extern const struct bt_mesh_model_op bt_mesh_light_hsl_srv_op[];
1172 extern const struct bt_mesh_model_op bt_mesh_light_hsl_hue_srv_op[];
1173 extern const struct bt_mesh_model_op bt_mesh_light_hsl_sat_srv_op[];
1174 extern const struct bt_mesh_model_op bt_mesh_light_hsl_setup_srv_op[];
1175 extern const struct bt_mesh_model_op bt_mesh_light_xyl_srv_op[];
1176 extern const struct bt_mesh_model_op bt_mesh_light_xyl_setup_srv_op[];
1177 extern const struct bt_mesh_model_cb bt_mesh_light_lightness_srv_cb;
1178 extern const struct bt_mesh_model_cb bt_mesh_light_lightness_setup_srv_cb;
1179 extern const struct bt_mesh_model_cb bt_mesh_light_ctl_srv_cb;
1180 extern const struct bt_mesh_model_cb bt_mesh_light_ctl_setup_srv_cb;
1181 extern const struct bt_mesh_model_cb bt_mesh_light_ctl_temp_srv_cb;
1182 extern const struct bt_mesh_model_cb bt_mesh_light_hsl_srv_cb;
1183 extern const struct bt_mesh_model_cb bt_mesh_light_hsl_hue_srv_cb;
1184 extern const struct bt_mesh_model_cb bt_mesh_light_hsl_sat_srv_cb;
1185 extern const struct bt_mesh_model_cb bt_mesh_light_hsl_setup_srv_cb;
1186 extern const struct bt_mesh_model_cb bt_mesh_light_xyl_srv_cb;
1187 extern const struct bt_mesh_model_cb bt_mesh_light_xyl_setup_srv_cb;
1188 extern const struct bt_mesh_model_op bt_mesh_light_lc_srv_op[];
1189 extern const struct bt_mesh_model_op bt_mesh_light_lc_setup_srv_op[];
1190 extern const struct bt_mesh_model_cb bt_mesh_light_lc_srv_cb;
1191 extern const struct bt_mesh_model_cb bt_mesh_light_lc_setup_srv_cb;
1192 #endif /* CONFIG_BLE_MESH_LIGHTING_SERVER */
1193
1194 /* Time and Scenes Server Models */
1195 #if CONFIG_BLE_MESH_TIME_SCENE_SERVER
1196 extern const struct bt_mesh_model_op bt_mesh_time_srv_op[];
1197 extern const struct bt_mesh_model_op bt_mesh_time_setup_srv_op[];
1198 extern const struct bt_mesh_model_op bt_mesh_scene_srv_op[];
1199 extern const struct bt_mesh_model_op bt_mesh_scene_setup_srv_op[];
1200 extern const struct bt_mesh_model_op bt_mesh_scheduler_srv_op[];
1201 extern const struct bt_mesh_model_op bt_mesh_scheduler_setup_srv_op[];
1202 extern const struct bt_mesh_model_cb bt_mesh_time_srv_cb;
1203 extern const struct bt_mesh_model_cb bt_mesh_time_setup_srv_cb;
1204 extern const struct bt_mesh_model_cb bt_mesh_scene_srv_cb;
1205 extern const struct bt_mesh_model_cb bt_mesh_scene_setup_srv_cb;
1206 extern const struct bt_mesh_model_cb bt_mesh_scheduler_srv_cb;
1207 extern const struct bt_mesh_model_cb bt_mesh_scheduler_setup_srv_cb;
1208 #endif /* CONFIG_BLE_MESH_TIME_SCENE_SERVER */
1209
1210 /* Sensor Server Models */
1211 #if CONFIG_BLE_MESH_SENSOR_SERVER
1212 extern const struct bt_mesh_model_op bt_mesh_sensor_srv_op[];
1213 extern const struct bt_mesh_model_op bt_mesh_sensor_setup_srv_op[];
1214 extern const struct bt_mesh_model_cb bt_mesh_sensor_srv_cb;
1215 extern const struct bt_mesh_model_cb bt_mesh_sensor_setup_srv_cb;
1216 #endif /* CONFIG_BLE_MESH_SENSOR_SERVER */
1217
btc_ble_mesh_model_op_set(esp_ble_mesh_model_t * model)1218 static void btc_ble_mesh_model_op_set(esp_ble_mesh_model_t *model)
1219 {
1220 if (!model) {
1221 BT_ERR("%s, Invalid parameter", __func__);
1222 return;
1223 }
1224
1225 /* For SIG client and server models, model->op will be NULL and initialized here.
1226 * For vendor models whose opcode is 3 bytes, model->op will be initialized here.
1227 */
1228 if (model->op && BLE_MESH_MODEL_OP_LEN(model->op->opcode) == 3) {
1229 goto set_vnd_op;
1230 }
1231
1232 switch (model->model_id) {
1233 case BLE_MESH_MODEL_ID_CFG_SRV: {
1234 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_cfg_srv_op;
1235 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_cfg_srv_cb;
1236 struct bt_mesh_cfg_srv *srv = (struct bt_mesh_cfg_srv *)model->user_data;
1237 if (srv) {
1238 srv->hb_sub.func = btc_ble_mesh_node_recv_heartbeat_cb;
1239 }
1240 break;
1241 }
1242 #if CONFIG_BLE_MESH_CFG_CLI
1243 case BLE_MESH_MODEL_ID_CFG_CLI: {
1244 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_cfg_cli_op;
1245 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_cfg_cli_cb;
1246 bt_mesh_config_client_t *cli = (bt_mesh_config_client_t *)model->user_data;
1247 if (cli != NULL) {
1248 cli->publish_status = btc_ble_mesh_config_client_publish_callback;
1249 }
1250 break;
1251 }
1252 #endif /* CONFIG_BLE_MESH_CFG_CLI */
1253 #if CONFIG_BLE_MESH_HEALTH_SRV
1254 case BLE_MESH_MODEL_ID_HEALTH_SRV: {
1255 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_health_srv_op;
1256 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_health_srv_cb;
1257 struct bt_mesh_health_srv *srv = (struct bt_mesh_health_srv *)model->user_data;
1258 if (srv) {
1259 srv->cb.fault_clear = btc_ble_mesh_health_server_fault_clear;
1260 srv->cb.fault_test = btc_ble_mesh_health_server_fault_test;
1261 srv->cb.attn_on = btc_ble_mesh_health_server_attention_on;
1262 srv->cb.attn_off = btc_ble_mesh_health_server_attention_off;
1263 }
1264 break;
1265 }
1266 #endif /* CONFIG_BLE_MESH_HEALTH_SRV */
1267 #if CONFIG_BLE_MESH_HEALTH_CLI
1268 case BLE_MESH_MODEL_ID_HEALTH_CLI: {
1269 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_health_cli_op;
1270 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_health_cli_cb;
1271 bt_mesh_health_client_t *cli = (bt_mesh_health_client_t *)model->user_data;
1272 if (cli != NULL) {
1273 cli->publish_status = btc_ble_mesh_health_publish_callback;
1274 }
1275 break;
1276 }
1277 #endif /* CONFIG_BLE_MESH_HEALTH_CLI */
1278 #if CONFIG_BLE_MESH_GENERIC_CLIENT
1279 case BLE_MESH_MODEL_ID_GEN_ONOFF_CLI: {
1280 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_onoff_cli_op;
1281 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_generic_client_cb;
1282 bt_mesh_gen_onoff_client_t *cli = (bt_mesh_gen_onoff_client_t *)model->user_data;
1283 if (cli != NULL) {
1284 cli->publish_status = btc_ble_mesh_generic_client_publish_callback;
1285 }
1286 break;
1287 }
1288 case BLE_MESH_MODEL_ID_GEN_LEVEL_CLI: {
1289 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_level_cli_op;
1290 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_generic_client_cb;
1291 bt_mesh_gen_level_client_t *cli = (bt_mesh_gen_level_client_t *)model->user_data;
1292 if (cli != NULL) {
1293 cli->publish_status = btc_ble_mesh_generic_client_publish_callback;
1294 }
1295 break;
1296 }
1297 case BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI: {
1298 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_def_trans_time_cli_op;
1299 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_generic_client_cb;
1300 bt_mesh_gen_def_trans_time_client_t *cli = (bt_mesh_gen_def_trans_time_client_t *)model->user_data;
1301 if (cli != NULL) {
1302 cli->publish_status = btc_ble_mesh_generic_client_publish_callback;
1303 }
1304 break;
1305 }
1306 case BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI: {
1307 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_power_onoff_cli_op;
1308 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_generic_client_cb;
1309 bt_mesh_gen_power_onoff_client_t *cli = (bt_mesh_gen_power_onoff_client_t *)model->user_data;
1310 if (cli != NULL) {
1311 cli->publish_status = btc_ble_mesh_generic_client_publish_callback;
1312 }
1313 break;
1314 }
1315 case BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI: {
1316 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_power_level_cli_op;
1317 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_generic_client_cb;
1318 bt_mesh_gen_power_level_client_t *cli = (bt_mesh_gen_power_level_client_t *)model->user_data;
1319 if (cli != NULL) {
1320 cli->publish_status = btc_ble_mesh_generic_client_publish_callback;
1321 }
1322 break;
1323 }
1324 case BLE_MESH_MODEL_ID_GEN_BATTERY_CLI: {
1325 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_battery_cli_op;
1326 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_generic_client_cb;
1327 bt_mesh_gen_battery_client_t *cli = (bt_mesh_gen_battery_client_t *)model->user_data;
1328 if (cli != NULL) {
1329 cli->publish_status = btc_ble_mesh_generic_client_publish_callback;
1330 }
1331 break;
1332 }
1333 case BLE_MESH_MODEL_ID_GEN_LOCATION_CLI: {
1334 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_location_cli_op;
1335 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_generic_client_cb;
1336 bt_mesh_gen_location_client_t *cli = (bt_mesh_gen_location_client_t *)model->user_data;
1337 if (cli != NULL) {
1338 cli->publish_status = btc_ble_mesh_generic_client_publish_callback;
1339 }
1340 break;
1341 }
1342 case BLE_MESH_MODEL_ID_GEN_PROP_CLI: {
1343 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_property_cli_op;
1344 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_generic_client_cb;
1345 bt_mesh_gen_property_client_t *cli = (bt_mesh_gen_property_client_t *)model->user_data;
1346 if (cli != NULL) {
1347 cli->publish_status = btc_ble_mesh_generic_client_publish_callback;
1348 }
1349 break;
1350 }
1351 #endif /* CONFIG_BLE_MESH_GENERIC_CLIENT */
1352 #if CONFIG_BLE_MESH_LIGHTING_CLIENT
1353 case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI: {
1354 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_lightness_cli_op;
1355 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_lighting_client_cb;
1356 bt_mesh_light_lightness_client_t *cli = (bt_mesh_light_lightness_client_t *)model->user_data;
1357 if (cli != NULL) {
1358 cli->publish_status = btc_ble_mesh_lighting_client_publish_callback;
1359 }
1360 break;
1361 }
1362 case BLE_MESH_MODEL_ID_LIGHT_CTL_CLI: {
1363 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_ctl_cli_op;
1364 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_lighting_client_cb;
1365 bt_mesh_light_ctl_client_t *cli = (bt_mesh_light_ctl_client_t *)model->user_data;
1366 if (cli != NULL) {
1367 cli->publish_status = btc_ble_mesh_lighting_client_publish_callback;
1368 }
1369 break;
1370 }
1371 case BLE_MESH_MODEL_ID_LIGHT_HSL_CLI: {
1372 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_hsl_cli_op;
1373 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_lighting_client_cb;
1374 bt_mesh_light_hsl_client_t *cli = (bt_mesh_light_hsl_client_t *)model->user_data;
1375 if (cli != NULL) {
1376 cli->publish_status = btc_ble_mesh_lighting_client_publish_callback;
1377 }
1378 break;
1379 }
1380 case BLE_MESH_MODEL_ID_LIGHT_XYL_CLI: {
1381 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_xyl_cli_op;
1382 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_lighting_client_cb;
1383 bt_mesh_light_xyl_client_t *cli = (bt_mesh_light_xyl_client_t *)model->user_data;
1384 if (cli != NULL) {
1385 cli->publish_status = btc_ble_mesh_lighting_client_publish_callback;
1386 }
1387 break;
1388 }
1389 case BLE_MESH_MODEL_ID_LIGHT_LC_CLI: {
1390 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_lc_cli_op;
1391 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_lighting_client_cb;
1392 bt_mesh_light_lc_client_t *cli = (bt_mesh_light_lc_client_t *)model->user_data;
1393 if (cli != NULL) {
1394 cli->publish_status = btc_ble_mesh_lighting_client_publish_callback;
1395 }
1396 break;
1397 }
1398 #endif /* CONFIG_BLE_MESH_LIGHTING_CLIENT */
1399 #if CONFIG_BLE_MESH_SENSOR_CLI
1400 case BLE_MESH_MODEL_ID_SENSOR_CLI: {
1401 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_sensor_cli_op;
1402 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_sensor_client_cb;
1403 bt_mesh_sensor_client_t *cli = (bt_mesh_sensor_client_t *)model->user_data;
1404 if (cli != NULL) {
1405 cli->publish_status = btc_ble_mesh_sensor_client_publish_callback;
1406 }
1407 break;
1408 }
1409 #endif /* CONFIG_BLE_MESH_SENSOR_CLI */
1410 #if CONFIG_BLE_MESH_TIME_SCENE_CLIENT
1411 case BLE_MESH_MODEL_ID_TIME_CLI: {
1412 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_time_cli_op;
1413 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_time_scene_client_cb;
1414 bt_mesh_time_client_t *cli = (bt_mesh_time_client_t *)model->user_data;
1415 if (cli != NULL) {
1416 cli->publish_status = btc_ble_mesh_time_scene_client_publish_callback;
1417 }
1418 break;
1419 }
1420 case BLE_MESH_MODEL_ID_SCENE_CLI: {
1421 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_scene_cli_op;
1422 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_time_scene_client_cb;
1423 bt_mesh_scene_client_t *cli = (bt_mesh_scene_client_t *)model->user_data;
1424 if (cli != NULL) {
1425 cli->publish_status = btc_ble_mesh_time_scene_client_publish_callback;
1426 }
1427 break;
1428 }
1429 case BLE_MESH_MODEL_ID_SCHEDULER_CLI: {
1430 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_scheduler_cli_op;
1431 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_time_scene_client_cb;
1432 bt_mesh_scheduler_client_t *cli = (bt_mesh_scheduler_client_t *)model->user_data;
1433 if (cli != NULL) {
1434 cli->publish_status = btc_ble_mesh_time_scene_client_publish_callback;
1435 }
1436 break;
1437 }
1438 #endif /* CONFIG_BLE_MESH_TIME_SCENE_CLIENT */
1439 #if CONFIG_BLE_MESH_GENERIC_SERVER
1440 case BLE_MESH_MODEL_ID_GEN_ONOFF_SRV:
1441 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_onoff_srv_op;
1442 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_onoff_srv_cb;
1443 if (model->pub) {
1444 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1445 }
1446 break;
1447 case BLE_MESH_MODEL_ID_GEN_LEVEL_SRV:
1448 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_level_srv_op;
1449 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_level_srv_cb;
1450 if (model->pub) {
1451 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1452 }
1453 break;
1454 case BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV:
1455 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_def_trans_time_srv_op;
1456 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_def_trans_time_srv_cb;
1457 if (model->pub) {
1458 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1459 }
1460 break;
1461 case BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV:
1462 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_power_onoff_srv_op;
1463 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_power_onoff_srv_cb;
1464 if (model->pub) {
1465 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1466 }
1467 break;
1468 case BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV:
1469 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_power_onoff_setup_srv_op;
1470 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_power_onoff_setup_srv_cb;
1471 if (model->pub) {
1472 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1473 }
1474 break;
1475 case BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV:
1476 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_power_level_srv_op;
1477 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_power_level_srv_cb;
1478 if (model->pub) {
1479 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1480 }
1481 break;
1482 case BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV:
1483 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_power_level_setup_srv_op;
1484 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_power_level_setup_srv_cb;
1485 if (model->pub) {
1486 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1487 }
1488 break;
1489 case BLE_MESH_MODEL_ID_GEN_BATTERY_SRV:
1490 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_battery_srv_op;
1491 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_battery_srv_cb;
1492 if (model->pub) {
1493 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1494 }
1495 break;
1496 case BLE_MESH_MODEL_ID_GEN_LOCATION_SRV:
1497 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_location_srv_op;
1498 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_location_srv_cb;
1499 if (model->pub) {
1500 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1501 }
1502 break;
1503 case BLE_MESH_MODEL_ID_GEN_USER_PROP_SRV:
1504 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_user_prop_srv_op;
1505 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_user_prop_srv_cb;
1506 if (model->pub) {
1507 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1508 }
1509 break;
1510 case BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV:
1511 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_admin_prop_srv_op;
1512 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_admin_prop_srv_cb;
1513 if (model->pub) {
1514 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1515 }
1516 break;
1517 case BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV:
1518 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_manu_prop_srv_op;
1519 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_manu_prop_srv_cb;
1520 if (model->pub) {
1521 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1522 }
1523 break;
1524 case BLE_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV:
1525 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_client_prop_srv_op;
1526 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_client_prop_srv_cb;
1527 if (model->pub) {
1528 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1529 }
1530 break;
1531 case BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV:
1532 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_location_setup_srv_op;
1533 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_location_setup_srv_cb;
1534 if (model->pub) {
1535 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1536 }
1537 break;
1538 #endif /* CONFIG_BLE_MESH_GENERIC_SERVER */
1539 #if CONFIG_BLE_MESH_LIGHTING_SERVER
1540 case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV:
1541 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_lightness_srv_op;
1542 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_lightness_srv_cb;
1543 if (model->pub) {
1544 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1545 }
1546 break;
1547 case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV:
1548 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_lightness_setup_srv_op;
1549 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_lightness_setup_srv_cb;
1550 if (model->pub) {
1551 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1552 }
1553 break;
1554 case BLE_MESH_MODEL_ID_LIGHT_CTL_SRV:
1555 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_ctl_srv_op;
1556 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_ctl_srv_cb;
1557 if (model->pub) {
1558 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1559 }
1560 break;
1561 case BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV:
1562 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_ctl_setup_srv_op;
1563 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_ctl_setup_srv_cb;
1564 if (model->pub) {
1565 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1566 }
1567 break;
1568 case BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV:
1569 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_ctl_temp_srv_op;
1570 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_ctl_temp_srv_cb;
1571 if (model->pub) {
1572 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1573 }
1574 break;
1575 case BLE_MESH_MODEL_ID_LIGHT_HSL_SRV:
1576 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_hsl_srv_op;
1577 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_hsl_srv_cb;
1578 if (model->pub) {
1579 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1580 }
1581 break;
1582 case BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV:
1583 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_hsl_hue_srv_op;
1584 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_hsl_hue_srv_cb;
1585 if (model->pub) {
1586 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1587 }
1588 break;
1589 case BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV:
1590 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_hsl_sat_srv_op;
1591 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_hsl_sat_srv_cb;
1592 if (model->pub) {
1593 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1594 }
1595 break;
1596 case BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV:
1597 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_hsl_setup_srv_op;
1598 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_hsl_setup_srv_cb;
1599 if (model->pub) {
1600 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1601 }
1602 break;
1603 case BLE_MESH_MODEL_ID_LIGHT_XYL_SRV:
1604 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_xyl_srv_op;
1605 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_xyl_srv_cb;
1606 if (model->pub) {
1607 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1608 }
1609 break;
1610 case BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV:
1611 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_xyl_setup_srv_op;
1612 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_xyl_setup_srv_cb;
1613 if (model->pub) {
1614 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1615 }
1616 break;
1617 case BLE_MESH_MODEL_ID_LIGHT_LC_SRV:
1618 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_lc_srv_op;
1619 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_lc_srv_cb;
1620 if (model->pub) {
1621 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1622 }
1623 break;
1624 case BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV:
1625 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_lc_setup_srv_op;
1626 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_lc_setup_srv_cb;
1627 if (model->pub) {
1628 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1629 }
1630 break;
1631 #endif /* CONFIG_BLE_MESH_LIGHTING_SERVER */
1632 #if CONFIG_BLE_MESH_TIME_SCENE_SERVER
1633 case BLE_MESH_MODEL_ID_TIME_SRV:
1634 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_time_srv_op;
1635 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_time_srv_cb;
1636 if (model->pub) {
1637 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1638 }
1639 break;
1640 case BLE_MESH_MODEL_ID_TIME_SETUP_SRV:
1641 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_time_setup_srv_op;
1642 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_time_setup_srv_cb;
1643 if (model->pub) {
1644 /* Time Setup Server model does not support subscribing nor publishing. */
1645 BT_ERR("Time Setup Server shall not support publication");
1646 return;
1647 }
1648 break;
1649 case BLE_MESH_MODEL_ID_SCENE_SRV:
1650 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_scene_srv_op;
1651 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_scene_srv_cb;
1652 if (model->pub) {
1653 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1654 }
1655 break;
1656 case BLE_MESH_MODEL_ID_SCENE_SETUP_SRV:
1657 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_scene_setup_srv_op;
1658 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_scene_setup_srv_cb;
1659 if (model->pub) {
1660 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1661 }
1662 break;
1663 case BLE_MESH_MODEL_ID_SCHEDULER_SRV:
1664 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_scheduler_srv_op;
1665 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_scheduler_srv_cb;
1666 if (model->pub) {
1667 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1668 }
1669 break;
1670 case BLE_MESH_MODEL_ID_SCHEDULER_SETUP_SRV:
1671 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_scheduler_setup_srv_op;
1672 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_scheduler_setup_srv_cb;
1673 if (model->pub) {
1674 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1675 }
1676 break;
1677 #endif /* CONFIG_BLE_MESH_TIME_SCENE_SERVER */
1678 #if CONFIG_BLE_MESH_SENSOR_SERVER
1679 case BLE_MESH_MODEL_ID_SENSOR_SRV:
1680 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_sensor_srv_op;
1681 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_sensor_srv_cb;
1682 if (model->pub) {
1683 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1684 }
1685 break;
1686 case BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV:
1687 model->op = (esp_ble_mesh_model_op_t *)bt_mesh_sensor_setup_srv_op;
1688 model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_sensor_setup_srv_cb;
1689 if (model->pub) {
1690 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1691 }
1692 break;
1693 #endif /* CONFIG_BLE_MESH_SENSOR_SERVER */
1694 default:
1695 goto set_vnd_op;
1696 }
1697 return;
1698
1699 set_vnd_op:
1700 if (model->pub) {
1701 model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update;
1702 }
1703 esp_ble_mesh_model_op_t *op = model->op;
1704 while (op != NULL && op->opcode != 0) {
1705 op->param_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_server_model_op_cb;
1706 op++;
1707 }
1708 return;
1709 }
1710
btc_ble_mesh_prov_call_handler(btc_msg_t * msg)1711 void btc_ble_mesh_prov_call_handler(btc_msg_t *msg)
1712 {
1713 esp_ble_mesh_prov_cb_param_t param = {0};
1714 btc_ble_mesh_prov_args_t *arg = NULL;
1715 uint8_t act = 0U;
1716
1717 if (!msg) {
1718 BT_ERR("%s, Invalid parameter", __func__);
1719 return;
1720 }
1721
1722 arg = (btc_ble_mesh_prov_args_t *)(msg->arg);
1723
1724 switch (msg->act) {
1725 case BTC_BLE_MESH_ACT_MESH_INIT: {
1726 for (int i = 0; i < arg->mesh_init.comp->element_count; i++) {
1727 esp_ble_mesh_elem_t *elem = &arg->mesh_init.comp->elements[i];
1728
1729 for (int j = 0; j < elem->sig_model_count; j++) {
1730 esp_ble_mesh_model_t *sig_model = &elem->sig_models[j];
1731 if (sig_model->op && BLE_MESH_MODEL_OP_LEN(sig_model->op->opcode) == 3) {
1732 /* Opcode of SIG model must be 1 or 2 bytes. */
1733 btc_ble_mesh_prov_register_complete_cb(-EINVAL);
1734 return;
1735 }
1736 btc_ble_mesh_model_op_set(sig_model);
1737 }
1738
1739 for (int k = 0; k < elem->vnd_model_count; k++) {
1740 esp_ble_mesh_model_t *vnd_model = &elem->vnd_models[k];
1741 if (vnd_model->op && BLE_MESH_MODEL_OP_LEN(vnd_model->op->opcode) < 3) {
1742 /* Opcode of vendor model must be 3 bytes. */
1743 btc_ble_mesh_prov_register_complete_cb(-EINVAL);
1744 return;
1745 }
1746 btc_ble_mesh_model_op_set(vnd_model);
1747 }
1748 }
1749 #if CONFIG_BLE_MESH_NODE
1750 arg->mesh_init.prov->oob_pub_key_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_oob_pub_key_cb;
1751 arg->mesh_init.prov->output_num_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_output_number_cb;
1752 arg->mesh_init.prov->output_str_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_output_string_cb;
1753 arg->mesh_init.prov->input_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_input_cb;
1754 arg->mesh_init.prov->link_open_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_link_open_cb;
1755 arg->mesh_init.prov->link_close_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_link_close_cb;
1756 arg->mesh_init.prov->complete_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_complete_cb;
1757 arg->mesh_init.prov->reset_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_reset_cb;
1758 #endif /* CONFIG_BLE_MESH_NODE */
1759 #if CONFIG_BLE_MESH_PROVISIONER
1760 arg->mesh_init.prov->provisioner_prov_read_oob_pub_key = (esp_ble_mesh_cb_t)btc_ble_mesh_provisioner_prov_read_oob_pub_key_cb;
1761 arg->mesh_init.prov->provisioner_prov_input = (esp_ble_mesh_cb_t)btc_ble_mesh_provisioner_prov_input_cb;
1762 arg->mesh_init.prov->provisioner_prov_output = (esp_ble_mesh_cb_t)btc_ble_mesh_provisioner_prov_output_cb;
1763 arg->mesh_init.prov->provisioner_link_open = (esp_ble_mesh_cb_t)btc_ble_mesh_provisioner_link_open_cb;
1764 arg->mesh_init.prov->provisioner_link_close = (esp_ble_mesh_cb_t)btc_ble_mesh_provisioner_link_close_cb;
1765 arg->mesh_init.prov->provisioner_prov_comp = (esp_ble_mesh_cb_t)btc_ble_mesh_provisioner_prov_complete_cb;
1766 bt_mesh_provisioner_adv_pkt_cb_register(btc_ble_mesh_provisioner_recv_unprov_adv_pkt_cb);
1767 #endif /* CONFIG_BLE_MESH_PROVISIONER */
1768 #if CONFIG_BLE_MESH_LOW_POWER
1769 bt_mesh_lpn_set_cb(btc_ble_mesh_lpn_cb);
1770 #endif /* CONFIG_BLE_MESH_LOW_POWER */
1771 #if CONFIG_BLE_MESH_FRIEND
1772 bt_mesh_friend_set_cb(btc_ble_mesh_friend_cb);
1773 #endif /* CONFIG_BLE_MESH_FRIEND */
1774 #if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
1775 bt_mesh_proxy_client_set_adv_recv_cb(btc_ble_mesh_proxy_client_adv_recv_cb);
1776 bt_mesh_proxy_client_set_conn_cb(btc_ble_mesh_proxy_client_connect_cb);
1777 bt_mesh_proxy_client_set_disconn_cb(btc_ble_mesh_proxy_client_disconnect_cb);
1778 bt_mesh_proxy_client_set_filter_status_cb(btc_ble_mesh_proxy_client_filter_status_recv_cb);
1779 #endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
1780 int err_code = bt_mesh_init((struct bt_mesh_prov *)arg->mesh_init.prov,
1781 (struct bt_mesh_comp *)arg->mesh_init.comp);
1782 /* Give the semaphore when BLE Mesh initialization is finished. */
1783 xSemaphoreGive(arg->mesh_init.semaphore);
1784 btc_ble_mesh_prov_register_complete_cb(err_code);
1785 return;
1786 }
1787 #if CONFIG_BLE_MESH_NODE
1788 case BTC_BLE_MESH_ACT_PROV_ENABLE:
1789 act = ESP_BLE_MESH_NODE_PROV_ENABLE_COMP_EVT;
1790 param.node_prov_enable_comp.err_code = bt_mesh_prov_enable(arg->node_prov_enable.bearers);
1791 break;
1792 case BTC_BLE_MESH_ACT_PROV_DISABLE:
1793 act = ESP_BLE_MESH_NODE_PROV_DISABLE_COMP_EVT;
1794 param.node_prov_disable_comp.err_code = bt_mesh_prov_disable(arg->node_prov_disable.bearers);
1795 break;
1796 case BTC_BLE_MESH_ACT_NODE_RESET:
1797 bt_mesh_node_reset();
1798 return;
1799 case BTC_BLE_MESH_ACT_SET_OOB_PUB_KEY:
1800 act = ESP_BLE_MESH_NODE_PROV_SET_OOB_PUB_KEY_COMP_EVT;
1801 param.node_prov_set_oob_pub_key_comp.err_code =
1802 bt_mesh_set_oob_pub_key(arg->set_oob_pub_key.pub_key_x,
1803 arg->set_oob_pub_key.pub_key_y,
1804 arg->set_oob_pub_key.private_key);
1805 break;
1806 case BTC_BLE_MESH_ACT_INPUT_NUMBER:
1807 act = ESP_BLE_MESH_NODE_PROV_INPUT_NUMBER_COMP_EVT;
1808 param.node_prov_input_num_comp.err_code = bt_mesh_input_number(arg->input_number.number);
1809 break;
1810 case BTC_BLE_MESH_ACT_INPUT_STRING:
1811 act = ESP_BLE_MESH_NODE_PROV_INPUT_STRING_COMP_EVT;
1812 param.node_prov_input_str_comp.err_code = bt_mesh_input_string(arg->input_string.string);
1813 break;
1814 case BTC_BLE_MESH_ACT_NODE_ADD_LOCAL_NET_KEY:
1815 act = ESP_BLE_MESH_NODE_ADD_LOCAL_NET_KEY_COMP_EVT;
1816 param.node_add_net_key_comp.net_idx = arg->node_add_local_net_key.net_idx;
1817 param.node_add_net_key_comp.err_code =
1818 bt_mesh_node_local_net_key_add(arg->node_add_local_net_key.net_idx,
1819 arg->node_add_local_net_key.net_key);
1820 break;
1821 case BTC_BLE_MESH_ACT_NODE_ADD_LOCAL_APP_KEY:
1822 act = ESP_BLE_MESH_NODE_ADD_LOCAL_APP_KEY_COMP_EVT;
1823 param.node_add_app_key_comp.net_idx = arg->node_add_local_app_key.net_idx;
1824 param.node_add_app_key_comp.app_idx = arg->node_add_local_app_key.app_idx;
1825 param.node_add_app_key_comp.err_code =
1826 bt_mesh_node_local_app_key_add(arg->node_add_local_app_key.net_idx,
1827 arg->node_add_local_app_key.app_idx,
1828 arg->node_add_local_app_key.app_key);
1829 break;
1830 case BTC_BLE_MESH_ACT_NODE_BIND_APP_KEY_TO_MODEL:
1831 act = ESP_BLE_MESH_NODE_BIND_APP_KEY_TO_MODEL_COMP_EVT;
1832 param.node_bind_app_key_to_model_comp.element_addr = arg->node_local_mod_app_bind.element_addr;
1833 param.node_bind_app_key_to_model_comp.model_id = arg->node_local_mod_app_bind.model_id;
1834 param.node_bind_app_key_to_model_comp.company_id = arg->node_local_mod_app_bind.company_id;
1835 param.node_bind_app_key_to_model_comp.app_idx = arg->node_local_mod_app_bind.app_idx;
1836 param.node_bind_app_key_to_model_comp.err_code =
1837 bt_mesh_node_bind_app_key_to_model(arg->node_local_mod_app_bind.element_addr,
1838 arg->node_local_mod_app_bind.model_id,
1839 arg->node_local_mod_app_bind.company_id,
1840 arg->node_local_mod_app_bind.app_idx);
1841 break;
1842 #endif /* CONFIG_BLE_MESH_NODE */
1843 #if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \
1844 CONFIG_BLE_MESH_GATT_PROXY_SERVER
1845 case BTC_BLE_MESH_ACT_SET_DEVICE_NAME:
1846 act = ESP_BLE_MESH_NODE_SET_UNPROV_DEV_NAME_COMP_EVT;
1847 param.node_set_unprov_dev_name_comp.err_code = bt_mesh_set_device_name(arg->set_device_name.name);
1848 break;
1849 #if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
1850 case BTC_BLE_MESH_ACT_PROXY_IDENTITY_ENABLE:
1851 act = ESP_BLE_MESH_NODE_PROXY_IDENTITY_ENABLE_COMP_EVT;
1852 param.node_proxy_identity_enable_comp.err_code = bt_mesh_proxy_identity_enable();
1853 break;
1854 case BTC_BLE_MESH_ACT_PROXY_GATT_ENABLE:
1855 act = ESP_BLE_MESH_NODE_PROXY_GATT_ENABLE_COMP_EVT;
1856 param.node_proxy_gatt_enable_comp.err_code = bt_mesh_proxy_server_gatt_enable();
1857 break;
1858 case BTC_BLE_MESH_ACT_PROXY_GATT_DISABLE:
1859 act = ESP_BLE_MESH_NODE_PROXY_GATT_DISABLE_COMP_EVT;
1860 param.node_proxy_gatt_disable_comp.err_code = bt_mesh_proxy_server_gatt_disable();
1861 break;
1862 #endif /* CONFIG_BLE_MESH_GATT_PROXY_SERVER */
1863 #endif /* (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_SERVER */
1864 #if CONFIG_BLE_MESH_PROVISIONER
1865 case BTC_BLE_MESH_ACT_PROVISIONER_READ_OOB_PUB_KEY:
1866 act = ESP_BLE_MESH_PROVISIONER_PROV_READ_OOB_PUB_KEY_COMP_EVT;
1867 param.provisioner_prov_read_oob_pub_key_comp.err_code =
1868 bt_mesh_provisioner_read_oob_pub_key(arg->provisioner_read_oob_pub_key.link_idx,
1869 arg->provisioner_read_oob_pub_key.pub_key_x,
1870 arg->provisioner_read_oob_pub_key.pub_key_y);
1871 break;
1872 case BTC_BLE_MESH_ACT_PROVISIONER_INPUT_STR:
1873 act = ESP_BLE_MESH_PROVISIONER_PROV_INPUT_STRING_COMP_EVT;
1874 param.provisioner_prov_input_str_comp.err_code =
1875 bt_mesh_provisioner_set_oob_input_data(arg->provisioner_input_str.link_idx,
1876 (const uint8_t *)&arg->provisioner_input_str.string,
1877 false);
1878 break;
1879 case BTC_BLE_MESH_ACT_PROVISIONER_INPUT_NUM:
1880 act = ESP_BLE_MESH_PROVISIONER_PROV_INPUT_NUMBER_COMP_EVT;
1881 param.provisioner_prov_input_num_comp.err_code =
1882 bt_mesh_provisioner_set_oob_input_data(arg->provisioner_input_num.link_idx,
1883 (const uint8_t *)&arg->provisioner_input_num.number,
1884 true);
1885 break;
1886 case BTC_BLE_MESH_ACT_PROVISIONER_ENABLE:
1887 act = ESP_BLE_MESH_PROVISIONER_PROV_ENABLE_COMP_EVT;
1888 param.provisioner_prov_enable_comp.err_code =
1889 bt_mesh_provisioner_enable(arg->provisioner_enable.bearers);
1890 break;
1891 case BTC_BLE_MESH_ACT_PROVISIONER_DISABLE:
1892 act = ESP_BLE_MESH_PROVISIONER_PROV_DISABLE_COMP_EVT;
1893 param.provisioner_prov_disable_comp.err_code =
1894 bt_mesh_provisioner_disable(arg->provisioner_disable.bearers);
1895 break;
1896 case BTC_BLE_MESH_ACT_PROVISIONER_DEV_ADD: {
1897 struct bt_mesh_unprov_dev_add add_dev = {0};
1898 add_dev.addr_type = arg->provisioner_dev_add.add_dev.addr_type;
1899 add_dev.oob_info = arg->provisioner_dev_add.add_dev.oob_info;
1900 add_dev.bearer = arg->provisioner_dev_add.add_dev.bearer;
1901 memcpy(add_dev.addr, arg->provisioner_dev_add.add_dev.addr, 6);
1902 memcpy(add_dev.uuid, arg->provisioner_dev_add.add_dev.uuid, 16);
1903 act = ESP_BLE_MESH_PROVISIONER_ADD_UNPROV_DEV_COMP_EVT;
1904 param.provisioner_add_unprov_dev_comp.err_code =
1905 bt_mesh_provisioner_add_unprov_dev(&add_dev, arg->provisioner_dev_add.flags);
1906 break;
1907 }
1908 case BTC_BLE_MESH_ACT_PROVISIONER_PROV_DEV_WITH_ADDR:
1909 act = ESP_BLE_MESH_PROVISIONER_PROV_DEV_WITH_ADDR_COMP_EVT;
1910 param.provisioner_prov_dev_with_addr_comp.err_code =
1911 bt_mesh_provisioner_prov_device_with_addr(arg->provisioner_prov_dev_with_addr.uuid,
1912 arg->provisioner_prov_dev_with_addr.addr, arg->provisioner_prov_dev_with_addr.addr_type,
1913 arg->provisioner_prov_dev_with_addr.bearer, arg->provisioner_prov_dev_with_addr.oob_info,
1914 arg->provisioner_prov_dev_with_addr.unicast_addr);
1915 break;
1916 case BTC_BLE_MESH_ACT_PROVISIONER_DEV_DEL: {
1917 struct bt_mesh_device_delete del_dev = {0};
1918 if (arg->provisioner_dev_del.del_dev.flag & DEL_DEV_ADDR_FLAG) {
1919 del_dev.addr_type = arg->provisioner_dev_del.del_dev.addr_type;
1920 memcpy(del_dev.addr, arg->provisioner_dev_del.del_dev.addr, 6);
1921 } else if (arg->provisioner_dev_del.del_dev.flag & DEL_DEV_UUID_FLAG) {
1922 memcpy(del_dev.uuid, arg->provisioner_dev_del.del_dev.uuid, 16);
1923 }
1924 act = ESP_BLE_MESH_PROVISIONER_DELETE_DEV_COMP_EVT;
1925 param.provisioner_delete_dev_comp.err_code = bt_mesh_provisioner_delete_device(&del_dev);
1926 break;
1927 }
1928 case BTC_BLE_MESH_ACT_PROVISIONER_SET_DEV_UUID_MATCH:
1929 act = ESP_BLE_MESH_PROVISIONER_SET_DEV_UUID_MATCH_COMP_EVT;
1930 param.provisioner_set_dev_uuid_match_comp.err_code =
1931 bt_mesh_provisioner_set_dev_uuid_match(arg->set_dev_uuid_match.offset,
1932 arg->set_dev_uuid_match.match_len,
1933 arg->set_dev_uuid_match.match_val,
1934 arg->set_dev_uuid_match.prov_after_match);
1935 break;
1936 case BTC_BLE_MESH_ACT_PROVISIONER_SET_PROV_DATA_INFO: {
1937 struct bt_mesh_prov_data_info info = {0};
1938 info.flag = arg->set_prov_data_info.prov_data.flag;
1939 if (arg->set_prov_data_info.prov_data.flag & PROV_DATA_NET_IDX_FLAG) {
1940 info.net_idx = arg->set_prov_data_info.prov_data.net_idx;
1941 } else if (arg->set_prov_data_info.prov_data.flag & PROV_DATA_FLAGS_FLAG) {
1942 info.flags = arg->set_prov_data_info.prov_data.flags;
1943 } else if (arg->set_prov_data_info.prov_data.flag & PROV_DATA_IV_INDEX_FLAG) {
1944 info.iv_index = arg->set_prov_data_info.prov_data.iv_index;
1945 }
1946 act = ESP_BLE_MESH_PROVISIONER_SET_PROV_DATA_INFO_COMP_EVT;
1947 param.provisioner_set_prov_data_info_comp.err_code =
1948 bt_mesh_provisioner_set_prov_data_info(&info);
1949 break;
1950 }
1951 case BTC_BLE_MESH_ACT_PROVISIONER_SET_STATIC_OOB_VAL:
1952 act = ESP_BLE_MESH_PROVISIONER_SET_STATIC_OOB_VALUE_COMP_EVT;
1953 param.provisioner_set_static_oob_val_comp.err_code =
1954 bt_mesh_provisioner_set_static_oob_value(
1955 arg->set_static_oob_val.value, arg->set_static_oob_val.length);
1956 break;
1957 case BTC_BLE_MESH_ACT_PROVISIONER_SET_PRIMARY_ELEM_ADDR:
1958 act = ESP_BLE_MESH_PROVISIONER_SET_PRIMARY_ELEM_ADDR_COMP_EVT;
1959 param.provisioner_set_primary_elem_addr_comp.err_code =
1960 bt_mesh_provisioner_set_primary_elem_addr(arg->set_primary_elem_addr.addr);
1961 break;
1962 case BTC_BLE_MESH_ACT_PROVISIONER_SET_NODE_NAME:
1963 act = ESP_BLE_MESH_PROVISIONER_SET_NODE_NAME_COMP_EVT;
1964 param.provisioner_set_node_name_comp.node_index = arg->set_node_name.index;
1965 param.provisioner_set_node_name_comp.err_code =
1966 bt_mesh_provisioner_set_node_name(arg->set_node_name.index, arg->set_node_name.name);
1967 break;
1968 case BTC_BLE_MESH_ACT_PROVISIONER_ADD_LOCAL_APP_KEY: {
1969 const uint8_t *app_key = NULL;
1970 const uint8_t zero[16] = {0};
1971 if (memcmp(arg->add_local_app_key.app_key, zero, 16)) {
1972 app_key = arg->add_local_app_key.app_key;
1973 }
1974 act = ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_APP_KEY_COMP_EVT;
1975 param.provisioner_add_app_key_comp.err_code =
1976 bt_mesh_provisioner_local_app_key_add(app_key, arg->add_local_app_key.net_idx,
1977 &arg->add_local_app_key.app_idx);
1978 param.provisioner_add_app_key_comp.net_idx = arg->add_local_app_key.net_idx;
1979 param.provisioner_add_app_key_comp.app_idx = arg->add_local_app_key.app_idx;
1980 break;
1981 }
1982 case BTC_BLE_MESH_ACT_PROVISIONER_UPDATE_LOCAL_APP_KEY:
1983 act = ESP_BLE_MESH_PROVISIONER_UPDATE_LOCAL_APP_KEY_COMP_EVT;
1984 param.provisioner_update_app_key_comp.net_idx = arg->update_local_app_key.net_idx;
1985 param.provisioner_update_app_key_comp.app_idx = arg->update_local_app_key.app_idx;
1986 param.provisioner_update_app_key_comp.err_code =
1987 bt_mesh_provisioner_local_app_key_update(arg->update_local_app_key.app_key,
1988 arg->update_local_app_key.net_idx, arg->update_local_app_key.app_idx);
1989 break;
1990 case BTC_BLE_MESH_ACT_PROVISIONER_BIND_LOCAL_MOD_APP:
1991 act = ESP_BLE_MESH_PROVISIONER_BIND_APP_KEY_TO_MODEL_COMP_EVT;
1992 param.provisioner_bind_app_key_to_model_comp.element_addr = arg->local_mod_app_bind.elem_addr;
1993 param.provisioner_bind_app_key_to_model_comp.app_idx = arg->local_mod_app_bind.app_idx;
1994 param.provisioner_bind_app_key_to_model_comp.company_id = arg->local_mod_app_bind.cid;
1995 param.provisioner_bind_app_key_to_model_comp.model_id = arg->local_mod_app_bind.model_id;
1996 param.provisioner_bind_app_key_to_model_comp.err_code =
1997 bt_mesh_provisioner_bind_local_model_app_idx(arg->local_mod_app_bind.elem_addr,
1998 arg->local_mod_app_bind.model_id,
1999 arg->local_mod_app_bind.cid,
2000 arg->local_mod_app_bind.app_idx);
2001 break;
2002 case BTC_BLE_MESH_ACT_PROVISIONER_ADD_LOCAL_NET_KEY: {
2003 const uint8_t *net_key = NULL;
2004 const uint8_t zero[16] = {0};
2005 if (memcmp(arg->add_local_net_key.net_key, zero, 16)) {
2006 net_key = arg->add_local_net_key.net_key;
2007 }
2008 act = ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_NET_KEY_COMP_EVT;
2009 param.provisioner_add_net_key_comp.err_code =
2010 bt_mesh_provisioner_local_net_key_add(net_key, &arg->add_local_net_key.net_idx);
2011 param.provisioner_add_net_key_comp.net_idx = arg->add_local_net_key.net_idx;
2012 break;
2013 }
2014 case BTC_BLE_MESH_ACT_PROVISIONER_UPDATE_LOCAL_NET_KEY:
2015 act = ESP_BLE_MESH_PROVISIONER_UPDATE_LOCAL_NET_KEY_COMP_EVT;
2016 param.provisioner_update_net_key_comp.net_idx = arg->update_local_net_key.net_idx;
2017 param.provisioner_update_net_key_comp.err_code =
2018 bt_mesh_provisioner_local_net_key_update(arg->update_local_net_key.net_key,
2019 arg->update_local_net_key.net_idx);
2020 break;
2021 case BTC_BLE_MESH_ACT_PROVISIONER_STORE_NODE_COMP_DATA:
2022 act = ESP_BLE_MESH_PROVISIONER_STORE_NODE_COMP_DATA_COMP_EVT;
2023 param.provisioner_store_node_comp_data_comp.addr = arg->store_node_comp_data.unicast_addr;
2024 param.provisioner_store_node_comp_data_comp.err_code =
2025 bt_mesh_provisioner_store_node_comp_data(arg->store_node_comp_data.unicast_addr,
2026 arg->store_node_comp_data.data, arg->store_node_comp_data.length);
2027 break;
2028 case BTC_BLE_MESH_ACT_PROVISIONER_DELETE_NODE_WITH_UUID:
2029 act = ESP_BLE_MESH_PROVISIONER_DELETE_NODE_WITH_UUID_COMP_EVT;
2030 memcpy(param.provisioner_delete_node_with_uuid_comp.uuid, arg->delete_node_with_uuid.uuid, 16);
2031 param.provisioner_delete_node_with_uuid_comp.err_code =
2032 bt_mesh_provisioner_delete_node_with_uuid(arg->delete_node_with_uuid.uuid);
2033 break;
2034 case BTC_BLE_MESH_ACT_PROVISIONER_DELETE_NODE_WITH_ADDR:
2035 act = ESP_BLE_MESH_PROVISIONER_DELETE_NODE_WITH_ADDR_COMP_EVT;
2036 param.provisioner_delete_node_with_addr_comp.unicast_addr = arg->delete_node_with_addr.unicast_addr;
2037 param.provisioner_delete_node_with_addr_comp.err_code =
2038 bt_mesh_provisioner_delete_node_with_node_addr(arg->delete_node_with_addr.unicast_addr);
2039 break;
2040 #if CONFIG_BLE_MESH_PROVISIONER_RECV_HB
2041 case BTC_BLE_MESH_ACT_PROVISIONER_ENABLE_HEARTBEAT_RECV:
2042 act = ESP_BLE_MESH_PROVISIONER_ENABLE_HEARTBEAT_RECV_COMP_EVT;
2043 param.provisioner_enable_heartbeat_recv_comp.enable = arg->enable_heartbeat_recv.enable;
2044 param.provisioner_enable_heartbeat_recv_comp.err_code =
2045 bt_mesh_provisioner_recv_heartbeat(arg->enable_heartbeat_recv.enable ?
2046 btc_ble_mesh_provisioner_recv_heartbeat_cb : NULL);
2047 break;
2048 case BTC_BLE_MESH_ACT_PROVISIONER_SET_HEARTBEAT_FILTER_TYPE:
2049 act = ESP_BLE_MESH_PROVISIONER_SET_HEARTBEAT_FILTER_TYPE_COMP_EVT;
2050 param.provisioner_set_heartbeat_filter_type_comp.type = arg->set_heartbeat_filter_type.type;
2051 param.provisioner_set_heartbeat_filter_type_comp.err_code =
2052 bt_mesh_provisioner_set_heartbeat_filter_type(arg->set_heartbeat_filter_type.type);
2053 break;
2054 case BTC_BLE_MESH_ACT_PROVISIONER_SET_HEARTBEAT_FILTER_INFO:
2055 act = ESP_BLE_MESH_PROVISIONER_SET_HEARTBEAT_FILTER_INFO_COMP_EVT;
2056 param.provisioner_set_heartbeat_filter_info_comp.op = arg->set_heartbeat_filter_info.op;
2057 param.provisioner_set_heartbeat_filter_info_comp.hb_src = arg->set_heartbeat_filter_info.hb_src;
2058 param.provisioner_set_heartbeat_filter_info_comp.hb_dst = arg->set_heartbeat_filter_info.hb_dst;
2059 param.provisioner_set_heartbeat_filter_info_comp.err_code =
2060 bt_mesh_provisioner_set_heartbeat_filter_info(arg->set_heartbeat_filter_info.op,
2061 arg->set_heartbeat_filter_info.hb_src,
2062 arg->set_heartbeat_filter_info.hb_dst);
2063 break;
2064 #endif /* CONFIG_BLE_MESH_PROVISIONER_RECV_HB */
2065 #if CONFIG_BLE_MESH_SETTINGS
2066 case BTC_BLE_MESH_ACT_PROVISIONER_DIRECT_ERASE_SETTINGS:
2067 act = ESP_BLE_MESH_PROVISIONER_DRIECT_ERASE_SETTINGS_COMP_EVT;
2068 param.provisioner_direct_erase_settings_comp.err_code = bt_mesh_provisioner_direct_erase_settings();
2069 break;
2070 #endif /* CONFIG_BLE_MESH_SETTINGS */
2071 #if CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE
2072 case BTC_BLE_MESH_ACT_PROVISIONER_OPEN_SETTINGS_WITH_INDEX:
2073 act = ESP_BLE_MESH_PROVISIONER_OPEN_SETTINGS_WITH_INDEX_COMP_EVT;
2074 param.provisioner_open_settings_with_index_comp.index = arg->open_settings_with_index.index;
2075 param.provisioner_open_settings_with_index_comp.err_code =
2076 bt_mesh_provisioner_open_settings_with_index(arg->open_settings_with_index.index);
2077 break;
2078 case BTC_BLE_MESH_ACT_PROVISIONER_OPEN_SETTINGS_WITH_UID:
2079 act = ESP_BLE_MESH_PROVISIONER_OPEN_SETTINGS_WITH_UID_COMP_EVT;
2080 strncpy(param.provisioner_open_settings_with_uid_comp.uid,
2081 arg->open_settings_with_uid.uid, ESP_BLE_MESH_SETTINGS_UID_SIZE + 1);
2082 param.provisioner_open_settings_with_uid_comp.err_code =
2083 bt_mesh_provisioner_open_settings_with_uid(arg->open_settings_with_uid.uid,
2084 ¶m.provisioner_open_settings_with_uid_comp.index);
2085 break;
2086 case BTC_BLE_MESH_ACT_PROVISIONER_CLOSE_SETTINGS_WITH_INDEX:
2087 act = ESP_BLE_MESH_PROVISIONER_CLOSE_SETTINGS_WITH_INDEX_COMP_EVT;
2088 param.provisioner_close_settings_with_index_comp.index = arg->close_settings_with_index.index;
2089 param.provisioner_close_settings_with_index_comp.err_code =
2090 bt_mesh_provisioner_close_settings_with_index(arg->close_settings_with_index.index,
2091 arg->close_settings_with_index.erase);
2092 break;
2093 case BTC_BLE_MESH_ACT_PROVISIONER_CLOSE_SETTINGS_WITH_UID:
2094 act = ESP_BLE_MESH_PROVISIONER_CLOSE_SETTINGS_WITH_UID_COMP_EVT;
2095 strncpy(param.provisioner_close_settings_with_uid_comp.uid,
2096 arg->close_settings_with_uid.uid, ESP_BLE_MESH_SETTINGS_UID_SIZE + 1);
2097 param.provisioner_close_settings_with_uid_comp.err_code =
2098 bt_mesh_provisioner_close_settings_with_uid(arg->close_settings_with_uid.uid,
2099 arg->close_settings_with_uid.erase,
2100 ¶m.provisioner_close_settings_with_uid_comp.index);
2101 break;
2102 case BTC_BLE_MESH_ACT_PROVISIONER_DELETE_SETTINGS_WITH_INDEX:
2103 act = ESP_BLE_MESH_PROVISIONER_DELETE_SETTINGS_WITH_INDEX_COMP_EVT;
2104 param.provisioner_delete_settings_with_index_comp.index = arg->delete_settings_with_index.index;
2105 param.provisioner_delete_settings_with_index_comp.err_code =
2106 bt_mesh_provisioner_delete_settings_with_index(arg->delete_settings_with_index.index);
2107 break;
2108 case BTC_BLE_MESH_ACT_PROVISIONER_DELETE_SETTINGS_WITH_UID:
2109 act = ESP_BLE_MESH_PROVISIONER_DELETE_SETTINGS_WITH_UID_COMP_EVT;
2110 strncpy(param.provisioner_delete_settings_with_uid_comp.uid,
2111 arg->delete_settings_with_uid.uid, ESP_BLE_MESH_SETTINGS_UID_SIZE + 1);
2112 param.provisioner_delete_settings_with_uid_comp.err_code =
2113 bt_mesh_provisioner_delete_settings_with_uid(arg->delete_settings_with_uid.uid,
2114 ¶m.provisioner_delete_settings_with_uid_comp.index);
2115 break;
2116 #endif /* CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE */
2117 #endif /* CONFIG_BLE_MESH_PROVISIONER */
2118 #if CONFIG_BLE_MESH_FAST_PROV
2119 case BTC_BLE_MESH_ACT_SET_FAST_PROV_INFO:
2120 act = ESP_BLE_MESH_SET_FAST_PROV_INFO_COMP_EVT;
2121 param.set_fast_prov_info_comp.status_unicast =
2122 bt_mesh_set_fast_prov_unicast_addr_range(arg->set_fast_prov_info.unicast_min,
2123 arg->set_fast_prov_info.unicast_max);
2124 param.set_fast_prov_info_comp.status_net_idx =
2125 bt_mesh_set_fast_prov_net_idx(arg->set_fast_prov_info.net_idx);
2126 bt_mesh_set_fast_prov_flags_iv_index(arg->set_fast_prov_info.flags,
2127 arg->set_fast_prov_info.iv_index);
2128 param.set_fast_prov_info_comp.status_match =
2129 bt_mesh_provisioner_set_dev_uuid_match(arg->set_fast_prov_info.offset,
2130 arg->set_fast_prov_info.match_len,
2131 arg->set_fast_prov_info.match_val, false);
2132 break;
2133 case BTC_BLE_MESH_ACT_SET_FAST_PROV_ACTION:
2134 act = ESP_BLE_MESH_SET_FAST_PROV_ACTION_COMP_EVT;
2135 param.set_fast_prov_action_comp.status_action =
2136 bt_mesh_set_fast_prov_action(arg->set_fast_prov_action.action);
2137 break;
2138 #endif /* CONFIG_BLE_MESH_FAST_PROV */
2139 #if CONFIG_BLE_MESH_LOW_POWER
2140 case BTC_BLE_MESH_ACT_LPN_ENABLE:
2141 act = ESP_BLE_MESH_LPN_ENABLE_COMP_EVT;
2142 param.lpn_enable_comp.err_code = bt_mesh_lpn_set(true, false);
2143 break;
2144 case BTC_BLE_MESH_ACT_LPN_DISABLE:
2145 act = ESP_BLE_MESH_LPN_DISABLE_COMP_EVT;
2146 param.lpn_disable_comp.err_code = bt_mesh_lpn_set(false, arg->lpn_disable.force);
2147 break;
2148 case BTC_BLE_MESH_ACT_LPN_POLL:
2149 act = ESP_BLE_MESH_LPN_POLL_COMP_EVT;
2150 param.lpn_poll_comp.err_code = bt_mesh_lpn_poll();
2151 break;
2152 #endif /* CONFIG_BLE_MESH_LOW_POWER */
2153 #if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
2154 case BTC_BLE_MESH_ACT_PROXY_CLIENT_CONNECT:
2155 act = ESP_BLE_MESH_PROXY_CLIENT_CONNECT_COMP_EVT;
2156 memcpy(param.proxy_client_connect_comp.addr, arg->proxy_client_connect.addr, BD_ADDR_LEN);
2157 param.proxy_client_connect_comp.addr_type = arg->proxy_client_connect.addr_type;
2158 param.proxy_client_connect_comp.net_idx = arg->proxy_client_connect.net_idx;
2159 param.proxy_client_connect_comp.err_code =
2160 bt_mesh_proxy_client_connect(arg->proxy_client_connect.addr,
2161 arg->proxy_client_connect.addr_type,
2162 arg->proxy_client_connect.net_idx);
2163 break;
2164 case BTC_BLE_MESH_ACT_PROXY_CLIENT_DISCONNECT:
2165 act = ESP_BLE_MESH_PROXY_CLIENT_DISCONNECT_COMP_EVT;
2166 param.proxy_client_disconnect_comp.conn_handle = arg->proxy_client_disconnect.conn_handle;
2167 param.proxy_client_disconnect_comp.err_code =
2168 bt_mesh_proxy_client_disconnect(arg->proxy_client_disconnect.conn_handle);
2169 break;
2170 case BTC_BLE_MESH_ACT_PROXY_CLIENT_SET_FILTER_TYPE: {
2171 struct bt_mesh_proxy_cfg_pdu pdu = {
2172 .opcode = BLE_MESH_PROXY_CFG_FILTER_SET,
2173 .set.filter_type = arg->proxy_client_set_filter_type.filter_type,
2174 };
2175 act = ESP_BLE_MESH_PROXY_CLIENT_SET_FILTER_TYPE_COMP_EVT;
2176 param.proxy_client_set_filter_type_comp.conn_handle = arg->proxy_client_set_filter_type.conn_handle;
2177 param.proxy_client_set_filter_type_comp.net_idx = arg->proxy_client_set_filter_type.net_idx;
2178 param.proxy_client_set_filter_type_comp.err_code =
2179 bt_mesh_proxy_client_cfg_send(arg->proxy_client_set_filter_type.conn_handle,
2180 arg->proxy_client_set_filter_type.net_idx, &pdu);
2181 break;
2182 }
2183 case BTC_BLE_MESH_ACT_PROXY_CLIENT_ADD_FILTER_ADDR: {
2184 struct bt_mesh_proxy_cfg_pdu pdu = {
2185 .opcode = BLE_MESH_PROXY_CFG_FILTER_ADD,
2186 .add.addr = arg->proxy_client_add_filter_addr.addr,
2187 .add.addr_num = arg->proxy_client_add_filter_addr.addr_num,
2188 };
2189 act = ESP_BLE_MESH_PROXY_CLIENT_ADD_FILTER_ADDR_COMP_EVT;
2190 param.proxy_client_add_filter_addr_comp.conn_handle = arg->proxy_client_add_filter_addr.conn_handle;
2191 param.proxy_client_add_filter_addr_comp.net_idx = arg->proxy_client_add_filter_addr.net_idx;
2192 param.proxy_client_add_filter_addr_comp.err_code =
2193 bt_mesh_proxy_client_cfg_send(arg->proxy_client_add_filter_addr.conn_handle,
2194 arg->proxy_client_add_filter_addr.net_idx, &pdu);
2195 break;
2196 }
2197 case BTC_BLE_MESH_ACT_PROXY_CLIENT_REMOVE_FILTER_ADDR: {
2198 struct bt_mesh_proxy_cfg_pdu pdu = {
2199 .opcode = BLE_MESH_PROXY_CFG_FILTER_REMOVE,
2200 .remove.addr = arg->proxy_client_remove_filter_addr.addr,
2201 .remove.addr_num = arg->proxy_client_remove_filter_addr.addr_num,
2202 };
2203 act = ESP_BLE_MESH_PROXY_CLIENT_REMOVE_FILTER_ADDR_COMP_EVT;
2204 param.proxy_client_remove_filter_addr_comp.conn_handle = arg->proxy_client_remove_filter_addr.conn_handle;
2205 param.proxy_client_remove_filter_addr_comp.net_idx = arg->proxy_client_remove_filter_addr.net_idx;
2206 param.proxy_client_remove_filter_addr_comp.err_code =
2207 bt_mesh_proxy_client_cfg_send(arg->proxy_client_remove_filter_addr.conn_handle,
2208 arg->proxy_client_remove_filter_addr.net_idx, &pdu);
2209 break;
2210 }
2211 #endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
2212 case BTC_BLE_MESH_ACT_MODEL_SUBSCRIBE_GROUP_ADDR:
2213 act = ESP_BLE_MESH_MODEL_SUBSCRIBE_GROUP_ADDR_COMP_EVT;
2214 param.model_sub_group_addr_comp.element_addr = arg->model_sub_group_addr.element_addr;
2215 param.model_sub_group_addr_comp.company_id = arg->model_sub_group_addr.company_id;
2216 param.model_sub_group_addr_comp.model_id = arg->model_sub_group_addr.model_id;
2217 param.model_sub_group_addr_comp.group_addr = arg->model_sub_group_addr.group_addr;
2218 param.model_sub_group_addr_comp.err_code =
2219 bt_mesh_model_subscribe_group_addr(arg->model_sub_group_addr.element_addr,
2220 arg->model_sub_group_addr.company_id,
2221 arg->model_sub_group_addr.model_id,
2222 arg->model_sub_group_addr.group_addr);
2223 break;
2224 case BTC_BLE_MESH_ACT_MODEL_UNSUBSCRIBE_GROUP_ADDR:
2225 act = ESP_BLE_MESH_MODEL_UNSUBSCRIBE_GROUP_ADDR_COMP_EVT;
2226 param.model_unsub_group_addr_comp.element_addr = arg->model_unsub_group_addr.element_addr;
2227 param.model_unsub_group_addr_comp.company_id = arg->model_unsub_group_addr.company_id;
2228 param.model_unsub_group_addr_comp.model_id = arg->model_unsub_group_addr.model_id;
2229 param.model_unsub_group_addr_comp.group_addr = arg->model_unsub_group_addr.group_addr;
2230 param.model_unsub_group_addr_comp.err_code =
2231 bt_mesh_model_unsubscribe_group_addr(arg->model_unsub_group_addr.element_addr,
2232 arg->model_unsub_group_addr.company_id,
2233 arg->model_unsub_group_addr.model_id,
2234 arg->model_unsub_group_addr.group_addr);
2235 break;
2236 #if CONFIG_BLE_MESH_DEINIT
2237 case BTC_BLE_MESH_ACT_DEINIT_MESH:
2238 act = ESP_BLE_MESH_DEINIT_MESH_COMP_EVT;
2239 param.deinit_mesh_comp.err_code = bt_mesh_deinit((struct bt_mesh_deinit_param *)&arg->mesh_deinit.param);
2240 break;
2241 #endif /* CONFIG_BLE_MESH_DEINIT */
2242 default:
2243 BT_WARN("%s, Unknown act %d", __func__, msg->act);
2244 return;
2245 }
2246
2247 /* Callback operation completion events */
2248 btc_ble_mesh_prov_set_complete_cb(¶m, act);
2249
2250 if (msg->arg) {
2251 btc_ble_mesh_prov_arg_deep_free(msg);
2252 }
2253 return;
2254 }
2255
btc_ble_mesh_prov_cb_handler(btc_msg_t * msg)2256 void btc_ble_mesh_prov_cb_handler(btc_msg_t *msg)
2257 {
2258 esp_ble_mesh_prov_cb_param_t *param = NULL;
2259
2260 if (!msg) {
2261 BT_ERR("%s, Invalid parameter", __func__);
2262 return;
2263 }
2264
2265 param = (esp_ble_mesh_prov_cb_param_t *)(msg->arg);
2266
2267 if (msg->act < ESP_BLE_MESH_PROV_EVT_MAX) {
2268 btc_ble_mesh_prov_cb_to_app(msg->act, param);
2269 } else {
2270 BT_ERR("%s, Unknown act %d", __func__, msg->act);
2271 }
2272 }
2273
btc_ble_mesh_model_call_handler(btc_msg_t * msg)2274 void btc_ble_mesh_model_call_handler(btc_msg_t *msg)
2275 {
2276 btc_ble_mesh_model_args_t *arg = NULL;
2277 int err = 0;
2278
2279 if (!msg || !msg->arg) {
2280 BT_ERR("%s, Invalid parameter", __func__);
2281 return;
2282 }
2283
2284 arg = (btc_ble_mesh_model_args_t *)(msg->arg);
2285
2286 switch (msg->act) {
2287 case BTC_BLE_MESH_ACT_MODEL_PUBLISH: {
2288 if (arg->model_publish.device_role == PROVISIONER) {
2289 /* Currently Provisioner only supports client model */
2290 err = bt_mesh_set_client_model_role((struct bt_mesh_model *)arg->model_publish.model,
2291 arg->model_publish.device_role);
2292 if (err) {
2293 BT_ERR("Failed to set client role");
2294 btc_ble_mesh_model_publish_comp_cb(arg->model_publish.model, err);
2295 break;
2296 }
2297 }
2298 err = bt_mesh_model_publish((struct bt_mesh_model *)arg->model_publish.model);
2299 btc_ble_mesh_model_publish_comp_cb(arg->model_publish.model, err);
2300 break;
2301 }
2302 case BTC_BLE_MESH_ACT_SERVER_MODEL_SEND: {
2303 /* arg->model_send.length contains opcode & payload, plus extra 4-bytes TransMIC */
2304 struct net_buf_simple *buf = bt_mesh_alloc_buf(arg->model_send.length + BLE_MESH_MIC_SHORT);
2305 if (!buf) {
2306 BT_ERR("%s, Out of memory", __func__);
2307 btc_ble_mesh_model_send_comp_cb(arg->model_send.model, arg->model_send.ctx,
2308 arg->model_send.opcode, -ENOMEM);
2309 break;
2310 }
2311
2312 net_buf_simple_add_mem(buf, arg->model_send.data, arg->model_send.length);
2313 arg->model_send.ctx->srv_send = true;
2314
2315 err = bt_mesh_model_send((struct bt_mesh_model *)arg->model_send.model,
2316 (struct bt_mesh_msg_ctx *)arg->model_send.ctx,
2317 buf, NULL, NULL);
2318 bt_mesh_free_buf(buf);
2319 btc_ble_mesh_model_send_comp_cb(arg->model_send.model, arg->model_send.ctx,
2320 arg->model_send.opcode, err);
2321 break;
2322 }
2323 case BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND: {
2324 /* arg->model_send.length contains opcode & message, plus extra 4-bytes TransMIC */
2325 struct net_buf_simple *buf = bt_mesh_alloc_buf(arg->model_send.length + BLE_MESH_MIC_SHORT);
2326 if (!buf) {
2327 BT_ERR("%s, Out of memory", __func__);
2328 btc_ble_mesh_model_send_comp_cb(arg->model_send.model, arg->model_send.ctx,
2329 arg->model_send.opcode, -ENOMEM);
2330 break;
2331 }
2332
2333 net_buf_simple_add_mem(buf, arg->model_send.data, arg->model_send.length);
2334 bt_mesh_client_common_param_t param = {
2335 .opcode = arg->model_send.opcode,
2336 .model = (struct bt_mesh_model *)arg->model_send.model,
2337 .ctx.net_idx = arg->model_send.ctx->net_idx,
2338 .ctx.app_idx = arg->model_send.ctx->app_idx,
2339 .ctx.addr = arg->model_send.ctx->addr,
2340 .ctx.send_rel = arg->model_send.ctx->send_rel,
2341 .ctx.send_ttl = arg->model_send.ctx->send_ttl,
2342 .ctx.srv_send = false,
2343 .msg_timeout = arg->model_send.msg_timeout,
2344 .msg_role = arg->model_send.device_role,
2345 };
2346 err = bt_mesh_client_send_msg(¶m, buf, arg->model_send.need_rsp,
2347 btc_ble_mesh_client_model_timeout_cb);
2348 bt_mesh_free_buf(buf);
2349 btc_ble_mesh_model_send_comp_cb(arg->model_send.model, arg->model_send.ctx,
2350 arg->model_send.opcode, err);
2351 break;
2352 }
2353 #if CONFIG_BLE_MESH_SERVER_MODEL
2354 case BTC_BLE_MESH_ACT_SERVER_MODEL_UPDATE_STATE:
2355 err = bt_mesh_update_binding_state(
2356 (struct bt_mesh_model *)arg->model_update_state.model, arg->model_update_state.type,
2357 (bt_mesh_server_state_value_t *)arg->model_update_state.value);
2358 btc_ble_mesh_server_model_update_state_comp_cb(arg->model_update_state.model,
2359 arg->model_update_state.type, err);
2360 break;
2361 #endif /* CONFIG_BLE_MESH_SERVER_MODEL */
2362 default:
2363 BT_WARN("%s, Unknown act %d", __func__, msg->act);
2364 break;
2365 }
2366
2367 btc_ble_mesh_model_arg_deep_free(msg);
2368 return;
2369 }
2370
btc_ble_mesh_model_cb_handler(btc_msg_t * msg)2371 void btc_ble_mesh_model_cb_handler(btc_msg_t *msg)
2372 {
2373 esp_ble_mesh_model_cb_param_t *param = NULL;
2374
2375 if (!msg || !msg->arg) {
2376 BT_ERR("%s, Invalid parameter", __func__);
2377 return;
2378 }
2379
2380 param = (esp_ble_mesh_model_cb_param_t *)(msg->arg);
2381
2382 if (msg->act < ESP_BLE_MESH_MODEL_EVT_MAX) {
2383 btc_ble_mesh_model_cb_to_app(msg->act, param);
2384 } else {
2385 BT_ERR("%s, Unknown act %d", __func__, msg->act);
2386 }
2387
2388 btc_ble_mesh_model_free_req_data(msg);
2389 return;
2390 }
2391