10#ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_ACCESS_H_
11#define ZEPHYR_INCLUDE_BLUETOOTH_MESH_ACCESS_H_
19#define BT_MESH_KEY_UNUSED_ELT_(IDX, _) BT_MESH_KEY_UNUSED
20#define BT_MESH_ADDR_UNASSIGNED_ELT_(IDX, _) BT_MESH_ADDR_UNASSIGNED
21#define BT_MESH_UUID_UNASSIGNED_ELT_(IDX, _) NULL
22#define BT_MESH_MODEL_KEYS_UNUSED(_keys) \
23 { LISTIFY(_keys, BT_MESH_KEY_UNUSED_ELT_, (,)) }
24#define BT_MESH_MODEL_GROUPS_UNASSIGNED(_grps) \
25 { LISTIFY(_grps, BT_MESH_ADDR_UNASSIGNED_ELT_, (,)) }
26#if CONFIG_BT_MESH_LABEL_COUNT > 0
27#define BT_MESH_MODEL_UUIDS_UNASSIGNED() \
28 .uuids = (const uint8_t *[]){ LISTIFY(CONFIG_BT_MESH_LABEL_COUNT, \
29 BT_MESH_UUID_UNASSIGNED_ELT_, (,)) },
31#define BT_MESH_MODEL_UUIDS_UNASSIGNED()
34#define BT_MESH_MODEL_RUNTIME_INIT(_user_data) \
35 .rt = &(struct bt_mesh_model_rt_ctx){ .user_data = (_user_data) },
52#define BT_MESH_ADDR_UNASSIGNED 0x0000
53#define BT_MESH_ADDR_ALL_NODES 0xffff
54#define BT_MESH_ADDR_RELAYS 0xfffe
55#define BT_MESH_ADDR_FRIENDS 0xfffd
56#define BT_MESH_ADDR_PROXIES 0xfffc
57#define BT_MESH_ADDR_DFW_NODES 0xfffb
58#define BT_MESH_ADDR_IP_NODES 0xfffa
59#define BT_MESH_ADDR_IP_BR_ROUTERS 0xfff9
68#define BT_MESH_KEY_UNUSED 0xffff
69#define BT_MESH_KEY_ANY 0xffff
70#define BT_MESH_KEY_DEV 0xfffe
71#define BT_MESH_KEY_DEV_LOCAL BT_MESH_KEY_DEV
72#define BT_MESH_KEY_DEV_REMOTE 0xfffd
73#define BT_MESH_KEY_DEV_ANY 0xfffc
81#define BT_MESH_ADDR_IS_UNICAST(addr) ((addr) && (addr) < 0x8000)
85#define BT_MESH_ADDR_IS_GROUP(addr) ((addr) >= 0xc000 && (addr) < 0xff00)
89#define BT_MESH_ADDR_IS_FIXED_GROUP(addr) ((addr) >= 0xff00 && (addr) < 0xffff)
93#define BT_MESH_ADDR_IS_VIRTUAL(addr) ((addr) >= 0x8000 && (addr) < 0xc000)
97#define BT_MESH_ADDR_IS_RFU(addr) ((addr) >= 0xff00 && (addr) <= 0xfff8)
102#define BT_MESH_IS_DEV_KEY(key) (key == BT_MESH_KEY_DEV_LOCAL || \
103 key == BT_MESH_KEY_DEV_REMOTE)
106#define BT_MESH_APP_SEG_SDU_MAX 12
109#define BT_MESH_APP_UNSEG_SDU_MAX 15
112#if defined(CONFIG_BT_MESH_RX_SEG_MAX)
113#define BT_MESH_RX_SEG_MAX CONFIG_BT_MESH_RX_SEG_MAX
115#define BT_MESH_RX_SEG_MAX 0
119#if defined(CONFIG_BT_MESH_TX_SEG_MAX)
120#define BT_MESH_TX_SEG_MAX CONFIG_BT_MESH_TX_SEG_MAX
122#define BT_MESH_TX_SEG_MAX 0
126#define BT_MESH_TX_SDU_MAX MAX((BT_MESH_TX_SEG_MAX * \
127 BT_MESH_APP_SEG_SDU_MAX), \
128 BT_MESH_APP_UNSEG_SDU_MAX)
131#define BT_MESH_RX_SDU_MAX MAX((BT_MESH_RX_SEG_MAX * \
132 BT_MESH_APP_SEG_SDU_MAX), \
133 BT_MESH_APP_UNSEG_SDU_MAX)
144#define BT_MESH_ELEM(_loc, _mods, _vnd_mods) \
146 .rt = &(struct bt_mesh_elem_rt_ctx) { 0 }, \
148 .model_count = ARRAY_SIZE(_mods), \
149 .vnd_model_count = ARRAY_SIZE(_vnd_mods), \
151 .vnd_models = (_vnd_mods), \
202#define BT_MESH_MODEL_OP_1(b0) (b0)
203#define BT_MESH_MODEL_OP_2(b0, b1) (((b0) << 8) | (b1))
204#define BT_MESH_MODEL_OP_3(b0, cid) ((((b0) << 16) | 0xc00000) | (cid))
207#define BT_MESH_LEN_EXACT(len) (-len)
209#define BT_MESH_LEN_MIN(len) (len)
212#define BT_MESH_MODEL_OP_END { 0, 0, NULL }
214#if !defined(__cplusplus) || defined(__DOXYGEN__)
221#define BT_MESH_MODEL_NO_OPS ((struct bt_mesh_model_op []) \
222 { BT_MESH_MODEL_OP_END })
230#define BT_MESH_MODEL_NONE ((const struct bt_mesh_model []){})
249#define BT_MESH_MODEL_CNT_CB(_id, _op, _pub, _user_data, _keys, _grps, _cb) \
252 BT_MESH_MODEL_RUNTIME_INIT(_user_data) \
254 .keys = (uint16_t []) BT_MESH_MODEL_KEYS_UNUSED(_keys), \
256 .groups = (uint16_t []) BT_MESH_MODEL_GROUPS_UNASSIGNED(_grps), \
257 .groups_cnt = _grps, \
258 BT_MESH_MODEL_UUIDS_UNASSIGNED() \
281#define BT_MESH_MODEL_CNT_VND_CB(_company, _id, _op, _pub, _user_data, _keys, _grps, _cb) \
283 .vnd.company = (_company), \
285 BT_MESH_MODEL_RUNTIME_INIT(_user_data) \
288 .keys = (uint16_t []) BT_MESH_MODEL_KEYS_UNUSED(_keys), \
290 .groups = (uint16_t []) BT_MESH_MODEL_GROUPS_UNASSIGNED(_grps), \
291 .groups_cnt = _grps, \
292 BT_MESH_MODEL_UUIDS_UNASSIGNED() \
308#define BT_MESH_MODEL_CB(_id, _op, _pub, _user_data, _cb) \
309 BT_MESH_MODEL_CNT_CB(_id, _op, _pub, _user_data, \
310 CONFIG_BT_MESH_MODEL_KEY_COUNT, \
311 CONFIG_BT_MESH_MODEL_GROUP_COUNT, _cb)
329#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV)
330#define BT_MESH_MODEL_METADATA_CB(_id, _op, _pub, _user_data, _cb, _metadata) \
333 BT_MESH_MODEL_RUNTIME_INIT(_user_data) \
335 .keys = (uint16_t []) BT_MESH_MODEL_KEYS_UNUSED(CONFIG_BT_MESH_MODEL_KEY_COUNT), \
336 .keys_cnt = CONFIG_BT_MESH_MODEL_KEY_COUNT, \
337 .groups = (uint16_t []) BT_MESH_MODEL_GROUPS_UNASSIGNED(CONFIG_BT_MESH_MODEL_GROUP_COUNT), \
338 .groups_cnt = CONFIG_BT_MESH_MODEL_GROUP_COUNT, \
339 BT_MESH_MODEL_UUIDS_UNASSIGNED() \
342 .metadata = _metadata, \
345#define BT_MESH_MODEL_METADATA_CB(_id, _op, _pub, _user_data, _cb, _metadata) \
346 BT_MESH_MODEL_CB(_id, _op, _pub, _user_data, _cb)
363#define BT_MESH_MODEL_VND_CB(_company, _id, _op, _pub, _user_data, _cb) \
364 BT_MESH_MODEL_CNT_VND_CB(_company, _id, _op, _pub, _user_data, \
365 CONFIG_BT_MESH_MODEL_KEY_COUNT, \
366 CONFIG_BT_MESH_MODEL_GROUP_COUNT, _cb)
384#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV)
385#define BT_MESH_MODEL_VND_METADATA_CB(_company, _id, _op, _pub, _user_data, _cb, _metadata) \
387 .vnd.company = (_company), \
389 BT_MESH_MODEL_RUNTIME_INIT(_user_data) \
392 .keys = (uint16_t []) BT_MESH_MODEL_KEYS_UNUSED(CONFIG_BT_MESH_MODEL_KEY_COUNT), \
393 .keys_cnt = CONFIG_BT_MESH_MODEL_KEY_COUNT, \
394 .groups = (uint16_t []) BT_MESH_MODEL_GROUPS_UNASSIGNED(CONFIG_BT_MESH_MODEL_GROUP_COUNT), \
395 .groups_cnt = CONFIG_BT_MESH_MODEL_GROUP_COUNT, \
396 BT_MESH_MODEL_UUIDS_UNASSIGNED() \
398 .metadata = _metadata, \
401#define BT_MESH_MODEL_VND_METADATA_CB(_company, _id, _op, _pub, _user_data, _cb, _metadata) \
402 BT_MESH_MODEL_VND_CB(_company, _id, _op, _pub, _user_data, _cb)
415#define BT_MESH_MODEL(_id, _op, _pub, _user_data) \
416 BT_MESH_MODEL_CB(_id, _op, _pub, _user_data, NULL)
430#define BT_MESH_MODEL_VND(_company, _id, _op, _pub, _user_data) \
431 BT_MESH_MODEL_VND_CB(_company, _id, _op, _pub, _user_data, NULL)
444#define BT_MESH_TRANSMIT(count, int_ms) ((uint8_t)((count) | (((int_ms / 10) - 1) << 3)))
453#define BT_MESH_TRANSMIT_COUNT(transmit) (((transmit) & (uint8_t)BIT_MASK(3)))
462#define BT_MESH_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 10)
474#define BT_MESH_PUB_TRANSMIT(count, int_ms) BT_MESH_TRANSMIT(count, \
484#define BT_MESH_PUB_TRANSMIT_COUNT(transmit) BT_MESH_TRANSMIT_COUNT(transmit)
493#define BT_MESH_PUB_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 50)
503#define BT_MESH_PUB_MSG_TOTAL(pub) (BT_MESH_PUB_TRANSMIT_COUNT((pub)->retransmit) + 1)
514#define BT_MESH_PUB_MSG_NUM(pub) (BT_MESH_PUB_TRANSMIT_COUNT((pub)->retransmit) + 1 - (pub)->count)
583#define BT_MESH_MODEL_PUB_DEFINE(_name, _update, _msg_len) \
584 NET_BUF_SIMPLE_DEFINE_STATIC(bt_mesh_pub_msg_##_name, _msg_len); \
585 static struct bt_mesh_model_pub _name = { \
586 .msg = &bt_mesh_pub_msg_##_name, \
614#define BT_MESH_MODELS_METADATA_ENTRY(_len, _id, _data) \
616 .len = (_len), .id = _id, .data = _data, \
620#define BT_MESH_MODELS_METADATA_NONE NULL
623#define BT_MESH_MODELS_METADATA_END { 0, 0, NULL }
641 const char *name,
size_t len_rd,
718#ifdef CONFIG_BT_MESH_MODEL_EXTENSIONS
737#if (CONFIG_BT_MESH_LABEL_COUNT > 0) || defined(__DOXYGEN__)
748#if defined(CONFIG_BT_MESH_LARGE_COMP_DATA_SRV) || defined(__DOXYGEN__)
768 void (*
end)(
int err,
void *cb_data);
773#define BT_MESH_TTL_DEFAULT 0xff
776#define BT_MESH_TTL_MAX 0x7f
876 const char *name,
const void *data,
Bluetooth Assigned Numbers, codes and identifiers.
int bt_mesh_model_correspond(const struct bt_mesh_model *corresponding_mod, const struct bt_mesh_model *base_mod)
Let a model correspond to another.
int bt_mesh_model_publish(const struct bt_mesh_model *model)
Send a model publication message.
bool bt_mesh_model_is_extended(const struct bt_mesh_model *model)
Check if model is extended by another model.
#define BT_MESH_PUB_TRANSMIT_COUNT(transmit)
Decode Publish Retransmit count from a given value.
Definition access.h:484
static bool bt_mesh_model_pub_is_retransmission(const struct bt_mesh_model *model)
Check if a message is being retransmitted.
Definition access.h:817
int bt_mesh_models_metadata_change_prepare(void)
Indicate that the metadata will change on next bootup.
void bt_mesh_model_data_store_schedule(const struct bt_mesh_model *mod)
Schedule the model's user data store in persistent storage.
int bt_mesh_model_send(const 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.
int bt_mesh_comp2_register(const struct bt_mesh_comp2 *comp2)
Register composition data page 2 of the device.
int bt_mesh_comp_change_prepare(void)
Indicate that the composition data will change on next bootup.
const struct bt_mesh_elem * bt_mesh_model_elem(const struct bt_mesh_model *mod)
Get the element that a model belongs to.
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:859
const 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_data_store(const 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.
const 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_extend(const struct bt_mesh_model *extending_mod, const struct bt_mesh_model *base_mod)
Let a model extend another.
ssize_t(* settings_read_cb)(void *cb_arg, void *data, size_t len)
Function used to read the data from the settings storage in h_set handler implementations.
Definition settings.h:64
__SIZE_TYPE__ ssize_t
Definition types.h:28
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Composition data page 2 record.
Definition access.h:978
uint16_t id
Mesh profile ID.
Definition access.h:980
struct bt_mesh_comp2_record::@315261044123040067132243322322175125334172045074 version
Mesh Profile Version.
uint8_t y
Minor version.
Definition access.h:986
uint8_t x
Major version.
Definition access.h:984
const uint8_t * elem_offset
Element offset list.
Definition access.h:993
uint16_t data_len
Length of additional data.
Definition access.h:995
uint8_t z
Z version.
Definition access.h:988
const void * data
Additional data.
Definition access.h:997
uint8_t elem_offset_cnt
Element offset count.
Definition access.h:991
Node Composition data page 2.
Definition access.h:1001
size_t record_cnt
The number of Mesh Profile records on a device.
Definition access.h:1003
const struct bt_mesh_comp2_record * record
List of records.
Definition access.h:1005
Node Composition.
Definition access.h:968
uint16_t pid
Product ID.
Definition access.h:970
uint16_t cid
Company ID.
Definition access.h:969
uint16_t vid
Version ID.
Definition access.h:971
const struct bt_mesh_elem * elem
List of elements.
Definition access.h:974
size_t elem_count
The number of elements in this device.
Definition access.h:973
Mesh Element runtime information.
Definition access.h:157
uint16_t addr
Unicast Address.
Definition access.h:159
Abstraction that describes a Mesh Element.
Definition access.h:155
struct bt_mesh_elem::bt_mesh_elem_rt_ctx rt
const struct bt_mesh_model *const models
The list of SIG models in this element.
Definition access.h:170
const uint16_t loc
Location Descriptor (GATT Bluetooth Namespace Descriptors)
Definition access.h:163
const uint8_t model_count
The number of SIG models in this element.
Definition access.h:165
const struct bt_mesh_model *const vnd_models
The list of vendor models in this element.
Definition access.h:172
const uint8_t vnd_model_count
The number of vendor models in this element.
Definition access.h:167
Vendor model ID.
Definition access.h:696
uint16_t company
Vendor's company ID.
Definition access.h:698
uint16_t id
Model ID.
Definition access.h:700
const struct bt_mesh_model * next
Definition access.h:720
void * user_data
Model-specific user data.
Definition access.h:723
uint8_t mod_idx
Definition access.h:715
uint16_t flags
Definition access.h:716
uint8_t elem_idx
Definition access.h:714
Model callback functions.
Definition access.h:626
int(*const init)(const struct bt_mesh_model *model)
Model init callback.
Definition access.h:670
int(*const settings_set)(const 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:640
void(*const reset)(const struct bt_mesh_model *model)
Model reset callback.
Definition access.h:682
int(*const start)(const struct bt_mesh_model *model)
Callback called when the mesh is started.
Definition access.h:656
void(*const pending_store)(const struct bt_mesh_model *model)
Callback used to store pending model's user data.
Definition access.h:692
Model opcode handler.
Definition access.h:176
const uint32_t opcode
OpCode encoded using the BT_MESH_MODEL_OP_* macros.
Definition access.h:178
const ssize_t len
Message length.
Definition access.h:186
int(*const func)(const struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf)
Handler function for this opcode.
Definition access.h:197
Model publication context.
Definition access.h:521
int(* update)(const struct bt_mesh_model *mod)
Callback for updating the publication buffer.
Definition access.h:570
uint16_t key
Publish AppKey Index.
Definition access.h:527
uint16_t retr_update
Call update callback on every retransmission.
Definition access.h:531
uint8_t delayable
Use random delay for publishing.
Definition access.h:539
uint16_t cred
Friendship Credentials Flag.
Definition access.h:528
uint8_t retransmit
Retransmit Count & Interval Steps.
Definition access.h:534
uint16_t addr
Publish Address.
Definition access.h:525
uint8_t count
Transmissions left.
Definition access.h:537
uint8_t period_div
Divisor for the Period.
Definition access.h:536
struct net_buf_simple * msg
Publication buffer, containing the publication message.
Definition access.h:550
uint8_t ttl
Publish Time to Live.
Definition access.h:533
const struct bt_mesh_model * mod
The model the context belongs to.
Definition access.h:523
uint32_t period_start
Start of the current period.
Definition access.h:541
uint16_t send_rel
Force reliable sending (segment acks)
Definition access.h:529
uint16_t fast_period
Use FastPeriodDivisor.
Definition access.h:530
const uint8_t * uuid
Label UUID if Publish Address is Virtual Address.
Definition access.h:526
uint8_t period
Publish Period.
Definition access.h:535
struct k_work_delayable timer
Publish Period Timer.
Definition access.h:573
Abstraction that describes a Mesh Model instance.
Definition access.h:704
const uint8_t **const uuids
List of Label UUIDs the model is subscribed to.
Definition access.h:739
const struct bt_mesh_mod_id_vnd vnd
Vendor model ID.
Definition access.h:709
struct bt_mesh_model::bt_mesh_model_rt_ctx rt
uint16_t *const groups
Subscription List (group or virtual addresses)
Definition access.h:734
const struct bt_mesh_model_op *const op
Opcode handler list.
Definition access.h:743
uint16_t *const keys
AppKey List.
Definition access.h:730
const struct bt_mesh_model_cb *const cb
Model callback structure.
Definition access.h:746
const uint16_t keys_cnt
Definition access.h:731
const uint16_t id
SIG model ID.
Definition access.h:707
const uint16_t groups_cnt
Definition access.h:735
struct bt_mesh_model_pub *const pub
Model Publication.
Definition access.h:727
const struct bt_mesh_models_metadata_entry *const metadata
Definition access.h:750
Models Metadata Entry struct.
Definition access.h:595
const uint16_t len
Definition access.h:597
const void *const data
Definition access.h:603
const uint16_t id
Definition access.h:600
Message sending context.
Definition msg.h:76
Callback structure for monitoring model message sending.
Definition access.h:755
void(* start)(uint16_t duration, int err, void *cb_data)
Handler called at the start of the transmission.
Definition access.h:762
void(* end)(int err, void *cb_data)
Handler called at the end of the transmission.
Definition access.h:768
A structure used to submit work after a delay.
Definition kernel.h:4322
Simple network buffer representation.
Definition net_buf.h:89