test_ap_acs.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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_multi_bss_acs(dev, apdev):
  63. """hostapd start with a multi-BSS configuration file using ACS"""
  64. ifname = apdev[0]['ifname']
  65. force_prev_ap_on_24g(apdev[0])
  66. # start the actual test
  67. hostapd.add_iface(ifname, 'multi-bss-acs.conf')
  68. hapd = hostapd.Hostapd(ifname)
  69. hapd.enable()
  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("bss-1", key_mgmt="NONE", scan_freq=freq)
  75. dev[1].connect("bss-2", psk="12345678", scan_freq=freq)
  76. dev[2].connect("bss-3", psk="qwertyuiop", scan_freq=freq)
  77. def test_ap_acs_40mhz(dev, apdev):
  78. """Automatic channel selection for 40 MHz channel"""
  79. clear_scan_cache(apdev[0]['ifname'])
  80. force_prev_ap_on_24g(apdev[0])
  81. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  82. params['channel'] = '0'
  83. params['ht_capab'] = '[HT40+]'
  84. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  85. wait_acs(hapd)
  86. freq = hapd.get_status_field("freq")
  87. if int(freq) < 2400:
  88. raise Exception("Unexpected frequency")
  89. sec = hapd.get_status_field("secondary_channel")
  90. if int(sec) == 0:
  91. raise Exception("Secondary channel not set")
  92. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  93. def test_ap_acs_5ghz(dev, apdev):
  94. """Automatic channel selection on 5 GHz"""
  95. try:
  96. hapd = None
  97. force_prev_ap_on_5g(apdev[0])
  98. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  99. params['hw_mode'] = 'a'
  100. params['channel'] = '0'
  101. params['country_code'] = 'US'
  102. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  103. wait_acs(hapd)
  104. freq = hapd.get_status_field("freq")
  105. if int(freq) < 5000:
  106. raise Exception("Unexpected frequency")
  107. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  108. finally:
  109. dev[0].request("DISCONNECT")
  110. if hapd:
  111. hapd.request("DISABLE")
  112. subprocess.call(['iw', 'reg', 'set', '00'])
  113. dev[0].flush_scan_cache()
  114. def test_ap_acs_5ghz_40mhz(dev, apdev):
  115. """Automatic channel selection on 5 GHz for 40 MHz channel"""
  116. try:
  117. hapd = None
  118. force_prev_ap_on_5g(apdev[0])
  119. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  120. params['hw_mode'] = 'a'
  121. params['channel'] = '0'
  122. params['ht_capab'] = '[HT40+]'
  123. params['country_code'] = 'US'
  124. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  125. wait_acs(hapd)
  126. freq = hapd.get_status_field("freq")
  127. if int(freq) < 5000:
  128. raise Exception("Unexpected frequency")
  129. sec = hapd.get_status_field("secondary_channel")
  130. if int(sec) == 0:
  131. raise Exception("Secondary channel not set")
  132. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  133. finally:
  134. dev[0].request("DISCONNECT")
  135. if hapd:
  136. hapd.request("DISABLE")
  137. subprocess.call(['iw', 'reg', 'set', '00'])
  138. dev[0].flush_scan_cache()
  139. def test_ap_acs_vht(dev, apdev):
  140. """Automatic channel selection for VHT"""
  141. try:
  142. hapd = None
  143. force_prev_ap_on_5g(apdev[0])
  144. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  145. params['hw_mode'] = 'a'
  146. params['channel'] = '0'
  147. params['ht_capab'] = '[HT40+]'
  148. params['country_code'] = 'US'
  149. params['ieee80211ac'] = '1'
  150. params['vht_oper_chwidth'] = '1'
  151. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  152. wait_acs(hapd)
  153. freq = hapd.get_status_field("freq")
  154. if int(freq) < 5000:
  155. raise Exception("Unexpected frequency")
  156. sec = hapd.get_status_field("secondary_channel")
  157. if int(sec) == 0:
  158. raise Exception("Secondary channel not set")
  159. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)
  160. finally:
  161. dev[0].request("DISCONNECT")
  162. if hapd:
  163. hapd.request("DISABLE")
  164. subprocess.call(['iw', 'reg', 'set', '00'])
  165. dev[0].flush_scan_cache()
  166. def test_ap_acs_bias(dev, apdev):
  167. """Automatic channel selection with bias values"""
  168. force_prev_ap_on_24g(apdev[0])
  169. params = hostapd.wpa2_params(ssid="test-acs", passphrase="12345678")
  170. params['channel'] = '0'
  171. params['acs_chan_bias'] = '1:0.8 3:1.2 6:0.7 11:0.8'
  172. hapd = hostapd.add_ap(apdev[0]['ifname'], params, wait_enabled=False)
  173. wait_acs(hapd)
  174. freq = hapd.get_status_field("freq")
  175. if int(freq) < 2400:
  176. raise Exception("Unexpected frequency")
  177. dev[0].connect("test-acs", psk="12345678", scan_freq=freq)