Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
access.h
Go to the documentation of this file.
1
5/*
6 * Copyright (c) 2017 Intel Corporation
7 *
8 * SPDX-License-Identifier: Apache-2.0
9 */
10#ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_ACCESS_H_
11#define ZEPHYR_INCLUDE_BLUETOOTH_MESH_ACCESS_H_
12
13#include <settings/settings.h>
14#include <sys/util.h>
15#include <bluetooth/mesh/msg.h>
16
17/* Internal macros used to initialize array members */
18#define BT_MESH_KEY_UNUSED_ELT_(IDX, _) BT_MESH_KEY_UNUSED,
19#define BT_MESH_ADDR_UNASSIGNED_ELT_(IDX, _) BT_MESH_ADDR_UNASSIGNED,
20#define BT_MESH_MODEL_KEYS_UNUSED \
21 { UTIL_LISTIFY(CONFIG_BT_MESH_MODEL_KEY_COUNT, \
22 BT_MESH_KEY_UNUSED_ELT_) }
23#define BT_MESH_MODEL_GROUPS_UNASSIGNED \
24 { UTIL_LISTIFY(CONFIG_BT_MESH_MODEL_GROUP_COUNT, \
25 BT_MESH_ADDR_UNASSIGNED_ELT_) }
26
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#define BT_MESH_ADDR_UNASSIGNED 0x0000
39#define BT_MESH_ADDR_ALL_NODES 0xffff
40#define BT_MESH_ADDR_PROXIES 0xfffc
41#define BT_MESH_ADDR_FRIENDS 0xfffd
42#define BT_MESH_ADDR_RELAYS 0xfffe
43
44#define BT_MESH_KEY_UNUSED 0xffff
45#define BT_MESH_KEY_ANY 0xffff
46#define BT_MESH_KEY_DEV 0xfffe
47#define BT_MESH_KEY_DEV_LOCAL BT_MESH_KEY_DEV
48#define BT_MESH_KEY_DEV_REMOTE 0xfffd
49#define BT_MESH_KEY_DEV_ANY 0xfffc
50
51#define BT_MESH_ADDR_IS_UNICAST(addr) ((addr) && (addr) < 0x8000)
52#define BT_MESH_ADDR_IS_GROUP(addr) ((addr) >= 0xc000 && (addr) <= 0xff00)
53#define BT_MESH_ADDR_IS_VIRTUAL(addr) ((addr) >= 0x8000 && (addr) < 0xc000)
54#define BT_MESH_ADDR_IS_RFU(addr) ((addr) >= 0xff00 && (addr) <= 0xfffb)
55
56#define BT_MESH_IS_DEV_KEY(key) (key == BT_MESH_KEY_DEV_LOCAL || \
57 key == BT_MESH_KEY_DEV_REMOTE)
58
60#define BT_MESH_APP_SEG_SDU_MAX 12
62#define BT_MESH_TX_SDU_MAX (CONFIG_BT_MESH_TX_SEG_MAX * \
63 BT_MESH_APP_SEG_SDU_MAX)
65#define BT_MESH_RX_SDU_MAX (CONFIG_BT_MESH_RX_SEG_MAX * \
66 BT_MESH_APP_SEG_SDU_MAX)
67
77#define BT_MESH_ELEM(_loc, _mods, _vnd_mods) \
78{ \
79 .loc = (_loc), \
80 .model_count = ARRAY_SIZE(_mods), \
81 .vnd_model_count = ARRAY_SIZE(_vnd_mods), \
82 .models = (_mods), \
83 .vnd_models = (_vnd_mods), \
84}
85
90
97
99 struct bt_mesh_model * const models;
101 struct bt_mesh_model * const vnd_models;
102};
103
104/* Foundation Models */
105#define BT_MESH_MODEL_ID_CFG_SRV 0x0000
106#define BT_MESH_MODEL_ID_CFG_CLI 0x0001
107#define BT_MESH_MODEL_ID_HEALTH_SRV 0x0002
108#define BT_MESH_MODEL_ID_HEALTH_CLI 0x0003
109
110/* Models from the Mesh Model Specification */
111#define BT_MESH_MODEL_ID_GEN_ONOFF_SRV 0x1000
112#define BT_MESH_MODEL_ID_GEN_ONOFF_CLI 0x1001
113#define BT_MESH_MODEL_ID_GEN_LEVEL_SRV 0x1002
114#define BT_MESH_MODEL_ID_GEN_LEVEL_CLI 0x1003
115#define BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV 0x1004
116#define BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI 0x1005
117#define BT_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV 0x1006
118#define BT_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV 0x1007
119#define BT_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI 0x1008
120#define BT_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV 0x1009
121#define BT_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV 0x100a
122#define BT_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI 0x100b
123#define BT_MESH_MODEL_ID_GEN_BATTERY_SRV 0x100c
124#define BT_MESH_MODEL_ID_GEN_BATTERY_CLI 0x100d
125#define BT_MESH_MODEL_ID_GEN_LOCATION_SRV 0x100e
126#define BT_MESH_MODEL_ID_GEN_LOCATION_SETUPSRV 0x100f
127#define BT_MESH_MODEL_ID_GEN_LOCATION_CLI 0x1010
128#define BT_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV 0x1011
129#define BT_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV 0x1012
130#define BT_MESH_MODEL_ID_GEN_USER_PROP_SRV 0x1013
131#define BT_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV 0x1014
132#define BT_MESH_MODEL_ID_GEN_PROP_CLI 0x1015
133#define BT_MESH_MODEL_ID_SENSOR_SRV 0x1100
134#define BT_MESH_MODEL_ID_SENSOR_SETUP_SRV 0x1101
135#define BT_MESH_MODEL_ID_SENSOR_CLI 0x1102
136#define BT_MESH_MODEL_ID_TIME_SRV 0x1200
137#define BT_MESH_MODEL_ID_TIME_SETUP_SRV 0x1201
138#define BT_MESH_MODEL_ID_TIME_CLI 0x1202
139#define BT_MESH_MODEL_ID_SCENE_SRV 0x1203
140#define BT_MESH_MODEL_ID_SCENE_SETUP_SRV 0x1204
141#define BT_MESH_MODEL_ID_SCENE_CLI 0x1205
142#define BT_MESH_MODEL_ID_SCHEDULER_SRV 0x1206
143#define BT_MESH_MODEL_ID_SCHEDULER_SETUP_SRV 0x1207
144#define BT_MESH_MODEL_ID_SCHEDULER_CLI 0x1208
145#define BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV 0x1300
146#define BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV 0x1301
147#define BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI 0x1302
148#define BT_MESH_MODEL_ID_LIGHT_CTL_SRV 0x1303
149#define BT_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV 0x1304
150#define BT_MESH_MODEL_ID_LIGHT_CTL_CLI 0x1305
151#define BT_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV 0x1306
152#define BT_MESH_MODEL_ID_LIGHT_HSL_SRV 0x1307
153#define BT_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV 0x1308
154#define BT_MESH_MODEL_ID_LIGHT_HSL_CLI 0x1309
155#define BT_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV 0x130a
156#define BT_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV 0x130b
157#define BT_MESH_MODEL_ID_LIGHT_XYL_SRV 0x130c
158#define BT_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV 0x130d
159#define BT_MESH_MODEL_ID_LIGHT_XYL_CLI 0x130e
160#define BT_MESH_MODEL_ID_LIGHT_LC_SRV 0x130f
161#define BT_MESH_MODEL_ID_LIGHT_LC_SETUPSRV 0x1310
162#define BT_MESH_MODEL_ID_LIGHT_LC_CLI 0x1311
163
168
176
186 int (*const func)(struct bt_mesh_model *model,
187 struct bt_mesh_msg_ctx *ctx,
188 struct net_buf_simple *buf);
189};
190
191#define BT_MESH_MODEL_OP_1(b0) (b0)
192#define BT_MESH_MODEL_OP_2(b0, b1) (((b0) << 8) | (b1))
193#define BT_MESH_MODEL_OP_3(b0, cid) ((((b0) << 16) | 0xc00000) | (cid))
194
196#define BT_MESH_LEN_EXACT(len) (-len)
198#define BT_MESH_LEN_MIN(len) (len)
199
201#define BT_MESH_MODEL_OP_END { 0, 0, NULL }
203#define BT_MESH_MODEL_NO_OPS ((struct bt_mesh_model_op []) \
204 { BT_MESH_MODEL_OP_END })
205
207#define BT_MESH_MODEL_NONE ((struct bt_mesh_model []){})
208
219#define BT_MESH_MODEL_CB(_id, _op, _pub, _user_data, _cb) \
220{ \
221 .id = (_id), \
222 .pub = _pub, \
223 .keys = BT_MESH_MODEL_KEYS_UNUSED, \
224 .groups = BT_MESH_MODEL_GROUPS_UNASSIGNED, \
225 .op = _op, \
226 .cb = _cb, \
227 .user_data = _user_data, \
228}
229
241#define BT_MESH_MODEL_VND_CB(_company, _id, _op, _pub, _user_data, _cb) \
242{ \
243 .vnd.company = (_company), \
244 .vnd.id = (_id), \
245 .op = _op, \
246 .pub = _pub, \
247 .keys = BT_MESH_MODEL_KEYS_UNUSED, \
248 .groups = BT_MESH_MODEL_GROUPS_UNASSIGNED, \
249 .user_data = _user_data, \
250 .cb = _cb, \
251}
252
253
263#define BT_MESH_MODEL(_id, _op, _pub, _user_data) \
264 BT_MESH_MODEL_CB(_id, _op, _pub, _user_data, NULL)
265
276#define BT_MESH_MODEL_VND(_company, _id, _op, _pub, _user_data) \
277 BT_MESH_MODEL_VND_CB(_company, _id, _op, _pub, _user_data, NULL)
278
290#define BT_MESH_TRANSMIT(count, int_ms) ((count) | (((int_ms / 10) - 1) << 3))
291
300#define BT_MESH_TRANSMIT_COUNT(transmit) (((transmit) & (uint8_t)BIT_MASK(3)))
301
310#define BT_MESH_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 10)
311
323#define BT_MESH_PUB_TRANSMIT(count, int_ms) BT_MESH_TRANSMIT(count, \
324 (int_ms) / 5)
325
334#define BT_MESH_PUB_TRANSMIT_COUNT(transmit) BT_MESH_TRANSMIT_COUNT(transmit)
335
344#define BT_MESH_PUB_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 50)
345
354
377
393 int (*update)(struct bt_mesh_model *mod);
394
397};
398
407#define BT_MESH_MODEL_PUB_DEFINE(_name, _update, _msg_len) \
408 NET_BUF_SIMPLE_DEFINE_STATIC(bt_mesh_pub_msg_##_name, _msg_len); \
409 static struct bt_mesh_model_pub _name = { \
410 .msg = &bt_mesh_pub_msg_##_name, \
411 .update = _update, \
412 }
413
429 int (*const settings_set)(struct bt_mesh_model *model,
430 const char *name, size_t len_rd,
431 settings_read_cb read_cb, void *cb_arg);
432
445 int (*const start)(struct bt_mesh_model *model);
446
459 int (*const init)(struct bt_mesh_model *model);
460
471 void (*const reset)(struct bt_mesh_model *model);
472};
473
480};
481
484 union {
489 };
490
491 /* Internal information, mainly for persistent storage */
492 uint8_t elem_idx; /* Belongs to Nth element */
493 uint8_t mod_idx; /* Is the Nth model in the element */
494 uint16_t flags; /* Model flags for internal bookkeeping */
495
497 struct bt_mesh_model_pub * const pub;
498
500 uint16_t keys[CONFIG_BT_MESH_MODEL_KEY_COUNT];
501
503 uint16_t groups[CONFIG_BT_MESH_MODEL_GROUP_COUNT];
504
506 const struct bt_mesh_model_op * const op;
507
509 const struct bt_mesh_model_cb * const cb;
510
511#ifdef CONFIG_BT_MESH_MODEL_EXTENSIONS
512 /* Pointer to the next model in a model extension list. */
514#endif
515
518};
519
528 void (*start)(uint16_t duration, int err, void *cb_data);
534 void (*end)(int err, void *cb_data);
535};
536
537
539#define BT_MESH_TTL_DEFAULT 0xff
540
542#define BT_MESH_TTL_MAX 0x7f
543
555 struct bt_mesh_msg_ctx *ctx,
556 struct net_buf_simple *msg,
557 const struct bt_mesh_send_cb *cb,
558 void *cb_data);
559
574
582
592 uint16_t id);
593
604 uint16_t company, uint16_t id);
605
612static inline bool bt_mesh_model_in_primary(const struct bt_mesh_model *mod)
613{
614 return (mod->elem_idx == 0);
615}
616
629 const char *name, const void *data,
630 size_t data_len);
631
651int bt_mesh_model_extend(struct bt_mesh_model *extending_mod,
652 struct bt_mesh_model *base_mod);
653
661
668 size_t elem_count;
670};
671
672#ifdef __cplusplus
673}
674#endif
675
680#endif /* ZEPHYR_INCLUDE_BLUETOOTH_MESH_ACCESS_H_ */
void
Definition: eswifi_shell.c:15
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_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.
static bool bt_mesh_model_in_primary(const struct bt_mesh_model *mod)
Get whether the model is in the primary element of the device.
Definition: access.h:612
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.
int bt_mesh_model_send(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *msg, const struct bt_mesh_send_cb *cb, void *cb_data)
Send an Access Layer message.
ssize_t(* settings_read_cb)(void *cb_arg, void *data, size_t len)
Definition: settings.h:57
__SIZE_TYPE__ ssize_t
Definition: types.h:28
Message APIs.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT8_TYPE__ uint8_t
Definition: stdint.h:58
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
Definition: access.h:663
uint16_t pid
Definition: access.h:665
uint16_t cid
Definition: access.h:664
uint16_t vid
Definition: access.h:666
struct bt_mesh_elem * elem
Definition: access.h:669
size_t elem_count
Definition: access.h:668
Definition: access.h:87
struct bt_mesh_model *const models
Definition: access.h:99
const uint16_t loc
Definition: access.h:92
const uint8_t model_count
Definition: access.h:94
struct bt_mesh_model *const vnd_models
Definition: access.h:101
uint16_t addr
Definition: access.h:89
const uint8_t vnd_model_count
Definition: access.h:96
Definition: access.h:475
uint16_t company
Definition: access.h:477
uint16_t id
Definition: access.h:479
Definition: access.h:415
int(*const settings_set)(struct bt_mesh_model *model, const char *name, size_t len_rd, settings_read_cb read_cb, void *cb_arg)
Set value handler of user data tied to the model.
Definition: access.h:429
void(*const reset)(struct bt_mesh_model *model)
Model reset callback.
Definition: access.h:471
int(*const start)(struct bt_mesh_model *model)
Callback called when the mesh is started.
Definition: access.h:445
int(*const init)(struct bt_mesh_model *model)
Model init callback.
Definition: access.h:459
Definition: access.h:165
const uint32_t opcode
Definition: access.h:167
const ssize_t len
Definition: access.h:175
int(*const func)(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
Handler function for this opcode.
Definition: access.h:186
Definition: access.h:351
uint16_t key
Definition: access.h:356
int(* update)(struct bt_mesh_model *mod)
Callback for updating the publication buffer.
Definition: access.h:393
uint16_t cred
Definition: access.h:357
uint8_t retransmit
Definition: access.h:362
uint16_t addr
Definition: access.h:355
uint8_t count
Definition: access.h:365
uint8_t period_div
Definition: access.h:364
struct net_buf_simple * msg
Publication buffer, containing the publication message.
Definition: access.h:376
struct bt_mesh_model * mod
Definition: access.h:353
uint8_t ttl
Definition: access.h:361
uint32_t period_start
Definition: access.h:367
uint16_t send_rel
Definition: access.h:358
uint16_t fast_period
Definition: access.h:359
uint8_t period
Definition: access.h:363
struct k_work_delayable timer
Definition: access.h:396
Definition: access.h:483
uint8_t elem_idx
Definition: access.h:492
const struct bt_mesh_mod_id_vnd vnd
Definition: access.h:488
uint16_t keys[CONFIG_BT_MESH_MODEL_KEY_COUNT]
Definition: access.h:500
const struct bt_mesh_model_op *const op
Definition: access.h:506
uint16_t groups[CONFIG_BT_MESH_MODEL_GROUP_COUNT]
Definition: access.h:503
void * user_data
Definition: access.h:517
const struct bt_mesh_model_cb *const cb
Definition: access.h:509
uint16_t flags
Definition: access.h:494
const uint16_t id
Definition: access.h:486
uint8_t mod_idx
Definition: access.h:493
struct bt_mesh_model * next
Definition: access.h:513
struct bt_mesh_model_pub *const pub
Definition: access.h:497
Definition: msg.h:78
Definition: access.h:521
void(* start)(uint16_t duration, int err, void *cb_data)
Handler called at the start of the transmission.
Definition: access.h:528
void(* end)(int err, void *cb_data)
Handler called at the end of the transmission.
Definition: access.h:534
A structure used to submit work after a delay.
Definition: kernel.h:3651
Simple network buffer representation.
Definition: buf.h:87
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
Misc utilities.