10#ifndef __BT_MESH_ACCESS_H
11#define __BT_MESH_ACCESS_H
27#define BT_MESH_ADDR_UNASSIGNED 0x0000
28#define BT_MESH_ADDR_ALL_NODES 0xffff
29#define BT_MESH_ADDR_PROXIES 0xfffc
30#define BT_MESH_ADDR_FRIENDS 0xfffd
31#define BT_MESH_ADDR_RELAYS 0xfffe
33#define BT_MESH_KEY_UNUSED 0xffff
34#define BT_MESH_KEY_ANY 0xffff
35#define BT_MESH_KEY_DEV 0xfffe
36#define BT_MESH_KEY_DEV_LOCAL BT_MESH_KEY_DEV
37#define BT_MESH_KEY_DEV_REMOTE 0xfffd
38#define BT_MESH_KEY_DEV_ANY 0xfffc
40#define BT_MESH_ADDR_IS_UNICAST(addr) ((addr) && (addr) < 0x8000)
41#define BT_MESH_ADDR_IS_GROUP(addr) ((addr) >= 0xc000 && (addr) <= 0xff00)
42#define BT_MESH_ADDR_IS_VIRTUAL(addr) ((addr) >= 0x8000 && (addr) < 0xc000)
43#define BT_MESH_ADDR_IS_RFU(addr) ((addr) >= 0xff00 && (addr) <= 0xfffb)
45#define BT_MESH_IS_DEV_KEY(key) (key == BT_MESH_KEY_DEV_LOCAL || \
46 key == BT_MESH_KEY_DEV_REMOTE)
48#define BT_MESH_APP_SEG_SDU_MAX 12
49#define BT_MESH_TX_SDU_MAX (CONFIG_BT_MESH_TX_SEG_MAX * BT_MESH_APP_SEG_SDU_MAX)
50#define BT_MESH_RX_SDU_MAX (CONFIG_BT_MESH_RX_SEG_MAX * BT_MESH_APP_SEG_SDU_MAX)
60#define BT_MESH_ELEM(_loc, _mods, _vnd_mods) \
63 .model_count = ARRAY_SIZE(_mods), \
65 .vnd_model_count = ARRAY_SIZE(_vnd_mods), \
66 .vnd_models = (_vnd_mods), \
77 const uint8_t model_count;
78 const uint8_t vnd_model_count;
85#define BT_MESH_MODEL_ID_CFG_SRV 0x0000
86#define BT_MESH_MODEL_ID_CFG_CLI 0x0001
87#define BT_MESH_MODEL_ID_HEALTH_SRV 0x0002
88#define BT_MESH_MODEL_ID_HEALTH_CLI 0x0003
91#define BT_MESH_MODEL_ID_GEN_ONOFF_SRV 0x1000
92#define BT_MESH_MODEL_ID_GEN_ONOFF_CLI 0x1001
93#define BT_MESH_MODEL_ID_GEN_LEVEL_SRV 0x1002
94#define BT_MESH_MODEL_ID_GEN_LEVEL_CLI 0x1003
95#define BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV 0x1004
96#define BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI 0x1005
97#define BT_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV 0x1006
98#define BT_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV 0x1007
99#define BT_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI 0x1008
100#define BT_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV 0x1009
101#define BT_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV 0x100a
102#define BT_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI 0x100b
103#define BT_MESH_MODEL_ID_GEN_BATTERY_SRV 0x100c
104#define BT_MESH_MODEL_ID_GEN_BATTERY_CLI 0x100d
105#define BT_MESH_MODEL_ID_GEN_LOCATION_SRV 0x100e
106#define BT_MESH_MODEL_ID_GEN_LOCATION_SETUPSRV 0x100f
107#define BT_MESH_MODEL_ID_GEN_LOCATION_CLI 0x1010
108#define BT_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV 0x1011
109#define BT_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV 0x1012
110#define BT_MESH_MODEL_ID_GEN_USER_PROP_SRV 0x1013
111#define BT_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV 0x1014
112#define BT_MESH_MODEL_ID_GEN_PROP_CLI 0x1015
113#define BT_MESH_MODEL_ID_SENSOR_SRV 0x1100
114#define BT_MESH_MODEL_ID_SENSOR_SETUP_SRV 0x1101
115#define BT_MESH_MODEL_ID_SENSOR_CLI 0x1102
116#define BT_MESH_MODEL_ID_TIME_SRV 0x1200
117#define BT_MESH_MODEL_ID_TIME_SETUP_SRV 0x1201
118#define BT_MESH_MODEL_ID_TIME_CLI 0x1202
119#define BT_MESH_MODEL_ID_SCENE_SRV 0x1203
120#define BT_MESH_MODEL_ID_SCENE_SETUP_SRV 0x1204
121#define BT_MESH_MODEL_ID_SCENE_CLI 0x1205
122#define BT_MESH_MODEL_ID_SCHEDULER_SRV 0x1206
123#define BT_MESH_MODEL_ID_SCHEDULER_SETUP_SRV 0x1207
124#define BT_MESH_MODEL_ID_SCHEDULER_CLI 0x1208
125#define BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV 0x1300
126#define BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV 0x1301
127#define BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI 0x1302
128#define BT_MESH_MODEL_ID_LIGHT_CTL_SRV 0x1303
129#define BT_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV 0x1304
130#define BT_MESH_MODEL_ID_LIGHT_CTL_CLI 0x1305
131#define BT_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV 0x1306
132#define BT_MESH_MODEL_ID_LIGHT_HSL_SRV 0x1307
133#define BT_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV 0x1308
134#define BT_MESH_MODEL_ID_LIGHT_HSL_CLI 0x1309
135#define BT_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV 0x130a
136#define BT_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV 0x130b
137#define BT_MESH_MODEL_ID_LIGHT_XYL_SRV 0x130c
138#define BT_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV 0x130d
139#define BT_MESH_MODEL_ID_LIGHT_XYL_CLI 0x130e
140#define BT_MESH_MODEL_ID_LIGHT_LC_SRV 0x130f
141#define BT_MESH_MODEL_ID_LIGHT_LC_SETUPSRV 0x1310
142#define BT_MESH_MODEL_ID_LIGHT_LC_CLI 0x1311
144struct bt_mesh_model_op {
146 const uint32_t opcode;
162#define BT_MESH_MODEL_OP_1(b0) (b0)
163#define BT_MESH_MODEL_OP_2(b0, b1) (((b0) << 8) | (b1))
164#define BT_MESH_MODEL_OP_3(b0, cid) ((((b0) << 16) | 0xc00000) | (cid))
167#define BT_MESH_LEN_EXACT(len) (-len)
169#define BT_MESH_LEN_MIN(len) (len)
171#define BT_MESH_MODEL_OP_END { 0, 0, NULL }
172#define BT_MESH_MODEL_NO_OPS ((struct bt_mesh_model_op []) \
173 { BT_MESH_MODEL_OP_END })
176#define BT_MESH_MODEL_NONE ((struct bt_mesh_model []){})
188#define BT_MESH_MODEL_CB(_id, _op, _pub, _user_data, _cb) \
192 .keys = { [0 ... (CONFIG_BT_MESH_MODEL_KEY_COUNT - 1)] = \
193 BT_MESH_KEY_UNUSED }, \
195 .groups = { [0 ... (CONFIG_BT_MESH_MODEL_GROUP_COUNT - 1)] = \
196 BT_MESH_ADDR_UNASSIGNED }, \
197 .user_data = _user_data, \
212#define BT_MESH_MODEL_VND_CB(_company, _id, _op, _pub, _user_data, _cb) \
214 .vnd.company = (_company), \
218 .keys = { [0 ... (CONFIG_BT_MESH_MODEL_KEY_COUNT - 1)] = \
219 BT_MESH_KEY_UNUSED }, \
220 .groups = { [0 ... (CONFIG_BT_MESH_MODEL_GROUP_COUNT - 1)] = \
221 BT_MESH_ADDR_UNASSIGNED }, \
222 .user_data = _user_data, \
236#define BT_MESH_MODEL(_id, _op, _pub, _user_data) \
237 BT_MESH_MODEL_CB(_id, _op, _pub, _user_data, NULL)
249#define BT_MESH_MODEL_VND(_company, _id, _op, _pub, _user_data) \
250 BT_MESH_MODEL_VND_CB(_company, _id, _op, _pub, _user_data, NULL)
263#define BT_MESH_TRANSMIT(count, int_ms) ((count) | (((int_ms / 10) - 1) << 3))
273#define BT_MESH_TRANSMIT_COUNT(transmit) (((transmit) & (uint8_t)BIT_MASK(3)))
283#define BT_MESH_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 10)
296#define BT_MESH_PUB_TRANSMIT(count, int_ms) BT_MESH_TRANSMIT(count, \
307#define BT_MESH_PUB_TRANSMIT_COUNT(transmit) BT_MESH_TRANSMIT_COUNT(transmit)
317#define BT_MESH_PUB_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 50)
392 const char *name,
char *val);
459 uint16_t keys[CONFIG_BT_MESH_MODEL_KEY_COUNT];
462 uint16_t groups[CONFIG_BT_MESH_MODEL_GROUP_COUNT];
464 const struct bt_mesh_model_op *
const op;
469#if MYNEWT_VAL(BLE_MESH_MODEL_EXTENSIONS)
478struct bt_mesh_send_cb {
479 void (*start)(uint16_t duration,
int err,
void *cb_data);
480 void (*end)(
int err,
void *cb_data);
484#define BT_MESH_TTL_DEFAULT 0xff
487#define BT_MESH_TTL_MAX 0x7f
503 const struct bt_mesh_send_cb *cb,
552 uint16_t company, uint16_t
id);
560static inline bool bt_mesh_model_in_primary(
const struct bt_mesh_model *mod)
562 return (mod->elem_idx == 0);
577 const char *name,
const void *data,
bool bt_mesh_model_is_extended(struct bt_mesh_model *model)
Check if model is extended by another model.
struct bt_mesh_elem * bt_mesh_model_elem(struct bt_mesh_model *mod)
Get the element that a model belongs to.
struct bt_mesh_model * bt_mesh_model_find_vnd(const struct bt_mesh_elem *elem, uint16_t company, uint16_t id)
Find a vendor model.
int bt_mesh_model_send(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct os_mbuf *msg, const struct bt_mesh_send_cb *cb, void *cb_data)
Send an Access Layer message.
int bt_mesh_model_publish(struct bt_mesh_model *model)
Send a model publication message.
struct bt_mesh_model * bt_mesh_model_find(const struct bt_mesh_elem *elem, uint16_t id)
Find a SIG model.
int bt_mesh_model_data_store(struct bt_mesh_model *mod, bool vnd, const char *name, const void *data, size_t data_len)
Immediately store the model's user data in persistent storage.
int bt_mesh_model_extend(struct bt_mesh_model *extending_mod, struct bt_mesh_model *base_mod)
Let a model extend another.
Bluetooth Mesh Message APIs.
uint16_t company
Definition access.h:438
uint16_t id
Definition access.h:440
void(*const reset)(struct bt_mesh_model *model)
Model reset callback.
Definition access.h:432
int(*const settings_set)(struct bt_mesh_model *model, const char *name, char *val)
Set value handler of user data tied to the model.
Definition access.h:391
int(*const start)(struct bt_mesh_model *model)
Callback called when the mesh is started.
Definition access.h:405
int(*const init)(struct bt_mesh_model *model)
Model init callback.
Definition access.h:420
uint16_t key
Definition access.h:325
int(* update)(struct bt_mesh_model *mod)
Callback for updating the publication buffer.
Definition access.h:373
uint16_t cred
Definition access.h:326
uint8_t retransmit
Definition access.h:331
uint16_t addr
Definition access.h:324
uint8_t period_div
Definition access.h:333
struct bt_mesh_model * mod
Definition access.h:322
struct os_mbuf * msg
Publication buffer, containing the publication message.
Definition access.h:355
uint8_t ttl
Definition access.h:330
uint32_t period_start
Definition access.h:336
uint16_t send_rel
Definition access.h:327
uint16_t fast_period
Definition access.h:328
uint8_t period
Definition access.h:332
struct k_work_delayable timer
Definition access.h:376