1 /** @file
2 * @brief Bluetooth Mesh Access Layer APIs.
3 */
4
5 /*
6 * SPDX-FileCopyrightText: 2017 Intel Corporation
7 * SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
8 *
9 * SPDX-License-Identifier: Apache-2.0
10 */
11 #ifndef _BLE_MESH_ACCESS_H_
12 #define _BLE_MESH_ACCESS_H_
13
14 #include "mesh_config.h"
15 #include "mesh_buf.h"
16 #include "mesh_timer.h"
17
18 /**
19 * @brief Bluetooth Mesh Access Layer
20 * @defgroup bt_mesh_access Bluetooth Mesh Access Layer
21 * @ingroup bt_mesh
22 * @{
23 */
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #define BLE_MESH_CID_NVAL 0xFFFF
30
31 #define BLE_MESH_ADDR_UNASSIGNED 0x0000
32 #define BLE_MESH_ADDR_ALL_NODES 0xffff
33 #define BLE_MESH_ADDR_PROXIES 0xfffc
34 #define BLE_MESH_ADDR_FRIENDS 0xfffd
35 #define BLE_MESH_ADDR_RELAYS 0xfffe
36
37 #define BLE_MESH_KEY_UNUSED 0xffff
38 #define BLE_MESH_KEY_DEV 0xfffe
39
40 /** Helper to define a mesh element within an array.
41 *
42 * In case the element has no SIG or Vendor models the helper
43 * macro BLE_MESH_MODEL_NONE can be given instead.
44 *
45 * @param _loc Location Descriptor.
46 * @param _mods Array of models.
47 * @param _vnd_mods Array of vendor models.
48 */
49 #define BLE_MESH_ELEM(_loc, _mods, _vnd_mods) \
50 { \
51 .loc = (_loc), \
52 .model_count = ARRAY_SIZE(_mods), \
53 .vnd_model_count = ARRAY_SIZE(_vnd_mods), \
54 .models = (_mods), \
55 .vnd_models = (_vnd_mods), \
56 }
57
58 /** Abstraction that describes a Mesh Element */
59 struct bt_mesh_elem {
60 /* Unicast Address. Set at runtime during provisioning. */
61 uint16_t addr;
62
63 /* Location Descriptor (GATT Bluetooth Namespace Descriptors) */
64 const uint16_t loc;
65
66 const uint8_t model_count;
67 const uint8_t vnd_model_count;
68
69 struct bt_mesh_model *const models;
70 struct bt_mesh_model *const vnd_models;
71 };
72
73 /* Foundation Models */
74 #define BLE_MESH_MODEL_ID_CFG_SRV 0x0000
75 #define BLE_MESH_MODEL_ID_CFG_CLI 0x0001
76 #define BLE_MESH_MODEL_ID_HEALTH_SRV 0x0002
77 #define BLE_MESH_MODEL_ID_HEALTH_CLI 0x0003
78
79 /* Models from the Mesh Model Specification */
80 #define BLE_MESH_MODEL_ID_GEN_ONOFF_SRV 0x1000
81 #define BLE_MESH_MODEL_ID_GEN_ONOFF_CLI 0x1001
82 #define BLE_MESH_MODEL_ID_GEN_LEVEL_SRV 0x1002
83 #define BLE_MESH_MODEL_ID_GEN_LEVEL_CLI 0x1003
84 #define BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV 0x1004
85 #define BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI 0x1005
86 #define BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV 0x1006
87 #define BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV 0x1007
88 #define BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI 0x1008
89 #define BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV 0x1009
90 #define BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV 0x100a
91 #define BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI 0x100b
92 #define BLE_MESH_MODEL_ID_GEN_BATTERY_SRV 0x100c
93 #define BLE_MESH_MODEL_ID_GEN_BATTERY_CLI 0x100d
94 #define BLE_MESH_MODEL_ID_GEN_LOCATION_SRV 0x100e
95 #define BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV 0x100f
96 #define BLE_MESH_MODEL_ID_GEN_LOCATION_CLI 0x1010
97 #define BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV 0x1011
98 #define BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV 0x1012
99 #define BLE_MESH_MODEL_ID_GEN_USER_PROP_SRV 0x1013
100 #define BLE_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV 0x1014
101 #define BLE_MESH_MODEL_ID_GEN_PROP_CLI 0x1015
102 #define BLE_MESH_MODEL_ID_SENSOR_SRV 0x1100
103 #define BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV 0x1101
104 #define BLE_MESH_MODEL_ID_SENSOR_CLI 0x1102
105 #define BLE_MESH_MODEL_ID_TIME_SRV 0x1200
106 #define BLE_MESH_MODEL_ID_TIME_SETUP_SRV 0x1201
107 #define BLE_MESH_MODEL_ID_TIME_CLI 0x1202
108 #define BLE_MESH_MODEL_ID_SCENE_SRV 0x1203
109 #define BLE_MESH_MODEL_ID_SCENE_SETUP_SRV 0x1204
110 #define BLE_MESH_MODEL_ID_SCENE_CLI 0x1205
111 #define BLE_MESH_MODEL_ID_SCHEDULER_SRV 0x1206
112 #define BLE_MESH_MODEL_ID_SCHEDULER_SETUP_SRV 0x1207
113 #define BLE_MESH_MODEL_ID_SCHEDULER_CLI 0x1208
114 #define BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV 0x1300
115 #define BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV 0x1301
116 #define BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI 0x1302
117 #define BLE_MESH_MODEL_ID_LIGHT_CTL_SRV 0x1303
118 #define BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV 0x1304
119 #define BLE_MESH_MODEL_ID_LIGHT_CTL_CLI 0x1305
120 #define BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV 0x1306
121 #define BLE_MESH_MODEL_ID_LIGHT_HSL_SRV 0x1307
122 #define BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV 0x1308
123 #define BLE_MESH_MODEL_ID_LIGHT_HSL_CLI 0x1309
124 #define BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV 0x130a
125 #define BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV 0x130b
126 #define BLE_MESH_MODEL_ID_LIGHT_XYL_SRV 0x130c
127 #define BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV 0x130d
128 #define BLE_MESH_MODEL_ID_LIGHT_XYL_CLI 0x130e
129 #define BLE_MESH_MODEL_ID_LIGHT_LC_SRV 0x130f
130 #define BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV 0x1310
131 #define BLE_MESH_MODEL_ID_LIGHT_LC_CLI 0x1311
132
133 /** Message sending context. */
134 struct bt_mesh_msg_ctx {
135 /** NetKey Index of the subnet to send the message on. */
136 uint16_t net_idx;
137
138 /** AppKey Index to encrypt the message with. */
139 uint16_t app_idx;
140
141 /** Remote address. */
142 uint16_t addr;
143
144 /** Destination address of a received message. Not used for sending. */
145 uint16_t recv_dst;
146
147 /** RSSI of received packet. Not used for sending. */
148 int8_t recv_rssi;
149
150 /** Received TTL value. Not used for sending. */
151 uint8_t recv_ttl: 7;
152
153 /** Force sending reliably by using segment acknowledgement */
154 uint8_t send_rel: 1;
155
156 /** TTL, or BLE_MESH_TTL_DEFAULT for default TTL. */
157 uint8_t send_ttl;
158
159 /** Change by Espressif, opcode of a received message.
160 * Not used for sending message. */
161 uint32_t recv_op;
162
163 /** Change by Espressif, model corresponds to the message */
164 struct bt_mesh_model *model;
165
166 /** Change by Espressif, if the message is sent by a server
167 * model. Not used for receiving message. */
168 bool srv_send;
169 };
170
171 struct bt_mesh_model_op {
172 /* OpCode encoded using the BLE_MESH_MODEL_OP_* macros */
173 const uint32_t opcode;
174
175 /* Minimum required message length */
176 const size_t min_len;
177
178 /* Message handler for the opcode */
179 void (*const func)(struct bt_mesh_model *model,
180 struct bt_mesh_msg_ctx *ctx,
181 struct net_buf_simple *buf);
182 };
183
184 #define BLE_MESH_MODEL_OP_1(b0) (b0)
185 #define BLE_MESH_MODEL_OP_2(b0, b1) (((b0) << 8) | (b1))
186 #define BLE_MESH_MODEL_OP_3(b0, cid) ((((b0) << 16) | 0xc00000) | (cid))
187
188 #define BLE_MESH_MODEL_OP_END { 0, 0, NULL }
189 #define BLE_MESH_MODEL_NO_OPS ((struct bt_mesh_model_op []) \
190 { BLE_MESH_MODEL_OP_END })
191
192 /** Helper to define an empty model array */
193 #define BLE_MESH_MODEL_NONE ((struct bt_mesh_model []){})
194
195 /** Length of a short Mesh MIC. */
196 #define BLE_MESH_MIC_SHORT 4
197 /** Length of a long Mesh MIC. */
198 #define BLE_MESH_MIC_LONG 8
199
200 /** @def BLE_MESH_MODEL_OP_LEN
201 *
202 * @brief Helper to determine the length of an opcode.
203 *
204 * @param _op Opcode.
205 */
206 #define BLE_MESH_MODEL_OP_LEN(_op) ((_op) <= 0xff ? 1 : (_op) <= 0xffff ? 2 : 3)
207
208 /** @def BLE_MESH_MODEL_BUF_LEN
209 *
210 * @brief Helper for model message buffer length.
211 *
212 * Returns the length of a Mesh model message buffer, including the opcode
213 * length and a short MIC.
214 *
215 * @param _op Opcode of the message.
216 * @param _payload_len Length of the model payload.
217 */
218 #define BLE_MESH_MODEL_BUF_LEN(_op, _payload_len) \
219 (BLE_MESH_MODEL_OP_LEN(_op) + (_payload_len) + BLE_MESH_MIC_SHORT)
220
221 /** @def BLE_MESH_MODEL_BUF_LEN_LONG_MIC
222 *
223 * @brief Helper for model message buffer length.
224 *
225 * Returns the length of a Mesh model message buffer, including the opcode
226 * length and a long MIC.
227 *
228 * @param _op Opcode of the message.
229 * @param _payload_len Length of the model payload.
230 */
231 #define BLE_MESH_MODEL_BUF_LEN_LONG_MIC(_op, _payload_len) \
232 (BLE_MESH_MODEL_OP_LEN(_op) + (_payload_len) + BLE_MESH_MIC_LONG)
233
234 /** @def BLE_MESH_MODEL_BUF_DEFINE
235 *
236 * @brief Define a Mesh model message buffer using @ref NET_BUF_SIMPLE_DEFINE.
237 *
238 * @param _buf Buffer name.
239 * @param _op Opcode of the message.
240 * @param _payload_len Length of the model message payload.
241 */
242 #define BLE_MESH_MODEL_BUF_DEFINE(_buf, _op, _payload_len) \
243 NET_BUF_SIMPLE_DEFINE(_buf, BLE_MESH_MODEL_BUF_LEN((_op), (_payload_len)))
244
245 /** @def BLE_MESH_MODEL_CB
246 *
247 * @brief Composition data SIG model entry with callback functions.
248 *
249 * @param _id Model ID.
250 * @param _op Array of model opcode handlers.
251 * @param _pub Model publish parameters.
252 * @param _user_data User data for the model.
253 * @param _cb Callback structure, or NULL to keep no callbacks.
254 */
255 #define BLE_MESH_MODEL_CB(_id, _op, _pub, _user_data, _cb) \
256 { \
257 .id = (_id), \
258 .pub = (_pub), \
259 .keys = ESP_BLE_MESH_MODEL_KEYS_UNUSED, \
260 .groups = ESP_BLE_MESH_MODEL_GROUPS_UNASSIGNED, \
261 .op = (_op), \
262 .cb = (_cb), \
263 .user_data = (_user_data), \
264 }
265
266 /** @def BLE_MESH_MODEL_VND_CB
267 *
268 * @brief Composition data vendor model entry with callback functions.
269 *
270 * @param _company Company ID.
271 * @param _id Model ID.
272 * @param _op Array of model opcode handlers.
273 * @param _pub Model publish parameters.
274 * @param _user_data User data for the model.
275 * @param _cb Callback structure, or NULL to keep no callbacks.
276 */
277 #define BLE_MESH_MODEL_VND_CB(_company, _id, _op, _pub, _user_data, _cb) \
278 { \
279 .vnd.company = (_company), \
280 .vnd.id = (_id), \
281 .pub = (_pub), \
282 .keys = ESP_BLE_MESH_MODEL_KEYS_UNUSED, \
283 .groups = ESP_BLE_MESH_MODEL_GROUPS_UNASSIGNED, \
284 .op = (_op), \
285 .cb = (_cb), \
286 .user_data = (_user_data), \
287 }
288
289 /** @def BLE_MESH_TRANSMIT
290 *
291 * @brief Encode transmission count & interval steps.
292 *
293 * @param count Number of retransmissions (first transmission is excluded).
294 * @param int_ms Interval steps in milliseconds. Must be greater than 0
295 * and a multiple of 10.
296 *
297 * @return Mesh transmit value that can be used e.g. for the default
298 * values of the configuration model data.
299 */
300 #define BLE_MESH_TRANSMIT(count, int_ms) ((count) | ((((int_ms) / 10) - 1) << 3))
301
302 /** @def BLE_MESH_TRANSMIT_COUNT
303 *
304 * @brief Decode transmit count from a transmit value.
305 *
306 * @param transmit Encoded transmit count & interval value.
307 *
308 * @return Transmission count (actual transmissions is N + 1).
309 */
310 #define BLE_MESH_TRANSMIT_COUNT(transmit) (((transmit) & (uint8_t)BIT_MASK(3)))
311
312 /** @def BLE_MESH_TRANSMIT_INT
313 *
314 * @brief Decode transmit interval from a transmit value.
315 *
316 * @param transmit Encoded transmit count & interval value.
317 *
318 * @return Transmission interval in milliseconds.
319 */
320 #define BLE_MESH_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 10)
321
322 /** @def BLE_MESH_PUB_TRANSMIT
323 *
324 * @brief Encode Publish Retransmit count & interval steps.
325 *
326 * @param count Number of retransmissions (first transmission is excluded).
327 * @param int_ms Interval steps in milliseconds. Must be greater than 0
328 * and a multiple of 50.
329 *
330 * @return Mesh transmit value that can be used e.g. for the default
331 * values of the configuration model data.
332 */
333 #define BLE_MESH_PUB_TRANSMIT(count, int_ms) BLE_MESH_TRANSMIT((count), (int_ms) / 5)
334
335 /** @def BLE_MESH_PUB_TRANSMIT_COUNT
336 *
337 * @brief Decode Publish Retransmit count from a given value.
338 *
339 * @param transmit Encoded Publish Retransmit count & interval value.
340 *
341 * @return Retransmission count (actual transmissions is N + 1).
342 */
343 #define BLE_MESH_PUB_TRANSMIT_COUNT(transmit) BLE_MESH_TRANSMIT_COUNT(transmit)
344
345 /** @def BLE_MESH_PUB_TRANSMIT_INT
346 *
347 * @brief Decode Publish Retransmit interval from a given value.
348 *
349 * @param transmit Encoded Publish Retransmit count & interval value.
350 *
351 * @return Transmission interval in milliseconds.
352 */
353 #define BLE_MESH_PUB_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 50)
354
355 /** Model publication context. */
356 struct bt_mesh_model_pub {
357 /** The model the context belongs to. Initialized by the stack. */
358 struct bt_mesh_model *mod;
359
360 uint16_t addr; /**< Publish Address. */
361 uint16_t key:12, /**< Publish AppKey Index. */
362 cred:1, /**< Friendship Credentials Flag. */
363 send_rel:1; /**< Force reliable sending (segment acks) */
364
365 uint8_t ttl; /**< Publish Time to Live. */
366 uint8_t retransmit; /**< Retransmit Count & Interval Steps. */
367 uint8_t period; /**< Publish Period. */
368 uint8_t period_div:4, /**< Divisor for the Period. */
369 fast_period:1, /**< Use FastPeriodDivisor */
370 count:3; /**< Retransmissions left. */
371
372 uint32_t period_start; /**< Start of the current period. */
373
374 /** @brief Publication buffer, containing the publication message.
375 *
376 * This will get correctly created when the publication context
377 * has been defined using the BLE_MESH_MODEL_PUB_DEFINE macro.
378 *
379 * BLE_MESH_MODEL_PUB_DEFINE(name, update, size);
380 */
381 struct net_buf_simple *msg;
382
383 /** @brief Callback for updating the publication buffer.
384 *
385 * When set to NULL, the model is assumed not to support
386 * periodic publishing. When set to non-NULL the callback
387 * will be called periodically and is expected to update
388 * @ref bt_mesh_model_pub.msg with a valid publication
389 * message.
390 *
391 * If the callback returns non-zero, the publication is skipped
392 * and will resume on the next periodic publishing interval.
393 *
394 * @param mod The Model the Publication Context belongs to.
395 *
396 * @return Zero on success or (negative) error code otherwise.
397 */
398 int (*update)(struct bt_mesh_model *mod);
399
400 /** Publish Period Timer. Only for stack-internal use. */
401 struct k_delayed_work timer;
402
403 /* Change by Espressif, role of the device going to publish messages */
404 uint8_t dev_role;
405 };
406
407 /** @def BLE_MESH_MODEL_PUB_DEFINE
408 *
409 * Define a model publication context.
410 *
411 * @param _name Variable name given to the context.
412 * @param _update Optional message update callback (may be NULL).
413 * @param _msg_len Length of the publication message.
414 */
415 #define BLE_MESH_MODEL_PUB_DEFINE(_name, _update, _msg_len) \
416 NET_BUF_SIMPLE_DEFINE_STATIC(bt_mesh_pub_msg_##_name, _msg_len); \
417 static struct bt_mesh_model_pub _name = { \
418 .msg = &bt_mesh_pub_msg_##_name, \
419 .update = _update, \
420 }
421
422 /** Model callback functions. */
423 struct bt_mesh_model_cb {
424 /** @brief Model init callback.
425 *
426 * Called on every model instance during mesh initialization.
427 *
428 * If any of the model init callbacks return an error, the mesh
429 * subsystem initialization will be aborted, and the error will
430 * be returned to the caller of @ref bt_mesh_init.
431 *
432 * @param model Model to be initialized.
433 *
434 * @return 0 on success, error otherwise.
435 */
436 int (*const init)(struct bt_mesh_model *model);
437
438 #if CONFIG_BLE_MESH_DEINIT
439 /** @brief Model deinit callback.
440 *
441 * Called on every model instance during mesh deinitialization.
442 * All model data is deleted, and the model should clear its state.
443 *
444 * If any of the model deinit callbacks return an error, the mesh
445 * subsystem deinitialization will be aborted, and the error will
446 * be returned to the caller of @ref bt_mesh_deinit.
447 *
448 * @param model Model to be de-initialized.
449 */
450 int (*const deinit)(struct bt_mesh_model *model);
451 #endif /* CONFIG_BLE_MESH_DEINIT */
452 };
453
454 /** Abstraction that describes a Mesh Model instance */
455 struct bt_mesh_model {
456 union {
457 const uint16_t id;
458 struct {
459 uint16_t company;
460 uint16_t id;
461 } vnd;
462 };
463
464 /* Internal information, mainly for persistent storage */
465 uint8_t elem_idx; /* Belongs to Nth element */
466 uint8_t model_idx; /* Is the Nth model in the element */
467 uint16_t flags; /* Information about what has changed */
468
469 /* The Element this Model belongs to */
470 struct bt_mesh_elem *elem;
471
472 /* Model Publication */
473 struct bt_mesh_model_pub *const pub;
474
475 /* AppKey List */
476 uint16_t keys[CONFIG_BLE_MESH_MODEL_KEY_COUNT];
477
478 /* Subscription List (group or virtual addresses) */
479 uint16_t groups[CONFIG_BLE_MESH_MODEL_GROUP_COUNT];
480
481 /** Opcode handler list */
482 const struct bt_mesh_model_op *const op;
483
484 /** Model callback structure. */
485 const struct bt_mesh_model_cb *const cb;
486
487 /* Model-specific user data */
488 void *user_data;
489 };
490
491 struct bt_mesh_send_cb {
492 void (*start)(uint16_t duration, int err, void *cb_data);
493 void (*end)(int err, void *cb_data);
494 };
495
496 void bt_mesh_model_msg_init(struct net_buf_simple *msg, uint32_t opcode);
497
498 /** Special TTL value to request using configured default TTL */
499 #define BLE_MESH_TTL_DEFAULT 0xff
500
501 /** Maximum allowed TTL value */
502 #define BLE_MESH_TTL_MAX 0x7f
503
504 /**
505 * @brief Send an Access Layer message.
506 *
507 * @param model Mesh (client) Model that the message belongs to.
508 * @param ctx Message context, includes keys, TTL, etc.
509 * @param msg Access Layer payload (the actual message to be sent).
510 * @param cb Optional "message sent" callback.
511 * @param cb_data User data to be passed to the callback.
512 *
513 * @return 0 on success, or (negative) error code on failure.
514 */
515 int bt_mesh_model_send(struct bt_mesh_model *model,
516 struct bt_mesh_msg_ctx *ctx,
517 struct net_buf_simple *msg,
518 const struct bt_mesh_send_cb *cb,
519 void *cb_data);
520
521 /**
522 * @brief Send a model publication message.
523 *
524 * Before calling this function, the user needs to ensure that the model
525 * publication message (@ref bt_mesh_model_pub.msg) contains a valid
526 * message to be sent. Note that this API is only to be used for
527 * non-period publishing. For periodic publishing the app only needs
528 * to make sure that @ref bt_mesh_model_pub.msg contains a valid message
529 * whenever the @ref bt_mesh_model_pub.update callback is called.
530 *
531 * @param model Mesh (client) Model that's publishing the message.
532 *
533 * @return 0 on success, or (negative) error code on failure.
534 */
535 int bt_mesh_model_publish(struct bt_mesh_model *model);
536
537 /**
538 * @brief Get the element that a model belongs to.
539 *
540 * @param mod Mesh model.
541 *
542 * @return Pointer to the element that the given model belongs to.
543 */
544 struct bt_mesh_elem *bt_mesh_model_elem(struct bt_mesh_model *mod);
545
546 /** @brief Find a SIG model.
547 *
548 * @param elem Element to search for the model in.
549 * @param id Model ID of the model.
550 *
551 * @return A pointer to the Mesh model matching the given parameters, or NULL
552 * if no SIG model with the given ID exists in the given element.
553 */
554 struct bt_mesh_model *bt_mesh_model_find(struct bt_mesh_elem *elem, uint16_t id);
555
556 /** @brief Find a vendor model.
557 *
558 * @param elem Element to search for the model in.
559 * @param company Company ID of the model.
560 * @param id Model ID of the model.
561 *
562 * @return A pointer to the Mesh model matching the given parameters, or NULL
563 * if no vendor model with the given ID exists in the given element.
564 */
565 struct bt_mesh_model *bt_mesh_model_find_vnd(struct bt_mesh_elem *elem,
566 uint16_t company, uint16_t id);
567
568 /** @brief Get whether the model is in the primary element of the device.
569 *
570 * @param mod Mesh model.
571 *
572 * @return true if the model is on the primary element, false otherwise.
573 */
bt_mesh_model_in_primary(const struct bt_mesh_model * mod)574 static inline bool bt_mesh_model_in_primary(const struct bt_mesh_model *mod)
575 {
576 return (mod->elem_idx == 0);
577 }
578
579 /** Node Composition */
580 struct bt_mesh_comp {
581 uint16_t cid;
582 uint16_t pid;
583 uint16_t vid;
584
585 size_t elem_count;
586 struct bt_mesh_elem *elem;
587 };
588
589 #ifdef __cplusplus
590 }
591 #endif
592
593 /**
594 * @}
595 */
596
597 #endif /* __BLE_MESH_ACCESS_H */
598