1 /* 2 * Copyright (c) 2020 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_SUBSYS_BLUETOOTH_MESH_APP_KEYS_H_ 8 #define ZEPHYR_SUBSYS_BLUETOOTH_MESH_APP_KEYS_H_ 9 10 #include <zephyr/bluetooth/mesh.h> 11 #include "subnet.h" 12 13 /** @brief Reset the app keys module. */ 14 void bt_mesh_app_keys_reset(void); 15 16 /** @brief Initialize a new application key with the given parameters. 17 * 18 * @param app_idx AppIndex. 19 * @param net_idx NetIndex the application is bound to. 20 * @param old_key Current application key. 21 * @param new_key Updated application key, or NULL if not known. 22 * 23 * @return 0 on success, or (negative) error code on failure. 24 */ 25 int bt_mesh_app_key_set(uint16_t app_idx, uint16_t net_idx, 26 const struct bt_mesh_key *old_key, const struct bt_mesh_key *new_key); 27 28 /** @brief Resolve the message encryption keys, given a message context. 29 * 30 * Will use the @c ctx::app_idx and @c ctx::net_idx fields to find a pair of 31 * message encryption keys. If @c ctx::app_idx represents a device key, the 32 * @c ctx::net_idx will be used to determine the net key. Otherwise, the 33 * @c ctx::net_idx parameter will be ignored. 34 * 35 * @param ctx Message context. 36 * @param sub Subnet return parameter. 37 * @param app_key Application return parameter. 38 * @param aid Application ID return parameter. 39 * 40 * @return 0 on success, or (negative) error code on failure. 41 */ 42 int bt_mesh_keys_resolve(struct bt_mesh_msg_ctx *ctx, 43 struct bt_mesh_subnet **sub, 44 const struct bt_mesh_key **app_key, uint8_t *aid); 45 46 /** @brief Iterate through all matching application keys and call @c cb on each. 47 * 48 * @param dev_key Whether to return device keys. 49 * @param aid 7 bit application ID to match. 50 * @param rx RX structure to match against. 51 * @param cb Callback to call for every valid app key. 52 * @param cb_data Callback data to pass to the callback. 53 * 54 * @return The AppIdx that yielded a 0-return from the callback. 55 */ 56 uint16_t bt_mesh_app_key_find(bool dev_key, uint8_t aid, 57 struct bt_mesh_net_rx *rx, 58 int (*cb)(struct bt_mesh_net_rx *rx, 59 const struct bt_mesh_key *key, void *cb_data), 60 void *cb_data); 61 62 /** @brief Store pending application keys in persistent storage. */ 63 void bt_mesh_app_key_pending_store(void); 64 65 #endif /* ZEPHYR_SUBSYS_BLUETOOTH_MESH_APP_KEYS_H_ */ 66