-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Feature/add role change cb #90126
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
base: main
Are you sure you want to change the base?
Feature/add role change cb #90126
Conversation
add `role_changed` to `struct bt_conn_cb` to notify the HCI_Role_Change event to application. Signed-off-by: Mark Wang <[email protected]>
43ed4cc
to
2009ed9
Compare
|
||
if (!strcmp(action, "central")) { | ||
/* 0 - Change own Role to Central for this BD_ADDR. */ | ||
role = 0; |
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.
It is not readable. I suggest defining two marcos.
#define BT_HCI_SWITCH_ROLE_CENTRAL 0
#define BT_HCI_SWITCH_ROLE_PERIPHERAL 1
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.
Updated.
err = bt_conn_get_info(default_conn, &info); | ||
if (err) { | ||
shell_error(sh, "Failed to get info (err %d)", err); | ||
return err; | ||
} |
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 is a function bt_conn_get_dst_br()
can be used to get the peer address.
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.
Updated.
if (buf != NULL) { | ||
cp = net_buf_add(buf, sizeof(*cp)); | ||
memcpy(&cp->bdaddr, &info.br.dst->val[0], sizeof(cp->bdaddr)); | ||
cp->role = role; |
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.
What if the new role is the same as the old one?
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.
From my test, the controller gives error for the result.
buf = bt_hci_cmd_create(BT_HCI_OP_SWITCH_ROLE, sizeof(*cp)); | ||
if (buf != NULL) { | ||
cp = net_buf_add(buf, sizeof(*cp)); | ||
memcpy(&cp->bdaddr, &info.br.dst->val[0], sizeof(cp->bdaddr)); | ||
cp->role = role; | ||
err = bt_hci_cmd_send_sync(BT_HCI_OP_SWITCH_ROLE, buf, NULL); | ||
if (err) { | ||
shell_print(sh, "fail to send hci cmd (err %d)", err); | ||
} | ||
} else { | ||
shell_error(sh, "hi cmd fail to create"); | ||
} |
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.
If can we add an API for BR role switch function?
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.
I think it is better to add an API. I think another pr for the API is better because the current pr is mainly for adding new callback.
@@ -1041,6 +1116,7 @@ SHELL_STATIC_SUBCMD_SET_CREATE(br_cmds, | |||
SHELL_CMD_ARG(oob, NULL, NULL, cmd_oob, 1, 0), | |||
SHELL_CMD_ARG(pscan, NULL, "<value: on, off>", cmd_connectable, 2, 0), | |||
SHELL_CMD_ARG(sdp-find, NULL, "<HFPAG, HFPHF>", cmd_sdp_find_record, 2, 0), | |||
SHELL_CMD_ARG(switch-role, NULL, "<central, peripheral", cmd_switch_role, 2, 0), |
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.
>
is missing in <central, 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.
Fixed
@@ -478,6 +478,10 @@ void bt_conn_set_state(struct bt_conn *conn, bt_conn_state_t state); | |||
|
|||
void bt_conn_connected(struct bt_conn *conn); | |||
|
|||
#if defined(CONFIG_BT_CLASSIC) |
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.
As my understand, function declarations do not need to be controlled by conditional compilation.
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.
add BT_HCI_OP_SWITCH_ROLE and struct bt_hci_cp_switch_role Signed-off-by: Mark Wang <[email protected]>
add br switch-role shell cmd and test the role_changed callback. Signed-off-by: Mark Wang <[email protected]> (cherry picked from commit e8eef61b1203dc14a45baeac34163df3b1f0573d)
2009ed9
to
7c6719d
Compare
|
add
role_changed
tostruct bt_conn_cb
to notify the HCI_Role_Change event to application.add BT_HCI_OP_SWITCH_ROLE and struct bt_hci_cp_switch_role.
add br switch-role shell cmd and test the role_changed callback.