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 <joakim.andersson@nordicsemi.no>
This commit is contained in:
Joakim Andersson 2020-01-07 14:13:01 +01:00 committed by Johan Hedberg
commit c635425487
2 changed files with 10 additions and 13 deletions

View file

@ -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(&param_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:

View file

@ -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;