OpenWRT – reload conf when RADAR is detected

  • by

OpenWRT is a Linux operating system targeting embedded devices, main targets are Wireless Routers, like the name suggests ( ). The first issue I had was with the configuration of the 5GHz channel, so I want to share this.

Use of radio frequencies is strictly regulated, every county has its own law, but usually restrictions are in place for frequencies that can interferes with RADAR devices. This is a pain in the ass when, like myself, you live near an airport. It means some frequencies cannot be used, and you can have hard times finding a free slot of 80MHz in the 5GHz band, needed for 802.11ac standard.

With Linux (OpenWRT has a Linux kernel, and busybox providing standard GNU Linux commands) you can see the relevant information of your device

root@router02:~# iw reg get
 country FR: DFS-ETSI
         (2402 - 2482 @ 40), (N/A, 20), (N/A)
         (5170 - 5250 @ 80), (N/A, 20), (N/A), AUTO-BW
         (5250 - 5330 @ 80), (N/A, 20), (0 ms), DFS, AUTO-BW
         (5490 - 5710 @ 160), (N/A, 27), (0 ms), DFS
         (57000 - 66000 @ 2160), (N/A, 40), (N/A)

Here I see French regulations, it’s built in the device firmware. You can change the country settings, but only to make them more restrictive, unless you want to modify and recompile the drivers, which I don’t since I should redo it on every driver update, and it’s also against the law, probably. I should change the country setting to Switzerland, but since it’s almost identical I won’t. Here you can find the details for the main countries:

In the output above you see some frequencies range has a DFS tag. What the hell is DFS?

DFS is a spectrum-sharing mechanism that allows wireless LANs (WLANs) to coexist with radar systems. It automatically selects a frequency that does not interfere with certain radar systems while operating in the 5 GHz band. DFS is a feature of ETSI BRAN HIPERLAN/2 and IEEE Standard 802.11h

(Yes, I copy pasted that with no shame)

Range of my WIFI router is really short, like every home router, especially indoor on 5GHz band, and I get a RADAR detection only occasionally, the airport is like 5 km away. There could be a lot of false positive detection. When this happens the channel will change, eventually until the overcrowded 36, the only 80 MHz channel without DFS in Europe. This kills bandwidth and raise latency, because of interference between access points on the same channel.

When a detection happens you will see something like this in the logs (here channel was 116, changed to 100):

Sun Dec  1 17:03:58 2019 kernel: [290936.007081] ieee80211 phy0: radar detected by firmware
Sun Dec  1 17:03:58 2019 daemon.notice hostapd: wlan0: DFS-RADAR-DETECTED freq=5580 ht_enabled=0 chan_offset=0 chan_width=3 cf1=5610 cf2=0
Sun Dec  1 17:03:58 2019 daemon.notice hostapd: wlan0: DFS-NEW-CHANNEL freq=5500 chan=100 sec_chan=1

Then new CAC ( Channel Availability Check ) will start, scanning for 60 seconds in order to check no RADAR are in that frequency:

Sun Dec  1 17:03:58 2019 daemon.notice hostapd: wlan0: DFS-CAC-START freq=5500 chan=100 sec_chan=1, width=1, seg0=106, seg1=0, cac_time=60s
Sun Dec  1 17:05:02 2019 daemon.notice hostapd: wlan0: DFS-CAC-COMPLETED success=1 freq=5500 ht_enabled=0 chan_offset=0 chan_width=3 cf1=5530 cf2=0<

BTW: here the list of available channels (my device support 160 MHz but I can forget that, you probably should live in the middle of nowhere to be able to use it, I will go for 80 MHz.) Taken from

Most home routers will make you select the base 20 MHz frequency, which is wrong, selecting channel from 52 to 64 will gives you the same 80 MHz channel, which is #58

In fact, here the list of actually available channels

Channel WidthValid Channel Numbers
20 MHz36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116,
120, 124, 128, 132, 136, 140, 144, 149, 153, 161, 165, 169
40 MHz38, 46, 54, 62, 102, 110, 118, 126, 134, 142, 151, 159
80 MHz42, 58, 106, 122, 138, 155
160 MHz50, 114

Back to my issue, I just want to get my good and free Channel 116 (which is actually #122) since I know there’s no RADAR issue, and in any case it will scan for another 60 seconds, and if RADAR is confirmed it will not gives me the frequency. (Yep, there will be a down of 1 minute, my mobile devices will switch to the 2.4 GHz band in that time frame). I put in crontab a check every 15 minutes, if channel is below 100 than I restart the adapter, which hopefully will gives me my Channel 116, the one that is in the conf file.

Check configured channel using uci:

root@router02:~# uci show wireless.radio0

Check options currently in place (some info masked with “XXXX”):

root@router02:~# cat /sys/kernel/debug/ieee80211/phy0/XXXXXXXXX/vif
macid: 0
 type: ap
 mac address: XX:XX:XX:XX:XX:XX
 channel: 52: width: 3
 freq: 5260 freq1: 5290 freq2: 0
 hw_crypto_enabled: true
 key idx: 1
 IV: 000000000001
 0xdd 0x18 0x00 0x50 0xf2 0x02 0x01 0x01
 0x80 0x00 0x03 0xa4 0x00 0x00 0x27 0xa4
 0x00 0x00 0x42 0x43 0x5e 0x00 0x62 0x32
 0x2f 0x00
 0x30 0x14 0x01 0x00 0x00 0x0f 0xac 0x04
 0x01 0x00 0x00 0x0f 0xac 0x04 0x01 0x00
 0x00 0x0f 0xac 0x02 0x0c 0x00
 0x2d 0x1a 0x6f 0x08 0x17 0xff 0xff 0xff
 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00
 0x00 0x01 0x00 0x00 0x00 0x00 0x00 0x00
 0x00 0x00 0x00 0x00 0x3d 0x16 0x34 0x05
 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
 0x00 0x00 0x00 0x00 0x7f 0x08 0x04 0x00
 0x00 0x00 0x00 0x00 0x00 0x40
 0xbf 0x0c 0x76 0x19 0x88 0x33 0xea 0xff
 0x00 0x00 0xea 0xff 0x00 0x00 0xc0 0x05
 0x01 0x3a 0x00 0xfc 0xff
root@router02:~# cat /sys/kernel/debug/ieee80211/phy0/XXXXXXXXX/vif | awk -F: '/^channel/ {print $2}'
root@router02:~# crontab -l
 */15 * * * * [[ $( cat /sys/kernel/debug/ieee80211/phy0/XXXXXXXXX/vif | awk -F: '/^channel/ {print $2}' ) -lt 100 ]] && wifi down radio0 && sleep 5 && wifi up radio0

Et voilà, it works like a charm.

Leave a Reply

Your email address will not be published.