Skip to content

Commit 9aa0e34

Browse files
committed
Add simulated band steering post
1 parent 830ef6a commit 9aa0e34

File tree

3 files changed

+245
-0
lines changed

3 files changed

+245
-0
lines changed
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
+++
2+
title = "Simulated WiFi Band Steering"
3+
date = "2025-11-01"
4+
description = ""
5+
path = "blog/simulated-band-steering"
6+
7+
#[taxonomies]
8+
#tags = ["linux", "wifi"]
9+
+++
10+
11+
## Overview
12+
13+
In this post, I'll provide some background on and demonstrate how to simulate WiFi band steering. We'll use open source
14+
Linux tools that are used in commercial WiFi products. _No physical WiFi radios are required!_
15+
16+
If you'd like to replicate this yourself, you'll need a Linux system with `sudo` access, kernel support for the `mac80211_hwsim` driver
17+
(which is generally the case for most Linux distributions), and `hostapd` and `wpa_supplicant` installed. These tools will permit
18+
complete WiFi simulation in software. However, the same setup will also work with real WiFi radios. This can also be run within
19+
a container or virtual machine.
20+
21+
This setup will require some experience using Linux, Wireshark, and WiFi. There are plenty of great resources out there.
22+
I maintain a reference of Linux commands I use often [here](@/blog/2023-12-linux-cmds.md). Additionally, if you'd like to (responsibly) do real
23+
WiFi packet capture with Wireshark, I wrote a guide which is available [here](@/blog/2023-10-wifi-packet-capture.md).
24+
25+
## Background
26+
27+
Before we dive in, I'd like to first cover some background WiFi information, especially as it relates to band steering. If you're familiar already, skip to the next section.
28+
29+
In WiFi, clients select and connect to the WiFi access point (AP) BSSID they want. Each client operates slightly differently, but metrics like channel utilization and estimated throughput strongly influence this decision. As a client operates and possibly moves around in its environment, conditions will change. The client may decide to shift to another channel on the same AP (different BSSID), it may roam to another AP, or it may do something else entirely! These decisions are ultimately left up to the client, not the AP.
30+
31+
Given this, an AP is left with limited options to influence the client decisions. An AP can reject the client's authentication/association request or send a deauthentication/disassociation. However, these methods are heavy handed and may result in poor user experience.
32+
33+
Several amendments to the WiFi 802.11 standard serve to address this and to improve user experience generally. Amendments 802.11k (neighbor reports), 802.11r (fast transition), and 802.11v (BSS transition management) are a couple widely known examples. For the purposes of this post, we'll focus on 802.11k and 802.11v, which introduce neighbor reports and BSS transition management (BTM), respectively. Both are essential for band steering, whether it be simulated or real-world.
34+
35+
If you'd like to brush up on band steering or the amendments I mentioned, check out my colleague Isaac Konikoff's talk on band steering fails [here](https://www.youtube.com/watch?v=X5ffNbd5Duw) and this Cisco 802.11v explainer available [here](https://web.archive.org/web/20230815035221/https://www.cisco.com/c/en/us/td/docs/wireless/controller/9800/config-guide/b_wl_16_10_cg/802-11v.pdf). For more in-depth coverage, check out my colleague Sitarama Penumetsa's lecture [here](https://youtu.be/BiktVCtMGnk?si=c6LDYNyg1qJ_DqQ8&t=2002) from his WiFi fundamentals course.
36+
37+
With this all in mind, we're ready to setup for testing!
38+
39+
## Test Setup
40+
41+
In order to simulate band steering, we must first configure our test environment. While this same configuration is possible with
42+
real radios, we'll instead use the `mac80211_hwsim` Linux driver to simulate this testing entirely in software.
43+
44+
### Recommendations
45+
46+
To make your life easier, I recommend the following:
47+
48+
- **Use three terminals**
49+
50+
- One terminal each for AP, client, and configuration CLI
51+
52+
- This will permit reading logs while we setup and run the test
53+
54+
- Now may be a good time to learn how to use `tmux` or `screen`
55+
56+
- It's possible to setup this test with `wpa_supplicant` and `hostapd` daemonized (`-B` argument), but I would only recommend it for advanced users
57+
58+
- **Disconnect from your WiFi (if present) while running this**
59+
60+
- When running with verbose logging, `wpa_supplicant` and `hostapd` will output information on any changes to any interface
61+
on the system. Verbose logs can especially become busy on a normal system, as they will log periodic scans run by
62+
your networking daemon for any existing WiFi interface.
63+
64+
- Make sure **not** to run `nmcli radio wifi off`, as this will enable rfkill which soft blocks WiFi on all interfaces
65+
(including the `mac80211_hwsim` ones)
66+
67+
### Instructions
68+
69+
**NOTE:** Many commands in this post will require root permissions (e.g. run with `sudo`), including `hostapd`, `wpa_supplicant`, `modprobe`.
70+
71+
1. **Load the `mac80211_hwsim` kernel module (driver)**
72+
73+
```Bash
74+
# Three simulated radios are needed
75+
# 1. Client (STA)
76+
# 2. AP 2.4 GHz BSSID
77+
# 3. AP 5 GHz BSSID
78+
modprobe mac80211_hwsim radios=3 support_p2p_device=0
79+
```
80+
81+
2. **Identify simulated WiFi interfaces and their MAC addresses**
82+
83+
**Most likely the `mac80211_hwsim` interfaces will be named `wlan0`, `wlan1`, and `wlan2`**. The driver will additionally
84+
create another interface named `hwsim0`, which permits packet capture of simulated WiFi traffic.
85+
86+
To identify the interfaces and corresponding MAC addresses, use the `ip -br addr show` and `ip -br link show` commands.
87+
First check the MAC address. The driver creates the interfaces using the format `02:00:00:00:XX:00`, where the `XX`
88+
matches the simulated radio number, which is easy to identify.
89+
90+
If you're encountering issues or want to know more, check out [this section](#identifying-interfaces-and-macs-cont).
91+
92+
3. **Configure your network daemon to ignore the interfaces**
93+
94+
Practically all modern workstation Linux distributions ship with NetworkManager. If you're using something else, I assume you know
95+
what you're doing or can figure it out...
96+
97+
When using NetworkManager, we must configure it to ignore the new `mac80211_hwsim` interfaces, which you can do with the
98+
following command. We don't need any IP configuration for this testing anyway.
99+
100+
When complete, the interfaces should show as `unmanaged` in the output of `nmcli device status` (or `nmcli device` for short),
101+
as shown below.
102+
103+
```Bash
104+
# Run this for each simulated WiFi interface, substituting in
105+
# your system's interface names for this and subsequent commands
106+
nmcli device set wlan0 managed false
107+
```
108+
109+
4. **Download example `hostapd` and `wpa_supplicant` configs from [here](https://codeberg.org/a-gavin/hostap-confs)**
110+
111+
I recommend using the open (no security) configuration, as this will make packet capture much more simple.
112+
With configurations supporting encryption, packet decryption is possible, but security improvements like 802.11w
113+
and WPA3 make this increasingly difficult (which is good for security!).
114+
115+
```Bash
116+
git clone https://codeberg.org/a-gavin/hostap-confs.git
117+
```
118+
119+
5. **Start the AP interfaces**
120+
121+
```Bash
122+
# Options used are:
123+
# -t: Print timestamps
124+
# -i: Specify interface to run AP with. Can be specified multiple times.
125+
#
126+
# For verbose or very verbose logging, add the '-d' or '-dd' options
127+
hostapd -t -i wlan0 -i wlan1 hostapd_2.4GHz-open.conf hostapd_5GHz-open.conf
128+
```
129+
130+
Assuming no errors appear in the logs, you can verify the AP interface channel/frequency, SSID, and MAC
131+
with the `iw wlan0 info` command.
132+
133+
6. **Enable `mac80211_hwsim` packet capture interface**
134+
135+
This interface is likely named `hwsim0`.
136+
137+
```Bash
138+
ip link set up dev hwsim0
139+
```
140+
141+
7. **Run Wireshark using the `mac80211_hwsim` packet capture interface**
142+
143+
Packet capture requires root permissions. See the Wireshark documentation [here](https://wiki.wireshark.org/capturesetup/captureprivileges#gnulinux-distributions-wireshark-is-installed-using-a-package-manager) for more information on how to enable
144+
this.
145+
146+
8. **Start the client interface**
147+
148+
```Bash
149+
# Similar options and requirements as 'hostapd'
150+
# The '-c' option required to specify the config file
151+
wpa_supplicant -t -i wlan2 -c supplicant_open.conf
152+
```
153+
154+
9. **Wait for client to connect**
155+
156+
As the client connects, you should see start to see the simulated WiFi traffic in Wireshark. The simulated client will
157+
connect through the normal WiFi client connection process (use the `wlan.fc.type_subtype != 8` filter to filter out beacons).
158+
Connection is complete once the AP responds with a successful association response frame.
159+
160+
Once the client connects, you should see the message `CTRL-EVENT-CONNECTED` in the station logs and `AP-STA-CONNECTED` in
161+
the AP logs. Take note of the AP interface that the client connected to. As with the AP interfaces, you can run the
162+
`iw wlan2 info` command to verify connection, channel, SSID, BSSID, etc.
163+
164+
With the simulated client connected and Wireshark running, we're ready to run some tests!
165+
166+
## Simulated Band Steering
167+
168+
To start, we'll first attempt to steer the client from its currently associated AP BSSID to the other AP BSSID.
169+
This aims to simulate a real AP requesting a client transition.
170+
171+
This type of interaction is often seen as client signal reduces. The AP monitors this and suggests the client transition to
172+
a higher signal BSSID (e.g. from 6 GHz to 5 GHz). Metrics like signal to noise ratio (SNR) are often used for this.
173+
174+
1. **Connect to the `hostapd` CLI interface**
175+
176+
In another terminal, run the following command. This will enter a the `hostapd` CLI interface which may
177+
or may not permit line editing and/or command history, depending on your system.
178+
179+
```Bash
180+
# The '-p' option isn't necessary if using the example configs, as they use
181+
# the default control interface path
182+
hostapd_cli -p /var/run/hostapd/
183+
```
184+
185+
2. **Select the AP interface to which the client connected**
186+
187+
Using the `interface` command, select the desired interface. Then, check the list of connected clients
188+
with the `list_sta` command, as shown below.
189+
190+
```Bash
191+
$ hostapd_cli -p /var/run/hostapd/
192+
...
193+
> interface wlan0
194+
> list_sta <---- No clients associated, check the other AP interface
195+
> interface wlan1
196+
> list_sta
197+
02:00:00:00:02:00
198+
```
199+
200+
3. **Send a BSS Transition Management (BTM) request to the client**
201+
202+
With the interface still selected in the `hostapd` CLI interface, run the following command to send a BTM request
203+
to the client. This will generate a BTM request frame, to which the client should respond.
204+
205+
If a client does not support BTM, then the client should not respond. You can simulate this by adding `disable_btm=1`
206+
to the client's `wpa_supplicant` config outside of the network block and then resetting the client to make this active.
207+
208+
```Bash
209+
# From 5 GHz to 2.4 GHz
210+
# First MAC is client MAC. Second MAC (neighbor) is 2.4 GHz BSSID.
211+
bss_tm_req 02:00:00:00:02:00 pref=1 neighbor=02:00:00:00:00:00,0x0000008f,81,1,14
212+
213+
# From 2.4 GHz to 5 GHz
214+
# First MAC is client MAC. Second MAC (neighbor) is 5 GHz BSSID.
215+
bss_tm_req 02:00:00:00:02:00 pref=1 neighbor=02:00:00:00:01:00,0x0000008f,81,36,14
216+
```
217+
218+
Assuming this ran okay, you should see a successful BTM request and response exchange in Wireshark as shown below.
219+
220+
{{ image(src="/blog/2025-11-simulated-band-steering/btm_request_success_5ghz_to_2.4ghz.png", caption="BTM Request to downsteer from 5 GHz to 2.4 GHz BSSID", alt="BTM Request to downsteer from 5 GHz to 2.4 GHz BSSID") }}
221+
222+
Here's another BTM request exchange, this time where the client rejects the AP's request with status code 7, no suitable candidates.
223+
224+
{{ image(src="/blog/2025-11-simulated-band-steering/btm_request_reject_no_suitable_candidates.png", caption="BTM Request rejected, no suitable candidates", alt="BTM Request rejected, no suitable candidates") }}
225+
226+
## Identifying Interfaces and MACs Cont
227+
228+
In the case that interface names and MAC addresses are non-default or difficult to identify, there may be several
229+
things getting in the way. This section covers a couple reasons why this may be.
230+
231+
When any WiFi kernel module loads, the driver creates a virtual interface (vif) per radio. A vif is a general term which refers
232+
to a WiFi interface, be it a station, AP, monitor, or others and applies regardless of WiFi driver (simulated or not).
233+
It's possible to load the `mac80211_hwsim` kernel module without creating a vif for each radio, but that's beyond the
234+
scope of this post (see `modinfo mac80211_hwsim`).
235+
236+
When created, virtual interfaces will generally use a unique name on most modern Linux distributions, thanks to systemd's
237+
predictable network interface naming (see [here](https://systemd.io/PREDICTABLE_INTERFACE_NAMES/) for more info). The
238+
`mac80211_hwsim` interfaces generally dodge this and are reliably named `wlanX` (unsure if they skip udev), assuming the
239+
configured name doesn't already exist.
240+
241+
If the `mac80211_hwsim` interfaces are difficult to identify by name, check the MAC address which is configured to something matching
242+
the format `02:00:00:00:XX:00` (output by `ip -br link show`), assuming your network daemon doesn't get in the way (NetworkManager
243+
may randomize the MACs, have fun).
244+
245+
<!-- TODO: How to disable MAC changing on NetworkManager -->
137 KB
Loading
226 KB
Loading

0 commit comments

Comments
 (0)