Lines Matching +full:app +full:- +full:path
5 * SPDX-License-Identifier: Apache-2.0
31 /* Tracking of what storage changes are pending for App Keys. We track this in
63 [0 ... (CONFIG_BT_MESH_APP_KEY_COUNT - 1)] = {
82 char path[20]; in clear_app_key() local
85 snprintk(path, sizeof(path), "bt/mesh/AppKey/%x", app_idx); in clear_app_key()
86 err = settings_delete(path); in clear_app_key()
96 const struct app_key *app; in store_app_key() local
98 char path[20]; in store_app_key() local
101 snprintk(path, sizeof(path), "bt/mesh/AppKey/%x", app_idx); in store_app_key()
103 app = app_get(app_idx); in store_app_key()
104 if (!app) { in store_app_key()
109 key.net_idx = app->net_idx, in store_app_key()
110 key.updated = app->updated, in store_app_key()
112 memcpy(&key.val[0], &app->keys[0].val, sizeof(struct bt_mesh_key)); in store_app_key()
113 memcpy(&key.val[1], &app->keys[1].val, sizeof(struct bt_mesh_key)); in store_app_key()
115 err = settings_save_one(path, &key, sizeof(key)); in store_app_key()
117 LOG_ERR("Failed to store AppKey %s value", path); in store_app_key()
119 LOG_DBG("Stored AppKey %s value", path); in store_app_key()
135 if (!update->valid) { in app_key_update_find()
140 if (update->key_idx == key_idx) { in app_key_update_find()
157 update->clear = clear; in update_app_key_settings()
172 free_slot->valid = 1U; in update_app_key_settings()
173 free_slot->key_idx = app_idx; in update_app_key_settings()
174 free_slot->clear = clear; in update_app_key_settings()
179 static void app_key_evt(struct app_key *app, enum bt_mesh_key_evt evt) in app_key_evt() argument
182 cb->evt_handler(app->app_idx, app->net_idx, evt); in app_key_evt()
188 struct app_key *app = NULL; in app_key_alloc() local
196 if (!app && apps[i].app_idx == BT_MESH_KEY_UNUSED) { in app_key_alloc()
197 app = &apps[i]; in app_key_alloc()
201 return app; in app_key_alloc()
204 static void app_key_del(struct app_key *app) in app_key_del() argument
206 LOG_DBG("AppIdx 0x%03x", app->app_idx); in app_key_del()
209 update_app_key_settings(app->app_idx, false); in app_key_del()
212 app_key_evt(app, BT_MESH_KEY_DELETED); in app_key_del()
214 app->net_idx = BT_MESH_KEY_UNUSED; in app_key_del()
215 app->app_idx = BT_MESH_KEY_UNUSED; in app_key_del()
216 bt_mesh_key_destroy(&app->keys[0].val); in app_key_del()
217 bt_mesh_key_destroy(&app->keys[1].val); in app_key_del()
218 memset(app->keys, 0, sizeof(app->keys)); in app_key_del()
221 static void app_key_revoke(struct app_key *app) in app_key_revoke() argument
223 if (!app->updated) { in app_key_revoke()
227 bt_mesh_key_destroy(&app->keys[0].val); in app_key_revoke()
228 memcpy(&app->keys[0], &app->keys[1], sizeof(app->keys[0])); in app_key_revoke()
229 memset(&app->keys[1], 0, sizeof(app->keys[1])); in app_key_revoke()
230 app->updated = false; in app_key_revoke()
233 update_app_key_settings(app->app_idx, true); in app_key_revoke()
236 app_key_evt(app, BT_MESH_KEY_REVOKED); in app_key_revoke()
242 struct app_key *app; in bt_mesh_app_key_add() local
250 app = app_key_alloc(app_idx); in bt_mesh_app_key_add()
251 if (!app) { in bt_mesh_app_key_add()
255 if (app->app_idx == app_idx) { in bt_mesh_app_key_add()
256 if (app->net_idx != net_idx) { in bt_mesh_app_key_add()
260 if (bt_mesh_key_compare(key, &app->keys[0].val)) { in bt_mesh_app_key_add()
267 if (bt_mesh_app_id(key, &app->keys[0].id)) { in bt_mesh_app_key_add()
271 LOG_DBG("AppIdx 0x%04x AID 0x%02x", app_idx, app->keys[0].id); in bt_mesh_app_key_add()
273 app->net_idx = net_idx; in bt_mesh_app_key_add()
274 app->app_idx = app_idx; in bt_mesh_app_key_add()
275 app->updated = false; in bt_mesh_app_key_add()
276 if (bt_mesh_key_import(BT_MESH_KEY_TYPE_APP, key, &app->keys[0].val)) { in bt_mesh_app_key_add()
283 update_app_key_settings(app->app_idx, true); in bt_mesh_app_key_add()
286 app_key_evt(app, BT_MESH_KEY_ADDED); in bt_mesh_app_key_add()
294 struct app_key *app; in bt_mesh_app_key_update() local
299 app = app_get(app_idx); in bt_mesh_app_key_update()
300 if (!app) { in bt_mesh_app_key_update()
304 if (net_idx != BT_MESH_KEY_UNUSED && app->net_idx != net_idx) { in bt_mesh_app_key_update()
308 sub = bt_mesh_subnet_get(app->net_idx); in bt_mesh_app_key_update()
318 if (sub->kr_phase != BT_MESH_KR_PHASE_1) { in bt_mesh_app_key_update()
322 if (app->updated) { in bt_mesh_app_key_update()
323 if (bt_mesh_key_compare(key, &app->keys[1].val)) { in bt_mesh_app_key_update()
330 if (bt_mesh_app_id(key, &app->keys[1].id)) { in bt_mesh_app_key_update()
334 LOG_DBG("app_idx 0x%04x AID 0x%02x", app_idx, app->keys[1].id); in bt_mesh_app_key_update()
336 app->updated = true; in bt_mesh_app_key_update()
337 if (bt_mesh_key_import(BT_MESH_KEY_TYPE_APP, key, &app->keys[1].val)) { in bt_mesh_app_key_update()
344 update_app_key_settings(app->app_idx, true); in bt_mesh_app_key_update()
347 app_key_evt(app, BT_MESH_KEY_UPDATED); in bt_mesh_app_key_update()
354 struct app_key *app; in bt_mesh_app_key_del() local
362 app = app_get(app_idx); in bt_mesh_app_key_del()
363 if (!app) { in bt_mesh_app_key_del()
370 if (net_idx != BT_MESH_KEY_UNUSED && net_idx != app->net_idx) { in bt_mesh_app_key_del()
374 app_key_del(app); in bt_mesh_app_key_del()
379 static int app_id_set(struct app_key *app, int key_idx, const struct bt_mesh_key *key) in app_id_set() argument
389 err = bt_mesh_app_id(raw_key, &app->keys[key_idx].id); in app_id_set()
394 bt_mesh_key_assign(&app->keys[key_idx].val, key); in app_id_set()
402 struct app_key *app; in bt_mesh_app_key_set() local
404 app = app_key_alloc(app_idx); in bt_mesh_app_key_set()
405 if (!app) { in bt_mesh_app_key_set()
406 return -ENOMEM; in bt_mesh_app_key_set()
409 if (app->app_idx == app_idx) { in bt_mesh_app_key_set()
413 LOG_DBG("AppIdx 0x%04x AID 0x%02x", app_idx, app->keys[0].id); in bt_mesh_app_key_set()
415 if (app_id_set(app, 0, old_key)) { in bt_mesh_app_key_set()
416 return -EIO; in bt_mesh_app_key_set()
419 if (new_key != NULL && app_id_set(app, 1, new_key)) { in bt_mesh_app_key_set()
420 return -EIO; in bt_mesh_app_key_set()
423 app->net_idx = net_idx; in bt_mesh_app_key_set()
424 app->app_idx = app_idx; in bt_mesh_app_key_set()
425 app->updated = !!new_key; in bt_mesh_app_key_set()
447 struct app_key *app = &apps[i]; in bt_mesh_app_keys_get() local
449 if (app->app_idx == BT_MESH_KEY_UNUSED) { in bt_mesh_app_keys_get()
453 if (net_idx != BT_MESH_KEY_ANY && app->net_idx != net_idx) { in bt_mesh_app_keys_get()
458 skip--; in bt_mesh_app_keys_get()
463 return -ENOMEM; in bt_mesh_app_keys_get()
466 app_idxs[count++] = app->app_idx; in bt_mesh_app_keys_get()
476 struct app_key *app = NULL; in bt_mesh_keys_resolve() local
478 if (BT_MESH_IS_DEV_KEY(ctx->app_idx)) { in bt_mesh_keys_resolve()
482 *sub = bt_mesh_subnet_get(ctx->net_idx); in bt_mesh_keys_resolve()
484 LOG_WRN("Unknown NetKey 0x%03x", ctx->net_idx); in bt_mesh_keys_resolve()
485 return -EINVAL; in bt_mesh_keys_resolve()
488 if (ctx->app_idx == BT_MESH_KEY_DEV_REMOTE && in bt_mesh_keys_resolve()
489 !bt_mesh_has_addr(ctx->addr)) { in bt_mesh_keys_resolve()
493 LOG_WRN("No DevKey for 0x%04x", ctx->addr); in bt_mesh_keys_resolve()
494 return -EINVAL; in bt_mesh_keys_resolve()
497 node = bt_mesh_cdb_node_get(ctx->addr); in bt_mesh_keys_resolve()
499 LOG_WRN("No DevKey for 0x%04x", ctx->addr); in bt_mesh_keys_resolve()
500 return -EINVAL; in bt_mesh_keys_resolve()
503 *app_key = &node->dev_key; in bt_mesh_keys_resolve()
512 app = app_get(ctx->app_idx); in bt_mesh_keys_resolve()
513 if (!app) { in bt_mesh_keys_resolve()
514 LOG_WRN("Unknown AppKey 0x%03x", ctx->app_idx); in bt_mesh_keys_resolve()
515 return -EINVAL; in bt_mesh_keys_resolve()
518 *sub = bt_mesh_subnet_get(app->net_idx); in bt_mesh_keys_resolve()
520 LOG_WRN("Unknown NetKey 0x%03x", app->net_idx); in bt_mesh_keys_resolve()
521 return -EINVAL; in bt_mesh_keys_resolve()
524 if ((*sub)->kr_phase == BT_MESH_KR_PHASE_2 && app->updated) { in bt_mesh_keys_resolve()
525 *aid = app->keys[1].id; in bt_mesh_keys_resolve()
526 *app_key = &app->keys[1].val; in bt_mesh_keys_resolve()
528 *aid = app->keys[0].id; in bt_mesh_keys_resolve()
529 *app_key = &app->keys[0].val; in bt_mesh_keys_resolve()
549 rx->net_if != BT_MESH_NET_IF_LOCAL) { in bt_mesh_app_key_find()
552 node = bt_mesh_cdb_node_get(rx->ctx.addr); in bt_mesh_app_key_find()
553 if (node && !cb(rx, &node->dev_key, cb_data)) { in bt_mesh_app_key_find()
561 if (BT_MESH_ADDR_IS_UNICAST(rx->ctx.recv_dst)) { in bt_mesh_app_key_find()
587 const struct app_key *app = &apps[i]; in bt_mesh_app_key_find() local
590 if (app->app_idx == BT_MESH_KEY_UNUSED) { in bt_mesh_app_key_find()
594 if (app->net_idx != rx->sub->net_idx) { in bt_mesh_app_key_find()
598 if (rx->new_key && app->updated) { in bt_mesh_app_key_find()
599 cred = &app->keys[1]; in bt_mesh_app_key_find()
601 cred = &app->keys[0]; in bt_mesh_app_key_find()
604 if (cred->id != aid) { in bt_mesh_app_key_find()
608 err = cb(rx, &cred->val, cb_data); in bt_mesh_app_key_find()
613 return app->app_idx; in bt_mesh_app_key_find()
626 struct app_key *app = &apps[i]; in subnet_evt() local
628 if (app->app_idx == BT_MESH_KEY_UNUSED) { in subnet_evt()
632 if (app->net_idx != sub->net_idx) { in subnet_evt()
637 app_key_del(app); in subnet_evt()
639 app_key_revoke(app); in subnet_evt()
640 } else if (evt == BT_MESH_KEY_SWAPPED && app->updated) { in subnet_evt()
641 app_key_evt(app, BT_MESH_KEY_SWAPPED); in subnet_evt()
653 struct app_key *app = &apps[i]; in bt_mesh_app_keys_reset() local
655 if (app->app_idx != BT_MESH_KEY_UNUSED) { in bt_mesh_app_keys_reset()
656 app_key_del(app); in bt_mesh_app_keys_reset()
671 return -ENOENT; in app_key_set()
682 return -EINVAL; in app_key_set()
693 LOG_ERR("Failed to set \'app-key\'"); in app_key_set()
702 BT_MESH_SETTINGS_DEFINE(app, "AppKey", app_key_set);
711 if (!update->valid) { in bt_mesh_app_key_pending_store()
715 update->valid = 0U; in bt_mesh_app_key_pending_store()
717 if (update->clear) { in bt_mesh_app_key_pending_store()
718 clear_app_key(update->key_idx); in bt_mesh_app_key_pending_store()
720 store_app_key(update->key_idx); in bt_mesh_app_key_pending_store()