1 /*
2  * Copyright (c) 2017 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #define OP_APP_KEY_ADD                     BT_MESH_MODEL_OP_1(0x00)
8 #define OP_APP_KEY_UPDATE                  BT_MESH_MODEL_OP_1(0x01)
9 #define OP_DEV_COMP_DATA_STATUS            BT_MESH_MODEL_OP_1(0x02)
10 #define OP_MOD_PUB_SET                     BT_MESH_MODEL_OP_1(0x03)
11 #define OP_HEALTH_CURRENT_STATUS           BT_MESH_MODEL_OP_1(0x04)
12 #define OP_HEALTH_FAULT_STATUS             BT_MESH_MODEL_OP_1(0x05)
13 #define OP_HEARTBEAT_PUB_STATUS            BT_MESH_MODEL_OP_1(0x06)
14 #define OP_APP_KEY_DEL                     BT_MESH_MODEL_OP_2(0x80, 0x00)
15 #define OP_APP_KEY_GET                     BT_MESH_MODEL_OP_2(0x80, 0x01)
16 #define OP_APP_KEY_LIST                    BT_MESH_MODEL_OP_2(0x80, 0x02)
17 #define OP_APP_KEY_STATUS                  BT_MESH_MODEL_OP_2(0x80, 0x03)
18 #define OP_ATTENTION_GET                   BT_MESH_MODEL_OP_2(0x80, 0x04)
19 #define OP_ATTENTION_SET                   BT_MESH_MODEL_OP_2(0x80, 0x05)
20 #define OP_ATTENTION_SET_UNREL             BT_MESH_MODEL_OP_2(0x80, 0x06)
21 #define OP_ATTENTION_STATUS                BT_MESH_MODEL_OP_2(0x80, 0x07)
22 #define OP_DEV_COMP_DATA_GET               BT_MESH_MODEL_OP_2(0x80, 0x08)
23 #define OP_BEACON_GET                      BT_MESH_MODEL_OP_2(0x80, 0x09)
24 #define OP_BEACON_SET                      BT_MESH_MODEL_OP_2(0x80, 0x0a)
25 #define OP_BEACON_STATUS                   BT_MESH_MODEL_OP_2(0x80, 0x0b)
26 #define OP_DEFAULT_TTL_GET                 BT_MESH_MODEL_OP_2(0x80, 0x0c)
27 #define OP_DEFAULT_TTL_SET                 BT_MESH_MODEL_OP_2(0x80, 0x0d)
28 #define OP_DEFAULT_TTL_STATUS              BT_MESH_MODEL_OP_2(0x80, 0x0e)
29 #define OP_FRIEND_GET                      BT_MESH_MODEL_OP_2(0x80, 0x0f)
30 #define OP_FRIEND_SET                      BT_MESH_MODEL_OP_2(0x80, 0x10)
31 #define OP_FRIEND_STATUS                   BT_MESH_MODEL_OP_2(0x80, 0x11)
32 #define OP_GATT_PROXY_GET                  BT_MESH_MODEL_OP_2(0x80, 0x12)
33 #define OP_GATT_PROXY_SET                  BT_MESH_MODEL_OP_2(0x80, 0x13)
34 #define OP_GATT_PROXY_STATUS               BT_MESH_MODEL_OP_2(0x80, 0x14)
35 #define OP_KRP_GET                         BT_MESH_MODEL_OP_2(0x80, 0x15)
36 #define OP_KRP_SET                         BT_MESH_MODEL_OP_2(0x80, 0x16)
37 #define OP_KRP_STATUS                      BT_MESH_MODEL_OP_2(0x80, 0x17)
38 #define OP_MOD_PUB_GET                     BT_MESH_MODEL_OP_2(0x80, 0x18)
39 #define OP_MOD_PUB_STATUS                  BT_MESH_MODEL_OP_2(0x80, 0x19)
40 #define OP_MOD_PUB_VA_SET                  BT_MESH_MODEL_OP_2(0x80, 0x1a)
41 #define OP_MOD_SUB_ADD                     BT_MESH_MODEL_OP_2(0x80, 0x1b)
42 #define OP_MOD_SUB_DEL                     BT_MESH_MODEL_OP_2(0x80, 0x1c)
43 #define OP_MOD_SUB_DEL_ALL                 BT_MESH_MODEL_OP_2(0x80, 0x1d)
44 #define OP_MOD_SUB_OVERWRITE               BT_MESH_MODEL_OP_2(0x80, 0x1e)
45 #define OP_MOD_SUB_STATUS                  BT_MESH_MODEL_OP_2(0x80, 0x1f)
46 #define OP_MOD_SUB_VA_ADD                  BT_MESH_MODEL_OP_2(0x80, 0x20)
47 #define OP_MOD_SUB_VA_DEL                  BT_MESH_MODEL_OP_2(0x80, 0x21)
48 #define OP_MOD_SUB_VA_OVERWRITE            BT_MESH_MODEL_OP_2(0x80, 0x22)
49 #define OP_NET_TRANSMIT_GET                BT_MESH_MODEL_OP_2(0x80, 0x23)
50 #define OP_NET_TRANSMIT_SET                BT_MESH_MODEL_OP_2(0x80, 0x24)
51 #define OP_NET_TRANSMIT_STATUS             BT_MESH_MODEL_OP_2(0x80, 0x25)
52 #define OP_RELAY_GET                       BT_MESH_MODEL_OP_2(0x80, 0x26)
53 #define OP_RELAY_SET                       BT_MESH_MODEL_OP_2(0x80, 0x27)
54 #define OP_RELAY_STATUS                    BT_MESH_MODEL_OP_2(0x80, 0x28)
55 #define OP_MOD_SUB_GET                     BT_MESH_MODEL_OP_2(0x80, 0x29)
56 #define OP_MOD_SUB_LIST                    BT_MESH_MODEL_OP_2(0x80, 0x2a)
57 #define OP_MOD_SUB_GET_VND                 BT_MESH_MODEL_OP_2(0x80, 0x2b)
58 #define OP_MOD_SUB_LIST_VND                BT_MESH_MODEL_OP_2(0x80, 0x2c)
59 #define OP_LPN_TIMEOUT_GET                 BT_MESH_MODEL_OP_2(0x80, 0x2d)
60 #define OP_LPN_TIMEOUT_STATUS              BT_MESH_MODEL_OP_2(0x80, 0x2e)
61 #define OP_HEALTH_FAULT_CLEAR              BT_MESH_MODEL_OP_2(0x80, 0x2f)
62 #define OP_HEALTH_FAULT_CLEAR_UNREL        BT_MESH_MODEL_OP_2(0x80, 0x30)
63 #define OP_HEALTH_FAULT_GET                BT_MESH_MODEL_OP_2(0x80, 0x31)
64 #define OP_HEALTH_FAULT_TEST               BT_MESH_MODEL_OP_2(0x80, 0x32)
65 #define OP_HEALTH_FAULT_TEST_UNREL         BT_MESH_MODEL_OP_2(0x80, 0x33)
66 #define OP_HEALTH_PERIOD_GET               BT_MESH_MODEL_OP_2(0x80, 0x34)
67 #define OP_HEALTH_PERIOD_SET               BT_MESH_MODEL_OP_2(0x80, 0x35)
68 #define OP_HEALTH_PERIOD_SET_UNREL         BT_MESH_MODEL_OP_2(0x80, 0x36)
69 #define OP_HEALTH_PERIOD_STATUS            BT_MESH_MODEL_OP_2(0x80, 0x37)
70 #define OP_HEARTBEAT_PUB_GET               BT_MESH_MODEL_OP_2(0x80, 0x38)
71 #define OP_HEARTBEAT_PUB_SET               BT_MESH_MODEL_OP_2(0x80, 0x39)
72 #define OP_HEARTBEAT_SUB_GET               BT_MESH_MODEL_OP_2(0x80, 0x3a)
73 #define OP_HEARTBEAT_SUB_SET               BT_MESH_MODEL_OP_2(0x80, 0x3b)
74 #define OP_HEARTBEAT_SUB_STATUS            BT_MESH_MODEL_OP_2(0x80, 0x3c)
75 #define OP_MOD_APP_BIND                    BT_MESH_MODEL_OP_2(0x80, 0x3d)
76 #define OP_MOD_APP_STATUS                  BT_MESH_MODEL_OP_2(0x80, 0x3e)
77 #define OP_MOD_APP_UNBIND                  BT_MESH_MODEL_OP_2(0x80, 0x3f)
78 #define OP_NET_KEY_ADD                     BT_MESH_MODEL_OP_2(0x80, 0x40)
79 #define OP_NET_KEY_DEL                     BT_MESH_MODEL_OP_2(0x80, 0x41)
80 #define OP_NET_KEY_GET                     BT_MESH_MODEL_OP_2(0x80, 0x42)
81 #define OP_NET_KEY_LIST                    BT_MESH_MODEL_OP_2(0x80, 0x43)
82 #define OP_NET_KEY_STATUS                  BT_MESH_MODEL_OP_2(0x80, 0x44)
83 #define OP_NET_KEY_UPDATE                  BT_MESH_MODEL_OP_2(0x80, 0x45)
84 #define OP_NODE_IDENTITY_GET               BT_MESH_MODEL_OP_2(0x80, 0x46)
85 #define OP_NODE_IDENTITY_SET               BT_MESH_MODEL_OP_2(0x80, 0x47)
86 #define OP_NODE_IDENTITY_STATUS            BT_MESH_MODEL_OP_2(0x80, 0x48)
87 #define OP_NODE_RESET                      BT_MESH_MODEL_OP_2(0x80, 0x49)
88 #define OP_NODE_RESET_STATUS               BT_MESH_MODEL_OP_2(0x80, 0x4a)
89 #define OP_SIG_MOD_APP_GET                 BT_MESH_MODEL_OP_2(0x80, 0x4b)
90 #define OP_SIG_MOD_APP_LIST                BT_MESH_MODEL_OP_2(0x80, 0x4c)
91 #define OP_VND_MOD_APP_GET                 BT_MESH_MODEL_OP_2(0x80, 0x4d)
92 #define OP_VND_MOD_APP_LIST                BT_MESH_MODEL_OP_2(0x80, 0x4e)
93 
94 #define STATUS_SUCCESS                     0x00
95 #define STATUS_INVALID_ADDRESS             0x01
96 #define STATUS_INVALID_MODEL               0x02
97 #define STATUS_INVALID_APPKEY              0x03
98 #define STATUS_INVALID_NETKEY              0x04
99 #define STATUS_INSUFF_RESOURCES            0x05
100 #define STATUS_IDX_ALREADY_STORED          0x06
101 #define STATUS_NVAL_PUB_PARAM              0x07
102 #define STATUS_NOT_SUB_MOD                 0x08
103 #define STATUS_STORAGE_FAIL                0x09
104 #define STATUS_FEAT_NOT_SUPP               0x0a
105 #define STATUS_CANNOT_UPDATE               0x0b
106 #define STATUS_CANNOT_REMOVE               0x0c
107 #define STATUS_CANNOT_BIND                 0x0d
108 #define STATUS_TEMP_STATE_CHG_FAIL         0x0e
109 #define STATUS_CANNOT_SET                  0x0f
110 #define STATUS_UNSPECIFIED                 0x10
111 #define STATUS_INVALID_BINDING             0x11
112 
113 void bt_mesh_model_reset(void);
114 
115 void bt_mesh_attention(struct bt_mesh_model *model, uint8_t time);
116 
117 #include <sys/byteorder.h>
118 
key_idx_pack(struct net_buf_simple * buf,uint16_t idx1,uint16_t idx2)119 static inline void key_idx_pack(struct net_buf_simple *buf,
120 				uint16_t idx1, uint16_t idx2)
121 {
122 	net_buf_simple_add_le16(buf, idx1 | ((idx2 & 0x00f) << 12));
123 	net_buf_simple_add_u8(buf, idx2 >> 4);
124 }
125 
key_idx_unpack(struct net_buf_simple * buf,uint16_t * idx1,uint16_t * idx2)126 static inline void key_idx_unpack(struct net_buf_simple *buf,
127 				  uint16_t *idx1, uint16_t *idx2)
128 {
129 	*idx1 = sys_get_le16(&buf->data[0]) & 0xfff;
130 	*idx2 = sys_get_le16(&buf->data[1]) >> 4;
131 	net_buf_simple_pull(buf, 3);
132 }
133