]>
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.
8 logger
= logging
.getLogger()
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 hwsim_utils
.test_connectivity(dev
[0], hapd
)
21 ev
= hapd
.wait_event([ "AP-STA-CONNECTED" ], timeout
=5)
23 raise Exception("No connection event received from hostapd")
24 dev
[0].request("DISCONNECT")
25 ev
= hapd
.wait_event([ "AP-STA-DISCONNECTED" ], timeout
=5)
27 raise Exception("No disconnection event received from hostapd")
29 def 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
)
38 dev
[i
].connect("open", key_mgmt
="NONE", scan_freq
="2412",
41 ev
= dev
[i
].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=20)
43 raise Exception("Association with the AP timed out")
45 def 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)
55 raise Exception("Timeout on MGMT-TX-STATUS")
56 if "result=SUCCESS" not in ev
:
57 raise Exception("AP did not ack Action frame")
59 def 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)
66 raise Exception("Timeout on disconnection")
67 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout
=2)
69 raise Exception("Timeout on reconnection")
71 def test_ap_open_assoc_timeout(dev
, apdev
):
72 """AP timing out association"""
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",
79 for i
in range(0, 10):
82 raise Exception("MGMT RX wait timed out")
83 if req
['subtype'] == 11:
87 raise Exception("Authentication frame not received")
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)
98 for i
in range(0, 10):
101 raise Exception("MGMT RX wait timed out")
102 if req
['subtype'] == 0:
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)
111 raise Exception("Timeout on connection")
113 def 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",
118 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"])
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")
126 def 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)
136 raise Exception("Unexpected connection")
138 dev
[0].select_network("any")
139 ev
= dev
[0].wait_event(["CTRL-EVENT-CONNECTED"])
141 raise Exception("Association with the AP timed out")
143 def 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")
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)
155 raise Exception("Association with the AP timed out")
156 dev
[0].dump_monitor()
158 dev
[0].request("REMOVE_NETWORK all")
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)
166 raise Exception("Disconnection with the AP timed out")