Lines Matching refs:app
96 const struct app_key *app; in store_app_key() local
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()
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()
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()
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()
419 if (new_key != NULL && app_id_set(app, 1, new_key)) { 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()
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
512 app = app_get(ctx->app_idx); in bt_mesh_keys_resolve()
513 if (!app) { 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()
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()
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()
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()
702 BT_MESH_SETTINGS_DEFINE(app, "AppKey", app_key_set);