Skip to content

Fix BCM4350 Bluetooth coexistence on MacBookPro14,1 - #13298

Open
Clowdyffs wants to merge 3 commits into
omacom:quattrofrom
Clowdyffs:fix/macbookpro14-1-bluetooth-coexistence
Open

Clowdyffs wants to merge 3 commits into
omacom:quattrofrom
Clowdyffs:fix/macbookpro14-1-bluetooth-coexistence

Conversation

@Clowdyffs

@Clowdyffs Clowdyffs commented Sep 26, 2026 •

Copy link
Copy Markdown

Fixes #13297.

On MacBookPro14,1, BCM4350's default hybrid coexistence policy interrupts A2DP audio while 2.4 GHz Wi-Fi is connected. Switching to parallel mode restored steady tones and music, including a concurrent Wi-Fi download; restoring hybrid mode reproduced the failure. The issue and hardware measurements document the comparison.

Add one NetworkManager dispatcher scoped to MacBookPro14,1, BCM4350 rev 5 (14e4:43a3), and firmware 7.35.180.133 / 01-c45b39d6. It changes default mode 5 to mode 4 on 2.4 GHz and restores only its owned override when disconnected or on another band. Ownership records the interface's ifindex, so a stale marker cannot authorize restoration after re-registration. A confirmed nonparallel readback after an attempted write releases ownership; an unavailable acknowledgement/readback retains recovery state because the outcome is unknown. Different firmware and nondefault policies are preserved.

Repeated events with mode 4 active send no additional firmware write; irrelevant events exit before Python. A boot-only command would miss later firmware reloads, while leaving mode 4 enabled on every band broadens the tested policy. The existing omarchy-settings recipe ships the executable directly from etc/, so package updates maintain or retire it and new/existing installs pick it up at their next network activation. No daemon, migration or driver reset.

Validation:

  • All 11 focused test groups pass: scope guards, vendor protocol, repeated events, band changes, ownership and failure recovery. New coverage distinguishes a confirmed failed write from lost acknowledgement/unavailable readback and verifies preservation of an independent mode-4 writer on the same interface.
  • The new regression fails against published dispatcher 786e1ffc. The full fixture sequence on that head confirms an ignored write leaves mode 5 and a marker, followed by an unwanted SET 5 after another tool chooses 4. With this correction the marker is absent and the independent mode 4 is preserved. No live network or firmware-policy writes were used for these tests.
  • Bash syntax, embedded Python syntax, and diff whitespace checks pass. The full aggregate suite was not rerun for this three-line production correction. Earlier testing of the preceding revision reported a CLI theme assertion and nine failed shell files, all reproduced on unchanged base 7b336b1b; those remain historical results, not a new aggregate pass.
  • The 5→4→5 policy transitions were tested on hardware in the published measurements; the preceding entrypoint was also invoked with mode 4 already active. Ownership corrections are tested with external fixtures. Independent testing of this exact revision on another target Mac, reboot/resume behavior, other access points, and microphone calls remain outstanding. Within-connection roaming is checked at the next dispatcher event.

@llstrk

llstrk commented Sep 27, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

No defect found in the normal dispatcher path at 4e8afe85. One narrow ownership-marker case can still overwrite a policy the dispatcher did not set, and a few test and logging notes follow. Everything below comes from source reading and a sandbox with a stubbed iw. Nothing ran on the target hardware.

Verified:

  • Vendor request and reply. The request bytes match brcmfmac's struct brcmf_vndr_dcmd_hdr in Linux v7.2 (vendor.h):

    • get: (262, 256, 20, 0, 0) + "ver\0"
    • set: (263, 13, 20, 1, 0) + "btc_mode\0" + LE 4

    The parser accepts the kernel's actual reply layout (DATA, then LEN, plain attribute types). Broadcom's wlioctl_defs.h defines 4 as parallel and 5 as hybrid. brcmfmac's own coexistence code writes btc_params, never btc_mode, so the driver itself never overwrites it (a firmware reload returns it to the default).

  • Scope guards. Other models, or missing DMI, exit in bash with no iw call. A MacBookPro14,1 with different firmware gets one read-only ver query and no btc_mode access. A different vendor, device, revision or driver gets no iw call.

  • Packaging and dispatch. omarchy-settings copies etc/ with cp -a under makepkg's umask 0022, so the file ships 0755 root:root. That passes NetworkManager's dispatcher permission check (root-owned, not group/other-writable, owner-executable). NetworkManager rescans dispatcher.d on each event and runs scripts one at a time, so a newly installed file takes effect at the next event, and the script never runs concurrently with itself. NetworkManager.service enables the dispatcher service through Also=, on fresh installs and on the quattro upgrade path. iw arrives through wireless-regdb and python through python-gobject, both in install/omarchy-base.packages. The package build was not run; this chain comes from reading the PKGBUILD and makepkg.

  • Failure handling. A missing iw, a hung iw (ended by timeout=2 after about 2.07 s), firmware errors, empty replies and device removal all exit 0.

  • Test. The new test passes at this head (6 ok - lines) and fails on the base tree, where the dispatcher does not exist. It caught 12 of 15 diagnostic mutants of the dispatcher.

A stale ownership marker can restore 5 over another writer's 4

If a dispatcher event arrives after the card was unbound or removed, the sysfs vendor read (dispatcher lines 57-59) raises before any marker logic. main() catches it and exits 0, and /run/omarchy-bcm4350-coexistence/<iface> stays. A firmware hang during the run keeps the marker the same way. After a rebind, the firmware is back at 5 and usually the next event clears or reuses the marker correctly. The wrong write needs a second writer that sets exactly 4:

up on 2.4 GHz            write 4, marker created
card unbound, then down   sysfs read fails, marker kept
rebind                    firmware back at 5
another tool sets 4       (while on 5 GHz)
next up on 5 GHz          marker present, mode 4 -> writes 5

Reproduced with the production script and a stubbed iw. With the other writer's 4 already set at a 2.4 GHz up, the marker also survives, and the next off-2.4 event writes 5. Neither write happens without the stale marker.

Impact: a single write of the hybrid default while off 2.4 GHz, outside the 2.4 GHz case the issue describes. It contradicts the line 82 comment and the docs' "only if /run/omarchy-bcm4350-coexistence/ records that it applied parallel mode". It needs a second writer of btc_mode, such as an administrator's own earlier workaround script; nothing at the quattro tip or in the related PRs writes btc_mode. A stale marker needs the card to be re-registered with fresh firmware while the marker exists and before an event clears it: for example a manual rebind, a module reload, brcmfmac's crash reset, or its resume re-probe when the sleep-time down runs late. Open PRs #7180, #7333, #12314 and #12688 unbind and rebind this card around every suspend, which would put every suspend taken on 2.4 GHz into this race; how often NetworkManager's down loses it was not measured.

Suggested change: record the interface's ifindex in the marker when taking ownership, and drop a marker whose ifindex differs from the live interface before deciding anything. Linux assigns a new ifindex on each netdev registration, so a rebind, crash reset or module reload changes it. A prototype of this passed all of the marker sequences above plus the normal-behaviour checks. The PR's own test was not run against it; its fake sysfs would need an ifindex file. Deleting the marker when the device node is missing is simpler but does not cover the firmware-hang case.

Minor notes

  • Optional test improvement: removing the if current == 4: restore guard (dispatcher line 83) still passes the test, because the independent-policies block drops ownership with a reapply on 2.4 GHz before changing band. Apply on 2.4 GHz, then change the mode to 2 with no event, then send down; expecting no write and mode 2 fails that mutant.
  • Optional test improvement: the test's iw stub sends LEN before DATA and sets the nested flag on DATA (test lines 75-77). The kernel sends DATA then LEN with plain types. The production parser handles both, but a parser that matched only the kernel's plain types failed the test. Emitting DATA then LEN with plain attribute types, as brcmfmac does, would test the real layout.
  • Optional: on MacBookPro14,1, handled events for interfaces without a PCI device (for example Docker bridges or USB network adapters) log BCM4350: coexistence quirk skipped (FileNotFoundError), which reads like a failure. Returning silently when /sys/class/net/<iface>/device/vendor is absent would avoid this.
  • Optional: the dispatcher is package-owned in /etc and replaced on upgrade, and a deliberately chosen mode 5 cannot be told apart from the default, so there is no persistent opt-out. NetworkManager also reads /usr/lib/NetworkManager/dispatcher.d/, where /etc takes precedence and a /dev/null symlink masks a script. Shipping it there would give administrators that standard mask, at the cost of a PKGBUILD install line and a departure from the etc/ pattern.
  • Related: open PR fix: Bluetooth audio dropouts on Macs with Broadcom BT #7644 targets Broadcom Bluetooth audio dropouts on Macs by other means (codec cap, btusb autosuspend) and touches none of these files. This head merges cleanly with the quattro tip and with fix: Bluetooth audio dropouts on Macs with Broadcom BT #7644, apple: rebind brcmfmac across suspend #12314 and [Intel Mac P10] Consolidate Broadcom calibration and sleep recovery #12688.

Review information

Test scope: head 4e8afe85, merge base 7b336b1b on quattro. Source reading of the dispatcher, the omarchy-settings PKGBUILD and makepkg, NetworkManager's dispatcher (main and 1.58.1), Linux v7.2 brcmfmac and iw 6.17. Runs in a sandbox with no network and an empty /sys: the PR test, 15 dispatcher mutants, and scenario runs of the production script with sysfs, DMI and /run paths redirected and iw stubbed from the brcmfmac and iw sources. No real hardware, NetworkManager or iw was used. Not established: whether the final script's 5→4 write and 4→5 restore ran on hardware (the PR describes a run on already-repaired hardware), and any Wi-Fi throughput or latency cost of parallel mode, which the issue does not measure.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@omarchybot omarchybot added bug Something isn't working compatibility Make Omarchy work better on everything! labels Sep 27, 2026
@Clowdyffs

Clowdyffs commented Sep 27, 2026 •

Copy link
Copy Markdown
Author

Well yeah, "no defect found in the normal dispatcher path" still isn't a useful lead here. The question behind this patch is how the BCM4350 actually behaves with 2.4 GHz Wi-Fi and Bluetooth active. Code following the expected path doesn't establish that; the MacBookPro14,1 measurements below are the relevant evidence.

The ownership finding was valid. I independently reproduced it, and the update fixes it. Calling the whole review "read only" was too broad, since you did run sandbox tests.

I still think this could've been a much shorter, more useful review. For a hardware-specific patch, please test on the hardware where possible. For a sandbox bug report, include the runnable reproducer and output so the result can be checked directly. A long description of the testing isn't a substitute for sharing it. Lead with the actual defect and evidence, please.

@Clowdyffs

Copy link
Copy Markdown
Author

Here are the hardware measurements from the September 26 test on MacBookPro14,1, BCM4350 rev 5, firmware 7.35.180.133 / 01-c45b39d6, linux-omarchy 7.2.5-3, AirPods Pro 3 / AAC 48 kHz. These are from the actual machine's HCI capture.

During continuous music playback, only btc_mode changed 5 → 4 → 5. Wi-Fi stayed connected on 2.4 GHz; codec and volume were unchanged, and Bluetooth discovery was off.

Mode / load Analyzed window Audio packets/s HCI completion median / p95 RTP sequence-gap events
5, baseline 4.90 s 15.91 481 / 616 ms 37
4, Wi-Fi idle 8.90 s 46.97 32 / 65 ms 0
4, Wi-Fi download 7.93 s 46.88 35 / 73 ms 0
4, after download 8.90 s 46.83 33 / 70 ms 0
5, restored 4.91 s 33.82 236 / 426 ms 23

Expected cadence: 46.875 packets/s. The three mode-4 windows contain 1,207 packets, with no sequence gaps within any window. Playback reported Playing in 60/60 samples; 0/306 analyzed PCM blocks before Bluetooth encoding were silent. Listening matched the capture: steady music in mode 4, cutouts returning after restoring 5.

The concurrent download transferred 8,861,121 bytes in 9.022 s, averaging 982,142 bytes/s. That establishes working Wi-Fi under this load; it does not measure parallel mode's throughput or latency cost against mode 5.

Windows exclude the first 1 s and last 0.1 s of each phase. Completion delays use FIFO matching of host ACL submissions to controller completion events, accounting for eight initially outstanding packets; they are not end-to-end audio latency or measurements of RF packet loss.

The 5→4→5 transitions were tested on hardware. The final PR entrypoint was separately exercised with mode 4 already active. These results support the firmware-policy change; they do not validate the separate stale-ownership/rebind case raised above.

@llstrk

llstrk commented Sep 28, 2026

Copy link
Copy Markdown

Thanks for the feedback. I agree that the way the review is structured was bad in this case and it has grown way too long.

I've stopped the current run to improve it.

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 786e1ffc800075fe8784323ecfe9fe8b105fd9ce against quattro. Nothing found that would hurt a machine other than the target. Whether the fix works on the target can't be checked here.

What ran, on a disposable Omarchy VM (QEMU, not a Mac):

  • test/shell.d/bcm4350-coexistence-test.sh: all 9 groups pass.
  • ./test/cli: one failure, vscode generated theme references current theme file. The same failure happens on the merge base 7b336b1b, so this change didn't cause it.
  • I installed the dispatcher root-owned in /etc/NetworkManager/dispatcher.d/ and brought the connection up again. The script left at the DMI check without starting Python and the network stayed connected. That is the path every Omarchy machine except a MacBookPro14,1 will take.

What was only read: the vendor command packing and reply parsing. Codex Medium, the second reviewer, checked them against brcmfmac's vendor.h/vendor.c and iw's recvbin and found them correct. It also found no way for the interface name or the paths to be abused when the script runs as root.

The evidence for the fix itself is your hardware comparison in #13297 and above. It has not been reproduced independently, and no worker can reproduce it. You opened the issue as well as this pull request, so the confirmation that would mark this verified needs to come from someone else: a maintainer, or another MacBookPro14,1 owner, testing this exact commit.

One narrow case, left to you rather than pushed. At etc/NetworkManager/dispatcher.d/90-omarchy-bcm4350-coexistence:89-95, the marker is written before the btc_mode=4 write, and it stays even when the readback shows the firmware is still at 5. If another tool then sets 4 on the same interface and the link leaves 2.4 GHz, the dispatcher writes 5 over a policy it never set. The ifindex check doesn't help here because the interface never changed. The fix would be to remove the marker when the readback definitely shows the write did not land, and keep it only when the outcome is unknown (an exception from iw). Your test asserts the current behaviour on purpose (ignore_write), so I haven't changed it. Nothing in Omarchy writes btc_mode, and the result would be one return to the firmware default, so this is low severity. Codex Medium found this case; I checked it against the source.

For the maintainer:

  • How it ships. Other Mac quirks under install/hardware/apple/ are installed only on machines that match. This one ships to every machine through omarchy-settings and checks the hardware at run time. That avoids a migration and means package updates also remove it, but it is a different pattern.
  • Scope. The smallest fix is a dispatcher that sets btc_mode=4 on 2.4 GHz for this machine. About 30 dispatcher lines, most of the test and the three-paragraph docs/file-layout.md section exist to restore hybrid mode off 2.4 GHz, because parallel mode was only tested on 2.4 GHz.
  • Kernel. @kwilczynski's kernel suggestion in MacBookPro14,1: BCM4350 hybrid coexistence starves Bluetooth audio on 2.4 GHz Wi-Fi #13297 is still open, and it may decide whether a workaround is needed at all.

Related: #7644 also targets Broadcom Bluetooth audio dropouts on Macs, through the codec cap and btusb autosuspend. This machine's Bluetooth is on UART, and #7644 touches none of these files, so the two don't compete. Nothing else open changes btc_mode.

Reviewed by Claude Opus 5.5 and Codex Medium. Codex's agreement on the packing and safety points was given with this review's reasoning available to it, so it isn't guaranteed to be independent. It found the narrow case above on its own. Waiting on the maintainer.

@Clowdyffs

Copy link
Copy Markdown
Author

Reproduced and fixed the ownership case. On 786e1ffc, an ignored 5→4 write leaves mode 5 and its marker; another tool then selects 4 on the same interface, and a 5 GHz event wrongly writes 5. The correction clears ownership after definite nonparallel readback and preserves the other tool's 4. Lost acknowledgement or unavailable readback retains recovery state because the outcome is unknown.

bash test/shell.d/bcm4350-coexistence-test.sh passes all 11 groups, covering that sequence, successful retry, lost acknowledgement/readback, and failed restoration recovery. The new regression fails against the published dispatcher. Bash/Python syntax and diff whitespace checks pass.

These tests use device/firmware fixtures, without live resets or policy changes. The existing 5→4→5 hardware comparison supports the policy; independent testing of this revision on another MacBookPro14,1 remains outstanding. Hardware/firmware guards and off-2.4 GHz restoration are unchanged.

The kernel suggested in #13297 remains untested here; the author's September 28 question about its changes and intended comparison is unanswered.

— GPT-6.1 Sol high

@greptile-apps

greptile-apps Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[High risk] Adds network dispatcher script that controls Bluetooth firmware.

Fix ownership across interface replacement during a hook run before merging.

Findings

  1. P1 Recovery loses override ownership ▶

Summary

Adds a narrowly scoped NetworkManager hook that switches BCM4350 coexistence from mode 5 to mode 4 on 2.4 GHz and restores its recorded override off that band.

  • Limits writes by Mac model, chip revision, driver, firmware, and current policy.
  • Adds controlled tests and documents installation and hardware limits.
  • The focused tests, Bash syntax check, and diff whitespace check passed.
  • Interface replacement during a hook run can still separate the firmware change from its ownership record.
  • Clowdyffs explicitly states that roaming is checked at the next dispatcher event and that reboot/resume and microphone calls remain untested. Failed restoration retaining ownership for a later retry is intentional.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Supported network event] --> B{Matching hardware and firmware?}
  B -->|No| Z[Exit without firmware write]
  B -->|Yes| C[Check interface index and live band]
  C --> D{2.4 GHz and mode 5?}
  D -->|Yes| E[Record interface index]
  E --> F[Set mode 4 and check readback]
  D -->|No| G{Off 2.4 GHz with owned override?}
  G -->|Yes| H[Restore mode 5 if current mode is 4]
  H --> I[Remove ownership record]
  G -->|No| Z
Loading

Reviews (1) · Last reviewed commit: "Release BCM4350 policy ownership after a..."

Comment on lines +92 to +93
state.write_text(ifindex + '\n')
iovar(iface, 'btc_mode', 4)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Recovery loses override ownership

ifindex is checked before the firmware queries, but every iw command uses the interface name. If driver recovery replaces wlan0 during those queries, this branch can set the new interface to mode 4 while recording the old interface's index. The next event deletes that marker, leaving parallel mode active without permission to restore it on 5 GHz or disconnect.

Use the saved interface index for firmware commands, or stop when the interface changes. Add a test that replaces the interface during a query.

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

Labels

bug Something isn't working compatibility Make Omarchy work better on everything!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MacBookPro14,1: BCM4350 hybrid coexistence starves Bluetooth audio on 2.4 GHz Wi-Fi

3 participants