Using UCI antenna gain in /etc/config/wireless mac80211

Hi All.

Anyone using antenna_gain in their /etc/config/wireless?
Mine isn't firing properly on my msm466 flashed on msm460.
After a sanity check before I go digging deeper.

Example config:

root@OpenWrt-J9622-testap:~# cat /etc/config/wireless 

config wifi-device 'radio0'
	option type 'mac80211'
	option path 'ffe09000.pcie/pci0000:00/0000:00:00.0/0000:01:00.0'
	option channel 'auto'
	option channels '1,5,9,13'
	option band '2g'
	option htmode 'HT20'
	option cell_density '0'
	option country 'AU'
	option txpower '22'
	option distance '1000'
	option antenna_gain '22'

config wifi-iface 'default_radio0'
	option device 'radio0'
	option network 'leglan'
	option mode 'ap'
	option ssid 'OpenWrt-gaintest0'
	option encryption 'sae'
	option key 'redacted'
	option ieee80211r '1'
	option ft_over_ds '0'

config wifi-device 'radio1'
	option type 'mac80211'
	option path 'ffe0a000.pcie/pci0001:02/0001:02:00.0/0001:03:00.0'
	option channel 'auto'
	option channels '157-165,132-144'
	option band '5g'
	option htmode 'HT40'
	option country 'AU'
	option cell_density '0'
	option txpower '18'
	option distance '1000'
	option antenna_gain '22'

config wifi-iface 'default_radio1'
	option device 'radio1'
	option network 'leglan'
	option mode 'ap'
	option ssid 'OpenWrt-gaintest2'
	option encryption 'sae'
	option key 'redacted'
	option ieee80211r '1'
	option ft_over_ds '0'

For example after reboot the power is this:

oot@OpenWrt-J9622-testap:~# uptime
 20:07:52 up 0 min,  load average: 0.68, 0.18, 0.06
root@OpenWrt-J9622-testap:~# iwinfo 
phy0-ap0  ESSID: "OpenWrt-gaintest0"
          Access Point: 50:65:F3:DB:57:20
          Mode: Master  Channel: 5 (2.432 GHz)  HT Mode: HT20
          Center Channel 1: 5 2: unknown
          Tx-Power: 22 dBm  Link Quality: unknown/70
          Signal: unknown  Noise: -92 dBm
          Bit Rate: unknown
          Encryption: WPA3 SAE (CCMP)
          Type: nl80211  HW Mode(s): 802.11a/b/g/n
          Hardware: 168C:0030 168C:3114 [Atheros AR9390]
          TX power offset: none
          Frequency offset: none
          Supports VAPs: yes  PHY name: phy0

phy1-ap0  ESSID: "OpenWrt-gaintest2"
          Access Point: 50:65:F3:DB:57:30
          Mode: Master  Channel: 161 (5.805 GHz)  HT Mode: HT20
          Center Channel 1: 161 2: unknown
          Tx-Power: 17 dBm  Link Quality: unknown/70
          Signal: unknown  Noise: -93 dBm
          Bit Rate: unknown
          Encryption: WPA3 SAE (CCMP)
          Type: nl80211  HW Mode(s): 802.11a/b/g/n
          Hardware: 168C:0030 168C:3114 [Atheros AR9390]
          TX power offset: none
          Frequency offset: none
          Supports VAPs: yes  PHY name: phy1

root@OpenWrt-J9622-testap:~# 

What i'd expect. For example after setting it with iw manually:

root@OpenWrt-J9622-testap:~# iw phy0 set antenna_gain 22
root@OpenWrt-J9622-testap:~# iw phy1 set antenna_gain 22
root@OpenWrt-J9622-testap:~# iwinfo 
phy0-ap0  ESSID: "OpenWrt-gaintest0"
          Access Point: 50:65:F3:DB:57:20
          Mode: Master  Channel: 5 (2.432 GHz)  HT Mode: HT20
          Center Channel 1: 5 2: unknown
          Tx-Power: 14 dBm  Link Quality: unknown/70
          Signal: unknown  Noise: -89 dBm
          Bit Rate: unknown
          Encryption: WPA3 SAE (CCMP)
          Type: nl80211  HW Mode(s): 802.11a/b/g/n
          Hardware: 168C:0030 168C:3114 [Atheros AR9390]
          TX power offset: none
          Frequency offset: none
          Supports VAPs: yes  PHY name: phy0

phy1-ap0  ESSID: "OpenWrt-gaintest2"
          Access Point: 50:65:F3:DB:57:30
          Mode: Master  Channel: 161 (5.805 GHz)  HT Mode: HT20
          Center Channel 1: 161 2: unknown
          Tx-Power: 14 dBm  Link Quality: unknown/70
          Signal: unknown  Noise: -93 dBm
          Bit Rate: unknown
          Encryption: WPA3 SAE (CCMP)
          Type: nl80211  HW Mode(s): 802.11a/b/g/n
          Hardware: 168C:0030 168C:3114 [Atheros AR9390]
          TX power offset: none
          Frequency offset: none
          Supports VAPs: yes  PHY name: phy1

root@OpenWrt-J9622-testap:~# 

Please provide official OpenWrt documentation of this parameter.

Also, why are you attempting to modify such a parameter?

(The value relates to a output total set by law when manufacturered with the proved antennas.)

Please provide the output of:

ubus call system board

Are you saying you flashed firmware for a different device?

MAC80211 options in https://openwrt.org/docs/guide-user/network/wifi/basic

There was a patch to mac80211.sh at some point from what I read. I'd have to find it again.
openwrt/package/kernel/mac80211/files/lib/netifd/wireless/mac80211.sh

I'm running a board where the default antenna gain built into the ath9k eeprom should be zero I guess. Output power is just output power at the RP-SMA connectors. Not related to EIRP yet without setting an antenna gain.

i.e. because it's a model with RP-SMA and never came with default antennas.
I'm probably not going to be running antenna gains over 10-15dBi anyway so I'm not going to run near regulatory limits as long as I restrict my channels. But it would be nice to set it properly in case someone goes and changes the channels in the config. But I wanted to see it work just in case I get some ridiculous sector or point to point antenna.

Yeah MSM460 and MSM466 same baseboard.
Only thing I have at the moment with external antennas and the only AP at my desk to test.
This behaviour should be board independent though right?

The only other applicable device I can think of at the moment that shares a device tree / board name and has an internal antenna and external antenna model would be the HiveAP 330 / HiveAP 350.

{
	"kernel": "5.15.162",
	"hostname": "OpenWrt-J9622-testap",
	"system": "e500v2",
	"model": "Hewlett-Packard MSM460",
	"board_name": "hpe,msm460",
	"rootfs_type": "squashfs",
	"release": {
		"distribution": "OpenWrt",
		"version": "23.05.4",
		"revision": "r24012-d8dd03c46f",
		"target": "mpc85xx/p1020",
		"description": "OpenWrt 23.05.4 r24012-d8dd03c46f"
	}
}

1 Like

Gotcha.

The documentation says:

Reduction in antenna gain from regulatory maximum in dBi

(emphasis added by me)

To be clear, do you wish to raise or lower the gain?

44 + 18 == 40

40 > 15

(I didn't provide the subtraction for obvious reasons.)

Have you calculated correctly?

It seems you're [endeavoring at] adding quite a lot to me. From my cursory review, they're invalid values.

Edit:

What do you mean by "restrict channels"?

What I want is a reduction in power so I don't go over the regulatory limit.
The "gain" is added by selecting an antenna. Effective isotropic radiated power (EIRP) is changing without touching the output power setting.

(As an aside, certified antennas on MSM466 are J9170A, J9169A, J9171A, J9659A. So the max certified pairing is 13.5dBi on 5ghz and 10.9dBi on 2.4ghz)

If I was to get a third party sector or horn/dish antenna I can get gains above those. But then the whole system wouldn't be certified. But that's distracting from the point.

The value I'm planning to put there is the antenna gain of the antenna that is attached to the device.

Per original command output I put in a ludicrously high gain and then setting it manually by iw.

Doing it manually is working fine.
But UCI config on boot reload networking / reload wifi I don't get the reduction in transmit power as expected.

A worked example:

In 5730-5785MHz (149-157) I have 36dBm EIRP limit per iw reg get. and no antenna gain limit as that's "N/A".

If I have a 11dBi antenna and the radio itself is limited to 18dBm I have EIRP of 29dBm. This is below EIRP limit so I'm fine.

I would need to restrict my selection of channels so I don't exceed the EIRP limits.

I'm going to have a problem If we go outside 149-157 in this example. (Working with iw reg limits)

I'd have to read the class licenses again but I think in AU it's a little different from what iw reg get is spitting out anyway. ( 23dBm (200mW) in 5170-5330 30dBm (1W) EIRP for 5490-5730 (100-144). 36dBm (4W) EIRP for 149-165)

Similarly one would have to go and select the right channel if one was going to be operating outdoors.

Below is my output on the device.

iw reg get
global
country AU: DFS-ETSI
	(915 - 920 @ 4), (N/A, 30), (N/A)
	(920 - 928 @ 8), (N/A, 30), (N/A)
	(2400 - 2483 @ 40), (N/A, 36), (N/A)
	(5150 - 5250 @ 80), (N/A, 23), (N/A), NO-OUTDOOR, AUTO-BW
	(5250 - 5350 @ 80), (N/A, 20), (0 ms), NO-OUTDOOR, DFS, AUTO-BW
	(5470 - 5600 @ 80), (N/A, 26), (0 ms), DFS
	(5650 - 5730 @ 80), (N/A, 26), (0 ms), DFS
	(5730 - 5850 @ 80), (N/A, 36), (N/A), AUTO-BW
	(5850 - 5875 @ 20), (N/A, 13), (N/A), AUTO-BW
	(5925 - 6425 @ 160), (N/A, 23), (N/A), NO-OUTDOOR
	(57000 - 71000 @ 2160), (N/A, 43), (N/A), NO-OUTDOOR
iw phy0 info 
Wiphy phy0
	wiphy index: 0
	max # scan SSIDs: 4
	max scan IEs length: 2257 bytes
	max # sched scan SSIDs: 0
	max # match sets: 0
	Retry short limit: 7
	Retry long limit: 4
	Coverage class: 3 (up to 1350m)
	Device supports AP-side u-APSD.
	Device supports T-DLS.
	Available Antennas: TX 0x7 RX 0x7
	Configured Antennas: TX 0x7 RX 0x7
	Supported interface modes:
		 * IBSS
		 * managed
		 * AP
		 * AP/VLAN
		 * monitor
		 * mesh point
		 * P2P-client
		 * P2P-GO
		 * outside context of a BSS
	Band 1:
		Capabilities: 0x11ef
			RX LDPC
			HT20/HT40
			SM Power Save disabled
			RX HT20 SGI
			RX HT40 SGI
			TX STBC
			RX STBC 1-stream
			Max AMSDU length: 3839 bytes
			DSSS/CCK HT40
		Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
		Minimum RX AMPDU time spacing: 8 usec (0x06)
		HT TX/RX MCS rate indexes supported: 0-23
		Frequencies:
			* 2412 MHz [1] (22.0 dBm)
			* 2417 MHz [2] (22.0 dBm)
			* 2422 MHz [3] (22.0 dBm)
			* 2427 MHz [4] (22.0 dBm)
			* 2432 MHz [5] (22.0 dBm)
			* 2437 MHz [6] (22.0 dBm)
			* 2442 MHz [7] (22.0 dBm)
			* 2447 MHz [8] (22.0 dBm)
			* 2452 MHz [9] (22.0 dBm)
			* 2457 MHz [10] (22.0 dBm)
			* 2462 MHz [11] (22.0 dBm)
			* 2467 MHz [12] (22.0 dBm)
			* 2472 MHz [13] (22.0 dBm)
			* 2484 MHz [14] (disabled)
	Band 2:
		Capabilities: 0x11ef
			RX LDPC
			HT20/HT40
			SM Power Save disabled
			RX HT20 SGI
			RX HT40 SGI
			TX STBC
			RX STBC 1-stream
			Max AMSDU length: 3839 bytes
			DSSS/CCK HT40
		Maximum RX AMPDU length 65535 bytes (exponent: 0x003)
		Minimum RX AMPDU time spacing: 8 usec (0x06)
		HT TX/RX MCS rate indexes supported: 0-23
		Frequencies:
			* 5180 MHz [36] (18.0 dBm)
			* 5200 MHz [40] (18.0 dBm)
			* 5220 MHz [44] (18.0 dBm)
			* 5240 MHz [48] (18.0 dBm)
			* 5260 MHz [52] (18.0 dBm) (radar detection)
			* 5280 MHz [56] (18.0 dBm) (radar detection)
			* 5300 MHz [60] (18.0 dBm) (radar detection)
			* 5320 MHz [64] (18.0 dBm) (radar detection)
			* 5500 MHz [100] (18.0 dBm) (radar detection)
			* 5520 MHz [104] (18.0 dBm) (radar detection)
			* 5540 MHz [108] (18.0 dBm) (radar detection)
			* 5560 MHz [112] (18.0 dBm) (radar detection)
			* 5580 MHz [116] (18.0 dBm) (radar detection)
			* 5600 MHz [120] (disabled)
			* 5620 MHz [124] (disabled)
			* 5640 MHz [128] (disabled)
			* 5660 MHz [132] (18.0 dBm) (radar detection)
			* 5680 MHz [136] (18.0 dBm) (radar detection)
			* 5700 MHz [140] (18.0 dBm) (radar detection)
			* 5745 MHz [149] (18.0 dBm)
			* 5765 MHz [153] (18.0 dBm)
			* 5785 MHz [157] (18.0 dBm)
			* 5805 MHz [161] (17.0 dBm)
			* 5825 MHz [165] (17.0 dBm)
	valid interface combinations:
		 * #{ managed } <= 2048, #{ AP, mesh point } <= 8, #{ P2P-client, P2P-GO } <= 1, #{ IBSS } <= 1,
		   total <= 2048, #channels <= 1, STA/AP BI must match, radar detect widths: { 20 MHz (no HT), 20 MHz, 40 MHz }

	HT Capability overrides:
		 * MCS: ff ff ff ff ff ff ff ff ff ff
		 * maximum A-MSDU length
		 * supported channel width
		 * short GI for 40 MHz
		 * max A-MPDU length exponent
		 * min MPDU start spacing
	max # scan plans: 1
	max scan plan interval: -1
	max scan plan iterations: 0
	Supported extended features:
		* [ RRM ]: RRM
		* [ FILS_STA ]: STA FILS (Fast Initial Link Setup)
		* [ CQM_RSSI_LIST ]: multiple CQM_RSSI_THOLD records
		* [ CONTROL_PORT_OVER_NL80211 ]: control port over nl80211
		* [ TXQS ]: FQ-CoDel-enabled intermediate TXQs
		* [ SCAN_RANDOM_SN ]: use random sequence numbers in scans
		* [ SCAN_MIN_PREQ_CONTENT ]: use probe request with only rate IEs in scans
		* [ CAN_REPLACE_PTK0 ]: can safely replace PTK 0 when rekeying
		* [ AIRTIME_FAIRNESS ]: airtime fairness scheduling
		* [ CONTROL_PORT_NO_PREAUTH ]: disable pre-auth over nl80211 control port support
		* [ DEL_IBSS_STA ]: deletion of IBSS station support
		* [ MULTICAST_REGISTRATIONS ]: mgmt frame registration for multicast
		* [ SCAN_FREQ_KHZ ]: scan on kHz frequency support
		* [ CONTROL_PORT_OVER_NL80211_TX_STATUS ]: tx status for nl80211 control port support

Have you tried using the negative symbol?

As an aside antenna gain can be negative in the first place so that shouldn't be the issue. Just means your antenna is actually attenuating.

I tested it anyway no that doesn't reduce the output power. It would be interesting to check if the transmit power that is initially limited goes up if you set a negative gain though.

I was under the impression that it was taking that value and putting it directly as the argument to iw set antenna_gain <antenna_gain> per the shell script but eh. The interface is in terms of what your antenna gain is anyway.

Thanks for your input and allowing me to talk through the problem. I'll have to put investigating this more and reading the mac80211.sh script on my todo list.

1 Like

Yes, I understand it's possible to install an antenna that provides negative gain.

Tbh, I think that value is old, verify the version 23 script manipulates it. I recall a lot of work regarding calculations of gain, etc. being done. Quite a few users inquire from time to time.

No worries!

1 Like

Ok had time to look for this today.

Looks like it was removed in 2023.

99a98b3

" mac80211: remove non-upstream antenna gain configuration patch "

1 Like