1 /*  Bluetooth Mesh */
2 
3 /*
4  * Copyright (c) 2017 Intel Corporation
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 #define OP_APP_KEY_ADD                     BT_MESH_MODEL_OP_1(0x00)
10 #define OP_APP_KEY_UPDATE                  BT_MESH_MODEL_OP_1(0x01)
11 #define OP_DEV_COMP_DATA_STATUS            BT_MESH_MODEL_OP_1(0x02)
12 #define OP_MOD_PUB_SET                     BT_MESH_MODEL_OP_1(0x03)
13 #define OP_HEALTH_CURRENT_STATUS           BT_MESH_MODEL_OP_1(0x04)
14 #define OP_HEALTH_FAULT_STATUS             BT_MESH_MODEL_OP_1(0x05)
15 #define OP_HEARTBEAT_PUB_STATUS            BT_MESH_MODEL_OP_1(0x06)
16 #define OP_APP_KEY_DEL                     BT_MESH_MODEL_OP_2(0x80, 0x00)
17 #define OP_APP_KEY_GET                     BT_MESH_MODEL_OP_2(0x80, 0x01)
18 #define OP_APP_KEY_LIST                    BT_MESH_MODEL_OP_2(0x80, 0x02)
19 #define OP_APP_KEY_STATUS                  BT_MESH_MODEL_OP_2(0x80, 0x03)
20 #define OP_ATTENTION_GET                   BT_MESH_MODEL_OP_2(0x80, 0x04)
21 #define OP_ATTENTION_SET                   BT_MESH_MODEL_OP_2(0x80, 0x05)
22 #define OP_ATTENTION_SET_UNREL             BT_MESH_MODEL_OP_2(0x80, 0x06)
23 #define OP_ATTENTION_STATUS                BT_MESH_MODEL_OP_2(0x80, 0x07)
24 #define OP_DEV_COMP_DATA_GET               BT_MESH_MODEL_OP_2(0x80, 0x08)
25 #define OP_BEACON_GET                      BT_MESH_MODEL_OP_2(0x80, 0x09)
26 #define OP_BEACON_SET                      BT_MESH_MODEL_OP_2(0x80, 0x0a)
27 #define OP_BEACON_STATUS                   BT_MESH_MODEL_OP_2(0x80, 0x0b)
28 #define OP_DEFAULT_TTL_GET                 BT_MESH_MODEL_OP_2(0x80, 0x0c)
29 #define OP_DEFAULT_TTL_SET                 BT_MESH_MODEL_OP_2(0x80, 0x0d)
30 #define OP_DEFAULT_TTL_STATUS              BT_MESH_MODEL_OP_2(0x80, 0x0e)
31 #define OP_FRIEND_GET                      BT_MESH_MODEL_OP_2(0x80, 0x0f)
32 #define OP_FRIEND_SET                      BT_MESH_MODEL_OP_2(0x80, 0x10)
33 #define OP_FRIEND_STATUS                   BT_MESH_MODEL_OP_2(0x80, 0x11)
34 #define OP_GATT_PROXY_GET                  BT_MESH_MODEL_OP_2(0x80, 0x12)
35 #define OP_GATT_PROXY_SET                  BT_MESH_MODEL_OP_2(0x80, 0x13)
36 #define OP_GATT_PROXY_STATUS               BT_MESH_MODEL_OP_2(0x80, 0x14)
37 #define OP_KRP_GET                         BT_MESH_MODEL_OP_2(0x80, 0x15)
38 #define OP_KRP_SET                         BT_MESH_MODEL_OP_2(0x80, 0x16)
39 #define OP_KRP_STATUS                      BT_MESH_MODEL_OP_2(0x80, 0x17)
40 #define OP_MOD_PUB_GET                     BT_MESH_MODEL_OP_2(0x80, 0x18)
41 #define OP_MOD_PUB_STATUS                  BT_MESH_MODEL_OP_2(0x80, 0x19)
42 #define OP_MOD_PUB_VA_SET                  BT_MESH_MODEL_OP_2(0x80, 0x1a)
43 #define OP_MOD_SUB_ADD                     BT_MESH_MODEL_OP_2(0x80, 0x1b)
44 #define OP_MOD_SUB_DEL                     BT_MESH_MODEL_OP_2(0x80, 0x1c)
45 #define OP_MOD_SUB_DEL_ALL                 BT_MESH_MODEL_OP_2(0x80, 0x1d)
46 #define OP_MOD_SUB_OVERWRITE               BT_MESH_MODEL_OP_2(0x80, 0x1e)
47 #define OP_MOD_SUB_STATUS                  BT_MESH_MODEL_OP_2(0x80, 0x1f)
48 #define OP_MOD_SUB_VA_ADD                  BT_MESH_MODEL_OP_2(0x80, 0x20)
49 #define OP_MOD_SUB_VA_DEL                  BT_MESH_MODEL_OP_2(0x80, 0x21)
50 #define OP_MOD_SUB_VA_OVERWRITE            BT_MESH_MODEL_OP_2(0x80, 0x22)
51 #define OP_NET_TRANSMIT_GET                BT_MESH_MODEL_OP_2(0x80, 0x23)
52 #define OP_NET_TRANSMIT_SET                BT_MESH_MODEL_OP_2(0x80, 0x24)
53 #define OP_NET_TRANSMIT_STATUS             BT_MESH_MODEL_OP_2(0x80, 0x25)
54 #define OP_RELAY_GET                       BT_MESH_MODEL_OP_2(0x80, 0x26)
55 #define OP_RELAY_SET                       BT_MESH_MODEL_OP_2(0x80, 0x27)
56 #define OP_RELAY_STATUS                    BT_MESH_MODEL_OP_2(0x80, 0x28)
57 #define OP_MOD_SUB_GET                     BT_MESH_MODEL_OP_2(0x80, 0x29)
58 #define OP_MOD_SUB_LIST                    BT_MESH_MODEL_OP_2(0x80, 0x2a)
59 #define OP_MOD_SUB_GET_VND                 BT_MESH_MODEL_OP_2(0x80, 0x2b)
60 #define OP_MOD_SUB_LIST_VND                BT_MESH_MODEL_OP_2(0x80, 0x2c)
61 #define OP_LPN_TIMEOUT_GET                 BT_MESH_MODEL_OP_2(0x80, 0x2d)
62 #define OP_LPN_TIMEOUT_STATUS              BT_MESH_MODEL_OP_2(0x80, 0x2e)
63 #define OP_HEALTH_FAULT_CLEAR              BT_MESH_MODEL_OP_2(0x80, 0x2f)
64 #define OP_HEALTH_FAULT_CLEAR_UNREL        BT_MESH_MODEL_OP_2(0x80, 0x30)
65 #define OP_HEALTH_FAULT_GET                BT_MESH_MODEL_OP_2(0x80, 0x31)
66 #define OP_HEALTH_FAULT_TEST               BT_MESH_MODEL_OP_2(0x80, 0x32)
67 #define OP_HEALTH_FAULT_TEST_UNREL         BT_MESH_MODEL_OP_2(0x80, 0x33)
68 #define OP_HEALTH_PERIOD_GET               BT_MESH_MODEL_OP_2(0x80, 0x34)
69 #define OP_HEALTH_PERIOD_SET               BT_MESH_MODEL_OP_2(0x80, 0x35)
70 #define OP_HEALTH_PERIOD_SET_UNREL         BT_MESH_MODEL_OP_2(0x80, 0x36)
71 #define OP_HEALTH_PERIOD_STATUS            BT_MESH_MODEL_OP_2(0x80, 0x37)
72 #define OP_HEARTBEAT_PUB_GET               BT_MESH_MODEL_OP_2(0x80, 0x38)
73 #define OP_HEARTBEAT_PUB_SET               BT_MESH_MODEL_OP_2(0x80, 0x39)
74 #define OP_HEARTBEAT_SUB_GET               BT_MESH_MODEL_OP_2(0x80, 0x3a)
75 #define OP_HEARTBEAT_SUB_SET               BT_MESH_MODEL_OP_2(0x80, 0x3b)
76 #define OP_HEARTBEAT_SUB_STATUS            BT_MESH_MODEL_OP_2(0x80, 0x3c)
77 #define OP_MOD_APP_BIND                    BT_MESH_MODEL_OP_2(0x80, 0x3d)
78 #define OP_MOD_APP_STATUS                  BT_MESH_MODEL_OP_2(0x80, 0x3e)
79 #define OP_MOD_APP_UNBIND                  BT_MESH_MODEL_OP_2(0x80, 0x3f)
80 #define OP_NET_KEY_ADD                     BT_MESH_MODEL_OP_2(0x80, 0x40)
81 #define OP_NET_KEY_DEL                     BT_MESH_MODEL_OP_2(0x80, 0x41)
82 #define OP_NET_KEY_GET                     BT_MESH_MODEL_OP_2(0x80, 0x42)
83 #define OP_NET_KEY_LIST                    BT_MESH_MODEL_OP_2(0x80, 0x43)
84 #define OP_NET_KEY_STATUS                  BT_MESH_MODEL_OP_2(0x80, 0x44)
85 #define OP_NET_KEY_UPDATE                  BT_MESH_MODEL_OP_2(0x80, 0x45)
86 #define OP_NODE_IDENTITY_GET               BT_MESH_MODEL_OP_2(0x80, 0x46)
87 #define OP_NODE_IDENTITY_SET               BT_MESH_MODEL_OP_2(0x80, 0x47)
88 #define OP_NODE_IDENTITY_STATUS            BT_MESH_MODEL_OP_2(0x80, 0x48)
89 #define OP_NODE_RESET                      BT_MESH_MODEL_OP_2(0x80, 0x49)
90 #define OP_NODE_RESET_STATUS               BT_MESH_MODEL_OP_2(0x80, 0x4a)
91 #define OP_SIG_MOD_APP_GET                 BT_MESH_MODEL_OP_2(0x80, 0x4b)
92 #define OP_SIG_MOD_APP_LIST                BT_MESH_MODEL_OP_2(0x80, 0x4c)
93 #define OP_VND_MOD_APP_GET                 BT_MESH_MODEL_OP_2(0x80, 0x4d)
94 #define OP_VND_MOD_APP_LIST                BT_MESH_MODEL_OP_2(0x80, 0x4e)
95 /*[Genie begin] add by wenbing.cwb at 2021-01-21*/
96 #ifdef CONFIG_BT_MESH_CTRL_RELAY
97 #define OP_CTRL_RELAY_CONF_GET             BT_MESH_MODEL_OP_2(0x80, 0x70)
98 #define OP_CTRL_RELAY_CONF_SET             BT_MESH_MODEL_OP_2(0x80, 0x71)
99 #define OP_CTRL_RELAY_CONF_STATUS          BT_MESH_MODEL_OP_2(0x80, 0x72)
100 #endif
101 /*[Genie end] add by wenbing.cwb at 2021-01-21*/
102 
103 #define STATUS_SUCCESS                     0x00
104 #define STATUS_INVALID_ADDRESS             0x01
105 #define STATUS_INVALID_MODEL               0x02
106 #define STATUS_INVALID_APPKEY              0x03
107 #define STATUS_INVALID_NETKEY              0x04
108 #define STATUS_INSUFF_RESOURCES            0x05
109 #define STATUS_IDX_ALREADY_STORED          0x06
110 #define STATUS_NVAL_PUB_PARAM              0x07
111 #define STATUS_NOT_SUB_MOD                 0x08
112 #define STATUS_STORAGE_FAIL                0x09
113 #define STATUS_FEAT_NOT_SUPP               0x0a
114 #define STATUS_CANNOT_UPDATE               0x0b
115 #define STATUS_CANNOT_REMOVE               0x0c
116 #define STATUS_CANNOT_BIND                 0x0d
117 #define STATUS_TEMP_STATE_CHG_FAIL         0x0e
118 #define STATUS_CANNOT_SET                  0x0f
119 #define STATUS_UNSPECIFIED                 0x10
120 #define STATUS_INVALID_BINDING             0x11
121 
122 int bt_mesh_cfg_srv_init(struct bt_mesh_model *model, bool primary);
123 int bt_mesh_health_srv_init(struct bt_mesh_model *model, bool primary);
124 
125 int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary);
126 int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary);
127 
128 void bt_mesh_cfg_reset(void);
129 
130 void bt_mesh_heartbeat(u16_t src, u16_t dst, u8_t hops, u16_t feat);
131 
132 void bt_mesh_attention(struct bt_mesh_model *model, u8_t time);
133 
134 u8_t *bt_mesh_label_uuid_get(u16_t addr);
135 
136 struct bt_mesh_hb_pub *bt_mesh_hb_pub_get(void);
137 void bt_mesh_hb_pub_disable(void);
138 struct bt_mesh_cfg_srv *bt_mesh_cfg_get(void);
139 
140 u8_t bt_mesh_net_transmit_get(void);
141 u8_t bt_mesh_relay_get(void);
142 u8_t bt_mesh_friend_get(void);
143 u8_t bt_mesh_relay_retransmit_get(void);
144 u8_t bt_mesh_beacon_get(void);
145 u8_t bt_mesh_gatt_proxy_get(void);
146 u8_t bt_mesh_default_ttl_get(void);
147 
148 void bt_mesh_subnet_del(struct bt_mesh_subnet *sub, bool store);
149 
150 struct bt_mesh_app_key *bt_mesh_app_key_alloc(u16_t app_idx);
151 void bt_mesh_app_key_del(struct bt_mesh_app_key *key, bool store);
152 
153 #include <misc/byteorder.h>
154 
key_idx_pack(struct net_buf_simple * buf,u16_t idx1,u16_t idx2)155 static inline void key_idx_pack(struct net_buf_simple *buf,
156 				u16_t idx1, u16_t idx2)
157 {
158 	net_buf_simple_add_le16(buf, idx1 | ((idx2 & 0x00f) << 12));
159 	net_buf_simple_add_u8(buf, idx2 >> 4);
160 }
161 
key_idx_unpack(struct net_buf_simple * buf,u16_t * idx1,u16_t * idx2)162 static inline void key_idx_unpack(struct net_buf_simple *buf,
163 				  u16_t *idx1, u16_t *idx2)
164 {
165 	*idx1 = sys_get_le16(&buf->data[0]) & 0xfff;
166 	*idx2 = sys_get_le16(&buf->data[1]) >> 4;
167 	net_buf_simple_pull(buf, 3);
168 }
169