Skip to content

cyw43: add the missing padding before BssInfo::ie_length - #7601

Open
modelmiser wants to merge 1 commit into
embassy-rs:mainfrom
modelmiser:cyw43-bssinfo-padding
Open

modelmiser wants to merge 1 commit into
embassy-rs:mainfrom
modelmiser:cyw43-bssinfo-padding

Conversation

@modelmiser

Copy link
Copy Markdown

BssInfo mirrors the firmware's wl_bss_info_t version 109 (Linux brcmfmac's struct brcmf_bss_info_le). That C struct is not packed, so two bytes of padding sit between ie_offset (offset 116) and ie_length (offset 120), with SNR at 124 and sizeof 128. The Rust struct is repr(C, packed(2)) and names the other alignment pads explicitly (reserved1…reserved4) but not this one, so ie_length is read at 118 and snr at 122.

Effect before this change: with the pad bytes zero, ie_length comes out as the real length shifted up by 16 bits (332 bytes of IEs read as 0x014C0000, the value @plugwash measured in #3164), and snr reads the high half of ie_length, i.e. 0.

This adds the two bytes, as they proposed there, plus two bytes of tail padding so the struct is 128 bytes like the C one.

  • Breaking: BssInfo::SIZE goes from 124 to 128, and with it the array length in the public from_bytes / from_bytes_mut / to_bytes.
  • No driver logic reads ie_offset, ie_length or snr. BssInfo::SIZE is the minimum record length ScanResults::parse and BssInfo::parse accept and the number of bytes copied into the event, so a scan event whose record is shorter than 128 bytes is dropped (the floor was 124). The CYW43439 reports ie_offset 128, so its records are at least that long.
  • size_of::<events::Message>() goes from 140 to 144; the event queue holds two.
  • Tests: offset_of! pins the three fields at 116 / 120 / 124 and the size at 128, and a record laid out like the C struct decodes ie_length 332 and snr 25. Both fail without the pad before ie_length. CI does not run them (.github/ci/test.sh has no cyw43 entry); I can add cargo test --manifest-path ./cyw43/Cargo.toml --lib there if you want.
  • Tested on a Pico 2 W (CYW43439) only: with the fix, ie_length reads 150–394 on real scan results, and the record's length - ie_offset equals ie_length rounded up to a multiple of 4. The CYW4373 and CYW43455 share this struct and were not tested; the driver does not check the record's version.

Related: #3164.

🤖 Generated with Claude Code

wl_bss_info_t v109 (brcmfmac's brcmf_bss_info_le) is naturally aligned:
ie_offset at 116, two pad bytes, ie_length at 120, SNR at 124, sizeof 128.
BssInfo is repr(C, packed(2)) and names every other alignment pad explicitly
but not this one, so ie_length was read at 118 (the real value shifted up by
16 bits: 0x014C0000 for 332) and snr at 122 (the high half of ie_length,
always 0). Add the two bytes, and two bytes of tail padding so SIZE is 128
like the C struct. SIZE is public, so this is a breaking change.
Tests pin the offsets and decode a firmware-layout record.

Reported with the fix in embassy-rs#3164 by plugwash.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@embassy-bot

embassy-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown

👋 Welcome, @modelmiser, and thanks for opening your first pull request here!

If you haven't already, please give the contributor guide a read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant