Skip to content

Commit

Permalink
fix(split): reserve peripheral slot before stopping scanning
Browse files Browse the repository at this point in the history
In the event that the peripheral MAC address does not match, this allows
scanning to continue.
  • Loading branch information
xudongzheng committed Sep 2, 2023
1 parent 185457b commit 10e7390
Showing 1 changed file with 10 additions and 8 deletions.
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

0 comments on commit 10e7390

Please sign in to comment.