From 544612c8c0929ff3089bcdb86f9ea8a2f77081eb Mon Sep 17 00:00:00 2001 From: Xudong Zheng <7pkvm5aw@slicealias.com> Date: Fri, 1 Sep 2023 23:32:17 -0400 Subject: [PATCH] fix(split): reserve peripheral slot before stopping scanning In the event that the peripheral MAC address does not match, this allows scanning to continue. --- app/src/split/bluetooth/central.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index b70d79e3..ccf1cc28 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -433,20 +433,22 @@ static int stop_scanning() { static bool split_central_eir_found(const bt_addr_le_t *addr) { LOG_DBG("Found the split service"); + // Reserve peripheral slot. Once the central has bonded to its peripherals, + // the peripheral MAC addresses will be validated internally and the slot + // reservation will fail if there is a mismatch. + int slot_idx = reserve_peripheral_slot(addr); + if (slot_idx < 0) { + LOG_INF("Unable to reserve peripheral slot (err %d)", slot_idx); + return false; + } + struct peripheral_slot *slot = &peripherals[slot_idx]; + // Stop scanning so we can connect to the peripheral device. int err = stop_scanning(); if (err < 0) { return false; } - int slot_idx = reserve_peripheral_slot(addr); - if (slot_idx < 0) { - LOG_ERR("Failed to reserve peripheral slot (err %d)", slot_idx); - return false; - } - - struct peripheral_slot *slot = &peripherals[slot_idx]; - LOG_DBG("Initiating new connnection"); struct bt_le_conn_param *param = BT_LE_CONN_PARAM(CONFIG_ZMK_SPLIT_BLE_PREF_INT, CONFIG_ZMK_SPLIT_BLE_PREF_INT,