From 3263f9374760bf22d5e668ba707acceae06f01db Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Thu, 4 Jul 2019 12:03:57 +0200 Subject: [PATCH] Bluetooth: host: Pairing callback fail and complete for SSP Proved the Authentication callback for pairing failed and pairing complete when BR/EDR SSP is complete. Signed-off-by: Joakim Andersson --- subsys/bluetooth/host/conn.c | 15 +++++++++++++++ subsys/bluetooth/host/conn_internal.h | 1 + subsys/bluetooth/host/hci_core.c | 23 +++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index a46d5e88884..7208e18863c 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -744,6 +744,21 @@ static int ssp_confirm_neg_reply(struct bt_conn *conn) NULL); } +void bt_conn_ssp_auth_complete(struct bt_conn *conn, u8_t status) +{ + if (!status) { + bool bond = !atomic_test_bit(conn->flags, BT_CONN_BR_NOBOND); + + if (bt_auth && bt_auth->pairing_complete) { + bt_auth->pairing_complete(conn, bond); + } + } else { + if (bt_auth && bt_auth->pairing_failed) { + bt_auth->pairing_failed(conn, status); + } + } +} + void bt_conn_ssp_auth(struct bt_conn *conn, u32_t passkey) { conn->br.pairing_method = ssp_pair_method(conn); diff --git a/subsys/bluetooth/host/conn_internal.h b/subsys/bluetooth/host/conn_internal.h index fa13b6c4466..1090cf5ece6 100644 --- a/subsys/bluetooth/host/conn_internal.h +++ b/subsys/bluetooth/host/conn_internal.h @@ -173,6 +173,7 @@ void bt_conn_pin_code_req(struct bt_conn *conn); u8_t bt_conn_get_io_capa(void); u8_t bt_conn_ssp_get_auth(const struct bt_conn *conn); void bt_conn_ssp_auth(struct bt_conn *conn, u32_t passkey); +void bt_conn_ssp_auth_complete(struct bt_conn *conn, u8_t status); void bt_conn_disconnect_all(u8_t id); diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index cabd154faeb..17174df93d3 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -1679,6 +1679,28 @@ int bt_unpair(u8_t id, const bt_addr_le_t *addr) #endif /* CONFIG_BT_CONN */ +#if defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR) +static enum bt_security_err security_err_get(u8_t hci_err) +{ + switch (hci_err) { + case BT_HCI_ERR_SUCCESS: + return BT_SECURITY_ERR_SUCCESS; + case BT_HCI_ERR_AUTHENTICATION_FAIL: + return BT_SECURITY_ERR_AUTHENTICATION_FAIL; + case BT_HCI_ERR_PIN_OR_KEY_MISSING: + return BT_SECURITY_ERR_PIN_OR_KEY_MISSING; + case BT_HCI_ERR_PAIRING_NOT_SUPPORTED: + return BT_SECURITY_ERR_PAIR_NOT_SUPPORTED; + case BT_HCI_ERR_PAIRING_NOT_ALLOWED: + return BT_SECURITY_ERR_PAIR_NOT_ALLOWED; + case BT_HCI_ERR_INVALID_PARAM: + return BT_SECURITY_ERR_INVALID_PARAM; + default: + return BT_SECURITY_ERR_UNSPECIFIED; + } +} +#endif /* defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR) */ + #if defined(CONFIG_BT_BREDR) static void reset_pairing(struct bt_conn *conn) { @@ -2186,6 +2208,7 @@ static void ssp_complete(struct net_buf *buf) return; } + bt_conn_ssp_auth_complete(conn, security_err_get(evt->status)); if (evt->status) { bt_conn_disconnect(conn, BT_HCI_ERR_AUTHENTICATION_FAIL); }