test_ap_ht.py 3.8 KB

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