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: bt_gatt_cb.att_mtu_updated only called when MTU exchange completes #67858

Conversation

ubieda
Copy link
Member

@ubieda ubieda commented Jan 19, 2024

This PR attempts to address #64172, by issuing the following changes:

  1. bt_gatt_cb.att_mtu_updated is only called when the MTU exchange is completed (only once per connection).
  2. Modified tests/bsim/bluetooth/host/att/mtu_update to directly verify MTU exchange takes place both on Central and Peripheral.
  3. Updated Migration Guide document to reflect the behavior change of att_mu_updated as it was previously also triggered upon connection establishment (before MTU exchange).

NOTE: att_mtu_updated is not triggered if an MTU exchange results in an ATT_ERROR_RSP (e.g: Not supported). There's a comment on the issue whether that should also result in calling att_mtu_updated.

Status on PR Actionable Items:

  • Modify triggering of att_mtu_updated callback.
    • For (U)ATT Bearers
      • Do not trigger on ATT connection.
      • Trigger after successful MTU Exchange.
      • Trigger after a Failed MTU Exchange.
    • For EATT Bearers
      • May trigger on ATT connection, with updated MTU.
      • May trigger on Channel Reconfiguration.
  • Capture test-cases to lock-in MTU update behavior.
    • For (U)ATT Bearers
      • On Successfull MTU Exchange.
      • On Failed MTU exchange.
    • For EATT Bearers
      • On MTU-update from ATT connection.
      • On MTU-update from ATT channel reconfiguration.

@zephyrbot zephyrbot added area: Bluetooth Host Bluetooth Host (excluding BR/EDR) area: Bluetooth Release Notes To be mentioned in the release notes area: Samples Samples labels Jan 19, 2024
@ubieda ubieda force-pushed the fix/bt/gatt/notif-mtu-changed-only-after-exchange branch 2 times, most recently from e82a864 to 5b28e24 Compare January 19, 2024 23:24
samples/bluetooth/mtu_update/central/src/main.c Outdated Show resolved Hide resolved
samples/bluetooth/mtu_update/peripheral/src/main.c Outdated Show resolved Hide resolved
tests/bsim/bluetooth/host/att/mtu_update/src/main.c Outdated Show resolved Hide resolved
tests/bsim/bluetooth/host/att/mtu_update/src/main.c Outdated Show resolved Hide resolved
tests/bsim/bluetooth/host/att/mtu_update/src/main.c Outdated Show resolved Hide resolved
tests/bsim/bluetooth/host/att/mtu_update/src/main.c Outdated Show resolved Hide resolved
tests/bsim/bluetooth/host/att/mtu_update/src/main.c Outdated Show resolved Hide resolved
@ubieda ubieda force-pushed the fix/bt/gatt/notif-mtu-changed-only-after-exchange branch from 5b28e24 to 731b5d4 Compare January 22, 2024 16:14
@ubieda
Copy link
Member Author

ubieda commented Jan 22, 2024

@Thalley thanks for your feedback!

I've addressed the following changes:

  1. Restored APIs used for the mtu_exchange samples.
  2. Added the bt_gatt_cb_register() on the tests before running the samples (both for peripheral and central).
  3. Addressed formatting suggestions.

Follow-up Actions:

  1. Make sure change works with EATT Bearers. Extend BabbleSIM test to do so.

I don't think this will work for EATT bearers, as the MTU is negotiated as par of the connection request, so if I understood correctly, this will not provide MTU information to the application on EATT connection established. We should probably extend one of the EATT babblesim tests to also care about the MTU exchange to ensure that the change we do here, works as expected for EATT as well.

  1. @Thalley Do you have any feedback on Bluetooth: Host: Unable to easily determine if the GATT MTU has been exchanged #64172 (comment)?

@alwa-nordic
Copy link
Collaborator

I propose adding more test cases to nail down the behavior:

  • a test for MTU 23 case
  • a test that connects EATT but does not perform an ATT MTU exchange
  • a test for when the exchange results in an error

What do you think?

@ubieda
Copy link
Member Author

ubieda commented Jan 24, 2024

I propose adding more test cases to nail down the behavior:

  • a test for MTU 23 case
  • a test that connects EATT but does not perform an ATT MTU exchange
  • a test for when the exchange results in an error

What do you think?

@alwa-nordic Sounds good. I'll capture them in the tests!

@ubieda ubieda force-pushed the fix/bt/gatt/notif-mtu-changed-only-after-exchange branch from 731b5d4 to b24fe02 Compare January 25, 2024 06:42
Per issue zephyrproject-rtos#64172, `att_mtu_updated` is expected to only notify once the
MTU exchange has taken place in a Bluetooth connection, and not once
connection is established. This allows each GATT profile to use this
callback as a way to be signaled when higher MTU is available, which is
expected to occur once per connection.
There is the exception for EATT L2CAP channels, where an MTU exchange
takes place at the L2CAP level, during ATT connection establishment.

Signed-off-by: Luis Ubieda <[email protected]>
Now is not triggered upon connection establishment.

Signed-off-by: Luis Ubieda <[email protected]>
Previously this sample verified the MTU exchange in an indirect manner
by being able to send a larger notification size. Now this adjustment
allows directly verifying both on the Central and the Peripheral that
the expected MTU exchange takes place, and that the listeners
subscribed through `bt_gatt_cb_register` are notified when this
exchange takes place (once per connection).

Signed-off-by: Luis Ubieda <[email protected]>
@ubieda ubieda force-pushed the fix/bt/gatt/notif-mtu-changed-only-after-exchange branch from b24fe02 to 08e9a29 Compare January 25, 2024 06:54
Comment on lines +292 to +294
* The handler `att_mtu_updated` registered over the :c:func:`bt_gatt_cb_register`
API is no longer triggered upon connection establishment. It is now only
called when the MTU exchange has taken place.
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's still called on EATT connection establishment though

Comment on lines +211 to +213
if (info.role == BT_CONN_ROLE_CENTRAL) {
(void)mtu_exchange(conn);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems superfluous to guard a function call with BT_CONN_ROLE_CENTRAL in a central sample.

Furthermore, both the central and peripheral is allowed to do the MTU exchange

Comment on lines +74 to +77
if (central_mtu_count == 1 &&
central_mtu_tx == expected_mtu &&
central_mtu_rx == expected_mtu) {
PASS("MTU Update test passed [Central]\n");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some indentation is off here

Comment on lines +113 to +115
if (peripheral_mtu_count == 1 &&
peripheral_mtu_tx == expected_mtu &&
peripheral_mtu_rx == expected_mtu) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some indentation is off here

Suggested change
if (peripheral_mtu_count == 1 &&
peripheral_mtu_tx == expected_mtu &&
peripheral_mtu_rx == expected_mtu) {
if (peripheral_mtu_count == 1 &&
peripheral_mtu_tx == expected_mtu &&
peripheral_mtu_rx == expected_mtu) {

Comment on lines +79 to +80
FAIL("MTU Update test failed [Central] - Count: %u, MTU RX: %u, MTU TX: %u\n",
central_mtu_count, central_mtu_rx, central_mtu_tx);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
FAIL("MTU Update test failed [Central] - Count: %u, MTU RX: %u, MTU TX: %u\n",
central_mtu_count, central_mtu_rx, central_mtu_tx);
FAIL("MTU Update test failed [Central] - Count: %u, MTU RX: %u, MTU TX: %u\n",
central_mtu_count, central_mtu_rx, central_mtu_tx);

Comment on lines +118 to +119
FAIL("MTU Update test failed [Peripheral] - Count: %u, MTU RX: %u, MTU TX: %u\n",
peripheral_mtu_count, peripheral_mtu_rx, peripheral_mtu_tx);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
FAIL("MTU Update test failed [Peripheral] - Count: %u, MTU RX: %u, MTU TX: %u\n",
peripheral_mtu_count, peripheral_mtu_rx, peripheral_mtu_tx);
FAIL("MTU Update test failed [Peripheral] - Count: %u, MTU RX: %u, MTU TX: %u\n",
peripheral_mtu_count, peripheral_mtu_rx, peripheral_mtu_tx);

Comment on lines -53 to -54
uint8_t notify_data[100] = {};
uint8_t is_data_equal;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it make sense to remove the notification part of the test?

Wouldn't it make sense to both verify the MTU values and verify the notification length?

@jori-nordic
Copy link
Collaborator

@ubieda sorry for the super-short notice, but do you want to join the meeting today (in an hour or so) to discuss this PR?

@ubieda
Copy link
Member Author

ubieda commented Jan 25, 2024

@ubieda sorry for the super-short notice, but do you want to join the meeting today (in an hour or so) to discuss this PR?

@jori-nordic Yeah - I'll see y'all in a few minutes!

@ubieda
Copy link
Member Author

ubieda commented Jan 29, 2024

Just to capture current status on this PR: It's marked as blocked on #68107. Once that is addressed, we can re-evaluate this PR and follow-up with the change-requests.

Comment on lines +292 to +294
* The handler `att_mtu_updated` registered over the :c:func:`bt_gatt_cb_register`
API is no longer triggered upon connection establishment. It is now only
called when the MTU exchange has taken place.
Copy link
Member

Choose a reason for hiding this comment

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

This needs to go into the migration guide for v3.7.0 instead.

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 Apr 25, 2024
@ubieda
Copy link
Member Author

ubieda commented Apr 30, 2024

@Thalley @jori-nordic feel free to close if, after the latest changes in the BT Stack, this work needs to be restarted / no longer a suitable approach.

@jori-nordic
Copy link
Collaborator

Yeah let's close it. It's linked to the RFC issue, so we can always go back and re-open it later.
Thanks for putting in the work!

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 area: Samples Samples Release Notes To be mentioned in the release notes Stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants