I am using this configuration for wifi direct connection in Raspberry PI 2 B+
ctrl_interface=DIR=/var/run/wpa_supplicant
driver_param=use_p2p_group_interface=1
update_config=1
device_name=Raspberry_pi
device_type=1-0050F204-1
p2p_go_intent=1
p2p_go_ht40=1
country=IN
and then started wpa supplicant using
sudo wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant/p2p.conf -B
and then add new group using
sudo wpa_cli -iwlan0 p2p_group_add
and then set an IP using
ifconfig p2p-wlan0-0 192.168.1.20
and then set the pin using
sudo wpa_cli -ip2p-wlan0-0 wps_pin any 0000
up to this, everything is working fine and I am able to connect to the Raspberry Pi over wifi direct from an Android device. Now I am facing two problems,
Edit 1:
When I restart the wpa supplicant and connects for the first time, this is what I get in the log
CTRL-EVENT-EAP-STARTED 2a:3f:69:1d:ed:c5
<3>CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=1
<3>CTRL-EVENT-EAP-PROPOSED-METHOD vendor=14122 method=254
<3>WPS-REG-SUCCESS 2a:3f:69:1d:ed:c5 884efa75-0a98-52c6-85aa-07527f4a9c35
<3>WPS-SUCCESS
<3>CTRL-EVENT-EAP-FAILURE 2a:3f:69:1d:ed:c5
<3>AP-STA-CONNECTED 2a:3f:69:1d:ed:c5 p2p_dev_addr=2a:3f:69:1d:ed:c5
and after the automatic disconnection
AP-STA-DISCONNECTED 2a:3f:69:1d:ed:c5 p2p_dev_addr=2a:3f:69:1d:ed:c5
if I try to reconnect without restarting this is printed in the console
CTRL-EVENT-EAP-STARTED 2a:3f:69:1d:ed:c5
<3>CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=1
<3>CTRL-EVENT-EAP-PROPOSED-METHOD vendor=14122 method=254
<3>WPS-PIN-NEEDED 884efa75-0a98-52c6-85aa-07527f4a9c35 2a:3f:69:1d:ed:c5 [Xperia XA |MediaTek Inc.|MTK Wireless Model|1.0|2.0|10-0050F204-5]
<3>CTRL-EVENT-EAP-FAILURE 2a:3f:69:1d:ed:c5
Your Raspberry Pi is probably in the P2P Group Owner (GO) role since you are manually creating a group with the p2p_group_add
command (autonomous GO) rather than letting the devices negotiate based on their GO intent values. p2p_go_intent=1
in your config would likely have no effect in this case.
The device in the GO role should run a DHCP server in order to assign IP addresses to the connecting P2P Clients. Correspondingly, each client should run a DHCP client in order to receive an IP address.
Excerpt from Section 3.2.6.1 of the Wi-Fi P2P Technical Spec:
Higher-layer data services may use IP. The P2P Group Owner shall act as a DHCP server to provide IP addresses to the connected P2P Clients that use IP. The DHCP Server shall at a minimum support Internet Protocol version 4 (IPv4) and assignment of an IP address, subnet mask...
...A P2P Client that uses IP shall be capable of acting as a DHCP Client.
Note — While a P2P Device can select distinct IP subnets for each P2P Group for which it is P2P Group Owner, it is possible that a P2P Device connected to more than one P2P Group may end up with colliding subnets. Use of a random component in the selection of IP subnet may reduce the probability of (but not eliminate) this situation occurring
I think you will find that the Android device is waiting to receive an IP configuration via DHCP before moving on to a connected state, timing out if that does not happen.
To make the connection persistent the group needs to be created as a persistent group. You should be able to do that in the autonomous GO scenario with p2p_group_add persistent
. In the negotiated GO scenario you should be able to do something like p2p_connect <peer device address> <pbc|pin|PIN#|p2ps> [display|keypad|p2ps] persistent go_intent=15
. See the wpa_supplicant README-P2P for further details: https://w1.fi/cgit/hostap/plain/wpa_supplicant/README-P2P.
Finally, the command wps_pin any <PIN>
allows any device to connect using the provided PIN but restricts the PIN to one-time-use. Either use the wps_pin <address> <PIN>
form or set a new PIN by running wps_pin any <PIN>
again.