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,13 +493,18 @@ 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), "");
|
||||
}
|
||||
|
||||
/* Store address for later use */
|
||||
#if defined(CONFIG_BT_CENTRAL)
|
||||
if ((info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE) != 0U) {
|
||||
struct bt_conn *conn = bt_conn_lookup_addr_le(selected_id, info->addr);
|
||||
|
||||
/* Only store auto-connect address for devices we are not already connected to */
|
||||
if (conn == NULL) {
|
||||
/* Store address for later use */
|
||||
auto_connect.addr_set = true;
|
||||
bt_addr_le_copy(&auto_connect.addr, info->addr);
|
||||
|
||||
/* Use the above auto_connect.addr address to automatically connect */
|
||||
if ((info->adv_props & BT_GAP_ADV_PROP_CONNECTABLE) != 0U && auto_connect.connect_name) {
|
||||
if (auto_connect.connect_name) {
|
||||
auto_connect.connect_name = false;
|
||||
|
||||
cmd_scan_off(ctx_shell);
|
||||
|
@ -510,6 +515,10 @@ static void scan_recv(const struct bt_le_scan_recv_info *info, struct net_buf_si
|
|||
/* "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 */
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue