From 4f74f698143e4343c5d066fa4827ee17c648802e Mon Sep 17 00:00:00 2001 From: Mariusz Skamra Date: Tue, 18 Sep 2018 09:39:54 +0200 Subject: [PATCH] Bluetooth: Add run-time option to disable SMP bondable mode This adds a function that will disable Bonding flag in Authentication Requirements flag in SMP Pairing Request/Response. This is needed for qualification purposes. Signed-off-by: Mariusz Skamra --- include/bluetooth/conn.h | 12 ++++++++++++ subsys/bluetooth/host/smp.c | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/bluetooth/conn.h b/include/bluetooth/conn.h index 755492e79a1..00d558bd2e7 100644 --- a/include/bluetooth/conn.h +++ b/include/bluetooth/conn.h @@ -386,6 +386,18 @@ struct bt_conn_cb { */ void bt_conn_cb_register(struct bt_conn_cb *cb); +/** Enable/disable bonding. + * + * Set/clear the Bonding flag in the Authentication Requirements of + * SMP Pairing Request/Response data. + * The initial value of this flag depends on BT_BONDABLE Kconfig setting. + * For the vast majority of applications calling this function shouldn't be + * needed. + * + * @param enable Value allowing/disallowing to be bondable. + */ +void bt_set_bondable(bool enable); + /** @def BT_PASSKEY_INVALID * * Special passkey value that can be used to disable a previously diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index 5409d022dbd..64ad75a0f59 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -249,6 +249,7 @@ static struct bt_smp_br bt_smp_br_pool[CONFIG_BT_MAX_CONN]; #endif /* CONFIG_BT_BREDR */ static struct bt_smp bt_smp_pool[CONFIG_BT_MAX_CONN]; +static bool bondable = IS_ENABLED(CONFIG_BT_BONDABLE); static bool sc_supported; static bool sc_local_pkey_valid; static u8_t sc_public_key[64]; @@ -2267,6 +2268,11 @@ static int smp_init(struct bt_smp *smp) return 0; } +void bt_set_bondable(bool enable) +{ + bondable = enable; +} + static u8_t get_auth(u8_t auth) { if (sc_supported) { @@ -2281,6 +2287,12 @@ static u8_t get_auth(u8_t auth) auth |= BT_SMP_AUTH_MITM; } + if (bondable) { + auth |= BT_SMP_AUTH_BONDING; + } else { + auth &= ~BT_SMP_AUTH_BONDING; + } + return auth; }