test_ap_acs.py 7.8 KB

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