diff --git a/app/src/ble.c b/app/src/ble.c index fdbde81d..501d4752 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -551,13 +551,19 @@ static void auth_cancel(struct bt_conn *conn) { LOG_DBG("Pairing cancelled: %s", addr); } +static bool pairing_allowed_for_current_profile(struct bt_conn *conn) { + return zmk_ble_active_profile_is_open() || + (IS_ENABLED(CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE) && + bt_addr_le_cmp(zmk_ble_active_profile_addr(), bt_conn_get_dst(conn)) == 0); +} + static enum bt_security_err auth_pairing_accept(struct bt_conn *conn, const struct bt_conn_pairing_feat *const feat) { struct bt_conn_info info; bt_conn_get_info(conn, &info); LOG_DBG("role %d, open? %s", info.role, zmk_ble_active_profile_is_open() ? "yes" : "no"); - if (info.role == BT_CONN_ROLE_PERIPHERAL && !zmk_ble_active_profile_is_open()) { + if (info.role == BT_CONN_ROLE_PERIPHERAL && !pairing_allowed_for_current_profile(conn)) { LOG_WRN("Rejecting pairing request to taken profile %d", active_profile); return BT_SECURITY_ERR_PAIR_NOT_ALLOWED; } @@ -578,7 +584,7 @@ static void auth_pairing_complete(struct bt_conn *conn, bool bonded) { return; } - if (!zmk_ble_active_profile_is_open()) { + if (!pairing_allowed_for_current_profile(conn)) { LOG_ERR("Pairing completed but current profile is not open: %s", addr); bt_unpair(BT_ID_DEFAULT, dst); return;