From a6d78b93818a29d0ac0e5b71387013a2a0b32ab2 Mon Sep 17 00:00:00 2001 From: Ivan Iushkov Date: Mon, 11 Nov 2024 16:29:28 +0100 Subject: [PATCH] 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 --- include/zephyr/bluetooth/conn.h | 17 ------- subsys/bluetooth/host/conn.c | 70 --------------------------- subsys/bluetooth/host/conn_internal.h | 2 +- subsys/bluetooth/host/shell/bt.c | 30 ------------ 4 files changed, 1 insertion(+), 118 deletions(-) diff --git a/include/zephyr/bluetooth/conn.h b/include/zephyr/bluetooth/conn.h index b4cf1c5c6bab2..bbccd1e52c55e 100644 --- a/include/zephyr/bluetooth/conn.h +++ b/include/zephyr/bluetooth/conn.h @@ -1418,23 +1418,6 @@ int bt_conn_le_create_auto(const struct bt_conn_le_create_param *create_param, */ int bt_conn_create_auto_stop(void); -/** @brief Automatically connect to remote device if it's in range. - * - * This function enables/disables automatic connection initiation. - * Every time the device loses the connection with peer, this connection - * will be re-established if connectable advertisement from peer is received. - * - * @note Auto connect is disabled during explicit scanning. - * - * @param addr Remote Bluetooth address. - * @param param If non-NULL, auto connect is enabled with the given - * parameters. If NULL, auto connect is disabled. - * - * @return Zero on success or error code otherwise. - */ -int bt_le_set_auto_conn(const bt_addr_le_t *addr, - const struct bt_le_conn_param *param); - /** @brief Set security level for a connection. * * This function enable security (encryption) for a connection. If the device diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index f77710b3e08d0..0bb468d62deea 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -1851,18 +1851,6 @@ static int conn_disconnect(struct bt_conn *conn, uint8_t reason) int bt_conn_disconnect(struct bt_conn *conn, uint8_t reason) { - /* Disconnection is initiated by us, so auto connection shall - * be disabled. Otherwise the passive scan would be enabled - * and we could send LE Create Connection as soon as the remote - * starts advertising. - */ -#if !defined(CONFIG_BT_FILTER_ACCEPT_LIST) - if (IS_ENABLED(CONFIG_BT_CENTRAL) && - conn->type == BT_CONN_TYPE_LE) { - bt_le_set_auto_conn(&conn->le.dst, NULL); - } -#endif /* !defined(CONFIG_BT_FILTER_ACCEPT_LIST) */ - switch (conn->state) { case BT_CONN_SCAN_BEFORE_INITIATING: conn->err = reason; @@ -3856,64 +3844,6 @@ int bt_conn_le_create_synced(const struct bt_le_ext_adv *adv, return 0; } -#if !defined(CONFIG_BT_FILTER_ACCEPT_LIST) -int bt_le_set_auto_conn(const bt_addr_le_t *addr, - const struct bt_le_conn_param *param) -{ - struct bt_conn *conn; - - if (!atomic_test_bit(bt_dev.flags, BT_DEV_READY)) { - return -EAGAIN; - } - - if (param && !bt_le_conn_params_valid(param)) { - return -EINVAL; - } - - if (!bt_id_scan_random_addr_check()) { - return -EINVAL; - } - - /* Only default identity is supported */ - conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr); - if (!conn) { - conn = bt_conn_add_le(BT_ID_DEFAULT, addr); - if (!conn) { - return -ENOMEM; - } - } - - if (param) { - bt_conn_set_param_le(conn, param); - - if (!atomic_test_and_set_bit(conn->flags, - BT_CONN_AUTO_CONNECT)) { - bt_conn_ref(conn); - } - } else { - if (atomic_test_and_clear_bit(conn->flags, - BT_CONN_AUTO_CONNECT)) { - bt_conn_unref(conn); - if (conn->state == BT_CONN_SCAN_BEFORE_INITIATING) { - bt_conn_set_state(conn, BT_CONN_DISCONNECTED); - } - } - } - - int err = 0; - if (conn->state == BT_CONN_DISCONNECTED && - atomic_test_bit(bt_dev.flags, BT_DEV_READY)) { - if (param) { - bt_conn_set_state(conn, BT_CONN_SCAN_BEFORE_INITIATING); - err = bt_le_scan_user_add(BT_LE_SCAN_USER_CONN); - } - } - - bt_conn_unref(conn); - - return err; -} -#endif /* !defined(CONFIG_BT_FILTER_ACCEPT_LIST) */ #endif /* CONFIG_BT_CENTRAL */ int bt_conn_le_conn_update(struct bt_conn *conn, diff --git a/subsys/bluetooth/host/conn_internal.h b/subsys/bluetooth/host/conn_internal.h index 5ad5aee5daa47..cd4eb2b8045d4 100644 --- a/subsys/bluetooth/host/conn_internal.h +++ b/subsys/bluetooth/host/conn_internal.h @@ -49,7 +49,7 @@ typedef enum __packed { enum { /** The connection context is used for automatic connection establishment * - * That is, with @ref bt_conn_le_create_auto() or bt_le_set_auto_conn(). + * That is, with @ref bt_conn_le_create_auto(). * This flag is set even after the connection has been established so * that the connection can be reestablished once disconnected. * The connection establishment may be performed with or without the filter diff --git a/subsys/bluetooth/host/shell/bt.c b/subsys/bluetooth/host/shell/bt.c index e53e8123aa0d6..7b68cc12be1c2 100644 --- a/subsys/bluetooth/host/shell/bt.c +++ b/subsys/bluetooth/host/shell/bt.c @@ -3320,33 +3320,6 @@ static int cmd_connect_le(const struct shell *sh, size_t argc, char *argv[]) return 0; } -#if !defined(CONFIG_BT_FILTER_ACCEPT_LIST) -static int cmd_auto_conn(const struct shell *sh, size_t argc, char *argv[]) -{ - bt_addr_le_t addr; - int err; - - err = bt_addr_le_from_str(argv[1], argv[2], &addr); - if (err) { - shell_error(sh, "Invalid peer address (err %d)", err); - return err; - } - - if (argc < 4) { - return bt_le_set_auto_conn(&addr, BT_LE_CONN_PARAM_DEFAULT); - } else if (!strcmp(argv[3], "on")) { - return bt_le_set_auto_conn(&addr, BT_LE_CONN_PARAM_DEFAULT); - } else if (!strcmp(argv[3], "off")) { - return bt_le_set_auto_conn(&addr, NULL); - } else { - shell_help(sh); - return SHELL_CMD_HELP_PRINTED; - } - - return 0; -} -#endif /* !defined(CONFIG_BT_FILTER_ACCEPT_LIST) */ - static int cmd_connect_le_name(const struct shell *sh, size_t argc, char *argv[]) { const struct bt_le_scan_param param = { @@ -5075,9 +5048,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(bt_cmds, #if defined(CONFIG_BT_CENTRAL) SHELL_CMD_ARG(connect, NULL, HELP_ADDR_LE EXT_ADV_SCAN_OPT, cmd_connect_le, 1, 3), -#if !defined(CONFIG_BT_FILTER_ACCEPT_LIST) - SHELL_CMD_ARG(auto-conn, NULL, HELP_ADDR_LE, cmd_auto_conn, 3, 0), -#endif /* !defined(CONFIG_BT_FILTER_ACCEPT_LIST) */ SHELL_CMD_ARG(connect-name, NULL, "", cmd_connect_le_name, 2, 0), #endif /* CONFIG_BT_CENTRAL */