Skip to content

Commit bf361aa

Browse files
demantmrrvjhedberg
authored andcommitted
Bluetooth: Host: Add CONFIG_BT_BONDING_REQUIRED flag
Added configuration for accepting pairing requests only if both devices has bonding flag set in order to reject other devices at an early stage, thus leaving more chance for devices expected to bond. With the CONFIG_BT_BONDING_REQUIRED flag the device only accept pairing requests if it has CONFIG_BT_BONMDABLE set and the device requesting pairing has Bonding_Flags field set to Bonding (0x01) in its AuthReq. Note: When using bt_set_bondable(false) pairing requests will be rejected when CONFIG_BT_BONDING_REQUIRED is set. Signed-off-by: Martin Rieva <[email protected]>
1 parent f30bed3 commit bf361aa

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

subsys/bluetooth/host/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,14 @@ config BT_BONDABLE
348348
Bonding flag in AuthReq of SMP Pairing Request/Response will be set
349349
indicating the support for this mode.
350350

351+
config BT_BONDING_REQUIRED
352+
bool "Always require bonding"
353+
depends on BT_BONDABLE
354+
help
355+
When this option is enabled remote devices are required to always
356+
set the bondable flag in their pairing request. Any other kind of
357+
requests will be rejected.
358+
351359
config BT_STORE_DEBUG_KEYS
352360
bool "Store Debug Mode bonds"
353361
help

subsys/bluetooth/host/smp.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2774,6 +2774,9 @@ static u8_t smp_pairing_req(struct bt_smp *smp, struct net_buf *buf)
27742774
if ((rsp->auth_req & BT_SMP_AUTH_BONDING) &&
27752775
(req->auth_req & BT_SMP_AUTH_BONDING)) {
27762776
atomic_set_bit(smp->flags, SMP_FLAG_BOND);
2777+
} else if (IS_ENABLED(CONFIG_BT_BONDING_REQUIRED)) {
2778+
/* Reject pairing req if not both intend to bond */
2779+
return BT_SMP_ERR_UNSPECIFIED;
27772780
}
27782781

27792782
atomic_set_bit(smp->flags, SMP_FLAG_PAIRING);
@@ -2955,6 +2958,9 @@ static u8_t smp_pairing_rsp(struct bt_smp *smp, struct net_buf *buf)
29552958
if ((rsp->auth_req & BT_SMP_AUTH_BONDING) &&
29562959
(req->auth_req & BT_SMP_AUTH_BONDING)) {
29572960
atomic_set_bit(smp->flags, SMP_FLAG_BOND);
2961+
} else if (IS_ENABLED(CONFIG_BT_BONDING_REQUIRED)) {
2962+
/* Reject pairing req if not both intend to bond */
2963+
return BT_SMP_ERR_UNSPECIFIED;
29582964
}
29592965

29602966
smp->method = get_pair_method(smp, rsp->io_capability);
@@ -3686,6 +3692,12 @@ static u8_t smp_security_request(struct bt_smp *smp, struct net_buf *buf)
36863692
auth = req->auth_req & BT_SMP_AUTH_MASK;
36873693
}
36883694

3695+
if (IS_ENABLED(CONFIG_BT_BONDING_REQUIRED) &&
3696+
!(bondable && (auth & BT_SMP_AUTH_BONDING))) {
3697+
/* Reject security req if not both intend to bond */
3698+
return BT_SMP_ERR_UNSPECIFIED;
3699+
}
3700+
36893701
if (conn->le.keys) {
36903702
/* Make sure we have an LTK to encrypt with */
36913703
if (!(conn->le.keys->keys & (BT_KEYS_LTK_P256 | BT_KEYS_LTK))) {

0 commit comments

Comments
 (0)