NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
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 __BT_MESH_ACCESS_H
11#define __BT_MESH_ACCESS_H
12
13#include "msg.h"
14#include <sys/types.h>
15
23#ifdef __cplusplus
24extern "C" {
25#endif
26
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
32
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
39
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)
44
45#define BT_MESH_IS_DEV_KEY(key) (key == BT_MESH_KEY_DEV_LOCAL || \
46 key == BT_MESH_KEY_DEV_REMOTE)
47
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) \
61{ \
62 .loc = (_loc), \
63 .model_count = ARRAY_SIZE(_mods), \
64 .models = (_mods), \
65 .vnd_model_count = ARRAY_SIZE(_vnd_mods), \
66 .vnd_models = (_vnd_mods), \
67}
68
71 /* Unicast Address. Set at runtime during provisioning. */
72 uint16_t addr;
73
74 /* Location Descriptor (GATT Bluetooth Namespace Descriptors) */
75 const uint16_t loc;
76
77 const uint8_t model_count;
78 const uint8_t vnd_model_count;
79
80 struct bt_mesh_model * const models;
81 struct bt_mesh_model * const vnd_models;
82};
83
84/* Foundation Models */
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
89
90/* Models from the Mesh Model Specification */
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
143
144struct bt_mesh_model_op {
145 /* OpCode encoded using the BT_MESH_MODEL_OP_* macros */
146 const uint32_t opcode;
147
154 const ssize_t len;
155
156 /* Message handler for the opcode */
157 int (*const func)(struct bt_mesh_model *model,
158 struct bt_mesh_msg_ctx *ctx,
159 struct os_mbuf *buf);
160};
161
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))
165
167#define BT_MESH_LEN_EXACT(len) (-len)
169#define BT_MESH_LEN_MIN(len) (len)
170
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 })
174
176#define BT_MESH_MODEL_NONE ((struct bt_mesh_model []){})
177
188#define BT_MESH_MODEL_CB(_id, _op, _pub, _user_data, _cb) \
189{ \
190 .id = (_id), \
191 .op = _op, \
192 .keys = { [0 ... (CONFIG_BT_MESH_MODEL_KEY_COUNT - 1)] = \
193 BT_MESH_KEY_UNUSED }, \
194 .pub = _pub, \
195 .groups = { [0 ... (CONFIG_BT_MESH_MODEL_GROUP_COUNT - 1)] = \
196 BT_MESH_ADDR_UNASSIGNED }, \
197 .user_data = _user_data, \
198 .cb = _cb, \
199}
200
212#define BT_MESH_MODEL_VND_CB(_company, _id, _op, _pub, _user_data, _cb) \
213{ \
214 .vnd.company = (_company), \
215 .vnd.id = (_id), \
216 .op = _op, \
217 .pub = _pub, \
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, \
223 .cb = _cb, \
224}
225
226
236#define BT_MESH_MODEL(_id, _op, _pub, _user_data) \
237 BT_MESH_MODEL_CB(_id, _op, _pub, _user_data, NULL)
238
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)
251
263#define BT_MESH_TRANSMIT(count, int_ms) ((count) | (((int_ms / 10) - 1) << 3))
264
273#define BT_MESH_TRANSMIT_COUNT(transmit) (((transmit) & (uint8_t)BIT_MASK(3)))
274
283#define BT_MESH_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 10)
284
296#define BT_MESH_PUB_TRANSMIT(count, int_ms) BT_MESH_TRANSMIT(count, \
297 (int_ms) / 5)
298
307#define BT_MESH_PUB_TRANSMIT_COUNT(transmit) BT_MESH_TRANSMIT_COUNT(transmit)
308
317#define BT_MESH_PUB_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 50)
318
323
324 uint16_t addr;
325 uint16_t key:12,
330 uint8_t ttl;
331 uint8_t retransmit;
332 uint8_t period;
333 uint8_t period_div:4,
334 count:4;
335
336 uint32_t period_start;
355 struct os_mbuf *msg;
356
373 int (*update)(struct bt_mesh_model *mod);
374
376 struct k_work_delayable timer;
377};
378
391 int (*const settings_set)(struct bt_mesh_model *model,
392 const char *name, char *val);
393
405 int (*const start)(struct bt_mesh_model *model);
406
420 int (*const init)(struct bt_mesh_model *model);
421
432 void (*const reset)(struct bt_mesh_model *model);
433};
434
438 uint16_t company;
440 uint16_t id;
441};
442
445 union {
446 const uint16_t id;
447 const struct bt_mesh_mod_id_vnd vnd;
448 };
449
450 /* Internal information, mainly for persistent storage */
451 uint8_t elem_idx; /* Belongs to Nth element */
452 uint8_t mod_idx; /* Is the Nth model in the element */
453 uint16_t flags; /* Model flags for internal bookkeeping */
454
455 /* Model Publication */
456 struct bt_mesh_model_pub * const pub;
457
458 /* AppKey List */
459 uint16_t keys[CONFIG_BT_MESH_MODEL_KEY_COUNT];
460
461 /* Subscription List (group or virtual addresses) */
462 uint16_t groups[CONFIG_BT_MESH_MODEL_GROUP_COUNT];
463
464 const struct bt_mesh_model_op * const op;
465
466 /* Model callback structure. */
467 const struct bt_mesh_model_cb * const cb;
468
469#if MYNEWT_VAL(BLE_MESH_MODEL_EXTENSIONS)
470 /* Pointer to the next model in a model extension list. */
471 struct bt_mesh_model *next;
472#endif
473
474 /* Model-specific user data */
475 void *user_data;
476};
477
478struct bt_mesh_send_cb {
479 void (*start)(uint16_t duration, int err, void *cb_data);
480 void (*end)(int err, void *cb_data);
481};
482
484#define BT_MESH_TTL_DEFAULT 0xff
485
487#define BT_MESH_TTL_MAX 0x7f
488
501 struct bt_mesh_msg_ctx *ctx,
502 struct os_mbuf *msg,
503 const struct bt_mesh_send_cb *cb,
504 void *cb_data);
505
521
530
540 uint16_t id);
541
552 uint16_t company, uint16_t id);
553
560static inline bool bt_mesh_model_in_primary(const struct bt_mesh_model *mod)
561{
562 return (mod->elem_idx == 0);
563}
564
576int bt_mesh_model_data_store(struct bt_mesh_model *mod, bool vnd,
577 const char *name, const void *data,
578 size_t data_len);
579
599int bt_mesh_model_extend(struct bt_mesh_model *extending_mod,
600 struct bt_mesh_model *base_mod);
601
609
612 uint16_t cid;
613 uint16_t pid;
614 uint16_t vid;
615
616 size_t elem_count;
617 struct bt_mesh_elem *elem;
618};
619
620#ifdef __cplusplus
621}
622#endif
623
628#endif /* __BT_MESH_ACCESS_H */
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.
Definition access.h:611
Definition access.h:70
Definition access.h:436
uint16_t company
Definition access.h:438
uint16_t id
Definition access.h:440
Definition access.h:380
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
Definition access.h:320
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
Definition access.h:444
Definition msg.h:80
Definition os_mbuf.h:86