Lines Matching +full:active +full:- +full:range +full:- +full:x +full:- +full:min
4 * SPDX-License-Identifier: Apache-2.0
36 /* 20 - 50ms */
38 /* 20 - 500ms */
75 /** Type of relation; value in range 0x00-0xFE marks correspondence
100 (mod_rel_list[(idx)].elem_base == mod->rt->elem_idx && \
101 mod_rel_list[(idx)].idx_base == mod->rt->mod_idx + (offset))
104 (mod_rel_list[(idx)].elem_ext == mod->rt->elem_idx && \
105 mod_rel_list[(idx)].idx_ext == mod->rt->mod_idx + (offset))
130 for (i = 0; i < dev_comp->elem_count; i++) { in bt_mesh_model_foreach()
131 const struct bt_mesh_elem *elem = &dev_comp->elem[i]; in bt_mesh_model_foreach()
133 for (j = 0; j < elem->model_count; j++) { in bt_mesh_model_foreach()
134 const struct bt_mesh_model *model = &elem->models[j]; in bt_mesh_model_foreach()
139 for (j = 0; j < elem->vnd_model_count; j++) { in bt_mesh_model_foreach()
140 const struct bt_mesh_model *model = &elem->vnd_models[j]; in bt_mesh_model_foreach()
149 return (4 + (elem->model_count * 2U) + (elem->vnd_model_count * 4U)); in bt_mesh_comp_elem_size()
156 *offset -= 1; in data_buf_add_u8_offset()
167 *offset -= 2; in data_buf_add_le16_offset()
170 *offset -= 1; in data_buf_add_le16_offset()
181 *offset -= len; in data_buf_add_mem_offset()
185 net_buf_simple_add_mem(buf, data + *offset, len - *offset); in data_buf_add_mem_offset()
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()
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()
224 size += sizeof(entry->len) + sizeof(entry->id) + entry->len; in metadata_model_size()
238 for (i = 0; i < dev_comp->elem_count; i++) { in bt_mesh_metadata_page_0_size()
239 const struct bt_mesh_elem *elem = &dev_comp->elem[i]; in bt_mesh_metadata_page_0_size()
241 size += sizeof(elem->model_count) + in bt_mesh_metadata_page_0_size()
242 sizeof(elem->vnd_model_count); in bt_mesh_metadata_page_0_size()
244 for (j = 0; j < elem->model_count; j++) { in bt_mesh_metadata_page_0_size()
245 const struct bt_mesh_model *model = &elem->models[j]; in bt_mesh_metadata_page_0_size()
250 for (j = 0; j < elem->vnd_model_count; j++) { in bt_mesh_metadata_page_0_size()
251 const struct bt_mesh_model *model = &elem->vnd_models[j]; in bt_mesh_metadata_page_0_size()
266 struct net_buf_simple *buf = arg->buf; in metadata_add_model()
267 size_t *offset = arg->offset; in metadata_add_model()
275 *offset -= model_size; in metadata_add_model()
281 return -E2BIG; 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()
290 data_buf_add_le16_offset(buf, entry->len, offset); in metadata_add_model()
291 data_buf_add_le16_offset(buf, entry->id, offset); in metadata_add_model()
292 data_buf_add_mem_offset(buf, entry->data, entry->len, offset); in metadata_add_model()
317 for (i = 0; i < comp->elem_count; i++) { in bt_mesh_metadata_get_page_0()
318 const struct bt_mesh_elem *elem = &dev_comp->elem[i]; in bt_mesh_metadata_get_page_0()
324 return -E2BIG; in bt_mesh_metadata_get_page_0()
329 for (j = 0; j < elem->model_count; j++) { in bt_mesh_metadata_get_page_0()
330 const struct bt_mesh_model *model = &elem->models[j]; in bt_mesh_metadata_get_page_0()
332 if (!model->metadata) { in bt_mesh_metadata_get_page_0()
346 for (j = 0; j < elem->vnd_model_count; j++) { in bt_mesh_metadata_get_page_0()
347 const struct bt_mesh_model *model = &elem->vnd_models[j]; in bt_mesh_metadata_get_page_0()
349 if (!model->metadata) { in bt_mesh_metadata_get_page_0()
379 *offset -= elem_size; in comp_add_elem()
383 if (net_buf_simple_tailroom(buf) < ((elem_size - *offset) + BT_MESH_MIC_SHORT)) { in comp_add_elem()
389 LOG_DBG("Element 0x%04x didn't fit in the Data field", in comp_add_elem()
390 elem->rt->addr); in comp_add_elem()
395 return -E2BIG; in comp_add_elem()
398 data_buf_add_le16_offset(buf, elem->loc, offset); in comp_add_elem()
400 data_buf_add_u8_offset(buf, elem->model_count, offset); in comp_add_elem()
401 data_buf_add_u8_offset(buf, elem->vnd_model_count, offset); in comp_add_elem()
403 for (i = 0; i < elem->model_count; i++) { in comp_add_elem()
404 const struct bt_mesh_model *model = &elem->models[i]; in comp_add_elem()
409 for (i = 0; i < elem->vnd_model_count; i++) { in comp_add_elem()
410 const struct bt_mesh_model *model = &elem->vnd_models[i]; in comp_add_elem()
442 data_buf_add_le16_offset(buf, comp->cid, &offset); in bt_mesh_comp_data_get_page_0()
443 data_buf_add_le16_offset(buf, comp->pid, &offset); in bt_mesh_comp_data_get_page_0()
444 data_buf_add_le16_offset(buf, comp->vid, &offset); in bt_mesh_comp_data_get_page_0()
448 for (i = 0; i < comp->elem_count; i++) { in bt_mesh_comp_data_get_page_0()
451 err = comp_add_elem(buf, &comp->elem[i], &offset); in bt_mesh_comp_data_get_page_0()
471 offset = mod_rel_list[i].elem_ext - in count_mod_ext()
518 max_offset < -4) { in prep_model_item_header()
541 elem_offset = mod->rt->elem_idx - mod_rel_list[i].elem_base; in add_items_to_page()
545 elem_offset > -5) { in add_items_to_page()
577 offset = mod->rt->elem_idx - mod_rel_list[i].elem_base; in mod_items_size()
578 temp_size += (ext_mod_cnt < 32 && offset < 4 && offset > -5) ? 1 : 2; in mod_items_size()
589 for (int i = 0; i < elem->model_count; i++) { in page1_elem_size()
590 temp_size += is_cor_present(&elem->models[i], NULL, 0) ? 2 : 1; in page1_elem_size()
591 temp_size += mod_items_size(&elem->models[i], 0); in page1_elem_size()
594 for (int i = 0; i < elem->vnd_model_count; i++) { in page1_elem_size()
595 temp_size += is_cor_present(&elem->vnd_models[i], NULL, elem->model_count) ? 2 : 1; in page1_elem_size()
596 temp_size += mod_items_size(&elem->vnd_models[i], elem->model_count); in page1_elem_size()
611 for (i = 0; i < comp->elem_count; i++) { in bt_mesh_comp_data_get_page_1()
612 size_t elem_size = page1_elem_size(&comp->elem[i]); in bt_mesh_comp_data_get_page_1()
615 offset -= elem_size; in bt_mesh_comp_data_get_page_1()
619 if (net_buf_simple_tailroom(buf) < ((elem_size - offset) + BT_MESH_MIC_SHORT)) { in bt_mesh_comp_data_get_page_1()
625 LOG_DBG("Element 0x%04x didn't fit in the Data field", in bt_mesh_comp_data_get_page_1()
626 comp->elem[i].rt->addr); in bt_mesh_comp_data_get_page_1()
631 return -E2BIG; in bt_mesh_comp_data_get_page_1()
634 data_buf_add_u8_offset(buf, comp->elem[i].model_count, &offset); in bt_mesh_comp_data_get_page_1()
635 data_buf_add_u8_offset(buf, comp->elem[i].vnd_model_count, &offset); in bt_mesh_comp_data_get_page_1()
636 for (j = 0; j < comp->elem[i].model_count; j++) { in bt_mesh_comp_data_get_page_1()
637 prep_model_item_header(&comp->elem[i].models[j], &cor_id, &ext_mod_cnt, buf, in bt_mesh_comp_data_get_page_1()
640 add_items_to_page(buf, &comp->elem[i].models[j], ext_mod_cnt, in bt_mesh_comp_data_get_page_1()
646 for (j = 0; j < comp->elem[i].vnd_model_count; j++) { in bt_mesh_comp_data_get_page_1()
647 prep_model_item_header(&comp->elem[i].vnd_models[j], &cor_id, &ext_mod_cnt, in bt_mesh_comp_data_get_page_1()
649 comp->elem[i].model_count); in bt_mesh_comp_data_get_page_1()
651 add_items_to_page(buf, &comp->elem[i].vnd_models[j], ext_mod_cnt, in bt_mesh_comp_data_get_page_1()
653 comp->elem[i].model_count); in bt_mesh_comp_data_get_page_1()
664 return -ENODEV; in bt_mesh_comp_data_get_page_2()
669 for (int i = 0; i < dev_comp2->record_cnt; i++) { in bt_mesh_comp_data_get_page_2()
671 8 + dev_comp2->record[i].elem_offset_cnt + dev_comp2->record[i].data_len; in bt_mesh_comp_data_get_page_2()
673 offset -= elem_size; in bt_mesh_comp_data_get_page_2()
677 if (net_buf_simple_tailroom(buf) < ((elem_size - offset) + BT_MESH_MIC_SHORT)) { in bt_mesh_comp_data_get_page_2()
683 LOG_DBG("Record 0x%04x didn't fit in the Data field", i); in bt_mesh_comp_data_get_page_2()
688 return -E2BIG; in bt_mesh_comp_data_get_page_2()
691 data_buf_add_le16_offset(buf, dev_comp2->record[i].id, &offset); in bt_mesh_comp_data_get_page_2()
692 data_buf_add_u8_offset(buf, dev_comp2->record[i].version.x, &offset); in bt_mesh_comp_data_get_page_2()
693 data_buf_add_u8_offset(buf, dev_comp2->record[i].version.y, &offset); in bt_mesh_comp_data_get_page_2()
694 data_buf_add_u8_offset(buf, dev_comp2->record[i].version.z, &offset); in bt_mesh_comp_data_get_page_2()
695 data_buf_add_u8_offset(buf, dev_comp2->record[i].elem_offset_cnt, &offset); in bt_mesh_comp_data_get_page_2()
696 if (dev_comp2->record[i].elem_offset_cnt) { in bt_mesh_comp_data_get_page_2()
697 data_buf_add_mem_offset(buf, dev_comp2->record[i].elem_offset, in bt_mesh_comp_data_get_page_2()
698 dev_comp2->record[i].elem_offset_cnt, &offset); in bt_mesh_comp_data_get_page_2()
701 data_buf_add_le16_offset(buf, dev_comp2->record[i].data_len, &offset); in bt_mesh_comp_data_get_page_2()
702 if (dev_comp2->record[i].data_len) { in bt_mesh_comp_data_get_page_2()
703 data_buf_add_mem_offset(buf, dev_comp2->record[i].data, in bt_mesh_comp_data_get_page_2()
704 dev_comp2->record[i].data_len, &offset); in bt_mesh_comp_data_get_page_2()
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()
753 struct bt_mesh_model_pub *pub = mod->pub; in next_period()
757 elapsed = k_uptime_get_32() - pub->period_start; 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()
770 if (!!pub->delayable) { in next_period()
778 return BT_MESH_PUB_TRANSMIT_INT(mod->pub->retransmit); in next_period()
792 if (!!pub->delayable) { in next_period()
800 return period - elapsed; in next_period()
817 k_work_schedule(&mod->pub->timer, K_MSEC(delay)); in publish_sent()
838 struct bt_mesh_model_pub *pub = mod->pub; in publish_transmit()
842 .src = bt_mesh_model_elem(mod)->rt->addr, in publish_transmit()
843 .friend_cred = pub->cred, in publish_transmit()
846 net_buf_simple_add_mem(&sdu, pub->msg->data, pub->msg->len); in publish_transmit()
855 pub->count = BT_MESH_PUB_TRANSMIT_COUNT(pub->retransmit); in pub_period_start()
857 if (!pub->update) { in pub_period_start()
861 err = pub->update(pub->mod); in pub_period_start()
863 pub->period_start = k_uptime_get_32(); in pub_period_start()
868 pub->count = 0; in pub_period_start()
869 publish_sent(err, (void *)pub->mod); in pub_period_start()
895 return -ENOTSUP; in pub_delay_schedule()
899 err = k_work_reschedule(&pub->timer, K_MSEC(random)); in pub_delay_schedule()
917 if (pub->addr == BT_MESH_ADDR_UNASSIGNED || in mod_publish()
919 /* Publication is no longer active, but the cancellation of the in mod_publish()
927 if (pub->count) { in mod_publish()
928 pub->count--; in mod_publish()
930 if (pub->retr_update && pub->update && in mod_publish()
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()
946 if (!!pub->delayable && !pub_delay_schedule(pub, RANDOM_DELAY_SHORT)) { in mod_publish()
948 pub->count++; in mod_publish()
953 err = publish_transmit(pub->mod); in mod_publish()
956 publish_sent(err, (void *)pub->mod); in mod_publish()
962 return &dev_comp->elem[mod->rt->elem_idx]; in bt_mesh_model_elem()
969 if (elem_idx >= dev_comp->elem_count) { in bt_mesh_model_get()
974 elem = &dev_comp->elem[elem_idx]; in bt_mesh_model_get()
977 if (mod_idx >= elem->vnd_model_count) { in bt_mesh_model_get()
982 return &elem->vnd_models[mod_idx]; in bt_mesh_model_get()
984 if (mod_idx >= elem->model_count) { in bt_mesh_model_get()
989 return &elem->models[mod_idx]; in bt_mesh_model_get()
999 for (op = mod->op; op->func; op++) { in bt_mesh_vnd_mod_msg_cid_check()
1000 cid = (uint16_t)(op->opcode & 0xffff); in bt_mesh_vnd_mod_msg_cid_check()
1002 if (cid == mod->vnd.company) { in bt_mesh_vnd_mod_msg_cid_check()
1006 LOG_ERR("Invalid vendor model(company:0x%04x" in bt_mesh_vnd_mod_msg_cid_check()
1007 " id:0x%04x) message opcode 0x%08x", 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()
1010 return -EINVAL; in bt_mesh_vnd_mod_msg_cid_check()
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()
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()
1061 if (!comp || !comp->elem_count) { in bt_mesh_comp_register()
1062 return -EINVAL; in bt_mesh_comp_register()
1091 MOD_REL_LIST_SIZE - i); in bt_mesh_comp_register()
1101 return -EINVAL; in bt_mesh_comp2_register()
1115 LOG_DBG("addr 0x%04x elem_count %zu", addr, dev_comp->elem_count); in bt_mesh_comp_provision()
1117 for (i = 0; i < dev_comp->elem_count; i++) { in bt_mesh_comp_provision()
1118 const struct bt_mesh_elem *elem = &dev_comp->elem[i]; in bt_mesh_comp_provision()
1120 elem->rt->addr = addr++; in bt_mesh_comp_provision()
1122 LOG_DBG("addr 0x%04x mod_count %u vnd_mod_count %u", elem->rt->addr, in bt_mesh_comp_provision()
1123 elem->model_count, elem->vnd_model_count); in bt_mesh_comp_provision()
1133 for (int i = 0; i < dev_comp->elem_count; i++) { in bt_mesh_comp_unprovision()
1134 const struct bt_mesh_elem *elem = &dev_comp->elem[i]; in bt_mesh_comp_unprovision()
1136 elem->rt->addr = BT_MESH_ADDR_UNASSIGNED; in bt_mesh_comp_unprovision()
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()
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()
1173 if (ctx->entry) { in find_group_mod_visitor()
1174 ctx->mod = mod; in find_group_mod_visitor()
1201 if (mod->uuids[i] == uuid) { in model_uuid_get()
1209 return &mod->uuids[i]; in model_uuid_get()
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()
1231 if (ctx->entry) { in find_uuid_mod_visitor()
1232 ctx->mod = mod; in find_uuid_mod_visitor()
1265 for (i = 0; i < elem->model_count; i++) { in bt_mesh_elem_find_group()
1266 model = &elem->models[i]; in bt_mesh_elem_find_group()
1274 for (i = 0; i < elem->vnd_model_count; i++) { in bt_mesh_elem_find_group()
1275 model = &elem->vnd_models[i]; in bt_mesh_elem_find_group()
1294 index = addr - dev_comp->elem[0].rt->addr; in bt_mesh_elem_find()
1295 if (index >= dev_comp->elem_count) { in bt_mesh_elem_find()
1299 return &dev_comp->elem[index]; in bt_mesh_elem_find()
1314 for (index = 0; index < dev_comp->elem_count; index++) { in bt_mesh_has_addr()
1315 const struct bt_mesh_elem *elem = &dev_comp->elem[index]; in bt_mesh_has_addr()
1341 LOG_DBG("net_idx 0x%04x app_idx 0x%04x dst 0x%04x", tx.ctx->net_idx, tx.ctx->app_idx, in bt_mesh_access_send()
1342 tx.ctx->addr); in bt_mesh_access_send()
1343 LOG_DBG("len %u: %s", buf->len, bt_hex(buf->data, buf->len)); in bt_mesh_access_send()
1347 return -EAGAIN; in bt_mesh_access_send()
1355 return dev_comp->elem_count; in bt_mesh_elem_count()
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()
1376 return (dev_comp->elem[mod->rt->elem_idx].rt->addr == dst); in model_has_dst()
1380 (BT_MESH_ADDR_IS_FIXED_GROUP(dst) && mod->rt->elem_idx != 0)) { in model_has_dst()
1388 return mod->rt->elem_idx == 0; in model_has_dst()
1400 /* SIG models cannot contain 3-byte (vendor) OpCodes, and in find_op()
1401 * vendor models cannot contain SIG (1- or 2-byte) OpCodes, so in find_op()
1405 models = elem->models; in find_op()
1406 count = elem->model_count; in find_op()
1408 models = elem->vnd_models; in find_op()
1409 count = elem->vnd_model_count; in find_op()
1426 for (op = (*model)->op; op->func; op++) { in find_op()
1427 if (op->opcode == opcode) { in find_op()
1439 switch (buf->data[0] >> 6) { in get_opcode()
1442 if (buf->data[0] == 0x7f) { in get_opcode()
1444 return -EINVAL; in get_opcode()
1450 if (buf->len < 2) { in get_opcode()
1451 LOG_ERR("Too short payload for 2-octet OpCode"); in get_opcode()
1452 return -EINVAL; in get_opcode()
1458 if (buf->len < 3) { in get_opcode()
1459 LOG_ERR("Too short payload for 3-octet OpCode"); in get_opcode()
1460 return -EINVAL; in get_opcode()
1465 * little-endian in the mesh spec and using BT_MESH_MODEL_OP_3 in get_opcode()
1485 LOG_DBG("No OpCode 0x%08x for elem 0x%02x", opcode, elem->rt->addr); in element_model_recv()
1489 if (!bt_mesh_model_has_key(model, ctx->app_idx)) { in element_model_recv()
1490 LOG_DBG("Model at 0x%04x is not bound to app idx %d", elem->rt->addr, ctx->app_idx); in element_model_recv()
1494 if (!model_has_dst(model, ctx->recv_dst, ctx->uuid)) { in element_model_recv()
1495 LOG_DBG("Dst addr 0x%02x is invalid for model at 0x%04x", ctx->recv_dst, in element_model_recv()
1496 elem->rt->addr); in element_model_recv()
1500 if ((op->len >= 0) && (buf->len < (size_t)op->len)) { in element_model_recv()
1501 LOG_ERR("Too short message for OpCode 0x%08x", opcode); in element_model_recv()
1503 } else if ((op->len < 0) && (buf->len != (size_t)(-op->len))) { in element_model_recv()
1504 LOG_ERR("Invalid message size for OpCode 0x%08x", opcode); in element_model_recv()
1509 ctx->rnd_delay = true; in element_model_recv()
1513 err = op->func(model, ctx, buf); in element_model_recv()
1528 LOG_DBG("app_idx 0x%04x src 0x%04x dst 0x%04x", ctx->app_idx, ctx->addr, in bt_mesh_model_recv()
1529 ctx->recv_dst); in bt_mesh_model_recv()
1530 LOG_DBG("len %u: %s", buf->len, bt_hex(buf->data, buf->len)); in bt_mesh_model_recv()
1533 bt_mesh_test_model_recv(ctx->addr, ctx->recv_dst, buf->data, buf->len); in bt_mesh_model_recv()
1541 LOG_DBG("OpCode 0x%08x", opcode); in bt_mesh_model_recv()
1543 if (BT_MESH_ADDR_IS_UNICAST(ctx->recv_dst)) { in bt_mesh_model_recv()
1544 index = ctx->recv_dst - dev_comp->elem[0].rt->addr; in bt_mesh_model_recv()
1546 if (index >= dev_comp->elem_count) { in bt_mesh_model_recv()
1547 LOG_ERR("Invalid address 0x%02x", ctx->recv_dst); in bt_mesh_model_recv()
1550 const struct bt_mesh_elem *elem = &dev_comp->elem[index]; in bt_mesh_model_recv()
1556 for (index = 0; index < dev_comp->elem_count; index++) { in bt_mesh_model_recv()
1557 const struct bt_mesh_elem *elem = &dev_comp->elem[index]; in bt_mesh_model_recv()
1599 if (!bt_mesh_model_has_key(model, ctx->app_idx)) { in bt_mesh_model_send()
1600 LOG_ERR("Model not bound to AppKey 0x%04x", ctx->app_idx); in bt_mesh_model_send()
1601 return -EINVAL; in bt_mesh_model_send()
1606 if (ctx->rnd_delay && in bt_mesh_model_send()
1607 !(bt_mesh_has_addr(ctx->addr) && BT_MESH_ADDR_IS_UNICAST(ctx->addr))) { in bt_mesh_model_send()
1608 return bt_mesh_delayable_msg_manage(ctx, msg, bt_mesh_model_elem(model)->rt->addr, in bt_mesh_model_send()
1613 return bt_mesh_access_send(ctx, msg, bt_mesh_model_elem(model)->rt->addr, cb, cb_data); in bt_mesh_model_send()
1618 struct bt_mesh_model_pub *pub = model->pub; in bt_mesh_model_publish()
1621 return -ENOTSUP; in bt_mesh_model_publish()
1626 if (pub->addr == BT_MESH_ADDR_UNASSIGNED) { in bt_mesh_model_publish()
1627 return -EADDRNOTAVAIL; in bt_mesh_model_publish()
1630 if (!pub->msg || !pub->msg->len) { in bt_mesh_model_publish()
1632 return -EINVAL; in bt_mesh_model_publish()
1635 if (pub->msg->len + BT_MESH_MIC_SHORT > BT_MESH_TX_SDU_MAX) { in bt_mesh_model_publish()
1637 return -EMSGSIZE; in bt_mesh_model_publish()
1640 if (pub->count) { in bt_mesh_model_publish()
1645 pub->count = BT_MESH_PUB_MSG_TOTAL(pub); in bt_mesh_model_publish()
1646 pub->period_start = k_uptime_get_32(); in bt_mesh_model_publish()
1648 LOG_DBG("Publish Retransmit Count %u Interval %ums", pub->count, in bt_mesh_model_publish()
1649 BT_MESH_PUB_TRANSMIT_INT(pub->retransmit)); in bt_mesh_model_publish()
1654 * When the publication of a message is the result of a power-up, a state transition in bt_mesh_model_publish()
1659 if (!!pub->delayable && !pub_delay_schedule(pub, RANDOM_DELAY_LONG)) { in bt_mesh_model_publish()
1663 k_work_reschedule(&pub->timer, K_NO_WAIT); in bt_mesh_model_publish()
1673 for (i = 0U; i < elem->vnd_model_count; i++) { in bt_mesh_model_find_vnd()
1674 if (elem->vnd_models[i].vnd.company == company && in bt_mesh_model_find_vnd()
1675 elem->vnd_models[i].vnd.id == id) { in bt_mesh_model_find_vnd()
1676 return &elem->vnd_models[i]; in bt_mesh_model_find_vnd()
1688 for (i = 0U; i < elem->model_count; i++) { in bt_mesh_model_find()
1689 if (elem->models[i].id == id) { in bt_mesh_model_find()
1690 return &elem->models[i]; in bt_mesh_model_find()
1713 if (cb(model, user_data) == BT_MESH_WALK_STOP || !model->rt->next) { in bt_mesh_model_extensions_walk()
1718 for (it = model->rt->next; it != model; it = it->rt->next) { in bt_mesh_model_extensions_walk()
1735 for (i = 0U; i < elem->vnd_model_count; i++) { in get_sig_offset()
1736 if (&elem->vnd_models[i] == mod) { in get_sig_offset()
1737 return elem->model_count; in get_sig_offset()
1749 base->rt->elem_idx, in mod_rel_register()
1750 base->rt->mod_idx + get_sig_offset(base), in mod_rel_register()
1751 ext->rt->elem_idx, in mod_rel_register()
1752 ext->rt->mod_idx + get_sig_offset(ext), in mod_rel_register()
1769 return -ENOMEM; in mod_rel_register()
1777 const struct bt_mesh_model *a_next = a->rt->next; in bt_mesh_model_extend()
1778 const struct bt_mesh_model *b_next = b->rt->next; in bt_mesh_model_extend()
1781 base_mod->rt->flags |= BT_MESH_MOD_EXTENDED; in bt_mesh_model_extend()
1788 for (it = a; (it != NULL) && (it->rt->next != a); it = it->rt->next) { in bt_mesh_model_extend()
1796 b->rt->next = a_next; in bt_mesh_model_extend()
1798 b->rt->next = a; in bt_mesh_model_extend()
1802 a->rt->next = b_next; in bt_mesh_model_extend()
1804 a->rt->next = b; in bt_mesh_model_extend()
1812 return -ENOMEM; in bt_mesh_model_extend()
1825 return -ENOTSUP; in bt_mesh_model_correspond()
1855 return model->rt->flags & BT_MESH_MOD_EXTENDED; in bt_mesh_model_is_extended()
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()
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()
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()
1956 if (!mod->pub) { in mod_set_pub()
1958 return -EINVAL; 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()
1981 LOG_ERR("Failed to set \'model-pub\'"); 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()
1998 LOG_DBG("Restored model publication, dst 0x%04x app_idx 0x%03x", pub.base.addr, in mod_set_pub()
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()
2031 return -ENOENT; in mod_set()
2038 LOG_DBG("Decoded mod_key 0x%04x as elem_idx %u mod_idx %u", mod_key, elem_idx, mod_idx); in mod_set()
2043 return -ENOENT; in mod_set()
2049 return -ENOENT; in mod_set()
2079 return -ENOENT; in mod_set()
2115 uint16_t mod_key = (((uint16_t)mod->rt->elem_idx << 8) | mod->rt->mod_idx); in encode_mod_path()
2118 snprintk(path, path_len, "bt/mesh/v/%x/%s", mod_key, key); in encode_mod_path()
2120 snprintk(path, path_len, "bt/mesh/s/%x/%s", mod_key, key); in encode_mod_path()
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()
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()
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()
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()
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()
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()
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()
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()
2281 mod->rt->flags |= BT_MESH_MOD_BIND_PENDING; in bt_mesh_model_bind_store()
2287 mod->rt->flags |= BT_MESH_MOD_SUB_PENDING; in bt_mesh_model_sub_store()
2293 mod->rt->flags |= BT_MESH_MOD_PUB_PENDING; in bt_mesh_model_pub_store()
2307 return -EINVAL; in bt_mesh_comp_data_get_page()
2314 size_t size = 10; /* Non-variable length params of comp page 0. */ in comp_page_0_size()
2318 for (int i = 0; i < comp->elem_count; i++) { in comp_page_0_size()
2319 elem = &comp->elem[i]; in comp_page_0_size()
2333 for (int i = 0; i < comp->elem_count; i++) { in comp_page_1_size()
2335 size += page1_elem_size(&comp->elem[i]); in comp_page_1_size()
2350 for (int i = 0; i < dev_comp2->record_cnt; i++) { in comp_page_2_size()
2351 size += 8 + dev_comp2->record[i].elem_offset_cnt + dev_comp2->record[i].data_len; in comp_page_2_size()
2407 return -ENOTSUP; in bt_mesh_comp_change_prepare()
2434 return -ENOBUFS; in read_comp_cb()
2442 return -EALREADY; in read_comp_cb()
2447 size_t original_len = buf->len; in bt_mesh_comp_read()
2452 return -ENOTSUP; in bt_mesh_comp_read()
2462 return -ENOENT; in bt_mesh_comp_read()
2471 if (buf->len == original_len) { in bt_mesh_comp_read()
2472 return -ENOENT; in bt_mesh_comp_read()
2531 if (err == -E2BIG) { in bt_mesh_models_metadata_store()
2555 size_t original_len = buf->len; in bt_mesh_models_metadata_read()
2559 return -ENOTSUP; in bt_mesh_models_metadata_read()
2573 net_buf_simple_add_mem(buf, &stored_buf.data, MIN(net_buf_simple_tailroom(buf), 2)); in bt_mesh_models_metadata_read()
2580 MIN(net_buf_simple_tailroom(buf), stored_buf.len - offset)); in bt_mesh_models_metadata_read()
2582 LOG_DBG("metadata read %d", buf->len); in bt_mesh_models_metadata_read()
2584 if (buf->len == original_len) { in bt_mesh_models_metadata_read()
2585 return -ENOENT; in bt_mesh_models_metadata_read()
2622 return -ENOTSUP; in bt_mesh_models_metadata_change_prepare()
2629 if (mod->pub && mod->pub->update && in commit_mod()
2630 mod->pub->addr != BT_MESH_ADDR_UNASSIGNED) { in commit_mod()
2634 /* Delay the first publication after power-up for longer time (section in commit_mod()
2637 * When the publication of a message is the result of a power-up, a state 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()
2670 mod->rt->flags |= BT_MESH_MOD_DATA_PENDING; in bt_mesh_model_data_store_schedule()