test_ap_ht.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # Test cases for HT operations with hostapd
  2. # Copyright (c) 2013, 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. import time
  7. import logging
  8. logger = logging.getLogger()
  9. import struct
  10. import hostapd
  11. def test_ap_ht40_scan(dev, apdev):
  12. """HT40 co-ex scan"""
  13. params = { "ssid": "test-ht40",
  14. "channel": "5",
  15. "ht_capab": "[HT40-]"}
  16. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  17. state = hapd.get_status_field("state")
  18. if state != "HT_SCAN":
  19. time.sleep(0.1)
  20. state = hapd.get_status_field("state")
  21. if state != "HT_SCAN":
  22. raise Exception("Unexpected interface state - expected HT_SCAN")
  23. ev = hapd.wait_event(["AP-ENABLED"], timeout=10)
  24. if not ev:
  25. raise Exception("AP setup timed out")
  26. state = hapd.get_status_field("state")
  27. if state != "ENABLED":
  28. raise Exception("Unexpected interface state - expected ENABLED")
  29. freq = hapd.get_status_field("freq")
  30. if freq != "2432":
  31. raise Exception("Unexpected frequency")
  32. pri = hapd.get_status_field("channel")
  33. if pri != "5":
  34. raise Exception("Unexpected primary channel")
  35. sec = hapd.get_status_field("secondary_channel")
  36. if sec != "-1":
  37. raise Exception("Unexpected secondary channel")
  38. dev[0].connect("test-ht40", key_mgmt="NONE", scan_freq=freq)
  39. def test_obss_scan(dev, apdev):
  40. """Overlapping BSS scan request"""
  41. params = { "ssid": "obss-scan",
  42. "channel": "6",
  43. "ht_capab": "[HT40-]",
  44. "obss_interval": "10" }
  45. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  46. dev[0].connect("obss-scan", key_mgmt="NONE", scan_freq="2437")
  47. hapd.set("ext_mgmt_frame_handling", "1")
  48. logger.info("Waiting for OBSS scan to occur")
  49. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout=15)
  50. if ev is None:
  51. raise Exception("Timed out while waiting for OBSS scan to start")
  52. ev = dev[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout=10)
  53. if ev is None:
  54. raise Exception("Timed out while waiting for OBSS scan results")
  55. received = False
  56. for i in range(0, 4):
  57. frame = hapd.mgmt_rx(timeout=5)
  58. if frame is None:
  59. raise Exception("MGMT RX wait timed out")
  60. if frame['subtype'] != 13:
  61. continue
  62. payload = frame['payload']
  63. if len(payload) < 3:
  64. continue
  65. (category, action, ie) = struct.unpack('BBB', payload[0:3])
  66. if category != 4:
  67. continue
  68. if action != 0:
  69. continue
  70. if ie == 72:
  71. logger.info("20/40 BSS Coexistence report received")
  72. received = True
  73. break
  74. if not received:
  75. raise Exception("20/40 BSS Coexistence report not seen")
  76. def test_olbc(dev, apdev):
  77. """OLBC detection"""
  78. params = { "ssid": "test-olbc",
  79. "channel": "6",
  80. "ht_capab": "[HT40-]" }
  81. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  82. status = hapd.get_status()
  83. if status['olbc'] != '0' or status['olbc_ht'] != '0':
  84. raise Exception("Unexpected OLBC information")
  85. params = { "ssid": "olbc-ap",
  86. "hw_mode": "b",
  87. "channel": "6",
  88. "wmm_enabled": "0" }
  89. hostapd.add_ap(apdev[1]['ifname'], params)
  90. time.sleep(0.5)
  91. status = hapd.get_status()
  92. if status['olbc'] != '1' or status['olbc_ht'] != '1':
  93. raise Exception("Missing OLBC information")
  94. def test_ap_require_ht(dev, apdev):
  95. """Require HT"""
  96. params = { "ssid": "require-ht",
  97. "require_ht": "1" }
  98. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  99. dev[0].connect("require-ht", key_mgmt="NONE", scan_freq="2412")