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

drv/bluetooth/stm32_cc2640: send correct max size #229

Merged
merged 2 commits into from
Jan 22, 2024
Merged

drv/bluetooth/stm32_cc2640: send correct max size #229

merged 2 commits into from
Jan 22, 2024

Conversation

dlech
Copy link
Member

@dlech dlech commented Jan 21, 2024

This finishes a TODO in the CC2640 driver to send the correct max payload size to the host via the Pybricks hub capabilities characteristic. Previously, this was hardcoded to use the hub max MTU size. But some Bluetooth adapters have a smaller MTU size, so we need to use the smaller of the two.

Fixes: pybricks/support#947

This finishes a TODO in the CC2640 driver to send the correct max
payload size to the host via the Pybricks hub capabilities
characteristic. Previously, this was hardcoded to use the hub max MTU
size. But some Bluetooth adapters have a smaller MTU size, so we need
to use the smaller of the two.

Fixes: pybricks/support#947
@coveralls
Copy link

coveralls commented Jan 21, 2024

Coverage Status

coverage: 56.508%. remained the same
when pulling d501df1 on bt-mtu-fix
into 264dfae on master.

@dlech
Copy link
Member Author

dlech commented Jan 21, 2024

I added another commit to be sure we are responding to prepared (long) write requests.

Previously, BlueZ would hang for a long time waiting for a response from these. Now it works as shown in the screenshot.

image

If a host tries to write more than MTU - 3 bytes to an attribute, the
host should do a prepared write to split up the write into multiple long
writes. We currently don't support this. So we need to send an error
response to the prepared write request. The host may also follow this
with an execute write command to cancel the prepared write, so we need
to respond to that too.

Issue: pybricks/support#947
@laurensvalk
Copy link
Member

Thanks!

Is this expected to have any side effects at all or would it only affect the Pybricks Code connection on the affected hosts?

In order words, any platforms this should be extensively tested on? Otherwise happy to just merge.

@dlech
Copy link
Member Author

dlech commented Jan 22, 2024

The changes are quite minimal so I feel like we have done adequate testing. The only behavior change will be for hosts that report an MTU less than 158. And we have verified that case is working as expected now since it was previously broken.

@dlech dlech merged commit 086d327 into master Jan 22, 2024
38 checks passed
@dlech dlech deleted the bt-mtu-fix branch January 22, 2024 15:04

attExchangeMTURsp_t rsp;
rsp.serverRxMTU = PBDRV_BLUETOOTH_MAX_MTU_SIZE;
Copy link
Member

Choose a reason for hiding this comment

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

Just curious, why does this response not use the conn_mtu value?

Copy link
Member Author

Choose a reason for hiding this comment

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

Per the Bluetooth spec, both the central and peripheral send their own value and take the lesser of the two. This way, it doesn't matter who asks first.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks! If you have time at some point, I have a few more Bluetooth questions 😄

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.

[Bug] Code fails to run from the edit window
3 participants