Skip to content

Conversation

@alwa-nordic
Copy link
Contributor

@alwa-nordic alwa-nordic commented Aug 4, 2023

In this PR we improve _bt_gatt_ccc.value to use a more natural definition: bitwise-or instead of max. We ensure that only currently connected peers affect this value, so that the definitions stays independent of the CCC lazy loading kconfig. We document the use case for _bt_gatt_ccc.value and clarify the documentation of cfg_changed.

Fixes: #61260
Resolves: #55373

@alwa-nordic alwa-nordic marked this pull request as ready for review August 4, 2023 14:02
@zephyrbot zephyrbot added Release Notes To be mentioned in the release notes area: Bluetooth area: Bluetooth Host Bluetooth Host (excluding BR/EDR) labels Aug 4, 2023
@jori-nordic
Copy link
Contributor

jori-nordic commented Aug 8, 2023

could you add/extend a test for this? ie subscribing to indications, checking the CCC value on the server and then doing the same for notifications

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 5fc8c4f to dceb291 Compare August 8, 2023 13:39
@alwa-nordic alwa-nordic requested a review from wopu-ot as a code owner August 8, 2023 13:39
@alwa-nordic alwa-nordic marked this pull request as draft August 8, 2023 13:39
break;
}

__ASSERT_NO_MSG(!err);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since ASSERTS can be disabled via Kconfig, wouldn't it be better to use regular ifs?

__ASSERT_NO_MSG(!err);

while (bt_eatt_count(conn) == 0) {
LOG_DBG("E..");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this DBG intended?

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 it is a good idea with some common testlib functionality. Is this something that we can perhaps apply to multiple tests, rather than keep in this single test case, or do the tests differ too much to be able to use a common testlib?

Comment on lines +32 to +33
}
k_condvar_signal(&g_ctx->done);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
}
k_condvar_signal(&g_ctx->done);
}
k_condvar_signal(&g_ctx->done);


int bt_testlib_adv_conn(struct bt_conn **conn, int id, uint32_t adv_options)
{
int api_err;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to prefix this with api?

Suggested change
int api_err;
int err;

Comment on lines +68 to +70
api_err = bt_gatt_read(ctx->conn, &ctx->params);

if (!api_err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
api_err = bt_gatt_read(ctx->conn, &ctx->params);
if (!api_err) {
api_err = bt_gatt_read(ctx->conn, &ctx->params);
if (!api_err) {

Comment on lines +95 to +98
.params = {.by_uuid = {.uuid = type,
.start_handle = start_handle,
.end_handle = end_handle},
IF_ENABLED(CONFIG_BT_EATT, (.chan_opt = bearer))},
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it could be indented differently to be more readable. If using clang-format, try adding , after the last element

Comment on lines +116 to +118
.params = {.handle_count = 1,
.single = {.handle = handle, .offset = offset},
IF_ENABLED(CONFIG_BT_EATT, (.chan_opt = bearer))},
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto

Comment on lines +54 to +56
api_err = bt_conn_le_create(peer, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, conn);

if (!api_err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
api_err = bt_conn_le_create(peer, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, conn);
if (!api_err) {
api_err = bt_conn_le_create(peer, BT_CONN_LE_CREATE_CONN, BT_LE_CONN_PARAM_DEFAULT, conn);
if (!api_err) {

{
int api_err;
struct bt_scan_find_name_closure ctx = {
.wanted_name = name,
Copy link
Contributor

Choose a reason for hiding this comment

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

The simple pointer assignment assignment here indicates that name shall have a long life time (at least until the device is found), but that isn't really that obvious from the header file. Suggest to either do a copy, or to somehow indicate in the header file that the name argument cannot just be stack allocated.

@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 Oct 14, 2023
@github-actions github-actions bot closed this Oct 29, 2023
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 Release Notes To be mentioned in the release notes Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve the description of _changed callback in BT_GATT_CCC macro in gatt.h Bluetooth: Host: Disconnected bonds affect _bt_gatt_ccc.value

4 participants