Skip to content

wifi: brcmfmac: wake on one magic packet during the associated sleep - #1679

Merged
RyanTheTide merged 1 commit into
integration/aurorafrom
wifi/brcmf-wowlan-macos-sleep
Nov 12, 2026
Merged

RyanTheTide merged 1 commit into
integration/aurorafrom
wifi/brcmf-wowlan-macos-sleep

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

With WoWLAN armed for magic packets, one packet now wakes the Mac from s2idle. Before this, a single broadcast magic packet woke an M1 Pro 3 times in 17 and an M2 never in 26, and unicast magic packets never matched.

What changes in the associated sleep

  • Power save: PM_FAST instead of PM_MAX, with bcn_li_dtim 1, bcn_li_bcn 0, pm2_sleep_ret 15, pm2_bcn_sleep_ret 50, pm_bcmc_wait 65000 and pm_bcmc_moredata_wait 30000. These are the values macOS sets on the same chips (from our own macOS capture). Each one is read first and written back on resume. A firmware that does not know one keeps its own value.
  • Unicast magic packets: the firmware tests filters while only the start of a frame is in dongle memory, so the 102-byte magic pattern never matches a unicast frame. New pattern-list (type 2) filters match UDP to each IPv4 and IPv6 address of the interface whose payload starts with six 0xff bytes and the station address, plus the same start after an EtherType 0x0842 header. Element offsets count from the IP and UDP headers, which the firmware finds itself, so IPv4 options don't move them. The layout is the public DHD wl_pkt_filter_pattern_list one.
  • ICMP echo offload for the IPv4 address. A sleeping Mac answers ping without waking, like it already does for ARP and ND.

The broadcast magic filter, the event mask, LPAS and the MSI wake path from #1653 are unchanged. WoWLAN off is unchanged.

Results

s2idle with one magic packet per sleep, sent from a host on the same AP (5 GHz). A wake counts when the Mac's own UDP heartbeat comes back before the RTC alarm; ping can't be used because the sleeping firmware now answers it. Brcmfmac built from this branch's driver on the fleet kernel, swapped in at runtime.

M1 Pro (BCM4387) M2 (BCM4387) J616s (BCM4388)
one broadcast magic packet 12/13 13/13 11/13
one unicast magic packet 13/13 13/13 13/13
before this change, one broadcast 3/17 0/26 -
before this change, one unicast 0/22 (all Macs)
time to wake (unicast) 0.2-0.4 s 1.4-1.8 s 1.6-1.9 s
5 pings while asleep answered, no wake (2/2) answered, no wake (2/2) answered, no wake (2/2)
other UDP to our address no wake (2/2) no wake (2/2) no wake (2/2)
no packet, 45 s slept to the alarm slept to the alarm slept to the alarm
WoWLAN off unchanged (2/2: disconnect, sleep, reconnect) unchanged (2/2) unchanged (2/2)

The association was kept in every WoWLAN cycle (same BSSID, no disconnect event), and there were 0 AVC denials. All six sleep iovars and every new filter were accepted by the M1 Pro and M2 firmware (20.96.31.0.8.7.148) and the J616s firmware.

A missed broadcast never reached the host: no wake frame, and the frames flushed after the RTC wake don't include it. Broadcast frames aren't acknowledged on the air. macOS on the same M1 Pro and AP missed 2 of 2 single broadcasts. Running without LPAS didn't change the broadcast rate (M1 Pro 8/10, J616s 9/10), so LPAS stays on.

30-minute idle sleep with WoWLAN armed, re-suspending after any early wake: M1 Pro 1800 s, M2 1802 s and J616s 1802 s, each one sleep to the RTC alarm with 0 spurious wakes, association kept and Wi-Fi up afterwards. macOS in the same lab woke itself for Wi-Fi every few seconds in the first minutes after boot and on TCP keepalive offload traffic.

Tests

  • tools/asahi/run-host-tests.py --only brcmf: 35/35. New brcmf-wowl-filter-tests.py runs the production filter builders against stubs, checks every pkt_filter_add byte against the public layout, and checks that running out of firmware filter slots keeps the filters already installed. It kills 4 mutants (base enum order, mask/data order, totsize, tracking).
  • W=1 build of brcm80211 is clean. checkpatch: 0 errors, 0 warnings.

🤖 Generated with Claude Code

With WoWLAN armed for magic packets, the LPAS associated sleep in s2idle
wakes the host only on repeated magic packets. One broadcast packet woke
an M1 Pro 3 times in 17 and an M2 never in 26, and a unicast magic packet
never matched.

Two things were missing. With PM_MAX and the firmware's default listen
and broadcast-wait settings, most single broadcast frames never reach the
sleeping firmware. And on unicast frames only patterns near the headers
match: a filter on the destination IPv4 address matches, while the
102-byte magic pattern (at a fixed offset or found anywhere) never does.

Set the sleep the way macOS sets it on these chips:

- PM_FAST instead of PM_MAX, with bcn_li_dtim 1, bcn_li_bcn 0,
  pm2_sleep_ret 15, pm2_bcn_sleep_ret 50, pm_bcmc_wait 65000 and
  pm_bcmc_moredata_wait 30000. Each value is saved and restored, and a
  firmware that does not know one keeps its own.
- Pattern-list (type 2) filters for unicast magic packets: UDP to each
  IPv4 address and each IPv6 address of the interface whose payload
  starts with six 0xff bytes and the station address, and the same start
  after an EtherType 0x0842 header. Element offsets count from the IP
  and UDP headers, which the firmware finds itself.
- ICMP echo offload for the IPv4 address, next to ARP and ND offload.

The broadcast magic filter stays as it was.

Tested on the M1 Pro (BCM4387), M2 (BCM4387) and M4 Pro J616s (BCM4388)
in s2idle, one packet per sleep, association kept, 0 AVC:

                       M1 Pro   M2      J616s
  one broadcast        12/13    13/13   11/13
  one unicast          13/13    13/13   13/13
  ping while asleep    answered by the firmware, no wake
  other UDP to us      no wake
  no packet            slept to the RTC alarm

A missed broadcast never reached the host: broadcast frames are not
acknowledged on the air, and macOS on the M1 Pro missed 2 of 2 single
broadcasts in the same lab.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
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.

1 participant