Bluetooth: Shell: Only auto-connect to unconnected devices
The bt connect and bt connect-name commands should only attempt to connect to connectable devices that we are not already connected to. This commit moves the check for BT_GAP_ADV_PROP_CONNECTABLE as well as checks that we do not already have a connection to that device with the current ID. Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
parent
e54902bdbe
commit
6158ff03f5
1 changed files with 20 additions and 11 deletions
|
@ -493,22 +493,31 @@ static void scan_recv(const struct bt_le_scan_recv_info *info, struct net_buf_si
|
||||||
shell_info(ctx_shell, "%*s[SCAN DATA END]", strlen(scan_response_label), "");
|
shell_info(ctx_shell, "%*s[SCAN DATA END]", strlen(scan_response_label), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Store address for later use */
|
|
||||||
#if defined(CONFIG_BT_CENTRAL)
|
#if defined(CONFIG_BT_CENTRAL)
|
||||||
auto_connect.addr_set = true;
|
if ((info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE) != 0U) {
|
||||||
bt_addr_le_copy(&auto_connect.addr, info->addr);
|
struct bt_conn *conn = bt_conn_lookup_addr_le(selected_id, info->addr);
|
||||||
|
|
||||||
/* Use the above auto_connect.addr address to automatically connect */
|
/* Only store auto-connect address for devices we are not already connected to */
|
||||||
if ((info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE) != 0U && auto_connect.connect_name) {
|
if (conn == NULL) {
|
||||||
auto_connect.connect_name = false;
|
/* Store address for later use */
|
||||||
|
auto_connect.addr_set = true;
|
||||||
|
bt_addr_le_copy(&auto_connect.addr, info->addr);
|
||||||
|
|
||||||
cmd_scan_off(ctx_shell);
|
/* Use the above auto_connect.addr address to automatically connect */
|
||||||
|
if (auto_connect.connect_name) {
|
||||||
|
auto_connect.connect_name = false;
|
||||||
|
|
||||||
/* "name" is what would be in argv[0] normally */
|
cmd_scan_off(ctx_shell);
|
||||||
cmd_scan_filter_clear_name(ctx_shell, 1, (char *[]){ "name" });
|
|
||||||
|
|
||||||
/* "connect" is what would be in argv[0] normally */
|
/* "name" is what would be in argv[0] normally */
|
||||||
cmd_connect_le(ctx_shell, 1, (char *[]){ "connect" });
|
cmd_scan_filter_clear_name(ctx_shell, 1, (char *[]){"name"});
|
||||||
|
|
||||||
|
/* "connect" is what would be in argv[0] normally */
|
||||||
|
cmd_connect_le(ctx_shell, 1, (char *[]){"connect"});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bt_conn_unref(conn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BT_CENTRAL */
|
#endif /* CONFIG_BT_CENTRAL */
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue