mainpostsannouncesoft/projmiscstorage

making hostapd LAR-friendly (on Intel 5GHz wireless cards)

2022/07/07 1:26 AM (UTC -5) | tildearrow

Intel wireless cards are among the best for Linux, with support for new devices landing even before they are released. however, they have one big drawback: LAR (Location-Aware Regulatory).

basically the card detects in which country it is (and therefore the regulatory domain) based on nearby access points' ones, and doesn't let you change it manually.
the sad thing is that it often sets the card to the wrong country, which is a problem.

prior to Linux 5.5 there was an option to disable this annoying feature in the iwlwifi module (lar_disable=1), but it was removed as later firmware versions caused card crashes and Intel claimed the option shouldn't be accessible anyway (ridiculous I know!).

this negatively affects hostapd (an application which turns your wireless card into an access point), as it prevents you from creating an access point in the 5GHz band at all.
most discussions on LAR end with everyone giving up and admitting Intel isn't a good choice (which honestly I may agree with), but I decided to take a deeper look at the problem...

here's my analysis.

when LAR actually works, the real issue isn't LAR, but rather hostapd not scanning before setting up the AP.
when hostapd sets up the wireless interface, the card resets the country to 00 ("world"), which only has 2.4GHz channels and the 5GHz ones are unusable.
so even if there are 5GHz networks nearby, it will not be able to start the access point up on the 5GHz band.

however, after running iw dev wlan0 scan, the country will change to something else (depending on the other networks' country settings).

so I thought... why not make hostapd scan for networks before fetching the list of available channels?

after some trial and error, I was able to get hostapd to start in the 5GHz band on an Intel card with LAR enabled:


nl80211: Interface wlan0 is in bridge br0
nl80211: Add own interface ifindex 5 (ifidx_reason 4)
nl80211: if_indices[16]: 5(4)
nl80211: Add own interface ifindex 4 (ifidx_reason -1)
nl80211: if_indices[16]: 5(4) 4(-1)
nl80211: Do not open EAPOL RX socket - using control port for RX
phy: phy0
BSS count 1, BSSID mask 00:00:00:00:00:00 (0 bits)
wlan0: interface state UNINITIALIZED->COUNTRY_UPDATE
Previous country code US, new country code US
wlan0: nl80211: scan request
nl80211: Passive scan requested
Scan requested (ret=0) - scan timeout 10 seconds
Sleeping...
nl80211: No channel number found for frequency 5905 MHz
nl80211: Added 802.11b mode based on 802.11g information
nl80211: Mode IEEE 802.11g: 2412 2417 2422 2427 2432 2437 2442 2447 2452 2457 2462 2467 2472 2484[DISABLED]
nl80211: Mode IEEE 802.11a: 5180 5200 5220 5240 5260[NO_IR][RADAR] 5280[NO_IR][RADAR] 5300[NO_IR][RADAR] 5320[NO_IR][RADAR] 5340[DISABLED] 5360[DISABLED] 5380[DISABLED] 5400[DISABLED] 5420[DISABLED] 5440[DISABLED]
nl80211: Mode IEEE 802.11a: 5955[NO_IR] 5975[NO_IR] 5995[NO_IR] 6015[NO_IR] 6035[NO_IR] 6055[NO_IR] 6075[NO_IR] 6095[NO_IR] 6115[NO_IR] 6135[NO_IR] 6155[NO_IR] 6175[NO_IR] 6195[NO_IR] 6215[NO_IR] 6235[NO_IR] 6255[NO_IR]
nl80211: Mode IEEE 802.11b: 2412 2417 2422 2427 2432 2437 2442 2447 2452 2457 2462 2467 2472 2484[DISABLED]
Allowed channel: mode=1 chan=1 freq=2412 MHz max_tx_power=0 dBm
Allowed channel: mode=1 chan=2 freq=2417 MHz max_tx_power=0 dBm
Allowed channel: mode=1 chan=3 freq=2422 MHz max_tx_power=0 dBm
Allowed channel: mode=1 chan=4 freq=2427 MHz max_tx_power=0 dBm
Allowed channel: mode=1 chan=5 freq=2432 MHz max_tx_power=0 dBm
Allowed channel: mode=1 chan=6 freq=2437 MHz max_tx_power=0 dBm
Allowed channel: mode=1 chan=7 freq=2442 MHz max_tx_power=0 dBm
Allowed channel: mode=1 chan=8 freq=2447 MHz max_tx_power=0 dBm
Allowed channel: mode=1 chan=9 freq=2452 MHz max_tx_power=0 dBm
Allowed channel: mode=1 chan=10 freq=2457 MHz max_tx_power=0 dBm
Allowed channel: mode=1 chan=11 freq=2462 MHz max_tx_power=0 dBm
Allowed channel: mode=1 chan=12 freq=2467 MHz max_tx_power=0 dBm
Allowed channel: mode=1 chan=13 freq=2472 MHz max_tx_power=0 dBm
Allowed channel: mode=2 chan=36 freq=5180 MHz max_tx_power=0 dBm
Allowed channel: mode=2 chan=40 freq=5200 MHz max_tx_power=0 dBm
Allowed channel: mode=2 chan=44 freq=5220 MHz max_tx_power=0 dBm
Allowed channel: mode=2 chan=48 freq=5240 MHz max_tx_power=0 dBm
Allowed channel: mode=2 chan=149 freq=5745 MHz max_tx_power=0 dBm
Allowed channel: mode=2 chan=153 freq=5765 MHz max_tx_power=0 dBm
Allowed channel: mode=2 chan=157 freq=5785 MHz max_tx_power=0 dBm
Allowed channel: mode=2 chan=161 freq=5805 MHz max_tx_power=0 dBm
Allowed channel: mode=2 chan=165 freq=5825 MHz max_tx_power=0 dBm
Allowed channel: mode=0 chan=1 freq=2412 MHz max_tx_power=0 dBm
Allowed channel: mode=0 chan=2 freq=2417 MHz max_tx_power=0 dBm
Allowed channel: mode=0 chan=3 freq=2422 MHz max_tx_power=0 dBm
Allowed channel: mode=0 chan=4 freq=2427 MHz max_tx_power=0 dBm
Allowed channel: mode=0 chan=5 freq=2432 MHz max_tx_power=0 dBm
Allowed channel: mode=0 chan=6 freq=2437 MHz max_tx_power=0 dBm
Allowed channel: mode=0 chan=7 freq=2442 MHz max_tx_power=0 dBm
Allowed channel: mode=0 chan=8 freq=2447 MHz max_tx_power=0 dBm
Allowed channel: mode=0 chan=9 freq=2452 MHz max_tx_power=0 dBm
Allowed channel: mode=0 chan=10 freq=2457 MHz max_tx_power=0 dBm
Allowed channel: mode=0 chan=11 freq=2462 MHz max_tx_power=0 dBm
Allowed channel: mode=0 chan=12 freq=2467 MHz max_tx_power=0 dBm
Allowed channel: mode=0 chan=13 freq=2472 MHz max_tx_power=0 dBm
Disable HT capability [DSSS_CCK-40] on 5 GHz band
hw vht capab: 0x39071f6, conf vht capab: 0x0
You are sucking today!
HT40: control channel: 149 (5745 MHz), secondary channel: 153 (5765 MHz)
Completing interface initialization
Mode: IEEE 802.11a Channel: 149 Frequency: 5745 MHz

...

wlan0: interface state COUNTRY_UPDATE->ENABLED
wlan0: AP-ENABLED
wlan0: Setup of interface done.

this works by scanning prior to hostapd_get_hw_features (which initializes the list of available channels).
I tested it on my Intel AX210 card for a few hours and seems to work. a few issues though:

here's the patch which can be applied to hostapd version 2.10! this includes the noscan patch by dviktor.

you can apply it by running this after cd'ing to the hostapd source directory:
patch -p1 < hostapd-2.10-lar.patch

(NOTE: use at your own risk! respect local regulations!)

I hope this helps.