test_ap_acs.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. # Test cases for automatic channel selection with hostapd
  2. # Copyright (c) 2013-2015, 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 time
  10. import hostapd
  11. from utils import skip_with_fips
  12. from test_ap_ht import clear_scan_cache
  13. def force_prev_ap_on_24g(ap):
  14. # For now, make sure the last operating channel was on 2.4 GHz band to get
  15. # sufficient survey data from mac80211_hwsim.
  16. hostapd.add_ap(ap, { "ssid": "open" })
  17. time.sleep(0.1)
  18. hostapd.remove_bss(ap)
  19. def force_prev_ap_on_5g(ap):
  20. # For now, make sure the last operating channel was on 5 GHz band to get
  21. # sufficient survey data from mac80211_hwsim.
  22. hostapd.add_ap(ap, { "ssid": "open", "hw_mode": "a",
  23. "channel": "36", "country_code": "US" })
  24. time.sleep(0.1)
  25. hostapd.remove_bss(ap)
  26. def wait_acs(hapd):
  27. ev = hapd.wait_event(["ACS-STARTED", "ACS-COMPLETED", "ACS-FAILED",
  28. "AP-ENABLED", "AP-DISABLED"], timeout=5)
  29. if not ev:
  30. raise Exception("ACS start timed out")
  31. if "ACS-STARTED" not in ev:
  32. raise Exception("Unexpected ACS event: " + ev)
  33. state = hapd.get_status_field("state")
  34. if state != "ACS":
  35. raise Exception("Unexpected interface state")
  36. ev = hapd.wait_event(["ACS-COMPLETED", "ACS-FAILED", "AP-ENABLED",
  37. "AP-DISABLED"], timeout=20)
  38. if not ev:
  39. raise Exception("ACS timed out")
  40. if "ACS-COMPLETED" not in ev:
  41. raise Exception("Unexpected ACS event: " + ev)
  42. ev = hapd.wait_event(["AP-ENABLED", "AP-DISABLED"], timeout=5)
  43. if not ev:
  44. raise Exception("AP setup timed out")
  45. if "AP-ENABLED" not in ev:
  46. raise Exception("Unexpected ACS event: " + ev)
  47. state = hapd.get_status_field("state")
  48. if state != "ENABLED":
  49. raise Exception("Unexpected interface state")
  50. def test_ap_acs(dev, apdev):
  51. """Automatic channel selection"""
  52. force_prev_ap_on_24g(apdev[0])
  53. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  54. params['channel'] = '0'
  55. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  56. wait_acs(hapd)
  57. freq = hapd.get_status_field("freq")
  58. if int(freq) < 2400:
  59. raise Exception("Unexpected frequency")
  60. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  61. def test_ap_acs_chanlist(dev, apdev):
  62. """Automatic channel selection with chanlist set"""
  63. force_prev_ap_on_24g(apdev[0])
  64. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  65. params['channel'] = '0'
  66. params['chanlist'] = '1 6 11'
  67. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  68. wait_acs(hapd)
  69. freq = hapd.get_status_field("freq")
  70. if int(freq) < 2400:
  71. raise Exception("Unexpected frequency")
  72. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  73. def test_ap_multi_bss_acs(dev, apdev):
  74. """hostapd start with a multi-BSS configuration file using ACS"""
  75. skip_with_fips(dev[0])
  76. force_prev_ap_on_24g(apdev[0])
  77. # start the actual test
  78. hapd = hostapd.add_iface(apdev[0], 'multi-bss-acs.conf')
  79. hapd.enable()
  80. wait_acs(hapd)
  81. freq = hapd.get_status_field("freq")
  82. if int(freq) < 2400:
  83. raise Exception("Unexpected frequency")
  84. dev[0].connect("bss-1", key_mgmt="NONE", scan_freq=freq)
  85. dev[1].connect("bss-2", psk="12345678", scan_freq=freq)
  86. dev[2].connect("bss-3", psk="qwertyuiop", scan_freq=freq)
  87. def test_ap_acs_40mhz(dev, apdev):
  88. """Automatic channel selection for 40 MHz channel"""
  89. clear_scan_cache(apdev[0]['ifname'])
  90. force_prev_ap_on_24g(apdev[0])
  91. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  92. params['channel'] = '0'
  93. params['ht_capab'] = '[HT40+]'
  94. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  95. wait_acs(hapd)
  96. freq = hapd.get_status_field("freq")
  97. if int(freq) < 2400:
  98. raise Exception("Unexpected frequency")
  99. sec = hapd.get_status_field("secondary_channel")
  100. if int(sec) == 0:
  101. raise Exception("Secondary channel not set")
  102. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  103. def test_ap_acs_5ghz(dev, apdev):
  104. """Automatic channel selection on 5 GHz"""
  105. try:
  106. hapd = None
  107. force_prev_ap_on_5g(apdev[0])
  108. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  109. params['hw_mode'] = 'a'
  110. params['channel'] = '0'
  111. params['country_code'] = 'US'
  112. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  113. wait_acs(hapd)
  114. freq = hapd.get_status_field("freq")
  115. if int(freq) < 5000:
  116. raise Exception("Unexpected frequency")
  117. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  118. finally:
  119. dev[0].request("DISCONNECT")
  120. if hapd:
  121. hapd.request("DISABLE")
  122. subprocess.call(['iw', 'reg', 'set', '00'])
  123. dev[0].flush_scan_cache()
  124. def test_ap_acs_5ghz_40mhz(dev, apdev):
  125. """Automatic channel selection on 5 GHz for 40 MHz channel"""
  126. try:
  127. hapd = None
  128. force_prev_ap_on_5g(apdev[0])
  129. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  130. params['hw_mode'] = 'a'
  131. params['channel'] = '0'
  132. params['ht_capab'] = '[HT40+]'
  133. params['country_code'] = 'US'
  134. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  135. wait_acs(hapd)
  136. freq = hapd.get_status_field("freq")
  137. if int(freq) < 5000:
  138. raise Exception("Unexpected frequency")
  139. sec = hapd.get_status_field("secondary_channel")
  140. if int(sec) == 0:
  141. raise Exception("Secondary channel not set")
  142. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  143. finally:
  144. dev[0].request("DISCONNECT")
  145. if hapd:
  146. hapd.request("DISABLE")
  147. subprocess.call(['iw', 'reg', 'set', '00'])
  148. dev[0].flush_scan_cache()
  149. def test_ap_acs_vht(dev, apdev):
  150. """Automatic channel selection for VHT"""
  151. try:
  152. hapd = None
  153. force_prev_ap_on_5g(apdev[0])
  154. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  155. params['hw_mode'] = 'a'
  156. params['channel'] = '0'
  157. params['ht_capab'] = '[HT40+]'
  158. params['country_code'] = 'US'
  159. params['ieee80211ac'] = '1'
  160. params['vht_oper_chwidth'] = '1'
  161. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  162. wait_acs(hapd)
  163. freq = hapd.get_status_field("freq")
  164. if int(freq) < 5000:
  165. raise Exception("Unexpected frequency")
  166. sec = hapd.get_status_field("secondary_channel")
  167. if int(sec) == 0:
  168. raise Exception("Secondary channel not set")
  169. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  170. finally:
  171. dev[0].request("DISCONNECT")
  172. if hapd:
  173. hapd.request("DISABLE")
  174. subprocess.call(['iw', 'reg', 'set', '00'])
  175. dev[0].flush_scan_cache()
  176. def test_ap_acs_bias(dev, apdev):
  177. """Automatic channel selection with bias values"""
  178. force_prev_ap_on_24g(apdev[0])
  179. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  180. params['channel'] = '0'
  181. params['acs_chan_bias'] = '1:0.8 3:1.2 6:0.7 11:0.8'
  182. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  183. wait_acs(hapd)
  184. freq = hapd.get_status_field("freq")
  185. if int(freq) < 2400:
  186. raise Exception("Unexpected frequency")
  187. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)