Skip to content
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: tester: Add support for BTP_GAP_SET_POWERED command #67359

Conversation

zhaynxp
Copy link
Contributor

@zhaynxp zhaynxp commented Jan 9, 2024

Fill BTP_GAP_SET_POWERED command to support power on/off BLE controller independently

Fixes: #67346

Signed-off-by: Ying Zhang [email protected]

Copy link

github-actions bot commented Jan 9, 2024

Hello @zhaynxp, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@zhaynxp
Copy link
Contributor Author

zhaynxp commented Jan 9, 2024

The issue this PR solves is #67346 , please help to review, thanks!

@Thalley
Copy link
Collaborator

Thalley commented Jan 9, 2024

@zhaynxp zhaynxp force-pushed the enable_and_fill_BTP_GAP_SET_POWERED_cmd branch from f520dad to 8d1e3ef Compare January 10, 2024 02:23
@zhaynxp
Copy link
Contributor Author

zhaynxp commented Jan 10, 2024

@Thalley , thanks for your comments, have linked issue to this PR.
BTW, there is compile error in this PR workflow checking, said undeclared function 'bt_conn_cb_unregister', actually this function was created by my nxp colleague in PR #64599 , the feature developed in this PR was based on fixes in #64599, otherwise BLE connection can't be established after bt_disable --> bt_enable ,
so need below PR checked in first, could you please help to review both PR, and let us know if any action needed?
#64599
The bt_disable --> bt_enable --> bt_disable repeat test is mandatory to us no matter with bt-shell or bt-tester, and currently block our testing, so please help to review and merge these PRs ASAP. Thanks advance!

@Thalley
Copy link
Collaborator

Thalley commented Jan 10, 2024

@Thalley , thanks for your comments, have linked issue to this PR.

Hi @zhaynxp - It is not linked correctly. You have to add something like closes https://github.com/zephyrproject-rtos/zephyr/issues/67346 or fixes https://github.com/zephyrproject-rtos/zephyr/issues/67346 to properly link it

@sjanc
Copy link
Collaborator

sjanc commented Jan 10, 2024

Hi,

I don't think zephyr should implement this command, it is meant for systems that can disable controller only (ie. Linux) without shutting down whole host/apps stack. And you also disable already registered services on power off.

If you need to disable bluetooth in zephyr I think correct way would be to implement service unregister functions and than BTP user can unregister services (including GAP which could disable bluetooth subsystem). Just note that unregister functions would have to properly cleanup things as current implementation only have stubs for services unregister (as we don't really use it in autopts for now)

@zhaynxp zhaynxp closed this Jan 11, 2024
@zhaynxp zhaynxp reopened this Jan 11, 2024
@zhaynxp zhaynxp changed the title Issue-number#67346 tests: bluetooth: tester: Enable and fill BTP_GAP_SET_POWERED command Fixes #67346 tests: bluetooth: tester: Enable and fill BTP_GAP_SET_POWERED command Jan 11, 2024
@zhaynxp zhaynxp force-pushed the enable_and_fill_BTP_GAP_SET_POWERED_cmd branch from 8d1e3ef to 3a94633 Compare January 11, 2024 08:09
@zhaynxp
Copy link
Contributor Author

zhaynxp commented Jan 11, 2024

@Thalley , thanks for your comments, have linked issue to this PR.

Hi @zhaynxp - It is not linked correctly. You have to add something like closes https://github.com/zephyrproject-rtos/zephyr/issues/67346 or fixes https://github.com/zephyrproject-rtos/zephyr/issues/67346 to properly link it

Hi @Thalley , thanks! I've submitted new commit message to link issue, please help check and review. Thanks!

@zhaynxp
Copy link
Contributor Author

zhaynxp commented Jan 11, 2024

Hi,

I don't think zephyr should implement this command, it is meant for systems that can disable controller only (ie. Linux) without shutting down whole host/apps stack. And you also disable already registered services on power off.

If you need to disable bluetooth in zephyr I think correct way would be to implement service unregister functions and than BTP user can unregister services (including GAP which could disable bluetooth subsystem). Just note that unregister functions would have to properly cleanup things as current implementation only have stubs for services unregister (as we don't really use it in autopts for now)

Hi @sjanc , thanks a lot for your suggestion, we'd deprecated the BTP_GAP_SET_POWERED command, and use Unregister GAP Service command(00 04 ff 01 00 01) instead to shutdown whole Bluetooth Subsystem, it will act as main switch to power off BT controller and clean up app+host stack layer resources, and will call unregister_all_services_except_gap to unregister all other services such as GATT, L2CAP.. as you know, user/customer may registered lots of services during use, when they want to shutdown Bluetooth, it's hard/impossible to unregister the services one by one manually, so a main switch is convenient and important we think, and we made it all cleaned with one Unregister GAP Service command. Next time, user need to enter Register GAP Service to power up/enable Bluetooth again to use. Please help to review the new solution and commit, thank you very much!

@Thalley Thalley removed their request for review January 11, 2024 09:17
@dleach02 dleach02 changed the title Fixes #67346 tests: bluetooth: tester: Enable and fill BTP_GAP_SET_POWERED command Bluetooth: tester: Use Unregister GAP Service command to shutdown Bluetooth subsystem Jan 15, 2024
@zhaynxp
Copy link
Contributor Author

zhaynxp commented Jan 31, 2024

Dear Reviewers,

Since this PR is on top of PR #64599 which completed bsim test recently and ready to merge soon if no accident, want to check what's your opinion on this PR? Is it ok to merge after PR #64599 merged and all checks passed? We have a tight schedule to upstream these PRs, so please kindly share your views and let us know any pending items on our side, thanks a lot!

Copy link
Collaborator

@Thalley Thalley left a comment

Choose a reason for hiding this comment

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

Some comments, but ideally @sjanc is the one that really needs to look at this

tests/bluetooth/tester/src/btp_gap.c Outdated Show resolved Hide resolved
tests/bluetooth/tester/src/btp_core.c Outdated Show resolved Hide resolved
tests/bluetooth/tester/src/btp_gatt.c Outdated Show resolved Hide resolved
tests/bluetooth/tester/src/btp_gap.c Outdated Show resolved Hide resolved
@zhaynxp zhaynxp force-pushed the enable_and_fill_BTP_GAP_SET_POWERED_cmd branch 3 times, most recently from b9e780a to c00a6c3 Compare February 2, 2024 01:52
@zhaynxp
Copy link
Contributor Author

zhaynxp commented Feb 2, 2024

Dear Reviewers,

Would you please help to review solution in this PR? Since currently no unregister services will be called by autopts or other vendor, also obviously bt_tester lacks such an interface to call bt_disable , so guess this should be fine. Kindly help to review it again, many thanks!

@Thalley
Copy link
Collaborator

Thalley commented Feb 2, 2024

Dear Reviewers,

Would you please help to review solution in this PR? Since currently no unregister services will be called by autopts or other vendor, also obviously bt_tester lacks such an interface to call bt_disable , so guess this should be fine. Kindly help to review it again, many thanks!

Please be patient :) I don't have any significant change requests, but @sjanc is effectively the maintainer of the BT tester, so I'd like to wait for him to provide a review.

@sjanc
Copy link
Collaborator

sjanc commented Feb 14, 2024

Hi,

sorry for late response, BTP protocol doesn't allow for implicit unregistering of services

Since Zephyr's host doesn't really allow for shutdown, but rather full re-init, my suggestion would be to implement this per service. As GAP profile is kinda special it may for example return error as long as any other service is stil registered. And than that specifics can be handled in test system that is using tester application.

Other option could be extending BTP to allow for this behavior (eg a command in core service) but I don't have clear idea on how such command should look like (probably should allow for some customization to accommodate for various stacks)

@zhaynxp
Copy link
Contributor Author

zhaynxp commented Feb 23, 2024

Hi,

sorry for late response, BTP protocol doesn't allow for implicit unregistering of services

Since Zephyr's host doesn't really allow for shutdown, but rather full re-init, my suggestion would be to implement this per service. As GAP profile is kinda special it may for example return error as long as any other service is stil registered. And than that specifics can be handled in test system that is using tester application.

Other option could be extending BTP to allow for this behavior (eg a command in core service) but I don't have clear idea on how such command should look like (probably should allow for some customization to accommodate for various stacks)

Hi @sjanc , thanks for your reply. so you mean should not unregister other services inside unregister GAP service? and it should be the test system or user who use bt_tester themselves to unregister the registered services one by one, right?
Also is it ok to call bt_disable inside unregister GAP service? as introduced in issue #67346 , we need an interface to call the bt_disable to shutdown Bluetooth subsystem, similar as the bt disable cmd in bt_shell app.
Could you please help to double confirm? Thanks a lot!

@zhaynxp
Copy link
Contributor Author

zhaynxp commented Feb 29, 2024

Hi @sjanc ,

As introduced in #67346 , our demand is to have an interface to call bt_disable in bt_tester so as to power off BLE controller during COEX test, and can work normally after power on the controller again. The reason why we clear app resource and unregister services in this PR was because there exists unable to connect issue with bt_tester after power on controller again.
As you know, this topic is pending for a long time, we reviewed this case and have few possible proposals as below, could you please help to review and share your opinion ASAP? Thanks a lot!
a. use below BTP_GAP_RESET command to call bt_disable + bt_enable to achieve restart BLE controller feature
image
advantages of this way is : reset controller with only 1 cmd + no unregister services and clear app resource needed, the already registered services and command handlers can keep running
b. use below BTP_GAP_SET_POWERED command to power on/off controller, if the cmd parameter Powered is 1 then call bt_enable to power on controller, else call bt_disable to power off controller
image
advantages of this way is : no unregister services and clear app resource needed+ can disable/enable controller separately
c. as submitted in this PR, or the comment last week, use unregister GAP service to call bt_disable
d. no way to call bt_disable, won't support this, and share the reason
Could you please let us know your preference explicitly so we can proceed this ticket accordingly? Thanks again!

@sjanc
Copy link
Collaborator

sjanc commented Mar 5, 2024

Hi,

Okay, so I thought about this, double checked APIs and discussed this with with Emil.
Conclusion was that it should be possible to implement 'Set powered' command by simply mapping this to bt_disable() and bt_enable() API.

It is not ideal but best we can get regarding BTP and what Zephyr offers. Just make sure to properly toggle BTP_GAP_SETTINGS_POWERED BTP setting when doing so (via BTP_GAP_EV_NEW_SETTINGS event)

@Thalley
Copy link
Collaborator

Thalley commented Mar 5, 2024

Hi,

Okay, so I thought about this, double checked APIs and discussed this with with Emil. Conclusion was that it should be possible to implement 'Set powered' command by simply mapping this to bt_disable() and bt_enable() API.

It is not ideal but best we can get regarding BTP and what Zephyr offers. Just make sure to properly toggle BTP_GAP_SETTINGS_POWERED BTP setting when doing so (via BTP_GAP_EV_NEW_SETTINGS event)

It is, however, very important to note that bt_disable() followed by a bt_enable() does not mimic a reboot. At best it mimics this in the controller, but there are data in the host that is not cleared (most notably registered services, callbacks, etc. (anything that can be changed before calling bt_enable())).

@zhaynxp zhaynxp closed this Mar 6, 2024
@zhaynxp zhaynxp force-pushed the enable_and_fill_BTP_GAP_SET_POWERED_cmd branch from c00a6c3 to 4824e40 Compare March 6, 2024 06:10
@zhaynxp zhaynxp reopened this Mar 6, 2024
@zhaynxp zhaynxp force-pushed the enable_and_fill_BTP_GAP_SET_POWERED_cmd branch 2 times, most recently from 8a7bc80 to c3ba9d7 Compare March 6, 2024 06:45
@zhaynxp
Copy link
Contributor Author

zhaynxp commented Mar 6, 2024

Hi @sjanc @Thalley ,

Thank you very much for the confirmation, agree that currently the set powered command seems to be the most appropriate for the power on/off controller scenario. Well understand it's not system/BT reboot, but can help controller reboot without touch app layer resources. Have submitted the PR for review, kindly pls help to review and approve, let us know any comments.
Many thanks!

@zhaynxp zhaynxp changed the title Bluetooth: tester: Use Unregister GAP Service command to shutdown Bluetooth subsystem Bluetooth: tester: Add support for BTP_GAP_SET_POWERED command Mar 6, 2024
@zhaynxp zhaynxp force-pushed the enable_and_fill_BTP_GAP_SET_POWERED_cmd branch from c3ba9d7 to 9bba095 Compare March 6, 2024 08:24
Copy link
Collaborator

@sjanc sjanc left a comment

Choose a reason for hiding this comment

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

enable set powered command bit in supported_commands(), otherwise looks OK to me

Fill BTP_GAP_SET_POWERED command to support power on/off BT controller

Fixes: zephyrproject-rtos#67346

Signed-off-by: Ying Zhang <[email protected]>
@zhaynxp zhaynxp force-pushed the enable_and_fill_BTP_GAP_SET_POWERED_cmd branch from 9bba095 to 4f16914 Compare March 6, 2024 09:12
@zhaynxp
Copy link
Contributor Author

zhaynxp commented Mar 6, 2024

enable set powered command bit in supported_commands(), otherwise looks OK to me

thanks sjanc for the reminder ! Have corrected this

@fabiobaltieri fabiobaltieri merged commit b32c819 into zephyrproject-rtos:main Mar 7, 2024
17 checks passed
Copy link

github-actions bot commented Mar 7, 2024

Hi @zhaynxp!
Congratulations on getting your very first Zephyr pull request merged 🎉🥳. This is a fantastic achievement, and we're thrilled to have you as part of our community!

To celebrate this milestone and showcase your contribution, we'd love to award you the Zephyr Technical Contributor badge. If you're interested, please claim your badge by filling out this form: Claim Your Zephyr Badge.

Thank you for your valuable input, and we look forward to seeing more of your contributions in the future! 🪁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable bt-tester BTP_GAP_SET_POWERED cmd to call bt_disable() to power off controller
6 participants