Lines Matching refs:mod
99 #define IS_MOD_BASE(mod, idx, offset) \ argument
100 (mod_rel_list[(idx)].elem_base == mod->rt->elem_idx && \
101 mod_rel_list[(idx)].idx_base == mod->rt->mod_idx + (offset))
103 #define IS_MOD_EXTENSION(mod, idx, offset) \ argument
104 (mod_rel_list[(idx)].elem_ext == mod->rt->elem_idx && \
105 mod_rel_list[(idx)].idx_ext == mod->rt->mod_idx + (offset))
122 void bt_mesh_model_foreach(void (*func)(const struct bt_mesh_model *mod, in bt_mesh_model_foreach() argument
189 static void comp_add_model(const struct bt_mesh_model *mod, const struct bt_mesh_elem *elem, in comp_add_model() argument
195 data_buf_add_le16_offset(arg->buf, mod->vnd.company, arg->offset); in comp_add_model()
196 data_buf_add_le16_offset(arg->buf, mod->vnd.id, arg->offset); in comp_add_model()
198 data_buf_add_le16_offset(arg->buf, mod->id, arg->offset); in comp_add_model()
204 static size_t metadata_model_size(const struct bt_mesh_model *mod, in metadata_model_size() argument
210 if (!mod->metadata) { in metadata_model_size()
215 size += sizeof(mod->vnd.company); in metadata_model_size()
216 size += sizeof(mod->vnd.id); in metadata_model_size()
218 size += sizeof(mod->id); in metadata_model_size()
223 for (entry = mod->metadata; entry && entry->len; ++entry) { in metadata_model_size()
260 static int metadata_add_model(const struct bt_mesh_model *mod, in metadata_add_model() argument
272 model_size = metadata_model_size(mod, elem, vnd); in metadata_add_model()
284 comp_add_model(mod, elem, vnd, user_data); in metadata_add_model()
288 if (mod->metadata) { in metadata_add_model()
289 for (entry = mod->metadata; entry && entry->data != NULL; ++entry) { in metadata_add_model()
460 static uint8_t count_mod_ext(const struct bt_mesh_model *mod, in count_mod_ext() argument
468 if (IS_MOD_EXTENSION(mod, i, sig_offset) && in count_mod_ext()
485 static bool is_cor_present(const struct bt_mesh_model *mod, uint8_t *cor_id, uint8_t sig_offset) in is_cor_present() argument
491 if ((IS_MOD_BASE(mod, i, sig_offset) || in is_cor_present()
492 IS_MOD_EXTENSION(mod, i, sig_offset)) && in is_cor_present()
503 static void prep_model_item_header(const struct bt_mesh_model *mod, uint8_t *cor_id, in prep_model_item_header() argument
512 ext_mod_cnt = count_mod_ext(mod, &max_offset, sig_offset); in prep_model_item_header()
513 cor_present = is_cor_present(mod, cor_id, sig_offset); in prep_model_item_header()
532 static void add_items_to_page(struct net_buf_simple *buf, const struct bt_mesh_model *mod, in add_items_to_page() argument
539 if (IS_MOD_EXTENSION(mod, i, sig_offset) && in add_items_to_page()
541 elem_offset = mod->rt->elem_idx - mod_rel_list[i].elem_base; in add_items_to_page()
565 static size_t mod_items_size(const struct bt_mesh_model *mod, uint8_t sig_offset) in mod_items_size() argument
569 int ext_mod_cnt = count_mod_ext(mod, NULL, sig_offset); in mod_items_size()
576 if (IS_MOD_EXTENSION(mod, i, sig_offset)) { in mod_items_size()
577 offset = mod->rt->elem_idx - mod_rel_list[i].elem_base; in mod_items_size()
711 int32_t bt_mesh_model_pub_period_get(const struct bt_mesh_model *mod) in bt_mesh_model_pub_period_get() argument
715 if (!mod->pub) { in bt_mesh_model_pub_period_get()
719 switch (mod->pub->period >> 6) { in bt_mesh_model_pub_period_get()
722 period = (mod->pub->period & BIT_MASK(6)) * 100U; in bt_mesh_model_pub_period_get()
726 period = (mod->pub->period & BIT_MASK(6)) * MSEC_PER_SEC; in bt_mesh_model_pub_period_get()
730 period = (mod->pub->period & BIT_MASK(6)) * 10U * MSEC_PER_SEC; in bt_mesh_model_pub_period_get()
734 period = (mod->pub->period & BIT_MASK(6)) * 600U * MSEC_PER_SEC; in bt_mesh_model_pub_period_get()
740 if (mod->pub->fast_period) { in bt_mesh_model_pub_period_get()
745 return MAX(period >> mod->pub->period_div, 100); in bt_mesh_model_pub_period_get()
751 static int32_t next_period(const struct bt_mesh_model *mod) in next_period() argument
753 struct bt_mesh_model_pub *pub = mod->pub; in next_period()
760 if (mod->pub->count) { in next_period()
764 period = BT_MESH_PUB_TRANSMIT_INT(mod->pub->retransmit); in next_period()
765 period *= BT_MESH_PUB_MSG_NUM(mod->pub); in next_period()
778 return BT_MESH_PUB_TRANSMIT_INT(mod->pub->retransmit); in next_period()
783 period = bt_mesh_model_pub_period_get(mod); in next_period()
805 const struct bt_mesh_model *mod = user_data; in publish_sent() local
810 delay = next_period(mod); in publish_sent()
817 k_work_schedule(&mod->pub->timer, K_MSEC(delay)); in publish_sent()
835 static int publish_transmit(const struct bt_mesh_model *mod) in publish_transmit() argument
838 struct bt_mesh_model_pub *pub = mod->pub; in publish_transmit()
842 .src = bt_mesh_model_elem(mod)->rt->addr, in publish_transmit()
848 return bt_mesh_trans_send(&tx, &sdu, &pub_sent_cb, (void *)mod); in publish_transmit()
861 err = pub->update(pub->mod); in pub_period_start()
869 publish_sent(err, (void *)pub->mod); in pub_period_start()
931 bt_mesh_model_pub_is_retransmission(pub->mod)) { in mod_publish()
932 err = pub->update(pub->mod); in mod_publish()
934 publish_sent(err, (void *)pub->mod); in mod_publish()
953 err = publish_transmit(pub->mod); in mod_publish()
956 publish_sent(err, (void *)pub->mod); in mod_publish()
960 const struct bt_mesh_elem *bt_mesh_model_elem(const struct bt_mesh_model *mod) in bt_mesh_model_elem() argument
962 return &dev_comp->elem[mod->rt->elem_idx]; in bt_mesh_model_elem()
994 static int bt_mesh_vnd_mod_msg_cid_check(const struct bt_mesh_model *mod) in bt_mesh_vnd_mod_msg_cid_check() argument
999 for (op = mod->op; op->func; op++) { in bt_mesh_vnd_mod_msg_cid_check()
1002 if (cid == mod->vnd.company) { in bt_mesh_vnd_mod_msg_cid_check()
1008 mod->vnd.company, mod->vnd.id, op->opcode); in bt_mesh_vnd_mod_msg_cid_check()
1017 static void mod_init(const struct bt_mesh_model *mod, const struct bt_mesh_elem *elem, in mod_init() argument
1027 if (mod->pub) { in mod_init()
1028 mod->pub->mod = mod; in mod_init()
1029 k_work_init_delayable(&mod->pub->timer, mod_publish); in mod_init()
1032 for (i = 0; i < mod->keys_cnt; i++) { in mod_init()
1033 mod->keys[i] = BT_MESH_KEY_UNUSED; in mod_init()
1036 mod->rt->elem_idx = elem - dev_comp->elem; in mod_init()
1038 mod->rt->mod_idx = mod - elem->vnd_models; in mod_init()
1041 *err = bt_mesh_vnd_mod_msg_cid_check(mod); in mod_init()
1048 mod->rt->mod_idx = mod - elem->models; in mod_init()
1051 if (mod->cb && mod->cb->init) { in mod_init()
1052 *err = mod->cb->init(mod); in mod_init()
1145 static uint16_t *model_group_get(const struct bt_mesh_model *mod, uint16_t addr) in model_group_get() argument
1149 for (i = 0; i < mod->groups_cnt; i++) { in model_group_get()
1150 if (mod->groups[i] == addr) { in model_group_get()
1151 return &mod->groups[i]; in model_group_get()
1160 const struct bt_mesh_model *mod; member
1164 static enum bt_mesh_walk find_group_mod_visitor(const struct bt_mesh_model *mod, void *user_data) in find_group_mod_visitor() argument
1168 if (mod->rt->elem_idx != ctx->mod->rt->elem_idx) { in find_group_mod_visitor()
1172 ctx->entry = model_group_get(mod, ctx->addr); in find_group_mod_visitor()
1174 ctx->mod = mod; in find_group_mod_visitor()
1181 uint16_t *bt_mesh_model_find_group(const struct bt_mesh_model **mod, uint16_t addr) in bt_mesh_model_find_group() argument
1184 .mod = *mod, in bt_mesh_model_find_group()
1189 bt_mesh_model_extensions_walk(*mod, find_group_mod_visitor, &ctx); in bt_mesh_model_find_group()
1191 *mod = ctx.mod; in bt_mesh_model_find_group()
1196 static const uint8_t **model_uuid_get(const struct bt_mesh_model *mod, const uint8_t *uuid) in model_uuid_get() argument
1201 if (mod->uuids[i] == uuid) { in model_uuid_get()
1205 if (uuid == NULL && !model_group_get(mod, BT_MESH_ADDR_UNASSIGNED)) { in model_uuid_get()
1209 return &mod->uuids[i]; in model_uuid_get()
1218 const struct bt_mesh_model *mod; member
1222 static enum bt_mesh_walk find_uuid_mod_visitor(const struct bt_mesh_model *mod, void *user_data) in find_uuid_mod_visitor() argument
1226 if (mod->rt->elem_idx != ctx->mod->rt->elem_idx) { in find_uuid_mod_visitor()
1230 ctx->entry = model_uuid_get(mod, ctx->uuid); in find_uuid_mod_visitor()
1232 ctx->mod = mod; in find_uuid_mod_visitor()
1240 const uint8_t **bt_mesh_model_find_uuid(const struct bt_mesh_model **mod, const uint8_t *uuid) in bt_mesh_model_find_uuid() argument
1244 .mod = *mod, in bt_mesh_model_find_uuid()
1249 bt_mesh_model_extensions_walk(*mod, find_uuid_mod_visitor, &ctx); in bt_mesh_model_find_uuid()
1251 *mod = ctx.mod; in bt_mesh_model_find_uuid()
1358 bool bt_mesh_model_has_key(const struct bt_mesh_model *mod, uint16_t key) in bt_mesh_model_has_key() argument
1362 for (i = 0; i < mod->keys_cnt; i++) { in bt_mesh_model_has_key()
1363 if (mod->keys[i] == key || in bt_mesh_model_has_key()
1364 (mod->keys[i] == BT_MESH_KEY_DEV_ANY && in bt_mesh_model_has_key()
1373 static bool model_has_dst(const struct bt_mesh_model *mod, uint16_t dst, const uint8_t *uuid) in model_has_dst() argument
1376 return (dev_comp->elem[mod->rt->elem_idx].rt->addr == dst); in model_has_dst()
1378 return !!bt_mesh_model_find_uuid(&mod, uuid); in model_has_dst()
1380 (BT_MESH_ADDR_IS_FIXED_GROUP(dst) && mod->rt->elem_idx != 0)) { in model_has_dst()
1381 return !!bt_mesh_model_find_group(&mod, dst); in model_has_dst()
1388 return mod->rt->elem_idx == 0; in model_has_dst()
1703 enum bt_mesh_walk (*cb)(const struct bt_mesh_model *mod, in bt_mesh_model_extensions_walk() argument
1730 static uint8_t get_sig_offset(const struct bt_mesh_model *mod) in get_sig_offset() argument
1732 const struct bt_mesh_elem *elem = bt_mesh_model_elem(mod); in get_sig_offset()
1736 if (&elem->vnd_models[i] == mod) { in get_sig_offset()
1858 static int mod_set_bind(const struct bt_mesh_model *mod, size_t len_rd, in mod_set_bind() argument
1865 for (i = 0; i < mod->keys_cnt; i++) { in mod_set_bind()
1866 mod->keys[i] = BT_MESH_KEY_UNUSED; in mod_set_bind()
1874 len = read_cb(cb_arg, mod->keys, mod->keys_cnt * sizeof(mod->keys[0])); in mod_set_bind()
1880 LOG_HEXDUMP_DBG(mod->keys, len, "val"); in mod_set_bind()
1882 LOG_DBG("Decoded %zu bound keys for model", len / sizeof(mod->keys[0])); in mod_set_bind()
1886 static int mod_set_sub(const struct bt_mesh_model *mod, size_t len_rd, in mod_set_sub() argument
1889 size_t size = mod->groups_cnt * sizeof(mod->groups[0]); in mod_set_sub()
1893 (void)memset(mod->groups, 0, size); in mod_set_sub()
1900 len = read_cb(cb_arg, mod->groups, size); in mod_set_sub()
1906 LOG_HEXDUMP_DBG(mod->groups, len, "val"); in mod_set_sub()
1908 LOG_DBG("Decoded %zu subscribed group addresses for model", len / sizeof(mod->groups[0])); in mod_set_sub()
1913 static int mod_set_sub_va(const struct bt_mesh_model *mod, size_t len_rd, in mod_set_sub_va() argument
1923 (void)memset(mod->uuids, 0, CONFIG_BT_MESH_LABEL_COUNT * sizeof(mod->uuids[0])); in mod_set_sub_va()
1939 mod->uuids[count] = bt_mesh_va_get_uuid_by_idx(uuidxs[i]); in mod_set_sub_va()
1940 if (mod->uuids[count] != NULL) { in mod_set_sub_va()
1950 static int mod_set_pub(const struct bt_mesh_model *mod, size_t len_rd, in mod_set_pub() argument
1956 if (!mod->pub) { in mod_set_pub()
1962 mod->pub->addr = BT_MESH_ADDR_UNASSIGNED; in mod_set_pub()
1963 mod->pub->key = 0U; in mod_set_pub()
1964 mod->pub->cred = 0U; in mod_set_pub()
1965 mod->pub->ttl = 0U; in mod_set_pub()
1966 mod->pub->period = 0U; in mod_set_pub()
1967 mod->pub->retransmit = 0U; in mod_set_pub()
1968 mod->pub->count = 0U; in mod_set_pub()
1969 mod->pub->uuid = NULL; in mod_set_pub()
1986 mod->pub->uuid = bt_mesh_va_get_uuid_by_idx(pub.uuidx); in mod_set_pub()
1989 mod->pub->addr = pub.base.addr; in mod_set_pub()
1990 mod->pub->key = pub.base.key; in mod_set_pub()
1991 mod->pub->cred = pub.base.cred; in mod_set_pub()
1992 mod->pub->ttl = pub.base.ttl; in mod_set_pub()
1993 mod->pub->period = pub.base.period; in mod_set_pub()
1994 mod->pub->retransmit = pub.base.retransmit; in mod_set_pub()
1995 mod->pub->period_div = pub.base.period_div; in mod_set_pub()
1996 mod->pub->count = 0U; in mod_set_pub()
2004 static int mod_data_set(const struct bt_mesh_model *mod, in mod_data_set() argument
2012 if (mod->cb && mod->cb->settings_set) { in mod_data_set()
2013 return mod->cb->settings_set(mod, next, len_rd, in mod_data_set()
2023 const struct bt_mesh_model *mod; in mod_set() local
2040 mod = bt_mesh_model_get(vnd, elem_idx, mod_idx); in mod_set()
2041 if (!mod) { in mod_set()
2058 return mod_set_bind(mod, len_rd, read_cb, cb_arg); in mod_set()
2060 return mod_set_sub_va(mod, len_rd, read_cb, cb_arg); in mod_set()
2062 return mod_data_set(mod, next, len_rd, read_cb, cb_arg); in mod_set()
2068 return mod_set_sub(mod, len_rd, read_cb, cb_arg); in mod_set()
2070 return mod_set_pub(mod, len_rd, read_cb, cb_arg); in mod_set()
2112 static void encode_mod_path(const struct bt_mesh_model *mod, bool vnd, in encode_mod_path() argument
2115 uint16_t mod_key = (((uint16_t)mod->rt->elem_idx << 8) | mod->rt->mod_idx); in encode_mod_path()
2124 static void store_pending_mod_bind(const struct bt_mesh_model *mod, bool vnd) in store_pending_mod_bind() argument
2130 for (i = 0, count = 0; i < mod->keys_cnt; i++) { in store_pending_mod_bind()
2131 if (mod->keys[i] != BT_MESH_KEY_UNUSED) { in store_pending_mod_bind()
2132 keys[count++] = mod->keys[i]; in store_pending_mod_bind()
2133 LOG_DBG("model key 0x%04x", mod->keys[i]); in store_pending_mod_bind()
2137 encode_mod_path(mod, vnd, "bind", path, sizeof(path)); in store_pending_mod_bind()
2152 static void store_pending_mod_sub(const struct bt_mesh_model *mod, bool vnd) in store_pending_mod_sub() argument
2158 for (i = 0, count = 0; i < mod->groups_cnt; i++) { in store_pending_mod_sub()
2159 if (mod->groups[i] != BT_MESH_ADDR_UNASSIGNED) { in store_pending_mod_sub()
2160 groups[count++] = mod->groups[i]; in store_pending_mod_sub()
2164 encode_mod_path(mod, vnd, "sub", path, sizeof(path)); in store_pending_mod_sub()
2179 static void store_pending_mod_sub_va(const struct bt_mesh_model *mod, bool vnd) in store_pending_mod_sub_va() argument
2187 if (mod->uuids[i] != NULL) { in store_pending_mod_sub_va()
2188 err = bt_mesh_va_get_idx_by_uuid(mod->uuids[i], &uuidxs[count]); in store_pending_mod_sub_va()
2195 encode_mod_path(mod, vnd, "subv", path, sizeof(path)); in store_pending_mod_sub_va()
2211 static void store_pending_mod_pub(const struct bt_mesh_model *mod, bool vnd) in store_pending_mod_pub() argument
2217 encode_mod_path(mod, vnd, "pub", path, sizeof(path)); in store_pending_mod_pub()
2219 if (!mod->pub || mod->pub->addr == BT_MESH_ADDR_UNASSIGNED) { in store_pending_mod_pub()
2222 pub.base.addr = mod->pub->addr; in store_pending_mod_pub()
2223 pub.base.key = mod->pub->key; in store_pending_mod_pub()
2224 pub.base.ttl = mod->pub->ttl; in store_pending_mod_pub()
2225 pub.base.retransmit = mod->pub->retransmit; in store_pending_mod_pub()
2226 pub.base.period = mod->pub->period; in store_pending_mod_pub()
2227 pub.base.period_div = mod->pub->period_div; in store_pending_mod_pub()
2228 pub.base.cred = mod->pub->cred; in store_pending_mod_pub()
2230 if (BT_MESH_ADDR_IS_VIRTUAL(mod->pub->addr)) { in store_pending_mod_pub()
2231 (void)bt_mesh_va_get_idx_by_uuid(mod->pub->uuid, &pub.uuidx); in store_pending_mod_pub()
2244 static void store_pending_mod(const struct bt_mesh_model *mod, in store_pending_mod() argument
2248 if (!mod->rt->flags) { in store_pending_mod()
2252 if (mod->rt->flags & BT_MESH_MOD_BIND_PENDING) { in store_pending_mod()
2253 mod->rt->flags &= ~BT_MESH_MOD_BIND_PENDING; in store_pending_mod()
2254 store_pending_mod_bind(mod, vnd); in store_pending_mod()
2257 if (mod->rt->flags & BT_MESH_MOD_SUB_PENDING) { in store_pending_mod()
2258 mod->rt->flags &= ~BT_MESH_MOD_SUB_PENDING; in store_pending_mod()
2259 store_pending_mod_sub(mod, vnd); in store_pending_mod()
2260 store_pending_mod_sub_va(mod, vnd); in store_pending_mod()
2263 if (mod->rt->flags & BT_MESH_MOD_PUB_PENDING) { in store_pending_mod()
2264 mod->rt->flags &= ~BT_MESH_MOD_PUB_PENDING; in store_pending_mod()
2265 store_pending_mod_pub(mod, vnd); in store_pending_mod()
2268 if (mod->rt->flags & BT_MESH_MOD_DATA_PENDING) { in store_pending_mod()
2269 mod->rt->flags &= ~BT_MESH_MOD_DATA_PENDING; in store_pending_mod()
2270 mod->cb->pending_store(mod); in store_pending_mod()
2279 void bt_mesh_model_bind_store(const struct bt_mesh_model *mod) in bt_mesh_model_bind_store() argument
2281 mod->rt->flags |= BT_MESH_MOD_BIND_PENDING; in bt_mesh_model_bind_store()
2285 void bt_mesh_model_sub_store(const struct bt_mesh_model *mod) in bt_mesh_model_sub_store() argument
2287 mod->rt->flags |= BT_MESH_MOD_SUB_PENDING; in bt_mesh_model_sub_store()
2291 void bt_mesh_model_pub_store(const struct bt_mesh_model *mod) in bt_mesh_model_pub_store() argument
2293 mod->rt->flags |= BT_MESH_MOD_PUB_PENDING; in bt_mesh_model_pub_store()
2477 int bt_mesh_model_data_store(const struct bt_mesh_model *mod, bool vnd, in bt_mesh_model_data_store() argument
2484 encode_mod_path(mod, vnd, "data", path, sizeof(path)); in bt_mesh_model_data_store()
2626 static void commit_mod(const struct bt_mesh_model *mod, const struct bt_mesh_elem *elem, in commit_mod() argument
2629 if (mod->pub && mod->pub->update && in commit_mod()
2630 mod->pub->addr != BT_MESH_ADDR_UNASSIGNED) { in commit_mod()
2631 int32_t ms = bt_mesh_model_pub_period_get(mod); in commit_mod()
2645 random = !!mod->pub->delayable ? pub_delay_get(RANDOM_DELAY_LONG) : 0; in commit_mod()
2648 k_work_schedule(&mod->pub->timer, K_MSEC(ms + random)); in commit_mod()
2656 for (int i = 0; i < mod->groups_cnt; i++) { in commit_mod()
2657 if (mod->groups[i] != BT_MESH_ADDR_UNASSIGNED) { in commit_mod()
2658 bt_mesh_lpn_group_add(mod->groups[i]); in commit_mod()
2668 void bt_mesh_model_data_store_schedule(const struct bt_mesh_model *mod) in bt_mesh_model_data_store_schedule() argument
2670 mod->rt->flags |= BT_MESH_MOD_DATA_PENDING; in bt_mesh_model_data_store_schedule()