p2praspberry-pi4wifi-directwpa-supplicantwps

Wifi direct (Wifi P2P) connection between raspberry pi 4b and android device only possible after reboot


I am trying to connect my Raspberry Pi 4b with my Android device (Google Pixel 6 with ANdroid 14) using the pbc (virtual_push_button) method. If the Raspberry Pi was freshly rebooted, there are no issues with connecting. However, if I disconnect the devices and delete the p2p-group (in this case p2p-wlan0-1) and try to connect again with the same commands, I get the following error:

P2P-GROUP-FORMATION-FAILURE

As of my setup, i followed this guide: https://raspberrypi.stackexchange.com/questions/117238/connect-android-smartphone-with-wi-fi-direct-to-a-raspberry-pi

Now a list of steps i do when trying to connect the devices:
RPI: Things i do on the Raspberry PI using the wpa_cli (started using wpa_cli -i p2p-dev-wlan0)
AD: Things i do on the Android Device

  1. AD- Going into settings to the Wifi-Direct setting and make sure the device is searching for peers
  2. RPI- find peers and list them
p2p_find
p2p_peers
  1. RPI- make sure that the found device-adress is the Android device:
p2p_peer <device-adress>
  1. AD- click on the the now visible Raspberry Pi so the status says "invited"

5.RPI- connect to the device

p2p_connect <device-adress> pbc

The first time, this works like a charm. Getting the following outputs from the wpa_cli:

<3>CTRL-EVENT-SCAN-STARTED
<3>CTRL-EVENT-SCAN-STARTED
<3>P2P-DEVICE-FOUND 66:5d:70:17:a1:4e p2p_dev_addr=66:5d:70:17:a1:4e pri_dev_type=10-0050F204-5 name='Android_M6CV' config_methods=0x188 dev_capab=0x25 group_capab=0x0 new=1
<3>P2P-PROV-DISC-PBC-REQ 66:5d:70:17:a1:4e p2p_dev_addr=66:5d:70:17:a1:4e pri_dev_type=10-0050F204-5 name='Android_M6CV' config_methods=0x188 dev_capab=0x25 group_capab=0x0
<3>P2P-PROV-DISC-PBC-REQ 66:5d:70:17:a1:4e p2p_dev_addr=66:5d:70:17:a1:4e pri_dev_type=10-0050F204-5 name='Android_M6CV' config_methods=0x188 dev_capab=0x25 group_capab=0x0
<3>P2P-GO-NEG-REQUEST 66:5d:70:17:a1:4e dev_passwd_id=4 go_intent=6
<3>CTRL-EVENT-SCAN-STARTED 9:69 pbc
> p2p_connect 66:5d:70:17:a1:4e pbc
OK
<3>P2P-FIND-STOPPED
<3>P2P-GO-NEG-SUCCESS role=GO freq=5200 ht40=1 peer_dev=66:5d:70:17:a1:4e peer_iface=ce:af:bd:69:40:c0 wps_method=PBC
<3>CTRL-EVENT-SCAN-RESULTS
<3>P2P-GROUP-FORMATION-SUCCESS
<3>P2P-GROUP-STARTED p2p-wlan0-1 GO ssid="DIRECT-ER" freq=5200 passphrase="F1vHWtHI" go_dev_addr=da:3a:dd:97:2f:6a
<3>AP-STA-CONNECTED ce:af:bd:69:40:c0 p2p_dev_addr=66:5d:70:17:a1:4e

Now to the part where things get messed up.
First i delete the p2p_group:

> p2p_group_remove p2p-wlan0-1
OK
<3>P2P-GROUP-REMOVED p2p-wlan0-1 GO reason=REQUESTED
<3>AP-STA-DISCONNECTED ba:8a:83:c2:7d:9a p2p_dev_addr=42:f3:6b:24:42:33
<3>P2P-DEVICE-LOST p2p_dev_addr=42:f3:6b:24:42:33

Now i do the EXACT same steps as i described above and get the following error from the wpa_cli:

<3>P2P-PROV-DISC-PBC-REQ 6a:44:f4:3e:e9:69 p2p_dev_addr=6a:44:f4:3e:e9:69 pri_dev_type=10-0050F204-5 name='Android_M6CV' config_methods=0x188 dev_capab=0x25 group_capab=0x0
<3>P2P-DEVICE-FOUND 6a:44:f4:3e:e9:69 p2p_dev_addr=6a:44:f4:3e:e9:69 pri_dev_type=10-0050F204-5 name='Android_M6CV' config_methods=0x80 dev_capab=0x25 group_capab=0x2a new=0
<3>P2P-GO-NEG-REQUEST 6a:44:f4:3e:e9:69 dev_passwd_id=4 go_intent=6
<3>CTRL-EVENT-SCAN-STARTED 9:69 pbc
> p2p_connect 6a:44:f4:3e:e9:69 pbc
OK
<3>P2P-FIND-STOPPED
<3>P2P-GO-NEG-SUCCESS role=GO freq=5220 ht40=1 peer_dev=6a:44:f4:3e:e9:69 peer_iface=82:71:76:45:19:02 wps_method=PBC
<3>CTRL-EVENT-SCAN-RESULTS
<3>P2P-GROUP-FORMATION-FAILURE
<3>P2P-GROUP-REMOVED wlan0 GO reason=FORMATION_FAILED

I also made sure that wpa_supplicant.service is disabled and wpa_supplicant@wlan0.service is enabled

Now why is this happening? And why does it work after rebooting the Raspberry Pi?
Is there any other service like NetworkManager who is messing up the system?

Any help appreciated and thanks in advance :D

config files:
/etc/wpa_supplicant/wpa_supplicant.conf

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

/etc/wpa_supplicant/wpa_supplicant-wlan0.config

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=DE
device_name=DIRECT-RasPi1
config_methods=virtual_push_button
# this on p2p_connect commands.
p2p_go_intent=15
# In order to support 802.11n for the p2p Group Owner
p2p_go_ht40=1

# Device type
#   6-0050F204-1 (Network Infrastructure / AP)
device_type=6-0050F204-1
driver_param=p2p_device=6

/etc/systemd/network/12-p2p-wlan0.network

[Match]
Name=p2p-wlan0-*
[Network]
Address=192.168.4.1/24
DHCPServer=yes

Solution

  • Somehow it didnt work because of the frequency of 5gHz. I added freq=2472 to the p2p_connect command and it works perfectly. Only on 2.4gHz but thats fine for me.