raspberrypi / linux

Kernel source tree for Raspberry Pi-provided kernel builds. Issues unrelated to the linux kernel should be posted on the community forum at https://forums.raspberrypi.com/
Other
10.85k stars 4.88k forks source link

Avoiding autonomous 5GHz band Wi-Fi steering when a P2P-GO is set to freq=2 #4078

Open Ircama opened 3 years ago

Ircama commented 3 years ago

Is this the right place for my bug report?

I think that this issue might be related to the BCM2711 nl80211 wireless kernel device driver.

Describe the bug

With a Raspberry Pi supporting the 5GHz Wi-Fi band (e.g., Raspberry Pi 4 Model B), if a Wi-Fi Direct P2P-GO group is created with option 2.4 GHz (freq=2), considering also the presence of some P2P Clients only supporting 2.4 GHz and some supporting Wi-Fi dual bands, the starting P2P-GO band will be 2.4GHz, but after some time the band will autonomously move to 5 GHz.

To reproduce

wpa_supplicant config file (wpa_supplicant.conf):

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
device_name=DIRECT-test
device_type=6-0050F204-1
p2p_go_intent=15
country=IT

No AP shall be active (P2P-GO and AP cannot run concurrently on such hw),

wpa_supplicant command:

sudo wpa_supplicant -c/etc/wpa_supplicant/wpa_supplicant.conf -iwlan0 -Dnl80211,wext

Start wpa_cli -i p2p-dev-wlan0 and issue:

p2p_group_add freq=2

The result is the following (iw dev):

        Interface p2p-wlan0-0
                ifindex 5
                wdev 0x4
                addr de:a6:32:01:82:03
                type P2P-GO
                channel 1 (2412 MHz), width: 20 MHz, center1: 2412 MHz
                txpower 31.00 dBm
        Unnamed/non-netdev interface
                wdev 0x2
                addr dc:a6:32:01:02:03
                type P2P-device
                txpower 31.00 dBm
        Interface wlan0
                ifindex 3
                wdev 0x1
                addr dc:a6:32:00:9a:f5
                ssid TIM-86817771
                type managed
                channel 104 (5520 MHz), width: 40 MHz, center1: 5510 MHz
                txpower 31.00 dBm

Notice the different channels of p2p-wlan0-0 (2.4 GHz) and wlan0 (5 GHz)

Ensure wpa_supplicant is not interfering:

sudo killall -STOP wpa_supplicant

Wait for several minutes.

The iw dev will show a 5 GHz channel for the p2p-wlan0-0 Interface:

phy#0
        Interface p2p-wlan0-1
                ifindex 5
                wdev 0x4
                addr de:a6:32:01:82:03
                type P2P-GO
                channel 36 (5180 MHz), width: 40 MHz, center1: 5190 MHz
                txpower 31.00 dBm
        Unnamed/non-netdev interface
                wdev 0x2
                addr dc:a6:32:01:02:03
                type P2P-device
                txpower 31.00 dBm
        Interface wlan0
                ifindex 3
                wdev 0x1
                addr dc:a6:32:00:9a:f5
                ssid TIM-86817771
                type managed
                channel 104 (5520 MHz), width: 40 MHz, center1: 5510 MHz
                txpower 31.00 dBm

Expected behaviour

p2p-wlan0-0 channel shall not autonomously move to different frequencies when not driven by wpa_supplicant.

Actual behaviour

Just after creating the P2P-GO group, wpa_supplicant correctly configures the band, in fact the initial P2P-GO virtual interface (p2p-wlan0-0) is set to a 2.4 GHz frequency even if the Wi-Fi interface (wlan0) is set to a frequency in the 5 GHz band. To verify that wpa_supplicant does not interfere, we can send a SIGSTOP signal just after the P2P-GO group is created.

After several minutes, the Broadcom nl80211 wireless device driver autonomously appears to move the P2P-GO frequency from the 2.4 GHz band to the 5 GHz band.

The result is that 5 GHz P2P Devices can still connect the P2P-GO group after a while, while the 2.4 GHz ones will no more receive the group beaconing data.

Considering to find a workaround by modifying the wpa_supplicant sources, which is the correct nl80211 wireless device driver option to prevent this (wrong) default behavior when creating the NL80211_IFTYPE_P2P_GO type interface? Notice that if the P2P-GO interface is created with NL80211_ATTR_FREQ_FIXED property, the results are unchanged.

System Results of the raspinfo command

Additional context

I'm not sure that this is misleading, but there should be a way to overcome the issue, in fact if I run the following commands (after resuming and stopping wpa_supplicant with sudo killall -CONT wpa_supplicant; sleep 10; sudo killall wpa_supplicant), the frequency of the interface appears to stably remain to 2.4 GHz even if, before issuing them, the wlan0 frequency was in a 5 GHz band:

iw dev wlan0 interface add p2p-wlan0-0 type __p2pgo
ifconfig p2p-wlan0-0 192.168.4.1 netmask 255.255.255.0 up
iw dev p2p-wlan0-0 ap start DIRECT-PP-Toyota 2437 100 1 head 80000000ffffffffffff0a85bc6459460a85bc645946000000000000000000006400110400104449524543542d50502d546f796f746101088c129824b048606c030101
iw dev

The output is the following:

phy#0
        Interface p2p-wlan0-0
                ifindex 6
                wdev 0x5
                addr de:a6:32:01:82:03
                type P2P-GO
                channel 6 (2437 MHz), width: 20 MHz, center1: 2437 MHz
                txpower 31.00 dBm
        Interface wlan0
                ifindex 3
                wdev 0x1
                addr dc:a6:32:00:9a:f5
                type managed
                channel 6 (2437 MHz), width: 20 MHz, center1: 2437 MHz

Such case is anyway different and possibly not appropriate: both p2p-wlan0-0 and wlan0 are stably set to the same fixed 2.4 GHz frequency, while ideally only the P2P-GO group should be set to a 2.4 GHz frequency.

Ircama commented 3 years ago

Meanwhile, there is an (invasive) workaround to fix the 2.4 GHz band, by editing wpa_supplicant.conf and setting an appropriate country that needs to both respect the regulatory settings of the region where the interface is used and at the same time disable the 5 GHz band. For instance, country=RU.

Use iw reg get to get the currently used settings.

Use iwlist wlan0 frequency to get the list of the frequencies available with the interface settings.

use iw reg set RU;iwlist wlan0 frequency;iw reg get to set the region settings and check the used frequencies. The output can be compared with the previous commands in order to verify compatibility with the regulatory specifications.