]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_ap_open.py
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.
7 from remotehost
import remote_compatible
9 logger
= logging
.getLogger()
17 from tshark
import run_tshark
19 from wpasupplicant
import WpaSupplicant
20 from wlantest
import WlantestCapture
21 from test_ap_ht
import set_world_reg
24 def test_ap_open(dev
, apdev
):
25 """AP with open mode (no security) configuration"""
26 _test_ap_open(dev
, apdev
)
28 def _test_ap_open(dev
, apdev
):
29 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
30 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
32 ev
= hapd
.wait_event(["AP-STA-CONNECTED"], timeout
=5)
34 raise Exception("No connection event received from hostapd")
35 hwsim_utils
.test_connectivity(dev
[0], hapd
)
37 dev
[0].request("DISCONNECT")
38 ev
= hapd
.wait_event(["AP-STA-DISCONNECTED"], timeout
=5)
40 raise Exception("No disconnection event received from hostapd")
42 def test_ap_open_packet_loss(dev
, apdev
):
43 """AP with open mode configuration and large packet loss"""
44 params
= {"ssid": "open",
45 "ignore_probe_probability": "0.5",
46 "ignore_auth_probability": "0.5",
47 "ignore_assoc_probability": "0.5",
48 "ignore_reassoc_probability": "0.5"}
49 hapd
= hostapd
.add_ap(apdev
[0], params
)
51 dev
[i
].connect("open", key_mgmt
="NONE", scan_freq
="2412",
54 dev
[i
].wait_connected(timeout
=20)
57 def test_ap_open_unknown_action(dev
, apdev
):
58 """AP with open mode configuration and unknown Action frame"""
59 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
60 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
61 bssid
= apdev
[0]['bssid']
62 cmd
= "MGMT_TX {} {} freq=2412 action=765432".format(bssid
, bssid
)
63 if "FAIL" in dev
[0].request(cmd
):
64 raise Exception("Could not send test Action frame")
65 ev
= dev
[0].wait_event(["MGMT-TX-STATUS"], timeout
=10)
67 raise Exception("Timeout on MGMT-TX-STATUS")
68 if "result=SUCCESS" not in ev
:
69 raise Exception("AP did not ack Action frame")
71 def test_ap_open_invalid_wmm_action(dev
, apdev
):
72 """AP with open mode configuration and invalid WMM Action frame"""
73 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
74 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
75 bssid
= apdev
[0]['bssid']
76 cmd
= "MGMT_TX {} {} freq=2412 action=1100".format(bssid
, bssid
)
77 if "FAIL" in dev
[0].request(cmd
):
78 raise Exception("Could not send test Action frame")
79 ev
= dev
[0].wait_event(["MGMT-TX-STATUS"], timeout
=10)
80 if ev
is None or "result=SUCCESS" not in ev
:
81 raise Exception("AP did not ack Action frame")
84 def test_ap_open_reconnect_on_inactivity_disconnect(dev
, apdev
):
85 """Reconnect to open mode AP after inactivity related disconnection"""
86 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
87 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
88 hapd
.request("DEAUTHENTICATE " + dev
[0].p2p_interface_addr() + " reason=4")
89 dev
[0].wait_disconnected(timeout
=5)
90 dev
[0].wait_connected(timeout
=2, error
="Timeout on reconnection")
93 def test_ap_open_assoc_timeout(dev
, apdev
):
94 """AP timing out association"""
96 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
97 dev
[0].scan(freq
="2412")
98 hapd
.set("ext_mgmt_frame_handling", "1")
99 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
101 for i
in range(0, 10):
104 raise Exception("MGMT RX wait timed out")
105 if req
['subtype'] == 11:
109 raise Exception("Authentication frame not received")
112 resp
['fc'] = req
['fc']
113 resp
['da'] = req
['sa']
114 resp
['sa'] = req
['da']
115 resp
['bssid'] = req
['bssid']
116 resp
['payload'] = struct
.pack('<HHH', 0, 2, 0)
120 for i
in range(0, 10):
123 raise Exception("MGMT RX wait timed out")
124 if req
['subtype'] == 0:
129 raise Exception("Association Request frames not received: assoc=%d" % assoc
)
130 hapd
.set("ext_mgmt_frame_handling", "0")
131 dev
[0].wait_connected(timeout
=15)
133 def test_ap_open_auth_drop_sta(dev
, apdev
):
134 """AP dropping station after successful authentication"""
135 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], {"ssid": "open"})
136 dev
[0].scan(freq
="2412")
137 hapd
.set("ext_mgmt_frame_handling", "1")
138 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
140 for i
in range(0, 10):
143 raise Exception("MGMT RX wait timed out")
144 if req
['subtype'] == 11:
148 raise Exception("Authentication frame not received")
150 # turn off before sending successful response
151 hapd
.set("ext_mgmt_frame_handling", "0")
154 resp
['fc'] = req
['fc']
155 resp
['da'] = req
['sa']
156 resp
['sa'] = req
['da']
157 resp
['bssid'] = req
['bssid']
158 resp
['payload'] = struct
.pack('<HHH', 0, 2, 0)
161 dev
[0].wait_connected(timeout
=15)
164 def test_ap_open_id_str(dev
, apdev
):
165 """AP with open mode and id_str"""
166 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
167 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412", id_str
="foo",
169 ev
= dev
[0].wait_connected(timeout
=10)
170 if "id_str=foo" not in ev
:
171 raise Exception("CTRL-EVENT-CONNECT did not have matching id_str: " + ev
)
172 if dev
[0].get_status_field("id_str") != "foo":
173 raise Exception("id_str mismatch")
176 def test_ap_open_select_any(dev
, apdev
):
177 """AP with open mode and select any network"""
178 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
179 id = dev
[0].connect("unknown", key_mgmt
="NONE", scan_freq
="2412",
180 only_add_network
=True)
181 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
182 only_add_network
=True)
183 dev
[0].select_network(id)
184 ev
= dev
[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND",
185 "CTRL-EVENT-CONNECTED"], timeout
=10)
187 raise Exception("No result reported")
188 if "CTRL-EVENT-CONNECTED" in ev
:
189 raise Exception("Unexpected connection")
191 dev
[0].select_network("any")
192 dev
[0].wait_connected(timeout
=10)
195 def test_ap_open_unexpected_assoc_event(dev
, apdev
):
196 """AP with open mode and unexpected association event"""
197 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
198 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
199 dev
[0].request("DISCONNECT")
200 dev
[0].wait_disconnected(timeout
=15)
201 dev
[0].dump_monitor()
202 # This will be accepted due to matching network
203 dev
[0].cmd_execute(['iw', 'dev', dev
[0].ifname
, 'connect', 'open', "2412",
205 dev
[0].wait_connected(timeout
=15)
206 dev
[0].dump_monitor()
208 dev
[0].request("REMOVE_NETWORK all")
209 dev
[0].wait_disconnected(timeout
=5)
210 dev
[0].dump_monitor()
211 # This will result in disconnection due to no matching network
212 dev
[0].cmd_execute(['iw', 'dev', dev
[0].ifname
, 'connect', 'open', "2412",
214 dev
[0].wait_disconnected(timeout
=15)
216 def test_ap_open_external_assoc(dev
, apdev
):
217 """AP with open mode and external association"""
218 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open-ext-assoc"})
220 dev
[0].request("STA_AUTOCONNECT 0")
221 id = dev
[0].connect("open-ext-assoc", key_mgmt
="NONE", scan_freq
="2412",
222 only_add_network
=True)
223 dev
[0].request("ENABLE_NETWORK %s no-connect" % id)
224 dev
[0].dump_monitor()
225 # This will be accepted due to matching network
226 dev
[0].cmd_execute(['iw', 'dev', dev
[0].ifname
, 'connect',
227 'open-ext-assoc', "2412", apdev
[0]['bssid']])
228 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED",
229 "CTRL-EVENT-CONNECTED"], timeout
=10)
231 raise Exception("Connection timed out")
232 if "CTRL-EVENT-DISCONNECTED" in ev
:
233 raise Exception("Unexpected disconnection event")
234 dev
[0].dump_monitor()
235 dev
[0].request("DISCONNECT")
236 dev
[0].wait_disconnected(timeout
=5)
238 dev
[0].request("STA_AUTOCONNECT 1")
241 def test_ap_bss_load(dev
, apdev
):
242 """AP with open mode (no security) configuration"""
243 hapd
= hostapd
.add_ap(apdev
[0],
245 "bss_load_update_period": "10",
246 "chan_util_avg_period": "20"})
247 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
248 # this does not really get much useful output with mac80211_hwsim currently,
249 # but run through the channel survey update couple of times
250 for i
in range(0, 10):
251 hwsim_utils
.test_connectivity(dev
[0], hapd
)
252 hwsim_utils
.test_connectivity(dev
[0], hapd
)
253 hwsim_utils
.test_connectivity(dev
[0], hapd
)
255 avg
= hapd
.get_status_field("chan_util_avg")
257 raise Exception("No STATUS chan_util_avg seen")
259 def test_ap_bss_load_fail(dev
, apdev
):
260 """BSS Load update failing to get survey data"""
261 hapd
= hostapd
.add_ap(apdev
[0],
263 "bss_load_update_period": "1"})
264 with
fail_test(hapd
, 1, "wpa_driver_nl80211_get_survey"):
265 wait_fail_trigger(hapd
, "GET_FAIL")
267 def hapd_out_of_mem(hapd
, apdev
, count
, func
):
268 with
alloc_fail(hapd
, count
, func
):
271 hostapd
.add_ap(apdev
, {"ssid": "open"})
276 raise Exception("hostapd interface started even with memory allocation failure: %d:%s" % (count
, func
))
278 def test_ap_open_out_of_memory(dev
, apdev
):
279 """hostapd failing to setup interface due to allocation failure"""
280 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
281 hapd_out_of_mem(hapd
, apdev
[1], 1, "hostapd_alloc_bss_data")
283 for i
in range(1, 3):
284 hapd_out_of_mem(hapd
, apdev
[1], i
, "hostapd_iface_alloc")
286 for i
in range(1, 5):
287 hapd_out_of_mem(hapd
, apdev
[1], i
, "hostapd_config_defaults;hostapd_config_alloc")
289 hapd_out_of_mem(hapd
, apdev
[1], 1, "hostapd_config_alloc")
291 hapd_out_of_mem(hapd
, apdev
[1], 1, "hostapd_driver_init")
293 for i
in range(1, 3):
294 hapd_out_of_mem(hapd
, apdev
[1], i
, "=wpa_driver_nl80211_drv_init")
296 # eloop_register_read_sock() call from i802_init()
297 hapd_out_of_mem(hapd
, apdev
[1], 1, "eloop_sock_table_add_sock;?eloop_register_sock;?eloop_register_read_sock;=i802_init")
299 # verify that a new interface can still be added when memory allocation does
301 hostapd
.add_ap(apdev
[1], {"ssid": "open"})
303 def test_bssid_black_white_list(dev
, apdev
):
304 """BSSID black/white list"""
305 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
306 hapd2
= hostapd
.add_ap(apdev
[1], {"ssid": "open"})
308 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
309 bssid_whitelist
=apdev
[1]['bssid'])
310 dev
[1].connect("open", key_mgmt
="NONE", scan_freq
="2412",
311 bssid_blacklist
=apdev
[1]['bssid'])
312 dev
[2].connect("open", key_mgmt
="NONE", scan_freq
="2412",
313 bssid_whitelist
="00:00:00:00:00:00/00:00:00:00:00:00",
314 bssid_blacklist
=apdev
[1]['bssid'])
315 if dev
[0].get_status_field('bssid') != apdev
[1]['bssid']:
316 raise Exception("dev[0] connected to unexpected AP")
317 if dev
[1].get_status_field('bssid') != apdev
[0]['bssid']:
318 raise Exception("dev[1] connected to unexpected AP")
319 if dev
[2].get_status_field('bssid') != apdev
[0]['bssid']:
320 raise Exception("dev[2] connected to unexpected AP")
321 dev
[0].request("REMOVE_NETWORK all")
322 dev
[1].request("REMOVE_NETWORK all")
323 dev
[2].request("REMOVE_NETWORK all")
325 dev
[2].connect("open", key_mgmt
="NONE", scan_freq
="2412",
326 bssid_whitelist
="00:00:00:00:00:00", wait_connect
=False)
327 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
328 bssid_whitelist
="11:22:33:44:55:66/ff:00:00:00:00:00 " + apdev
[1]['bssid'] + " aa:bb:cc:dd:ee:ff")
329 dev
[1].connect("open", key_mgmt
="NONE", scan_freq
="2412",
330 bssid_blacklist
="11:22:33:44:55:66/ff:00:00:00:00:00 " + apdev
[1]['bssid'] + " aa:bb:cc:dd:ee:ff")
331 if dev
[0].get_status_field('bssid') != apdev
[1]['bssid']:
332 raise Exception("dev[0] connected to unexpected AP")
333 if dev
[1].get_status_field('bssid') != apdev
[0]['bssid']:
334 raise Exception("dev[1] connected to unexpected AP")
335 dev
[0].request("REMOVE_NETWORK all")
336 dev
[1].request("REMOVE_NETWORK all")
337 ev
= dev
[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=0.1)
339 raise Exception("Unexpected dev[2] connectin")
340 dev
[2].request("REMOVE_NETWORK all")
342 def test_ap_open_wpas_in_bridge(dev
, apdev
):
343 """Open mode AP and wpas interface in a bridge"""
344 br_ifname
= 'sta-br0'
347 _test_ap_open_wpas_in_bridge(dev
, apdev
)
349 subprocess
.call(['ip', 'link', 'set', 'dev', br_ifname
, 'down'])
350 subprocess
.call(['brctl', 'delif', br_ifname
, ifname
])
351 subprocess
.call(['brctl', 'delbr', br_ifname
])
352 subprocess
.call(['iw', ifname
, 'set', '4addr', 'off'])
354 def _test_ap_open_wpas_in_bridge(dev
, apdev
):
355 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
357 br_ifname
= 'sta-br0'
359 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
360 # First, try a failure case of adding an interface
362 wpas
.interface_add(ifname
, br_ifname
=br_ifname
)
363 raise Exception("Interface addition succeeded unexpectedly")
364 except Exception as e
:
365 if "Failed to add" in str(e
):
366 logger
.info("Ignore expected interface_add failure due to missing bridge interface: " + str(e
))
370 # Next, add the bridge interface and add the interface again
371 subprocess
.call(['brctl', 'addbr', br_ifname
])
372 subprocess
.call(['brctl', 'setfd', br_ifname
, '0'])
373 subprocess
.call(['ip', 'link', 'set', 'dev', br_ifname
, 'up'])
374 subprocess
.call(['iw', ifname
, 'set', '4addr', 'on'])
375 subprocess
.check_call(['brctl', 'addif', br_ifname
, ifname
])
376 wpas
.interface_add(ifname
, br_ifname
=br_ifname
)
378 wpas
.connect("open", key_mgmt
="NONE", scan_freq
="2412")
381 def test_ap_open_start_disabled(dev
, apdev
):
382 """AP with open mode and beaconing disabled"""
383 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open",
384 "start_disabled": "1"})
385 bssid
= apdev
[0]['bssid']
387 dev
[0].flush_scan_cache()
388 dev
[0].scan(freq
=2412, only_new
=True)
389 if dev
[0].get_bss(bssid
) is not None:
390 raise Exception("AP was seen beaconing")
391 if "OK" not in hapd
.request("RELOAD"):
392 raise Exception("RELOAD failed")
393 dev
[0].scan_for_bss(bssid
, freq
=2412)
394 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
397 def test_ap_open_start_disabled2(dev
, apdev
):
398 """AP with open mode and beaconing disabled (2)"""
399 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open",
400 "start_disabled": "1"})
401 bssid
= apdev
[0]['bssid']
403 dev
[0].flush_scan_cache()
404 dev
[0].scan(freq
=2412, only_new
=True)
405 if dev
[0].get_bss(bssid
) is not None:
406 raise Exception("AP was seen beaconing")
407 if "OK" not in hapd
.request("UPDATE_BEACON"):
408 raise Exception("UPDATE_BEACON failed")
409 dev
[0].scan_for_bss(bssid
, freq
=2412)
410 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
411 if "OK" not in hapd
.request("UPDATE_BEACON"):
412 raise Exception("UPDATE_BEACON failed")
413 dev
[0].request("DISCONNECT")
414 dev
[0].wait_disconnected()
415 dev
[0].request("RECONNECT")
416 dev
[0].wait_connected()
419 def test_ap_open_ifdown(dev
, apdev
):
420 """AP with open mode and external ifconfig down"""
421 params
= {"ssid": "open",
422 "ap_max_inactivity": "1"}
423 hapd
= hostapd
.add_ap(apdev
[0], params
)
424 bssid
= apdev
[0]['bssid']
426 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
427 dev
[1].connect("open", key_mgmt
="NONE", scan_freq
="2412")
428 hapd
.cmd_execute(['ip', 'link', 'set', 'dev', apdev
[0]['ifname'], 'down'])
429 ev
= hapd
.wait_event(["AP-STA-DISCONNECTED"], timeout
=10)
431 raise Exception("Timeout on AP-STA-DISCONNECTED (1)")
432 ev
= hapd
.wait_event(["AP-STA-DISCONNECTED"], timeout
=5)
434 raise Exception("Timeout on AP-STA-DISCONNECTED (2)")
435 ev
= hapd
.wait_event(["INTERFACE-DISABLED"], timeout
=5)
437 raise Exception("No INTERFACE-DISABLED event")
438 # The following wait tests beacon loss detection in mac80211 on dev0.
439 # dev1 is used to test stopping of AP side functionality on client polling.
440 dev
[1].request("REMOVE_NETWORK all")
441 hapd
.cmd_execute(['ip', 'link', 'set', 'dev', apdev
[0]['ifname'], 'up'])
442 dev
[0].wait_disconnected()
443 dev
[1].wait_disconnected()
444 ev
= hapd
.wait_event(["INTERFACE-ENABLED"], timeout
=10)
446 raise Exception("No INTERFACE-ENABLED event")
447 dev
[0].wait_connected()
448 hwsim_utils
.test_connectivity(dev
[0], hapd
)
450 def test_ap_open_disconnect_in_ps(dev
, apdev
, params
):
451 """Disconnect with the client in PS to regression-test a kernel bug"""
452 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
453 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
455 ev
= hapd
.wait_event(["AP-STA-CONNECTED"], timeout
=5)
457 raise Exception("No connection event received from hostapd")
460 # enable power save mode
461 hwsim_utils
.set_powersave(dev
[0], hwsim_utils
.PS_ENABLED
)
464 # inject some traffic
466 da
= dev
[0].own_addr()
467 hapd
.request('DATA_TEST_CONFIG 1')
468 hapd
.request('DATA_TEST_TX {} {} 0'.format(da
, sa
))
469 hapd
.request('DATA_TEST_CONFIG 0')
471 # let the AP send couple of Beacon frames
474 # disconnect - with traffic pending - shouldn't cause kernel warnings
475 dev
[0].request("DISCONNECT")
477 hwsim_utils
.set_powersave(dev
[0], hwsim_utils
.PS_DISABLED
)
480 out
= run_tshark(os
.path
.join(params
['logdir'], "hwsim0.pcapng"),
481 "wlan_mgt.tim.partial_virtual_bitmap",
482 ["wlan_mgt.tim.partial_virtual_bitmap"])
485 for l
in out
.splitlines():
487 if pvb
> 0 and state
== 0:
489 elif pvb
== 0 and state
== 1:
492 raise Exception("Didn't observe TIM bit getting set and unset (state=%d)" % state
)
494 def test_ap_open_sta_ps(dev
, apdev
):
495 """Station power save operation"""
496 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
497 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
503 dev
[0].cmd_execute(['iw', 'dev', dev
[0].ifname
,
504 'set', 'power_save', 'on'])
505 run_ap_open_sta_ps(dev
, hapd
)
507 dev
[0].cmd_execute(['iw', 'dev', dev
[0].ifname
,
508 'set', 'power_save', 'on'])
510 def run_ap_open_sta_ps(dev
, hapd
):
511 hwsim_utils
.test_connectivity(dev
[0], hapd
)
512 # Give time to enter PS
515 phyname
= dev
[0].get_driver_status_field("phyname")
516 hw_conf
= '/sys/kernel/debug/ieee80211/' + phyname
+ '/hw_conf'
521 with
open(hw_conf
, 'r') as f
:
529 raise Exception("STA did not enter power save")
530 except FileNotFoundError
:
531 raise HwsimSkip("Kernel does not support inspecting HW PS state")
533 def test_ap_open_ps_mc_buf(dev
, apdev
, params
):
534 """Multicast buffering with a station in power save"""
535 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
536 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
542 dev
[0].cmd_execute(['iw', 'dev', dev
[0].ifname
,
543 'set', 'power_save', 'on'])
544 # Give time to enter PS
548 # Verify that multicast frames are released
549 hwsim_utils
.run_multicast_connectivity_test(hapd
, dev
[0])
551 # Check frames were buffered until DTIM
552 out
= run_tshark(os
.path
.join(params
['logdir'], "hwsim0.pcapng"),
553 "wlan.fc.type_subtype == 0x0008",
554 ["wlan.tim.bmapctl.multicast"])
555 for line
in out
.splitlines():
556 buffered_mcast
= int(line
)
557 if buffered_mcast
== 1:
559 if buffered_mcast
== 1:
562 dev
[0].cmd_execute(['iw', 'dev', dev
[0].ifname
,
563 'set', 'power_save', 'off'])
565 if buffered_mcast
!= 1:
566 raise Exception("AP did not buffer multicast frames")
569 def test_ap_open_select_network(dev
, apdev
):
570 """Open mode connection and SELECT_NETWORK to change network"""
571 hapd1
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
572 bssid1
= apdev
[0]['bssid']
573 hapd2
= hostapd
.add_ap(apdev
[1], {"ssid": "open2"})
574 bssid2
= apdev
[1]['bssid']
576 id1
= dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
577 only_add_network
=True)
578 id2
= dev
[0].connect("open2", key_mgmt
="NONE", scan_freq
="2412")
579 hwsim_utils
.test_connectivity(dev
[0], hapd2
)
581 dev
[0].select_network(id1
)
582 dev
[0].wait_connected()
583 res
= dev
[0].request("BLACKLIST")
584 if bssid1
in res
or bssid2
in res
:
585 raise Exception("Unexpected blacklist entry")
586 hwsim_utils
.test_connectivity(dev
[0], hapd1
)
588 dev
[0].select_network(id2
)
589 dev
[0].wait_connected()
590 hwsim_utils
.test_connectivity(dev
[0], hapd2
)
591 res
= dev
[0].request("BLACKLIST")
592 if bssid1
in res
or bssid2
in res
:
593 raise Exception("Unexpected blacklist entry(2)")
596 def test_ap_open_disable_enable(dev
, apdev
):
597 """AP with open mode getting disabled and re-enabled"""
598 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
599 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
603 hapd
.request("DISABLE")
604 dev
[0].wait_disconnected()
605 hapd
.request("ENABLE")
606 dev
[0].wait_connected()
607 hwsim_utils
.test_connectivity(dev
[0], hapd
)
609 def sta_enable_disable(dev
, bssid
):
610 dev
.scan_for_bss(bssid
, freq
=2412)
611 work_id
= dev
.request("RADIO_WORK add block-work")
612 ev
= dev
.wait_event(["EXT-RADIO-WORK-START"])
614 raise Exception("Timeout while waiting radio work to start")
615 id = dev
.connect("open", key_mgmt
="NONE", scan_freq
="2412",
616 only_add_network
=True)
617 dev
.request("ENABLE_NETWORK %d" % id)
618 if "connect@" not in dev
.request("RADIO_WORK show"):
619 raise Exception("connect radio work missing")
620 dev
.request("DISABLE_NETWORK %d" % id)
621 dev
.request("RADIO_WORK done " + work_id
)
625 if "connect@" not in dev
.request("RADIO_WORK show"):
630 raise Exception("connect radio work not completed")
631 ev
= dev
.wait_event(["CTRL-EVENT-CONNECTED"], timeout
=0.1)
633 raise Exception("Unexpected connection")
634 dev
.request("DISCONNECT")
636 def test_ap_open_sta_enable_disable(dev
, apdev
):
637 """AP with open mode and wpa_supplicant ENABLE/DISABLE_NETWORK"""
638 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
639 bssid
= apdev
[0]['bssid']
641 sta_enable_disable(dev
[0], bssid
)
643 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
644 wpas
.interface_add("wlan5", drv_params
="force_connect_cmd=1")
645 sta_enable_disable(wpas
, bssid
)
648 def test_ap_open_select_twice(dev
, apdev
):
649 """AP with open mode and select network twice"""
650 id = dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
651 only_add_network
=True)
652 dev
[0].select_network(id)
653 ev
= dev
[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout
=10)
655 raise Exception("No result reported")
656 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
657 # Verify that the second SELECT_NETWORK starts a new scan immediately by
658 # waiting less than the default scan period.
659 dev
[0].select_network(id)
660 dev
[0].wait_connected(timeout
=3)
663 def test_ap_open_reassoc_not_found(dev
, apdev
):
664 """AP with open mode and REASSOCIATE not finding a match"""
665 id = dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
666 only_add_network
=True)
667 dev
[0].select_network(id)
668 ev
= dev
[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout
=10)
670 raise Exception("No result reported")
671 dev
[0].request("DISCONNECT")
674 dev
[0].dump_monitor()
676 dev
[0].request("REASSOCIATE")
677 ev
= dev
[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout
=10)
679 raise Exception("No result reported")
680 dev
[0].request("DISCONNECT")
683 def test_ap_open_sta_statistics(dev
, apdev
):
684 """AP with open mode and STA statistics"""
685 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
686 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
687 addr
= dev
[0].own_addr()
689 stats1
= hapd
.get_sta(addr
)
690 logger
.info("stats1: " + str(stats1
))
692 stats2
= hapd
.get_sta(addr
)
693 logger
.info("stats2: " + str(stats2
))
694 hwsim_utils
.test_connectivity(dev
[0], hapd
)
695 stats3
= hapd
.get_sta(addr
)
696 logger
.info("stats3: " + str(stats3
))
698 # Cannot require specific inactive_msec changes without getting rid of all
699 # unrelated traffic, so for now, just print out the results in the log for
703 def test_ap_open_poll_sta(dev
, apdev
):
704 """AP with open mode and STA poll"""
705 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
706 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
707 addr
= dev
[0].own_addr()
709 if "OK" not in hapd
.request("POLL_STA " + addr
):
710 raise Exception("POLL_STA failed")
711 ev
= hapd
.wait_event(["AP-STA-POLL-OK"], timeout
=5)
713 raise Exception("Poll response not seen")
715 raise Exception("Unexpected poll response: " + ev
)
717 def test_ap_open_poll_sta_no_ack(dev
, apdev
):
718 """AP with open mode and STA poll without ACK"""
719 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
720 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
721 addr
= dev
[0].own_addr()
723 hapd
.set("ext_mgmt_frame_handling", "1")
724 dev
[0].request("DISCONNECT")
725 dev
[0].wait_disconnected()
726 hapd
.set("ext_mgmt_frame_handling", "0")
727 if "OK" not in hapd
.request("POLL_STA " + addr
):
728 raise Exception("POLL_STA failed")
729 ev
= hapd
.wait_event(["AP-STA-POLL-OK"], timeout
=1)
731 raise Exception("Unexpected poll response reported")
733 def test_ap_open_pmf_default(dev
, apdev
):
734 """AP with open mode (no security) configuration and pmf=2"""
735 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
736 dev
[1].connect("open", key_mgmt
="NONE", scan_freq
="2412",
737 ieee80211w
="2", wait_connect
=False)
738 dev
[2].connect("open", key_mgmt
="NONE", scan_freq
="2412",
741 dev
[0].request("SET pmf 2")
742 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
744 dev
[0].request("DISCONNECT")
745 dev
[0].wait_disconnected()
747 dev
[0].request("SET pmf 0")
748 dev
[2].request("DISCONNECT")
749 dev
[2].wait_disconnected()
751 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=0.1)
753 raise Exception("Unexpected dev[1] connection")
754 dev
[1].request("DISCONNECT")
756 def test_ap_open_drv_fail(dev
, apdev
):
757 """AP with open mode and driver operations failing"""
758 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
760 with
fail_test(dev
[0], 1, "wpa_driver_nl80211_authenticate"):
761 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
763 wait_fail_trigger(dev
[0], "GET_FAIL")
764 dev
[0].request("REMOVE_NETWORK all")
766 with
fail_test(dev
[0], 1, "wpa_driver_nl80211_associate"):
767 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
769 wait_fail_trigger(dev
[0], "GET_FAIL")
770 dev
[0].request("REMOVE_NETWORK all")
772 def run_multicast_to_unicast(dev
, apdev
, convert
):
773 params
= {"ssid": "open"}
774 params
["multicast_to_unicast"] = "1" if convert
else "0"
775 hapd
= hostapd
.add_ap(apdev
[0], params
)
776 dev
[0].scan_for_bss(hapd
.own_addr(), freq
=2412)
777 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
778 ev
= hapd
.wait_event(["AP-STA-CONNECTED"], timeout
=5)
780 raise Exception("No connection event received from hostapd")
781 hwsim_utils
.test_connectivity(dev
[0], hapd
, multicast_to_unicast
=convert
)
782 dev
[0].request("DISCONNECT")
783 ev
= hapd
.wait_event(["AP-STA-DISCONNECTED"], timeout
=5)
785 raise Exception("No disconnection event received from hostapd")
787 def test_ap_open_multicast_to_unicast(dev
, apdev
):
788 """Multicast-to-unicast conversion enabled"""
789 run_multicast_to_unicast(dev
, apdev
, True)
791 def test_ap_open_multicast_to_unicast_disabled(dev
, apdev
):
792 """Multicast-to-unicast conversion disabled"""
793 run_multicast_to_unicast(dev
, apdev
, False)
795 def test_ap_open_drop_duplicate(dev
, apdev
, params
):
796 """AP dropping duplicate management frames"""
797 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open",
798 "interworking": "1"})
799 hapd
.set("ext_mgmt_frame_handling", "1")
800 bssid
= hapd
.own_addr().replace(':', '')
801 addr
= "020304050607"
802 auth
= "b0003a01" + bssid
+ addr
+ bssid
+ '1000000001000000'
803 if "OK" not in hapd
.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % auth
):
804 raise Exception("MGMT_RX_PROCESS failed")
805 auth
= "b0083a01" + bssid
+ addr
+ bssid
+ '1000000001000000'
806 if "OK" not in hapd
.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % auth
):
807 raise Exception("MGMT_RX_PROCESS failed")
809 ies
= "00046f70656e010802040b160c12182432043048606c2d1a3c101bffff0000000000000000000001000000000000000000007f0a04000a020140004000013b155151525354737475767778797a7b7c7d7e7f808182dd070050f202000100"
810 assoc_req
= "00003a01" + bssid
+ addr
+ bssid
+ "2000" + "21040500" + ies
811 if "OK" not in hapd
.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % assoc_req
):
812 raise Exception("MGMT_RX_PROCESS failed")
813 assoc_req
= "00083a01" + bssid
+ addr
+ bssid
+ "2000" + "21040500" + ies
814 if "OK" not in hapd
.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % assoc_req
):
815 raise Exception("MGMT_RX_PROCESS failed")
816 reassoc_req
= "20083a01" + bssid
+ addr
+ bssid
+ "2000" + "21040500" + ies
817 if "OK" not in hapd
.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % reassoc_req
):
818 raise Exception("MGMT_RX_PROCESS failed")
819 if "OK" not in hapd
.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % reassoc_req
):
820 raise Exception("MGMT_RX_PROCESS failed")
822 action
= "d0003a01" + bssid
+ addr
+ bssid
+ "1000" + "040a006c0200000600000102000101"
823 if "OK" not in hapd
.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % action
):
824 raise Exception("MGMT_RX_PROCESS failed")
826 action
= "d0083a01" + bssid
+ addr
+ bssid
+ "1000" + "040a006c0200000600000102000101"
827 if "OK" not in hapd
.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % action
):
828 raise Exception("MGMT_RX_PROCESS failed")
830 out
= run_tshark(os
.path
.join(params
['logdir'], "hwsim0.pcapng"),
831 "wlan.fc.type == 0", ["wlan.fc.subtype"])
836 for subtype
in out
.splitlines():
847 raise Exception("Unexpected number of Authentication frames: %d" % num_auth
)
849 raise Exception("Unexpected number of association frames: %d" % num_assoc
)
851 raise Exception("Unexpected number of reassociation frames: %d" % num_reassoc
)
853 raise Exception("Unexpected number of Action frames: %d" % num_action
)
855 def test_ap_open_select_network_freq(dev
, apdev
):
856 """AP with open mode and use for SELECT_NETWORK freq parameter"""
857 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
858 id = dev
[0].connect("open", key_mgmt
="NONE", only_add_network
=True)
859 dev
[0].select_network(id, freq
=2412)
860 start
= os
.times()[4]
861 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout
=5)
863 raise Exception("Scan not started")
864 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout
=15)
866 raise Exception("Scan not completed")
868 logger
.info("Scan duration: {} seconds".format(end
- start
))
870 raise Exception("Scan took unexpectedly long time")
871 dev
[0].wait_connected()
873 def test_ap_open_noncountry(dev
, apdev
):
874 """AP with open mode and noncountry entity as Country String"""
875 _test_ap_open_country(dev
, apdev
, "XX", "0x58")
877 def test_ap_open_country_table_e4(dev
, apdev
):
878 """AP with open mode and Table E-4 Country String"""
879 _test_ap_open_country(dev
, apdev
, "DE", "0x04")
881 def test_ap_open_country_indoor(dev
, apdev
):
882 """AP with open mode and indoor country code"""
883 _test_ap_open_country(dev
, apdev
, "DE", "0x49")
885 def test_ap_open_country_outdoor(dev
, apdev
):
886 """AP with open mode and outdoor country code"""
887 _test_ap_open_country(dev
, apdev
, "DE", "0x4f")
889 def _test_ap_open_country(dev
, apdev
, country_code
, country3
):
892 hapd
= run_ap_open_country(dev
, apdev
, country_code
, country3
)
894 clear_regdom(hapd
, dev
)
896 def run_ap_open_country(dev
, apdev
, country_code
, country3
):
897 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open",
898 "country_code": country_code
,
899 "country3": country3
,
901 dev
[0].scan_for_bss(hapd
.own_addr(), freq
=2412)
902 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
903 dev
[0].wait_regdom(country_ie
=True)
906 def test_ap_open_disable_select(dev
, apdev
):
907 """DISABLE_NETWORK for connected AP followed by SELECT_NETWORK"""
908 hapd1
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
909 hapd2
= hostapd
.add_ap(apdev
[1], {"ssid": "open"})
910 id = dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
912 dev
[0].request("DISABLE_NETWORK %d" % id)
913 dev
[0].wait_disconnected()
914 res
= dev
[0].request("BLACKLIST")
915 if hapd1
.own_addr() in res
or hapd2
.own_addr() in res
:
916 raise Exception("Unexpected blacklist entry added")
917 dev
[0].request("SELECT_NETWORK %d" % id)
918 dev
[0].wait_connected()
920 def test_ap_open_reassoc_same(dev
, apdev
):
921 """AP with open mode and STA reassociating back to same AP without auth exchange"""
922 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
923 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
925 dev
[0].request("SET reassoc_same_bss_optim 1")
926 dev
[0].request("REATTACH")
927 dev
[0].wait_connected()
928 hwsim_utils
.test_connectivity(dev
[0], hapd
)
930 dev
[0].request("SET reassoc_same_bss_optim 0")
932 def test_ap_open_no_reflection(dev
, apdev
):
933 """AP with open mode, STA sending packets to itself"""
934 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
935 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
937 ev
= hapd
.wait_event(["AP-STA-CONNECTED"], timeout
=5)
939 raise Exception("No connection event received from hostapd")
940 # test normal connectivity is OK
941 hwsim_utils
.test_connectivity(dev
[0], hapd
)
943 # test that we can't talk to ourselves
944 addr
= dev
[0].own_addr()
945 res
= dev
[0].request('DATA_TEST_CONFIG 1')
949 cmd
= "DATA_TEST_TX {} {} {}".format(addr
, addr
, 0)
952 ev
= dev
[0].wait_event(["DATA-TEST-RX"], timeout
=1)
954 if ev
is not None and "DATA-TEST-RX {} {}".format(addr
, addr
) in ev
:
955 raise Exception("STA can unexpectedly talk to itself")
957 dev
[0].request('DATA_TEST_CONFIG 0')
959 def test_ap_no_auth_ack(dev
, apdev
):
960 """AP not receiving Authentication frame ACK"""
961 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open",
962 "ap_max_inactivity": "1"})
963 hapd
.set("ext_mgmt_frame_handling", "1")
964 bssid
= hapd
.own_addr()
965 addr
= "02:01:02:03:04:05"
966 frame
= "b0003a01" + bssid
.replace(':', '') + addr
.replace(':', '') + bssid
.replace(':', '') + "1000" + "000001000000"
967 if "OK" not in hapd
.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + frame
):
968 raise Exception("MGMT_RX_PROCESS failed")
969 ev
= hapd
.wait_event(["MGMT-TX-STATUS"], timeout
=5)
971 raise Exception("TX status for Authentication frame not reported")
972 if "ok=0 buf=b0" not in ev
:
973 raise Exception("Unexpected TX status contents: " + ev
)
975 # wait for STA to be removed due to timeout
976 ev
= hapd
.wait_event(["MGMT-TX-STATUS"], timeout
=5)
978 raise Exception("TX status for Deauthentication frame not reported")
979 if "ok=0 buf=c0" not in ev
:
980 raise Exception("Unexpected TX status contents (disconnect): " + ev
)
982 def test_ap_open_layer_2_update(dev
, apdev
, params
):
983 """AP with open mode (no security) and Layer 2 Update frame"""
984 prefix
= "ap_open_layer_2_update"
985 ifname
= apdev
[0]["ifname"]
986 cap
= os
.path
.join(params
['logdir'], prefix
+ "." + ifname
+ ".pcap")
988 hapd
= hostapd
.add_ap(apdev
[0], {"ssid": "open"})
989 wt
= WlantestCapture(ifname
, cap
)
992 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
994 hwsim_utils
.test_connectivity(dev
[0], hapd
)
996 hwsim_utils
.test_connectivity(dev
[0], hapd
)
1000 # Check for Layer 2 Update frame and unexpected frames from the station
1001 # that did not fully complete authentication.
1002 res
= run_tshark(cap
, "basicxid.llc.xid.format == 0x81",
1003 ["eth.src"], wait
=False)
1004 real_sta_seen
= False
1005 unexpected_sta_seen
= False
1006 real_addr
= dev
[0].own_addr()
1007 for l
in res
.splitlines():
1009 real_sta_seen
= True
1011 unexpected_sta_seen
= True
1012 if unexpected_sta_seen
:
1013 raise Exception("Layer 2 Update frame from unexpected STA seen")
1014 if not real_sta_seen
:
1015 raise Exception("Layer 2 Update frame from real STA not seen")