test_ap_acs.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. # Test cases for automatic channel selection 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 logging
  7. logger = logging.getLogger()
  8. import subprocess
  9. import hostapd
  10. def wait_acs(hapd):
  11. ev = hapd.wait_event(["ACS-STARTED", "ACS-COMPLETED", "ACS-FAILED",
  12. "AP-ENABLED", "AP-DISABLED"], timeout=5)
  13. if not ev:
  14. raise Exception("ACS start timed out")
  15. if "ACS-STARTED" not in ev:
  16. raise Exception("Unexpected ACS event: " + ev)
  17. state = hapd.get_status_field("state")
  18. if state != "ACS":
  19. raise Exception("Unexpected interface state")
  20. ev = hapd.wait_event(["ACS-COMPLETED", "ACS-FAILED", "AP-ENABLED",
  21. "AP-DISABLED"], timeout=20)
  22. if not ev:
  23. raise Exception("ACS timed out")
  24. if "ACS-COMPLETED" not in ev:
  25. raise Exception("Unexpected ACS event: " + ev)
  26. ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=5)
  27. if not ev:
  28. raise Exception("AP setup timed out")
  29. if "AP-ENABLED" not in ev:
  30. raise Exception("Unexpected ACS event: " + ev)
  31. state = hapd.get_status_field("state")
  32. if state != "ENABLED":
  33. raise Exception("Unexpected interface state")
  34. def test_ap_acs(dev, apdev):
  35. """Automatic channel selection"""
  36. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  37. params['channel'] = '0'
  38. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  39. wait_acs(hapd)
  40. freq = hapd.get_status_field("freq")
  41. if int(freq) < 2400:
  42. raise Exception("Unexpected frequency")
  43. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  44. def test_ap_multi_bss_acs(dev, apdev):
  45. """hostapd start with a multi-BSS configuration file using ACS"""
  46. ifname = apdev[0]['ifname']
  47. hostapd.add_iface(ifname, 'multi-bss-acs.conf')
  48. hapd = hostapd.Hostapd(ifname)
  49. hapd.enable()
  50. wait_acs(hapd)
  51. freq = hapd.get_status_field("freq")
  52. if int(freq) < 2400:
  53. raise Exception("Unexpected frequency")
  54. dev[0].connect("bss-1", key_mgmt="NONE", scan_freq=freq)
  55. dev[1].connect("bss-2", psk="12345678", scan_freq=freq)
  56. dev[2].connect("bss-3", psk="qwertyuiop", scan_freq=freq)
  57. def test_ap_acs_40mhz(dev, apdev):
  58. """Automatic channel selection for 40 MHz channel"""
  59. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  60. params['channel'] = '0'
  61. params['ht_capab'] = '[HT40+]'
  62. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  63. wait_acs(hapd)
  64. freq = hapd.get_status_field("freq")
  65. if int(freq) < 2400:
  66. raise Exception("Unexpected frequency")
  67. sec = hapd.get_status_field("secondary_channel")
  68. if int(sec) == 0:
  69. raise Exception("Secondary channel not set")
  70. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  71. def test_ap_acs_5ghz(dev, apdev):
  72. """Automatic channel selection on 5 GHz"""
  73. try:
  74. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  75. params['hw_mode'] = 'a'
  76. params['channel'] = '0'
  77. params['country_code'] = 'US'
  78. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  79. # TODO: Remove exception acceptance once mac80211_hwsim supports ACS on
  80. # 5 GHz
  81. run = False
  82. try:
  83. wait_acs(hapd)
  84. run = True
  85. except Exception, e:
  86. logger.info("Ignore exception due to missing hwsim support: " + str(e))
  87. if run:
  88. freq = hapd.get_status_field("freq")
  89. if int(freq) < 5000:
  90. raise Exception("Unexpected frequency")
  91. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  92. finally:
  93. subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
  94. def test_ap_acs_5ghz_40mhz(dev, apdev):
  95. """Automatic channel selection on 5 GHz for 40 MHz channel"""
  96. try:
  97. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  98. params['hw_mode'] = 'a'
  99. params['channel'] = '0'
  100. params['ht_capab'] = '[HT40+]'
  101. params['country_code'] = 'US'
  102. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  103. # TODO: Remove exception acceptance once mac80211_hwsim supports ACS on
  104. # 5 GHz
  105. run = False
  106. try:
  107. wait_acs(hapd)
  108. run = True
  109. except Exception, e:
  110. logger.info("Ignore exception due to missing hwsim support: " + str(e))
  111. if run:
  112. freq = hapd.get_status_field("freq")
  113. if int(freq) < 5000:
  114. raise Exception("Unexpected frequency")
  115. sec = hapd.get_status_field("secondary_channel")
  116. if int(sec) == 0:
  117. raise Exception("Secondary channel not set")
  118. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  119. finally:
  120. subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])
  121. def test_ap_acs_vht(dev, apdev):
  122. """Automatic channel selection for VHT"""
  123. try:
  124. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  125. params['hw_mode'] = 'a'
  126. params['channel'] = '0'
  127. params['ht_capab'] = '[HT40+]'
  128. params['country_code'] = 'US'
  129. params['ieee80211ac'] = '1'
  130. params['vht_oper_chwidth'] = '1'
  131. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  132. # TODO: Remove exception acceptance once mac80211_hwsim supports ACS on
  133. # 5 GHz
  134. run = False
  135. try:
  136. wait_acs(hapd)
  137. run = True
  138. except Exception, e:
  139. logger.info("Ignore exception due to missing hwsim support: " + str(e))
  140. if run:
  141. freq = hapd.get_status_field("freq")
  142. if int(freq) < 5000:
  143. raise Exception("Unexpected frequency")
  144. sec = hapd.get_status_field("secondary_channel")
  145. if int(sec) == 0:
  146. raise Exception("Secondary channel not set")
  147. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  148. finally:
  149. subprocess.call(['sudo', 'iw', 'reg', 'set', '00'])