10#ifndef ZEPHYR_INCLUDE_BLUETOOTH_MESH_ACCESS_H_ 
   11#define ZEPHYR_INCLUDE_BLUETOOTH_MESH_ACCESS_H_ 
   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(_keys)                        \ 
   21        { LISTIFY(_keys, BT_MESH_KEY_UNUSED_ELT_, (,)) } 
   22#define BT_MESH_MODEL_GROUPS_UNASSIGNED(_grps)                  \ 
   23        { LISTIFY(_grps, BT_MESH_ADDR_UNASSIGNED_ELT_, (,)) } 
   36#define BT_MESH_ADDR_UNASSIGNED   0x0000 
   37#define BT_MESH_ADDR_ALL_NODES    0xffff 
   38#define BT_MESH_ADDR_PROXIES      0xfffc 
   39#define BT_MESH_ADDR_FRIENDS      0xfffd 
   40#define BT_MESH_ADDR_RELAYS       0xfffe 
   42#define BT_MESH_KEY_UNUSED        0xffff 
   43#define BT_MESH_KEY_ANY           0xffff 
   44#define BT_MESH_KEY_DEV           0xfffe 
   45#define BT_MESH_KEY_DEV_LOCAL     BT_MESH_KEY_DEV 
   46#define BT_MESH_KEY_DEV_REMOTE    0xfffd 
   47#define BT_MESH_KEY_DEV_ANY       0xfffc 
   49#define BT_MESH_ADDR_IS_UNICAST(addr) ((addr) && (addr) < 0x8000) 
   50#define BT_MESH_ADDR_IS_GROUP(addr) ((addr) >= 0xc000 && (addr) < 0xff00) 
   51#define BT_MESH_ADDR_IS_FIXED_GROUP(addr) ((addr) >= 0xff00 && (addr) < 0xffff) 
   52#define BT_MESH_ADDR_IS_VIRTUAL(addr) ((addr) >= 0x8000 && (addr) < 0xc000) 
   53#define BT_MESH_ADDR_IS_RFU(addr) ((addr) >= 0xff00 && (addr) <= 0xfffb) 
   55#define BT_MESH_IS_DEV_KEY(key) (key == BT_MESH_KEY_DEV_LOCAL || \ 
   56                                 key == BT_MESH_KEY_DEV_REMOTE) 
   59#define BT_MESH_APP_SEG_SDU_MAX   12 
   62#define BT_MESH_APP_UNSEG_SDU_MAX 15 
   65#if defined(CONFIG_BT_MESH_RX_SEG_MAX) 
   66#define BT_MESH_RX_SEG_MAX CONFIG_BT_MESH_RX_SEG_MAX 
   68#define BT_MESH_RX_SEG_MAX 0 
   72#if defined(CONFIG_BT_MESH_TX_SEG_MAX) 
   73#define BT_MESH_TX_SEG_MAX CONFIG_BT_MESH_TX_SEG_MAX 
   75#define BT_MESH_TX_SEG_MAX 0 
   79#define BT_MESH_TX_SDU_MAX        MAX((BT_MESH_TX_SEG_MAX *             \ 
   80                                       BT_MESH_APP_SEG_SDU_MAX),        \ 
   81                                      BT_MESH_APP_UNSEG_SDU_MAX) 
   84#define BT_MESH_RX_SDU_MAX        MAX((BT_MESH_RX_SEG_MAX *             \ 
   85                                       BT_MESH_APP_SEG_SDU_MAX),        \ 
   86                                      BT_MESH_APP_UNSEG_SDU_MAX) 
   97#define BT_MESH_ELEM(_loc, _mods, _vnd_mods)        \ 
  100        .model_count      = ARRAY_SIZE(_mods),      \ 
  101        .vnd_model_count  = ARRAY_SIZE(_vnd_mods),  \ 
  103        .vnd_models       = (_vnd_mods),            \ 
  125#define BT_MESH_MODEL_ID_CFG_SRV                   0x0000 
  126#define BT_MESH_MODEL_ID_CFG_CLI                   0x0001 
  127#define BT_MESH_MODEL_ID_HEALTH_SRV                0x0002 
  128#define BT_MESH_MODEL_ID_HEALTH_CLI                0x0003 
  131#define BT_MESH_MODEL_ID_GEN_ONOFF_SRV             0x1000 
  132#define BT_MESH_MODEL_ID_GEN_ONOFF_CLI             0x1001 
  133#define BT_MESH_MODEL_ID_GEN_LEVEL_SRV             0x1002 
  134#define BT_MESH_MODEL_ID_GEN_LEVEL_CLI             0x1003 
  135#define BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV    0x1004 
  136#define BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI    0x1005 
  137#define BT_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV       0x1006 
  138#define BT_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV 0x1007 
  139#define BT_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI       0x1008 
  140#define BT_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV       0x1009 
  141#define BT_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV 0x100a 
  142#define BT_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI       0x100b 
  143#define BT_MESH_MODEL_ID_GEN_BATTERY_SRV           0x100c 
  144#define BT_MESH_MODEL_ID_GEN_BATTERY_CLI           0x100d 
  145#define BT_MESH_MODEL_ID_GEN_LOCATION_SRV          0x100e 
  146#define BT_MESH_MODEL_ID_GEN_LOCATION_SETUPSRV     0x100f 
  147#define BT_MESH_MODEL_ID_GEN_LOCATION_CLI          0x1010 
  148#define BT_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV        0x1011 
  149#define BT_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV 0x1012 
  150#define BT_MESH_MODEL_ID_GEN_USER_PROP_SRV         0x1013 
  151#define BT_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV       0x1014 
  152#define BT_MESH_MODEL_ID_GEN_PROP_CLI              0x1015 
  153#define BT_MESH_MODEL_ID_SENSOR_SRV                0x1100 
  154#define BT_MESH_MODEL_ID_SENSOR_SETUP_SRV          0x1101 
  155#define BT_MESH_MODEL_ID_SENSOR_CLI                0x1102 
  156#define BT_MESH_MODEL_ID_TIME_SRV                  0x1200 
  157#define BT_MESH_MODEL_ID_TIME_SETUP_SRV            0x1201 
  158#define BT_MESH_MODEL_ID_TIME_CLI                  0x1202 
  159#define BT_MESH_MODEL_ID_SCENE_SRV                 0x1203 
  160#define BT_MESH_MODEL_ID_SCENE_SETUP_SRV           0x1204 
  161#define BT_MESH_MODEL_ID_SCENE_CLI                 0x1205 
  162#define BT_MESH_MODEL_ID_SCHEDULER_SRV             0x1206 
  163#define BT_MESH_MODEL_ID_SCHEDULER_SETUP_SRV       0x1207 
  164#define BT_MESH_MODEL_ID_SCHEDULER_CLI             0x1208 
  165#define BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV       0x1300 
  166#define BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV 0x1301 
  167#define BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI       0x1302 
  168#define BT_MESH_MODEL_ID_LIGHT_CTL_SRV             0x1303 
  169#define BT_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV       0x1304 
  170#define BT_MESH_MODEL_ID_LIGHT_CTL_CLI             0x1305 
  171#define BT_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV        0x1306 
  172#define BT_MESH_MODEL_ID_LIGHT_HSL_SRV             0x1307 
  173#define BT_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV       0x1308 
  174#define BT_MESH_MODEL_ID_LIGHT_HSL_CLI             0x1309 
  175#define BT_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV         0x130a 
  176#define BT_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV         0x130b 
  177#define BT_MESH_MODEL_ID_LIGHT_XYL_SRV             0x130c 
  178#define BT_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV       0x130d 
  179#define BT_MESH_MODEL_ID_LIGHT_XYL_CLI             0x130e 
  180#define BT_MESH_MODEL_ID_LIGHT_LC_SRV              0x130f 
  181#define BT_MESH_MODEL_ID_LIGHT_LC_SETUPSRV         0x1310 
  182#define BT_MESH_MODEL_ID_LIGHT_LC_CLI              0x1311 
  211#define BT_MESH_MODEL_OP_1(b0) (b0) 
  212#define BT_MESH_MODEL_OP_2(b0, b1) (((b0) << 8) | (b1)) 
  213#define BT_MESH_MODEL_OP_3(b0, cid) ((((b0) << 16) | 0xc00000) | (cid)) 
  216#define BT_MESH_LEN_EXACT(len) (-len) 
  218#define BT_MESH_LEN_MIN(len) (len) 
  221#define BT_MESH_MODEL_OP_END { 0, 0, NULL } 
  223#define BT_MESH_MODEL_NO_OPS ((struct bt_mesh_model_op []) \ 
  224                              { BT_MESH_MODEL_OP_END }) 
  227#define BT_MESH_MODEL_NONE ((struct bt_mesh_model []){}) 
  243#define BT_MESH_MODEL_CNT_CB(_id, _op, _pub, _user_data, _keys, _grps, _cb)     \ 
  247        .keys = (uint16_t []) BT_MESH_MODEL_KEYS_UNUSED(_keys),                 \ 
  249        .groups = (uint16_t []) BT_MESH_MODEL_GROUPS_UNASSIGNED(_grps),         \ 
  250        .groups_cnt = _grps,                                                    \ 
  253        .user_data = _user_data,                                                \ 
  271#define BT_MESH_MODEL_CNT_VND_CB(_company, _id, _op, _pub, _user_data, _keys, _grps, _cb)       \ 
  273        .vnd.company = (_company),                                                              \ 
  277        .keys = (uint16_t []) BT_MESH_MODEL_KEYS_UNUSED(_keys),                                 \ 
  279        .groups = (uint16_t []) BT_MESH_MODEL_GROUPS_UNASSIGNED(_grps),                         \ 
  280        .groups_cnt = _grps,                                                                    \ 
  281        .user_data = _user_data,                                                                \ 
  294#define BT_MESH_MODEL_CB(_id, _op, _pub, _user_data, _cb)       \ 
  295        BT_MESH_MODEL_CNT_CB(_id, _op, _pub, _user_data,        \ 
  296                             CONFIG_BT_MESH_MODEL_KEY_COUNT,    \ 
  297                             CONFIG_BT_MESH_MODEL_GROUP_COUNT, _cb) 
  310#define BT_MESH_MODEL_VND_CB(_company, _id, _op, _pub, _user_data, _cb) \ 
  311        BT_MESH_MODEL_CNT_VND_CB(_company, _id, _op, _pub, _user_data,  \ 
  312                                 CONFIG_BT_MESH_MODEL_KEY_COUNT,        \ 
  313                                 CONFIG_BT_MESH_MODEL_GROUP_COUNT, _cb) 
  323#define BT_MESH_MODEL(_id, _op, _pub, _user_data)                              \ 
  324        BT_MESH_MODEL_CB(_id, _op, _pub, _user_data, NULL) 
  335#define BT_MESH_MODEL_VND(_company, _id, _op, _pub, _user_data)                \ 
  336        BT_MESH_MODEL_VND_CB(_company, _id, _op, _pub, _user_data, NULL) 
  348#define BT_MESH_TRANSMIT(count, int_ms) ((count) | (((int_ms / 10) - 1) << 3)) 
  357#define BT_MESH_TRANSMIT_COUNT(transmit) (((transmit) & (uint8_t)BIT_MASK(3))) 
  366#define BT_MESH_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 10) 
  378#define BT_MESH_PUB_TRANSMIT(count, int_ms) BT_MESH_TRANSMIT(count,           \ 
  388#define BT_MESH_PUB_TRANSMIT_COUNT(transmit) BT_MESH_TRANSMIT_COUNT(transmit) 
  397#define BT_MESH_PUB_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 50) 
  407#define BT_MESH_PUB_MSG_TOTAL(pub) (BT_MESH_PUB_TRANSMIT_COUNT((pub)->retransmit) + 1) 
  418#define BT_MESH_PUB_MSG_NUM(pub) (BT_MESH_PUB_TRANSMIT_COUNT((pub)->retransmit) + 1 - (pub)->count) 
  484#define BT_MESH_MODEL_PUB_DEFINE(_name, _update, _msg_len) \ 
  485        NET_BUF_SIMPLE_DEFINE_STATIC(bt_mesh_pub_msg_##_name, _msg_len); \ 
  486        static struct bt_mesh_model_pub _name = { \ 
  487                .msg = &bt_mesh_pub_msg_##_name, \ 
  507                                  const char *name, 
size_t len_rd,
 
  590#ifdef CONFIG_BT_MESH_MODEL_EXTENSIONS 
  613        void (*
end)(
int err, 
void *cb_data);
 
  618#define BT_MESH_TTL_DEFAULT 0xff 
  621#define BT_MESH_TTL_MAX     0x7f 
  721                             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.
 
#define BT_MESH_PUB_TRANSMIT_COUNT(transmit)
Decode Publish Retransmit count from a given value.
Definition: access.h:388
 
struct bt_mesh_elem * bt_mesh_model_elem(struct bt_mesh_model *mod)
Get the element that a model belongs to.
 
static bool bt_mesh_model_pub_is_retransmission(const struct bt_mesh_model *model)
Check if a message is being retransmitted.
Definition: access.h:662
 
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:704
 
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
 
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
 
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
 
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
 
uint16_t pid
Definition: access.h:757
 
uint16_t cid
Definition: access.h:756
 
uint16_t vid
Definition: access.h:758
 
struct bt_mesh_elem * elem
Definition: access.h:761
 
size_t elem_count
Definition: access.h:760
 
struct bt_mesh_model *const models
Definition: access.h:119
 
const uint16_t loc
Definition: access.h:112
 
const uint8_t model_count
Definition: access.h:114
 
struct bt_mesh_model *const vnd_models
Definition: access.h:121
 
uint16_t addr
Definition: access.h:109
 
const uint8_t vnd_model_count
Definition: access.h:116
 
uint16_t company
Definition: access.h:554
 
uint16_t id
Definition: access.h:556
 
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:506
 
void(*const reset)(struct bt_mesh_model *model)
Model reset callback.
Definition: access.h:548
 
int(*const start)(struct bt_mesh_model *model)
Callback called when the mesh is started.
Definition: access.h:522
 
int(*const init)(struct bt_mesh_model *model)
Model init callback.
Definition: access.h:536
 
const uint32_t opcode
Definition: access.h:187
 
const ssize_t len
Definition: access.h:195
 
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:206
 
uint16_t key
Definition: access.h:430
 
uint16_t retr_update
Definition: access.h:434
 
int(* update)(struct bt_mesh_model *mod)
Callback for updating the publication buffer.
Definition: access.h:471
 
uint16_t cred
Definition: access.h:431
 
uint8_t retransmit
Definition: access.h:437
 
uint16_t addr
Definition: access.h:429
 
uint8_t count
Definition: access.h:440
 
uint8_t period_div
Definition: access.h:439
 
struct net_buf_simple * msg
Publication buffer, containing the publication message.
Definition: access.h:451
 
struct bt_mesh_model * mod
Definition: access.h:427
 
uint8_t ttl
Definition: access.h:436
 
uint32_t period_start
Definition: access.h:442
 
uint16_t send_rel
Definition: access.h:432
 
uint16_t fast_period
Definition: access.h:433
 
uint8_t period
Definition: access.h:438
 
struct k_work_delayable timer
Definition: access.h:474
 
uint8_t elem_idx
Definition: access.h:569
 
const struct bt_mesh_mod_id_vnd vnd
Definition: access.h:565
 
uint16_t *const groups
Definition: access.h:581
 
const struct bt_mesh_model_op *const op
Definition: access.h:585
 
uint16_t *const keys
Definition: access.h:577
 
void * user_data
Definition: access.h:596
 
const struct bt_mesh_model_cb *const cb
Definition: access.h:588
 
uint16_t flags
Definition: access.h:571
 
const uint16_t keys_cnt
Definition: access.h:578
 
const uint16_t id
Definition: access.h:563
 
uint8_t mod_idx
Definition: access.h:570
 
struct bt_mesh_model * next
Definition: access.h:592
 
const uint16_t groups_cnt
Definition: access.h:582
 
struct bt_mesh_model_pub *const pub
Definition: access.h:574
 
void(* start)(uint16_t duration, int err, void *cb_data)
Handler called at the start of the transmission.
Definition: access.h:607
 
void(* end)(int err, void *cb_data)
Handler called at the end of the transmission.
Definition: access.h:613
 
A structure used to submit work after a delay.
Definition: kernel.h:3735
 
Simple network buffer representation.
Definition: buf.h:82
 
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
 
static void msg(uint64_t c64)
Definition: main.c:17