Welcome to mirror list, hosted at ThFree Co, Russian Federation.

appli_config_client.c « app « STM32_WPAN « BLE_MeshLightingPRFNode « BLE « Applications « P-NUCLEO-WB55.Nucleo « Projects - github.com/Flipper-Zero/STM32CubeWB.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3b7fce7a29270c886179b549da299af96c09f3a4 (plain)
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
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
/**
 ******************************************************************************
 * @file    appli_config_client.c
 * @author  BLE Mesh Team
 * @brief   Application interface for Config CLient Mesh Model
 ******************************************************************************
 * @attention
 *
 * <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
 * All rights reserved.</center></h2>
 *
 * This software component is licensed by ST under Ultimate Liberty license
 * SLA0044, the "License"; You may not use this file except in compliance with
 * the License. You may obtain a copy of the License at:
 *                             www.st.com/SLA0044
 *
 *
 ******************************************************************************
*/

/* Includes ------------------------------------------------------------------*/
#include "hal_common.h"
#include "types.h"
#include "appli_generic.h"
#include "appli_light.h"
#include "common.h"
#include "mesh_cfg.h"
#include "mesh_cfg_usr.h"
#include "appli_nvm.h"
#include "config_client.h"
#include "appli_config_client.h"
#include "appli_mesh.h"
#include "sensors.h"
#include "light_lc.h"
#include "vendor.h"

/** @addtogroup ST_BLE_Mesh
*  @{
*/

/** @addtogroup Application_Mesh_Models
*  @{
*/

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/

#define DEFAULT_GROUP_ADDR   0xC000
#define DEFAULT_PUBLISH_ADDR 0xC000
#define DEFAULT_NETKEY_INDEX 0x0000
#define DEFAULT_APPKEY_INDEX 0x0000
#define DEFAULT_CREDENTIAL_FLAG 0x00
#define DEFAULT_PUBLISH_TTL   0x08
#define DEFAULT_PUBLISH_PERIOD   0x00
#define DEFAULT_PUBLISH_RETRANSMIT_COUNT 0x00   
#define DEFAULT_PUBLISH_RETRANSMIT_INTERVAL_STEPS 0x00

#define NUM_VENDOR_MODELS_TO_SUBSCRIBE 0
#define NUM_VENDOR_MODELS_TO_PUBLISH 0
#define NUM_VENDOR_MODELS_TO_BIND_APP 0

/******************************************************************************/
#if defined (ENABLE_PROVISIONER_FEATURE) || defined(DYNAMIC_PROVISIONER)
/******************************************************************************/

const MOBLEUINT8 aConfigAppKeyDefault[19]= 
                { /* NetKeyIndexAndAppKeyIndex : 3B
                Index of the NetKey and index of the AppKey*/
                (MOBLEUINT8)(DEFAULT_NETKEY_INDEX & 0x00ff), 
                (MOBLEUINT8)((DEFAULT_NETKEY_INDEX & 0x0f00) >> 8) | (MOBLEUINT8) ((DEFAULT_APPKEY_INDEX & 0x000f) << 4), 
                (MOBLEUINT8) ((DEFAULT_APPKEY_INDEX >>4) & 0xff), 
                /* AppKey is initialised as below = 16B */
                 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 
                 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10 };


const MOBLEUINT8 aConfigAppKeyDeleteDefault[3]= 
                { /* NetKeyIndexAndAppKeyIndex : 3B
                Index of the NetKey and index of the AppKey*/
                (MOBLEUINT8)(DEFAULT_NETKEY_INDEX & 0x00ff), 
                (MOBLEUINT8)((DEFAULT_NETKEY_INDEX & 0x0f00) >> 8) | (MOBLEUINT8) ((DEFAULT_APPKEY_INDEX & 0x000f) << 4), 
                (MOBLEUINT8) ((DEFAULT_APPKEY_INDEX >>4) & 0xff)};


const MOBLEUINT8 aConfigAppKeyGetDefault[2]= 
                { /* NetKeyIndex : 2B
                Index of the NetKey */
                (MOBLEUINT8)(DEFAULT_NETKEY_INDEX & 0x00ff), 
                (MOBLEUINT8)((DEFAULT_NETKEY_INDEX & 0x0f00) >> 8) };

const MOBLEUINT8 aNoParamDefaultConfig;

const MOBLEUINT8 aNoInitParamDefault[MAX_CONFIG_PARAM_SIZE]= {0};

/* Private macro -------------------------------------------------------------*/

const MODEL_CONFIG_CLIENT_OpcodeTableParam_t ConfigClient_MessageOpcodes_Table[] = {
  /*    MOBLEUINT16 opcode, 
        MOBLEUINT8 min_payload_size, 
        MOBLEUINT8 max_payload_size;
  Here in this array, Handler is not defined; */

  /* 4.3.2.37 Config AppKey Add, Opcode = 0x00
     The Config AppKey Add is an acknowledged message used to add an AppKey 
       to the AppKey List on a node and bind it to the NetKey identified by 
       NetKeyIndex. The added AppKey can be used by the node only as a pair with 
       the specified NetKey. 
    The AppKey is used to authenticate and decrypt messages it receives, as well 
      as authenticate and encrypt messages it sends.
    The response to a Config AppKey Add message is a Config AppKey Status message.

    message parameters:
    -------------------
    NetKeyIndexAndAppKeyIndex: 3B : Index of the NetKey and index of the AppKey
    AppKey 16B : AppKey value */
  { OPCODE_CONFIG_APPKEY_ADD,    19, 19, aConfigAppKeyDefault },  

  /* 4.3.2.39 Config AppKey Delete, Opcode = 0x80 0x00
     The Config AppKey Delete is an acknowledged message used to delete an 
       AppKey from the AppKey List on a node. 
     The response to a Config AppKey Delete message is a 
       Config AppKey Status message.

    message parameters:
    -------------------
    NetKeyIndexAndAppKeyIndex : 3B : Index of the NetKey and index of the AppKey
   */
  { OPCODE_CONFIG_APPKEY_DELETE,  3,  3, aConfigAppKeyDeleteDefault },
  
  /* 4.3.2.41 Config AppKey Get, Opcode = 0x80 0x01
     The AppKey Get is an acknowledged message used to report all AppKeys bound 
       to the NetKey.
     The response to a Config AppKey Get message is a Config AppKey List message */
  { OPCODE_CONFIG_APPKEY_GET,     2,  2, aConfigAppKeyGetDefault }, 
  
  /* 4.3.2.38 Config AppKey Update, Opcode = 0x01
     The Config AppKey Update is an acknowledged message used to update an 
     AppKey value on the AppKey List on a node. The updated AppKey is used by 
     the node to authenticate and decrypt messages it receives, as well as 
     authenticate and encrypt messages it sends, as defined by the Key Refresh procedure (see Section 3.10.4).
     The response to an Config AppKey Update message is an Config AppKey Status message. 

    message parameters:
    -------------------
    NetKeyIndexAndAppKeyIndex: 3B : Index of the NetKey and index of the AppKey
    AppKey 16B : AppKey value */
  { OPCODE_CONFIG_APPKEY_UPDATE, 19, 19, aConfigAppKeyDefault },

    /* 4.3.2.1 Config Beacon Get, Opcode = 0x80 0x09
     The Config Beacon Get is an acknowledged message used to get the current 
     Secure Network Beacon state of a node (see Section 4.2.10).
     The response to a Config Beacon Get message is a Config Beacon Status message.
     There are no Parameters for this message. */
  { OPCODE_CONFIG_BEACON_GET, 0, 0, aNoInitParamDefault }, 

  /* 4.3.2.2 Config Beacon Set, Opcode = 0x80 0x0A
    The Config Beacon Set is an acknowledged message used to set the 
    Secure Network Beacon state of a node (see Section 4.2.10).
    The response to a Config Beacon Set message is a Config Beacon Status message.
    Beacon : 1B: New Secure Network Beacon state*/
  { OPCODE_CONFIG_BEACON_SET, 1, 1, aNoInitParamDefault }, 

  /* 4.3.2.4 Config Composition Data Get, Opcode = 0x80 0x08
     The Config Composition Data Get is an acknowledged message used to read 
       one page of the Composition Data (see Section 4.2.1).
     The response to a Config Composition Data Get message is a 
        Config Composition Data Status message. 
     Page : 1B : Page number of the Composition Data   */
  { OPCODE_CONFIG_COMPOSITION_DATA_GET, 1, 1, aNoInitParamDefault },
  
  /* 4.3.2.16 Config Model Publication Set, Opcode = 0x03
     The Config Model Publication Set is an acknowledged message used to set the
     Model Publication state (see Section 4.2.2) of an outgoing message that 
     originates from a model.
     The response to a Config Model Publication Set message is a 
        Config Model Publication Status message.
     The Config Model Publication Set message uses a single octet opcode to 
         maximize the size of a payload.

      ElementAddress : 16b : Address of the element
      PublishAddress : 16b : Value of the publish address
      AppKeyIndex : 12b : Index of the application key
      CredentialFlag : 1b : Value of the Friendship Credential Flag
      RFU : 3b : Reserved for Future Use
      PublishTTL : 8b : Default TTL value for the outgoing messages
      PublishPeriod : 8b : Period for periodic status publishing
      PublishRetransmitCount : 3b : Number of retransmissions for each published message
      PublishRetransmitIntervalSteps : 5b: Number of 50-millisecond steps between retransmissions
      ModelIdentifier: 16 or 32b: SIG Model ID or Vendor Model ID
   */
  
  { OPCODE_CONFIG_CONFIG_MODEL_PUBLICATION_SET, 11, 13, }, 

  /* 4.3.2.6 Config Default TTL Get, Opcode = 0x80 0x0C
    The Config Default TTL Get is an acknowledged message used to get the 
    current Default TTL state of a node.
    The response to a Config Default TTL Get message is a Config Default TTL Status message.
    There are no Parameters for this message.
  */
  { OPCODE_CONFIG_DEFAULT_TTL_GET, 0, 0, aNoInitParamDefault },          
  
  /* 4.3.2.7 Config Default TTL Set, Opcode = 0x80 0x0D
     The Config Default TTL Set is an acknowledged message used to set the 
     Default TTL state of a node (see Section 4.2.7).
     The response to a Config Default TTL Set message is a 
       Config Default TTL Status message. 
     TTL : 1B : New Default TTL value*/
  { OPCODE_CONFIG_DEFAULT_TTL_SET, 1, 1, aNoInitParamDefault }, 

  /* 4.3.2.55 Config Friend Get, Opcode = 0x80 0x0F
     The Config Friend Get is an acknowledged message used to get the current 
       Friend state of a node (see Section 4.2.13).
     The response to a Config Friend Get message is a Config Friend Status message.
     There are no Parameters for this message. */
  { OPCODE_CONFIG_FRIEND_GET, 0, 0, aNoInitParamDefault }, 
  
  /* 4.3.2.56 Config Friend Set, Opcode = 0x80 0x10
     The Config Friend Set is an acknowledged message used to set the 
      Friend state of a node (see Section 4.2.13).
     The response to a Config Friend Set message is a Config Friend Status message. 
      Friend : 1B : New Friend state    */
  { OPCODE_CONFIG_FRIEND_SET, 1, 1, aNoInitParamDefault },

  /* 4.3.2.9 Config GATT Proxy Get, Opcode = 0x80 0x12
     The Config GATT Proxy Get is an acknowledged message used to get the 
     current GATT Proxy state of a node (see Section 4.2.11).
     The response to a Config GATT Proxy Get message is a 
        Config GATT Proxy Status message.
     There are no Parameters for this message. */
  { OPCODE_CONFIG_GATT_PROXY_GET, 0, 0, aNoInitParamDefault },          

  /* 4.3.2.10 Config GATT Proxy Set, Opcode = 0x80 0x12
     The Config GATT Proxy Set is an acknowledged message used to set the 
        GATT Proxy state of a node (see Section 4.2.11).
     The response to a Config GATT Proxy Set message is a Config GATT Proxy 
        Status message
     GATTProxy : 1B  : New GATT Proxy state */
  { OPCODE_CONFIG_GATT_PROXY_SET, 1, 1, aNoInitParamDefault },

    /* 4.3.2.61 Config Heartbeat Publication Get, Opcode = 0x80 0x38
    The Config Heartbeat Publication Get is an acknowledged message used to get 
    the current Heartbeat Publication state of an element (see Section 4.2.17).
    The response to a Config Heartbeat Publication Get message is a 
    Config Heartbeat Publication Status message.
    The message has no parameters.*/
  { OPCODE_CONFIG_HEARTBEAT_PUBLICATION_GET, 0, 0, aNoInitParamDefault },
  
  /* 4.3.2.62 Config Heartbeat Publication Set, Opcode = 0x80 0x39
    The Config Heartbeat Publication Set is an acknowledged message used to set 
    the current Heartbeat Publication state of an element (see Section 4.2.17).
    The response to a Config Heartbeat Publication Set message is a 
    Config Heartbeat Publication Status message. 

   Destination : 2B : Destination address for Heartbeat messages
   CountLog    : 1B : Number of Heartbeat messages to be sent
   PeriodLog   : 1B : Period for sending Heartbeat messages
   TTL         : 1B : TTL to be used when sending Heartbeat messages
   Features    : 2B : Bit field indicating features that trigger Heartbeat messages when changed
   NetKeyIndex : 2B : NetKey Index
  */
  { OPCODE_CONFIG_HEARTBEAT_PUBLICATION_SET, 9, 9, aNoInitParamDefault },
  
  /* 4.3.2.64 Config Heartbeat Subscription Get, Opcode = 0x80 0x3A
     The Config Heartbeat Subscription Get is an acknowledged message used to get  
     the current Heartbeat Subscription state of an element (see Section 4.2.18).
     The response to a Config Heartbeat Subscription Get message is a 
     Config Heartbeat Subscription Status message.
   The message has no parameters. */
  { OPCODE_CONFIG_HEARTBEAT_SUBSCRIPTION_GET, 0, 0, aNoInitParamDefault },
  
  /* 4.3.2.65 Config Heartbeat Subscription Set, Opcode = 0x80 0x3B
     The Config Heartbeat Subscription Set is an acknowledged message used to 
     set the current Heartbeat Subscription state of an element (see Section 4.2.18).
      The response to a Config Heartbeat Subscription Set message is a 
      Config Heartbeat Subscription Status message.

      Source : 2B : Source address for Heartbeat messages
      Destination : 2B : Destination address for Heartbeat messages
      PeriodLog : 1B : Period for receiving Heartbeat messages */
  { OPCODE_CONFIG_HEARTBEAT_SUBSCRIPTION_SET, 5, 5, aNoInitParamDefault },

  /* 4.3.2.58 Config Key Refresh Phase Get, Opcode = 0x80 0x15
     The Config Key Refresh Phase Get is an acknowledged message used to get the
       current Key Refresh Phase state of the identified network key.
     The response to a Config Key Refresh Phase Get message is a 
       Config Key Refresh Phase Status message. 
     NetKeyIndex : 2B : NetKey Index*/
  { OPCODE_CONFIG_KEY_REFRESH_PHASE_GET, 2, 2, aNoInitParamDefault },
  
  /* 4.3.2.59 Config Key Refresh Phase Set, Opcode = 0x80 0x16
    The Config Key Refresh Phase Set is an acknowledged message used to set the 
    Key Refresh Phase state of the identified network key (see Section 4.2.14).
   The response to a Config Key Refresh Phase Set message is a 
      Config Key Refresh Phase Status message. 
   
   NetKeyIndex : 2B : NetKey Index 
   Transition  : 1B : New Key Refresh Phase Transition */
  { OPCODE_CONFIG_KEY_REFRESH_PHASE_SET, 3, 3, aNoInitParamDefault },

  /* 4.3.2.67 Config Low Power Node PollTimeout Get, Opcode = 0x80 0x2D
     The Config Low Power Node PollTimeout Get is an acknowledged message used 
     to get the current value of PollTimeout timer of the Low Power node within 
     a Friend node (see Section 3.6.6.1). The message is sent to a Friend node 
    that has claimed to be handling messages by sending ACKs On Behalf Of (OBO) 
    the indicated Low Power node. This message should only be sent to a node 
    that has the Friend feature supported and enabled.
    The response to a Config Low Power Node PollTimeout Get message is a 
    Config Low Power Node PollTimeout Status message. 

    LPNAddress : 2B : The unicast address of the Low Power node */
  { OPCODE_CONFIG_LOW_POWER_NODE_POLLTIMEOUT_GET, 2, 2, aNoInitParamDefault },

  
  /* 4.3.3.12 Health Attention Get
     The Health Attention Get is an acknowledged message used to get the current
     Attention Timer state of an element (see Section 4.2.9).
     The response to a Health Attention Get message is an Attention Status message.
     There are no Parameters for this message.*/
  { OPCODE_HEALTH_ATTENTION_GET, 0, 0, aNoInitParamDefault }, 
  
  /* 4.3.3.13 Health Attention Set
     The Health Attention Set is an acknowledged message used to set the 
     Attention Timer state of an element (see Section 4.2.9).
     The response to a Health Attention Set message is a 
     Health Attention Status message 
    Attention: 1B: Value of the Attention Timer state*/
  { OPCODE_HEALTH_ATTENTION_SET, 1, 1, aNoInitParamDefault }, 
  
  /* 4.3.3.14 Health Attention Set Unacknowledged
     The Health Attention Set Unacknowledged is an unacknowledged message used 
     to set the Attention Timer state of an element (see Section 4.2.9). */
  { OPCODE_HEALTH_ATTENTION_SET_UNACKNOWLEDGED, 1, 1, aNoInitParamDefault }, 
  
  

  


  /* 4.3.2.15 Config Model Publication Get
     The Config Model Publication Get is an acknowledged message used to get the
     publish address and parameters of an outgoing message that originates 
     from a model.
     The response to a Config Model Publication Get message is a 
     Config Model Publication Status message.

     ElementAddress : 2B : Address of the element
     ModelIdentifier : 2 or 4B : SIG Model ID or Vendor Model ID
  */
  { OPCODE_CONFIG_MODEL_PUBLICATION_GET, 4, 6, aNoInitParamDefault },
  
  /* 4.3.2.17 Config Model Publication Virtual Address Set
     The Config Model Publication Virtual Address Set is an acknowledged message 
     used to set the model Publication state (see Section 4.2.2) of an 
     outgoing message that originates from a model.
     The response to a Config Model Publication Virtual Address Set message is 
        a Config Model Publication Status message.

      ElementAddress : 16b : Address of the element
      PublishAddress : 128b : Value of the Label UUID publish address
      AppKeyIndex : 12b : Index of the application key
      CredentialFlag : 1b : Value of the Friendship Credential Flag
      RFU : 3b : Reserved for Future Use
      PublishTTL : 8b : Default TTL value for the outgoing messages
      PublishPeriod : 8b : Period for periodic status publishing
      PublishRetransmitCount : 3b : Number of retransmissions for each published message
      PublishRetransmitIntervalSteps : 5b: Number of 50-millisecond steps between retransmissions
      ModelIdentifier: 16 or 32b: SIG Model ID or Vendor Model ID
  */
  { OPCODE_CONFIG_MODEL_PUBLICATION_VIRTUAL_ADDRESS_SET, 25, 27, aNoInitParamDefault },
  
  /* 4.3.2.19 Config Model Subscription Add
     The Config Model Subscription Add is an acknowledged message used to add an 
     address to a Subscription List of a model (see Section 4.2.3).

      The response to a Config Model Subscription Add message is a 
      Config Model Subscription Status message.

    ElementAddress  : 2B       : Address of the element
    address     : 2B           : Value of the address
    ModelIdentifier : 2B or 4B : SIG Model ID or Vendor Model ID
*/
  { OPCODE_CONFIG_MODEL_SUBSCRIPTION_ADD, 6, 8, aNoInitParamDefault },
  
  /* 4.3.2.21 Config Model Subscription Delete
     The Config Model Subscription Delete is an acknowledged message used to 
     delete a subscription address from the Subscription List of a model (see Section 4.2.3).
      The response to a Config Model Subscription Delete message is a 
      Config Model Subscription Status message.

    ElementAddress  : 2B       : Address of the element
    address     : 2B           : Value of the address
    ModelIdentifier : 2B or 4B : SIG Model ID or Vendor Model ID
  */
  { OPCODE_CONFIG_MODEL_SUBSCRIPTION_DELETE, 6, 8, aNoInitParamDefault },
  
  /* 4.3.2.25 Config Model Subscription Delete All
     The Config Model Subscription Delete All is an acknowledged message used to 
        discard the Subscription List of a model (see Section 4.2.3).
     The response to a Config Model Subscription Delete All message is a 
        Config Model Subscription Status message. 
    ElementAddress  : 2B       : Address of the element
    ModelIdentifier : 2B or 4B : SIG Model ID or Vendor Model ID */
  { OPCODE_CONFIG_MODEL_SUBSCRIPTION_DELETE_ALL, 4, 6, aNoInitParamDefault },

  /* 4.3.2.23 Config Model Subscription Overwrite
     The Config Model Subscription Overwrite is an acknowledged message used to 
     discard the Subscription List and add an address to the 
     cleared Subscription List of a model (see Section 4.2.3).
     
     The response to a Config Model Subscription Overwrite message is a 
     Config Model Subscription Status message. 

    ElementAddress  : 2B       : Address of the element
    address     : 2B           : Value of the address
    ModelIdentifier : 2B or 4B : SIG Model ID or Vendor Model ID */
  { OPCODE_CONFIG_MODEL_SUBSCRIPTION_OVERWRITE, 6, 8, aNoInitParamDefault },

  /* 4.3.2.20 Config Model Subscription Virtual Address Add
     The Config Model Subscription Virtual Address Add is an acknowledged message 
    used to add an address to a Subscription List of a model (see Section 4.2.3).
    The response to a Config Model Subscription Virtual Address Add message is a 
    Config Model Subscription Status message. 

    ElementAddress  : 2B       : Address of the element
    Label           : 16B      : Value of the Label UUID
    ModelIdentifier : 2B or 4B : SIG Model ID or Vendor Model ID */
  { OPCODE_CONFIG_MODEL_SUBSCRIPTION_VIRTUAL_ADDRESS_ADD, 20, 22, aNoInitParamDefault },
  
  /* 4.3.2.22 Config Model Subscription Virtual Address Delete
     The Config Model Subscription Virtual Address Delete is an acknowledged 
       message used to delete a subscription address from the 
       Subscription List of a model (see Section 4.2.3).
     The response to a Config Model Subscription Virtual Address Delete message 
     is a Config Model Subscription Status message. 
    ElementAddress  : 2B       : Address of the element
    Address         : 16B      : Value of the Label UUID
    ModelIdentifier : 2B or 4B : SIG Model ID or Vendor Model ID */
  { OPCODE_CONFIG_MODEL_SUBSCRIPTION_VIRTUAL_ADDRESS_DELETE, 20, 22, aNoInitParamDefault },
  
    /* 4.3.2.24 Config Model Subscription Virtual Address Overwrite
       The Config Model Subscription Virtual Address Overwrite is an acknowledged 
       message used to discard the Subscription List and add an address to the 
       cleared Subscription List of a model (see Section 4.2.3).
       The response to a Config Model Subscription Virtual Address Overwrite 
       message is a Config Model Subscription Status message. 
       Element Address  : 2B       : Address of the element
       Address          : 16B      : Value of the Label UUID
       ModelIdentifier  : 2B or 4B : SIG Model ID or Vendor Model ID */

  { OPCODE_CONFIG_MODEL_SUBSCRIPTION_VIRTUAL_ADDRESS_OVERWRITE, 20, 22, aNoInitParamDefault },
  
  /* 4.3.2.69 Config Network Transmit Get
     The Config Network Transmit Get is an acknowledged message used to get the 
     current Network Transmit state of a node (see Section 4.2.19).
     The response to a Config Network Transmit Get message is a Config Network 
        Transmit Status message.
    There are no Parameters for this message. */
  { OPCODE_CONFIG_NETWORK_TRANSMIT_GET, 0, 0, aNoInitParamDefault },     
  
  /* 4.3.2.70 Config Network Transmit Set
     The Config Network Transmit Set is an acknowledged message used to set the 
        Network Transmit state of a node (see Section 4.2.19).
     The response to a Config Network Transmit Set message is a Config Network 
        Transmit Status message.
     
     NetworkTransmitCount : 3b : Number of transmissions for each Network PDU originating from the node
     NetworkTransmitIntervalSteps : 5b : Number of 10-millisecond steps between transmissions 
  */
  { OPCODE_CONFIG_NETWORK_TRANSMIT_SET, 1, 1, aNoInitParamDefault }, 

  /* 4.3.2.12 Config Relay Get
     The Config Relay Get is an acknowledged message used to get the 
       current Relay (see Section 4.2.8) and Relay Retransmit (see Section 4.2.20) 
       states of a node.
     The response to a Config Relay Get message is a Config Relay Status message.
     There are no Parameters for this message.*/
  { OPCODE_CONFIG_RELAY_GET, 0, 0, aNoInitParamDefault },      
  
  /* 4.3.2.13 Config Relay Set
     The Config Relay Set is an acknowledged message used to set the Relay 
    (see Section 4.2.8) and Relay Retransmit (see Section 4.2.20) states of a node.
    The response to a Config Relay Set message is a Config Relay Status message. 
    Relay : 8 bits : Relay
    RelayRetransmitCount  : 3b : Number of retransmissions on advertising bearer for each Network PDU relayed by the node
    RelayRetransmitIntervalSteps : 5b : Number of 10-millisecond steps between retransmissions
  */
  { OPCODE_CONFIG_RELAY_SET, 2, 2, aNoInitParamDefault },      

  /* 4.3.2.27 Config SIG Model Subscription Get
     The Config SIG Model Subscription Get is an acknowledged message used to 
     get the list of subscription addresses of a model within the element. 
     This message is only for SIG Models.
     The response to a Config SIG Model Subscription Get message is a Config SIG 
     Model Subscription List message.
       Element Address  : 2B       : Address of the element
       ModelIdentifier  : 2B       : SIG Model ID  */

  { OPCODE_CONFIG_SIG_MODEL_SUBSCRIPTION_GET, 4, 4, aNoInitParamDefault },
  
  /* 4.3.2.29 Config Vendor Model Subscription Get
     The Config Vendor Model Subscription Get is an acknowledged message used to
     get the list of subscription addresses of a model within the element. 
     This message is only for Vendor Models.
     The response to a Config Vendor Model Subscription Get message is a 
     Config Vendor Model Subscription List message.
       Element Address  : 2B       : Address of the element
       ModelIdentifier  : 4B       : Vendor Model ID */

  { OPCODE_CONFIG_VENDOR_MODEL_SUBSCRIPTION_GET, 6, 6, aNoInitParamDefault },
  

  /* 4.3.3.4 Health Fault Clear
     The Health Fault Clear is an acknowledged message used to clear the current
       Registered Fault state identified by Company ID of an element 
       (see Section 4.2.15.2).
     The response to a Health Fault Clear message is a Health Fault Status message */
  { OPCODE_HEALTH_FAULT_CLEAR, 2, 2, aNoInitParamDefault },

       /* 4.3.3.3 Health Fault Clear Unacknowledged
      The Health Fault Clear Unacknowledged is an unacknowledged message used to
      clear the current Registered Fault state identified by Company ID of an 
      element (see Section 4.2.15.2).
      Company ID : 2B : 16-bit Bluetooth assigned Company Identifier */

   { OPCODE_HEALTH_FAULT_CLEAR_UNACKNOWLEDGED, 2, 2, aNoInitParamDefault },
  
  /* 4.3.3.2 Health Fault Get
     The Health Fault Get is an acknowledged message used to get the current 
     Registered Fault state identified by Company ID of an element 
     (see Section 4.2.15.2).
     The response to a Health Fault Get message is a Health Fault Status message
     Company ID : 2B : 16-bit Bluetooth assigned Company Identifier */
   { OPCODE_HEALTH_FAULT_GET, 2, 2, aNoInitParamDefault },
   
   /* 4.3.3.5 Health Fault Test
      The Health Fault Test is an acknowledged message used to invoke a 
      self-test procedure of an element. 
      The procedure is implementation specific and may result in changing the 
       Health Fault state of an element (see Section 4.2.15).
     The response to a Health Fault Test message is a Health Fault Status message.

     Test ID : 1B : Identifier of a specific test to be performed 
    Company ID : 2B : 16-bit Bluetooth assigned Company Identifier */
  { OPCODE_HEALTH_FAULT_TEST, 3, 3, aNoInitParamDefault },
   
  /* 4.3.3.6 Health Fault Test Unacknowledged
     The Health Fault Test Unacknowledged is an unacknowledged message used to 
     invoke a self-test procedure of an element. The procedure is implementation
     specific and may result in changing the Health Fault state of an element 
    (see Section 4.2.15). 

    Test ID : 1B : Identifier of a specific test to be performed 
    Company ID : 2B : 16-bit Bluetooth assigned Company Identifier */
  { OPCODE_HEALTH_FAULT_TEST_UNACKNOWLEDGED, 3, 3, aNoInitParamDefault },
  
  /* 4.3.3.8 Health Period Get
    The Health Period Get is an acknowledged message used to get the 
    current Health Fast Period Divisor state of an element (see Section 4.2.16).
    The response to a Health Period Get message is a Health Period Status message.
    There are no parameters for this message. */
  { OPCODE_HEALTH_PERIOD_GET, 0, 0, aNoInitParamDefault },
  
  /* 4.3.3.10 Health Period Set
    The Health Period Set is an acknowledged message used to set the current 
    Health Fast Period Divisor state of an element (see Section 4.2.16).
    The response to a Health Period Set message is a Health Period Status message
   
    FastPeriodDivisor : 1B: Divider for the Publish Period. 
               Modified Publish Period is used for sending Current */
  { OPCODE_HEALTH_PERIOD_SET, 1, 1, aNoInitParamDefault },
  
  /* 4.3.3.9 Health Period Set Unacknowledged
     The Health Period Set Unacknowledged is an unacknowledged message used to 
     set the current Health Fast Period Divisor state of an element 
    (see Section 4.2.16). 

   FastPeriodDivisor : 1B: Divider for the Publish Period. 
               Modified Publish Period is used for sending Current 
           Health Status messages when there are active faults to communicate */
  { OPCODE_HEALTH_PERIOD_SET_UNACKNOWLEDGED, 1, 1, aNoInitParamDefault },
   /* { OPCODE_HEALTH_PERIOD_STATUS              0x8037  */



  /* 4.3.2.46 Config Model App Bind
     The Config Model App Bind is an acknowledged message used to bind an 
      AppKey to a model.
    The response to a Config Model App Bind message is a 
      Config Model App Status message.

  ElementAddress : 2B : Address of the element
  AppKeyIndex : 2B : Index of the AppKey
  ModelIdentifier : 2 or 4: SIG Model ID or Vendor Model ID */

  { OPCODE_CONFIG_MODEL_APP_BIND, 6, 8, aNoInitParamDefault },
  
  /* 4.3.2.47 Config Model App Unbind
     The Config Model App Unbind is an acknowledged message used to remove the 
         binding between an AppKey and a model.
     The response to a Config Model App Unbind message is a Config Model App Status message. 


  ElementAddress : 2B : Address of the element
  AppKeyIndex : 2B : Index of the AppKey
  ModelIdentifier : 2 or 4: SIG Model ID or Vendor Model ID */
  { OPCODE_CONFIG_MODEL_APP_UNBIND, 6, 8, aNoInitParamDefault },
  
  /* 4.3.2.31 Config NetKey Add
    The Config NetKey Add is an acknowledged message used to add a NetKey 
       to a NetKey List (see Section 4.2.4) on a node. 
    The added NetKey is then used by the node to authenticate and decrypt messages it receives, as well as authenticate and encrypt messages it sends.
    The response to a Config NetKey Add message is a Config NetKey Status message.
    NetKeyIndex  : 2B
    NetKey       : 16B NetKey  */
  { OPCODE_CONFIG_NETKEY_ADD, 18, 18, aNoInitParamDefault },
  
  /* 4.3.2.33 Config NetKey Delete
     The Config NetKey Delete is an acknowledged message used to delete a NetKey 
     on a NetKey List from a node.
     The response to a Config NetKey Delete message is a 
        Config NetKey Status message. 
    NetKeyIndex  : 2B  */
  { OPCODE_CONFIG_NETKEY_DELETE, 2, 2, aNoInitParamDefault },

  /* 4.3.2.35 Config NetKey Get
     The Config NetKey Get is an acknowledged message used to report all NetKeys
     known to the node.
    The response to a Config NetKey Get message is a Config NetKey List message.
    There are no Parameters for this message. */
  { OPCODE_CONFIG_NETKEY_GET, 0, 0, aNoInitParamDefault },

  /* 4.3.2.32 Config NetKey Update
     The Config NetKey Update is an acknowledged message used to update a NetKey 
     on a node. The updated NetKey is then used by the node to authenticate and 
     decrypt messages it receives, as well as authenticate and encrypt messages 
     it sends, as defined by the Key Refresh procedure (see Section 3.10.4).
     The response to a Config NetKey Update message is a Config NetKey Status message. 
    NetKeyIndex  : 2B  : Index of the NetKey
    NetKey       : 16B : NetKey  */
  { OPCODE_CONFIG_NETKEY_UPDATE, 18, 18, aNoInitParamDefault},
  
  /* 4.3.2.43 Config Node Identity Get
     The Config Node Identity Get is an acknowledged message used to get the 
           current Node Identity state for a subnet (see Section 4.2.12).
       The response to a Config Node Identity Get message is a 
            Config Node Identity Status message. 

    NetKeyIndex  : 2B : Index of the NetKey */
  { OPCODE_CONFIG_NODE_IDENTITY_GET, 2, 2, aNoInitParamDefault},
  
  /* 4.3.2.44 Config Node Identity Set
    The Config Node Identity Set is an acknowledged message used to set the 
        current Node Identity state for a subnet (see Section 4.2.12).
     The response to a Config Node Identity Set message is a 
         Config Node Identity Status message. 

    NetKeyIndex : 2B : Index of the NetKey
    Identity    : 1B : New Node Identity state */
  { OPCODE_CONFIG_NODE_IDENTITY_SET, 3, 3, aNoInitParamDefault},

  /* 4.3.2.53 Config Node Reset
     The Config Node Reset is an acknowledged message used to reset a node 
       (other than a Provisioner) and remove it from the network.
     The response to a Config Node Reset message is a Config Node Reset 
          Status message.
     There are no Parameters for this message.  */
  { OPCODE_CONFIG_NODE_RESET, 0, 0, aNoInitParamDefault },
  
  /* 4.3.2.49 Config SIG Model App Get
     The Config SIG Model App Get is an acknowledged message used to request 
       report of all AppKeys bound to the SIG Model.
     The response to a Config SIG Model App Get message is a Config SIG Model 
     App List message. 

     ElementAddress  : 2B : Address of the element
     ModelIdentifier : 2B : SIG Model ID */
  { OPCODE_CONFIG_SIG_MODEL_APP_GET, 4, 4, aNoInitParamDefault },

  /* 4.3.2.51 Config Vendor Model App Get
     The Config Vendor Model App Get is an acknowledged message used to request 
     report of all AppKeys bound to the model. This message is only for Vendor Models.
     The response to a Config Vendor Model App Get message is a Config Vendor Model App List message 

     ElementAddress  : 2B : Address of the element
     ModelIdentifier : 4B : Vendor Model ID */ 
  { OPCODE_CONFIG_VENDOR_MODEL_APP_GET, 6, 6, aNoInitParamDefault },

};
/* Private variables ---------------------------------------------------------*/

eClientSendMsgState_t eClientSendMsgState; /* Keeps the state of Sent Message */
eServerRespRecdState_t eServerRespRecdState; /* Keeps the state of Received Message */

/* Private function prototypes -----------------------------------------------*/
MOBLEUINT8 AppliConfigClient_SendMessageDefault(MOBLEUINT8 elementIdx);

/* Private functions ---------------------------------------------------------*/

/**
* @brief  This function is callback from library after the Provisioning is 
          completed by embedded Provisioner
* @param  prvState: Provisioning State of the Node. Expecting "1" when the
                   provisioning is completed
* @retval None
*/ 
void Appli_ConfigClientStartNodeConfiguration(MOBLEUINT8 prvState)
{
  if (prvState==1 )
  {
    Appli_ConfigClient_Init();
    eClientSendMsgState = ProvisioningDone_State;
    NodeInfo.nodePrimaryAddress = GetAddressToConfigure();
  }
}


/**
* @brief  This function is Init function for the state machine of the 
          Configuration Client. The Function shall be called everytime a new 
          node is provisioned 
* @param  None
* @retval None
*/ 
MOBLE_RESULT Appli_ConfigClient_Init(void) 
{
  eClientSendMsgState = ClientIdle_State; /* Init the value of state machine  */ 
  eServerRespRecdState = NodeIdle_State;  /* Init the value of state machine  */
  ConfigClient_ResetTrials();
  
  return MOBLE_RESULT_SUCCESS;
}


/**
* @brief  Appli_ConfigClient_Process: This function is Process function and 
          shall be called from while(1) loop 
* @param  None
* @retval MOBLE_RESULT
*/ 
MOBLE_RESULT Appli_ConfigClient_Process(void) 
{
    
  Appli_ConfigClient_ConfigureNode();
  
  return MOBLE_RESULT_SUCCESS;
}


/**
* @brief  This function is used to configure the Node after provisioning
* @param  None
* @retval MOBLE_RESULT
*/ 
MOBLE_RESULT Appli_ConfigClient_ConfigureNode(void) 
{
  MOBLE_RESULT result = MOBLE_RESULT_SUCCESS;
  MOBLEUINT32 nowClockTime;
    
    /* 
    State                  response                   called function
    --------------------------------------------------------------------------------
    ClientIdle_State       X                               None
    ProvisioningDone_State X                               Start the configuration
    CompositionGet_State   ConfigRespInit_State       GetComposition
    CompositionGet_State   CompositionRecd_State      ChangeThe State to next 
    AppKeyAdd_State        X                          Issue AppKey
    AppKeyAdd_State        AppkeyAck_State            ChangeThe State to next 
    AppBindModel_State     X                          Issue AppKetBind
    AppBindModel_State     AppBindModelAck_State      ChangeThe State to next 
    AddSubscription_State  X                          Issue the Subscription 
    AddSubscription_State  SubscriptionAck_State      ChangeThe State to next 
    SetPublication_State   PublicationStatus_State    Issue the Subscription 
    SetPublication_State   PublicationStatus_State    ChangeThe State to next 

  */

  /* If the Node is already configured, return from here  */
  if (eClientSendMsgState == ConfigurationDone_State) 
    return result;
  
  if (eClientSendMsgState == ClientIdle_State) 
  {
    /* Waiting for the Provisioning to be done before to Start the 
       node configuration procedure */
      return result;
  }
  
  if (eServerRespRecdState == NodeNoResponse_State) 
  {
    /* No Response received from Node under Provisioning for some config 
       messages. So, no need to do the trials  */
      return MOBLE_RESULT_FAIL;
  }
  
  if (eClientSendMsgState == ProvisioningDone_State) 
  {
    /* Start the node configuration procedure */
    eClientSendMsgState = CompositionGet_State;
    ConfigClient_SaveMsgSendingTime();
  }
  
  else if (eClientSendMsgState == CompositionGet_State)
  {
     nowClockTime = Clock_Time();
     if( (nowClockTime - NodeInfo.Initial_time) < CONFIGURATION_START_DELAY)
     {
       return result;
     }
     /*------------- Add the delay before to start the configuration messages */
    
    if (eServerRespRecdState == CompositionRecdCompleted_State)
    {
      eClientSendMsgState = AppKeyAdd_State;  /* Change the state to Next */
      eServerRespRecdState = NodeIdle_State;
    }
    else 
    {
      /* Continue the GetComposition servicing */
      Appli_ConfigClient_GetCompositionData();
    }
  }
  
  else if (eClientSendMsgState == AppKeyAdd_State)
  {
    if (eServerRespRecdState == AppkeyAckCompleted_State)
    {
      eClientSendMsgState = AppBindModel_State;  /* Change the send state */
      eServerRespRecdState = NodeIdle_State;
    }
    else
    {
      /* Continue the AppKeyAdd servicing */
    Appli_ConfigClient_DefaultAppKeyAdd();
  }
  }  
  
  else if (eClientSendMsgState == AppBindModel_State)
  {
    if (eServerRespRecdState == AppBindModelAckCompleted_State)
    {
      eClientSendMsgState = AddSubscription_State;  /* Change the send state */
      eServerRespRecdState = NodeIdle_State;
    }
    else
    {
       /* Continue the AppKeyBIND servicing */
    Appli_ConfigClient_DefaultAppKeyBind();
  }
  }
  
  else if (eClientSendMsgState == AddSubscription_State)
  {
    if (eServerRespRecdState == SubscriptionAckCompleted_State)
    {
      eClientSendMsgState = SetPublication_State;  /* Change the send state */
      eServerRespRecdState = NodeIdle_State;
    }
    else 
    {
      /* Continue the Subscription add servicing */
    AppliConfigClient_SubscriptionAddDefault();
    }    
  }

  else if (eClientSendMsgState == SetPublication_State)
  {
    if (eServerRespRecdState == PublicationStatusCompleted_State)
    {
      eClientSendMsgState = ConfigurationDone_State;  /* Change the send state */
      eServerRespRecdState = NodeIdle_State;
      TRACE_M(TF_CONFIG_CLIENT,"**Node is configured** \r\n");  
    }
    else 
    {
      /* Continue the Publication add servicing */
    AppliConfigClient_PublicationSetDefault();
    }
  }
  
  return result;
}


/**
* @brief  This function is called to Get the Composition data from the 
*         a node under configuration
* @param  None
* @retval MOBLE_RESULT
*/ 
MOBLE_RESULT Appli_ConfigClient_GetCompositionData (void)
{
    MOBLE_RESULT result = MOBLE_RESULT_SUCCESS;
    MOBLEUINT8 retry;
    MOBLEUINT16 dst_peer;
    
    switch(eServerRespRecdState)
    {
    case NodeIdle_State:

      ConfigClient_SaveMsgSendingTime();
      
      dst_peer = GetAddressToConfigure(); 
      
      /* Start the Get Composition Message */
      ConfigClient_CompositionDataGet(dst_peer);
      
      /* Switch to InProgress_State */
      eServerRespRecdState = InProgress_State;
      break;

    case CompositionRecd_State:
      /* Switch the state to next state AddAppKey_State */
      ConfigClient_ResetTrials();
      eServerRespRecdState = CompositionRecdCompleted_State;
      break;
      
    case InProgress_State:
      /* Just wait and let the messages be completed 
         or look for timeout */

      retry = ConfigClient_ChkRetries();
      
      if (retry == CLIENT_TX_RETRY_ENDS)
      {
        eServerRespRecdState = NodeNoResponse_State;
      }
      else if (retry == CLIENT_TX_TIMEOUT)
      {
        eServerRespRecdState = NodeIdle_State; /* Run next re-trial cycle again */
      }
      
      break;
      
    default:
      /* Error State */
      break;
    }
    
  return result;
}


/**
* @brief  Appli_ConfigClient_DefaultAppKeyAdd: This function is called to 
          add the default AppKeys and NetKeys to a node under configuration
* @param  None
* @retval MOBLE_RESULT
*/ 
MOBLE_RESULT Appli_ConfigClient_DefaultAppKeyAdd (void)
{
   MOBLE_RESULT result = MOBLE_RESULT_SUCCESS;
  MOBLEUINT8 retry; 
   MOBLEUINT8 *pAppKey;  
   MOBLEUINT16 netKeyIndex = DEFAULT_NETKEY_INDEX;
   MOBLEUINT16 appKeyIndex = DEFAULT_APPKEY_INDEX;
  MOBLE_ADDRESS dst_addr;

   pAppKey = GetNewProvNodeAppKey();
   
    switch(eServerRespRecdState)
    {
    case NodeIdle_State:
      ConfigClient_SaveMsgSendingTime();
      
      dst_addr = GetAddressToConfigure(); 
      
      /* Start the Set Appkey message  */
      ConfigClient_AppKeyAdd ( dst_addr,
                               netKeyIndex, 
                                  appKeyIndex,
                                  pAppKey);
      
      /* Switch to InProgress_State */
      eServerRespRecdState = InProgress_State; 
      break;

    case AppkeyAck_State:
      ConfigClient_ResetTrials();
      eServerRespRecdState = AppkeyAckCompleted_State;
      break;
      
    case InProgress_State:
      /* Just wait and let the messages be completed 
         or look for timeout */

      retry = ConfigClient_ChkRetries();
      
      if (retry == CLIENT_TX_RETRY_ENDS)
      {
        eServerRespRecdState = NodeNoResponse_State;
      }
      else if (retry == CLIENT_TX_TIMEOUT)
      {
        eServerRespRecdState = NodeIdle_State; /* Run next re-trial cycle again */
      }

      break;

    default:
      /* Error State */
      break;
}

  return result;
}


/**
* @brief  Appli_ConfigClient_DefaultAppKeyBind: This function is application used for 
          function to Bind the element(node) with AppKeyIndex and Models
* @param  None
* @retval MOBLE_RESULT
*/ 
MOBLE_RESULT Appli_ConfigClient_DefaultAppKeyBind (void)
{
   static MOBLEUINT32 modelIdentifier;
   static MOBLEUINT8 elementIndex;
   static MOBLEUINT8  indexSIGmodels;
   static MOBLEUINT8  indexVendormodels;
   MOBLEUINT16 elementAddress;
   MOBLEUINT16 appKeyIndex = DEFAULT_APPKEY_INDEX;

   MOBLEUINT8  numSIGmodels;
   MOBLEUINT8  numVendorModels;
   MOBLEUINT8  numofElements;        
   MOBLE_RESULT result = MOBLE_RESULT_SUCCESS;
   MOBLEUINT8 retry;  
  
    switch(eServerRespRecdState)
    {
    case NodeIdle_State:
      /* Start the AppBindModel_State message  */
        elementIndex = 0; /* Initialize it for the complete loop */
        indexSIGmodels = 0; /* Initialize it for the complete loop */
        indexVendormodels = 0;

    case NodeNextSigModel_State:
        numSIGmodels = GetCountSIGModelToBindApp(elementIndex);
        modelIdentifier = GetSIGModelToBindApp(elementIndex,
                                               &indexSIGmodels, 
                                               numSIGmodels);
        
        /* Switch to NodeSendMessage_State */
        eServerRespRecdState = NodeSendMessage_State;
      break;

    case NodeNextVendorModel_State:
        modelIdentifier = GetVendorModelToBindApp(elementIndex,indexVendormodels );
      /* Switch to NodeSendMessage_State */
        eServerRespRecdState = NodeSendMessage_State;
      break;
      
     case NodeSendMessage_State:
      /* Start the AppBindModel_State message  */
        elementAddress = GetServerElementAddress(elementIndex);

        /* Switch to InProgress_State */
        eServerRespRecdState = InProgress_State;

        ConfigClient_SaveMsgSendingTime();
        
        /* Send the Message to the server */
        ConfigClient_ModelAppBind (elementAddress, appKeyIndex, modelIdentifier);
      break;

    case AppBindModelAck_State:
       /* Need to check if all SIG Models are binded ? */

      ConfigClient_ResetTrials();
            
      numSIGmodels = GetCountSIGModelToBindApp(elementIndex);
      numVendorModels = GetCountVendorModelToBindApp(elementIndex);
      
      if (indexSIGmodels < numSIGmodels )
      { /* Even when all SIG Models are serviced, we need to start for Vendor Models */
        indexSIGmodels++; 
        indexVendormodels =0;  /* Reset back, bcoz, we are still process the SIG Models */
      }
      else if (indexVendormodels < numVendorModels)
      {
        indexVendormodels++; /* When SIG Models and Vendor Models are processed
                                the loop condition will become true */
      }
      
      if (indexSIGmodels < numSIGmodels )
      {/* if index is still less, then we have scope of reading 1 more index */
       
        eServerRespRecdState = NodeNextSigModel_State;
        /* Switch to InProgress_State */
      }
      else if (indexVendormodels < numVendorModels)
      {
        /*Now, do binding for Vendor Model */
        eServerRespRecdState = NodeNextVendorModel_State;
      }
      else
      {
        /* Now, the element index is handled, change the element index */
        elementIndex++;
        numofElements = ConfigClient_GetNodeElements();  
        if (elementIndex >=  numofElements)
        {/* we are comparing Index whose counting started from 0, becomes equal, 
            then exit the loop */
          
           eServerRespRecdState = AppBindModelAckCompleted_State; 
        }
        else if (elementIndex < numofElements)
        { /* When the Element Index is still less than the total number of 
             elements in the Node: So, Restart the cycle */
          indexSIGmodels = 0; /* Initialize it for the complete loop */
          indexVendormodels = 0;
        
          eServerRespRecdState = NodeNextSigModel_State; 
      }
      }
      break;
      
    case InProgress_State:
      /* Just wait and let the messages be completed 
         or look for timeout */
      retry = ConfigClient_ChkRetries();
      
      if (retry == CLIENT_TX_RETRY_ENDS)
      {
        eServerRespRecdState = NodeNoResponse_State;
      }
      else if (retry == CLIENT_TX_TIMEOUT)
      {
        eServerRespRecdState = NodeSendMessage_State; /* Run next re-trial cycle again */;
      }
      break;
     
    default:
      /* Error State */
      break;
    }
    
  return result;
}


/**
* @brief  AppliConfigClient_SubscriptionAddDefault: This function is application
          used for adding subscription to the element(node) for default settings
* @param  None
* @retval MOBLE_RESULT
*/ 
MOBLE_RESULT AppliConfigClient_SubscriptionAddDefault (void) 
{
   static MOBLEUINT32 modelIdentifier;
   static MOBLEUINT16 elementAddress;
   static MOBLEUINT8 elementIndex;
   static MOBLEUINT8  indexSIGmodels;
   static MOBLEUINT8  indexVendormodels;
   MOBLEUINT8  numSIGmodels;
   MOBLEUINT8  numVendorModels;
   MOBLEUINT8  numofElements;        
   MOBLEUINT16 address = DEFAULT_GROUP_ADDR;
   MOBLE_RESULT result = MOBLE_RESULT_SUCCESS;
   MOBLEUINT8 retry; 
      
    switch(eServerRespRecdState)
    {
    case NodeIdle_State:
      /* Start the SubscriptionAdd message  */

        elementIndex = 0; /* Initialize it for the complete loop */
        indexSIGmodels = 0; /* Initialize it for the complete loop */
        indexVendormodels = 0;

    case NodeNextSigModel_State:
        numSIGmodels = GetCountSIGModelToSubscribe(elementIndex);
        modelIdentifier = GetSIGModelToSubscribe(elementIndex,
                                               &indexSIGmodels, 
                                               numSIGmodels);

        /* Switch to NodeSendMessage_State */
        eServerRespRecdState = NodeSendMessage_State;
      break;

    case NodeNextVendorModel_State:
        modelIdentifier = GetVendorModelToSubscribe(elementIndex,indexVendormodels );
      /* Switch to NodeSendMessage_State */
        eServerRespRecdState = NodeSendMessage_State;
      break;
      
    case NodeSendMessage_State:
        elementAddress = GetServerElementAddress(elementIndex);
        ConfigClient_SaveMsgSendingTime();

         /* Switch to InProgress_State */
        eServerRespRecdState = InProgress_State;        
        ConfigClient_SubscriptionAdd (elementAddress, address, modelIdentifier);
      
      break;

       
    case SubscriptionAck_State:
       /* Need to check if all SIG Models are subscribed ? */
      ConfigClient_ResetTrials();

      numSIGmodels = GetCountSIGModelToSubscribe(elementIndex);
      numVendorModels = GetCountVendorModelToSubscribe(elementIndex);
      elementAddress = GetServerElementAddress(elementIndex);
      
      if (indexSIGmodels < numSIGmodels )
      { /* Even when all SIG Models are serviced, we need to start for Vendor Models */
        indexSIGmodels++; 
        indexVendormodels =0;  /* Reset back, bcoz, we are still process the SIG Models */
      }
      else if (indexVendormodels < numVendorModels)
      {
        indexVendormodels++; /* When SIG Models and Vendor Models are processed
                                the loop condition will become true */
      }
      
      if (indexSIGmodels < numSIGmodels )
      {/* if index is still less, then we have scope of reading 1 more index */
       
        /* Get the Next Model and Bind it again till all SIG Models are binded */
        eServerRespRecdState = NodeNextSigModel_State;
        
      }
      else if (indexVendormodels < numVendorModels)
{
        eServerRespRecdState = NodeNextVendorModel_State;
      }
      else
      {
        /* Now, the element index is handled, change the element index */
        elementIndex++;
        numofElements = ConfigClient_GetNodeElements();  
        if (elementIndex ==  numofElements)
        {/* we are comparing Index whose counting started from 0, becomes equal, 
            then exit the loop */
           eServerRespRecdState = SubscriptionAckCompleted_State; 
        }
        else if (elementIndex < numofElements)
        { /* When the Element Index is still less than the total number of 
             elements in the Node: So, Restart the cycle */
        
          eServerRespRecdState = NodeNextSigModel_State; 
          indexSIGmodels =0; /* Reset the variable again for the next element */
        indexVendormodels = 0;
      }
      }
      break;
      
    case InProgress_State:
      /* Just wait and let the messages be completed 
         or look for timeout */
      retry = ConfigClient_ChkRetries();
      
      if (retry == CLIENT_TX_RETRY_ENDS)
      {
        eServerRespRecdState = NodeNoResponse_State;
      }
      else if (retry == CLIENT_TX_TIMEOUT)
      {
        eServerRespRecdState = NodeSendMessage_State; /* Run next re-trial cycle again */;
      }
      break;
      
    default:
      /* Error State */
      break;
    }
    
  return result;
}


/**
* @brief  AppliConfigClient_PublicationSetDefault: This function is application
          used for adding publication settings to the element(node) 
          for default settings
* @param  None
* @retval MOBLE_RESULT
*/ 
MOBLE_RESULT AppliConfigClient_PublicationSetDefault (void) 
{
  MOBLEUINT16 publishAddress = DEFAULT_PUBLISH_ADDR;
  MOBLEUINT16 appKeyIndex = DEFAULT_APPKEY_INDEX;
  MOBLEUINT8 credentialFlag = DEFAULT_CREDENTIAL_FLAG;
  MOBLEUINT8 publishTTL = DEFAULT_PUBLISH_TTL;
  MOBLEUINT8 publishPeriod = DEFAULT_PUBLISH_PERIOD;
  MOBLEUINT8 publishRetransmitCount = DEFAULT_PUBLISH_RETRANSMIT_COUNT;
  MOBLEUINT8 publishRetransmitIntervalSteps= DEFAULT_PUBLISH_RETRANSMIT_INTERVAL_STEPS;
  
   static MOBLEUINT16 elementAddress;
   static MOBLEUINT32 modelIdentifier;
   static MOBLEUINT8 elementIndex;
   static MOBLEUINT8  indexSIGmodels;
   static MOBLEUINT8  indexVendormodels;
   MOBLEUINT8  numSIGmodels;
   MOBLEUINT8  numVendorModels;
   MOBLEUINT8  numofElements;        
   MOBLE_RESULT result = MOBLE_RESULT_SUCCESS;
   MOBLEUINT8 retry; 
      
    switch(eServerRespRecdState)
    {
    case NodeIdle_State:
      /* Start the Publication Add message  */

        elementIndex = 0; /* Initialize it for the complete loop */
        indexSIGmodels = 0; /* Initialize it for the complete loop */
        indexVendormodels = 0;

    case NodeNextSigModel_State:
        numSIGmodels = GetCountSIGModelToPublish(elementIndex);
        modelIdentifier = GetSIGModelToPublish(elementIndex,
                                               &indexSIGmodels, 
                                               numSIGmodels);
        
         /* Switch to NodeSendMessage_State */
        eServerRespRecdState = NodeSendMessage_State;        
      break;
        
    case NodeNextVendorModel_State:
        modelIdentifier = GetVendorModelToPublish(elementIndex,indexVendormodels);
      /* Switch to NodeSendMessage_State */
        eServerRespRecdState = NodeSendMessage_State;
      break;

      
    case NodeSendMessage_State:
        elementAddress = GetServerElementAddress(elementIndex);

        ConfigClient_SaveMsgSendingTime();

         /* Switch to InProgress_State */
        eServerRespRecdState = InProgress_State;        
        ConfigClient_PublicationSet(elementAddress,
                              publishAddress,
                              appKeyIndex,
                              credentialFlag,
                              publishTTL,
                              publishPeriod,
                              publishRetransmitCount,
                              publishRetransmitIntervalSteps,
                              modelIdentifier);

      break;

      
    case PublicationStatus_State:
       /* Need to check if all SIG Models are subscribed ? */
      ConfigClient_ResetTrials();

      numSIGmodels = GetCountSIGModelToPublish(elementIndex);
      numVendorModels = GetCountVendorModelToPublish(elementIndex);
      elementAddress = GetServerElementAddress(elementIndex);
      
      if (indexSIGmodels < numSIGmodels )
      { /* Even when all SIG Models are serviced, we need to start for Vendor Models */
        indexSIGmodels++; 
        indexVendormodels =0;  /* Reset back, bcoz, we are still process the SIG Models */
      }
      else if (indexVendormodels < numVendorModels)
      {
        indexVendormodels++; /* When SIG Models and Vendor Models are processed
                                the loop condition will become true */
      }

      
      if (indexSIGmodels < numSIGmodels )
      {/* if index is still less, then we have scope of reading 1 more index */
        eServerRespRecdState = NodeNextSigModel_State;        
      }
      else if (indexVendormodels < numVendorModels)
      {
        eServerRespRecdState = NodeNextVendorModel_State;        
      }
      else
      {
        /* Now, the element index is handled, change the element index */
        elementIndex++;
        numofElements = ConfigClient_GetNodeElements();  

        if (elementIndex ==  numofElements)
        {/* we are comparing Index whose counting started from 0, becomes equal, 
            then exit the loop */
           eServerRespRecdState = PublicationStatusCompleted_State; 
        }
        else if (elementIndex < numofElements)
        { /* When the Element Index is still less than the total number of 
             elements in the Node: So, Restart the cycle */
        
          eServerRespRecdState = NodeNextSigModel_State; 
          indexSIGmodels =0; /* Reset the variable again for the next element */
        indexVendormodels = 0;
      }
      }
      break;
      
    case InProgress_State:
      /* Just wait and let the messages be completed 
         or look for timeout */
      retry = ConfigClient_ChkRetries();
      
      if (retry == CLIENT_TX_RETRY_ENDS)
      {
        eServerRespRecdState = NodeNoResponse_State;
      }
      else if (retry == CLIENT_TX_TIMEOUT)
      {
        eServerRespRecdState = NodeSendMessage_State; /* Run next re-trial cycle again */;
      }
      break;
      
    default:
      /* Error State */
      break;
    }

  return result;
}


/**
* @brief  AppliConfigClient_SelfPublicationSetDefault: This function is application
          used for adding publication settings to the element(node) 
          for default settings
* @param  None
* @retval MOBLE_RESULT
*/ 
MOBLE_RESULT AppliConfigClient_SelfPublicationSetDefault (void) 
{
  MOBLEUINT16 publishAddress = DEFAULT_PUBLISH_ADDR;
  MOBLEUINT16 appKeyIndex = DEFAULT_APPKEY_INDEX;
  MOBLEUINT8 credentialFlag = DEFAULT_CREDENTIAL_FLAG;
  MOBLEUINT8 publishTTL = DEFAULT_PUBLISH_TTL;
  MOBLEUINT8 publishPeriod = DEFAULT_PUBLISH_PERIOD;
  MOBLEUINT8 publishRetransmitCount = DEFAULT_PUBLISH_RETRANSMIT_COUNT;
  MOBLEUINT8 publishRetransmitIntervalSteps= DEFAULT_PUBLISH_RETRANSMIT_INTERVAL_STEPS;
 
  MOBLEUINT16 elementAddress;
  MOBLEUINT32 modelIdentifier=0;
  MOBLEUINT8  elementIndex;
  MOBLE_RESULT result = MOBLE_RESULT_SUCCESS;
  
  for (elementIndex=0; elementIndex < APPLICATION_NUMBER_OF_ELEMENTS; elementIndex++ )
  { 
    /*Checking for SIG Models*/
    for (MOBLEUINT8 index=0; index < APPLICATION_SIG_MODELS_MAX_COUNT;  index++)
    {
      elementAddress = BLEMesh_GetAddress();
      elementAddress += elementIndex;

      modelIdentifier = (MOBLEUINT16) Appli_SIG_Models[elementIndex][index]; 
  
      if(modelIdentifier == NO_MODEL_AVLBL)
      {
        break;
      }
      else if (MODEL_IS_FOUNDATION_MODEL(modelIdentifier)) 
      {
        /* If Model is Foundation Model, then it doesnt need to be 
            added for Publishing */  
        
        /* Do NOTHING, let the next Model be picked */
      }

      else
      {
        ConfigClient_PublicationSet(elementAddress,
                                    publishAddress,
                                    appKeyIndex,
                                    credentialFlag,
                                    publishTTL,
                                    publishPeriod,
                                    publishRetransmitCount,
                                    publishRetransmitIntervalSteps,
                                    modelIdentifier);
      }
    }
    
    /*Checking for VENDOR Models*/
    for (MOBLEUINT8 index=0; index < APPLICATION_VENDOR_MODELS_MAX_COUNT;  index++)
  {
      elementAddress = BLEMesh_GetAddress();
      elementAddress += elementIndex;

      modelIdentifier = (MOBLEUINT32) Appli_Vendor_Models[elementIndex][index]; 
    
      if(modelIdentifier == NO_MODEL_AVLBL)
      {
        break;
      }
      else
      {
    ConfigClient_PublicationSet(elementAddress,
                                publishAddress,
                                appKeyIndex,
                                credentialFlag,
                                publishTTL,
                                publishPeriod,
                                publishRetransmitCount,
                                publishRetransmitIntervalSteps,
                                modelIdentifier);
  }
    }
  }
  return result;
}


/**
* @brief  AppliConfigClient_SelfSubscriptionSetDefault: This function is application
          used for adding Subscription settings to the element(node) 
          for default settings
* @param  None
* @retval MOBLE_RESULT
*/ 
MOBLE_RESULT AppliConfigClient_SelfSubscriptionSetDefault (void) 
{
  MOBLEUINT32 modelIdentifier=0;
  MOBLEUINT16 elementAddress;
  MOBLEUINT8  elementIndex;
  MOBLEUINT16 address = DEFAULT_GROUP_ADDR;
  MOBLE_RESULT result = MOBLE_RESULT_SUCCESS;
  
  for (elementIndex=0; elementIndex < APPLICATION_NUMBER_OF_ELEMENTS; elementIndex++ )
  {
    /*Checking for SIG Models*/
    for (MOBLEUINT8 index=0; index < APPLICATION_SIG_MODELS_MAX_COUNT;  index++)
    {
      elementAddress = BLEMesh_GetAddress();
      elementAddress += elementIndex;

      modelIdentifier = (MOBLEUINT16) Appli_SIG_Models[elementIndex][index]; 
      
      /*If limit is reaching to no models*/
      if(modelIdentifier == NO_MODEL_AVLBL)
      {
        break;
      }
      else if (MODEL_IS_FOUNDATION_MODEL(modelIdentifier)) 
      {
        /* If Model is Foundation Model, then it doesnt need to be 
            Subscribed */  
        
        /* Do NOTHING, let the next Model be picked */
      }
      else
      {
        ConfigClient_SubscriptionAdd (elementAddress, address, modelIdentifier);
      }
    }
  
    /*Checking for Vendor Models*/
    for (MOBLEUINT8 index=0; index < APPLICATION_VENDOR_MODELS_MAX_COUNT;  index++)
  {
      elementAddress = BLEMesh_GetAddress();
      elementAddress += elementIndex;
    
      modelIdentifier = (MOBLEUINT32) Appli_Vendor_Models[elementIndex][index]; 
      if(modelIdentifier == NO_MODEL_AVLBL)
      {
        break;
      }
      else
      {
    ConfigClient_SubscriptionAdd (elementAddress, address, modelIdentifier);
  }
    }
  
  }
  return result; 
}


/**
* @brief  Appli_ConfigClient_DefaultAppKeyBind: This function is application used for 
          function to Bind the element(node) with AppKeyIndex and Models
* @param  None
* @retval MOBLE_RESULT
*/ 
MOBLE_RESULT Appli_ConfigClient_SelfDefaultAppKeyBind (void)
{
  
  MOBLEUINT32 modelIdentifier=0;
  MOBLEUINT16 appKeyIndex = DEFAULT_APPKEY_INDEX;
  MOBLEUINT16 elementAddress;
  MOBLEUINT8  elementIndex;
  MOBLE_RESULT result = MOBLE_RESULT_SUCCESS;
  appKeyIndex = DEFAULT_APPKEY_INDEX;
  
  for (elementIndex=0; elementIndex < APPLICATION_NUMBER_OF_ELEMENTS; elementIndex++ )
  {
    /*Checking for SIG Models*/
    for (MOBLEUINT8 index=0; index < APPLICATION_SIG_MODELS_MAX_COUNT;  index++)
    {
      elementAddress = BLEMesh_GetAddress();
      elementAddress += elementIndex;
      
      modelIdentifier = (MOBLEUINT16) Appli_SIG_Models[elementIndex][index];  
 
      if(modelIdentifier == NO_MODEL_AVLBL)
      {
        break;
      }
      else if (MODEL_IS_FOUNDATION_MODEL(modelIdentifier)) 
      {
        /* If Model is Foundation Model, then it doesnt need to be binded 
           with AppKey */  
        
        /* Do NOTHING, let the next Model be picked */
      }
      else
  {
        ConfigClient_ModelAppBind (elementAddress, appKeyIndex, modelIdentifier);
      }
    }
  
    /*Checking for VENDOR Models*/
    for (MOBLEUINT8 index=0; index < APPLICATION_VENDOR_MODELS_MAX_COUNT;  index++)
  {
      elementAddress = BLEMesh_GetAddress();
      elementAddress += elementIndex;
      
      modelIdentifier = (MOBLEUINT32) Appli_Vendor_Models[elementIndex][index]; 
      
      if(modelIdentifier == NO_MODEL_AVLBL)
      {
        break;
      }
      else
      {
    ConfigClient_ModelAppBind (elementAddress, appKeyIndex, modelIdentifier);
  }      
  }
    
  }
  return result;
}

/**
* @brief  Appli_CompositionDataStatusCb: This function is callback from config 
         client middleware on reception of the response
* @param  None
* @retval MOBLE_RESULT
*/ 
void Appli_CompositionDataStatusCb(MOBLE_RESULT status)
{
   eServerRespRecdState = CompositionRecd_State;
}


/**
* @brief  Appli_AppKeyStatusCb: This function is callback from config 
         client middleware on reception of the response
* @param  None
* @retval MOBLE_RESULT
*/ 
void Appli_AppKeyStatusCb(MOBLEUINT8 status)
{
   /* Change the received state for application  */
   eServerRespRecdState = AppkeyAck_State;
}


/**
* @brief  Appli_AppBindModelStatusCb: This function is callback from config 
         client middleware on reception of the response
* @param  None
* @retval MOBLE_RESULT
*/ 
void Appli_AppBindModelStatusCb(MOBLEUINT8 status)
{
   /* Change the received state for application  */
   eServerRespRecdState = AppBindModelAck_State;
}


/**
* @brief  Appli_SubscriptionAddStatusCb: This function is callback from config 
         client middleware on reception of the response
* @param  None
* @retval MOBLE_RESULT
*/ 
void Appli_SubscriptionAddStatusCb(MOBLEUINT8 status)
{
   /* Change the received state for application  */
   eServerRespRecdState = SubscriptionAck_State;
}


/**
* @brief  Appli_PublicationStatusCb: This function is callback from config 
         client middleware on reception of the response
* @param  None
* @retval MOBLE_RESULT
*/ 
void Appli_PublicationStatusCb(MOBLEUINT8 status)
{
   /* Change the received state for application  */
   eServerRespRecdState = PublicationStatus_State;
}


/**
* @brief  Appli_NodeResetStatusCb: This function is callback from config 
         client middleware on reception of the Node Reset response
* @param  None
* @retval None
*/ 
void Appli_NodeResetStatusCb(void)
{
   /* Change the received state for application  */
   eServerRespRecdState = NodeResetStatus_State;
}


/**
* @brief  GetSIGModelToBindApp: This function gets the SIG Model to Bind 
* @param  elementIndex Index of the Element
* @param  pModelIndex  Pointer to Index of the Element to be updated 
* @param  numberOfModels Total number of Models to be scanned
* @retval MOBLE_RESULT
*/ 
MOBLEUINT16 GetSIGModelToBindApp(MOBLEUINT8 elementIndex, 
                                 MOBLEUINT8 *pModelIndex, 
                                 MOBLEUINT8 numberOfModels) 
{
  
  MOBLEUINT16 model_id;
  MOBLEUINT8 index;
  MOBLEUINT8 idxSIG = *pModelIndex;
  
  for (index = idxSIG; index < numberOfModels ; index++ )
  {
    model_id = aNodeElements[elementIndex].aSIGModels[index];
    if (MODEL_IS_FOUNDATION_MODEL(model_id)) 
    {
      /* Do nothing, let the next model_if be scanned */
      model_id = 0xffff;  /* Invalid Model ID */
    }
    else
    {
      break;
    }
  }
  
  *pModelIndex = index;
  return model_id;

}


/**
* @brief  GetVendorModelToBindApp: This function gets the Vendor Model to Bind 
* @param  elementIndex Index of the Element
* @param  pModelIndex  Pointer to Index of the Element to be updated 
* @param  numberOfModels Total number of Models to be scanned
* @retval MOBLE_RESULT
*/ 
MOBLEUINT32 GetVendorModelToBindApp(MOBLEUINT8 elementIndex, MOBLEUINT8 indexModels)
{
  return aNodeElements[elementIndex].aVendorModels[indexModels];
}

/**
* @brief  GetCountSIGModelToBindApp: This function gets the NUMBER of SIG Model 
              to Bind 
* @param  elementIndex Index of the Element for which the Count is needed
* @retval MOBLE_RESULT
*/ 
MOBLEUINT8 GetCountSIGModelToBindApp(MOBLEUINT8 elementIndex)
{
  return aNodeElements[elementIndex].NumSIGmodels;
}


/**
* @brief  GetCountVendorModelToBindApp: This function gets the Vendor Model to Bind 
* @param  elementIndex Index of the Element for which the Count is needed
* @retval MOBLE_RESULT
*/ 
MOBLEUINT8 GetCountVendorModelToBindApp(MOBLEUINT8 elementIndex)
{
  return aNodeElements[elementIndex].NumVendorModels;
}


/**
* @brief  GetSIGModelToPublish: This function gets the SIG Model to Publish 
* @param  elementIndex Index of the Element
* @param  pModelIndex  Pointer to Index of the Element to be updated 
* @param  numberOfModels Total number of Models to be scanned
* @retval MOBLE_RESULT
*/ 
MOBLEUINT16 GetSIGModelToPublish(MOBLEUINT8 elementIndex, 
                                     MOBLEUINT8 *pModelIndex, 
                                     MOBLEUINT8 numberOfModels)

{
  return GetSIGModelToBindApp(elementIndex, 
                              pModelIndex, 
                              numberOfModels);
}


/**
* @brief  GetVendorModelToPublish: This function gets the Vendor Model to Publish
* @param  elementIndex Index of the Element
* @param  idxSIG  Pointer to Index of the Model
* @retval MOBLE_RESULT
*/ 
MOBLEUINT32 GetVendorModelToPublish(MOBLEUINT8 elementIndex, MOBLEUINT8 idxSIG)
{
  return aNodeElements[elementIndex].aVendorModels[idxSIG];
}


/**
* @brief  GetCountSIGModelToPublish: This function gets the SIG Model to Bind 
* @param  elementIndex Index of the Element
* @retval MOBLE_RESULT
*/ 
MOBLEUINT8 GetCountSIGModelToPublish(MOBLEUINT8 elementIndex)
{
  return aNodeElements[elementIndex].NumSIGmodels;
}


/**
* @brief  GetCountVendorModelToPublish: This function gets the Vendor Model to Publish
* @param  elementIndex Index of the Element
* @retval MOBLE_RESULT
*/ 
MOBLEUINT8 GetCountVendorModelToPublish(MOBLEUINT8 elementIndex)
{
  return aNodeElements[elementIndex].NumVendorModels;
}


/**
* @brief  GetSIGModelToSubscribe: This function gets the SIG Model to Bind 
* @param  elementIndex Index of the Element
* @param  pModelIndex  Pointer to Index of the Element to be updated 
* @param  numberOfModels Total number of Models to be scanned
* @retval MOBLE_RESULT
*/ 
MOBLEUINT16 GetSIGModelToSubscribe(MOBLEUINT8 elementIndex, 
                                 MOBLEUINT8 *pModelIndex, 
                                 MOBLEUINT8 numberOfModels) 
{
  return GetSIGModelToBindApp(elementIndex, 
                              pModelIndex, 
                              numberOfModels);
}


/**
* @brief  GetVendorModelToSubscribe: This function Gets the Vendor Model ID for 
          Subscription
* @param  elementIndex Index of the Element
* @param  idxSIG  Index to the Model ID to Subscribe
* @retval MOBLE_RESULT
*/ 
MOBLEUINT32 GetVendorModelToSubscribe(MOBLEUINT8 elementIndex, 
                                      MOBLEUINT8 idxSIG)
{
  return aNodeElements[elementIndex].aVendorModels[idxSIG];
}


/**
* @brief  GetCountSIGModelToSubscribe: This function gets the SIG Model to Subscribe 
* @param  elementIndex Index of the Element
* @retval MOBLE_RESULT
*/ 
MOBLEUINT8 GetCountSIGModelToSubscribe(MOBLEUINT8 elementIndex)
{
  return aNodeElements[elementIndex].NumSIGmodels;
}


/**
* @brief  GetCountVendorModelToPublish: This function gets the Count of the 
           Vendor Model to Subscribe
* @param  elementIndex Index of the Element
* @retval MOBLE_RESULT
*/ 
MOBLEUINT8 GetCountVendorModelToSubscribe(MOBLEUINT8 elementIndex)
{
  return aNodeElements[elementIndex].NumVendorModels;
}


/**
* @brief  AppliConfigClient_SendMessageDefault: This function is used for sending
          a message. 
          ** The Function is not yet written fully
* @param  None
* @retval MOBLE_RESULT
*/ 
MOBLEUINT8 AppliConfigClient_SendMessageDefault(MOBLEUINT8 elementIdx)
{
  return NUM_VENDOR_MODELS_TO_SUBSCRIBE; 
}

/******************************************************************************/
#endif /* defined (ENABLE_PROVISIONER_FEATURE) || defined(DYNAMIC_PROVISIONER) */
/******************************************************************************/

/**
* @}
*/

/**
* @}
*/

/******************* (C) COPYRIGHT 2020 STMicroelectronics *****END OF FILE****/