All posts

Simulate a Full Wi-Fi Network in Software with mac80211_hwsim

Can we run a full Wi‑Fi network: AP, client, association, monitor mode and live frame capture in Wireshark with zero Wi‑Fi radios, no antennas, no regulatory limits and no hardware constraints? Yes. It's possible with mac80211_hwsim, a kernel module that simulates 802.11 radios entirely in software.

From the kernel's perspective, it's just another WLAN driver. mac80211 has no idea there's no real radio behind it. It plugs in at the exact same layer a real Wi‑Fi chipset driver would, so everything above it: the MAC stack, cfg80211, nl80211, hostapd and wpa_supplicant behaves identically to real hardware.

Diagram showing mac80211_hwsim plugging into the Linux Wi-Fi stack at the same layer as a real chipset driver, below mac80211, cfg80211 and nl80211

How it actually works

It tracks the current channel of each virtual radio and copies every transmitted frame to all other radios on that same channel. When radio A transmits:

  1. mac80211 hands the frame to hwsim's tx() callback.
  2. hwsim checks radio A's current channel.
  3. It copies the frame into the RX path (ieee80211_rx_irqsafe()) of every other enabled radio on that channel.
  4. Those radios' mac80211 instances process it as a normally received frame.

hwsim also uses software encryption in mac80211, so frames are genuinely encrypted.

Try it

Simulate 2 radios. This creates phy0/wlan0 and phy1/wlan1:

sudo modprobe mac80211_hwsim radios=2

Start the AP on wlan0:

sudo hostapd hostapd.conf

Start the client on wlan1:

sudo wpa_supplicant -iwlan1 -c wpa_supplicant.conf

Add monitor mode on the AP's phy and open Wireshark on mon0:

sudo iw phy phy0 interface add mon0 type monitor
sudo ip link set mon0 up

When to use it

It's great for learning Wi‑Fi protocols hands-on, and for testing Wi‑Fi kernel modules, hostapd and wpa_supplicant. Keep in mind it is not intended to emulate real-world RF/PHY behavior, there's no fading, no noise, no path loss. It's the protocol stack that's real here, not the radio.

— Gopi Raga