test_hapd_ctrl.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. # hostapd control interface
  2. # Copyright (c) 2014, Qualcomm Atheros, Inc.
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import hostapd
  7. def test_hapd_ctrl_status(dev, apdev):
  8. """hostapd ctrl_iface STATUS commands"""
  9. ssid = "hapd-ctrl"
  10. bssid = apdev[0]['bssid']
  11. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  12. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  13. status = hapd.get_status()
  14. driver = hapd.get_driver_status()
  15. if status['bss[0]'] != apdev[0]['ifname']:
  16. raise Exception("Unexpected bss[0]")
  17. if status['ssid[0]'] != ssid:
  18. raise Exception("Unexpected ssid[0]")
  19. if status['bssid[0]'] != bssid:
  20. raise Exception("Unexpected bssid[0]")
  21. if status['freq'] != "2412":
  22. raise Exception("Unexpected freq")
  23. if driver['beacon_set'] != "1":
  24. raise Exception("Unexpected beacon_set")
  25. if driver['addr'] != bssid:
  26. raise Exception("Unexpected addr")
  27. def test_hapd_ctrl_p2p_manager(dev, apdev):
  28. """hostapd as P2P Device manager"""
  29. ssid = "hapd-p2p-mgr"
  30. passphrase = "12345678"
  31. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  32. params['manage_p2p'] = '1'
  33. params['allow_cross_connection'] = '0'
  34. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  35. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  36. addr = dev[0].p2p_dev_addr()
  37. if "OK" not in hapd.request("DEAUTHENTICATE " + addr + " p2p=2"):
  38. raise Exception("DEAUTHENTICATE command failed")
  39. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
  40. if ev is None:
  41. raise Exception("Disconnection event timed out")
  42. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"])
  43. if ev is None:
  44. raise Exception("Re-connection timed out")
  45. if "OK" not in hapd.request("DISASSOCIATE " + addr + " p2p=2"):
  46. raise Exception("DISASSOCIATE command failed")
  47. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
  48. if ev is None:
  49. raise Exception("Disconnection event timed out")
  50. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"])
  51. if ev is None:
  52. raise Exception("Re-connection timed out")
  53. def test_hapd_ctrl_sta(dev, apdev):
  54. """hostapd and STA ctrl_iface commands"""
  55. ssid = "hapd-ctrl-sta"
  56. passphrase = "12345678"
  57. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  58. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  59. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  60. addr = dev[0].p2p_dev_addr()
  61. if "FAIL" in hapd.request("STA " + addr):
  62. raise Exception("Unexpected STA failure")
  63. if "FAIL" not in hapd.request("STA " + addr + " eapol"):
  64. raise Exception("Unexpected STA-eapol success")
  65. if "FAIL" not in hapd.request("STA 00:11:22:33:44"):
  66. raise Exception("Unexpected STA success")
  67. if "FAIL" not in hapd.request("STA 00:11:22:33:44:55"):
  68. raise Exception("Unexpected STA success")
  69. if len(hapd.request("STA-NEXT " + addr).splitlines()) > 0:
  70. raise Exception("Unexpected STA-NEXT result")
  71. if "FAIL" not in hapd.request("STA-NEXT 00:11:22:33:44"):
  72. raise Exception("Unexpected STA-NEXT success")
  73. def test_hapd_ctrl_disconnect(dev, apdev):
  74. """hostapd and disconnection ctrl_iface commands"""
  75. ssid = "hapd-ctrl"
  76. passphrase = "12345678"
  77. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  78. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  79. dev[0].connect(ssid, psk=passphrase, scan_freq="2412")
  80. addr = dev[0].p2p_dev_addr()
  81. if "FAIL" not in hapd.request("DEAUTHENTICATE 00:11:22:33:44"):
  82. raise Exception("Unexpected DEAUTHENTICATE success")
  83. if "OK" not in hapd.request("DEAUTHENTICATE ff:ff:ff:ff:ff:ff"):
  84. raise Exception("Unexpected DEAUTHENTICATE failure")
  85. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
  86. if ev is None:
  87. raise Exception("Disconnection event timed out")
  88. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"])
  89. if ev is None:
  90. raise Exception("Re-connection timed out")
  91. if "FAIL" not in hapd.request("DISASSOCIATE 00:11:22:33:44"):
  92. raise Exception("Unexpected DISASSOCIATE success")
  93. if "OK" not in hapd.request("DISASSOCIATE ff:ff:ff:ff:ff:ff"):
  94. raise Exception("Unexpected DISASSOCIATE failure")
  95. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
  96. if ev is None:
  97. raise Exception("Disconnection event timed out")
  98. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"])
  99. if ev is None:
  100. raise Exception("Re-connection timed out")
  101. def test_hapd_ctrl_chan_switch(dev, apdev):
  102. """hostapd and CHAN_SWITCH ctrl_iface command"""
  103. ssid = "hapd-ctrl"
  104. params = { "ssid": ssid }
  105. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  106. if "FAIL" not in hapd.request("CHAN_SWITCH "):
  107. raise Exception("Unexpected CHAN_SWITCH success")
  108. if "FAIL" not in hapd.request("CHAN_SWITCH qwerty 2422"):
  109. raise Exception("Unexpected CHAN_SWITCH success")
  110. if "FAIL" not in hapd.request("CHAN_SWITCH 5 qwerty"):
  111. raise Exception("Unexpected CHAN_SWITCH success")
  112. if "FAIL" not in hapd.request("CHAN_SWITCH 0 2432 center_freq1=123 center_freq2=234 bandwidth=1000 sec_channel_offset=20 ht vht"):
  113. raise Exception("Unexpected CHAN_SWITCH success")
  114. def test_hapd_ctrl_level(dev, apdev):
  115. """hostapd and LEVEL ctrl_iface command"""
  116. ssid = "hapd-ctrl"
  117. params = { "ssid": ssid }
  118. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  119. if "FAIL" not in hapd.request("LEVEL 0"):
  120. raise Exception("Unexpected LEVEL success on non-monitor interface")
  121. def test_hapd_ctrl_new_sta(dev, apdev):
  122. """hostapd and NEW_STA ctrl_iface command"""
  123. ssid = "hapd-ctrl"
  124. params = { "ssid": ssid }
  125. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  126. if "FAIL" not in hapd.request("NEW_STA 00:11:22:33:44"):
  127. raise Exception("Unexpected NEW_STA success")
  128. if "OK" not in hapd.request("NEW_STA 00:11:22:33:44:55"):
  129. raise Exception("Unexpected NEW_STA failure")
  130. if "AUTHORIZED" not in hapd.request("STA 00:11:22:33:44:55"):
  131. raise Esception("Unexpected NEW_STA STA status")
  132. def test_hapd_ctrl_get(dev, apdev):
  133. """hostapd and GET ctrl_iface command"""
  134. ssid = "hapd-ctrl"
  135. params = { "ssid": ssid }
  136. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  137. if "FAIL" not in hapd.request("GET foo"):
  138. raise Exception("Unexpected GET success")
  139. if "FAIL" in hapd.request("GET version"):
  140. raise Exception("Unexpected GET version failure")
  141. def test_hapd_ctrl_unknown(dev, apdev):
  142. """hostapd and unknown ctrl_iface command"""
  143. ssid = "hapd-ctrl"
  144. params = { "ssid": ssid }
  145. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  146. if "UNKNOWN COMMAND" not in hapd.request("FOO"):
  147. raise Exception("Unexpected response")