BLE notifications get silently truncated when the negotiated MTU is too small
Maintainers usually reply within 1 day
A pull request for this has already been merged.
- #52 by @Tichael — merged
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- flutter, rust
- Domain
- embedded-iot, mobile-dev
Research direction
Start with the BLE TX task in boards/esp/src/ble/transport.rs around lines 638 and 666, then check how trouble-host handles notifications in gatt::assemble and how the mobile app handles the requested MTU in mobile-app/lib/providers/ble_connection_provider.dart. The issue suggests waiting for the MTU exchange event and checking each payload against the negotiated MTU; done means oversized messages are never silently truncated and a small MTU is logged on both sides.
Written by the indexing model from the issue text.
Description
Problem
BLE messages aren't fragmented: every message must fit in one ATT packet, at most ble.payload.max_message_bytes (244 bytes, from an ATT MTU of 247). The firmware never checks the MTU that was actually negotiated:
- After the link is encrypted, the TX task sleeps 500 ms and assumes the MTU exchange is done by then (
boards/esp/src/ble/transport.rs:638). Nothing confirms it. - trouble-host 0.6 trims a notification to the connection's ATT MTU without returning an error (
gatt::assembleintrouble-host-0.6.0/src/gatt.rs:644). Sonotify(...)attransport.rs:666reports success while the app receives a cut-off protobuf it can't decode. - The app requests
kBleAttMtu(mobile-app/lib/providers/ble_connection_provider.dart:219). When it gets less, it only logs a warning.
When it happens
The MTU exchange takes longer than 500 ms, or the phone negotiates less than 247. Some Android phones do; iOS picks its own MTU, which matters if iOS is ever supported. State updates near the worst-case size are then lost silently.
Ideas
- Wait for the MTU-exchange event instead of sleeping.
- Before each notify, compare the payload with
conn.raw().att_mtu() - 3and drop or log anything that doesn't fit, rather than sending a truncated message. - Longer term: BLE fragmentation (https://github.com/OpenCarControls/contracts/issues/5) removes the limit.
Done when
No message is ever sent truncated, and an MTU that's too small is visible in the logs on both sides.
- Dominant language
- Rust
- Stars
- 1
- Forks
- 0
- Avg merge
- 10h 56m
- Merged PRs (30d)
- 15
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from OpenCarControls/firmware
-
Clean up E-GMP leftoversPossibly taken @Tichael claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
OpenCarControls/firmware#34 ·
Maintainers usually reply within 1 day
-
BLE: send the current state when the app subscribesPossibly taken @Tichael claimed this today. Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
OpenCarControls/firmware#58 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
OpenCarControls/firmware#55 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
OpenCarControls/firmware#54 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 55/100
OpenCarControls/firmware#53 ·
Maintainers usually reply within 1 day
All issues in OpenCarControls/firmware
Similar issues
-
Difficulty 1/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
area:sim good first issue kind:feature
Difficulty 2/5 1-3 hours Newbie friendliness 87/100
Maintainers usually reply within 1 day
-
The demo's interval button and chart legend keep the previous interval after an interval changeOpenbug ui
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
userFRM/egui-charts#670 ·
Maintainers usually reply within 1 day
-
docs good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 84/100
Usenova-Labs/usenova-backend#35 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
lugassawan/swe-workbench#823 ·
Maintainers usually reply within 1 day