3

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,

  1. The connection automatically gets disconnected after a few seconds
  2. When I tried to reconnect the android device, it shows invited forever(but disconnecting and connecting n times between 2 Android devices works fine and the connections are not getting disconnected). I am able to connect to the Raspberry PI only after terminating wpa supplicant and starts the process again. What is wrong with this configuration? What changes should be made to make the connection persistent? Any help will be appreciated, please ask if you need more details.

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
Sony
  • 145
  • 6

1 Answers1

3

I have observed this behavior when one device does not get an ip address. Then the connection is shut down after some seconds. You have to ensure that there is a DHCP server running that will give the devices an ip address. WiFi Direct is managed in groups and each group has a group owner (GO). Because there must only one DHCP server run per group, only the group owner is allowed to have a DHCP server. The two android devices will negotiate which is the group owner and that runs a DHCP server.

This negotiation is controlled with the parameter p2p_go_intent. You set it by default to p2p_go_intent=1 so it is very unlikely that the RasPi becomes the group owner. The android device will get it and send the RasPi an ip address from its DHCP server but the RasPi don't see it because it has a static one. So the communication is shut down after some seconds.

Your setup is a bit more complicated because you use p2p_group_add. This will set up a P2P group owner manually (i.e., without group owner negotiation with a specific peer). This is also known as autonomous GO and it behaves more than an access point with another connection mechanism.

You have to ensure that the RasPi always becomes the group owner, but not setting an autonomous GO and that it has a DHCP server installed and running on the group interface. Further information about this and how to setup a working WiFi Direct connection you can find at Setting up Wifi direct (wifi p2p) and DHCP server.

Ingo
  • 40,606
  • 15
  • 76
  • 189