Lines Matching refs:sub
68 static void subnet_evt(struct bt_mesh_subnet *sub, enum bt_mesh_key_evt evt) in subnet_evt() argument
71 cb->evt_handler(sub, evt); in subnet_evt()
93 const struct bt_mesh_subnet *sub; in store_subnet() local
98 sub = bt_mesh_subnet_get(net_idx); in store_subnet()
99 if (!sub) { in store_subnet()
108 memcpy(&key.val[0], &sub->keys[0].net, sizeof(struct bt_mesh_key)); in store_subnet()
109 memcpy(&key.val[1], &sub->keys[1].net, sizeof(struct bt_mesh_key)); in store_subnet()
111 key.kr_phase = sub->kr_phase; in store_subnet()
146 uint8_t bt_mesh_net_flags(struct bt_mesh_subnet *sub) in bt_mesh_net_flags() argument
150 if (sub && (sub->kr_phase == BT_MESH_KR_PHASE_2)) { in bt_mesh_net_flags()
211 static void key_refresh(struct bt_mesh_subnet *sub, uint8_t new_phase) in key_refresh() argument
213 LOG_DBG("Phase 0x%02x -> 0x%02x", sub->kr_phase, new_phase); in key_refresh()
218 sub->kr_phase = new_phase; in key_refresh()
219 subnet_evt(sub, BT_MESH_KEY_UPDATED); in key_refresh()
223 sub->kr_phase = new_phase; in key_refresh()
224 subnet_evt(sub, BT_MESH_KEY_SWAPPED); in key_refresh()
228 if (sub->kr_phase == BT_MESH_KR_NORMAL) { in key_refresh()
233 sub->kr_phase = BT_MESH_KR_NORMAL; in key_refresh()
234 subnet_keys_destroy(&sub->keys[0]); in key_refresh()
235 memcpy(&sub->keys[0], &sub->keys[1], sizeof(sub->keys[0])); in key_refresh()
236 sub->keys[1].valid = 0U; in key_refresh()
237 subnet_evt(sub, BT_MESH_KEY_REVOKED); in key_refresh()
243 bt_mesh_subnet_store(sub->net_idx); in key_refresh()
247 void bt_mesh_kr_update(struct bt_mesh_subnet *sub, bool kr_flag, bool new_key) in bt_mesh_kr_update() argument
253 if (sub->kr_phase == BT_MESH_KR_PHASE_1) { in bt_mesh_kr_update()
257 key_refresh(sub, (kr_flag ? BT_MESH_KR_PHASE_2 : in bt_mesh_kr_update()
259 } else if (sub->kr_phase == BT_MESH_KR_PHASE_2 && !kr_flag) { in bt_mesh_kr_update()
260 key_refresh(sub, BT_MESH_KR_PHASE_3); in bt_mesh_kr_update()
266 struct bt_mesh_subnet *sub = NULL; in subnet_alloc() local
274 if (!sub && subnets[i].net_idx == BT_MESH_KEY_UNUSED) { in subnet_alloc()
275 sub = &subnets[i]; in subnet_alloc()
279 return sub; in subnet_alloc()
282 static void subnet_del(struct bt_mesh_subnet *sub) in subnet_del() argument
285 update_subnet_settings(sub->net_idx, false); in subnet_del()
288 for (int i = 0; i < ARRAY_SIZE(sub->keys); i++) { in subnet_del()
289 if (sub->keys[i].valid) { in subnet_del()
290 subnet_keys_destroy(&sub->keys[i]); in subnet_del()
294 bt_mesh_net_loopback_clear(sub->net_idx); in subnet_del()
296 subnet_evt(sub, BT_MESH_KEY_DELETED); in subnet_del()
297 (void)memset(sub, 0, sizeof(*sub)); in subnet_del()
298 sub->net_idx = BT_MESH_KEY_UNUSED; in subnet_del()
373 struct bt_mesh_subnet *sub = NULL; in bt_mesh_subnet_add() local
378 sub = subnet_alloc(net_idx); in bt_mesh_subnet_add()
379 if (!sub) { in bt_mesh_subnet_add()
383 if (sub->net_idx == net_idx) { in bt_mesh_subnet_add()
384 if (bt_mesh_key_compare(key, &sub->keys[0].net)) { in bt_mesh_subnet_add()
391 err = net_keys_create(&sub->keys[0], true, key); in bt_mesh_subnet_add()
396 sub->net_idx = net_idx; in bt_mesh_subnet_add()
397 sub->kr_phase = BT_MESH_KR_NORMAL; in bt_mesh_subnet_add()
400 sub->node_id = BT_MESH_NODE_IDENTITY_STOPPED; in bt_mesh_subnet_add()
402 sub->node_id = BT_MESH_NODE_IDENTITY_NOT_SUPPORTED; in bt_mesh_subnet_add()
405 subnet_evt(sub, BT_MESH_KEY_ADDED); in bt_mesh_subnet_add()
409 bt_mesh_subnet_store(sub->net_idx); in bt_mesh_subnet_add()
422 struct bt_mesh_subnet *sub; in bt_mesh_subnet_update() local
427 sub = bt_mesh_subnet_get(net_idx); in bt_mesh_subnet_update()
428 if (!sub) { in bt_mesh_subnet_update()
438 switch (sub->kr_phase) { in bt_mesh_subnet_update()
440 if (!bt_mesh_key_compare(key, &sub->keys[0].net)) { in bt_mesh_subnet_update()
445 if (!bt_mesh_key_compare(key, &sub->keys[1].net)) { in bt_mesh_subnet_update()
454 err = net_keys_create(&sub->keys[1], true, key); in bt_mesh_subnet_update()
459 key_refresh(sub, BT_MESH_KR_PHASE_1); in bt_mesh_subnet_update()
466 struct bt_mesh_subnet *sub; in bt_mesh_subnet_del() local
470 sub = bt_mesh_subnet_get(net_idx); in bt_mesh_subnet_del()
471 if (!sub) { in bt_mesh_subnet_del()
478 subnet_del(sub); in bt_mesh_subnet_del()
520 struct bt_mesh_subnet *sub; in bt_mesh_subnet_kr_phase_set() local
524 sub = bt_mesh_subnet_get(net_idx); in bt_mesh_subnet_kr_phase_set()
525 if (!sub) { in bt_mesh_subnet_kr_phase_set()
530 if (*phase == sub->kr_phase) { in bt_mesh_subnet_kr_phase_set()
534 if (sub->kr_phase < ARRAY_SIZE(valid_transitions) && in bt_mesh_subnet_kr_phase_set()
535 valid_transitions[sub->kr_phase] & BIT(*phase)) { in bt_mesh_subnet_kr_phase_set()
536 key_refresh(sub, *phase); in bt_mesh_subnet_kr_phase_set()
538 *phase = sub->kr_phase; in bt_mesh_subnet_kr_phase_set()
543 LOG_WRN("Invalid KR transition: 0x%02x -> 0x%02x", sub->kr_phase, *phase); in bt_mesh_subnet_kr_phase_set()
545 *phase = sub->kr_phase; in bt_mesh_subnet_kr_phase_set()
552 struct bt_mesh_subnet *sub; in bt_mesh_subnet_kr_phase_get() local
554 sub = bt_mesh_subnet_get(net_idx); in bt_mesh_subnet_kr_phase_get()
555 if (!sub) { in bt_mesh_subnet_kr_phase_get()
560 *phase = sub->kr_phase; in bt_mesh_subnet_kr_phase_get()
568 struct bt_mesh_subnet *sub; in bt_mesh_subnet_node_id_set() local
574 sub = bt_mesh_subnet_get(net_idx); in bt_mesh_subnet_node_id_set()
575 if (!sub) { in bt_mesh_subnet_node_id_set()
597 bt_mesh_proxy_identity_start(sub, false); in bt_mesh_subnet_node_id_set()
599 bt_mesh_proxy_identity_stop(sub); in bt_mesh_subnet_node_id_set()
610 struct bt_mesh_subnet *sub; in bt_mesh_subnet_node_id_get() local
612 sub = bt_mesh_subnet_get(net_idx); in bt_mesh_subnet_node_id_get()
613 if (!sub) { in bt_mesh_subnet_node_id_get()
618 *node_id = sub->node_id; in bt_mesh_subnet_node_id_get()
620 *node_id &= !sub->priv_beacon_ctx.node_id; in bt_mesh_subnet_node_id_get()
630 struct bt_mesh_subnet *sub; in bt_mesh_subnet_priv_node_id_set() local
636 sub = bt_mesh_subnet_get(net_idx); in bt_mesh_subnet_priv_node_id_set()
637 if (!sub) { in bt_mesh_subnet_priv_node_id_set()
660 bt_mesh_proxy_identity_start(sub, true); in bt_mesh_subnet_priv_node_id_set()
662 bt_mesh_proxy_identity_stop(sub); in bt_mesh_subnet_priv_node_id_set()
673 struct bt_mesh_subnet *sub; in bt_mesh_subnet_priv_node_id_get() local
675 sub = bt_mesh_subnet_get(net_idx); in bt_mesh_subnet_priv_node_id_get()
676 if (!sub) { in bt_mesh_subnet_priv_node_id_get()
682 if (sub->node_id == BT_MESH_FEATURE_ENABLED && sub->priv_beacon_ctx.node_id) { in bt_mesh_subnet_priv_node_id_get()
683 *priv_node_id = sub->node_id; in bt_mesh_subnet_priv_node_id_get()
715 struct bt_mesh_subnet *sub = &subnets[i]; in bt_mesh_subnets_get() local
717 if (sub->net_idx == BT_MESH_KEY_UNUSED) { in bt_mesh_subnets_get()
730 net_idxs[count++] = sub->net_idx; in bt_mesh_subnets_get()
739 struct bt_mesh_subnet *sub = &subnets[i]; in bt_mesh_subnet_get() local
741 if (sub->net_idx == net_idx) { in bt_mesh_subnet_get()
742 return sub; in bt_mesh_subnet_get()
749 static int subnet_key_set(struct bt_mesh_subnet *sub, int key_idx, const struct bt_mesh_key *key) in subnet_key_set() argument
759 bt_mesh_key_assign(&sub->keys[key_idx].net, key); in subnet_key_set()
760 err = net_keys_create(&sub->keys[key_idx], false, raw_key); in subnet_key_set()
771 struct bt_mesh_subnet *sub; in bt_mesh_subnet_set() local
774 sub = subnet_alloc(net_idx); in bt_mesh_subnet_set()
775 if (!sub) { in bt_mesh_subnet_set()
779 if (sub->net_idx == net_idx) { in bt_mesh_subnet_set()
784 err = subnet_key_set(sub, 0, old_key); in bt_mesh_subnet_set()
791 err = subnet_key_set(sub, 1, new_key); in bt_mesh_subnet_set()
797 sub->net_idx = net_idx; in bt_mesh_subnet_set()
798 sub->kr_phase = kr_phase; in bt_mesh_subnet_set()
801 sub->node_id = BT_MESH_NODE_IDENTITY_STOPPED; in bt_mesh_subnet_set()
803 sub->node_id = BT_MESH_NODE_IDENTITY_NOT_SUPPORTED; in bt_mesh_subnet_set()
807 bt_mesh_beacon_update(sub); in bt_mesh_subnet_set()
812 struct bt_mesh_subnet *bt_mesh_subnet_find(bool (*cb)(struct bt_mesh_subnet *sub, void *cb_data), in bt_mesh_subnet_find() argument
828 size_t bt_mesh_subnet_foreach(void (*cb)(struct bt_mesh_subnet *sub)) in bt_mesh_subnet_foreach() argument
844 struct bt_mesh_subnet *bt_mesh_subnet_next(struct bt_mesh_subnet *sub) in bt_mesh_subnet_next() argument
846 if (sub) { in bt_mesh_subnet_next()
847 sub++; in bt_mesh_subnet_next()
849 sub = &subnets[0]; in bt_mesh_subnet_next()
852 for (int i = 0; i < ARRAY_SIZE(subnets); i++, sub++) { in bt_mesh_subnet_next()
854 if (sub == &subnets[ARRAY_SIZE(subnets)]) { in bt_mesh_subnet_next()
855 sub = &subnets[0]; in bt_mesh_subnet_next()
858 if (sub->net_idx != BT_MESH_KEY_UNUSED) { in bt_mesh_subnet_next()
859 return sub; in bt_mesh_subnet_next()
874 struct bt_mesh_subnet *sub = &subnets[i]; in bt_mesh_net_keys_reset() local
876 if (sub->net_idx != BT_MESH_KEY_UNUSED) { in bt_mesh_net_keys_reset()
877 subnet_del(sub); in bt_mesh_net_keys_reset()
895 rx->sub = bt_mesh.lpn.sub; in bt_mesh_net_cred_find()
898 if (!rx->sub->keys[j].valid) { in bt_mesh_net_cred_find()
905 rx->ctx.net_idx = rx->sub->net_idx; in bt_mesh_net_cred_find()
926 rx->sub = frnd->subnet; in bt_mesh_net_cred_find()
929 if (!rx->sub->keys[j].valid) { in bt_mesh_net_cred_find()
936 rx->ctx.net_idx = rx->sub->net_idx; in bt_mesh_net_cred_find()
944 rx->sub = &subnets[i]; in bt_mesh_net_cred_find()
945 if (rx->sub->net_idx == BT_MESH_KEY_UNUSED) { in bt_mesh_net_cred_find()
949 for (j = 0; j < ARRAY_SIZE(rx->sub->keys); j++) { in bt_mesh_net_cred_find()
950 if (!rx->sub->keys[j].valid) { in bt_mesh_net_cred_find()
954 if (cb(rx, in, out, &rx->sub->keys[j].msg)) { in bt_mesh_net_cred_find()
957 rx->ctx.net_idx = rx->sub->net_idx; in bt_mesh_net_cred_find()