2 # Copyright (c) 2014, Qualcomm Atheros, Inc.
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
8 logger = logging.getLogger()
14 def test_ap_open(dev, apdev):
15 """AP with open mode (no security) configuration"""
16 hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
17 dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
18 hwsim_utils.test_connectivity(dev[0].ifname, apdev[0]['ifname'])
19 ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
21 raise Exception("No connection event received from hostapd")
22 dev[0].request("DISCONNECT")
23 ev = hapd.wait_event([ "AP-STA-DISCONNECTED" ], timeout=5)
25 raise Exception("No disconnection event received from hostapd")
27 def test_ap_open_packet_loss(dev, apdev):
28 """AP with open mode configuration and large packet loss"""
29 params = { "ssid": "open",
30 "ignore_probe_probability": "0.5",
31 "ignore_auth_probability": "0.5",
32 "ignore_assoc_probability": "0.5",
33 "ignore_reassoc_probability": "0.5" }
34 hapd = hostapd.add_ap(apdev[0]['ifname'], params)
36 dev[i].connect("open", key_mgmt="NONE", scan_freq="2412",
39 ev = dev[i].wait_event(["CTRL-EVENT-CONNECTED"], timeout=20)
41 raise Exception("Association with the AP timed out")
43 def test_ap_open_unknown_action(dev, apdev):
44 """AP with open mode configuration and unknown Action frame"""
45 hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
46 dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
47 bssid = apdev[0]['bssid']
48 cmd = "MGMT_TX {} {} freq=2412 action=765432".format(bssid, bssid)
49 if "FAIL" in dev[0].request(cmd):
50 raise Exception("Could not send test Action frame")
51 ev = dev[0].wait_event(["MGMT-TX-STATUS"], timeout=10)
53 raise Exception("Timeout on MGMT-TX-STATUS")
54 if "result=SUCCESS" not in ev:
55 raise Exception("AP did not ack Action frame")
57 def test_ap_open_reconnect_on_inactivity_disconnect(dev, apdev):
58 """Reconnect to open mode AP after inactivity related disconnection"""
59 hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
60 dev[0].connect("open", key_mgmt="NONE", scan_freq="2412")
61 hapd.request("DEAUTHENTICATE " + dev[0].p2p_interface_addr() + " reason=4")
62 ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=5)
64 raise Exception("Timeout on disconnection")
65 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=2)
67 raise Exception("Timeout on reconnection")
69 def test_ap_open_assoc_timeout(dev, apdev):
70 """AP timing out association"""
72 hapd = hostapd.add_ap(apdev[0]['ifname'], { "ssid": "open" })
73 dev[0].scan(freq="2412")
74 hapd.set("ext_mgmt_frame_handling", "1")
75 dev[0].connect("open", key_mgmt="NONE", scan_freq="2412",
77 for i in range(0, 10):
80 raise Exception("MGMT RX wait timed out")
81 if req['subtype'] == 11:
85 raise Exception("Authentication frame not received")
88 resp['fc'] = req['fc']
89 resp['da'] = req['sa']
90 resp['sa'] = req['da']
91 resp['bssid'] = req['bssid']
92 resp['payload'] = struct.pack('<HHH', 0, 2, 0)
96 for i in range(0, 10):
99 raise Exception("MGMT RX wait timed out")
100 if req['subtype'] == 0:
105 raise Exception("Association Request frames not received: assoc=%d" % assoc)
106 hapd.set("ext_mgmt_frame_handling", "0")
107 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
109 raise Exception("Timeout on connection")