Select one of the symbols to view example projects that use it.
 
Outline
#include <string.h>
#include <errno.h>
#include "btc_ble_mesh_model_common.h"
#include "btc_ble_mesh_config_model.h"
#include "esp_ble_mesh_config_model_api.h"
#include "mesh/cfg_cli.h"
btc_ble_mesh_config_server_cb_to_app(esp_ble_mesh_cfg_server_cb_event_t, esp_ble_mesh_cfg_server_cb_param_t *)
btc_ble_mesh_config_server_callback(esp_ble_mesh_cfg_server_cb_param_t *, uint8_t)
bt_mesh_config_server_cb_evt_to_btc(uint8_t, struct bt_mesh_model *, struct bt_mesh_msg_ctx *, const uint8_t *, size_t)
btc_ble_mesh_config_server_cb_handler(btc_msg_t *)
Files
loading...
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 *//* ... */ #include <string.h> #include <errno.h> #include "btc_ble_mesh_model_common.h" #include "btc_ble_mesh_config_model.h" #include "esp_ble_mesh_config_model_api.h"5 includes #if CONFIG_BLE_MESH_CFG_CLI #include "mesh/cfg_cli.h" /* Configuration Client Model related functions */ static inline void btc_ble_mesh_config_client_cb_to_app(esp_ble_mesh_cfg_client_cb_event_t event, esp_ble_mesh_cfg_client_cb_param_t *param) { esp_ble_mesh_cfg_client_cb_t btc_ble_mesh_cb = (esp_ble_mesh_cfg_client_cb_t)btc_profile_cb_get(BTC_PID_CONFIG_CLIENT); if (btc_ble_mesh_cb) { btc_ble_mesh_cb(event, param); }{...} }{...} void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) { btc_ble_mesh_config_client_args_t *dst = (btc_ble_mesh_config_client_args_t *)p_dest; btc_ble_mesh_config_client_args_t *src = (btc_ble_mesh_config_client_args_t *)p_src; if (!msg || !dst || !src) { BT_ERR("%s, Invalid parameter", __func__); return; }{...} switch (msg->act) { case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE: { dst->cfg_client_get_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (dst->cfg_client_get_state.params) { memcpy(dst->cfg_client_get_state.params, src->cfg_client_get_state.params, sizeof(esp_ble_mesh_client_common_param_t)); }{...} else { BT_ERR("%s, Out of memory, act %d", __func__, msg->act); break; }{...} if (src->cfg_client_get_state.get_state) { dst->cfg_client_get_state.get_state = (esp_ble_mesh_cfg_client_get_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_cfg_client_get_state_t)); if (dst->cfg_client_get_state.get_state) { memcpy(dst->cfg_client_get_state.get_state, src->cfg_client_get_state.get_state, sizeof(esp_ble_mesh_cfg_client_get_state_t)); }{...} else { BT_ERR("%s, Out of memory, act %d", __func__, msg->act); }{...} }{...} break; }{...} ... case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE: { dst->cfg_client_set_state.params = (esp_ble_mesh_client_common_param_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (dst->cfg_client_set_state.params) { memcpy(dst->cfg_client_set_state.params, src->cfg_client_set_state.params, sizeof(esp_ble_mesh_client_common_param_t)); }{...} else { BT_ERR("%s, Out of memory, act %d", __func__, msg->act); break; }{...} if (src->cfg_client_set_state.set_state) { dst->cfg_client_set_state.set_state = (esp_ble_mesh_cfg_client_set_state_t *)bt_mesh_malloc(sizeof(esp_ble_mesh_cfg_client_set_state_t)); if (dst->cfg_client_set_state.set_state) { memcpy(dst->cfg_client_set_state.set_state, src->cfg_client_set_state.set_state, sizeof(esp_ble_mesh_cfg_client_set_state_t)); }{...} else { BT_ERR("%s, Out of memory, act %d", __func__, msg->act); }{...} }{...} break; }{...} ... default: BT_DBG("%s, Unknown act %d", __func__, msg->act); break;... }{...} }{...} void btc_ble_mesh_config_client_arg_deep_free(btc_msg_t *msg) { btc_ble_mesh_config_client_args_t *arg = NULL; if (!msg) { BT_ERR("%s, Invalid parameter", __func__); return; }{...} arg = (btc_ble_mesh_config_client_args_t *)(msg->arg); switch (msg->act) { case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE: if (arg->cfg_client_get_state.params) { bt_mesh_free(arg->cfg_client_get_state.params); }{...} if (arg->cfg_client_get_state.get_state) { bt_mesh_free(arg->cfg_client_get_state.get_state); }{...} break;... case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE: if (arg->cfg_client_set_state.params) { bt_mesh_free(arg->cfg_client_set_state.params); }{...} if (arg->cfg_client_set_state.set_state) { bt_mesh_free(arg->cfg_client_set_state.set_state); }{...} break;... default: break;... }{...} }{...} static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src) { esp_ble_mesh_cfg_client_cb_param_t *p_dest_data = (esp_ble_mesh_cfg_client_cb_param_t *)p_dest; esp_ble_mesh_cfg_client_cb_param_t *p_src_data = (esp_ble_mesh_cfg_client_cb_param_t *)p_src; uint16_t length = 0U; if (!msg || !p_src_data || !p_dest_data) { BT_ERR("%s, Invalid parameter", __func__); return; }{...} if (p_src_data->params) { p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (!p_dest_data->params) { BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; }{...} memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t)); }{...} switch (msg->act) { case ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT: case ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT: case ESP_BLE_MESH_CFG_CLIENT_PUBLISH_EVT: if (p_src_data->params) { switch (p_src_data->params->opcode) { case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET: case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_STATUS: if (p_src_data->status_cb.comp_data_status.composition_data) { length = p_src_data->status_cb.comp_data_status.composition_data->len; p_dest_data->status_cb.comp_data_status.composition_data = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.comp_data_status.composition_data) { BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; }{...} net_buf_simple_add_mem(p_dest_data->status_cb.comp_data_status.composition_data, p_src_data->status_cb.comp_data_status.composition_data->data, p_src_data->status_cb.comp_data_status.composition_data->len); }{...} break;... case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET: case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET: case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_LIST: case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_LIST: if (p_src_data->status_cb.model_sub_list.sub_addr) { length = p_src_data->status_cb.model_sub_list.sub_addr->len; p_dest_data->status_cb.model_sub_list.sub_addr = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.model_sub_list.sub_addr) { BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; }{...} net_buf_simple_add_mem(p_dest_data->status_cb.model_sub_list.sub_addr, p_src_data->status_cb.model_sub_list.sub_addr->data, p_src_data->status_cb.model_sub_list.sub_addr->len); }{...} break;... case ESP_BLE_MESH_MODEL_OP_NET_KEY_GET: case ESP_BLE_MESH_MODEL_OP_NET_KEY_LIST: if (p_src_data->status_cb.netkey_list.net_idx) { length = p_src_data->status_cb.netkey_list.net_idx->len; p_dest_data->status_cb.netkey_list.net_idx = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.netkey_list.net_idx) { BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; }{...} net_buf_simple_add_mem(p_dest_data->status_cb.netkey_list.net_idx, p_src_data->status_cb.netkey_list.net_idx->data, p_src_data->status_cb.netkey_list.net_idx->len); }{...} break;... case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET: case ESP_BLE_MESH_MODEL_OP_APP_KEY_LIST: if (p_src_data->status_cb.appkey_list.app_idx) { length = p_src_data->status_cb.appkey_list.app_idx->len; p_dest_data->status_cb.appkey_list.app_idx = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.appkey_list.app_idx) { BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; }{...} net_buf_simple_add_mem(p_dest_data->status_cb.appkey_list.app_idx, p_src_data->status_cb.appkey_list.app_idx->data, p_src_data->status_cb.appkey_list.app_idx->len); }{...} break;... case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET: case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET: case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_LIST: case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_LIST: if (p_src_data->status_cb.model_app_list.app_idx) { length = p_src_data->status_cb.model_app_list.app_idx->len; p_dest_data->status_cb.model_app_list.app_idx = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.model_app_list.app_idx) { BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; }{...} net_buf_simple_add_mem(p_dest_data->status_cb.model_app_list.app_idx, p_src_data->status_cb.model_app_list.app_idx->data, p_src_data->status_cb.model_app_list.app_idx->len); }{...} break;... default: break;... }{...} }{...} ... case ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT: break;... default: break;... }{...} }{...} static void btc_ble_mesh_config_client_free_req_data(btc_msg_t *msg) { esp_ble_mesh_cfg_client_cb_param_t *arg = NULL; if (!msg) { BT_ERR("%s, Invalid parameter", __func__); return; }{...} arg = (esp_ble_mesh_cfg_client_cb_param_t *)(msg->arg); switch (msg->act) { case ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT: case ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT: case ESP_BLE_MESH_CFG_CLIENT_PUBLISH_EVT: if (arg->params) { switch (arg->params->opcode) { case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET: case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_STATUS: bt_mesh_free_buf(arg->status_cb.comp_data_status.composition_data); break;... case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET: case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET: case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_LIST: case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_LIST: bt_mesh_free_buf(arg->status_cb.model_sub_list.sub_addr); break;... case ESP_BLE_MESH_MODEL_OP_NET_KEY_GET: case ESP_BLE_MESH_MODEL_OP_NET_KEY_LIST: bt_mesh_free_buf(arg->status_cb.netkey_list.net_idx); break;... case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET: case ESP_BLE_MESH_MODEL_OP_APP_KEY_LIST: bt_mesh_free_buf(arg->status_cb.appkey_list.app_idx); break;... case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET: case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET: case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_LIST: case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_LIST: bt_mesh_free_buf(arg->status_cb.model_app_list.app_idx); break;... default: break;... }{...} }{...} ... case ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT: if (arg->params) { bt_mesh_free(arg->params); }{...} break;... default: break;... }{...} }{...} static void btc_ble_mesh_config_client_callback(esp_ble_mesh_cfg_client_cb_param_t *cb_params, uint8_t act) { btc_msg_t msg = {0}; /* If corresponding callback is not registered, event will not be posted. */ if (!btc_profile_cb_get(BTC_PID_CONFIG_CLIENT)) { return; }{...} msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_CONFIG_CLIENT; msg.act = act; btc_transfer_context(&msg, cb_params, cb_params == NULL ? 0 : sizeof(esp_ble_mesh_cfg_client_cb_param_t), btc_ble_mesh_config_client_copy_req_data, btc_ble_mesh_config_client_free_req_data); }{...} void bt_mesh_config_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type, struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, const uint8_t *val, size_t len) { esp_ble_mesh_cfg_client_cb_param_t cb_params = {0}; esp_ble_mesh_client_common_param_t params = {0}; uint8_t act = 0U; if (!model || !ctx || len > sizeof(cb_params.status_cb)) { BT_ERR("%s, Invalid parameter", __func__); return; }{...} switch (evt_type) { case BTC_BLE_MESH_EVT_CONFIG_CLIENT_GET_STATE: act = ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT; break;... case BTC_BLE_MESH_EVT_CONFIG_CLIENT_SET_STATE: act = ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT; break;... case BTC_BLE_MESH_EVT_CONFIG_CLIENT_PUBLISH: act = ESP_BLE_MESH_CFG_CLIENT_PUBLISH_EVT; break;... case BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT: act = ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT; break;... default: BT_ERR("Unknown Config client event type %d", evt_type); return;... }{...} params.opcode = opcode; params.model = (esp_ble_mesh_model_t *)model; params.ctx.net_idx = ctx->net_idx; params.ctx.app_idx = ctx->app_idx; params.ctx.addr = ctx->addr; params.ctx.recv_ttl = ctx->recv_ttl; params.ctx.recv_op = ctx->recv_op; params.ctx.recv_dst = ctx->recv_dst; params.ctx.recv_rssi = ctx->recv_rssi; params.ctx.send_ttl = ctx->send_ttl; cb_params.error_code = 0; cb_params.params = &params; if (val && len) { memcpy(&cb_params.status_cb, val, len); }{...} btc_ble_mesh_config_client_callback(&cb_params, act); }{...} void btc_ble_mesh_config_client_publish_callback(uint32_t opcode, struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { if (!model || !ctx || !buf) { BT_ERR("%s, Invalid parameter", __func__); return; }{...} bt_mesh_config_client_cb_evt_to_btc(opcode, BTC_BLE_MESH_EVT_CONFIG_CLIENT_PUBLISH, model, ctx, buf->data, buf->len); }{...} static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *params, esp_ble_mesh_cfg_client_get_state_t *get) { bt_mesh_client_common_param_t param = {0}; if (params == NULL) { BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; }{...} switch (params->opcode) { case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET: case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET: case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET: case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET: case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET: case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_GET: case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET: case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET: case ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_GET: case ESP_BLE_MESH_MODEL_OP_LPN_POLLTIMEOUT_GET: if (get == NULL) { BT_ERR("Invalid Configuration Get"); return -EINVAL; }{...} break;... default: break;... }{...} btc_ble_mesh_set_client_common_param(params, &param, true); switch (param.opcode) { case ESP_BLE_MESH_MODEL_OP_BEACON_GET: return bt_mesh_cfg_beacon_get(&param);... case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_GET: return bt_mesh_cfg_ttl_get(&param);... case ESP_BLE_MESH_MODEL_OP_FRIEND_GET: return bt_mesh_cfg_friend_get(&param);... case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_GET: return bt_mesh_cfg_gatt_proxy_get(&param);... case ESP_BLE_MESH_MODEL_OP_RELAY_GET: return bt_mesh_cfg_relay_get(&param);... case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET: return bt_mesh_cfg_mod_pub_get(&param, get->model_pub_get.element_addr, get->model_pub_get.model_id, get->model_pub_get.company_id);... case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_GET: return bt_mesh_cfg_hb_pub_get(&param);... case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_GET: return bt_mesh_cfg_hb_sub_get(&param);... case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET: return bt_mesh_cfg_comp_data_get(&param, get->comp_data_get.page);... case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET: return bt_mesh_cfg_mod_sub_get(&param, get->sig_model_sub_get.element_addr, get->sig_model_sub_get.model_id);... case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET: return bt_mesh_cfg_mod_sub_get_vnd(&param, get->vnd_model_sub_get.element_addr, get->vnd_model_sub_get.model_id, get->vnd_model_sub_get.company_id);... case ESP_BLE_MESH_MODEL_OP_NET_KEY_GET: return bt_mesh_cfg_net_key_get(&param);... case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET: return bt_mesh_cfg_app_key_get(&param, get->app_key_get.net_idx);... case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_GET: return bt_mesh_cfg_node_identity_get(&param, get->node_identity_get.net_idx);... case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET: return bt_mesh_cfg_mod_app_get(&param, get->sig_model_app_get.element_addr, get->sig_model_app_get.model_id);... case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET: return bt_mesh_cfg_mod_app_get_vnd(&param, get->vnd_model_app_get.element_addr, get->vnd_model_app_get.model_id, get->vnd_model_app_get.company_id);... case ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_GET: return bt_mesh_cfg_kr_phase_get(&param, get->kr_phase_get.net_idx);... case ESP_BLE_MESH_MODEL_OP_LPN_POLLTIMEOUT_GET: return bt_mesh_cfg_lpn_timeout_get(&param, get->lpn_pollto_get.lpn_addr);... case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_GET: return bt_mesh_cfg_net_transmit_get(&param);... default: BT_ERR("Invalid Configuration Get opcode 0x%04x", param.opcode); return -EINVAL;... }{...} }{...} static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_t *params, esp_ble_mesh_cfg_client_set_state_t *set) { bt_mesh_client_common_param_t param = {0}; if (params == NULL) { BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; }{...} if (params->opcode != ESP_BLE_MESH_MODEL_OP_NODE_RESET && set == NULL) { BT_ERR("Invalid Configuration Set"); return -EINVAL; }{...} btc_ble_mesh_set_client_common_param(params, &param, true); switch (param.opcode) { case ESP_BLE_MESH_MODEL_OP_BEACON_SET: return bt_mesh_cfg_beacon_set(&param, set->beacon_set.beacon);... case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_SET: return bt_mesh_cfg_ttl_set(&param, set->default_ttl_set.ttl);... case ESP_BLE_MESH_MODEL_OP_FRIEND_SET: return bt_mesh_cfg_friend_set(&param, set->friend_set.friend_state);... case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_SET: return bt_mesh_cfg_gatt_proxy_set(&param, set->gatt_proxy_set.gatt_proxy);... case ESP_BLE_MESH_MODEL_OP_RELAY_SET: return bt_mesh_cfg_relay_set(&param, set->relay_set.relay, set->relay_set.relay_retransmit);... case ESP_BLE_MESH_MODEL_OP_NET_KEY_ADD: return bt_mesh_cfg_net_key_add(&param, set->net_key_add.net_idx, &set->net_key_add.net_key[0]);... case ESP_BLE_MESH_MODEL_OP_APP_KEY_ADD: return bt_mesh_cfg_app_key_add(&param, set->app_key_add.net_idx, set->app_key_add.app_idx, &set->app_key_add.app_key[0]);... case ESP_BLE_MESH_MODEL_OP_MODEL_APP_BIND: return bt_mesh_cfg_mod_app_bind(&param, set->model_app_bind.element_addr, set->model_app_bind.model_app_idx, set->model_app_bind.model_id, set->model_app_bind.company_id);... case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_SET: { struct bt_mesh_cfg_mod_pub model_pub = { .addr = set->model_pub_set.publish_addr, .app_idx = set->model_pub_set.publish_app_idx, .cred_flag = set->model_pub_set.cred_flag, .ttl = set->model_pub_set.publish_ttl, .period = set->model_pub_set.publish_period, .transmit = set->model_pub_set.publish_retransmit, }{...}; return bt_mesh_cfg_mod_pub_set(&param, set->model_pub_set.element_addr, set->model_pub_set.model_id, set->model_pub_set.company_id, &model_pub); }{...} ... case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_ADD: return bt_mesh_cfg_mod_sub_add(&param, set->model_sub_add.element_addr, set->model_sub_add.sub_addr, set->model_sub_add.model_id, set->model_sub_add.company_id);... case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE: return bt_mesh_cfg_mod_sub_del(&param, set->model_sub_delete.element_addr, set->model_sub_delete.sub_addr, set->model_sub_delete.model_id, set->model_sub_delete.company_id);... case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_OVERWRITE: return bt_mesh_cfg_mod_sub_overwrite(&param, set->model_sub_overwrite.element_addr, set->model_sub_overwrite.sub_addr, set->model_sub_overwrite.model_id, set->model_sub_overwrite.company_id);... case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_ADD: return bt_mesh_cfg_mod_sub_va_add(&param, set->model_sub_va_add.element_addr, &set->model_sub_va_add.label_uuid[0], set->model_sub_va_add.model_id, set->model_sub_va_add.company_id);... case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_OVERWRITE: return bt_mesh_cfg_mod_sub_va_overwrite(&param, set->model_sub_va_overwrite.element_addr, &set->model_sub_va_overwrite.label_uuid[0], set->model_sub_va_overwrite.model_id, set->model_sub_va_overwrite.company_id);... case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_VIRTUAL_ADDR_DELETE: return bt_mesh_cfg_mod_sub_va_del(&param, set->model_sub_va_delete.element_addr, &set->model_sub_va_delete.label_uuid[0], set->model_sub_va_delete.model_id, set->model_sub_va_delete.company_id);... case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_SET: return bt_mesh_cfg_hb_sub_set(&param, (struct bt_mesh_cfg_hb_sub *)&set->heartbeat_sub_set);... case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_SET: return bt_mesh_cfg_hb_pub_set(&param, (struct bt_mesh_cfg_hb_pub *)&set->heartbeat_pub_set);... case ESP_BLE_MESH_MODEL_OP_NODE_RESET: return bt_mesh_cfg_node_reset(&param);... case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_VIRTUAL_ADDR_SET: { struct bt_mesh_cfg_mod_pub model_pub = { .app_idx = set->model_pub_va_set.publish_app_idx, .cred_flag = set->model_pub_va_set.cred_flag, .ttl = set->model_pub_va_set.publish_ttl, .period = set->model_pub_va_set.publish_period, .transmit = set->model_pub_va_set.publish_retransmit, }{...}; return bt_mesh_cfg_mod_pub_va_set(&param, set->model_pub_va_set.element_addr, set->model_pub_va_set.model_id, set->model_pub_va_set.company_id, set->model_pub_va_set.label_uuid, &model_pub); }{...} ... case ESP_BLE_MESH_MODEL_OP_MODEL_SUB_DELETE_ALL: return bt_mesh_cfg_mod_sub_del_all(&param, set->model_sub_delete_all.element_addr, set->model_sub_delete_all.model_id, set->model_sub_delete_all.company_id);... case ESP_BLE_MESH_MODEL_OP_NET_KEY_UPDATE: return bt_mesh_cfg_net_key_update(&param, set->net_key_update.net_idx, set->net_key_update.net_key);... case ESP_BLE_MESH_MODEL_OP_NET_KEY_DELETE: return bt_mesh_cfg_net_key_delete(&param, set->net_key_delete.net_idx);... case ESP_BLE_MESH_MODEL_OP_APP_KEY_UPDATE: return bt_mesh_cfg_app_key_update(&param, set->app_key_update.net_idx, set->app_key_update.app_idx, set->app_key_update.app_key);... case ESP_BLE_MESH_MODEL_OP_APP_KEY_DELETE: return bt_mesh_cfg_app_key_delete(&param, set->app_key_delete.net_idx, set->app_key_delete.app_idx);... case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_SET: return bt_mesh_cfg_node_identity_set(&param, set->node_identity_set.net_idx, set->node_identity_set.identity);... case ESP_BLE_MESH_MODEL_OP_MODEL_APP_UNBIND: return bt_mesh_cfg_mod_app_unbind(&param, set->model_app_unbind.element_addr, set->model_app_unbind.model_app_idx, set->model_app_unbind.model_id, set->model_app_unbind.company_id);... case ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_SET: return bt_mesh_cfg_kr_phase_set(&param, set->kr_phase_set.net_idx, set->kr_phase_set.transition);... case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_SET: return bt_mesh_cfg_net_transmit_set(&param, set->net_transmit_set.net_transmit);... default: BT_ERR("Invalid Configuration Set opcode 0x%04x", param.opcode); return -EINVAL;... }{...} }{...} void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg) { btc_ble_mesh_config_client_args_t *arg = NULL; esp_ble_mesh_cfg_client_cb_param_t cb = {0}; if (!msg) { BT_ERR("%s, Invalid parameter", __func__); return; }{...} arg = (btc_ble_mesh_config_client_args_t *)(msg->arg); switch (msg->act) { case BTC_BLE_MESH_ACT_CONFIG_CLIENT_GET_STATE: { cb.params = arg->cfg_client_get_state.params; cb.error_code = btc_ble_mesh_config_client_get_state(arg->cfg_client_get_state.params, arg->cfg_client_get_state.get_state); if (cb.error_code) { btc_ble_mesh_config_client_callback(&cb, ESP_BLE_MESH_CFG_CLIENT_GET_STATE_EVT); }{...} break; }{...} ... case BTC_BLE_MESH_ACT_CONFIG_CLIENT_SET_STATE: { cb.params = arg->cfg_client_set_state.params; cb.error_code = btc_ble_mesh_config_client_set_state(arg->cfg_client_set_state.params, arg->cfg_client_set_state.set_state); if (cb.error_code) { btc_ble_mesh_config_client_callback(&cb, ESP_BLE_MESH_CFG_CLIENT_SET_STATE_EVT); }{...} break; }{...} ... default: break;... }{...} btc_ble_mesh_config_client_arg_deep_free(msg); }{...} void btc_ble_mesh_config_client_cb_handler(btc_msg_t *msg) { esp_ble_mesh_cfg_client_cb_param_t *param = NULL; if (!msg) { BT_ERR("%s, Invalid parameter", __func__); return; }{...} param = (esp_ble_mesh_cfg_client_cb_param_t *)(msg->arg); if (msg->act < ESP_BLE_MESH_CFG_CLIENT_EVT_MAX) { btc_ble_mesh_config_client_cb_to_app(msg->act, param); }{...} else { BT_ERR("%s, Unknown act %d", __func__, msg->act); }{...} btc_ble_mesh_config_client_free_req_data(msg); }{...} /* ... */ #endif /* CONFIG_BLE_MESH_CFG_CLI */ /* Configuration Server Model related functions */ static inline void btc_ble_mesh_config_server_cb_to_app(esp_ble_mesh_cfg_server_cb_event_t event, esp_ble_mesh_cfg_server_cb_param_t *param) { esp_ble_mesh_cfg_server_cb_t btc_ble_mesh_cb = (esp_ble_mesh_cfg_server_cb_t)btc_profile_cb_get(BTC_PID_CONFIG_SERVER); if (btc_ble_mesh_cb) { btc_ble_mesh_cb(event, param); }{...} }{ ... } static void btc_ble_mesh_config_server_callback(esp_ble_mesh_cfg_server_cb_param_t *cb_params, uint8_t act) { btc_msg_t msg = {0}; /* If corresponding callback is not registered, event will not be posted. */ if (!btc_profile_cb_get(BTC_PID_CONFIG_SERVER)) { return; }{...} msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_CONFIG_SERVER; msg.act = act; btc_transfer_context(&msg, cb_params, cb_params == NULL ? 0 : sizeof(esp_ble_mesh_cfg_server_cb_param_t), NULL, NULL); }{ ... } void bt_mesh_config_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, const uint8_t *val, size_t len) { esp_ble_mesh_cfg_server_cb_param_t cb_params = {0}; uint8_t act = 0U; if (!model || !ctx || len > sizeof(cb_params.value)) { BT_ERR("%s, Invalid parameter", __func__); return; }{...} switch (evt_type) { case BTC_BLE_MESH_EVT_CONFIG_SERVER_STATE_CHANGE: act = ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT; break;... default: BT_ERR("Unknown Config server event type %d", evt_type); return;... }{...} cb_params.model = (esp_ble_mesh_model_t *)model; cb_params.ctx.net_idx = ctx->net_idx; cb_params.ctx.app_idx = ctx->app_idx; cb_params.ctx.addr = ctx->addr; cb_params.ctx.recv_ttl = ctx->recv_ttl; cb_params.ctx.recv_op = ctx->recv_op; cb_params.ctx.recv_dst = ctx->recv_dst; cb_params.ctx.recv_rssi = ctx->recv_rssi; cb_params.ctx.send_ttl = ctx->send_ttl; if (val && len) { memcpy(&cb_params.value, val, len); }{...} btc_ble_mesh_config_server_callback(&cb_params, act); }{ ... } void btc_ble_mesh_config_server_cb_handler(btc_msg_t *msg) { esp_ble_mesh_cfg_server_cb_param_t *param = NULL; if (!msg) { BT_ERR("%s, Invalid parameter", __func__); return; }{...} param = (esp_ble_mesh_cfg_server_cb_param_t *)(msg->arg); if (msg->act < ESP_BLE_MESH_CFG_SERVER_EVT_MAX) { btc_ble_mesh_config_server_cb_to_app(msg->act, param); }{...} else { BT_ERR("%s, Unknown act %d", __func__, msg->act); }{...} }{ ... }
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.