From 9b6ad4067be40b8c8aa1da67fc39eb53fb50ace5 Mon Sep 17 00:00:00 2001 From: Jun Li Date: Wed, 13 Jun 2018 13:37:49 -0700 Subject: [PATCH] bluetooth: add callback to notify pairing is complete Added two new callbacks for Bluetooth stack to notify the application that pairing has been completed or failed. fixes: #8390 Signed-off-by: Jun Li --- include/bluetooth/conn.h | 16 ++++++++++++++++ subsys/bluetooth/host/smp.c | 25 ++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/include/bluetooth/conn.h b/include/bluetooth/conn.h index d8beda535f3..377379b8f6c 100644 --- a/include/bluetooth/conn.h +++ b/include/bluetooth/conn.h @@ -392,6 +392,22 @@ struct bt_conn_auth_cb { #if defined(CONFIG_BT_BREDR) void (*pincode_entry)(struct bt_conn *conn, bool highsec); #endif + + /** @brief notify that pairing process was complete. + * + * This callback notifies the applicaiton that the pairing process + * has been completed. + * + * @param conn Connection object. + * @param bonded pairing is bonded or not. + */ + void (*pairing_complete)(struct bt_conn *conn, bool bonded); + + /** @brief notify that pairing process has failed. + * + * @param conn Connection object. + */ + void (*pairing_failed)(struct bt_conn *conn); }; /** @brief Register authentication callbacks. diff --git a/subsys/bluetooth/host/smp.c b/subsys/bluetooth/host/smp.c index 707f1fdb614..9f852fdd013 100644 --- a/subsys/bluetooth/host/smp.c +++ b/subsys/bluetooth/host/smp.c @@ -711,10 +711,20 @@ static void smp_pairing_br_complete(struct bt_smp_br *smp, u8_t status) if (keys) { bt_keys_clear(keys); } - } else if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { - if (keys) { + + if (bt_auth->pairing_failed) { + bt_auth->pairing_failed(smp->chan.chan.conn); + } + } else { + bool bond_flag = atomic_test_bit(smp->flags, SMP_FLAG_BOND); + + if (bond_flag && keys) { bt_keys_store(keys); } + + if (bt_auth->pairing_complete) { + bt_auth->pairing_complete(smp->chan.chan.conn, bond_flag); + } } smp_br_reset(smp); @@ -1483,9 +1493,18 @@ static void smp_pairing_complete(struct bt_smp *smp, u8_t status) sc_derive_link_key(smp); } #endif /* CONFIG_BT_BREDR */ - if (atomic_test_bit(smp->flags, SMP_FLAG_BOND)) { + bool bond_flag = atomic_test_bit(smp->flags, SMP_FLAG_BOND); + + if (bond_flag) { bt_keys_store(smp->chan.chan.conn->le.keys); } + + if (bt_auth->pairing_complete) { + bt_auth->pairing_complete(smp->chan.chan.conn, + bond_flag); + } + } else if (bt_auth->pairing_failed) { + bt_auth->pairing_failed(smp->chan.chan.conn); } smp_reset(smp);