Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/file-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ logo.{txt,svg}, icon.{txt,png} ──► omarchy-settings /usr/share/omarchy

The hardware-conditional `force-igpu` and `keyboard-backlight` sources also live under `default/systemd/system-sleep/`, but their setup commands publish root-owned copies only on machines that need them; they are not installed by `omarchy-settings`.

### BCM4350 Bluetooth coexistence

`etc/NetworkManager/dispatcher.d/90-omarchy-bcm4350-coexistence` ships executable through `omarchy-settings`, so package updates also update or retire the quirk. It selects parallel coexistence for MacBookPro14,1 with BCM4350 rev 5 and firmware `7.35.180.133` / `01-c45b39d6` on 2.4 GHz; [the controlled comparison](https://github.com/omacom/omarchy/issues/13297) documents the audio failure under the default hybrid policy. Other hardware, firmware versions, and nondefault policies are preserved.

The dispatcher runs on network activation, reapply, DHCP changes, and disconnect. It writes only when the mode needs changing; repeated events with parallel mode active perform no firmware write. It restores hybrid mode when the link leaves 2.4 GHz only if `/run/omarchy-bcm4350-coexistence/` records ownership for the current interface's `ifindex`. Device removal and re-registration discard old ownership, including markers from the previous empty format. New and existing installations pick it up at their next network activation; no copied installer artifact or migration is needed. Roaming within an active connection is checked at the next dispatcher event, not continuously. Reboot/resume and headset microphone calls have not been validated on hardware.

A boot-only action can lose its effect when brcmfmac reloads firmware during recovery or a cold resume. The event hook handles subsequent network activation and keeps the override limited to the tested 2.4 GHz case. Changing board NVRAM or leaving parallel mode enabled on every band requires separate hardware validation.

### Why `etc-overrides/` exists

Some files under `/etc/` (`.bashrc` in `/etc/skel`, `nsswitch.conf`,
Expand Down
124 changes: 124 additions & 0 deletions etc/NetworkManager/dispatcher.d/90-omarchy-bcm4350-coexistence
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#!/bin/bash

# The hybrid policy starves A2DP on this Mac's BCM4350 with 2.4 GHz Wi-Fi.
# Measurements and scope: https://github.com/omacom/omarchy/issues/13297
# Keep other machines out of the vendor-command path entirely.
case "${2:-}" in
up|reapply|dhcp4-change|dhcp6-change|down) ;;
*) exit 0 ;;
esac
[[ -r /sys/class/dmi/id/product_name ]] || exit 0
[[ $(</sys/class/dmi/id/product_name) == "MacBookPro14,1" ]] || exit 0

/usr/bin/python3 -I - "$@" <<'PY'
from pathlib import Path
import re
import struct
import subprocess
import sys

STATE = Path('/run/omarchy-bcm4350-coexistence')


def run(*args, data=None):
return subprocess.run(args, input=data, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, check=True, timeout=2).stdout


def iovar(iface, name, value=None):
# brcmfmac's BRCMF_VNDR_CMDS_DCMD: native 20-byte header, LE firmware values.
payload = name.encode('ascii') + b'\0'
if value is not None:
payload += struct.pack('<I', value)
request = struct.pack('=IiIII', 262 if value is None else 263,
256 if value is None else len(payload),
20, int(value is not None), 0) + payload
response = run('/usr/bin/iw', 'dev', iface, 'vendor', 'recvbin',
'0x001018', '0x1', '-', data=request)
if value is not None:
return
# iw returns aligned netlink attributes: DATA=2, LEN=1.
result = bytearray()
offset = 0
while offset < len(response):
length, kind = struct.unpack_from('=HH', response, offset)
if length < 4 or offset + length > len(response):
raise ValueError('invalid vendor response')
if kind & 0x3fff == 2:
result.extend(response[offset + 4:offset + length])
offset += (length + 3) & ~3
if not result:
raise ValueError('empty vendor response')
return bytes(result)


def mode(iface):
return struct.unpack_from('<I', iovar(iface, 'btc_mode'))[0]


def apply(iface):
interface = Path('/sys/class/net') / iface
state = STATE / iface
try:
ifindex = (interface / 'ifindex').read_text().strip()
except FileNotFoundError:
state.unlink(missing_ok=True)
return
# A re-probe reuses the name but creates a new interface. An old marker
# (including the previous empty format) does not own that interface's policy.
if state.exists() and state.read_text().strip() != ifindex:
state.unlink()
device = interface / 'device'
if not (device / 'vendor').is_file():
return
if ((device / 'vendor').read_text().strip() != '0x14e4'
or (device / 'device').read_text().strip() != '0x43a3'
or (device / 'revision').read_text().strip() != '0x05'
or (device / 'driver').resolve().name != 'brcmfmac'):
return
version = iovar(iface, 'ver').split(b'\0', 1)[0]
if not re.search(rb'\bversion 7\.35\.180\.133\b.*\bFWID:? 01-c45b39d6\b', version):
return

# Dispatcher events can be stale by the time they run; inspect the live link.
link = run('/usr/bin/iw', 'dev', iface, 'link').decode(errors='replace')
frequency = re.search(r'^\s*freq:\s*(\d+)', link, re.MULTILINE)
on_2ghz = frequency is not None and 2400 <= int(frequency[1]) <= 2500
current = mode(iface)

if on_2ghz and current == 5:
# Record ownership before writing so a failed readback remains recoverable.
STATE.mkdir(mode=0o755, exist_ok=True)
state.write_text(ifindex + '\n')
iovar(iface, 'btc_mode', 4)
Comment on lines +92 to +93

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.

if mode(iface) != 4:
# A definite nonparallel readback is not an override we own. Exceptions
# leave the marker intact because the write's outcome is still unknown.
state.unlink()
raise ValueError('parallel policy readback failed')
print('BCM4350: enabled parallel coexistence on 2.4 GHz', file=sys.stderr)
elif not on_2ghz and state.exists():
# Restore only our recorded override; leave a different current policy alone.
if current == 4:
iovar(iface, 'btc_mode', 5)
if mode(iface) != 5:
raise ValueError('hybrid policy readback failed')
state.unlink()
elif current != 4:
state.unlink(missing_ok=True)


def main(argv):
if (len(argv) != 3
or not re.fullmatch(r'[A-Za-z0-9][A-Za-z0-9_.:-]{0,14}', argv[1])):
return
try:
apply(argv[1])
except (OSError, ValueError, struct.error, subprocess.SubprocessError) as error:
# Device removal or unavailable firmware must not fail network activation.
print(f'BCM4350: coexistence quirk skipped ({type(error).__name__})', file=sys.stderr)


if __name__ == '__main__':
main(sys.argv)
PY
Loading