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 <jun.r.li@intel.com>
This commit is contained in:
Jun Li 2018-06-13 13:37:49 -07:00 committed by Johan Hedberg
commit 9b6ad4067b
2 changed files with 38 additions and 3 deletions

View file

@ -392,6 +392,22 @@ struct bt_conn_auth_cb {
#if defined(CONFIG_BT_BREDR) #if defined(CONFIG_BT_BREDR)
void (*pincode_entry)(struct bt_conn *conn, bool highsec); void (*pincode_entry)(struct bt_conn *conn, bool highsec);
#endif #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. /** @brief Register authentication callbacks.

View file

@ -711,10 +711,20 @@ static void smp_pairing_br_complete(struct bt_smp_br *smp, u8_t status)
if (keys) { if (keys) {
bt_keys_clear(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); bt_keys_store(keys);
} }
if (bt_auth->pairing_complete) {
bt_auth->pairing_complete(smp->chan.chan.conn, bond_flag);
}
} }
smp_br_reset(smp); 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); sc_derive_link_key(smp);
} }
#endif /* CONFIG_BT_BREDR */ #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); 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); smp_reset(smp);