Lines Matching +full:tracking +full:- +full:index

4  * SPDX-License-Identifier: Apache-2.0
28 /* Tracking of what storage changes are pending for App and Net Keys. We
34 uint16_t key_idx:12, /* AppKey or NetKey Index */
40 /* Tracking of what storage changes are pending for node settings. */
73 uint32_t index; member
86 [0 ... (CONFIG_BT_MESH_CDB_NODE_COUNT - 1)] = {
91 [0 ... (CONFIG_BT_MESH_CDB_SUBNET_COUNT - 1)] = {
96 [0 ... (CONFIG_BT_MESH_CDB_APP_KEY_COUNT - 1)] = {
104 * Check if an address range from addr_start for addr_start + num_elem - 1 is
106 * available after the conflicting range and -EAGAIN will be returned.
110 uint16_t addr_end = addr_start + num_elem - 1; in addr_is_free()
117 return -EINVAL; in addr_is_free()
123 if (node->addr == BT_MESH_ADDR_UNASSIGNED) { in addr_is_free()
127 other_start = node->addr; in addr_is_free()
128 other_end = other_start + node->num_elem - 1; in addr_is_free()
135 return -EAGAIN; in addr_is_free()
166 } else if (err != -EAGAIN) { in find_lowest_free_addr()
200 bt_mesh_cdb.iv_index = net.iv.index; in cdb_net_set()
224 return -ENOENT; in cdb_node_set()
255 return -ENOMEM; in cdb_node_set()
259 atomic_set_bit(node->flags, BT_MESH_CDB_NODE_CONFIGURED); in cdb_node_set()
262 memcpy(node->uuid, val.uuid, 16); in cdb_node_set()
268 bt_mesh_key_assign(&node->dev_key, &tmp); in cdb_node_set()
286 return -ENOENT; in cdb_subnet_set()
296 return -ENOENT; in cdb_subnet_set()
306 LOG_ERR("Failed to set \'net-key\'"); in cdb_subnet_set()
319 sub->kr_phase = key.kr_phase; in cdb_subnet_set()
320 bt_mesh_key_assign(&sub->keys[0].net_key, &tmp[0]); in cdb_subnet_set()
321 bt_mesh_key_assign(&sub->keys[1].net_key, &tmp[1]); in cdb_subnet_set()
329 return -ENOMEM; in cdb_subnet_set()
332 sub->kr_phase = key.kr_phase; in cdb_subnet_set()
333 bt_mesh_key_assign(&sub->keys[0].net_key, &tmp[0]); in cdb_subnet_set()
334 bt_mesh_key_assign(&sub->keys[1].net_key, &tmp[1]); in cdb_subnet_set()
352 return -ENOENT; in cdb_app_key_set()
371 LOG_ERR("Failed to set \'app-key\'"); in cdb_app_key_set()
388 return -ENOMEM; in cdb_app_key_set()
391 bt_mesh_key_assign(&app->keys[0].app_key, &tmp[0]); in cdb_app_key_set()
392 bt_mesh_key_assign(&app->keys[1].app_key, &tmp[1]); in cdb_app_key_set()
407 return -ENOENT; in cdb_set()
419 return -ENOENT; in cdb_set()
435 return -ENOENT; in cdb_set()
446 val.net_idx = node->net_idx; in store_cdb_node()
447 val.num_elem = node->num_elem; in store_cdb_node()
450 if (atomic_test_bit(node->flags, BT_MESH_CDB_NODE_CONFIGURED)) { in store_cdb_node()
454 memcpy(val.uuid, node->uuid, 16); in store_cdb_node()
455 memcpy(&val.dev_key, &node->dev_key, sizeof(struct bt_mesh_key)); in store_cdb_node()
457 snprintk(path, sizeof(path), "bt/mesh/cdb/Node/%x", node->addr); in store_cdb_node()
489 LOG_DBG("NetKeyIndex 0x%03x NetKey %s", sub->net_idx, in store_cdb_subnet()
490 bt_hex(&sub->keys[0].net_key, sizeof(struct bt_mesh_key))); in store_cdb_subnet()
492 memcpy(&key.val[0], &sub->keys[0].net_key, sizeof(struct bt_mesh_key)); in store_cdb_subnet()
493 memcpy(&key.val[1], &sub->keys[1].net_key, sizeof(struct bt_mesh_key)); in store_cdb_subnet()
495 key.kr_phase = sub->kr_phase; in store_cdb_subnet()
497 snprintk(path, sizeof(path), "bt/mesh/cdb/Subnet/%x", sub->net_idx); in store_cdb_subnet()
529 key.net_idx = app->net_idx; in store_cdb_app_key()
531 memcpy(&key.val[0], &app->keys[0].app_key, sizeof(struct bt_mesh_key)); in store_cdb_app_key()
532 memcpy(&key.val[1], &app->keys[1].app_key, sizeof(struct bt_mesh_key)); in store_cdb_app_key()
534 snprintk(path, sizeof(path), "bt/mesh/cdb/AppKey/%x", app->app_idx); in store_cdb_app_key()
581 if (update->addr == BT_MESH_ADDR_UNASSIGNED) { in cdb_node_update_find()
586 if (update->addr == addr) { in cdb_node_update_find()
599 LOG_DBG("Node 0x%04x", node->addr); in update_cdb_node_settings()
601 update = cdb_node_update_find(node->addr, &free_slot); in update_cdb_node_settings()
603 update->clear = !store; in update_cdb_node_settings()
612 clear_cdb_node(node->addr); in update_cdb_node_settings()
617 free_slot->addr = node->addr; in update_cdb_node_settings()
618 free_slot->clear = !store; in update_cdb_node_settings()
635 if (!update->valid) { in cdb_key_update_find()
640 if (update->app_key != app_key) { in cdb_key_update_find()
644 if (update->key_idx == key_idx) { in cdb_key_update_find()
658 LOG_DBG("NetKeyIndex 0x%03x", sub->net_idx); in update_cdb_subnet_settings()
660 update = cdb_key_update_find(false, sub->net_idx, &free_slot); in update_cdb_subnet_settings()
662 update->clear = clear; in update_cdb_subnet_settings()
671 clear_cdb_subnet(sub->net_idx); in update_cdb_subnet_settings()
676 free_slot->valid = 1U; in update_cdb_subnet_settings()
677 free_slot->key_idx = sub->net_idx; in update_cdb_subnet_settings()
678 free_slot->app_key = 0U; in update_cdb_subnet_settings()
679 free_slot->clear = clear; in update_cdb_subnet_settings()
690 LOG_DBG("AppKeyIndex 0x%03x", key->app_idx); in update_cdb_app_key_settings()
692 update = cdb_key_update_find(true, key->app_idx, &free_slot); in update_cdb_app_key_settings()
694 update->clear = clear; in update_cdb_app_key_settings()
703 clear_cdb_app_key(key->app_idx); in update_cdb_app_key_settings()
709 free_slot->valid = 1U; in update_cdb_app_key_settings()
710 free_slot->key_idx = key->app_idx; in update_cdb_app_key_settings()
711 free_slot->app_key = 1U; in update_cdb_app_key_settings()
712 free_slot->clear = clear; in update_cdb_app_key_settings()
724 LOG_DBG("Address range 0x%04x-0x%04x is not free", addr, in addr_assign()
725 addr + num_elem - 1); in addr_assign()
739 return -EALREADY; in bt_mesh_cdb_create()
744 return -ENOMEM; in bt_mesh_cdb_create()
747 err = bt_mesh_key_import(BT_MESH_KEY_TYPE_NET, key, &sub->keys[0].net_key); in bt_mesh_cdb_create()
795 LOG_DBG("Updating IV index to %d\n", iv_index); in bt_mesh_cdb_iv_update()
797 /* Reset the last deleted addr when IV Index is updated or recovered. */ in bt_mesh_cdb_iv_update()
824 if (sub->net_idx != BT_MESH_KEY_UNUSED) { in bt_mesh_cdb_subnet_alloc()
828 sub->net_idx = net_idx; in bt_mesh_cdb_subnet_alloc()
838 LOG_DBG("NetIdx 0x%03x store %u", sub->net_idx, store); in bt_mesh_cdb_subnet_del()
844 sub->net_idx = BT_MESH_KEY_UNUSED; in bt_mesh_cdb_subnet_del()
845 bt_mesh_key_destroy(&sub->keys[0].net_key); in bt_mesh_cdb_subnet_del()
846 bt_mesh_key_destroy(&sub->keys[1].net_key); in bt_mesh_cdb_subnet_del()
847 memset(sub->keys, 0, sizeof(sub->keys)); in bt_mesh_cdb_subnet_del()
888 if (!bt_mesh_key_compare(in, &sub->keys[key_idx].net_key)) { in bt_mesh_cdb_subnet_key_import()
892 bt_mesh_key_destroy(&sub->keys[key_idx].net_key); in bt_mesh_cdb_subnet_key_import()
894 return bt_mesh_key_import(BT_MESH_KEY_TYPE_NET, in, &sub->keys[key_idx].net_key); in bt_mesh_cdb_subnet_key_import()
900 return bt_mesh_key_export(out, &sub->keys[key_idx].net_key); in bt_mesh_cdb_subnet_key_export()
916 if (node->addr == BT_MESH_ADDR_UNASSIGNED) { in bt_mesh_cdb_node_alloc()
917 memcpy(node->uuid, uuid, 16); in bt_mesh_cdb_node_alloc()
918 node->addr = addr; in bt_mesh_cdb_node_alloc()
919 node->num_elem = num_elem; in bt_mesh_cdb_node_alloc()
920 node->net_idx = net_idx; in bt_mesh_cdb_node_alloc()
921 atomic_set(node->flags, 0); in bt_mesh_cdb_node_alloc()
936 LOG_DBG("Node addr 0x%04x store %u", node->addr, store); in bt_mesh_cdb_node_del()
942 if (store && node->addr + node->num_elem > bt_mesh_cdb.lowest_avail_addr) { in bt_mesh_cdb_node_del()
943 bt_mesh_cdb.lowest_avail_addr = node->addr + node->num_elem; in bt_mesh_cdb_node_del()
950 node->addr = BT_MESH_ADDR_UNASSIGNED; in bt_mesh_cdb_node_del()
951 bt_mesh_key_destroy(&node->dev_key); in bt_mesh_cdb_node_del()
952 memset(&node->dev_key, 0, sizeof(node->dev_key)); in bt_mesh_cdb_node_del()
965 node->addr = addr; in bt_mesh_cdb_node_update()
966 node->num_elem = num_elem; in bt_mesh_cdb_node_update()
980 if (addr >= node->addr && in bt_mesh_cdb_node_get()
981 addr <= node->addr + node->num_elem - 1) { in bt_mesh_cdb_node_get()
1014 if (!bt_mesh_key_compare(in, &node->dev_key)) { in bt_mesh_cdb_node_key_import()
1018 bt_mesh_key_destroy(&node->dev_key); in bt_mesh_cdb_node_key_import()
1020 return bt_mesh_key_import(BT_MESH_KEY_TYPE_DEV, in, &node->dev_key); in bt_mesh_cdb_node_key_import()
1025 return bt_mesh_key_export(out, &node->dev_key); in bt_mesh_cdb_node_key_export()
1037 if (key->app_idx == app_idx) { in bt_mesh_cdb_app_key_alloc()
1041 if (key->net_idx != BT_MESH_KEY_UNUSED || vacant_key) { in bt_mesh_cdb_app_key_alloc()
1049 vacant_key->net_idx = net_idx; in bt_mesh_cdb_app_key_alloc()
1050 vacant_key->app_idx = app_idx; in bt_mesh_cdb_app_key_alloc()
1058 LOG_DBG("AppIdx 0x%03x store %u", key->app_idx, store); in bt_mesh_cdb_app_key_del()
1064 key->net_idx = BT_MESH_KEY_UNUSED; in bt_mesh_cdb_app_key_del()
1065 key->app_idx = BT_MESH_KEY_UNUSED; in bt_mesh_cdb_app_key_del()
1066 bt_mesh_key_destroy(&key->keys[0].app_key); in bt_mesh_cdb_app_key_del()
1067 bt_mesh_key_destroy(&key->keys[1].app_key); in bt_mesh_cdb_app_key_del()
1068 memset(key->keys, 0, sizeof(key->keys)); in bt_mesh_cdb_app_key_del()
1078 if (key->net_idx != BT_MESH_KEY_UNUSED && in bt_mesh_cdb_app_key_get()
1079 key->app_idx == app_idx) { in bt_mesh_cdb_app_key_get()
1096 if (!bt_mesh_key_compare(in, &key->keys[key_idx].app_key)) { in bt_mesh_cdb_app_key_import()
1100 bt_mesh_key_destroy(&key->keys[key_idx].app_key); in bt_mesh_cdb_app_key_import()
1102 return bt_mesh_key_import(BT_MESH_KEY_TYPE_APP, in, &key->keys[key_idx].app_key); in bt_mesh_cdb_app_key_import()
1107 return bt_mesh_key_export(out, &key->keys[key_idx].app_key); in bt_mesh_cdb_app_key_export()
1129 net.iv.index = bt_mesh_cdb.iv_index; in store_cdb_pending_net()
1150 if (update->addr == BT_MESH_ADDR_UNASSIGNED) { in store_cdb_pending_nodes()
1154 addr = update->addr; in store_cdb_pending_nodes()
1155 update->addr = BT_MESH_ADDR_UNASSIGNED; in store_cdb_pending_nodes()
1157 LOG_DBG("addr: 0x%04x, clear: %d", addr, update->clear); in store_cdb_pending_nodes()
1159 if (update->clear) { in store_cdb_pending_nodes()
1181 if (!update->valid) { in store_cdb_pending_keys()
1185 update->valid = 0U; in store_cdb_pending_keys()
1187 if (update->clear) { in store_cdb_pending_keys()
1188 if (update->app_key) { in store_cdb_pending_keys()
1189 clear_cdb_app_key(update->key_idx); in store_cdb_pending_keys()
1191 clear_cdb_subnet(update->key_idx); in store_cdb_pending_keys()
1194 if (update->app_key) { in store_cdb_pending_keys()
1197 key = bt_mesh_cdb_app_key_get(update->key_idx); in store_cdb_pending_keys()
1201 LOG_WRN("AppKeyIndex 0x%03x not found", update->key_idx); in store_cdb_pending_keys()
1206 sub = bt_mesh_cdb_subnet_get(update->key_idx); in store_cdb_pending_keys()
1210 LOG_WRN("NetKeyIndex 0x%03x not found", update->key_idx); in store_cdb_pending_keys()