Skip to content

Commit 916d0d8

Browse files
joerchancarlescufi
authored andcommitted
[nrf fromtree] 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]> (cherry picked from commit 7fee6b8) Signed-off-by: Joakim Andersson <[email protected]>
1 parent ff20657 commit 916d0d8

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
@@ -738,14 +738,8 @@ static uint8_t get_encryption_key_size(struct bt_smp *smp)
738738
/* Check that if a new pairing procedure with an existing bond will not lower
739739
* the established security level of the bond.
740740
*/
741-
static bool update_keys_check(struct bt_smp *smp)
741+
static bool update_keys_check(struct bt_smp *smp, struct bt_keys *keys)
742742
{
743-
struct bt_conn *conn = smp->chan.chan.conn;
744-
745-
if (!conn->le.keys) {
746-
conn->le.keys = bt_keys_get_addr(conn->id, &conn->le.dst);
747-
}
748-
749743
if (IS_ENABLED(CONFIG_BT_SMP_DISABLE_LEGACY_JW_PASSKEY) &&
750744
!atomic_test_bit(smp->flags, SMP_FLAG_SC) &&
751745
smp->method != LEGACY_OOB) {
@@ -757,27 +751,27 @@ static bool update_keys_check(struct bt_smp *smp)
757751
return false;
758752
}
759753

760-
if (!conn->le.keys ||
761-
!(conn->le.keys->keys & (BT_KEYS_LTK_P256 | BT_KEYS_LTK))) {
754+
if (!keys ||
755+
!(keys->keys & (BT_KEYS_LTK_P256 | BT_KEYS_LTK))) {
762756
return true;
763757
}
764758

765-
if (conn->le.keys->enc_size > get_encryption_key_size(smp)) {
759+
if (keys->enc_size > get_encryption_key_size(smp)) {
766760
return false;
767761
}
768762

769-
if ((conn->le.keys->keys & BT_KEYS_LTK_P256) &&
763+
if ((keys->keys & BT_KEYS_LTK_P256) &&
770764
!atomic_test_bit(smp->flags, SMP_FLAG_SC)) {
771765
return false;
772766
}
773767

774-
if ((conn->le.keys->flags & BT_KEYS_AUTHENTICATED) &&
768+
if ((keys->flags & BT_KEYS_AUTHENTICATED) &&
775769
smp->method == JUST_WORKS) {
776770
return false;
777771
}
778772

779773
if (!IS_ENABLED(CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE) &&
780-
(!(conn->le.keys->flags & BT_KEYS_AUTHENTICATED)
774+
(!(keys->flags & BT_KEYS_AUTHENTICATED)
781775
&& smp->method == JUST_WORKS)) {
782776
return false;
783777
}
@@ -2956,7 +2950,7 @@ static uint8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf)
29562950

29572951
smp->method = get_pair_method(smp, req->io_capability);
29582952

2959-
if (!update_keys_check(smp)) {
2953+
if (!update_keys_check(smp, conn->le.keys)) {
29602954
return BT_SMP_ERR_AUTH_REQUIREMENTS;
29612955
}
29622956

@@ -3158,7 +3152,7 @@ static uint8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf)
31583152

31593153
smp->method = get_pair_method(smp, rsp->io_capability);
31603154

3161-
if (!update_keys_check(smp)) {
3155+
if (!update_keys_check(smp, conn->le.keys)) {
31623156
return BT_SMP_ERR_AUTH_REQUIREMENTS;
31633157
}
31643158

0 commit comments

Comments
 (0)