test_ap_dynamic.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. dev[0].request("DISCONNECT")
  21. logger.info("Change SSID dynamically")
  22. hapd = hostapd.Hostapd(apdev[0]['ifname'])
  23. res = hapd.request("SET ssid test-wpa2-psk-new")
  24. if "OK" not in res:
  25. raise Exception("SET command failed")
  26. res = hapd.request("RELOAD")
  27. if "OK" not in res:
  28. raise Exception("RELOAD command failed")
  29. dev[0].set_network_quoted(id, "ssid", "test-wpa2-psk-new")
  30. dev[0].connect_network(id)
  31. def multi_check(dev, check0, check1, check2):
  32. for d in dev:
  33. d.request("BSS_FLUSH 0")
  34. d.dump_monitor()
  35. id0 = dev[0].connect("bss-1", key_mgmt="NONE", scan_freq="2412",
  36. wait_connect=check0)
  37. id1 = dev[1].connect("bss-2", key_mgmt="NONE", scan_freq="2412",
  38. wait_connect=check1)
  39. id2 = dev[2].connect("bss-3", key_mgmt="NONE", scan_freq="2412",
  40. wait_connect=check2)
  41. if not check0:
  42. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.2)
  43. if ev:
  44. raise Exception("Unexpected connection")
  45. if not check1:
  46. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.2)
  47. if ev:
  48. raise Exception("Unexpected connection")
  49. if not check2:
  50. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.2)
  51. if ev:
  52. raise Exception("Unexpected connection")
  53. dev[0].remove_network(id0)
  54. dev[1].remove_network(id1)
  55. dev[2].remove_network(id2)
  56. time.sleep(0.3)
  57. res0 = dev[0].request("BSS RANGE=ALL MASK=0x2")
  58. res1 = dev[1].request("BSS RANGE=ALL MASK=0x2")
  59. res2 = dev[2].request("BSS RANGE=ALL MASK=0x2")
  60. if not check0:
  61. if ('02:00:00:00:03:00' in res0 or
  62. '02:00:00:00:03:00' in res1 or
  63. '02:00:00:00:03:00' in res2):
  64. raise Exception("Unexpected BSS0 in scan results")
  65. if not check1:
  66. if ('02:00:00:00:03:01' in res0 or
  67. '02:00:00:00:03:01' in res1 or
  68. '02:00:00:00:03:01' in res2):
  69. raise Exception("Unexpected BSS1 in scan results")
  70. if not check2:
  71. if ('02:00:00:00:03:02' in res0 or
  72. '02:00:00:00:03:02' in res1 or
  73. '02:00:00:00:03:02' in res2):
  74. raise Exception("Unexpected BSS2 in scan results")
  75. def test_ap_bss_add_remove(dev, apdev):
  76. """Dynamic BSS add/remove operations with hostapd"""
  77. for d in dev:
  78. d.request("SET ignore_old_scan_res 1")
  79. ifname1 = apdev[0]['ifname']
  80. ifname2 = apdev[0]['ifname'] + '-2'
  81. ifname3 = apdev[0]['ifname'] + '-3'
  82. logger.info("Set up three BSSes one by one")
  83. hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
  84. multi_check(dev, True, False, False)
  85. hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
  86. multi_check(dev, True, True, False)
  87. hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
  88. multi_check(dev, True, True, True)
  89. logger.info("Remove the last BSS and re-add it")
  90. hostapd.remove_bss(ifname3)
  91. multi_check(dev, True, True, False)
  92. hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
  93. multi_check(dev, True, True, True)
  94. logger.info("Remove the middle BSS and re-add it")
  95. hostapd.remove_bss(ifname2)
  96. multi_check(dev, True, False, True)
  97. hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
  98. multi_check(dev, True, True, True)
  99. logger.info("Remove the first BSS and re-add it")
  100. hostapd.remove_bss(ifname1)
  101. multi_check(dev, False, True, True)
  102. hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
  103. multi_check(dev, True, True, True)
  104. logger.info("Remove two BSSes and re-add them")
  105. hostapd.remove_bss(ifname2)
  106. multi_check(dev, True, False, True)
  107. hostapd.remove_bss(ifname3)
  108. multi_check(dev, True, False, False)
  109. dev[0].request("NOTE failure-done")
  110. hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
  111. multi_check(dev, True, True, False)
  112. hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
  113. multi_check(dev, True, True, True)
  114. logger.info("Remove three BSSes and re-add them")
  115. hostapd.remove_bss(ifname1)
  116. multi_check(dev, False, True, True)
  117. hostapd.remove_bss(ifname2)
  118. multi_check(dev, False, False, True)
  119. hostapd.remove_bss(ifname3)
  120. multi_check(dev, False, False, False)
  121. hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
  122. multi_check(dev, True, False, False)
  123. hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
  124. multi_check(dev, True, True, False)
  125. hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
  126. multi_check(dev, True, True, True)
  127. logger.info("Remove three BSSes in reverse order and re-add them")
  128. hostapd.remove_bss(ifname3)
  129. multi_check(dev, True, True, False)
  130. hostapd.remove_bss(ifname2)
  131. multi_check(dev, True, False, False)
  132. hostapd.remove_bss(ifname1)
  133. hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
  134. multi_check(dev, True, False, False)
  135. hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
  136. multi_check(dev, True, True, False)
  137. hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
  138. multi_check(dev, True, True, True)
  139. logger.info("Test error handling if a duplicate ifname is tried")
  140. hostapd.add_bss('phy3', ifname3, 'bss-3.conf', ignore_error=True)
  141. multi_check(dev, True, True, True)