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