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:
Trond Einar Snekvik 2020-11-03 09:10:33 +01:00 committed by Johan Hedberg
parent bf62ef172e
commit 2fb56ba74d
1 changed files with 14 additions and 7 deletions

View File

@ -597,8 +597,8 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu,
return 0;
}
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)
static int trans_encrypt(const struct bt_mesh_net_tx *tx, const uint8_t *key,
struct net_buf_simple *msg)
{
struct bt_mesh_app_crypto_ctx crypto = {
.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,
.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;
uint8_t aid;
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;
}
if (BT_MESH_ADDR_IS_VIRTUAL(tx->ctx->addr)) {
crypto.ad = bt_mesh_va_label_get(tx->ctx->addr);
}
err = bt_mesh_app_encrypt(key, &crypto, msg);
err = trans_encrypt(tx, key, msg);
if (err) {
return err;
}