1 # Test cases for HT operations with hostapd
2 # Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
9 logger = logging.getLogger()
14 from utils import HwsimSkip, alloc_fail
16 from test_ap_csa import csa_supported
18 def clear_scan_cache(ifname):
19 subprocess.call(['ifconfig', ifname, 'up'])
20 subprocess.call(['iw', ifname, 'scan', 'trigger', 'freq', '2412', 'flush'])
22 subprocess.call(['ifconfig', ifname, 'down'])
24 def test_ap_ht40_scan(dev, apdev):
26 clear_scan_cache(apdev[0]['ifname'])
27 params = { "ssid": "test-ht40",
29 "ht_capab": "[HT40-]"}
30 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
32 state = hapd.get_status_field("state")
33 if state != "HT_SCAN":
35 state = hapd.get_status_field("state")
36 if state != "HT_SCAN":
37 raise Exception("Unexpected interface state - expected HT_SCAN")
39 ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
41 raise Exception("AP setup timed out")
43 state = hapd.get_status_field("state")
44 if state != "ENABLED":
45 raise Exception("Unexpected interface state - expected ENABLED")
47 freq = hapd.get_status_field("freq")
49 raise Exception("Unexpected frequency")
50 pri = hapd.get_status_field("channel")
52 raise Exception("Unexpected primary channel")
53 sec = hapd.get_status_field("secondary_channel")
55 raise Exception("Unexpected secondary channel")
57 dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
59 def test_ap_ht40_scan_conflict(dev, apdev):
60 """HT40 co-ex scan conflict"""
61 clear_scan_cache(apdev[0]['ifname'])
62 params = { "ssid": "test-ht40",
64 "ht_capab": "[HT40+]"}
65 hostapd.add_ap(apdev[1]['ifname'], params)
67 params = { "ssid": "test-ht40",
69 "ht_capab": "[HT40-]"}
70 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
72 state = hapd.get_status_field("state")
73 if state != "HT_SCAN":
75 state = hapd.get_status_field("state")
76 if state != "HT_SCAN":
77 raise Exception("Unexpected interface state - expected HT_SCAN")
79 ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
81 raise Exception("AP setup timed out")
83 state = hapd.get_status_field("state")
84 if state != "ENABLED":
85 raise Exception("Unexpected interface state - expected ENABLED")
87 freq = hapd.get_status_field("freq")
89 raise Exception("Unexpected frequency")
90 pri = hapd.get_status_field("channel")
92 raise Exception("Unexpected primary channel")
93 sec = hapd.get_status_field("secondary_channel")
95 raise Exception("Unexpected secondary channel: " + sec)
97 dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
99 def test_ap_ht40_scan_conflict2(dev, apdev):
100 """HT40 co-ex scan conflict (HT40-)"""
101 clear_scan_cache(apdev[0]['ifname'])
102 params = { "ssid": "test-ht40",
104 "ht_capab": "[HT40-]"}
105 hostapd.add_ap(apdev[1]['ifname'], params)
107 params = { "ssid": "test-ht40",
109 "ht_capab": "[HT40+]"}
110 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
112 state = hapd.get_status_field("state")
113 if state != "HT_SCAN":
115 state = hapd.get_status_field("state")
116 if state != "HT_SCAN":
117 raise Exception("Unexpected interface state - expected HT_SCAN")
119 ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
121 raise Exception("AP setup timed out")
123 state = hapd.get_status_field("state")
124 if state != "ENABLED":
125 raise Exception("Unexpected interface state - expected ENABLED")
127 freq = hapd.get_status_field("freq")
129 raise Exception("Unexpected frequency")
130 pri = hapd.get_status_field("channel")
132 raise Exception("Unexpected primary channel")
133 sec = hapd.get_status_field("secondary_channel")
135 raise Exception("Unexpected secondary channel: " + sec)
137 dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
139 def test_ap_ht40_scan_not_affected(dev, apdev):
140 """HT40 co-ex scan and other BSS not affected"""
141 clear_scan_cache(apdev[0]['ifname'])
142 params = { "ssid": "test-ht20",
144 hostapd.add_ap(apdev[1]['ifname'], params)
146 subprocess.call(['ifconfig', apdev[0]['ifname'], 'up'])
147 subprocess.call(['iw', apdev[0]['ifname'], 'scan', 'trigger', 'freq', '2462'])
149 subprocess.call(['iw', apdev[0]['ifname'], 'scan', 'dump'],
150 stdout=open('/dev/null', 'w'))
152 subprocess.call(['ifconfig', apdev[0]['ifname'], 'down'])
154 params = { "ssid": "test-ht40",
156 "ht_capab": "[HT40+]"}
157 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
159 state = hapd.get_status_field("state")
160 if state != "HT_SCAN":
162 state = hapd.get_status_field("state")
163 if state != "HT_SCAN":
164 raise Exception("Unexpected interface state - expected HT_SCAN")
166 ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
168 raise Exception("AP setup timed out")
170 state = hapd.get_status_field("state")
171 if state != "ENABLED":
172 raise Exception("Unexpected interface state - expected ENABLED")
174 freq = hapd.get_status_field("freq")
176 raise Exception("Unexpected frequency")
177 pri = hapd.get_status_field("channel")
179 raise Exception("Unexpected primary channel")
180 sec = hapd.get_status_field("secondary_channel")
182 raise Exception("Unexpected secondary channel: " + sec)
184 dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
186 def test_ap_ht40_scan_legacy_conflict(dev, apdev):
187 """HT40 co-ex scan conflict with legacy 20 MHz AP"""
188 clear_scan_cache(apdev[0]['ifname'])
189 params = { "ssid": "legacy-20",
190 "channel": "7", "ieee80211n": "0" }
191 hostapd.add_ap(apdev[1]['ifname'], params)
193 params = { "ssid": "test-ht40",
195 "ht_capab": "[HT40-]"}
196 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
198 state = hapd.get_status_field("state")
199 if state != "HT_SCAN":
201 state = hapd.get_status_field("state")
202 if state != "HT_SCAN":
203 raise Exception("Unexpected interface state - expected HT_SCAN")
205 ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
207 raise Exception("AP setup timed out")
209 state = hapd.get_status_field("state")
210 if state != "ENABLED":
211 raise Exception("Unexpected interface state - expected ENABLED")
213 freq = hapd.get_status_field("freq")
215 raise Exception("Unexpected frequency: " + freq)
216 pri = hapd.get_status_field("channel")
218 raise Exception("Unexpected primary channel: " + pri)
219 sec = hapd.get_status_field("secondary_channel")
221 raise Exception("Unexpected secondary channel: " + sec)
223 dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
225 def test_ap_ht40_scan_ht20_conflict(dev, apdev):
226 """HT40 co-ex scan conflict with HT 20 MHz AP"""
227 clear_scan_cache(apdev[0]['ifname'])
228 params = { "ssid": "ht-20",
229 "channel": "7", "ieee80211n": "1" }
230 hostapd.add_ap(apdev[1]['ifname'], params)
232 params = { "ssid": "test-ht40",
234 "ht_capab": "[HT40-]"}
235 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
237 state = hapd.get_status_field("state")
238 if state != "HT_SCAN":
240 state = hapd.get_status_field("state")
241 if state != "HT_SCAN":
242 raise Exception("Unexpected interface state - expected HT_SCAN")
244 ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
246 raise Exception("AP setup timed out")
248 state = hapd.get_status_field("state")
249 if state != "ENABLED":
250 raise Exception("Unexpected interface state - expected ENABLED")
252 freq = hapd.get_status_field("freq")
254 raise Exception("Unexpected frequency: " + freq)
255 pri = hapd.get_status_field("channel")
257 raise Exception("Unexpected primary channel: " + pri)
258 sec = hapd.get_status_field("secondary_channel")
260 raise Exception("Unexpected secondary channel: " + sec)
262 dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
264 def test_ap_ht40_scan_intolerant(dev, apdev):
265 """HT40 co-ex scan finding an AP advertising 40 MHz intolerant"""
266 clear_scan_cache(apdev[0]['ifname'])
267 params = { "ssid": "another-bss",
269 "ht_capab": "[40-INTOLERANT]" }
270 hostapd.add_ap(apdev[1]['ifname'], params)
272 params = { "ssid": "test-ht40",
274 "ht_capab": "[HT40+]"}
275 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
277 state = hapd.get_status_field("state")
278 if state != "HT_SCAN":
280 state = hapd.get_status_field("state")
281 if state != "HT_SCAN":
282 raise Exception("Unexpected interface state - expected HT_SCAN")
284 ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
286 raise Exception("AP setup timed out")
288 state = hapd.get_status_field("state")
289 if state != "ENABLED":
290 raise Exception("Unexpected interface state - expected ENABLED")
292 freq = hapd.get_status_field("freq")
294 raise Exception("Unexpected frequency: " + freq)
295 pri = hapd.get_status_field("channel")
297 raise Exception("Unexpected primary channel: " + pri)
298 sec = hapd.get_status_field("secondary_channel")
300 raise Exception("Unexpected secondary channel: " + sec)
302 dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
304 def test_ap_ht40_scan_match(dev, apdev):
305 """HT40 co-ex scan matching configuration"""
306 clear_scan_cache(apdev[0]['ifname'])
307 params = { "ssid": "test-ht40",
309 "ht_capab": "[HT40-]"}
310 hostapd.add_ap(apdev[1]['ifname'], params)
312 params = { "ssid": "test-ht40",
314 "ht_capab": "[HT40-]"}
315 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
317 state = hapd.get_status_field("state")
318 if state != "HT_SCAN":
320 state = hapd.get_status_field("state")
321 if state != "HT_SCAN":
322 raise Exception("Unexpected interface state - expected HT_SCAN")
324 ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
326 raise Exception("AP setup timed out")
328 state = hapd.get_status_field("state")
329 if state != "ENABLED":
330 raise Exception("Unexpected interface state - expected ENABLED")
332 freq = hapd.get_status_field("freq")
334 raise Exception("Unexpected frequency")
335 pri = hapd.get_status_field("channel")
337 raise Exception("Unexpected primary channel")
338 sec = hapd.get_status_field("secondary_channel")
340 raise Exception("Unexpected secondary channel: " + sec)
342 dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
344 def test_ap_ht40_5ghz_match(dev, apdev):
345 """HT40 co-ex scan on 5 GHz with matching pri/sec channel"""
346 clear_scan_cache(apdev[0]['ifname'])
350 params = { "ssid": "test-ht40",
353 "country_code": "US",
354 "ht_capab": "[HT40+]"}
355 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
357 params = { "ssid": "test-ht40",
360 "ht_capab": "[HT40+]"}
361 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
363 state = hapd.get_status_field("state")
364 if state != "HT_SCAN":
366 state = hapd.get_status_field("state")
367 if state != "HT_SCAN":
368 raise Exception("Unexpected interface state - expected HT_SCAN")
370 ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
372 raise Exception("AP setup timed out")
374 state = hapd.get_status_field("state")
375 if state != "ENABLED":
376 raise Exception("Unexpected interface state - expected ENABLED")
378 freq = hapd.get_status_field("freq")
380 raise Exception("Unexpected frequency")
381 pri = hapd.get_status_field("channel")
383 raise Exception("Unexpected primary channel")
384 sec = hapd.get_status_field("secondary_channel")
386 raise Exception("Unexpected secondary channel: " + sec)
388 dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
390 dev[0].request("DISCONNECT")
392 hapd.request("DISABLE")
394 hapd2.request("DISABLE")
395 subprocess.call(['iw', 'reg', 'set', '00'])
396 dev[0].flush_scan_cache()
398 def test_ap_ht40_5ghz_switch(dev, apdev):
399 """HT40 co-ex scan on 5 GHz switching pri/sec channel"""
400 clear_scan_cache(apdev[0]['ifname'])
404 params = { "ssid": "test-ht40",
407 "country_code": "US",
408 "ht_capab": "[HT40+]"}
409 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
411 params = { "ssid": "test-ht40",
414 "ht_capab": "[HT40-]"}
415 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
417 state = hapd.get_status_field("state")
418 if state != "HT_SCAN":
420 state = hapd.get_status_field("state")
421 if state != "HT_SCAN":
422 raise Exception("Unexpected interface state - expected HT_SCAN")
424 ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
426 raise Exception("AP setup timed out")
428 state = hapd.get_status_field("state")
429 if state != "ENABLED":
430 raise Exception("Unexpected interface state - expected ENABLED")
432 freq = hapd.get_status_field("freq")
434 raise Exception("Unexpected frequency: " + freq)
435 pri = hapd.get_status_field("channel")
437 raise Exception("Unexpected primary channel: " + pri)
438 sec = hapd.get_status_field("secondary_channel")
440 raise Exception("Unexpected secondary channel: " + sec)
442 dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
444 dev[0].request("DISCONNECT")
446 hapd.request("DISABLE")
448 hapd2.request("DISABLE")
449 subprocess.call(['iw', 'reg', 'set', '00'])
451 def test_ap_ht40_5ghz_switch2(dev, apdev):
452 """HT40 co-ex scan on 5 GHz switching pri/sec channel (2)"""
453 clear_scan_cache(apdev[0]['ifname'])
457 params = { "ssid": "test-ht40",
460 "country_code": "US",
461 "ht_capab": "[HT40+]"}
462 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
464 id = dev[0].add_network()
465 dev[0].set_network(id, "mode", "2")
466 dev[0].set_network_quoted(id, "ssid", "wpas-ap-open")
467 dev[0].set_network(id, "key_mgmt", "NONE")
468 dev[0].set_network(id, "frequency", "5200")
469 dev[0].set_network(id, "scan_freq", "5200")
470 dev[0].select_network(id)
473 params = { "ssid": "test-ht40",
476 "ht_capab": "[HT40-]"}
477 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
479 state = hapd.get_status_field("state")
480 if state != "HT_SCAN":
482 state = hapd.get_status_field("state")
483 if state != "HT_SCAN":
484 raise Exception("Unexpected interface state - expected HT_SCAN")
486 ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
488 raise Exception("AP setup timed out")
490 state = hapd.get_status_field("state")
491 if state != "ENABLED":
492 raise Exception("Unexpected interface state - expected ENABLED")
494 freq = hapd.get_status_field("freq")
496 raise Exception("Unexpected frequency: " + freq)
497 pri = hapd.get_status_field("channel")
499 raise Exception("Unexpected primary channel: " + pri)
500 sec = hapd.get_status_field("secondary_channel")
502 raise Exception("Unexpected secondary channel: " + sec)
504 dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
506 dev[0].request("DISCONNECT")
508 hapd.request("DISABLE")
510 hapd2.request("DISABLE")
511 subprocess.call(['iw', 'reg', 'set', '00'])
512 dev[0].flush_scan_cache()
514 def test_obss_scan(dev, apdev):
515 """Overlapping BSS scan request"""
516 params = { "ssid": "obss-scan",
518 "ht_capab": "[HT40-]",
519 "obss_interval": "10" }
520 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
522 params = { "ssid": "another-bss",
525 hostapd.add_ap(apdev[1]['ifname'], params)
527 dev[0].connect("obss-scan", key_mgmt="NONE", scan_freq="2437")
528 hapd.set("ext_mgmt_frame_handling", "1")
529 logger.info("Waiting for OBSS scan to occur")
530 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=15)
532 raise Exception("Timed out while waiting for OBSS scan to start")
533 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
535 raise Exception("Timed out while waiting for OBSS scan results")
537 for i in range(0, 4):
538 frame = hapd.mgmt_rx(timeout=5)
540 raise Exception("MGMT RX wait timed out")
541 if frame['subtype'] != 13:
543 payload = frame['payload']
546 (category, action, ie) = struct.unpack('BBB', payload[0:3])
552 logger.info("20/40 BSS Coexistence report received")
556 raise Exception("20/40 BSS Coexistence report not seen")
558 def test_obss_scan_40_intolerant(dev, apdev):
559 """Overlapping BSS scan request with 40 MHz intolerant AP"""
560 params = { "ssid": "obss-scan",
562 "ht_capab": "[HT40-]",
563 "obss_interval": "10" }
564 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
566 params = { "ssid": "another-bss",
568 "ht_capab": "[40-INTOLERANT]" }
569 hostapd.add_ap(apdev[1]['ifname'], params)
571 dev[0].connect("obss-scan", key_mgmt="NONE", scan_freq="2437")
572 hapd.set("ext_mgmt_frame_handling", "1")
573 logger.info("Waiting for OBSS scan to occur")
574 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=15)
576 raise Exception("Timed out while waiting for OBSS scan to start")
577 ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
579 raise Exception("Timed out while waiting for OBSS scan results")
581 for i in range(0, 4):
582 frame = hapd.mgmt_rx(timeout=5)
584 raise Exception("MGMT RX wait timed out")
585 if frame['subtype'] != 13:
587 payload = frame['payload']
590 (category, action, ie) = struct.unpack('BBB', payload[0:3])
596 logger.info("20/40 BSS Coexistence report received")
600 raise Exception("20/40 BSS Coexistence report not seen")
602 def test_obss_coex_report_handling(dev, apdev):
603 """Overlapping BSS scan report handling with obss_interval=0"""
604 clear_scan_cache(apdev[0]['ifname'])
605 params = { "ssid": "obss-scan",
607 "ht_capab": "[HT40-]" }
608 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
609 bssid = apdev[0]['bssid']
610 dev[0].connect("obss-scan", key_mgmt="NONE", scan_freq="2437")
612 sec = hapd.get_status_field("secondary_channel")
614 raise Exception("AP is not using 40 MHz channel")
616 # 20/40 MHz co-ex report tests: number of invalid reports and a valid report
617 # that forces 20 MHz channel.
618 tests = [ '0400', '040048', '04004801', '0400480000', '0400490100',
619 '040048ff0000', '04004801ff49ff00', '04004801004900',
620 '0400480100490101', '0400480100490201ff',
621 '040048010449020005' ]
623 req = "MGMT_TX {} {} freq=2437 action={}".format(bssid, bssid, msg)
624 if "OK" not in dev[0].request(req):
625 raise Exception("Could not send management frame")
627 sec = hapd.get_status_field("secondary_channel")
629 raise Exception("AP did not move to 20 MHz channel")
631 def test_obss_coex_report_handling1(dev, apdev):
632 """Overlapping BSS scan report handling with obss_interval=1"""
633 clear_scan_cache(apdev[0]['ifname'])
634 params = { "ssid": "obss-scan",
636 "ht_capab": "[HT40+]",
637 "obss_interval": "1" }
638 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
639 bssid = apdev[0]['bssid']
640 dev[0].connect("obss-scan", key_mgmt="NONE", scan_freq="2437")
642 sec = hapd.get_status_field("secondary_channel")
644 raise Exception("AP is not using 40 MHz channel")
646 # 20/40 MHz co-ex report forcing 20 MHz channel
647 msg = '040048010449020005'
648 req = "MGMT_TX {} {} freq=2437 action={}".format(bssid, bssid, msg)
649 if "OK" not in dev[0].request(req):
650 raise Exception("Could not send management frame")
652 sec = hapd.get_status_field("secondary_channel")
654 raise Exception("AP did not move to 20 MHz channel")
656 # No 20/40 MHz co-ex reports forcing 20 MHz channel during next interval
658 sec = hapd.get_status_field("secondary_channel")
663 raise Exception("AP did not return to 40 MHz channel")
665 def test_olbc(dev, apdev):
667 params = { "ssid": "test-olbc",
669 "ht_capab": "[HT40-]",
670 "ap_table_expiration_time": "2" }
671 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
672 status = hapd.get_status()
673 if status['olbc'] != '0' or status['olbc_ht'] != '0':
674 raise Exception("Unexpected OLBC information")
676 params = { "ssid": "olbc-ap",
680 hostapd.add_ap(apdev[1]['ifname'], params)
682 status = hapd.get_status()
683 if status['olbc'] != '1' or status['olbc_ht'] != '1':
684 raise Exception("Missing OLBC information")
686 hapd_global = hostapd.HostapdGlobal()
687 hapd_global.remove(apdev[1]['ifname'])
689 logger.info("Waiting for OLBC state to time out")
691 for i in range(0, 15):
693 status = hapd.get_status()
694 if status['olbc'] == '0' and status['olbc_ht'] == '0':
698 raise Exception("OLBC state did nto time out")
700 def test_olbc_table_limit(dev, apdev):
701 """OLBC AP table size limit"""
702 ifname1 = apdev[0]['ifname']
703 ifname2 = apdev[0]['ifname'] + '-2'
704 ifname3 = apdev[0]['ifname'] + '-3'
705 hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
706 hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
707 hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
709 params = { "ssid": "test-olbc",
711 "ap_table_max_size": "2" }
712 hapd = hostapd.add_ap(apdev[1]['ifname'], params)
715 with alloc_fail(hapd, 1, "ap_list_process_beacon"):
717 hapd.set("ap_table_max_size", "1")
719 hapd.set("ap_table_max_size", "0")
722 def test_olbc_5ghz(dev, apdev):
723 """OLBC detection on 5 GHz"""
727 params = { "ssid": "test-olbc",
728 "country_code": "FI",
731 "ht_capab": "[HT40+]" }
732 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
733 status = hapd.get_status()
734 if status['olbc'] != '0' or status['olbc_ht'] != '0':
735 raise Exception("Unexpected OLBC information")
737 params = { "ssid": "olbc-ap",
738 "country_code": "FI",
743 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
747 status = hapd.get_status()
748 logger.debug('olbc_ht: ' + status['olbc_ht'])
749 if status['olbc_ht'] == '1':
753 raise Exception("Missing OLBC information")
756 hapd.request("DISABLE")
758 hapd2.request("DISABLE")
759 subprocess.call(['iw', 'reg', 'set', '00'])
761 def test_ap_require_ht(dev, apdev):
763 params = { "ssid": "require-ht",
765 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
767 dev[1].connect("require-ht", key_mgmt="NONE", scan_freq="2412",
768 disable_ht="1", wait_connect=False)
769 dev[0].connect("require-ht", key_mgmt="NONE", scan_freq="2412")
770 ev = dev[1].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
772 raise Exception("Association rejection timed out")
773 if "status_code=27" not in ev:
774 raise Exception("Unexpected rejection status code")
775 dev[2].connect("require-ht", key_mgmt="NONE", scan_freq="2412",
776 ht_mcs="0x01 00 00 00 00 00 00 00 00 00",
777 disable_max_amsdu="1", ampdu_factor="2",
778 ampdu_density="1", disable_ht40="1", disable_sgi="1",
781 def test_ap_require_ht_limited_rates(dev, apdev):
782 """Require HT with limited supported rates"""
783 params = { "ssid": "require-ht",
784 "supported_rates": "60 120 240 360 480 540",
786 hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
788 dev[1].connect("require-ht", key_mgmt="NONE", scan_freq="2412",
789 disable_ht="1", wait_connect=False)
790 dev[0].connect("require-ht", key_mgmt="NONE", scan_freq="2412")
791 ev = dev[1].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
793 raise Exception("Association rejection timed out")
794 if "status_code=27" not in ev:
795 raise Exception("Unexpected rejection status code")
797 def test_ap_ht_capab_not_supported(dev, apdev):
798 """HT configuration with driver not supporting all ht_capab entries"""
799 params = { "ssid": "test-ht40",
801 "ht_capab": "[HT40-][LDPC][SMPS-STATIC][SMPS-DYNAMIC][GF][SHORT-GI-20][SHORT-GI-40][TX-STBC][RX-STBC1][RX-STBC12][RX-STBC123][DELAYED-BA][MAX-AMSDU-7935][DSSS_CCK-40][LSIG-TXOP-PROT]"}
802 hapd = hostapd.add_ap(apdev[0]['ifname'], params, no_enable=True)
803 if "FAIL" not in hapd.request("ENABLE"):
804 raise Exception("Unexpected ENABLE success")
806 def test_ap_ht_40mhz_intolerant_sta(dev, apdev):
807 """Associated STA indicating 40 MHz intolerant"""
808 clear_scan_cache(apdev[0]['ifname'])
809 params = { "ssid": "intolerant",
811 "ht_capab": "[HT40-]" }
812 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
813 if hapd.get_status_field("num_sta_ht40_intolerant") != "0":
814 raise Exception("Unexpected num_sta_ht40_intolerant value")
815 if hapd.get_status_field("secondary_channel") != "-1":
816 raise Exception("Unexpected secondary_channel")
818 dev[0].connect("intolerant", key_mgmt="NONE", scan_freq="2437")
819 if hapd.get_status_field("num_sta_ht40_intolerant") != "0":
820 raise Exception("Unexpected num_sta_ht40_intolerant value")
821 if hapd.get_status_field("secondary_channel") != "-1":
822 raise Exception("Unexpected secondary_channel")
824 dev[2].connect("intolerant", key_mgmt="NONE", scan_freq="2437",
827 if hapd.get_status_field("num_sta_ht40_intolerant") != "1":
828 raise Exception("Unexpected num_sta_ht40_intolerant value (expected 1)")
829 if hapd.get_status_field("secondary_channel") != "0":
830 raise Exception("Unexpected secondary_channel (did not disable 40 MHz)")
832 dev[2].request("DISCONNECT")
834 if hapd.get_status_field("num_sta_ht40_intolerant") != "0":
835 raise Exception("Unexpected num_sta_ht40_intolerant value (expected 0)")
836 if hapd.get_status_field("secondary_channel") != "-1":
837 raise Exception("Unexpected secondary_channel (did not re-enable 40 MHz)")
839 def test_ap_ht_40mhz_intolerant_ap(dev, apdev):
840 """Associated STA reports 40 MHz intolerant AP after association"""
841 clear_scan_cache(apdev[0]['ifname'])
842 params = { "ssid": "ht",
844 "ht_capab": "[HT40-]",
845 "obss_interval": "3" }
846 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
848 dev[0].connect("ht", key_mgmt="NONE", scan_freq="2437")
850 if hapd.get_status_field("secondary_channel") != "-1":
851 raise Exception("Unexpected secondary channel information")
853 logger.info("Start 40 MHz intolerant AP")
854 params = { "ssid": "intolerant",
856 "ht_capab": "[40-INTOLERANT]" }
857 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
859 logger.info("Waiting for co-ex report from STA")
861 for i in range(0, 20):
863 if hapd.get_status_field("secondary_channel") == "0":
864 logger.info("AP moved to 20 MHz channel")
868 raise Exception("AP did not move to 20 MHz channel")
870 if "OK" not in hapd2.request("DISABLE"):
871 raise Exception("Failed to disable 40 MHz intolerant AP")
873 # make sure the intolerant AP disappears from scan results more quickly
874 dev[0].scan(type="ONLY", freq="2432", only_new=True)
875 dev[0].scan(type="ONLY", freq="2432", only_new=True)
876 dev[0].dump_monitor()
878 logger.info("Waiting for AP to move back to 40 MHz channel")
880 for i in range(0, 30):
882 if hapd.get_status_field("secondary_channel") == "-1":
883 logger.info("AP moved to 40 MHz channel")
887 raise Exception("AP did not move to 40 MHz channel")
889 def test_ap_ht40_csa(dev, apdev):
890 """HT with 40 MHz channel width and CSA"""
891 csa_supported(dev[0])
894 params = { "ssid": "ht",
895 "country_code": "US",
898 "ht_capab": "[HT40+]",
900 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
902 dev[0].connect("ht", key_mgmt="NONE", scan_freq="5180")
903 hwsim_utils.test_connectivity(dev[0], hapd)
905 hapd.request("CHAN_SWITCH 5 5200 ht sec_channel_offset=-1 bandwidth=40")
906 ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
908 raise Exception("CSA finished event timed out")
909 if "freq=5200" not in ev:
910 raise Exception("Unexpected channel in CSA finished event")
911 ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
913 raise Exception("Unexpected STA disconnection during CSA")
914 hwsim_utils.test_connectivity(dev[0], hapd)
916 hapd.request("CHAN_SWITCH 5 5180 ht sec_channel_offset=1 bandwidth=40")
917 ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
919 raise Exception("CSA finished event timed out")
920 if "freq=5180" not in ev:
921 raise Exception("Unexpected channel in CSA finished event")
922 ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
924 raise Exception("Unexpected STA disconnection during CSA")
925 hwsim_utils.test_connectivity(dev[0], hapd)
927 dev[0].request("DISCONNECT")
929 hapd.request("DISABLE")
930 subprocess.call(['iw', 'reg', 'set', '00'])
931 dev[0].flush_scan_cache()
933 def test_ap_ht40_csa2(dev, apdev):
934 """HT with 40 MHz channel width and CSA"""
935 csa_supported(dev[0])
938 params = { "ssid": "ht",
939 "country_code": "US",
942 "ht_capab": "[HT40+]",
944 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
946 dev[0].connect("ht", key_mgmt="NONE", scan_freq="5180")
947 hwsim_utils.test_connectivity(dev[0], hapd)
949 hapd.request("CHAN_SWITCH 5 5220 ht sec_channel_offset=1 bandwidth=40")
950 ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
952 raise Exception("CSA finished event timed out")
953 if "freq=5220" not in ev:
954 raise Exception("Unexpected channel in CSA finished event")
955 ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
957 raise Exception("Unexpected STA disconnection during CSA")
958 hwsim_utils.test_connectivity(dev[0], hapd)
960 hapd.request("CHAN_SWITCH 5 5180 ht sec_channel_offset=1 bandwidth=40")
961 ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
963 raise Exception("CSA finished event timed out")
964 if "freq=5180" not in ev:
965 raise Exception("Unexpected channel in CSA finished event")
966 ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
968 raise Exception("Unexpected STA disconnection during CSA")
969 hwsim_utils.test_connectivity(dev[0], hapd)
971 dev[0].request("DISCONNECT")
973 hapd.request("DISABLE")
974 subprocess.call(['iw', 'reg', 'set', '00'])
975 dev[0].flush_scan_cache()
977 def test_ap_ht40_csa3(dev, apdev):
978 """HT with 40 MHz channel width and CSA"""
979 csa_supported(dev[0])
982 params = { "ssid": "ht",
983 "country_code": "US",
986 "ht_capab": "[HT40+]",
988 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
990 dev[0].connect("ht", key_mgmt="NONE", scan_freq="5180")
991 hwsim_utils.test_connectivity(dev[0], hapd)
993 hapd.request("CHAN_SWITCH 5 5240 ht sec_channel_offset=-1 bandwidth=40")
994 ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
996 raise Exception("CSA finished event timed out")
997 if "freq=5240" not in ev:
998 raise Exception("Unexpected channel in CSA finished event")
999 ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
1001 raise Exception("Unexpected STA disconnection during CSA")
1002 hwsim_utils.test_connectivity(dev[0], hapd)
1004 hapd.request("CHAN_SWITCH 5 5180 ht sec_channel_offset=1 bandwidth=40")
1005 ev = hapd.wait_event(["AP-CSA-FINISHED"], timeout=10)
1007 raise Exception("CSA finished event timed out")
1008 if "freq=5180" not in ev:
1009 raise Exception("Unexpected channel in CSA finished event")
1010 ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=0.5)
1012 raise Exception("Unexpected STA disconnection during CSA")
1013 hwsim_utils.test_connectivity(dev[0], hapd)
1015 dev[0].request("DISCONNECT")
1017 hapd.request("DISABLE")
1018 subprocess.call(['iw', 'reg', 'set', '00'])
1019 dev[0].flush_scan_cache()
1021 def test_ap_ht_smps(dev, apdev):
1022 """SMPS AP configuration options"""
1023 params = { "ssid": "ht1", "ht_capab": "[SMPS-STATIC]" }
1025 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
1027 raise HwsimSkip("Assume mac80211_hwsim was not recent enough to support SMPS")
1028 params = { "ssid": "ht2", "ht_capab": "[SMPS-DYNAMIC]" }
1029 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
1031 dev[0].connect("ht1", key_mgmt="NONE", scan_freq="2412")
1032 dev[1].connect("ht2", key_mgmt="NONE", scan_freq="2412")
1033 hwsim_utils.test_connectivity(dev[0], hapd)
1034 hwsim_utils.test_connectivity(dev[1], hapd2)
1036 def test_prefer_ht20(dev, apdev):
1037 """Preference on HT20 over no-HT"""
1038 params = { "ssid": "test",
1041 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
1042 bssid = apdev[0]['bssid']
1043 params = { "ssid": "test",
1046 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
1047 bssid2 = apdev[1]['bssid']
1049 dev[0].scan_for_bss(bssid, freq=2412)
1050 dev[0].scan_for_bss(bssid2, freq=2412)
1051 dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
1052 if dev[0].get_status_field('bssid') != bssid2:
1053 raise Exception("Unexpected BSS selected")
1055 est = dev[0].get_bss(bssid)['est_throughput']
1057 raise Exception("Unexpected BSS0 est_throughput: " + est)
1059 est = dev[0].get_bss(bssid2)['est_throughput']
1061 raise Exception("Unexpected BSS1 est_throughput: " + est)
1063 def test_prefer_ht40(dev, apdev):
1064 """Preference on HT40 over HT20"""
1065 params = { "ssid": "test",
1068 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
1069 bssid = apdev[0]['bssid']
1070 params = { "ssid": "test",
1073 "ht_capab": "[HT40+]" }
1074 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
1075 bssid2 = apdev[1]['bssid']
1077 dev[0].scan_for_bss(bssid, freq=2412)
1078 dev[0].scan_for_bss(bssid2, freq=2412)
1079 dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
1080 if dev[0].get_status_field('bssid') != bssid2:
1081 raise Exception("Unexpected BSS selected")
1083 est = dev[0].get_bss(bssid)['est_throughput']
1085 raise Exception("Unexpected BSS0 est_throughput: " + est)
1087 est = dev[0].get_bss(bssid2)['est_throughput']
1089 raise Exception("Unexpected BSS1 est_throughput: " + est)
1091 def test_prefer_ht20_during_roam(dev, apdev):
1092 """Preference on HT20 over no-HT in roaming consideration"""
1093 params = { "ssid": "test",
1096 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
1097 bssid = apdev[0]['bssid']
1099 dev[0].scan_for_bss(bssid, freq=2412)
1100 dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
1102 params = { "ssid": "test",
1105 hapd2 = hostapd.add_ap(apdev[1]['ifname'], params)
1106 bssid2 = apdev[1]['bssid']
1107 dev[0].scan_for_bss(bssid2, freq=2412)
1108 dev[0].scan(freq=2412)
1109 dev[0].wait_connected()
1111 if dev[0].get_status_field('bssid') != bssid2:
1112 raise Exception("Unexpected BSS selected")
1114 def test_ap_ht40_5ghz_invalid_pair(dev, apdev):
1115 """HT40 on 5 GHz with invalid channel pair"""
1116 clear_scan_cache(apdev[0]['ifname'])
1118 params = { "ssid": "test-ht40",
1121 "country_code": "US",
1122 "ht_capab": "[HT40+]"}
1123 hapd = hostapd.add_ap(apdev[1]['ifname'], params, wait_enabled=False)
1124 ev = hapd.wait_event(["AP-DISABLED"], timeout=10)
1126 raise Exception("AP setup failure timed out")
1128 subprocess.call(['iw', 'reg', 'set', '00'])