Skip to content

Commit a6d78b9

Browse files
committed
Bluetooth: Host: remove unused bt_le_set_auto_conn()
bt_le_set_auto_conn() doesn't work as expected. When it is used notify_disconnected() is not called, also reconnection doesn't work. I didn't find easy way to fix it and I think it was broken for a long time. Instead of using this function, a user application can implement reconnecting to the disconnected device by starting scanner again and connecting manually Signed-off-by: Ivan Iushkov <[email protected]>
1 parent c50777a commit a6d78b9

File tree

4 files changed

+1
-118
lines changed

4 files changed

+1
-118
lines changed

include/zephyr/bluetooth/conn.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,23 +1418,6 @@ int bt_conn_le_create_auto(const struct bt_conn_le_create_param *create_param,
14181418
*/
14191419
int bt_conn_create_auto_stop(void);
14201420

1421-
/** @brief Automatically connect to remote device if it's in range.
1422-
*
1423-
* This function enables/disables automatic connection initiation.
1424-
* Every time the device loses the connection with peer, this connection
1425-
* will be re-established if connectable advertisement from peer is received.
1426-
*
1427-
* @note Auto connect is disabled during explicit scanning.
1428-
*
1429-
* @param addr Remote Bluetooth address.
1430-
* @param param If non-NULL, auto connect is enabled with the given
1431-
* parameters. If NULL, auto connect is disabled.
1432-
*
1433-
* @return Zero on success or error code otherwise.
1434-
*/
1435-
int bt_le_set_auto_conn(const bt_addr_le_t *addr,
1436-
const struct bt_le_conn_param *param);
1437-
14381421
/** @brief Set security level for a connection.
14391422
*
14401423
* This function enable security (encryption) for a connection. If the device

subsys/bluetooth/host/conn.c

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,18 +1851,6 @@ static int conn_disconnect(struct bt_conn *conn, uint8_t reason)
18511851

18521852
int bt_conn_disconnect(struct bt_conn *conn, uint8_t reason)
18531853
{
1854-
/* Disconnection is initiated by us, so auto connection shall
1855-
* be disabled. Otherwise the passive scan would be enabled
1856-
* and we could send LE Create Connection as soon as the remote
1857-
* starts advertising.
1858-
*/
1859-
#if !defined(CONFIG_BT_FILTER_ACCEPT_LIST)
1860-
if (IS_ENABLED(CONFIG_BT_CENTRAL) &&
1861-
conn->type == BT_CONN_TYPE_LE) {
1862-
bt_le_set_auto_conn(&conn->le.dst, NULL);
1863-
}
1864-
#endif /* !defined(CONFIG_BT_FILTER_ACCEPT_LIST) */
1865-
18661854
switch (conn->state) {
18671855
case BT_CONN_SCAN_BEFORE_INITIATING:
18681856
conn->err = reason;
@@ -3856,64 +3844,6 @@ int bt_conn_le_create_synced(const struct bt_le_ext_adv *adv,
38563844
return 0;
38573845
}
38583846

3859-
#if !defined(CONFIG_BT_FILTER_ACCEPT_LIST)
3860-
int bt_le_set_auto_conn(const bt_addr_le_t *addr,
3861-
const struct bt_le_conn_param *param)
3862-
{
3863-
struct bt_conn *conn;
3864-
3865-
if (!atomic_test_bit(bt_dev.flags, BT_DEV_READY)) {
3866-
return -EAGAIN;
3867-
}
3868-
3869-
if (param && !bt_le_conn_params_valid(param)) {
3870-
return -EINVAL;
3871-
}
3872-
3873-
if (!bt_id_scan_random_addr_check()) {
3874-
return -EINVAL;
3875-
}
3876-
3877-
/* Only default identity is supported */
3878-
conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr);
3879-
if (!conn) {
3880-
conn = bt_conn_add_le(BT_ID_DEFAULT, addr);
3881-
if (!conn) {
3882-
return -ENOMEM;
3883-
}
3884-
}
3885-
3886-
if (param) {
3887-
bt_conn_set_param_le(conn, param);
3888-
3889-
if (!atomic_test_and_set_bit(conn->flags,
3890-
BT_CONN_AUTO_CONNECT)) {
3891-
bt_conn_ref(conn);
3892-
}
3893-
} else {
3894-
if (atomic_test_and_clear_bit(conn->flags,
3895-
BT_CONN_AUTO_CONNECT)) {
3896-
bt_conn_unref(conn);
3897-
if (conn->state == BT_CONN_SCAN_BEFORE_INITIATING) {
3898-
bt_conn_set_state(conn, BT_CONN_DISCONNECTED);
3899-
}
3900-
}
3901-
}
3902-
3903-
int err = 0;
3904-
if (conn->state == BT_CONN_DISCONNECTED &&
3905-
atomic_test_bit(bt_dev.flags, BT_DEV_READY)) {
3906-
if (param) {
3907-
bt_conn_set_state(conn, BT_CONN_SCAN_BEFORE_INITIATING);
3908-
err = bt_le_scan_user_add(BT_LE_SCAN_USER_CONN);
3909-
}
3910-
}
3911-
3912-
bt_conn_unref(conn);
3913-
3914-
return err;
3915-
}
3916-
#endif /* !defined(CONFIG_BT_FILTER_ACCEPT_LIST) */
39173847
#endif /* CONFIG_BT_CENTRAL */
39183848

39193849
int bt_conn_le_conn_update(struct bt_conn *conn,

subsys/bluetooth/host/conn_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ typedef enum __packed {
4949
enum {
5050
/** The connection context is used for automatic connection establishment
5151
*
52-
* That is, with @ref bt_conn_le_create_auto() or bt_le_set_auto_conn().
52+
* That is, with @ref bt_conn_le_create_auto().
5353
* This flag is set even after the connection has been established so
5454
* that the connection can be reestablished once disconnected.
5555
* The connection establishment may be performed with or without the filter

subsys/bluetooth/host/shell/bt.c

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3320,33 +3320,6 @@ static int cmd_connect_le(const struct shell *sh, size_t argc, char *argv[])
33203320
return 0;
33213321
}
33223322

3323-
#if !defined(CONFIG_BT_FILTER_ACCEPT_LIST)
3324-
static int cmd_auto_conn(const struct shell *sh, size_t argc, char *argv[])
3325-
{
3326-
bt_addr_le_t addr;
3327-
int err;
3328-
3329-
err = bt_addr_le_from_str(argv[1], argv[2], &addr);
3330-
if (err) {
3331-
shell_error(sh, "Invalid peer address (err %d)", err);
3332-
return err;
3333-
}
3334-
3335-
if (argc < 4) {
3336-
return bt_le_set_auto_conn(&addr, BT_LE_CONN_PARAM_DEFAULT);
3337-
} else if (!strcmp(argv[3], "on")) {
3338-
return bt_le_set_auto_conn(&addr, BT_LE_CONN_PARAM_DEFAULT);
3339-
} else if (!strcmp(argv[3], "off")) {
3340-
return bt_le_set_auto_conn(&addr, NULL);
3341-
} else {
3342-
shell_help(sh);
3343-
return SHELL_CMD_HELP_PRINTED;
3344-
}
3345-
3346-
return 0;
3347-
}
3348-
#endif /* !defined(CONFIG_BT_FILTER_ACCEPT_LIST) */
3349-
33503323
static int cmd_connect_le_name(const struct shell *sh, size_t argc, char *argv[])
33513324
{
33523325
const struct bt_le_scan_param param = {
@@ -5075,9 +5048,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(bt_cmds,
50755048
#if defined(CONFIG_BT_CENTRAL)
50765049
SHELL_CMD_ARG(connect, NULL, HELP_ADDR_LE EXT_ADV_SCAN_OPT,
50775050
cmd_connect_le, 1, 3),
5078-
#if !defined(CONFIG_BT_FILTER_ACCEPT_LIST)
5079-
SHELL_CMD_ARG(auto-conn, NULL, HELP_ADDR_LE, cmd_auto_conn, 3, 0),
5080-
#endif /* !defined(CONFIG_BT_FILTER_ACCEPT_LIST) */
50815051
SHELL_CMD_ARG(connect-name, NULL, "<name filter>",
50825052
cmd_connect_le_name, 2, 0),
50835053
#endif /* CONFIG_BT_CENTRAL */

0 commit comments

Comments
 (0)