Skip to content

Commit a95f900

Browse files
CanWang001kartben
authored andcommitted
Bluetooth: Shell: Fix issue that BR connection is not selected.
LE and BR connection have already been established, after that, LE disconnection occurs, BR connection will not be selected as the next default connection. Fix this issue by searching for both BR and LE after disconnection occurs. Signed-off-by: Can Wang <[email protected]>
1 parent 361f8e2 commit a95f900

File tree

1 file changed

+17
-6
lines changed
  • subsys/bluetooth/host/shell

1 file changed

+17
-6
lines changed

subsys/bluetooth/host/shell/bt.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -809,12 +809,7 @@ static void disconnected_set_new_default_conn_cb(struct bt_conn *conn, void *use
809809
}
810810

811811
if (info.state == BT_CONN_STATE_CONNECTED) {
812-
char addr_str[BT_ADDR_LE_STR_LEN];
813-
814812
default_conn = bt_conn_ref(conn);
815-
816-
bt_addr_le_to_str(info.le.dst, addr_str, sizeof(addr_str));
817-
bt_shell_print("Selected conn is now: %s", addr_str);
818813
}
819814
}
820815

@@ -826,11 +821,27 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
826821
bt_shell_print("Disconnected: %s (reason 0x%02x)", addr, reason);
827822

828823
if (default_conn == conn) {
824+
struct bt_conn_info info;
825+
enum bt_conn_type conn_type = BT_CONN_TYPE_LE;
826+
827+
if (IS_ENABLED(CONFIG_BT_CLASSIC)) {
828+
conn_type |= BT_CONN_TYPE_BR;
829+
}
830+
831+
bt_conn_get_info(conn, &info);
829832
bt_conn_unref(default_conn);
830833
default_conn = NULL;
831834

832835
/* If we are connected to other devices, set one of them as default */
833-
bt_conn_foreach(BT_CONN_TYPE_LE, disconnected_set_new_default_conn_cb, NULL);
836+
bt_conn_foreach(info.type, disconnected_set_new_default_conn_cb, NULL);
837+
if (default_conn == NULL) {
838+
bt_conn_foreach(conn_type, disconnected_set_new_default_conn_cb, NULL);
839+
}
840+
841+
if (default_conn != NULL) {
842+
conn_addr_str(default_conn, addr, sizeof(addr));
843+
bt_shell_print("Selected conn is now: %s", addr);
844+
}
834845
}
835846
}
836847

0 commit comments

Comments
 (0)