tests: Use hapd from hostapd.add_ap() in TDLS
[mech_eap.git] / tests / hwsim / test_ap_tdls.py
1 # TDLS tests
2 # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
3 #
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
6
7 import time
8 import logging
9 logger = logging.getLogger()
10 import subprocess
11
12 import hwsim_utils
13 from hostapd import HostapdGlobal
14 from hostapd import Hostapd
15 import hostapd
16 from utils import HwsimSkip, skip_with_fips
17 from wlantest import Wlantest
18 from test_ap_vht import vht_supported
19
20 def start_ap_wpa2_psk(ap):
21     params = hostapd.wpa2_params(ssid="test-wpa2-psk", passphrase="12345678")
22     return hostapd.add_ap(ap, params)
23
24 def connectivity(dev, hapd):
25     hwsim_utils.test_connectivity_sta(dev[0], dev[1])
26     hwsim_utils.test_connectivity(dev[0], hapd)
27     hwsim_utils.test_connectivity(dev[1], hapd)
28
29 def connect_2sta(dev, ssid, hapd):
30     dev[0].connect(ssid, psk="12345678", scan_freq="2412")
31     dev[1].connect(ssid, psk="12345678", scan_freq="2412")
32     connectivity(dev, hapd)
33
34 def connect_2sta_wpa2_psk(dev, hapd):
35     connect_2sta(dev, "test-wpa2-psk", hapd)
36
37 def connect_2sta_wpa_psk(dev, hapd):
38     connect_2sta(dev, "test-wpa-psk", hapd)
39
40 def connect_2sta_wpa_psk_mixed(dev, hapd):
41     dev[0].connect("test-wpa-mixed-psk", psk="12345678", proto="WPA",
42                    scan_freq="2412")
43     dev[1].connect("test-wpa-mixed-psk", psk="12345678", proto="WPA2",
44                    scan_freq="2412")
45     connectivity(dev, hapd)
46
47 def connect_2sta_wep(dev, hapd):
48     dev[0].connect("test-wep", key_mgmt="NONE", wep_key0='"hello"',
49                    scan_freq="2412")
50     dev[1].connect("test-wep", key_mgmt="NONE", wep_key0='"hello"',
51                    scan_freq="2412")
52     connectivity(dev, hapd)
53
54 def connect_2sta_open(dev, hapd, scan_freq="2412"):
55     dev[0].connect("test-open", key_mgmt="NONE", scan_freq=scan_freq)
56     dev[1].connect("test-open", key_mgmt="NONE", scan_freq=scan_freq)
57     connectivity(dev, hapd)
58
59 def wlantest_setup():
60     wt = Wlantest()
61     wt.flush()
62     wt.add_passphrase("12345678")
63     wt.add_wepkey("68656c6c6f")
64
65 def wlantest_tdls_packet_counters(bssid, addr0, addr1):
66     wt = Wlantest()
67     dl = wt.get_tdls_counter("valid_direct_link", bssid, addr0, addr1)
68     inv_dl = wt.get_tdls_counter("invalid_direct_link", bssid, addr0, addr1)
69     ap = wt.get_tdls_counter("valid_ap_path", bssid, addr0, addr1)
70     inv_ap = wt.get_tdls_counter("invalid_ap_path", bssid, addr0, addr1)
71     return [dl,inv_dl,ap,inv_ap]
72
73 def tdls_check_dl(sta0, sta1, bssid, addr0, addr1):
74     wt = Wlantest()
75     wt.tdls_clear(bssid, addr0, addr1)
76     hwsim_utils.test_connectivity_sta(sta0, sta1)
77     [dl,inv_dl,ap,inv_ap] = wlantest_tdls_packet_counters(bssid, addr0, addr1)
78     if dl == 0:
79         raise Exception("No valid frames through direct link")
80     if inv_dl > 0:
81         raise Exception("Invalid frames through direct link")
82     if ap > 0:
83         raise Exception("Unexpected frames through AP path")
84     if inv_ap > 0:
85         raise Exception("Invalid frames through AP path")
86
87 def tdls_check_ap(sta0, sta1, bssid, addr0, addr1):
88     wt = Wlantest()
89     wt.tdls_clear(bssid, addr0, addr1);
90     hwsim_utils.test_connectivity_sta(sta0, sta1)
91     [dl,inv_dl,ap,inv_ap] = wlantest_tdls_packet_counters(bssid, addr0, addr1)
92     if dl > 0:
93         raise Exception("Unexpected frames through direct link")
94     if inv_dl > 0:
95         raise Exception("Invalid frames through direct link")
96     if ap == 0:
97         raise Exception("No valid frames through AP path")
98     if inv_ap > 0:
99         raise Exception("Invalid frames through AP path")
100
101 def check_connectivity(sta0, sta1, hapd):
102     hwsim_utils.test_connectivity_sta(sta0, sta1)
103     hwsim_utils.test_connectivity(sta0, hapd)
104     hwsim_utils.test_connectivity(sta1, hapd)
105
106 def setup_tdls(sta0, sta1, hapd, reverse=False, expect_fail=False):
107     logger.info("Setup TDLS")
108     check_connectivity(sta0, sta1, hapd)
109     bssid = hapd.own_addr()
110     addr0 = sta0.p2p_interface_addr()
111     addr1 = sta1.p2p_interface_addr()
112     wt = Wlantest()
113     wt.tdls_clear(bssid, addr0, addr1);
114     wt.tdls_clear(bssid, addr1, addr0);
115     sta0.tdls_setup(addr1)
116     time.sleep(1)
117     if expect_fail:
118         tdls_check_ap(sta0, sta1, bssid, addr0, addr1)
119         return
120     if reverse:
121         addr1 = sta0.p2p_interface_addr()
122         addr0 = sta1.p2p_interface_addr()
123     conf = wt.get_tdls_counter("setup_conf_ok", bssid, addr0, addr1);
124     if conf == 0:
125         raise Exception("No TDLS Setup Confirm (success) seen")
126     tdls_check_dl(sta0, sta1, bssid, addr0, addr1)
127     check_connectivity(sta0, sta1, hapd)
128
129 def teardown_tdls(sta0, sta1, hapd, responder=False, wildcard=False):
130     logger.info("Teardown TDLS")
131     check_connectivity(sta0, sta1, hapd)
132     bssid = hapd.own_addr()
133     addr0 = sta0.p2p_interface_addr()
134     addr1 = sta1.p2p_interface_addr()
135     if responder:
136         sta1.tdls_teardown(addr0)
137     elif wildcard:
138         sta0.tdls_teardown("*")
139     else:
140         sta0.tdls_teardown(addr1)
141     time.sleep(1)
142     wt = Wlantest()
143     teardown = wt.get_tdls_counter("teardown", bssid, addr0, addr1);
144     if teardown == 0:
145         raise Exception("No TDLS Setup Teardown seen")
146     tdls_check_ap(sta0, sta1, bssid, addr0, addr1)
147     check_connectivity(sta0, sta1, hapd)
148
149 def check_tdls_link(sta0, sta1, connected=True):
150     addr0 = sta0.own_addr()
151     addr1 = sta1.own_addr()
152     status0 = sta0.tdls_link_status(addr1).rstrip()
153     status1 = sta1.tdls_link_status(addr0).rstrip()
154     logger.info("%s: %s" % (sta0.ifname, status0))
155     logger.info("%s: %s" % (sta1.ifname, status1))
156     if status0 != status1:
157         raise Exception("TDLS link status differs between stations")
158     if "status: connected" in status0:
159         if not connected:
160             raise Exception("Expected TDLS link status NOT to be connected")
161     else:
162         if connected:
163             raise Exception("Expected TDLS link status to be connected")
164
165 def test_ap_tdls_discovery(dev, apdev):
166     """WPA2-PSK AP and two stations using TDLS discovery"""
167     hapd = start_ap_wpa2_psk(apdev[0])
168     wlantest_setup()
169     connect_2sta_wpa2_psk(dev, hapd)
170     dev[0].request("TDLS_DISCOVER " + dev[1].p2p_interface_addr())
171     time.sleep(0.2)
172
173 def test_ap_wpa2_tdls(dev, apdev):
174     """WPA2-PSK AP and two stations using TDLS"""
175     hapd = start_ap_wpa2_psk(apdev[0])
176     wlantest_setup()
177     connect_2sta_wpa2_psk(dev, hapd)
178     setup_tdls(dev[0], dev[1], hapd)
179     teardown_tdls(dev[0], dev[1], hapd)
180     setup_tdls(dev[1], dev[0], hapd)
181     #teardown_tdls(dev[0], dev[1], hapd)
182
183 def test_ap_wpa2_tdls_concurrent_init(dev, apdev):
184     """Concurrent TDLS setup initiation"""
185     hapd = start_ap_wpa2_psk(apdev[0])
186     wlantest_setup()
187     connect_2sta_wpa2_psk(dev, hapd)
188     dev[0].request("SET tdls_testing 0x80")
189     setup_tdls(dev[1], dev[0], hapd, reverse=True)
190
191 def test_ap_wpa2_tdls_concurrent_init2(dev, apdev):
192     """Concurrent TDLS setup initiation (reverse)"""
193     hapd = start_ap_wpa2_psk(apdev[0])
194     wlantest_setup()
195     connect_2sta_wpa2_psk(dev, hapd)
196     dev[1].request("SET tdls_testing 0x80")
197     setup_tdls(dev[0], dev[1], hapd)
198
199 def test_ap_wpa2_tdls_decline_resp(dev, apdev):
200     """Decline TDLS Setup Response"""
201     hapd = start_ap_wpa2_psk(apdev[0])
202     wlantest_setup()
203     connect_2sta_wpa2_psk(dev, hapd)
204     dev[1].request("SET tdls_testing 0x200")
205     setup_tdls(dev[1], dev[0], hapd, expect_fail=True)
206
207 def test_ap_wpa2_tdls_long_lifetime(dev, apdev):
208     """TDLS with long TPK lifetime"""
209     hapd = start_ap_wpa2_psk(apdev[0])
210     wlantest_setup()
211     connect_2sta_wpa2_psk(dev, hapd)
212     dev[1].request("SET tdls_testing 0x40")
213     setup_tdls(dev[1], dev[0], hapd)
214
215 def test_ap_wpa2_tdls_long_frame(dev, apdev):
216     """TDLS with long setup/teardown frames"""
217     hapd = start_ap_wpa2_psk(apdev[0])
218     wlantest_setup()
219     connect_2sta_wpa2_psk(dev, hapd)
220     dev[0].request("SET tdls_testing 0x1")
221     dev[1].request("SET tdls_testing 0x1")
222     setup_tdls(dev[1], dev[0], hapd)
223     teardown_tdls(dev[1], dev[0], hapd)
224     setup_tdls(dev[0], dev[1], hapd)
225
226 def test_ap_wpa2_tdls_reneg(dev, apdev):
227     """Renegotiate TDLS link"""
228     hapd = start_ap_wpa2_psk(apdev[0])
229     wlantest_setup()
230     connect_2sta_wpa2_psk(dev, hapd)
231     setup_tdls(dev[1], dev[0], hapd)
232     setup_tdls(dev[0], dev[1], hapd)
233
234 def test_ap_wpa2_tdls_wrong_lifetime_resp(dev, apdev):
235     """Incorrect TPK lifetime in TDLS Setup Response"""
236     hapd = start_ap_wpa2_psk(apdev[0])
237     wlantest_setup()
238     connect_2sta_wpa2_psk(dev, hapd)
239     dev[1].request("SET tdls_testing 0x10")
240     setup_tdls(dev[0], dev[1], hapd, expect_fail=True)
241
242 def test_ap_wpa2_tdls_diff_rsnie(dev, apdev):
243     """TDLS with different RSN IEs"""
244     hapd = start_ap_wpa2_psk(apdev[0])
245     wlantest_setup()
246     connect_2sta_wpa2_psk(dev, hapd)
247     dev[1].request("SET tdls_testing 0x2")
248     setup_tdls(dev[1], dev[0], hapd)
249     teardown_tdls(dev[1], dev[0], hapd)
250
251 def test_ap_wpa2_tdls_wrong_tpk_m2_mic(dev, apdev):
252     """Incorrect MIC in TDLS Setup Response"""
253     hapd = start_ap_wpa2_psk(apdev[0])
254     wlantest_setup()
255     connect_2sta_wpa2_psk(dev, hapd)
256     dev[0].request("SET tdls_testing 0x800")
257     addr0 = dev[0].p2p_interface_addr()
258     dev[1].tdls_setup(addr0)
259     time.sleep(1)
260
261 def test_ap_wpa2_tdls_wrong_tpk_m3_mic(dev, apdev):
262     """Incorrect MIC in TDLS Setup Confirm"""
263     hapd = start_ap_wpa2_psk(apdev[0])
264     wlantest_setup()
265     connect_2sta_wpa2_psk(dev, hapd)
266     dev[1].request("SET tdls_testing 0x800")
267     addr0 = dev[0].p2p_interface_addr()
268     dev[1].tdls_setup(addr0)
269     time.sleep(1)
270
271 def test_ap_wpa_tdls(dev, apdev):
272     """WPA-PSK AP and two stations using TDLS"""
273     skip_with_fips(dev[0])
274     hapd = hostapd.add_ap(apdev[0],
275                           hostapd.wpa_params(ssid="test-wpa-psk",
276                                              passphrase="12345678"))
277     wlantest_setup()
278     connect_2sta_wpa_psk(dev, hapd)
279     setup_tdls(dev[0], dev[1], hapd)
280     teardown_tdls(dev[0], dev[1], hapd)
281     setup_tdls(dev[1], dev[0], hapd)
282
283 def test_ap_wpa_mixed_tdls(dev, apdev):
284     """WPA+WPA2-PSK AP and two stations using TDLS"""
285     skip_with_fips(dev[0])
286     hapd = hostapd.add_ap(apdev[0],
287                           hostapd.wpa_mixed_params(ssid="test-wpa-mixed-psk",
288                                                    passphrase="12345678"))
289     wlantest_setup()
290     connect_2sta_wpa_psk_mixed(dev, hapd)
291     setup_tdls(dev[0], dev[1], hapd)
292     teardown_tdls(dev[0], dev[1], hapd)
293     setup_tdls(dev[1], dev[0], hapd)
294
295 def test_ap_wep_tdls(dev, apdev):
296     """WEP AP and two stations using TDLS"""
297     hapd = hostapd.add_ap(apdev[0],
298                           { "ssid": "test-wep", "wep_key0": '"hello"' })
299     wlantest_setup()
300     connect_2sta_wep(dev, hapd)
301     setup_tdls(dev[0], dev[1], hapd)
302     teardown_tdls(dev[0], dev[1], hapd)
303     setup_tdls(dev[1], dev[0], hapd)
304
305 def test_ap_open_tdls(dev, apdev):
306     """Open AP and two stations using TDLS"""
307     hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
308     wlantest_setup()
309     connect_2sta_open(dev, hapd)
310     setup_tdls(dev[0], dev[1], hapd)
311     teardown_tdls(dev[0], dev[1], hapd)
312     setup_tdls(dev[1], dev[0], hapd)
313     teardown_tdls(dev[1], dev[0], hapd, wildcard=True)
314
315 def test_ap_wpa2_tdls_bssid_mismatch(dev, apdev):
316     """TDLS failure due to BSSID mismatch"""
317     try:
318         ssid = "test-wpa2-psk"
319         passphrase = "12345678"
320         params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
321         params['bridge'] = 'ap-br0'
322         hapd = hostapd.add_ap(apdev[0], params)
323         hostapd.add_ap(apdev[1], params)
324         wlantest_setup()
325         subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
326         subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
327         dev[0].connect(ssid, psk=passphrase, scan_freq="2412",
328                        bssid=apdev[0]['bssid'])
329         dev[1].connect(ssid, psk=passphrase, scan_freq="2412",
330                        bssid=apdev[1]['bssid'])
331         hwsim_utils.test_connectivity_sta(dev[0], dev[1])
332         hwsim_utils.test_connectivity_iface(dev[0], hapd, "ap-br0")
333         hwsim_utils.test_connectivity_iface(dev[1], hapd, "ap-br0")
334
335         addr0 = dev[0].p2p_interface_addr()
336         dev[1].tdls_setup(addr0)
337         time.sleep(1)
338         hwsim_utils.test_connectivity_sta(dev[0], dev[1])
339     finally:
340         subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'])
341         subprocess.call(['brctl', 'delbr', 'ap-br0'])
342
343 def test_ap_wpa2_tdls_responder_teardown(dev, apdev):
344     """TDLS teardown from responder with WPA2-PSK AP"""
345     hapd = start_ap_wpa2_psk(apdev[0])
346     wlantest_setup()
347     connect_2sta_wpa2_psk(dev, hapd)
348     setup_tdls(dev[0], dev[1], hapd)
349     teardown_tdls(dev[0], dev[1], hapd, responder=True)
350
351 def test_ap_open_tdls_vht(dev, apdev):
352     """Open AP and two stations using TDLS"""
353     params = { "ssid": "test-open",
354                "country_code": "DE",
355                "hw_mode": "a",
356                "channel": "36",
357                "ieee80211n": "1",
358                "ieee80211ac": "1",
359                "ht_capab": "",
360                "vht_capab": "",
361                "vht_oper_chwidth": "0",
362                "vht_oper_centr_freq_seg0_idx": "0" }
363     try:
364         hapd = hostapd.add_ap(apdev[0], params)
365         wlantest_setup()
366         connect_2sta_open(dev, hapd, scan_freq="5180")
367         setup_tdls(dev[0], dev[1], hapd)
368         teardown_tdls(dev[0], dev[1], hapd)
369         setup_tdls(dev[1], dev[0], hapd)
370         teardown_tdls(dev[1], dev[0], hapd, wildcard=True)
371     finally:
372         dev[0].request("DISCONNECT")
373         dev[1].request("DISCONNECT")
374         if hapd:
375             hapd.request("DISABLE")
376         subprocess.call(['iw', 'reg', 'set', '00'])
377         dev[0].flush_scan_cache()
378         dev[1].flush_scan_cache()
379
380 def test_ap_open_tdls_vht80(dev, apdev):
381     """Open AP and two stations using TDLS with VHT 80"""
382     params = { "ssid": "test-open",
383                "country_code": "US",
384                "hw_mode": "a",
385                "channel": "36",
386                "ht_capab": "[HT40+]",
387                "ieee80211n": "1",
388                "ieee80211ac": "1",
389                "vht_capab": "",
390                "vht_oper_chwidth": "1",
391                "vht_oper_centr_freq_seg0_idx": "42" }
392     try:
393         hapd = None
394         hapd = hostapd.add_ap(apdev[0], params)
395         wlantest_setup()
396         connect_2sta_open(dev, hapd, scan_freq="5180")
397         sig = dev[0].request("SIGNAL_POLL").splitlines()
398         if "WIDTH=80 MHz" not in sig:
399             raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
400         setup_tdls(dev[0], dev[1], hapd)
401         for i in range(10):
402             check_connectivity(dev[0], dev[1], hapd)
403         for i in range(2):
404             cmd = subprocess.Popen(['iw', dev[0].ifname, 'station', 'dump'],
405                                    stdout=subprocess.PIPE)
406             res = cmd.stdout.read()
407             cmd.stdout.close()
408             logger.info("Station dump on dev[%d]:\n%s" % (i, res))
409     except Exception, e:
410         if isinstance(e, Exception) and str(e) == "AP startup failed":
411             if not vht_supported():
412                 raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
413         raise
414     finally:
415         dev[0].request("DISCONNECT")
416         dev[1].request("DISCONNECT")
417         if hapd:
418             hapd.request("DISABLE")
419         subprocess.call(['iw', 'reg', 'set', '00'])
420         dev[0].flush_scan_cache()
421         dev[1].flush_scan_cache()
422
423 def test_ap_open_tdls_vht80plus80(dev, apdev):
424     """Open AP and two stations using TDLS with VHT 80+80"""
425     params = { "ssid": "test-open",
426                "country_code": "US",
427                "hw_mode": "a",
428                "channel": "36",
429                "ht_capab": "[HT40+]",
430                "ieee80211n": "1",
431                "ieee80211ac": "1",
432                "vht_capab": "",
433                "vht_oper_chwidth": "3",
434                "vht_oper_centr_freq_seg0_idx": "42",
435                "vht_oper_centr_freq_seg1_idx": "155" }
436     try:
437         hapd = None
438         hapd = hostapd.add_ap(apdev[0], params)
439         wlantest_setup()
440         connect_2sta_open(dev, hapd, scan_freq="5180")
441         sig = dev[0].request("SIGNAL_POLL").splitlines()
442         if "FREQUENCY=5180" not in sig:
443             raise Exception("Unexpected SIGNAL_POLL value(1): " + str(sig))
444         if "WIDTH=80+80 MHz" not in sig:
445             raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
446         if "CENTER_FRQ1=5210" not in sig:
447             raise Exception("Unexpected SIGNAL_POLL value(3): " + str(sig))
448         if "CENTER_FRQ2=5775" not in sig:
449             raise Exception("Unexpected SIGNAL_POLL value(4): " + str(sig))
450         setup_tdls(dev[0], dev[1], hapd)
451         for i in range(10):
452             check_connectivity(dev[0], dev[1], hapd)
453         for i in range(2):
454             cmd = subprocess.Popen(['iw', dev[0].ifname, 'station', 'dump'],
455                                    stdout=subprocess.PIPE)
456             res = cmd.stdout.read()
457             cmd.stdout.close()
458             logger.info("Station dump on dev[%d]:\n%s" % (i, res))
459     except Exception, e:
460         if isinstance(e, Exception) and str(e) == "AP startup failed":
461             if not vht_supported():
462                 raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
463         raise
464     finally:
465         dev[0].request("DISCONNECT")
466         dev[1].request("DISCONNECT")
467         if hapd:
468             hapd.request("DISABLE")
469         subprocess.call(['iw', 'reg', 'set', '00'])
470         dev[0].flush_scan_cache()
471         dev[1].flush_scan_cache()
472
473 def test_ap_open_tdls_vht160(dev, apdev):
474     """Open AP and two stations using TDLS with VHT 160"""
475     params = { "ssid": "test-open",
476                "country_code": "ZA",
477                "hw_mode": "a",
478                "channel": "104",
479                "ht_capab": "[HT40-]",
480                "ieee80211n": "1",
481                "ieee80211ac": "1",
482                "vht_oper_chwidth": "2",
483                "vht_oper_centr_freq_seg0_idx": "114" }
484     try:
485         hapd = None
486         hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
487         ev = hapd.wait_event(["AP-ENABLED"], timeout=2)
488         if not ev:
489             cmd = subprocess.Popen(["iw", "reg", "get"], stdout=subprocess.PIPE)
490             reg = cmd.stdout.readlines()
491             for r in reg:
492                 if "5490" in r and "DFS" in r:
493                     raise HwsimSkip("ZA regulatory rule did not have DFS requirement removed")
494             raise Exception("AP setup timed out")
495         wlantest_setup()
496         connect_2sta_open(dev, hapd, scan_freq="5520")
497         sig = dev[0].request("SIGNAL_POLL").splitlines()
498         if "WIDTH=160 MHz" not in sig:
499             raise Exception("Unexpected SIGNAL_POLL value(2): " + str(sig))
500         setup_tdls(dev[0], dev[1], hapd)
501         for i in range(10):
502             check_connectivity(dev[0], dev[1], hapd)
503         for i in range(2):
504             cmd = subprocess.Popen(['iw', dev[0].ifname, 'station', 'dump'],
505                                    stdout=subprocess.PIPE)
506             res = cmd.stdout.read()
507             cmd.stdout.close()
508             logger.info("Station dump on dev[%d]:\n%s" % (i, res))
509     except Exception, e:
510         if isinstance(e, Exception) and str(e) == "AP startup failed":
511             if not vht_supported():
512                 raise HwsimSkip("80/160 MHz channel not supported in regulatory information")
513         raise
514     finally:
515         dev[0].request("DISCONNECT")
516         dev[1].request("DISCONNECT")
517         if hapd:
518             hapd.request("DISABLE")
519         subprocess.call(['iw', 'reg', 'set', '00'])
520         dev[0].flush_scan_cache()
521         dev[1].flush_scan_cache()
522
523 def test_tdls_chan_switch(dev, apdev):
524     """Open AP and two stations using TDLS"""
525     flags = int(dev[0].get_driver_status_field('capa.flags'), 16)
526     if flags & 0x800000000 == 0:
527         raise HwsimSkip("Driver does not support TDLS channel switching")
528
529     hapd = hostapd.add_ap(apdev[0], { "ssid": "test-open" })
530     connect_2sta_open(dev, hapd)
531     setup_tdls(dev[0], dev[1], hapd)
532     if "OK" not in dev[0].request("TDLS_CHAN_SWITCH " + dev[1].own_addr() + " 81 2462"):
533         raise Exception("Failed to enable TDLS channel switching")
534     if "OK" not in dev[0].request("TDLS_CANCEL_CHAN_SWITCH " + dev[1].own_addr()):
535         raise Exception("Could not disable TDLS channel switching")
536     if "FAIL" not in dev[0].request("TDLS_CANCEL_CHAN_SWITCH " + dev[1].own_addr()):
537         raise Exception("TDLS_CANCEL_CHAN_SWITCH accepted even though channel switching was already disabled")
538
539 def test_ap_tdls_link_status(dev, apdev):
540     """Check TDLS link status between two stations"""
541     hapd = start_ap_wpa2_psk(apdev[0])
542     wlantest_setup()
543     connect_2sta_wpa2_psk(dev, hapd)
544     check_tdls_link(dev[0], dev[1], connected=False)
545     setup_tdls(dev[0], dev[1], hapd)
546     check_tdls_link(dev[0], dev[1], connected=True)
547     teardown_tdls(dev[0], dev[1], hapd)
548     check_tdls_link(dev[0], dev[1], connected=False)
549     if "FAIL" not in dev[0].request("TDLS_LINK_STATUS foo"):
550         raise Exception("Unexpected TDLS_LINK_STATUS response for invalid argument")