git: fcc5031c9c51 - stable/13 - LinuxKPI: 802.11: further fix RSSI calculations

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Thu, 14 Apr 2022 18:01:24 UTC
The branch stable/13 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=fcc5031c9c5110a12d29e146613b237034329df7

commit fcc5031c9c5110a12d29e146613b237034329df7
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-04-08 11:00:11 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-04-14 16:38:06 +0000

    LinuxKPI: 802.11: further fix RSSI calculations
    
    60970a328e280b25b05f1d9a9de1ef91af573c4a did one half of the job
    of making rssi relative to nf and numbers for radiotap were fine.
    net80211 internally works with .5 dBm units thus we need to apply a
    * 2 to the value we pass in to c_rssi;  leave a comment explaining.
    
    Note: it is only ifconfig in user space which re-adjust it for printing
    or contrib/wpa for calculations.  Other applications getting values
    from kernel also have to apply the maths.
    
    In collaboration with:  J.R. Oldroyd (fbsd opal.com)
    Sponsored by:           The FreeBSD Foundation
    
    (cherry picked from commit 170acccf1e191ae28571845ad6f0b5a2fbf0effc)
---
 sys/compat/linuxkpi/common/src/linux_80211.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c
index 72bbb1ff1382..001040d025ed 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211.c
+++ b/sys/compat/linuxkpi/common/src/linux_80211.c
@@ -3647,6 +3647,7 @@ linuxkpi_ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
 	struct ieee80211_hdr *hdr;
 	struct lkpi_sta *lsta;
 	int i, offset, ok;
+	int8_t rssi;
 	bool is_beacon;
 
 	if (skb->len < 2) {
@@ -3729,10 +3730,15 @@ no_trace_beacons:
 	rx_stats.c_nf = -96;
 	if (ieee80211_hw_check(hw, SIGNAL_DBM) &&
 	    !(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
-		rx_stats.c_rssi = rx_status->signal;
+		rssi = rx_status->signal;
 	else
-		rx_stats.c_rssi = 0;
-	rx_stats.c_rssi -= rx_stats.c_nf;
+		rssi = rx_stats.c_nf;
+	/*
+	 * net80211 signal strength data are in .5 dBm units relative to
+	 * the current noise floor (see comment in ieee80211_node.h).
+	 */
+	rssi -= rx_stats.c_nf;
+	rx_stats.c_rssi = rssi * 2;
 	rx_stats.r_flags |= IEEE80211_R_BAND;
 	rx_stats.c_band =
 	    lkpi_nl80211_band_to_net80211_band(rx_status->band);
@@ -3827,7 +3833,7 @@ skip_device_ts:
 		rtap->wr_chan_freq = htole16(rx_stats.c_freq);
 		if (ic->ic_curchan->ic_ieee == rx_stats.c_ieee)
 			rtap->wr_chan_flags = htole16(ic->ic_curchan->ic_flags);
-		rtap->wr_dbm_antsignal = rx_stats.c_rssi;
+		rtap->wr_dbm_antsignal = rssi;
 		rtap->wr_dbm_antnoise = rx_stats.c_nf;
 	}