rtwn/rtl8821au: strange issue with 5GHz channels

From: Andriy Gapon <avg_at_FreeBSD.org>
Date: Tue, 19 Aug 2025 12:46:07 UTC
I have an access point running OpenWRT.
Its 5 GHz radio is configured for 80 MHz width.
The channel is currently 149, I also tried 116 before.
This is according to OpenWRT guidelines that the channel should be set to the 
lowest one in the range.

"radio1": {
         "up": true,
         "pending": false,
         "autostart": true,
         "disabled": false,
         "retry_setup_failed": false,
         "config": {
                 "path": "1e140000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0",
                 "band": "5g",
                 "htmode": "VHT80",
                 "cell_density": 0,
                 "country": "UA",
                 "channel": "149"
         },

On the FreeBSD side I have very recent main / CURRENT, an Edimax EW-7811UAC USB 
WiFi adapter with RTL8821AU recognized by rtwn driver.
I am trying to connect using WPA (wpa_supplicant).

That almost always fails and works only once out of dozen attempts.
With debug logs enabled it seems that there is a timeout receiving a management 
frame from the AP (or something like that).
E.g.:

Aug  9 18:05:21 rock64b kernel: wlan0: ni 0xffff0000afe8f000 mode STA state AUTH 
arg 0x2 status 0
Aug  9 18:05:23 rock64b kernel: wlan0: vap 0xffffa00005f47000 mode STA state 
AUTH flags 0x42400 & 0x80

This may be unsurprising becomes the adapter sees a wrong / strange channel 
number comparing to what's configured on the AP.  It's almost always +4.
And only rarely it's the correct number.  In those cases the connection works.

E.g., right now:
$ ifconfig wlan0 scan | sort -t '' -k 1.66,1.67n | head -2
SSID/MESH ID                      BSSID              CHAN RATE    S:N     INT CAPS
HolyLan                           7a:d2:94:80:1f:ec  153   54M  -70:-95   100 
EPS  RSN BSSLOAD HTCAP VHTCAP VHTOPMODE VHTPWRENV WME

Looks like perhaps there is some wrong calculation in the driver when bandwidth 
is greater than 20 MHz.

-- 
Andriy Gapon