Moving from hardware analysis to writing a mainline Linux mac80211 wireless driver is where reverse engineering turns into systems engineering. A clean-room GPL-2.0 driver never copies decompiled vendor control flow: instead, it wires documented hardware state transitions into Linux's native bcma bus layer, struct ieee80211_ops SoftMAC callbacks, 64-bit DMA descriptor rings, and hardened request_firmware() binary loaders.
5-Part IoT Router Firmware & Linux Wi-Fi Driver Reverse Engineering Curriculum
- Part 1: Dissecting NETGEAR
.chk, BroadcomTRX&SquashFSContainers by Hand - Part 2: Triage of ARM
ET_RELKernel Modules,.rel.rodataTables & D11 Microcode - Part 3: Black-Box
BAR0Page-Fault MMIO Traps & Differential NVRAM Fuzzing on ARMv7 - Part 4 (You Are Here): Clean-Room Linux 6.12
mac80211, BCMA Windowing &B43DFirmware Loaders - Part 5: 2.6.36-to-6.12
sk_buffABI Interposition vs. Native OpenWrt 25.12 Packaging
hostapd down to drivers/bcma. Right: Defensive ring-0 validation of external B43D firmware data blobs.1. Binding the Right Bus: bcma_driver vs. Raw pci_driver
In Part 3 we saw why binding a raw pci_driver directly to 14e4:43a0 fails unless you manually rewrite PCI config 0x80 and sequence AXI agent wrapper clocks. Mainline Linux 6.12 already solves all of that inside drivers/bcma/!
When OpenWrt 25.12 boots on a BCM4709A0 router, bcma-pci-bridge claims both BCM4360 PCIe endpoints, walks the Core Enumeration ROM at 0x18107000, extracts SROM rev 11 board calibration parameters into bus->sprom (including per-chain fem.ghz2 / fem.ghz5 and TX power curves via OpenWrt's platform NVRAM hook), and registers each internal IP core on the kernel's bcma bus. Therefore, your wireless driver binds to core BCMA_CORE_80211 (0x812), revision 42 (0x2A):
static const struct bcma_device_id b43_ac_bcma_tbl[] = {
BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_80211, 0x2A, BCMA_ANY_CLASS),
{},
};
MODULE_DEVICE_TABLE(bcma, b43_ac_bcma_tbl);
Inside your .probe(struct bcma_device *core) callback, calling bcma_core_enable(core, phy_ctl_flags) cleanly asserts reset, enables SICF clocks (including the 80/160 MHz DAC/PHY clock mode required by AC-PHY), waits for clock stabilization, and maps bcma_read16(core, B43_MMIO_PHY_VER) straight onto D11 core 0x18001000 โ immediately returning 0x0B01!
2. The mac80211 SoftMAC Lifecycle & Staged Bring-Up
Nobody writes a full 3x3:3 802.11ac AP+STA driver in a single weekend. Every successful mainline wireless driver brings up hardware in four strictly verifiable milestones across struct ieee80211_ops:
| Bring-Up Stage | Key ieee80211_ops & Subsystems |
Observable Hardware Proof on Router |
|---|---|---|
| Stage 1: Bus, Clocks & Microcode | ieee80211_alloc_hw(), .start, .stop, ucode42.fw upload |
D11 PSM boots and writes microcode revision 784.2 into SHM offset 0x0000; B43_IRQ_MAC_SUSPENDED fires cleanly |
| Stage 2: Passive 2.4 / 5 GHz RX | .add_interface, .config (Radio 2069 PLL tune), .configure_filter, 64-bit RX DMA ring |
iw dev wlan0 scan or monitor-mode tcpdump captures valid live 802.11 beacon frames with accurate RSSI & FCS |
| Stage 3: Unencrypted & WPA2/3 TX | .tx, 64-bit TX DMA ring + b43_txhdr PLCP header, TX status IRQ -> ieee80211_tx_status_irqsafe() |
Station associates via wpa_supplicant / hostapd; bidirectional ICMP & TCP traffic passes |
| Stage 4: VHT80 & Closed-Loop TSSI | .bss_info_changed, .ampdu_action, periodic PHY calibration workqueue |
Sustained 3x3 VHT80 MCS9 throughput without thermal TX power drift or DMA ring stalls |
Notice why Stage 2 (Passive RX) is always separated from Stage 3 (Active TX): passive reception exercises 85% of your driver's complexity (core reset, microcode boot, Radio 2069 synthesizer tuning, AC-PHY init tables, eLNA/FEM switch paths, 64-bit DMA ring descriptors, and IRQ handling) with zero risk of out-of-band RF emissions while you validate your calibration math!
3. 64-Bit DMA Rings on D11 Core Rev 42
Modern Broadcom D11 cores (rev >= 42) use 64-bit little-endian DMA engines located at BAR0 offsets 0x0200, 0x0240, 0x0280, and so on. Each ring entry is a 16-byte hardware descriptor allocated in coherent memory (dma_alloc_coherent()):
struct b43_dmadesc64 {
__le32 control0; /* EOT (bit 28), IOC (bit 29), EOF (bit 30), SOF (bit 31) */
__le32 control1; /* Buffer byte count in bits [14:0] */
__le32 addr_low; /* Streaming DMA bus address [31:0] */
__le32 addr_high; /* Streaming DMA bus address [63:32] */
} __packed;
Two ring-0 DMA bugs bite nearly every new driver author on Cortex-A9:
- Missing Cache Sync Before Ring Kick: Unlike coherent descriptor rings, packet
sk_buffpayloads are mapped with streaming DMA (dma_map_single(..., DMA_TO_DEVICE / DMA_FROM_DEVICE)). Because Cortex-A9 PCIe transactions are not hardware-cache-coherent on Northstar without explicit maintenance, touchingskb->dataon the CPU afterdma_map_single()withoutdma_sync_single_for_cpu()delivers stale bytes or corrupts RX frames. - Forgetting the End-of-Table (
EOT) Bit: Bit 28 ofcontrol0MUST remain set on the final slot of the descriptor array so the hardware DMA engine wraps back to slot0instead of walking off the end of physical DRAM!
4. Designing & Hardening a Clean-Room B43D Firmware Data Container
Rather than baking thousands of lines of raw calibration integers into kernel C files, modern clean-room efforts load structured Type-Length-Value (TLV) table containers via Linux's request_firmware() API (for example, a B43D binary container carrying chip/radio tables and optional per-board overrides).
Whenever a ring-0 kernel driver parses bytes read from a filesystem buffer, you must treat that buffer as untrusted input. A single unchecked 32-bit multiplication like uint32_t bytes = elem_count * 4; wraps around to 4 when a malformed blob supplies elem_count = 0x40000001, bypassing a naive offset + bytes <= fw->size check and triggering an out-of-bounds kernel read panic during table upload! Every production firmware validator enforces six defensive invariants:
- Exact magic (
"B43D"=0x44333442), ABI version, silicon/PHY/radio tuple, andtotal_len == size. - Cryptographic or IEEE 802.3 CRC-32 verification before trusting any section offset.
- Strict 4-byte alignment on every
payload_offand check thatpayload_off >= header_end. - 64-bit widened arithmetic (
uint64_t byte_len = (uint64_t)elem_count * elem_bytes;) prior to checkingpayload_off + byte_len <= size. - Zero reserved padding bytes (and zeroed
board_tagon generic chip-level blobs) so future ABI flags cannot be silently misinterpreted. - Pairwise verification that no two section descriptors share a duplicate
sect_idor overlap in[payload_off, payload_off + byte_len).
5. Your Turn โ Hands-On Lab 04 Checkpoints (Zero Spoilers)
Open labs/04-clean-room-mac80211-driver.md and inspect labs/starter/kshim.h + labs/starter/lab04_b43d_loader_skeleton.c (as well as the intentional architectural bug waiting for you in driver-bcm4360/b43_acphy_main.c):
- Audit
driver-bcm4360/b43_acphy_main.c: Spot why its currentpci_driverprobe reads the wrong BCMA core atBAR0 + 0x03E0and design its migration tostruct bcma_driver. - Implement
b43d_validate_blob()in C: Write the complete ring-0 bounds, CRC-32, alignment, 64-bit overflow, duplicate-ID, and interval-overlap validator inlabs/starter/lab04_b43d_loader_skeleton.cso it compiles with zero warnings undergcc -O2 -Wall -Wextra -Werror. - Fuzz-Test via the Verifier: Run
python3 labs/verify_labs.py --lab 4to compile your C parser againstkshim.hand test it against both validB43Dimages and six hostile malformed/overflowing fuzz vectors in userspace!
Continue to Part 5 (Series Finale)
What if someone asks whether you can force-load the legacy 2.6.36 binary blob directly onto Linux 6.12 using binary symbol shims instead of writing a native mac80211 driver? Continue to Part 5: Linux 2.6.36-to-6.12 sk_buff ABI Interposition vs. Native OpenWrt 25.12 Packaging to build a working objcopy + shadow-sk_buff shim and compare both engineering paths head-to-head.
