WIFI Direct

安装必要软件:
iw
wpa-supplicant

查看无线网卡是否支持WIFI Direct
$ sudo iw list

GREP查看, 如果有以下的模式:
?* IBSS
?* managed
?* monitor
?* AP
?* P2P-GO
?* P2P-Client

如果看到 P2P-GO(Group Owner) 和 P2P-Client,
你的无线网卡是支持 Wi-Fi Direct 的了.

$  sudo wpa_cli
一些P2P 的终端命令
1.p2p_find
2.p2p_stop_find
3.p2p_connect
4.p2p_invite
5.p2p_group_add
6.p2p_remove_group
7.terminate
8.status

Wi-Fi Direct 的连接方法:
1.PBC – Push Button Control method
2.PIN – Secret PIN number method
3.Invite – Invitation Method



wpa_supplicant.conf – P2P 方面的配置:
 ctrl_interface=/var/run/wpa_supplicant
 # For Android Terminals un-comment below line & comment above Line
 #ctrl_interface=DIR=/data/system/wpa_supplicant GROUP=wifi

ap_scan=1
device_name=Terminal-1
device_type=1-0050F204-1
driver_param=use_p2p_group_interface=1

# If you need to modify the group owner intent, 0-15, the higher
# number indicates preference to become the GO. You can also set
# this on p2p_connect commands.
#p2p_go_intent=15

# optional, can be useful for monitoring, forces
# wpa_supplicant to use only channel 1 rather than
# 1, 6 and 11:
#p2p_listen_reg_class=81
#p2p_listen_channel=1
#p2p_oper_reg_class=81
#p2p_oper_channel=1

Terminal-1: (一号终端机, 可能是一个LINUX PC,或 一个 ANDROID 设备) 
$ sudo vi /etc/wpa_supplicant-t1.conf

ctrl_interface=/var/run/wpa_supplicant
 ap_scan=1
 device_name=Terminal-1
 device_type=1-0050F204-1
 driver_param=use_p2p_group_interface=1

Terminal-2:  (二号终端机, 可能是一个LINUX PC,或 一个 ANDROID 设备) 
$ sudo vi /etc/wpa_supplicant-t2.conf

ctrl_interface=/var/run/wpa_supplicant
 ap_scan=1
 device_name=Terminal-2
 device_type=1-0050F204-1
 driver_param=use_p2p_group_interface=1

Terminal-1: run wpa_supplicant as daemon
sudo ./wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant-t1.conf -Bd
Terminal-2: run wpa_supplicant as daemon
$ sudo ./wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wpa_supplicant-t2.conf -Bd
Terminal-1: wpa_cli – client
$ sudo ./wpa_cli -i wlan0
Terminal-2: wpa_cli – client
$ sudo ./wpa_cli -i wlan0

Wi-Fi Direct 的连接PBC Method方法 
Terminal-1:
  > p2p_find
Terminal-2:
 >p2p_find
 >p2p_peers
 <Terminal-1 Mac Address>
Terminal-1:
 > p2p_peers
<Terminal-2 MAC Address>
Terminal-2:
 > p2p_find
 > p2p_peers
 <Terminal-1 MAC Address>
Terminal-1:
 > p2p_connect pbc auth go_intent=7 freq=2412  #channel-1
?Here GO_INTENT value is very important. Because it decides P2P-GO negotiation.
?Who is having higher GO_INTENT will be come P2P-GO, the lowest one will become P2P-Client.
?GO_INTENT values ranges from 0 to 15
?You can choose any channel by changing the frequency to 2.4GHz/5GHz bands..
Terminal-2:
 > p2p_connect <Terminal-1 MAC Address> pbc freq=2412 go_intent=7
 > status # This will print the connection status
?Here tie-breaker bit will be set, since the GO_INTENT values are same. Either Terminal-1 or Terminal-2 will become P2P-GO(SoftAP), other terminal will act as P2P-Client.
?New P2P interface will be created, you can check using ifconfig. i.e. p2p-wlan0
Terminal-1:
 $ sudo ifconfig p2p-wlan0 192.168.2.1 up #P2P-GO
 $ sudo iw dev wlan0
$ sudo iw dev p2p-wlan0
Terminal-2:
 $ sudo ifconfig p2p-wlan0 192.168.2.2 up #P2P-Client
 $ sudo iw dev wlan0
$ sudo iw dev p2p-wlan0 link #p2p-wlan0 will keep changing.

Ping Test
Terminal-1:
$ ping 192.168.2.2
Terminal-2:
$ ping 192.168.2.1


本文转载至:http://blog.csdn.net/myxmu/article/details/12249751


本文描述了用iperf测试wifi direct的传输速度的方法。

1.推送iperf文件到待测试的两个手机


adb remount
adb push iperf /system/bin
adb shell
cd /system/bin/
chmod 777 iperf


2.两手机进行wifi direct连接


首先,对所有已保存的ap进行取消保存的操作。
然后wifi direct连接。

3.获取手机的ip地址

adb shell
ifconfig p2p0

4.在一个手机上启iperf的server

cd /system/bin/
iperf -s

5.在另一个手机上启iperf的client端

cd /system/bin/
iperf -c [另一手机的ip地址] -i 3 -t 180
这样就可以了。
-i 3表示每隔3s报告一次传输速度。
-t 180 表示总共处理180s。

### WiFi Direct 技术介绍 WiFi Direct 是一种允许无线设备之间无需通过传统路由器即可直接相互通信的技术[^1]。这项技术由 Wi-Fi Alliance 在 2010 年推出,旨在简化设备之间的连接过程并提高数据传输效率。 #### 特点和优势 相比于传统的 WLAN 连接方式以及蓝牙等其他短距离通信协议,WiFi Direct 提供更快的数据传输速率和更远的有效范围。尽管其能耗相对较高,但在许多应用场景下仍具有明显的优势: - **高速率**:提供更高的带宽用于文件共享和其他多媒体应用; - **广覆盖**:有效操作距离超过大多数个人区域网络技术; - **易配置**:支持一键式简单配对机制; ### 工作原理 当两个兼容 WiFi Direct 的设备想要建立连接时,其中一个会临时充当组所有者(Group Owner),类似于小型 AP 的角色,而另一个则作为客户端加入该小组。一旦建立了这样的关系,则可以在两者间形成一个独立的小型局域网来进行高效的信息交换。 具体来说,在初始化阶段,双方先执行发现流程来识别彼此的存在及其能力属性。之后协商决定哪个节点成为 GO (Group Owner),这通常基于某些预定义的标准或用户输入的选择。成功选定后,GO 将广播 SSID 和安全参数给潜在成员以便它们能够关联进来完成整个握手过程[^3]。 ```python import wifi_direct_module as wdm deviceA = wdm.Device() deviceB = wdm.Device() # 发现附近可用的WiFi Direct 设备 nearby_devices = deviceA.discover_peers() if nearby_devices: go_negotiation_result = deviceA.negotiate_group_owner(deviceB) if go_negotiation_result['is_go']: ssid, password = generate_network_info() # 假设这是创建新的SSID和密码的方法 setup_wifi_network(ssid, password) ``` ### 应用场景 由于具备快速简便的特点,WiFi Direct 可广泛应用于多个领域内促进不同类型的电子装置互相协作交流。例如智能家居控制系统里,各种传感器、摄像头或者其他智能家电可以通过此方法迅速组建起局部通讯环境从而更好地服务于家庭自动化需求。 此外,在移动计算环境中也很有用处——比如智能手机和平板电脑之间分享照片视频资料或是投影屏幕显示内容等等。它同样适用于打印机直连打印作业、游戏机手柄同步等功能扩展上。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值