test_ap_acs.py 7.7 KB

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