2013-03-02 00:05:03 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# P2P group formation test
|
|
|
|
# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
|
|
|
|
#
|
|
|
|
# This software may be distributed under the terms of the BSD license.
|
|
|
|
# See README for more details.
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
2013-03-02 10:38:56 +01:00
|
|
|
import subprocess
|
2013-03-02 00:05:03 +01:00
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from wpasupplicant import WpaSupplicant
|
|
|
|
|
|
|
|
|
2013-03-02 10:38:56 +01:00
|
|
|
def test_connectivity(ifname1, ifname2):
|
|
|
|
cmd = ["sudo",
|
|
|
|
"../../mac80211_hwsim/tools/hwsim_test",
|
|
|
|
ifname1,
|
|
|
|
ifname2]
|
|
|
|
subprocess.check_call(cmd)
|
|
|
|
|
2013-03-02 00:05:03 +01:00
|
|
|
def main():
|
|
|
|
if len(sys.argv) > 1 and sys.argv[1] == '-d':
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
else:
|
|
|
|
logging.basicConfig()
|
|
|
|
|
|
|
|
dev0 = WpaSupplicant('wlan0')
|
|
|
|
dev1 = WpaSupplicant('wlan1')
|
|
|
|
dev0.request("hello")
|
|
|
|
dev0.ping()
|
|
|
|
if not dev0.ping() or not dev1.ping():
|
|
|
|
print "No response from wpa_supplicant"
|
|
|
|
return
|
|
|
|
addr0 = dev0.p2p_dev_addr()
|
|
|
|
addr1 = dev1.p2p_dev_addr()
|
|
|
|
print "dev0 P2P Device Address: " + addr0
|
|
|
|
print "dev1 P2P Device Address: " + addr1
|
|
|
|
dev0.reset()
|
|
|
|
dev1.reset()
|
|
|
|
|
|
|
|
dev0.p2p_listen()
|
|
|
|
dev1.p2p_listen()
|
|
|
|
pin = dev0.wps_read_pin()
|
|
|
|
dev0.p2p_go_neg_auth(addr1, pin, "display")
|
|
|
|
print "Start GO negotiation"
|
|
|
|
dev1.p2p_go_neg_init(addr0, pin, "enter", timeout=15)
|
|
|
|
dev0.dump_monitor()
|
|
|
|
dev1.dump_monitor()
|
2013-03-02 10:38:56 +01:00
|
|
|
print "Group formed"
|
|
|
|
|
|
|
|
test_connectivity('wlan0', 'wlan1')
|
|
|
|
|
|
|
|
dev0.remove_group('wlan0')
|
|
|
|
try:
|
|
|
|
dev1.remove_group('wlan1')
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
print "Test passed"
|
2013-03-02 00:05:03 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|