Skip to content

bluetooth: improve the controller address resolution enablement #90705

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MarkWangChinese
Copy link
Collaborator

If the controller resolving list is cleared by HCI_LE_Clear_Resolving_List, don't need to enable the controller address resolution.

I think it is one improvement, please help to review.

If the controller resolving list is cleared by HCI_LE_Clear_Resolving_List,
don't need to enable the controller address resolution.

Signed-off-by: Mark Wang <yichang.wang@nxp.com>
Copy link

Comment on lines +1071 to +1074
/* if fail to disable, it should already be enabled,
* don't need to enable gain.
*/
enable_controller_res = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't this depend on what the HCI error code is?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think any HCI error code mean the disabling "controller addr resolution" fail. so I think don't need to check the HCI error value. If you still think we need to check the HCI error code, could you help to explain more details? Thanks.

Comment on lines 1079 to +1085
if (bt_dev.le.rl_entries == bt_dev.le.rl_size) {
LOG_WRN("Resolving list size exceeded. Switching to host.");

/* since the controller resolving list is cleared,
* don't need to enable the Address Resolution.
*/
enable_controller_res = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if the if should be changed to bt_dev.le.rl_entries >= bt_dev.le.rl_size.

e.g. if bt_dev.le.rl_size=2 and bt_dev.le.rl_entries=0 then
First call to bt_id_add => bt_dev.le.rl_entries=1 and Controller resolution is re-enabled
Second call to bt_id_add => bt_dev.le.rl_entries=2 and Controller resolution is disabled
Third call to bt_id_add => bt_dev.le.rl_entries=3 and Controller resolution is re-enabled

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In second call, the bt_dev.le.rl_entries is 1 before the if, the controller resolution is still enabled. After the call, bt_dev.le.rl_entries is 2.
In third call, the bt_dev.le.rl_entries is 2 before the if, so if is True, then the address resolution is switched to host and controller resolution is disabled. After the call, bt_dev.le.rl_entries is 3.
In fourth call, the bt_dev.le.rl_entries is 3 at the begin of the function. there is the follow code at the begin of the function, so it will return directly.

	/* Nothing to be done if host-side resolving is used */
	if (!bt_dev.le.rl_size || bt_dev.le.rl_entries > bt_dev.le.rl_size) {
		bt_dev.le.rl_entries++;
		keys->state |= BT_KEYS_ID_ADDED;
		return;
	}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, missed that early return

@Thalley Thalley requested a review from Copilot May 28, 2025 15:37
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refines when the Bluetooth controller’s address resolution is re-enabled by introducing a flag to skip re-enabling if disabling failed or the resolving list was cleared.

  • Add enable_controller_res flag initialized to true.
  • Set the flag to false on disable failure or after clearing the resolving list.
  • Wrap the final addr_res_enable(BT_HCI_ADDR_RES_ENABLE) call in a conditional based on the flag.
Comments suppressed due to low confidence (2)

subsys/bluetooth/host/id.c:1014

  • [nitpick] Consider renaming enable_controller_res to should_enable_controller_res or reenable_controller_res for clearer intent.
bool enable_controller_res = true;

subsys/bluetooth/host/id.c:1085

  • Add a test case to cover the scenario where the resolving list is cleared so that address resolution is not re-enabled.
enable_controller_res = false;

@@ -1067,13 +1068,21 @@ void bt_id_add(struct bt_keys *keys)
err = addr_res_enable(BT_HCI_ADDR_RES_DISABLE);
if (err) {
LOG_WRN("Failed to disable address resolution");
/* if fail to disable, it should already be enabled,
* don't need to enable gain.
Copy link
Preview

Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

The comment has a typo: 'enable gain' should be 'enable again'.

Suggested change
* don't need to enable gain.
* don't need to enable again.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Bluetooth Host Bluetooth Host (excluding BR/EDR) area: Bluetooth
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants