Linux:如何使用wpa_supplicant及wpa_cli 创建p2p
注意,当 go_intent=15 时,说明强制当前设备为Go角色。最近在搞linux 系统的p2p,特此简单总结下。
·
如何使用wpa_supplicant及wpa_cli 创建p2p
最近在搞linux 系统的p2p,特此简单总结下。
1. p2p_connect 方式协商P2P
使用p2p_connect的方式,其完整命令如下:
wpa_supplicant -B -i wlan0 -c /data/cfg/wpa_supplicant.conf
wpa_cli
p2p_find
p2p_connect 52:7c:85:b2:de:34 pbc go_intent=1 (当go_intent=15时,强制当前设备为GO角色)
p2p_group_remove p2p-wlan0-0
完整示例如下:
[root:/]# wpa_supplicant -B -i wlan0 -c /data/cfg/wpa_supplicant.conf
Successfully initialized wpa_supplicant
[root:/]# wpa_cli
Selected interface 'p2p-dev-wlan0'
// 1. 使能p2p 且允许被其他设备搜索到
> p2p_find
OK
<3>P2P-DEVICE-FOUND 7e:76:68:0e:d7:d9 p2p_dev_addr=7e:76:68:0e:57:d9 pri_dev_type=10-0050F204-5 name='HUAWEI Mate 20 Pro (UD)' config_methods=0x188 dev_capab=0x25 group_capab=0x2b vendor_elems=1 new=1
// 2. 当其他设备搜索到当前设备时,会发起连接请求
<3>P2P-GO-NEG-REQUEST 52:7c:85:b2:de:34 dev_passwd_id=4 go_intent=14
// 3. 收到连接请求后通过 p2p_connect 连接其mac, 角包为两者协商
> p2p_connect 52:7c:85:b2:de:34 pbc go_intent=1
OK
<3>P2P-FIND-STOPPED
// 4. 协商结果,当前设备为 client角色,其他设备为 GO角色
<3>P2P-GO-NEG-SUCCESS role=client freq=5180 ht40=1 peer_dev=52:7c:85:b2:de:34 peer_iface=72:ec:4b:ac:5a:53 wps_method=PBC
<3>P2P-GROUP-FORMATION-SUCCESS
<3>P2P-GROUP-STARTED p2p-wlan0-0 client ssid="DIRECT-UC-HUAWEI Mate 30 Pro" freq=5180 psk=96ffd94980aa6e6d103d01af20a293d5d566bd49e68b29f110e10df537ad7306 go_dev_addr=52:7c:85:b2:de:34 [PERSISTENT]
// 5. 断开连接
> p2p_group_remove p2p-wlan0-0
OK
<3>P2P-GROUP-REMOVED p2p-wlan0-0 client reason=REQUESTED
注意,当 go_intent=15 时,说明强制当前设备为Go角色。
> p2p_find
OK
<3>P2P-DEVICE-FOUND 52:7c:85:b2:de:34 p2p_dev_addr=52:7c:85:b2:de:34 pri_dev_type=10-0050F204-5 name='HUAWEI Mate 30 Pro' config_methods=0x188 dev_capab=0x25 group_capab=0x0 vendor_elems=1 new=0
<3>P2P-INVITATION-RECEIVED sa=52:7c:85:b2:de:34 go_dev_addr=82:c5:f2:a9:32:1d unknown-network
<3>P2P-GO-NEG-REQUEST 52:7c:85:b2:de:34 dev_passwd_id=4 go_intent=14
> p2p_connect 52:7c:85:b2:de:34 pbc go_intent=15
OK
<3>P2P-FIND-STOPPED
<3>P2P-GO-NEG-SUCCESS role=GO freq=5200 ht40=1 peer_dev=52:7c:85:b2:de:34 peer_iface=82:ba:1c:59:35:ba wps_method=PBC
<3>P2P-GROUP-FORMATION-SUCCESS
<3>P2P-GROUP-STARTED p2p-wlan0-2 GO ssid="DIRECT-VZ" freq=5200 passphrase="LRVoCUqG" go_dev_addr=82:c5:f2:a9:32:1d
<3>AP-STA-CONNECTED 82:ba:1c:59:35:ba p2p_dev_addr=52:7c:85:b2:de:34
1.1 PIN码方式加入
Steps | 设备1 (Client) | 设备2(Go) |
---|---|---|
1 | wpa_cli | wpa_cli |
2 | p2p_find | |
3 | p2p_find | |
4 | p2p_connect 82:ba:1c:59:35:ba pin go_intent=1 示例:10632994 | |
5 | p2p_connect 52:7c:85:b2: de:34 10632994 go_intent=15 | |
6 | ifconfig p2p-wlan0-0 169.254.108.49 netmask 255.255.0.0 | ifconfig p2p-wlan0-0 169.254.108.1 netmask 255.255.0.0 |
7 | ping 169.254.108.1 | ping 169.254.108.49 |
1.2 PBC方式加入
Steps | 设备1 (Client) | 设备2(Go) |
---|---|---|
1 | wpa_cli | wpa_cli |
2 | p2p_find | |
3 | p2p_find | |
4 | p2p_connect 82:ba:1c:59:35:ba pbc go_intent=1 | |
5 | p2p_connect 52:7c:85:b2: de:34 pbc go_intent=14 | |
6 | ifconfig p2p-wlan0-0 169.254.108.49 netmask 255.255.0.0 | ifconfig p2p-wlan0-0 169.254.108.1 netmask 255.255.0.0 |
7 | ping 169.254.108.1 | ping 169.254.108.49 |
2. p2p_group_add 方式提前创建Group 组
2.1 PBC方式加入
Steps | 设备1 (GO) | 设备2(Client) |
---|---|---|
1 | wpa_cli | wpa_cli |
2 | p2p_group_add | |
3 | Ctrl-c to exit | |
4 | ifconfig p2p-wlan0-0 169.254.108.1 netmask 255.255.0.0 | |
5 | dnsmasq -C /data/bin/dnsmasq.conf --interface=p2p-wlan0-0 --no-dhcp-interface=usb0 | |
6 | p2p_find | |
7 | p2p_connect 82:ba:1c:59:35:ba pbc join | |
8 | wpa_cli -i p2p-wlan0-0 wps_pbc | Ctrl-c to exit |
9 | ping 169.254.108.49 | ping 169.254.108.1 |
2.2 PIN码方式加入(from GO)
Steps | 设备1 (GO) | 设备2(Client) |
---|---|---|
1 | wpa_cli | wpa_cli |
2 | p2p_group_add | |
3 | Ctrl-c to exit | |
4 | wpa_cli -i p2p-wlan0-0 wps_pin any (shows <pin>,如: 73077947) | |
5 | ifconfig p2p-wlan0-0 169.254.108.1 netmask 255.255.0.0 | |
6 | dnsmasq -C /data/bin/dnsmasq.conf --interface=p2p-wlan0-0 --no-dhcp-interface=usb0 | |
7 | p2p_find | |
8 | p2p_connect 82:ba:1c:59:35:ba 73077947 join | |
9 | wpa_cli -i p2p-wlan0-0 wps_pbc | Ctrl-c to exit |
10 | ping 169.254.108.49 | ping 169.254.108.1 |
2.3 PIN码方式加入(from Client)
Steps | 设备1 (GO) | 设备2(Client) |
---|---|---|
1 | wpa_cli | wpa_cli |
2 | p2p_group_add | |
3 | Ctrl-c to exit | |
4 | ifconfig p2p-wlan0-0 169.254.108.1 netmask 255.255.0.0 | |
5 | dnsmasq -C /data/bin/dnsmasq.conf --interface=p2p-wlan0-0 --no-dhcp-interface=usb0 | |
6 | p2p_find | |
7 | p2p_connect 82:ba:1c:59:35:ba pin join 示例:10632994 | |
8 | wpa_cli -i p2p-wlan0-0 wps_pin any 10632994 | |
9 | ping 169.254.108.49 | ping 169.254.108.1 |
2.4 Invite方式加入
Steps | 设备1 (GO) | 设备2(Client) |
---|---|---|
1 | wpa_cli | wpa_cli |
2 | p2p_group_add | |
3 | Ctrl-c to exit | |
4 | ifconfig p2p-wlan0-0 169.254.108.1 netmask 255.255.0.0 | |
5 | dnsmasq -C /data/bin/dnsmasq.conf --interface=p2p-wlan0-0 --no-dhcp-interface=usb0 | |
6 | p2p_find | |
7 | p2p_invite group=p2p-p2p0-0 peer=82:ba:1c:59:35:ba | |
8 | p2p_connect 52:7c:85:b2: de:34 pbc join | |
9 | wpa_cli -i p2p-wlan0-0 wps_pbc | Ctrl-c to exit |
9 | ping 169.254.108.49 | ping 169.254.108.1 |
3. dnsmasq.conf 及 wpa_supplicant.conf 内容
3.1 dnsmasq.conf
user=root
interface=wlan0 p2p-dev-wlan0
#listen-address=127.0.0.1
dhcp-range=169.254.108.2,169.254.108.51
#server=8.8.8.8
3.2 wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
#update_config=1
device_name=p2p-5G-test
device_type=10-0050F204-5
config_methods=display push_button keypad virtual_push_button physical_display
p2p_add_cli_chan=1
p2p_go_ht40=1
pmf=1
network={
ssid="SSID"
psk="PASSWORD"
key_mgmt=WPA-PSK
priority=1
}
network={
ssid="DIRECT-p2p-5G-test"
bssid=82:c5:f2:a9:32:1d
psk="123456789"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP
auth_alg=OPEN
mode=3
disabled=2
}
ap_scan=1
network={
ssid="TP-LINK_aaaa"
psk="135246789"
key_mgmt=WPA-PSK
priority=1
}
详细可参考:《Wi-Fi direct》
版权声明
本文转自: https://blog.csdn.net/Ciellee/article/details/117529523
更多推荐
已为社区贡献7条内容
所有评论(0)