Bluetooth: Mesh: Account for ASZMIC in encrypt
The decision to set aszmic = 1 in the net_tx structure was made after the variable was passed to the crypto context, creating a discrepancy between the two when aszmic is 1. Extracts transport encryption to a separate function. Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
This commit is contained in:
parent
bf62ef172e
commit
2fb56ba74d
1 changed files with 14 additions and 7 deletions
|
@ -597,8 +597,8 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
|
static int trans_encrypt(const struct bt_mesh_net_tx *tx, const uint8_t *key,
|
||||||
const struct bt_mesh_send_cb *cb, void *cb_data)
|
struct net_buf_simple *msg)
|
||||||
{
|
{
|
||||||
struct bt_mesh_app_crypto_ctx crypto = {
|
struct bt_mesh_app_crypto_ctx crypto = {
|
||||||
.dev_key = BT_MESH_IS_DEV_KEY(tx->ctx->app_idx),
|
.dev_key = BT_MESH_IS_DEV_KEY(tx->ctx->app_idx),
|
||||||
|
@ -608,6 +608,17 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
|
||||||
.seq_num = bt_mesh.seq,
|
.seq_num = bt_mesh.seq,
|
||||||
.iv_index = BT_MESH_NET_IVI_TX,
|
.iv_index = BT_MESH_NET_IVI_TX,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (BT_MESH_ADDR_IS_VIRTUAL(tx->ctx->addr)) {
|
||||||
|
crypto.ad = bt_mesh_va_label_get(tx->ctx->addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bt_mesh_app_encrypt(key, &crypto, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
|
||||||
|
const struct bt_mesh_send_cb *cb, void *cb_data)
|
||||||
|
{
|
||||||
const uint8_t *key;
|
const uint8_t *key;
|
||||||
uint8_t aid;
|
uint8_t aid;
|
||||||
int err;
|
int err;
|
||||||
|
@ -649,11 +660,7 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg,
|
||||||
tx->aszmic = 1U;
|
tx->aszmic = 1U;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BT_MESH_ADDR_IS_VIRTUAL(tx->ctx->addr)) {
|
err = trans_encrypt(tx, key, msg);
|
||||||
crypto.ad = bt_mesh_va_label_get(tx->ctx->addr);
|
|
||||||
}
|
|
||||||
|
|
||||||
err = bt_mesh_app_encrypt(key, &crypto, msg);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue