tests: Use Wlantest class in test_autogo_tdls
[mech_eap.git] / tests / hwsim / test_p2p_autogo.py
1 #!/usr/bin/python
2 #
3 # P2P autonomous GO test cases
4 # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
5 #
6 # This software may be distributed under the terms of the BSD license.
7 # See README for more details.
8
9 import time
10 import subprocess
11 import logging
12 logger = logging.getLogger(__name__)
13
14 import hwsim_utils
15 from wlantest import Wlantest
16
17 def autogo(go):
18     logger.info("Start autonomous GO " + go.ifname)
19     res = go.p2p_start_go()
20     logger.debug("res: " + str(res))
21
22 def connect_cli(go, client):
23     logger.info("Try to connect the client to the GO")
24     pin = client.wps_read_pin()
25     go.p2p_go_authorize_client(pin)
26     client.p2p_connect_group(go.p2p_dev_addr(), pin, timeout=60)
27     logger.info("Client connected")
28     hwsim_utils.test_connectivity_p2p(go, client)
29
30 def test_autogo(dev):
31     """P2P autonomous GO and client joining group"""
32     autogo(dev[0])
33     connect_cli(dev[0], dev[1])
34     dev[0].remove_group()
35     try:
36         dev[1].remove_group()
37     except:
38         pass
39
40 def test_autogo_2cli(dev):
41     """P2P autonomous GO and two clients joining group"""
42     autogo(dev[0])
43     connect_cli(dev[0], dev[1])
44     connect_cli(dev[0], dev[2])
45     hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
46     dev[2].remove_group()
47     dev[1].remove_group()
48     dev[0].remove_group()
49
50 def test_autogo_tdls(dev):
51     """P2P autonomous GO and two clients using TDLS"""
52     wt = Wlantest()
53     go = dev[0]
54     logger.info("Start autonomous GO with fixed parameters " + go.ifname)
55     id = go.add_network()
56     go.set_network_quoted(id, "ssid", "DIRECT-tdls")
57     go.set_network_quoted(id, "psk", "12345678")
58     go.set_network(id, "mode", "3")
59     go.set_network(id, "disabled", "2")
60     res = go.p2p_start_go(persistent=id)
61     logger.debug("res: " + str(res))
62     wt.flush()
63     wt.add_passphrase("12345678")
64     connect_cli(go, dev[1])
65     connect_cli(go, dev[2])
66     hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
67     bssid = dev[0].p2p_interface_addr()
68     addr1 = dev[1].p2p_interface_addr()
69     addr2 = dev[2].p2p_interface_addr()
70     dev[1].tdls_setup(addr2)
71     time.sleep(1)
72     hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
73     conf = wt.get_tdls_counter("setup_conf_ok", bssid, addr1, addr2);
74     if conf == 0:
75         raise Exception("No TDLS Setup Confirm (success) seen")
76     dl = wt.get_tdls_counter("valid_direct_link", bssid, addr1, addr2);
77     if dl == 0:
78         raise Exception("No valid frames through direct link")
79     wt.tdls_clear(bssid, addr1, addr2);
80     dev[1].tdls_teardown(addr2)
81     time.sleep(1)
82     teardown = wt.get_tdls_counter("teardown", bssid, addr1, addr2);
83     if teardown == 0:
84         raise Exception("No TDLS Setup Teardown seen")
85     wt.tdls_clear(bssid, addr1, addr2);
86     hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
87     ap_path = wt.get_tdls_counter("valid_ap_path", bssid, addr1, addr2);
88     if ap_path == 0:
89         raise Exception("No valid frames via AP path")
90     direct_link = wt.get_tdls_counter("valid_direct_link", bssid, addr1, addr2);
91     if direct_link > 0:
92         raise Exception("Unexpected frames through direct link")
93     idirect_link = wt.get_tdls_counter("invalid_direct_link", bssid, addr1,
94                                        addr2);
95     if idirect_link > 0:
96         raise Exception("Unexpected frames through direct link (invalid)")
97     dev[2].remove_group()
98     dev[1].remove_group()
99     dev[0].remove_group()