espradio: add ESP32 BLE support using espradio VHCI transport - #464
Open
deadprogram wants to merge 5 commits into
Open
espradio: add ESP32 BLE support using espradio VHCI transport#464deadprogram wants to merge 5 commits into
deadprogram wants to merge 5 commits into
Conversation
marcofeltmann
suggested changes
Jul 29, 2026
marcofeltmann
left a comment
There was a problem hiding this comment.
Local build with v1.24.4 but github workflow on macos with v1.25.0 seems odd, better sync the versions.
Signed-off-by: deadprogram <ron@hybridgroup.com>
Member
Author
|
Test failure until the next TinyGo release, since this repo builds that use the current release, but this PR needs the upcoming one. |
Adds a new `espradio` build tag that wires the existing HCI stack up to the ESP32's virtual HCI controller via tinygo.org/x/espradio. The new Adapter calls espradio.BLEInit() and hands a VHCI-backed transport to newBLEStack(); for WiFi+BLE co-existence, espradio.Enable() should be called first. The shared HCI implementation files pick up the espradio build tag, and go.mod is updated for the espradio and drivers dependencies. Signed-off-by: deadprogram <ron@hybridgroup.com>
Advertisement payload parsing and the HCI receive path both used wire-supplied lengths to index fixed-size buffers without validating them, panicking with "slice out of range" while scanning on ESP32. Add nextADField as a single bounds-checked AD field iterator, clamp the read size in poll after the 4-byte rounding, reject packets larger than the read buffer, and validate lengths before indexing in the event and ACL handlers. Add tests for malformed advertisement payloads. Signed-off-by: deadprogram <ron@hybridgroup.com>
poll advanced its parse cursor a byte at a time while reading another packet on every iteration, so reads outpaced parsing and the buffer ratcheted full. Once it did, the read was clamped to the space left, which the CYW43439 rejects because it hands back whole packets. Advance the cursor to everything that has been read, only read when there is room for a full packet, and size the buffer for the largest packet plus the transport's header and alignment padding. Signed-off-by: deadprogram <ron@hybridgroup.com>
Member
Author
|
This PR is now working, just awaiting the release of TinyGo 0.42 which will be right after Go 1.27 |
deadprogram
marked this pull request as ready for review
August 4, 2026 01:31
Scanning was hardcoded to passive, so peripherals that only put their complete local name in the scan response were reported without one. Default to active scanning instead, and pass our own address type in the scan parameters so the controller can fill in the SCAN_REQ. Add Adapter.SetScanType to select ScanTypeActive or ScanTypePassive before calling Scan, for callers that want the lower power use and silence of listening only. Signed-off-by: deadprogram <ron@hybridgroup.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a new
espradiobuild tag that wires the existing HCI stack up to the ESP32's virtual HCI controller via tinygo.org/x/espradio. The new Adapter calls espradio.BLEInit() and hands a VHCI-backed transport to newBLEStack(); for WiFi+BLE co-existence, espradio.Enable() should be called first.The shared HCI implementation files pick up the espradio build tag, and go.mod is updated for the espradio and drivers dependencies.
Works on ESP32C3 for both central and advertiser roles!
DONE: Requires that both tinygo-org/espradio#58 and tinygo-org/espradio#59 be merged, which is why this is in draft. It also requires the current
devbranch of TinyGo.