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:
parent
a45226a238
commit
c635425487
2 changed files with 10 additions and 13 deletions
|
@ -2293,19 +2293,6 @@ struct bt_conn *bt_conn_create_slave_le(const bt_addr_le_t *peer,
|
||||||
if (conn) {
|
if (conn) {
|
||||||
switch (conn->state) {
|
switch (conn->state) {
|
||||||
case BT_CONN_CONNECT_DIR_ADV:
|
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:
|
case BT_CONN_CONNECTED:
|
||||||
return conn;
|
return conn;
|
||||||
case BT_CONN_DISCONNECTED:
|
case BT_CONN_DISCONNECTED:
|
||||||
|
|
|
@ -5992,6 +5992,16 @@ int bt_le_adv_stop(void)
|
||||||
return 0;
|
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);
|
err = set_advertise_enable(false);
|
||||||
if (err) {
|
if (err) {
|
||||||
return err;
|
return err;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue