Skip to content

Commit 81141b1

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: Shell: Improve command bt connections to support BR conn
When execute `bt connections`, only the peer device address of selected LE connection is flagged with `*`. Improve the command `bt connections` to support BR connections. Regardless of the connection type, `*` will be shown to indicate the peer address of the current connection if the peer device address is the peer address of selected connection. Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
1 parent f9701a1 commit 81141b1

File tree

1 file changed

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

1 file changed

+10
-17
lines changed

subsys/bluetooth/host/shell/bt.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3942,46 +3942,39 @@ static int cmd_bonds(const struct shell *sh, size_t argc, char *argv[])
39423942
return 0;
39433943
}
39443944

3945-
static const char *role_str(uint8_t role)
3946-
{
3947-
switch (role) {
3948-
case BT_CONN_ROLE_CENTRAL:
3949-
return "Central";
3950-
case BT_CONN_ROLE_PERIPHERAL:
3951-
return "Peripheral";
3952-
}
3953-
3954-
return "Unknown";
3955-
}
3956-
39573945
static void connection_info(struct bt_conn *conn, void *user_data)
39583946
{
39593947
char addr[BT_ADDR_LE_STR_LEN];
39603948
int *conn_count = user_data;
39613949
struct bt_conn_info info;
3950+
const char *selected;
3951+
const char *role_str;
39623952

39633953
if (bt_conn_get_info(conn, &info) < 0) {
39643954
bt_shell_error("Unable to get info: conn %p", conn);
39653955
return;
39663956
}
39673957

3958+
selected = conn == default_conn ? "*" : " ";
3959+
role_str = get_conn_role_str(info.role);
3960+
39683961
switch (info.type) {
39693962
#if defined(CONFIG_BT_CLASSIC)
39703963
case BT_CONN_TYPE_BR:
39713964
bt_addr_to_str(info.br.dst, addr, sizeof(addr));
3972-
bt_shell_print(" #%u [BR][%s] %s", info.id, role_str(info.role), addr);
3965+
bt_shell_print("%s#%u [BR][%s] %s", selected, info.id, role_str, addr);
39733966
break;
39743967
#endif
39753968
case BT_CONN_TYPE_LE:
39763969
bt_addr_le_to_str(info.le.dst, addr, sizeof(addr));
3977-
bt_shell_print("%s#%u [LE][%s] %s: Interval %u latency %u timeout %u",
3978-
conn == default_conn ? "*" : " ", info.id, role_str(info.role), addr,
3979-
info.le.interval, info.le.latency, info.le.timeout);
3970+
bt_shell_print("%s#%u [LE][%s] %s: Interval %u latency %u timeout %u", selected,
3971+
info.id, role_str, addr, info.le.interval, info.le.latency,
3972+
info.le.timeout);
39803973
break;
39813974
#if defined(CONFIG_BT_ISO)
39823975
case BT_CONN_TYPE_ISO:
39833976
bt_addr_le_to_str(info.le.dst, addr, sizeof(addr));
3984-
bt_shell_print(" #%u [ISO][%s] %s", info.id, role_str(info.role), addr);
3977+
bt_shell_print(" #%u [ISO][%s] %s", info.id, role_str, addr);
39853978
break;
39863979
#endif
39873980
default:

0 commit comments

Comments
 (0)