Bluetooth: SMP: Clean up and unify remote key distribution tracking

Ensure smp->remote_dist tracks unreceived PDUs both for slave and
master role, and use the same logic in all PDU handlers for
remote_dist and allowed_cmds.

Change-Id: If4769d0be0118e8e764d7483f0d93ef8b61fa398
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2015-08-27 13:15:31 +03:00 committed by Anas Nashif
commit bac8917917

View file

@ -950,14 +950,7 @@ static uint8_t smp_master_ident(struct bt_conn *conn, struct bt_buf *buf)
keys->ltk.ediv = req->ediv;
keys->ltk.rand = req->rand;
if (conn->role == BT_HCI_ROLE_MASTER) {
smp->remote_dist &= ~BT_SMP_DIST_ENC_KEY;
if (!smp->remote_dist) {
bt_smp_distribute_keys(conn);
return 0;
}
}
smp->remote_dist &= ~BT_SMP_DIST_ENC_KEY;
if (smp->remote_dist & BT_SMP_DIST_ID_KEY) {
atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_IDENT_INFO);
@ -965,6 +958,10 @@ static uint8_t smp_master_ident(struct bt_conn *conn, struct bt_buf *buf)
atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_SIGNING_INFO);
}
if (conn->role == BT_HCI_ROLE_MASTER && !smp->remote_dist) {
bt_smp_distribute_keys(conn);
}
return 0;
}
@ -1019,19 +1016,16 @@ static uint8_t smp_ident_addr_info(struct bt_conn *conn, struct bt_buf *buf)
bt_addr_le_copy(&conn->dst, &req->addr);
}
if (conn->role == BT_HCI_ROLE_MASTER) {
smp->remote_dist &= ~BT_SMP_DIST_ID_KEY;
if (!smp->remote_dist) {
bt_smp_distribute_keys(conn);
}
return 0;
}
smp->remote_dist &= ~BT_SMP_DIST_ID_KEY;
if (smp->remote_dist & BT_SMP_DIST_SIGN) {
atomic_set_bit(&smp->allowed_cmds, BT_SMP_CMD_SIGNING_INFO);
}
if (conn->role == BT_HCI_ROLE_MASTER && !smp->remote_dist) {
bt_smp_distribute_keys(conn);
}
return 0;
}
@ -1053,11 +1047,10 @@ static uint8_t smp_signing_info(struct bt_conn *conn, struct bt_buf *buf)
memcpy(keys->remote_csrk.val, req->csrk, sizeof(keys->remote_csrk.val));
keys->remote_csrk.type = get_keys_type(smp->method);
if (conn->role == BT_HCI_ROLE_MASTER) {
smp->remote_dist &= ~BT_SMP_DIST_SIGN;
if (!smp->remote_dist) {
bt_smp_distribute_keys(conn);
}
smp->remote_dist &= ~BT_SMP_DIST_SIGN;
if (conn->role == BT_HCI_ROLE_MASTER && !smp->remote_dist) {
bt_smp_distribute_keys(conn);
}
return 0;