-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Bluetooth: Shell: Classic: Add command info
and select
#90123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bluetooth: Shell: Classic: Add command info
and select
#90123
Conversation
Add shell command `info` to get the BR connect info. Signed-off-by: Lyle Zhu <[email protected]>
Add a shell command `select` to select a specific BR connect according to the given BR address. Signed-off-by: Lyle Zhu <[email protected]>
3732561
to
74d0ad8
Compare
|
Just reminder. |
@@ -989,6 +989,105 @@ static int cmd_clear(const struct shell *sh, size_t argc, char *argv[]) | |||
return err; | |||
} | |||
|
|||
static int cmd_select(const struct shell *sh, size_t argc, char *argv[]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to have an unselect
command, otherwise we can never bt_conn_unref
this connection before another conn
can be found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the all commanders use default_conn
as the conn handle to access the APIs, we need to use a function to change the default_conn
if we want to send the command to specific connection.
The command is used to select a connection from all connections. It just likes as bt select
commander.
return err; | ||
} | ||
|
||
conn = bt_conn_lookup_addr_br(&addr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, what's the behavior when disconnect this conn
?
Should we do something to unref it first?
It look like ref
and unref
are not paired.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are three cases to unref
the default_conn
.
Case 1, the connection default_conn
is disconnected.
zephyr/subsys/bluetooth/host/shell/bt.c
Lines 823 to 845 in 46f7313
if (default_conn == conn) { | |
struct bt_conn_info info; | |
enum bt_conn_type conn_type = BT_CONN_TYPE_LE; | |
if (IS_ENABLED(CONFIG_BT_CLASSIC)) { | |
conn_type |= BT_CONN_TYPE_BR; | |
} | |
bt_conn_get_info(conn, &info); | |
bt_conn_unref(default_conn); | |
default_conn = NULL; | |
/* If we are connected to other devices, set one of them as default */ | |
bt_conn_foreach(info.type, disconnected_set_new_default_conn_cb, NULL); | |
if (default_conn == NULL) { | |
bt_conn_foreach(conn_type, disconnected_set_new_default_conn_cb, NULL); | |
} | |
if (default_conn != NULL) { | |
conn_addr_str(default_conn, addr, sizeof(addr)); | |
bt_shell_print("Selected conn is now: %s", addr); | |
} | |
} |
Case 2, use commander br select
or bt select
to select other connect.
Case 3, a new connection is connected if it is central role,
zephyr/subsys/bluetooth/host/shell/bt.c
Lines 777 to 783 in 46f7313
if (info.role == BT_CONN_ROLE_CENTRAL) { | |
if (default_conn != NULL) { | |
bt_conn_unref(default_conn); | |
} | |
default_conn = bt_conn_ref(conn); | |
} else if (info.role == BT_CONN_ROLE_PERIPHERAL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
info
to get conn infoAdd shell command
info
to get the BR connect info.select
to select BR connectAdd a shell command
select
to select a specific BR connect according to the given BR address.