Bluetooth: Mesh: Expose app key get
Provides a utility function for getting an application key given a subnet and an app ID. Primary use-case in friendship re-encryption. Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
This commit is contained in:
parent
ec5e43ba5f
commit
70b5556b09
2 changed files with 41 additions and 19 deletions
|
@ -485,6 +485,7 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
|
|||
{
|
||||
const u8_t *key;
|
||||
u8_t *ad;
|
||||
u8_t aid;
|
||||
int err;
|
||||
|
||||
if (net_buf_simple_tailroom(msg) < 4) {
|
||||
|
@ -500,27 +501,14 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
|
|||
tx->ctx->app_idx, tx->ctx->addr);
|
||||
BT_DBG("len %u: %s", msg->len, bt_hex(msg->data, msg->len));
|
||||
|
||||
if (tx->ctx->app_idx == BT_MESH_KEY_DEV) {
|
||||
key = bt_mesh.dev_key;
|
||||
tx->aid = 0U;
|
||||
} else {
|
||||
struct bt_mesh_app_key *app_key;
|
||||
|
||||
app_key = bt_mesh_app_key_find(tx->ctx->app_idx);
|
||||
if (!app_key) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (tx->sub->kr_phase == BT_MESH_KR_PHASE_2 &&
|
||||
app_key->updated) {
|
||||
key = app_key->keys[1].val;
|
||||
tx->aid = app_key->keys[1].id;
|
||||
} else {
|
||||
key = app_key->keys[0].val;
|
||||
tx->aid = app_key->keys[0].id;
|
||||
}
|
||||
err = bt_mesh_app_key_get(tx->sub, tx->ctx->app_idx, &key,
|
||||
&aid);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
tx->aid = aid;
|
||||
|
||||
if (!tx->ctx->send_rel || net_buf_simple_tailroom(msg) < 8) {
|
||||
tx->aszmic = 0U;
|
||||
} else {
|
||||
|
@ -1600,3 +1588,34 @@ void bt_mesh_heartbeat_send(void)
|
|||
bt_mesh_ctl_send(&tx, TRANS_CTL_OP_HEARTBEAT, &hb, sizeof(hb),
|
||||
NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
int bt_mesh_app_key_get(const struct bt_mesh_subnet *subnet, u16_t app_idx,
|
||||
const u8_t **key, u8_t *aid)
|
||||
{
|
||||
struct bt_mesh_app_key *app_key;
|
||||
|
||||
if (app_idx == BT_MESH_KEY_DEV) {
|
||||
*aid = 0;
|
||||
*key = bt_mesh.dev_key;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!subnet) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
app_key = bt_mesh_app_key_find(app_idx);
|
||||
if (!app_key) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
if (subnet->kr_phase == BT_MESH_KR_PHASE_2 && app_key->updated) {
|
||||
*key = app_key->keys[1].val;
|
||||
*aid = app_key->keys[1].id;
|
||||
} else {
|
||||
*key = app_key->keys[0].val;
|
||||
*aid = app_key->keys[0].id;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -97,3 +97,6 @@ void bt_mesh_trans_init(void);
|
|||
void bt_mesh_rpl_clear(void);
|
||||
|
||||
void bt_mesh_heartbeat_send(void);
|
||||
|
||||
int bt_mesh_app_key_get(const struct bt_mesh_subnet *subnet, u16_t app_idx,
|
||||
const u8_t **key, u8_t *aid);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue