How to use wpa_supplicant (P2P mode)

What is P2P (Wi-Fi Direct)?

So far, I've explained how to use hostap's wpa_supplicant (client mode) and how to use hostapd (AP mode).

This time I would like to explain how to use wpa_supplicant (P2P mode).

 

P2P (Wi-Fi Direct) is a function that connects P2P compatible devices to form a P2Pgroup and uses a Peer-to-Peer connection without connecting to an AP.

Unlike ad-hoc, GC (GroupClient) / GO (GroupOwner) roles are allocated and communicated.

* GC = Client/GO = AP.

There are three types of devices that appear when using P2P:

- P2P device: P2P compatible device that does not form a P2P group

- Group client: A device that has formed a P2P group and acts as a Group client

- Group owner: A device that has formed a P2P group and operates as a Group owner

P2P behavior

There are several P2P connection procedures. This time, I will explain how to connect 1 and 2.

1. P2P device -> P2P device

Create a new P2P group: Connection between P2P devices that do not form a P2P group

2. P2P device -> P2P GO

Connect to already formed P2P group: P2P device connects to P2P group as Group client

3. P2P GO -> P2P device

Invite P2P device from Group owner to already formed P2P group: Invite and connect P2P device from Group owner to P2P group

4. P2P GO - P2P device ->P2P device

Invite from Group client to already formed P2P group: Invite and connect P2P device from Group client to P2P group

 

The basic connection sequence looks like this:

(1).Search/listen

Look for P2P devices. The two devices each search/listen repeatedly to find each other.

(2).ProvisionDiscovery

Notifies the WPS method used when connecting (PBC/PIN display/PIN keypad, etc.).

(3).GO negotiation

Decide which device will be GO. (The one with the larger value of go_intent becomes GO.)

(4).Provisioning

Run WPS and run Credential.

(5).4Way-handshake

Exchange key information.

environment

This time, the environment used is Ubuntu16.04 + Kernel4.9.11 +QCA9377(Qualcomm Wireless LAN products) will be combined.

Setting and starting wpa_supplicant

There are several ways to activate the p2p mode, but this time we will activate using the interface for P2P.

wpa_supplicant -ip2p0 -Dnl80211 -c p2p_supplicant.conf

Configure p2p_supplicant.conf as follows:

ctrl_interface=/var/run/p2p_supplicant country=JP device_name=Test device2 <= ユーザーフレンドリーなデバイス名を設定します。 persistent_reconnect=1 <= "persistent"の招待時に自動で接続します。 p2p_no_group_iface=1 <= p2p0をP2P Groupのコントロール用インターフェースとして使用します。設定しない場合“p2p-p2p0-0”のようなインターフェースが、P2P Groupができたときに生成されます。

Start wpa_cli

Match the interface name when wpa_supplicant is started.

wpa_cli -ip2p0 -p/var/run/p2p_supplicant

Run Scan

For P2P, do "p2p_find" instead of "scan".

Unlike Client/AP (Legacy Wi-Fi hereafter), it will call back the found device information at any time.

Main device information

p2p_dev_addr: address for P2P connection

pri_dev_type: device information

name: device name

config_methods: Supported WPS method information

dev_capab: Device capability information

gtoup_capab: group capability information

> p2p_find
OK
<3>CTRL-EVENT-SCAN-STARTED 
<3>P2P-DEVICE-FOUND 11:22:33:44:55:66 p2p_dev_addr=11:22:33:44:55:66 pri_dev_type=0-00000000-0 name='' config_methods=0x1108 dev_capab=0x25 group_capab=0x0 vendor_elems=1 new=1

connection

If the connection destination is a P2P device:

p2p_connect <p2p device address> <config_method>: Execute the connection process.

This time, we will connect with an easy-to-understand PBC (PushButton).

First, send a connection request (GO negotiation request) to the connection destination. (Because you don't know when the connected party will reply, it will wait for a GO negotiation request from the connected party.)

If the peer accepts the connection, it sends a GO negotiation request back to the originator.

Triggered by a GO negotiation request from the connection destination, the connection source determines which device is in charge of Group client/Group owner, and executes WPS with the selected config_method (PBC) to connect.

接続元のP2P device > p2p_connect 11:22:33:44:55:66 pbc <= 接続先にGO negotiation requestを送信します。 OK <3>P2P-FIND-STOPPED <3>P2P-GO-NEG-SUCCESS role=client freq=5240 ht40=0 peer_dev=11:22:33:44:55:66 peer_iface=11:22:33:44:55:66 wps_method=PBC <= P2P clientでconfig_methodとして“PBC”を選択。 <3>CTRL-EVENT-SCAN-RESULTS <3>WPS-AP-AVAILABLE <3>P2P-GROUP-FORMATION-SUCCESS <= 接続先からのGO negotiation requestを受けGroup client/Group ownerを決定します。 <3>CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD <3>CTRL-EVENT-REGDOM-CHANGE init=USER type=COUNTRY alpha2=JP <3>P2P-GROUP-STARTED p2p0 client ssid="DIRECT-Eb" freq=5240 psk=57c0f5512daa0d44399bc35d530212721885abcad660850a9ea0ff0fbad86291 go_dev_addr=11:22:33:44:55:66 <= 接続元がGroup clientとして接続完了。P2P groupのSSIDは“DIRECT-Eb”(Legacy clientからもpskで接続可能)。
接続先のP2P device <3>CTRL-EVENT-SCAN-STARTED > P2P-GO-NEG-REQUEST 66:55:44:33:22:11 dev_passwd_id=4 go_intent=7 <= 接続元からのGO negotiation requestを受信。 <3>P2P-GO-NEG-REQUEST 66:55:44:33:22:11 dev_passwd_id=4 go_intent=7 <3>CTRL-EVENT-SCAN-STARTED > p2p_connect 66:55:44:33:22:11 pbc <= 受け入れるため接続コマンドを実行します。 P2P-FIND-STOPPED OK <3>P2P-FIND-STOPPED > P2P-GO-NEG-SUCCESS role=GO freq=5240 ht40=0 peer_dev=66:55:44:33:22:11 peer_iface=66:55:44:33:22:11 wps_method=PBC <= 接続先がGroup ownerとしてP2P Groupを形成。 [ 1303.755698] IPv6: ADDRCONF(NETDEV_UP): p2p0: link is not ready <3>P2P-GO-NEG-SUCCESS role=GO freq=5240 ht40=0 peer_dev66:55:44:33:22:11 peer_iface=66:55:44:33:22:11 wps_method=PBC [ 1303.901587] IPv6: ADDRCONF(NETDEV_CHANGE): p2p0: link becomes ready p2p0: interface state UNINITIALIZED->ENABLED p2p0: AP-ENABLED p2p0: CTRL-EVENT-CONNECTED - Connection to 11:22:33:44:55:66 completed [id=0 id_str=] p2p0: WPS-PBC-ACTIVE p2p0: CTRL-EVENT-CHANNEL-SWITCH freq=5240 ht_enabled=1 ch_offset=0 ch_width=20 MHz cf1=5240 cf2=0 p2p0: CTRL-EVENT-CHANNEL-SWITCH freq=5240 ht_enabled=1 ch_offset=0 ch_width=20 MHz cf1=5240 cf2=0 dfs=0 p2p0: AP-CSA-FINISHED freq=5240 dfs=0 p2p0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0 p2p0: CTRL-EVENT-EAP-STARTED 66:55:44:33:22:11 p2p0: CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=1 p2p0: CTRL-EVENT-EAP-PROPOSED-METHOD vendor=14122 method=254 p2p0: WPS-REG-SUCCESS 66:55:44:33:22:11 8a9b5c52-863a-503b-9335-5c200b832f0e P2P-GROUP-FORMATION-SUCCESS <3>P2P-GROUP-FORMATION-SUCCESS > P2P-GROUP-STARTED p2p0 GO ssid="DIRECT-Eb" freq=5240 go_dev_addr=11:22:33:44:55:66 <3>P2P-GROUP-STARTED p2p0 GO ssid="DIRECT-Eb" freq=5240 passphrase="CLgJ3w4j" go_dev_addr=11:22:33:44:55:66 > p2p0: WPS-PBC-DISABLE p2p0: WPS-SUCCESS p2p0: CTRL-EVENT-EAP-FAILURE 66:55:44:33:22:11 p2p0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0 p2p0: AP-STA-CONNECTED 66:55:44:33:22:11 p2p_dev_addr=66:55:44:33:22:11 AP-STA-CONNECTED 66:55:44:33:22:11 p2p_dev_addr=66:55:44:33:22:11 p2p0: EAPOL-4WAY-HS-COMPLETED 66:55:44:33:22:11 <3>AP-STA-CONNECTED 66:55:44:33:22:11 p2p_dev_addr=66:55:44:33:22:11

If the connection destination is P2P GO:

p2p_connect <p2p device address> <config_method> join: Execute connection process.

Under the hood, it will run WPS and connect with the config_method of your choice.

If the destination is GO, GO negotiation is not executed because the role has already been decided.

A ProvisionDiscoveryRequest is sent from the GC, and WPS is started on the GO side.

接続元のP2P device > p2p_find OK <3>CTRL-EVENT-SCAN-STARTED > P2P-DEVICE-FOUND 11:22:33:44:55:66 p2p_dev_addr=11:22:33:44:55:66 pri_dev_type=0-00000000-0 name='' config_methods=0x1108 dev_capab=0x25 group_capab=0x9 vendor_elems=1 new=1 <3>P2P-DEVICE-FOUND 11:22:33:44:55:66 p2p_dev_addr=11:22:33:44:55:66 pri_dev_type=0-00000000-0 name='' config_methods=0x1108 dev_capab=0x25 group_capab=0x9 vendor_elems=1 new=1 <3>CTRL-EVENT-SCAN-STARTED > p2p_connect 11:22:33:44:55:66 pbc join <= PBCでGOに対して接続要求を出します。 P2P-FIND-STOPPED OK <3>P2P-FIND-STOPPED <3>CTRL-EVENT-SCAN-STARTED <3>CTRL-EVENT-SCAN-RESULTS <3>WPS-AP-AVAILABLE > p2p0: WPS-PBC-ACTIVE <3>CTRL-EVENT-SCAN-RESULTS <3>WPS-AP-AVAILABLE > p2p0: Trying to associate with 11:22:33:44:55:66 (SSID='DIRECT-dP' freq=5180 MHz) p2p0: Associated with 11:22:33:44:55:66 p2p0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0 p2p0: CTRL-EVENT-EAP-STARTED EAP authentication started p2p0: CTRL-EVENT-EAP-PROPOSED-METHOD vendor=14122 method=1 p2p0: CTRL-EVENT-EAP-METHOD EAP vendor 14122 method 1 (WSC) selected p2p0: WPS-CRED-RECEIVED p2p0: WPS-SUCCESS P2P-GROUP-FORMATION-SUCCESS <3>P2P-GROUP-FORMATION-SUCCESS > p2p0: CTRL-EVENT-EAP-FAILURE EAP authentication failed p2p0: CTRL-EVENT-DISCONNECTED bssid=11:22:33:44:55:66 reason=3 locally_generated=1 p2p0: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD <3>CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD > p2p0: Trying to associate with SSID 'DIRECT-dP' p2p0: Associated with 11:22:33:44:55:66 p2p0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0 p2p0: WPA: Key negotiation completed with 11:22:33:44:55:66 [PTK=CCMP GTK=CCMP] p2p0: CTRL-EVENT-CONNECTED - Connection to 11:22:33:44:55:66 completed [id=0 id_str=] P2P-GROUP-STARTED p2p0 client ssid="DIRECT-dP" freq=5180 go_dev_addr=11:22:33:44:55:66 <3>P2P-GROUP-STARTED p2p0 client ssid="DIRECT-dP" freq=5180 psk=ee5fb984cc62fb35f6d05a18232e0f991b3c88b4787c0ae64863e3363413b0f4 go_dev_addr=11:22:33:44:55:66
接続先のGroup owner <3>P2P-PROV-DISC-PBC-REQ 66:55:44:33:22:11 p2p_dev_addr=66:55:44:33:22:11 pri_dev_type=0-00000000-0 name='' config_methods=0x1108 dev_capab=0x25 group_capab=0x0 group=p2p0 <= 接続元からの接続要求。 > wps_pbc <= PBCを実行します。 p2p0: WPS-PBC-ACTIVE OK <3>WPS-PBC-ACTIVE <3>CTRL-EVENT-SCAN-RESULTS <3>WPS-ENROLLEE-SEEN 66:55:44:33:22:11 bfb33606-2998-5883-8bc0-66d39f85d094 0-00000000-0 0x3148 4 1 [ ] <3>RX-PROBE-REQUEST sa=66:55:44:33:22:11 signal=-4000 <3>WPS-ENROLLEE-SEEN 66:55:44:33:22:11 bfb33606-2998-5883-8bc0-66d39f85d094 0-00000000-0 0x3148 4 1 [ ] <3>RX-PROBE-REQUEST sa=66:55:44:33:22:11 signal=-3900 <3>WPS-ENROLLEE-SEEN 66:55:44:33:22:11 bfb33606-2998-5883-8bc0-66d39f85d094 0-00000000-0 0x3148 4 1 [ ] <3>RX-PROBE-REQUEST sa=66:55:44:33:22:11 signal=-3800 p2p0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0 p2p0: CTRL-EVENT-EAP-STARTED 66:55:44:33:22:11 p2p0: CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=1 <3>CTRL-EVENT-SUBNET-STATUS-UPDATE status=0 <3>CTRL-EVENT-EAP-STARTED 66:55:44:33:22:11 <3>CTRL-EVENT-EAP-PROPOSED-METHOD vendor=0 method=1 > p2p0: CTRL-EVENT-EAP-PROPOSED-METHOD vendor=14122 method=254 <3>CTRL-EVENT-EAP-PROPOSED-METHOD vendor=14122 method=254 > p2p0: WPS-REG-SUCCESS 66:55:44:33:22:11 bfb33606-2998-5883-8bc0-66d39f85d094 <3>WPS-REG-SUCCESS 66:55:44:33:22:11 bfb33606-2998-5883-8bc0-66d39f85d094 > p2p0: WPS-PBC-DISABLE p2p0: WPS-SUCCESS p2p0: CTRL-EVENT-EAP-FAILURE 66:55:44:33:22:11 <3>WPS-PBC-DISABLE <3>WPS-SUCCESS <3>CTRL-EVENT-EAP-FAILURE 66:55:44:33:22:11 > p2p0: CTRL-EVENT-SUBNET-STATUS-UPDATE status=0 <3>CTRL-EVENT-SUBNET-STATUS-UPDATE status=0 > p2p0: AP-STA-CONNECTED 66:55:44:33:22:11 p2p_dev_addr=66:55:44:33:22:11 AP-STA-CONNECTED 66:55:44:33:22:11 p2p_dev_addr=66:55:44:33:22:11 p2p0: EAPOL-4WAY-HS-COMPLETED 66:55:44:33:22:11 <3>AP-STA-CONNECTED 66:55:44:33:22:11 p2p_dev_addr=66:55:44:33:22:11 <3>EAPOL-4WAY-HS-COMPLETED 66:55:44:33:22:11

cutting

Termination of P2P group / Leaving P2P group

p2p_group_remove <interface name of P2P group>: If the group owner, remove the P2P group. For Group clients, leave the P2P group.

Group Client側 > p2p_group_remove p2p0 p2p0: CTRL-EVENT-DISCONNECTED bssid=11:22:33:44:55:66 reason=3 locally_generated=1 P2P-GROUP-REMOVED p2p0 client reason=REQUESTED OK <3>P2P-GROUP-REMOVED p2p0 client reason=REQUESTED
Group owner側 > p2p_group_remove p2p0 P2P-GROUP-REMOVED p2p0 GO reason=REQUESTED OK > p2p0: interface state ENABLED->DISABLED p2p0: AP-DISABLED <3>AP-DISABLED > p2p0: CTRL-EVENT-DISCONNECTED bssid=11:22:33:44:55:66 reason=3 locally_generated=1 <3>CTRL-EVENT-DISCONNECTED bssid=11:22:33:44:55:66 reason=3 locally_generated=1

Saving P2P networks

If you save P2P network in conf file like Legacy Wi-Fi, next time you connect, you can connect faster in previous role without GO negotiation/WPS.

command:

p2p_connect 11:22:33:44:55:66 pbc persistent

Once connected, a network block will be created in p2p_supplicant.conf as shown below.

ctrl_interface=/var/run/p2p_supplicant update_config=1 device_name=Test device1 persistent_reconnect=1 p2p_no_group_iface=1 country=JP network={ ssid="DIRECT-v6" bssid=66:55:44:33:22:11 <= GOのデバイスアドレス。 psk="43FGe2rD" proto=RSN key_mgmt=WPA-PSK pairwise=CCMP auth_alg=OPEN mode=3 disabled=2 p2p_client_list=11:22:33:44:55:66 <= 自分がGOの場合、Clientデバイスのリストが表示されます。 }
p2p_connect 11:22:33:44:55:66 pbc persistent > P2P-GROUP-STARTED p2p0 client ssid="DIRECT-v6" freq=5180 go_dev_addr=66:55:44:33:22:11 [PERSISTENT] <- P2P-GROUP-STARTEDで[PERSISTENT]となっている場合はP2P Group情報が保存されています。 保存されているP2P Group情報で再度P2P Groupを作成する場合 > list_networks network id / ssid / bssid / flags 1 DIRECT-v6 66:55:44:33:22:11 [DISABLED][P2P-PERSISTENT] > p2p_invite persistent=1 peer=11:22:33:44:55:66 <= persistentの’1’はlist_networksの“network ID” OK <3>P2P-FIND-STOPPED <3>P2P-INVITATION-RESULT status=0 <= p2p_inviteの受信側のp2p_supplicant.confに“persistent_reconnect=1”が設定されていれば自動で接続されます。 <3>AP-ENABLED <3>CTRL-EVENT-CONNECTED - Connection to 66:55:44:33:22:11 completed [id=2 id_str=] <3>P2P-GROUP-STARTED p2p0 GO ssid="DIRECT-v6" freq=5180 passphrase="43FGe2rD" go_dev_addr=66:55:44:33:22:11 [PERSISTENT] <3>CTRL-EVENT-CHANNEL-SWITCH freq=5180 ht_enabled=1 ch_offset=1 ch_width=80 MHz cf1=5210 cf2=0 <3>CTRL-EVENT-CHANNEL-SWITCH freq=5180 ht_enabled=1 ch_offset=1 ch_width=80 MHz cf1=5210 cf2=0 dfs=0 <3>AP-CSA-FINISHED freq=5180 dfs=0 <3>WPS-ENROLLEE-SEEN 11:22:33:44:55:66 484189fc-758a-513e-bd71-8d1a51775c6c 0-00000000-0 0x3148 0 0 [Test device2] <3>RX-PROBE-REQUEST sa=11:22:33:44:55:66 signal=-3500 <3>CTRL-EVENT-SUBNET-STATUS-UPDATE status=0 <3>AP-STA-CONNECTED 11:22:33:44:55:66 p2p_dev_addr=11:22:33:44:55:66 <3>EAPOL-4WAY-HS-COMPLETED 11:22:33:44:55:66

Summary

This time, we have explained the basic usage of P2P.

Compared to Legacy Wi-Fi, P2P has a complicated connection procedure and is difficult to understand. It's just connected in the same way as

The advantage of using P2P is that large-capacity data communication is possible even in an environment without an AP. (Miracast etc. can also be used on P2P.)

Many Android devices are also compatible, so why not give it a try?

 

Also, although I did not explain this time, it is also possible to connect concurrently (using Legacy Wi-Fi and P2P at the same time) by using separate interfaces on the Client side and P2P side on Qualcomm devices.

*QCA9377 is limited to SCC (Same channel conccurent)

If you are interested, please contact us below.

Inquiry

If you have any questions about Qualcomm products, please contact us from the link below.

To Qualcomm manufacturer information Top

If you want to return to Qualcomm manufacturer information top page, please click below.

Related information