BLE management advertisement can become too long #108

Merged
albert merged 4 commits from fix/ble-advertisement-name-overflow into main 2026-07-26 21:58:57 +00:00
Owner

The BLE advertisement contains the service UUID along with a few other bytes of data, which eat away at the total 31 bytes allowed in a BLE advertisement. This change truncates the name so that the advertisement is never longer than 31 bytes -- a fix with a similar history as https://albertarmea.com/post/bt-auto-connect/#discovery-using-bluetooth-le.

This was only one of the issues preventing a successful BLE connection. The other is a very recent kernel regression in the MGMT Add Extended Advertising Data (0x0055) command:

I've also opened #109 to track that issue internally.

The BLE advertisement contains the service UUID along with a few other bytes of data, which eat away at the total 31 bytes allowed in a BLE advertisement. This change truncates the name so that the advertisement is never longer than 31 bytes -- a fix with a similar history as https://albertarmea.com/post/bt-auto-connect/#discovery-using-bluetooth-le. This was only one of the issues preventing a successful BLE connection. The other is a very recent kernel regression in the MGMT `Add Extended Advertising Data` (0x0055) command: * https://github.com/raspberrypi/linux/issues/7473 -- the exact issue, but seen in and resolved in the Raspberry Pi kernel only * https://bugs.launchpad.net/ubuntu/+source/linux/+bug/2161852 -- opened as a result of this investigation I've also opened #109 to track that issue internally.
A device_name longer than 8 bytes (the system hostname by default, e.g.
"copernicus") pushed the advertisement over the 31-byte legacy PDU:
Flags (3) + 128-bit service UUID (18) + local name (2 + len). BlueZ
rejected the whole advertisement with "Invalid Parameters (0x0d)", so
the management service UUID never went on air and the companion's
UUID-filtered scan found nothing — presenting as "the device won't
pair" when it was really undiscoverable, and only on hosts whose name
overflowed.

Trim the advertised name to MAX_ADV_NAME_BYTES on a UTF-8 char boundary,
with a trailing ellipsis when shortened (copernicus -> coper…), and warn
when it happens. The service UUID now always fits; the full name still
reaches the companion over GATT.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
btmon on two devices (Intel 8265 BT4.2 and a BT5 controller, both on
Ubuntu 26.04 7.0.0-28-generic) shows bluetoothd's MGMT "Add Extended
Advertising Data" rejected with Invalid Parameters (0x0d) for a valid
3-byte advertisement, while the legacy "Add Advertising" MGMT path
(btmgmt add-adv) succeeds. It's a kernel extended-advertising regression,
not shepherd, not the controller, not advertised-name length.

Rewrite the history note to lead with the real root cause (keeping the
name-trim as documented separate hardening) and add an INSTALL.md
troubleshooting entry with the btmgmt/btmon repro and kernel-level
remediation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Confirmed the BLE advertising failure is the mainline 6.18 ext-adv
regression (raspberrypi/linux#7473): Ubuntu 26.04 dpkg log brackets it
to 7.0.0-27.27 (works) -> 7.0.0-28.28 (broken), verified by booting back
to -27. Document the pin/hold/GRUB rollback in INSTALL.md and the
confirmed bracket + upstream reference in the history note.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
docs(ble): link the filed kernel bug (LP #2161852)
All checks were successful
CI / Version harmony (pull_request) Successful in 34s
CI / ShellCheck (pull_request) Successful in 38s
CI / Arch neutrality (pull_request) Successful in 37s
CI / CI image (pull_request) Successful in 40s
CI / CI image (Android) (pull_request) Successful in 24s
CI / CI images (pull_request) Successful in 0s
CI / Warm cargo registry (pull_request) Successful in 46s
CI / Rustfmt (pull_request) Successful in 44s
CI / Android media (cargo-ndk build) (pull_request) Successful in 1m6s
CI / Android companion (unit tests) (pull_request) Successful in 1m24s
CI / Clippy (pull_request) Successful in 1m38s
CI / Build (pull_request) Successful in 2m44s
CI / Test (pull_request) Successful in 2m48s
CI / E2E (pull_request) Successful in 2m47s
CI / Firewall E2E (pull_request) Successful in 4m4s
CI / Package (.deb smoke build) (pull_request) Successful in 2m17s
c23e897572
Reference the Launchpad regression bug for the 7.0.0-28 BLE ext-adv
failure in both the INSTALL.md troubleshooting entry and the history
note, so the kernel pin has a tracking link to unpin against.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
albert merged commit 4a7c06d24f into main 2026-07-26 21:58:57 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
albert/shepherd-launcher!108
No description provided.