Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions install/hardware/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ run_logged "$OMARCHY_INSTALL/hardware/framework/qmk-hid.sh"
run_logged "$OMARCHY_INSTALL/hardware/apple/fix-spi-keyboard.sh"
run_logged "$OMARCHY_INSTALL/hardware/apple/fix-suspend-nvme.sh"
run_logged "$OMARCHY_INSTALL/hardware/apple/fix-t2.sh"
run_logged "$OMARCHY_INSTALL/hardware/apple/fix-brcmfmac-supplicant.sh"

run_logged "$OMARCHY_INSTALL/hardware/lenovo/fix-yoga-pro7-bass-speakers.sh"

Expand Down
27 changes: 27 additions & 0 deletions install/hardware/apple/fix-brcmfmac-supplicant.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Apple Macs ship Broadcom Wi-Fi driven by brcmfmac, whose firmware runs the WPA
# handshake itself. On these parts that offload fails against an access point in
# WPA2/WPA3 transition mode: the client associates, the four-way handshake never
# completes, and NetworkManager reports the password as wrong.
#
# feature_disable turns off the firmware supplicant (FWSUP, 0x2000) and firmware
# authenticator (FWAUTH, 0x80000), handing the handshake back to wpa_supplicant
# in software.
#
# This quirk already shipped for T2 Macs. The bug is in the Broadcom firmware,
# not in the T2 bridge, so Macs without one need it just as much: a
# MacBookPro11,4 with BCM43602 (14e4:43ba) and 2015 firmware fails exactly this
# way, and connects once the offload is disabled.
sys_vendor="$(cat /sys/class/dmi/id/sys_vendor 2>/dev/null || true)"

if [[ $sys_vendor == "Apple Inc." || $sys_vendor == "Apple Computer, Inc." ]] &&
lspci -nn | grep -qiE 'network controller.*\[14e4:'; then
echo "Detected a Mac with Broadcom Wi-Fi; running the WPA handshake in software"

mkdir -p /etc/modprobe.d
cat > /etc/modprobe.d/brcmfmac.conf <<'EOF'
# Broadcom's firmware supplicant and authenticator fail the WPA four-way
# handshake on Apple hardware, which surfaces as a rejected password. Disable
# both so wpa_supplicant performs the handshake instead.
options brcmfmac feature_disable=0x82000
EOF
Comment on lines +28 to +34
fi
6 changes: 0 additions & 6 deletions install/hardware/apple/fix-t2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ if lspci -nn | grep "106b:180[12]" >/dev/null; then
echo "MODULES+=(t2bce_vhci usbhid hid_apple hid_generic xhci_pci xhci_hcd)" > \
/etc/mkinitcpio.conf.d/apple-t2.conf

mkdir -p /etc/modprobe.d
cat > /etc/modprobe.d/brcmfmac.conf <<'EOF'
# Fix for T2 MacBook WiFi connectivity issues
options brcmfmac feature_disable=0x82000
EOF

mkdir -p /etc/limine-entry-tool.d
cat > /etc/limine-entry-tool.d/t2-mac.conf <<'EOF'
# Generated by Omarchy installer for T2 Mac support
Expand Down
88 changes: 88 additions & 0 deletions test/shell.d/brcmfmac-supplicant-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

leaf="$ROOT/install/hardware/apple/fix-brcmfmac-supplicant.sh"
fix_t2="$ROOT/install/hardware/apple/fix-t2.sh"
all="$ROOT/install/hardware/all.sh"

grep -q 'apple/fix-brcmfmac-supplicant.sh' "$all" ||
fail "the brcmfmac quirk runs during hardware setup"

# Two leaves writing one config means the later one silently wins, and which is
# later is a detail of all.sh nobody would think to check.
! grep -q 'brcmfmac' "$fix_t2" ||
fail "only one leaf owns /etc/modprobe.d/brcmfmac.conf"
pass "the brcmfmac quirk has a single owner and runs during setup"

test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT

stub_bin="$test_tmp/bin"
mkdir -p "$stub_bin" "$test_tmp/dmi"

cat >"$stub_bin/lspci" <<'SH'
#!/bin/bash

# Chatty like real lspci: keep writing well past the pipe buffer after the match,
# so a grep -q consumer would kill this stub with SIGPIPE and pipefail would read
# that as "no such hardware" (#6608).
[[ -n ${STUB_WIFI_LINE:-} ]] && echo "$STUB_WIFI_LINE"
for _ in {1..4096}; do
echo '02:00.0 Host bridge [0600]: Filler Device [ffff:0000]'
done
SH
chmod +x "$stub_bin"/*

# The leaf reads the vendor from an absolute path, so point it at a fixture by
# running with a fake root on PATH-independent state.
run_leaf() {
local vendor="$1" wifi="${2:-}"
rm -rf "$test_tmp/etc"
mkdir -p "$test_tmp/etc"
printf '%s' "$vendor" >"$test_tmp/dmi/sys_vendor"

# Redirect both absolute paths the leaf touches into the sandbox.
local script="$test_tmp/leaf.sh"
sed -e "s|/sys/class/dmi/id/sys_vendor|$test_tmp/dmi/sys_vendor|g" \
-e "s|/etc/modprobe.d|$test_tmp/etc/modprobe.d|g" \
"$leaf" >"$script"

STUB_WIFI_LINE="$wifi" PATH="$stub_bin:$PATH" \
bash -eE -c 'source "$1"' bash "$script" </dev/null
}

broadcom='03:00.0 Network controller [0280]: Broadcom Inc. and subsidiaries BCM43602 802.11ac Wireless LAN SoC [14e4:43ba]'
intel_wifi='03:00.0 Network controller [0280]: Intel Corporation Wi-Fi 6 AX200 [8086:2723]'

# The machine this was written for: a pre-T2 Mac, which the T2 gate never covered.
run_leaf "Apple Inc." "$broadcom" >/dev/null
grep -q 'feature_disable=0x82000' "$test_tmp/etc/modprobe.d/brcmfmac.conf" 2>/dev/null ||
fail "a Mac with Broadcom Wi-Fi gets the quirk" "$(ls -R "$test_tmp/etc" 2>&1)"
pass "a pre-T2 Mac with Broadcom Wi-Fi gets the quirk"

# Older Macs report the vendor differently.
run_leaf "Apple Computer, Inc." "$broadcom" >/dev/null
[[ -f $test_tmp/etc/modprobe.d/brcmfmac.conf ]] ||
fail "the older Apple vendor string is recognized"
pass "the older Apple vendor string is recognized"

# The quirk works around Broadcom firmware, so it has no business on a Mac whose
# Wi-Fi is something else.
run_leaf "Apple Inc." "$intel_wifi" >/dev/null
[[ ! -f $test_tmp/etc/modprobe.d/brcmfmac.conf ]] ||
fail "a Mac without Broadcom Wi-Fi is left alone"
pass "a Mac without Broadcom Wi-Fi is left alone"

# Plenty of non-Apple hardware uses brcmfmac and does not share this bug.
run_leaf "LENOVO" "$broadcom" >/dev/null
[[ ! -f $test_tmp/etc/modprobe.d/brcmfmac.conf ]] ||
fail "non-Apple hardware with a Broadcom part is left alone"
pass "non-Apple hardware is left alone"

run_leaf "Apple Inc." "" >/dev/null
[[ ! -f $test_tmp/etc/modprobe.d/brcmfmac.conf ]] ||
fail "a Mac with no wireless device is left alone"
pass "a Mac with no wireless device is left alone"