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