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: Bitwise-or CCC values #44136

Closed

Conversation

alwa-nordic
Copy link
Collaborator

@alwa-nordic alwa-nordic commented Mar 23, 2022

This PR fixes several issues:

  • Only consider connected peers when summing CCC values instead of
    connected or bonded.
  • Aggregate the value of the CCC using bitwise-or instead of max.
  • Document the cfg_changed event.

Comment on lines 714 to 716
* This event will not trigger if only the @c cfg field changes but the
* @c value field remains the same. Combine the use of this event and
* @c cfg_write to catch all changes to the @c cfg field.
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 would like to change this to trigger on any change to the cfg field. RFC

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

On the other hand, it would be awkward because only value is passed as a parameter here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see your point.
Technically a device keeps a CCCD for each client which is of course abstracted away by the API, so it appears as just a single value.

It does sound a bit odd to call the callback every time there is a change, since the value may not actually change here, and the application would thus not really be able to use that information for anything.

I think in the case where an application needs/wants more specific knowledge or handling of CCCD writes, it would just just the BT_GATT_CCC_MANAGED to do that.

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.

I think the bit-wise approach will give a better API to be honest. I also assume that for 99% of use cases this will not affect existing applications - Besides HAS I am not away of any services that even allow both indications and notifications on the same characteristic.

I think it will be worth going ahead with this change, and of course also add an entry in the release notes.

@alwa-nordic alwa-nordic force-pushed the bitwise-or-ccc-value branch from 3e446a6 to d081dae Compare March 23, 2022 19:20
@github-actions github-actions bot added area: API Changes to public APIs area: Bluetooth area: Bluetooth Host area: Documentation Release Notes To be mentioned in the release notes labels Mar 23, 2022
@alwa-nordic alwa-nordic force-pushed the bitwise-or-ccc-value branch from d081dae to 6fc3e8a Compare March 23, 2022 19:24
The doc on `_bt_gatt_ccc.value` specifies that only connected peers
contribute to that value. But before this change, it was all computed
from all entries in `_bt_gatt_ccc.cfg`, which include bonded but not
connected peers when `CONFIG_BT_SETTINGS_CCC_LAZY_LOADING` is set.

Signed-off-by: Aleksander Wasaznik <[email protected]>
Summarize the value of the CCC using bitwise-or instead of max. This
is more natural and affords distinguishing between when only indications
are enabled and when both notifications and indications are enabled.

It is not expected that this change will affect any applications. It will
not affect attributes that allow only one of notifications and indications.
It will also not affect applications that only compare this value to zero.

But it simplifies the interface of `_bt_gatt_ccc.value` and
`_bt_gatt_ccc.cfg_changed`.

Signed-off-by: Aleksander Wasaznik <[email protected]>
This documents the behavior and a suggested use case.

Signed-off-by: Aleksander Wasaznik <[email protected]>
@alwa-nordic alwa-nordic force-pushed the bitwise-or-ccc-value branch from 6fc3e8a to 8fa7c03 Compare March 24, 2022 09:42
@alwa-nordic alwa-nordic marked this pull request as ready for review March 28, 2022 08:48
value |= ccc->cfg[i].value;

bt_conn_unref(conn);
conn = NULL;
Copy link
Member

Choose a reason for hiding this comment

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

This setting to NULL doesn't really give you anything, as the function returns immediately thereafter and the variable goes out of scope

@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label May 29, 2022
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.

LGTM, but please consider fixing the comment from Johan

@jhedberg jhedberg removed the Stale label Jun 1, 2022
@carlescufi
Copy link
Member

@alwa-nordic please follow-up and rebase

@alwa-nordic alwa-nordic marked this pull request as draft July 14, 2022 10:46
@github-actions
Copy link

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions bot added the Stale label Sep 13, 2022
@alwa-nordic alwa-nordic self-assigned this Sep 15, 2022
@github-actions github-actions bot closed this Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants