Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPI4: WiFi station's signal always is 0 #4574

Open
yzm157 opened this issue Sep 10, 2021 · 9 comments
Open

RPI4: WiFi station's signal always is 0 #4574

yzm157 opened this issue Sep 10, 2021 · 9 comments

Comments

@yzm157
Copy link

yzm157 commented Sep 10, 2021

I upgraded the Raspberry Pi to the latest kernel. When I get all the client information through the command "hostapd_cli all_sta", the signal is always 0, which is good in the 2021-05-07 version.

@pelwell
Copy link
Contributor

pelwell commented Sep 10, 2021

Fill out the Bug template with the required information or you will get no assistance.

@pelwell pelwell closed this as completed Sep 10, 2021
@yzm157 yzm157 changed the title WiFi station's signal always is 0 RPI4: WiFi station's signal always is 0 Sep 10, 2021
@yzm157
Copy link
Author

yzm157 commented Dec 3, 2021

Fill out the Bug template with the required information or you will get no assistance.

@pelwell thank you for your reply。

I use the Raspberry Pi 4B as an AP, and use the create_ap tool to create the AP.
Latest kernel: Linux raspberrypi 5.10.63-v7l+ #1496 SMP Wed Dec 1 15:58:56 GMT 2021 armv7l GNU/Linux
sudo ./create_ap wlan0 eth0 rpi-4b raspberry

WARN: brmfmac driver doesn't work properly with virtual interfaces and
it can cause kernel panic. For this reason we disallow virtual
interfaces for your adapter.
For more info: oblique/create_ap#203
WARN: Your adapter does not fully support AP virtual interface, enabling --no-virt
Config dir: /tmp/create_ap.wlan0.conf.mXhkCVOa
PID: 765
Sharing Internet using method: nat
hostapd command-line interface: hostapd_cli -p /tmp/create_ap.wlan0.conf.mXhkCVOa/hostapd_ctrl
Configuration file: /tmp/create_ap.wlan0.conf.mXhkCVOa/hostapd.conf
wlan0: Could not connect to kernel driver
Using interface wlan0 with hwaddr dc:a6:32:23:97:82 and ssid "rpi-4b"
wlan0: interface state UNINITIALIZED->ENABLED
wlan0: AP-ENABLED

Connect to wireless via mobile phone, ssid: rpi-4b, password: raspberry

wlan0: STA d0:49:7c:xx:xx:xx IEEE 802.11: associated
wlan0: AP-STA-CONNECTED d0:49:7c:xx:xx:xx
wlan0: STA d0:49:7c:xx:xx:xx RADIUS: starting accounting session 7689891474B5DB3C
wlan0: STA d0:49:7c:xx:xx:xx WPA: pairwise key handshake completed (WPA)
wlan0: STA d0:49:7c:xx:xx:xx WPA: group key handshake completed (WPA)

Now the wireless connection is complete

sudo hostapd_cli -p /tmp/create_ap.wlan0.conf.mXhkCVOa/hostapd_ctrl all_sta

Selected interface 'wlan0'
d0:49:7c:xx:xx:xx
flags=[AUTH][ASSOC][AUTHORIZED]
aid=0
capability=0x0
listen_interval=0
supported_rates=
timeout_next=NULLFUNC POLL
dot11RSNAStatsSTAAddress=d0:49:7c:20:5d:9f
dot11RSNAStatsVersion=1
dot11RSNAStatsSelectedPairwiseCipher=00-50-f2-4
dot11RSNAStatsTKIPLocalMICFailures=0
dot11RSNAStatsTKIPRemoteMICFailures=0
hostapdWPAPTKState=11
hostapdWPAPTKGroupState=0
rx_packets=1145
tx_packets=853
rx_bytes=222539
tx_bytes=398039
inactive_msec=0
signal=0
rx_rate_info=10
tx_rate_info=650
connected_time=159
supp_op_classes=515153547374757677787c7d7e7f8082

When obtaining all client information through hostapd_cli, the signal is always 0,which is good in the 2021-05-07 raspbian firmware version (Linux raspberrypi 5.10.17-v7l+ #1414 SMP Fri Apr 30 13:20:47 BST 2021 armv7l GNU/Linux).

yzm157 referenced this issue Dec 3, 2021
[ Upstream commit 9a15909 ]

The rx_lastpkt_rssi field provided by the firmware is suitable for
NL80211_STA_INFO_{SIGNAL,CHAIN_SIGNAL}, while the rssi field is an
average. Fix up the assignments and set the correct STA_INFO bits. This
lets userspace know that the average RSSI is part of the station info.

Fixes: cae355d ("brcmfmac: Add RSSI information to get_station.")
Signed-off-by: Alvin Šipraga <alsi@bang-olufsen.dk>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210506132010.3964484-2-alsi@bang-olufsen.dk
Signed-off-by: Sasha Levin <sashal@kernel.org>
@pelwell pelwell reopened this Dec 6, 2021
@pelwell
Copy link
Contributor

pelwell commented Dec 6, 2021

[ Reopening this issue because comments on commits are easily lost ]
You've identified 5b8d0b0 as being the breaking commit. You also wrote that:

I printed sta_info_le.rx_lastpkt_rssi[x], it is always 0

[22219.454004] brcmfmac: brcmf_cfg80211_get_station: sta_info_le.rssi[0] = -50
[22219.454025] brcmfmac: brcmf_cfg80211_get_station: sta_info_le.rx_lastpkt_rssi[0] = 0
[22219.454042] brcmfmac: brcmf_cfg80211_get_station: sta_info_le.rssi[1] = 0
[22219.454059] brcmfmac: brcmf_cfg80211_get_station: sta_info_le.rx_lastpkt_rssi[1] = 0
[22219.454075] brcmfmac: brcmf_cfg80211_get_station: sta_info_le.rssi[2] = 0
[22219.454091] brcmfmac: brcmf_cfg80211_get_station: sta_info_le.rx_lastpkt_rssi[2] = 0
[22219.454107] brcmfmac: brcmf_cfg80211_get_station: sta_info_le.rssi[3] = 0
[22219.454122] brcmfmac: brcmf_cfg80211_get_station: sta_info_le.rx_lastpkt_rssi[3] = 0

What happens if you change the code from:

                       if (sta_info_le.rssi[i] == 0 ||
                           sta_info_le.rx_lastpkt_rssi[i] == 0)
                               continue;

to:

                       if (sta_info_le.rssi[i] == 0)
                               continue;

?

@yzm157
Copy link
Author

yzm157 commented Dec 7, 2021

What happens if you change the code from:

                       if (sta_info_le.rssi[i] == 0 ||
                           sta_info_le.rx_lastpkt_rssi[i] == 0)
                               continue;

to:

                       if (sta_info_le.rssi[i] == 0)
                               continue;

?

                for (i = 0; i < BRCMF_ANT_MAX; i++) {
                        brcmf_err("sta_info_le.rssi[%d] = %d\n", i, sta_info_le.rssi[i]);
                        brcmf_err("sta_info_le.rx_lastpkt_rssi[%d] = %d\n", i, sta_info_le.rx_lastpkt_rssi[i]);
                        if (sta_info_le.rssi[i] == 0)
                                continue;
                        sinfo->chains |= BIT(count_rssi);
                        sinfo->chain_signal[count_rssi] =
                                sta_info_le.rx_lastpkt_rssi[i];
                        sinfo->chain_signal_avg[count_rssi] =
                                sta_info_le.rssi[i];
                        total_rssi += sta_info_le.rx_lastpkt_rssi[i];
                        total_rssi_avg += sta_info_le.rssi[i];
                        count_rssi++;
                        brcmf_err("i = %d, total_rssi = %d, total_rssi_avg = %d, count_rssi = %d\n", i, total_rssi, total_rssi_avg, count_rssi);
                }
                if (count_rssi) {
                        sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
                        sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
                        sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL);
                        sinfo->filled |=
                                BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG);
                        sinfo->signal = total_rssi / count_rssi;
                        sinfo->signal_avg = total_rssi_avg / count_rssi;
                        brcmf_err("sinfo->signal = %d, sinfo->signal_avg = %d\n", sinfo->signal, sinfo->signal_avg);
                }

I tried to modify the above code, but still can't get the value of sinfo->signal, the value of sinfo->signal_avg exists, and the value of rssi should be sinfo->signal, not sinfo->signal_avg

[47670.394993] brcmfmac: brcmf_cfg80211_get_station: sta_info_le.rssi[0] = -50
[47670.395012] brcmfmac: brcmf_cfg80211_get_station: sta_info_le.rx_lastpkt_rssi[0] = 0
[47670.395028] brcmfmac: brcmf_cfg80211_get_station: i = 0, total_rssi = 0, total_rssi_avg = -50, count_rssi = 1
[47670.395042] brcmfmac: brcmf_cfg80211_get_station: sta_info_le.rssi[1] = 0
[47670.395057] brcmfmac: brcmf_cfg80211_get_station: sta_info_le.rx_lastpkt_rssi[1] = 0
[47670.395070] brcmfmac: brcmf_cfg80211_get_station: sta_info_le.rssi[2] = 0
[47670.395098] brcmfmac: brcmf_cfg80211_get_station: sta_info_le.rx_lastpkt_rssi[2] = 0
[47670.395112] brcmfmac: brcmf_cfg80211_get_station: sta_info_le.rssi[3] = 0
[47670.395125] brcmfmac: brcmf_cfg80211_get_station: sta_info_le.rx_lastpkt_rssi[3] = 0
[47670.395139] brcmfmac: brcmf_cfg80211_get_station: sinfo->signal = 0, sinfo->signal_avg = -50

@pelwell
Copy link
Contributor

pelwell commented Dec 7, 2021

All the Broadcom-based chips and firmwares I tried return 0 in the rx_lastpkt_rssi field, i.e. it is only reporting an average value.

In the unmodified rpi-5.10.y version of the code, count_rssi ends up as 0 because of the test for both rssi and rx_lastpkt_rssi being non-zero, which means it falls back to use this bit of code:

		} else if (test_bit(BRCMF_VIF_STATUS_CONNECTED,
			&ifp->vif->sme_state)) {
			memset(&scb_val, 0, sizeof(scb_val));
			err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI,
						     &scb_val, sizeof(scb_val));
			if (err) {
				bphy_err(drvr, "Could not get rssi (%d)\n",
					 err);
				goto done;
			} else {
				rssi = le32_to_cpu(scb_val.val);
				sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
				sinfo->signal = rssi;
				brcmf_dbg(CONN, "RSSI %d dBm\n", rssi);
			}
		}

Can you confirm that it is getting as far as sinfo->signal = rssi;, and that the assigned value is non-zero?

@yzm157
Copy link
Author

yzm157 commented Dec 8, 2021

@pelwell The code did not execute this branch.

                brcmf_err("test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state) = %d\n", 
                                test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state));
                if (count_rssi) {
                        sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
                        sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL_AVG);
                        sinfo->filled |= BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL);
                        sinfo->filled |=
                                BIT_ULL(NL80211_STA_INFO_CHAIN_SIGNAL_AVG);
                        sinfo->signal = total_rssi / count_rssi;
                        sinfo->signal_avg = total_rssi_avg / count_rssi;
                } else if (test_bit(BRCMF_VIF_STATUS_CONNECTED,
                        &ifp->vif->sme_state)) {
                        memset(&scb_val, 0, sizeof(scb_val));
                        err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI,
                                                     &scb_val, sizeof(scb_val));
                        if (err) {
                                bphy_err(drvr, "Could not get rssi (%d)\n",
                                         err);
                                goto done;
                        } else {
                                rssi = le32_to_cpu(scb_val.val);
                                sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL);
                                sinfo->signal = rssi;
                                brcmf_err("RSSI %d dBm\n", rssi);
                                brcmf_dbg(CONN, "RSSI %d dBm\n", rssi);
                        }
                }

Output:

brcmfmac: brcmf_cfg80211_get_station: test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state) = 0

@pelwell
Copy link
Contributor

pelwell commented Dec 8, 2021

I was assuming, but failed to state, that the other patch (removing the || sta_info_le.rx_lastpkt_rssi[i] == 0) would be reverted. I'm trying to establish what is populating sinfo->filled, sinfo->signal and sinfo->signal_avg (if anything) in the normal path through the code for you.

@yzm157
Copy link
Author

yzm157 commented Apr 11, 2022

@pelwell
Is there any progress on this issue?

@pelwell
Copy link
Contributor

pelwell commented Apr 13, 2022

No.

intel-lab-lkp pushed a commit to intel-lab-lkp/linux that referenced this issue Nov 25, 2024
After commit 9a15909 ("brcmfmac: correctly report average RSSI in
station info") it is required from firmware to provide rx_lastpkt_rssi.
If this field is not provided brcmfmac doesn't report any RSSI at all.
Unfortunately some firmwares doesn't provide it. One example is firmware
for BCM43455 found in Raspbberry Pi.
See raspberrypi/linux#4574

Fix it by falling back to rssi field if rx_lastpkt_rssi is not provided
(like it was before 9a15909).

Fixes: 9a15909 ("brcmfmac: correctly report average RSSI in station info")
Signed-off-by: Alex Shumsky <alexthreed@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants