Lines Matching refs:bt_mesh
90 struct bt_mesh_net bt_mesh = { variable
91 .local_queue = SYS_SLIST_STATIC_INIT(&bt_mesh.local_queue),
191 (bt_mesh.seq % CONFIG_BT_MESH_SEQ_STORE_RATE)) { in bt_mesh_net_seq_store()
221 bt_mesh.iv_index = iv_index; in bt_mesh_net_create()
222 atomic_set_bit_to(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS, in bt_mesh_net_create()
234 bt_mesh.ivu_duration = BT_MESH_IVU_MIN_HOURS; in bt_mesh_net_create()
236 bt_mesh.ivu_duration = 0U; in bt_mesh_net_create()
251 atomic_set_bit_to(bt_mesh.flags, BT_MESH_IVU_TEST, enable); in bt_mesh_iv_update_test()
253 bt_mesh.ivu_duration = 0U; in bt_mesh_iv_update_test()
263 if (atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)) { in bt_mesh_iv_update()
264 bt_mesh_net_iv_update(bt_mesh.iv_index, false); in bt_mesh_iv_update()
266 bt_mesh_net_iv_update(bt_mesh.iv_index + 1, true); in bt_mesh_iv_update()
269 return atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS); in bt_mesh_iv_update()
276 if (iv_index < bt_mesh.iv_index || in bt_mesh_net_iv_update()
277 iv_index > bt_mesh.iv_index + 42) { in bt_mesh_net_iv_update()
278 LOG_ERR("IV Index out of sync: 0x%08x != 0x%08x", iv_index, bt_mesh.iv_index); in bt_mesh_net_iv_update()
283 if (iv_index == bt_mesh.iv_index && iv_update) { in bt_mesh_net_iv_update()
288 if ((iv_index > bt_mesh.iv_index + 1) || in bt_mesh_net_iv_update()
289 (iv_index == bt_mesh.iv_index + 1 && in bt_mesh_net_iv_update()
290 (atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS) || !iv_update))) { in bt_mesh_net_iv_update()
292 (bt_mesh.ivu_duration < (2 * BT_MESH_IVU_MIN_HOURS))) { in bt_mesh_net_iv_update()
312 bt_mesh.iv_index = iv_index; in bt_mesh_net_iv_update()
313 bt_mesh.seq = 0U; in bt_mesh_net_iv_update()
318 if (atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS) == iv_update) { in bt_mesh_net_iv_update()
324 atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_TEST))) { in bt_mesh_net_iv_update()
325 if (bt_mesh.ivu_duration < BT_MESH_IVU_MIN_HOURS) { in bt_mesh_net_iv_update()
334 atomic_set_bit(bt_mesh.flags, BT_MESH_IVU_PENDING); in bt_mesh_net_iv_update()
339 bt_mesh.iv_index = iv_index; in bt_mesh_net_iv_update()
340 LOG_DBG("IV Update state entered. New index 0x%08x", bt_mesh.iv_index); in bt_mesh_net_iv_update()
346 bt_mesh.seq = 0U; in bt_mesh_net_iv_update()
350 atomic_set_bit_to(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS, iv_update); in bt_mesh_net_iv_update()
351 bt_mesh.ivu_duration = 0U; in bt_mesh_net_iv_update()
353 k_work_reschedule(&bt_mesh.ivu_timer, BT_MESH_IVU_TIMEOUT); in bt_mesh_net_iv_update()
381 uint32_t seq = bt_mesh.seq++; in bt_mesh_next_seq()
387 if (!atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS) && in bt_mesh_next_seq()
388 bt_mesh.seq > IV_UPDATE_SEQ_LIMIT && in bt_mesh_next_seq()
391 bt_mesh_net_iv_update(bt_mesh.iv_index + 1, true); in bt_mesh_next_seq()
402 while ((node = sys_slist_get(&bt_mesh.local_queue))) { in bt_mesh_net_local()
418 .old_iv = (IVI(buf->data) != (bt_mesh.iv_index & 0x01)), in bt_mesh_net_local()
438 if (tx->friend_cred && bt_mesh.lpn.frnd) { in net_tx_cred_get()
439 return &bt_mesh.lpn.cred[SUBNET_KEY_TX_IDX(tx->sub)]; in net_tx_cred_get()
461 bt_mesh.seq); in net_header_encode()
524 sys_slist_append(&bt_mesh.local_queue, &buf->node); in net_loopback()
526 k_work_submit(&bt_mesh.local_work); in net_loopback()
540 LOG_DBG("Seq 0x%06x", bt_mesh.seq); in bt_mesh_net_send()
608 while ((node = sys_slist_get(&bt_mesh.local_queue))) { in bt_mesh_net_loopback_clear()
619 bt_mesh.local_queue = new_list; in bt_mesh_net_loopback_clear()
633 LOG_DBG("IVI %u net->iv_index 0x%08x", IVI(in->data), bt_mesh.iv_index); in net_decrypt()
635 rx->old_iv = (IVI(in->data) != (bt_mesh.iv_index & 0x01)); in net_decrypt()
797 rx->old_iv = (IVI(buf->data) != (bt_mesh.iv_index & 0x01)); in bt_mesh_net_header_parse()
959 bt_mesh.ivu_duration = MIN(UINT8_MAX, in ivu_refresh()
960 bt_mesh.ivu_duration + BT_MESH_IVU_HOURS); in ivu_refresh()
963 atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS) ? "IVU in Progress" in ivu_refresh()
965 bt_mesh.ivu_duration, bt_mesh.ivu_duration == 1U ? "" : "s"); in ivu_refresh()
967 if (bt_mesh.ivu_duration < BT_MESH_IVU_MIN_HOURS) { in ivu_refresh()
979 if (!(bt_mesh.ivu_duration % BT_MESH_IVU_MIN_HOURS)) { in ivu_refresh()
983 if (atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS)) { in ivu_refresh()
985 bt_mesh_net_iv_update(bt_mesh.iv_index, false); in ivu_refresh()
991 k_work_reschedule(&bt_mesh.ivu_timer, BT_MESH_IVU_TIMEOUT); in ivu_refresh()
996 k_work_init_delayable(&bt_mesh.ivu_timer, ivu_refresh); in bt_mesh_net_init()
998 k_work_init(&bt_mesh.local_work, bt_mesh_net_local); in bt_mesh_net_init()
1012 bt_mesh_key_destroy(&bt_mesh.dev_key); in net_set()
1013 memset(&bt_mesh.dev_key, 0, sizeof(struct bt_mesh_key)); in net_set()
1028 bt_mesh_key_assign(&bt_mesh.dev_key, &key); in net_set()
1032 LOG_DBG("Recovered DevKey %s", bt_hex(&bt_mesh.dev_key, sizeof(struct bt_mesh_key))); in net_set()
1048 bt_mesh.iv_index = 0U; in iv_set()
1049 atomic_clear_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS); in iv_set()
1059 bt_mesh.iv_index = iv.iv_index; in iv_set()
1060 atomic_set_bit_to(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS, iv.iv_update); in iv_set()
1061 bt_mesh.ivu_duration = iv.iv_duration; in iv_set()
1080 bt_mesh.seq = 0U; in seq_set()
1090 bt_mesh.seq = sys_get_le24(seq.val); in seq_set()
1097 bt_mesh.seq += (CONFIG_BT_MESH_SEQ_STORE_RATE - in seq_set()
1098 (bt_mesh.seq % CONFIG_BT_MESH_SEQ_STORE_RATE)); in seq_set()
1099 bt_mesh.seq--; in seq_set()
1102 LOG_DBG("Sequence Number 0x%06x", bt_mesh.seq); in seq_set()
1118 err = bt_mesh_settings_set(read_cb, cb_arg, &bt_mesh.dev_key_cand, in dev_key_cand_set()
1122 atomic_set_bit(bt_mesh.flags, BT_MESH_DEVKEY_CAND); in dev_key_cand_set()
1136 if (atomic_test_bit(bt_mesh.flags, BT_MESH_DEVKEY_CAND)) { in bt_mesh_net_pending_dev_key_cand_store()
1137 err = settings_save_one("bt/mesh/DevKeyC", &bt_mesh.dev_key_cand, in bt_mesh_net_pending_dev_key_cand_store()
1173 iv.iv_index = bt_mesh.iv_index; in store_pending_iv()
1174 iv.iv_update = atomic_test_bit(bt_mesh.flags, BT_MESH_IVU_IN_PROGRESS); in store_pending_iv()
1175 iv.iv_duration = bt_mesh.ivu_duration; in store_pending_iv()
1187 if (atomic_test_bit(bt_mesh.flags, BT_MESH_VALID)) { in bt_mesh_net_pending_iv_store()
1212 bt_hex(&bt_mesh.dev_key, sizeof(struct bt_mesh_key))); in store_pending_net()
1215 memcpy(&net.dev_key, &bt_mesh.dev_key, sizeof(struct bt_mesh_key)); in store_pending_net()
1227 if (atomic_test_bit(bt_mesh.flags, BT_MESH_VALID)) { in bt_mesh_net_pending_net_store()
1239 if (atomic_test_bit(bt_mesh.flags, BT_MESH_VALID)) { in bt_mesh_net_pending_seq_store()
1240 sys_put_le24(bt_mesh.seq, seq.val); in bt_mesh_net_pending_seq_store()
1273 if (bt_mesh.ivu_duration < BT_MESH_IVU_MIN_HOURS) { in bt_mesh_net_settings_commit()
1274 k_work_reschedule(&bt_mesh.ivu_timer, BT_MESH_IVU_TIMEOUT); in bt_mesh_net_settings_commit()