test_ap_open.py 7.2 KB

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