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