|
|
@ -63,19 +63,24 @@ static uint8_t active_profile; |
|
|
|
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME |
|
|
|
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME |
|
|
|
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1) |
|
|
|
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define IS_HOST_PERIPHERAL \ |
|
|
|
|
|
|
|
(!IS_ENABLED(CONFIG_ZMK_SPLIT) || IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL)) |
|
|
|
|
|
|
|
#define IS_SPLIT_PERIPHERAL \ |
|
|
|
|
|
|
|
(IS_ENABLED(CONFIG_ZMK_SPLIT) && !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_CENTRAL)) |
|
|
|
|
|
|
|
|
|
|
|
static const struct bt_data zmk_ble_ad[] = { |
|
|
|
static const struct bt_data zmk_ble_ad[] = { |
|
|
|
#if !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) |
|
|
|
#if IS_HOST_PERIPHERAL |
|
|
|
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN), |
|
|
|
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN), |
|
|
|
BT_DATA_BYTES(BT_DATA_GAP_APPEARANCE, 0xC1, 0x03), |
|
|
|
BT_DATA_BYTES(BT_DATA_GAP_APPEARANCE, 0xC1, 0x03), |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), |
|
|
|
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), |
|
|
|
BT_DATA_BYTES(BT_DATA_UUID16_SOME, |
|
|
|
BT_DATA_BYTES(BT_DATA_UUID16_SOME, |
|
|
|
#if !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) |
|
|
|
#if IS_HOST_PERIPHERAL |
|
|
|
0x12, 0x18, /* HID Service */ |
|
|
|
0x12, 0x18, /* HID Service */ |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
0x0f, 0x18 /* Battery Service */ |
|
|
|
0x0f, 0x18 /* Battery Service */ |
|
|
|
), |
|
|
|
), |
|
|
|
#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) |
|
|
|
#if IS_SPLIT_PERIPHERAL |
|
|
|
BT_DATA_BYTES(BT_DATA_UUID128_ALL, ZMK_SPLIT_BT_SERVICE_UUID) |
|
|
|
BT_DATA_BYTES(BT_DATA_UUID128_ALL, ZMK_SPLIT_BT_SERVICE_UUID) |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
}; |
|
|
|
}; |
|
|
@ -373,7 +378,7 @@ static void connected(struct bt_conn *conn, uint8_t err) { |
|
|
|
|
|
|
|
|
|
|
|
bt_conn_le_param_update(conn, BT_LE_CONN_PARAM(0x0006, 0x000c, 30, 400)); |
|
|
|
bt_conn_le_param_update(conn, BT_LE_CONN_PARAM(0x0006, 0x000c, 30, 400)); |
|
|
|
|
|
|
|
|
|
|
|
#if IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) |
|
|
|
#if IS_SPLIT_PERIPHERAL |
|
|
|
bt_conn_le_phy_update(conn, BT_CONN_LE_PHY_PARAM_2M); |
|
|
|
bt_conn_le_phy_update(conn, BT_CONN_LE_PHY_PARAM_2M); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
@ -462,7 +467,7 @@ static void auth_cancel(struct bt_conn *conn) { |
|
|
|
LOG_DBG("Pairing cancelled: %s", log_strdup(addr)); |
|
|
|
LOG_DBG("Pairing cancelled: %s", log_strdup(addr)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) |
|
|
|
#if IS_HOST_PERIPHERAL |
|
|
|
static enum bt_security_err auth_pairing_accept(struct bt_conn *conn, |
|
|
|
static enum bt_security_err auth_pairing_accept(struct bt_conn *conn, |
|
|
|
const struct bt_conn_pairing_feat *const feat) { |
|
|
|
const struct bt_conn_pairing_feat *const feat) { |
|
|
|
struct bt_conn_info info; |
|
|
|
struct bt_conn_info info; |
|
|
@ -476,7 +481,7 @@ static enum bt_security_err auth_pairing_accept(struct bt_conn *conn, |
|
|
|
|
|
|
|
|
|
|
|
return BT_SECURITY_ERR_SUCCESS; |
|
|
|
return BT_SECURITY_ERR_SUCCESS; |
|
|
|
}; |
|
|
|
}; |
|
|
|
#endif /* !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) */ |
|
|
|
#endif /* IS_HOST_PERIPHERAL */ |
|
|
|
|
|
|
|
|
|
|
|
static void auth_pairing_complete(struct bt_conn *conn, bool bonded) { |
|
|
|
static void auth_pairing_complete(struct bt_conn *conn, bool bonded) { |
|
|
|
struct bt_conn_info info; |
|
|
|
struct bt_conn_info info; |
|
|
@ -491,22 +496,22 @@ static void auth_pairing_complete(struct bt_conn *conn, bool bonded) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#if !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) |
|
|
|
#if IS_HOST_PERIPHERAL |
|
|
|
if (!zmk_ble_active_profile_is_open()) { |
|
|
|
if (!zmk_ble_active_profile_is_open()) { |
|
|
|
LOG_ERR("Pairing completed but current profile is not open: %s", log_strdup(addr)); |
|
|
|
LOG_ERR("Pairing completed but current profile is not open: %s", log_strdup(addr)); |
|
|
|
bt_unpair(BT_ID_DEFAULT, dst); |
|
|
|
bt_unpair(BT_ID_DEFAULT, dst); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
#endif /* !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) */ |
|
|
|
#endif /* IS_HOST_PERIPHERAL */ |
|
|
|
|
|
|
|
|
|
|
|
set_profile_address(active_profile, dst); |
|
|
|
set_profile_address(active_profile, dst); |
|
|
|
update_advertising(); |
|
|
|
update_advertising(); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
static struct bt_conn_auth_cb zmk_ble_auth_cb_display = { |
|
|
|
static struct bt_conn_auth_cb zmk_ble_auth_cb_display = { |
|
|
|
#if !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) |
|
|
|
#if IS_HOST_PERIPHERAL |
|
|
|
.pairing_accept = auth_pairing_accept, |
|
|
|
.pairing_accept = auth_pairing_accept, |
|
|
|
#endif /* !IS_ENABLED(CONFIG_ZMK_SPLIT_BLE_ROLE_PERIPHERAL) */ |
|
|
|
#endif /* IS_HOST_PERIPHERAL */ |
|
|
|
.pairing_complete = auth_pairing_complete, |
|
|
|
.pairing_complete = auth_pairing_complete, |
|
|
|
// .passkey_display = auth_passkey_display,
|
|
|
|
// .passkey_display = auth_passkey_display,
|
|
|
|
|
|
|
|
|
|
|
|