Select one of the symbols to view example projects that use it.
 
Outline
#include <string.h>
#include <errno.h>
#include "btc_ble_mesh_generic_model.h"
#include "mesh/config.h"
#include "mesh/model_opcode.h"
#include "mesh/generic_client.h"
#define BLE_MESH_GEN_ONOFF_GET_MSG_LEN
#define BLE_MESH_GEN_ONOFF_SET_MSG_LEN
#define BLE_MESH_GEN_LEVEL_GET_MSG_LEN
#define BLE_MESH_GEN_LEVEL_SET_MSG_LEN
#define BLE_MESH_GEN_DELTA_SET_MSG_LEN
#define BLE_MESH_GEN_MOVE_SET_MSG_LEN
#define BLE_MESH_GEN_DEF_TRANS_TIME_GET_MSG_LEN
#define BLE_MESH_GEN_DEF_TRANS_TIME_SET_MSG_LEN
#define BLE_MESH_GEN_ONPOWERUP_GET_MSG_LEN
#define BLE_MESH_GEN_ONPOWERUP_SET_MSG_LEN
#define BLE_MESH_GEN_POWER_LEVEL_GET_MSG_LEN
#define BLE_MESH_GEN_POWER_LEVEL_SET_MSG_LEN
#define BLE_MESH_GEN_POWER_LAST_GET_MSG_LEN
#define BLE_MESH_GEN_POWER_DEFAULT_GET_MSG_LEN
#define BLE_MESH_GEN_POWER_DEFAULT_SET_MSG_LEN
#define BLE_MESH_GEN_POWER_RANGE_GET_MSG_LEN
#define BLE_MESH_GEN_POWER_RANGE_SET_MSG_LEN
#define BLE_MESH_GEN_BATTERY_GET_MSG_LEN
#define BLE_MESH_GEN_LOC_GLOBAL_GET_MSG_LEN
#define BLE_MESH_GEN_LOC_GLOBAL_SET_MSG_LEN
#define BLE_MESH_GEN_LOC_LOCAL_GET_MSG_LEN
#define BLE_MESH_GEN_LOC_LOCAL_SET_MSG_LEN
#define BLE_MESH_GEN_USER_PROPERTIES_GET_MSG_LEN
#define BLE_MESH_GEN_USER_PROPERTY_GET_MSG_LEN
#define BLE_MESH_GEN_USER_PROPERTY_SET_MSG_LEN
#define BLE_MESH_GEN_ADMIN_PROPERTIES_GET_MSG_LEN
#define BLE_MESH_GEN_ADMIN_PROPERTY_GET_MSG_LEN
#define BLE_MESH_GEN_ADMIN_PROPERTY_SET_MSG_LEN
#define BLE_MESH_GEN_MANU_PROPERTIES_GET_MSG_LEN
#define BLE_MESH_GEN_MANU_PROPERTY_GET_MSG_LEN
#define BLE_MESH_GEN_MANU_PROPERTY_SET_MSG_LEN
#define BLE_MESH_GEN_CLIENT_PROPERTIES_GET_MSG_LEN
#define BLE_MESH_GEN_GET_STATE_MSG_LEN
Files
loading...
SourceVuESP-IDF Framework and ExamplesESP-IDFcomponents/bt/esp_ble_mesh/models/client/generic_client.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
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/* * 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_generic_model.h" #include "mesh/config.h" #include "mesh/model_opcode.h"5 includes #if CONFIG_BLE_MESH_GENERIC_CLIENT #include "mesh/generic_client.h" /* The followings are the macro definitions of Generic client * model message length, and a message is composed of 3 parts: * Opcode + Payload + MIC *//* ... */ /* Generic onoff client messages length */ #define BLE_MESH_GEN_ONOFF_GET_MSG_LEN (2 + 0 + 4) #define BLE_MESH_GEN_ONOFF_SET_MSG_LEN (2 + 4 + 4) /* Generic level client messages length */ #define BLE_MESH_GEN_LEVEL_GET_MSG_LEN (2 + 0 + 4) #define BLE_MESH_GEN_LEVEL_SET_MSG_LEN (2 + 5 + 4) #define BLE_MESH_GEN_DELTA_SET_MSG_LEN (2 + 7 + 4) #define BLE_MESH_GEN_MOVE_SET_MSG_LEN (2 + 5 + 4) /* Generic default transition time client messages length */ #define BLE_MESH_GEN_DEF_TRANS_TIME_GET_MSG_LEN (2 + 0 + 4) #define BLE_MESH_GEN_DEF_TRANS_TIME_SET_MSG_LEN (2 + 1 + 4) /* Generic power onoff client messages length */ #define BLE_MESH_GEN_ONPOWERUP_GET_MSG_LEN (2 + 0 + 4) #define BLE_MESH_GEN_ONPOWERUP_SET_MSG_LEN (2 + 1 + 4) /* Generic power level client messages length */ #define BLE_MESH_GEN_POWER_LEVEL_GET_MSG_LEN (2 + 0 + 4) #define BLE_MESH_GEN_POWER_LEVEL_SET_MSG_LEN (2 + 5 + 4) #define BLE_MESH_GEN_POWER_LAST_GET_MSG_LEN (2 + 0 + 4) #define BLE_MESH_GEN_POWER_DEFAULT_GET_MSG_LEN (2 + 0 + 4) #define BLE_MESH_GEN_POWER_DEFAULT_SET_MSG_LEN (2 + 2 + 4) #define BLE_MESH_GEN_POWER_RANGE_GET_MSG_LEN (2 + 0 + 4) #define BLE_MESH_GEN_POWER_RANGE_SET_MSG_LEN (2 + 4 + 4) /* Generic battery client messages length */ #define BLE_MESH_GEN_BATTERY_GET_MSG_LEN (2 + 0 + 4) /* Generic location client messages length */ #define BLE_MESH_GEN_LOC_GLOBAL_GET_MSG_LEN (2 + 0 + 4) #define BLE_MESH_GEN_LOC_GLOBAL_SET_MSG_LEN (1 + 10 + 4) #define BLE_MESH_GEN_LOC_LOCAL_GET_MSG_LEN (2 + 0 + 4) #define BLE_MESH_GEN_LOC_LOCAL_SET_MSG_LEN (2 + 9 + 4) /* Generic property client messages length */ #define BLE_MESH_GEN_USER_PROPERTIES_GET_MSG_LEN (2 + 0 + 4) #define BLE_MESH_GEN_USER_PROPERTY_GET_MSG_LEN (2 + 2 + 4) #define BLE_MESH_GEN_USER_PROPERTY_SET_MSG_LEN /* variable */ #define BLE_MESH_GEN_ADMIN_PROPERTIES_GET_MSG_LEN (2 + 0 + 4) #define BLE_MESH_GEN_ADMIN_PROPERTY_GET_MSG_LEN (2 + 2 + 4) #define BLE_MESH_GEN_ADMIN_PROPERTY_SET_MSG_LEN /* variable */ #define BLE_MESH_GEN_MANU_PROPERTIES_GET_MSG_LEN (2 + 0 + 4) #define BLE_MESH_GEN_MANU_PROPERTY_GET_MSG_LEN (2 + 2 + 4) #define BLE_MESH_GEN_MANU_PROPERTY_SET_MSG_LEN (1 + 3 + 4) #define BLE_MESH_GEN_CLIENT_PROPERTIES_GET_MSG_LEN (1 + 2 + 4) #define BLE_MESH_GEN_GET_STATE_MSG_LEN (2 + 2 + 4)33 defines static const bt_mesh_client_op_pair_t gen_op_pair[] = { { BLE_MESH_MODEL_OP_GEN_ONOFF_GET, BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS }, { BLE_MESH_MODEL_OP_GEN_ONOFF_SET, BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS }, { BLE_MESH_MODEL_OP_GEN_LEVEL_GET, BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS }, { BLE_MESH_MODEL_OP_GEN_LEVEL_SET, BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS }, { BLE_MESH_MODEL_OP_GEN_DELTA_SET, BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS }, { BLE_MESH_MODEL_OP_GEN_MOVE_SET, BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS }, { BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET, BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS }, { BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET, BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS }, { BLE_MESH_MODEL_OP_GEN_ONPOWERUP_GET, BLE_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS }, { BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET, BLE_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS }, { BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_GET, BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS }, { BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET, BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS }, { BLE_MESH_MODEL_OP_GEN_POWER_LAST_GET, BLE_MESH_MODEL_OP_GEN_POWER_LAST_STATUS }, { BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET, BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS }, { BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET, BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS }, { BLE_MESH_MODEL_OP_GEN_POWER_RANGE_GET, BLE_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS }, { BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET, BLE_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS }, { BLE_MESH_MODEL_OP_GEN_BATTERY_GET, BLE_MESH_MODEL_OP_GEN_BATTERY_STATUS }, { BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET, BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS }, { BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET, BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS }, { BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_GET, BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS }, { BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET, BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS }, { BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET, BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS }, { BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET, BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS }, { BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET, BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS }, { BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET, BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS }, { BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET, BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS }, { BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET, BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS }, { BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET, BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS }, { BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET, BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS }, { BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET, BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS }, { BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET, BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS }, }{...}; static bt_mesh_mutex_t generic_client_lock; static void timeout_handler(struct k_work *work) { struct k_delayed_work *timer = NULL; bt_mesh_client_node_t *node = NULL; struct bt_mesh_model *model = NULL; struct bt_mesh_msg_ctx ctx = {0}; uint32_t opcode = 0U; BT_WARN("Receive generic status message timeout"); bt_mesh_mutex_lock(&generic_client_lock); timer = CONTAINER_OF(work, struct k_delayed_work, work); if (timer && !k_delayed_work_free(timer)) { node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work); if (node) { memcpy(&ctx, &node->ctx, sizeof(ctx)); opcode = node->opcode; model = node->model; bt_mesh_client_free_node(node); bt_mesh_generic_client_cb_evt_to_btc( opcode, BTC_BLE_MESH_EVT_GENERIC_CLIENT_TIMEOUT, model, &ctx, NULL, 0); }{...} }{...} bt_mesh_mutex_unlock(&generic_client_lock); }{...} static void generic_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { bt_mesh_client_node_t *node = NULL; uint8_t *val = NULL; uint8_t evt = 0xFF; size_t len = 0U; BT_DBG("len %d, bytes %s", buf->len, bt_hex(buf->data, buf->len)); switch (ctx->recv_op) { case BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS: { struct bt_mesh_gen_onoff_status *status = NULL; if (buf->len != 1 && buf->len != 3) { BT_ERR("Invalid Generic OnOff Status length %d", buf->len); return; }{...} status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_onoff_status)); if (!status) { BT_ERR("%s, Out of memory", __func__); return; }{...} status->present_onoff = net_buf_simple_pull_u8(buf); if (buf->len) { status->op_en = true; status->target_onoff = net_buf_simple_pull_u8(buf); status->remain_time = net_buf_simple_pull_u8(buf); }{...} val = (uint8_t *)status; len = sizeof(struct bt_mesh_gen_onoff_status); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS: { struct bt_mesh_gen_level_status *status = NULL; if (buf->len != 2 && buf->len != 5) { BT_ERR("Invalid Generic Level Status length %d", buf->len); return; }{...} status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_level_status)); if (!status) { BT_ERR("%s, Out of memory", __func__); return; }{...} status->present_level = net_buf_simple_pull_le16(buf); if (buf->len) { status->op_en = true; status->target_level = net_buf_simple_pull_le16(buf); status->remain_time = net_buf_simple_pull_u8(buf); }{...} val = (uint8_t *)status; len = sizeof(struct bt_mesh_gen_level_status); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS: { struct bt_mesh_gen_def_trans_time_status *status = NULL; if (buf->len != 1) { BT_ERR("Invalid Generic Default Trans Time Status length %d", buf->len); return; }{...} status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_def_trans_time_status)); if (!status) { BT_ERR("%s, Out of memory", __func__); return; }{...} status->trans_time = net_buf_simple_pull_u8(buf); val = (uint8_t *)status; len = sizeof(struct bt_mesh_gen_def_trans_time_status); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS: { struct bt_mesh_gen_onpowerup_status *status = NULL; if (buf->len != 1) { BT_ERR("Invalid Generic OnPowerUp Status length %d", buf->len); return; }{...} status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_onpowerup_status)); if (!status) { BT_ERR("%s, Out of memory", __func__); return; }{...} status->onpowerup = net_buf_simple_pull_u8(buf); val = (uint8_t *)status; len = sizeof(struct bt_mesh_gen_onpowerup_status); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS: { struct bt_mesh_gen_power_level_status *status = NULL; if (buf->len != 2 && buf->len != 5) { BT_ERR("Invalid Generic Power Level Status length %d", buf->len); return; }{...} status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_level_status)); if (!status) { BT_ERR("%s, Out of memory", __func__); return; }{...} status->present_power = net_buf_simple_pull_le16(buf); if (buf->len) { status->op_en = true; status->target_power = net_buf_simple_pull_le16(buf); status->remain_time = net_buf_simple_pull_u8(buf); }{...} val = (uint8_t *)status; len = sizeof(struct bt_mesh_gen_power_level_status); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_POWER_LAST_STATUS: { struct bt_mesh_gen_power_last_status *status = NULL; if (buf->len != 2) { BT_ERR("Invalid Generic Power Last Status length %d", buf->len); return; }{...} status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_last_status)); if (!status) { BT_ERR("%s, Out of memory", __func__); return; }{...} status->power = net_buf_simple_pull_le16(buf); val = (uint8_t *)status; len = sizeof(struct bt_mesh_gen_power_last_status); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS: { struct bt_mesh_gen_power_default_status *status = NULL; if (buf->len != 2) { BT_ERR("Invalid Generic Power Default Status length %d", buf->len); return; }{...} status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_default_status)); if (!status) { BT_ERR("%s, Out of memory", __func__); return; }{...} status->power = net_buf_simple_pull_le16(buf); val = (uint8_t *)status; len = sizeof(struct bt_mesh_gen_power_default_status); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS: { struct bt_mesh_gen_power_range_status *status = NULL; if (buf->len != 5) { BT_ERR("Invalid Generic Power Range Status length %d", buf->len); return; }{...} status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_range_status)); if (!status) { BT_ERR("%s, Out of memory", __func__); return; }{...} status->status_code = net_buf_simple_pull_u8(buf); status->range_min = net_buf_simple_pull_le16(buf); status->range_max = net_buf_simple_pull_le16(buf); val = (uint8_t *)status; len = sizeof(struct bt_mesh_gen_power_range_status); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_BATTERY_STATUS: { struct bt_mesh_gen_battery_status *status = NULL; if (buf->len != 8) { BT_ERR("Invalid Generic Battery Status length %d", buf->len); return; }{...} status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_battery_status)); if (!status) { BT_ERR("%s, Out of memory", __func__); return; }{...} uint32_t value = 0; value = net_buf_simple_pull_le32(buf); status->battery_level = (uint8_t)value; status->time_to_discharge = (value >> 8); value = net_buf_simple_pull_le32(buf); status->time_to_charge = (value & 0xffffff); status->flags = (uint8_t)(value >> 24); val = (uint8_t *)status; len = sizeof(struct bt_mesh_gen_battery_status); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS: { struct bt_mesh_gen_loc_global_status *status = NULL; if (buf->len != 10) { BT_ERR("Invalid Generic Location Global Status length %d", buf->len); return; }{...} status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_loc_global_status)); if (!status) { BT_ERR("%s, Out of memory", __func__); return; }{...} status->global_latitude = net_buf_simple_pull_le32(buf); status->global_longitude = net_buf_simple_pull_le32(buf); status->global_altitude = net_buf_simple_pull_le16(buf); val = (uint8_t *)status; len = sizeof(struct bt_mesh_gen_loc_global_status); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS: { struct bt_mesh_gen_loc_local_status *status = NULL; if (buf->len != 9) { BT_ERR("Invalid Generic Location Local Status length %d", buf->len); return; }{...} status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_loc_local_status)); if (!status) { BT_ERR("%s, Out of memory", __func__); return; }{...} status->local_north = net_buf_simple_pull_le16(buf); status->local_east = net_buf_simple_pull_le16(buf); status->local_altitude = net_buf_simple_pull_le16(buf); status->floor_number = net_buf_simple_pull_u8(buf); status->uncertainty = net_buf_simple_pull_le16(buf); val = (uint8_t *)status; len = sizeof(struct bt_mesh_gen_loc_local_status); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS: { struct bt_mesh_gen_user_properties_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_user_properties_status)); if (!status) { BT_ERR("%s, Out of memory", __func__); return; }{...} status->user_property_ids = bt_mesh_alloc_buf(buf->len); if (!status->user_property_ids) { BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; }{...} net_buf_simple_add_mem(status->user_property_ids, buf->data, buf->len); val = (uint8_t *)status; len = sizeof(struct bt_mesh_gen_user_properties_status); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS: { struct bt_mesh_gen_user_property_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_user_property_status)); if (!status) { BT_ERR("%s, Out of memory", __func__); return; }{...} status->user_property_id = net_buf_simple_pull_le16(buf); if (buf->len) { status->op_en = true; status->user_access = net_buf_simple_pull_u8(buf); status->user_property_value = bt_mesh_alloc_buf(buf->len); if (!status->user_property_value) { BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; }{...} net_buf_simple_add_mem(status->user_property_value, buf->data, buf->len); }{...} val = (uint8_t *)status; len = sizeof(struct bt_mesh_gen_user_property_status); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS: { struct bt_mesh_gen_admin_properties_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_admin_properties_status)); if (!status) { BT_ERR("%s, Out of memory", __func__); return; }{...} status->admin_property_ids = bt_mesh_alloc_buf(buf->len); if (!status->admin_property_ids) { BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; }{...} net_buf_simple_add_mem(status->admin_property_ids, buf->data, buf->len); val = (uint8_t *)status; len = sizeof(struct bt_mesh_gen_admin_properties_status); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS: { struct bt_mesh_gen_admin_property_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_admin_property_status)); if (!status) { BT_ERR("%s, Out of memory", __func__); return; }{...} status->admin_property_id = net_buf_simple_pull_le16(buf); if (buf->len) { status->op_en = true; status->admin_user_access = net_buf_simple_pull_u8(buf); status->admin_property_value = bt_mesh_alloc_buf(buf->len); if (!status->admin_property_value) { BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; }{...} net_buf_simple_add_mem(status->admin_property_value, buf->data, buf->len); }{...} val = (uint8_t *)status; len = sizeof(struct bt_mesh_gen_admin_property_status); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS: { struct bt_mesh_gen_manu_properties_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_manu_properties_status)); if (!status) { BT_ERR("%s, Out of memory", __func__); return; }{...} status->manu_property_ids = bt_mesh_alloc_buf(buf->len); if (!status->manu_property_ids) { BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; }{...} net_buf_simple_add_mem(status->manu_property_ids, buf->data, buf->len); val = (uint8_t *)status; len = sizeof(struct bt_mesh_gen_manu_properties_status); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS: { struct bt_mesh_gen_manu_property_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_manu_property_status)); if (!status) { BT_ERR("%s, Out of memory", __func__); return; }{...} status->manu_property_id = net_buf_simple_pull_le16(buf); if (buf->len) { status->op_en = true; status->manu_user_access = net_buf_simple_pull_u8(buf); status->manu_property_value = bt_mesh_alloc_buf(buf->len); if (!status->manu_property_value) { BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; }{...} net_buf_simple_add_mem(status->manu_property_value, buf->data, buf->len); }{...} val = (uint8_t *)status; len = sizeof(struct bt_mesh_gen_manu_property_status); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS: { struct bt_mesh_gen_client_properties_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_client_properties_status)); if (!status) { BT_ERR("%s, Out of memory", __func__); return; }{...} status->client_property_ids = bt_mesh_alloc_buf(buf->len); if (!status->client_property_ids) { BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; }{...} net_buf_simple_add_mem(status->client_property_ids, buf->data, buf->len); val = (uint8_t *)status; len = sizeof(struct bt_mesh_gen_client_properties_status); break; }{...} ... default: BT_ERR("Invalid Generic Status opcode 0x%04x", ctx->recv_op); return;... }{...} buf->data = val; buf->len = len; bt_mesh_mutex_lock(&generic_client_lock); node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true); if (!node) { BT_DBG("Unexpected Generic Status 0x%04x", ctx->recv_op); }{...} else { switch (node->opcode) { case BLE_MESH_MODEL_OP_GEN_ONOFF_GET: case BLE_MESH_MODEL_OP_GEN_LEVEL_GET: case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET: case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_GET: case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_GET: case BLE_MESH_MODEL_OP_GEN_POWER_LAST_GET: case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET: case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_GET: case BLE_MESH_MODEL_OP_GEN_BATTERY_GET: case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET: case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_GET: case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET: case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET: case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET: case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET: case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET: case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET: case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET: evt = BTC_BLE_MESH_EVT_GENERIC_CLIENT_GET_STATE; break;... case BLE_MESH_MODEL_OP_GEN_ONOFF_SET: case BLE_MESH_MODEL_OP_GEN_LEVEL_SET: case BLE_MESH_MODEL_OP_GEN_DELTA_SET: case BLE_MESH_MODEL_OP_GEN_MOVE_SET: case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET: case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET: case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET: case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET: case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET: case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET: case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET: case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET: case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET: case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET: evt = BTC_BLE_MESH_EVT_GENERIC_CLIENT_SET_STATE; break;... default: break;... }{...} if (!k_delayed_work_free(&node->timer)) { uint32_t opcode = node->opcode; bt_mesh_client_free_node(node); bt_mesh_generic_client_cb_evt_to_btc(opcode, evt, model, ctx, val, len); }{...} }{...} bt_mesh_mutex_unlock(&generic_client_lock); switch (ctx->recv_op) { case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS: { struct bt_mesh_gen_user_properties_status *status; status = (struct bt_mesh_gen_user_properties_status *)val; bt_mesh_free_buf(status->user_property_ids); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS: { struct bt_mesh_gen_user_property_status *status; status = (struct bt_mesh_gen_user_property_status *)val; bt_mesh_free_buf(status->user_property_value); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS: { struct bt_mesh_gen_admin_properties_status *status; status = (struct bt_mesh_gen_admin_properties_status *)val; bt_mesh_free_buf(status->admin_property_ids); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS: { struct bt_mesh_gen_admin_property_status *status; status = (struct bt_mesh_gen_admin_property_status *)val; bt_mesh_free_buf(status->admin_property_value); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS: { struct bt_mesh_gen_manu_properties_status *status; status = (struct bt_mesh_gen_manu_properties_status *)val; bt_mesh_free_buf(status->manu_property_ids); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS: { struct bt_mesh_gen_manu_property_status *status; status = (struct bt_mesh_gen_manu_property_status *)val; bt_mesh_free_buf(status->manu_property_value); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS: { struct bt_mesh_gen_client_properties_status *status; status = (struct bt_mesh_gen_client_properties_status *)val; bt_mesh_free_buf(status->client_property_ids); break; }{...} ... default: break;... }{...} bt_mesh_free(val); }{...} const struct bt_mesh_model_op bt_mesh_gen_onoff_cli_op[] = { { BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS, 1, generic_status }, BLE_MESH_MODEL_OP_END, }{...}; const struct bt_mesh_model_op bt_mesh_gen_level_cli_op[] = { { BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS, 2, generic_status }, BLE_MESH_MODEL_OP_END, }{...}; const struct bt_mesh_model_op bt_mesh_gen_def_trans_time_cli_op[] = { { BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS, 1, generic_status }, BLE_MESH_MODEL_OP_END, }{...}; const struct bt_mesh_model_op bt_mesh_gen_power_onoff_cli_op[] = { { BLE_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS, 1, generic_status }, BLE_MESH_MODEL_OP_END, }{...}; const struct bt_mesh_model_op bt_mesh_gen_power_level_cli_op[] = { { BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS, 2, generic_status }, { BLE_MESH_MODEL_OP_GEN_POWER_LAST_STATUS, 2, generic_status }, { BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS, 2, generic_status }, { BLE_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS, 5, generic_status }, BLE_MESH_MODEL_OP_END, }{...}; const struct bt_mesh_model_op bt_mesh_gen_battery_cli_op[] = { { BLE_MESH_MODEL_OP_GEN_BATTERY_STATUS, 8, generic_status }, BLE_MESH_MODEL_OP_END, }{...}; const struct bt_mesh_model_op bt_mesh_gen_location_cli_op[] = { { BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS, 10, generic_status }, { BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS, 9, generic_status }, BLE_MESH_MODEL_OP_END, }{...}; const struct bt_mesh_model_op bt_mesh_gen_property_cli_op[] = { { BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS, 2, generic_status }, { BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS, 2, generic_status }, { BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS, 2, generic_status }, { BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS, 2, generic_status }, { BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS, 2, generic_status }, { BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS, 2, generic_status }, { BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS, 2, generic_status }, BLE_MESH_MODEL_OP_END, }{...}; static int gen_get_state(bt_mesh_client_common_param_t *common, void *value) { NET_BUF_SIMPLE_DEFINE(msg, BLE_MESH_GEN_GET_STATE_MSG_LEN); bt_mesh_model_msg_init(&msg, common->opcode); if (value) { switch (common->opcode) { case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET: { struct bt_mesh_gen_user_property_get *get; get = (struct bt_mesh_gen_user_property_get *)value; net_buf_simple_add_le16(&msg, get->user_property_id); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET: { struct bt_mesh_gen_admin_property_get *get; get = (struct bt_mesh_gen_admin_property_get *)value; net_buf_simple_add_le16(&msg, get->admin_property_id); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET: { struct bt_mesh_gen_manu_property_get *get; get = (struct bt_mesh_gen_manu_property_get *)value; net_buf_simple_add_le16(&msg, get->manu_property_id); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET: { struct bt_mesh_gen_client_properties_get *get; get = (struct bt_mesh_gen_client_properties_get *)value; net_buf_simple_add_le16(&msg, get->client_property_id); break; }{...} ... default: BT_DBG("No parameters for Generic Get 0x%04x", common->opcode); break;... }{...} }{...} return bt_mesh_client_send_msg(common, &msg, true, timeout_handler); }{...} static int gen_set_state(bt_mesh_client_common_param_t *common, void *value, uint16_t value_len, bool need_ack) { struct net_buf_simple *msg = NULL; int err = 0; msg = bt_mesh_alloc_buf(value_len); if (!msg) { BT_ERR("%s, Out of memory", __func__); return -ENOMEM; }{...} bt_mesh_model_msg_init(msg, common->opcode); switch (common->opcode) { case BLE_MESH_MODEL_OP_GEN_ONOFF_SET: case BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK: { struct bt_mesh_gen_onoff_set *set; set = (struct bt_mesh_gen_onoff_set *)value; net_buf_simple_add_u8(msg, set->onoff); net_buf_simple_add_u8(msg, set->tid); if (set->op_en) { net_buf_simple_add_u8(msg, set->trans_time); net_buf_simple_add_u8(msg, set->delay); }{...} break; }{...} ... case BLE_MESH_MODEL_OP_GEN_LEVEL_SET: case BLE_MESH_MODEL_OP_GEN_LEVEL_SET_UNACK: { struct bt_mesh_gen_level_set *set; set = (struct bt_mesh_gen_level_set *)value; net_buf_simple_add_le16(msg, set->level); net_buf_simple_add_u8(msg, set->tid); if (set->op_en) { net_buf_simple_add_u8(msg, set->trans_time); net_buf_simple_add_u8(msg, set->delay); }{...} break; }{...} ... case BLE_MESH_MODEL_OP_GEN_DELTA_SET: case BLE_MESH_MODEL_OP_GEN_DELTA_SET_UNACK: { struct bt_mesh_gen_delta_set *set; set = (struct bt_mesh_gen_delta_set *)value; net_buf_simple_add_le32(msg, set->delta_level); net_buf_simple_add_u8(msg, set->tid); if (set->op_en) { net_buf_simple_add_u8(msg, set->trans_time); net_buf_simple_add_u8(msg, set->delay); }{...} break; }{...} ... case BLE_MESH_MODEL_OP_GEN_MOVE_SET: case BLE_MESH_MODEL_OP_GEN_MOVE_SET_UNACK: { struct bt_mesh_gen_move_set *set; set = (struct bt_mesh_gen_move_set *)value; net_buf_simple_add_le16(msg, set->delta_level); net_buf_simple_add_u8(msg, set->tid); if (set->op_en) { net_buf_simple_add_u8(msg, set->trans_time); net_buf_simple_add_u8(msg, set->delay); }{...} break; }{...} ... case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET: case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET_UNACK: { struct bt_mesh_gen_def_trans_time_set *set; set = (struct bt_mesh_gen_def_trans_time_set *)value; net_buf_simple_add_u8(msg, set->trans_time); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET: case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET_UNACK: { struct bt_mesh_gen_onpowerup_set *set; set = (struct bt_mesh_gen_onpowerup_set *)value; net_buf_simple_add_u8(msg, set->onpowerup); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET: case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET_UNACK: { struct bt_mesh_gen_power_level_set *set; set = (struct bt_mesh_gen_power_level_set *)value; net_buf_simple_add_le16(msg, set->power); net_buf_simple_add_u8(msg, set->tid); if (set->op_en) { net_buf_simple_add_u8(msg, set->trans_time); net_buf_simple_add_u8(msg, set->delay); }{...} break; }{...} ... case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET: case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET_UNACK: { struct bt_mesh_gen_power_default_set *set; set = (struct bt_mesh_gen_power_default_set *)value; net_buf_simple_add_le16(msg, set->power); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET: case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET_UNACK: { struct bt_mesh_gen_power_range_set *set; set = (struct bt_mesh_gen_power_range_set *)value; net_buf_simple_add_le16(msg, set->range_min); net_buf_simple_add_le16(msg, set->range_max); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET: case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET_UNACK: { struct bt_mesh_gen_loc_global_set *set; set = (struct bt_mesh_gen_loc_global_set *)value; net_buf_simple_add_le32(msg, set->global_latitude); net_buf_simple_add_le32(msg, set->global_longitude); net_buf_simple_add_le16(msg, set->global_altitude); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET: case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET_UNACK: { struct bt_mesh_gen_loc_local_set *set; set = (struct bt_mesh_gen_loc_local_set *)value; net_buf_simple_add_le16(msg, set->local_north); net_buf_simple_add_le16(msg, set->local_east); net_buf_simple_add_le16(msg, set->local_altitude); net_buf_simple_add_u8(msg, set->floor_number); net_buf_simple_add_le16(msg, set->uncertainty); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET: case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK: { struct bt_mesh_gen_user_property_set *set; set = (struct bt_mesh_gen_user_property_set *)value; net_buf_simple_add_le16(msg, set->user_property_id); net_buf_simple_add_mem(msg, set->user_property_value->data, set->user_property_value->len); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET: case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK: { struct bt_mesh_gen_admin_property_set *set; set = (struct bt_mesh_gen_admin_property_set *)value; net_buf_simple_add_le16(msg, set->admin_property_id); net_buf_simple_add_u8(msg, set->admin_user_access); net_buf_simple_add_mem(msg, set->admin_property_value->data, set->admin_property_value->len); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET: case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET_UNACK: { struct bt_mesh_gen_manu_property_set *set; set = (struct bt_mesh_gen_manu_property_set *)value; net_buf_simple_add_le16(msg, set->manu_property_id); net_buf_simple_add_u8(msg, set->manu_user_access); break; }{...} ... default: BT_ERR("Invalid Generic Set opcode 0x%04x", common->opcode); err = -EINVAL; goto end;... }{...} err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler); end: bt_mesh_free_buf(msg); return err; }{...} int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common, void *get) { bt_mesh_generic_client_t *client = NULL; if (!common || !common->model) { BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; }{...} client = (bt_mesh_generic_client_t *)common->model->user_data; if (!client || !client->internal_data) { BT_ERR("Invalid Generic client data"); return -EINVAL; }{...} switch (common->opcode) { case BLE_MESH_MODEL_OP_GEN_ONOFF_GET: case BLE_MESH_MODEL_OP_GEN_LEVEL_GET: case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET: case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_GET: case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_GET: case BLE_MESH_MODEL_OP_GEN_POWER_LAST_GET: case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET: case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_GET: case BLE_MESH_MODEL_OP_GEN_BATTERY_GET: case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET: case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_GET: case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET: case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET: case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET: break;... case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET: if (!get) { BT_ERR("Invalid Generic User Property Get"); return -EINVAL; }{...} break;... case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET: if (!get) { BT_ERR("Invalid Generic Admin Property Get"); return -EINVAL; }{...} break;... case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET: if (!get) { BT_ERR("Invalid Generic Manu Property Get"); return -EINVAL; }{...} break;... case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET: if (!get) { BT_ERR("Invalid Generic Client Properties Get"); return -EINVAL; }{...} break;... default: BT_ERR("Invalid Generic Get opcode 0x%04x", common->opcode); return -EINVAL;... }{...} return gen_get_state(common, get); }{...} int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void *set) { bt_mesh_generic_client_t *client = NULL; uint16_t length = 0U; bool need_ack = false; if (!common || !common->model || !set) { BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; }{...} client = (bt_mesh_generic_client_t *)common->model->user_data; if (!client || !client->internal_data) { BT_ERR("Invalid Generic client data"); return -EINVAL; }{...} switch (common->opcode) { case BLE_MESH_MODEL_OP_GEN_ONOFF_SET: need_ack = true;... case BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK: { struct bt_mesh_gen_onoff_set *value; value = (struct bt_mesh_gen_onoff_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { BT_ERR("Invalid Generic OnOff Set transition time"); return -EINVAL; }{...} }{...} length = BLE_MESH_GEN_ONOFF_SET_MSG_LEN; break; }{...} ... case BLE_MESH_MODEL_OP_GEN_LEVEL_SET: need_ack = true;... case BLE_MESH_MODEL_OP_GEN_LEVEL_SET_UNACK: { struct bt_mesh_gen_level_set *value; value = (struct bt_mesh_gen_level_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { BT_ERR("Invalid Generic Level Set transition time"); return -EINVAL; }{...} }{...} length = BLE_MESH_GEN_LEVEL_SET_MSG_LEN; break; }{...} ... case BLE_MESH_MODEL_OP_GEN_DELTA_SET: need_ack = true;... case BLE_MESH_MODEL_OP_GEN_DELTA_SET_UNACK: { struct bt_mesh_gen_delta_set *value; value = (struct bt_mesh_gen_delta_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { BT_ERR("Invalid Generic Delta Set transition time"); return -EINVAL; }{...} }{...} length = BLE_MESH_GEN_DELTA_SET_MSG_LEN; break; }{...} ... case BLE_MESH_MODEL_OP_GEN_MOVE_SET: need_ack = true;... case BLE_MESH_MODEL_OP_GEN_MOVE_SET_UNACK: { struct bt_mesh_gen_move_set *value; value = (struct bt_mesh_gen_move_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { BT_ERR("Invalid Generic Move Set transition time"); return -EINVAL; }{...} }{...} length = BLE_MESH_GEN_MOVE_SET_MSG_LEN; break; }{...} ... case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET: need_ack = true;... case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET_UNACK: { uint8_t value = *(uint8_t *)set; if ((value & 0x3F) > 0x3E) { BT_ERR("Invalid Generic Default Trans Time Set transition time"); return -EINVAL; }{...} length = BLE_MESH_GEN_DEF_TRANS_TIME_SET_MSG_LEN; break; }{...} ... case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET: need_ack = true;... case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET_UNACK: length = BLE_MESH_GEN_ONPOWERUP_SET_MSG_LEN; break;... case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET: need_ack = true;... case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET_UNACK: { struct bt_mesh_gen_power_level_set *value; value = (struct bt_mesh_gen_power_level_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { BT_ERR("Invalid Generic Power Level Set transition time"); return -EINVAL; }{...} }{...} length = BLE_MESH_GEN_POWER_LEVEL_SET_MSG_LEN; break; }{...} ... case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET: need_ack = true;... case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET_UNACK: length = BLE_MESH_GEN_POWER_DEFAULT_SET_MSG_LEN; break;... case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET: need_ack = true;... case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET_UNACK: { struct bt_mesh_gen_power_range_set *value; value = (struct bt_mesh_gen_power_range_set *)set; if (value->range_min > value->range_max) { BT_ERR("Generic Power Level Set range min is greater than range max"); return -EINVAL; }{...} length = BLE_MESH_GEN_POWER_RANGE_SET_MSG_LEN; break; }{...} ... case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET: need_ack = true;... case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET_UNACK: length = BLE_MESH_GEN_LOC_GLOBAL_SET_MSG_LEN; break;... case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET: need_ack = true;... case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET_UNACK: length = BLE_MESH_GEN_LOC_LOCAL_SET_MSG_LEN; break;... case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET: need_ack = true;... case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK: { struct bt_mesh_gen_user_property_set *value; value = (struct bt_mesh_gen_user_property_set *)set; if (!value->user_property_value) { BT_ERR("Invalid Generic User Property value"); return -EINVAL; }{...} length = (1 + 2 + value->user_property_value->len + 4); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET: need_ack = true;... case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK: { struct bt_mesh_gen_admin_property_set *value; value = (struct bt_mesh_gen_admin_property_set *)set; if (!value->admin_property_value) { BT_ERR("Invalid Generic Admin Property value"); return -EINVAL; }{...} length = (1 + 2 + 1 + value->admin_property_value->len + 4); break; }{...} ... case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET: need_ack = true;... case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET_UNACK: length = BLE_MESH_GEN_MANU_PROPERTY_SET_MSG_LEN; break;... default: BT_ERR("Invalid Generic Set opcode 0x%04x", common->opcode); return -EINVAL;... }{...} return gen_set_state(common, set, length, need_ack); }{...} static int generic_client_init(struct bt_mesh_model *model) { generic_internal_data_t *internal = NULL; bt_mesh_generic_client_t *client = NULL; if (!model) { BT_ERR("Invalid Generic client model"); return -EINVAL; }{...} client = (bt_mesh_generic_client_t *)model->user_data; if (!client) { BT_ERR("No Generic client context provided"); return -EINVAL; }{...} if (client->internal_data) { BT_WARN("%s, Already", __func__); return -EALREADY; }{...} internal = bt_mesh_calloc(sizeof(generic_internal_data_t)); if (!internal) { BT_ERR("%s, Out of memory", __func__); return -ENOMEM; }{...} sys_slist_init(&internal->queue); client->model = model; client->op_pair_size = ARRAY_SIZE(gen_op_pair); client->op_pair = gen_op_pair; client->internal_data = internal; bt_mesh_mutex_create(&generic_client_lock); return 0; }{...} #if CONFIG_BLE_MESH_DEINIT static int generic_client_deinit(struct bt_mesh_model *model) { bt_mesh_generic_client_t *client = NULL; if (!model) { BT_ERR("Invalid Generic client model"); return -EINVAL; }{...} client = (bt_mesh_generic_client_t *)model->user_data; if (!client) { BT_ERR("No Generic client context provided"); return -EINVAL; }{...} if (client->internal_data) { /* Remove items from the list */ bt_mesh_client_clear_list(client->internal_data); /* Free the allocated internal data */ bt_mesh_free(client->internal_data); client->internal_data = NULL; }{...} bt_mesh_mutex_free(&generic_client_lock); return 0; }{...} /* ... */#endif /* CONFIG_BLE_MESH_DEINIT */ const struct bt_mesh_model_cb bt_mesh_generic_client_cb = { .init = generic_client_init, #if CONFIG_BLE_MESH_DEINIT .deinit = generic_client_deinit, #endif /* CONFIG_BLE_MESH_DEINIT */ }{...}; /* ... */ #endif /* CONFIG_BLE_MESH_GENERIC_CLIENT */
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.