feat(ble): Request encryption if notifying fails
* If attempting to notify and getting an EPERM return value, request upgrading the security of the connection at that moment, since it likely means we got a connection to a bonded host but the connection hasn't been upgraded to encrypted yet.
This commit is contained in:
parent
ba8495317d
commit
ea0868c4db
1 changed files with 13 additions and 6 deletions
|
@ -258,8 +258,10 @@ void send_keyboard_report_callback(struct k_work *work) {
|
||||||
};
|
};
|
||||||
|
|
||||||
int err = bt_gatt_notify_cb(conn, ¬ify_params);
|
int err = bt_gatt_notify_cb(conn, ¬ify_params);
|
||||||
if (err) {
|
if (err == -EPERM) {
|
||||||
LOG_ERR("Error notifying %d", err);
|
bt_conn_set_security(conn, BT_SECURITY_L2);
|
||||||
|
} else if (err) {
|
||||||
|
LOG_DBG("Error notifying %d", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_conn_unref(conn);
|
bt_conn_unref(conn);
|
||||||
|
@ -308,7 +310,9 @@ void send_consumer_report_callback(struct k_work *work) {
|
||||||
};
|
};
|
||||||
|
|
||||||
int err = bt_gatt_notify_cb(conn, ¬ify_params);
|
int err = bt_gatt_notify_cb(conn, ¬ify_params);
|
||||||
if (err) {
|
if (err == -EPERM) {
|
||||||
|
bt_conn_set_security(conn, BT_SECURITY_L2);
|
||||||
|
} else if (err) {
|
||||||
LOG_DBG("Error notifying %d", err);
|
LOG_DBG("Error notifying %d", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,7 +363,9 @@ void send_mouse_report_callback(struct k_work *work) {
|
||||||
};
|
};
|
||||||
|
|
||||||
int err = bt_gatt_notify_cb(conn, ¬ify_params);
|
int err = bt_gatt_notify_cb(conn, ¬ify_params);
|
||||||
if (err) {
|
if (err == -EPERM) {
|
||||||
|
bt_conn_set_security(conn, BT_SECURITY_L2);
|
||||||
|
} else if (err) {
|
||||||
LOG_DBG("Error notifying %d", err);
|
LOG_DBG("Error notifying %d", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,9 +386,10 @@ int zmk_hog_send_mouse_report(struct zmk_hid_mouse_report_body *report) {
|
||||||
};
|
};
|
||||||
|
|
||||||
int err = bt_gatt_notify_cb(conn, ¬ify_params);
|
int err = bt_gatt_notify_cb(conn, ¬ify_params);
|
||||||
if (err) {
|
if (err == -EPERM) {
|
||||||
|
bt_conn_set_security(conn, BT_SECURITY_L2);
|
||||||
|
} else if (err) {
|
||||||
LOG_DBG("Error notifying %d", err);
|
LOG_DBG("Error notifying %d", err);
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_conn_unref(conn);
|
bt_conn_unref(conn);
|
||||||
|
|
Loading…
Add table
Reference in a new issue