]>
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 test_ap_ht
import set_world_reg
23 def test_ap_open(dev
, apdev
):
24 """AP with open mode (no security) configuration"""
25 _test_ap_open(dev
, apdev
)
27 def _test_ap_open(dev
, apdev
):
28 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
29 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
31 ev
= hapd
.wait_event([ "AP-STA-CONNECTED" ], timeout
=5)
33 raise Exception("No connection event received from hostapd")
34 hwsim_utils
.test_connectivity(dev
[0], hapd
)
36 dev
[0].request("DISCONNECT")
37 ev
= hapd
.wait_event([ "AP-STA-DISCONNECTED" ], timeout
=5)
39 raise Exception("No disconnection event received from hostapd")
41 def test_ap_open_packet_loss(dev
, apdev
):
42 """AP with open mode configuration and large packet loss"""
43 params
= { "ssid": "open",
44 "ignore_probe_probability": "0.5",
45 "ignore_auth_probability": "0.5",
46 "ignore_assoc_probability": "0.5",
47 "ignore_reassoc_probability": "0.5" }
48 hapd
= hostapd
.add_ap(apdev
[0], params
)
50 dev
[i
].connect("open", key_mgmt
="NONE", scan_freq
="2412",
53 dev
[i
].wait_connected(timeout
=20)
56 def test_ap_open_unknown_action(dev
, apdev
):
57 """AP with open mode configuration and unknown Action frame"""
58 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
59 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
60 bssid
= apdev
[0]['bssid']
61 cmd
= "MGMT_TX {} {} freq=2412 action=765432".format(bssid
, bssid
)
62 if "FAIL" in dev
[0].request(cmd
):
63 raise Exception("Could not send test Action frame")
64 ev
= dev
[0].wait_event(["MGMT-TX-STATUS"], timeout
=10)
66 raise Exception("Timeout on MGMT-TX-STATUS")
67 if "result=SUCCESS" not in ev
:
68 raise Exception("AP did not ack Action frame")
70 def test_ap_open_invalid_wmm_action(dev
, apdev
):
71 """AP with open mode configuration and invalid WMM Action frame"""
72 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
73 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
74 bssid
= apdev
[0]['bssid']
75 cmd
= "MGMT_TX {} {} freq=2412 action=1100".format(bssid
, bssid
)
76 if "FAIL" in dev
[0].request(cmd
):
77 raise Exception("Could not send test Action frame")
78 ev
= dev
[0].wait_event(["MGMT-TX-STATUS"], timeout
=10)
79 if ev
is None or "result=SUCCESS" not in ev
:
80 raise Exception("AP did not ack Action frame")
83 def test_ap_open_reconnect_on_inactivity_disconnect(dev
, apdev
):
84 """Reconnect to open mode AP after inactivity related disconnection"""
85 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
86 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
87 hapd
.request("DEAUTHENTICATE " + dev
[0].p2p_interface_addr() + " reason=4")
88 dev
[0].wait_disconnected(timeout
=5)
89 dev
[0].wait_connected(timeout
=2, error
="Timeout on reconnection")
92 def test_ap_open_assoc_timeout(dev
, apdev
):
93 """AP timing out association"""
95 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
96 dev
[0].scan(freq
="2412")
97 hapd
.set("ext_mgmt_frame_handling", "1")
98 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
100 for i
in range(0, 10):
103 raise Exception("MGMT RX wait timed out")
104 if req
['subtype'] == 11:
108 raise Exception("Authentication frame not received")
111 resp
['fc'] = req
['fc']
112 resp
['da'] = req
['sa']
113 resp
['sa'] = req
['da']
114 resp
['bssid'] = req
['bssid']
115 resp
['payload'] = struct
.pack('<HHH', 0, 2, 0)
119 for i
in range(0, 10):
122 raise Exception("MGMT RX wait timed out")
123 if req
['subtype'] == 0:
128 raise Exception("Association Request frames not received: assoc=%d" % assoc
)
129 hapd
.set("ext_mgmt_frame_handling", "0")
130 dev
[0].wait_connected(timeout
=15)
133 def test_ap_open_id_str(dev
, apdev
):
134 """AP with open mode and id_str"""
135 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
136 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412", id_str
="foo",
138 ev
= dev
[0].wait_connected(timeout
=10)
139 if "id_str=foo" not in ev
:
140 raise Exception("CTRL-EVENT-CONNECT did not have matching id_str: " + ev
)
141 if dev
[0].get_status_field("id_str") != "foo":
142 raise Exception("id_str mismatch")
145 def test_ap_open_select_any(dev
, apdev
):
146 """AP with open mode and select any network"""
147 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
148 id = dev
[0].connect("unknown", key_mgmt
="NONE", scan_freq
="2412",
149 only_add_network
=True)
150 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
151 only_add_network
=True)
152 dev
[0].select_network(id)
153 ev
= dev
[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND",
154 "CTRL-EVENT-CONNECTED"], timeout
=10)
156 raise Exception("No result reported")
157 if "CTRL-EVENT-CONNECTED" in ev
:
158 raise Exception("Unexpected connection")
160 dev
[0].select_network("any")
161 dev
[0].wait_connected(timeout
=10)
164 def test_ap_open_unexpected_assoc_event(dev
, apdev
):
165 """AP with open mode and unexpected association event"""
166 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
167 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
168 dev
[0].request("DISCONNECT")
169 dev
[0].wait_disconnected(timeout
=15)
170 dev
[0].dump_monitor()
171 # This will be accepted due to matching network
172 dev
[0].cmd_execute(['iw', 'dev', dev
[0].ifname
, 'connect', 'open', "2412",
174 dev
[0].wait_connected(timeout
=15)
175 dev
[0].dump_monitor()
177 dev
[0].request("REMOVE_NETWORK all")
178 dev
[0].wait_disconnected(timeout
=5)
179 dev
[0].dump_monitor()
180 # This will result in disconnection due to no matching network
181 dev
[0].cmd_execute(['iw', 'dev', dev
[0].ifname
, 'connect', 'open', "2412",
183 dev
[0].wait_disconnected(timeout
=15)
185 def test_ap_open_external_assoc(dev
, apdev
):
186 """AP with open mode and external association"""
187 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open-ext-assoc" })
189 dev
[0].request("STA_AUTOCONNECT 0")
190 id = dev
[0].connect("open-ext-assoc", key_mgmt
="NONE", scan_freq
="2412",
191 only_add_network
=True)
192 dev
[0].request("ENABLE_NETWORK %s no-connect" % id)
193 dev
[0].dump_monitor()
194 # This will be accepted due to matching network
195 dev
[0].cmd_execute(['iw', 'dev', dev
[0].ifname
, 'connect',
196 'open-ext-assoc', "2412", apdev
[0]['bssid']])
197 ev
= dev
[0].wait_event([ "CTRL-EVENT-DISCONNECTED",
198 "CTRL-EVENT-CONNECTED" ], timeout
=10)
200 raise Exception("Connection timed out")
201 if "CTRL-EVENT-DISCONNECTED" in ev
:
202 raise Exception("Unexpected disconnection event")
203 dev
[0].dump_monitor()
204 dev
[0].request("DISCONNECT")
205 dev
[0].wait_disconnected(timeout
=5)
207 dev
[0].request("STA_AUTOCONNECT 1")
210 def test_ap_bss_load(dev
, apdev
):
211 """AP with open mode (no security) configuration"""
212 hapd
= hostapd
.add_ap(apdev
[0],
214 "bss_load_update_period": "10",
215 "chan_util_avg_period": "20" })
216 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
217 # this does not really get much useful output with mac80211_hwsim currently,
218 # but run through the channel survey update couple of times
219 for i
in range(0, 10):
220 hwsim_utils
.test_connectivity(dev
[0], hapd
)
221 hwsim_utils
.test_connectivity(dev
[0], hapd
)
222 hwsim_utils
.test_connectivity(dev
[0], hapd
)
224 avg
= hapd
.get_status_field("chan_util_avg")
226 raise Exception("No STATUS chan_util_avg seen")
228 def test_ap_bss_load_fail(dev
, apdev
):
229 """BSS Load update failing to get survey data"""
230 hapd
= hostapd
.add_ap(apdev
[0],
232 "bss_load_update_period": "1" })
233 with
fail_test(hapd
, 1, "wpa_driver_nl80211_get_survey"):
234 wait_fail_trigger(hapd
, "GET_FAIL")
236 def hapd_out_of_mem(hapd
, apdev
, count
, func
):
237 with
alloc_fail(hapd
, count
, func
):
240 hostapd
.add_ap(apdev
, { "ssid": "open" })
245 raise Exception("hostapd interface started even with memory allocation failure: %d:%s" % (count
, func
))
247 def test_ap_open_out_of_memory(dev
, apdev
):
248 """hostapd failing to setup interface due to allocation failure"""
249 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
250 hapd_out_of_mem(hapd
, apdev
[1], 1, "hostapd_alloc_bss_data")
252 for i
in range(1, 3):
253 hapd_out_of_mem(hapd
, apdev
[1], i
, "hostapd_iface_alloc")
255 for i
in range(1, 5):
256 hapd_out_of_mem(hapd
, apdev
[1], i
, "hostapd_config_defaults;hostapd_config_alloc")
258 hapd_out_of_mem(hapd
, apdev
[1], 1, "hostapd_config_alloc")
260 hapd_out_of_mem(hapd
, apdev
[1], 1, "hostapd_driver_init")
262 for i
in range(1, 3):
263 hapd_out_of_mem(hapd
, apdev
[1], i
, "=wpa_driver_nl80211_drv_init")
265 # eloop_register_read_sock() call from i802_init()
266 hapd_out_of_mem(hapd
, apdev
[1], 1, "eloop_sock_table_add_sock;?eloop_register_sock;?eloop_register_read_sock;=i802_init")
268 # verify that a new interface can still be added when memory allocation does
270 hostapd
.add_ap(apdev
[1], { "ssid": "open" })
272 def test_bssid_black_white_list(dev
, apdev
):
273 """BSSID black/white list"""
274 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
275 hapd2
= hostapd
.add_ap(apdev
[1], { "ssid": "open" })
277 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
278 bssid_whitelist
=apdev
[1]['bssid'])
279 dev
[1].connect("open", key_mgmt
="NONE", scan_freq
="2412",
280 bssid_blacklist
=apdev
[1]['bssid'])
281 dev
[2].connect("open", key_mgmt
="NONE", scan_freq
="2412",
282 bssid_whitelist
="00:00:00:00:00:00/00:00:00:00:00:00",
283 bssid_blacklist
=apdev
[1]['bssid'])
284 if dev
[0].get_status_field('bssid') != apdev
[1]['bssid']:
285 raise Exception("dev[0] connected to unexpected AP")
286 if dev
[1].get_status_field('bssid') != apdev
[0]['bssid']:
287 raise Exception("dev[1] connected to unexpected AP")
288 if dev
[2].get_status_field('bssid') != apdev
[0]['bssid']:
289 raise Exception("dev[2] connected to unexpected AP")
290 dev
[0].request("REMOVE_NETWORK all")
291 dev
[1].request("REMOVE_NETWORK all")
292 dev
[2].request("REMOVE_NETWORK all")
294 dev
[2].connect("open", key_mgmt
="NONE", scan_freq
="2412",
295 bssid_whitelist
="00:00:00:00:00:00", wait_connect
=False)
296 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
297 bssid_whitelist
="11:22:33:44:55:66/ff:00:00:00:00:00 " + apdev
[1]['bssid'] + " aa:bb:cc:dd:ee:ff")
298 dev
[1].connect("open", key_mgmt
="NONE", scan_freq
="2412",
299 bssid_blacklist
="11:22:33:44:55:66/ff:00:00:00:00:00 " + apdev
[1]['bssid'] + " aa:bb:cc:dd:ee:ff")
300 if dev
[0].get_status_field('bssid') != apdev
[1]['bssid']:
301 raise Exception("dev[0] connected to unexpected AP")
302 if dev
[1].get_status_field('bssid') != apdev
[0]['bssid']:
303 raise Exception("dev[1] connected to unexpected AP")
304 dev
[0].request("REMOVE_NETWORK all")
305 dev
[1].request("REMOVE_NETWORK all")
306 ev
= dev
[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=0.1)
308 raise Exception("Unexpected dev[2] connectin")
309 dev
[2].request("REMOVE_NETWORK all")
311 def test_ap_open_wpas_in_bridge(dev
, apdev
):
312 """Open mode AP and wpas interface in a bridge"""
316 _test_ap_open_wpas_in_bridge(dev
, apdev
)
318 subprocess
.call(['ip', 'link', 'set', 'dev', br_ifname
, 'down'])
319 subprocess
.call(['brctl', 'delif', br_ifname
, ifname
])
320 subprocess
.call(['brctl', 'delbr', br_ifname
])
321 subprocess
.call(['iw', ifname
, 'set', '4addr', 'off'])
323 def _test_ap_open_wpas_in_bridge(dev
, apdev
):
324 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
328 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
329 # First, try a failure case of adding an interface
331 wpas
.interface_add(ifname
, br_ifname
=br_ifname
)
332 raise Exception("Interface addition succeeded unexpectedly")
333 except Exception as e
:
334 if "Failed to add" in str(e
):
335 logger
.info("Ignore expected interface_add failure due to missing bridge interface: " + str(e
))
339 # Next, add the bridge interface and add the interface again
340 subprocess
.call(['brctl', 'addbr', br_ifname
])
341 subprocess
.call(['brctl', 'setfd', br_ifname
, '0'])
342 subprocess
.call(['ip', 'link', 'set', 'dev', br_ifname
, 'up'])
343 subprocess
.call(['iw', ifname
, 'set', '4addr', 'on'])
344 subprocess
.check_call(['brctl', 'addif', br_ifname
, ifname
])
345 wpas
.interface_add(ifname
, br_ifname
=br_ifname
)
347 wpas
.connect("open", key_mgmt
="NONE", scan_freq
="2412")
350 def test_ap_open_start_disabled(dev
, apdev
):
351 """AP with open mode and beaconing disabled"""
352 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open",
353 "start_disabled": "1" })
354 bssid
= apdev
[0]['bssid']
356 dev
[0].flush_scan_cache()
357 dev
[0].scan(freq
=2412, only_new
=True)
358 if dev
[0].get_bss(bssid
) is not None:
359 raise Exception("AP was seen beaconing")
360 if "OK" not in hapd
.request("RELOAD"):
361 raise Exception("RELOAD failed")
362 dev
[0].scan_for_bss(bssid
, freq
=2412)
363 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
366 def test_ap_open_start_disabled2(dev
, apdev
):
367 """AP with open mode and beaconing disabled (2)"""
368 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open",
369 "start_disabled": "1" })
370 bssid
= apdev
[0]['bssid']
372 dev
[0].flush_scan_cache()
373 dev
[0].scan(freq
=2412, only_new
=True)
374 if dev
[0].get_bss(bssid
) is not None:
375 raise Exception("AP was seen beaconing")
376 if "OK" not in hapd
.request("UPDATE_BEACON"):
377 raise Exception("UPDATE_BEACON failed")
378 dev
[0].scan_for_bss(bssid
, freq
=2412)
379 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
380 if "OK" not in hapd
.request("UPDATE_BEACON"):
381 raise Exception("UPDATE_BEACON failed")
382 dev
[0].request("DISCONNECT")
383 dev
[0].wait_disconnected()
384 dev
[0].request("RECONNECT")
385 dev
[0].wait_connected()
388 def test_ap_open_ifdown(dev
, apdev
):
389 """AP with open mode and external ifconfig down"""
390 params
= { "ssid": "open",
391 "ap_max_inactivity": "1" }
392 hapd
= hostapd
.add_ap(apdev
[0], params
)
393 bssid
= apdev
[0]['bssid']
395 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
396 dev
[1].connect("open", key_mgmt
="NONE", scan_freq
="2412")
397 hapd
.cmd_execute(['ip', 'link', 'set', 'dev', apdev
[0]['ifname'], 'down'])
398 ev
= hapd
.wait_event(["AP-STA-DISCONNECTED"], timeout
=10)
400 raise Exception("Timeout on AP-STA-DISCONNECTED (1)")
401 ev
= hapd
.wait_event(["AP-STA-DISCONNECTED"], timeout
=5)
403 raise Exception("Timeout on AP-STA-DISCONNECTED (2)")
404 ev
= hapd
.wait_event(["INTERFACE-DISABLED"], timeout
=5)
406 raise Exception("No INTERFACE-DISABLED event")
407 # The following wait tests beacon loss detection in mac80211 on dev0.
408 # dev1 is used to test stopping of AP side functionality on client polling.
409 dev
[1].request("REMOVE_NETWORK all")
410 hapd
.cmd_execute(['ip', 'link', 'set', 'dev', apdev
[0]['ifname'], 'up'])
411 dev
[0].wait_disconnected()
412 dev
[1].wait_disconnected()
413 ev
= hapd
.wait_event(["INTERFACE-ENABLED"], timeout
=10)
415 raise Exception("No INTERFACE-ENABLED event")
416 dev
[0].wait_connected()
417 hwsim_utils
.test_connectivity(dev
[0], hapd
)
419 def test_ap_open_disconnect_in_ps(dev
, apdev
, params
):
420 """Disconnect with the client in PS to regression-test a kernel bug"""
421 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
422 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
424 ev
= hapd
.wait_event([ "AP-STA-CONNECTED" ], timeout
=5)
426 raise Exception("No connection event received from hostapd")
429 # enable power save mode
430 hwsim_utils
.set_powersave(dev
[0], hwsim_utils
.PS_ENABLED
)
433 # inject some traffic
435 da
= dev
[0].own_addr()
436 hapd
.request('DATA_TEST_CONFIG 1')
437 hapd
.request('DATA_TEST_TX {} {} 0'.format(da
, sa
))
438 hapd
.request('DATA_TEST_CONFIG 0')
440 # let the AP send couple of Beacon frames
443 # disconnect - with traffic pending - shouldn't cause kernel warnings
444 dev
[0].request("DISCONNECT")
446 hwsim_utils
.set_powersave(dev
[0], hwsim_utils
.PS_DISABLED
)
449 out
= run_tshark(os
.path
.join(params
['logdir'], "hwsim0.pcapng"),
450 "wlan_mgt.tim.partial_virtual_bitmap",
451 ["wlan_mgt.tim.partial_virtual_bitmap"])
454 for l
in out
.splitlines():
456 if pvb
> 0 and state
== 0:
458 elif pvb
== 0 and state
== 1:
461 raise Exception("Didn't observe TIM bit getting set and unset (state=%d)" % state
)
464 def test_ap_open_select_network(dev
, apdev
):
465 """Open mode connection and SELECT_NETWORK to change network"""
466 hapd1
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
467 bssid1
= apdev
[0]['bssid']
468 hapd2
= hostapd
.add_ap(apdev
[1], { "ssid": "open2" })
469 bssid2
= apdev
[1]['bssid']
471 id1
= dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
472 only_add_network
=True)
473 id2
= dev
[0].connect("open2", key_mgmt
="NONE", scan_freq
="2412")
474 hwsim_utils
.test_connectivity(dev
[0], hapd2
)
476 dev
[0].select_network(id1
)
477 dev
[0].wait_connected()
478 res
= dev
[0].request("BLACKLIST")
479 if bssid1
in res
or bssid2
in res
:
480 raise Exception("Unexpected blacklist entry")
481 hwsim_utils
.test_connectivity(dev
[0], hapd1
)
483 dev
[0].select_network(id2
)
484 dev
[0].wait_connected()
485 hwsim_utils
.test_connectivity(dev
[0], hapd2
)
486 res
= dev
[0].request("BLACKLIST")
487 if bssid1
in res
or bssid2
in res
:
488 raise Exception("Unexpected blacklist entry(2)")
491 def test_ap_open_disable_enable(dev
, apdev
):
492 """AP with open mode getting disabled and re-enabled"""
493 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
494 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
498 hapd
.request("DISABLE")
499 dev
[0].wait_disconnected()
500 hapd
.request("ENABLE")
501 dev
[0].wait_connected()
502 hwsim_utils
.test_connectivity(dev
[0], hapd
)
504 def sta_enable_disable(dev
, bssid
):
505 dev
.scan_for_bss(bssid
, freq
=2412)
506 work_id
= dev
.request("RADIO_WORK add block-work")
507 ev
= dev
.wait_event(["EXT-RADIO-WORK-START"])
509 raise Exception("Timeout while waiting radio work to start")
510 id = dev
.connect("open", key_mgmt
="NONE", scan_freq
="2412",
511 only_add_network
=True)
512 dev
.request("ENABLE_NETWORK %d" % id)
513 if "connect@" not in dev
.request("RADIO_WORK show"):
514 raise Exception("connect radio work missing")
515 dev
.request("DISABLE_NETWORK %d" % id)
516 dev
.request("RADIO_WORK done " + work_id
)
520 if "connect@" not in dev
.request("RADIO_WORK show"):
525 raise Exception("connect radio work not completed")
526 ev
= dev
.wait_event(["CTRL-EVENT-CONNECTED"], timeout
=0.1)
528 raise Exception("Unexpected connection")
529 dev
.request("DISCONNECT")
531 def test_ap_open_sta_enable_disable(dev
, apdev
):
532 """AP with open mode and wpa_supplicant ENABLE/DISABLE_NETWORK"""
533 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
534 bssid
= apdev
[0]['bssid']
536 sta_enable_disable(dev
[0], bssid
)
538 wpas
= WpaSupplicant(global_iface
='/tmp/wpas-wlan5')
539 wpas
.interface_add("wlan5", drv_params
="force_connect_cmd=1")
540 sta_enable_disable(wpas
, bssid
)
543 def test_ap_open_select_twice(dev
, apdev
):
544 """AP with open mode and select network twice"""
545 id = dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
546 only_add_network
=True)
547 dev
[0].select_network(id)
548 ev
= dev
[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout
=10)
550 raise Exception("No result reported")
551 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
552 # Verify that the second SELECT_NETWORK starts a new scan immediately by
553 # waiting less than the default scan period.
554 dev
[0].select_network(id)
555 dev
[0].wait_connected(timeout
=3)
558 def test_ap_open_reassoc_not_found(dev
, apdev
):
559 """AP with open mode and REASSOCIATE not finding a match"""
560 id = dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
561 only_add_network
=True)
562 dev
[0].select_network(id)
563 ev
= dev
[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout
=10)
565 raise Exception("No result reported")
566 dev
[0].request("DISCONNECT")
569 dev
[0].dump_monitor()
571 dev
[0].request("REASSOCIATE")
572 ev
= dev
[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND"], timeout
=10)
574 raise Exception("No result reported")
575 dev
[0].request("DISCONNECT")
578 def test_ap_open_sta_statistics(dev
, apdev
):
579 """AP with open mode and STA statistics"""
580 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
581 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
582 addr
= dev
[0].own_addr()
584 stats1
= hapd
.get_sta(addr
)
585 logger
.info("stats1: " + str(stats1
))
587 stats2
= hapd
.get_sta(addr
)
588 logger
.info("stats2: " + str(stats2
))
589 hwsim_utils
.test_connectivity(dev
[0], hapd
)
590 stats3
= hapd
.get_sta(addr
)
591 logger
.info("stats3: " + str(stats3
))
593 # Cannot require specific inactive_msec changes without getting rid of all
594 # unrelated traffic, so for now, just print out the results in the log for
598 def test_ap_open_poll_sta(dev
, apdev
):
599 """AP with open mode and STA poll"""
600 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
601 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
602 addr
= dev
[0].own_addr()
604 if "OK" not in hapd
.request("POLL_STA " + addr
):
605 raise Exception("POLL_STA failed")
606 ev
= hapd
.wait_event(["AP-STA-POLL-OK"], timeout
=5)
608 raise Exception("Poll response not seen")
610 raise Exception("Unexpected poll response: " + ev
)
612 def test_ap_open_pmf_default(dev
, apdev
):
613 """AP with open mode (no security) configuration and pmf=2"""
614 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
615 dev
[1].connect("open", key_mgmt
="NONE", scan_freq
="2412",
616 ieee80211w
="2", wait_connect
=False)
617 dev
[2].connect("open", key_mgmt
="NONE", scan_freq
="2412",
620 dev
[0].request("SET pmf 2")
621 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
623 dev
[0].request("DISCONNECT")
624 dev
[0].wait_disconnected()
626 dev
[0].request("SET pmf 0")
627 dev
[2].request("DISCONNECT")
628 dev
[2].wait_disconnected()
630 ev
= dev
[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=0.1)
632 raise Exception("Unexpected dev[1] connection")
633 dev
[1].request("DISCONNECT")
635 def test_ap_open_drv_fail(dev
, apdev
):
636 """AP with open mode and driver operations failing"""
637 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
639 with
fail_test(dev
[0], 1, "wpa_driver_nl80211_authenticate"):
640 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
642 wait_fail_trigger(dev
[0], "GET_FAIL")
643 dev
[0].request("REMOVE_NETWORK all")
645 with
fail_test(dev
[0], 1, "wpa_driver_nl80211_associate"):
646 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412",
648 wait_fail_trigger(dev
[0], "GET_FAIL")
649 dev
[0].request("REMOVE_NETWORK all")
651 def run_multicast_to_unicast(dev
, apdev
, convert
):
652 params
= { "ssid": "open" }
653 params
["multicast_to_unicast"] = "1" if convert
else "0"
654 hapd
= hostapd
.add_ap(apdev
[0], params
)
655 dev
[0].scan_for_bss(hapd
.own_addr(), freq
=2412)
656 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
657 ev
= hapd
.wait_event([ "AP-STA-CONNECTED" ], timeout
=5)
659 raise Exception("No connection event received from hostapd")
660 hwsim_utils
.test_connectivity(dev
[0], hapd
, multicast_to_unicast
=convert
)
661 dev
[0].request("DISCONNECT")
662 ev
= hapd
.wait_event([ "AP-STA-DISCONNECTED" ], timeout
=5)
664 raise Exception("No disconnection event received from hostapd")
666 def test_ap_open_multicast_to_unicast(dev
, apdev
):
667 """Multicast-to-unicast conversion enabled"""
668 run_multicast_to_unicast(dev
, apdev
, True)
670 def test_ap_open_multicast_to_unicast_disabled(dev
, apdev
):
671 """Multicast-to-unicast conversion disabled"""
672 run_multicast_to_unicast(dev
, apdev
, False)
674 def test_ap_open_drop_duplicate(dev
, apdev
, params
):
675 """AP dropping duplicate management frames"""
676 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open",
677 "interworking": "1" })
678 hapd
.set("ext_mgmt_frame_handling", "1")
679 bssid
= hapd
.own_addr().replace(':', '')
680 addr
= "020304050607"
681 auth
= "b0003a01" + bssid
+ addr
+ bssid
+ '1000000001000000'
682 if "OK" not in hapd
.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % auth
):
683 raise Exception("MGMT_RX_PROCESS failed")
684 auth
= "b0083a01" + bssid
+ addr
+ bssid
+ '1000000001000000'
685 if "OK" not in hapd
.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % auth
):
686 raise Exception("MGMT_RX_PROCESS failed")
688 ies
= "00046f70656e010802040b160c12182432043048606c2d1a3c101bffff0000000000000000000001000000000000000000007f0a04000a020140004000013b155151525354737475767778797a7b7c7d7e7f808182dd070050f202000100"
689 assoc_req
= "00003a01" + bssid
+ addr
+ bssid
+ "2000" + "21040500" + ies
690 if "OK" not in hapd
.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % assoc_req
):
691 raise Exception("MGMT_RX_PROCESS failed")
692 assoc_req
= "00083a01" + bssid
+ addr
+ bssid
+ "2000" + "21040500" + ies
693 if "OK" not in hapd
.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % assoc_req
):
694 raise Exception("MGMT_RX_PROCESS failed")
695 reassoc_req
= "20083a01" + bssid
+ addr
+ bssid
+ "2000" + "21040500" + ies
696 if "OK" not in hapd
.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % reassoc_req
):
697 raise Exception("MGMT_RX_PROCESS failed")
698 if "OK" not in hapd
.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % reassoc_req
):
699 raise Exception("MGMT_RX_PROCESS failed")
701 action
= "d0003a01" + bssid
+ addr
+ bssid
+ "1000" + "040a006c0200000600000102000101"
702 if "OK" not in hapd
.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % action
):
703 raise Exception("MGMT_RX_PROCESS failed")
705 action
= "d0083a01" + bssid
+ addr
+ bssid
+ "1000" + "040a006c0200000600000102000101"
706 if "OK" not in hapd
.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=%s" % action
):
707 raise Exception("MGMT_RX_PROCESS failed")
709 out
= run_tshark(os
.path
.join(params
['logdir'], "hwsim0.pcapng"),
710 "wlan.fc.type == 0", ["wlan.fc.subtype"])
715 for subtype
in out
.splitlines():
726 raise Exception("Unexpected number of Authentication frames: %d" % num_auth
)
728 raise Exception("Unexpected number of association frames: %d" % num_assoc
)
730 raise Exception("Unexpected number of reassociation frames: %d" % num_reassoc
)
732 raise Exception("Unexpected number of Action frames: %d" % num_action
)
734 def test_ap_open_select_network_freq(dev
, apdev
):
735 """AP with open mode and use for SELECT_NETWORK freq parameter"""
736 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
737 id = dev
[0].connect("open", key_mgmt
="NONE", only_add_network
=True)
738 dev
[0].select_network(id, freq
=2412)
739 start
= os
.times()[4]
740 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-STARTED"], timeout
=5)
742 raise Exception("Scan not started")
743 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], timeout
=15)
745 raise Exception("Scan not completed")
747 logger
.info("Scan duration: {} seconds".format(end
- start
))
749 raise Exception("Scan took unexpectedly long time")
750 dev
[0].wait_connected()
752 def test_ap_open_noncountry(dev
, apdev
):
753 """AP with open mode and noncountry entity as Country String"""
754 _test_ap_open_country(dev
, apdev
, "XX", "0x58")
756 def test_ap_open_country_table_e4(dev
, apdev
):
757 """AP with open mode and Table E-4 Country String"""
758 _test_ap_open_country(dev
, apdev
, "DE", "0x04")
760 def test_ap_open_country_indoor(dev
, apdev
):
761 """AP with open mode and indoor country code"""
762 _test_ap_open_country(dev
, apdev
, "DE", "0x49")
764 def test_ap_open_country_outdoor(dev
, apdev
):
765 """AP with open mode and outdoor country code"""
766 _test_ap_open_country(dev
, apdev
, "DE", "0x4f")
768 def _test_ap_open_country(dev
, apdev
, country_code
, country3
):
771 hapd
= run_ap_open_country(dev
, apdev
, country_code
, country3
)
773 clear_regdom(hapd
, dev
)
775 def run_ap_open_country(dev
, apdev
, country_code
, country3
):
776 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open",
777 "country_code": country_code
,
778 "country3": country3
,
780 dev
[0].scan_for_bss(hapd
.own_addr(), freq
=2412)
781 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
782 dev
[0].wait_regdom(country_ie
=True)
785 def test_ap_open_disable_select(dev
, apdev
):
786 """DISABLE_NETWORK for connected AP followed by SELECT_NETWORK"""
787 hapd1
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
788 hapd2
= hostapd
.add_ap(apdev
[1], { "ssid": "open" })
789 id = dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
791 dev
[0].request("DISABLE_NETWORK %d" % id)
792 dev
[0].wait_disconnected()
793 res
= dev
[0].request("BLACKLIST")
794 if hapd1
.own_addr() in res
or hapd2
.own_addr() in res
:
795 raise Exception("Unexpected blacklist entry added")
796 dev
[0].request("SELECT_NETWORK %d" % id)
797 dev
[0].wait_connected()
799 def test_ap_open_reassoc_same(dev
, apdev
):
800 """AP with open mode and STA reassociating back to same AP without auth exchange"""
801 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
802 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
804 dev
[0].request("SET reassoc_same_bss_optim 1")
805 dev
[0].request("REATTACH")
806 dev
[0].wait_connected()
807 hwsim_utils
.test_connectivity(dev
[0], hapd
)
809 dev
[0].request("SET reassoc_same_bss_optim 0")
811 def test_ap_open_no_reflection(dev
, apdev
):
812 """AP with open mode, STA sending packets to itself"""
813 hapd
= hostapd
.add_ap(apdev
[0], { "ssid": "open" })
814 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
816 ev
= hapd
.wait_event([ "AP-STA-CONNECTED" ], timeout
=5)
818 raise Exception("No connection event received from hostapd")
819 # test normal connectivity is OK
820 hwsim_utils
.test_connectivity(dev
[0], hapd
)
822 # test that we can't talk to ourselves
823 addr
= dev
[0].own_addr()
824 res
= dev
[0].request('DATA_TEST_CONFIG 1')
828 cmd
= "DATA_TEST_TX {} {} {}".format(addr
, addr
, 0)
831 ev
= dev
[0].wait_event(["DATA-TEST-RX"], timeout
=1)
833 if ev
is not None and "DATA-TEST-RX {} {}".format(addr
, addr
) in ev
:
834 raise Exception("STA can unexpectedly talk to itself")
836 dev
[0].request('DATA_TEST_CONFIG 0')