Skip to content

Bluetooth: Host: Bonding with the same Central using multiple identities #2963

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

PavelVPV
Copy link
Contributor

@PavelVPV PavelVPV commented Jun 17, 2025

This PR adds a feature to allow bonding with the same Central using multiple identities.

The PR consists of 2 commits.

The first commit adds a new Kconfig option by enabling which Host will keep
bonding with the same Central instead of rejecting pairing.

Brief implementation details:

This implementation adds a new flag to bt_keys struct:
BT_KEYS_ID_CONFLICT. The flag is set, when:

  • bonding with the same peer and conflict identified
  • when loading conflicting keys from persistent storage.

When bonding and conflict is identified, the new keys aren't added to
the Resolving List immediately. Instead, the old keys stay in the
Resolving List.

When start advertising, Host finds conflicting keys that are already
added to the Resolving List and substitues them.

If, however, there is another advertiser already started for the added
keys, the new request is reject and advertising start function returns
-EPERM.

The second adds the following tests:

  • a test that checks undirected advertisements
  • a test that checks directed advertisements
  • a test that checks undirected advertisement with the Filter Accept List
  • a test that checks unpairing
  • a test that checks start of multiple advertisements in parallel
  • a test that checks recovering BT_KEYS_ID_CONFLICT after reboot

bool "Automatically swap conflicting entries in the Resolving List"
depends on !BT_ID_UNPAIR_MATCHING_BONDS
depends on BT_PRIVACY && BT_PERIPHERAL && !BT_CENTRAL
select EXPERIMENTAL
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if I need to keep this option as experimental.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think experimental should be removed as this goes into production by customer.

@PavelVPV PavelVPV force-pushed the multi_id_bond branch 3 times, most recently from 358652b to 024e250 Compare June 17, 2025 19:50
@alxelax
Copy link
Contributor

alxelax commented Jun 19, 2025

Just curious how are implemented bsim tests going to be checked if CI bsim in downstream isn't run?

@PavelVPV
Copy link
Contributor Author

Just curious how are implemented bsim tests going to be checked if CI bsim in downstream isn't run?

Manually

@PavelVPV PavelVPV force-pushed the multi_id_bond branch 2 times, most recently from 187ccc8 to 92987f9 Compare June 19, 2025 09:03
@PavelVPV
Copy link
Contributor Author

Added persistent storage test to verify that re-connection works fine after recovering bonding data from flash.

struct bt_id_conflict {
struct bt_keys *candidate;
struct bt_keys *found;
bool all;
Copy link
Contributor

Choose a reason for hiding this comment

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

Only one nitpick: all seems to me a bit ambiguous. Perhaps better to call it check_all_irk or similar? Feel free to disregard. Otherwise to me this PR looks good, although with the caveat that I am still lacking quite some knowledge of the host, nor did I manually run the bsim tests you added to check.

@@ -630,6 +630,24 @@ config BT_ID_UNPAIR_MATCHING_BONDS
link-layer. The Host does not have control over this acknowledgment,
and the order of distribution is fixed by the specification.

config BT_ID_AUTO_SWAP_MATCHING_BONDS
bool "Automatically swap conflicting entries in the Resolving List"
depends on !BT_ID_UNPAIR_MATCHING_BONDS
Copy link
Contributor

Choose a reason for hiding this comment

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

I think "!BT_CENTRAL" is unnecessary. You may have central which is dealing with other non-private connections with other peripherals, and that would work without any issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't even want to think what will happen if BT_CENTRAL is enabled. The current use case is for Peripheral role only. Therefore it is easier to prevent compiling with BT_CENTRAL. If a customer comes with request to support Central role as well, we will look at this again.

@PavelVPV
Copy link
Contributor Author

Addressed comments. Also found bug when removing last conflicting key during unpairing.

@PavelVPV PavelVPV force-pushed the multi_id_bond branch 2 times, most recently from 750b10f to 447cebe Compare June 25, 2025 19:33
@PavelVPV
Copy link
Contributor Author

Test commit is dropped. Tests are moved to the internal test framework.

Copy link
Contributor

@omkar3141 omkar3141 left a comment

Choose a reason for hiding this comment

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

unrelated: bt_le_adv_start_ext could be made static.

Copy link
Contributor

@Balaklaka Balaklaka left a comment

Choose a reason for hiding this comment

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

Some of the github actions should be fixed.

bool "Automatically swap conflicting entries in the Resolving List"
depends on !BT_ID_UNPAIR_MATCHING_BONDS
depends on BT_PRIVACY && BT_PERIPHERAL && !BT_CENTRAL
select EXPERIMENTAL
Copy link
Contributor

Choose a reason for hiding this comment

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

I think experimental should be removed as this goes into production by customer.

@PavelVPV PavelVPV requested a review from Balaklaka June 26, 2025 12:51
@PavelVPV PavelVPV force-pushed the multi_id_bond branch 2 times, most recently from aeab23c to 966aa7a Compare June 26, 2025 13:02
This commit adds a new Kconfig option by enabling which Host will keep
bonding with the same Central instead of rejecting pairing.

Brief implementation details:

This implementation adds a new flag to bt_keys struct:
BT_KEYS_ID_CONFLICT. The flag is set, when:
- bonding with the same peer and conflict identified
- when loading conflicting keys from persistent storage.

When bonding and conflict is identified, the new keys aren't added to
the Resolving List immediately. Instead, the old keys stay in the
Resolving List.

When start advertising, Host finds conflicting keys that are already
added to the Resolving List and substitues them.

If, however, there is another advertiser already started for the added
keys, the new request is reject and advertising start function returns
-EPERM.

This is supported by Peripheral role only for now.

Signed-off-by: Pavel Vasilyev <[email protected]>
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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

Successfully merging this pull request may close these issues.

6 participants