test_ap_dynamic.py 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. #!/usr/bin/python
  2. #
  3. # Test cases for dynamic BSS changes with hostapd
  4. # Copyright (c) 2013, Qualcomm Atheros, Inc.
  5. #
  6. # This software may be distributed under the terms of the BSD license.
  7. # See README for more details.
  8. import time
  9. import subprocess
  10. import logging
  11. logger = logging.getLogger()
  12. import hwsim_utils
  13. import hostapd
  14. def test_ap_change_ssid(dev, apdev):
  15. """Dynamic SSID change with hostapd and WPA2-PSK"""
  16. params = hostapd.wpa2_params(ssid="test-wpa2-psk-start",
  17. passphrase="12345678")
  18. hostapd.add_ap(apdev[0]['ifname'], params)
  19. id = dev[0].connect("test-wpa2-psk-start", psk="12345678",
  20. scan_freq="2412")
  21. dev[0].request("DISCONNECT")
  22. logger.info("Change SSID dynamically")
  23. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  24. res = hapd.request("SET ssid test-wpa2-psk-new")
  25. if "OK" not in res:
  26. raise Exception("SET command failed")
  27. res = hapd.request("RELOAD")
  28. if "OK" not in res:
  29. raise Exception("RELOAD command failed")
  30. dev[0].set_network_quoted(id, "ssid", "test-wpa2-psk-new")
  31. dev[0].connect_network(id)
  32. def multi_check(dev, check):
  33. id = []
  34. for i in range(0, 3):
  35. dev[i].request("BSS_FLUSH 0")
  36. dev[i].dump_monitor()
  37. id.append(dev[i].connect("bss-" + str(i + 1), key_mgmt="NONE",
  38. scan_freq="2412", wait_connect=check[i]))
  39. for i in range(0, 3):
  40. if not check[i]:
  41. ev = dev[i].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.2)
  42. if ev:
  43. raise Exception("Unexpected connection")
  44. for i in range(0, 3):
  45. dev[i].remove_network(id[i])
  46. time.sleep(0.3)
  47. res = ''
  48. for i in range(0, 3):
  49. res = res + dev[i].request("BSS RANGE=ALL MASK=0x2")
  50. for i in range(0, 3):
  51. if not check[i]:
  52. bssid = '02:00:00:00:03:0' + str(i)
  53. if bssid in res:
  54. raise Exception("Unexpected BSS" + str(i) + " in scan results")
  55. def test_ap_bss_add_remove(dev, apdev):
  56. """Dynamic BSS add/remove operations with hostapd"""
  57. for d in dev:
  58. d.request("SET ignore_old_scan_res 1")
  59. ifname1 = apdev[0]['ifname']
  60. ifname2 = apdev[0]['ifname'] + '-2'
  61. ifname3 = apdev[0]['ifname'] + '-3'
  62. logger.info("Set up three BSSes one by one")
  63. hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
  64. multi_check(dev, [ True, False, False ])
  65. hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
  66. multi_check(dev, [ True, True, False ])
  67. hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
  68. multi_check(dev, [ True, True, True ])
  69. logger.info("Remove the last BSS and re-add it")
  70. hostapd.remove_bss(ifname3)
  71. multi_check(dev, [ True, True, False ])
  72. hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
  73. multi_check(dev, [ True, True, True ])
  74. logger.info("Remove the middle BSS and re-add it")
  75. hostapd.remove_bss(ifname2)
  76. multi_check(dev, [ True, False, True ])
  77. hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
  78. multi_check(dev, [ True, True, True ])
  79. logger.info("Remove the first BSS and re-add it and other BSSs")
  80. hostapd.remove_bss(ifname1)
  81. multi_check(dev, [ False, False, False ])
  82. hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
  83. hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
  84. hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
  85. multi_check(dev, [ True, True, True ])
  86. logger.info("Remove two BSSes and re-add them")
  87. hostapd.remove_bss(ifname2)
  88. multi_check(dev, [ True, False, True ])
  89. hostapd.remove_bss(ifname3)
  90. multi_check(dev, [ True, False, False ])
  91. hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
  92. multi_check(dev, [ True, True, False ])
  93. hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
  94. multi_check(dev, [ True, True, True ])
  95. logger.info("Remove three BSSes in and re-add them")
  96. hostapd.remove_bss(ifname3)
  97. multi_check(dev, [ True, True, False ])
  98. hostapd.remove_bss(ifname2)
  99. multi_check(dev, [ True, False, False ])
  100. hostapd.remove_bss(ifname1)
  101. multi_check(dev, [ False, False, False ])
  102. hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
  103. multi_check(dev, [ True, False, False ])
  104. hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
  105. multi_check(dev, [ True, True, False ])
  106. hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
  107. multi_check(dev, [ True, True, True ])
  108. logger.info("Test error handling if a duplicate ifname is tried")
  109. hostapd.add_bss('phy3', ifname3, 'bss-3.conf', ignore_error=True)
  110. multi_check(dev, [ True, True, True ])
  111. def test_ap_multi_bss_config(dev, apdev):
  112. """hostapd start with a multi-BSS configuration file"""
  113. for d in dev:
  114. d.request("SET ignore_old_scan_res 1")
  115. ifname1 = apdev[0]['ifname']
  116. ifname2 = apdev[0]['ifname'] + '-2'
  117. ifname3 = apdev[0]['ifname'] + '-3'
  118. logger.info("Set up three BSSes with one configuration file")
  119. hostapd.add_iface(ifname1, 'multi-bss.conf')
  120. hapd = hostapd.Hostapd(ifname1)
  121. hapd.enable()
  122. multi_check(dev, [ True, True, True ])
  123. hostapd.remove_bss(ifname2)
  124. multi_check(dev, [ True, False, True ])
  125. hostapd.remove_bss(ifname3)
  126. multi_check(dev, [ True, False, False ])
  127. hostapd.remove_bss(ifname1)
  128. multi_check(dev, [ False, False, False ])
  129. hostapd.add_iface(ifname1, 'multi-bss.conf')
  130. hapd = hostapd.Hostapd(ifname1)
  131. hapd.enable()
  132. hostapd.remove_bss(ifname1)
  133. multi_check(dev, [ False, False, False ])
  134. def invalid_ap(hapd_global, ifname):
  135. logger.info("Trying to start AP " + ifname + " with invalid configuration")
  136. hapd_global.remove(ifname)
  137. hapd_global.add(ifname)
  138. hapd = hostapd.Hostapd(ifname)
  139. if not hapd.ping():
  140. raise Exception("Could not ping hostapd")
  141. hapd.set_defaults()
  142. hapd.set("ssid", "invalid-config")
  143. hapd.set("channel", "12345")
  144. try:
  145. hapd.enable()
  146. started = True
  147. except Exception, e:
  148. started = False
  149. if started:
  150. raise Exception("ENABLE command succeeded unexpectedly")
  151. return hapd
  152. def test_ap_invalid_config(dev, apdev):
  153. """Try to start AP with invalid configuration and fix configuration"""
  154. hapd_global = hostapd.HostapdGlobal()
  155. ifname = apdev[0]['ifname']
  156. hapd = invalid_ap(hapd_global, ifname)
  157. logger.info("Fix configuration and start AP again")
  158. hapd.set("channel", "1")
  159. hapd.enable()
  160. dev[0].connect("invalid-config", key_mgmt="NONE", scan_freq="2412")
  161. def test_ap_invalid_config2(dev, apdev):
  162. """Try to start AP with invalid configuration and remove interface"""
  163. hapd_global = hostapd.HostapdGlobal()
  164. ifname = apdev[0]['ifname']
  165. hapd = invalid_ap(hapd_global, ifname)
  166. logger.info("Remove interface with failed configuration")
  167. hapd_global.remove(ifname)
  168. def test_ap_remove_during_acs(dev, apdev):
  169. """Remove interface during ACS"""
  170. params = hostapd.wpa2_params(ssid="test-acs-remove", passphrase="12345678")
  171. params['channel'] = '0'
  172. ifname = apdev[0]['ifname']
  173. hapd = hostapd.HostapdGlobal()
  174. hostapd.add_ap(ifname, params)
  175. hapd.remove(ifname)
  176. def test_ap_remove_during_acs2(dev, apdev):
  177. """Remove BSS during ACS in multi-BSS configuration"""
  178. ifname = apdev[0]['ifname']
  179. ifname2 = ifname + "-2"
  180. hapd_global = hostapd.HostapdGlobal()
  181. hapd_global.add(ifname)
  182. hapd = hostapd.Hostapd(ifname)
  183. hapd.set_defaults()
  184. hapd.set("ssid", "test-acs-remove")
  185. hapd.set("channel", "0")
  186. hapd.set("bss", ifname2)
  187. hapd.set("ssid", "test-acs-remove2")
  188. hapd.enable()
  189. hapd_global.remove(ifname)
  190. def test_ap_remove_during_acs3(dev, apdev):
  191. """Remove second BSS during ACS in multi-BSS configuration"""
  192. ifname = apdev[0]['ifname']
  193. ifname2 = ifname + "-2"
  194. hapd_global = hostapd.HostapdGlobal()
  195. hapd_global.add(ifname)
  196. hapd = hostapd.Hostapd(ifname)
  197. hapd.set_defaults()
  198. hapd.set("ssid", "test-acs-remove")
  199. hapd.set("channel", "0")
  200. hapd.set("bss", ifname2)
  201. hapd.set("ssid", "test-acs-remove2")
  202. hapd.enable()
  203. hapd_global.remove(ifname2)
  204. def test_ap_remove_during_ht_coex_scan(dev, apdev):
  205. """Remove interface during HT co-ex scan"""
  206. params = hostapd.wpa2_params(ssid="test-ht-remove", passphrase="12345678")
  207. params['channel'] = '1'
  208. params['ht_capab'] = "[HT40+]"
  209. ifname = apdev[0]['ifname']
  210. hapd = hostapd.HostapdGlobal()
  211. hostapd.add_ap(ifname, params)
  212. hapd.remove(ifname)
  213. def test_ap_remove_during_ht_coex_scan2(dev, apdev):
  214. """Remove BSS during HT co-ex scan in multi-BSS configuration"""
  215. ifname = apdev[0]['ifname']
  216. ifname2 = ifname + "-2"
  217. hapd_global = hostapd.HostapdGlobal()
  218. hapd_global.add(ifname)
  219. hapd = hostapd.Hostapd(ifname)
  220. hapd.set_defaults()
  221. hapd.set("ssid", "test-ht-remove")
  222. hapd.set("channel", "1")
  223. hapd.set("ht_capab", "[HT40+]")
  224. hapd.set("bss", ifname2)
  225. hapd.set("ssid", "test-ht-remove2")
  226. hapd.enable()
  227. hapd_global.remove(ifname)
  228. def test_ap_remove_during_ht_coex_scan3(dev, apdev):
  229. """Remove second BSS during HT co-ex scan in multi-BSS configuration"""
  230. ifname = apdev[0]['ifname']
  231. ifname2 = ifname + "-2"
  232. hapd_global = hostapd.HostapdGlobal()
  233. hapd_global.add(ifname)
  234. hapd = hostapd.Hostapd(ifname)
  235. hapd.set_defaults()
  236. hapd.set("ssid", "test-ht-remove")
  237. hapd.set("channel", "1")
  238. hapd.set("ht_capab", "[HT40+]")
  239. hapd.set("bss", ifname2)
  240. hapd.set("ssid", "test-ht-remove2")
  241. hapd.enable()
  242. hapd_global.remove(ifname2)