From c635425487688fe55e8a438713f92a0f2d24b30c Mon Sep 17 00:00:00 2001 From: Joakim Andersson Date: Tue, 7 Jan 2020 14:13:01 +0100 Subject: [PATCH] Bluetooth: host: Refactor stopping directed advertiser Refactor stopping directed advertiser to disconnect the state object when calling advertise stop. This follows the same pattern as bt_conn_disconnect. Remove returning conn objects in BT_CONN_CONNECT state, this state could only be an initiator starting a connection in the central role. Signed-off-by: Joakim Andersson --- subsys/bluetooth/host/conn.c | 13 ------------- subsys/bluetooth/host/hci_core.c | 10 ++++++++++ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index 0aa0a7bee85..f532ed6a0a5 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -2293,19 +2293,6 @@ struct bt_conn *bt_conn_create_slave_le(const bt_addr_le_t *peer, if (conn) { switch (conn->state) { case BT_CONN_CONNECT_DIR_ADV: - /* Handle the case when advertising is stopped with - * bt_le_adv_stop function - */ - err = bt_le_adv_start_internal(¶m_int, NULL, 0, - NULL, 0, peer); - if (err && (err != -EALREADY)) { - BT_WARN("Directed advertising could not be" - " started: %d", err); - bt_conn_unref(conn); - return NULL; - } - - case BT_CONN_CONNECT: case BT_CONN_CONNECTED: return conn; case BT_CONN_DISCONNECTED: diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index 7bd62e298ef..4574711b0b5 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -5992,6 +5992,16 @@ int bt_le_adv_stop(void) return 0; } + if (IS_ENABLED(CONFIG_BT_PERIPHERAL)) { + struct bt_conn *conn; + + conn = bt_conn_lookup_state_le(NULL, BT_CONN_CONNECT_DIR_ADV); + if (conn) { + bt_conn_set_state(conn, BT_CONN_DISCONNECTED); + bt_conn_unref(conn); + } + } + err = set_advertise_enable(false); if (err) { return err;