1 # P2P autonomous GO test cases
2 # Copyright (c) 2013, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
10 logger = logging.getLogger()
14 from wlantest import Wlantest
16 def autogo(go, freq=None):
17 logger.info("Start autonomous GO " + go.ifname)
18 res = go.p2p_start_go(freq=freq)
19 logger.debug("res: " + str(res))
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 res = client.p2p_connect_group(go.p2p_dev_addr(), pin, timeout=60)
27 logger.info("Client connected")
28 hwsim_utils.test_connectivity_p2p(go, client)
32 """P2P autonomous GO and client joining group"""
34 if "p2p-wlan" in res['ifname']:
35 raise Exception("Unexpected group interface name on GO")
36 res = connect_cli(dev[0], dev[1])
37 if "p2p-wlan" in res['ifname']:
38 raise Exception("Unexpected group interface name on client")
39 bss = dev[1].get_bss("p2p_dev_addr=" + dev[0].p2p_dev_addr())
40 if bss['bssid'] != dev[0].p2p_interface_addr():
41 raise Exception("Unexpected BSSID in the BSS entry for the GO")
43 bss = dev[1].get_bss("ID-" + id)
45 raise Exception("Could not find BSS entry based on id")
46 res = dev[1].request("BSS RANGE=" + id + "- MASK=0x1")
47 if "id=" + id not in res:
48 raise Exception("Could not find BSS entry based on id range")
50 # Presence request to increase testing coverage
51 if "FAIL" in dev[1].group_request("P2P_PRESENCE_REQ 30000 102400"):
52 raise Exception("Could not send presence request")
53 ev = dev[1].wait_event(["P2P-PRESENCE-RESPONSE"])
55 raise Exception("Timeout while waiting for Presence Response")
58 dev[1].wait_go_ending_session()
60 def test_autogo2(dev):
61 """P2P autonomous GO with a separate group interface and client joining group"""
62 dev[0].request("SET p2p_no_group_iface 0")
64 if "p2p-wlan" not in res['ifname']:
65 raise Exception("Unexpected group interface name on GO")
66 if res['ifname'] not in utils.get_ifnames():
67 raise Exception("Could not find group interface netdev")
68 connect_cli(dev[0], dev[1])
70 dev[1].wait_go_ending_session()
71 if res['ifname'] in utils.get_ifnames():
72 raise Exception("Group interface netdev was not removed")
74 def test_autogo3(dev):
75 """P2P autonomous GO and client with a separate group interface joining group"""
76 dev[1].request("SET p2p_no_group_iface 0")
78 res = connect_cli(dev[0], dev[1])
79 if "p2p-wlan" not in res['ifname']:
80 raise Exception("Unexpected group interface name on client")
81 if res['ifname'] not in utils.get_ifnames():
82 raise Exception("Could not find group interface netdev")
84 dev[1].wait_go_ending_session()
86 if res['ifname'] in utils.get_ifnames():
87 raise Exception("Group interface netdev was not removed")
89 def test_autogo4(dev):
90 """P2P autonomous GO and client joining group (both with a separate group interface)"""
91 dev[0].request("SET p2p_no_group_iface 0")
92 dev[1].request("SET p2p_no_group_iface 0")
94 res2 = connect_cli(dev[0], dev[1])
95 if "p2p-wlan" not in res1['ifname']:
96 raise Exception("Unexpected group interface name on GO")
97 if "p2p-wlan" not in res2['ifname']:
98 raise Exception("Unexpected group interface name on client")
99 ifnames = utils.get_ifnames()
100 if res1['ifname'] not in ifnames:
101 raise Exception("Could not find GO group interface netdev")
102 if res2['ifname'] not in ifnames:
103 raise Exception("Could not find client group interface netdev")
104 dev[0].remove_group()
105 dev[1].wait_go_ending_session()
107 ifnames = utils.get_ifnames()
108 if res1['ifname'] in ifnames:
109 raise Exception("GO group interface netdev was not removed")
110 if res2['ifname'] in ifnames:
111 raise Exception("Client group interface netdev was not removed")
113 def test_autogo_2cli(dev):
114 """P2P autonomous GO and two clients joining group"""
116 connect_cli(dev[0], dev[1])
117 connect_cli(dev[0], dev[2])
118 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
119 dev[0].global_request("P2P_REMOVE_CLIENT " + dev[1].p2p_dev_addr())
120 dev[1].wait_go_ending_session()
121 dev[0].remove_group()
122 dev[2].wait_go_ending_session()
124 def test_autogo_tdls(dev):
125 """P2P autonomous GO and two clients using TDLS"""
128 logger.info("Start autonomous GO with fixed parameters " + go.ifname)
129 id = go.add_network()
130 go.set_network_quoted(id, "ssid", "DIRECT-tdls")
131 go.set_network_quoted(id, "psk", "12345678")
132 go.set_network(id, "mode", "3")
133 go.set_network(id, "disabled", "2")
134 res = go.p2p_start_go(persistent=id)
135 logger.debug("res: " + str(res))
137 wt.add_passphrase("12345678")
138 connect_cli(go, dev[1])
139 connect_cli(go, dev[2])
140 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
141 bssid = dev[0].p2p_interface_addr()
142 addr1 = dev[1].p2p_interface_addr()
143 addr2 = dev[2].p2p_interface_addr()
144 dev[1].tdls_setup(addr2)
146 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
147 conf = wt.get_tdls_counter("setup_conf_ok", bssid, addr1, addr2);
149 raise Exception("No TDLS Setup Confirm (success) seen")
150 dl = wt.get_tdls_counter("valid_direct_link", bssid, addr1, addr2);
152 raise Exception("No valid frames through direct link")
153 wt.tdls_clear(bssid, addr1, addr2);
154 dev[1].tdls_teardown(addr2)
156 teardown = wt.get_tdls_counter("teardown", bssid, addr1, addr2);
158 raise Exception("No TDLS Setup Teardown seen")
159 wt.tdls_clear(bssid, addr1, addr2);
160 hwsim_utils.test_connectivity_p2p(dev[1], dev[2])
161 ap_path = wt.get_tdls_counter("valid_ap_path", bssid, addr1, addr2);
163 raise Exception("No valid frames via AP path")
164 direct_link = wt.get_tdls_counter("valid_direct_link", bssid, addr1, addr2);
166 raise Exception("Unexpected frames through direct link")
167 idirect_link = wt.get_tdls_counter("invalid_direct_link", bssid, addr1,
170 raise Exception("Unexpected frames through direct link (invalid)")
171 dev[2].remove_group()
172 dev[1].remove_group()
173 dev[0].remove_group()
175 def test_autogo_legacy(dev):
176 """P2P autonomous GO and legacy clients"""
179 logger.info("Connect P2P client")
180 connect_cli(dev[0], dev[1])
182 logger.info("Connect legacy WPS client")
183 pin = dev[2].wps_read_pin()
184 dev[0].p2p_go_authorize_client(pin)
185 dev[2].request("P2P_SET disabled 1")
186 dev[2].dump_monitor()
187 dev[2].request("WPS_PIN any " + pin)
188 ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout=30)
190 raise Exception("Association with the GO timed out")
191 status = dev[2].get_status()
192 if status['wpa_state'] != 'COMPLETED':
193 raise Exception("Not fully connected")
194 hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
195 dev[2].request("DISCONNECT")
197 logger.info("Connect legacy non-WPS client")
198 dev[2].request("FLUSH")
199 dev[2].request("P2P_SET disabled 1")
200 dev[2].connect(ssid=res['ssid'], psk=res['passphrase'], proto='RSN',
201 key_mgmt='WPA-PSK', pairwise='CCMP', group='CCMP',
202 scan_freq=res['freq'])
203 hwsim_utils.test_connectivity_p2p_sta(dev[1], dev[2])
204 dev[2].request("DISCONNECT")
206 dev[0].remove_group()
207 dev[1].wait_go_ending_session()
209 def test_autogo_chan_switch(dev):
210 """P2P autonomous GO switching channels"""
211 autogo(dev[0], freq=2417)
212 connect_cli(dev[0], dev[1])
213 res = dev[0].request("CHAN_SWITCH 5 2422")
215 # for now, skip test since mac80211_hwsim support is not yet widely
218 ev = dev[0].wait_event(["AP-CSA-FINISHED"], timeout=10)
220 raise Exception("CSA finished event timed out")
221 if "freq=2422" not in ev:
222 raise Exception("Unexpected cahnnel in CSA finished event")
223 dev[0].dump_monitor()
224 dev[1].dump_monitor()
226 hwsim_utils.test_connectivity_p2p(dev[0], dev[1])