简体   繁体   中英

Wifi direct connection disconnects automatically after a few seconds in Raspberry Pi

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?

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.

I am running almost the very same scenario at the moment, follow the first section

Setting up a Raspberry Pi as an access point in a standalone network (NAT)

at this link in order to install/comfigure DHCP service on the Pi:

https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md

Btw, if it works for you, can you please share the order of running dhcp and enabling wifi p2p as I am sort of having trouble with p2p after enabling dhcp.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM