test_ap_open.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. # Open mode AP tests
  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 logging
  7. logger = logging.getLogger()
  8. import struct
  9. import subprocess
  10. import time
  11. import hostapd
  12. import hwsim_utils
  13. def test_ap_open(dev, apdev):
  14. """AP with open mode (no security) configuration"""
  15. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  16. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  17. bg_scan_period="0")
  18. ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
  19. if ev is None:
  20. raise Exception("No connection event received from hostapd")
  21. hwsim_utils.test_connectivity(dev[0], hapd)
  22. dev[0].request("DISCONNECT")
  23. ev = hapd.wait_event([ "AP-STA-DISCONNECTED" ], timeout=5)
  24. if ev is None:
  25. raise Exception("No disconnection event received from hostapd")
  26. def test_ap_open_packet_loss(dev, apdev):
  27. """AP with open mode configuration and large packet loss"""
  28. params = { "ssid": "open",
  29. "ignore_probe_probability": "0.5",
  30. "ignore_auth_probability": "0.5",
  31. "ignore_assoc_probability": "0.5",
  32. "ignore_reassoc_probability": "0.5" }
  33. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  34. for i in range(0, 3):
  35. dev[i].connect("open", key_mgmt="NONE", scan_freq="2412",
  36. wait_connect=False)
  37. for i in range(0, 3):
  38. dev[i].wait_connected(timeout=20)
  39. def test_ap_open_unknown_action(dev, apdev):
  40. """AP with open mode configuration and unknown Action frame"""
  41. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  42. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  43. bssid = apdev[0]['bssid']
  44. cmd = "MGMT_TX {} {} freq=2412 action=765432".format(bssid, bssid)
  45. if "FAIL" in dev[0].request(cmd):
  46. raise Exception("Could not send test Action frame")
  47. ev = dev[0].wait_event(["MGMT-TX-STATUS"], timeout=10)
  48. if ev is None:
  49. raise Exception("Timeout on MGMT-TX-STATUS")
  50. if "result=SUCCESS" not in ev:
  51. raise Exception("AP did not ack Action frame")
  52. def test_ap_open_reconnect_on_inactivity_disconnect(dev, apdev):
  53. """Reconnect to open mode AP after inactivity related disconnection"""
  54. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  55. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  56. hapd.request("DEAUTHENTICATE " + dev[0].p2p_interface_addr() + " reason=4")
  57. dev[0].wait_disconnected(timeout=5)
  58. dev[0].wait_connected(timeout=2, error="Timeout on reconnection")
  59. def test_ap_open_assoc_timeout(dev, apdev):
  60. """AP timing out association"""
  61. ssid = "test"
  62. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  63. dev[0].scan(freq="2412")
  64. hapd.set("ext_mgmt_frame_handling", "1")
  65. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  66. wait_connect=False)
  67. for i in range(0, 10):
  68. req = hapd.mgmt_rx()
  69. if req is None:
  70. raise Exception("MGMT RX wait timed out")
  71. if req['subtype'] == 11:
  72. break
  73. req = None
  74. if not req:
  75. raise Exception("Authentication frame not received")
  76. resp = {}
  77. resp['fc'] = req['fc']
  78. resp['da'] = req['sa']
  79. resp['sa'] = req['da']
  80. resp['bssid'] = req['bssid']
  81. resp['payload'] = struct.pack('<HHH', 0, 2, 0)
  82. hapd.mgmt_tx(resp)
  83. assoc = 0
  84. for i in range(0, 10):
  85. req = hapd.mgmt_rx()
  86. if req is None:
  87. raise Exception("MGMT RX wait timed out")
  88. if req['subtype'] == 0:
  89. assoc += 1
  90. if assoc == 3:
  91. break
  92. if assoc != 3:
  93. raise Exception("Association Request frames not received: assoc=%d" % assoc)
  94. hapd.set("ext_mgmt_frame_handling", "0")
  95. dev[0].wait_connected(timeout=15)
  96. def test_ap_open_id_str(dev, apdev):
  97. """AP with open mode and id_str"""
  98. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  99. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412", id_str="foo",
  100. wait_connect=False)
  101. ev = dev[0].wait_connected(timeout=10)
  102. if "id_str=foo" not in ev:
  103. raise Exception("CTRL-EVENT-CONNECT did not have matching id_str: " + ev)
  104. if dev[0].get_status_field("id_str") != "foo":
  105. raise Exception("id_str mismatch")
  106. def test_ap_open_select_any(dev, apdev):
  107. """AP with open mode and select any network"""
  108. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  109. id = dev[0].connect("unknown", key_mgmt="NONE", scan_freq="2412",
  110. only_add_network=True)
  111. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
  112. only_add_network=True)
  113. dev[0].select_network(id)
  114. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  115. if ev is not None:
  116. raise Exception("Unexpected connection")
  117. dev[0].select_network("any")
  118. dev[0].wait_connected(timeout=10)
  119. def test_ap_open_unexpected_assoc_event(dev, apdev):
  120. """AP with open mode and unexpected association event"""
  121. hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
  122. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  123. dev[0].request("DISCONNECT")
  124. dev[0].wait_disconnected(timeout=15)
  125. dev[0].dump_monitor()
  126. # This will be accepted due to matching network
  127. subprocess.call(['iw', 'dev', dev[0].ifname, 'connect', 'open', "2412",
  128. apdev[0]['bssid']])
  129. dev[0].wait_connected(timeout=15)
  130. dev[0].dump_monitor()
  131. dev[0].request("REMOVE_NETWORK all")
  132. dev[0].wait_disconnected(timeout=5)
  133. dev[0].dump_monitor()
  134. # This will result in disconnection due to no matching network
  135. subprocess.call(['iw', 'dev', dev[0].ifname, 'connect', 'open', "2412",
  136. apdev[0]['bssid']])
  137. dev[0].wait_disconnected(timeout=15)
  138. def test_ap_bss_load(dev, apdev):
  139. """AP with open mode (no security) configuration"""
  140. hapd = hostapd.add_ap(apdev[0]['ifname'],
  141. { "ssid": "open",
  142. "bss_load_update_period": "10" })
  143. dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
  144. # this does not really get much useful output with mac80211_hwsim currently,
  145. # but run through the channel survey update couple of times
  146. for i in range(0, 10):
  147. hwsim_utils.test_connectivity(dev[0], hapd)
  148. hwsim_utils.test_connectivity(dev[0], hapd)
  149. hwsim_utils.test_connectivity(dev[0], hapd)
  150. time.sleep(0.15)