Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(split): reserve peripheral slot before stopping scanning #1912

Merged
merged 1 commit into from Sep 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 deletions app/src/split/bluetooth/central.c
Expand Up @@ -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");

// Stop scanning so we can connect to the peripheral device.
int err = stop_scanning();
if (err < 0) {
return false;
}

// 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_ERR("Failed to reserve peripheral slot (err %d)", slot_idx);
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;
}

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,
Expand Down