diff --git a/net/bluetooth/conn.c b/net/bluetooth/conn.c index de0fc3ce61c..d1caaa77743 100644 --- a/net/bluetooth/conn.c +++ b/net/bluetooth/conn.c @@ -893,6 +893,25 @@ struct net_buf *bt_conn_create_pdu(struct nano_fifo *fifo, size_t reserve) return net_buf_get(fifo, head_reserve); } +static void background_scan_init(void) +{ +#if defined(CONFIG_BLUETOOTH_CENTRAL) + int i; + + for (i = 0; i < ARRAY_SIZE(conns); i++) { + struct bt_conn *conn = &conns[i]; + + if (!atomic_get(&conn->ref)) { + continue; + } + + if (atomic_test_bit(conn->flags, BT_CONN_AUTO_CONNECT)) { + bt_conn_set_state(conn, BT_CONN_CONNECT_SCAN); + } + } +#endif /* CONFIG_BLUETOOTH_CENTRAL */ +} + int bt_conn_init(void) { int err; @@ -909,5 +928,7 @@ int bt_conn_init(void) bt_l2cap_init(); + background_scan_init(); + return 0; } diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 4a3b054b526..990b5e87a36 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1244,6 +1244,9 @@ int bt_le_set_auto_conn(bt_addr_le_t *addr, bool auto_conn) if (conn->state == BT_CONN_DISCONNECTED && atomic_test_bit(bt_dev.flags, BT_DEV_READY)) { + if (auto_conn) { + bt_conn_set_state(conn, BT_CONN_CONNECT_SCAN); + } bt_le_scan_update(false); }