Skip to content

Commit

Permalink
feat(ble): Request encryption if notifying fails
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
petejohanson committed Jan 5, 2024
1 parent 55e3ae9 commit ccf514c
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions app/src/hog.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,10 @@ void send_keyboard_report_callback(struct k_work *work) {
};

int err = bt_gatt_notify_cb(conn, &notify_params);
if (err) {
LOG_ERR("Error notifying %d", err);
if (err == -EPERM) {
bt_conn_set_security(conn, BT_SECURITY_L2);
} else if (err) {
LOG_DBG("Error notifying %d", err);
}

bt_conn_unref(conn);
Expand Down Expand Up @@ -308,7 +310,9 @@ void send_consumer_report_callback(struct k_work *work) {
};

int err = bt_gatt_notify_cb(conn, &notify_params);
if (err) {
if (err == -EPERM) {
bt_conn_set_security(conn, BT_SECURITY_L2);
} else if (err) {
LOG_DBG("Error notifying %d", err);
}

Expand Down Expand Up @@ -359,7 +363,9 @@ void send_mouse_report_callback(struct k_work *work) {
};

int err = bt_gatt_notify_cb(conn, &notify_params);
if (err) {
if (err == -EPERM) {
bt_conn_set_security(conn, BT_SECURITY_L2);
} else if (err) {
LOG_DBG("Error notifying %d", err);
}

Expand All @@ -380,9 +386,10 @@ int zmk_hog_send_mouse_report(struct zmk_hid_mouse_report_body *report) {
};

int err = bt_gatt_notify_cb(conn, &notify_params);
if (err) {
if (err == -EPERM) {
bt_conn_set_security(conn, BT_SECURITY_L2);
} else if (err) {
LOG_DBG("Error notifying %d", err);
return err;
}

bt_conn_unref(conn);
Expand Down

0 comments on commit ccf514c

Please sign in to comment.