test_ap_dynamic.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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")
  80. hostapd.remove_bss(ifname1)
  81. multi_check(dev, [ False, True, True ])
  82. hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
  83. multi_check(dev, [ True, True, True ])
  84. logger.info("Remove two BSSes and re-add them")
  85. hostapd.remove_bss(ifname2)
  86. multi_check(dev, [ True, False, True ])
  87. hostapd.remove_bss(ifname3)
  88. multi_check(dev, [ True, False, False ])
  89. dev[0].request("NOTE failure-done")
  90. hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
  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 three BSSes and re-add them")
  95. hostapd.remove_bss(ifname1)
  96. multi_check(dev, [ False, True, True ])
  97. hostapd.remove_bss(ifname2)
  98. multi_check(dev, [ False, False, True ])
  99. hostapd.remove_bss(ifname3)
  100. multi_check(dev, [ False, False, False ])
  101. hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
  102. multi_check(dev, [ True, False, False ])
  103. hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
  104. multi_check(dev, [ True, True, False ])
  105. hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
  106. multi_check(dev, [ True, True, True ])
  107. logger.info("Remove three BSSes in reverse order and re-add them")
  108. hostapd.remove_bss(ifname3)
  109. multi_check(dev, [ True, True, False ])
  110. hostapd.remove_bss(ifname2)
  111. multi_check(dev, [ True, False, False ])
  112. hostapd.remove_bss(ifname1)
  113. hostapd.add_bss('phy3', ifname1, 'bss-1.conf')
  114. multi_check(dev, [ True, False, False ])
  115. hostapd.add_bss('phy3', ifname2, 'bss-2.conf')
  116. multi_check(dev, [ True, True, False ])
  117. hostapd.add_bss('phy3', ifname3, 'bss-3.conf')
  118. multi_check(dev, [ True, True, True ])
  119. logger.info("Test error handling if a duplicate ifname is tried")
  120. hostapd.add_bss('phy3', ifname3, 'bss-3.conf', ignore_error=True)
  121. multi_check(dev, [ True, True, True ])