BLE Security/Pairing fixes for "Just Works" SC.

This commit is contained in:
Pete Johanson 2020-05-15 11:39:16 -04:00
parent 73bea6218e
commit b135eb65f5
4 changed files with 24 additions and 11 deletions

View File

@ -8,6 +8,7 @@ CONFIG_USB_DEVICE_HID=y
CONFIG_USB_DEVICE_PRODUCT="ZMK Firmware"
CONFIG_BT=y
CONFIG_BT_SMP=y
CONFIG_BT_SMP_SC_PAIR_ONLY=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_GATT_DIS=y
# HID GATT notifications sent this way are *not* picked up by Linux, and possibly others.

View File

@ -20,10 +20,10 @@ static void connected(struct bt_conn *conn, u8_t err)
printk("Connected %s\n", addr);
// if (bt_conn_set_security(conn, BT_SECURITY_L0))
// {
// printk("Failed to set security\n");
// }
if (bt_conn_set_security(conn, BT_SECURITY_L2))
{
printk("Failed to set security\n");
}
}
static void disconnected(struct bt_conn *conn, u8_t reason)
@ -68,6 +68,16 @@ static void auth_passkey_display(struct bt_conn *conn, unsigned int passkey)
printk("Passkey for %s: %06u\n", addr, passkey);
}
static void auth_passkey_entry(struct bt_conn *conn)
{
char addr[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
printk("Passkey entry requested for %s\n", addr);
// bt_conn_auth_passkey_entry(conn, 1234);
}
static void auth_cancel(struct bt_conn *conn)
{
char addr[BT_ADDR_LE_STR_LEN];
@ -78,8 +88,8 @@ static void auth_cancel(struct bt_conn *conn)
}
static struct bt_conn_auth_cb zmk_ble_auth_cb_display = {
.passkey_display = auth_passkey_display,
.passkey_entry = NULL,
// .passkey_display = auth_passkey_display,
// .passkey_entry = auth_passkey_entry,
.cancel = auth_cancel,
};

View File

@ -28,6 +28,8 @@ int zmk_endpoints_init()
int zmk_endpoints_send_key_event(struct zmk_key_event key_event)
{
struct zmk_hid_report *report;
int err;
if (key_event.pressed)
{
zmk_hid_press_key(key_event.key);
@ -44,8 +46,10 @@ int zmk_endpoints_send_key_event(struct zmk_key_event key_event)
// // LOG_DBG("USB Send Failed");
// }
if (zmk_hog_send_report(report) != 0)
err = zmk_hog_send_report(report);
if (err)
{
printk("FAILED TO SEND OVER HOG: %d\n", err);
// LOG_DBG("HID Over GATTP Send Failed");
}

View File

@ -117,12 +117,10 @@ BT_GATT_SERVICE_DEFINE(hog_svc,
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_REPORT,
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY,
BT_GATT_PERM_READ_AUTHEN,
// BT_GATT_PERM_READ,
BT_GATT_PERM_READ_ENCRYPT,
read_hids_input_report, NULL, NULL),
BT_GATT_CCC(input_ccc_changed,
BT_GATT_PERM_READ_AUTHEN | BT_GATT_PERM_WRITE_AUTHEN),
// BT_GATT_PERM_READ | BT_GATT_PERM_WRITE),
BT_GATT_PERM_READ_ENCRYPT | BT_GATT_PERM_WRITE_ENCRYPT),
BT_GATT_DESCRIPTOR(BT_UUID_HIDS_REPORT_REF, BT_GATT_PERM_READ,
read_hids_report_ref, NULL, &input),
BT_GATT_CHARACTERISTIC(BT_UUID_HIDS_CTRL_POINT,