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: host: Avoid sending duplicate device to RL. #48641

Closed

Conversation

ibaz-nordic
Copy link
Contributor

@ibaz-nordic ibaz-nordic commented Aug 3, 2022

Fixes: #45827

Signed-off-by: Azizah Ibrahim [email protected]

Copy link
Member

@jhedberg jhedberg left a comment

Choose a reason for hiding this comment

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

Couple of inline comments. Also, could you explain what parts of bt_id_add() functionality is still critical for a duplicate entry? My initial (and probably naïve) thought is that do we need to call the function at all in the case of a duplicate?

Another way to avoid the controller error would be to always remove the entry via HCI before trying to add it. Yet another option is to simply cleanly deal with the specific HCI error code that results from a duplicate.

subsys/bluetooth/host/smp.c Outdated Show resolved Hide resolved
@@ -864,13 +864,19 @@ void bt_id_add(struct bt_keys *keys)
goto done;
}

if (duplicate_rl && !IS_ENABLED(CONFIG_BT_PRIVACY)) {
Copy link
Member

Choose a reason for hiding this comment

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

What about the rl_entries == rl_size branch above? That would still increment rl_entries even for a duplicate.

Also (minor issue): you have two spaces after &&

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way I see it, rl_entries is used to check if there's any address resolution. In this situation, it should have been counted before. So there's no need to increment.

@ibaz-nordic ibaz-nordic force-pushed the zephyr_duplicate_rl branch from 665849f to 923a1ec Compare August 4, 2022 09:14
@ibaz-nordic
Copy link
Contributor Author

Couple of inline comments. Also, could you explain what parts of bt_id_add() functionality is still critical for a duplicate entry? My initial (and probably naïve) thought is that do we need to call the function at all in the case of a duplicate?

Another way to avoid the controller error would be to always remove the entry via HCI before trying to add it. Yet another option is to simply cleanly deal with the specific HCI error code that results from a duplicate.

From Core 5.3 p2424 BT_HCI_OP_LE_ADD_DEV_TO_RL should return Invalid HCI Command
Parameters in one situation, and has the option to return Invalid HCI Command
Parameters in another situation. So I think it's difficult to deal with the situation based on error code.

I think identifying a duplicate address and not adding it is a better solution than deleting and then adding because a flash cycle is saved.

@ibaz-nordic ibaz-nordic requested a review from jhedberg August 4, 2022 09:40
Core v5.3, Vol 4, Part E, 7.8.38
Controller has the option to accept or reject when the same device
is added to RL.
In this patch host will not add the same device to controller RL.

Signed-off-by: Azizah Ibrahim <[email protected]>
@ibaz-nordic ibaz-nordic force-pushed the zephyr_duplicate_rl branch from 923a1ec to b940195 Compare August 4, 2022 09:59
Copy link
Collaborator

@alwa-nordic alwa-nordic left a comment

Choose a reason for hiding this comment

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

I think this is a completely wrong approach to fix the problem.

Abstractly, each local identity has its own bond database.

Each entry in the bond database must have a remote identity address and optionally a remote identity resolving key.

Both the remote identity address and the corresponding identity resolve key must each be unique within that bond database. This is because must exist a two way mapping between them.

A remote identity should be considered bonded only when it's has been added to the bond database. Before that, the bond is incomplete.

When we obtain an identity address and everything else necessary for a bond, we should try to realize the bond by adding it to the bond database. The database must refuse if there is a conflict in the uniqueness constraints. When that happens, we can prompt the application to handle the problem of a conflicting bond. The application can choose to use the normal bond deletion mechanism to delete the conflicting bond, in which case the new bond can be stored. Or it an disconnect to refuse.

If the application deletes the conflicting bond, one of the things that should happen is that the old identity address and identity resolving key are removed from the controller resolve list. This solves the problem this PR is trying to address.

I will take some time now to sketch out a possible realization of this, and give you the details in case you want to implement this.

@ibaz-nordic
Copy link
Contributor Author

@alwa-nordic will look into a different solution

@ibaz-nordic ibaz-nordic deleted the zephyr_duplicate_rl branch October 20, 2022 14:09
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.

bluetooth: bluetooth host: Adding the same device to resolving list
4 participants