From 4462c4bbbe7a7a2e015623f2003262d6e6303082 Mon Sep 17 00:00:00 2001 From: Peter Johanson Date: Sat, 22 Jul 2023 22:52:52 -0700 Subject: [PATCH] fix(bluetooth): Disconnect after pair failures. * When there's a failure to pair with a central, explicitly disconnect it with an appropriate error code, to ensure hosts properly report the failure to pair. --- app/src/ble.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/ble.c b/app/src/ble.c index 483bc9d7..e829870c 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -558,6 +558,11 @@ static void auth_pairing_complete(struct bt_conn *conn, bool bonded) { update_advertising(); }; +static void auth_pairing_failed(struct bt_conn *conn, enum bt_security_err err) { + LOG_DBG("Pairing failed (reason %d). Disconnecting", err); + bt_conn_disconnect(conn, BT_SECURITY_ERR_AUTH_FAIL); +} + static struct bt_conn_auth_cb zmk_ble_auth_cb_display = { .pairing_accept = auth_pairing_accept, // .passkey_display = auth_passkey_display, @@ -570,6 +575,7 @@ static struct bt_conn_auth_cb zmk_ble_auth_cb_display = { static struct bt_conn_auth_info_cb zmk_ble_auth_info_cb_display = { .pairing_complete = auth_pairing_complete, + .pairing_failed = auth_pairing_failed, }; static void zmk_ble_ready(int err) {