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 <mariusz.skamra@codecoup.pl>
This commit is contained in:
Mariusz Skamra 2018-09-18 09:39:54 +02:00 committed by Johan Hedberg
commit 4f74f69814
2 changed files with 24 additions and 0 deletions

View file

@ -386,6 +386,18 @@ struct bt_conn_cb {
*/ */
void bt_conn_cb_register(struct bt_conn_cb *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 /** @def BT_PASSKEY_INVALID
* *
* Special passkey value that can be used to disable a previously * Special passkey value that can be used to disable a previously

View file

@ -249,6 +249,7 @@ static struct bt_smp_br bt_smp_br_pool[CONFIG_BT_MAX_CONN];
#endif /* CONFIG_BT_BREDR */ #endif /* CONFIG_BT_BREDR */
static struct bt_smp bt_smp_pool[CONFIG_BT_MAX_CONN]; 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_supported;
static bool sc_local_pkey_valid; static bool sc_local_pkey_valid;
static u8_t sc_public_key[64]; static u8_t sc_public_key[64];
@ -2267,6 +2268,11 @@ static int smp_init(struct bt_smp *smp)
return 0; return 0;
} }
void bt_set_bondable(bool enable)
{
bondable = enable;
}
static u8_t get_auth(u8_t auth) static u8_t get_auth(u8_t auth)
{ {
if (sc_supported) { if (sc_supported) {
@ -2281,6 +2287,12 @@ static u8_t get_auth(u8_t auth)
auth |= BT_SMP_AUTH_MITM; auth |= BT_SMP_AUTH_MITM;
} }
if (bondable) {
auth |= BT_SMP_AUTH_BONDING;
} else {
auth &= ~BT_SMP_AUTH_BONDING;
}
return auth; return auth;
} }