From 914b5533823f6818bcc471ef3e716a0e2e1eaa4d Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Fri, 4 Dec 2015 11:38:50 +0200 Subject: [PATCH] Bluetooth: Fix setting CONNECT_SCAN state for connections. The state of auto-connectable bt_conn objects needs to be set to CONNECT_SCAN after init as well as whenever bt_le_set_auto_conn is called. Change-Id: Iad2ca32a00ee1b4259196dd20651d5bf94ba9f26 Signed-off-by: Johan Hedberg --- net/bluetooth/conn.c | 21 +++++++++++++++++++++ net/bluetooth/hci_core.c | 3 +++ 2 files changed, 24 insertions(+) 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); }