test_ap_acs.py 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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_5ghz(dev, apdev):
  103. """Automatic channel selection on 5 GHz"""
  104. try:
  105. hapd = None
  106. force_prev_ap_on_5g(apdev[0])
  107. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  108. params['hw_mode'] = 'a'
  109. params['channel'] = '0'
  110. params['country_code'] = 'US'
  111. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  112. wait_acs(hapd)
  113. freq = hapd.get_status_field("freq")
  114. if int(freq) < 5000:
  115. raise Exception("Unexpected frequency")
  116. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  117. finally:
  118. dev[0].request("DISCONNECT")
  119. if hapd:
  120. hapd.request("DISABLE")
  121. hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
  122. dev[0].flush_scan_cache()
  123. def test_ap_acs_5ghz_40mhz(dev, apdev):
  124. """Automatic channel selection on 5 GHz for 40 MHz channel"""
  125. try:
  126. hapd = None
  127. force_prev_ap_on_5g(apdev[0])
  128. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  129. params['hw_mode'] = 'a'
  130. params['channel'] = '0'
  131. params['ht_capab'] = '[HT40+]'
  132. params['country_code'] = 'US'
  133. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  134. wait_acs(hapd)
  135. freq = hapd.get_status_field("freq")
  136. if int(freq) < 5000:
  137. raise Exception("Unexpected frequency")
  138. sec = hapd.get_status_field("secondary_channel")
  139. if int(sec) == 0:
  140. raise Exception("Secondary channel not set")
  141. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  142. finally:
  143. dev[0].request("DISCONNECT")
  144. if hapd:
  145. hapd.request("DISABLE")
  146. hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
  147. dev[0].flush_scan_cache()
  148. def test_ap_acs_vht(dev, apdev):
  149. """Automatic channel selection for VHT"""
  150. try:
  151. hapd = None
  152. force_prev_ap_on_5g(apdev[0])
  153. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  154. params['hw_mode'] = 'a'
  155. params['channel'] = '0'
  156. params['ht_capab'] = '[HT40+]'
  157. params['country_code'] = 'US'
  158. params['ieee80211ac'] = '1'
  159. params['vht_oper_chwidth'] = '1'
  160. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  161. wait_acs(hapd)
  162. freq = hapd.get_status_field("freq")
  163. if int(freq) < 5000:
  164. raise Exception("Unexpected frequency")
  165. sec = hapd.get_status_field("secondary_channel")
  166. if int(sec) == 0:
  167. raise Exception("Secondary channel not set")
  168. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  169. finally:
  170. dev[0].request("DISCONNECT")
  171. if hapd:
  172. hapd.request("DISABLE")
  173. hostapd.cmd_execute(apdev[0], ['iw', 'reg', 'set', '00'])
  174. dev[0].flush_scan_cache()
  175. def test_ap_acs_bias(dev, apdev):
  176. """Automatic channel selection with bias values"""
  177. force_prev_ap_on_24g(apdev[0])
  178. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  179. params['channel'] = '0'
  180. params['acs_chan_bias'] = '1:0.8 3:1.2 6:0.7 11:0.8'
  181. hapd = hostapd.add_ap(apdev[0], params, wait_enabled=False)
  182. wait_acs(hapd)
  183. freq = hapd.get_status_field("freq")
  184. if int(freq) < 2400:
  185. raise Exception("Unexpected frequency")
  186. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)