Skip to content

Commit 858e64c

Browse files
lylezhu2012kartben
authored andcommitted
Bluetooth: Shell: Classic: Add command select to select BR connect
Add a shell command `select` to select a specific BR connect according to the given BR address. Signed-off-by: Lyle Zhu <lyle.zhu@nxp.com>
1 parent 1572277 commit 858e64c

File tree

1 file changed

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

1 file changed

+32
-0
lines changed

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

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

992+
static int cmd_select(const struct shell *sh, size_t argc, char *argv[])
993+
{
994+
char addr_str[BT_ADDR_STR_LEN];
995+
struct bt_conn *conn;
996+
bt_addr_t addr;
997+
int err;
998+
999+
err = bt_addr_from_str(argv[1], &addr);
1000+
if (err) {
1001+
shell_error(sh, "Invalid peer address (err %d)", err);
1002+
return err;
1003+
}
1004+
1005+
conn = bt_conn_lookup_addr_br(&addr);
1006+
if (!conn) {
1007+
shell_error(sh, "No matching connection found");
1008+
return -ENOEXEC;
1009+
}
1010+
1011+
if (default_conn != NULL) {
1012+
bt_conn_unref(default_conn);
1013+
}
1014+
1015+
default_conn = conn;
1016+
1017+
bt_addr_to_str(&addr, addr_str, sizeof(addr_str));
1018+
shell_print(sh, "Selected conn is now: %s", addr_str);
1019+
1020+
return 0;
1021+
}
1022+
9921023
static const char *get_conn_type_str(uint8_t type)
9931024
{
9941025
switch (type) {
@@ -1101,6 +1132,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(br_cmds,
11011132
SHELL_CMD_ARG(connect, NULL, "<address>", cmd_connect, 2, 0),
11021133
SHELL_CMD_ARG(bonds, NULL, HELP_NONE, cmd_bonds, 1, 0),
11031134
SHELL_CMD_ARG(clear, NULL, "[all] ["HELP_ADDR"]", cmd_clear, 2, 0),
1135+
SHELL_CMD_ARG(select, NULL, HELP_ADDR, cmd_select, 2, 0),
11041136
SHELL_CMD_ARG(info, NULL, HELP_ADDR, cmd_info, 1, 1),
11051137
SHELL_CMD_ARG(discovery, NULL, "<value: on, off> [length: 1-48] [mode: limited]",
11061138
cmd_discovery, 2, 2),

0 commit comments

Comments
 (0)