test_ap_acs.py 8.7 KB

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