diff --git a/app/src/ble.c b/app/src/ble.c index a930cadc..d9121583 100644 --- a/app/src/ble.c +++ b/app/src/ble.c @@ -377,9 +377,17 @@ static bool is_conn_active_profile(const struct bt_conn *conn) { static void connected(struct bt_conn *conn, uint8_t err) { char addr[BT_ADDR_LE_STR_LEN]; - bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + struct bt_conn_info info; LOG_DBG("Connected thread: %p", k_current_get()); + bt_conn_get_info(conn, &info); + + if (info.role != BT_CONN_ROLE_PERIPHERAL) { + LOG_DBG("SKIPPING FOR ROLE %d", info.role); + return; + } + + bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); advertising_status = ZMK_ADV_NONE; if (err) { @@ -408,11 +416,19 @@ static void connected(struct bt_conn *conn, uint8_t err) { static void disconnected(struct bt_conn *conn, uint8_t reason) { char addr[BT_ADDR_LE_STR_LEN]; + struct bt_conn_info info; bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); LOG_DBG("Disconnected from %s (reason 0x%02x)", log_strdup(addr), reason); + bt_conn_get_info(conn, &info); + + if (info.role != BT_CONN_ROLE_PERIPHERAL) { + LOG_DBG("SKIPPING FOR ROLE %d", info.role); + return; + } + // We need to do this in a work callback, otherwise the advertising update will still see the // connection for a profile as active, and not start advertising yet. k_work_submit(&update_advertising_work); diff --git a/app/src/split/bluetooth/central.c b/app/src/split/bluetooth/central.c index 07ab35a0..7eacc675 100644 --- a/app/src/split/bluetooth/central.c +++ b/app/src/split/bluetooth/central.c @@ -395,6 +395,8 @@ static bool split_central_eir_found(struct bt_data *data, void *user_data) { } else { param = BT_LE_CONN_PARAM(0x0006, 0x0006, 30, 400); + LOG_DBG("Initiating new connnection"); + err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, param, &slot->conn); if (err) { LOG_ERR("Create conn failed (err %d) (create conn? 0x%04x)", err, @@ -445,9 +447,17 @@ static int start_scan(void) { static void split_central_connected(struct bt_conn *conn, uint8_t conn_err) { char addr[BT_ADDR_LE_STR_LEN]; + struct bt_conn_info info; bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); + bt_conn_get_info(conn, &info); + + if (info.role != BT_CONN_ROLE_CENTRAL) { + LOG_DBG("SKIPPING FOR ROLE %d", info.role); + return; + } + if (conn_err) { LOG_ERR("Failed to connect to %s (%u)", log_strdup(addr), conn_err); @@ -465,12 +475,17 @@ static void split_central_connected(struct bt_conn *conn, uint8_t conn_err) { static void split_central_disconnected(struct bt_conn *conn, uint8_t reason) { char addr[BT_ADDR_LE_STR_LEN]; + int err; bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr)); LOG_DBG("Disconnected: %s (reason %d)", log_strdup(addr), reason); - release_peripheral_slot_for_conn(conn); + err = release_peripheral_slot_for_conn(conn); + + if (err < 0) { + return; + } start_scan(); }