feat(bt): Add support for unauth overwrite
* Properly handle the user enabling the `CONFIG_BT_SMP_ALLOW_UNAUTH_OVERWRITE` Zephyr flag and handle re-pairing to an existing taken profile from the same address.
This commit is contained in:
parent
69f7bfb409
commit
744f70c80c
1 changed files with 8 additions and 2 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue