Skip to content

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

Merged

Conversation

lylezhu2012
Copy link
Collaborator

  • Bluetooth: Shell: Classic: Add command info to get conn info

Add shell command info to get the BR connect info.

  • 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.

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]>
@lylezhu2012 lylezhu2012 force-pushed the classic_add_select_info_commands branch from 3732561 to 74d0ad8 Compare May 19, 2025 07:25
Copy link

@lylezhu2012
Copy link
Collaborator Author

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[])
Copy link
Collaborator

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.

Copy link
Collaborator Author

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);
Copy link
Collaborator

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.

Copy link
Collaborator Author

@lylezhu2012 lylezhu2012 May 29, 2025

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.

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,

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) {

Copy link
Collaborator

@gzh-terry gzh-terry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@kartben kartben merged commit 858e64c into zephyrproject-rtos:main May 29, 2025
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants