]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_hapd_ctrl.py
1 # hostapd control interface
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.
9 def test_hapd_ctrl_status(dev
, apdev
):
10 """hostapd ctrl_iface STATUS commands"""
12 bssid
= apdev
[0]['bssid']
13 params
= hostapd
.wpa2_params(ssid
=ssid
, passphrase
="12345678")
14 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
15 status
= hapd
.get_status()
16 driver
= hapd
.get_driver_status()
18 if status
['bss[0]'] != apdev
[0]['ifname']:
19 raise Exception("Unexpected bss[0]")
20 if status
['ssid[0]'] != ssid
:
21 raise Exception("Unexpected ssid[0]")
22 if status
['bssid[0]'] != bssid
:
23 raise Exception("Unexpected bssid[0]")
24 if status
['freq'] != "2412":
25 raise Exception("Unexpected freq")
27 if driver
['beacon_set'] != "1":
28 raise Exception("Unexpected beacon_set")
29 if driver
['addr'] != bssid
:
30 raise Exception("Unexpected addr")
32 def test_hapd_ctrl_p2p_manager(dev
, apdev
):
33 """hostapd as P2P Device manager"""
35 passphrase
= "12345678"
36 params
= hostapd
.wpa2_params(ssid
=ssid
, passphrase
=passphrase
)
37 params
['manage_p2p'] = '1'
38 params
['allow_cross_connection'] = '0'
39 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
40 dev
[0].connect(ssid
, psk
=passphrase
, scan_freq
="2412")
41 addr
= dev
[0].p2p_dev_addr()
42 if "OK" not in hapd
.request("DEAUTHENTICATE " + addr
+ " p2p=2"):
43 raise Exception("DEAUTHENTICATE command failed")
44 dev
[0].wait_disconnected(timeout
=5)
45 dev
[0].wait_connected(timeout
=10, error
="Re-connection timed out")
47 if "OK" not in hapd
.request("DISASSOCIATE " + addr
+ " p2p=2"):
48 raise Exception("DISASSOCIATE command failed")
49 dev
[0].wait_disconnected(timeout
=5)
50 dev
[0].wait_connected(timeout
=10, error
="Re-connection timed out")
52 def test_hapd_ctrl_sta(dev
, apdev
):
53 """hostapd and STA ctrl_iface commands"""
54 ssid
= "hapd-ctrl-sta"
55 passphrase
= "12345678"
56 params
= hostapd
.wpa2_params(ssid
=ssid
, passphrase
=passphrase
)
57 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
58 dev
[0].connect(ssid
, psk
=passphrase
, scan_freq
="2412")
59 addr
= dev
[0].p2p_dev_addr()
60 if "FAIL" in hapd
.request("STA " + addr
):
61 raise Exception("Unexpected STA failure")
62 if "FAIL" not in hapd
.request("STA " + addr
+ " eapol"):
63 raise Exception("Unexpected STA-eapol success")
64 if "FAIL" not in hapd
.request("STA 00:11:22:33:44"):
65 raise Exception("Unexpected STA success")
66 if "FAIL" not in hapd
.request("STA 00:11:22:33:44:55"):
67 raise Exception("Unexpected STA success")
69 if len(hapd
.request("STA-NEXT " + addr
).splitlines()) > 0:
70 raise Exception("Unexpected STA-NEXT result")
71 if "FAIL" not in hapd
.request("STA-NEXT 00:11:22:33:44"):
72 raise Exception("Unexpected STA-NEXT success")
74 def test_hapd_ctrl_disconnect(dev
, apdev
):
75 """hostapd and disconnection ctrl_iface commands"""
77 passphrase
= "12345678"
78 params
= hostapd
.wpa2_params(ssid
=ssid
, passphrase
=passphrase
)
79 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
80 dev
[0].connect(ssid
, psk
=passphrase
, scan_freq
="2412")
81 addr
= dev
[0].p2p_dev_addr()
83 if "FAIL" not in hapd
.request("DEAUTHENTICATE 00:11:22:33:44"):
84 raise Exception("Unexpected DEAUTHENTICATE success")
86 if "OK" not in hapd
.request("DEAUTHENTICATE ff:ff:ff:ff:ff:ff"):
87 raise Exception("Unexpected DEAUTHENTICATE failure")
88 dev
[0].wait_disconnected(timeout
=5)
89 dev
[0].wait_connected(timeout
=10, error
="Re-connection timed out")
91 if "FAIL" not in hapd
.request("DISASSOCIATE 00:11:22:33:44"):
92 raise Exception("Unexpected DISASSOCIATE success")
94 if "OK" not in hapd
.request("DISASSOCIATE ff:ff:ff:ff:ff:ff"):
95 raise Exception("Unexpected DISASSOCIATE failure")
96 dev
[0].wait_disconnected(timeout
=5)
97 dev
[0].wait_connected(timeout
=10, error
="Re-connection timed out")
99 def test_hapd_ctrl_chan_switch(dev
, apdev
):
100 """hostapd and CHAN_SWITCH ctrl_iface command"""
102 params
= { "ssid": ssid
}
103 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
104 if "FAIL" not in hapd
.request("CHAN_SWITCH "):
105 raise Exception("Unexpected CHAN_SWITCH success")
106 if "FAIL" not in hapd
.request("CHAN_SWITCH qwerty 2422"):
107 raise Exception("Unexpected CHAN_SWITCH success")
108 if "FAIL" not in hapd
.request("CHAN_SWITCH 5 qwerty"):
109 raise Exception("Unexpected CHAN_SWITCH success")
110 if "FAIL" not in hapd
.request("CHAN_SWITCH 0 2432 center_freq1=123 center_freq2=234 bandwidth=1000 sec_channel_offset=20 ht vht"):
111 raise Exception("Unexpected CHAN_SWITCH success")
113 def test_hapd_ctrl_level(dev
, apdev
):
114 """hostapd and LEVEL ctrl_iface command"""
116 params
= { "ssid": ssid
}
117 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
118 if "FAIL" not in hapd
.request("LEVEL 0"):
119 raise Exception("Unexpected LEVEL success on non-monitor interface")
121 def test_hapd_ctrl_new_sta(dev
, apdev
):
122 """hostapd and NEW_STA ctrl_iface command"""
124 params
= { "ssid": ssid
}
125 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
126 if "FAIL" not in hapd
.request("NEW_STA 00:11:22:33:44"):
127 raise Exception("Unexpected NEW_STA success")
128 if "OK" not in hapd
.request("NEW_STA 00:11:22:33:44:55"):
129 raise Exception("Unexpected NEW_STA failure")
130 if "AUTHORIZED" not in hapd
.request("STA 00:11:22:33:44:55"):
131 raise Esception("Unexpected NEW_STA STA status")
133 def test_hapd_ctrl_get(dev
, apdev
):
134 """hostapd and GET ctrl_iface command"""
136 params
= { "ssid": ssid
}
137 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
138 if "FAIL" not in hapd
.request("GET foo"):
139 raise Exception("Unexpected GET success")
140 if "FAIL" in hapd
.request("GET version"):
141 raise Exception("Unexpected GET version failure")
143 def test_hapd_ctrl_unknown(dev
, apdev
):
144 """hostapd and unknown ctrl_iface command"""
146 params
= { "ssid": ssid
}
147 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
148 if "UNKNOWN COMMAND" not in hapd
.request("FOO"):
149 raise Exception("Unexpected response")
151 def test_hapd_ctrl_hs20_wnm_notif(dev
, apdev
):
152 """hostapd and HS20_WNM_NOTIF ctrl_iface command"""
154 params
= { "ssid": ssid
}
155 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
156 if "FAIL" not in hapd
.request("HS20_WNM_NOTIF 00:11:22:33:44 http://example.com/"):
157 raise Exception("Unexpected HS20_WNM_NOTIF success")
158 if "FAIL" not in hapd
.request("HS20_WNM_NOTIF 00:11:22:33:44:55http://example.com/"):
159 raise Exception("Unexpected HS20_WNM_NOTIF success")
161 def test_hapd_ctrl_hs20_deauth_req(dev
, apdev
):
162 """hostapd and HS20_DEAUTH_REQ ctrl_iface command"""
164 params
= { "ssid": ssid
}
165 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
166 if "FAIL" not in hapd
.request("HS20_DEAUTH_REQ 00:11:22:33:44 1 120 http://example.com/"):
167 raise Exception("Unexpected HS20_DEAUTH_REQ success")
168 if "FAIL" not in hapd
.request("HS20_DEAUTH_REQ 00:11:22:33:44:55"):
169 raise Exception("Unexpected HS20_DEAUTH_REQ success")
170 if "FAIL" not in hapd
.request("HS20_DEAUTH_REQ 00:11:22:33:44:55 1"):
171 raise Exception("Unexpected HS20_DEAUTH_REQ success")
173 def test_hapd_ctrl_disassoc_imminent(dev
, apdev
):
174 """hostapd and DISASSOC_IMMINENT ctrl_iface command"""
176 params
= { "ssid": ssid
}
177 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
178 if "FAIL" not in hapd
.request("DISASSOC_IMMINENT 00:11:22:33:44"):
179 raise Exception("Unexpected DISASSOC_IMMINENT success")
180 if "FAIL" not in hapd
.request("DISASSOC_IMMINENT 00:11:22:33:44:55"):
181 raise Exception("Unexpected DISASSOC_IMMINENT success")
182 if "FAIL" not in hapd
.request("DISASSOC_IMMINENT 00:11:22:33:44:55 2"):
183 raise Exception("Unexpected DISASSOC_IMMINENT success")
184 dev
[0].connect(ssid
, key_mgmt
="NONE", scan_freq
="2412")
185 addr
= dev
[0].p2p_interface_addr()
186 if "OK" not in hapd
.request("DISASSOC_IMMINENT " + addr
+ " 2"):
187 raise Exception("Unexpected DISASSOC_IMMINENT failure")
188 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15)
190 raise Exception("Scan timed out")
192 def test_hapd_ctrl_ess_disassoc(dev
, apdev
):
193 """hostapd and ESS_DISASSOC ctrl_iface command"""
195 params
= { "ssid": ssid
}
196 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
197 if "FAIL" not in hapd
.request("ESS_DISASSOC 00:11:22:33:44"):
198 raise Exception("Unexpected ESS_DISASSOCT success")
199 if "FAIL" not in hapd
.request("ESS_DISASSOC 00:11:22:33:44:55"):
200 raise Exception("Unexpected ESS_DISASSOC success")
201 dev
[0].connect(ssid
, key_mgmt
="NONE", scan_freq
="2412")
202 addr
= dev
[0].p2p_interface_addr()
203 if "FAIL" not in hapd
.request("ESS_DISASSOC " + addr
):
204 raise Exception("Unexpected ESS_DISASSOC success")
205 if "FAIL" not in hapd
.request("ESS_DISASSOC " + addr
+ " -1"):
206 raise Exception("Unexpected ESS_DISASSOC success")
207 if "FAIL" not in hapd
.request("ESS_DISASSOC " + addr
+ " 1"):
208 raise Exception("Unexpected ESS_DISASSOC success")
209 if "OK" not in hapd
.request("ESS_DISASSOC " + addr
+ " 20 http://example.com/"):
210 raise Exception("Unexpected ESS_DISASSOC failure")
211 ev
= dev
[0].wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15)
213 raise Exception("Scan timed out")
215 def test_hapd_ctrl_set_deny_mac_file(dev
, apdev
):
216 """hostapd and SET deny_mac_file ctrl_iface command"""
218 params
= { "ssid": ssid
}
219 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
220 dev
[0].connect(ssid
, key_mgmt
="NONE", scan_freq
="2412")
221 dev
[1].connect(ssid
, key_mgmt
="NONE", scan_freq
="2412")
222 if "OK" not in hapd
.request("SET deny_mac_file hostapd.macaddr"):
223 raise Exception("Unexpected SET failure")
224 dev
[0].wait_disconnected(timeout
=15)
225 ev
= dev
[1].wait_event(["CTRL-EVENT-DISCONNECTED"], 1)
227 raise Exception("Unexpected disconnection")
229 def test_hapd_ctrl_set_accept_mac_file(dev
, apdev
):
230 """hostapd and SET accept_mac_file ctrl_iface command"""
232 params
= { "ssid": ssid
}
233 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
234 dev
[0].connect(ssid
, key_mgmt
="NONE", scan_freq
="2412")
235 dev
[1].connect(ssid
, key_mgmt
="NONE", scan_freq
="2412")
236 hapd
.request("SET macaddr_acl 1")
237 if "OK" not in hapd
.request("SET accept_mac_file hostapd.macaddr"):
238 raise Exception("Unexpected SET failure")
239 dev
[1].wait_disconnected(timeout
=15)
240 ev
= dev
[0].wait_event(["CTRL-EVENT-DISCONNECTED"], 1)
242 raise Exception("Unexpected disconnection")
244 def test_hapd_ctrl_set_error_cases(dev
, apdev
):
245 """hostapd and SET error cases"""
247 params
= { "ssid": ssid
}
248 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], params
)
249 errors
= [ "wpa_key_mgmt FOO",
250 "wpa_key_mgmt WPA-PSK \t FOO",
257 "wep_key0 12q3456789",
258 "wep_key_len_broadcast 20",
259 "wep_rekey_period -1",
261 "r0kh 02:00:00:00:03:0q nas1.w1.fi 100102030405060708090a0b0c0d0e0f",
262 "r0kh 02:00:00:00:03:00 12345678901234567890123456789012345678901234567890.nas1.w1.fi 100102030405060708090a0b0c0d0e0f",
263 "r0kh 02:00:00:00:03:00 nas1.w1.fi 100q02030405060708090a0b0c0d0e0f",
264 "r1kh 02:00:00:00:04:q0 00:01:02:03:04:06 200102030405060708090a0b0c0d0e0f",
265 "r1kh 02:00:00:00:04:00 00:01:02:03:04:q6 200102030405060708090a0b0c0d0e0f",
266 "r1kh 02:00:00:00:04:00 00:01:02:03:04:06 2q0102030405060708090a0b0c0d0e0f",
267 "roaming_consortium 1",
268 "roaming_consortium 12",
269 "roaming_consortium 112233445566778899aabbccddeeff00",
270 'venue_name P"engExample venue"',
271 'venue_name P"engExample venue',
272 "venue_name engExample venue",
273 "venue_name e:Example venue",
274 "venue_name eng1:Example venue",
275 "venue_name eng:Example venue 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890",
276 "anqp_3gpp_cell_net abc",
277 "anqp_3gpp_cell_net ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;",
278 "anqp_3gpp_cell_net 244",
279 "anqp_3gpp_cell_net 24,123",
280 "anqp_3gpp_cell_net 244,1",
281 "anqp_3gpp_cell_net 244,1234",
283 "nai_realm 0,1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.nas1.w1.fi",
284 "nai_realm 0,example.org,1,2,3,4,5,6,7,8",
285 "nai_realm 0,example.org,1[1:1][2:2][3:3][4:4][5:5]",
286 "nai_realm 0,example.org,1[1]",
287 "nai_realm 0,example.org,1[1:1",
288 "nai_realm 0,a.example.org;b.example.org;c.example.org;d.example.org;e.example.org;f.example.org;g.example.org;h.example.org;i.example.org;j.example.org;k.example.org",
289 "qos_map_set 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60",
290 "qos_map_set 53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,300",
291 "qos_map_set 53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,-1",
292 "qos_map_set 53,2,22,6,8,15,0,7,255,255,16,31,32,39,255,255,40,47,255,255,1",
296 "hs20_conn_capab 6:22",
297 "hs20_wan_metrics 0q:8000:1000:80:240:3000",
298 "hs20_wan_metrics 01",
299 "hs20_wan_metrics 01:8000",
300 "hs20_wan_metrics 01:8000:1000",
301 "hs20_wan_metrics 01:8000:1000:80",
302 "hs20_wan_metrics 01:8000:1000:80:240",
303 "hs20_oper_friendly_name eng1:Example",
306 "hs20_icon 32:32:eng",
307 "hs20_icon 32:32:eng:image/png",
308 "hs20_icon 32:32:eng:image/png:icon32",
309 "hs20_icon 32:32:eng:image/png:123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890:/tmp/icon32.png",
310 "hs20_icon 32:32:eng:image/png:name:/tmp/123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890.png",
314 'osu_ssid "1234567890123456789012345678901234567890"',
315 "osu_friendly_name eng:Example",
316 "osu_nai anonymous@example.com",
317 "osu_method_list 1 0",
319 "osu_service_desc eng:Example services",
320 "ssid 1234567890123456789012345678901234567890",
321 "pac_opaque_encr_key 123456",
322 "eap_fast_a_id 12345",
323 "eap_fast_a_id 12345q",
325 "auth_server_addr foo2",
326 "auth_server_shared_secret ",
327 "acct_server_addr foo3",
328 "acct_server_shared_secret ",
329 "radius_auth_req_attr 123::",
330 "radius_acct_req_attr 123::",
331 "radius_das_client 192.168.1.123",
332 "radius_das_client 192.168.1.1a foo",
335 "max_num_sta 1000000",
336 "wpa_passphrase 1234567",
337 "wpa_passphrase 1234567890123456789012345678901234567890123456789012345678901234",
338 "wpa_psk 1234567890123456789012345678901234567890123456789012345678901234a",
339 "wpa_psk 12345678901234567890123456789012345678901234567890123456789012",
340 "wpa_psk_radius 123",
342 "wpa_pairwise WEP40",
343 "wpa_pairwise WEP104",
345 "rsn_pairwise WEP40",
346 "rsn_pairwise WEP104",
347 "mobility_domain 01",
348 "r1_key_holder 0011223344",
349 "ctrl_interface_group nosuchgrouphere",
357 "rts_threshold 2348",
358 "fragm_threshold -1",
359 "fragm_threshold 2347",
360 "send_probe_response -1",
361 "send_probe_response 2",
363 "vlan_naming 10000000",
364 "group_mgmt_cipher FOO",
365 "assoc_sa_query_max_timeout 0",
366 "assoc_sa_query_retry_timeout 0",
370 "device_name 1234567890123456789012345678901234567890",
371 "manufacturer 1234567890123456789012345678901234567890123456789012345678901234567890",
372 "model_name 1234567890123456789012345678901234567890",
373 "model_number 1234567890123456789012345678901234567890",
374 "serial_number 1234567890123456789012345678901234567890",
377 "ap_settings /tmp/does/not/exist/ap-settings.foo",
378 "wps_nfc_dev_pw_id 4",
379 "wps_nfc_dev_pw_id 100000",
381 "access_network_type -1",
382 "access_network_type 16",
383 "hessid 00:11:22:33:44",
384 "network_auth_type 0q",
385 "ipaddr_type_availability 1q",
386 "hs20_operating_class 0",
387 "hs20_operating_class 0q",
390 "bss_load_test 12:80",
392 "vendor_elements 0q",
393 "local_pwr_constraint -1",
394 "local_pwr_constraint 256",
395 "wmm_ac_bk_cwmin -1",
396 "wmm_ac_be_cwmin 13",
397 "wmm_ac_vi_cwmax -1",
398 "wmm_ac_vo_cwmax 13",
399 "wmm_ac_foo_cwmax 6",
401 "wmm_ac_bk_aifs 256",
402 "wmm_ac_bk_txop_limit -1",
403 "wmm_ac_bk_txop_limit 65536",
407 "tx_queue_foo_aifs 3",
408 "tx_queue_data3_cwmin 4",
409 "tx_queue_data3_cwmax 4",
410 "tx_queue_data3_aifs -4",
411 "tx_queue_data3_foo 1" ]
413 if "FAIL" not in hapd
.request("SET " + e
):
414 raise Exception("Unexpected SET success: '%s'" % e
)
416 if "OK" not in hapd
.request("SET osu_server_uri https://example.com/"):
417 raise Exception("Unexpected SET osu_server_uri failure")
418 if "OK" not in hapd
.request("SET osu_friendly_name eng:Example"):
419 raise Exception("Unexpected SET osu_friendly_name failure")
421 errors
= [ "osu_friendly_name eng1:Example",
422 "osu_service_desc eng1:Example services" ]
424 if "FAIL" not in hapd
.request("SET " + e
):
425 raise Exception("Unexpected SET success: '%s'" % e
)
427 no_err
= [ "wps_nfc_dh_pubkey 0",
428 "wps_nfc_dh_privkey 0q",
429 "wps_nfc_dev_pw 012",
431 "disassoc_low_ack 0",
432 "network_auth_type 01",
434 "tdls_prohibit_chan_switch 0" ]
436 if "OK" not in hapd
.request("SET " + e
):
437 raise Exception("Unexpected SET failure: '%s'" % e
)