Skip to content

Commit 413eb08

Browse files
joerchannashif
authored andcommitted
Bluetooth: host: Refactor update_keys_check to operate on keys as input
Refactor update_keys_check helper function to operate on input keys input. This allows the function to be re-used on a keys structure that is not the current connection keys. This also avoids the helper function changing the connection state. The conn->le.keys pointer should at this point always have been assigned, as central when sending the pairing request, and as peripheral when receiving the pairing request at the very latest. Signed-off-by: Joakim Andersson <[email protected]>
1 parent 6339812 commit 413eb08

File tree

1 file changed

+9
-15
lines changed
  • subsys/bluetooth/host

1 file changed

+9
-15
lines changed

subsys/bluetooth/host/smp.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -554,35 +554,29 @@ static u8_t get_encryption_key_size(struct bt_smp *smp)
554554
/* Check that if a new pairing procedure with an existing bond will not lower
555555
* the established security level of the bond.
556556
*/
557-
bool update_keys_check(struct bt_smp *smp)
557+
static bool update_keys_check(struct bt_smp *smp, struct bt_keys *keys)
558558
{
559-
struct bt_conn *conn = smp->chan.chan.conn;
560-
561-
if (!conn->le.keys) {
562-
conn->le.keys = bt_keys_get_addr(conn->id, &conn->le.dst);
563-
}
564-
565-
if (!conn->le.keys ||
566-
!(conn->le.keys->keys & (BT_KEYS_LTK_P256 | BT_KEYS_LTK))) {
559+
if (!keys ||
560+
!(keys->keys & (BT_KEYS_LTK_P256 | BT_KEYS_LTK))) {
567561
return true;
568562
}
569563

570-
if (conn->le.keys->enc_size > get_encryption_key_size(smp)) {
564+
if (keys->enc_size > get_encryption_key_size(smp)) {
571565
return false;
572566
}
573567

574-
if ((conn->le.keys->keys & BT_KEYS_LTK_P256) &&
568+
if ((keys->keys & BT_KEYS_LTK_P256) &&
575569
!atomic_test_bit(smp->flags, SMP_FLAG_SC)) {
576570
return false;
577571
}
578572

579-
if ((conn->le.keys->flags & BT_KEYS_AUTHENTICATED) &&
573+
if ((keys->flags & BT_KEYS_AUTHENTICATED) &&
580574
smp->method == JUST_WORKS) {
581575
return false;
582576
}
583577

584578
if (!IS_ENABLED(CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE) &&
585-
(!(conn->le.keys->flags & BT_KEYS_AUTHENTICATED)
579+
(!(keys->flags & BT_KEYS_AUTHENTICATED)
586580
&& smp->method == JUST_WORKS)) {
587581
return false;
588582
}
@@ -2493,7 +2487,7 @@ static u8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf)
24932487

24942488
smp->method = get_pair_method(smp, req->io_capability);
24952489

2496-
if (!update_keys_check(smp)) {
2490+
if (!update_keys_check(smp, conn->le.keys)) {
24972491
return BT_SMP_ERR_AUTH_REQUIREMENTS;
24982492
}
24992493

@@ -2659,7 +2653,7 @@ static u8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf)
26592653

26602654
smp->method = get_pair_method(smp, rsp->io_capability);
26612655

2662-
if (!update_keys_check(smp)) {
2656+
if (!update_keys_check(smp, conn->le.keys)) {
26632657
return BT_SMP_ERR_AUTH_REQUIREMENTS;
26642658
}
26652659

0 commit comments

Comments
 (0)