Skip to content

Commit 1572277

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: Shell: Classic: Add command info to get conn info
Add shell command `info` to get the BR connect info. Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
1 parent 744380a commit 1572277

File tree

1 file changed

+69
-0
lines changed
  • subsys/bluetooth/host/classic/shell

1 file changed

+69
-0
lines changed

subsys/bluetooth/host/classic/shell/bredr.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,74 @@ static int cmd_clear(const struct shell *sh, size_t argc, char *argv[])
989989
return err;
990990
}
991991

992+
static const char *get_conn_type_str(uint8_t type)
993+
{
994+
switch (type) {
995+
case BT_CONN_TYPE_LE: return "LE";
996+
case BT_CONN_TYPE_BR: return "BR/EDR";
997+
case BT_CONN_TYPE_SCO: return "SCO";
998+
default: return "Invalid";
999+
}
1000+
}
1001+
1002+
static const char *get_conn_role_str(uint8_t role)
1003+
{
1004+
switch (role) {
1005+
case BT_CONN_ROLE_CENTRAL: return "central";
1006+
case BT_CONN_ROLE_PERIPHERAL: return "peripheral";
1007+
default: return "Invalid";
1008+
}
1009+
}
1010+
1011+
static int cmd_info(const struct shell *sh, size_t argc, char *argv[])
1012+
{
1013+
struct bt_conn *conn = NULL;
1014+
struct bt_conn_info info;
1015+
bt_addr_t addr;
1016+
int err;
1017+
1018+
if (argc > 1) {
1019+
err = bt_addr_from_str(argv[1], &addr);
1020+
if (err) {
1021+
shell_error(sh, "Invalid peer address (err %d)", err);
1022+
return err;
1023+
}
1024+
conn = bt_conn_lookup_addr_br(&addr);
1025+
} else {
1026+
if (default_conn) {
1027+
conn = bt_conn_ref(default_conn);
1028+
}
1029+
}
1030+
1031+
if (!conn) {
1032+
shell_error(sh, "Not connected");
1033+
return -ENOEXEC;
1034+
}
1035+
1036+
err = bt_conn_get_info(conn, &info);
1037+
if (err) {
1038+
shell_print(sh, "Failed to get info");
1039+
goto done;
1040+
}
1041+
1042+
shell_print(sh, "Type: %s, Role: %s, Id: %u",
1043+
get_conn_type_str(info.type),
1044+
get_conn_role_str(info.role),
1045+
info.id);
1046+
1047+
if (info.type == BT_CONN_TYPE_BR) {
1048+
char addr_str[BT_ADDR_STR_LEN];
1049+
1050+
bt_addr_to_str(info.br.dst, addr_str, sizeof(addr_str));
1051+
shell_print(sh, "Peer address %s", addr_str);
1052+
}
1053+
1054+
done:
1055+
bt_conn_unref(conn);
1056+
1057+
return err;
1058+
}
1059+
9921060
static int cmd_default_handler(const struct shell *sh, size_t argc, char **argv)
9931061
{
9941062
if (argc == 1) {
@@ -1033,6 +1101,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(br_cmds,
10331101
SHELL_CMD_ARG(connect, NULL, "<address>", cmd_connect, 2, 0),
10341102
SHELL_CMD_ARG(bonds, NULL, HELP_NONE, cmd_bonds, 1, 0),
10351103
SHELL_CMD_ARG(clear, NULL, "[all] ["HELP_ADDR"]", cmd_clear, 2, 0),
1104+
SHELL_CMD_ARG(info, NULL, HELP_ADDR, cmd_info, 1, 1),
10361105
SHELL_CMD_ARG(discovery, NULL, "<value: on, off> [length: 1-48] [mode: limited]",
10371106
cmd_discovery, 2, 2),
10381107
SHELL_CMD_ARG(iscan, NULL, "<value: on, off> [mode: limited]",

0 commit comments

Comments
 (0)